:root {
  --bg: #f4f6f8; --card: #ffffff; --text: #1b2733; --muted: #5d6b79; --line: #d9e0e7;
  --accent: #1f6fb2; --danger: #b3261e;
  --surface: #ffffff; --grid: #e3e8ee;
  /* Verkehrsmittel: geprüfte kategoriale Palette, feste Zuordnung (Farbe folgt dem Verkehrsmittel) */
  --fahrzeug: #2a78d6; --laufen: #eb6834; --gehen: #1baf7a; --velo: #eda100; --aufenthalt: #6250d6; --keine_daten: #8a96a3;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
h1 { font-size: 26px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
button { font: inherit; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; }
button[type=submit], #auth-submit { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--danger); border-color: #e6b8b5; }
button.danger[type=submit] { background: var(--danger); border-color: var(--danger); color: #fff; }
button:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible, li:focus-visible { outline: 3px solid #9cc7ea; outline-offset: 1px; }
input[type=email], input[type=password] { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; border: 1px solid var(--line); border-radius: 8px; }
label { display: block; margin: 12px 0; font-weight: 600; font-size: 14px; }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0; }
.hint, .lead, .sources { color: var(--muted); }
.hint:empty { display: none; }

/* Anmeldung */
#auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
#auth[hidden], #app[hidden] { display: none; }
.card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.card button { width: 100%; margin-top: 6px; }
.switch { display: flex; justify-content: space-between; gap: 12px; margin: 16px 0 0; font-size: 14px; }
a { color: var(--accent); }

/* Anwendung */
#app { height: 100%; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-size: 17px; }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.notice { font-size: 13px; background: #fff4d6; border: 1px solid #ecd58f; border-radius: 6px; padding: 3px 8px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; }
.menu summary::-webkit-details-marker { display: none; }
.menu-items { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; display: grid; gap: 6px; padding: 10px; width: 250px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.menu-items button { text-align: left; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 230px 1fr; }
#days { overflow-y: auto; background: var(--card); border-right: 1px solid var(--line); padding: 8px; }
#days button { display: block; width: 100%; text-align: left; border: 0; border-radius: 8px; padding: 8px 10px; margin-bottom: 2px; background: transparent; }
#days button:hover { background: #eef3f8; }
#days .d { font-weight: 600; }
#days .m { color: var(--muted); font-size: 12.5px; }
#days .empty { color: var(--muted); padding: 10px; }

.main { min-width: 0; min-height: 0; display: grid; grid-template-columns: 1fr 360px; grid-template-rows: 1fr auto; }
#map { grid-column: 1; grid-row: 1; min-height: 300px; }
.layers { grid-column: 1; grid-row: 2; display: flex; flex-wrap: wrap; gap: 4px 18px; padding: 8px 14px; background: var(--card); border-top: 1px solid var(--line); font-size: 14px; }
.layers label { margin: 0; font-weight: 400; }
.panel { grid-column: 2; grid-row: 1 / span 2; overflow-y: auto; padding: 14px 16px; background: var(--card); border-left: 1px solid var(--line); }
.summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 14px 86px 1fr; gap: 8px; align-items: baseline; padding: 7px 6px; border-radius: 8px; cursor: pointer; }
.timeline li:hover, .timeline li.active { background: #eef3f8; }
.timeline .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13.5px; }
.timeline .what { font-weight: 600; }
.timeline .meta { display: block; color: var(--muted); font-weight: 400; font-size: 13px; }
.sources { font-size: 12px; margin-top: 18px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; max-width: 420px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(20, 30, 40, .45); }
.row { display: flex; justify-content: flex-end; gap: 8px; }
.maplibregl-popup-content { font: 13px/1.4 inherit; padding: 8px 10px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #days { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  #days button { flex: none; width: auto; margin: 0 2px 0 0; }
  .main { grid-template-columns: 1fr; grid-template-rows: 45vh auto auto; overflow-y: auto; }
  #map { grid-row: 1; }
  .layers { grid-row: 2; }
  .panel { grid-column: 1; grid-row: 3; border-left: 0; overflow: visible; }
  .who { display: none; }
}

/* Ansichten */
.tabs { display: flex; gap: 2px; margin-left: 8px; }
.tabs button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tabs button:hover { background: #eef3f8; }
.tabs button[aria-current=true] { background: #dcebf7; color: var(--text); }
.layout[hidden], .page[hidden] { display: none; }

/* Tagesliste mit Optionen */
#days .day { border-radius: 8px; margin-bottom: 2px; }
#days .day.current { background: #dcebf7; }
#days .day .line { display: flex; align-items: stretch; }
#days .day .open { flex: 1; margin: 0; background: transparent; }
#days .day.current .open:hover { background: transparent; }
#days .day.is-hidden .d, #days .day.is-hidden .m { color: #8a96a3; }
#days .day .more { width: 34px; flex: none; padding: 0; margin: 0; text-align: center; font-size: 18px; line-height: 1; color: var(--muted); background: transparent; border: 0; border-radius: 8px; }
#days .day .more:hover { background: rgba(0,0,0,.06); }
#days .day .options { display: flex; gap: 6px; padding: 0 8px 8px; }
#days .day .options[hidden] { display: none; }
#days .day .options button { width: auto; flex: 1; padding: 5px 8px; font-size: 13px; text-align: center; border: 1px solid var(--line); background: #fff; margin: 0; }
#days .day .options button.danger { color: var(--danger); border-color: #e6b8b5; }
#days .show-hidden { display: block; padding: 10px; font-size: 13px; font-weight: 400; color: var(--muted); margin: 0; }

/* Analyse */
.page { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; }
.page > * { max-width: 980px; margin-left: auto; margin-right: auto; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 12px; }
.filters label { margin: 0; font-weight: 600; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px; }
.filters label.check { font-weight: 400; }
.filters select, .filters input[type=date] { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
.filters label[hidden] { display: none; }
.note { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.note:empty { display: none; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi .v { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 13px; }
.viz { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.meters { display: grid; grid-template-columns: max-content 1fr max-content; gap: 10px 12px; align-items: center; }
.meters .name { display: inline-flex; align-items: center; gap: 8px; }
.meters .track { height: 16px; min-width: 60px; }
.meters .bar { display: block; height: 16px; min-width: 2px; border-radius: 0 4px 4px 0; }
.meters .bar:hover, .meters .bar:focus-visible { filter: brightness(1.12); }
.meters .stack { display: flex; gap: 1px; border-radius: 0 4px 4px 0; overflow: hidden; }
.meters .stack span { display: block; height: 16px; min-width: 2px; }
.meters .stack:hover, .meters .stack:focus-visible { filter: brightness(1.12); }
.meters .fig { text-align: right; font-variant-numeric: tabular-nums; }
.meters .fig b { font-weight: 650; }
.meters .fig span { display: block; color: var(--muted); font-size: 12.5px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { font: 11.5px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; fill: var(--muted); }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .col:hover .seg, .chart .col:focus .seg { filter: brightness(1.12); }
.chart .col { outline: none; }
.chart .col:focus-visible .hit { stroke: #9cc7ea; stroke-width: 2; }
.chart .empty { color: var(--muted); padding: 20px 0; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }
tfoot td { font-weight: 650; border-bottom: 0; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: #1b2733; color: #fff; border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 260px; }
.tip .h { font-weight: 600; margin-bottom: 4px; }
.tip .r { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; }
.tip .r i { width: 12px; height: 3px; border-radius: 2px; }
.tip .r b { font-variant-numeric: tabular-nums; }
.tip .r span { color: #c9d3dd; }

/* Heatmap */
.page.heat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.page.heat[hidden] { display: none; }
.page.heat > * { max-width: none; margin: 0; }
.page.heat .filters { padding: 10px 16px; margin: 0; background: var(--card); border-bottom: 1px solid var(--line); }
#heatmap { flex: 1; min-height: 300px; }
.ramp { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.ramp i { width: 90px; height: 10px; border-radius: 5px; background: linear-gradient(90deg, #cde2fb, #5598e7, #256abf, #0d366b); }
@media (max-width: 900px) { .tabs button { padding: 7px 8px; } .meters { grid-template-columns: max-content 1fr; } .meters .fig { grid-column: 1 / -1; text-align: left; margin-top: -6px; } }

/* Kontoeinstellungen */
button.notice { cursor: pointer; color: var(--text); font: inherit; font-size: 13px; }
#settings-dialog { max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.dialog-head h2 { margin: 0; }
.setting { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.setting h3 { font-size: 15px; margin: 0 0 8px; }
.setting .current { margin: 0 0 6px; font-weight: 600; overflow-wrap: anywhere; }
.setting .state { font-weight: 400; font-size: 13px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.setting .state.ok { background: #e6f5ea; border-color: #b9dfc3; }
.setting .state.warn { background: #fff4d6; border-color: #ecd58f; }
.setting .pending { background: #eef3f8; border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 14px; overflow-wrap: anywhere; }
.setting .pending[hidden], .setting button[hidden] { display: none; }
.setting form { margin-top: 10px; }
.setting form button[type=submit] { margin-top: 4px; }
.status { min-height: 1.2em; margin: 6px 0; font-size: 14px; }
.status.error { color: var(--danger); }
.status.good { color: #1c6b34; }
button.link { border: 0; background: none; color: var(--accent); padding: 0 4px; text-decoration: underline; }

/* Registrierung, Kopplung */
#consent label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 13.5px; margin: 10px 0; }
#consent input { margin-top: 3px; flex: none; }
#consent[hidden] { display: none; }
.legal { text-align: center; font-size: 13px; margin: 14px 0 0; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.qr { display: grid; place-items: center; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; margin: 10px auto; width: max-content; }
.qr img { display: block; }
.pair-code { text-align: center; }
.pair-code strong { font: 600 20px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; margin-left: 6px; }
.devices { list-style: none; margin: 0 0 8px; padding: 0; }
.devices li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.devices .n { font-weight: 600; }
.devices .m { display: block; color: var(--muted); font-size: 12.5px; }
.devices button { padding: 5px 10px; font-size: 13px; flex: none; }
#device-empty[hidden] { display: none; }

/* Manuelle Annotation: Knopf und Markierungen in der Tagesansicht */
.annotate { width: 100%; margin: 0 0 12px; text-align: center; }
.annotate[hidden] { display: none; }
.timeline .badge { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 400; border: 1px solid var(--line); vertical-align: 1px; white-space: nowrap; }
.timeline .badge.ok { background: #e6f5ea; border-color: #b9dfc3; }
.timeline .badge.no { background: #fde9e7; border-color: #f0bcb7; }
.timeline .badge.mixed { background: #fff4d6; border-color: #ecd58f; }

/* Trainer, Freigabe, Chat */
dialog.wide { max-width: 560px; max-height: calc(100vh - 32px); overflow-y: auto; }
.notice.chat { background: #dcebf7; border-color: #a9cbe6; }
.viewing-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; background: #fff4d6; border-bottom: 1px solid #ecd58f; font-size: 14px; }
.viewing-bar[hidden] { display: none; }
.viewing-bar .spacer { flex: 1; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
body.viewing #days .more, body.viewing #annotate-btn, body.viewing #export-btn, body.viewing #import-btn { display: none; }
body.viewing.summary-only .tabs button[data-view=days], body.viewing.summary-only .tabs button[data-view=heat], body.viewing.summary-only #viewing-export { display: none; }
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.people li { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.people li.plain { grid-template-columns: 1fr; }
.people .n { font-weight: 650; }
.people .m { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.people .bio { margin: 6px 0 0; white-space: pre-line; overflow-wrap: anywhere; font-size: 14px; }
.people .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.people .state { font-weight: 400; font-size: 12.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; margin-left: 6px; }
.people .state.ok { background: #e6f5ea; border-color: #b9dfc3; }
.people .state.warn { background: #fff4d6; border-color: #ecd58f; }
.people .state.off { background: #f1f3f5; }
.avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: #e6ebf0; border: 1px solid var(--line); }
.avatar.big { width: 96px; height: 96px; }
.avatar.none { display: grid; place-items: center; color: var(--muted); font-weight: 650; font-size: 22px; }
.photo-row { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.rules { margin: 4px 0 8px; padding-left: 20px; font-size: 14px; }
.choice { display: grid; gap: 6px; margin: 10px 0; }
.choice label { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.choice small { display: block; color: var(--muted); }
#trainer-body .pending, #profile-dialog .pending { background: #eef3f8; border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 14px; }
ol.chat { list-style: none; margin: 8px 0; padding: 8px; height: min(46vh, 380px); overflow-y: auto; display: flex; flex-direction: column; gap: 6px; background: #f6f8fa; border: 1px solid var(--line); border-radius: 10px; }
ol.chat li { max-width: 80%; padding: 7px 10px; border-radius: 12px; background: #fff; border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; align-self: flex-start; }
ol.chat li.mine { align-self: flex-end; background: #dcebf7; border-color: #a9cbe6; }
ol.chat li time { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
ol.chat li.day { align-self: center; background: transparent; border: 0; color: var(--muted); font-size: 12.5px; padding: 2px; }
ol.chat li.empty { align-self: center; background: transparent; border: 0; color: var(--muted); }
#chat-form textarea { width: 100%; resize: vertical; }
.sr { font-size: 0; }
.sr textarea { font-size: 15px; }

#chat-form textarea, #profile-form textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; width: 100%; }
#profile-form label:not(.check), #trainer-body form label:not(.check) { display: block; font-weight: 600; margin: 8px 0; }
#profile-form input[type=text], #trainer-body form input[type=text] { display: block; width: 100%; margin-top: 4px; }
#profile-form label.check, #trainer-body form label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 13.5px; margin: 10px 0; }
