:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --ink: #142019;
  --muted: #66736b;
  --line: #dde4de;
  --brand: #0f5132;
  --brand-2: #147a4b;
  --brand-soft: #e2f2e8;
  --amber: #b45309;
  --amber-soft: #fdf0d5;
  --red: #b91c1c;
  --red-soft: #fde8e8;
  --blue: #1d4ed8;
  --blue-soft: #e6edff;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(16, 40, 28, .08);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: var(--brand-2); }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-top));
  padding-top: calc(10px + env(safe-area-inset-top));
  background: #0f2d24; color: #f2f7f4;
  box-shadow: 0 1px 0 rgba(255,255,255,.06);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 {
  font-size: 16px; font-weight: 650; letter-spacing: -.01em; line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.kicker { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: #8fbcab; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  min-width: 40px; height: 40px; padding: 0 10px;
  border: 1px solid rgba(255,255,255,.16); border-radius: 10px;
  background: rgba(255,255,255,.06); color: #f2f7f4;
  font-size: 20px; line-height: 1;
}
.icon-btn:active { background: rgba(255,255,255,.16); }
.badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: #f59e0b; color: #111;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

.offline-banner {
  position: sticky; top: 0; z-index: 30;
  padding: 8px 14px; background: #7c2d12; color: #fff;
  font-size: 12px; text-align: center;
}

/* ---------------------------------------------------------------- layout */
.app { max-width: 760px; margin: 0 auto; padding: 14px 12px 40px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.hidden { display: none !important; }
.spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card.tight { padding: 12px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 4px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  font-weight: 600; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-soft { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-danger { background: var(--red-soft); border-color: transparent; color: var(--red); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand-2); outline-offset: 1px; }

/* ---------------------------------------------------------------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: #0f2d24; }
.auth .card { width: min(420px, 100%); }
.auth h1 { font-size: 26px; letter-spacing: -.02em; margin-bottom: 6px; }
.auth .logo { width: 54px; height: 54px; border-radius: 14px; background: var(--brand); display: grid; place-items: center; color: #fff; font-weight: 800; margin-bottom: 16px; }

/* ---------------------------------------------------------------- liste */
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-2), #34d399); border-radius: 99px; transition: width .3s; }

.building {
  display: grid; grid-template-columns: 1fr auto; gap: 10px;
  align-items: center; padding: 14px; cursor: pointer;
}
.building h3 { font-size: 15px; font-weight: 650; }
.building .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.building .count { font-size: 13px; font-weight: 700; color: var(--brand); white-space: nowrap; }

.meter {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px;
  align-items: center; padding: 12px 14px; cursor: pointer;
}
.meter + .meter { border-top: 1px solid var(--line); }
.meter .icon {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface-2);
}
.meter .icon svg { width: 18px; height: 18px; }
.meter .icon.strom { background: #fff7e6; color: #b45309; }
.meter .icon.wasser { background: #e6f2ff; color: #1d4ed8; }
.meter .icon.gas { background: #ffeee6; color: #c2410c; }
.meter .icon.wmz { background: #f3e8ff; color: #7e22ce; }
.meter .name { font-size: 14px; font-weight: 600; line-height: 1.25; }
.meter .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.meter .value { text-align: right; font-variant-numeric: tabular-nums; }
.meter .value b { display: block; font-size: 15px; }
.meter .value span { font-size: 10px; color: var(--muted); letter-spacing: .02em; }
.meter.done { background: #f6fbf7; }
.meter.draft { background: #fffbeb; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 99px; }
.pill.ok { background: var(--brand-soft); color: var(--brand); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.err { background: var(--red-soft); color: var(--red); }
.pill.info { background: var(--blue-soft); color: var(--blue); }
.pill.gray { background: var(--surface-2); color: var(--muted); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar .btn { flex: 1 1 150px; }

.search {
  width: 100%; min-height: 44px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
}

/* ---------------------------------------------------------------- camera */
.capture {
  position: fixed; inset: 0; z-index: 60; background: #050807;
  display: grid; grid-template-rows: auto 1fr auto; color: #fff;
}
.capture-head { padding: calc(10px + env(safe-area-inset-top)) 14px 10px; display: flex; align-items: center; gap: 12px; }
.capture-head .title { flex: 1; font-size: 14px; font-weight: 600; }
.capture-stage { position: relative; overflow: hidden; display: grid; place-items: center; }
.capture-stage video { width: 100%; height: 100%; object-fit: cover; }
.capture-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.reticle {
  position: absolute; inset: 16% 12%;
  border: 2px solid rgba(255,255,255,.75); border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.25);
  pointer-events: none;
}
.reticle span {
  position: absolute; left: 50%; bottom: -34px; transform: translateX(-50%);
  font-size: 12px; color: #fff; background: rgba(0,0,0,.55);
  padding: 5px 10px; border-radius: 99px; white-space: nowrap;
}
.capture-foot {
  padding: 16px 18px calc(22px + env(safe-area-inset-bottom));
  display: grid; gap: 10px; background: linear-gradient(transparent, rgba(0,0,0,.55));
}
.shutter-row { display: flex; align-items: center; justify-content: space-between; }
.shutter {
  width: 74px; height: 74px; border-radius: 50%;
  border: 6px solid rgba(255,255,255,.85); background: rgba(255,255,255,.15);
}
.shutter:active { background: rgba(255,255,255,.45); }
.capture .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.capture .btn-primary { background: var(--brand-2); border-color: var(--brand-2); }

/* ---------------------------------------------------------------- review */
.photo-box { border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 4/3; display: grid; place-items: center; }
.photo-box img { width: 100%; height: 100%; object-fit: contain; }
.reading-value {
  font-size: 42px; font-weight: 800; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.reading-input {
  width: 100%; min-height: 62px; padding: 8px 14px;
  border: 2px solid var(--brand-2); border-radius: 14px;
  font-size: 34px; font-weight: 750; text-align: center;
  font-variant-numeric: tabular-nums;
  background: #fff; color: var(--ink);
}
.meter-head { display: grid; gap: 2px; }
.meter-head b { font-size: 16px; }
.meter-head span { font-size: 12px; color: var(--muted); }
.actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

/* ---------------------------------------------------------------- modal / toast */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(6, 20, 13, .55); display: grid; place-items: end center; padding: 0; }
.sheet {
  width: min(760px, 100%); max-height: 90vh; overflow: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 50px rgba(0,0,0,.25);
}
.sheet h2 { font-size: 18px; margin-bottom: 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 80;
  transform: translateX(-50%);
  background: #142019; color: #fff; padding: 10px 16px; border-radius: 99px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: 90vw;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen { min-height: 70vh; display: grid; place-items: center; gap: 14px; color: var(--muted); }
.loading-screen .spinner { border-color: var(--line); border-top-color: var(--brand); }

.queue-item { display: grid; grid-template-columns: 54px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; }
.queue-item + .queue-item { border-top: 1px solid var(--line); }
.queue-thumb { width: 54px; height: 54px; border-radius: 10px; object-fit: cover; background: var(--surface-2); }

@media (min-width: 640px) {
  .app { padding-top: 22px; }
  .meter .name { font-size: 15px; }
}

[hidden] { display: none !important; }

.qr-box {
  display: grid; place-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 4px;
}
.qr-box img { width: min(240px, 70vw); height: auto; display: block; }
.recovery-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.recovery-grid code {
  display: block; padding: 9px 10px; border-radius: 9px;
  background: var(--surface-2); font-size: 14px; font-weight: 700;
  text-align: center; letter-spacing: .04em;
}

/* ---------------------------------------------------------------- consumi / dashboard */
.notice { padding: 8px 10px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.notice.red { background: var(--red-soft); color: var(--red); }
.delta { font-size: 11px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.delta.high { color: var(--red); font-weight: 700; }
.downloads { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.link-btn {
  border: 0; background: none; color: var(--brand-2); font-size: 11px;
  padding: 0 4px; text-decoration: underline; cursor: pointer;
}
.history { width: 100%; border-collapse: collapse; font-size: 13px; }
.history th {
  text-align: left; font-size: 11px; text-transform: uppercase; color: var(--muted);
  padding: 6px 4px; border-bottom: 1px solid var(--line);
}
.history td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.history td.num { text-align: right; font-variant-numeric: tabular-nums; }
.history td.high { color: var(--red); font-weight: 700; }
.admin-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; }
.admin-row + .admin-row { border-top: 1px solid var(--line); }
.admin-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------------------------------------------------------------- sortierung */
.sort-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; }
.sort-row + .sort-row { border-top: 1px solid var(--line); }
.sort-actions { display: flex; gap: 6px; flex-shrink: 0; }
.sort-actions .btn { min-width: 42px; min-height: 36px; padding: 4px 8px; }

/* ---------------------------------------------------------------- foto-viewer */
body.photo-open { overflow: hidden; }
.photo-box { cursor: zoom-in; }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-viewer-root { position: fixed; inset: 0; z-index: 70; background: #050807; }
.photo-viewer { display: grid; grid-template-rows: auto 1fr; height: 100%; }
.photo-viewer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(9px + env(safe-area-inset-top)) 12px 9px;
  background: #0f2d24; color: #f2f7f4;
}
.photo-viewer-title { flex: 1; min-width: 0; }
.photo-viewer-title b {
  display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.photo-viewer-title span { display: block; font-size: 11px; color: #9fc4b4; }
.photo-viewer-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.photo-viewer-actions .icon-btn {
  min-width: 38px; height: 38px; background: rgba(255,255,255,.08);
  text-decoration: none; display: inline-grid; place-items: center;
}
.photo-viewer-stage {
  overflow: auto; display: flex; align-items: flex-start; justify-content: center;
  padding: 12px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.photo-viewer-stage img { max-width: none; height: auto; display: block; }
