:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --secondary: #64748b;
    --accent: #f59e0b;
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-alt: #f1f5f9;
    --text: #0f172a;
    --text-light: #64748b;
    --border: #e2e8f0;
    --tag-bg: #eff6ff;
    --tag-text: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);

    /* Subject & Group colors (Light Mode) */
    --subject-bg-sat: 75%;
    --subject-bg-light: 96%;
    --subject-text: #0f172a;
    --subject-border-sat: 60%;
    --subject-border-light: 40%;

    --group-banner-bg: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    --group-banner-border: #f59e0b;
    --group-banner-text: #92400e;
    --group-banner-btn-bg: white;
    --group-banner-btn-text: #92400e;

    /* Bell Preview (Light Mode) */
    --bell-bg: #f1f5f9;
    --bell-item-bg: var(--surface);
    --bell-break-bg: #fef3c7;
    --bell-break-border: #f59e0b;
    --bell-break-text: #92400e;
    --bell-assembly-bg: #ecfdf5;
    --bell-assembly-border: #10b981;
    --bell-assembly-text: #065f46;
    --bell-zero-bg: #f5f3ff;
    --bell-zero-border: #8b5cf6;
    --bell-zero-text: #5b21b6;
    /* Input & Notification Defaults */
    --input-bg: #ffffff;
    --input-focus: #ffffff;
    --warning-bg: #fffbeb;
    --warning-border: #f59e0b;
    --error-bg: #fef2f2;
    --error-border: #ef4444;
}

[data-theme='dark'] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #334155;
    --text: #f8fafc;
    --text-light: #94a3b8;
    --border: #334155;
    --tag-bg: #1e3a8a;
    --tag-text: #60a5fa;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);

    /* Dark Mode Overrides */
    --input-bg: #0f172a;
    --input-focus: #1e293b;
    --warning-bg: #451a03;
    --warning-border: #b45309;
    --error-bg: #450a0a;
    --error-border: #991b1b;

    /* Subject & Group colors (Dark Mode Styles) */
    --subject-bg-sat: 60%;
    --subject-bg-light: 25%;
    --subject-text: #f8fafc;
    --subject-border-sat: 50%;
    --subject-border-light: 40%;

    --group-banner-bg: linear-gradient(135deg, #451a03 0%, #78350f 100%);
    --group-banner-border: #b45309;
    --group-banner-text: #fef3c7;
    --group-banner-btn-bg: #451a03;
    --group-banner-btn-text: #fef3c7;

    /* Bell Preview (Dark Mode Styles) */
    --bell-bg: #0f172a;
    /* darker than surface */
    --bell-item-bg: var(--surface);
    --bell-break-bg: #451a03;
    --bell-break-border: #b45309;
    --bell-break-text: #fef3c7;
    --bell-assembly-bg: #064e3b;
    --bell-assembly-border: #059669;
    --bell-assembly-text: #d1fae5;
    --bell-zero-bg: #4c1d95;
    --bell-zero-border: #7c3aed;
    --bell-zero-text: #e9d5ff;
}

/* --- PRINT OPTIMIZATION --- */
.eco-print td {
    background: none !important;
    border: 2px solid #000 !important;
    color: #000 !important;
    box-shadow: none !important;
    filter: grayscale(100%) brightness(0.8) !important;
}

.eco-print .timetable-slot {
    background: #fff !important;
    border: 1px solid #ccc !important;
}

.eco-print h1,
.eco-print h2,
.eco-print th {
    color: #000 !important;
}

.print-scale-container {
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: top center;
}

/* --- SPOTLIGHT & DIMMING --- */
.timetable-slot {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dimmed {
    opacity: 0.15 !important;
    filter: grayscale(100%) blur(1px);
    transform: scale(0.95);
}

.spotlight-active {
    transform: scale(1.04);
    box-shadow: 0 12px 24px rgba(37, 99, 235, 0.25) !important;
    z-index: 100 !important;
    border: 2px solid var(--primary) !important;
    position: relative;
}

/* --- SIDEBAR COMMAND CENTER --- */
.sidebar-dashboard {
    margin: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: none;
    flex-direction: column;
    gap: 1.5rem;
    animation: slideInLeft 0.4s ease forwards;
}

.sidebar-dash-active .sidebar-dashboard {
    display: flex;
}

.sidebar-dash-active .nav {
    display: none;
}

/* Hide main nav when analytics active */
.sidebar-dash-active .brand {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 1rem;
}

.dash-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 800;
    color: #94a3b8;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dash-card {
    background: rgba(15, 23, 42, 0.3);
    border-radius: 10px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.metric-value {
    font-weight: 700;
    color: #fff;
}

.metric-label {
    color: #94a3b8;
}

.spotlight-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 4px;
}

.spotlight-item {
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    color: #cbd5e1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.spotlight-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.spotlight-item.active {
    background: var(--primary);
    color: #fff;
}

.conflict-item {
    padding: 8px;
    border-radius: 6px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    font-size: 0.75rem;
    margin-bottom: 6px;
    cursor: pointer;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Scrollbar for sidebar lists */
.spotlight-list::-webkit-scrollbar {
    width: 4px;
}

.spotlight-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

/* --- GENERATION LOADER --- */
#generation-loader {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    z-index: 9999;
    color: white;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.loader-content {
    position: relative;
    max-width: 600px;
    padding: 40px;
}

.pulse-ring {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--primary);
    position: relative;
    margin: 0 auto 30px;
    animation: pulse-glow 2s infinite;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
}

@keyframes pulse-glow {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 30px rgba(37, 99, 235, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
    }
}

.loader-status {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(90deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.loader-progress {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin: 20px 0;
}

.loader-bar {
    height: 100%;
    background: linear-gradient(90deg, #2563eb, #8b5cf6);
    width: 0%;
    transition: width 0.3s ease;
}

.loader-tip {
    font-size: 0.95rem;
    color: #94a3b8;
    font-style: italic;
    min-height: 24px;
    animation: fadeIn 0.5s ease;
}

* {
    box-sizing: border-box;
    outline: none;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Layout */
.app {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.mobile-header {
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 110;
}

.hamburger {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text);
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar {
    width: 260px;
    background: #0f172a;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 120;
    color: #94a3b8;
}

.overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 115;
    transition: opacity 0.3s;
}

.main {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
    width: 100%;
}

/* Sidebar */
.brand {
    padding: 1.5rem;
    font-size: 1.25rem;
    font-weight: 800;
    color: #38bdf8;
    letter-spacing: -0.5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav {
    padding: 1rem;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin-bottom: 4px;
    border-radius: var(--radius);
    cursor: pointer;
    color: #94a3b8;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #f8fafc;
}

.nav-item.active {
    background: #38bdf8;
    color: #0f172a;
}

[data-theme='dark'] .nav-item.active {
    background: var(--tag-bg);
    color: var(--tag-text);
}

[data-theme='dark'] .nav-item:hover {
    background: #334155;
}

[data-theme='dark'] input,
[data-theme='dark'] select {
    background: var(--input-bg);
    color: var(--text);
}

/* Content */
h1,
h2,
h3 {
    margin: 0 0 1rem 0;
    letter-spacing: -0.5px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
}

.required::after {
    content: " *";
    color: var(--danger);
    font-weight: bold;
}

input,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: border 0.2s;
}

option {
    background: var(--surface);
    color: var(--text);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
    background-color: var(--input-focus);
}

[data-theme='dark'] input:focus,
[data-theme='dark'] select:focus {
    background-color: var(--input-focus);
    box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.25);
}

.input-error {
    border-color: var(--error-border) !important;
    background-color: var(--error-bg) !important;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--surface-alt);
}

.btn-danger {
    background: var(--danger);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Tags & Lists */
.tag-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 8px;
}

.tag {
    background: var(--tag-bg);
    color: var(--tag-text);
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
}

.tag span {
    cursor: pointer;
    opacity: 0.6;
}

.tag span:hover {
    opacity: 1;
}

/* Setup Views */
.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.list-item:last-child {
    border-bottom: none;
}

/* Multigrade Toggle */
.toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.toggle input {
    display: none;
}

/* Custom Dropdown for Year */
.dropdown-container {
    position: relative;
    width: 100%;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 100;
    display: none;
    max-height: 200px;
    overflow-y: auto;
    margin-top: 4px;
}

.dropdown-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
}

.dropdown-item:hover {
    background: var(--surface-alt);
}

.dropdown-container.active .dropdown-menu {
    display: block;
}

.dropdown-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 0.7rem;
    opacity: 0.6;
    color: var(--text);
}

.slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

input:checked+.slider {
    background: var(--primary);
}

input:checked+.slider::before {
    transform: translateX(18px);
}

/* Bell Preview Styles */
.bell-preview-container {
    margin-top: 20px;
    padding: 15px;
    background: var(--bell-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.bell-preview-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.timeline {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.timeline-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--surface);
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    transition: transform 0.2s;
}

.timeline-item:hover {
    transform: translateX(4px);
}

.timeline-time {
    color: var(--text-light);
    font-weight: 500;
    min-width: 80px;
    font-family: monospace;
}

.timeline-label {
    color: var(--text);
    font-weight: 600;
}

/* Timeline Item Types */
.item-break {
    background: var(--bell-break-bg);
    border-color: var(--bell-break-border);
    color: var(--bell-break-text);
}

.item-break .timeline-time {
    color: var(--bell-break-text);
    opacity: 0.8;
}

.item-break .timeline-label {
    color: var(--bell-break-text);
}

.item-assembly {
    background: var(--bell-assembly-bg);
    border-color: var(--bell-assembly-border);
    color: var(--bell-assembly-text);
}

.item-assembly .timeline-time {
    color: var(--bell-assembly-text);
    opacity: 0.8;
}

.item-assembly .timeline-label {
    color: var(--bell-assembly-text);
}

.item-zero {
    background: var(--bell-zero-bg);
    border-color: var(--bell-zero-border);
    color: var(--bell-zero-text);
}

.item-zero .timeline-time {
    color: var(--bell-zero-text);
    opacity: 0.8;
}

.item-zero .timeline-label {
    color: var(--bell-zero-text);
}

/* --- VISIBILITY CONTROL FOR LANDING PAGE --- */

/* 1. Landing Page Styles */
#landing-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at top right, #1e293b, #0f172a);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    overflow-y: auto;
    transition: opacity 0.8s ease;
}

/* 2. Hide App & Header by default */
body:not(.app-visible) .app,
body:not(.app-visible) .mobile-header,
body:not(.app-visible) .overlay {
    display: none !important;
}

.fade-out {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* 3. Hide Landing Page when App is visible */
body.app-visible #landing-page {
    opacity: 0;
    pointer-events: none;
}

/* --- TOAST NOTIFICATIONS --- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--surface);
    color: var(--text);
    padding: 12px 16px;
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 400px;
    pointer-events: auto;
    animation: slideInRight 0.3s ease forwards;
    border-left: 4px solid var(--primary);
    font-size: 0.9rem;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.danger {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--accent);
}

.toast-hide {
    animation: fadeOutRight 0.3s ease forwards;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOutRight {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* 4. Ensure Body Layout is correct for App */
body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll, handle inside .app or #landing-page */
}

/* Animation for App Entry */
body.app-visible .app {
    animation: appFadeIn 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    display: flex !important;
    /* Restore flex layout */
}

body.app-visible .mobile-header {
    display: flex !important;
}

@media (min-width: 1025px) {
    body.app-visible .mobile-header {
        display: none !important;
    }
}

.hero-content {
    max-width: 800px;
    animation: fadeInUp 1s ease-out;
    text-align: center;
    padding: 2rem;
}

.hero-title {
    font-size: 4rem;
    font-weight: 900;
    background: linear-gradient(135deg, #60a5fa 0%, #2563eb 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1rem;
    letter-spacing: -2px;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: #94a3b8;
    margin-bottom: 2.5rem;
    line-height: 1.6;
}

.launch-btn {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    border: none;
    padding: 1rem 3rem;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 99px;
    cursor: pointer;
    box-shadow: 0 10px 25px -5px rgba(37, 99, 235, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.launch-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 20px 30px -10px rgba(37, 99, 235, 0.5);
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    width: 100%;
    max-width: 1000px;
    margin-top: 4rem;
    animation: fadeInUp 1.2s ease-out;
}

.feature-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.5rem;
    border-radius: 16px;
    backdrop-filter: blur(10px);
    transition: all 0.3s;
}

.feature-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-5px);
}

.feature-icon {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

.feature-name {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: #f8fafc;
}

.feature-desc {
    font-size: 0.9rem;
    color: #94a3b8;
    line-height: 1.5;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Overrides for Landing */
@media (max-width: 768px) {
    .hero-title {
        font-size: 2.5rem;
    }

    .hero-subtitle {
        font-size: 1.1rem;
    }

    .features-grid {
        margin-top: 2rem;
    }
}

/* --- END CSS --- */