/* ═══════════════════════════════════════════════════════════════════════════
   Analitika — дизайн-система
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f3f4f7;
  --surface-3: #eceef2;
  --border: #e5e7ec;
  --border-strong: #d5d9e0;
  --text: #0f1626;
  --text-2: #4f5869;
  --text-3: #8a92a2;

  --accent: #5b5bf0;
  --accent-hover: #4a4ae0;
  --accent-soft: rgba(91, 91, 240, .10);
  --accent-text: #4343d6;
  --on-accent: #fff;

  --good: #14a05a;   --good-soft: rgba(20, 160, 90, .12);
  --warn: #d68a00;   --warn-soft: rgba(214, 138, 0, .14);
  --bad: #e5484d;    --bad-soft: rgba(229, 72, 77, .12);
  --info: #0a8ae6;   --info-soft: rgba(10, 138, 230, .12);

  --c1: #5b5bf0; --c2: #14b8a6; --c3: #f59e0b; --c4: #f43f5e;
  --c5: #0ea5e9; --c6: #a855f7; --c7: #84cc16; --c8: #94a3b8;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 20px 48px -12px rgba(16, 24, 40, .25);
  --overlay: rgba(15, 22, 38, .45);

  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 248px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d12; --surface: #13161d; --surface-2: #191d26; --surface-3: #212633;
    --border: #232835; --border-strong: #303747;
    --text: #e9ecf3; --text-2: #a4acbc; --text-3: #6d7688;
    --accent: #7c7cff; --accent-hover: #8f8fff; --accent-soft: rgba(124, 124, 255, .16); --accent-text: #a3a3ff;
    --good: #3ccf8e; --good-soft: rgba(60, 207, 142, .14);
    --warn: #f5b13d; --warn-soft: rgba(245, 177, 61, .14);
    --bad: #ff6b6f;  --bad-soft: rgba(255, 107, 111, .14);
    --info: #4cb4ff; --info-soft: rgba(76, 180, 255, .14);
    --c1: #7c7cff; --c2: #2dd4bf; --c3: #fbbf24; --c4: #fb7185; --c5: #38bdf8; --c6: #c084fc; --c7: #a3e635; --c8: #64748b;
    --shadow-sm: none; --shadow: 0 1px 0 rgba(255, 255, 255, .02); --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .7);
    --overlay: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d12; --surface: #13161d; --surface-2: #191d26; --surface-3: #212633;
  --border: #232835; --border-strong: #303747;
  --text: #e9ecf3; --text-2: #a4acbc; --text-3: #6d7688;
  --accent: #7c7cff; --accent-hover: #8f8fff; --accent-soft: rgba(124, 124, 255, .16); --accent-text: #a3a3ff;
  --good: #3ccf8e; --good-soft: rgba(60, 207, 142, .14);
  --warn: #f5b13d; --warn-soft: rgba(245, 177, 61, .14);
  --bad: #ff6b6f;  --bad-soft: rgba(255, 107, 111, .14);
  --info: #4cb4ff; --info-soft: rgba(76, 180, 255, .14);
  --c1: #7c7cff; --c2: #2dd4bf; --c3: #fbbf24; --c4: #fb7185; --c5: #38bdf8; --c6: #c084fc; --c7: #a3e635; --c8: #64748b;
  --shadow-sm: none; --shadow: 0 1px 0 rgba(255, 255, 255, .02); --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .7);
  --overlay: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01", "tnum";
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
svg.i { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ─── Каркас ─────────────────────────────────────────────────────────────── */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  gap: 18px;
  padding: 18px 14px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px; font-weight: 700; font-size: 16px; letter-spacing: -.02em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--c6));
  color: #fff;
}
.brand-mark svg.i { width: 17px; height: 17px; stroke-width: 2.2; }

.sb-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 0 10px 6px; }

.company-switch { display: flex; flex-direction: column; gap: 2px; }
.company-btn {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 10px;
  border: 0; border-radius: var(--radius-sm);
  background: none; cursor: pointer; text-align: left;
  color: var(--text-2); font-weight: 500; font-size: 13px; line-height: 1.3;
}
.company-btn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex-shrink: 0; }
.company-btn:hover { background: var(--surface-2); color: var(--text); }
.company-btn.active { background: var(--surface-2); color: var(--text); }
.company-btn.active .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.nav { display: flex; flex-direction: column; gap: 14px; flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; scrollbar-width: thin; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
  text-decoration: none !important;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-text); }
.nav-link .kbd { margin-left: auto; }

.sb-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.sync-status {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 12px; color: var(--text-2); line-height: 1.35;
}
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.sync-dot.ok { background: var(--good); }
.sync-dot.err { background: var(--bad); }
.sync-dot.run { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.sb-row { display: flex; gap: 6px; }
.sb-row > * { flex: 1; }

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

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 32px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--border); }
.topbar h1 { font-size: 20px; }
.topbar .subtitle { font-size: 13px; color: var(--text-3); margin-top: 1px; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }

.content { padding: 8px 32px 48px; max-width: 1480px; width: 100%; }
.view { display: flex; flex-direction: column; gap: 20px; animation: fade-in .25s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }

/* ─── Кнопки и поля ──────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-weight: 550; font-size: 13px; white-space: nowrap;
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: background .15s, border-color .15s, color .15s;
  text-decoration: none !important;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg.i { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: none; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-icon { width: 36px; padding: 0; }
.btn-sm.btn-icon { width: 30px; }
.btn.spinning svg.i { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.input, .select, .textarea {
  height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; width: 100%; }
.select { padding-right: 30px; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a92a2' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input-icon { position: relative; display: flex; align-items: center; }
.input-icon svg.i { position: absolute; left: 11px; width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.input-icon .input { padding-left: 34px; width: 100%; }

.kbd {
  display: inline-flex; align-items: center; height: 20px; padding: 0 6px;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
  font: 500 11px/1 var(--font); color: var(--text-3); background: var(--surface);
}

.search-trigger { width: 280px; justify-content: flex-start; color: var(--text-3); font-weight: 450; }
.search-trigger .kbd { margin-left: auto; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.segmented button {
  height: 28px; padding: 0 12px; border: 0; border-radius: 7px;
  background: none; color: var(--text-2); font-weight: 550; font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar .grow { flex: 1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; color: var(--text-3); font-weight: 500; }

/* ─── Карточки ───────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 0; }
.card-head h3 { font-size: 15px; }
.card-head .sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-body { padding: 16px 20px 20px; }
.card-body.flush { padding: 12px 0 0; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }

.section-title { display: flex; align-items: baseline; gap: 10px; margin-top: 8px; }
.section-title h2 { font-size: 16px; }
.section-title span { color: var(--text-3); font-size: 13px; }

/* KPI */
.kpi { padding: 16px 18px 14px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; }
.kpi-label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.kpi-label svg.i { width: 15px; height: 15px; color: var(--text-3); }
.kpi-value { font-size: 26px; font-weight: 680; letter-spacing: -.025em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); min-height: 20px; }
.kpi-spark { position: absolute; right: 16px; top: 42px; width: 84px; height: 30px; opacity: .9; pointer-events: none; }
.delta { display: inline-flex; align-items: center; gap: 2px; height: 20px; padding: 0 7px; border-radius: 999px; font-weight: 600; font-size: 11.5px; }
.delta.up { background: var(--good-soft); color: var(--good); }
.delta.down { background: var(--bad-soft); color: var(--bad); }
.delta.flat { background: var(--surface-2); color: var(--text-2); }
.kpi.accent .kpi-value { color: var(--accent-text); }

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.chart-box.lg { height: 340px; }
.chart-box.xl { height: 460px; }

/* Статистика в строку */
.stat-row { display: flex; flex-wrap: wrap; gap: 28px; }
.stat-row .stat-label { font-size: 12px; color: var(--text-3); }
.stat-row .stat-value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ─── Таблицы ────────────────────────────────────────────────────────────── */

.table-wrap { overflow: auto; max-height: 620px; }
.table-wrap.short { max-height: 420px; }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th {
  position: sticky; top: 0; z-index: 1;
  padding: 9px 14px; text-align: left; white-space: nowrap;
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.table th:first-child { padding-left: 20px; }
.table th:last-child { padding-right: 20px; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table td:first-child { padding-left: 20px; }
.table td:last-child { padding-right: 20px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }
.table .r { text-align: right; }
.table .c { text-align: center; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .arrow { display: inline-block; width: 10px; color: var(--accent-text); }
.table td.idx { color: var(--text-3); width: 40px; font-variant-numeric: tabular-nums; }
.cell-main { font-weight: 550; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.table td:has(> .cell-sub) { min-width: 170px; }
.bar-cell { display: flex; align-items: center; gap: 10px; min-width: 140px; }
.bar-cell .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar-cell .bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar-cell .val { min-width: 76px; text-align: right; font-variant-numeric: tabular-nums; }

.pagination { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-3); }
.pagination .spacer { flex: 1; }

/* ─── Бейджи ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.badge svg.i { width: 13px; height: 13px; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }

/* ─── RFM ────────────────────────────────────────────────────────────────── */

.rfm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.rfm { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; transition: border-color .15s, transform .15s; }
.rfm:hover { border-color: var(--seg); transform: translateY(-1px); }
.rfm-head { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.rfm-head .sw { width: 10px; height: 10px; border-radius: 3px; background: var(--seg); }
.rfm-desc { font-size: 12px; color: var(--text-3); min-height: 32px; line-height: 1.35; }
.rfm-count { display: flex; align-items: baseline; gap: 8px; }
.rfm-count b { font-size: 26px; font-weight: 680; letter-spacing: -.02em; }
.rfm-count span { color: var(--text-3); font-size: 12.5px; }
.rfm-bar { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.rfm-bar i { display: block; height: 100%; background: var(--seg); }
.rfm-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding-top: 4px; border-top: 1px dashed var(--border); }
.rfm-meta div { display: flex; flex-direction: column; }
.rfm-meta span { font-size: 11px; color: var(--text-3); }
.rfm-meta b { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ─── Тепловые карты ─────────────────────────────────────────────────────── */

.heat { border-collapse: separate; border-spacing: 3px; font-size: 12px; font-variant-numeric: tabular-nums; }
.heat th { font-weight: 500; color: var(--text-3); padding: 2px 4px; white-space: nowrap; font-size: 11px; }
.heat th.row-h { text-align: left; color: var(--text-2); font-weight: 500; max-width: 260px; overflow: hidden; text-overflow: ellipsis; padding-right: 10px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.heat td { min-width: 42px; height: 30px; text-align: center; border-radius: 6px; color: var(--text-2); }
.heat td.lvl0 { background: var(--surface-2); color: var(--text-3); }
.heat td[data-pick] { cursor: pointer; }
.heat td[data-pick]:hover { outline: 2px solid var(--accent); outline-offset: -1px; }
.heat .meta-col { color: var(--text-2); font-weight: 600; padding-left: 10px; text-align: right; background: none; }
.heat-wrap { overflow: auto; max-height: 640px; padding: 0 16px 16px; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-3); }
.legend i { width: 18px; height: 10px; border-radius: 3px; display: inline-block; }

/* ─── Пустые состояния и скелетоны ───────────────────────────────────────── */

.empty { padding: 40px 20px; text-align: center; color: var(--text-3); font-size: 13px; }
.empty-hero { padding: 80px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty-hero h2 { font-size: 20px; }
.empty-hero p { color: var(--text-2); margin: 0 0 8px; max-width: 420px; }
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: 8px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.error-box { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); font-size: 13px; }

/* ─── Боковая панель (карточка клиента) ──────────────────────────────────── */

.scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 80; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 90;
  width: min(640px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; gap: 14px; padding: 20px 22px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 19px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px 28px; display: flex; flex-direction: column; gap: 22px; }
.avatar {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
  background: var(--accent-soft); color: var(--accent-text);
}
.contact-line { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-2); margin-top: 4px; }
.contact-line span { display: inline-flex; align-items: center; gap: 5px; }
.contact-line svg.i { width: 14px; height: 14px; color: var(--text-3); }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.mini-stat { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.mini-stat span { display: block; font-size: 11.5px; color: var(--text-3); }
.mini-stat b { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.block-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-row > .input, .form-row > .select { flex: 1; min-width: 140px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs button { padding: 8px 12px; border: 0; background: none; color: var(--text-3); font-weight: 600; font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs button .count { color: var(--text-3); font-weight: 500; margin-left: 4px; }

.timeline { display: flex; flex-direction: column; gap: 8px; }
.tl-item { display: flex; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13px; position: relative; }
.tl-icon { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; background: var(--surface); color: var(--text-2); }
.tl-icon svg.i { width: 15px; height: 15px; }
.tl-icon.good { color: var(--good); } .tl-icon.bad { color: var(--bad); } .tl-icon.info { color: var(--info); } .tl-icon.accent { color: var(--accent-text); }
.tl-main { flex: 1; min-width: 0; }
.tl-meta { font-size: 12px; color: var(--text-3); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.tl-text { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.tl-del { position: absolute; top: 6px; right: 6px; opacity: 0; }
.tl-item:hover .tl-del { opacity: 1; }
audio { height: 32px; max-width: 240px; }
.audio-sm { height: 28px; max-width: 190px; vertical-align: middle; }

/* ─── Поиск (командная палитра) ──────────────────────────────────────────── */

.palette {
  position: fixed; z-index: 100; left: 50%; top: 12vh; transform: translateX(-50%);
  width: min(620px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.palette-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.palette-input input { flex: 1; border: 0; outline: none; background: none; font-size: 16px; }
.palette-input svg.i { color: var(--text-3); }
.palette-list { max-height: 50vh; overflow-y: auto; padding: 6px; }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.palette-item.active { background: var(--accent-soft); }
.palette-item .avatar { width: 32px; height: 32px; border-radius: 9px; font-size: 13px; }
.palette-item .meta { margin-left: auto; text-align: right; font-size: 12px; color: var(--text-3); }
.palette-hint { padding: 9px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); display: flex; gap: 14px; }

/* ─── Уведомления ────────────────────────────────────────────────────────── */

.toasts { position: fixed; z-index: 120; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 11px; min-width: 240px; max-width: 380px;
  background: var(--text); color: var(--bg); font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: toast-in .2s ease;
}
.toast.bad { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ─── Popover ────────────────────────────────────────────────────────────── */

.popover {
  position: fixed; z-index: 95; width: 320px; max-height: 360px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 12px 14px; font-size: 12.5px;
}
.popover h4 { font-size: 13px; margin-bottom: 8px; }
.popover .rec { display: flex; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); }
.popover .rec:first-of-type { border-top: 0; }

/* ─── Период ──────────────────────────────────────────────────────────────── */

.period-menu { width: 270px; padding: 6px; max-height: none; }
.period-opt {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer; text-align: left; font-size: 13px;
}
.period-opt:hover { background: var(--surface-2); }
.period-opt.active { color: var(--accent-text); font-weight: 600; }
.period-opt svg.i { width: 15px; height: 15px; }
.period-custom { border-top: 1px solid var(--border); margin-top: 6px; padding: 10px 6px 4px; }
.period-custom .input { min-width: 0; height: 32px; padding: 0 8px; font-size: 12.5px; }
.period-note { font-size: 12.5px; color: var(--text-3); }

/* ─── Новые разделы ──────────────────────────────────────────────────────── */

.reco { display: flex; flex-direction: column; gap: 12px; font-size: 13.5px; line-height: 1.5; }
.reco-row { display: flex; gap: 12px; align-items: baseline; }
.reco-row .badge { flex-shrink: 0; }
.weekend { color: var(--c4); }
.tg-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.tg-steps { margin: 0 0 14px; padding-left: 20px; color: var(--text-2); font-size: 13px; line-height: 1.7; }
.tg-chats { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.tg-chats .x { border: 0; background: none; padding: 0 0 0 4px; cursor: pointer; color: inherit; display: inline-flex; }
.tg-chats .x svg.i { width: 12px; height: 12px; }
.tg-preview { white-space: normal; font-size: 13px; line-height: 1.55; background: var(--surface-2); border-radius: var(--radius-sm); padding: 14px 16px; max-width: 640px; }

/* ─── Адаптив ────────────────────────────────────────────────────────────── */

@media (max-width: 1200px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .topbar { padding: 12px 16px; }
  .content { padding: 4px 16px 40px; }
  .search-trigger { width: 36px; padding: 0; }
  .topbar .btn .label, .search-trigger .kbd { display: none; }
  #syncBtn { width: 36px; padding: 0; }
  #periodBtn { padding: 0 10px; }
  #periodBtn .label { display: inline; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
  .nav-link .kbd { display: none; }
}
@media (max-width: 560px) {
  .topbar h1 { font-size: 17px; }
  .topbar .subtitle { display: none; }
  .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 13px; }
  .kpi-value { font-size: 20px; }
  .kpi-foot { flex-wrap: wrap; gap: 4px 6px; font-size: 11.5px; }
  .kpi-spark { display: none; }
  .chart-box { height: 240px; }
  .card-head { padding: 14px 16px 0; flex-wrap: wrap; }
  .card-head .actions { margin-left: 0; }
  .card-body { padding: 12px 16px 16px; }
  .table th:first-child, .table td:first-child { padding-left: 16px; }
  .drawer-head, .drawer-body { padding-left: 16px; padding-right: 16px; }
  .toasts { left: 16px; right: 16px; }
}
