:root {
    /* Premium Slate Palette */
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;
    
    /* Brand Colors */
    --brand-primary: #3b82f6; /* Blue 500 */
    --brand-hover: #2563eb;   /* Blue 600 */
    --brand-light: #eff6ff;   /* Blue 50 */
    
    /* Semantic Colors */
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;

    /* Base Variables (White Theme) */
    --bg-body: #f9fafb;
    --bg-surface: #ffffff;
    --bg-sidebar: #ffffff;
    
    --text-primary: var(--slate-800);
    --text-secondary: var(--slate-500);
    --text-inverse: #ffffff; /* For primary buttons */
    
    --sidebar-text: var(--slate-600);
    --sidebar-text-hover: var(--brand-primary);
    --sidebar-bg-hover: var(--brand-light);
    
    --border-color: #e5e7eb;
    
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.03);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.06);
    
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --sidebar-width: 260px;
    --topbar-height: 72px;
}

/* ================= Reset & Typography ================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

h1 { font-size: 24px; }
h2 { font-size: 18px; margin-bottom: 8px; }
h3 { font-size: 14px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }

p { margin-bottom: 16px; }
.text-muted { color: var(--text-secondary); }

/* ================= Layout: Sidebar & Main ================= */
.dashboard-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header .logo {
    color: var(--brand-primary);
    font-size: 28px;
    display: flex;
    align-items: center;
}

.sidebar-header h2 {
    color: var(--text-primary);
    font-size: 18px;
    margin: 0;
    letter-spacing: -0.5px;
    font-weight: 700;
}

.sidebar-nav {
    flex: 1;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    width: 100%;
}

.nav-item i {
    font-size: 20px;
}

.nav-item:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
}

.nav-item.active {
    background-color: var(--brand-primary);
    color: var(--text-inverse);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: var(--topbar-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    flex-shrink: 0;
}

.topbar-left h1 {
    font-size: 20px;
}

.topbar-right .user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    font-size: 14px;
}

.avatar {
    width: 32px;
    height: 32px;
    background-color: var(--brand-light);
    color: var(--brand-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.content-wrapper {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
}

.view-section {
    max-width: 1200px;
    margin: 0 auto;
}
.hidden {
    display: none !important;
}

/* ================= UI Components ================= */
.card {
    background: var(--bg-surface);
    border: none;
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
}

.w-full { width: 100%; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-lg {
    padding: 14px 24px;
    font-size: 16px;
}

.btn-primary {
    background-color: var(--brand-primary);
    color: white;
}
.btn-primary:hover {
    background-color: var(--brand-hover);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.btn-outline:hover {
    background-color: var(--slate-50);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}
.icon-btn:hover { background: var(--slate-100); color: var(--text-primary); }

/* Forms */
.modern-form .form-group {
    margin-bottom: 16px;
}

.modern-form label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.modern-form input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text-primary);
    transition: all 0.2s;
}

.modern-form input:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-light);
}

.form-row {
    display: flex;
    gap: 16px;
}
.form-row .form-group { flex: 1; }

.form-msg {
    margin-top: 12px;
    font-size: 13px;
    text-align: center;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--slate-100);
    color: var(--slate-600);
}
.badge-subtle {
    background: var(--brand-light);
    color: var(--brand-hover);
}

/* ================= Specific Views ================= */

/* Overview */
.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-surface);
    border: none;
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--brand-light);
    color: var(--brand-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.stat-info h2 { font-size: 28px; margin: 0; color: var(--text-primary); }
.stat-info h3 { margin-bottom: 4px; }

.quick-actions .action-buttons {
    display: flex;
    gap: 16px;
    margin-top: 16px;
}

/* Scrape Section */
.form-card { max-width: 600px; margin: 0 auto; }
.status-card { max-width: 600px; margin: 24px auto; text-align: center; }

/* Grid Layouts for Classes & Settings */
.two-col-layout {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 24px;
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.subject-item {
    display: flex;
    flex-direction: column;
    padding: 16px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
}

.subject-item.clickable {
    cursor: pointer;
    transition: all 0.2s;
}
.subject-item.clickable:hover {
    border-color: var(--brand-primary);
    background: var(--brand-light);
}

/* Loader */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--slate-200);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Progress Bar */
.progress-track {
    width: 100%;
    height: 8px;
    background: var(--slate-100);
    border-radius: var(--radius-md);
    margin-top: 24px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: var(--brand-primary);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: var(--radius-md);
}

.progress-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Profile Grid & Toolbar */
.results-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-left h2 { margin: 0; }

.toolbar-right { display: flex; gap: 12px; align-items: center; }

.search-box {
    position: relative;
}
.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}
.search-box input {
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 13px;
    outline: none;
}
.search-box input:focus { border-color: var(--brand-primary); }

.modern-select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 13px;
    outline: none;
    background: var(--bg-surface);
}

.student-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

/* Profile Card */
.profile-card {
    background: var(--bg-surface);
    border: none;
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}
.profile-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.profile-info h3 {
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 4px;
    text-transform: none;
    letter-spacing: normal;
}
.profile-info .usn {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 13px;
}

.status-badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.status-badge.fcd { background: #dcfce7; color: #166534; }
.status-badge.fc { background: #e0e7ff; color: #3730a3; }
.status-badge.sc { background: #fef9c3; color: #854d0e; }
.status-badge.fail { background: #fee2e2; color: #991b1b; }

.profile-stats {
    display: flex;
    justify-content: space-between;
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
}

.stat-item {
    text-align: center;
}
.stat-item .label {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 4px;
}
.stat-item .value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--bg-surface);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-tabs {
    display: flex;
    gap: 24px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--slate-50);
}

.modal-tab {
    padding: 16px 0;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}
.modal-tab:hover { color: var(--text-primary); }
.modal-tab.active {
    color: var(--brand-primary);
    border-bottom-color: var(--brand-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

/* Semester Result Tables inside Modal */
.semester-result { margin-bottom: 24px; }

.subject-grid-header {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
    padding: 12px 16px;
    background: var(--slate-50);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border: 1px solid var(--border-color);
    border-bottom: none;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.subject-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-top: none;
    font-size: 13px;
}
.subject-row:last-child {
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.semester-summary {
    display: flex;
    gap: 24px;
    margin-top: 16px;
    padding: 16px;
    background: var(--brand-light);
    border-radius: var(--radius-md);
    color: var(--brand-hover);
    font-weight: 600;
}

/* ================= Responsiveness (Mobile) ================= */
.mobile-only {
    display: none !important;
}
.icon-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    .mobile-only {
        display: inline-flex !important;
    }

    /* Topbar Adjustments */
    .topbar {
        padding: 0 16px;
    }
    
    .topbar-left {
        display: flex;
        align-items: center;
        gap: 12px;
    }
    
    /* Layout Adjustments */
    .content-wrapper {
        padding: 16px;
    }

    /* Grids to Single Column */
    .overview-grid, 
    .two-col-layout,
    .student-grid,
    .history-grid {
        grid-template-columns: 1fr;
    }

    /* Forms */
    .form-row {
        flex-direction: column;
        gap: 16px;
    }
    
    /* Toolbar Stacking */
    .results-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }
    
    .toolbar-left, .toolbar-right {
        flex-direction: column;
        width: 100%;
        align-items: flex-start;
    }
    
    .toolbar-right {
        gap: 12px;
    }
    
    .search-box {
        width: 100%;
    }
    
    .search-box input {
        width: 100%;
    }

    /* Sidebar Slide-in Logic */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
    }

    /* Overlay */
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .overlay.visible {
        opacity: 1;
        visibility: visible;
        display: block !important;
    }
}
