/* ==========================================================================
   style.css — Zählerdokumentation, dunkles Theme
   ========================================================================== */

:root {
  --bg:          #0a0c10;
  --bg-elev:     #10131a;
  --surface:     #12161e;
  --surface-2:   #171c26;
  --surface-3:   #1d2331;
  --border:      #232a37;
  --border-soft: #1a202b;

  --text:        #e7ebf3;
  --text-dim:    #a3adc0;
  --muted:       #78839a;

  --accent:      #5b8def;
  --accent-soft: rgba(91, 141, 239, .14);
  --gas:         #ff9f43;
  --strom:       #ffd23f;
  --wasser:      #38bdf8;
  --ok:          #3ecf8e;
  --warn:        #f0b429;
  --danger:      #f2555a;

  --radius:      14px;
  --radius-sm:   10px;
  --shadow:      0 1px 2px rgba(0,0,0,.5), 0 12px 32px -12px rgba(0,0,0,.7);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Muss vor allen display-Regeln stehen: .lightbox/.modal setzen display:grid
   und würden das hidden-Attribut sonst aushebeln. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(91,141,239,.10), transparent 60%),
    radial-gradient(900px 500px at 95% 0%, rgba(56,189,248,.07), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.015em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1rem; }
p  { margin: 0; }
code { font-family: var(--mono); font-size: .9em; color: var(--text-dim); }

.muted { color: var(--muted); font-size: .875rem; }
.spacer { flex: 1; }
.num { font-variant-numeric: tabular-nums; }

::selection { background: var(--accent-soft); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ------------------------------------------------------------- Kopfzeile */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(10, 12, 16, .82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}

.topbar__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand__mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(91,141,239,.28), rgba(56,189,248,.14));
  border: 1px solid rgba(91,141,239,.32);
  color: #9dc0ff;
  flex: none;

  /* Knopf zum Neuladen — Button-Grundstile zurücksetzen */
  appearance: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .08s;
}
.brand__mark:hover {
  background: linear-gradient(145deg, rgba(91,141,239,.42), rgba(56,189,248,.22));
  border-color: rgba(91,141,239,.55);
  color: #c3d9ff;
}
.brand__mark:active { transform: scale(.92); }

.brand__mark svg { width: 18px; height: 18px; transition: transform .2s; }

/* Dreht sich, solange das Neuladen läuft */
.brand__mark.is-loading { pointer-events: none; }
.brand__mark.is-loading svg { animation: brandSpin .7s linear infinite; }
@keyframes brandSpin { to { transform: rotate(360deg); } }

.brand__text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand__text strong { font-size: .95rem; letter-spacing: -.01em; }
.brand__text small { color: var(--muted); font-size: .75rem; }

.tabs { display: flex; gap: 2px; margin-left: auto; }

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: 500 .875rem/1 var(--font);
  padding: 9px 13px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.is-active { background: var(--surface-3); color: var(--text); }

.topbar__right { display: flex; align-items: center; gap: 10px; }

.mode-badge {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(240,180,41,.12);
  border: 1px solid rgba(240,180,41,.3);
  color: var(--warn);
  white-space: nowrap;
}

/* --------------------------------------------------------------- Buttons */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: 500 .875rem/1 var(--font);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: #2c3547; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.btn svg { width: 15px; height: 15px; flex: none; }

.btn--primary {
  background: var(--accent);
  border-color: transparent;
  color: #06101f;
  font-weight: 600;
}
.btn--primary:hover:not(:disabled) { background: #6d9bf5; border-color: transparent; }

.btn--compact { padding: 8px 13px; }
.btn--sm { padding: 6px 11px; font-size: .8rem; border-radius: 8px; }
.btn--danger-ghost { color: var(--danger); border-color: rgba(242,85,90,.3); background: rgba(242,85,90,.07); }
.btn--danger-ghost:hover { background: rgba(242,85,90,.14); border-color: rgba(242,85,90,.5); }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.icon-btn--sm { width: 26px; height: 26px; display: inline-grid; place-items: center; }
.icon-btn--sm svg { width: 14px; height: 14px; }

/* --------------------------------------------------------- Segment-Regler */

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 11px;
}
.seg__btn {
  appearance: none; border: 0; background: transparent;
  color: var(--muted);
  font: 500 .8rem/1 var(--font);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-active { background: var(--surface-3); color: var(--text); }
.seg--sm .seg__btn { padding: 6px 10px; font-size: .78rem; }

/* --------------------------------------------------------------- Eingaben */

.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font: 400 .9rem/1.3 var(--font);
  font-variant-numeric: tabular-nums;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input--sm { padding: 7px 10px; font-size: .82rem; width: auto; }
.input::placeholder { color: #55607450; }

select.input { cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .78rem; color: var(--muted); font-weight: 500; }
.field--inline { flex-direction: column; align-items: flex-start; }
.field--inline .input { width: auto; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

/* ----------------------------------------------------------- Layout/Views */

.main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 20px 96px;
}

.view { display: none; animation: fade .22s ease; }
.view.is-active { display: block; }

@keyframes fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.view__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.view__head h1 { margin-bottom: 3px; }

.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ----------------------------------------------------------------- Panels */

.panel {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elev) 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}
.panel__body { padding: 18px; }
.panel--flush .panel__head { border-bottom: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 18px;
  align-items: start;
}

/* ------------------------------------------------------------ Zählerkarte */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.card {
  position: relative;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elev) 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--c, var(--accent));
  opacity: .75;
}
.card__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.card__icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: color-mix(in srgb, var(--c) 15%, transparent);
  color: var(--c);
  flex: none;
}
.card__icon svg { width: 17px; height: 17px; }
.card__title { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.card__title strong { font-size: .95rem; }
.card__title small { color: var(--muted); font-size: .74rem; }

.card__value {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 3px;
}
.card__value b {
  font-size: 1.85rem;
  font-weight: 650;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.card__value span { color: var(--muted); font-size: .85rem; }
.card__date { color: var(--muted); font-size: .76rem; margin-bottom: 14px; }

.card__stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.card__stat { background: var(--bg-elev); padding: 10px 12px; }
.card__stat small { display: block; color: var(--muted); font-size: .7rem; margin-bottom: 3px; }
.card__stat b { font-size: .95rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.card__spark { margin-top: 14px; height: 42px; }

/* Ohne diese Angaben leitet der Browser die Höhe aus dem viewBox-Verhältnis
   ab, ignoriert die Höhe des Containers und das SVG ragt unten heraus. */
.card__spark svg { display: block; width: 100%; height: 100%; }

.trend { font-size: .74rem; font-weight: 600; }
.trend--up { color: var(--danger); }
.trend--down { color: var(--ok); }

/* --------------------------------------------------------- Erfassen-Karte */

.capture-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.ccard {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elev) 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: border-color .18s;
}
.ccard::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 2px;
  background: var(--c); opacity: .75;
}
.ccard.is-filled { border-color: color-mix(in srgb, var(--c) 40%, var(--border-soft)); }

.ccard__prev {
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.ccard__prev b { color: var(--text-dim); font-variant-numeric: tabular-nums; font-weight: 600; }

.big-input {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color .15s, box-shadow .15s;
}
.big-input:focus-within {
  border-color: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 16%, transparent);
}
.big-input input {
  flex: 1;
  min-width: 0;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: 650 1.6rem/1 var(--font);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  padding: 15px 4px 15px 15px;
}
.big-input input:focus { outline: none; }
.big-input input::-webkit-outer-spin-button,
.big-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.big-input input[type=number] { -moz-appearance: textfield; }
.big-input__unit { padding: 0 15px 0 4px; color: var(--muted); font-size: .9rem; font-weight: 500; }

.ccard__calc {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  font-size: .82rem;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  min-height: 42px;
  align-items: center;
}
.ccard__calc b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.ccard__calc.is-empty { color: var(--muted); }

.hint {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  line-height: 1.45;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.hint--warn { background: rgba(240,180,41,.09); border: 1px solid rgba(240,180,41,.26); color: #f5cb6b; }
.hint--error { background: rgba(242,85,90,.09); border: 1px solid rgba(242,85,90,.28); color: #f79094; }

.ccard__foot {
  margin-top: 13px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.photo-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font: 500 .8rem/1 var(--font);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.photo-btn:hover { border-color: var(--c); color: var(--text); background: var(--surface-3); }
.photo-btn svg { width: 15px; height: 15px; }
.photo-btn.has-file { border-style: solid; border-color: color-mix(in srgb, var(--c) 45%, transparent); color: var(--text); }

.thumb-strip { display: flex; gap: 6px; flex-wrap: wrap; }
.thumb-strip img {
  width: 38px; height: 38px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* ------------------------------------------------------------ Speichern-Bar */

.capture-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: rgba(18, 22, 30, .93);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: 0 -4px 30px -10px rgba(0,0,0,.85);
}
.capture-bar__sum { font-size: .85rem; color: var(--text-dim); }
.capture-bar__sum b { color: var(--text); font-variant-numeric: tabular-nums; }
.capture-bar__actions { display: flex; gap: 10px; }

/* --------------------------------------------------------------- Tabellen */

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .855rem;
  font-variant-numeric: tabular-nums;
}
.table th {
  text-align: right;
  font-weight: 500;
  font-size: .72rem;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 11px 11px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.table th:first-child, .table td:first-child { text-align: left; padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.table td {
  text-align: right;
  padding: 10px 11px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  color: var(--text-dim);
}
.table td.strong { color: var(--text); font-weight: 600; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.is-change td { background: rgba(91,141,239,.05); }

/* Anbieterwechsel: der Monat wird grün hervorgehoben. Auf dem Telefon sind
   die Tarifspalten ausgeblendet — dort ist das der einzige Hinweis darauf,
   dass sich ab hier Grund- und Arbeitspreis ändern. */
.table tr.is-provider td { background: rgba(62,207,142,.07); }
.table tr.is-provider td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.table tr.is-provider td.strong { color: var(--ok); }

.pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .02em;
  vertical-align: middle;
}
.pill--est { background: rgba(240,180,41,.14); color: #f0b429; }
.pill--chg { background: rgba(91,141,239,.16); color: #8fb4f7; }
.pill--photo { background: rgba(62,207,142,.13); color: var(--ok); }
.pill--prov  { background: rgba(62,207,142,.18); color: var(--ok); }

.table-foot {
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  font-size: .82rem;
  color: var(--muted);
  background: var(--surface);
}
.table-foot b { color: var(--text); font-variant-numeric: tabular-nums; }

.link-btn {
  appearance: none; border: 0; background: transparent;
  color: var(--accent); font: 500 .8rem var(--font);
  cursor: pointer; padding: 2px 4px; border-radius: 6px;
}
.link-btn:hover { background: var(--accent-soft); }

/* --------------------------------------------------------------- Diagramme */

.chart-wrap { padding: 6px 10px 14px; }

/* Der viewBox wird in main.js auf die gemessene Containerbreite gesetzt, damit
   der Maßstab bei 1 liegt und die Beschriftung nicht gestaucht wird. */
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart-grid line { stroke: var(--border-soft); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart-bar { transition: opacity .15s; }

/* Trefferfläche über die volle Spaltenhöhe: fill muss "transparent" sein,
   "none" würde keine Mausereignisse empfangen. */
.chart-hit { fill: transparent; }
.chart-hit:hover { fill: rgba(255, 255, 255, .045); }

.chart-tip {
  position: fixed;
  z-index: 70;
  pointer-events: none;
  max-width: 260px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: .78rem;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- Letzte Werte */

.recent { padding: 6px 0 8px; }
.recent__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.recent__row:last-child { border-bottom: 0; }
.recent__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.recent__main { flex: 1; min-width: 0; }
.recent__main strong { display: block; font-size: .85rem; font-weight: 600; }
.recent__main small { color: var(--muted); font-size: .74rem; }
.recent__val { text-align: right; font-variant-numeric: tabular-nums; }
.recent__val b { display: block; font-size: .88rem; font-weight: 600; }
.recent__val small { color: var(--muted); font-size: .74rem; }

/* ------------------------------------------------------------------ Fotos */

.dropzone {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  margin-bottom: 20px;
  transition: border-color .18s, background .18s;
}
.dropzone:hover, .dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone svg { width: 30px; height: 30px; color: var(--accent); flex: none; }
.dropzone strong { display: block; font-size: .9rem; color: var(--text); }
.dropzone small { color: var(--muted); font-size: .78rem; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.photo {
  margin: 0;                 /* figure hat sonst UA-Ränder von 1em 40px */
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  aspect-ratio: 4 / 3;
  cursor: zoom-in;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; }
.photo:hover img { transform: scale(1.05); }
.photo__meta {
  position: absolute;
  inset: auto 0 0 0;
  padding: 20px 10px 8px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.86));
  font-size: .72rem;
  color: #e7ebf3;
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}
.photo__meta em { font-style: normal; color: var(--c, #cbd5e1); font-weight: 600; flex: none; }
.photo__meta span { overflow: hidden; text-overflow: ellipsis; }
.photo__del {
  position: absolute;
  top: 7px; right: 7px;
  width: 26px; height: 26px;
  border: 0;
  border-radius: 7px;
  background: rgba(10,12,16,.75);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s;
}
.photo:hover .photo__del { opacity: 1; }
.photo__del:hover { background: var(--danger); }

.photo--uploading { display: grid; place-items: center; color: var(--muted); font-size: .78rem; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 44px 20px;
  font-size: .88rem;
}

/* ----------------------------------------------------------- Einstellungen */

.cards--settings { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.tariff-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}

.kv {
  margin: 16px 0 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 18px;
  font-size: .84rem;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.row-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* --------------------------------------------------------------- Lightbox */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(6, 8, 11, .93);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 30px;
}
.lightbox__fig { margin: 0; max-width: 100%; max-height: 100%; text-align: center; }
.lightbox__fig img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.lightbox__fig figcaption { margin-top: 12px; color: var(--text-dim); font-size: .85rem; }
.lightbox__close {
  position: absolute;
  top: 18px; right: 22px;
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox__close:hover { background: var(--surface-3); }

/* ------------------------------------------------------------------ Modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(6, 8, 11, .72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal__box {
  width: min(520px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 70px -20px rgba(0,0,0,.9);
  animation: pop .18s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } to { opacity: 1; transform: none; } }

.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.modal__body {
  padding: 18px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.modal__body .full { grid-column: 1 / -1; }
.modal__foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
}

/* ------------------------------------------------------------------ Toasts */

.toasts {
  position: fixed;
  bottom: 22px; right: 22px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: min(380px, calc(100vw - 44px));
}
.toast {
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow);
  font-size: .85rem;
  animation: slideIn .22s ease;
}
.toast--ok { border-left-color: var(--ok); }
.toast--err { border-left-color: var(--danger); }
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Mobil
   --------------------------------------------------------------------------
   Referenzgerät iPhone 15: 2556 × 1179 physische Pixel bei dreifachem
   Pixelfaktor — für CSS sind das 393 × 852 pt hochkant bzw. 852 × 393 quer.
   Media Queries rechnen in Punkten, die Haltepunkte zielen deshalb auf 393
   und decken damit iPhone SE (375) bis Pro Max (430) mit ab.
   ========================================================================== */

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ------------------------------------------------- Tablets und Telefone */

@media (max-width: 760px) {
  .topbar__inner { flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .tabs {
    order: 3;
    width: 100%;
    margin-left: 0;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
    scroll-snap-type: x proximity;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { scroll-snap-align: start; }
  .topbar__right { margin-left: auto; }
  .brand__text small { display: none; }

  .main { padding: 20px 14px 90px; }
  h1 { font-size: 1.3rem; }

  .view__head { align-items: flex-start; }
  .cards, .capture-cards { grid-template-columns: 1fr; gap: 14px; }

  .capture-bar { flex-direction: column; align-items: stretch; }
  .capture-bar__actions { display: grid; grid-template-columns: 1fr 1.6fr; }

  .modal__body { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .toasts { left: 14px; right: 14px; bottom: 14px; max-width: none; }
  .dropzone { flex-direction: column; text-align: center; }

  /* Tarifspalten der Verlaufstabelle ausblenden — auf dem Telefon zählen
     Monat, Zählerstand, Verbrauch und Kosten. Die vollständigen Werte
     stehen weiterhin im Bearbeiten-Dialog. */
  .table .col--sec { display: none; }
}

/* --------------------------------------------------- Telefone (≤ 430 pt) */

@media (max-width: 430px) {
  /* Sichere Bereiche: Dynamic Island, abgerundete Ecken, Home-Indikator.
     Wirksam nur zusammen mit viewport-fit=cover im <meta viewport>. */
  .topbar__inner {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .main {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  h1 { font-size: 1.22rem; }
  .view__head { gap: 12px; margin-bottom: 16px; }
  .view__head .muted { font-size: .82rem; }

  /* Kopfzeile kompakter, damit vom Inhalt mehr sichtbar bleibt */
  .brand__mark { width: 30px; height: 30px; }
  .brand__mark svg { width: 16px; height: 16px; }
  .brand__text strong { font-size: .88rem; }
  .btn--compact { padding: 8px 11px; }
  .btn--compact span { font-size: .82rem; }

  .tab { padding: 9px 11px; font-size: .82rem; }

  /* Kennzahlen der Zählerkarte zweispaltig, aber luftiger */
  .card { padding: 16px; }
  .card__value b { font-size: 1.65rem; }
  .card__stat { padding: 9px 10px; }
  .card__stat b { font-size: .9rem; }
  .card__spark { height: 36px; }

  /* Erfassen: der Zahlenblock bleibt groß und gut treffbar */
  .ccard { padding: 16px; }
  .big-input input { font-size: 1.5rem; padding: 14px 4px 14px 14px; }
  .ccard__foot { gap: 10px 14px; }

  .capture-bar {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    border-radius: var(--radius) var(--radius) 0 0;
    margin: 0 calc(-1 * max(14px, env(safe-area-inset-left)))
            calc(-1 * env(safe-area-inset-bottom));
  }
  .capture-bar__sum { font-size: .8rem; }

  /* Verlaufstabelle: zweite Ausblendstufe und schmalere Spalten, damit
     Monat, Stand, Verbrauch und Kosten ohne Querscrollen nebeneinander passen. */
  .table .col--opt { display: none; }
  .table { font-size: .8rem; }
  .table th, .table td { padding: 9px 4px; }
  .table th:first-child, .table td:first-child { padding-left: 10px; }
  .table th:last-child, .table td:last-child { padding-right: 6px; }

  /* Versalien und Sperrung machen die Spaltenköpfe breiter als ihre Werte —
     hier bestimmen sie sonst die Tabellenbreite. */
  .table th { text-transform: none; letter-spacing: 0; font-size: .7rem; }

  /* Die Kennzeichnungen dürfen unter den Monat umbrechen, sonst zwingen sie
     die erste Spalte auf ein Vielfaches ihrer Breite. */
  .table td:first-child { white-space: normal; min-width: 5.5em; }
  .table .pill { font-size: .62rem; padding: 1px 5px; }

  /* Auf dem Telefon ist die grüne Zeile das Signal. Das lange Wort
     „Anbieterwechsel" ist nicht umbrechbar und würde die Monatsspalte um
     rund 30 px aufblähen — die Tabelle passte dann nicht mehr ohne Scrollen. */
  .table tr.is-provider td { background: rgba(62,207,142,.11); }
  .table .pill--prov { display: none; }

  .table-foot { gap: 12px; padding: 12px 14px; font-size: .78rem; }

  .gallery { grid-template-columns: repeat(2, 1fr); }

  .toasts {
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .modal { padding: 14px; align-items: flex-end; }
  .modal__box { max-height: 82dvh; }
  .modal__foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }

  .lightbox { padding: 14px; }
  .lightbox__close {
    top: calc(12px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
  }
  .lightbox__fig img { max-height: 74dvh; }

  .chart-wrap { padding: 4px 2px 10px; }
  .chart-tip { max-width: min(260px, calc(100vw - 28px)); }
}

/* ------------------------------------------------------- Querformat */

/* Quer ist das iPhone nur 393 pt hoch — die klebrige Kopfzeile und die
   Diagramme müssen dann deutlich flacher werden. */
@media (max-height: 480px) and (orientation: landscape) {
  .topbar__inner { padding-top: 6px; padding-bottom: 6px; gap: 8px; }
  .tab { padding: 7px 11px; }
  .main { padding-top: 16px; }

  .cards, .capture-cards { grid-template-columns: repeat(2, 1fr); }
  .card__spark { display: none; }
  /* Die Diagrammhöhe steuert main.js über den viewBox. Ein max-height hier
     würde nur stauchen und die Beschriftung verzerren. */
  .modal__box { max-height: 92dvh; }
  .lightbox__fig img { max-height: 82dvh; }
}

/* ----------------------------------------------------- Touch-Bedienung */

/* Greift auf allen Geräten ohne echten Mauszeiger. */
@media (hover: none) {
  /* Sonst nur bei Hover sichtbar — auf dem Telefon also nie erreichbar */
  .photo__del { opacity: 1; background: rgba(10, 12, 16, .82); }
  .photo:hover img { transform: none; }
  .chart-hit:hover { fill: none; }

  /* Fingerfreundliche Trefferflächen (Richtwert 44 pt) */

  /* Der Blitz bleibt optisch klein, die Trefferfläche wächst unsichtbar mit */
  .brand__mark { position: relative; }
  .brand__mark::after { content: ""; position: absolute; inset: -7px; }

  .icon-btn { width: 40px; height: 40px; }
  .icon-btn--sm { width: 38px; height: 38px; }
  .icon-btn--sm svg { width: 16px; height: 16px; }
  .photo__del { width: 34px; height: 34px; font-size: 1.15rem; }
  .btn { padding-top: 11px; padding-bottom: 11px; }
  .btn--sm { padding-top: 9px; padding-bottom: 9px; }
  .seg__btn { padding-top: 9px; padding-bottom: 9px; }
  .check input { width: 18px; height: 18px; }
  .photo-btn { padding: 11px 14px; }

  /* iOS Safari zoomt beim Fokus in Felder unter 16 px hinein und
     verschiebt dabei das Layout. 16 px verhindert das zuverlässig. */
  .input, select.input, .input--sm { font-size: 16px; }
  .big-input input { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.pill--span { background: rgba(120,131,154,.18); color: var(--text-dim); }

/* Umzug / neue Zählerreihe: Ab hier zählt ein anderes Zählwerk. Die Differenz
   zum Vormonat wäre sinnlos, deshalb steht dort „–“ statt einer Zahl. */
.pill--break { background: rgba(120,131,154,.22); color: var(--text-dim); }
.table tr.is-break td { background: rgba(120,131,154,.09); }
.table tr.is-break td:first-child { box-shadow: inset 3px 0 0 var(--muted); }

/* Unplausibler Rechenwert — meist ein falsch gesetztes Kennzeichen */
.pill--alarm { background: rgba(242,85,90,.18); color: var(--danger); font-weight: 700; }
.table tr.is-alarm td { background: rgba(242,85,90,.08); }
.table tr.is-alarm td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.table tr.is-alarm td.strong { color: var(--danger); }

/* ------------------------------------------- Foto-Auswahl im Bearbeiten-Dialog */

.menu-wrap { position: relative; display: inline-flex; }

.menu {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  z-index: 5;
  min-width: 190px;
  padding: 5px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
  box-shadow: 0 12px 30px -10px rgba(0,0,0,.85);
  animation: pop .14s ease;
}
.menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: 500 .875rem/1 var(--font);
  cursor: pointer;
  text-align: left;
}
.menu__item:hover { background: var(--surface-2); }
.menu__item svg { width: 18px; height: 18px; color: var(--accent); flex: none; }

/* Bereits zugeordnete Fotos der Ablesung */
.edit-photos { display: flex; gap: 8px; flex-wrap: wrap; }
.edit-photo {
  position: relative;
  margin: 0;
  width: 72px; height: 72px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.edit-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.edit-photo .photo__del { opacity: 1; width: 22px; height: 22px; top: 4px; right: 4px; font-size: .9rem; }

@media (max-width: 430px) {
  /* Groessere Ziele; das Menue darf ueber den Knopf hinausragen */
  .menu { left: 0; right: auto; min-width: 210px; }
  .menu__item { padding: 14px 12px; font-size: .95rem; }

  /* Reihenfolge wie am Rechner: die loeschende Aktion bleibt links und
     damit weit weg von „Speichern“. */
  .modal__foot { flex-wrap: wrap; gap: 8px; }
  .modal__foot .spacer { display: none; }
  .modal__foot .btn--danger-ghost { order: 1; flex: 1; }
  .modal__foot .menu-wrap { order: 2; flex: 1; }
  .modal__foot .menu-wrap .btn { width: 100%; }
  .modal__foot #editSave { order: 3; flex: 1.3; }
}
