:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #f8f9fb;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --good: #0f8a4f;
  --good-bg: #e7f6ee;
  --bad: #c43636;
  --bad-bg: #fdecec;
  --skip: #8a6d1d;
  --skip-bg: #fbf4dd;
  --new-bg: #eef0f3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a20;
    --ink: #e8eaee;
    --muted: #9097a3;
    --line: #262a33;
    --soft: #1c2028;
    --accent: #5b7fff;
    --good: #3fcf86;
    --good-bg: #13291f;
    --bad: #ff7272;
    --bad-bg: #2e1717;
    --skip: #e2c15a;
    --skip-bg: #2a2412;
    --new-bg: #232731;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---- layout ---- */
.side {
  width: 220px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line);
  padding: 20px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 18px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a {
  color: var(--ink); padding: 9px 10px; border-radius: 8px; font-weight: 500;
}
.side nav a:hover { background: var(--soft); text-decoration: none; }
.side nav a.on { background: var(--soft); color: var(--accent); }
.side .bottom { margin-top: auto; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1200px; }

@media (max-width: 800px) {
  body { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; align-items: center;
          padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand { padding: 0 10px 0 4px; white-space: nowrap; }
  .side nav { flex-direction: row; }
  .side nav a { white-space: nowrap; padding: 7px 9px; }
  .side .bottom { margin: 0 0 0 4px; }
  .main { padding: 18px 16px 50px; }
}

/* ---- blocks ---- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 20px 0; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(3, 1fr); margin-bottom: 18px; }
.kpis.five { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1000px) { .kpis.five { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .kpis, .kpis.five { grid-template-columns: repeat(2, 1fr); } .kpi .value { font-size: 20px; } }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.main-kpi { border-color: var(--good); }
.kpi.main-kpi .value { color: var(--good); }
.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---- tabs ---- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a {
  padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line);
  color: var(--ink); font-size: 14px;
}
.tabs a.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.tabs a:hover { text-decoration: none; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--soft); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--soft); }
td.name a { color: var(--ink); font-weight: 600; }
tr.off td { opacity: .5; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---- badges ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.b-issued { background: var(--good-bg); color: var(--good); }
.b-rejected { background: var(--bad-bg); color: var(--bad); }
.b-skipped { background: var(--skip-bg); color: var(--skip); }
.b-new { background: var(--new-bg); color: var(--muted); }
.b-active { background: var(--good-bg); color: var(--good); }
.b-closed { background: var(--new-bg); color: var(--muted); }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---- forms ---- */
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
button, .btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
button:hover, .btn:hover { background: var(--soft); text-decoration: none; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.primary:hover { background: var(--accent); filter: brightness(1.08); }
.danger { color: var(--bad); }
.sm { padding: 4px 9px; font-size: 13px; }
form.inline { display: inline; margin: 0; }

/* статусные кнопки в беседе */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 10px; font-size: 13px; font-weight: 600; background: var(--panel); color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on.s-issued { background: var(--good-bg); color: var(--good); }
.seg button.on.s-rejected { background: var(--bad-bg); color: var(--bad); }
.seg button.on.s-skipped { background: var(--skip-bg); color: var(--skip); }
.seg button.on.s-new { background: var(--new-bg); color: var(--ink); }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--good-bg); color: var(--good); font-weight: 500; }
.flash.err { background: var(--bad-bg); color: var(--bad); }

.progress { display: flex; height: 6px; border-radius: 99px; overflow: hidden; background: var(--new-bg); min-width: 90px; }
.progress span { display: block; height: 100%; }
.progress .p-issued { background: var(--good); }
.progress .p-rejected { background: var(--bad); }
.progress .p-skipped { background: var(--skip); }

details.edit summary { cursor: pointer; color: var(--accent); font-weight: 600; list-style: none; }
details.edit summary::-webkit-details-marker { display: none; }
details.edit[open] { background: var(--soft); border-radius: 10px; padding: 12px; margin: 6px 0; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 220px; padding-top: 18px; }
.bar-col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; }
.bar { background: var(--good); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .9; }
.bar.neg-bar { background: var(--bad); }
.bar-col:hover .bar { opacity: 1; filter: brightness(1.1); }
.bar-val { font-size: 11px; color: var(--muted); text-align: center; height: 16px; font-variant-numeric: tabular-nums; }
.bar-label { font-size: 11px; color: var(--muted); text-align: center; height: 18px; padding-top: 4px; white-space: nowrap; overflow: visible; border-top: 1px solid var(--line); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; gap: 10px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); width: 110px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
code.link { background: var(--soft); padding: 6px 8px; border-radius: 6px; font-size: 13px; word-break: break-all; display: inline-block; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }

/* login */
.login-wrap { margin: auto; width: 100%; max-width: 360px; padding: 16px; }
.login-wrap .card { padding: 28px; }
@media (max-width: 640px) { .hide-sm { display: none; } th, td { padding: 9px 10px; } }
input.amount { width: 84px; padding: 4px 6px; text-align: right; font-variant-numeric: tabular-nums; }
.terms { font-size: 12.5px; white-space: nowrap; }
.who { padding: 0 10px 6px; }
