/* ============================================================================
   Theme Variables
   ============================================================================ */
:root {
    --bg: #0b0c0d;
    --panel: #121416;
    --panel-2: #171a1d;
    --text: #e6e8ea;
    --muted: #a9b0b6;
    --accent: #7aa2ff;
    --success: #2ecc71;
    --danger: #e74c3c;
    --border: #22262a;
    --shadow: 0 10px 30px rgba(0,0,0,0.35);
    --radius: 16px;
}

/* ============================================================================
   Base / Reset
   ============================================================================ */
* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: radial-gradient(1200px 800px at 20% -10%, #111419 0%, var(--bg) 60%) fixed;
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
    line-height: 1.45;
}

/* ============================================================================
   Page Shell
   ============================================================================ */
.page {
    max-width: 980px;
    margin: 40px auto;
    padding: 0 20px;
}

/* ============================================================================
   Header
   ============================================================================ */
.header {
    margin-bottom: 18px;
    padding: 20px 24px;
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.header h1 {
    margin: 0 0 6px 0;
    font-size: 28px;
    letter-spacing: 0.2px;
}

.header .sub {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

/* ============================================================================
   Controls
   ============================================================================ */
.controls {
    display: flex;
    justify-content: flex-end;
    margin: 14px 0;
}

.controls form {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 10px;
}

.controls label {
    color: var(--muted);
    font-size: 13px;
}

.controls input[type="number"] {
    width: 72px;
    padding: 6px 8px;
    border-radius: 8px;
    background: #0f1214;
    color: var(--text);
    border: 1px solid var(--border);
}

.controls button {
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid #2b3340;
    background: #1a2330;
    color: var(--text);
    cursor: pointer;
}

.controls button:hover {
    border-color: #3b4759;
    background: #223044;
}

/* ============================================================================
   Table: Structure
   ============================================================================ */
table.exams {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

table.exams thead th {
    text-align: left;
    padding: 14px 16px;
    font-size: 13px;
    color: var(--muted);
    background: #0f1214;
    border-bottom: 1px solid var(--border);
}

table.exams tbody td {
    padding: 14px 16px;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

table.exams tbody tr:last-child td {
    border-bottom: none;
}

table.exams tbody tr {
    transition: transform 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}

table.exams tbody tr:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 18px rgba(0,0,0,0.25) inset;
}

/* ============================================================================
   Table: Column-Level Styling
   ============================================================================ */

/* Date column: keep numbers aligned and avoid wrapping */
td.when {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* Days-left column: center header + cells, keep numbers aligned, set a stable width */
table.exams thead th.days-left,
table.exams tbody td.days-left {
    text-align: center;                 /* override the left-align on thead th */
}

td.days-left {
    font-variant-numeric: tabular-nums;
    min-width: 64px;                    /* keeps column from jittering */
}

/* Exam cell: two-line stack (title + subject) */
td.exam .exam-title {
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 4px;
}

td.exam .exam-subject {
    color: var(--muted);
    font-size: 13px;
}

/* Person cell: keep on one line */
td.person {
    white-space: nowrap;
}

/* Color dot next to person */
.dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 999px;
    margin-right: 8px;
    vertical-align: -1px;
    border: 1px solid rgba(255,255,255,0.25);
}

/* ============================================================================
   Legend
   ============================================================================ */
.legend {
    margin-top: 18px;
    padding: 16px 18px;
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.legend h2 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: var(--muted);
}

.legend ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    gap: 14px 20px;
    flex-wrap: wrap;
}

.legend li {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    background: #0f1214;
    border: 1px solid var(--border);
}

.legend .swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.25);
}

/* ============================================================================
   Messages
   ============================================================================ */
.error, .empty {
    margin: 14px 0;
    padding: 14px 16px;
    background: #2a1212;
    border: 1px solid #4e1a1a;
    color: #ffd4d4;
    border-radius: 10px;
}

.empty {
    background: #131a20;
    border-color: #23303c;
    color: #cfdae5;
}

/* ============================================================================
   Footer
   ============================================================================ */
.footer {
    margin-top: 18px;
    display: flex;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    justify-content: center;
}

/* ============================================================================
   Responsive
   ============================================================================ */
@media (max-width: 680px) {
    /* Keep real table rows (no grid, no stacked cards) */
    table.exams thead {
        display: table-header-group;
    }
    table.exams tbody tr {
        display: table-row;
        padding: 0;
    }
    table.exams tbody td {
        display: table-cell;
        border: 0;
        padding: 8px 10px;              /* tighter rows */
        vertical-align: middle;         /* center content vertically to save space */
    }

    /* Smaller text overall inside the table */
    table.exams {
        font-size: 13px;
        table-layout: fixed;            /* prevents columns from expanding wildly */
    }

    /* Column widths (approximate, tuned for portrait phones) */
    table.exams thead th:nth-child(1),
    table.exams tbody td:nth-child(1) { /* Datum */
        width: 42%;
    }
    table.exams thead th:nth-child(2),
    table.exams tbody td:nth-child(2) { /* Tage */
        width: 56px;                    /* narrow and predictable */
    }
    table.exams thead th:nth-child(3),
    table.exams tbody td:nth-child(3) { /* Prüfung */
        width: auto;
    }
    table.exams thead th:nth-child(4),
    table.exams tbody td:nth-child(4) { /* Person */
        width: 1%;
        white-space: nowrap;            /* keep short */
    }

    /* Datum: keep on one line and slightly smaller */
    td.when {
        white-space: nowrap;
        font-size: 13px;
    }

    /* Tage: center nicely, fixed width already set above */
    table.exams thead th.days-left,
    table.exams tbody td.days-left {
        text-align: center;
    }
    td.days-left {
        font-variant-numeric: tabular-nums;
        padding-right: 6px;
        padding-left: 6px;
    }

    /* Prüfung: show only the title on small screens to save vertical space */
    td.exam .exam-title {
        font-size: 14px;
        margin-bottom: 0;               /* remove extra gap */
    }
    td.exam .exam-subject {
        display: none;                  /* hide subject on phones */
    }

    /* Person cell and dot: more compact */
    td.person {
        font-size: 13px;
    }
    .dot {
        width: 8px;
        height: 8px;
        margin-right: 6px;
    }

    /* Legend: smaller and tighter to avoid pushing content down */
    .legend {
        padding: 10px 12px;
    }
    .legend h2 {
        font-size: 14px;
        margin-bottom: 6px;
    }
    .legend li {
        padding: 4px 8px;
    }
}
