/* МаркетПульс — светлая тема */
:root {
  color-scheme: light;
  --page: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #f9f9f7;
  --surface-3: #f0efec;
  --border: rgba(11, 11, 11, 0.09);
  --border-strong: rgba(11, 11, 11, 0.16);
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #7a7873;
  --grid: #e1e0d9;
  --accent: #256abf;
  --accent-hover: #1c5cab;
  --accent-weak: #eaf2fc;
  --good-text: #006300;
  --bad-text: #b3261e;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --wb: #eb6834;
  --ozon: #2a78d6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.app > * { min-width: 0; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 8px; flex: none;
  background: var(--accent); display: grid; place-items: center;
}
.logo-mark svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.logo-name { font-weight: 700; font-size: 16px; }
.logo-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-group { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--surface-3); color: var(--ink); }
.nav a.active { background: var(--accent-weak); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding: 12px 8px 0; display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 600; color: var(--ink-2); flex: none; }
.user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 12px; color: var(--muted); }
.icon-btn {
  margin-left: auto; width: 32px; height: 32px; display: grid; place-items: center;
  border: 0; background: transparent; border-radius: var(--radius-sm); cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  padding: 14px 28px; background: rgba(245, 245, 242, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.period-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.filters { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- Элементы форм ---------- */
.select, .input {
  height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); min-width: 0;
}
.select { padding-right: 28px; appearance: none;
  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='%2352514e' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; cursor: pointer; }
.select:focus, .input:focus, .btn:focus-visible, .nav a:focus-visible, .icon-btn:focus-visible, .chip:focus-visible, th button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.input-sm { height: 30px; width: 96px; text-align: right; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.field .input, .field .select { width: 100%; height: 38px; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.btn {
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; transition: background .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--bad-text); }
.btn-danger:hover { background: #fbeceb; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:disabled { opacity: .55; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface); cursor: pointer; font-size: 13px; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { background: var(--surface-3); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.active .count { color: #c3c2b7; }

/* ---------- Карточки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 16px; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 600; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.grid-2-3 { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: 12px; }
.kpi { padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; white-space: nowrap; }
.kpi-foot { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.kpi-note { font-size: 12px; color: var(--muted); }
.delta { font-size: 12px; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: 2px; }
.delta.good { color: var(--good-text); }
.delta.bad { color: var(--bad-text); }
.delta.flat { color: var(--muted); }
.spark { margin-left: auto; width: 72px; height: 22px; flex: none; }
.kpi.alert { border-color: rgba(208, 59, 59, .35); }
.help {
  display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%;
  border: 1px solid var(--border-strong); color: var(--muted); font-size: 10px; font-weight: 700; cursor: help;
}

/* ---------- Графики ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.swatch.line { height: 3px; border-radius: 2px; width: 14px; }

.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 1.1fr) minmax(0, 2fr) auto; gap: 12px; align-items: center; font-size: 13px; }
.hbar-label { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 10px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 0 4px 4px 0; background: #86b6ef; }
.hbar-value { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hbar-value small { color: var(--muted); margin-left: 6px; display: inline-block; min-width: 44px; }
.hbar.total .hbar-label, .hbar.total .hbar-value { color: var(--ink); font-weight: 650; }
.hbar.total { padding-top: 10px; border-top: 1px solid var(--border); }

.segbar { display: flex; gap: 2px; height: 28px; }
.segbar > div { border-radius: 4px; display: flex; align-items: center; padding: 0 8px; color: #fff; font-size: 12px; font-weight: 600; overflow: hidden; white-space: nowrap; min-width: 0; }

/* Воронка */
.funnel { display: flex; flex-direction: column; gap: 12px; }
.funnel-step { display: grid; grid-template-columns: 200px minmax(0, 1fr) 150px; gap: 16px; align-items: center; }
.funnel-name { font-weight: 500; }
.funnel-name small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.funnel-track { height: 32px; background: var(--surface-2); border-radius: 4px; }
.funnel-bar { height: 100%; border-radius: 0 4px 4px 0; min-width: 4px; display: flex; align-items: center; padding-left: 10px; color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; }
.funnel-conv { font-size: 13px; color: var(--ink-2); }
.funnel-conv b { color: var(--ink); font-size: 15px; }

/* ---------- Таблицы ---------- */
.table-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.table-tools .input { width: 220px; }
.table-wrap { overflow-x: auto; margin: 0 -20px -18px; border-top: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: 12px; color: var(--ink-2); z-index: 1; }
th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th button:hover { color: var(--ink); }
th .arrow { color: var(--accent); font-size: 11px; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num button { flex-direction: row-reverse; }
tbody tr:hover { background: #fafaf8; }
tfoot td { font-weight: 650; background: var(--surface-2); border-bottom: 0; }
.cell-product { display: flex; flex-direction: column; gap: 1px; max-width: 320px; }
.cell-product .name { white-space: normal; font-weight: 500; line-height: 1.3; }
.cell-product .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.pos { color: var(--good-text); }
.neg { color: var(--bad-text); }
.dim { color: var(--muted); }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.more-row { padding: 12px 20px; text-align: center; }
.wrap-cell { white-space: normal; min-width: 200px; max-width: 320px; color: var(--ink-2); font-size: 12px; }

/* Метки */
.mp { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.mp::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.mp-wb { --c: var(--wb); }
.mp-ozon { --c: var(--ozon); }
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--bg); color: var(--ink);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.badge.critical { --c: var(--critical); --bg: #fbeaea; }
.badge.warning { --c: var(--warning); --bg: #fff5de; }
.badge.serious { --c: var(--serious); --bg: #fdeee7; }
.badge.good { --c: var(--good); --bg: #e7f6e7; }
.badge.neutral { --c: #a8a69f; --bg: var(--surface-3); }
.badge.info { --c: var(--accent); --bg: var(--accent-weak); }
.abc { display: inline-grid; place-items: center; width: 24px; height: 22px; border-radius: 5px; font-weight: 700; font-size: 12px; background: var(--surface-3); }
.abc-A { background: #cde2fb; color: #104281; }
.abc-B { background: #e6e4f9; color: #3a2e8f; }
.abc-C { background: var(--surface-3); color: var(--ink-2); }

/* Сообщения */
.banner {
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center;
  padding: 12px 16px; border-radius: var(--radius); background: #fff8e6; border: 1px solid #f4dfa6; font-size: 13px;
}
.banner b { font-weight: 600; }
.note { font-size: 12px; color: var(--muted); }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }
.error-box { padding: 16px; border-radius: var(--radius); background: #fbeaea; color: var(--bad-text); }
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 360px; }
.toast.error { background: var(--bad-text); }

/* Окна */
dialog {
  border: 0; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25); color: var(--ink);
}
dialog::backdrop { background: rgba(11, 11, 11, .35); }
.dialog-body { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; max-height: 75vh; overflow-y: auto; }
.dialog-body h2 { font-size: 18px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.form-error { color: var(--bad-text); font-size: 13px; }
.store-checks { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 500; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--ink); }

/* ---------- Адаптив ---------- */
@media (max-width: 1100px) {
  .grid-2, .grid-3-2, .grid-2-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .logo { padding: 0; }
  .logo-sub { display: none; }
  .nav { flex-direction: row; overflow-x: auto; order: 3; width: 100%; padding-bottom: 2px; }
  .nav-group { display: none; }
  .nav a { white-space: nowrap; }
  .sidebar-footer { margin: 0 0 0 auto; border: 0; padding: 0; }
  .sidebar-footer .user-info { display: none; }
  .topbar { position: static; padding: 12px 16px; }
  .filters { margin-left: 0; width: 100%; }
  .filters .select { flex: 1 1 140px; }
  #f-custom { display: flex; gap: 6px; align-items: center; width: 100%; }
  #f-custom .input { flex: 1; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px -16px; }
  th:first-child, td:first-child { padding-left: 16px; }
  .card-actions { margin-left: 0; }
  .spark { display: none; }
  .content { padding: 16px 16px 40px; }
  .funnel-step { grid-template-columns: 1fr; gap: 6px; }
  .kpi-value { font-size: 21px; }
  .table-tools .input { width: 100%; }
}
