:root {
    --bg: #101014;
    --bg-elevated: #1a1a20;
    --border: #2c2c33;
    --text: #eceef1;
    --text-muted: #96969f;
    --accent: #b0142f;
    --accent-glow: rgba(176, 20, 47, 0.35);
    --accent-hover: #d41a39;
    --success: #2fae5f;
    --radius: 12px;
}

html { scroll-behavior: smooth; }

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-hover); }

/* ---------- Layout ---------- */
.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: 20px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar .brand {
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 8px 12px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sidebar .brand .dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--accent); box-shadow: 0 0 10px var(--accent-glow);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    margin-bottom: 2px;
    border-left: 2px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-item:hover {
    background: rgba(176, 20, 47, 0.08);
    color: var(--text);
    border-left-color: var(--accent);
}
.nav-item.active {
    background: rgba(176, 20, 47, 0.14);
    color: #fff;
    border-left-color: var(--accent);
}
.nav-item .badge {
    margin-left: auto;
    font-size: 0.65rem;
    background: var(--border);
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 10px;
}

.content {
    flex: 1;
    min-width: 0;
    padding: 28px 32px;
}

.topbar-mobile {
    display: none;
}

/* ---------- Cards ---------- */
.wrap { max-width: 1000px; margin: 0 auto; }
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}
.card::before {
    content: "";
    position: absolute; left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--accent);
    opacity: 0.7;
}
.card.center { text-align: center; }

h1 { font-size: 1.4rem; margin: 0 0 6px; }
h2 { font-size: 1.05rem; margin: 0 0 14px; }
.muted { color: var(--text-muted); font-size: 0.88rem; }

/* ---------- Forms ---------- */
label { display: block; margin: 14px 0 5px; font-weight: 600; font-size: 0.85rem; color: var(--text-muted); }
input[type=text], input[type=password], input[type=url], input[type=email],
input[type=number], input[type=datetime-local], select, textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
select[multiple] { min-height: 110px; }

button, .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 16px;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
}
button:hover, .btn:hover { background: var(--accent-hover); }
button:active, .btn:active { transform: scale(0.98); }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--accent); color: #fff; background: rgba(176,20,47,0.1); }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 6px 10px; margin-top: 0; }
.btn-ghost:hover { color: #fff; background: rgba(255,255,255,0.06); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; margin-top: 0; }
.btn-danger { background: #7a1424; }
.btn-danger:hover { background: #9c1a2e; }

.error { color: #ff6b6b; margin-top: 10px; font-size: 0.88rem; }
.success-msg { color: var(--success); margin-top: 10px; font-size: 0.88rem; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: rgba(255,255,255,0.02); }

.tag { display:inline-block; padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.tag-active { background: rgba(47,174,95,0.15); color: var(--success); }
.tag-locked { background: rgba(176,20,47,0.18); color: #ff6b6b; }
.tag-frozen { background: rgba(255,180,0,0.15); color: #ffb400; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.stat-box { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.stat-box .num { font-size: 1.6rem; font-weight: 700; }
.stat-box .label { color: var(--text-muted); font-size: 0.78rem; }

/* ---------- Impersonation bar ---------- */
.impersonate-bar {
    background: #7a1424;
    color: #fff;
    text-align: center;
    padding: 8px;
    font-size: 0.85rem;
}
.impersonate-bar a { color: #fff; text-decoration: underline; margin-left: 10px; }

/* ---------- Screenshot-Galerie ---------- */
.gallery-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}
.gallery-count { color: var(--text-muted); font-size: 0.85rem; }
.gallery-search { flex: 1; max-width: 280px; margin: 0; }

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 16px;
}
.gallery-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    transition: border-color 0.15s;
}
.gallery-item:hover { border-color: var(--accent); }
.gallery-thumb-link { display: block; }
.gallery-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    background: #000;
}
.gallery-thumb-empty {
    display: flex; align-items: center; justify-content: center;
    width: 100%; aspect-ratio: 16 / 10;
    background: #000; color: var(--text-muted); font-size: 1.6rem;
}
.gallery-info { padding: 10px 12px 12px; }
.gallery-name {
    font-size: 0.85rem; font-weight: 600; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: block;
}
.gallery-meta {
    font-size: 0.74rem; color: var(--text-muted); margin-top: 3px;
    display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}
.gallery-actions {
    position: absolute;
    top: 8px; right: 8px;
    display: flex; gap: 6px;
    opacity: 0;
    transition: opacity 0.15s;
}
.gallery-item:hover .gallery-actions,
.gallery-item:focus-within .gallery-actions { opacity: 1; }
.icon-btn {
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(11,11,13,0.85);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
    margin: 0;
}
.icon-btn:hover { background: var(--accent); border-color: var(--accent); }
.icon-btn.danger:hover { background: #7a1424; border-color: #7a1424; }
.gallery-empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
    .app { flex-direction: column; }
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 50;
        width: 250px;
    }
    .sidebar.open { transform: translateX(0); }
    .topbar-mobile {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        background: var(--bg-elevated);
        border-bottom: 1px solid var(--border);
        position: sticky; top: 0; z-index: 40;
    }
    .hamburger {
        background: none; border: none; color: var(--text);
        font-size: 1.4rem; cursor: pointer; margin: 0; padding: 4px 8px;
    }
    .content { padding: 18px; }
    .overlay {
        display: none;
        position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 45;
    }
    .overlay.open { display: block; }
}

/* ---------- Notenrechner (Dashboard-Karten, dezent) ---------- */
.nr-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}
.nr-header h1 { font-size: 1.2rem; }
.nr-header-count { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; }

.nr-group-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    margin: 24px 2px 10px;
}
.nr-group-label:first-of-type { margin-top: 0; }
.nr-group-line { flex: 1; height: 1px; background: var(--border); }

/* ---------- Übersichtskacheln ---------- */
.nr-overview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 8px;
    margin-bottom: 24px;
}
.nr-tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-left: 3px solid var(--subject-color, var(--border));
    border-radius: 8px;
    padding: 8px 10px;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.nr-tile:hover {
    border-color: var(--subject-color, var(--border));
    box-shadow: 0 0 16px -7px var(--subject-color, transparent);
    transform: translateY(-1px);
}
.nr-tile-name {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nr-tile-points { font-size: 0.8rem; font-weight: 600; }
.nr-tile-note { font-size: 0.7rem; color: var(--text-muted); }

/* Dezente Fachbox: dünner Rahmen, leicht abgerundet, farbiger linker Akzent */
.nr-subject {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-left: 3px solid var(--subject-color, var(--border));
    border-radius: 10px;
    padding: 12px 14px 10px;
    margin-bottom: 10px;
    scroll-margin-top: 76px;
    transition: box-shadow 0.15s;
}
.nr-subject:hover {
    box-shadow: 0 0 20px -10px var(--subject-color, transparent);
}

.nr-subject-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--subject-color, var(--border));
    box-shadow: 0 0 6px -1px var(--subject-color, transparent);
    margin-right: 7px;
    vertical-align: middle;
}

.nr-subject-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}
.nr-subject-name {
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.nr-kurs-inline {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.74rem;
    color: var(--text-muted);
}
.nr-kurs-label { color: var(--text-muted); }
.nr-dot { color: var(--border); }
.nr-link {
    color: var(--text-muted);
    text-decoration: none;
    opacity: 0.75;
}
.nr-link:hover { color: var(--accent-hover); opacity: 1; text-decoration: underline; }
.nr-kurs-edit {
    display: inline-flex;
    gap: 3px;
    margin-left: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2px;
}
.nr-kurs-edit button {
    margin: 0;
    padding: 2px 8px;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
}
.nr-kurs-edit button.active { background: var(--accent); color: #fff; }

/* Tabelle bleibt innerhalb der Box - kein Seiten-Scroll. min-width sorgt
   dafür, dass keine Spalte (v.a. Info/Aktionen) unter ihre nötige Breite
   gestaucht wird. Reicht der Platz auf sehr schmalen Screens trotzdem nicht,
   scrollt NUR die Tabelle selbst horizontal (nicht die ganze Seite). */
.nr-table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.nr-table {
    width: 100%;
    min-width: 420px;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.82rem;
}

/* Explizite Spaltenbreiten über Klassen statt nth-child - eindeutig und
   robust, unabhängig von der Zellenreihenfolge im Markup. */
.nr-col-points { width: 54px; }
.nr-col-kind   { width: 92px; }
.nr-col-info   { width: 36px; }
.nr-col-actions{ width: 68px; }

.nr-table th {
    text-align: left;
    font-size: 0.64rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 3px 5px;
    font-weight: 600;
}
.nr-table th.nr-col-points,
.nr-table th.nr-col-info,
.nr-table th.nr-col-actions { text-align: center; }

.nr-table td {
    padding: 5px;
    vertical-align: middle;
    border-top: 1px solid var(--border);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nr-table td.nr-col-points { text-align: right; font-variant-numeric: tabular-nums; overflow: visible; }
.nr-table td.nr-col-kind,
.nr-table td.nr-col-info,
.nr-table td.nr-col-actions { text-align: center; overflow: visible; }

.nr-empty-row td { padding: 8px 5px; font-size: 0.8rem; border-top: none; white-space: normal; }

.nr-kind-tag {
    font-size: 0.66rem;
    color: var(--text-muted);
}
.nr-kind-schriftlich::before { content: "● "; color: #7fb3ff; font-size: 0.55rem; }
.nr-kind-muendlich::before { content: "● "; color: #ffb45c; font-size: 0.55rem; }
.nr-kind-sonstiges::before { content: "● "; color: var(--text-muted); font-size: 0.55rem; }

/* Info/Bearbeiten/Löschen: gleich große, quadratische Icon-Buttons, immer
   sichtbar (kein Hover-Reveal), reine Inline-Anordnung in der jeweiligen
   Zelle - kein position:absolute, kein Flex auf dem <td>. */
.nr-table .icon-btn {
    width: 22px;
    height: 22px;
    font-size: 0.7rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    opacity: 1;
}
.nr-table .icon-btn + .icon-btn { margin-left: 4px; }
.nr-table .icon-btn:hover { color: var(--text); border-color: var(--text-muted); background: var(--border); }
.nr-table .icon-btn.danger:hover { color: #ff9b9b; border-color: #7a1424; background: rgba(122, 20, 36, 0.25); }
.nr-info-btn { cursor: default; }

/* .nr-info: gleiches ⓘ außerhalb der Tabelle (z.B. neben dem Fachdurchschnitt) */
.nr-info {
    cursor: default;
    color: var(--text-muted);
    font-size: 0.78rem;
    opacity: 0.7;
}

/* Fachdurchschnitt: klar erkennbarer Ergebnisbereich statt Fließtext */
.nr-result {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 8px 10px;
    background: color-mix(in srgb, var(--subject-color, var(--border)) 8%, var(--bg));
    border-top: 2px solid var(--subject-color, var(--border));
    border-radius: 0 0 7px 7px;
    font-size: 0.82rem;
    color: var(--text);
}
.nr-result strong { font-weight: 700; }

.nr-subject-footer {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-top: 8px;
    font-size: 0.78rem;
}

/* "+ Leistung": dezent, aber mit klarer Kontur statt fast unsichtbar */
.nr-add-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 5px 11px;
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 600;
    transition: color 0.15s, border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.nr-add-link:hover {
    color: var(--subject-color, var(--accent-hover));
    border-color: var(--subject-color, var(--accent-hover));
    background: color-mix(in srgb, var(--subject-color, var(--accent)) 12%, var(--bg));
    box-shadow: 0 0 14px -7px var(--subject-color, var(--accent-glow));
    text-decoration: none;
}

.nr-form {
    margin-top: 8px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.nr-form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.nr-form label {
    font-size: 0.72rem;
    color: var(--text-muted);
    display: block;
    margin: 0 0 8px;
    flex: 1;
    min-width: 130px;
}
.nr-form input, .nr-form select {
    margin-top: 4px;
    width: 100%;
}
.nr-form-actions { display: flex; gap: 8px; margin-top: 2px; }
.nr-form-actions button { margin: 0; }

@media (max-width: 640px) {
    .nr-subject { padding: 10px 10px 8px; }
    .nr-table { font-size: 0.76rem; }
    .nr-table th, .nr-table td { padding: 4px; }
    .nr-kind-tag { font-size: 0; }
    .nr-subject-footer { font-size: 0.72rem; }
}

@media (max-width: 480px) {
    .nr-overview { grid-template-columns: repeat(2, 1fr); }
}
