:root {
    --bg: #eeeeee;
    --surface: #ffffff;
    --surface-2: #f5f5f5;
    --border: #c7c7c7;
    --text: #424242;
    --text-muted: #999999;
    --accent: #009688;
    --accent-hover: #00695c;
    --accent-glow: rgba(0, 150, 136, 0.12);
    --error: #B70000;
    --event-bg: #ffffff;
    --event-border: #009688;
    --sidebar-w: 200px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Sidebar ── */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: #009688;
    border-right: none;
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid #00695c;
}

.sidebar-brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}

.sidebar-brand .brand-sub {
    font-size: 0.7rem;
    color: #b2dfdb;
    margin-top: 0.15rem;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.65rem 1rem;
    margin: 0 0.5rem;
    color: #b2dfdb;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
    background: #00695c;
    color: #fff;
}

.sidebar-link.active {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

.sidebar-link .icon {
    font-size: 0.85rem;
    font-weight: 700;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    flex-shrink: 0;
    background: rgba(255,255,255,0.15);
    border-radius: 5px;
    font-family: monospace;
    color: #fff;
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid #00695c;
}

.sidebar-link.logout-link {
    color: #b2dfdb;
    font-size: 0.82rem;
}

.sidebar-link.logout-link:hover {
    background: rgba(183, 0, 0, 0.2);
    color: #ffcdd2;
}

/* Mobile hamburger */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 60;
    align-items: center;
    padding: 0 1rem;
    gap: 0.75rem;
}

.hamburger {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.hamburger:hover {
    color: var(--accent);
    background: none;
}

.mobile-topbar .brand {
    font-size: 1rem;
    font-weight: 700;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 45;
}

/* ── Main content area ── */

.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}

/* ── Content header (week nav, page title) ── */

.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.content-header .page-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.week-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.week-nav button {
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.week-nav button:hover {
    background: var(--border);
}

#week-label {
    font-size: 0.9rem;
    font-weight: 500;
    min-width: 180px;
    text-align: center;
    transition: opacity 0.2s;
}

#week-label.loading {
    opacity: 0.4;
}

/* ── Login ── */

.login-container {
    max-width: 360px;
    margin: 15vh auto;
    padding: 2rem;
}

.login-container h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: #009688;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.field input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.field input:focus {
    border-color: var(--accent);
}

button {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
}

button:hover {
    background: var(--accent-hover);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

form button[type=submit] {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.75rem;
}

.error {
    background: rgba(255, 77, 106, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 1.5rem;
    text-align: center;
}

/* ── Login progress ── */

.progress-container {
    width: 100%;
    height: 4px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.5s ease;
}

.progress-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    margin: 0;
}

/* ── Dashboard ── */

.dashboard {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.dash-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.7rem 0.9rem;
    min-height: 70px;
}

.dash-card.active {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.dash-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.dash-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-meta a {
    text-decoration: none;
}

.dash-link {
    color: var(--accent);
    text-decoration: none;
}

.dash-link:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .dashboard {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .dash-card {
        min-height: auto;
        padding: 0.5rem 0.7rem;
    }
}

/* ── Planning Grid ── */

.planning-container {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

.time-column {
    width: 50px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
}

.time-column .day-header {
    height: 52px;
    border-bottom: 1px solid var(--border);
}

.hours {
    display: flex;
    flex-direction: column;
}

.hour-label {
    height: 60px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    padding-top: 2px;
    border-top: 1px solid var(--border);
}

.days-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    overflow-y: auto;
}

.day-column {
    border-right: 1px solid var(--border);
    min-width: 0;
}

.day-column.weekend {
    opacity: 0.5;
}

.day-column:last-child {
    border-right: none;
}

.day-header {
    text-align: center;
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 5;
}

.day-header.today {
    background: var(--accent);
}

.day-name {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.day-date {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.today .day-date {
    color: rgba(255,255,255,0.8);
}

.day-slots {
    position: relative;
    height: calc(60px * 13);
    padding: 0 2px;
}

/* Hour grid lines */
.day-slots::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        to bottom,
        var(--border) 0px,
        var(--border) 1px,
        transparent 1px,
        transparent 60px
    );
    pointer-events: none;
    z-index: 0;
}

/* ── Events ── */

.event {
    position: absolute;
    left: 2px;
    right: 2px;
    height: 56px;
    background: var(--event-bg);
    border-left: 3px solid var(--event-border);
    border-radius: 4px;
    padding: 3px 5px;
    overflow: hidden;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.7rem;
    line-height: 1.25;
    z-index: 1;
}

.event:hover {
    background: #e0f2f1;
    z-index: 2;
    height: auto;
    min-height: 56px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.event-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.event-subtitle {
    font-size: 0.6rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.event-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 1px;
    position: absolute;
    bottom: 3px;
    left: 5px;
    right: 5px;
}

.event-time,
.event-type {
    color: var(--text-muted);
    font-size: 0.65rem;
}

.event-type {
    opacity: 0.7;
}

/* ── Moodle link on events ── */

.moodle-link {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    font-size: 0.6rem;
    font-weight: 700;
    font-family: monospace;
    background: var(--accent);
    color: white;
    border-radius: 3px;
    text-decoration: none;
    z-index: 3;
}

.moodle-link:hover {
    background: var(--accent-hover);
}

/* ── Modal ── */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    max-width: 420px;
    width: 90%;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.8rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    padding: 0;
}

.modal-close:hover {
    color: var(--text);
    background: none;
}

.modal-content h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding-right: 2rem;
}

.modal-details p {
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
}

.modal-details strong {
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Grades ── */

.grades-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem;
}

.grades-container h2 {
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
}

/* Summary Card */
.summary-card {
    display: flex;
    align-items: center;
    gap: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem 2rem;
    margin-bottom: 1.5rem;
}

.gpa-block {
    text-align: center;
    min-width: 120px;
}

.gpa-value {
    font-size: 2.8rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

.gpa-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.gpa-max {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 400;
}

.summary-stats {
    display: flex;
    gap: 1.2rem;
    flex-wrap: wrap;
    flex: 1;
}

.stat-pill {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
}

.stat-pill .badge {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.stat-pill .count {
    font-weight: 600;
    color: var(--text);
}

.stat-pill .label {
    color: var(--text-muted);
}

.badge-a { background: #22c55e; }
.badge-b { background: #7c5cff; }
.badge-c { background: #a78bfa; }
.badge-d { background: #eab308; }
.badge-e { background: #f97316; }
.badge-fx { background: #ef4444; }
.badge-f { background: #7f1d1d; }

/* Semester Sections */
.semester-section {
    margin-bottom: 2rem;
}

.semester-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.semester-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.01em;
}

.semester-avg {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.semester-avg strong {
    color: var(--accent);
    font-size: 0.95rem;
}

/* UE Table */
.ue-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.ue-table thead {
    background: var(--surface-2);
}

.ue-table th,
.ue-table td {
    padding: 0.65rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

.ue-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ue-table th:last-child,
.ue-table td:last-child {
    text-align: right;
}

.ue-row {
    cursor: pointer;
    transition: background 0.15s;
}

.ue-row:hover {
    background: var(--surface-2);
}

.ue-row td:first-child {
    font-weight: 600;
}

.expand-icon {
    display: inline-block;
    width: 18px;
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.ue-row.expanded .expand-icon {
    transform: rotate(90deg);
}

.avg-value {
    font-weight: 600;
    color: var(--accent);
}

.letter-grade {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.8rem;
    min-width: 28px;
    text-align: center;
}

.letter-a { background: rgba(34,197,94,0.15); color: #22c55e; }
.letter-b { background: rgba(124,92,255,0.15); color: #9478ff; }
.letter-c { background: rgba(167,139,250,0.15); color: #a78bfa; }
.letter-d { background: rgba(234,179,8,0.15); color: #eab308; }
.letter-e { background: rgba(249,115,22,0.15); color: #f97316; }
.letter-fx { background: rgba(239,68,68,0.15); color: #ef4444; }
.letter-f { background: rgba(127,29,29,0.15); color: #ef4444; }

.rattrapage-tag {
    font-size: 0.7rem;
    color: #f97316;
    margin-left: 0.4rem;
    font-weight: 400;
}

/* Nested evaluation rows */
.eval-row {
    background: var(--bg);
}

.eval-row td {
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 0.45rem 0.9rem 0.45rem 2.5rem;
    border-bottom: 1px solid rgba(46,46,58,0.5);
}

.eval-row td:first-child {
    font-weight: 400;
}

.eval-grade {
    color: var(--text);
    font-weight: 500;
}

.eval-no-grade {
    color: var(--text-muted);
    font-style: italic;
}

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

/* Loading / Error / Empty */
.grades-loading {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.grades-loading .spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 0.5rem;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-msg {
    background: rgba(255, 77, 106, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
    padding: 0.8rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.empty-msg {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

/* ── Responsive ── */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .mobile-topbar {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding-top: 48px;
    }

    .content-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .planning-container {
        height: calc(100vh - 48px - 80px);
    }

    .days-grid {
        grid-template-columns: 1fr !important;
    }

    .day-column.weekend {
        display: block;
        opacity: 1;
    }

    .summary-card {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
}

/* Bottom tab bar — mobile only */
.bottom-tabs {
    display: none;
}

@media (max-width: 768px) {
    .bottom-tabs {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: var(--surface);
        border-top: 1px solid var(--border);
        z-index: 60;
        justify-content: space-around;
        align-items: center;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .tab-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 0.65rem;
        padding: 6px 16px;
        border-radius: 8px;
        transition: color 0.15s;
    }

    .tab-item.active {
        color: var(--accent);
    }

    .tab-item .tab-icon {
        font-size: 1.1rem;
        font-weight: 700;
        font-family: monospace;
        width: 28px;
        height: 28px;
        line-height: 28px;
        text-align: center;
        border-radius: 6px;
    }

    .tab-item.active .tab-icon {
        background: var(--accent-glow);
    }

    /* Hide hamburger topbar on mobile — replaced by bottom tabs */
    .mobile-topbar {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }

    /* Adjust main content for bottom tabs */
    .main-content {
        padding-top: 0;
        padding-bottom: 60px;
    }
}

.offline-banner {
    background: var(--surface-2);
    color: var(--text-muted);
    text-align: center;
    padding: 6px;
    font-size: 0.75rem;
    border-bottom: 1px solid var(--border);
}
