:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #14181d;
  --muted: #5d6673;
  --border: #dfe3e8;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --free: #15803d;
  --free-bg: #e5f5ea;
  --soon: #a15c00;
  --soon-bg: #fff1d6;
  --busy: #b42318;
  --busy-bg: #fde8e6;
  --closed: #66707c;
  --closed-bg: #eceff2;
  --bar-busy: #e8a29b;
  --bar-free: #bfe3cb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f252c;
    --text: #e8ecf0;
    --muted: #9aa4b1;
    --border: #2a313a;
    --accent: #2dd4bf;
    --accent-text: #062a26;
    --free: #4ade80;
    --free-bg: #12301f;
    --soon: #fbbf24;
    --soon-bg: #33270d;
    --busy: #f87171;
    --busy-bg: #3a1714;
    --closed: #9aa4b1;
    --closed-bg: #232a32;
    --bar-busy: #8f3b34;
    --bar-free: #1f5236;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* ---------- Kopf ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 0 10px;
}
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: 1.45rem; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: .9rem; font-weight: 600;
  padding: 6px 14px; border-radius: 8px; cursor: pointer;
}
.seg.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.when {
  font: inherit; font-size: .9rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 10px; min-height: 36px;
}

.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

.chips { display: flex; gap: 6px; overflow-x: auto; margin-top: 10px; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: .85rem; padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: .9rem; font-weight: 600;
  border-radius: 10px; padding: 8px 14px; cursor: pointer; border: 1px solid transparent;
  white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--busy-bg); color: var(--busy); }
.btn:focus-visible, .seg:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Liste ---------- */
.summary { color: var(--muted); font-size: .9rem; margin: 16px 0 10px; }
.summary strong { color: var(--text); }
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 10px; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

.banner {
  margin-top: 14px; padding: 10px 14px; border-radius: 10px;
  background: var(--soon-bg); color: var(--soon); font-size: .9rem;
}

/* Kacheln */
.tile {
  display: flex; flex-direction: column; min-width: 0;
  padding: 12px 12px 10px; text-align: left; cursor: pointer;
  font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.tile:hover { border-color: var(--muted); }
.tile:active { transform: scale(.98); }
.tile:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.tile .code { font-size: 1.12rem; }
.tile .pill { font-size: .68rem; padding: 2px 7px; }
.tile .meta { margin-top: 1px; }
.tile .detail { margin-top: 8px; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .detail-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .timeline { margin-top: 8px; }
.tile .track { height: 6px; border-radius: 3px; }
.tile .track-wrap .now-mark { height: 12px; }
.tile.s-closed { background: var(--bg); box-shadow: none; }

.code { display: block; font-size: 1.2rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.meta { display: block; color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  display: inline-block; flex: none; font-size: .78rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px;
}
.detail { display: block; font-size: .9rem; font-weight: 600; margin-top: 3px; font-variant-numeric: tabular-nums; }
.detail-sub { display: block; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.s-free .pill { background: var(--free-bg); color: var(--free); }
.s-free .detail { color: var(--free); }
.s-soon .pill { background: var(--soon-bg); color: var(--soon); }
.s-soon .detail { color: var(--soon); }
.s-busy .pill { background: var(--busy-bg); color: var(--busy); }
.s-closed .pill, .s-unknown .pill { background: var(--closed-bg); color: var(--closed); }
.s-closed .code { color: var(--muted); }
.s-closed .detail, .s-unknown .detail { color: var(--muted); font-weight: 400; font-size: .85rem; }

/* Tagesbalken */
.track { position: relative; height: 10px; background: var(--bar-free); border-radius: 5px; overflow: hidden; }
.s-closed .track, .s-unknown .track { background: var(--surface-2); }
.seg-busy { position: absolute; top: 0; bottom: 0; background: var(--bar-busy); }
.now-mark { position: absolute; width: 2px; background: var(--text); border-radius: 1px; }
.track-wrap { position: relative; }
.track-wrap .now-mark { top: -3px; height: 16px; }
.ticks { position: relative; height: 1.1em; color: var(--muted); font-size: .72rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
.ticks span { position: absolute; top: 0; white-space: nowrap; }
.ticks .tick { transform: translateX(-50%); }
.ticks .tick-start { left: 0; }
.ticks .tick-end { right: 0; }

/* Details (Dialog) */
.extra { padding: 18px 20px 20px; font-size: .9rem; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-head h2 { margin: 0; font-size: 1.5rem; letter-spacing: -.01em; }
.detail-head .meta { font-size: .88rem; margin: 2px 0 0; white-space: normal; }
.icon-btn {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--text); font-size: 1rem; line-height: 1;
}
.detail-status { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin: 14px 0 12px; }
.detail-status .detail { margin: 0; font-size: 1rem; }
.extra .timeline { margin-bottom: 16px; }
.extra h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.events li { display: grid; grid-template-columns: 96px 1fr; gap: 8px; }
.events time { font-variant-numeric: tabular-nums; color: var(--muted); }
.events li.past { opacity: .5; }
.events li.current time { color: var(--busy); font-weight: 600; }
.extra .note { margin: 0 0 12px; color: var(--soon); }
.extra p { margin: 0; }
.extra a { color: var(--accent); font-weight: 600; }
.extra .links { margin-top: 14px; }

/* ---------- Footer ---------- */
.foot { color: var(--muted); font-size: .8rem; padding-top: 24px; padding-bottom: 40px; }
.foot p { margin: 0 0 8px; }

/* ---------- Dialog ---------- */
.dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.dialog::backdrop { background: rgba(10, 14, 20, .5); }
.dialog form { padding: 20px; }
.dialog h2 { margin: 0 0 6px; font-size: 1.2rem; }
.muted { color: var(--muted); font-size: .9rem; margin: 0 0 14px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; font-size: .9rem; font-weight: 600; }
.field em { font-weight: 400; color: var(--muted); font-style: normal; }
.field input, .field textarea, .field select {
  font: inherit; font-weight: 400; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; width: 100%;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.form-msg { min-height: 1.2em; margin: 0 0 8px; font-size: .9rem; }
.form-msg.ok { color: var(--free); }
.form-msg.err { color: var(--busy); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 420px) {
  .title-row .btn { padding: 8px 10px; }
  .list { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 10px 10px 9px; }
  .events li { grid-template-columns: 88px 1fr; }
}

/* Detail-Fenster: auf dem Handy als Sheet von unten */
.sheet { width: min(520px, calc(100vw - 32px)); max-height: 85vh; overflow-y: auto; overflow-x: hidden; }
@media (max-width: 600px) {
  .sheet {
    width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0;
    max-height: 85vh;
  }
}

/* ---------- Beliebtheit ---------- */
.tile-meta { display: flex; align-items: center; gap: 6px; min-width: 0; margin-top: 1px; }
.tile-meta .meta { flex: 1 1 auto; min-width: 0; margin: 0; }
.score {
  flex: none; font-size: .72rem; font-weight: 700; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.score.pos { color: var(--accent); }
.score.neg { color: var(--busy); }
.score.voted::after { content: "•"; margin-left: 2px; }

.vote {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px;
  margin: 0 0 16px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
}
.vote-label { font-weight: 600; font-size: .9rem; }
.vote-buttons { display: flex; gap: 8px; }
.vote-btn {
  display: inline-flex; align-items: center; gap: 6px; min-width: 64px; justify-content: center;
  font: inherit; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 7px 12px; border-radius: 10px; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.vote-btn svg { width: 18px; height: 18px; fill: currentColor; }
.vote-btn.up.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.vote-btn.down.active { background: var(--busy); color: #fff; border-color: var(--busy); }
.vote-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.vote-msg { flex-basis: 100%; margin: 0; font-size: .82rem; color: var(--busy); }
.vote-msg:empty { display: none; }

/* ---------- Impressum / Datenschutz ---------- */
.foot-links a { color: var(--muted); }
.legal { max-width: 720px; padding-top: 24px; padding-bottom: 48px; }
.legal h1 { font-size: 1.6rem; margin: 8px 0 16px; }
.legal h2 { font-size: 1.05rem; margin: 24px 0 6px; }
.legal p { margin: 0 0 10px; }
.legal a { color: var(--accent); }

/* ---------- Raum-Infos ---------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 12px; }
.stat {
  display: flex; flex-direction: column; min-width: 0;
  padding: 12px 12px 10px; border-radius: 12px; background: var(--surface-2);
}
.stat-value {
  font-size: 2rem; line-height: 1.05; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-value.word { font-size: 1.3rem; line-height: 1.55; letter-spacing: -.01em; }
.stat-label { margin-top: 4px; font-size: .82rem; font-weight: 600; }
.stat-sub { margin-top: 1px; font-size: .74rem; line-height: 1.3; color: var(--muted); overflow-wrap: anywhere; }
.stat.empty .stat-value { color: var(--muted); }
.info-empty { margin: 0 0 12px !important; color: var(--muted); font-size: .88rem; }

.contribute { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 4px; }
.contribute summary {
  display: flex; align-items: center; justify-content: space-between; cursor: pointer;
  list-style: none; padding: 10px 0; font-weight: 600; color: var(--accent);
}
.contribute summary::-webkit-details-marker { display: none; }
.contribute summary::after { content: "+"; font-size: 1.3rem; line-height: 1; font-weight: 400; }
.contribute[open] summary::after { content: "–"; }
.contribute summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.contribute-form { padding-bottom: 4px; }
.contribute-form .muted { margin-bottom: 12px; font-size: .84rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .field { margin-bottom: 4px; font-size: .84rem; }

.choice { border: 0; padding: 0; margin: 10px 0 12px; min-width: 0; }
.choice legend { padding: 0; margin-bottom: 6px; font-size: .84rem; font-weight: 600; }
.choice-options { display: flex; flex-wrap: wrap; gap: 6px; }
.choice-opt { position: relative; cursor: pointer; }
.choice-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice-opt span {
  display: inline-block; padding: 6px 12px; border-radius: 999px; font-size: .84rem;
  border: 1px solid var(--border); background: var(--surface);
}
.choice-opt input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.choice-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 420px) {
  .stat { padding: 10px 10px 8px; }
  .stat-value { font-size: 1.7rem; }
  .stat-value.word { font-size: 1.1rem; line-height: 1.55; }
}

/* ---------- Feedback ---------- */
.link-btn {
  padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; color: var(--muted); text-decoration: underline;
}
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
#feedback .choice { margin-top: 0; }
