:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c2230;
  --text-muted: #6b7280;
  --accent: #2f6feb;
  --accent-soft: #eaf1ff;
  --good: #1a8f5e;
  --bad: #d64545;
  --warn: #c98a1d;
  --radius: 10px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.topbar .brand { font-weight: 700; font-size: 16px; }

.topbar nav a {
  margin-right: 16px;
  color: var(--text);
  font-weight: 500;
}
.topbar nav a.active { color: var(--accent); }

.container { padding: 20px 24px 60px; max-width: 1400px; margin: 0 auto; }

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

.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 140px;
  flex: 1 1 140px;
}
.stat-tile .label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.stat-tile .value { font-size: 22px; font-weight: 700; margin-top: 4px; }

.period-nav { display: flex; align-items: center; gap: 10px; margin: 18px 0; flex-wrap: wrap; }
.period-nav .tabs a {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  margin-right: 6px;
}
.period-nav .tabs a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.period-nav .nav-arrow {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.period-nav .label { font-weight: 700; font-size: 16px; margin: 0 6px; }

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

table { border-collapse: collapse; width: 100%; min-width: 1200px; font-size: 13px; }
thead th {
  position: sticky; top: 0;
  background: #fafbfc;
  border-bottom: 2px solid var(--border);
  text-align: left;
  padding: 10px 10px;
  white-space: nowrap;
  font-weight: 600;
  color: var(--text-muted);
}
tbody td { padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover { background: var(--accent-soft); }
tr.total-row td { font-weight: 700; background: #fafbfc; border-top: 2px solid var(--border); }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 26px 0 8px; }

.pct-good { color: var(--good); font-weight: 600; }
.pct-bad { color: var(--bad); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 320px;
}
.login-box h1 { font-size: 18px; margin: 0 0 18px; }
.login-box input[type=password] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
}
.login-box button {
  width: 100%;
  padding: 10px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.login-box .error { color: var(--bad); font-size: 13px; margin-bottom: 10px; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.report-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.report-card h3 { margin: 0 0 4px; font-size: 15px; }
.report-card .date { color: var(--text-muted); font-size: 12px; margin-bottom: 10px; }
.report-card dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; margin: 0; }
.report-card dt { color: var(--text-muted); }
.report-card dd { margin: 0; font-weight: 600; text-align: right; }
.report-card .reasons { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.report-card .reasons-title { color: var(--text-muted); font-size: 12px; margin-bottom: 6px; }
.report-card .reasons ul { margin: 0; padding-left: 18px; }

.sync-btn { padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; font-size: 13px; }
.muted { color: var(--text-muted); font-size: 12px; }

.sync-error-banner {
  display: inline-block;
  margin: 8px 0;
  padding: 8px 12px;
  border: 1px solid var(--bad);
  border-radius: 8px;
  background: #fdecec;
  color: var(--bad);
  font-size: 13px;
}

.hh-badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; margin-left: 6px; }
.hh-badge-active { background: #e3f6ec; color: var(--good); }
.hh-badge-archived { background: #f0f1f3; color: var(--text-muted); }

tr.group-row td {
  background: #f0f2f6;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-muted);
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}

.filter-form { display: flex; gap: 10px; flex-wrap: wrap; margin: 18px 0; }
.filter-form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
.filter-form button {
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#trendChart { max-height: 260px; }

/* ===== Компактный полноэкранный вид (по образцу отчётов Roistat) ===== */
body { font-size: 13px; }
.topbar { padding: 8px 16px; }
.topbar .brand { font-size: 15px; }
.container { max-width: none; padding: 10px 14px 24px; }

.yesterday { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.yesterday b { color: var(--text); }
.yesterday > b:first-child { color: var(--text-muted); font-weight: 600; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px 20px; flex-wrap: wrap; margin: 0 0 8px; }
.toolbar .tb-left, .toolbar .tb-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toolbar .tabs { display: flex; gap: 4px; margin-right: 6px; }
.toolbar .tabs a, .toolbar .nav-arrow {
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: var(--surface); font-size: 12px;
}
.toolbar .tabs a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.toolbar .cut-tabs { margin-left: 14px; }
.toolbar .label { font-weight: 700; font-size: 14px; margin: 0 4px; }
form.inline { display: inline; margin: 0; }
.sync-btn { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.sync-btn-secondary { color: var(--text-muted); }
.sync-status.running { color: var(--accent); font-weight: 600; font-size: 12px; }

.table-scroll { overflow: auto; max-height: calc(100vh - 150px); }
table.dense { min-width: 0; width: 100%; font-size: 12px; border-collapse: separate; border-spacing: 0; }
table.dense thead th {
  position: sticky; top: 0; z-index: 3; padding: 6px 7px; font-size: 11px; line-height: 1.2;
  white-space: nowrap; background: #f3f5f8; border-bottom: 1px solid var(--border);
}
table.dense tbody td { padding: 4px 7px; border-bottom: 1px solid #eef0f3; white-space: nowrap; vertical-align: top; }
table.dense .num { text-align: right; font-variant-numeric: tabular-nums; }
table.dense .zero { color: #b6bcc6; }
table.dense .pc { color: var(--text-muted); font-size: 10.5px; margin-left: 4px; }
table.dense th.closed, table.dense td.closed { border-left: 1px solid #eef0f3; }
table.dense td.closed { white-space: normal; min-width: 92px; }
table.dense td.warn { color: var(--bad); font-weight: 700; }

table.dense .sticky-col { position: sticky; left: 0; z-index: 2; background: var(--surface); }
table.dense thead th.sticky-col { z-index: 4; background: #f3f5f8; text-align: left; }
table.dense td.name { max-width: 300px; min-width: 200px; overflow: hidden; text-overflow: ellipsis; }
table.dense td.child-name { padding-left: 28px; color: var(--text-muted); }
table.dense tr.child-row td { background: #fcfcfd; }
table.dense tr.child-row td.sticky-col { background: #fcfcfd; }
table.dense tr.vac-head td { font-weight: 600; cursor: pointer; }
table.dense tr.vac-head td.num { font-weight: 500; }
table.dense tbody tr.data-row:hover td { background: var(--accent-soft); }

table.dense tr.total-row td { background: #eaf1ff; font-weight: 700; border-bottom: 2px solid #c5d7fb; }
table.dense tr.total-row td.sticky-col { background: #eaf1ff; }

table.dense tr.group-row td { cursor: pointer; user-select: none; padding: 5px 7px; }
table.dense tr.group-row:hover td { background: #e6e9f0; }
.caret { display: inline-block; width: 12px; color: var(--text-muted); }
.hidden-by-group, .hidden-by-parent { display: none; }

td.otklik { position: relative; }
td.otklik .bar { position: absolute; left: 0; top: 2px; bottom: 2px; background: #dbe7fd; z-index: 0; border-radius: 2px; }
td.otklik b { position: relative; z-index: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 2px 3px; margin-top: 2px; justify-content: flex-end; }
.chip { background: #f0f2f6; color: var(--text-muted); border-radius: 4px; padding: 0 4px; font-size: 10px; line-height: 1.5; white-space: nowrap; }
.chip b { color: var(--text); font-weight: 600; }

.legend { margin-top: 8px; max-width: 1200px; line-height: 1.5; }

/* SLA по этапам */
table.sla td.stage { min-width: 92px; }
table.sla .done { font-weight: 600; }
table.sla .n { color: var(--text-muted); font-size: 10.5px; margin-left: 3px; }
table.sla .now { display: block; font-size: 10.5px; color: var(--text-muted); }
table.sla .now.stuck { color: var(--bad); font-weight: 600; }
table.sla td.heat-1 { background: #fff7e6; }
table.sla td.heat-2 { background: #fdebd0; }
table.sla td.heat-3 { background: #fbd9d9; }