:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --border: #e3e0d8;
  --text: #1f2328;
  --muted: #6b6f76;
  --accent: #1f6f5c;
  --accent-contrast: #ffffff;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
  --today: #fff6d6;
  --select: rgba(31, 111, 92, .16);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --surface: #1d2024; --surface-2: #25292e; --border: #33383f;
    --text: #e8eaed; --muted: #9aa0a8; --accent: #4fb89c; --accent-contrast: #0c1f1a;
    --danger: #f97066; --warn: #fdb022; --ok: #47cd89; --today: #3a3420; --select: rgba(79, 184, 156, .2);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: .5rem; color: var(--text); text-decoration: none; }
.brand svg { width: 26px; height: 26px; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a { padding: .4rem .75rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--select); color: var(--accent); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: .78rem; font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* ---------- Bausteine ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 1rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: 8px 0 0 8px; }
.btn-group .btn:last-child { border-radius: 0 8px 8px 0; }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn.active { background: var(--select); color: var(--accent); font-weight: 600; }

label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; padding: .55rem .7rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input[type=color] { padding: .15rem; height: 2.4rem; width: 3.5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field + .field { margin-top: .85rem; }
.row { display: flex; gap: .75rem; }
.row > * { flex: 1; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; flex-wrap: wrap; }
.actions .spacer { flex: 1; }

.alert { padding: .6rem .8rem; border-radius: 8px; font-size: .9rem; margin-bottom: .85rem; }
.alert.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.alert.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.alert.info { background: var(--surface-2); color: var(--text); }

table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th, table.list td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }

/* ---------- Login-Seiten ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { justify-content: center; font-size: 1.2rem; margin-bottom: 1rem; }
.auth-card .btn.primary { width: 100%; margin-top: 1.1rem; }
.auth-links { text-align: center; margin-top: 1rem; font-size: .9rem; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.15rem; letter-spacing: .05em; background: var(--surface-2); padding: .5rem .75rem; border-radius: 8px; display: inline-block; user-select: all; }

/* ---------- Dialog ---------- */
dialog { border: none; border-radius: 14px; padding: 0; width: min(480px, calc(100vw - 2rem)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 18, 22, .45); }
dialog form, dialog .dlg-body { padding: 1.25rem; }
dialog h2 { margin-bottom: 1rem; }

/* ---------- Toast ---------- */
#toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 100; background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; box-shadow: var(--shadow); font-size: .92rem; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }

/* ---------- Kalender ---------- */
.cal-toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.cal-title { font-size: 1.25rem; font-weight: 700; margin: 0 .5rem; min-width: 12ch; }
.cal-toolbar .spacer { flex: 1; }
.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); user-select: none; }
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--surface-2); border-bottom: 1px solid var(--border); }
.cal-head div { padding: .4rem .5rem; font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: minmax(22px, auto); position: relative; min-height: 104px; border-bottom: 1px solid var(--border); }
.cal-week:last-child { border-bottom: none; }
.cal-day { grid-row: 1 / -1; border-right: 1px solid var(--border); cursor: pointer; position: relative; }
.cal-day:nth-child(7) { border-right: none; }
.cal-day.other { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.cal-day.today { background: var(--today); }
.cal-day.sel { background: var(--select); }
.cal-day.readonly { cursor: default; }
.cal-num { grid-row: 1; padding: .2rem .45rem; font-size: .82rem; font-weight: 600; color: var(--muted); pointer-events: none; z-index: 1; }
.cal-num.today { color: var(--accent); }
.cal-bar {
  z-index: 2; margin: 1px 3px; padding: 1px 7px; border-radius: 5px; color: #fff; font-size: .8rem; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; line-height: 1.45;
  border: 0; text-align: left; font-family: inherit;
}
.cal-bar.cont-l { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; }
.cal-bar.cont-r { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; }
.cal-bar:focus-visible { outline: 2px solid var(--text); }
.cal.week .cal-week { min-height: 360px; grid-auto-rows: minmax(26px, auto); }
.cal.week .cal-bar { white-space: normal; padding: 4px 8px; font-size: .85rem; }
.cal.week .cal-bar .note { display: block; font-weight: 400; opacity: .9; font-size: .78rem; }
.cal.week .cal-num { font-size: .95rem; padding: .4rem .55rem; }
.legend { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin-top: .75rem; font-size: .85rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.cal-hint { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; }
.upcoming { margin-top: 1.25rem; }
.upcoming li { margin: .35rem 0; }
.upcoming ul { list-style: none; padding: 0; margin: 0; }
.upcoming .when { font-variant-numeric: tabular-nums; color: var(--muted); display: inline-block; min-width: 13ch; }

/* ---------- Klima ---------- */
.sensor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.sensor { position: relative; }
.sensor h3 { margin: 0; font-size: 1rem; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.sensor .temp { font-size: 2.3rem; font-weight: 700; line-height: 1.1; margin: .4rem 0 .2rem; font-variant-numeric: tabular-nums; }
.sensor .temp small { font-size: 1rem; font-weight: 500; color: var(--muted); }
.sensor dl { display: grid; grid-template-columns: auto 1fr; gap: .15rem .75rem; margin: .5rem 0 0; font-size: .9rem; }
.sensor dt { color: var(--muted); }
.sensor dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.sensor.outdoor { background: linear-gradient(135deg, color-mix(in srgb, #2b7fd8 12%, var(--surface)), var(--surface)); }
.sensor .foot { margin-top: .6rem; font-size: .78rem; color: var(--muted); }
.lvl-ok { color: var(--ok); } .lvl-warn { color: var(--warn); } .lvl-bad { color: var(--danger); }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(480px, 1fr)); gap: 1rem; margin-top: 1rem; }
@media (max-width: 560px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card h3 { margin: 0 0 .5rem; font-size: .95rem; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--border); }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: .4rem .6rem; font-size: .8rem; white-space: nowrap; z-index: 5; }
.chart-tip b { display: block; margin-bottom: .15rem; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .82rem; color: var(--muted); margin-top: .35rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.chart-legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

@media (max-width: 640px) {
  main { padding: .75rem; }
  .topbar { padding: .5rem .75rem; gap: .5rem; }
  .userbox .name { display: none; }
  .cal-week { min-height: 76px; }
  .cal-bar { font-size: .72rem; padding: 0 4px; }
  .cal-head div { padding: .3rem; font-size: .7rem; }
  .row { flex-direction: column; gap: .85rem; }
}
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.cell-actions { white-space: nowrap; text-align: right; }
.actions.start { justify-content: flex-start; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: var(--surface-2); padding: .05rem .3rem; border-radius: 4px; }
.history-head { margin-top: 2rem; margin-bottom: 0; }
.chart-tip .swatch { width: 9px; height: 9px; }
.chart-tip b.inline { display: inline; }

/* ---------- Einkaufsliste ---------- */
.shop { max-width: 760px; }
.shop > * + * { margin-top: 1rem; }
.shop-add-row { display: flex; gap: .5rem; }
.shop-add-row #text { flex: 2; }
.shop-add-row #note { flex: 1.3; }
.shop-add .alert { margin: .75rem 0 0; }
.shop-list { list-style: none; margin: 0; padding: 0; }
.shop-list li { display: flex; align-items: center; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.shop-list li:last-child { border-bottom: none; }
.shop-list li.empty { display: block; padding: .5rem 0; }
.shop-item { flex: 1; display: flex; align-items: flex-start; gap: .7rem; margin: 0; font-weight: 400; font-size: 1rem; cursor: pointer; }
.shop-item input { width: 1.25rem; height: 1.25rem; margin-top: .15rem; accent-color: var(--accent); flex: none; }
.shop-meta { display: block; font-size: .8rem; color: var(--muted); }
.shop-list.done .shop-text b { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.shop-done-head { margin-bottom: .25rem; }
.shop-done-head h2 { margin: 0; }
.shop h2 .badge { vertical-align: middle; margin-left: .25rem; }
@media (max-width: 640px) { .shop-add-row { flex-direction: column; } }

/* ---------- Startseite ---------- */
.hero {
  position: relative; min-height: clamp(280px, 52vh, 520px); display: flex; align-items: flex-end;
  background: #6b8fb5 url('/img/altberg.jpg') center 62% / cover no-repeat;
  color: #fff;
}
.hero::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0) 35%, rgba(0,0,0,.55) 100%);
}
.hero-inner { position: relative; width: 100%; max-width: 1200px; margin: 0 auto; padding: 1.25rem 1.25rem 4.5rem; }
.hero-kicker { margin: 0; font-size: 1.05rem; font-weight: 500; opacity: .95; text-shadow: 0 1px 3px rgba(0,0,0,.4); }
.hero-title { margin: .1rem 0 .35rem; font-size: clamp(2.4rem, 7vw, 4rem); font-weight: 800; letter-spacing: -.02em; line-height: 1; text-shadow: 0 2px 12px rgba(0,0,0,.35); }
.hero-status { margin: 0; display: inline-block; background: rgba(255,255,255,.18); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); padding: .35rem .75rem; border-radius: 99px; font-size: .92rem; font-weight: 500; }
.hero-status:empty { display: none; }
.start { margin-top: -3.25rem; position: relative; }
.start-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.tile { display: flex; flex-direction: column; color: var(--text); text-decoration: none; transition: transform .15s, box-shadow .15s; }
.tile:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(0,0,0,.06), 0 10px 28px rgba(0,0,0,.1); }
.tile h2 { display: flex; align-items: center; gap: .4rem; }
.tile-list { list-style: none; margin: 0; padding: 0; font-size: .92rem; }
.tile-list li { padding: .3rem 0; border-bottom: 1px solid var(--border); }
.tile-list li:last-child { border-bottom: none; }
.tile-list .when { display: inline-block; min-width: 9.5em; color: var(--muted); font-variant-numeric: tabular-nums; }
.tile-temp { font-size: 2.2rem; font-weight: 700; line-height: 1.1; margin-bottom: .4rem; font-variant-numeric: tabular-nums; }
.tile-temp small { font-size: .95rem; font-weight: 500; color: var(--muted); }
.tile-more { margin-top: auto; padding-top: .8rem; color: var(--accent); font-weight: 600; font-size: .9rem; }

/* Login-Seiten mit Hintergrundbild */
.auth-wrap { background: #6b8fb5 url('/img/altberg.jpg') center 62% / cover no-repeat; position: relative; }
.auth-wrap::before { content: ''; position: absolute; inset: 0; background: rgba(10, 20, 30, .25); }
.auth-card { position: relative; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.tile-list .when.block { display: block; min-width: 0; font-size: .82rem; }
