/* KIB Academy – Design System übernommen aus KIBspector (DB Style) */
:root {
    /* DB Brand Colors */
    --db-red: #ec0016;
    --db-red-dark: #c50014;
    --db-red-100: #fEE6E6;
    --db-red-200: #FCC8C3;
    --db-red-300: #FA9090;

    /* Cool Grays */
    --db-cool-gray-100: #F0F3F5;
    --db-cool-gray-200: #D7DCE1;
    --db-cool-gray-300: #AFB4BB;
    --db-cool-gray-400: #878C96;
    --db-cool-gray-500: #646973;
    --db-cool-gray-600: #3C414B;
    --db-cool-gray-700: #282D37;
    --db-cool-gray-800: #131821;

    /* Semantic */
    --db-success: #508B1B;
    --db-success-bg: #E2f3E5;
    --db-warning: #f75f00;
    --db-warning-bg: #FFF4D8;
    --db-error: #ec0016;
    --db-error-bg: #fEE6E6;
    --db-info: #0087B9;
    --db-info-bg: #E0EFFB;

    /* Aliases */
    --primary: #282D37;
    --primary-light: #3C414B;
    --primary-dark: #131821;
    --accent: #ec0016;
    --success: #508B1B;
    --warning: #f75f00;
    --danger: #ec0016;
    --bg: #F0F3F5;
    --text: #131821;
    --text-light: #646973;
    --border: #D7DCE1;
    --shadow: 0 2px 8px rgba(0,0,0,.08);
    --shadow-lg: 0 5px 30px rgba(0,0,0,.12);
    --radius: 4px;
    --font: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-head: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-mono: 'Menlo', 'Consolas', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior-y: none;
}
button, input, select, textarea { font-family: var(--font); }

/* ====== SPLASH ====== */
.splash-screen {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--primary-dark);
    display: flex; align-items: center; justify-content: center;
    transition: opacity .4s ease, visibility .4s ease;
}
.splash-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-content { text-align: center; color: #fff; }
.splash-logo img { height: 76px; width: auto; background: #fff; border-radius: 8px; padding: 8px 12px; margin-bottom: 24px; }
.splash-title { font-size: 28px; font-weight: 700; letter-spacing: -.5px; }
.splash-subtitle { font-size: 13px; color: var(--db-cool-gray-400); letter-spacing: .5px; margin: 4px 0 28px; }
.splash-spinner-track { width: 200px; height: 3px; margin: 0 auto; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; }
.splash-spinner-fill { height: 100%; width: 40%; background: var(--db-red); border-radius: 2px; animation: splash-loading 1.2s ease-in-out infinite; }
@keyframes splash-loading {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(150%); }
    100% { transform: translateX(350%); }
}

/* ====== LAYOUT ====== */
#app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    position: sticky; top: 0; z-index: 100;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
    box-shadow: var(--shadow);
}
.topbar .logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
.topbar .logo img { height: 26px; background: #fff; border-radius: 3px; padding: 3px 5px; }
.topbar .spacer { flex: 1; }
.topbar-btn {
    background: rgba(255,255,255,.08); border: none; color: #fff;
    width: 36px; height: 36px; border-radius: var(--radius);
    display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
    transition: background .15s;
}
.topbar-btn:hover { background: rgba(255,255,255,.16); }
.topbar-btn svg { width: 18px; height: 18px; }
.topbar-back { display: none; }
.topbar-back.visible { display: inline-flex; }

main {
    flex: 1;
    padding: 16px;
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    max-width: 900px; width: 100%; margin: 0 auto;
}

/* ====== BOTTOM NAV ====== */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
    background: #fff;
    border-top: 1px solid var(--border);
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
    flex: 1; background: none; border: none; cursor: pointer;
    padding: 8px 4px 10px;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--db-cool-gray-400); font-size: 10px; font-weight: 600;
    border-top: 2px solid transparent; margin-top: -1px;
    transition: color .15s;
}
.bottom-nav button svg { width: 20px; height: 20px; }
.bottom-nav button.active { color: var(--db-red); border-top-color: var(--db-red); }

/* ====== TYPO / SECTIONS ====== */
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -.4px; margin-bottom: 4px; }
.page-sub { font-size: 13px; color: var(--text-light); margin-bottom: 20px; }
.section-title {
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px;
    color: var(--db-cool-gray-400); margin: 24px 0 10px;
}

/* ====== CARDS ====== */
.card {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 16px;
}
.card + .card { margin-top: 12px; }

/* Hero / Weiterlernen */
.hero {
    background: var(--primary); color: #fff; border-radius: var(--radius);
    padding: 18px; display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow);
}
.hero-ring { flex: 0 0 auto; }
.hero h2 { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.hero p { font-size: 12px; color: var(--db-cool-gray-300); }
.hero .btn { margin-top: 10px; width: auto; padding: 8px 16px; min-height: 36px; font-size: 13px; }

/* Stat row */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px; text-align: center;
}
.stat-value { font-size: 20px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--db-cool-gray-400); margin-top: 3px; font-weight: 600; }

/* Mode cards */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-card {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px; cursor: pointer; text-align: left;
    display: flex; flex-direction: column; gap: 6px;
    transition: border-color .15s, transform .1s;
}
.mode-card:hover { border-color: var(--db-cool-gray-300); }
.mode-card:active { transform: scale(.985); }
.mode-card .icon {
    width: 32px; height: 32px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    background: var(--db-red-100); color: var(--db-red);
}
.mode-card .icon svg { width: 16px; height: 16px; }
.mode-card h4 { font-size: 14px; font-weight: 700; }
.mode-card p { font-size: 11px; color: var(--text-light); line-height: 1.4; }
.mode-card .badge {
    align-self: flex-start; margin-top: 2px;
    background: var(--db-warning-bg); color: var(--db-warning);
    font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 2px;
}

/* Kategorie-Liste */
.kat-item {
    display: flex; align-items: center; gap: 12px;
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 14px; cursor: pointer; margin-bottom: 8px;
    transition: border-color .15s;
}
.kat-item:hover { border-color: var(--db-cool-gray-300); }
.kat-bar { width: 4px; align-self: stretch; border-radius: 2px; background: var(--db-cool-gray-300); }
.kat-info { flex: 1; min-width: 0; }
.kat-name { font-size: 14px; font-weight: 700; }
.kat-meta { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.kat-progress { height: 4px; background: var(--db-cool-gray-100); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.kat-progress span { display: block; height: 100%; background: var(--db-success); border-radius: 2px; transition: width .3s; }
.kat-pct { font-size: 13px; font-weight: 700; color: var(--db-cool-gray-500); min-width: 38px; text-align: right; }

/* ====== QUIZ ====== */
.quiz-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.quiz-progress-track { flex: 1; height: 4px; background: var(--db-cool-gray-200); border-radius: 2px; overflow: hidden; }
.quiz-progress-fill { height: 100%; background: var(--db-red); border-radius: 2px; transition: width .3s ease; }
.quiz-counter { font-size: 12px; font-weight: 700; color: var(--db-cool-gray-500); font-variant-numeric: tabular-nums; }
.quiz-close { background: none; border: none; cursor: pointer; color: var(--db-cool-gray-400); padding: 4px; display: flex; }
.quiz-close svg { width: 18px; height: 18px; }

.q-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.q-body { padding: 18px; }
.q-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.q-tag {
    font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
    padding: 3px 7px; border-radius: 2px;
    background: var(--db-cool-gray-100); color: var(--db-cool-gray-500);
}
.q-tag.typ { background: var(--db-info-bg); color: var(--db-info); }
.q-text { font-size: 17px; font-weight: 700; line-height: 1.4; letter-spacing: -.2px; }
.q-hint { font-size: 12px; color: var(--text-light); margin-top: 6px; }

.q-img-wrap { margin: 14px 0 4px; }
.q-img {
    width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--db-cool-gray-100); display: block; cursor: zoom-in;
}
.q-img-caption { font-size: 11px; color: var(--text-light); margin-top: 5px; font-style: italic; }

/* Antwortoptionen */
.opts { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.opt {
    display: flex; align-items: flex-start; gap: 10px;
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 14px; cursor: pointer; background: #fff;
    transition: border-color .12s, background .12s;
    text-align: left; width: 100%;
    font-size: 14px; line-height: 1.4;
}
.opt:hover { border-color: var(--db-cool-gray-400); }
.opt-marker {
    flex: 0 0 auto; width: 20px; height: 20px; border-radius: 3px;
    border: 2px solid var(--db-cool-gray-300); background: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: var(--db-cool-gray-500);
    margin-top: 1px;
}
.opt.single .opt-marker { border-radius: 50%; }
.opt.selected { border-color: var(--primary); background: var(--db-cool-gray-100); }
.opt.selected .opt-marker { border-color: var(--primary); background: var(--primary); color: #fff; }
.opt.correct { border-color: var(--db-success); background: var(--db-success-bg); }
.opt.correct .opt-marker { border-color: var(--db-success); background: var(--db-success); color: #fff; }
.opt.wrong { border-color: var(--db-error); background: var(--db-error-bg); }
.opt.wrong .opt-marker { border-color: var(--db-error); background: var(--db-error); color: #fff; }
.opt.locked { cursor: default; pointer-events: none; }
.opt.locked:not(.correct):not(.wrong) { opacity: .55; }

/* Freitext / Karteikarte */
.q-textarea {
    width: 100%; min-height: 90px; margin-top: 14px;
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px; font-size: 14px; resize: vertical; color: var(--text);
}
.q-textarea:focus { outline: none; border-color: var(--primary); }
.q-solution {
    margin-top: 14px; padding: 12px 14px;
    background: var(--db-success-bg); border-left: 3px solid var(--db-success);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 13px; line-height: 1.5;
}
.q-solution strong { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--db-success); margin-bottom: 4px; }

/* Erklärung */
.q-explain {
    margin-top: 14px; padding: 12px 14px;
    background: var(--db-info-bg); border-left: 3px solid var(--db-info);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 13px; line-height: 1.5;
}
.q-explain strong { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--db-info); margin-bottom: 4px; }
.q-source { font-size: 11px; color: var(--db-cool-gray-400); margin-top: 10px; display: flex; align-items: center; gap: 5px; }
.q-source svg { width: 12px; height: 12px; }
.q-source a { color: var(--db-cool-gray-500); }

/* Footer-Aktionen */
.q-actions {
    border-top: 1px solid var(--border); padding: 12px 18px;
    display: flex; gap: 8px; background: var(--db-cool-gray-100);
}
.q-actions .btn { flex: 1; }

/* Selbstbewertung (Karteikarte) */
.self-grade { display: flex; gap: 8px; }
.self-grade .btn { flex: 1; font-size: 13px; }

/* ====== BUTTONS ====== */
.btn {
    padding: 10px 20px; border: none; border-radius: var(--radius);
    font-size: 14px; font-weight: 700; cursor: pointer;
    transition: background .15s, opacity .15s;
    min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--db-red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--db-red-dark); }
.btn-secondary { background: var(--db-cool-gray-200); color: var(--db-cool-gray-700); }
.btn-secondary:hover:not(:disabled) { background: var(--db-cool-gray-300); }
.btn-dark { background: var(--primary); color: #fff; }
.btn-dark:hover:not(:disabled) { background: var(--primary-light); }
.btn-success { background: var(--db-success); color: #fff; }
.btn-warning { background: var(--db-warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }

/* ====== ERGEBNIS ====== */
.result-hero { text-align: center; padding: 24px 16px; }
.result-score { font-size: 44px; font-weight: 700; letter-spacing: -1.5px; line-height: 1; }
.result-label { font-size: 13px; color: var(--text-light); margin-top: 6px; }
.result-badge {
    display: inline-block; margin-top: 14px; padding: 6px 14px; border-radius: var(--radius);
    font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
}
.result-badge.pass { background: var(--db-success-bg); color: var(--db-success); }
.result-badge.fail { background: var(--db-error-bg); color: var(--db-error); }

.review-item {
    display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.review-item:last-child { border-bottom: none; }
.review-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; }
.review-dot.ok { background: var(--db-success); }
.review-dot.no { background: var(--db-error); }
.review-q { font-size: 13px; font-weight: 600; line-height: 1.4; }
.review-a { font-size: 12px; color: var(--text-light); margin-top: 3px; }

/* ====== MATERIAL ====== */
.doc-item {
    display: flex; align-items: center; gap: 12px;
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 14px; margin-bottom: 8px; text-decoration: none; color: var(--text);
    transition: border-color .15s;
}
.doc-item:hover { border-color: var(--db-cool-gray-300); }
.doc-icon {
    flex: 0 0 auto; width: 34px; height: 34px; border-radius: var(--radius);
    background: var(--db-red-100); color: var(--db-red);
    display: flex; align-items: center; justify-content: center;
}
.doc-icon svg { width: 17px; height: 17px; }
.doc-name { font-size: 13px; font-weight: 700; word-break: break-word; }
.doc-meta { font-size: 11px; color: var(--text-light); margin-top: 2px; }

/* ====== EMPTY / LOADING ====== */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }
.empty-state svg { width: 44px; height: 44px; color: var(--db-cool-gray-300); margin-bottom: 12px; }
.empty-state p { font-size: 13px; line-height: 1.5; }
.loading-spinner {
    display: inline-block; width: 24px; height: 24px;
    border: 3px solid var(--db-cool-gray-200); border-top-color: var(--db-red);
    border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====== TOAST ====== */
.toast {
    position: fixed; bottom: 84px; left: 50%;
    transform: translateX(-50%) translateY(120px);
    background: var(--db-cool-gray-700); color: #fff;
    padding: 12px 24px; border-radius: var(--radius);
    font-size: 13px; font-weight: 600; z-index: 2000;
    transition: transform .3s ease; box-shadow: var(--shadow-lg);
    max-width: calc(100% - 32px); text-align: center;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--db-success); }
.toast.error { background: var(--db-error); }

/* ====== LIGHTBOX ====== */
.lightbox {
    position: fixed; inset: 0; z-index: 3000;
    background: rgba(19,24,33,.94);
    display: none; align-items: center; justify-content: center; padding: 20px;
}
.lightbox.active { display: flex; }
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: var(--radius); background: #fff; }
.lightbox-close {
    position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px;
    background: rgba(255,255,255,.12); border: none; color: #fff;
    width: 40px; height: 40px; border-radius: var(--radius); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.lightbox-close svg { width: 20px; height: 20px; }

/* ====== SHEET (Einstellungen) ====== */
.sheet-backdrop {
    position: fixed; inset: 0; z-index: 2500; background: rgba(19,24,33,.5);
    display: none;
}
.sheet-backdrop.active { display: block; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 2600;
    background: #fff; border-radius: var(--radius) var(--radius) 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    transform: translateY(100%); transition: transform .25s ease;
    max-width: 900px; margin: 0 auto;
    max-height: 85vh; overflow-y: auto;
}
.sheet.active { transform: translateY(0); }
.sheet h3 { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--db-cool-gray-400); margin-bottom: 5px; }
.field select, .field input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 14px; background: #fff; color: var(--text);
}
.field select:focus, .field input:focus { outline: none; border-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    background: #fff; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--db-cool-gray-600);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ====== PWA BANNER ====== */
.pwa-banner {
    position: fixed; bottom: calc(72px + env(safe-area-inset-bottom)); left: 12px; right: 12px;
    background: var(--primary); color: #fff; border-radius: var(--radius);
    padding: 12px 14px; display: none; align-items: center; gap: 12px;
    box-shadow: var(--shadow-lg); z-index: 1500; max-width: 876px; margin: 0 auto;
}
.pwa-banner.visible { display: flex; }
.pwa-banner p { flex: 1; font-size: 12px; line-height: 1.4; }
.pwa-banner .btn { min-height: 34px; padding: 6px 14px; font-size: 12px; }

/* ====== DESKTOP ====== */
@media (min-width: 900px) {
    .mode-grid { grid-template-columns: repeat(4, 1fr); }
    main { padding: 24px; padding-bottom: 100px; }
}
