/* Zähler — calm, mobile first, light + dark */
:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #efeee9; --line: #dfddd6;
  --text: #1d1f21; --muted: #6b6f72; --accent: #246b5e; --accent-ink: #ffffff; --accent-soft: #e2efeb;
  --water: #2f78c4; --gas: #d9822b; --electricity: #8a5cc7;
  --warn: #9a6300; --warn-bg: #fff4dc; --warn-line: #f0d08a;
  --err: #b3261e; --err-bg: #fdeceb; --err-line: #f1b8b4;
  --ok: #2e7d4f; --ok-bg: #e5f4ea;
  --radius: 14px; --tap: 52px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b; --surface: #1f2226; --surface-2: #272b30; --line: #33383e;
    --text: #e8e6e3; --muted: #9aa0a6; --accent: #5cb8a5; --accent-ink: #0d1f1b; --accent-soft: #1d3530;
    --water: #6aa8ec; --gas: #f0a35a; --electricity: #b493e8;
    --warn: #f2c063; --warn-bg: #3a2f15; --warn-line: #6b5523;
    --err: #ff8a80; --err-bg: #3d1d1b; --err-line: #6e2f2b;
    --ok: #7fd3a0; --ok-bg: #1b3326;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; margin: 0 0 .5rem; }
small { font-size: .8em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.tnum { font-variant-numeric: tabular-nums; }
code { font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 6px; overflow-wrap: anywhere; }

main { max-width: 1180px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 560px; }

/* ---------- navigation: bottom tab bar on phones, top bar on desktop ---------- */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line);
       display: flex; align-items: center; gap: 12px; padding: 8px 16px; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.who { margin-left: auto; color: var(--muted); font-size: .9rem; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr);
        background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
          min-height: 60px; color: var(--muted); text-decoration: none; font-size: .74rem; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabs { position: static; display: flex; gap: 4px; background: none; border: 0; padding: 0; margin-left: 24px; }
  .tabs a { flex-direction: row; min-height: 40px; padding: 0 14px; border-radius: 10px; font-size: .95rem; gap: 8px; }
  .tabs a.on { background: var(--accent-soft); }
  .tabs svg { width: 18px; height: 18px; }
}

/* ---------- cards, alerts, buttons ---------- */
.card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
.stack > * + * { margin-top: 14px; }
.alert { padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--text); }
.alert.error { background: var(--err-bg); border-color: var(--err-line); }
.alert.ok { background: var(--ok-bg); border-color: transparent; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px;
       border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
       font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; }
.btn.danger { color: var(--err); border-color: var(--err-line); background: transparent; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, .chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- forms ---------- */
.field { display: block; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; }
input, textarea, select { font: inherit; color: var(--text); background: var(--surface); border: 1.5px solid var(--line);
                          border-radius: 12px; padding: 12px 14px; width: 100%; min-height: var(--tap); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); margin: 0; flex: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.confirm { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; }
.confirm[hidden] { display: none; }
.warn-text { color: var(--warn); display: block; margin-top: 4px; }

.reading-form { display: flex; flex-direction: column; gap: 14px; }
.meter { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.meter.has-issue { border-color: var(--warn-line); }
.meter-label { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 1.05rem; margin-bottom: 8px; }
.meter-label small { color: var(--muted); font-weight: 400; }
.meter-input { font-size: 1.75rem; font-weight: 600; min-height: 62px; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.meter-input::placeholder { color: var(--muted); opacity: .45; font-weight: 400; }
.meter.secondary .meter-input { font-size: 1.35rem; min-height: 54px; }
.hint { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; margin-top: 6px; color: var(--muted); font-size: .9rem; }
.hint b { color: var(--text); font-weight: 600; }
.issues:empty { display: none; }
.issues { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.issue { margin: 0; padding: 8px 10px; border-radius: 10px; font-size: .93rem; }
.issue.warning { background: var(--warn-bg); color: var(--text); }
.issue.error { background: var(--err-bg); color: var(--text); }
.issue.warning::before { content: "⚠ "; color: var(--warn); }
.issue.error::before { content: "✕ "; color: var(--err); font-weight: 700; }
.suggest { align-self: flex-start; min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1.5px solid var(--accent);
           background: var(--accent-soft); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; background: var(--muted); }
.dot.water { background: var(--water); } .dot.gas { background: var(--gas); } .dot.electricity { background: var(--electricity); }

/* login */
main.login { padding-top: 12vh; }
.login-title { font-size: 2rem; margin-bottom: 0; }
.who-pick { border: 0; padding: 0; margin: 0; display: flex; gap: 10px; flex-wrap: wrap; }
.who-pick legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.chip { flex: 1; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span { display: flex; align-items: center; justify-content: center; min-height: var(--tap); border: 1.5px solid var(--line);
             border-radius: 12px; font-weight: 600; font-size: 1.1rem; cursor: pointer; }
.chip input:checked + span { border-color: var(--accent); background: var(--accent-soft); }

/* after save */
.saved { border-color: var(--ok); }
.saved h2 small { font-weight: 400; }
.since { list-style: none; margin: 8px 0; padding: 0; }
.since li { display: grid; grid-template-columns: 14px 1fr auto; column-gap: 8px; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--line); }
.since li:first-child { border-top: 0; }
.since .val { font-weight: 650; text-align: right; }
.since .sub { grid-column: 2 / 4; color: var(--muted); font-size: .85rem; }
.since .badge { grid-column: 2 / 4; justify-self: start; }
.row { display: flex; gap: 20px; margin: 8px 0 0; }

/* ---------- readings list ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 8px; }
.page-head h1 { margin: 0; }
.pill { margin: 0; padding: 4px 12px; border-radius: 20px; font-size: .88rem; font-weight: 600; }
.pill.suspect { background: var(--warn-bg); color: var(--warn); }
.legend { margin-top: 0; }
.readings { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.reading { display: block; color: inherit; text-decoration: none; background: var(--surface); border: 1px solid var(--line);
           border-radius: var(--radius); padding: 12px 14px; }
.reading:hover { border-color: var(--accent); }
:target > .reading { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.r-head { display: flex; justify-content: space-between; gap: 8px; }
.r-date { font-weight: 650; }
.r-comment { margin: 4px 0 0; font-size: .92rem; color: var(--muted); font-style: italic; }
.r-values { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin-top: 10px; }
.r-val { display: grid; grid-template-columns: 1fr; padding: 6px 8px; border-radius: 10px; }
.r-name { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.r-num { font-size: 1.08rem; font-weight: 600; }
.r-delta { font-size: .82rem; color: var(--muted); }
.r-val.suspect { background: var(--warn-bg); outline: 1px solid var(--warn-line); }
.r-val.suspect .r-num { text-decoration: underline wavy var(--warn); text-underline-offset: 4px; }
.r-val.secondary .r-num { font-size: .95rem; font-weight: 500; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 10px; margin-top: 2px; justify-self: start; text-transform: uppercase; letter-spacing: .03em; }
.badge.suspect { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line); }
.badge.confirmed { background: var(--ok-bg); color: var(--ok); }
@media (min-width: 760px) {
  .r-values { grid-template-columns: repeat(4, 1fr); }
  .reading { display: grid; grid-template-columns: 210px 1fr; column-gap: 16px; }
  .r-head { flex-direction: column; gap: 0; }
  .r-comment { grid-column: 1; grid-row: 2; }
  .r-values { grid-column: 2; grid-row: 1 / 3; margin-top: 0; }
}

/* edit page */
.back { margin: 0 0 4px; }
.back a { display: inline-flex; min-height: 44px; align-items: center; text-decoration: none; }
.delete-form { margin: 18px 0 0; }
.history { margin-top: 28px; }
.audit { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.audit > li { padding: 4px 0 12px 14px; position: relative; }
.audit > li::before { content: ""; position: absolute; left: -6px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.diff { margin: 4px 0 0; padding-left: 18px; font-size: .9rem; }

/* ---------- analysis ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg a { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 9px;
         color: var(--text); text-decoration: none; font-weight: 600; }
.seg a.on { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 12px 0 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.k-label { color: var(--muted); font-size: .85rem; }
.k-val { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
.k-val small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.k-sub { font-size: .85rem; color: var(--muted); }
.k-sub b.up { color: var(--err); } .k-sub b.down { color: var(--ok); }
.chart { width: 100%; height: 300px; }
.chart.tall { height: 380px; }
@media (max-width: 600px) { .chart { height: 260px; } .chart.tall { height: 330px; } }
.grid2 { display: grid; gap: 0 16px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.notes { list-style: none; padding: 0; margin: 10px 0 0; font-size: .9rem; display: grid; gap: 4px; }
.notes li { display: flex; gap: 8px; align-items: baseline; }
.notes .n { flex: none; width: 20px; height: 20px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line);
            display: inline-flex; align-items: center; justify-content: center; font-size: .72rem; font-weight: 700; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { text-align: left; color: var(--muted); font-weight: 600; font-size: .82rem; }
table.data .r { text-align: right; }
table.data tr.partial td, table.data tr.uncertain td { color: var(--muted); }
@media (max-width: 600px) { table.data th, table.data td { padding: 8px 6px; } table.data { font-size: .86rem; } }
.source { color: var(--muted); font-size: .82rem; margin-top: 8px; }
.logout { margin-top: 8px; }
.settings-form { margin-bottom: 20px; }
