/* ============================================================
   CrazyDrift Stats — Design System
   Inspired by Toast/Square dashboards: ops-first, scannable, dense.
   ============================================================ */

:root {
  /* Accent — amber/orange (брендовый) */
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --accent-active: #b45309;
  --accent-soft: #fef3c7;
  --accent-text: #92400e;

  /* Semantic colors */
  --green: #16a34a;       --green-soft: #dcfce7;       --green-text: #14532d;
  --yellow: #eab308;      --yellow-soft: #fef9c3;      --yellow-text: #713f12;
  --red: #dc2626;         --red-soft: #fee2e2;         --red-text: #7f1d1d;
  --blue: #2563eb;        --blue-soft: #dbeafe;        --blue-text: #1e3a8a;
  --purple: #7c3aed;      --purple-soft: #ede9fe;      --purple-text: #4c1d95;

  /* Neutrals (light theme) */
  --bg: #f8fafc;                /* page bg */
  --surface: #ffffff;           /* cards */
  --surface-2: #f1f5f9;         /* subtle bg (inputs, hover) */
  --surface-elevated: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-on-accent: #ffffff;

  /* Typography */
  --font: 'Onest', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Spacing scale (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radius */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px 0 rgba(15, 23, 42, 0.05), 0 1px 2px -1px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);

  /* Transition */
  --t-fast: 120ms ease;
  --t: 180ms ease;
  --t-slow: 280ms ease;

  /* Layout */
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;
}

/* Dark theme override */
[data-theme="dark"] {
  --bg: #0a0a0e;
  --surface: #14141a;
  --surface-2: #1c1c24;
  --surface-elevated: #1c1c24;
  --border: #2a2a32;
  --border-strong: #3a3a44;
  --text: #f1f5f9;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent-soft: rgba(245, 158, 11, 0.15);
  --accent-text: #fbbf24;
  --green-soft: rgba(22, 163, 74, 0.15);
  --green-text: #4ade80;
  --yellow-soft: rgba(234, 179, 8, 0.15);
  --yellow-text: #facc15;
  --red-soft: rgba(220, 38, 38, 0.15);
  --red-text: #f87171;
  --blue-soft: rgba(37, 99, 235, 0.15);
  --blue-text: #60a5fa;
  --purple-soft: rgba(124, 58, 237, 0.15);
  --purple-text: #a78bfa;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.3);
  --shadow: 0 1px 3px 0 rgba(0,0,0,0.4), 0 1px 2px -1px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.5), 0 2px 4px -2px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.6), 0 4px 6px -4px rgba(0,0,0,0.4);
}

/* ============================================================
   Base reset & typography
   ============================================================ */
* { box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-4) 0; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   App shell (sidebar + main)
   ============================================================ */
.ds-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--t);
}
.ds-app.collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

.ds-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0;
  height: 100vh;
  /* FIX: убрали overflow-y: auto чтобы tooltip data-info-side="right"
     не клипился краем sidebar. Скролл (если нужен) делаем на .ds-nav. */
  overflow: visible;
  z-index: 10;
}
.ds-sidebar .ds-nav {
  flex: 1;
  min-height: 0;
  /* Без overflow — tooltip data-info-side="right" свободно выходит вправо.
     11 пунктов меню помещаются на любом экране ≥ 600px высоты. */
  overflow: visible;
}

/* FIX (audit 2026-05-30): защита от обрезания tooltip в sidebar.
   Поднимаем z-index выше main-content, ограничиваем max-width для длинных
   подсказок, чтобы не закрывать половину экрана. */
.ds-sidebar [data-info]:hover::after,
.ds-sidebar [data-info]:focus::after {
  z-index: 1100;
  max-width: 280px;
  min-width: 160px;
}

/* ============================================================
   Toast notifications (P1.1, audit 2026-05-30)
   Заменяет нативный alert() для UX-нотификаций.
   ============================================================ */
.cd-toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  z-index: 9999;
  pointer-events: none;
  max-width: calc(100vw - 40px);
}
.cd-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-dim);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  width: 360px;
  max-width: 100%;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity .2s ease-out, transform .2s ease-out;
}
.cd-toast--in {
  opacity: 1;
  transform: translateX(0);
}
.cd-toast--out {
  opacity: 0;
  transform: translateX(20px);
}
.cd-toast--success { border-left-color: var(--green, #16a34a); }
.cd-toast--info    { border-left-color: var(--accent, #3b82f6); }
.cd-toast--warning { border-left-color: var(--yellow, #eab308); }
.cd-toast--error   { border-left-color: var(--red, #dc2626); }

.cd-toast__icon {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  background: var(--surface-2);
}
.cd-toast--success .cd-toast__icon { background: rgba(22, 163, 74, .14); color: var(--green, #16a34a); }
.cd-toast--info    .cd-toast__icon { background: rgba(59, 130, 246, .14); color: var(--accent, #3b82f6); }
.cd-toast--warning .cd-toast__icon { background: rgba(234, 179, 8, .18); color: var(--yellow, #ca8a04); }
.cd-toast--error   .cd-toast__icon { background: rgba(220, 38, 38, .14); color: var(--red, #dc2626); }

.cd-toast__msg {
  flex: 1;
  word-break: break-word;
}
.cd-toast__close {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 4px;
  transition: var(--t-fast);
  font-family: inherit;
}
.cd-toast__close:hover {
  background: var(--surface-2);
  color: var(--text);
}

@media (max-width: 640px) {
  .cd-toast-stack { left: 20px; bottom: 20px; right: 20px; }
  .cd-toast { width: 100%; }
}

/* ============================================================
   Design polish (P3, audit 2026-05-30)
   • A1: tabular-nums — стабильная ширина чисел (KPI не «прыгают»)
   • A2: card hover micro-animation
   • A3: skeleton-loader (shimmer)
   • A4: badge pulse при изменении counter
   ============================================================ */

/* A1: Все числовые значения с одинаковой шириной цифр */
.ds-kpi__value,
.ds-kpi__delta,
.rc-cell-val,
.rc-cell-prev,
.cd-num,
[data-tabular] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* A2: Cards — лёгкий lift при hover. Стоимость = ноль, добавляет жизни. */
.card {
  transition: transform .15s ease-out, box-shadow .15s ease-out, border-color .15s ease-out;
}
.card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md, 0 4px 12px rgba(0,0,0,.08));
}
/* Исключения для карточек с встроенной интерактивностью внутри (модалки и т.п.) */
.card:has(.card__title:only-child) { transform: none; box-shadow: none; }

/* A3: Skeleton-loader (для KPI и других «—» состояний) */
@keyframes cd-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.cd-skeleton {
  display: inline-block;
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--border) 50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: cd-shimmer 1.5s linear infinite;
  border-radius: 4px;
  color: transparent;
  pointer-events: none;
  user-select: none;
  min-width: 60px;
  min-height: 1em;
}
.cd-skeleton--lg { min-height: 32px; min-width: 120px; }
.cd-skeleton--block { display: block; height: 1em; margin: 4px 0; }

/* A4: Badge pulse animation при появлении новых алертов */
@keyframes cd-badge-pulse {
  0%   { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, .6); }
  60%  { transform: scale(1.2); box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}
.ds-nav__badge {
  transition: transform .2s ease-out;
}
.ds-nav__badge.cd-pulse {
  animation: cd-badge-pulse 1s ease-out;
}

/* Уважение к prefers-reduced-motion (a11y) */
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover { transform: none; }
  .cd-skeleton { animation: none; }
  .ds-nav__badge.cd-pulse { animation: none; }
  .cd-toast { transition: opacity .1s; }
}

/* ============================================================
   Quick wins (audit 2026-05-30): полировка в стиле Эвотор
   ============================================================ */

/* Sparkline host рядом с KPI value */
.cd-spark { line-height: 0; }
.cd-spark svg { display: block; }

/* Top-N с горизонтальными прогресс-барами (заменяет flat-сетку аттракционов) */
.cd-topbar {
  display: grid;
  grid-template-columns: minmax(80px, 1.5fr) 3fr minmax(60px, auto);
  gap: 10px;
  align-items: center;
  padding: 6px 0;
  font-size: 13px;
}
.cd-topbar:not(:last-child) { border-bottom: 1px dashed var(--border); }
.cd-topbar__label {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-topbar__track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.cd-topbar__fill {
  height: 100%;
  border-radius: 4px;
  transition: width .3s ease-out;
  min-width: 4px;
}
.cd-topbar__value {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

/* Лента чеков (recent checks feed) */
.cd-check-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  font-size: 13px;
}
.cd-check-row:not(:last-child) { border-bottom: 1px solid var(--border); }
.cd-check-row__icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}
.cd-check-row__main { min-width: 0; }
.cd-check-row__name {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-check-row__time {
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}
.cd-check-row__amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

/* ============================================================
   Operations list (P3 webhook: finance + storage operations)
   ============================================================ */
.cd-op-row {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr minmax(90px, auto);
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background .12s ease-out;
}
.cd-op-row:last-child { border-bottom: 0; }
.cd-op-row:hover { background: var(--surface-2); }
.cd-op-row__type {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.cd-op-row__main { min-width: 0; }
.cd-op-row__amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.cd-op-row__meta {
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-op-row__badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  text-align: center;
}

.ds-select {
  background: var(--bg-input, var(--surface-2));
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  font-family: var(--font);
  cursor: pointer;
}
.ds-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.ds-sidebar__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
}
.ds-logo {
  font-weight: 800; font-size: 16px; letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.ds-logo__compact { display: none; font-size: 18px; }
.collapsed .ds-logo { display: none; }
.collapsed .ds-logo__compact { display: inline; }

.ds-sidebar__collapse {
  background: transparent; border: 0;
  color: var(--text-muted);
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--t);
  display: flex; align-items: center; justify-content: center;
}
.ds-sidebar__collapse:hover { background: var(--surface-2); color: var(--text); }
.collapsed .ds-sidebar__collapse { transform: rotate(180deg); }

.ds-nav {
  padding: var(--space-3);
  flex: 1;
  display: flex; flex-direction: column; gap: 2px;
}
.ds-nav__group {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: var(--space-4) var(--space-3) var(--space-2);
}
.collapsed .ds-nav__group { display: none; }

.ds-nav__link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-weight: 500; font-size: 13px;
  text-decoration: none;
  transition: var(--t-fast);
  position: relative;
}
.ds-nav__link:hover { background: var(--surface-2); color: var(--text); }
.ds-nav__link--active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}
.ds-nav__link svg { width: 18px; height: 18px; flex-shrink: 0; }
.ds-nav__link__label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.collapsed .ds-nav__link__label { display: none; }
.collapsed .ds-nav__link { justify-content: center; padding: var(--space-3); }

.ds-nav__badge {
  margin-left: auto;
  background: var(--red);
  color: white;
  font-size: 10px; font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  min-width: 18px; text-align: center;
}
.collapsed .ds-nav__badge {
  position: absolute; top: 4px; right: 4px; margin: 0;
}

.ds-sidebar__foot {
  padding: var(--space-3);
  border-top: 1px solid var(--border);
}
.ds-user-card {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
}
.ds-user-card__avatar {
  width: 32px; height: 32px; border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.ds-user-card__info { flex: 1; min-width: 0; }
.ds-user-card__name { font-weight: 600; font-size: 13px; }
.ds-user-card__role { font-size: 11px; color: var(--text-muted); }
.collapsed .ds-user-card__info { display: none; }
.collapsed .ds-user-card { justify-content: center; }

.ds-theme-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: var(--space-2);
  background: transparent; border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  border-radius: var(--radius);
  margin-top: var(--space-2);
  font-size: 12px;
  transition: var(--t-fast);
}
.ds-theme-toggle:hover { background: var(--surface-2); color: var(--text); }

.ds-logout {
  display: block; width: 100%;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius);
  margin-top: var(--space-2);
  font-size: 12px;
  transition: var(--t-fast);
}
.ds-logout:hover { background: var(--red-soft); color: var(--red); border-color: var(--red); }

.ds-main {
  min-width: 0;
  display: flex; flex-direction: column;
}

/* ============================================================
   Topbar
   ============================================================ */
.ds-topbar {
  height: var(--topbar-h);
  padding: 0 var(--space-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 9;
}
.ds-topbar__title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.ds-topbar__actions { display: flex; align-items: center; gap: var(--space-2); }
/* Кнопка «назад» в шапке (межстраничная навигация) */
.ds-back-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text-dim, var(--text));
  cursor: pointer; text-decoration: none; padding: 0;
  transition: background .15s, color .15s, border-color .15s;
}
.ds-back-btn:hover {
  background: var(--accent-soft, var(--surface-2));
  color: var(--accent, var(--text));
  border-color: var(--accent, var(--border));
}
.ds-back-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ds-pagecontent {
  flex: 1;
  padding: var(--space-6);
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ============================================================
   Page header
   ============================================================ */
.ds-page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.ds-page-head__title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.ds-page-head__sub { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }
.ds-page-head__actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

/* ============================================================
   Buttons
   ============================================================ */
.ds-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 36px;
  font-family: var(--font); font-weight: 600; font-size: 13px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: var(--t-fast);
  text-decoration: none;
  white-space: nowrap;
}
.ds-btn:hover { background: var(--border); }
.ds-btn:active { transform: translateY(1px); }
.ds-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.ds-btn--primary {
  background: var(--accent); color: var(--text-on-accent); border-color: var(--accent);
}
.ds-btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.ds-btn--ghost { background: transparent; }
.ds-btn--ghost:hover { background: var(--surface-2); }

.ds-btn--outline {
  background: transparent; border-color: var(--border-strong);
}
.ds-btn--outline:hover { background: var(--surface-2); }

.ds-btn--danger {
  background: var(--red); color: white; border-color: var(--red);
}
.ds-btn--danger:hover { background: #b91c1c; border-color: #b91c1c; }

.ds-btn--sm { height: 30px; padding: 0 var(--space-3); font-size: 12px; }
.ds-btn--lg { height: 44px; padding: 0 var(--space-5); font-size: 14px; }
.ds-btn--icon { width: 36px; padding: 0; }

/* ============================================================
   Inputs
   ============================================================ */
.ds-input, .ds-select {
  height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font); font-size: 13px;
  transition: var(--t-fast);
  width: 100%;
}
.ds-input:focus, .ds-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.ds-input::placeholder { color: var(--text-muted); }
.ds-select { cursor: pointer; appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}

.ds-field { display: flex; flex-direction: column; gap: var(--space-2); }
.ds-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); }

/* ============================================================
   Card
   ============================================================ */
.ds-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: var(--t);
}
.ds-card--interactive { cursor: pointer; }
.ds-card--interactive:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.ds-card__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: var(--space-4);
  gap: var(--space-3);
}
.ds-card__title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-secondary);
}
.ds-card__action { font-size: 12px; color: var(--text-muted); }

/* ============================================================
   KPI tile
   ============================================================ */
.ds-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
}
.ds-kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: var(--t);
  position: relative;
  overflow: hidden;
}
.ds-kpi:hover { box-shadow: var(--shadow-md); }
.ds-kpi__label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}
.ds-kpi__value {
  font-size: 28px; font-weight: 700; line-height: 1.1;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.ds-kpi__delta { font-size: 12px; color: var(--text-muted); margin-top: var(--space-2); display: flex; align-items: center; gap: 6px; }
.ds-kpi__delta--up { color: var(--green); }
.ds-kpi__delta--down { color: var(--red); }
.ds-kpi__spark { position: absolute; bottom: 0; right: 0; opacity: 0.4; height: 40px; }

/* ============================================================
   Pill (status badge)
   ============================================================ */
.ds-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px;
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.ds-pill__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ds-pill--success { background: var(--green-soft); color: var(--green-text); }
.ds-pill--warning { background: var(--yellow-soft); color: var(--yellow-text); }
.ds-pill--danger { background: var(--red-soft); color: var(--red-text); }
.ds-pill--info { background: var(--blue-soft); color: var(--blue-text); }
.ds-pill--accent { background: var(--accent-soft); color: var(--accent-text); }

/* ============================================================
   Table
   ============================================================ */
.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.ds-table thead th {
  text-align: left; padding: var(--space-2) var(--space-3);
  font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.ds-table tbody td {
  padding: var(--space-3); border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.ds-table tbody tr:hover { background: var(--surface-2); }
.ds-table tbody tr:last-child td { border-bottom: 0; }
.ds-table .num, .ds-table th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 12px; }
.ds-table--compact tbody td { padding: var(--space-2) var(--space-3); }

/* ============================================================
   Alert banner
   ============================================================ */
.ds-alert {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: var(--space-4);
}
.ds-alert--success { background: var(--green-soft); border-color: rgba(22,163,74,0.3); color: var(--green-text); }
.ds-alert--warning { background: var(--yellow-soft); border-color: rgba(234,179,8,0.3); color: var(--yellow-text); }
.ds-alert--danger  { background: var(--red-soft); border-color: rgba(220,38,38,0.3); color: var(--red-text); }
.ds-alert--info    { background: var(--blue-soft); border-color: rgba(37,99,235,0.3); color: var(--blue-text); }
.ds-alert__icon { font-size: 18px; line-height: 1; flex-shrink: 0; }
.ds-alert__body { flex: 1; min-width: 0; }
.ds-alert__title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.ds-alert__msg { font-size: 13px; }

/* ============================================================
   Sections / grids
   ============================================================ */
.ds-section { margin-bottom: var(--space-8); }
.ds-section__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-4);
  gap: var(--space-3);
}
.ds-section__title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.ds-section__sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.ds-grid { display: grid; gap: var(--space-4); }
.ds-grid--2 { grid-template-columns: repeat(2, 1fr); }
.ds-grid--3 { grid-template-columns: repeat(3, 1fr); }
.ds-grid--4 { grid-template-columns: repeat(4, 1fr); }
.ds-grid--auto { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
@media (max-width: 900px) {
  .ds-grid--2, .ds-grid--3, .ds-grid--4 { grid-template-columns: 1fr; }
}

/* ============================================================
   Branch card (для dashboard)
   ============================================================ */
.ds-branch-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  transition: var(--t);
  cursor: pointer;
  display: flex; flex-direction: column;
  position: relative;
}
.ds-branch-card:hover {
  border-color: var(--border-strong); box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.ds-branch-card__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: var(--space-3);
  gap: var(--space-2);
}
.ds-branch-card__title {
  font-size: 14px; font-weight: 700; margin: 0;
  text-decoration: none; color: var(--text);
}
.ds-branch-card__city { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.ds-branch-card__metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.ds-branch-card__metric-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.ds-branch-card__metric-value { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* Health indicator strip */
.ds-branch-card__health {
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px; border-top-left-radius: var(--radius-lg); border-top-right-radius: var(--radius-lg);
}
.ds-branch-card--good .ds-branch-card__health { background: var(--green); }
.ds-branch-card--warn .ds-branch-card__health { background: var(--yellow); }
.ds-branch-card--bad .ds-branch-card__health { background: var(--red); }
.ds-branch-card--neutral .ds-branch-card__health { background: var(--border); }

/* ============================================================
   Empty state
   ============================================================ */
.ds-empty {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-muted);
}
.ds-empty__icon { font-size: 40px; margin-bottom: var(--space-3); opacity: 0.5; }
.ds-empty__title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: var(--space-2); }
.ds-empty__msg { font-size: 13px; color: var(--text-muted); }

/* ============================================================
   Loading / skeleton
   ============================================================ */
.ds-skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: ds-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius);
}
@keyframes ds-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.ds-loading-spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ds-spin 0.7s linear infinite;
}
@keyframes ds-spin { to { transform: rotate(360deg); } }

/* ============================================================
   Tabs
   ============================================================ */
.ds-tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
}
.ds-tab {
  padding: var(--space-3) var(--space-4);
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: var(--t-fast);
  margin-bottom: -1px;
}
.ds-tab:hover { color: var(--text); }
.ds-tab--active {
  color: var(--accent); border-bottom-color: var(--accent); font-weight: 600;
}

/* ============================================================
   Utility helpers
   ============================================================ */
.ds-flex { display: flex; }
.ds-flex--center { align-items: center; }
.ds-flex--between { justify-content: space-between; }
.ds-flex--col { flex-direction: column; }
.ds-gap-1 { gap: var(--space-1); }
.ds-gap-2 { gap: var(--space-2); }
.ds-gap-3 { gap: var(--space-3); }
.ds-gap-4 { gap: var(--space-4); }
.ds-mb-1 { margin-bottom: var(--space-1); } .ds-mb-2 { margin-bottom: var(--space-2); }
.ds-mb-3 { margin-bottom: var(--space-3); } .ds-mb-4 { margin-bottom: var(--space-4); }
.ds-mb-6 { margin-bottom: var(--space-6); } .ds-mb-8 { margin-bottom: var(--space-8); }
.ds-text-muted { color: var(--text-muted); }
.ds-text-secondary { color: var(--text-secondary); }
.ds-text-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.ds-text-xs { font-size: 11px; } .ds-text-sm { font-size: 12px; }
.ds-text-lg { font-size: 16px; } .ds-text-xl { font-size: 20px; }
.ds-fw-600 { font-weight: 600; } .ds-fw-700 { font-weight: 700; }
.ds-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============================================================
   Info-tooltip (объяснения терминов)
   ============================================================ */
.ds-info {
  display: inline-flex;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 10px; line-height: 1;
  align-items: center; justify-content: center;
  cursor: help;
  position: relative;
  font-weight: 700;
  border: 1px solid var(--border);
  margin-left: 5px;
  vertical-align: middle;
  font-family: var(--font);
  transition: var(--t-fast);
  flex-shrink: 0;
}
.ds-info::before { content: "?"; }
.ds-info:hover {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}
/* Универсальный hover-tooltip — срабатывает на ЛЮБОМ элементе с data-info.
   Раньше работало только на .ds-info[data-info]; теперь подхватываются и
   .ds-pill[data-info], <a data-info=...>, <button data-info=...>, и т.п.
   Это позволяет заменить нативный title="..." на data-info="..." и получить
   единый красивый стиль на всей платформе. */
[data-info] {
  position: relative;
}
[data-info]:hover::after,
[data-info]:focus::after,
[data-info]:focus-within::after {
  content: attr(data-info);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(calc(-50% + var(--info-shift, 0px)));
  background: var(--text);
  color: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 400;
  white-space: normal;
  /* P3 audit 2026-06-01: ширина адаптирована под viewport, без min-width
     чтобы короткие тултипы не растягивались на 200px и не клипались на
     узких колонках. */
  width: max-content;
  max-width: min(320px, calc(100vw - 32px));
  text-align: left;
  pointer-events: none;
  z-index: 10000;
  box-shadow: var(--shadow-lg);
  line-height: 1.5;
  letter-spacing: 0;
  text-transform: none;
}
[data-info-side="right"]:hover::after,
[data-info-side="right"]:focus::after {
  bottom: 50%; left: calc(100% + 10px); transform: translateY(50%);
}
[data-info-side="below"]:hover::after,
[data-info-side="below"]:focus::after {
  bottom: auto; top: calc(100% + 10px);
}
/* Защита от обрезания на крайних элементах: если родитель имеет overflow
   hidden — добавьте ему .ds-info-host или раскройте overflow вокруг. */

/* Метка термина: текст + ? */
.ds-term { display: inline-flex; align-items: center; gap: 4px; }

/* ─── P3 audit 2026-06-01 ──────────────────────────────────────────
   Table column headers: предотвращаем визуальное слипание info-иконок
   соседних right-aligned .num колонок (видно на /forecast декомпозиции).
   Решение: 
   • явный gap между текстом заголовка и иконкой через wrap;
   • дополнительный padding между соседними num колонками;
   • subtler focus-visible — без второго «кольца» вокруг иконки. */
.ds-table th { white-space: nowrap; }
.ds-table th .ds-info { margin-left: 6px; vertical-align: -2px; }
.ds-table th.num + th.num,
.ds-table td.num + td.num { padding-left: 20px; }
.ds-info:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Если в th есть текст-метка ПЛЮС info-иконка — стопроцентно держим их
   вместе в одном inline-flex; полезно для длинных названий типа «+ Календарь» */
.ds-table th .ds-info { flex-shrink: 0; }

/* ============================================================
   Legacy classes (для существующих страниц до их переноса на ds-*)
   ============================================================ */
.container { max-width: 1600px; margin: 0 auto; padding: 0; }
.page-header {
  display: flex; align-items: center; gap: var(--space-4);
  margin-bottom: var(--space-6); flex-wrap: wrap;
}
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-5);
  transition: var(--t);
}
.card__title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-secondary); margin: 0 0 var(--space-3);
}
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 var(--space-4); height: 36px;
  border-radius: var(--radius);
  font-family: var(--font); font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text);
  transition: var(--t-fast);
  white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn--primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--secondary { background: transparent; border-color: var(--border-strong); color: var(--text-secondary); }
.btn--secondary:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--red-soft); color: var(--red-text); border-color: rgba(220,38,38,0.3); }
.btn--danger:hover { background: var(--red); color: white; }
.btn--sm { height: 28px; padding: 0 var(--space-3); font-size: 11px; }
.btn--xs { height: 24px; padding: 0 var(--space-2); font-size: 11px; }
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: var(--radius-full); font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--text-secondary);
}
.badge--green  { background: var(--green-soft); color: var(--green-text); }
.badge--red    { background: var(--red-soft); color: var(--red-text); }
.badge--yellow { background: var(--yellow-soft); color: var(--yellow-text); }
.badge--accent { background: var(--accent-soft); color: var(--accent-text); }

/* Legacy form-group / inputs */
.form-group { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.form-group label, label.label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-secondary);
}
.form-group input[type=text], .form-group input[type=number], .form-group input[type=email],
.form-group input[type=password], .form-group input[type=date], .form-group select,
.form-group textarea,
input[type=text]:not(.ds-input), input[type=number]:not(.ds-input), select:not(.ds-select), textarea:not(.ds-input) {
  height: 36px; padding: 0 var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: var(--font); font-size: 13px;
  transition: var(--t-fast);
}
.form-group textarea, textarea:not(.ds-input) { height: auto; padding: var(--space-2) var(--space-3); min-height: 80px; resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus,
input:focus:not(.ds-input), select:focus:not(.ds-select), textarea:focus:not(.ds-input) {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

.subtitle { color: var(--text-secondary); font-size: 13px; }

/* Legacy spinner */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ds-spin 0.7s linear infinite;
  margin: 0 auto;
}

/* Generic <table> within .tbl-wrap */
.tbl-wrap { overflow-x: auto; }
.tbl-wrap table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl-wrap th, .tbl-wrap td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); text-align: left; }
.tbl-wrap th {
  font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-secondary); background: var(--surface);
}
.tbl-wrap tbody tr:hover { background: var(--surface-2); }

/* Generic h1/h2/h3 fallback */
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 var(--space-3); }
h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 var(--space-3); }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 var(--space-2); }
.h-row { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }

/* ============================================================
   Legacy CSS variable aliases (для совместимости со старыми inline-стилями)
   ============================================================ */
:root {
  --bg-card: var(--surface);
  --bg-input: var(--surface-2);
  --border-h: var(--border-strong);
  --text-dim: var(--text-secondary);
  --accent-h: var(--accent-hover);
  --accent-dim: var(--accent-soft);
  --green-dim: var(--green-soft);
  --yellow-dim: var(--yellow-soft);
  --red-dim: var(--red-soft);
  --transition: var(--t);
  --shadow: var(--shadow-md);
}

/* Responsive — mobile sidebar collapse */
@media (max-width: 900px) {
  .ds-app { grid-template-columns: 64px 1fr; }
  .ds-sidebar { width: 64px; }
  .ds-logo, .ds-nav__group, .ds-nav__link__label, .ds-user-card__info { display: none; }
  .ds-pagecontent { padding: var(--space-4); }
}
