:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2a37;
  --muted: #6b7684;
  --border: #d5dbe1;
  --primary: #0e6ba8;
  --primary-text: #ffffff;
  --danger: #c0392b;
  --radius: 12px;
  /* Diagramme (validierte Kategorie-Slots 1+2, siehe dataviz-Palette) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --chart-grid: #e1e0d9;
  --chart-axis: #898781;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171d;
    --card: #1c232b;
    --text: #e6eaee;
    --muted: #93a0ad;
    --border: #33404d;
    --primary: #3b9ae1;
    --danger: #ef6b5b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --chart-grid: #2c3640;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
.icon { width: 20px; height: 20px; flex: none; }

.topbar {
  background: var(--primary);
  color: var(--primary-text);
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 600; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; min-width: 0; }
input[type=text], input[type=password], input[type=time], input[type=datetime-local], textarea {
  font: inherit;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
textarea { resize: vertical; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.input-unit { position: relative; display: block; }
.input-unit input { padding-right: 48px; }
.input-unit > span {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none; font-weight: 400;
}
label.big input { font-size: 2rem; font-weight: 600; padding: 14px 64px 14px 14px; }
label.big .input-unit > span { font-size: 1.2rem; }

button, .button {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-size: 1.05rem; padding: 14px; }
button:disabled { opacity: .6; }
button.link { background: none; border: none; color: var(--danger); padding: 4px 0; font-weight: 500; }

.photo-field .label { font-weight: 500; display: block; margin-bottom: 6px; }
.photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photo-buttons .button { flex-direction: row; gap: 8px; }
#photo-preview { margin-top: 10px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
#photo-preview img { max-width: 100%; max-height: 240px; border-radius: 10px; }

details summary { cursor: pointer; color: var(--muted); }
details label { margin-top: 10px; }

.error { color: var(--danger); margin: 0; min-height: 0; }
.error:empty { display: none; }
.muted { color: var(--muted); }
.small { font-size: .875rem; margin: 0; }

fieldset.days { border: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
fieldset.days legend { font-weight: 500; margin-bottom: 6px; padding: 0; }
fieldset.days label, label.switch { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
fieldset.days label {
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
}

.entries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.entry {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
}
.entry > * { grid-column: 1; }
.entry .pressure { font-size: 1.5rem; font-weight: 700; }
.entry .temps { color: var(--text); font-size: .95rem; }
.entry time { color: var(--muted); font-size: .875rem; }
.entry .note { grid-column: 1 / -1; white-space: pre-wrap; margin: 4px 0 0; }
.entry img { grid-row: 1 / span 3; grid-column: 2; width: 72px; height: 72px; object-fit: cover; border-radius: 8px; cursor: zoom-in; }
.entry .actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }

#list-more { width: 100%; margin-top: 12px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; text-decoration: none; color: var(--muted);
}
.tabbar .icon { width: 24px; height: 24px; }
.tabbar a span { font-size: .75rem; }
.tabbar a.active { color: var(--primary); font-weight: 600; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: calc(100% - 32px);
}

dialog.lightbox { border: none; padding: 0; background: transparent; max-width: 100vw; max-height: 100vh; }
dialog.lightbox::backdrop { background: rgba(0,0,0,.85); }
dialog.lightbox img { max-width: 100vw; max-height: 100vh; display: block; }

/* ---------- Statistik ---------- */
.range-filter { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }
.range-filter button { padding: 8px 14px; border-radius: 999px; font-weight: 500; white-space: nowrap; }
.range-filter button[aria-checked=true] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

#stats-content { transition: opacity .15s; }
#stats-content.loading { opacity: .5; }

.hero { gap: 2px; }
.hero-value { font-size: 3rem; font-weight: 700; line-height: 1.1; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.tile strong { font-size: 1.15rem; }
h2 .unit { font-weight: 400; }

.chart-legend { display: flex; gap: 16px; font-size: .875rem; color: var(--muted); margin: -4px 0 4px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.line-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; flex: none; }

.chart-plot { position: relative; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; overflow: visible; }
.chart svg:focus { outline: none; }
.chart svg:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.chart .axis text { fill: var(--chart-axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--card); stroke-width: 2; }
.chart .crosshair { stroke: var(--chart-axis); stroke-width: 1; }
.chart .end-label { fill: var(--muted); font-size: 12px; }
.chart-empty { color: var(--muted); margin: 0; }

.chart-tooltip {
  position: absolute; top: 8px; pointer-events: none;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.15); padding: 8px 10px; font-size: .85rem; white-space: nowrap;
}
.tt-head { color: var(--muted); margin-bottom: 4px; }
.tt-row { display: flex; align-items: center; gap: 8px; }
.tt-row span { color: var(--muted); }

.stats-table summary { font-weight: 500; }
.table-scroll { overflow-x: auto; max-height: 360px; }
.stats-table table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.stats-table th, .stats-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table th { position: sticky; top: 0; background: var(--card); color: var(--muted); font-weight: 500; }
