:root {
  --bg: #f6f7f9;
  --fg: #1c2024;
  --muted: #6b7280;
  --line: #e3e6ea;
  --panel: #ffffff;
  --accent: #2f6feb;
  --totals-bg: #eceff3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --fg: #e8eaed;
    --muted: #9aa3ad;
    --line: #2a2f36;
    --panel: #1b1e23;
    --accent: #6c9bff;
    --totals-bg: #242830;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 16px;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

h1 { font-size: 20px; margin: 0; }

/* Шапка одной строкой: заголовок, срез, обновление, сохранение, cookies */
.topbar {
  gap: 8px;
  justify-content: flex-start;
  margin-bottom: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.topbar h1 { font-size: 16px; margin-right: 6px; white-space: nowrap; }

/* Переключатель страниц «Сделки» / «Свод» */
.views { display: flex; gap: 2px; }
.views a {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.views a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.topbar .push-right { margin-left: auto; }
.snapshot-select { max-width: 260px; }

form { display: flex; gap: 8px; align-items: center; }
label { color: var(--muted); font-size: 13px; }

select, button {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  font-size: 14px;
}

.error {
  padding: 12px 14px;
  border: 1px solid #e0b4b4;
  background: #fdf0f0;
  color: #8a2020;
  border-radius: 8px;
  margin-bottom: 20px;
}

.ok {
  padding: 12px 14px;
  border: 1px solid #b6ddb6;
  background: #f0f8f0;
  color: #1f5e1f;
  border-radius: 8px;
  margin-bottom: 20px;
}

.muted { color: var(--muted); font-size: 13px; }

.hint { color: var(--muted); font-size: 13px; max-width: 68ch; }
.hint code { background: rgba(127,127,127,.15); padding: 1px 4px; border-radius: 4px; }

.link-btn { color: var(--accent); font-size: 13px; text-decoration: none; }
.link-btn:hover { text-decoration: underline; }

.stack { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; max-width: 68ch; margin-bottom: 20px; }
.stack label { display: flex; flex-direction: column; gap: 4px; width: 100%; }

textarea, input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; cursor: pointer; }

summary { cursor: pointer; color: var(--muted); font-size: 14px; }
h2.section { font-size: 15px; margin: 22px 0 6px; }

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

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card-total { border-color: var(--accent); }
.card-total .card-value { color: var(--accent); }

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

/* width: auto + min-width: 100% — когда таблица шире экрана, столбцы сжимаются
   до содержимого и лишняя ширина никуда не растягивается */
table {
  border-collapse: collapse;
  width: auto;
  min-width: 100%;
  font-size: 14px;
}

th, td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

thead th {
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

tbody tr:hover td { background: rgba(127, 127, 127, .07); }

.num { text-align: right; font-variant-numeric: tabular-nums; }
thead th.num { letter-spacing: 0; }
/* В таблице с авторазметкой max-width на ячейке не работает — обрезаем содержимое */
.clip {
  max-width: 145px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clip-title { max-width: 260px; }

/* Название сделки не уезжает при горизонтальной прокрутке */
.sticky-col {
  position: sticky;
  left: 0;
  background: var(--panel);
  z-index: 1;
  border-right: 1px solid var(--line);
}
thead .sticky-col { z-index: 2; }
.totals-row .sticky-col { background: var(--totals-bg); }
tbody tr:hover .sticky-col { background: var(--panel); }
tfoot .sticky-col { background: var(--panel); }
.check { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
form { flex-wrap: wrap; }

.inline-form { display: flex; gap: 8px; align-items: center; }

/* Прогресс обновления */
.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--panel);
  font-size: 14px;
}
.progress.hidden { display: none; }
.spinner {
  width: 14px;
  height: 14px;
  flex: none;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--line); }
}
/* input[type="text"] задаёт width: 100% и моношрифт — перебиваем по типу элемента */
input.snapshot-name {
  width: 150px;
  font: 14px/1.4 inherit;
  font-family: inherit;
  padding: 6px 8px;
}
button { cursor: pointer; }
button[disabled] { opacity: .5; cursor: not-allowed; }
button.danger { color: #b3261e; border-color: #e0b4b4; }

/* Форма фильтров — только контейнер, поля живут в шапке таблицы */
.hidden-form { display: none; }

/* Полоса фильтров над заголовками столбцов */
.filter-row th {
  background: var(--panel);
  padding: 7px 10px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  vertical-align: middle;
}
.filter-row .check { color: var(--muted); font-size: 13px; }
/* Список показателей стоит в заголовке блока: держим его компактным, чтобы
   столбец оставался шириной «цифры + отступы» */
.metric-select {
  width: 100%;
  min-width: 0;
  max-width: 150px;
  font-size: 12px;
  padding: 3px 4px;
}
.block-head-inner { display: flex; align-items: center; gap: 6px; min-width: 0; }

/* Выпадающий список с чекбоксами */
.dropdown { position: relative; }
.dropdown-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.dropdown.has-selection .dropdown-btn { border-color: var(--accent); color: var(--accent); }
.dropdown-count { color: var(--muted); }
.dropdown.has-selection .dropdown-count { color: inherit; }
.dropdown-panel {
  display: none;
  /* fixed, а не absolute: панель внутри .table-wrap обрезалась бы прокруткой */
  position: fixed;
  z-index: 50;
  min-width: 220px;
  max-height: 280px;
  overflow-y: auto;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.dropdown.open .dropdown-panel { display: block; }
.dropdown-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 5px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.dropdown-panel label:hover { background: rgba(127, 127, 127, .12); }
.dropdown-panel .select-all { font-weight: 600; }
.dropdown-divider { height: 1px; margin: 5px 2px; background: var(--line); }

/* Колонки периодов */
.col-toggle { color: inherit; text-decoration: none; white-space: nowrap; }
.col-toggle:hover { color: var(--accent); }
.chev { margin-left: 4px; opacity: .6; }

/* Заголовок колонки периода: значок сортировки слева, название справа */
.col-head { display: flex; align-items: center; justify-content: space-between; gap: 5px; }
.sort-mark {
  color: var(--muted);
  text-decoration: none;
  opacity: .55;
  font-size: 11px;
}
.sort-mark:hover { opacity: 1; color: var(--accent); }
.sort-mark.active { opacity: 1; color: var(--accent); }

.deal-link { color: inherit; text-decoration: none; }
.deal-link:hover { color: var(--accent); text-decoration: underline; }
.col-month { background: rgba(127, 127, 127, .05); }

/* Границы блоков «прогноз» / «взвешенный прогноз» */
.block-start { border-left: 2px solid var(--accent); }
.filter-row th.block-head,
.block-head {
  /* по левому краю блока — при широкой таблице центр уезжает за экран */
  text-align: left;
  /* подпись блока может переноситься: иначе она растягивает столбцы,
     когда блок свёрнут в одну колонку */
  white-space: normal;
  background: var(--totals-bg);
  color: var(--fg);
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  border-left: 2px solid var(--accent);
}

.totals-row th {
  background: var(--totals-bg);
  color: var(--fg);
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
}
.total-cell { font-weight: 600; }
.subhead th { font-size: 11px; text-transform: none; letter-spacing: 0; }
.hit { color: var(--accent); font-weight: 600; }
.strong { font-weight: 600; }

tfoot td { border-bottom: none; background: rgba(127, 127, 127, .06); font-weight: 600; }

.empty { color: var(--muted); }

/* Свод: блоки периодов, каждый со своей шапкой */
table.summary tbody tr:hover td { background: rgba(127, 127, 127, .07); }
table.summary .period-row th {
  background: var(--totals-bg);
  color: var(--fg);
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  border-top: 2px solid var(--accent);
}
table.summary .sticky-col { min-width: 150px; }
table.summary .row-revenue td { font-weight: 600; }
table.summary .row-deals td { color: var(--muted); }
.cell-link { color: inherit; text-decoration: none; }
.cell-link:hover { text-decoration: underline; }
.cell-link.hit { color: var(--accent); }

/* Выбор периода стоит на месте его названия в шапке свода */
.period-select {
  font-size: 13px;
  font-weight: 600;
  padding: 3px 6px;
  max-width: 160px;
}

/* ---------------------------------------------------------------- P&L */
.views a + a { margin-left: 0; }
.pnl-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg a {
  padding: 5px 10px;
  color: var(--fg);
  text-decoration: none;
  font-size: 13px;
  background: var(--panel);
}
.seg a + a { border-left: 1px solid var(--line); }
.seg a.active { background: var(--accent); color: #fff; }
.badge {
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(127, 127, 127, .15);
  color: var(--muted);
  font-size: 13px;
}
.center { text-align: center; }

table.pnl tbody + tbody .period-row th { border-top-width: 2px; }
table.pnl .line-revenue td,
table.pnl .line-gm1 td,
table.pnl .line-gp3 td,
table.pnl .line-ebitda td { font-weight: 600; }
table.pnl .line-ebitda td { border-bottom: 2px solid var(--line); }
table.pnl .kind-sub td { color: var(--muted); font-size: 13px; }
table.pnl .kind-sub td.sticky-col { padding-left: 24px; }
table.pnl .kind-pct td { color: var(--muted); font-size: 13px; font-style: italic; }
table.pnl .kind-pct td.sticky-col { padding-left: 24px; }

.settings { margin: 14px 0; max-width: 980px; }
.settings summary { margin-bottom: 8px; }
.sga-form { display: block; }
.sga-table { min-width: 0; margin-bottom: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.sga-table td, .sga-table th { padding: 6px 10px; }
.sga-table .exclude { display: flex; flex-wrap: wrap; gap: 4px 12px; white-space: normal; }

/* Поля ввода в таблицах */
input.num-input, input.text-input {
  width: 120px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
input.text-input { text-align: left; }
input.text-input.wide { width: 260px; }
input.num-input.small { width: 64px; }
input.num-input:hover, input.text-input:hover { border-color: var(--line); }
input.num-input:focus, input.text-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
}
input.num-input:disabled, input.text-input:disabled { color: var(--fg); }
input.is-error { border-color: #d14343 !important; background: rgba(209, 67, 67, .08); }
.pnl-toolbar input.num-input { border-color: var(--line); background: var(--panel); }
td.input-cell { padding: 2px 4px; }
.cogs-table td, .staff-table td { padding-top: 4px; padding-bottom: 4px; }
.cogs-table select, .staff-table select { padding: 3px 6px; font-size: 13px; }
.muted-num { color: var(--muted); }
.group-row th { border-bottom: none; }
.save-state { color: var(--muted); font-size: 13px; }
.save-state.is-error { color: #d14343; }

.cost-cell.override { background: rgba(230, 160, 30, .14); cursor: pointer; }
.cost-cell.override::after { content: " ✎"; font-size: 11px; color: #c07a00; }

button.icon { padding: 2px 8px; font-size: 12px; }
.add-row { margin: 10px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.add-row input.text-input { border-color: var(--line); background: var(--panel); }

/* Вход и пользователи */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-card {
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
  width: 320px; padding: 24px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px;
}
.login-card h1 { font-size: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; }
.login-card input { font-family: inherit; font-size: 15px; }
.user-chip { font-size: 13px; color: var(--muted); white-space: nowrap; }
.user-form { flex-wrap: wrap; gap: 8px; }
.users-table td { white-space: normal; }
.sbu-boxes { display: flex; flex-wrap: wrap; gap: 4px 10px; }
input.text-input.bordered { border-color: var(--line); background: var(--panel); width: 180px; }
.closed-mark {
  margin-left: 6px; padding: 1px 5px; border-radius: 4px;
  background: rgba(40, 160, 90, .16); color: #1f7a45; font-size: 11px; font-weight: 600;
  text-transform: none; letter-spacing: 0;
}
input.num-input.tiny { width: 44px; }
input.num-input.bordered { border-color: var(--line); background: var(--panel); }
input.num-input::placeholder { color: var(--muted); opacity: .75; }
td.manual input.num-input { color: #1f7a45; font-weight: 600; }
.adjustment-row td { background: rgba(108, 155, 255, .06); }
.adj-title { display: flex; align-items: center; gap: 6px; }
.adj-mark {
  padding: 1px 5px; border-radius: 4px; font-size: 11px; font-weight: 600;
  background: rgba(108, 155, 255, .2); color: var(--accent);
}
.add-caption { font-size: 14px; align-self: center; }
.staff-table select { max-width: 130px; }
.staff-table input.num-input.small { width: 72px; }

/* ------------------------------------------------------- боковое меню */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 210px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 8px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 20;
  overflow: hidden;
  transition: width .15s ease;
}
body:has(.sidebar) { padding-left: 226px; transition: padding-left .15s ease; }
body:has(.sidebar.collapsed) { padding-left: 72px; }
.sidebar.collapsed { width: 56px; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 0 0 10px 8px; }
.sidebar-brand { font-weight: 600; font-size: 16px; white-space: nowrap; }
.sidebar-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; flex: none;
  border: none; background: none; color: var(--muted);
}
.sidebar-toggle:hover { color: var(--fg); background: rgba(127, 127, 127, .1); }
.sidebar-toggle .nav-icon { transition: transform .15s ease; }
.sidebar.collapsed .sidebar-toggle .nav-icon { transform: rotate(180deg); }
.sidebar.collapsed .sidebar-head { padding-left: 0; justify-content: center; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.nav-icon { flex: none; }
.side-nav a:hover { background: rgba(127, 127, 127, .1); }
.side-nav a.active { background: var(--accent); color: #fff; }
.side-nav-bottom { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
.side-nav-bottom a { font-size: 13px; color: var(--muted); }
.sidebar.collapsed .nav-label { display: none; }
.sidebar.collapsed .side-nav a { justify-content: center; padding: 8px 0; }

@media (prefers-reduced-motion: reduce) {
  .sidebar, body:has(.sidebar), .sidebar-toggle .nav-icon { transition: none; }
}

@media (max-width: 800px) {
  .sidebar, .sidebar.collapsed {
    position: static;
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px;
  }
  body:has(.sidebar), body:has(.sidebar.collapsed) { padding-left: 16px; }
  .sidebar-head { padding: 0 4px 0 4px; }
  .sidebar-toggle { display: none; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .side-nav-bottom { margin-top: 0; padding-top: 0; border-top: none; }
}

/* Кнопки-переключатели (год, период) */
.topbar .seg a { font-size: 14px; }
.seg a:hover:not(.active) { background: rgba(127, 127, 127, .1); }
button.link-btn.plain { border: none; background: none; padding: 0; cursor: pointer; }

/* ------------------------------------------- настраиваемые колонки */
.cols-ready thead th:not(.sticky-col) { position: relative; }
.col-resize {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
  touch-action: none;
}
.col-resize:hover, .col-resizing .col-resize:active { background: var(--accent); opacity: .5; }
body.col-resizing { cursor: col-resize; user-select: none; }
th.col-movable { cursor: grab; }
th.col-dragging { opacity: .45; }
th.drop-before { box-shadow: inset 3px 0 0 var(--accent); }
th.drop-after { box-shadow: inset -3px 0 0 var(--accent); }

/* ------------------------------------- боковая панель: срезы, обновление, вход */
.side-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  min-height: 0;
  flex: 1 1 auto;
}
.side-title {
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em;
}
.side-title .nav-icon { width: 16px; height: 16px; }
.snapshot-list {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto; min-height: 0; flex: 0 1 auto;
}
.snapshot-list li { display: flex; align-items: center; border-radius: 6px; }
.snapshot-list li:hover { background: rgba(127, 127, 127, .1); }
.snapshot-list li.active { background: rgba(108, 155, 255, .16); }
.snapshot-list li.active .snapshot-title { color: var(--accent); font-weight: 600; }
.snapshot-list a {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  padding: 5px 10px; color: var(--fg); text-decoration: none;
}
.snapshot-title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snapshot-date { font-size: 11px; color: var(--muted); }
.snapshot-list form { display: block; }
.snapshot-delete {
  border: none; background: none; color: var(--muted); padding: 2px 8px; font-size: 12px; visibility: hidden;
}
.snapshot-list li:hover .snapshot-delete { visibility: visible; }
.snapshot-delete:hover { color: #d14343; }
.snapshot-save { display: flex; flex-wrap: nowrap; gap: 4px; padding: 0 2px; }
.sidebar input.snapshot-name { width: 100%; min-width: 0; font-size: 13px; padding: 5px 7px; }
.snapshot-save button { display: flex; align-items: center; padding: 4px 6px; }
.snapshot-save .nav-icon { width: 16px; height: 16px; }
.side-actions { display: flex; flex-direction: column; gap: 4px; }
.side-actions form, .side-nav-bottom form { display: block; }
.side-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 10px; border: 1px solid transparent; border-radius: 6px;
  background: none; color: var(--fg); font-size: 13px; text-align: left; white-space: nowrap;
}
.side-btn:hover:not([disabled]) { background: rgba(127, 127, 127, .1); }
.side-btn.primary { background: var(--accent); color: #fff; }
.side-btn.primary:hover:not([disabled]) { background: var(--accent); filter: brightness(1.08); }
.side-btn.primary[disabled] { background: rgba(127, 127, 127, .15); color: var(--muted); opacity: 1; }
.side-btn small, .side-user small { display: block; font-size: 11px; opacity: .8; }
.side-user {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  font-size: 13px; color: var(--fg); white-space: nowrap; overflow: hidden;
}
.side-user .nav-label { overflow: hidden; text-overflow: ellipsis; }
.side-nav-bottom { margin-top: 10px; }
.sidebar.collapsed .side-title { justify-content: center; padding: 0; }
.sidebar.collapsed .side-btn, .sidebar.collapsed .side-user { justify-content: center; padding: 8px 0; }
.sidebar.collapsed .snapshot-list,
.sidebar.collapsed .snapshot-save { display: none; }
.sidebar { overflow-y: auto; }

/* ------------------------------------------------ сделки и проекты */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; color: var(--muted);
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.pnl-toolbar .push-right { margin-left: auto; }
.grid-table thead th { position: relative; vertical-align: bottom; }
.grid-table thead th.sticky-col { position: sticky; }
.grid-table .head-row th { white-space: nowrap; }
.sort-btn {
  border: none; background: none; padding: 0; color: inherit; font: inherit;
  text-transform: inherit; letter-spacing: inherit; cursor: pointer; white-space: nowrap;
}
.sort-btn:hover { color: var(--accent); }
.sort-arrow { color: var(--accent); }
.filter-row th { padding: 4px 6px; background: var(--panel); }
input.filter-input {
  width: 100%; min-width: 60px; padding: 3px 6px; font: 12px/1.3 inherit; font-family: inherit;
  text-transform: none; letter-spacing: 0;
}
input.filter-input.num { text-align: right; }
.filter-btn {
  width: 100%; min-width: 60px; padding: 3px 6px; font-size: 12px; text-align: left;
  color: var(--muted); text-transform: none; letter-spacing: 0; white-space: nowrap;
}
.filter-btn.active { color: var(--accent); border-color: var(--accent); }
.filter-pop {
  position: fixed; z-index: 60; min-width: 200px; max-height: 320px; overflow-y: auto;
  padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.filter-pop label {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 5px;
  font-size: 14px; color: var(--fg); cursor: pointer; white-space: nowrap;
}
.filter-pop label:hover { background: rgba(127, 127, 127, .12); }
.filter-pop .select-all { font-weight: 600; }
.title-cell { display: flex; align-items: center; gap: 6px; min-width: 0; }
.title-cell .clip-title { display: block; }
.cell-in { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.fact-mark {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; padding: 0; border: none; border-radius: 4px;
  background: rgba(40, 160, 90, .18); color: #1f7a45; font-size: 11px; font-weight: 700; line-height: 1;
}
button.fact-mark { cursor: pointer; }
button.fact-mark:hover { background: #1f7a45; color: #fff; }
@media (prefers-color-scheme: dark) { .fact-mark { color: #5fd08f; } }
.grid-table td.manual { color: #1f7a45; font-weight: 600; }
.flash-row td { animation: flash 2s ease-out; }
@keyframes flash { from { background: rgba(108, 155, 255, .3); } to { background: transparent; } }

.cols-dialog {
  width: min(420px, calc(100vw - 32px)); max-height: 80vh; padding: 18px;
  background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 12px;
}
.cols-dialog::backdrop { background: rgba(0, 0, 0, .35); }
.cols-dialog form { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.cols-dialog h2 { margin: 0; font-size: 17px; }
.cols-dialog p { margin: 0; }
.cols-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; max-height: 55vh; border: 1px solid var(--line); border-radius: 8px; }
.cols-list li { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-bottom: 1px solid var(--line); background: var(--panel); }
.cols-list li:last-child { border-bottom: none; }
.cols-list li.dragging { opacity: .4; }
.cols-list li.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.cols-list li.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.cols-list label { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--fg); font-size: 14px; cursor: pointer; }
.drag-handle { cursor: grab; color: var(--muted); letter-spacing: -2px; user-select: none; }
.cols-actions { display: flex; gap: 8px; margin-top: 4px; }
.cols-actions .push-right { margin-left: auto; }
.title-cell input.text-input { width: 240px; }

/* -------------------- сделки: закреплённая шапка, фильтры, тона блоков */
.grid-wrap { max-height: calc(100vh - 150px); overflow: auto; }
.grid-table thead { position: sticky; top: 0; z-index: 4; }
.grid-table thead th { background-color: var(--panel); }
.grid-table thead .totals-row th { background-color: var(--totals-bg); box-shadow: inset 0 -1px 0 var(--line); }
.grid-table thead th.sticky-col { z-index: 5; }
.th-in { display: flex; align-items: center; gap: 4px; }
.grid-table th.num .th-in { justify-content: flex-end; }
.filter-icon {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; padding: 0; border: none; border-radius: 4px;
  background: none; color: var(--muted); opacity: .55;
}
.filter-icon:hover { opacity: 1; color: var(--accent); background: rgba(127, 127, 127, .12); }
.filter-icon.active { opacity: 1; color: #fff; background: var(--accent); }
.filter-pop { min-width: 260px; max-height: none; overflow: visible; padding: 10px; }
.pop-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.pop-row { display: flex; gap: 6px; align-items: center; }
.filter-pop input.text-input { width: 220px; font-size: 13px; text-align: left; }
.pop-btn { width: 30px; height: 30px; padding: 0; font-size: 14px; line-height: 1; flex: none; }
.pop-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.pop-error { margin-top: 6px; font-size: 12px; color: #d14343; }

/* Блоки колонок — разные тона фона, чтобы не сливались */
:root {
  --t-rev: rgba(47, 111, 235, .06);
  --t-cogs: rgba(230, 120, 30, .07);
  --t-wrev: rgba(30, 160, 150, .07);
  --t-wcogs: rgba(190, 80, 140, .06);
  --t-wrev-h: rgba(100, 80, 220, .07);
  --t-wcogs-h: rgba(200, 160, 20, .08);
  --t-gm1: rgba(40, 160, 90, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --t-rev: rgba(108, 155, 255, .08);
    --t-cogs: rgba(255, 150, 60, .08);
    --t-wrev: rgba(60, 210, 190, .08);
    --t-wcogs: rgba(240, 110, 180, .08);
    --t-wrev-h: rgba(150, 130, 255, .1);
    --t-wcogs-h: rgba(240, 200, 60, .08);
    --t-gm1: rgba(80, 210, 130, .09);
  }
}
.grid-table [data-grp="rev"] { background-image: linear-gradient(var(--t-rev), var(--t-rev)); }
.grid-table [data-grp="cogs"] { background-image: linear-gradient(var(--t-cogs), var(--t-cogs)); }
.grid-table [data-grp="wrev"] { background-image: linear-gradient(var(--t-wrev), var(--t-wrev)); }
.grid-table [data-grp="wcogs"] { background-image: linear-gradient(var(--t-wcogs), var(--t-wcogs)); }
.grid-table [data-grp="wrev-h"] { background-image: linear-gradient(var(--t-wrev-h), var(--t-wrev-h)); }
.grid-table [data-grp="wcogs-h"] { background-image: linear-gradient(var(--t-wcogs-h), var(--t-wcogs-h)); }
.grid-table [data-grp="gm1"] { background-image: linear-gradient(var(--t-gm1), var(--t-gm1)); }
.grid-table tbody tr:hover td { background-color: rgba(127, 127, 127, .07); }

/* -------------------------------------------------------- экран «Срезы» */
.side-spacer { flex: 1 1 auto; }
.page-title { font-size: 18px; margin: 4px 0 12px; }
.panel-card {
  max-width: 820px; margin-bottom: 12px; padding: 12px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.panel-card h3 { margin: 0 0 4px; font-size: 15px; }
.panel-card p { margin: 0 0 10px; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.snapshots-wrap { max-width: 820px; }
.snapshots-table .row-actions { display: flex; gap: 12px; align-items: center; justify-content: flex-end; }
.snapshots-table .row-actions form { display: inline-flex; }
.selected-row td { background: rgba(108, 155, 255, .08); }
.snapshots-table .badge { margin-left: 6px; font-size: 11px; }
.panel-card, .snapshots-wrap { max-width: 980px; }
input.text-input.snapshot-name-input { width: 320px; }
/* Закреплённая колонка названия всегда непрозрачная */
.grid-table tbody td.sticky-col,
.grid-table tbody tr:hover td.sticky-col { background-color: var(--panel); }
.grid-table tbody tr.adjustment-row td.sticky-col {
  background: linear-gradient(rgba(108, 155, 255, .1), rgba(108, 155, 255, .1)), var(--panel);
}
@media (prefers-color-scheme: dark) {
  :root {
    --t-rev: rgba(108, 155, 255, .11);
    --t-cogs: rgba(255, 150, 60, .1);
    --t-wrev: rgba(60, 210, 190, .1);
    --t-wcogs: rgba(240, 110, 180, .1);
    --t-wrev-h: rgba(150, 130, 255, .12);
    --t-wcogs-h: rgba(240, 200, 60, .1);
    --t-gm1: rgba(80, 210, 130, .11);
  }
}
.section-title { font-size: 15px; margin: 18px 0 8px; }
.panel-gap { margin-bottom: 14px; }
.panel-card .sga-table { margin-bottom: 10px; }
.account-card { max-width: 420px; }
.account-card .stack { max-width: none; margin: 0; }
.account-card input.text-input { width: 100%; font-family: inherit; text-align: left; }
a.side-user { text-decoration: none; border-radius: 6px; }
a.side-user:hover { background: rgba(127, 127, 127, .1); }
a.side-user.active { background: var(--accent); color: #fff; }
.account-card input[type="password"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg); font: 14px/1.4 inherit; font-family: inherit;
}
.account-card input[type="password"]:focus { outline: none; border-color: var(--accent); }
.account-card .stack label { color: var(--muted); }

/* Все цифры — помельче (как в полях ввода) */
td.num, th.num, .num { font-size: 13px; }
table.pnl td.num { font-size: 13px; }
input.num-input { font-size: 13px; }

/* Фильтр со списком значений */
.pop-list { max-height: 300px; overflow-y: auto; margin-bottom: 6px; }
.pop-list label {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 5px;
  font-size: 13px; color: var(--fg); cursor: pointer; white-space: nowrap;
}
.pop-list label:hover { background: rgba(127, 127, 127, .12); }
.pop-list .select-all { font-weight: 600; }
.pop-buttons { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.filter-pop input.text-input { width: 240px; }
.top-check { font-size: 13px; }
.grid-filter-state { white-space: nowrap; }
.grid-table td.center input[type="checkbox"] { margin: 0; }
.staff-table select { padding: 3px 6px; font-size: 13px; max-width: 140px; }
/* Персонал: тона блоков */
.grid-table [data-grp="fot"] { background-image: linear-gradient(var(--t-rev), var(--t-rev)); }
.grid-table [data-grp="bonus"] { background-image: linear-gradient(var(--t-cogs), var(--t-cogs)); }
.grid-table [data-grp="extra"] { background-image: linear-gradient(var(--t-wrev), var(--t-wrev)); }
.grid-table [data-grp="cost"] { background-image: linear-gradient(var(--t-wcogs), var(--t-wcogs)); }
.grid-table [data-grp="cost-h"] { background-image: linear-gradient(var(--t-wrev-h), var(--t-wrev-h)); }
.grid-table [data-grp="fact"] { background-image: linear-gradient(var(--t-gm1), var(--t-gm1)); }
.grid-table [data-grp="plv"] { background-image: linear-gradient(rgba(108, 155, 255, .16), rgba(108, 155, 255, .16)); }
.sga-table input.sga-sbu { width: 110px; }
.sga-table td.sga-warn { color: #d14343; font-weight: 600; }
.panel-card .table-wrap { margin-bottom: 10px; }
/* P&L: Total выделен фоном */
table.pnl .total-col { background-color: rgba(108, 155, 255, .12); }
table.pnl thead .total-col, table.pnl .period-row th.total-col { background-color: rgba(108, 155, 255, .2); }
.export-cols { display: flex; gap: 16px; flex-wrap: wrap; }
.export-cols fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; flex: 1; min-width: 160px; }
.export-cols legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.export-cols .check { padding: 3px 0; color: var(--fg); font-size: 14px; }
.fact-mark.manual-mark { background: rgba(108, 155, 255, .2); color: var(--accent); font-weight: 400; }
button.fact-mark.manual-mark:hover { background: var(--accent); color: #fff; }
.closed-row { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; font-size: 14px; }
.closed-row .check { color: var(--fg); }
.sga-cell .check { flex-direction: column; gap: 2px; font-size: 12px; }
.grid-table [data-grp="qcoef"] { background-image: linear-gradient(var(--t-wcogs-h), var(--t-wcogs-h)); }
.steps { margin: 4px 0 10px; padding-left: 20px; font-size: 14px; }
.steps li { margin: 4px 0; }
a.bookmarklet {
  display: inline-block; padding: 3px 10px; border-radius: 6px; background: var(--accent); color: #fff;
  text-decoration: none; font-weight: 600; cursor: grab;
}
.renew-token { margin-top: 8px; }
.renew-token button { font-size: 12px; padding: 3px 8px; }
.crm-session { margin-top: 10px; }
.crm-session summary { font-size: 14px; }
.crm-session .stack { max-width: 640px; margin: 8px 0; }

/* ------------------------------------------------------ сравнение срезов */
.compare-form select { max-width: 280px; }
.compare-form select.is-active { border-color: var(--accent); color: var(--accent); }
.bridge-col { background-color: rgba(127, 127, 127, .08); }
table.pnl thead .bridge-col, table.pnl .period-row th.bridge-col { background-color: rgba(127, 127, 127, .16); }
.bridge-pos { color: #1f9d55; white-space: nowrap; }
.bridge-neg { color: #d14343; white-space: nowrap; }
.bridge-mark { font-size: 10px; margin-right: 3px; }
@media (prefers-color-scheme: dark) { .bridge-pos { color: #4fd18b; } .bridge-neg { color: #ff7a7a; } }
.grid-table [data-grp="bridge"] { background-image: linear-gradient(rgba(127,127,127,.1), rgba(127,127,127,.1)); }
.only-cmp { margin-left: 6px; padding: 1px 5px; border-radius: 4px; font-size: 11px; background: rgba(209,67,67,.15); color: #d14343; white-space: nowrap; }
.only-cmp-row td { opacity: .75; }
