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

:root {
    --bg: #f4f6f9;
    --sidebar: #1e293b;
    --sidebar-active: #334155;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --white: #ffffff;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1);
}

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

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--sidebar);
    color: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-brand { padding: 1.5rem; border-bottom: 1px solid var(--sidebar-active); }
.sidebar-brand h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: .5px; }

.auth-actions {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--sidebar-active);
}
.auth-actions .btn {
    width: 100%;
    border-color: var(--sidebar-active);
    background: var(--sidebar-active);
    color: #e2e8f0;
}
.auth-actions .btn:hover {
    background: #475569;
}

/* Org selector in sidebar */
.org-selector {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--sidebar-active);
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    align-items: center;
}
.org-selector label {
    width: 100%;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #94a3b8;
    margin-bottom: .1rem;
}
.org-selector select {
    flex: 1;
    padding: .35rem .5rem;
    border-radius: 4px;
    border: 1px solid var(--sidebar-active);
    background: var(--sidebar-active);
    color: #fff;
    font-size: .8rem;
    min-width: 0;
}
.org-selector .btn { padding: .25rem .5rem; font-size: .8rem; }

.nav-links { list-style: none; padding: .5rem 0; }
.nav-link {
    display: block;
    padding: .75rem 1.5rem;
    color: #94a3b8;
    text-decoration: none;
    font-size: .9rem;
    transition: all .15s;
}
.nav-link:hover, .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
}

/* Main content */
.content {
    margin-left: 240px;
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
}

.page { display: none; }
.page.active { display: block; }

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.page-header h1 { font-size: 1.5rem; }

/* Buttons */
.btn {
    padding: .55rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--white);
    cursor: pointer;
    font-size: .85rem;
    transition: all .15s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.data-table th, .data-table td {
    text-align: left;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    background: #f8fafc;
    font-size: .8rem;
    text-transform: uppercase;
    color: var(--text-light);
    font-weight: 600;
}
.data-table td { font-size: .9rem; }
.data-table tbody tr:hover { background: #f8fafc; }
.actions { display: flex; gap: .5rem; }

/* Stats grid (dashboard) */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.stat-card .label { font-size: .8rem; color: var(--text-light); text-transform: uppercase; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; margin-top: .25rem; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal {
    background: var(--white);
    border-radius: var(--radius);
    width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; }
.btn-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-light); }
#modal-body { padding: 1.5rem; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
}

/* Form fields */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .3rem; }
.form-group input,
.form-group select {
    width: 100%;
    padding: .55rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
}
.form-group select[multiple] { height: 100px; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); }
.checkbox-row { display: flex; align-items: center; gap: .5rem; }
.checkbox-row input[type="checkbox"] { width: auto; }

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: .75rem 1.5rem;
    background: var(--sidebar);
    color: #fff;
    border-radius: var(--radius);
    font-size: .9rem;
    z-index: 200;
    transition: opacity .3s;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.auth-overlay {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1.25rem;
    background:
        radial-gradient(1200px 500px at 10% 0%, rgba(59, 130, 246, 0.24), transparent 70%),
        radial-gradient(1000px 500px at 100% 100%, rgba(16, 185, 129, 0.22), transparent 70%),
        linear-gradient(130deg, #0f172a 0%, #1e293b 45%, #334155 100%);
    z-index: 400;
}

body.auth-mode {
    overflow: hidden;
}

.auth-shell {
    width: min(960px, 94vw);
    min-height: min(560px, 90vh);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 28px 60px rgba(2, 6, 23, 0.4);
    background: #ffffff;
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.auth-hero {
    color: #e2e8f0;
    background:
        linear-gradient(160deg, rgba(15, 23, 42, 0.96), rgba(30, 41, 59, 0.94)),
        repeating-linear-gradient(-45deg, rgba(148, 163, 184, 0.1) 0 8px, rgba(148, 163, 184, 0.02) 8px 16px);
    padding: 2.4rem 2.2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1rem;
}

.auth-chip {
    display: inline-flex;
    align-self: flex-start;
    padding: .3rem .65rem;
    border-radius: 999px;
    font-size: .75rem;
    letter-spacing: .3px;
    text-transform: uppercase;
    color: #dbeafe;
    background: rgba(37, 99, 235, 0.35);
    border: 1px solid rgba(147, 197, 253, 0.35);
}

.auth-hero-title {
    font-size: clamp(1.7rem, 2.6vw, 2.3rem);
    line-height: 1.12;
    letter-spacing: .2px;
}

.auth-hero-copy {
    color: #cbd5e1;
    font-size: 1rem;
    max-width: 34ch;
}

.auth-hero-points {
    list-style: none;
    display: grid;
    gap: .55rem;
}

.auth-hero-points li {
    color: #dbeafe;
    font-size: .92rem;
    display: flex;
    align-items: center;
    gap: .45rem;
}

.auth-hero-points li::before {
    content: "";
    width: .48rem;
    height: .48rem;
    border-radius: 50%;
    background: #38bdf8;
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.2);
}

.auth-panel {
    padding: clamp(1.5rem, 3.5vw, 2.4rem);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: .75rem;
}

.auth-panel h2 {
    font-size: 1.65rem;
    color: #0f172a;
}

.auth-subtitle {
    color: var(--text-light);
    margin-bottom: .9rem;
    font-size: .9rem;
}

.auth-form .form-group {
    margin-bottom: .85rem;
}

.auth-form input {
    height: 2.65rem;
    border-radius: 10px;
}

.auth-form input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.auth-error {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
    border-radius: 10px;
    padding: .55rem .7rem;
    font-size: .82rem;
}

.auth-submit {
    width: 100%;
    height: 2.7rem;
    border-radius: 10px;
    font-weight: 600;
}

@media (max-width: 900px) {
    .auth-shell {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .auth-hero {
        padding: 1.4rem 1.3rem 1.1rem;
        gap: .65rem;
    }

    .auth-hero-points {
        gap: .35rem;
    }

    .auth-panel {
        padding: 1.3rem;
    }
}

/* Optimize controls */
.optimize-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.optimize-controls label { font-size: .85rem; display: flex; align-items: center; gap: .4rem; }
.optimize-controls input { width: 80px; padding: .4rem; border: 1px solid var(--border); border-radius: var(--radius); }

.status-bar {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .9rem;
}
.status-bar.loading { background: #dbeafe; color: #1e40af; }
.status-bar.error { background: #fee2e2; color: #991b1b; }

.version-hint {
    margin-bottom: 1rem;
    color: var(--text-light);
    font-size: .9rem;
}

.fitness-badge {
    display: inline-block;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: .95rem;
    margin-bottom: 1rem;
}
.fitness-badge.high { background: #dcfce7; color: #166534; }
.fitness-badge.medium { background: #fef9c3; color: #854d0e; }
.fitness-badge.low { background: #fee2e2; color: #991b1b; }

.version-banner {
    margin: 0 0 1rem 0;
    padding: .55rem .85rem;
    border-radius: var(--radius);
    font-size: .85rem;
    font-weight: 600;
}
.version-banner.draft { background: #fef9c3; color: #854d0e; }
.version-banner.confirmed { background: #dcfce7; color: #166534; }

.version-actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin: 0 0 1rem;
}

.view-toggle { margin-bottom: 1rem; display: flex; gap: .5rem; }

/* Perspective bar */
.perspective-bar {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.perspective-bar label { font-weight: 600; font-size: .9rem; }
.perspective-bar select {
    padding: .45rem .6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
    background: var(--white);
}
.perspective-subtitle {
    margin-bottom: .75rem;
    font-size: 1.1rem;
    color: var(--primary);
}

/* Timetable grid */
.timetable-grid {
    overflow-x: auto;
}
.timetable-grid table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    font-size: .85rem;
}
.timetable-grid th, .timetable-grid td {
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    text-align: center;
    vertical-align: top;
}
.timetable-grid th { background: var(--sidebar); color: #fff; font-size: .75rem; text-transform: uppercase; }
.timetable-grid .slot {
    background: #eff6ff;
    border-radius: 4px;
    padding: .35rem;
    margin: 2px 0;
    font-size: .78rem;
    text-align: left;
}
.timetable-grid .slot .course-name { font-weight: 600; color: var(--primary); }
.timetable-grid .slot .meta { color: var(--text-light); font-size: .72rem; }

.timetable-html { background: var(--white); padding: 1rem; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }

.version-list-wrap {
    margin-top: 1.5rem;
}
.version-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .75rem;
}
.version-list-header h2 {
    font-size: 1.1rem;
}

.hidden { display: none !important; }

/* Badge */
.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 99px;
    font-size: .75rem;
    font-weight: 600;
}
.badge-yes { background: #dcfce7; color: #166534; }
.badge-no { background: #f1f5f9; color: var(--text-light); }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid #93c5fd;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
    vertical-align: middle;
    margin-right: .5rem;
}

/* ── Admin Settings ── */
.settings-form fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
.settings-form legend {
    font-weight: 700;
    font-size: 1.05rem;
    padding: 0 .5rem;
}
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}
.form-row .form-group { flex: 1 1 180px; }
.settings-form .hint {
    color: var(--text-light);
    font-size: .85rem;
    margin-bottom: 1rem;
}

.security-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.inline-check {
    margin-top: 1.8rem;
}

.inline-password {
    width: 180px;
    padding: .35rem .5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.criteria-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.criteria-item {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}
.criteria-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .4rem;
    font-weight: 600;
}
.criteria-value {
    background: var(--primary);
    color: #fff;
    padding: .1rem .5rem;
    border-radius: 99px;
    font-size: .8rem;
    min-width: 2.5rem;
    text-align: center;
}
.criteria-item input[type=range] { width: 100%; }
.criteria-desc {
    margin-top: .3rem;
    font-size: .8rem;
    color: var(--text-light);
}
