/* Визуальный язык — по шаблону Apex (DashboardPack 2.2.1): шрифт Geist, изумрудный акцент,
   тёмный сайдбар в обеих темах, белые карточки с тонкой рамкой, сегментные вкладки. */
@font-face {
  font-family: "Geist"; src: url("fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Geist Mono"; src: url("fonts/GeistMono-Variable.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}

:root {
  color-scheme: light;
  --font: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --page: #f9fafb;
  --surface: #ffffff;
  --surface-2: #f1f4f5;
  --ink: #060d11;
  --ink-2: #3f494f;
  --muted: #646e74;
  --grid: #eceff1;
  --axis: #d3d9dc;
  --border: #e2e6e8;
  --accent: #007f47;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 8%, var(--surface));
  --ring: color-mix(in srgb, var(--accent) 45%, transparent);
  --good: #15803d;
  --bad: #dc2626;
  --warn: #ed9a00;
  --s1: #008e4c; --s2: #1a83db; --s3: #b87800; --s4: #a95cbb;
  --s5: #e5484d; --s6: #009294; --s7: #5b5bd6; --s8: #d4569b;
  --shadow: 0 1px 2px rgba(16, 24, 32, .05), 0 1px 3px rgba(16, 24, 32, .04);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 32, .08), 0 2px 4px -2px rgba(16, 24, 32, .05);
  --shadow-lg: 0 16px 40px -8px rgba(16, 24, 32, .18), 0 4px 12px -4px rgba(16, 24, 32, .08);
  --radius: 14px;
  --radius-md: 8px;
  /* сайдбар: тёмный в обеих темах, как в Apex */
  --side-bg: #090909;
  --side-border: #1c1c1c;
  --side-ink: #e4e7e9;
  --side-ink-2: #a7acaf;
  --side-muted: #7c8285;
  --side-hover: #141414;
  --side-active: #1a1a1a;
  --side-primary: #12b06a;
  --side-w: 256px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #050505; --surface: #141414; --surface-2: #1e1e1e;
    --ink: #e6e9eb; --ink-2: #b4bcc0; --muted: #8d969c; --grid: #222222; --axis: #3a3a3a;
    --border: #292929; --accent: #00b065; --accent-ink: #050505; --good: #22c55e; --bad: #f05252; --warn: #f0a800;
    --s1: #00a862; --s2: #2389e2; --s3: #c08200; --s4: #b36cc4;
    --s5: #ec5b5f; --s6: #00a0a0; --s7: #7a7ae6; --s8: #d25c9b;
    --shadow: none; --shadow-md: 0 4px 16px rgba(0, 0, 0, .5); --shadow-lg: 0 20px 50px rgba(0, 0, 0, .7);
    --side-bg: #040404; --side-border: #242424; --side-hover: #121212; --side-active: #1a1a1a; --side-primary: #00b065;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #050505; --surface: #141414; --surface-2: #1e1e1e;
  --ink: #e6e9eb; --ink-2: #b4bcc0; --muted: #8d969c; --grid: #222222; --axis: #3a3a3a;
  --border: #292929; --accent: #00b065; --accent-ink: #050505; --good: #22c55e; --bad: #f05252; --warn: #f0a800;
  --s1: #00a862; --s2: #2389e2; --s3: #c08200; --s4: #b36cc4;
  --s5: #ec5b5f; --s6: #00a0a0; --s7: #7a7ae6; --s8: #d25c9b;
  --shadow: none; --shadow-md: 0 4px 16px rgba(0, 0, 0, .5); --shadow-lg: 0 20px 50px rgba(0, 0, 0, .7);
  --side-bg: #040404; --side-border: #242424; --side-hover: #121212; --side-active: #1a1a1a; --side-primary: #00b065;
}

* { box-sizing: border-box; }
html { accent-color: var(--accent); }
html { scroll-behavior: smooth; scroll-padding-top: 128px; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.5 var(--font); font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 18px; font-weight: 650; margin: 0 0 14px; letter-spacing: -.015em; }
h3 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--accent); text-underline-offset: 3px; }
code, pre { font-family: var(--font-mono); font-size: 12.5px; }
pre { background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius-md); overflow-x: auto; white-space: pre-wrap; word-break: break-all; border: 1px solid var(--border); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* фокус: кольцо как в Apex */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible, .seg button:focus-visible, .tab:focus-visible, .link-btn:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--ring); border-color: var(--accent);
}
.custom-range input:focus-visible, .search:focus-visible, .form-grid input:focus-visible, .form-grid select:focus-visible, .form-grid textarea:focus-visible,
.status-list input:focus-visible, .status-list select:focus-visible, .login-card input:focus-visible,
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .input:focus-visible, .status-select:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring);
}

/* тонкие полосы прокрутки */
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 40%, transparent); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--muted) 65%, transparent); }

/* ---------- оболочка: тёмный сайдбар слева, справа шапка и страница ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); align-items: start; min-height: 100vh; }
.content { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--side-bg); color: var(--side-ink); border-right: 1px solid var(--side-border); z-index: 30;
}
.side-brand { display: flex; align-items: center; gap: 12px; height: 64px; flex: none; padding: 0 18px; border-bottom: 1px solid var(--side-border); text-decoration: none; color: var(--side-ink); }
.side-brand .brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--side-primary); color: #050505; font-size: 12px; }
.side-brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.side-brand-text b { font-size: 14px; font-weight: 700; letter-spacing: -.01em; }
.side-brand-text small { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: var(--side-muted); margin-top: 3px; }
.side nav { display: grid; gap: 2px; align-content: start; flex: 1; overflow-y: auto; padding: 14px 12px; scrollbar-color: transparent transparent; }
.side nav:hover, .side nav:focus-within { scrollbar-color: #3a3a3a transparent; }
.side-group { padding: 14px 12px 6px; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: var(--side-muted); }
.side-group:first-child { padding-top: 4px; }
.side a[data-nav] { position: relative; display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: var(--radius-md); color: var(--side-ink-2); text-decoration: none; font-size: 14px; font-weight: 500; transition: background .15s, color .15s; }
.side a[data-nav] svg { width: 18px; height: 18px; flex: none; color: var(--side-muted); transition: color .15s; }
.side a[data-nav]:hover { background: var(--side-hover); color: var(--side-ink); }
.side a[data-nav]:hover svg { color: var(--side-ink-2); }
.side a[data-nav].on { background: var(--side-active); color: var(--side-primary); }
.side a[data-nav].on svg { color: var(--side-primary); }
.side a:focus-visible { outline: 2px solid var(--side-primary); outline-offset: -2px; }
.side-user { flex: none; display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-top: 1px solid var(--side-border); }
.side-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; flex: none; background: linear-gradient(135deg, color-mix(in srgb, var(--side-primary) 75%, #000), var(--side-primary)); color: #050505; font-size: 11px; font-weight: 700; }
.side-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.side-user-text b { font-size: 13.5px; font-weight: 600; color: var(--side-ink); }
.side-user-text small { font-size: 11.5px; color: var(--side-muted); }
.side-role::after { content: "дашборд"; }
body[data-role="owner"] .side-role::after { content: "владелец"; }
body[data-role="manager"] .side-role::after { content: "менеджер"; }

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px;
  min-height: 64px; padding: 12px 24px; background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4); border-bottom: 1px solid var(--border);
}
.topbar-row { display: contents; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; color: var(--ink); text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11.5px; font-weight: 700; letter-spacing: .02em; flex: none; }
.brand-sub { font-weight: 500; font-size: 13px; color: var(--muted); }
.topbar .brand { display: none; order: 1; }
.nav-toggle { order: 0; }
.filters { order: 2; flex: 0 1 auto; min-width: 0; }
.top-actions { order: 3; margin-left: auto; display: flex; gap: 2px; align-items: center; }
.sections { display: flex; gap: 4px; overflow-x: auto; }
.sections a { color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: var(--radius-md); white-space: nowrap; }
.sections a:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn {
  position: relative; display: inline-grid; place-items: center; min-width: 34px; height: 34px; padding: 0 6px;
  border: 1px solid transparent; background: transparent; color: var(--ink-2); border-radius: var(--radius-md); cursor: pointer; font-size: 18px; line-height: 1;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.top-actions .icon-btn svg { width: 17px; height: 17px; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* значки темы: луна в светлой, солнце в тёмной */
#theme .i-sun { display: none; }
:root[data-theme="dark"] #theme .i-sun { display: block; }
:root[data-theme="dark"] #theme .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme .i-sun { display: block; }
  :root:not([data-theme="light"]) #theme .i-moon { display: none; }
}
.nav-toggle .i-close { display: none; }
body.nav-open .nav-toggle .i-open { display: none; }
body.nav-open .nav-toggle .i-close { display: block; }
.top-sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.period-label { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.seg { display: inline-flex; border: 0; border-radius: 10px; background: var(--surface-2); padding: 3px; flex-wrap: wrap; gap: 2px; }
.seg button { border: 1px solid transparent; background: none; padding: 4px 9px; border-radius: 7px; cursor: pointer; color: var(--ink-2); white-space: nowrap; font-size: 13.5px; font-weight: 500; transition: background .15s, color .15s; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(16, 24, 32, .08), 0 1px 3px rgba(16, 24, 32, .06); }
:root[data-theme="dark"] .seg button.on { background: #2c2c2c; border-color: #383838; box-shadow: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .seg button.on { background: #2c2c2c; border-color: #383838; box-shadow: none; } }
.seg.small button { padding: 3px 9px; font-size: 13px; }
.custom-range { display: flex; align-items: center; gap: 6px; }
.custom-range input, .search, .form-grid input, .form-grid select, .form-grid textarea, .status-list input, .status-list select, .login-card input {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); border-radius: var(--radius-md); padding: 6px 11px; min-height: 36px;
  box-shadow: 0 1px 2px rgba(16, 24, 32, .04); transition: border-color .15s, box-shadow .15s;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); border-radius: var(--radius-md); padding: 6px 14px; min-height: 36px;
  cursor: pointer; white-space: nowrap; font-size: 14px; font-weight: 500; text-decoration: none; box-shadow: 0 1px 2px rgba(16, 24, 32, .05); transition: background .15s, border-color .15s, filter .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 90%, var(--ink)); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 8%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 2px 4px; font-size: 13px; font-weight: 500; border-radius: 6px; }
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

.nav-toggle { display: none; }
.page[hidden] { display: none !important; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h2 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.025em; line-height: 1.2; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
/* вкладки раздела — сегментная полоса, как TabsList в Apex */
.tabs { display: flex; width: fit-content; max-width: 100%; gap: 2px; flex-wrap: wrap; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 20px; }
.tab { padding: 5px 14px; color: var(--ink-2); text-decoration: none; border: 1px solid transparent; border-radius: 7px; white-space: nowrap; font-size: 13.5px; font-weight: 500; transition: background .15s, color .15s; }
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); background: var(--surface); box-shadow: 0 1px 2px rgba(16, 24, 32, .08), 0 1px 3px rgba(16, 24, 32, .06); }
:root[data-theme="dark"] .tab.on { background: #2c2c2c; border-color: #383838; box-shadow: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tab.on { background: #2c2c2c; border-color: #383838; box-shadow: none; } }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.crumbs button { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; font-weight: 500; }
.crumbs .cur { color: var(--ink); font-weight: 600; }
/* бейджи статусов: мягкая заливка, скругление 6px */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; line-height: 1.5; padding: 1px 8px; border-radius: 6px; border: 1px solid transparent; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.good { color: color-mix(in srgb, var(--good) 82%, var(--ink)); background: color-mix(in srgb, var(--good) 12%, var(--surface)); }
.pill.bad { color: color-mix(in srgb, var(--bad) 85%, var(--ink)); background: color-mix(in srgb, var(--bad) 11%, var(--surface)); }
.pill.warn { color: color-mix(in srgb, var(--warn) 50%, var(--ink)); background: color-mix(in srgb, var(--warn) 16%, var(--surface)); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink); }
.field input, .field select, .field textarea, .input {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); border-radius: var(--radius-md); padding: 6px 11px; min-height: 36px; font: inherit; font-weight: 400;
  box-shadow: 0 1px 2px rgba(16, 24, 32, .04); transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; }
::placeholder { color: var(--muted); opacity: 1; }
.split { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 16px; align-items: start; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--grid); }
.list-row { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 10px; cursor: pointer; border-radius: var(--radius-md); color: inherit; font: inherit; transition: background .15s; }
.list-row:hover { background: var(--surface-2); }
.list-row.on { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
/* таблицы: шапка мелким серым, строки с тонкой линией и подсветкой при наведении */
table.data-grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-grid th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; }
table.data-grid th.sortable { cursor: pointer; }
table.data-grid th.sortable:hover { color: var(--ink); }
table.data-grid th.sorted { color: var(--ink); }
table.data-grid th.sorted::after { content: " ↓"; color: var(--accent); }
table.data-grid th.sorted.asc::after { content: " ↑"; }
table.data-grid td { padding: 10px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.data-grid tbody tr:last-child td { border-bottom: 0; }
table.data-grid tbody tr { transition: background .12s; }
table.data-grid tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
table.data-grid .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data-grid tr.clickable { cursor: pointer; }
table.data-grid tr.clickable:hover { background: var(--surface-2); }
table.data-grid tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
table.data-grid.compact td, table.data-grid.compact th { padding: 6px 10px; }
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 200; background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); transition: opacity .4s, transform .4s; max-width: 380px; font-weight: 500;
}
.toast.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
:root[data-theme="dark"] .toast.bad { background: #b91c1c; border-color: #b91c1c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast.bad { background: #b91c1c; border-color: #b91c1c; } }
.toast.out { opacity: 0; transform: translateY(8px); }
.role-owner-only { display: none; }
body[data-role="owner"] .role-owner-only { display: revert; }

/* ---------- раскладка ---------- */
main { padding: 24px 24px 64px; max-width: 1600px; width: 100%; margin: 0 auto; min-width: 0; flex: 1; }
.section { margin-bottom: 36px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid .wide { grid-column: 1 / -1; }
.stack { display: grid; gap: 16px; align-content: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); min-width: 0; transition: opacity .2s, box-shadow .2s; }
.card.loading, .kpis.loading { opacity: .5; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { font-size: 16px; font-weight: 600; }
.card-tools { display: flex; align-items: center; gap: 8px; }
.note { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.error-text { color: var(--bad); font-size: 13px; margin: 8px 0 0; min-height: 1em; }
.block-error { color: var(--bad); padding: 24px 4px; font-size: 13.5px; }
.empty { color: var(--muted); padding: 28px 4px; text-align: center; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 16px; transition: opacity .2s; }
.kpis.six { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; transition: box-shadow .2s, border-color .2s; }
.kpi:hover { box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--accent) 22%, var(--border)); }
.kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 7px; }
.kpi-label .key { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.03em; margin-top: 6px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.kpi-delta.up { color: var(--good); font-weight: 500; }
.kpi-delta.down { color: var(--bad); font-weight: 500; }

/* ---------- графики ---------- */
.chart { position: relative; height: 260px; }
.chart.short { height: 200px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart svg:focus { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .seg-rect { stroke: var(--surface); stroke-width: 2; }
/* Как в Apex: подсветка полосы под курсором у столбцов и плавное появление графиков. */
.chart .bar-cursor { fill: var(--surface-2); opacity: .7; pointer-events: none; }
.chart .mt-line-in { animation: mt-draw .8s cubic-bezier(.33, 1, .68, 1) forwards; }
.chart .mt-area-in { animation: mt-fade .7s ease-out .15s both; }
.chart .mt-bar-in { animation: mt-grow .55s cubic-bezier(.33, 1, .68, 1) both; transform-box: view-box; }
@keyframes mt-draw { to { stroke-dashoffset: 0; } }
@keyframes mt-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mt-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@media (prefers-reduced-motion: reduce) {
  .chart .mt-line-in, .chart .mt-area-in, .chart .mt-bar-in { animation: none; stroke-dashoffset: 0; }
}
.chart .bar-hit { fill: transparent; cursor: default; }
.chart .bar-hit:hover + g, .chart g.hl { filter: brightness(1.08); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: -4px 0 10px; font-size: 13px; color: var(--ink-2); }
.legend button { display: inline-flex; align-items: center; gap: 7px; border: 0; background: none; padding: 2px 0; cursor: pointer; color: inherit; border-radius: 4px; }
.legend button.off { opacity: .4; }
.legend .key { width: 9px; height: 9px; border-radius: 50%; }
.legend .key.line { height: 3px; width: 14px; border-radius: 2px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 7px 10px; border-bottom: 1px solid var(--grid); text-align: right; }
.data-table th { color: var(--muted); font-weight: 500; font-size: 12.5px; border-bottom-color: var(--border); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.chart.as-table { height: auto; max-height: 320px; overflow: auto; }

.tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow-lg);
  font-size: 13px; min-width: 150px; max-width: 300px;
}
.tip-title { color: var(--muted); font-size: 12px; font-weight: 500; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tip-row .k { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.tip-row .v { font-weight: 650; font-variant-numeric: tabular-nums; }
.tip-row .n { color: var(--ink-2); }
.tip-dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; }
.tip-dl dt { color: var(--ink-2); }
.tip-dl dd { margin: 0; font-weight: 600; }
.tip-name { font-weight: 650; margin-bottom: 6px; display: flex; align-items: center; gap: 7px; }
.tip-name .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ---------- лента заявок ---------- */
.feed { list-style: none; margin: 0; padding: 0; max-height: 640px; overflow-y: auto; }
.feed li { border-bottom: 1px solid var(--grid); }
.feed li:last-child { border-bottom: 0; }
.feed-row { display: grid; grid-template-columns: 58px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left; border: 0; background: none; padding: 10px 6px; cursor: pointer; border-radius: var(--radius-md); transition: background .12s; }
.feed-row:hover { background: var(--surface-2); }
.badge { display: inline-flex; justify-content: center; align-items: center; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 6px; border: 1px solid transparent; color: var(--ink-2); background: var(--surface-2); }
.badge.site::before, .badge.mail::before { content: ""; width: 6px; height: 6px; border-radius: 50%; margin: 0 5px 0 0; flex: none; }
.badge.site::before { background: var(--s1); }
.badge.mail::before { background: var(--s2); }
.feed-main { min-width: 0; display: block; }
.feed-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.feed-title .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.feed-sub { display: block; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-time { color: var(--muted); font-size: 12px; white-space: nowrap; text-align: right; }
.feed-detail { padding: 0 6px 12px 76px; font-size: 13px; color: var(--ink-2); }
.feed-detail dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0 0 6px; }
.feed-detail dt { color: var(--muted); }
.feed-detail dd { margin: 0; color: var(--ink); white-space: pre-wrap; word-break: break-word; }
.feed.compact { max-height: 380px; }
.feed.compact .feed-row { grid-template-columns: 52px 1fr auto; padding: 8px 6px; }
.bell-wrap { position: relative; }
.bell-count { position: absolute; top: -3px; right: -3px; min-width: 17px; height: 17px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 10.5px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; box-shadow: 0 0 0 2px var(--page); }
.bell-panel { position: absolute; right: 0; top: 44px; width: min(420px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 0; z-index: 40; overflow: hidden; }
.bell-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.bell-panel .feed { padding: 4px 8px; }
.bell-all { display: block; text-align: center; padding: 10px 0; text-decoration: none; font-size: 13px; font-weight: 500; border-top: 1px solid var(--border); }
.bell-all:hover { background: var(--surface-2); }

/* ---------- заказы ---------- */
.status-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.sum-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.sum-card .t { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.sum-card .v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.sum-card .s { color: var(--muted); font-size: 12.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 11px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink-2); transition: background .15s, border-color .15s, color .15s; }
.chip:hover { background: var(--surface-2); color: var(--ink); }
.chip .c { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip.on { background: var(--accent-soft); color: color-mix(in srgb, var(--accent) 80%, var(--ink)); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.chip.on .c { color: inherit; }
.search { width: 240px; }
.table-wrap { overflow-x: auto; }
table.orders { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.orders th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; }
table.orders th:not([data-sort]) { cursor: default; }
table.orders th.sorted { color: var(--ink); }
table.orders th.sorted::after { content: " ↓"; color: var(--accent); }
table.orders th.sorted.asc::after { content: " ↑"; }
table.orders td { padding: 11px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.orders tbody tr:last-child td { border-bottom: 0; }
table.orders tbody tr { cursor: pointer; transition: background .12s; }
table.orders tbody tr:hover { background: var(--surface-2); }
table.orders .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
table.orders .date { white-space: nowrap; font-variant-numeric: tabular-nums; }
.client-cell { display: flex; align-items: center; gap: 9px; min-width: 200px; font-weight: 500; }
.client-cell .sw { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.client-cell .src { white-space: nowrap; font-size: 11px; font-weight: 500; color: var(--muted); background: var(--surface-2); border-radius: 5px; padding: 0 6px; }
.status-select { border: 1px solid var(--border); background: var(--surface); color: var(--ink); border-radius: var(--radius-md); padding: 4px 8px; font-size: 13px; max-width: 190px; }

/* ---------- календарь ---------- */
.cal-title { min-width: 150px; text-align: center; font-size: 15px; font-weight: 600; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--ink-2); margin-bottom: 14px; align-items: center; }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.mark { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 2px solid var(--ink-2); }
.mark.launch { background: var(--ink-2); }
.mark.due { background: transparent; border-style: dashed; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.cal-dow { font-size: 12px; font-weight: 500; color: var(--muted); padding: 8px; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.cal-dow:nth-child(7n) { border-right: 0; }
.cal-day { min-height: 104px; padding: 4px 5px 6px; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day.other { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.cal-day.other .cal-num { color: var(--muted); }
.cal-day.weekend .cal-num { color: var(--bad); }
.cal-num { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--ink-2); align-self: flex-end; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .cal-num { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.ev {
  display: flex; align-items: center; gap: 5px; border-radius: 6px; padding: 2px 6px 2px 5px; font-size: 12px; line-height: 1.35;
  cursor: pointer; border: 1.5px solid var(--c); background: color-mix(in srgb, var(--c) 18%, var(--surface)); color: var(--ink);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; width: 100%; text-align: left;
}
.ev.due { border-style: dashed; background: var(--surface); }
.ev:hover, .ev:focus-visible { background: color-mix(in srgb, var(--c) 34%, var(--surface)); outline: none; }
.ev .ic { font-size: 10px; flex: none; color: var(--ink-2); }
.ev .nm { overflow: hidden; text-overflow: ellipsis; }
.cal-orders { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.cal-orders span { display: inline-flex; align-items: center; gap: 6px; }
.cal-orders .sw { width: 10px; height: 10px; border-radius: 50%; }
.cal-more { font-size: 11.5px; color: var(--muted); padding-left: 4px; }

/* ---------- диалоги ---------- */
.dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; background: var(--surface); color: var(--ink); width: min(620px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
.dialog[open] { animation: dlg-in .18s ease-out; }
@keyframes dlg-in { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }
.dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dialog h3 { font-size: 18px; font-weight: 600; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid textarea { resize: vertical; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; min-height: 36px; align-items: center; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; outline-offset: 2px; }
.swatches button.on { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--surface); }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 20px; }
.dialog-actions .spacer { flex: 1; }
.status-list { margin: 10px 0; padding-left: 22px; display: grid; gap: 6px; }
.status-list li { display: grid; grid-template-columns: 1fr 150px auto auto auto; gap: 6px; align-items: center; }
.status-list .icon-btn { min-width: 30px; height: 30px; font-size: 14px; border-color: var(--border); }
.hint { margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.hint summary { cursor: pointer; color: var(--accent); font-weight: 500; }

/* ---------- вход ---------- */
.login { position: fixed; inset: 0; z-index: 100; background: var(--page); display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; display: grid; gap: 10px; box-shadow: var(--shadow-md); }
.login-card .brand { margin-bottom: 10px; font-size: 17px; }
.login-card label { font-size: 13px; font-weight: 500; color: var(--ink); }

/* ---------- адаптив ---------- */
@media (max-width: 1420px) {
  .filters { order: 4; flex-basis: 100%; }
}
@media (max-width: 1000px) {
  .grid.two { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .shell { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-grid; }
  .topbar .brand { display: flex; }
  .topbar { padding: 10px 16px; }
  .side { position: fixed; z-index: 60; left: 0; top: 0; bottom: 0; height: auto; width: 264px; box-shadow: 0 0 60px rgba(0, 0, 0, .45); transform: translateX(-105%); transition: transform .22s ease; visibility: hidden; }
  body.nav-open .side { transform: none; visibility: visible; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .5); pointer-events: none; }
  body.nav-open .nav-toggle { position: fixed; z-index: 70; top: 15px; left: 274px; background: var(--surface); border-color: var(--border); color: var(--ink); }
}
@media (max-width: 640px) {
  .topbar { position: static; }
  .status-summary { grid-template-columns: 1fr 1fr; gap: 10px; }
  .sum-card { padding: 12px 14px; }
  .sum-card .v { font-size: 18px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpis.six { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 12px 14px; }
  .kpi-label, .kpi-delta { font-size: 12px; }
  main { padding: 18px 16px 48px; }
  .card { padding: 16px; }
  .brand-sub { display: none; }
  .kpi-value { font-size: 22px; }
  .page-head h2 { font-size: 22px; }
  .chart { height: 220px; }
  .cal-day { min-height: 64px; padding: 2px; }
  .ev .nm { display: none; }
  .ev { justify-content: center; padding: 2px; }
  .form-grid { grid-template-columns: 1fr; }
  .search { width: 100%; }
  .status-list li { grid-template-columns: 1fr; }
  .dialog { padding: 18px; }
  .tabs { width: 100%; }
  html { scroll-padding-top: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .icon-btn.spin svg { animation: none; }
  .side, .dialog[open] { transition: none; animation: none; }
}
