:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --card: #ffffff;
  --line: #d9e0ea;
  --text: #1f2937;
  --muted: #64748b;
  --accent: #7c3aed;
  --accent-soft: #ede9fe;
  --ok: #15803d;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }

body { margin: 0; background: var(--bg); color: var(--text); }

/* 1600px — общая ширина всех страниц с вкладочной шапкой (tests/reportPageContainerWidth):
   своё число здесь заставляло контент прыгать при переходе по вкладкам. */
.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.hero, .filters, .stats, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.hero { padding: 24px 28px; margin-bottom: 16px; }
.hero h1 { margin: 0 0 8px; font-size: 30px; line-height: 1.1; }
.hero p { margin: 0; color: var(--muted); max-width: 920px; line-height: 1.5; }

.filters { padding: 16px 20px; margin-bottom: 16px; }
.filters form { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.field input, .field select {
  height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 14px; background: #fff; color: var(--text);
}
.field select { min-width: 180px; cursor: pointer; }

.actions { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.btn {
  height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; text-decoration: none;
}
.btn:hover { border-color: #b9c3d1; }
.btn[disabled] { opacity: .55; cursor: default; }
/* вторичные кнопки — тёмный текст, иначе ссылка JSON читается фиолетовой */
a.btn { color: var(--text); }
a.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { border-color: var(--accent); }
a.btn-primary { color: #fff; }

.error {
  display: none; margin-bottom: 16px; padding: 12px 16px;
  border: 1px solid #fecaca; border-radius: 10px; background: #fef2f2; color: #b91c1c;
}

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; padding: 16px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
/* Специфичность выше темы (она задаёт .stat-value 30px): девятизначная сумма
   в 30px рвёт плитку и отрывает ₽ на вторую строку. */
.stats .stat .stat-value {
  margin-top: 6px; font-weight: 800; letter-spacing: -.02em;
  font-size: clamp(20px, 1.7vw, 26px); line-height: 1.15;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.stat-sub { margin-top: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.stat-sub:empty { display: none; }

.panel { padding: 0; }
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 16px; }
.meta { font-size: 12px; color: var(--muted); text-align: right; }

.table-wrap { overflow: auto; max-height: 70vh; }

table { width: 100%; min-width: 900px; border-collapse: collapse; font-size: 13.5px; }
thead th {
  position: sticky; top: 0; background: #f7f8fa; z-index: 2;
  padding: 10px 12px; text-align: right; white-space: nowrap;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  box-shadow: inset 0 -1px 0 var(--line);
}
thead th.l { text-align: left; }

tbody td { padding: 9px 12px; text-align: left; border-bottom: 1px solid #eef1f6; white-space: nowrap; }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody td.amount { font-weight: 700; }
tbody td.l { white-space: normal; max-width: 420px; }
tbody td.dim { color: var(--muted); white-space: nowrap; }
tbody tr:hover td { background: #faf9ff; }

/* Липкой строку группы не делаем: все tr лежат в одном tbody, поэтому sticky
   их не сменяет, а копит — на длинном списке получается полоса из шести
   прилипших шапок, которая прячет две строки заказов. */
tr.manager td {
  background: #f7f8fa; font-weight: 700;
  border-bottom: 1px solid var(--line); border-top: 1px solid var(--line);
}
tr.manager td.l { font-size: 14px; }
tr.manager:hover td { background: #f7f8fa; }
/* «без менеджера» — не человек, а дырка в данных: платить по этой строке некому */
tr.manager.no-manager td { background: #fff7ed; color: #9a3412; }
tr.manager.no-manager:hover td { background: #fff7ed; }

tr.total td { background: #f1f5f9; font-weight: 700; border-top: 2px solid var(--line); }
tr.total:hover td { background: #f1f5f9; }

tr.empty-row td, tr.loading-row td {
  padding: 22px 18px; color: var(--muted); text-align: left; white-space: normal;
}
tr.empty-row strong { color: var(--text); }
.access-actions { margin-top: 12px; }

td a { color: var(--accent); font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }

.muted { color: var(--muted); font-weight: 400; }
.zero { color: #94a3b8; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* «К выплате» — главная цифра отчёта, не оставляем её одну в полупустом ряду */
  .stats .stat:last-child { grid-column: 1 / -1; }
  .panel-head { flex-direction: column; align-items: flex-start; }
  .meta { text-align: left; }
}

@media (max-width: 640px) {
  .page { padding: 18px 12px 28px; }
  .hero { padding: 18px 16px; }
  .hero h1 { font-size: 24px; }
  .stats { grid-template-columns: 1fr; }
  .filters form { flex-direction: column; align-items: stretch; }
  .field select { width: 100%; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .actions .btn { justify-content: center; }
  /* max-height НЕ снимаем: .table-wrap остаётся overflow:auto в любом случае,
     и без своей высоты он просто уезжает со страницей — вместе с sticky-шапкой. */
}
