:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e3e6eb;
  --text: #191919; --text-2: #666666; --accent: #257de0; --accent-text: #1b64be;
  --good: #0a7d1d; --good-bg: #e6f4e8; --bad: #c62f30; --bad-bg: #fde9e9; --warn: #9a6400; --warn-bg: #fff4da;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111111; --surface: #191919; --surface-2: #222222; --border: #2e2e2e;
    --text: #efefef; --text-2: #9c9c9c; --accent: #338ced; --accent-text: #84b9f3;
    --good: #4cc25f; --good-bg: #13301a; --bad: #f07a7b; --bad-bg: #3a1717; --warn: #f2b84b; --warn-bg: #3a2c0c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111111; --surface: #191919; --surface-2: #222222; --border: #2e2e2e;
  --text: #efefef; --text-2: #9c9c9c; --accent: #338ced; --accent-text: #84b9f3;
  --good: #4cc25f; --good-bg: #13301a; --bad: #f07a7b; --bad-bg: #3a1717; --warn: #f2b84b; --warn-bg: #3a2c0c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--text-2); font-weight: 600; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.mt { margin-top: 24px; }
.r { text-align: right; white-space: nowrap; }
.err-text { color: var(--bad); }

/* шапка */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand a { font-weight: 700; color: var(--text); font-size: 16px; }
.brand span { color: var(--text-2); font-weight: 500; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--text-2); }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.tools { display: flex; align-items: center; gap: 8px; }
.sync { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.sync.err { color: var(--bad); }

.btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; display: inline-block; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.icon { padding: 6px 9px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { border-color: transparent; }

.banner { padding: 10px 20px; font-size: 13px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.err { background: var(--bad-bg); color: var(--bad); }
.card .banner { border-radius: 8px; margin: 8px 0; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 20px; }
.foot { text-align: center; color: var(--text-2); font-size: 12px; padding: 24px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 + section { margin-top: 16px; }

/* вывод и плитки */
.lead-summary { font-size: 17px; margin: 0 0 16px; max-width: 70ch; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { color: var(--text-2); font-size: 13px; }
.tile-value { font-size: 28px; font-weight: 650; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.delta { font-size: 12px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.delta.up-good { color: var(--good); }
.delta.up-bad { color: var(--bad); }
.delta.neutral, .delta.flat { color: var(--text-2); }
.small-tiles { margin-bottom: 16px; }

.badge { display: inline-block; min-width: 22px; padding: 0 7px; border-radius: 11px; font-size: 12px; text-align: center;
  background: var(--surface-2); color: var(--text-2); font-weight: 600; }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 11px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.more { font-size: 12px; font-weight: 500; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .date { color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; margin-right: 6px; white-space: nowrap; }

/* проекты */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.project header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.project header h2 { margin: 0; flex: 1; }
.project.closed { opacity: .7; }
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.row-stats { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; margin: 8px 0 12px; color: var(--text-2); }
.row-stats b { color: var(--text); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
details { margin-top: 10px; font-size: 13px; }
summary { cursor: pointer; color: var(--bad); }

/* фильтры и таблицы */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { flex: 1 1 260px; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; }
.check, .inline-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card .table-wrap { border: 0; border-radius: 0; }
table.dt { width: 100%; border-collapse: collapse; font-size: 13px; }
.dt th, .dt td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.dt th { font-weight: 600; color: var(--text-2); background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
.dt th.r, .dt td.r { text-align: right; }
.dt th[data-sort] { cursor: pointer; user-select: none; }
.dt th.asc::after { content: " ▲"; font-size: 10px; }
.dt th.desc::after { content: " ▼"; font-size: 10px; }
.dt tbody tr:hover { background: var(--surface-2); }
.dt tfoot td { font-weight: 600; border-bottom: 0; }
.dt td { font-variant-numeric: tabular-nums; }
.idle-bad { color: var(--bad); font-weight: 600; }
.st { font-size: 12px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); white-space: nowrap; }
.st-in_progress { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-text); }
.st-done { background: var(--good-bg); color: var(--good); }
.st-lost { background: var(--bad-bg); color: var(--bad); }
.st-tender { background: var(--warn-bg); color: var(--warn); }
tr.sem-S td, tr.sem-F td { color: var(--text-2); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 5px 12px; border-radius: 8px; border: 1px solid var(--border); color: var(--text-2); background: var(--surface); }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs.inline { margin: 0 0 0 auto; font-size: 12px; font-weight: 400; }
.tabs.inline a { padding: 2px 8px; }

.chart-box { position: relative; width: 100%; min-height: 120px; }

.timeline h2 { font-size: 14px; color: var(--text-2); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 16px 0; }

.digest-body { white-space: pre-wrap; font-size: 14px; line-height: 1.6; }

/* вход */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); }

@media (max-width: 720px) {
  .top { padding: 8px 12px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .tools { margin-left: auto; }
  .sync { display: none; }
  .wrap { padding: 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile-value { font-size: 22px; }
  .kv { grid-template-columns: 100px 1fr; }
}
@media (forced-colors: active) { .progress span { background: Highlight; } }
