:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #17202a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --error: #b91c1c;
  --warn-bg: #fef3c7;
  --warn-text: #78350f;
  --nav: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --card: #1a2129;
    --text: #e6edf3;
    --muted: #93a1b0;
    --border: #2b3540;
    --accent: #2dd4bf;
    --accent-text: #062a26;
    --error: #f87171;
    --warn-bg: #3b2f0b;
    --warn-text: #fde68a;
    --nav: #151b22;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --card: #1a2129; --text: #e6edf3; --muted: #93a1b0; --border: #2b3540;
  --accent: #2dd4bf; --accent-text: #062a26; --error: #f87171; --warn-bg: #3b2f0b; --warn-text: #fde68a; --nav: #151b22;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--error); margin: 4px 0; min-height: 0; }
.error:empty { display: none; }
.warn { background: var(--warn-bg); color: var(--warn-text); padding: 10px 12px; border-radius: 10px; }

header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 20px; }
main { max-width: 760px; margin: 0 auto; padding: 14px 16px calc(84px + env(safe-area-inset-bottom)); }

h2 { font-size: 17px; margin: 0 0 10px; }
.section-title { margin: 20px 0 10px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; margin-bottom: 14px;
}

/* Navigation unten */
nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--nav); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  background: none; border: 0; color: var(--muted); font-size: 20px;
  padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
nav button span { font-size: 11px; }
nav button.active { color: var(--accent); }

/* Buttons & Formulare */
button { font: inherit; }
.primary, .secondary {
  border-radius: 10px; padding: 10px 16px; cursor: pointer; border: 1px solid transparent; font-weight: 600;
}
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.full { width: 100%; margin-bottom: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
input, select {
  display: block; width: 100%; margin-top: 4px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; margin-top: 12px; }
.grid-form button { grid-column: 1 / -1; }
details summary { cursor: pointer; color: var(--accent); margin-top: 8px; }

.upload {
  display: block; text-align: center; padding: 18px; border: 2px dashed var(--accent);
  border-radius: 12px; color: var(--accent); font-weight: 600; cursor: pointer; margin: 0;
}
.upload input { display: none; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; }
.login h1 { font-size: 22px; margin-top: 0; }
.login button { width: 100%; }

/* Übersicht */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { background: none; border: 0; padding: 8px 0; border-radius: 8px; color: var(--muted); cursor: pointer; font-weight: 600; }
.seg button.active { background: var(--accent); color: var(--accent-text); }
#range-label { margin: 6px 2px 12px; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; min-width: 0; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi b { font-size: 22px; font-variant-numeric: tabular-nums; margin: 2px 0; }
.kpi small { font-size: 12px; color: var(--muted); }

.chart-wrap { position: relative; height: 280px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 7px 4px; border-bottom: 1px solid var(--border); font-size: 14px; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr.total td { font-weight: 700; border-bottom: 0; }
tr.sub td { color: var(--muted); font-style: italic; border-bottom: 0; }

.meter-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.meter { background: var(--card); border: 1px solid var(--border); border-left: 5px solid var(--c); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.meter h3 { font-size: 14px; margin: 0 0 4px; }
.meter .val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.meter .meta { font-size: 12px; color: var(--muted); }
.meter .old { color: var(--error); }

/* Erfassen */
.capture .thumb { width: 100%; max-height: 260px; object-fit: contain; border-radius: 10px; background: #000; margin-bottom: 8px; }
.capture.saved { opacity: .6; }

/* Verlauf */
#history-filter { margin-bottom: 10px; }
.hist { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.hist:last-child { border-bottom: 0; }
.hist .main { flex: 1; min-width: 0; }
.hist .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.hist .m { font-size: 12px; color: var(--muted); }
.hist a { font-size: 13px; color: var(--accent); }
.hist button { background: none; border: 1px solid var(--border); color: var(--error); border-radius: 8px; padding: 4px 8px; cursor: pointer; }

@media (max-width: 380px) {
  .meter-cards { grid-template-columns: 1fr; }
  .grid-form { grid-template-columns: 1fr; }
}
