:root {
    --bg-dark: #1a1c23;
    --bg-card: #242731;
    --bg-sidebar: #20222a;
    --primary-color: #4a90e2;
    --text-primary: #ffffff;
    --text-secondary: #a9b1d6;
    --border-color: #3b4261;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    --green: #9ece6a;
    --orange: #ff9e64;
    --red: #f7768e;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    margin: 0;
    font-size: 16px;
}

/* =================================== */
/* ===== MOBILE-FIRST DEFAULT STYLES ===== */
/* =================================== */

.dashboard-layout {
    display: grid;
    grid-template-columns: 1fr;
}

.sidebar {
    background-color: var(--bg-sidebar);
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border-bottom: 1px solid var(--border-color);
}

.main-content {
    padding: 15px;
}

/* Sidebar contents */
.sidebar-header h2 {
    margin: 0;
    text-align: center;
    color: var(--primary-color);
}

.sidebar-section label {
    display: block;
    margin-bottom: 10px;
    color: var(--text-secondary);
    font-weight: 500;
}

.selection-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

select,
#student-id-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    background-color: var(--bg-dark);
    color: var(--text-primary);
}

select:disabled {
    background-color: #2a2d37;
    cursor: not-allowed;
}

.search-container {
    display: flex;
    gap: 10px;
}

#find-btn {
    padding: 0 20px;
    font-size: 16px;
    color: #fff;
    background-color: var(--primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

/* Highlights Cards */
#top-performers-card,
#support-card {
    background-color: var(--bg-dark);
    padding: 15px;
    border-radius: 8px;
}

#top-performers-list,
#support-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.topper-item {
    display: flex;
    align-items: center;
    padding: 10px 5px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.topper-rank {
    font-size: 1.5em;
    font-weight: bold;
    margin-right: 15px;
    color: var(--text-secondary);
}

.topper-details {
    flex-grow: 1;
}

.topper-name {
    font-weight: 600;
}

.topper-percentage,
.support-percentage {
    font-size: 0.9em;
}

.topper-percentage {
    color: var(--green);
}

.support-percentage {
    color: var(--orange);
}

/* Main Content: General */
#welcome-message {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-secondary);
}

.card {
    background-color: var(--bg-card);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Main Content: Student Header */
#student-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}
.header-info-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, auto));
    gap: 25px;
    flex-grow: 1;
}
.header-detail-item {
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-detail-item .icon {
    font-size: 1.8em;
    color: var(--primary-color);
    flex-shrink: 0;
}
.header-detail-item .text-content strong {
    display: block;
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 2px;
}
.header-detail-item .text-content span {
    font-weight: 600;
    font-size: 1.15em;
}
#student-nav-buttons { display: flex; gap: 10px; }
#student-nav-buttons button {
    background: none; border: 1px solid var(--border-color); color: var(--text-secondary);
    width: 40px; height: 40px; border-radius: 8px; cursor: pointer;
    transition: all 0.2s; font-size: 1.2em; line-height: 1;
}
#student-nav-buttons button:hover { background-color: var(--border-color); color: var(--text-primary); }
#student-nav-buttons button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Profile Tab Styling */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}
.profile-card {
    background-color: var(--bg-dark);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.profile-card .info-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 15px;
}
.profile-card .icon { font-size: 1.5em; color: var(--primary-color); }
.profile-card strong { font-weight: 600; color: var(--text-secondary); }
.profile-card .info-body {
    font-size: 1.2em;
    font-weight: 500;
    padding-left: 42px; /* Align with text, not icon */
}
.contact-link {
    display: inline-block;
    text-decoration: none;
    background-color: var(--green);
    color: #fff;
    padding: 8px 15px;
    border-radius: 5px;
    font-weight: 500;
    transition: background-color 0.2s;
}
.contact-link:hover { background-color: #7ab563; }

/* Notes Section Styling */
.notes-section {
    margin-top: 30px;
}
.notes-section h3 {
    margin-top: 0;
    padding-bottom: 10px;
    margin-bottom: 15px;
    font-size: 1.4em;
}
#notes-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.note-item {
    background-color: var(--bg-dark);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    gap: 15px;
    border: 1px solid var(--border-color);
    border-left-width: 5px; /* Add colored left border */
}
.note-achievement { border-left-color: var(--green); }
.note-complaint { border-left-color: var(--orange); }

.note-icon {
    font-size: 1.5em;
    margin-top: 2px;
}
.note-achievement .note-icon { color: var(--green); }
.note-complaint .note-icon { color: var(--orange); }
.note-content { flex-grow: 1; }
.note-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.note-type {
    font-weight: 600;
    font-size: 1.1em;
}
.note-date {
    font-size: 0.85em;
    color: var(--text-secondary);
}
.note-text {
    font-size: 0.95em;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.tab-link {
    padding: 10px 15px;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text-secondary);
    border-bottom: 3px solid transparent;
}

.tab-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.filter-pills {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.filter-pills button {
    background-color: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
}

.filter-pills button.active {
    background-color: var(--primary-color);
    color: #fff;
}

#test-reports-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.marks-table {
    width: 100%;
    border-collapse: collapse;
}

.marks-table th,
.marks-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.marks-table th {
    background-color: var(--bg-card);
}

/* --- Analytics & Charts Mobile --- */
#class-analytics-title {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.5em;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background-color: var(--bg-dark);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.stat-card strong {
    display: block;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-card span {
    font-size: 2em;
    font-weight: 700;
    color: var(--text-primary);
}

.charts-grid,
.analytics-charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.chart-container {
    padding: 20px;
    position: relative;
    min-width: 0;
    /* THE FIX: Remove fixed height and use aspect-ratio */
    aspect-ratio: 1 / 1;
    /* Default to a square aspect ratio for mobile charts */
    height: auto;
}

.chart-container h3 {
    text-align: center;
    margin: 0 0 15px 0;
    font-weight: 500;
}

.doughnut-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    height: 100%;
}

#performance-distribution-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
}

.legend-item {
    display: flex;
    align-items: center;
}

.legend-color-box {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    margin-right: 10px;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
}

.canvas-wrapper>canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

.doughnut-wrapper .canvas-wrapper {
    max-height: 200px;
    width: auto;
    aspect-ratio: 1/1;
}

/* =================================== */
/* ===== TABLET & SMALL DESKTOP ===== */
/* =================================== */
@media (min-width: 768px) {
    .main-content {
        padding: 20px;
    }

    .selection-grid {
        grid-template-columns: 1fr 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .profile-grid,
    #test-reports-container {
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    }

    .header-info-container {
        flex-direction: row;
    }

    .charts-grid {
        grid-template-columns: 1fr 1fr;
    }

    .analytics-charts-grid {
        grid-template-columns: 2fr 1fr;
    }

    .chart-container {
        aspect-ratio: auto;
        height: 400px;
    }

    /* Revert to fixed height on larger screens */
    .doughnut-wrapper {
        flex-direction: row;
    }

    .doughnut-wrapper .canvas-wrapper {
        max-height: 100%;
        max-width: 65%;
    }
}

/* =================================== */
/* ===== LARGE DESKTOP ===== */
/* =================================== */
@media (min-width: 1200px) {
    .dashboard-layout {
        grid-template-columns: 320px 1fr;
        height: 100vh;
    }

    .sidebar {
        border-right: 1px solid var(--border-color);
        border-bottom: none;
        overflow-y: auto;
        padding: 20px;
    }

    .main-content {
        overflow-y: auto;
        padding: 30px;
    }
}
/* style.css */

/* =================================== */
/* ===== CUSTOM CHART LEGEND STYLING ===== */
/* =================================== */
.chart-legend {
    display: flex;
    flex-wrap: wrap; /* Yeh mobile ke liye bahut zaroori hai */
    justify-content: center;
    gap: 15px 25px; /* row-gap column-gap */
    margin-top: 20px;
    padding: 0 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-color-box {
    width: 15px;
    height: 15px;
    border-radius: 4px;
    flex-shrink: 0; /* Box ko shrink hone se roke */
}

.legend-text .legend-label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1em;
    margin-bottom: 2px;
}

.legend-text .legend-value {
    display: block;
    color: var(--text-secondary);
    font-size: 0.85em;
}