:root {
    --bg: #f4f6fb;
    --bg-elev: #ffffff;
    --surface: #ffffff;
    --surface-2: #f0f3f9;
    --border: #e1e6ef;
    --border-strong: #c8d0df;
    --text: #1a2135;
    --text-soft: #4a5470;
    --muted: #7b85a0;
    --accent: #3b6ef5;
    --accent-hover: #2e5ad9;
    --accent-soft: #eaf0ff;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --fk: #d97706;
    --fk-soft: #fef3c7;
    --sk: #7c3aed;
    --sk-soft: #ede9fe;
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 3px rgba(25, 45, 95, 0.06), 0 4px 16px rgba(25, 45, 95, 0.04);
    --shadow-lg: 0 8px 40px rgba(25, 45, 95, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
        Roboto, sans-serif;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
body { overscroll-behavior-y: contain; min-height: 100vh; }

a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

@media (max-width: 720px) {
    .desktop-only { display: none !important; }
}

/* --- Auth --- */
body.auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(160deg, #e8eefa 0%, var(--bg) 60%);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 32px 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}
.auth-card h1 { margin: 0 0 4px 0; font-size: 24px; color: var(--text); }
.auth-card form { display: flex; flex-direction: column; gap: 16px; margin-top: 24px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-soft); font-weight: 500; }
.auth-card input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 16px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-card button[type=submit] {
    background: var(--accent);
    color: white;
    border: none;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.15s;
}
.auth-card button[type=submit]:active { background: var(--accent-hover); }

.auth-card .checkbox-label {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    margin-top: -4px;
}
.auth-card .checkbox-label input {
    width: 18px;
    height: 18px;
    padding: 0;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}
.error {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-top: 16px;
}

/* --- Topbar --- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
    padding-top: var(--safe-top);
}
.topbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    gap: 8px;
}
/* Subrow: BL-Chip zentriert, Sync/Menü absolut positioniert rechts */
.topbar-row.subrow {
    position: relative;
    justify-content: center;
    padding-top: 0;
    padding-bottom: 10px;
}
.topbar-row.subrow .topbar-actions {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    font-size: 22px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.icon-btn:active { background: var(--surface-2); }

.week-info { text-align: center; min-width: 140px; }
.week-kw { font-weight: 700; font-size: 18px; letter-spacing: -0.2px; }
.week-range { font-size: 12px; margin-top: 2px; }

.bl-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 4px 12px 4px 4px;
    border-radius: 999px;
    font-size: 13px;
    box-shadow: var(--shadow);
}
.bl-chip-nr {
    background: var(--accent);
    color: white;
    padding: 3px 10px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.3px;
}
.bl-chip-name { font-weight: 500; color: var(--text); }

.topbar-actions { display: flex; align-items: center; gap: 6px; position: relative; }

.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    transition: background 0.3s;
}
.sync-dot.syncing { background: var(--warning); animation: pulse 1.4s ease-in-out infinite; }
.sync-dot.error { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.sync-text { font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .sync-text { display: none; } }

.menu { position: relative; }
.menu-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-width: 200px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 60;
}
.menu-dropdown button,
.menu-dropdown a {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    padding: 12px 16px;
    font-size: 15px;
    cursor: pointer;
    font-family: inherit;
}
.menu-dropdown button:active,
.menu-dropdown a:active { background: var(--surface-2); }
.menu-dropdown a { color: var(--danger); border-top: 1px solid var(--border); }

/* --- Layout --- */
.app {
    max-width: 760px;
    margin: 0 auto;
    padding: 14px 12px calc(var(--safe-bottom) + 40px);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.card h2 {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.btn-small {
    background: var(--accent);
    color: white;
    border: none;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-small:active { background: var(--accent-hover); }
.btn-primary, .btn-secondary {
    padding: 13px 16px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-family: inherit;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:active { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:active { background: var(--border); }
.actions-card { display: flex; gap: 8px; background: transparent; padding: 0; border: none; box-shadow: none; }
.actions-card .btn-secondary { flex: 1; }

/* --- Progress --- */
.progress-row { margin-bottom: 14px; }
.progress-row:last-child { margin-bottom: 0; }
.progress-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--text);
}
.progress-count { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.progress-bar {
    height: 6px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.3s ease; width: 0%; }
.progress-fill.fk { background: var(--fk); }
.progress-fill.sk { background: var(--sk); }
.progress-fill.complete { background: var(--success); }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    min-width: 36px;
}
.badge.fk { background: var(--fk-soft); color: var(--fk); }
.badge.sk { background: var(--sk-soft); color: var(--sk); }

/* --- Filialen-Liste --- */
.filiale {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px;
}
.filiale.is-nl {
    border-color: var(--accent);
    background: linear-gradient(180deg, var(--accent-soft), var(--bg-elev) 50%);
}
.filiale:last-child { margin-bottom: 0; }

.filiale-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.filiale-header input.fil-nr {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    min-width: 0;
}
.filiale-header input.fil-nr:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.filiale-header input.fil-nr:disabled { background: var(--surface-2); cursor: not-allowed; color: var(--text-soft); }
.filiale-fixed-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 5px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.filiale-fixed-badge.nl { background: var(--accent); color: white; }

.btn-remove {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 20px;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.btn-remove:active { background: var(--danger-soft); }

.day-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}
.day-cell {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 4px;
    text-align: center;
    cursor: pointer;
    min-height: 58px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.15s;
}
.day-cell:active { transform: scale(0.96); }
.day-cell .day-label { font-size: 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.day-cell .day-value { font-size: 15px; font-weight: 700; margin-top: 2px; min-height: 22px; color: var(--text); }
.day-cell.has-value { border-color: var(--border-strong); background: var(--surface-2); }
.day-cell.fk-value { border-color: var(--fk); background: var(--fk-soft); }
.day-cell.fk-value .day-value { color: var(--fk); }
.day-cell.sk-value { border-color: var(--sk); background: var(--sk-soft); }
.day-cell.sk-value .day-value { color: var(--sk); }

/* --- Aufgaben: Card-Grid (Mobile: 2 Spalten, knapp passend) --- */
.aufgabe-fil {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px;
}
.aufgabe-fil:last-child { margin-bottom: 0; }
.aufgabe-fil-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-weight: 600;
}
.aufgabe-fil-header .fil-num {
    background: var(--surface-2);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text);
}
.aufgabe-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
/* Kassenprüfung (erstes Item) nimmt immer volle Breite ein */
.aufgabe-item.full-width {
    grid-column: 1 / -1;
}
.aufgabe-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    min-height: 46px;
    overflow: hidden;
}
.aufgabe-item:active { transform: scale(0.98); }
.aufgabe-item .aufg-label {
    font-size: 11.5px;
    line-height: 1.2;
    color: var(--text);
    flex: 1;
    min-width: 0;
    word-break: break-word;
}
.aufgabe-item .aufg-control {
    flex-shrink: 0;
}
.aufgabe-item.checked {
    background: var(--success-soft);
    border-color: var(--success);
}
.aufgabe-item.checked .aufg-label { color: var(--success); font-weight: 600; }
.aufgabe-item .x-mark {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: transparent;
    font-weight: 700;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.aufgabe-item.checked .x-mark {
    background: var(--success);
    border-color: var(--success);
    color: white;
}
.aufgabe-item .date-input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 5px 6px;
    border-radius: 6px;
    font-size: 11px;
    font-family: inherit;
    min-width: 0;
    width: 96px;
    max-width: 100%;
}
.aufgabe-item .date-input:focus { outline: none; border-color: var(--accent); }
.aufgabe-item.date-set { background: var(--success-soft); border-color: var(--success); }
.aufgabe-item.date-set .aufg-label { color: var(--success); font-weight: 600; }
.aufgabe-item.date-set .date-input { background: white; border-color: var(--success); }

/* Bei voller Breite mehr Platz für das Datum-Input */
.aufgabe-item.full-width .date-input {
    width: 140px;
    font-size: 13px;
    padding: 7px 10px;
}
.aufgabe-item.full-width .aufg-label { font-size: 13px; }

@media (min-width: 560px) {
    .aufgabe-grid { grid-template-columns: repeat(3, 1fr); }
    .aufgabe-item .aufg-label { font-size: 12px; }
}
@media (min-width: 760px) {
    .aufgabe-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
    .aufgabe-item { min-height: 50px; padding: 10px 12px; }
    .aufgabe-item .x-mark { width: 28px; height: 28px; }
    .aufgabe-item .date-input { width: 108px; font-size: 12px; }
}

/* --- Anmerkungen: EINZEILIG --- */
.textarea-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}
.textarea-label:last-child { margin-bottom: 0; }
.textarea-label > span {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.textarea-label input {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    width: 100%;
}
.textarea-label input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* --- Bottom Sheets --- */
.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fade-in 0.18s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.sheet {
    background: var(--surface);
    border-top: 1px solid var(--border);
    width: 100%;
    max-width: 560px;
    border-radius: 20px 20px 0 0;
    padding: 10px 16px calc(var(--safe-bottom) + 20px);
    animation: slide-up 0.22s ease;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 40px rgba(15, 23, 42, 0.15);
}
.sheet::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
    margin: 4px auto 8px;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 4px 14px;
    font-weight: 600;
    font-size: 16px;
    color: var(--text);
}
.sheet-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}
.sheet-body.sheet-list-body { padding-bottom: 8px; }

#besuchsart-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.sheet-option {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    text-align: left;
    color: var(--text);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-family: inherit;
    transition: all 0.15s;
}
.sheet-option:active { background: var(--surface-2); transform: scale(0.98); }
.sheet-option .opt-code {
    font-size: 17px;
    font-weight: 700;
    color: var(--accent);
}
.sheet-option .opt-label { font-size: 11px; color: var(--muted); }
.sheet-option.clear { grid-column: 1 / -1; justify-content: center; text-align: center; align-items: center; }
.sheet-option.clear .opt-code { color: var(--danger); }

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.15s;
}
.history-item:active { background: var(--surface-2); }
.history-item.current { border-color: var(--accent); background: var(--accent-soft); }
.history-item-main { display: flex; flex-direction: column; gap: 2px; }
.history-item-kw { font-weight: 700; font-size: 15px; color: var(--text); }
.history-item-date { font-size: 12px; color: var(--muted); }
.history-item-chev { font-size: 20px; color: var(--muted); }
.sheet-empty { padding: 40px 20px; text-align: center; font-size: 14px; }

.stamm-fil-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
}
.stamm-fil-item.is-nl {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.stamm-fil-item input.nr {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
}
.stamm-fil-item input.nr:focus { outline: none; border-color: var(--accent); }
.stamm-fil-item input.nr:disabled { background: var(--surface-2); color: var(--text-soft); cursor: not-allowed; }
.stamm-fil-item .fixed-note {
    font-size: 11px;
    color: var(--accent);
    font-weight: 700;
    padding: 4px 8px;
    background: var(--surface);
    border-radius: 6px;
}
.settings-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.settings-actions .btn-primary { padding: 11px 20px; }

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: calc(var(--safe-bottom) + 20px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    font-size: 14px;
    animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 20px); } }

/* --- Desktop --- */
@media (min-width: 720px) {
    body { font-size: 14px; }
    .week-info { min-width: 180px; }
    .filiale, .aufgabe-fil { padding: 14px; }
}
