:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #15181d;
    --muted: #6b7280;
    --border: #dfe2e7;
    --accent: #1f2a37;
    --primary: #0a5bd3;
    --danger: #c62828;
    --ok: #1b8a4a;
    --warn: #d98b00;
    --radius: 10px;
    --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--primary); }
code { font-family: Consolas, "Cascadia Mono", monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Buttons & Formulare ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
    text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: #b9bfc8; }
.btn:disabled { opacity: .5; cursor: default; }
/* Download läuft (wwwroot/js/download.js): Taste gesperrt, bis die Datei da ist. */
.btn.is-busy { opacity: .5; cursor: progress; pointer-events: none; }
.download-status { margin: .25rem 0 .75rem; padding: .55rem .8rem; border-radius: 8px; background: #eef4ff; border: 1px solid #c9dafc; }
.download-status.is-error { background: #fdecec; border-color: #f3b9b9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-icon { padding: .3rem .55rem; }
.icon { flex: none; }
/* Rückfrage (ConfirmButton): Folgen der Aktion in eigener Zeile über den beiden Tasten */
.confirm-box { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .3rem; vertical-align: middle; }
.confirm-warning { flex-basis: 100%; color: var(--danger); font-size: .85rem; font-weight: 600; white-space: normal; }
/* in Tabellen mit Tasten am rechten Rand rechtsbündig */
.table .confirm-box { justify-content: flex-end; }
.table .confirm-warning { text-align: right; }

input, select {
    font: inherit; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: var(--text); min-width: 0;
    font-size: 16px; /* kleiner zoomt iOS-Safari beim Antippen in das Feld die ganze Seite */
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
.input-sm { width: 7rem; }
.input-md { width: 12rem; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
label input, label select { color: var(--text); font-size: 16px; }
.form-error { color: var(--danger); background: #fdecec; padding: .6rem .8rem; border-radius: 8px; }
.form-ok { color: var(--ok); background: #e8f6ee; padding: .6rem .8rem; border-radius: 8px; }
.form-inline { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }

/* ---------- Admin ---------- */
.admin-header {
    display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 2rem;
    padding: .8rem 1.5rem; background: var(--accent); color: #fff;
}
.admin-brand { display: flex; flex-direction: column; }
.admin-event { font-weight: 700; }
.admin-sub { font-size: .8rem; opacity: .7; }
.admin-nav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.admin-nav a { color: #d6dbe2; text-decoration: none; padding: .45rem .75rem; border-radius: 6px; }
.admin-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.admin-nav a.active { background: rgba(255,255,255,.16); color: #fff; }
.admin-user { display: flex; gap: 1rem; align-items: center; font-size: .9rem; }
.admin-user a, .admin-user .link-button { color: #fff; }
.admin-user .muted { color: #aab3bf; }
.admin-main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .7rem; }
.card h2 { margin-top: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .75rem 0; }
.hint { background: #fff8e1; border: 1px solid #f3df9b; padding: .7rem 1rem; border-radius: 8px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: .3rem; }
.kpi span { color: var(--muted); font-size: .85rem; }
.kpi strong { font-size: 1.8rem; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .8rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td { font-weight: 600; background: #fafbfc; border-top: 2px solid var(--border); border-bottom: 0; }
.table tr.row-selected td { background: #eef4ff; font-weight: 600; }
.table td input:not(.input-sm):not(.input-xs):not(.input-order) { width: 100%; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * { margin-left: .3rem; }
/* Tabellen mit vielen Eingabefeldern (Bereiche): weniger Rand links und rechts, Tasten und Rückfrage dürfen umbrechen,
   damit die Tabelle bei 1280 px Breite auch mit Rückfrage ohne Querrollen passt */
.table-dense th, .table-dense td { padding-left: .5rem; padding-right: .5rem; }
.table-dense .actions { white-space: normal; min-width: 12.5rem; }
.table-dense .confirm-box { max-width: 11rem; }

.badge-previews { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 1rem; }
.badge-preview { margin: 0; display: flex; flex-direction: column; gap: .35rem; }
.badge-preview img { border: 1px solid var(--border); border-radius: 6px; }
/* Kleines Schachbrett in den Farben des gedruckten QR-Codes (Hintergrund und Module) */
.qr-chip { display: inline-block; width: 1.4rem; height: 1.4rem; border-radius: 4px; border: 1px solid #9ca3af; vertical-align: middle; margin-right: .4rem;
    background-color: var(--qr-bg); background-image: conic-gradient(var(--qr-fg) 25%, transparent 0 50%, var(--qr-fg) 0 75%, transparent 0); background-size: .7rem .7rem; }
.qr-color-cell { white-space: nowrap; }
.code-wrap { word-break: break-all; white-space: pre-wrap; }
.setup-qr { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-start; }
.setup-qr img { border: 1px solid var(--border); border-radius: 8px; image-rendering: pixelated; }
.setup-qr ol { margin-top: 0; padding-left: 1.2rem; }
.input-url { width: min(28rem, 80vw); }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.2rem; margin: 1rem 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr auto; place-items: center; padding: 16px; }
.login-page.dark { background: #0b0d10; }
.login-card {
    width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; padding: 2rem;
    display: flex; flex-direction: column; gap: 1rem; box-shadow: 0 10px 40px rgba(0,0,0,.08);
}
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card p { margin: 0; }
.login-card input { font-size: 1.1rem; padding: .7rem .8rem; }
.login-card .btn { padding: .75rem 1rem; }
.login-page.dark .login-card input[name=pin] { text-align: center; letter-spacing: .3em; font-size: 1.6rem; }

/* ---------- Dashboard ---------- */
.dash { min-height: 100vh; background: #0b0d10; color: #f3f4f6; padding: clamp(16px, 3vw, 48px); }
.dash-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: clamp(16px, 3vw, 40px); }
.dash-top { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .35rem; }
.dash-eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .8rem; color: #9aa3ae; }
.dash-lang { display: flex; gap: .3rem; }
.dash-lang a {
    color: #9aa3ae; text-decoration: none; font-size: .8rem; font-weight: 600; letter-spacing: .08em;
    min-width: 2.5rem; padding: .4rem .5rem; text-align: center; border: 1px solid #262c35; border-radius: 6px;
}
.dash-lang a:hover { color: #fff; border-color: #4b5563; }
.dash-lang a.active { color: #fff; background: #262c35; border-color: #4b5563; }
.dash h1 { margin: .2rem 0 0; font-size: clamp(1.8rem, 4vw, 3.2rem); font-weight: 700; }
.dash-meta { text-align: right; }
.dash-total { font-size: clamp(1.1rem, 2vw, 1.6rem); color: #c9ced6; }
.dash-total strong { color: #fff; font-size: 1.4em; font-variant-numeric: tabular-nums; }
.dash-updated { font-size: .85rem; color: #9aa3ae; display: flex; align-items: center; gap: .45rem; justify-content: flex-end; }
/* Verwaltung → Bereiche: Namensfelder (deutsch + Übersetzungen) so breit, dass übliche Namen lesbar bleiben */
.input-name { min-width: 9.5rem; }
/* Zahlenfelder behalten ihre Breite, auch wenn die Zeile durch längere Tasten breiter wird (sonst sieht man nur noch zwei Stellen) */
.input-xs { width: 5.5rem; min-width: 5.5rem; }
.input-order { width: 4.5rem; min-width: 4.5rem; }

/* Verwaltung → Dashboard-Links */
.lang-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.lang-card { display: flex; flex-direction: column; gap: .75rem; margin: 0; }
.lang-card h2 { margin: 0; }
.lang-card input { width: 100%; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 1rem; }
.lang-card .qr { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.lang-card .qr img { width: 150px; height: 150px; image-rendering: pixelated; border: 1px solid var(--border, #dde1e8); border-radius: 8px; background: #fff; }

.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.6); } 70% { box-shadow: 0 0 0 10px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
.dash-loading { color: #9aa3ae; }

.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: clamp(12px, 2vw, 28px); }
.area-card {
    --level: #22c55e;
    background: #161a20; border: 1px solid #262c35; border-top: 6px solid var(--level);
    border-radius: 14px; padding: clamp(16px, 2vw, 28px); display: flex; flex-direction: column; gap: .8rem;
}
.area-card.level-busy { --level: #eab308; }
.area-card.level-high { --level: #f97316; }
.area-card.level-full { --level: #ef4444; background: #2a1215; }
.area-card h2 { margin: 0; font-size: clamp(1.1rem, 1.8vw, 1.5rem); color: #fff; }
.area-count { display: flex; align-items: baseline; gap: .4rem; font-variant-numeric: tabular-nums; }
.area-count strong { font-size: clamp(2.6rem, 5vw, 4.4rem); line-height: 1; color: #fff; }
.area-count span { font-size: clamp(1rem, 1.6vw, 1.4rem); color: #9aa3ae; }
.bar { height: 14px; background: #262c35; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--level); border-radius: 99px; transition: width .6s ease; }
.area-foot { display: flex; justify-content: space-between; font-weight: 600; font-size: 1.05rem; }
.area-status { color: var(--level); }
.area-free { color: #9aa3ae; font-size: .9rem; }

/* ---------- Scanner (Smartphone) ---------- */
.scanner {
    --mode: #16a34a;
    position: fixed; inset: 0; display: flex; flex-direction: column;
    background: #0b0d10; color: #fff;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.scanner.mode-out { --mode: #ea580c; }
.scan-top { display: flex; flex-direction: column; gap: .5rem; padding: .6rem; background: #14181d; border-bottom: 4px solid var(--mode); }
.scan-top select { font-size: 1.1rem; padding: .6rem; background: #1f252d; color: #fff; border-color: #313944; }
.scan-modes { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.mode-btn { font: inherit; font-size: 1.1rem; font-weight: 700; padding: .7rem; border-radius: 8px; border: 2px solid #313944; background: #1f252d; color: #c9ced6; }
.mode-btn.active[data-mode=In] { background: #16a34a; border-color: #16a34a; color: #fff; }
.mode-btn.active[data-mode=Out] { background: #ea580c; border-color: #ea580c; color: #fff; }

.scan-view { position: relative; flex: 1; overflow: hidden; background: #000; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
    position: absolute; left: 50%; top: 50%; width: min(65vw, 60vh); aspect-ratio: 1; transform: translate(-50%, -50%);
    border: 3px solid var(--mode); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none;
}
.scan-mode-banner {
    position: absolute; top: .8rem; left: 50%; transform: translateX(-50%);
    background: var(--mode); color: #fff; font-weight: 800; letter-spacing: .15em; padding: .3rem 1rem; border-radius: 99px;
}
.scan-start {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    font: inherit; font-size: 1.2rem; font-weight: 700; padding: 1rem 1.6rem; border-radius: 12px; border: 0;
    background: var(--mode); color: #fff;
}
.scan-result {
    position: absolute; inset: auto .8rem .8rem .8rem; border-radius: 14px; padding: 1.1rem 1.2rem;
    background: #16a34a; color: #fff; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.scan-result.status-warning { background: #d97706; }
.scan-result.status-error { background: #dc2626; inset: .8rem; display: flex; flex-direction: column; justify-content: center; }
.res-title { font-size: 1.9rem; font-weight: 800; }
.res-msg { font-size: 1.1rem; margin-top: .3rem; }
.res-occ { font-size: .95rem; margin-top: .5rem; opacity: .9; }
.scan-result[hidden] { display: none; }
.res-force {
    margin-top: 1rem; font: inherit; font-size: 1.15rem; font-weight: 700; padding: .8rem 1.4rem;
    border: 2px solid #fff; border-radius: 10px; background: rgba(0,0,0,.25); color: #fff;
}
.res-force[hidden] { display: none; }

.scan-bottom { display: flex; flex-direction: column; gap: .5rem; padding: .6rem; background: #14181d; }
.scan-occ { text-align: center; font-weight: 700; font-size: 1.05rem; }
.scan-occ.full { color: #f87171; }
.scan-manual { display: flex; gap: .5rem; }
.scan-manual input { flex: 1; background: #1f252d; color: #fff; border-color: #313944; text-transform: uppercase; }
.scan-manual button { font: inherit; font-weight: 700; padding: .5rem 1rem; border-radius: 8px; border: 0; background: #313944; color: #fff; }
.scan-meta { display: flex; gap: .75rem; align-items: center; }
.scan-meta input { flex: 1; background: #1f252d; color: #fff; border-color: #313944; font-size: 1rem; }
.scan-meta a, .scan-meta .link-button { color: #9aa3ae; font-size: .9rem; }

/* Formular, das wie ein Link aussieht (Abmelden per POST) */
.inline-form { display: inline; margin: 0; }
.link-button { padding: 0; border: 0; background: none; font: inherit; text-decoration: underline; cursor: pointer; }

/* ---------- Fenster (z. B. „Verworfene Scans“ in der Auswertung) ---------- */
.kpi-button { font: inherit; text-align: left; cursor: pointer; }
.kpi-button:hover { border-color: #9ca3af; }
.modal-backdrop { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; padding: 1rem; background: rgba(0, 0, 0, .5); }
.modal { display: flex; flex-direction: column; gap: .75rem; width: 100%; max-width: 960px; max-height: 85vh; padding: 1.25rem; background: #fff; border-radius: 12px; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.modal h2 { margin: 0; }
.modal-scroll { overflow: auto; }

/* ---------- Belegungsbalken in der Auswertung (Farben wie auf dem Dashboard) ---------- */
.occ { --level: #22c55e; display: flex; align-items: center; gap: .6rem; min-width: 200px; }
.occ.level-busy { --level: #eab308; }
.occ.level-high { --level: #f97316; }
.occ.level-full { --level: #ef4444; }
.occ .bar { flex: 1; min-width: 90px; height: 10px; background: #e5e7eb; }
.occ-text { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Copyright-Hinweis am Seitenende ---------- */
.copyright { margin: 1.5rem 0 0; font-size: .75rem; color: #8b93a0; text-align: center; }
.dash .copyright, .scanner .copyright, .login-page.dark .copyright { color: #6b7380; }
.scanner .copyright { margin: .25rem 0 0; font-size: .7rem; }
.login-page .copyright { margin-top: 1rem; }
.admin .copyright { padding: 0 1rem 1.5rem; }

/* ---------- Blazor ---------- */
#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    padding: .7rem 1.2rem; background: #fff3cd; color: #000; box-shadow: 0 -1px 4px rgba(0,0,0,.2);
}
#blazor-error-ui .reload { margin-left: .5rem; }

@media (max-width: 640px) {
    .admin-main { padding: 1rem; }
    .admin-header { padding: .8rem 1rem; }

    /* Dashboard auf dem Smartphone: kompakte Zeilen, alle Bereiche auf einen Blick */
    .dash { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
    .dash-header { flex-direction: column; align-items: stretch; gap: .6rem; margin-bottom: 14px; }
    .dash h1 { font-size: 1.55rem; }
    .dash-eyebrow { font-size: .72rem; }
    .dash-meta { display: flex; justify-content: space-between; align-items: center; gap: .5rem; text-align: left;
                 background: #161a20; border: 1px solid #262c35; border-radius: 12px; padding: .55rem .8rem; }
    .dash-total { font-size: 1rem; }
    .dash-updated { justify-content: flex-end; font-size: .78rem; }
    .dash-grid { grid-template-columns: 1fr; gap: 10px; }
    .area-card {
        display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name count" "bar bar" "status free";
        gap: .4rem .75rem; padding: 12px 14px; border-top: 1px solid #262c35; border-left: 6px solid var(--level); border-radius: 12px;
    }
    .area-card h2 { grid-area: name; font-size: 1.1rem; align-self: center; }
    .area-count { grid-area: count; justify-self: end; }
    .area-count strong { font-size: 1.9rem; }
    .area-count span { font-size: .95rem; }
    .bar { grid-area: bar; height: 10px; }
    .area-foot { grid-area: status; justify-content: flex-start; gap: .6rem; font-size: .95rem; }
    .area-free { grid-area: free; justify-self: end; align-self: center; font-size: .85rem; }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .dash-grid { grid-template-columns: repeat(2, 1fr); }
}
