:root {
  --bg: #f4f2ee; --surface: #ffffff; --surface-2: #faf9f6; --line: #e4e0d8;
  --text: #1f1d1a; --muted: #6f6a61; --faint: #9b958a;
  --accent: #2f6f5e; --accent-soft: #e3efe9;
  --danger: #b4372b; --danger-soft: #fbe9e6;
  --warn: #a86a0c; --warn-soft: #fbf0dc;
  --info: #3a5f8f; --info-soft: #e7eef7;
  --ok: #2f7d4f; --ok-soft: #e4f3ea;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412; --surface: #1d1c19; --surface-2: #23221f; --line: #34322d;
    --text: #ece8e1; --muted: #a39d92; --faint: #79736a;
    --accent: #6cc2a6; --accent-soft: #1e3530;
    --danger: #f08a7e; --danger-soft: #3a201d;
    --warn: #e9b55a; --warn-soft: #3a2e19;
    --info: #8fb4e6; --info-soft: #1d2a3b;
    --ok: #79cf9b; --ok-soft: #1c3226;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
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: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }

/* ---- каркас ---- */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 16px; padding: 0 10px 18px; display: flex; gap: 8px; align-items: center; }
.brand .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.side form { margin-top: 18px; padding: 0 10px; }
main { padding: 28px 32px 60px; max-width: 1280px; width: 100%; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; height: auto; z-index: 10; padding: 10px 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 8px 8px; }
  .nav { display: flex; overflow-x: auto; gap: 4px; scrollbar-width: none; }
  .nav a { white-space: nowrap; gap: 6px; }
  .side form { display: none; }
  main { padding: 18px 16px 50px; }
}

/* ---- блоки ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 13px; color: var(--muted); margin-top: 2px; }
.up { color: var(--danger); } .down { color: var(--ok); }

/* ---- напоминания ---- */
.alerts { display: grid; gap: 8px; }
.alert { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 11px 14px; border-radius: 10px; border: 1px solid transparent; }
.alert .t { font-weight: 600; }
.alert .x { font-size: 13px; color: var(--muted); }
.alert.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert.danger .t { color: var(--danger); }
.alert.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert.warn .t { color: var(--warn); }
.alert.info { background: var(--surface); border-color: var(--line); }
.alert form { display: flex; gap: 6px; flex-shrink: 0; }
@media (max-width: 640px) { .alert { flex-direction: column; align-items: stretch; } }

/* ---- таблицы ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

/* ---- элементы ---- */
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
button, .btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 6px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; display: inline-block; }
button:hover, .btn:hover { border-color: var(--faint); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { button.primary, .btn.primary { color: #0f1a17; } }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 4px 8px; }
button.ghost:hover { color: var(--danger); }
button.sm, .btn.sm { padding: 3px 9px; font-size: 13px; }
input, select, textarea { font: inherit; font-size: 14px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=number] { width: 120px; }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.flash { background: var(--accent-soft); color: var(--accent); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a { padding: 6px 12px; border-radius: 8px; color: var(--muted); border: 1px solid var(--line); background: var(--surface); }
.tabs a.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.bar { height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 6px; }
.bar > i.warn { background: var(--warn); } .bar > i.danger { background: var(--danger); }
.bar > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--faint); }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.list-plain li:last-child { border-bottom: 0; }
.chart { position: relative; height: 260px; }
.empty { color: var(--faint); padding: 18px 0; text-align: center; }
details summary { cursor: pointer; color: var(--muted); }
.addr-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.meter-val { font-family: var(--mono); font-size: 20px; font-weight: 600; letter-spacing: .02em; }
.done { text-decoration: line-through; color: var(--faint); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }
.login input { width: 100%; }

/* ---- письма ---- */
.letter { display: block; padding: 12px 18px; border-bottom: 1px solid var(--line); color: var(--text); }
.letter:last-child { border-bottom: 0; }
.letter:hover { background: var(--surface-2); text-decoration: none; }
.letter-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.letter-subj { font-weight: 600; }
.letter-sum { margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.letter.done .letter-subj { color: var(--faint); }
.facts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.fact { font-size: 12px; background: var(--info-soft); color: var(--info); border-radius: 6px; padding: 2px 8px; }
.fact i { font-style: normal; opacity: .7; margin-right: 2px; }
.letter-body { white-space: pre-wrap; font-size: 14px; line-height: 1.6; max-height: 70vh; overflow-y: auto; word-break: break-word; }
