:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1a1f26; --muted: #6b7480;
  --line: #e3e7ec; --accent: #2f6df6; --accent-soft: #eaf1ff;
  --good: #1f9d55; --bad: #d64545; --sbp: #7b61ff; --cash: #1f9d55; --card: #2f6df6;
  --lead: #fff7e6; --lead-line: #f0c36d;
}
* { box-sizing: border-box; }
body {
  margin: 0; font: 14px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }

header.top {
  display: flex; align-items: center; gap: 20px; padding: 12px 22px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
header .brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
header nav { display: flex; gap: 4px; }
header nav a {
  padding: 6px 12px; border-radius: 7px; color: var(--muted); font-weight: 600;
}
header nav a.active { background: var(--accent-soft); color: var(--accent); }
header .spacer { flex: 1; }
header .logout { color: var(--muted); font-size: 13px; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 22px 60px; }

.filters {
  display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 18px;
}
.filters .grp { display: flex; flex-direction: column; gap: 5px; }
.filters label { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button, .seg a {
  border: 0; background: var(--panel); padding: 7px 12px; cursor: pointer;
  font: inherit; color: var(--muted); border-right: 1px solid var(--line);
}
.seg button:last-child, .seg a:last-child { border-right: 0; }
.seg button.on, .seg a.on { background: var(--accent); color: #fff; }
input[type=date], select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font: inherit; background: #fff;
}
select[multiple] { min-width: 190px; height: 74px; }
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 16px; font-weight: 600; cursor: pointer;
}
.badge {
  display: inline-block; background: var(--lead); border: 1px solid var(--lead-line);
  color: #8a5a00; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600;
}
.period-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi .k { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi .v small { font-size: 13px; color: var(--muted); font-weight: 600; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 18px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: 11px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: #fafbfc; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); background: #fbfcfe; }
td.num { font-variant-numeric: tabular-nums; }
td.lead { background: var(--lead); font-weight: 700; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.muted { color: var(--muted); }

/* Топ-SKU: фиксированная раскладка — таблица всегда по ширине экрана,
   длинное название усекается многоточием (полный текст в title по наведению). */
table.sku { table-layout: fixed; }
table.sku th, table.sku td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.sku td.name { text-align: left; }

.charts { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.charts.equal { grid-template-columns: 1fr 1fr; }   /* равные колонки (разбивки товаров) */
.charts .full { grid-column: 1 / -1; }
/* Критично: без этого широкая таблица-разбивка внутри ячейки грида не даёт
   колонке сжаться и выпихивает всю страницу вширь (горизонтальный скролл). */
.charts > * { min-width: 0; }
/* Длинные подписи разбивок (цвета/страны) переносим, а не растягиваем ячейку. */
.charts table td:first-child, .charts table th:first-child { white-space: normal; }
@media (max-width: 820px) { .charts { grid-template-columns: 1fr; } }
canvas { max-height: 300px; max-width: 100%; }

.login-wrap { max-width: 340px; margin: 12vh auto; }
.login-wrap .panel { text-align: center; }
.login-wrap input { width: 100%; margin: 10px 0; }
.err { color: var(--bad); font-size: 13px; }
.htmx-request .panel { opacity: .55; transition: opacity .15s; }
