/* Verbrauch – mobile first */
:root {
  --bg: #f3f5f7;
  --card: #ffffff;
  --text: #17202a;
  --muted: #647084;
  --line: #e3e8ee;
  --field: #ffffff;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #dff2ef;
  --c1: #0f766e;
  --c2: #a3afbf;
  --good: #047857;
  --bad: #b45309;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --ok-soft: #e3f5ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 18px rgba(16, 24, 40, .05);
  --radius: 16px;
  --tab-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1217;
    --card: #151c24;
    --text: #e8edf3;
    --muted: #95a3b4;
    --line: #243040;
    --field: #0f161d;
    --accent: #2dd4bf;
    --accent-ink: #04201d;
    --accent-soft: #11302d;
    --c1: #2dd4bf;
    --c2: #6a7a8e;
    --good: #34d399;
    --bad: #fbbf24;
    --danger: #f87171;
    --danger-soft: #3a1b1d;
    --ok-soft: #10301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.has-nav { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 8px 0; }
code { background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.icon { width: 20px; height: 20px; flex: none; vertical-align: middle; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}
.topbar-in { max-width: 640px; margin: 0 auto; height: 52px; padding: 0 12px; display: flex; align-items: center; gap: 4px; }
.topbar h1 { font-size: 19px; font-weight: 700; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; color: var(--text); margin-left: -8px; }
.back:active { background: var(--line); }
.wrap { max-width: 640px; margin: 0 auto; padding: 14px 14px 20px; }

/* Untere Navigation */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 160px; height: var(--tab-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabbar a.on { color: var(--accent); }
.tabbar a:active { background: var(--line); }

/* Karten */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin: 0 0 14px;
}
.card > h2 + * { margin-top: 10px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }

.flash { padding: 12px 14px; border-radius: 12px; margin: 0 0 14px; font-weight: 500; }
.flash.ok { background: var(--ok-soft); color: var(--good); }
.flash.err { background: var(--danger-soft); color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .6; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.actions .btn { flex: 1 1 auto; }

/* Formulare */
form label { display: block; font-weight: 600; font-size: 14px; margin-top: 14px; }
form label small { font-weight: 400; display: block; margin-top: 4px; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-size: 16px; /* 16px verhindert Zoom auf iOS */
  min-height: 48px; padding: 10px 12px;
  color: var(--text); background: var(--field);
  border: 1px solid var(--line); border-radius: 12px;
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px;
}
input.big { font-size: 24px; font-weight: 700; min-height: 58px; letter-spacing: .5px; font-variant-numeric: tabular-nums; }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; margin-top: 16px; }
label.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
form .btn.block { margin-top: 18px; }

.preview {
  margin-top: 14px; padding: 12px 14px; border-radius: 12px;
  background: var(--accent-soft); color: var(--text); font-size: 15px; min-height: 48px;
}
.preview.warn { background: var(--danger-soft); color: var(--danger); }
.preview strong { font-variant-numeric: tabular-nums; }

/* Login */
.login { text-align: center; margin-top: 8vh; }
.login form { text-align: left; }
.login-logo img { border-radius: 16px; }
.login h2 { font-size: 24px; margin-top: 10px; }

/* Zählerkarten */
.meter-head { display: flex; align-items: center; gap: 12px; }
.meter-head h2 { font-size: 18px; }
.meter-head p { margin: 2px 0 0; font-size: 14px; }
.kico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent); }
.kico .icon { width: 22px; height: 22px; }
.k-strom { background: #fff3d6; color: #a16207; }
.k-gas { background: #ffe8dc; color: #c2410c; }
.k-heizung { background: #fde4ea; color: #be123c; }
.k-wasser { background: #dcecff; color: #1d4ed8; }
.k-sonstiges { background: #e8ecf1; color: #475569; }
@media (prefers-color-scheme: dark) {
  .k-strom { background: #3a2f10; color: #fcd34d; }
  .k-gas { background: #3b2214; color: #fdba74; }
  .k-heizung { background: #3d1a25; color: #fda4af; }
  .k-wasser { background: #14284a; color: #93c5fd; }
  .k-sonstiges { background: #232d3a; color: #aab6c5; }
}
.kpi { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin-top: 14px; }
.kpi-num { font-size: 38px; font-weight: 800; letter-spacing: -.5px; font-variant-numeric: tabular-nums; line-height: 1; }
.kpi-unit { color: var(--muted); font-weight: 600; }
.trend { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; font-size: 14px; padding: 3px 9px 3px 6px; border-radius: 99px; margin-left: auto; }
.trend .icon { width: 16px; height: 16px; }
.trend small { font-weight: 500; opacity: .8; margin-left: 3px; }
.trend.up { background: #fdf0d9; color: #a35a05; }
.trend.down { background: var(--ok-soft); color: var(--good); }
.trend.flat { background: var(--line); color: var(--muted); }
@media (prefers-color-scheme: dark) { .trend.up { background: #3b2d0f; color: #fbbf24; } }
.facts { display: flex; gap: 8px 18px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--muted); }
.facts b { color: var(--text); font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: #fdf0d9; color: #a35a05; }
@media (prefers-color-scheme: dark) { .badge { background: #3b2d0f; color: #fbbf24; } }
.badge.neutral { background: var(--line); color: var(--muted); }
.badge .icon { width: 13px; height: 13px; }

.empty { text-align: center; padding: 28px 16px; }
.empty .kico { margin: 0 auto 10px; width: 54px; height: 54px; }
.empty p { color: var(--muted); }

/* Umschalter (Verlauf / Monate / Ablesungen) */
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 4px; margin: 0 0 14px; gap: 4px; }
.seg a { flex: 1; text-align: center; padding: 9px 4px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); text-decoration: none; }
.seg a.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

/* Kennzahlen-Raster */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.stat > b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.3px; }
.stat small { color: var(--muted); font-size: 12px; }

/* Diagramme */
.chart { margin: 10px 0 0; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 9.5px; font-variant-numeric: tabular-nums; }
.chart .ax2 { fill: var(--muted); font-size: 8px; opacity: .8; }
.chart .val { fill: var(--text); font-size: 9.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar.s1 { fill: var(--c1); }
.bar.s2 { fill: var(--c2); }
.bar.partial { opacity: .42; }
.legend { display: flex; gap: 16px; justify-content: center; font-size: 13px; color: var(--muted); margin-top: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.dot.s1 { background: var(--c1); }
.dot.s2 { background: var(--c2); }
.note { font-size: 13px; color: var(--muted); }

/* Tabellen & Listen */
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: right; font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 0 8px 8px; }
.tbl th:first-child, .tbl td:first-child { text-align: left; padding-left: 0; }
.tbl td { text-align: right; padding: 10px 0 10px 8px; border-top: 1px solid var(--line); vertical-align: top; font-size: 15px; }
.tbl td small { display: block; color: var(--muted); font-size: 12px; }
.tbl .up { color: var(--bad); }
.tbl .down { color: var(--good); }
.tbl tr.partial td { color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a.item, .list .item { display: flex; align-items: center; gap: 12px; padding: 12px 0; color: inherit; text-decoration: none; }
.list .grow { flex: 1; min-width: 0; }
.list .grow b { display: block; font-variant-numeric: tabular-nums; }
.list .grow small { color: var(--muted); display: block; }
.list .side { color: var(--muted); }
.list .reset { color: var(--bad); font-weight: 600; }

.inline-form { display: inline; }
.sep { height: 1px; background: var(--line); margin: 16px 0; border: 0; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }

@media (min-width: 700px) {
  .wrap { padding-top: 22px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .tabbar a { transition: background-color .12s, transform .06s; }
}
