:root {
  --bg: #f5f6f8; --card: #ffffff; --ink: #14171f; --muted: #646b7a; --line: #e3e6ec; --soft: #f0f2f6;
  --accent: #2457d6; --accent-ink: #ffffff; --good: #138a4a; --bad: #c8322b; --warn: #b26a00;
  --good-bg: #e7f5ed; --bad-bg: #fbeaea; --warn-bg: #fdf3e2; --chip: #eef2fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --r: 12px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --card: #171b23; --ink: #e9ecf2; --muted: #9aa2b2; --line: #272d39; --soft: #1d222c;
    --accent: #6b93ff; --accent-ink: #0b1020; --good: #3ccb7f; --bad: #ff6b63; --warn: #f0a640;
    --good-bg: #13291d; --bad-bg: #331a19; --warn-bg: #33270f; --chip: #1f2636; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --card: #171b23; --ink: #e9ecf2; --muted: #9aa2b2; --line: #272d39; --soft: #1d222c;
  --accent: #6b93ff; --accent-ink: #0b1020; --good: #3ccb7f; --bad: #ff6b63; --warn: #f0a640;
  --good-bg: #13291d; --bad-bg: #331a19; --warn-bg: #33270f; --chip: #1f2636; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0); }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.num, td.n, .kpi .v { font-variant-numeric: tabular-nums; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px)); background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; white-space: nowrap; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8'/%3E%3C/svg%3E"); }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 7px 11px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.nav a:hover { background: var(--soft); color: var(--ink); }
.nav a.on { background: var(--chip); color: var(--accent); font-weight: 600; }
.top-actions { display: flex; gap: 6px; margin-left: auto; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 20px; }
h1 { font-size: 22px; margin: 4px 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpi .l { color: var(--muted); font-size: 12.5px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; white-space: nowrap; }
.kpi .h { color: var(--muted); font-size: 12px; margin-top: 2px; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.est { color: var(--warn); font-weight: 600; cursor: help; }
.two { grid-template-columns: 1.35fr 1fr; margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn { border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 9px; cursor: pointer; text-decoration: none;
  color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=password], input[type=number], select, textarea {
  border: 1px solid var(--line); background: var(--card); border-radius: 9px; padding: 8px 10px; width: 100%; }
label.f { display: block; margin-bottom: 12px; }
label.f span { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }

.leak { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.leak:first-child { border-top: 0; }
.leak .t { font-weight: 600; }
.leak .amt { font-weight: 700; text-align: right; white-space: nowrap; color: var(--bad); }
.leak .why { color: var(--muted); grid-column: 1 / -1; }
.leak .adv { grid-column: 1 / -1; }
.leak .acts { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: var(--chip); color: var(--accent); margin-right: 6px; font-weight: 600; }
.tag.in_work { background: var(--warn-bg); color: var(--warn); }
.tag.ignored { background: var(--soft); color: var(--muted); }
.todo { counter-reset: t; list-style: none; padding: 0; margin: 0; }
.todo li { counter-increment: t; position: relative; padding: 10px 0 10px 38px; border-top: 1px solid var(--line); }
.todo li:first-child { border-top: 0; }
.todo li::before { content: counter(t); position: absolute; left: 0; top: 10px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 13px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--soft); font-weight: 600; color: var(--muted); cursor: pointer; user-select: none; font-size: 12px; }
th.n, td.n { text-align: right; }
th.sorted { color: var(--accent); }
tr:hover td { background: var(--soft); }
tfoot td { font-weight: 700; background: var(--soft); }
td.ph { width: 46px; padding: 4px 6px; }
td.ph img, td.ph .noimg { width: 34px; height: 45px; border-radius: 5px; object-fit: cover; background: var(--soft); display: block; }
td .vc { font-weight: 600; } td .ttl { color: var(--muted); font-size: 12px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 7px 12px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--chip); color: var(--accent); font-weight: 600; }

.alert { border-radius: 10px; padding: 10px 14px; margin: 12px 20px 0; border: 1px solid; }
.alert.warn { background: var(--warn-bg); border-color: transparent; color: var(--ink); }
.alert.bad { background: var(--bad-bg); border-color: transparent; }
.alert.info { background: var(--chip); border-color: transparent; }
#banner .alert { max-width: 1200px; margin-left: auto; margin-right: auto; }
.cats { list-style: none; padding: 0; margin: 10px 0 0; }
.cats li { display: flex; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.cats li:first-child { border-top: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: none; }
.dot.ok { background: var(--good); } .dot.no { background: var(--bad); } .dot.opt { background: var(--warn); }
.progress { height: 10px; border-radius: 99px; background: var(--soft); overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.chart-box { position: relative; height: 240px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.empty { color: var(--muted); padding: 22px 0; text-align: center; }

.modal { position: fixed; inset: 0; background: rgba(10, 12, 18, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--card); border-radius: 14px; padding: 20px; width: min(560px, 100%); max-height: 88vh; overflow: auto; position: relative; border: 1px solid var(--line); }
.modal-x { position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }
.kv { width: 100%; } .kv td { border-bottom: 1px dashed var(--line); padding: 6px 4px; white-space: normal; } .kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.formula { background: var(--soft); padding: 10px 12px; border-radius: 9px; margin: 8px 0 12px; font-weight: 600; }
.toast { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: calc(100% - 32px); }
.login { max-width: 360px; margin: 10vh auto; }
.wh { font-size: 12px; color: var(--muted); }
details summary { cursor: pointer; color: var(--accent); }

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 820px) {
  .two { grid-template-columns: 1fr; }
  .pulse-two .top5 { order: 2; }
  .top { flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .wrap { padding: 16px; }
  .alert { margin: 10px 16px 0; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .v { font-size: 19px; }
  .card { padding: 14px; }
  h1 { font-size: 19px; }
}
