/* Entlastungsnachweis – Gestaltung
   Fuers Handy zuerst ([FEST-16]): grosse Tippflaechen (>= 48 px), Schrift >= 16 px, hoher Kontrast.
   Hell und Dunkel ueber Farb-Tokens; die Wahl trifft die Nutzerin (Umschalter oben rechts),
   Standard folgt dem Geraet. */

:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #eef2f6;
    --border: #d5dde6;
    --text: #17212b;
    --text-muted: #5a6875;
    --primary: #1f5f8b;
    --primary-hover: #184d72;
    --primary-soft: #e3eef7;
    --on-primary: #ffffff;
    --success: #1f7a4d;
    --success-soft: #e2f3ea;
    --warning: #9a5b00;
    --warning-soft: #fdf0dc;
    --danger: #b3261e;
    --danger-soft: #fbe7e5;
    --focus: #f0a202;
    --shadow: 0 1px 2px rgba(16, 33, 58, .06), 0 4px 14px rgba(16, 33, 58, .06);
    --radius: 14px;
    --radius-sm: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f151c;
        --surface: #18212b;
        --surface-2: #202b37;
        --border: #2f3d4c;
        --text: #e8eef4;
        --text-muted: #9fb0c0;
        --primary: #5aa6dc;
        --primary-hover: #7bb9e5;
        --primary-soft: #1b3347;
        --on-primary: #0b1720;
        --success: #5cc48f;
        --success-soft: #16301f;
        --warning: #f0b35a;
        --warning-soft: #33260f;
        --danger: #f08a82;
        --danger-soft: #3a1b19;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0f151c;
    --surface: #18212b;
    --surface-2: #202b37;
    --border: #2f3d4c;
    --text: #e8eef4;
    --text-muted: #9fb0c0;
    --primary: #5aa6dc;
    --primary-hover: #7bb9e5;
    --primary-soft: #1b3347;
    --on-primary: #0b1720;
    --success: #5cc48f;
    --success-soft: #16301f;
    --warning: #f0b35a;
    --warning-soft: #33260f;
    --danger: #f08a82;
    --danger-soft: #3a1b19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 17px;
    line-height: 1.45;
}

h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .5rem; }
p { margin: .25rem 0 .75rem; }
a { color: var(--primary); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Grundgeruest ---------- */

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem max(1rem, env(safe-area-inset-left));
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; text-decoration: none; color: var(--text); flex: 1; min-width: 0; }
.topbar .brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: .8rem; font-weight: 800; flex: none; }
.topbar .brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .user { color: var(--text-muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

.page { max-width: 760px; margin: 0 auto; padding: 1rem 1rem 6rem; }
.page.wide { max-width: 1040px; }

.page-head { display: flex; align-items: flex-start; gap: .75rem; margin-bottom: 1rem; }
.page-head .back { flex: none; }
.page-head .titles { flex: 1; min-width: 0; }
.page-head .subtitle { color: var(--text-muted); margin: 0; }

/* ---------- Karten und Kacheln ---------- */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.flat { box-shadow: none; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }

.tiles { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 560px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tile {
    display: flex; flex-direction: column; justify-content: center; gap: .35rem;
    min-height: 140px; padding: 1.25rem; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
    color: var(--text); text-decoration: none; position: relative;
}
.tile:hover { border-color: var(--primary); }
.tile .tile-icon { font-size: 2rem; line-height: 1; }
.tile .tile-title { font-size: 1.3rem; font-weight: 700; }
.tile .tile-text { color: var(--text-muted); font-size: .95rem; }
.tile.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.tile.primary .tile-text { color: var(--on-primary); opacity: .85; }
.tile .badge { position: absolute; top: .9rem; right: .9rem; }
.tiles.small .tile { min-height: 96px; }
.tiles.small .tile .tile-title { font-size: 1.1rem; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    min-height: 48px; padding: .6rem 1.1rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
    touch-action: manipulation; user-select: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 72px; font-size: 1.35rem; border-radius: var(--radius); }
.btn.huge { min-height: 96px; font-size: 1.6rem; border-radius: var(--radius); width: 100%; }
.btn.small { min-height: 40px; padding: .35rem .75rem; font-size: .95rem; }
.btn.icon { min-width: 48px; padding: .5rem; }

.actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1rem; }
.actions.stack { flex-direction: column; }
.actions.end { justify-content: flex-end; }

.sticky-actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    padding: .75rem max(1rem, env(safe-area-inset-left)) calc(.75rem + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
}
.sticky-actions .inner { max-width: 760px; margin: 0 auto; display: flex; gap: .75rem; }
.sticky-actions .inner .btn { flex: 1; }

/* ---------- Formulare ---------- */

.form-grid { display: grid; grid-template-columns: 1fr; gap: .9rem 1rem; }
@media (min-width: 620px) {
    .form-grid.two { grid-template-columns: 1fr 1fr; }
    .form-grid .span-2 { grid-column: span 2; }
}

.field { display: flex; flex-direction: column; gap: .3rem; }
.field > label, .field > .label { font-weight: 600; font-size: .95rem; }
.field .hint { color: var(--text-muted); font-size: .88rem; }
.field .error { color: var(--danger); font-size: .9rem; font-weight: 600; }

input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number],
input[type=date], input[type=time], input[type=month], input[type=search], select, textarea {
    width: 100%; min-height: 48px; padding: .6rem .75rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font: inherit; font-size: 17px;
}
textarea { min-height: 96px; resize: vertical; }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }

.input-row { display: flex; gap: .5rem; align-items: stretch; }
.input-row > input, .input-row > select { flex: 1; min-width: 0; }
.input-row > .btn { flex: none; }

.check { display: flex; gap: .75rem; align-items: flex-start; padding: .5rem 0; cursor: pointer; }
.check input { width: 24px; height: 24px; margin-top: .1rem; flex: none; accent-color: var(--primary); }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button { min-height: 48px; border: 0; background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--primary); color: var(--on-primary); }

.search { position: relative; margin-bottom: 1rem; }

/* ---------- Listen ---------- */

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list > li + li { border-top: 1px solid var(--border); }
.list .row { display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; min-height: 64px; color: var(--text); text-decoration: none; }
a.row:hover, button.row:hover { background: var(--surface-2); }
button.row { width: 100%; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 650; }
.row .meta { color: var(--text-muted); font-size: .92rem; }
.row .side { text-align: right; flex: none; }
.row .chev { color: var(--text-muted); font-size: 1.4rem; flex: none; }

.empty { text-align: center; color: var(--text-muted); padding: 2rem 1rem; }

.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .55rem; border-radius: 999px; font-size: .82rem; font-weight: 700; background: var(--surface-2); color: var(--text-muted); white-space: nowrap; }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Tabellen ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th, table.data td { padding: .6rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { background: var(--surface-2); font-size: .85rem; color: var(--text-muted); font-weight: 700; }
table.data td.num, table.data th.num { text-align: right; white-space: nowrap; }
table.data tfoot td { font-weight: 800; border-bottom: 0; }
table.data.large { font-size: 1.1rem; }
.sm-only, .sm-only-inline { display: none; }
/* Auf dem Handy passt die Tabelle ohne Querscrollen: Stundenpreis wandert unter die Leistung,
   damit der Betrag, den der Versicherte unterschreibt, immer sichtbar bleibt. */
@media (max-width: 560px) {
    table.data .rate-col, table.data .hide-sm { display: none; }
    .sm-sort { display: block; }
    table.data .sm-only { display: block; margin-top: .15rem; }
    table.data .sm-only-inline { display: inline; }
    table.data .lg-only { display: none; }
    table.data, table.data.large { font-size: .95rem; }
    table.data th, table.data td { padding: .5rem .3rem; }
}

/* ---------- Filterleiste (7.8) ---------- */

.filter-bar { padding: .85rem 1rem; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.filter-grid .filter-search { grid-column: 1 / -1; }
/* Rasterzellen duerfen schmaler als ihr Inhalt werden – sonst ragen Datumsfelder am Handy aus der Karte. */
.filter-grid > .field { min-width: 0; }
.filter-grid input, .filter-grid select { min-width: 0; max-width: 100%; }
@media (min-width: 760px) {
    .filter-grid { grid-template-columns: repeat(4, 1fr); }
    .filter-grid .filter-search { grid-column: span 2; }
    .filter-grid .filter-search:first-child { grid-column: 1 / -1; }
}
.filter-foot { margin-top: .35rem; min-height: 1.75rem; }

/* ---------- Sortierbare Tabelle ---------- */

.sort-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: inherit; cursor: pointer; text-align: inherit; }
th.num .sort-btn { width: 100%; text-align: right; }
.sort-arrow { color: var(--primary); }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--surface-2); }
.sm-sort { display: none; margin-bottom: .75rem; }

/* ---------- Budgetbalken ---------- */

.budget { margin-top: .35rem; }
.meter.small-meter { height: 8px; margin: .2rem 0; }
.meter.small-meter.ok > span { background: var(--success); }
.meter.small-meter.low > span { background: var(--warning); }
.meter.small-meter.over { background: var(--danger-soft); }
.budget-text { font-size: .85rem; color: var(--text-muted); }
.budget-text.low { color: var(--warning); font-weight: 600; }
.budget-text.over { color: var(--danger); font-weight: 700; }

/* ---------- Hinweise ---------- */

.alert { padding: .85rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid transparent; }
.alert.info { background: var(--primary-soft); color: var(--text); border-color: var(--primary-soft); }
.alert.success { background: var(--success-soft); color: var(--text); border-left: 5px solid var(--success); }
.alert.warning { background: var(--warning-soft); color: var(--text); border-left: 5px solid var(--warning); }
.alert.danger { background: var(--danger-soft); color: var(--text); border-left: 5px solid var(--danger); }
.alert ul { margin: .25rem 0 0; padding-left: 1.2rem; }

.running-banner { display: flex; align-items: center; gap: .75rem; padding: 1rem; border-radius: var(--radius); background: var(--success); color: #fff; text-decoration: none; margin-bottom: 1rem; box-shadow: var(--shadow); }
.running-banner .pulse { width: 14px; height: 14px; border-radius: 50%; background: #fff; animation: pulse 1.6s infinite; flex: none; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: .35; } 100% { opacity: 1; } }

/* ---------- Timer und Kennzahlen ---------- */

.timer { font-variant-numeric: tabular-nums; font-size: 3.4rem; font-weight: 800; text-align: center; letter-spacing: .02em; margin: .5rem 0; }
.timer-sub { text-align: center; color: var(--text-muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: .75rem; text-align: center; }
.stat .value { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--text-muted); font-size: .85rem; }
.stat.highlight { background: var(--primary-soft); }
.stat.highlight .value { color: var(--primary); }

.meter { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: .4rem 0; }
.meter > span { display: block; height: 100%; background: var(--success); }
.meter.over > span { background: var(--warning); }

/* ---------- Unterschrift ---------- */

.signature-box { position: relative; border: 2px dashed var(--border); border-radius: var(--radius); background: #fff; overflow: hidden; }
.signature-box canvas { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.signature-box .baseline { position: absolute; left: 6%; right: 6%; bottom: 48px; border-bottom: 1.5px solid #9aa7b4; pointer-events: none; }
.signature-box .placeholder { position: absolute; left: 0; right: 0; bottom: 18px; text-align: center; color: #7a8795; font-size: .9rem; pointer-events: none; }
.signature-preview { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem; max-width: 360px; }
.signature-preview img { display: block; width: 100%; height: auto; }

/* Uebergabe an den Versicherten: ruhig, gross, ohne Menue (7.5 Schritt 2). */
.handover { font-size: 1.1rem; }
.handover .legal { font-size: 1.05rem; }
.handover h1 { font-size: 1.6rem; }

.longpress { position: relative; overflow: hidden; }
.longpress .fill { position: absolute; inset: 0; background: rgba(255, 255, 255, .25); transform-origin: left; transform: scaleX(0); }
.longpress.pressing .fill { transition: transform 1.5s linear; transform: scaleX(1); }

/* ---------- Dialog ---------- */

.backdrop { position: fixed; inset: 0; background: rgba(8, 15, 24, .55); z-index: 50; display: grid; place-items: end center; padding: 0; }
@media (min-width: 620px) { .backdrop { place-items: center; padding: 1rem; } }
.dialog { background: var(--surface); color: var(--text); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: var(--radius) var(--radius) 0 0; padding: 1.25rem; box-shadow: var(--shadow); }
@media (min-width: 620px) { .dialog { border-radius: var(--radius); } }
.dialog h2 { margin-top: 0; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 60; background: var(--text); color: var(--bg); padding: .8rem 1.1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow); max-width: calc(100% - 2rem); font-weight: 600; }
.has-sticky .toast { bottom: calc(5.5rem + env(safe-area-inset-bottom)); }

/* ---------- Verschiedenes ---------- */

.muted { color: var(--text-muted); }
.small { font-size: .9rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mb0 { margin-bottom: 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 2rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 1rem; color: var(--text-muted); }
.boot-logo { width: 64px; height: 64px; border-radius: 16px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 800; font-size: 1.3rem; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: 100%; max-width: 420px; }

#update-banner {
    position: fixed; left: 50%; transform: translateX(-50%); top: calc(.5rem + env(safe-area-inset-top)); z-index: 100;
    min-height: 48px; padding: .7rem 1.1rem; border: 0; border-radius: 999px; box-shadow: var(--shadow);
    background: var(--primary); color: var(--on-primary); font: inherit; font-weight: 700; cursor: pointer;
    max-width: calc(100% - 1.5rem);
}

#blazor-error-ui { background: var(--warning-soft); color: var(--text); bottom: 0; box-shadow: var(--shadow); display: none; left: 0; padding: .8rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; background: none; border: 0; font-size: 1.2rem; color: inherit; }

@media print {
    .topbar, .sticky-actions, .actions { display: none !important; }
}
