/* Интерфейс трекера: тёмная тема по умолчанию, светлая через data-theme="light".
   Одна сетка: слева навигация фиксированной ширины, справа прокручиваемый лист. */

:root {
  --bg: #0e1116;
  --bg-panel: #151a21;
  --bg-raised: #1b222b;
  --bg-hover: #212a35;
  --line: #262f3b;
  --line-soft: #1e252e;
  --text: #e6ebf2;
  --text-dim: #8b98a9;
  --text-faint: #5c6878;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --pos: #35c48b;
  --neg: #ef6a72;
  --warn: #e0a458;
  --radius: 10px;
  --row-h: 36px;
  --sidebar-w: 268px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-panel: #ffffff;
  --bg-raised: #ffffff;
  --bg-hover: #f0f2f5;
  --line: #e3e7ec;
  --line-soft: #eef1f4;
  --text: #14181e;
  --text-dim: #5f6b7a;
  --text-faint: #96a1ae;
  --accent: #2f6fe4;
  --accent-soft: rgba(47, 111, 228, 0.1);
  --pos: #10996a;
  --neg: #d2434c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: var(--accent); }

/* ------------------------------------------------------------------ каркас */

#app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; }

.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 16px 18px 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }

.networth { padding: 6px 18px 16px; border-bottom: 1px solid var(--line); }
.networth .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-faint); }
.networth .value { font: 600 26px/1.2 var(--mono); margin-top: 4px; letter-spacing: -0.5px; }
.networth .delta { font-size: 12px; margin-top: 3px; font-family: var(--mono); }
.networth .split { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--text-dim); }
.networth .split b { display: block; font: 500 13px/1.4 var(--mono); color: var(--text); }

.nav { flex: 1; overflow-y: auto; padding: 10px 10px 20px; }
.nav-group { margin-top: 14px; }
.nav-group > .title {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--text-faint);
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 8px; border-radius: 8px;
  color: var(--text-dim); text-align: left;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); }
.nav-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .sum { font: 400 12px/1 var(--mono); color: var(--text-faint); }
.nav-item.drop-target { box-shadow: inset 0 -2px 0 var(--accent); }

.sidebar-foot { border-top: 1px solid var(--line); padding: 8px 10px; display: flex; gap: 4px; }
.sidebar-foot button {
  flex: 1; padding: 7px; border-radius: 8px; color: var(--text-dim); font-size: 12px;
}
.sidebar-foot button:hover { background: var(--bg-hover); color: var(--text); }

/* -------------------------------------------------------------------- лист */

.main { overflow-y: auto; }
.sheet-head {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: flex-end; gap: 16px;
  padding: 22px 32px 14px;
  background: linear-gradient(var(--bg) 72%, transparent);
  backdrop-filter: blur(6px);
}
.sheet-head h1 { margin: 0; font-size: 22px; font-weight: 600; }
.sheet-head .total { margin-left: auto; text-align: right; }
.sheet-head .total .v { font: 600 20px/1.2 var(--mono); }
.sheet-head .total .d { font: 12px/1.4 var(--mono); color: var(--text-dim); }

.sheet-body { padding: 0 32px 120px; max-width: 1400px; }

/* ------------------------------------------------------------------- блоки */

.section {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}
.section.dragging { opacity: 0.4; }
.section.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.section.drop-after { box-shadow: 0 2px 0 var(--accent); }

.section-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.section.collapsed .section-head { border-bottom: 0; }
.section-head .chev { color: var(--text-faint); width: 18px; text-align: center; transition: transform 0.12s; }
.section.collapsed .section-head .chev { transform: rotate(-90deg); }
.section-head .name { font-weight: 600; }
.section-head .count { color: var(--text-faint); font-size: 12px; }
.section-head .total { margin-left: auto; font: 500 14px/1 var(--mono); }
.section-head .grip { color: var(--text-faint); cursor: grab; opacity: 0; }
.section:hover .section-head .grip { opacity: 1; }

.section.collapsed .table-wrap { display: none; }

/* ----------------------------------------------------------------- таблица */

.table-wrap { overflow-x: auto; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; }

table.grid th {
  position: relative;
  padding: 7px 10px;
  font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-faint); text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg-panel);
}
table.grid th.num, table.grid td.num { text-align: right; }
table.grid th .resize {
  position: absolute; top: 0; right: -3px; width: 6px; height: 100%;
  cursor: col-resize;
}
table.grid th .resize:hover { background: var(--accent-soft); }

table.grid td {
  height: var(--row-h);
  padding: 0;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr.row:hover td { background: var(--bg-hover); }
table.grid tr.row.dragging { opacity: 0.35; }
table.grid tr.row.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
table.grid tr.row.drop-after td { box-shadow: inset 0 -2px 0 var(--accent); }
table.grid tr.row.selected td { background: var(--accent-soft); }

.cell {
  display: block; width: 100%; height: var(--row-h);
  padding: 0 10px; line-height: var(--row-h);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: text;
}
.cell.num { text-align: right; font-family: var(--mono); }
.cell.empty { color: var(--text-faint); }
.cell.editing { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 3px; background: var(--bg-raised); }
.cell input {
  width: 100%; height: 100%; padding: 0; border: 0; outline: 0; background: transparent;
  font: inherit; text-align: inherit;
}
.cell .cur { color: var(--text-faint); font-size: 11px; margin-left: 4px; }
.cell a { text-decoration: none; }

td.gutter, th.gutter { width: 28px; }
td.spacer, th.spacer { width: auto; min-width: 0; }
td.gutter .grip { display: block; width: 100%; text-align: center; color: var(--text-faint); opacity: 0; cursor: grab; }
tr.row:hover td.gutter .grip { opacity: 1; }
td.tools, th.tools { width: 34px; }
td.tools button { opacity: 0; padding: 4px 6px; border-radius: 6px; color: var(--text-faint); }
tr.row:hover td.tools button { opacity: 1; }
td.tools button:hover { background: var(--bg-hover); color: var(--text); }

.delta { font-family: var(--mono); font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--text-faint); }

.section-foot { display: flex; gap: 6px; padding: 7px 10px; border-top: 1px solid var(--line-soft); }
.section-foot button { color: var(--text-faint); font-size: 12px; padding: 4px 8px; border-radius: 6px; }
.section-foot button:hover { background: var(--bg-hover); color: var(--text); }

/* -------------------------------------------------------------- элементы UI */

.btn {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  color: var(--text-dim); font-size: 13px; background: var(--bg-panel);
}
.btn:hover { background: var(--bg-hover); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger:hover { color: var(--neg); border-color: var(--neg); }

.icon-btn { padding: 5px 7px; border-radius: 7px; color: var(--text-faint); }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.menu {
  position: fixed; z-index: 200; min-width: 190px; padding: 5px;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 9px; border-radius: 7px; text-align: left; font-size: 13px; }
.menu button:hover { background: var(--bg-hover); }
.menu button.danger:hover { color: var(--neg); }
.menu .sep { height: 1px; margin: 5px 4px; background: var(--line); }
.menu .head { padding: 6px 9px 3px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-faint); }

.overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal {
  width: min(680px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.modal header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 16px; }
.modal header .icon-btn { margin-left: auto; }
.modal .body { padding: 18px 20px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; font-size: 12px; color: var(--text-dim); }
.field input, .field select {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--line); outline: 0;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

table.plain { width: 100%; border-collapse: collapse; }
table.plain th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--text-faint); padding: 6px 8px; }
table.plain td { padding: 4px 8px; border-top: 1px solid var(--line-soft); }
table.plain input { width: 100%; padding: 6px 8px; border-radius: 7px; background: var(--bg); border: 1px solid var(--line); outline: 0; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 400; display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; border-radius: 10px;
  background: var(--bg-raised); border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  font-size: 13px;
}
.toast button { color: var(--accent); font-weight: 500; }

/* ------------------------------------------------------------------- обзор */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--bg-panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--text-faint); }
.card .value { font: 600 22px/1.3 var(--mono); margin-top: 4px; }
.card .sub { font: 12px/1.4 var(--mono); color: var(--text-dim); }

.chart-box { background: var(--bg-panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; }
.chart-box header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.chart-box header h3 { margin: 0; font-size: 14px; font-weight: 600; }
.chart-box .ranges { margin-left: auto; display: flex; gap: 4px; }
.chart-box .ranges button { padding: 3px 9px; border-radius: 6px; font-size: 12px; color: var(--text-dim); }
.chart-box .ranges button.active { background: var(--accent-soft); color: var(--text); }
svg.chart { width: 100%; height: 240px; display: block; }
svg.chart .grid-line { stroke: var(--line-soft); stroke-width: 1; }
svg.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
svg.chart .area { fill: url(#kgrad); }
svg.chart text { fill: var(--text-faint); font: 10px var(--mono); }
svg.chart .dot { fill: var(--accent); }

.breakdown .bar { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.breakdown .bar .nm { width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breakdown .bar .track { flex: 1; height: 8px; border-radius: 4px; background: var(--bg-hover); overflow: hidden; }
.breakdown .bar .fill { height: 100%; border-radius: 4px; background: var(--accent); }
.breakdown .bar.debt .fill { background: var(--neg); }
.breakdown .bar .vl { width: 130px; text-align: right; font-family: var(--mono); font-size: 12px; }

.empty-state { padding: 60px 0; text-align: center; color: var(--text-faint); }
.empty-state p { margin: 0 0 14px; }

/* ------------------------------------------------------------------- вход */

body.login { display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 330px; padding: 28px; border-radius: 14px;
  background: var(--bg-panel); border: 1px solid var(--line);
}
.login-card h1 { margin: 0 0 4px; font-size: 19px; }
.login-card p { margin: 0 0 20px; color: var(--text-dim); font-size: 13px; }
.login-card .err { color: var(--neg); font-size: 12px; min-height: 17px; margin-top: 8px; }
.login-card button { width: 100%; margin-top: 10px; padding: 10px; }

.menu-toggle { display: none; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 100; width: var(--sidebar-w); height: 100%;
    transform: translateX(-100%); transition: transform 0.18s;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.4);
  }
  .sidebar.open { transform: none; }
  .menu-toggle { display: block; }
  .sheet-head, .sheet-body { padding-left: 16px; padding-right: 16px; }
  .sheet-head { padding-top: 14px; }
}
