:root {
  --bg: #f4f6f7; --card: #fff; --text: #1d2b30; --muted: #6b7b80; --line: #e2e8ea;
  --brand: #0f5c6e; --brand-2: #e8f2f4; --ok: #2e8b57; --warn: #c2410c; --err-bg: #fdecea; --ok-bg: #e7f5ed;
  --gas: #e8590c; --strom: #d4a106; --wasser: #1c7ed6; --waerme: #c92a2a; --salz: #6b7b80; --sonstiges: #7048e8;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11181b; --card: #1a2327; --text: #e6eef0; --muted: #93a4a9; --line: #2a373c;
    --brand: #4fb3c8; --brand-2: #1f3238; --err-bg: #3a1f1c; --ok-bg: #173026; --warn: #fb923c; --ok: #4ade80;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
.card h2 { margin-top: 0; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
small { font-size: .7em; font-weight: 500; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; word-break: break-all; }
.warn { color: var(--warn); }
.good { color: var(--ok); }
.r { text-align: right; }
.nowrap { white-space: nowrap; }

/* Kopfzeile */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.2rem;
  background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text); }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: #fff; font-weight: 800; }
.logo.big { width: 44px; height: 44px; font-size: 1.3rem; border-radius: 12px; }
.topnav { display: flex; gap: .3rem; flex: 1; }
.topnav a { padding: .45rem .8rem; border-radius: 9px; color: var(--muted); font-weight: 500; }
.topnav a.on, .topnav a:hover { background: var(--brand-2); color: var(--brand); }
.usermenu { display: flex; gap: 1rem; font-size: .9rem; }
.bottomnav { display: none; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 1.2rem 1.2rem 3rem; }

/* Karten & Raster */
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem;
  box-shadow: var(--shadow); color: var(--text); margin-bottom: 1rem; }
a.card:hover { border-color: var(--brand); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid > .card { margin-bottom: 0; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 1rem; }
.grid.sites, .grid.meters { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); margin-bottom: 1rem; }
.big-num { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; margin: .2rem 0; }
.empty { color: var(--muted); padding: .6rem 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.page-head h1 { margin-bottom: .1rem; }
.back { display: inline-block; margin-bottom: .5rem; font-size: .9rem; }

.pill, .tag { display: inline-block; padding: .15rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--brand-2); color: var(--brand); }
.pill.gas { background: color-mix(in srgb, var(--gas) 14%, transparent); color: var(--gas); }
.tag.privat { background: color-mix(in srgb, var(--sonstiges) 14%, transparent); color: var(--sonstiges); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.open { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.cat { font-weight: 600; }
.cat.gas { color: var(--gas); } .cat.strom { color: var(--strom); } .cat.wasser { color: var(--wasser); }
.cat.waerme { color: var(--waerme); } .cat.salz { color: var(--salz); } .cat.sonstiges { color: var(--sonstiges); }

.catlist { list-style: none; margin: .6rem 0 .3rem; padding: 0; }
.catlist li { display: grid; grid-template-columns: 1fr auto; gap: 0 .6rem; padding: .45rem 0; border-top: 1px solid var(--line); }
.catlist li .muted { grid-column: 1; font-size: .82rem; }
.catlist li .num { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-weight: 600; }
.addr { font-size: .88rem; }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: .5rem 0; }
.progress span { display: block; height: 100%; background: var(--ok); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-bg); }
.dot.off { background: var(--muted); }

/* Diagramm */
.chart { width: 100%; height: 90px; display: block; margin-top: .6rem; }
.chart rect { fill: var(--brand); opacity: .85; }
.chart-labels { display: flex; justify-content: space-between; font-size: .66rem; color: var(--muted); }
.chart-labels span { flex: 1; text-align: center; }

/* Tabs */
.tabs { display: flex; gap: .4rem; overflow-x: auto; margin-bottom: 1rem; padding-bottom: .2rem; scrollbar-width: none; }
.tabs a { white-space: nowrap; padding: .45rem .85rem; border-radius: 99px; background: var(--card); border: 1px solid var(--line); color: var(--text); font-size: .9rem; }
.tabs a.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Tabellen */
.table-wrap { overflow-x: auto; margin: 0 -1.1rem; padding: 0 1.1rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th.r, td.r { text-align: right; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .88rem; }
.facts dd { margin: 0; }
.note { background: var(--brand-2); padding: .6rem .8rem; border-radius: 10px; font-size: .9rem; }
ul.plain { list-style: none; padding: 0; } ul.plain li { padding: .3rem 0; }

/* Formulare */
.form { display: flex; flex-direction: column; gap: .8rem; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem 1rem; }
.grid-form .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 500; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .65rem .75rem; width: 100%; }
input[type=checkbox] { width: 20px; height: 20px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.btn { display: inline-flex; justify-content: center; align-items: center; gap: .4rem; padding: .65rem 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.block { width: 100%; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: .2rem .4rem; }
details > summary { cursor: pointer; list-style: none; }
details > summary h2 { display: inline; margin: 0; }
details[open] > summary { margin-bottom: 1rem; }

.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--brand-2); }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--warn); }

/* Login */
.login { min-height: 80vh; display: grid; place-items: center; }
.narrow { max-width: 420px; width: 100%; margin: 0 auto; }
.login-head { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.login-head h1 { margin: 0; }

/* Monatserfassung */
.card.list { padding: 0 1.1rem; }
.entry-row { display: flex; align-items: center; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--line); }
.entry-row:last-child { border-bottom: 0; }
.entry-row.done { opacity: .7; }
.entry-info { flex: 1; display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.entry-input { display: flex; align-items: center; gap: .4rem; width: 200px; }
.entry-input input { text-align: right; font-weight: 600; }
.unit { color: var(--muted); font-size: .85rem; min-width: 2.2rem; }
.sticky-date { display: flex; }
.sticky-date label { flex-direction: row; align-items: center; gap: .8rem; width: 100%; }
.sticky-date input { max-width: 200px; }
.save-bar { position: sticky; bottom: 0; padding: 1rem 0; background: linear-gradient(transparent, var(--bg) 35%); }

/* Handy */
@media (max-width: 760px) {
  .topnav, .usermenu { display: none; }
  .topbar { padding: .6rem 1rem; padding-top: calc(.6rem + env(safe-area-inset-top)); }
  .wrap { padding: 1rem 1rem calc(5.5rem + env(safe-area-inset-bottom)); }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .5rem 0 .55rem; font-size: .7rem; color: var(--muted); }
  .bottomnav a span { font-size: 1.25rem; line-height: 1; filter: grayscale(1); opacity: .7; }
  .bottomnav a.on { color: var(--brand); font-weight: 600; }
  .bottomnav a.on span { filter: none; opacity: 1; }
  h1 { font-size: 1.3rem; }
  .grid.sites, .grid.meters, .grid.kpis, .grid.two { grid-template-columns: 1fr; }
  .big-num { font-size: 1.6rem; }
  .entry-row { flex-direction: column; align-items: stretch; gap: .5rem; }
  .entry-input { width: 100%; }
  .entry-input input { font-size: 1.1rem; padding: .75rem; }
  .save-bar { bottom: calc(3.6rem + env(safe-area-inset-bottom)); }
  .page-head { flex-wrap: wrap; }
  .sticky-date input { max-width: none; }
}
