/**
 * dashboard.css - Dashboard-specific styles
 * Used by: index.html (main dashboard page)
 */

/* CSS Variables */
:root {
    --header-bg: #ffd54f;
    --section-bg: #fff9c4;
    --font-scale: 1;
}

/* Dashboard body override */
body {
    padding: 20px;
}

/* Top bar with expand controls */
.top-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 10px;
}

.top-bar-right {
    display: flex;
    gap: 8px;
}

.expand-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.toggle-label {
    font-size: 0.85em;
    color: #666;
    margin-right: 4px;
}

.btn-outline {
    background: white;
    border: 1px solid #ccc;
    color: #666;
}

.btn-outline:hover {
    background: #f5f5f5;
    border-color: #999;
}

.btn-outline.active {
    background: #e3f2fd;
    border-color: #2196f3;
    color: #1976d2;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.stat {
    background: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    text-align: center;
    min-width: 110px;
}

.stat-value {
    font-size: 1.4em;
    font-weight: bold;
}

.stat-label {
    color: #666;
    font-size: 0.8em;
}

.stat.passed .stat-value {
    color: #4caf50;
}

.stat.open .stat-value {
    color: #f44336;
}

.stat.cp .stat-value {
    color: #2196f3;
}

.stat.grade .stat-value {
    color: #9c27b0;
}

/* Study Grid Wrapper */
.study-grid-wrapper {
    overflow: visible;
}

/* Study Grid Table */
.study-grid {
    width: 100%;
    border-collapse: collapse;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    table-layout: fixed;
}

.study-grid th,
.study-grid td {
    border: 1px solid #ccc;
    padding: 8px;
    text-align: center;
    vertical-align: top;
    font-size: calc(0.9em * var(--font-scale));
}

.study-grid th {
    background: var(--header-bg);
    font-weight: bold;
}

.study-grid .section-header {
    background: var(--section-bg);
    font-weight: bold;
    text-align: left;
    padding-left: 10px;
    width: 12%;
}

.study-grid .section-header .cp-count {
    font-weight: normal;
    font-size: 0.85em;
    color: #666;
}

.study-grid .section-header .cp-count.complete {
    color: #4caf50;
    font-weight: 500;
}

/* Module Card - now uses bereich color as background */
.module {
    padding: 8px;
    margin: 4px;
    border-radius: 6px;
    text-align: left;
    min-height: 70px;
    position: relative;
    cursor: pointer;
    transition: box-shadow 0.2s;
    /* Default background, will be overridden by inline style with bereich color */
    background: #f5f5f5;
}

.module:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.module-name {
    font-weight: 500;
    font-size: 0.9em;
    margin-bottom: 4px;
    padding-right: 50px;
}

.module-cp {
    font-size: 0.75em;
    color: #666;
}

/* Grade Tag - positioned at bottom right */
.module-grade {
    position: absolute;
    bottom: 6px;
    right: 6px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.85em;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.module-grade.passed {
    background: #e8f5e9;
    color: #2e7d32;
}

.module-grade.partial {
    background: #fff3e0;
    color: #e65100;
}

.module-grade.failed {
    background: #ffebee;
    color: #c62828;
}

.module-grade.open {
    background: #f5f5f5;
    color: #888;
    font-weight: normal;
}

/* Expand Arrow */
.module-expand {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    color: #666;
    transition: transform 0.2s;
}

.module.expanded .module-expand {
    transform: rotate(180deg);
}

/* Exam Details */
.exam-details {
    display: none;
    margin-top: 8px;
    padding-top: 8px;
    padding-bottom: 24px;
    border-top: 1px solid rgba(0,0,0,0.1);
    font-size: 0.8em;
}

.module.expanded .exam-details {
    display: block;
}

/* Wahlpflicht expanded: exam-details braucht kein extra padding,
   da wahlpflicht-module bereits padding-bottom hat */
.wahlpflicht-module.expanded .exam-details {
    padding-bottom: 0;
}

.exam-item {
    padding: 6px 0;
}

.exam-item + .exam-item {
    border-top: 1px solid rgba(0,0,0,0.1);
}

.exam-item .exam-header {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 2px;
}

.exam-item .exam-code {
    font-size: 0.75em;
    padding: 1px 4px;
    border-radius: 3px;
    color: #fff;
    background: #005EA7;
}

.exam-item .exam-code.type-b {
    background: #D7005F;
}

.exam-item .exam-cp {
    color: #666;
    font-size: 0.85em;
}

.exam-item .exam-grade {
    font-weight: 500;
    color: #4caf50;
    font-size: 0.85em;
}

.exam-item .exam-date {
    color: #888;
    font-size: 0.8em;
}

.exam-item .exam-name {
    display: block;
    font-size: 0.9em;
}

/* Wahlpflicht Dropdown */
.wahlpflicht-module {
    position: relative;
    padding-bottom: 32px;
}

.wahlpflicht-controls {
    clear: both;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px dashed #ddd;
}

.wahlpflicht-select {
    width: 100%;
    padding: 6px;
    margin-top: 4px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.85em;
    background: white;
}

.wahlpflicht-label {
    font-size: 0.75em;
    color: #666;
}

/* Total Row */
.total-row {
    background: var(--header-bg);
    font-weight: bold;
}

.total-row td {
    text-align: center;
}

/* No PO Hint */
.no-po-hint {
    background: #fff3e0;
    border: 1px solid #ff9800;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 15px;
    color: #e65100;
    font-size: 0.9em;
    text-align: center;
}

/* Responsive - Mobile/Tablet (Horizontal Scroll ab 1300px) */
@media (max-width: 1300px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 1.3em;
    }

    .subtitle {
        font-size: 0.85em;
        margin-bottom: 15px;
    }

    /* Top Bar - mittig zentriert */
    .top-bar {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    .top-bar-left,
    .top-bar-right {
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Stats Bar - kompakter, 2x2 Grid */
    .stats-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        justify-content: center;
        max-width: 400px;
        margin: 0 auto 15px auto;
    }

    .stat {
        padding: 10px 12px;
        min-width: unset;
    }

    .stat-value {
        font-size: 1.2em;
    }

    .stat-label {
        font-size: 0.75em;
    }

    /* Expand Controls - mittig */
    .expand-controls {
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Mobile: Horizontal scrollbare Tabelle */
    .study-grid-wrapper {
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        /* WICHTIG: scroll-padding beruecksichtigt die sticky Bereich-Spalte (38.2% - goldener Schnitt) */
        scroll-padding-left: 38.2vw;
        margin: 0;
        /* Verhindert Overscroll */
        overscroll-behavior-x: contain;
        /* Reserviert immer Platz fuer Scrollbar - verhindert Layout-Shift */
        scrollbar-gutter: stable;
    }

    .study-grid {
        width: max-content;
        border-collapse: collapse;
        table-layout: fixed;
    }

    /* Bereich-Spalte sticky - 38.2% (goldener Schnitt) */
    .study-grid th:first-child,
    .study-grid td.section-header,
    .study-grid .total-row td:first-child {
        position: sticky;
        left: 0;
        z-index: 12;
        width: 38.2vw;
        min-width: 38.2vw;
        max-width: 38.2vw;
        box-shadow: 4px 0 8px -2px rgba(0,0,0,0.25);
    }

    .study-grid th:first-child {
        background: var(--header-bg);
        z-index: 13;
    }

    .study-grid td.section-header {
        background: var(--section-bg);
        padding: 8px 10px;
    }

    .study-grid .total-row td:first-child {
        background: var(--header-bg);
    }

    /* Semester-Spalten - saubere Berechnung:
       Sichtbarer Bereich = 100vw - 38.2vw (Bereich) = 61.8vw
       Davon abziehen: 2x Body-Padding (20px) + 2x Zell-Padding (16px) = 36px
       scrollbar-gutter: stable reserviert Scrollbar-Platz automatisch
    */
    .study-grid th:not(:first-child),
    .study-grid td:not(.section-header):not(:first-child) {
        width: calc(61.8vw - 36px);
        min-width: calc(61.8vw - 36px);
        max-width: calc(61.8vw - 36px);
        /* Snap auf den linken Rand der Zelle */
        scroll-snap-align: start;
        scroll-snap-stop: always;
        /* Gleichmaessiges Padding */
        padding: 8px;
    }

    /* Module volle Breite */
    .module {
        width: 100%;
        box-sizing: border-box;
        margin: 2px 0;
        min-height: 60px;
        padding: 8px;
    }

    .module-name {
        font-size: 0.85em;
        padding-right: 45px;
    }

    .module-cp {
        font-size: 0.75em;
    }

    .module-grade {
        font-size: 0.8em;
        padding: 2px 8px;
    }

    .module-expand {
        width: 18px;
        height: 18px;
        font-size: 0.65em;
    }

    /* Wahlpflicht */
    .wahlpflicht-select {
        font-size: 0.8em;
        padding: 5px;
    }

    /* Wahlpflicht Mobile - Platz fuer Note-Tag */
    .wahlpflicht-module {
        padding-bottom: 32px;
    }

    .wahlpflicht-module.expanded .exam-details {
        padding-bottom: 0;
    }
}

/* Kleinere Screens - noch kompakter */
@media (max-width: 500px) {
    h1 {
        font-size: 1.1em;
    }

    .subtitle {
        font-size: 0.75em;
    }

    .stats-bar {
        gap: 8px;
        max-width: 300px;
    }

    .stat {
        padding: 8px 10px;
    }

    .stat-value {
        font-size: 1.1em;
    }

    .stat-label {
        font-size: 0.7em;
    }

    /* Kleine Screens: Bereich etwas schmaler (32%) fuer mehr Sem-Platz */
    .study-grid-wrapper {
        scroll-padding-left: 32vw;
    }

    .study-grid th:first-child,
    .study-grid td.section-header,
    .study-grid .total-row td:first-child {
        width: 32vw;
        min-width: 32vw;
        max-width: 32vw;
    }

    .study-grid td.section-header {
        padding: 6px 8px;
    }

    /* Sichtbarer Bereich = 100vw - 32vw = 68vw
       Davon abziehen: 2x Body-Padding (20px) + 2x Zell-Padding (12px) = 32px
    */
    .study-grid th:not(:first-child),
    .study-grid td:not(.section-header):not(:first-child) {
        width: calc(68vw - 32px);
        min-width: calc(68vw - 32px);
        max-width: calc(68vw - 32px);
        padding: 6px;
    }

    .module {
        min-height: 50px;
        padding: 6px;
        margin: 2px 0;
    }
}
