:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #6b746f;
  --line: #e3e6e1;
  --accent: #2f6f4e;
  --accent-soft: #e4efe8;
  --pos: #2e7d4f;
  --neg: #c0392b;
  --warn-bg: #fff4d6;
  --err-bg: #fde8e6;
  --ok-bg: #e4efe8;
  --bar-in: #4f9d6f;
  --bar-out: #d9826b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --card: #1d2320;
    --text: #e6ebe7;
    --muted: #97a19b;
    --line: #2d3531;
    --accent: #6fbf91;
    --accent-soft: #24352b;
    --pos: #74c995;
    --neg: #f08a7a;
    --warn-bg: #3a3218;
    --err-bg: #3d2320;
    --ok-bg: #22352a;
    --bar-in: #5fb282;
    --bar-out: #e0907a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 48px; }

header.top { background: var(--card); border-bottom: 1px solid var(--line); }
header.top .wrap { display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 17px; }
header nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
header nav a { text-decoration: none; color: var(--text); padding: 6px 10px; border-radius: 6px; }
header nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
header nav a.muted { margin-left: auto; color: var(--muted); }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 16px; }
h3 { font-size: 14px; margin-top: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 16px; min-width: 0; }
.card.flush { padding: 0; overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--ok-bg); }
.flash.err { background: var(--err-bg); }
.flash.warn { background: var(--warn-bg); }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
@media (max-width: 860px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.tile span { display: block; color: var(--muted); font-size: 13px; }
.tile strong { display: block; font-size: 22px; font-variant-numeric: tabular-nums; margin: 2px 0; }
.tile.big strong { font-size: 26px; }
.tile small { color: var(--muted); font-size: 12px; }

.monthnav { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 12px; }
.monthnav a { text-decoration: none; }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .grid.zero { stroke: var(--muted); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .bar.in { fill: var(--bar-in); }
.chart .bar.out { fill: var(--bar-out); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .area { fill: var(--accent); opacity: .12; }
.chart .dot { fill: var(--card); stroke: var(--accent); stroke-width: 2; }
.legend { font-size: 13px; margin: 8px 0 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 8px; vertical-align: -1px; }
.legend i:first-child { margin-left: 0; }
.legend i.in { background: var(--bar-in); }
.legend i.out { background: var(--bar-out); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
table.list td:first-child { padding-left: 0; }
table.list td:last-child { padding-right: 0; }

table.cats td { padding: 6px 8px; vertical-align: middle; }
table.cats td:first-child { padding-left: 0; width: 55%; }
table.cats a { text-decoration: none; color: var(--text); }
.meter { position: relative; height: 6px; background: var(--line); border-radius: 3px; margin-top: 4px; }
.meter span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; max-width: 100%; }
.meter em { position: absolute; top: -3px; width: 2px; height: 12px; background: var(--text); opacity: .55; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; }
.summary { margin: 0 0 10px; }
table.tx td { vertical-align: middle; }
table.tx th:first-child, table.tx td:first-child { padding-left: 16px; }
.catform { display: flex; gap: 6px; align-items: center; }
.catform select { max-width: 190px; }
.catform select.none { border-color: var(--bar-out); }
.rulechk { font-size: 12px; color: var(--muted); white-space: nowrap; }

input, select, button { font: inherit; font-size: 14px; }
input:not([type=checkbox]):not([type=color]):not([type=file]), select {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--text); max-width: 100%;
}
input[type=color] { width: 34px; height: 32px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
button { padding: 7px 14px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }
@media (prefers-color-scheme: dark) { button { color: #0f1411; } }
button.secondary { background: var(--accent-soft); color: var(--accent); }
button.link { background: none; color: var(--muted); padding: 2px 6px; }
button.link:hover { color: var(--neg); }
form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
form.inline-x { display: inline; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.buttons form { margin: 0; }

table.rules td { vertical-align: middle; padding: 5px 8px; font-size: 14px; }
table.rules td:first-child { padding-left: 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.catedit { margin: 0; }
.catedit input[name=name] { flex: 1; min-width: 120px; }

.acc-row { display: grid; grid-template-columns: minmax(140px, 1.2fr) 1.4fr auto 1.6fr auto auto auto; gap: 10px; align-items: center; }
@media (max-width: 960px) { .acc-row { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .acc-row { grid-template-columns: 1fr; } .acc-row .num { text-align: left; } }
.acc-row span { overflow-wrap: anywhere; }
.manual { margin: 10px 0 0 0; padding: 10px 12px; background: var(--bg); border-radius: 8px; }
.manual form.inline { margin-bottom: 6px; }
ul.hist, ul.log { list-style: none; padding: 0; margin: 0; font-size: 13px; }
ul.hist li, ul.log li { padding: 2px 0; }

.empty { text-align: center; padding: 40px 18px; }

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 340px; }
.login-card label { display: block; margin: 12px 0; font-size: 14px; color: var(--muted); }
.login-card input { width: 100%; margin-top: 4px; }
.login-card button { width: 100%; padding: 10px; }

@media (max-width: 640px) {
  header.top .wrap { gap: 4px 12px; padding-top: 10px; padding-bottom: 6px; }
  header nav { flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  header nav a { white-space: nowrap; }
  .tile strong { font-size: 18px; }
  .tile.big strong { font-size: 20px; }
  table.tx small { display: none; }
  .catform select { max-width: 140px; }
  .chart .axis { font-size: 17px; }
  .chart .axis.odd { display: none; }
  .chart.wide .axis { font-size: 26px; }
  .chart.wide .dot { r: 6; }
}
