:root {
  --bg: #f5f4ef;
  --card: #ffffff;
  --border: #e3e1da;
  --text: #1f1e1b;
  --muted: #6f6d66;
  --accent: #378add;
  --accent-bg: #e6f1fb;
  --accent-text: #185fa5;
  --success: #0f6e56;
  --success-bg: #e1f5ee;
  --danger: #a32d2d;
  --danger-bg: #fcebeb;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191917;
    --card: #232320;
    --border: #38382f;
    --text: #eceae4;
    --muted: #a4a29a;
    --accent: #85b7eb;
    --accent-bg: #0c2c48;
    --accent-text: #b5d4f4;
    --success: #5dcaa5;
    --success-bg: #08301f;
    --danger: #f09595;
    --danger-bg: #3c1414;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; font-weight: 600; margin: 0; }

.container { max-width: 1000px; margin: 0 auto; padding: 20px 16px 48px; }

/* ---------- Nav ---------- */
.topnav { background: var(--card); border-bottom: 1px solid var(--border); }
.nav-inner {
  max-width: 1000px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; gap: 12px;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; color: var(--text); font-size: 15px;
}
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }
.nav-links { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-links a {
  color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: 14px;
}
.nav-links a:hover { text-decoration: none; background: var(--bg); }
.nav-links a.active { color: var(--text); font-weight: 600; background: var(--bg); }

/* ---------- Cards & layout ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 14px;
}
.grid { display: grid; gap: 14px; }
.grid .card { margin-bottom: 0; }
.grid { margin-bottom: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin: 6px 0 18px;
}

.card-label { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.card-label.accent { color: var(--accent-text); font-weight: 600; }
.card-value { font-size: 26px; font-weight: 600; margin: 0; }
.card-sub { font-size: 13px; margin: 4px 0 0; }
.card-sub.up { color: var(--success); }
.card-sub.down { color: var(--danger); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }

.card-insight { background: var(--accent-bg); border-color: transparent; }
.card-insight .insights { margin: 0; padding-left: 18px; color: var(--accent-text); font-size: 14px; }
.card-insight .insights li { margin-bottom: 4px; }

.charts-row .chart-wrap { position: relative; height: 220px; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 500;
  padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.table th.right { text-align: right; }
.table td { padding: 8px; border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: none; }
.table tfoot td { padding: 10px 8px; border-top: 1px solid var(--border); border-bottom: none; }

.badge {
  display: inline-block; font-size: 12px; padding: 2px 10px; border-radius: 999px;
  background: var(--bg); color: var(--muted);
}
.badge-liquid    { background: #e6f1fb; color: #185fa5; }
.badge-invest    { background: #e1f5ee; color: #0f6e56; }
.badge-gold      { background: #faeeda; color: #854f0b; }
.badge-forex     { background: #faece7; color: #993c1d; }
.badge-receivable{ background: #eeedfe; color: #534ab7; }
@media (prefers-color-scheme: dark) {
  .badge-liquid    { background: #0c2c48; color: #b5d4f4; }
  .badge-invest    { background: #08301f; color: #9fe1cb; }
  .badge-gold      { background: #3c2a08; color: #fac775; }
  .badge-forex     { background: #3c1a0e; color: #f5c4b3; }
  .badge-receivable{ background: #221f45; color: #cecbf6; }
}

.row-inactive { opacity: 0.55; }

/* ---------- Forms ---------- */
input[type="text"], input[type="password"], input[type="month"], select {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text); font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field-label { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.inline-form { display: inline-block; }
.inline-form input[type="month"] { width: auto; }
.form-actions { display: flex; gap: 8px; margin-top: 12px; }
.form-table input { max-width: 240px; }

.checkbox-grid { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.checkbox-item { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.checkbox-item input { width: auto; height: auto; }

.dyn-rows { margin-bottom: 8px; }
.dyn-row {
  display: grid; grid-template-columns: 1fr 1fr 34px; gap: 8px;
  margin-bottom: 8px; align-items: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text);
  font-size: 14px; font-family: inherit; cursor: pointer;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--text); color: var(--card); border-color: var(--text); }
.btn-primary:hover { opacity: 0.88; background: var(--text); }
.btn-block { width: 100%; }
.btn-small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { height: 30px; width: 34px; padding: 0; font-size: 16px; color: var(--muted); }

.submit-bar { margin-top: 4px; }

/* ---------- Misc ---------- */
.flash {
  background: var(--success-bg); color: var(--success);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}
.notice {
  background: var(--accent-bg); color: var(--accent-text);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}
.error {
  background: var(--danger-bg); color: var(--danger);
  border-radius: 8px; padding: 8px 12px; font-size: 14px;
}

.progress {
  height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden;
}
.progress-fill { height: 100%; background: #1d9e75; }
.goal-row { margin-bottom: 14px; }
.goal-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 6px; }
.goal-name { font-weight: 600; }
.goal-sub { font-size: 13px; margin: 6px 0 0; }
.actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.card .actions { justify-content: flex-start; margin-top: 10px; }

.empty-state { text-align: center; padding: 60px 20px; }
.empty-state p { margin: 10px 0 20px; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px 26px; width: 320px; max-width: calc(100vw - 32px);
}
.login-brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 17px; color: var(--text);
}
.login-brand svg { color: var(--accent); }
.login-card .muted { font-size: 13px; margin: 2px 0 16px; }
.login-card input { margin-bottom: 10px; }
.login-card .error { margin-bottom: 10px; }

@media (max-width: 560px) {
  .dyn-row { grid-template-columns: 1fr 1fr 30px; }
  .form-table input { max-width: none; }
  .nav-links a { padding: 6px 7px; font-size: 13px; }
}
