:root {
  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --ink-1: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11,11,11,.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #006300;
  --critical: #d03b3b;
  --accent-wash: rgba(42,120,214,.08);
  --sp: 8px;
  --r: 10px;
  --shadow: 0 1px 2px rgba(11,11,11,.04), 0 4px 16px rgba(11,11,11,.04);
}
:root[data-theme="dark"] {
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --ink-1: #ffffff;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255,255,255,.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good: #0ca30c;
  --critical: #d03b3b;
  --accent-wash: rgba(57,135,229,.14);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink-1);
  background: var(--plane);
  -webkit-font-smoothing: antialiased;
}
.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }

/* ---------- sidebar ---------- */
.side {
  background: var(--surface-1);
  border-right: 1px solid var(--ring);
  padding: 20px 12px;
  display: flex; flex-direction: column; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; flex: none;
  background: var(--series-1);
  display: grid; place-items: center;
  color: #fff; font-weight: 650; font-size: 13px;
}
.brand-name { font-weight: 600; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--ink-3); margin-top: -2px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 0 8px 6px; }
.nav button {
  appearance: none; border: 0; background: none; cursor: pointer;
  font: inherit; color: var(--ink-2); text-align: left;
  padding: 8px 10px; border-radius: 8px;
  display: flex; align-items: center; gap: 9px; width: 100%;
  transition: background .13s, color .13s;
}
.nav button:hover { background: var(--accent-wash); color: var(--ink-1); }
.nav button[aria-current="page"] { background: var(--accent-wash); color: var(--ink-1); font-weight: 550; }
.nav svg { width: 16px; height: 16px; flex: none; opacity: .75; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 8px; }
.theme-toggle, .logout {
  appearance: none; border: 1px solid var(--ring); background: none; cursor: pointer;
  font: inherit; font-size: 12px; color: var(--ink-2);
  padding: 7px 10px; border-radius: 8px; display: flex; align-items: center; gap: 8px;
  transition: border-color .13s, color .13s;
}
.theme-toggle:hover, .logout:hover { border-color: var(--axis); color: var(--ink-1); }

/* ---------- main ---------- */
.main { padding: 24px 28px 48px; max-width: 1240px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
h1 { font-size: 21px; font-weight: 600; letter-spacing: -.015em; margin: 0; }
.head-sub { font-size: 13px; color: var(--ink-3); margin-top: 3px; }
.seg { display: inline-flex; border: 1px solid var(--ring); border-radius: 8px; overflow: hidden; }
.seg button {
  appearance: none; border: 0; background: var(--surface-1); cursor: pointer;
  font: inherit; font-size: 13px; color: var(--ink-2); padding: 7px 13px;
  border-right: 1px solid var(--ring);
  transition: background .13s, color .13s;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--series-1); color: #fff; font-weight: 550; }

.card {
  background: var(--surface-1); border: 1px solid var(--ring);
  border-radius: var(--r); box-shadow: var(--shadow);
}
.card-head { padding: 14px 18px 0; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-title { font-size: 14px; font-weight: 600; }
.card-note { font-size: 12px; color: var(--ink-3); }
.card-body { padding: 14px 18px 18px; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--ring); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tile-value { font-size: 25px; font-weight: 600; letter-spacing: -.02em; margin-top: 6px; }
.tile-value .cur { font-size: 15px; font-weight: 500; color: var(--ink-3); margin-left: 3px; }
.tile-meta { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.up { color: var(--good); } .down { color: var(--critical); }

.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 12px; margin-top: 12px; }
.grid-2.even { grid-template-columns: 1fr 1fr; }

/* ---------- chart ---------- */
.legend { display: flex; gap: 16px; align-items: center; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
svg.chart { display: block; width: 100%; overflow: visible; }
.tick { font-size: 11px; fill: var(--ink-3); }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.mark-label { font-size: 10.5px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.hoverband { fill: transparent; }
.hoverband:hover { fill: var(--accent-wash); }

.tooltip {
  position: fixed; pointer-events: none; z-index: 50;
  background: var(--surface-1); border: 1px solid var(--ring); border-radius: 8px;
  box-shadow: var(--shadow); padding: 9px 11px; font-size: 12px; min-width: 168px;
  opacity: 0; transition: opacity .1s;
}
.tooltip.on { opacity: 1; }
.tt-title { font-weight: 600; margin-bottom: 5px; }
.tt-row { display: flex; justify-content: space-between; gap: 14px; color: var(--ink-2); }
.tt-row b { color: var(--ink-1); font-variant-numeric: tabular-nums; font-weight: 550; }
.tt-sep { border-top: 1px solid var(--ring); margin: 5px 0; }

/* ---------- bar list ---------- */
.barlist { display: flex; flex-direction: column; gap: 9px; }
.barrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; }
.barrow .name { font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barrow .val { font-size: 12.5px; font-variant-numeric: tabular-nums; font-weight: 550; }
.bartrack { grid-column: 1 / -1; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.barfill { height: 100%; border-radius: 3px; }

/* ---------- table ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
select, input[type="text"], input[type="number"], input[type="date"], input[type="password"] {
  appearance: none; font: inherit; font-size: 13px; color: var(--ink-1);
  background: var(--surface-1); border: 1px solid var(--ring);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input[type="date"] { color-scheme: light; }
:root[data-theme="dark"] input[type="date"] { color-scheme: dark; }
select:focus, input:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.search { flex: 1; min-width: 180px; }
.chip {
  font-size: 12px; color: var(--ink-2); background: var(--accent-wash);
  border: 0; border-radius: 999px; padding: 5px 11px; cursor: pointer; font-family: inherit;
}
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); font-weight: 550; padding: 0 10px 8px; border-bottom: 1px solid var(--ring);
  position: sticky; top: 0; background: var(--surface-1); z-index: 1;
}
tbody td { padding: 8px 10px; border-bottom: 1px solid var(--grid); font-size: 13px; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--accent-wash); }
td.num, th.num { text-align: right; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-2); }
.muted { color: var(--ink-3); }
.article { color: var(--ink-1); }
.article small { color: var(--ink-3); display: block; }
.scroll { max-height: 560px; overflow: auto; margin: 0 -18px; padding: 0 18px; }
.tfoot { display: flex; justify-content: space-between; gap: 16px; padding-top: 12px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.tfoot b { color: var(--ink-1); font-variant-numeric: tabular-nums; }
.rowdel {
  appearance: none; border: 0; background: none; cursor: pointer; color: var(--ink-3);
  font-size: 14px; padding: 2px 4px; border-radius: 6px; opacity: 0; font-family: inherit;
}
tbody tr:hover .rowdel { opacity: 1; }
.rowdel:hover { color: var(--critical); background: var(--surface-1); }
.pager { display: flex; gap: 6px; align-items: center; }
.pager button {
  appearance: none; border: 1px solid var(--ring); background: var(--surface-1); cursor: pointer;
  font: inherit; font-size: 13px; color: var(--ink-2); padding: 4px 10px; border-radius: 7px;
}
.pager button:disabled { opacity: .35; cursor: default; }

/* ---------- form ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }
label { font-size: 12px; color: var(--ink-2); }
.hint { font-size: 11.5px; color: var(--ink-3); }
.period { display: flex; align-items: center; gap: 8px; }
.period input { flex: 1; }
.split { display: flex; flex-direction: column; gap: 7px; }
.splitrow { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 13px; padding-bottom: 6px; border-bottom: 1px solid var(--grid); }
.splitrow .m { color: var(--ink-2); }
.splitrow .a { font-variant-numeric: tabular-nums; font-weight: 550; }
.splitrow.next .m { color: var(--ink-3); }
.callout {
  border-left: 2px solid var(--series-3); background: var(--surface-1);
  padding: 10px 12px; border-radius: 0 8px 8px 0; font-size: 12.5px; color: var(--ink-2);
  margin-top: 12px;
}
.callout b { color: var(--ink-1); }
.callout.err { border-color: var(--critical); color: var(--critical); }
.btn {
  appearance: none; border: 0; border-radius: 8px; cursor: pointer; font: inherit;
  font-size: 13.5px; font-weight: 550; padding: 10px 18px;
  background: var(--series-1); color: #fff;
  transition: filter .13s, opacity .13s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: none; color: var(--ink-2); border: 1px solid var(--ring); }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; }
.screen { display: none; }
.screen.on { display: block; animation: screenIn .22s ease both; }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- индикация загрузки ---------- */
#loadbar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 120;
  pointer-events: none; opacity: 0; transition: opacity .2s; overflow: hidden;
}
#loadbar.on { opacity: 1; }
#loadbar::before {
  content: ''; position: absolute; top: 0; bottom: 0; width: 40%;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--series-1), transparent);
  animation: loadsweep 1.1s ease-in-out infinite;
}
@keyframes loadsweep {
  from { transform: translateX(-110%); }
  to   { transform: translateX(360%); }
}
@keyframes spin { to { transform: rotate(360deg); } }
.spin {
  display: inline-block; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor;
  animation: spin .7s linear infinite;
  vertical-align: -2px; flex: none;
}
.hint.loading { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.btn.busy { pointer-events: none; }
.btn.busy::before {
  content: ''; display: inline-block; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 35%, transparent);
  border-top-color: currentColor;
  animation: spin .7s linear infinite;
  margin-right: 8px; vertical-align: -2px;
}

/* ---------- логин ---------- */
.login-veil {
  position: fixed; inset: 0; z-index: 100; display: none;
  background: var(--plane); place-items: center;
}
.login-veil.on { display: grid; }
.login-card {
  background: var(--surface-1); border: 1px solid var(--ring); border-radius: 12px;
  box-shadow: var(--shadow); padding: 28px; width: 320px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-card .brand { padding: 0; }
.login-err { font-size: 12.5px; color: var(--critical); min-height: 16px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(8px);
  z-index: 90; background: var(--ink-1); color: var(--plane);
  border-radius: 9px; padding: 10px 16px; font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
}
.toast.on { opacity: 1; transform: translateX(-50%); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .screen.on { animation: none; }
  * { transition-duration: .01ms !important; }
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .side { flex-direction: row; align-items: center; gap: 12px; padding: 10px 12px; }
  .nav { flex-direction: row; }
  .nav-label, .side-foot .hint { display: none; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; }
  .main { padding: 16px 14px 40px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2.even { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---- вкладки внутри раздела ---- */
.tabbar { margin-bottom: 16px; }
.tabbar button[aria-pressed="true"] { background: var(--accent-wash); color: var(--ink-1); font-weight: 550; }

/* ---- сверка с таблицами ---- */
.sync-rows { font-size: 12px; }
.sync-rows thead th { position: static; }
.sync-preview > td { padding: 4px 10px 12px; }

/* ---- ДДС / клиенты / прогноз ---- */
.dds-table { font-size: 12px; white-space: nowrap; }
.dds-table td, .dds-table th { padding: 5px 7px; }
.dds-table .dds-name { position: sticky; left: 0; background: var(--surface-1); min-width: 190px; max-width: 260px; white-space: normal; }
.dds-table .dds-sub { padding-left: 14px; color: var(--ink-2); display: inline-block; }
.dds-table tr.dds-head td { border-top: 1px solid var(--line); padding-top: 8px; }
.dds-table tr.dds-head.in td b { color: var(--good, var(--series-1)); }
.dds-table tr.dds-head.out td b { color: var(--critical); }
.dds-table tr.dds-saldo td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.dds-table tr.dds-flow td { border-top: 1px solid var(--line); }
.dds-table .dds-total { font-weight: 600; }
.alive-sel { font-size: 12px; padding: 4px 6px; }
tr.fc-cur td { background: color-mix(in srgb, var(--series-3) 9%, transparent); }
