/* =========================================================================
   Финансовый пульт — «Тёмный премиум»
   Direction B. Elevated dark theme in the spirit of Linear / Vercel / Raycast.
   Pure drop-in style.css. No HTML changes, no class renames, no web-font @import.
   ========================================================================= */

:root {
  /* ---- Neutrals: layered surfaces, each a half-step lighter ------------- */
  --bg:            #0a0b0f;   /* page canvas — deep near-black                 */
  --bg-tint:       #0c0e13;   /* ambient gradient partner                     */
  --surface:       #14161d;   /* card, slightly lighter than page             */
  --surface-2:     #191c24;   /* raised: inputs, segmented tracks             */
  --surface-3:     #20242e;   /* hover / active inner fill                    */
  --line:          #262b36;   /* hairline border                             */
  --line-strong:   #333a48;   /* emphasized hairline (heads, hovers)          */
  --line-lum:      rgba(255,255,255,.06); /* luminous top edge on surfaces    */

  /* ---- Text ------------------------------------------------------------- */
  --text:          #edeff4;
  --text-soft:     #cdd3de;
  --muted:         #8b93a5;
  --faint:         #626b7d;

  /* ---- Accent: electric violet ----------------------------------------- */
  --accent:        #7c6cf0;
  --accent-hi:     #948bf5;   /* hover                                        */
  --accent-lo:     #6353e0;   /* pressed                                      */
  --accent-ink:    #ffffff;   /* text on accent                              */
  --accent-soft:   rgba(124,108,240,.14);
  --accent-softer: rgba(124,108,240,.08);
  --accent-ring:   rgba(124,108,240,.45);
  --accent-glow:   rgba(124,108,240,.40);

  /* ---- Semantic (buckets, tags, notes) --------------------------------- */
  --good:          #34d399;
  --warn:          #f5b544;
  --bad:           #f4726b;
  --good-soft:     rgba(52,211,153,.14);
  --warn-soft:     rgba(245,181,68,.14);
  --bad-soft:      rgba(244,114,107,.14);

  /* ---- Chart palette (themable later) ---------------------------------- */
  --chart-balance:       #7c6cf0;             /* forecast line               */
  --chart-balance-fill:  rgba(124,108,240,.16);
  --chart-debt:          #f4726b;             /* debt line                   */
  --chart-debt-fill:     rgba(244,114,107,.14);
  --chart-payment:       #34d399;             /* payment / overpay           */
  --chart-bar:           #5a7fe0;             /* expense bars                */
  --chart-axis:          #7b8494;             /* axis tick labels            */
  --chart-grid:          rgba(255,255,255,.05);
  --chart-grid-strong:   rgba(255,255,255,.10);

  /* ---- Geometry & motion ------------------------------------------------ */
  --radius:      14px;
  --radius-sm:   10px;
  --radius-xs:   8px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 0 0 var(--line-lum) inset,
                 0 12px 32px -18px rgba(0,0,0,.65);
  --shadow-pop:  0 18px 50px -22px rgba(0,0,0,.8);
  --ease: cubic-bezier(.22,.61,.36,1);

  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

*, *::before, *::after { box-sizing: border-box; }

/* ---- HARD CONTRACT: hidden must win over any display ------------------- */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 620px at 78% -8%, rgba(124,108,240,.10), transparent 60%),
    radial-gradient(900px 520px at 6% 4%, rgba(70,120,230,.06), transparent 55%),
    linear-gradient(180deg, var(--bg-tint) 0%, var(--bg) 42%);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: .1px;
}

::selection { background: var(--accent-soft); color: var(--text); }

/* Custom scrollbar for that polished feel */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 999px;
  border: 3px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; }

/* =========================================================================
   LOGIN
   ========================================================================= */
.login-screen {
  min-height: 100vh;
  display: flex;                 /* overridden by [hidden] when not authed */
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,.03), transparent 40%),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 30px;
  width: min(380px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-pop), 0 0 0 1px var(--line-lum) inset;
}
.login-card::before {
  content: "";
  position: absolute; inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(160deg, rgba(124,108,240,.5), transparent 45%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  pointer-events: none;
  opacity: .7;
}
.login-card h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -.2px;
}
.login-card .muted { margin: 0 0 6px; font-size: 13px; }
.login-card input { width: 100%; padding: 11px 13px; }
.login-card button { width: 100%; padding: 11px 14px; margin-top: 2px; }
.login-card .error { margin-top: 2px; }

/* =========================================================================
   APP LAYOUT
   ========================================================================= */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 22px 56px;
}

/* ---- Topbar ----------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 0 14px;
  margin-bottom: 20px;
  background:
    linear-gradient(180deg, var(--bg) 60%, rgba(10,11,15,.72) 100%);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 650;
  font-size: 16px;
  letter-spacing: -.2px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}
.brand::before {
  content: "";
  width: 10px; height: 10px;
  border-radius: 3px;
  background: linear-gradient(150deg, var(--accent-hi), var(--accent-lo));
  box-shadow: 0 0 12px 1px var(--accent-glow);
}

/* ---- Tabs ------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 3px;
  margin: 0 auto 0 4px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: 0 1px 0 0 var(--line-lum) inset;
}
.tabs button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: color .16s var(--ease), background .16s var(--ease);
}
.tabs button:hover { color: var(--text-soft); background: var(--surface-3); }
.tabs button.active {
  color: var(--accent-ink);
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  box-shadow: 0 4px 16px -6px var(--accent-glow),
              0 1px 0 0 rgba(255,255,255,.22) inset;
}
.tabs button.active:hover { background: linear-gradient(180deg, var(--accent-hi), var(--accent)); }

/* =========================================================================
   METRICS
   ========================================================================= */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.metric {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,.025), transparent 46%),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
  transition: border-color .18s var(--ease), transform .18s var(--ease);
}
.metric:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.metric .label {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 550;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.metric .value {
  font-size: 24px;
  font-weight: 660;
  line-height: 1.15;
  margin-top: 7px;
  letter-spacing: -.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   GRID + CARDS
   ========================================================================= */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,.02), transparent 34%),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  box-shadow: var(--shadow-card);
}
.card.wide { grid-column: 1 / -1; }   /* HARD CONTRACT: full width */

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-head h2 {
  font-size: 15px;
  font-weight: 620;
  letter-spacing: -.1px;
  margin: 0;
  color: var(--text);
}

/* =========================================================================
   FORM CONTROLS
   ========================================================================= */
input, select, button, textarea { font: inherit; }

input, select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease),
              background .16s var(--ease);
}
input::placeholder { color: var(--faint); }
input:hover, select:hover { border-color: var(--line-strong); }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
select {
  cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
input[type="number"] { font-variant-numeric: tabular-nums; }

/* Range slider — themed track + violet thumb with glow */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  background: transparent;
  padding: 0;
  border: none;
  height: 22px;
  cursor: pointer;
}
input[type="range"]:focus { outline: none; box-shadow: none; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0 var(--pct,50%), var(--surface-3) var(--pct,50%) 100%);
  background: var(--surface-3);
  border: 1px solid var(--line);
}
input[type="range"]::-moz-range-track {
  height: 5px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--line);
}
input[type="range"]::-moz-range-progress {
  height: 5px; border-radius: 999px; background: var(--accent);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px var(--accent-softer), 0 2px 8px -1px var(--accent-glow);
  transition: box-shadow .16s var(--ease);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px var(--accent-softer), 0 2px 8px -1px var(--accent-glow);
}
input[type="range"]:focus::-webkit-slider-thumb { box-shadow: 0 0 0 5px var(--accent-ring); }
input[type="range"]:focus::-moz-range-thumb { box-shadow: 0 0 0 5px var(--accent-ring); }

/* Primary button */
button {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-xs);
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 570;
  letter-spacing: .1px;
  box-shadow: 0 6px 18px -8px var(--accent-glow),
              0 1px 0 0 rgba(255,255,255,.18) inset;
  transition: transform .12s var(--ease), box-shadow .16s var(--ease),
              filter .16s var(--ease);
}
button:hover { filter: brightness(1.06); box-shadow: 0 8px 22px -8px var(--accent-glow), 0 1px 0 0 rgba(255,255,255,.24) inset; }
button:active { transform: translateY(1px); filter: brightness(.97); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

/* Ghost button */
button.ghost {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  box-shadow: none;
}
button.ghost:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface-3);
  filter: none;
}
button.ghost:active { transform: translateY(1px); }

/* Segmented control */
.seg {
  display: inline-flex;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px;
  flex-wrap: wrap;
  box-shadow: 0 1px 0 0 var(--line-lum) inset;
}
.seg button {
  background: transparent;
  color: var(--muted);
  padding: 6px 13px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 530;
  box-shadow: none;
  transition: color .16s var(--ease), background .16s var(--ease);
}
.seg button:hover { color: var(--text-soft); background: var(--surface-3); filter: none; }
.seg button:active { transform: none; }
.seg button.active {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 3px 12px -5px var(--accent-glow),
              0 1px 0 0 rgba(255,255,255,.2) inset;
}
.seg button.active:hover { filter: brightness(1.04); }

/* Rows */
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0;
}
.row label { color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap; }
.row input { flex: 1; min-width: 0; }

/* =========================================================================
   NOTES / MUTED / ERROR
   ========================================================================= */
.muted { color: var(--muted); }
.note {
  color: var(--muted);
  font-size: 13px;
  margin: 10px 0;
  min-height: 18px;
  line-height: 1.45;
}
.note.good { color: var(--good); }
.note.bad  { color: var(--bad); }
/* Give populated good/bad notes a soft pill so they read as status chips */
.note.good:not(:empty), .note.bad:not(:empty) {
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  font-weight: 500;
  border: 1px solid transparent;
}
.note.good:not(:empty) { background: var(--good-soft); border-color: rgba(52,211,153,.22); }
.note.bad:not(:empty)  { background: var(--bad-soft);  border-color: rgba(244,114,107,.22); }

.error {
  color: var(--bad);
  font-size: 13px;
  font-weight: 500;
}
.error:not(:empty) {
  padding: 9px 12px;
  border-radius: var(--radius-xs);
  background: var(--bad-soft);
  border: 1px solid rgba(244,114,107,.24);
}

/* =========================================================================
   CHARTS
   ========================================================================= */
.chart-wrap {
  position: relative;
  height: 240px;     /* HARD CONTRACT: fixed height for Chart.js */
  margin-top: 12px;
}
.chart-wrap.small { height: 180px; }
.chart-wrap canvas { display: block; }

/* =========================================================================
   DEBT PAYOFF
   ========================================================================= */
.payoff-summary {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0 10px;
  font-variant-numeric: tabular-nums;
}
.payoff-summary .pill {
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.payoff-summary .pill b {
  color: var(--text);
  font-size: 16px;
  font-weight: 640;
  letter-spacing: -.2px;
}
.payoff-order {
  list-style: none;
  padding: 0;
  margin: 8px 0 4px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  counter-reset: payoff;
}
.payoff-order li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
}
.payoff-order li:last-child { border-bottom: none; }
.payoff-order li span:first-child {
  color: var(--text-soft);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.payoff-order li span:first-child::before {
  counter-increment: payoff;
  content: counter(payoff);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-hi);
  font-size: 11px;
  font-weight: 640;
  flex: none;
}
.payoff-order li span:last-child { color: var(--muted); white-space: nowrap; }

/* =========================================================================
   EXPENSES
   ========================================================================= */
.filepick { display: inline-block; }
.filepick input { display: none; }
.filepick span {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  cursor: pointer;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 500;
  transition: border-color .16s var(--ease), background .16s var(--ease), color .16s var(--ease);
}
.filepick span::before {
  content: "↑";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent-hi);
  font-weight: 700;
  font-size: 13px;
}
.filepick:hover span {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-softer);
}

.expense-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 14px;
  flex-wrap: wrap;
}
.expense-controls select { padding: 7px 30px 7px 11px; }

.buckets {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 14px 0;
}
.bucket-row .bar-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 12.5px;
  margin-bottom: 5px;
  font-variant-numeric: tabular-nums;
}
.bucket-row .bar-head span:first-child { color: var(--text-soft); font-weight: 500; }
.bucket-row .bar-head .muted { color: var(--muted); }
.bucket-row .track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.bucket-row .fill {
  height: 100%;
  border-radius: 999px;
  /* default fill; JS may recolour via --good/--warn/--bad or inline style */
  background: linear-gradient(90deg, var(--accent), var(--accent-hi));
  box-shadow: 0 0 10px -2px var(--accent-glow);
  transition: width .5s var(--ease);
}

/* Transfers */
#transfers-block { margin-top: 14px; }
.transfers-head {
  font-size: 12px;
  font-weight: 550;
  letter-spacing: .3px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 16px 0 6px;
}
.transfer-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.transfer-row:last-child { border-bottom: none; }
.transfer-row span:first-child { color: var(--text-soft); }
.transfer-row span:last-child { color: var(--muted); white-space: nowrap; }

/* =========================================================================
   INCOME
   ========================================================================= */
.income-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
}
.income-form input, .income-form select { width: 100%; }
.income-form button { white-space: nowrap; }

.income-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.income-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  transition: background .14s var(--ease);
  border-radius: var(--radius-xs);
}
.income-list li:last-child { border-bottom: none; }
.income-list li:hover { background: var(--surface-2); }
.income-list .inc-main {
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
}
.income-list li .inc-side {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex: none;
}
.income-list .inc-side b {
  color: var(--text);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

/* Tags */
.tag {
  font-size: 11px;
  font-weight: 560;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  letter-spacing: .2px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.tag.confirmed   { background: var(--good-soft); color: var(--good); border-color: rgba(52,211,153,.24); }
.tag.expected    { background: var(--accent-soft); color: var(--accent-hi); border-color: rgba(124,108,240,.26); }
.tag.speculative { background: var(--warn-soft); color: var(--warn); border-color: rgba(245,181,68,.24); }

/* Icon buttons (✎ / ✕) */
.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 7px;
  font-size: 12px;
  margin-left: 2px;
  line-height: 1.2;
  font-weight: 500;
  box-shadow: none;
  transition: color .14s var(--ease), border-color .14s var(--ease), background .14s var(--ease);
}
.icon-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-softer);
  filter: none;
}
.icon-btn:active { transform: none; }
.icon-btn[data-act="del"]:hover {
  color: var(--bad);
  border-color: var(--bad);
  background: var(--bad-soft);
}

/* Regular income block */
.regular-income {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.regular-income label { color: var(--muted); font-size: 13px; font-weight: 500; }
.ri-row { display: flex; gap: 10px; margin-top: 8px; }
.ri-row input { flex: 1; font-variant-numeric: tabular-nums; }
.ri-row button { white-space: nowrap; }

/* =========================================================================
   LOANS
   ========================================================================= */
.loans-head {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.loans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}
.loan-card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,.02), transparent 40%),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  box-shadow: var(--shadow-card);
  transition: border-color .18s var(--ease), transform .18s var(--ease);
}
.loan-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.loan-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.loan-id {
  font-weight: 640;
  font-size: 14.5px;
  letter-spacing: -.1px;
  color: var(--text);
}
.loan-kind {
  font-size: 12px;
  margin: 3px 0 12px;
  color: var(--muted);
}
.lstats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.lstat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.lstat-l { color: var(--muted); font-size: 11px; line-height: 1.3; }
.lstat-v { color: var(--text-soft); font-weight: 550; font-size: 13px; white-space: nowrap; }
.loan-share { margin-top: 15px; }
.loan-share-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.loan-bar {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.loan-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hi));
  box-shadow: 0 0 10px -2px var(--accent-glow);
  transition: width .5s var(--ease);
}

/* =========================================================================
   FOOTER
   ========================================================================= */
.foot {
  text-align: center;
  margin-top: 32px;
  font-size: 12px;
  color: var(--faint);
  letter-spacing: .2px;
}

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 780px) {
  .grid { grid-template-columns: 1fr; }   /* HARD CONTRACT: collapse to 1 col */
}

@media (max-width: 680px) {
  .app { padding: 0 16px 44px; }
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 0 12px;
  }
  .brand { order: 0; }
  #logout { order: 1; margin-left: auto; }
  .tabs {
    order: 2;
    width: 100%;
    margin: 0;
    justify-content: space-between;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tabs button { flex: 1 0 auto; padding: 8px 12px; }
  .metric .value { font-size: 21px; }
  .income-form { grid-template-columns: 1fr 1fr; }
  .card { padding: 16px 15px 18px; }
}

@media (max-width: 420px) {
  .income-form { grid-template-columns: 1fr; }
  .lstats { grid-template-columns: 1fr; }
}

/* =========================================================================
   КАТЕГОРИИ: прогноз + правила категоризации + регулярные расходы
   ========================================================================= */
.rules-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.rules-total { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.rule-form { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.rule-form input { flex: 1 1 120px; }
.rule-form select { flex: 0 0 auto; }
.rule-list { display: flex; flex-direction: column; gap: 2px; }
.rule-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.rule-key { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.type-badge { font-size: 11px; padding: 2px 9px; border: 1px solid; border-radius: 20px; white-space: nowrap; }
.op-search { width: 100%; margin: 8px 0 10px; }
.op-total { font-variant-numeric: tabular-nums; white-space: nowrap; }
.op-type { font-size: 12px; padding: 4px 8px; }
@media (max-width: 900px) { .rules-grid { grid-template-columns: 1fr; } }

/* =========================================================================
   ДОХОДЫ: мини-CRM (клиенты → скоупы → оплаты) + чекбоксы
   ========================================================================= */
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.chk input { width: 15px; height: 15px; accent-color: var(--accent); }
#income-crm { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.crm-client { border: 1px solid var(--line); border-radius: var(--radius-sm, 10px); overflow: hidden; }
.crm-client-head {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  background: var(--surface-2, rgba(255,255,255,.03)); border-bottom: 1px solid var(--line);
}
.crm-client-name { font-weight: 640; flex: 1; }
.crm-client-total { font-variant-numeric: tabular-nums; font-weight: 600; }
.crm-scope { padding: 4px 12px 8px 20px; border-bottom: 1px solid var(--line); }
.crm-scope:last-child { border-bottom: none; }
.crm-scope-head { display: flex; align-items: center; gap: 8px; padding: 6px 0 2px; }
.crm-scope-name { color: var(--text-soft, var(--text)); font-weight: 550; flex: 1; font-size: 13px; }
.crm-scope-total { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.pay-row { display: flex; align-items: center; gap: 10px; padding: 5px 0 5px 12px; font-size: 12.5px; border-bottom: 1px dashed var(--line); }
.pay-row:last-child { border-bottom: none; }
.pay-main { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay-side { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pay-empty { padding: 4px 0 4px 12px; font-size: 12px; }

/* =========================================================================
   MOTION SAFETY
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}