/* ============================================================================
   Склад — дизайн-система
   Две темы: тёмная «Night Ops» (по умолчанию) и светлая «Ink & Paper».
   Токены заданы на :root, светлая тема переопределяет их в [data-theme="light"].
   ========================================================================== */

/* ── Токены: тёмная тема ──────────────────────────────────────────────────── */
:root,
[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #07090d;
  --bg-soft:       #0b0f14;
  --surface:       #111821;
  --surface-2:     #16202b;
  --surface-3:     #1c2836;
  --line:          #1e2a37;
  --line-strong:   #2b3a4b;

  --text:          #e9f0f7;
  --text-dim:      #9dabbb;
  --text-mute:     #6a7a8d;

  --accent:        #b6f24a;
  --accent-ink:    #0a1005;
  --accent-soft:   rgba(182, 242, 74, .12);
  --accent-line:   rgba(182, 242, 74, .35);
  --info:          #5da9ff;
  --info-soft:     rgba(93, 169, 255, .13);
  --ok:            #3ddc97;
  --ok-soft:       rgba(61, 220, 151, .13);
  --warn:          #ffc65c;
  --warn-soft:     rgba(255, 198, 92, .13);
  --danger:        #ff6b6b;
  --danger-soft:   rgba(255, 107, 107, .13);

  --shadow-sm:  0 1px 2px rgba(0, 0, 0, .35);
  --shadow:     0 12px 32px rgba(0, 0, 0, .45);
  --shadow-lg:  0 24px 64px rgba(0, 0, 0, .55);

  --glow-1: radial-gradient(900px 420px at 12% -10%, rgba(182, 242, 74, .10), transparent 70%);
  --glow-2: radial-gradient(760px 380px at 100% 0%, rgba(93, 169, 255, .09), transparent 65%);

  --paper-bg:   #ffffff;
  --paper-ink:  #14181d;
  --grid-line:  rgba(255, 255, 255, .035);
}

/* ── Токены: светлая тема ─────────────────────────────────────────────────── */
[data-theme="light"] {
  color-scheme: light;

  --bg:            #f4efe4;
  --bg-soft:       #efe8da;
  --surface:       #fffdf7;
  --surface-2:     #f8f2e6;
  --surface-3:     #f1e9d9;
  --line:          #e4dac6;
  --line-strong:   #d2c5aa;

  --text:          #191611;
  --text-dim:      #57503f;
  --text-mute:     #8a806a;

  --accent:        #c2410c;
  --accent-ink:    #fffdf7;
  --accent-soft:   rgba(194, 65, 12, .10);
  --accent-line:   rgba(194, 65, 12, .32);
  --info:          #1d4ed8;
  --info-soft:     rgba(29, 78, 216, .10);
  --ok:            #15803d;
  --ok-soft:       rgba(21, 128, 61, .11);
  --warn:          #b45309;
  --warn-soft:     rgba(180, 83, 9, .12);
  --danger:        #b91c1c;
  --danger-soft:   rgba(185, 28, 28, .10);

  --shadow-sm:  0 1px 2px rgba(80, 62, 30, .10);
  --shadow:     0 12px 30px rgba(80, 62, 30, .13);
  --shadow-lg:  0 24px 60px rgba(80, 62, 30, .18);

  --glow-1: radial-gradient(900px 420px at 12% -10%, rgba(194, 65, 12, .10), transparent 70%);
  --glow-2: radial-gradient(760px 380px at 100% 0%, rgba(29, 78, 216, .06), transparent 65%);

  --paper-bg:   #fffefb;
  --paper-ink:  #14181d;
  --grid-line:  rgba(0, 0, 0, .03);
}

/* ── Общие размеры ────────────────────────────────────────────────────────── */
:root {
  --font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, monospace;

  --sidebar-w: 252px;
  --topbar-h:  58px;
  --content-max: none;   /* тянемся на всю ширину экрана */

  --r-xs: 6px;
  --r-sm: 9px;
  --r:    12px;
  --r-lg: 16px;
  --r-xl: 22px;

  --dur: 140ms;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

/* ── База ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--glow-1), var(--glow-2);
  background-repeat: no-repeat;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; transition: color var(--dur) var(--ease); }
a:hover { color: var(--accent); filter: brightness(1.15); }

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; letter-spacing: -.012em; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; opacity: 1; }

::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* Скроллбары */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-mute); background-clip: content-box; }

/* ── Связка с Bootstrap ───────────────────────────────────────────────────── */
[data-theme] {
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-body-font-family: var(--font-sans);
  --bs-border-color: var(--line);
  --bs-border-color-translucent: var(--line);
  --bs-secondary-color: var(--text-dim);
  --bs-secondary-bg: var(--surface-2);
  --bs-tertiary-bg: var(--surface-3);
  --bs-emphasis-color: var(--text);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent);
  --bs-primary: var(--accent);
  --bs-heading-color: var(--text);
  --bs-border-radius: var(--r-sm);
  --bs-border-radius-lg: var(--r);
  --bs-border-radius-sm: var(--r-xs);
}

/* ── Каркас ───────────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* Сайдбар */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 12px 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
.brand:hover { color: var(--text); }
.brand-logo { width: 34px; height: 34px; flex: 0 0 34px; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -.01em; line-height: 1.15; }
.brand-tagline {
  font-size: 10.5px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: .09em;
  line-height: 1.4;
}

.sidebar-scroll { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }

.nav-group { margin-bottom: 14px; }
.nav-group:last-child { margin-bottom: 0; }
.nav-group-label {
  padding: 6px 10px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--text-dim);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item + .nav-item { margin-top: 1px; }
.nav-item i { font-size: 15px; width: 17px; text-align: center; flex: 0 0 17px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 500;
}
.nav-item.is-active i { color: var(--accent); }
.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-line);
}
.nav-item.sub { padding-left: 32px; font-size: 12.5px; }
.nav-item .nav-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-mute);
  background: var(--surface-3);
  padding: 1px 6px;
  border-radius: 99px;
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  color: var(--text);
  border: 0;
  background: transparent;
  text-align: left;
}
.user-chip:hover { background: var(--surface-2); color: var(--text); }
.user-avatar {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}
.user-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 10.5px; color: var(--text-mute); }

/* Основная колонка */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}

.crumbs { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-mute); min-width: 0; }
.crumbs a { color: var(--text-dim); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: .5; }
.crumbs .current { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-spacer { flex: 1; }

.content {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 22px clamp(16px, 1.7vw, 40px) 56px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}
.page-head-text { min-width: 0; flex: 1; }
.page-title { font-size: 23px; font-weight: 650; letter-spacing: -.02em; }
.page-sub { margin-top: 3px; font-size: 13px; color: var(--text-dim); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.eyebrow {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-mute);
}

/* ── Типографика и утилиты ────────────────────────────────────────────────── */
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.dim  { color: var(--text-dim); }
.mute { color: var(--text-mute); }
.small { font-size: 12.5px; }
.xs { font-size: 11.5px; }
.strong { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line { display: flex; align-items: center; gap: 10px; }
.line-tight { display: flex; align-items: center; gap: 6px; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.pos  { color: var(--ok); }
.neg  { color: var(--danger); }

/* ── Кнопки ───────────────────────────────────────────────────────────────── */
.btn {
  --btn-bg: var(--surface-2);
  --btn-bg-hover: var(--surface-3);
  --btn-fg: var(--text);
  --btn-bd: var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--btn-bg-hover); color: var(--btn-fg); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled {
  opacity: .5;
  background: var(--btn-bg);
  border-color: var(--btn-bd);
  color: var(--btn-fg);
  cursor: not-allowed;
  transform: none;
}
.btn i { font-size: 14px; line-height: 1; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); border-color: var(--accent-line); }

.btn-primary {
  --btn-bg: var(--accent);
  --btn-bg-hover: color-mix(in srgb, var(--accent) 88%, #000);
  --btn-fg: var(--accent-ink);
  --btn-bd: transparent;
  font-weight: 600;
}
.btn-primary:hover { color: var(--accent-ink); }

.btn-ghost { --btn-bg: transparent; --btn-bg-hover: var(--surface-2); }
.btn-soft  { --btn-bg: var(--surface-2); --btn-bg-hover: var(--surface-3); }
.btn-danger { --btn-bg: var(--danger-soft); --btn-bg-hover: color-mix(in srgb, var(--danger) 24%, transparent); --btn-fg: var(--danger); --btn-bd: transparent; }
.btn-ok     { --btn-bg: var(--ok-soft); --btn-bg-hover: color-mix(in srgb, var(--ok) 24%, transparent); --btn-fg: var(--ok); --btn-bd: transparent; }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: var(--r-xs); }
.btn-xs { height: 24px; padding: 0 8px; font-size: 11.5px; border-radius: var(--r-xs); }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14px; border-radius: var(--r); }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn-block { width: 100%; }

/* ── Карточки ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.card-title { font-size: 13.5px; font-weight: 600; }
.card-sub { font-size: 12px; color: var(--text-mute); }
.card-body { padding: 16px; }
.card-body.tight { padding: 10px 12px; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--line); }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); }
.span-2 { grid-column: span 2; }

/* Панель фильтров, которая остаётся на месте при прокрутке длинных списков */
.sticky-bar {
  position: sticky;
  top: calc(var(--topbar-h) + 10px);
  z-index: 15;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
}

/* KPI */
.kpi {
  position: relative;
  overflow: hidden;
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.kpi-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-mute);
}
.kpi-value {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -.03em;
  line-height: 1.1;
}
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--text-mute); margin-left: 3px; }
.kpi-foot { margin-top: 8px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-mute); }
.kpi-spark { position: absolute; right: 12px; bottom: 12px; opacity: .55; pointer-events: none; }
.kpi:has(.kpi-spark) .kpi-foot { padding-right: 74px; }
.kpi.is-accent { border-color: var(--accent-line); background: linear-gradient(160deg, var(--accent-soft), transparent 60%), var(--surface); }
.kpi.is-accent .kpi-value { color: var(--accent); }
.kpi.is-danger { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.kpi.is-danger .kpi-value { color: var(--danger); }

/* ── Таблицы ──────────────────────────────────────────────────────────────── */
.tbl-wrap { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); }
.tbl-wrap.flush { border: 0; border-radius: 0; background: transparent; }

.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.tbl thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-mute);
  text-align: left;
  white-space: nowrap;
}
.tbl tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background var(--dur) var(--ease); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.is-empty:hover { background: transparent; }
.tbl .num, .tbl th.num { text-align: right; }
.tbl .t-actions { width: 1%; white-space: nowrap; text-align: right; }
.tbl .t-actions .btn { opacity: 0; transition: opacity var(--dur) var(--ease); }
.tbl tbody tr:hover .t-actions .btn,
.tbl .t-actions .btn:focus-visible { opacity: 1; }
.tbl .t-main { font-weight: 500; color: var(--text); }
.tbl .t-sub { font-size: 11.5px; color: var(--text-mute); }
.tbl-compact tbody td { padding: 7px 12px; }

/* ── Чипы и бейджи ────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.6;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-dim);
  border: 1px solid transparent;
}
.chip i { font-size: 11px; }
.chip .dot { width: 6px; height: 6px; border-radius: 99px; background: currentColor; flex: 0 0 6px; }
.chip-ok     { background: var(--ok-soft);     color: var(--ok); }
.chip-warn   { background: var(--warn-soft);   color: var(--warn); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.chip-info   { background: var(--info-soft);   color: var(--info); }
.chip-accent { background: var(--accent-soft); color: var(--accent); }
.chip-mute   { background: var(--surface-3);   color: var(--text-mute); }
.chip-outline { background: transparent; border-color: var(--line-strong); color: var(--text-dim); }

.chip-btn { cursor: pointer; border: 1px solid transparent; transition: all var(--dur) var(--ease); }
.chip-btn:hover { border-color: var(--line-strong); color: var(--text); }
.chip-btn.is-on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding: 1px 7px;
}

/* ── Поля ввода ───────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label {
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--text-dim);
}
.field .hint, .hint { font-size: 11.5px; color: var(--text-mute); }

.input, .select, .textarea {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.textarea { height: auto; padding: 9px 11px; resize: vertical; min-height: 76px; }
.input::placeholder, .textarea::placeholder { color: var(--text-mute); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent-line);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input.mono, .num-input { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.input-sm { height: 30px; font-size: 12.5px; padding: 0 9px; }
.input-lg { height: 42px; font-size: 15px; }

.select {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%238a97a6' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 9px center;
}

.input-wrap { display: flex; align-items: stretch; width: 100%; }
.input-wrap .input { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.input-suffix {
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--surface-3);
  color: var(--text-mute);
  font-size: 12.5px;
  white-space: nowrap;
}

.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 36px;
  height: 20px;
  border-radius: 99px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
  flex: 0 0 36px;
}
.switch .track::after {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  margin: 2px;
  border-radius: 99px;
  background: var(--text-mute);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--accent-soft); border-color: var(--accent-line); }
.switch input:checked + .track::after { transform: translateX(16px); background: var(--accent); }

/* ── Пустые состояния ─────────────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 44px 20px;
  text-align: center;
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-mute);
  font-size: 22px;
  margin-bottom: 2px;
}
.empty-title { font-size: 14.5px; font-weight: 600; }
.empty-text { font-size: 12.5px; color: var(--text-mute); max-width: 44ch; }
.empty .btn { margin-top: 8px; }

/* ── Тосты ────────────────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast-msg {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in 240ms var(--ease);
}
.toast-msg i { color: var(--accent); font-size: 15px; margin-top: 1px; }
.toast-msg.is-danger { border-left-color: var(--danger); }
.toast-msg.is-danger i { color: var(--danger); }
.toast-msg.is-ok { border-left-color: var(--ok); }
.toast-msg.is-ok i { color: var(--ok); }
.toast-msg.is-out { opacity: 0; transform: translateY(6px); transition: all 200ms var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Модальные окна / дропдауны / оффканвас ───────────────────────────────── */
.modal-content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}
.modal-header, .modal-footer { border-color: var(--line); padding: 14px 18px; }
.modal-body { padding: 18px; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-backdrop.show { opacity: .62; }

.dropdown-menu {
  --bs-dropdown-bg: var(--surface);
  --bs-dropdown-link-color: var(--text-dim);
  --bs-dropdown-link-hover-bg: var(--surface-2);
  --bs-dropdown-link-hover-color: var(--text);
  --bs-dropdown-link-active-bg: var(--accent-soft);
  --bs-dropdown-link-active-color: var(--accent);
  --bs-dropdown-border-color: var(--line);
  --bs-dropdown-divider-bg: var(--line);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 5px;
  font-size: 13px;
}
.dropdown-item { border-radius: var(--r-xs); padding: 7px 10px; }
.dropdown-item.text-danger:hover { background: var(--danger-soft); color: var(--danger) !important; }

.offcanvas { background: var(--surface); color: var(--text); border-color: var(--line); }

/* ── Хлебные крошки, разделители, шапки блоков ────────────────────────────── */
.section { display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; align-items: center; gap: 10px; }
.section-title { font-size: 13.5px; font-weight: 600; letter-spacing: -.01em; }
.section-link { font-size: 12px; color: var(--text-mute); display: inline-flex; align-items: center; gap: 4px; }
.section-link:hover { color: var(--accent); }

.divider-dashed {
  height: 1px;
  background-image: linear-gradient(to right, var(--line-strong) 40%, transparent 0%);
  background-size: 7px 1px;
  background-repeat: repeat-x;
}

/* ── Спарклайн / столбики ─────────────────────────────────────────────────── */
.spark { display: block; overflow: visible; }
.spark .spark-line { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.spark .area { fill: var(--accent-soft); stroke: none; }

/* ── График цены (SVG из шаблона) ─────────────────────────────────────────── */
.chart { display: block; width: 100%; height: 170px; overflow: visible; }
.chart .price-area { fill: var(--accent-soft); stroke: none; }
.chart .price-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ref-line { stroke: var(--warn); stroke-width: 1.4; stroke-dasharray: 5 4; opacity: .8; }
.chart .price-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 84px; }
.bars .bar {
  flex: 1;
  min-width: 6px;
  border-radius: 4px 4px 2px 2px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 35%, transparent));
  position: relative;
  transition: filter var(--dur) var(--ease);
}
.bars .bar:hover { filter: brightness(1.2); }
.bars .bar.is-flat { background: var(--surface-3); }
.bar-labels { display: flex; gap: 6px; margin-top: 6px; }
.bar-labels span { flex: 1; text-align: center; font-size: 10.5px; color: var(--text-mute); }

/* ── Фото и плитки товаров ────────────────────────────────────────────────── */
.thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--r-sm);
  object-fit: cover;
  background: var(--surface-3);
  border: 1px solid var(--line);
  flex: 0 0 44px;
}
.thumb-empty {
  display: grid;
  place-items: center;
  color: var(--text-mute);
  font-size: 15px;
}
.thumb-lg { width: 96px; height: 96px; flex-basis: 96px; border-radius: var(--r); }
.thumb-hero {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface-3);
}

.tile {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  color: var(--text);
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.tile:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  color: var(--text);
}
.tile-media {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.tile-media img { width: 100%; height: 100%; object-fit: cover; }
.tile-media .placeholder-icon { font-size: 26px; color: var(--text-mute); opacity: .7; }
.tile-body { padding: 11px 13px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.tile-title { font-size: 13px; font-weight: 500; line-height: 1.32; }
.tile-meta { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-mute); }
.tile-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 4px; }
.tile-badge { position: absolute; top: 8px; left: 8px; z-index: 1; }
.tile-source { position: absolute; bottom: 8px; right: 8px; font-size: 15px; filter: drop-shadow(0 1px 3px rgba(0,0,0,.5)); }
.tile-actions { position: absolute; top: 8px; right: 8px; opacity: 0; transition: opacity var(--dur) var(--ease); }
.tile:hover .tile-actions { opacity: 1; }
.tile.is-negative { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }

/* Загрузка фото */
.photo-drop { display: block; cursor: pointer; }
.photo-drop:hover .thumb-hero { border-color: var(--accent-line); background: var(--accent-soft); }
.source-option { cursor: pointer; }
.source-option input:checked + .chip-btn {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

/* ── Бумага: превью чека ──────────────────────────────────────────────────── */
/* Разметку .stage/.roll/.ln/.dash присылает receipt_engine — оформляем её здесь. */
.stage {
  display: flex;
  flex-direction: column;
  width: auto !important;
  font-family: 'Courier New', ui-monospace, monospace;
  font-size: 15px;
}
.stage .stage-label {
  margin-bottom: 7px;
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--text-mute);
  text-align: center;
}
.stage .roll {
  width: max-content !important;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 3px;
  background: #fff !important;
  color: #14181d;
  font-size: 15px;
  line-height: 1.42;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .38);
}
.stage .ln, .stage .dash { white-space: pre; color: #14181d; }
.stage .dash { opacity: .7; }
.stage .qrrow img { background: #fff; }

.paper {
  background: var(--paper-bg);
  color: var(--paper-ink);
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(0,0,0,.08), 0 12px 28px rgba(0,0,0,.28);
  padding: 16px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  overflow-x: auto;
}
.paper .ln { white-space: pre; }
.paper .dash { white-space: pre; color: var(--paper-ink); opacity: .75; }
.paper .qrrow { text-align: center; margin: 4px 0; }
.paper .qrrow img { display: inline-block; }
.paper-frame {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
}

/* ── Прочее ───────────────────────────────────────────────────────────────── */
.skeleton {
  border-radius: var(--r-xs);
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  height: 12px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mobile-only { display: none; }

/* ── Печать ───────────────────────────────────────────────────────────────── */
@media print {
  body { background: #fff !important; color: #000 !important; background-image: none !important; }
  .sidebar, .topbar, .no-print, .toast-stack, .page-actions { display: none !important; }
  .app { display: block; }
  .content { padding: 0 !important; max-width: none; }
  .card, .tbl-wrap, .kpi { border-color: #ccc !important; box-shadow: none !important; background: #fff !important; }
  .paper, .paper-frame { box-shadow: none !important; border: 0 !important; background: #fff !important; }
  .no-print-only { display: none !important; }
}

/* ── Адаптив ──────────────────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 292px);
    transform: translateX(-102%);
    transition: transform 220ms var(--ease);
    box-shadow: var(--shadow-lg);
    z-index: 1045;
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 1040;
    backdrop-filter: blur(2px);
  }
  .mobile-only { display: inline-flex; }
  .content { padding: 16px 14px 48px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .crumbs { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: span 1; }
  .page-title { font-size: 20px; }
  .tbl tbody td, .tbl thead th { padding-left: 9px; padding-right: 9px; }
  /* На узком экране таблицы переносят текст, иначе колонки уезжают за край */
  .tbl { font-size: 12.5px; }
  .tbl thead th { white-space: normal; }
  .tbl tbody td { white-space: normal; }
  .tbl .num, .tbl .t-actions { white-space: nowrap; }
  .card-head { flex-wrap: wrap; }
  .bars { height: 96px; }
}

@media (max-width: 560px) {
  .kpi-value { font-size: 21px; }
  .page-head { align-items: flex-start; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .hide-xs { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── Экран входа ──────────────────────────────────────────────────────────── */
.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 384px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
}
.auth-logo { width: 52px; height: 52px; }
.auth-title { font-size: 20px; font-weight: 650; letter-spacing: -.02em; }
.auth-sub { font-size: 12.5px; color: var(--text-mute); margin-top: 2px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
}
.auth-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--text-mute);
}
.auth-theme { position: fixed; top: 16px; right: 16px; }

/* ── Двухколоночные раскладки ─────────────────────────────────────────────── */
.grid-split { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-split-even { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); }
@media (max-width: 1080px) {
  .grid-split, .grid-split-even { grid-template-columns: minmax(0, 1fr); }
}

/* Ссылки внутри таблиц не должны кричать акцентом в каждой строке */
.tbl tbody a { color: var(--text); font-weight: 500; }
.tbl tbody a:hover { color: var(--accent); }

/* Пустое состояние вместо графика */
.chart-empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  min-height: 128px;
  border-radius: var(--r-sm);
  border: 1px dashed var(--line-strong);
  color: var(--text-mute);
  font-size: 12.5px;
}
.chart-empty i { font-size: 22px; opacity: .55; }
