/* Sempach Connect – Design (Farben aus dem offiziellen Logo) */
@font-face { font-family: 'Montserrat'; font-style: normal; font-weight: 400 800; font-display: swap;
  src: url('../assets/fonts/montserrat-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Montserrat'; font-style: normal; font-weight: 400 800; font-display: swap;
  src: url('../assets/fonts/montserrat-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  --yellow: #ffd200;
  --yellow-soft: #fff4b8;
  --red: #d9141e;
  --red-dark: #a50e15;
  --black: #141414;
  --blue: #1269d3;
  --green: #2e8b3a;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --line: #e4e1d9;
  --muted: #5f5b53;
  --neutral-fill: #ebe8e1;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(20, 20, 20, .10), 0 1px 3px rgba(20, 20, 20, .08);
  --header-h: 64px;
  --font-head: 'Montserrat', system-ui, sans-serif;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.45 var(--font); color: var(--black); background: var(--bg); display: flex; flex-direction: column; height: 100dvh; overflow: hidden; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 26px; font-weight: 800; } h2 { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; justify-content: space-between; } h3 { font-size: 15px; font-weight: 700; margin-top: 1.4em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--black); color: #fff; padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: .4em 0; }

/* ---------- Header ---------- */
.topbar { flex: 0 0 auto; height: var(--header-h); display: flex; align-items: center; gap: 16px; padding: 0 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); background: var(--surface); position: relative; z-index: 20; box-shadow: 0 1px 0 var(--line); }
.topbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -4px; height: 4px; background: linear-gradient(to bottom, var(--red) 0 50%, var(--yellow) 50% 100%); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--black); flex: 0 0 auto; }
.brand img { display: block; width: 46px; height: 46px; }
.wordmark { display: flex; flex-direction: column; font-family: var(--font-head); line-height: 1; }
.wordmark b { font-weight: 800; font-size: 21px; letter-spacing: .5px; }
.wordmark span { font-weight: 500; font-size: 10.5px; letter-spacing: 5.4px; margin-top: 3px; }
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tabs button { font: 600 14px var(--font-head); border: 0; background: none; padding: 9px 14px; border-radius: 999px; color: var(--black); cursor: pointer; }
.tabs svg { display: none; width: 22px; height: 22px; }
.tabs button:hover { background: var(--bg); }
.tabs button[aria-pressed="true"] { background: var(--black); color: #fff; }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.userbox { display: flex; align-items: center; gap: 8px; }
.user-email { font-size: 13px; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-only { display: none; }

/* ---------- Buttons & Forms ---------- */
.btn { font: 600 14px var(--font-head); display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1.5px solid var(--black); background: var(--surface); color: var(--black); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--black); color: #fff; }
.btn-primary:hover { background: #333; }
.btn-accent { background: var(--yellow); border-color: var(--black); }
.btn-accent:hover { background: #ffdf40; }
.btn-danger { border-color: var(--red); color: var(--red-dark); }
.btn-danger:hover { background: #fdecec; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 8px 0; font: inherit; text-decoration: underline; }
.form label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 0; }
.form input, .form select { display: block; width: 100%; margin-top: 4px; font: 15px var(--font); padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; color: var(--black); min-height: 42px; }
.form input:focus { border-color: var(--black); outline: none; box-shadow: 0 0 0 3px var(--yellow-soft); }
.form details { margin-top: 10px; font-size: 13px; } .form summary { cursor: pointer; color: var(--muted); }
.form-error { color: var(--red-dark); background: #fdecec; border-radius: 8px; padding: 8px 10px; font-size: 13px; }

/* ---------- Banner & Toast ---------- */
.banner { flex: 0 0 auto; margin-top: 4px; padding: 8px 16px; font-size: 13.5px; background: var(--yellow-soft); border-bottom: 1px solid #efd96a; z-index: 15; text-align: center; }
.banner.error { background: #fdecec; border-color: #f3b5b8; color: var(--red-dark); }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 200; background: var(--black); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); max-width: min(520px, calc(100vw - 32px)); font-size: 14px; display: flex; gap: 12px; align-items: center; }
.toast.error { background: var(--red-dark); }
.toast button { background: var(--yellow); color: var(--black); border: 0; border-radius: 8px; padding: 6px 10px; font-weight: 700; cursor: pointer; }

/* ---------- Layout ---------- */
main { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; margin-top: 4px; }
main[data-view="stats"], main[data-view="admin"] { display: block; overflow: auto; }
main[data-view="stats"] .map-area, main[data-view="stats"] .side, main[data-view="admin"] .map-area, main[data-view="admin"] .side { display: none; }
.map-area { position: relative; min-height: 0; min-width: 0; background: #dfe8ee; }
#map { position: absolute; inset: 0; }
.map-loading, .map-error { position: absolute; inset: 0; display: grid; place-items: center; font: 600 15px var(--font-head); color: var(--muted); pointer-events: none; text-align: center; padding: 24px; }
.map-error { background: var(--bg); pointer-events: auto; }

/* Karte: Fortschritts-Chip & Legende */
.map-chip { position: absolute; left: 16px; bottom: 30px; background: rgba(255, 255, 255, .96); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; min-width: 240px; z-index: 5; }
.chip-row { display: flex; align-items: baseline; gap: 6px; font-size: 13px; color: var(--muted); }
.chip-row strong { font: 800 22px var(--font-head); color: var(--red); }
.legend { display: flex; gap: 14px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid rgba(0, 0, 0, .25); }
.sw-on { background: var(--red); } .sw-off { background: var(--neutral-fill); }
.bar { height: 8px; background: var(--neutral-fill); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--red), #ef3a2b); border-radius: inherit; transition: width .6s ease; }
.bar-lg { height: 12px; } .bar-xl { height: 22px; }

/* Info-Karte */
.info { position: absolute; top: 16px; left: 16px; width: 340px; max-height: calc(100% - 32px); overflow: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 10; padding: 16px 18px 18px; border-top: 6px solid var(--neutral-fill); }
.info.is-on { border-top-color: var(--red); }
.info-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.info h2 { font-size: 21px; margin: 0; display: block; }
.info .close { border: 0; background: var(--bg); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 18px; line-height: 1; flex: 0 0 auto; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0 0; font-size: 14px; }
.info dt { color: var(--muted); } .info dd { margin: 0; font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: 6px; font: 700 12.5px var(--font-head); padding: 4px 10px; border-radius: 99px; background: var(--neutral-fill); color: var(--black); }
.badge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #9c978c; }
.badge.on { background: #fde3e4; color: var(--red-dark); } .badge.on::before { background: var(--red); }
.admin-box { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.admin-box .form label { margin-top: 0; }

/* ---------- Seitenleiste / Liste ---------- */
.side { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--line); }
.progress-card { padding: 16px 18px 14px; border-bottom: 1px solid var(--line); }
.pc-top { display: flex; justify-content: space-between; align-items: flex-end; }
.pc-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.pc-value { font: 800 34px var(--font-head); line-height: 1.05; }
.pc-nums { text-align: right; font-size: 13px; color: var(--muted); } .pc-nums b { color: var(--red); font-size: 15px; }
.filters { padding: 12px 18px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.search { position: relative; display: block; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { width: 100%; font: 15px var(--font); padding: 11px 12px 11px 38px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); min-height: 44px; }
.search input:focus { outline: none; border-color: var(--black); background: #fff; box-shadow: 0 0 0 3px var(--yellow-soft); }
.filter-row { display: flex; gap: 8px; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; flex: 1 1 auto; }
.seg button { flex: 1; border: 0; background: none; font: 600 13px var(--font-head); padding: 7px 6px; border-radius: 8px; cursor: pointer; color: var(--muted); min-height: 34px; }
.seg button[aria-pressed="true"] { background: #fff; color: var(--black); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
#kt { font: 13px var(--font); border: 1.5px solid var(--line); border-radius: 10px; padding: 0 8px; background: #fff; max-width: 130px; min-height: 40px; }
.list-head { padding: 8px 18px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--line); }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid #f0eee8; cursor: pointer; content-visibility: auto; contain-intrinsic-size: auto 46px; }
.list li:hover { background: var(--bg); }
.list li[aria-selected="true"] { background: var(--yellow-soft); box-shadow: inset 4px 0 0 var(--black); }
.list .dot { width: 10px; height: 10px; border-radius: 50%; background: #c9c4b9; flex: 0 0 auto; }
.list .on .dot { background: var(--red); }
.list .nm { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.list .kt { font: 700 11px var(--font-head); background: var(--bg); padding: 3px 6px; border-radius: 6px; color: var(--muted); }
.list .dt { font-size: 12px; color: var(--red-dark); white-space: nowrap; }
.list .empty { justify-content: center; color: var(--muted); cursor: default; }

/* ---------- Seiten (Statistik / Verwaltung) ---------- */
.page-inner { max-width: 1100px; margin: 0 auto; padding: 28px 20px 60px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(20, 20, 20, .06); border: 1px solid var(--line); padding: 20px; margin-bottom: 18px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.grid-2 .card { margin-bottom: 0; } .grid-2 + .card, .grid-2 + .source { margin-top: 18px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi-value { font: 800 32px var(--font-head); margin-top: 4px; }
.kpi-on .kpi-value { color: var(--red); }
.kpi-accent { background: var(--yellow); border-color: var(--yellow); }
.bp-labels { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.bp-labels span:nth-child(2) { font-weight: 700; color: var(--black); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 7px 8px; border-bottom: 1px solid #f0eee8; vertical-align: middle; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .bar-col { width: 34%; }
.table .bar { margin: 0; height: 8px; }
.table-wrap { overflow-x: auto; }
.recent { list-style: none; padding: 0; margin: 0; }
.recent li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f0eee8; }
.recent button { background: none; border: 0; padding: 0; font: 600 14px var(--font); cursor: pointer; color: var(--black); text-align: left; }
.recent button:hover { text-decoration: underline; }
.source { font-size: 12.5px; color: var(--muted); }
.source a, .info a { color: inherit; }
.admins { list-style: none; padding: 0; margin: 0 0 8px; }
.admins li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #f0eee8; }
.admins .who { flex: 1; min-width: 0; } .admins .who b { display: block; } .admins .who span { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.check-ok { color: var(--green); font-weight: 600; } .check-warn { color: var(--red-dark); font-weight: 600; }
.orphan { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid #f0eee8; font-size: 14px; }
.orphan .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.orphan input { width: 110px; padding: 6px 8px; border: 1.5px solid var(--line); border-radius: 8px; font: inherit; min-height: 36px; }

.form-inline { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.form-inline label { margin-top: 0; }

/* ---------- Lobby (Startbildschirm) ---------- */
.lobby { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; overflow: auto; padding: 24px 16px max(24px, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 50% 38%, #fff 0 45%, #fbf8ec 75%, #f5efd6 100%); }
.lobby::before { content: ''; position: fixed; left: 0; right: 0; top: 0; height: 8px; background: linear-gradient(to bottom, var(--red) 0 50%, var(--yellow) 50% 100%); }
.lobby-inner { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; width: 100%; max-width: 560px; }
.lobby-logo { display: block; width: min(78vw, 520px, calc(100dvh - 300px)); min-width: 200px; height: auto; aspect-ratio: 1; animation: lobby-in .7s ease both; }
.lobby-sub { font: 600 17px var(--font-head); margin: 0; color: var(--black); }
.lobby-stat { width: min(340px, 90vw); font-size: 14px; color: var(--muted); }
.lobby-stat b { color: var(--red); font: 800 18px var(--font-head); }
.btn-xl { min-height: 56px; padding: 12px 34px; font-size: 18px; border-radius: 14px; gap: 10px; box-shadow: 0 6px 18px rgba(20, 20, 20, .22); }
.btn-xl:hover { transform: translateY(-1px); }
.lobby.leaving { animation: lobby-out .35s ease forwards; }
@keyframes lobby-in { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes lobby-out { to { opacity: 0; visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .lobby-logo, .lobby.leaving { animation: none; } }

/* ---------- Dialog ---------- */
.dialog { border: 0; border-radius: 18px; padding: 24px; width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(20, 20, 20, .45); }
.dialog-logo { display: block; margin: 0 auto 8px; }
.dialog h2 { justify-content: center; text-align: center; }

/* ---------- MapLibre-Anpassungen ---------- */
.maplibregl-popup.sc-tip .maplibregl-popup-content { padding: 6px 10px; border-radius: 8px; font: 600 13px var(--font-head); box-shadow: var(--shadow); }
.maplibregl-popup.sc-tip .maplibregl-popup-tip { display: none; }
.maplibregl-ctrl-group { border-radius: 10px !important; box-shadow: var(--shadow) !important; }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* ---------- Tablet / Smartphone ---------- */
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  :root { --header-h: 58px; }
  .mobile-only { display: inline-block; }
  main { display: block; position: relative; }
  main[data-view="map"] .side { display: none; }
  main[data-view="list"] .map-area { display: none; }
  main[data-view="map"] .map-area, main[data-view="list"] .side { position: absolute; inset: 0; }
  .side { border-left: 0; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .info { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 62%; border-radius: 18px 18px 0 0; padding-bottom: max(18px, env(safe-area-inset-bottom)); box-shadow: 0 -6px 24px rgba(0, 0, 0, .18); }
  .map-chip { top: 12px; bottom: auto; left: 12px; min-width: 0; padding: 8px 12px; }
  .map-chip .legend { display: none; }
  .chip-row strong { font-size: 18px; }
  .map-area.has-info .map-chip { display: none; }
}
@media (max-width: 640px) {
  .topbar { gap: 8px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .wordmark b { font-size: 18px; } .wordmark span { font-size: 9px; letter-spacing: 4.6px; }
  .brand img { width: 40px; height: 40px; }
  /* Untere App-Navigation */
  :root { --nav-h: calc(60px + env(safe-area-inset-bottom)); }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0; gap: 0; height: var(--nav-h); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -2px 10px rgba(0, 0, 0, .06); }
  .tabs button { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 0; padding: 4px 2px; font-size: 11.5px; color: var(--muted); min-width: 0; }
  .tabs button.mobile-only { display: flex; }
  .tabs button[hidden] { display: none; }
  .tabs svg { display: block; }
  .tabs button:hover { background: none; }
  .tabs button[aria-pressed="true"] { background: none; color: var(--black); box-shadow: inset 0 3px 0 var(--red); }
  main { margin-bottom: var(--nav-h); }
  .toast { bottom: calc(var(--nav-h) + 12px); }
  .info { padding-bottom: 18px; }
  .account { margin-left: auto; }
  .account .btn span { display: none; }
  .btn-ghost#btnLogin, #btnLogout { padding: 8px; min-width: 40px; }
  .user-email { display: none; }
  .banner { font-size: 12.5px; padding: 6px 12px; }
  .page-inner { padding: 20px 14px 50px; }
  .form-inline { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 22px; }
  .kpi-value { font-size: 26px; }
  .table .bar-col { width: 28%; }
}
@media (max-width: 380px) {
  .seg button { font-size: 12px; }
  #kt { max-width: 100px; }
}
@media (prefers-reduced-motion: reduce) { .bar i { transition: none; } }
