:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2421;
  --muted: #6b7773;
  --line: #e3e8e6;
  --brand: #1f6f5c;
  --danger: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --card: #1c2321;
    --text: #e8eeec;
    --muted: #8d9a96;
    --line: #2a3330;
    --brand: #3fb596;
    --danger: #ef6a5b;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; cursor: pointer; }

header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: #fff;
}
header h1 { margin: 0; font-size: 1.1rem; }
header h1::first-letter { text-transform: uppercase; }
header button {
  background: rgba(255,255,255,.18); border: 0; color: #fff;
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.5rem; line-height: 1;
}

main { padding: 16px; max-width: 560px; margin: 0 auto; }
.tab > * + * { margin-top: 14px; }

.card { background: var(--card); border-radius: 14px; padding: 16px; border: 1px solid var(--line); }
.big { font-size: 2rem; font-weight: 700; margin: 2px 0 0; }
.muted { color: var(--muted); font-size: .88rem; }
h2 { margin: 0 0 10px; font-size: 1rem; }

.cards3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cards3 .card { padding: 10px; text-align: center; }
.cards3 b { display: block; font-size: .95rem; margin-top: 2px; }

.chart-wrap { display: flex; justify-content: center; }
canvas { width: 220px; height: 220px; }
.legend { list-style: none; margin: 12px 0 0; padding: 0; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.legend .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.legend .nm { flex: 1; }
.legend .pc { color: var(--muted); width: 48px; text-align: right; }
.legend .vl { width: 90px; text-align: right; font-variant-numeric: tabular-nums; }

.group { margin: 18px 0 6px; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-top: 8px;
}
.item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.item .info { flex: 1; min-width: 0; }
.item .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.item .val { font-weight: 600; font-variant-numeric: tabular-nums; }
.item.off { opacity: .55; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); }

nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button { background: none; border: 0; padding: 14px 4px; color: var(--muted); font-size: .85rem; }
nav button.on { color: var(--brand); font-weight: 700; box-shadow: inset 0 3px 0 var(--brand); }

#fab {
  position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 6;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--brand); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}

#overlay {
  position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
}
#overlay[hidden] { display: none; }
#form {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
#form h2 { font-size: 1.15rem; margin-bottom: 4px; }
#form label { display: block; margin-top: 12px; font-size: .85rem; color: var(--muted); }
#form input, #form select {
  width: 100%; margin-top: 4px; padding: 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
#form .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
#form .row { display: flex; gap: 8px; margin-top: 18px; }
#form .row button { flex: 1; padding: 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
#form .row .ok { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }
#form .row .del { color: var(--danger); }
.linkbtn { display: block; margin: 20px auto 0; background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: .85rem; }
