:root {
  --ink: #1c2430;
  --ink-soft: #5b6472;
  --line: #e2e5ea;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --accent: #2f6fed;
  --accent-hover: #2559c4;
  --accent-soft: #eaf1ff;
  --danger: #d1453b;
  --danger-soft: #f2c9c6;
  --danger-soft-bg: #fdf1f0;
  --profit: #16a34a;
  --loss: #dc2626;
  --radius: 6px;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

[data-theme="dark"] {
  --ink: #f8fafc;
  --ink-soft: #94a3b8;
  --line: #334155;
  --bg: #020617;
  --surface: #0e1223;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: #1a2b4d;
  --danger: #ef4444;
  --danger-soft: #5c2e2e;
  --danger-soft-bg: #2a1414;
  --profit: #22c55e;
  --loss: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

body.with-sidebar {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-brand {
  font-weight: 600;
  font-size: 15px;
  padding: 0 18px 14px;
}

.sidebar-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  padding: 14px 18px 6px;
}

.tabs.vertical { display: flex; flex-direction: column; gap: 1px; }

.tabs.horizontal {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tabs.horizontal .tab {
  padding: 8px 12px;
  border-bottom: 2px solid transparent;
}

.tabs.horizontal .tab.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 14px;
}

.tab {
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover { color: var(--ink); }

.tabs.vertical .tab {
  text-align: left;
  padding: 8px 18px;
  border-bottom: none;
  border-left: 2px solid transparent;
}

.tabs.vertical .tab.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-spacer { flex: 1; }

.sidebar-user {
  padding: 0 18px 10px;
  font-size: 12px;
  color: var(--ink-soft);
}

.sidebar > .btn { margin: 3px 18px; }

main { flex: 1; min-width: 0; }


main { padding: 20px 24px; }
main.full-width { max-width: none; }
main:not(.full-width) { max-width: 1200px; margin: 0 auto; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

select, input[type="text"], input[type="date"] {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface);
}

.date-filters { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); }

.spacer { flex: 1; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
}

.btn:hover { background: var(--bg); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }

.btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.danger:hover { background: var(--danger-soft-bg); }

.btn-icon {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  width: 32px; height: 32px;
  cursor: pointer;
  font-size: 15px;
  color: var(--ink-soft);
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: hidden;
  max-height: 70vh;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  white-space: nowrap;
}

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--accent-soft); cursor: pointer; }

.checkbox-col { width: 32px; }

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 13px;
}

.pagination button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  width: 30px; height: 30px;
  cursor: pointer;
}

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 24, 32, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border-radius: 10px;
  padding: 22px;
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}

.modal h3 { margin: 0 0 14px; font-size: 16px; }

#recordForm { display: flex; flex-direction: column; gap: 10px; }

#recordForm label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--ink-soft);
}

#recordForm input, #recordForm select {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
}

.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 18px;
}

.empty-row td {
  text-align: center;
  color: var(--ink-soft);
  padding: 28px 12px;
}

.btn, .tab, .btn-icon, tbody tr {
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.amount-positive { color: var(--profit); font-weight: 600; }
.amount-negative { color: var(--loss); }

/* замороженные первые 2 колонки для широких таблиц (Свод WB) —
   решает эффект "окна в окне": прокручиваем вправо, но не теряем
   из виду компанию/месяц. Ширина колонок задана явно — без этого
   left:130px у второй колонки не совпадает с реальной шириной первой
   (она зависит от контента) и заголовки/ячейки наезжают друг на друга. */
.table-wrap.frozen-cols td:nth-child(1),
.table-wrap.frozen-cols td:nth-child(2),
.table-wrap.frozen-cols th:nth-child(1),
.table-wrap.frozen-cols th:nth-child(2) {
  position: sticky;
  background: var(--surface);
  z-index: 1;
}
.table-wrap.frozen-cols td:nth-child(1),
.table-wrap.frozen-cols th:nth-child(1) { left: 0; width: 160px; min-width: 160px; max-width: 160px; }
.table-wrap.frozen-cols td:nth-child(2),
.table-wrap.frozen-cols th:nth-child(2) { left: 160px; width: 90px; min-width: 90px; max-width: 90px; border-right: 1px solid var(--line); }
.table-wrap.frozen-cols th:nth-child(1),
.table-wrap.frozen-cols th:nth-child(2) { z-index: 2; background: var(--bg); }

/* один замороженный столбец слева (название показателя) — для
   транспонированной таблицы ОПиУ (метрики строками, месяцы столбцами) */
.table-wrap.frozen-first-col td:nth-child(1),
.table-wrap.frozen-first-col th:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  width: 230px;
  min-width: 230px;
  max-width: 230px;
  white-space: normal;
}
.table-wrap.frozen-first-col th:nth-child(1) { z-index: 2; background: var(--bg); }
.opiu-table-row.total td { font-weight: 700; background: var(--accent-soft); }
.opiu-table-row.total td:first-child { background: var(--accent-soft); }
.opiu-table-row.indent td:first-child { color: var(--ink-soft); padding-left: 24px; }

.checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  max-height: 160px;
  overflow-y: auto;
}

.checkbox-list label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--ink);
  width: auto;
}

.checkbox-list input[type="checkbox"] { width: auto; }

.modal.modal-wide { width: 560px; }

.inline-checkbox {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
}
.inline-checkbox input { width: auto; }

/* ---------------- Отчёты: карточный дашборд ---------------- */

.dashboard-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.dashboard-toolbar select {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
  background: var(--surface);
  color: var(--ink);
}

.report-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 3px;
}

.report-toggle button {
  border: none;
  background: none;
  padding: 6px 14px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
}

.report-toggle button.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
}

.kpi-title {
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}

.kpi-bar {
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--bg);
  margin-bottom: 10px;
}

.kpi-bar span { height: 100%; }

.kpi-breakdown {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.kpi-breakdown-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink);
}

.kpi-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.kpi-breakdown-label { flex: 1; color: var(--ink-soft); }
.kpi-breakdown-value { font-variant-numeric: tabular-nums; font-weight: 500; }
.kpi-breakdown-pct { color: var(--ink-soft); font-size: 11px; width: 34px; text-align: right; }

.kpi-sub {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.trend-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
}

.trend-card h3 {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 600;
}

.opiu-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}

.opiu-row {
  display: flex;
  align-items: center;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  gap: 12px;
}

.opiu-row:last-child { border-bottom: none; }
.opiu-row.total { background: var(--bg); font-weight: 700; }
.opiu-row .opiu-label { flex: 1; color: var(--ink); }
.opiu-row .opiu-value { font-variant-numeric: tabular-nums; min-width: 130px; text-align: right; }
.opiu-row.indent .opiu-label { color: var(--ink-soft); padding-left: 16px; }

.empty-dashboard {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.period-note {
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 12.5px;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  line-height: 1.4;
}

.import-dropzone {
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
}
.import-dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.import-browse-link { color: var(--accent); text-decoration: underline; }
#importTemplateLink { display: inline-block; text-decoration: none; }

/* ---------- ОДДС ---------- */
.odds-tabs { margin-bottom: 12px; }
.odds-summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.odds-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; min-width: 190px; }
.odds-card span { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 2px; }
.odds-card b { font-size: 18px; }
.odds-reminder b { font-size: 14px; }
.odds-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.odds-toolbar .spacer { flex: 1; }
.odds-toolbar input, .odds-toolbar select { padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-size: 13px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.odds-table-wrap { max-height: 68vh; overflow: auto; }
.odds-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.odds-table th { position: sticky; top: 0; background: var(--surface); z-index: 1; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.odds-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); }
.odds-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.odds-table .odds-snap { font-size: 11px; color: var(--ink-soft); max-width: 260px; }
.odds-snapshot { background: var(--accent-soft); }
.odds-pager { margin-top: 10px; }
.odds-hint { color: var(--ink-soft); font-size: 12px; margin: 6px 0 12px; }
.odds-error, .odds-form-error { color: var(--danger); background: var(--danger-soft-bg); border: 1px solid var(--danger-soft); border-radius: var(--radius); padding: 8px 10px; font-size: 13px; }
.odds-form { display: flex; flex-direction: column; gap: 10px; }
.odds-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-soft); }
.odds-form label small { font-size: 11px; opacity: .8; }
.odds-form input, .odds-form select { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; font-size: 14px; color: var(--ink); background: var(--surface); }
.odds-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.odds-form details { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.odds-form summary { cursor: pointer; font-size: 13px; }
.modal-wide { width: 640px; max-height: 90vh; overflow: auto; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { text-align: center; font-size: 12px; color: var(--ink-soft); padding: 4px; }
.cal-cell { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-height: 86px; padding: 6px; font-size: 12px; }
.cal-cell[data-date] { cursor: pointer; }
.cal-cell[data-date]:hover { border-color: var(--accent); }
.cal-empty { background: transparent; border: none; }
.cal-credit { box-shadow: inset 0 0 0 1px var(--danger-soft); }
.cal-day { font-weight: 600; margin-bottom: 4px; }
.cal-count { color: var(--ink-soft); font-size: 11px; }
.cal-title { min-width: 150px; text-align: center; }
.odds-grid > label { min-width: 0; }
.odds-form input, .odds-form select { width: 100%; box-sizing: border-box; min-width: 0; }
.odds-table .odds-edit { width: 28px; padding-right: 0; }

.odds-red td { background: var(--danger-soft-bg); }
.odds-red td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.odds-paykind { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; }
.odds-paykind h4 { margin: 0 0 8px; font-size: 15px; }
.odds-paykind h4 small { display: block; font-weight: 400; color: var(--ink-soft); font-size: 12px; margin-top: 2px; }
.odds-paykind h5 { margin: 12px 0 6px; font-size: 13px; color: var(--ink-soft); }
