@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    /* Default (Light) Theme */
    --primary: #4F46E5;
    --primary-dark: #4338ca;
    --secondary: #06B6D4;
    --accent: #F43F5E;
    --background: #f3f4f6;
    --surface: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.85);
    --text-main: #111827;
    --text-muted: #6B7280;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 16px;
    --radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --bg-gradient-start: #e0e7ff;
    --bg-gradient-end: #f3f4f6;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-dark: #6366f1;
    --secondary: #22d3ee;
    --accent: #fb7185;
    --background: #0f172a;
    /* Slate 900 */
    --surface: #1e293b;
    /* Slate 800 */
    --surface-glass: rgba(30, 41, 59, 0.9);
    --text-main: #f1f5f9;
    /* Slate 100 */
    --text-muted: #94a3b8;
    /* Slate 400 */
    --border: #334155;
    /* Slate 700 */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);

    --bg-gradient-start: #0f172a;
    --bg-gradient-end: #1e293b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--surface-glass);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 10;
    transition: transform 0.3s ease;
}

.sidebar.collapsed {
    transform: translateX(-280px);
}

/* Floating button ONLY visible when sidebar is collapsed */
.sidebar-floating-toggle {
    position: fixed;
    left: 1rem;
    top: 1rem;
    z-index: 100;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    display: none;
    /* Hidden by default */
}

.sidebar.collapsed+.sidebar-floating-toggle {
    display: flex;
    /* Show when sidebar collapsed */
    animation: fadeIn 0.3s ease;
}


/* Sidebar Toggle Button (Integrated) */
.sidebar-toggle {
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    background: #f3f4f6;
    color: var(--primary);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Adjusted for mobile layout potentially */
    gap: 0.5rem;
}

#mobile-menu-toggle {
    display: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-main);
}

.logo span {
    color: var(--text-main);
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    padding-right: 0.5rem;
}

.nav-links::-webkit-scrollbar {
    width: 6px;
}

.nav-links::-webkit-scrollbar-track {
    background: transparent;
}

.nav-links::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.nav-links::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

.nav-item {
    padding: 0.875rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-item:hover {
    background: #eff6ff;
    color: var(--primary);
}

.nav-item.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-md);
}

.nav-item svg {
    width: 20px;
    height: 20px;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 280px;
    padding: 2rem;
    max-width: 1600px;
    transition: margin-left 0.3s ease;
    min-width: 0;
}

.sidebar.collapsed~.main-content {
    margin-left: 0;
}

/* Header */
header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-title h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

.page-title p {
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin: 0.5rem 0;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
    background: var(--surface);
    color: var(--text-main);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    background: var(--surface);
}

.form-input:disabled,
.form-select:disabled,
.form-input:read-only {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--background);
}



.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: rgba(150, 150, 150, 0.1);
    border-color: var(--text-muted);
}

/* Tables */
.table-container {
    overflow-x: auto;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1rem 1.5rem;
    background: #f9fafb;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    color: var(--text-main);
}

tr:hover td {
    background: #f8fafc;
}

/* Views */
.view {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Helpers */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.justify-between {
    justify-content: space-between;
}

.items-center {
    align-items: center;
}

.gap-4 {
    gap: 1rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.text-right {
    text-align: right;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-warning {
    background: #fef9c3;
    color: #854d0e;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    transform: scale(0.95);
    transition: var(--transition);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-overlay.open .modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

/* Report Card Specifics */
.raport-print {
    background: white;
    padding: 2rem;
    margin: 2rem auto;
    max-width: 210mm;
    /* A4 width */
    border: 1px solid var(--border);
    display: none;
}


@media print {
    @page {
        size: A4;
        margin: 1.27cm;
    }

    .sidebar,
    .no-print,
    #report-preview .card,
    button {
        display: none !important;
    }

    .main-content {
        margin: 0;
        padding: 0;
        width: 100%;
    }

    #print-area {
        display: block !important;
        border: none;
        margin: 0;
        padding: 0;
        font-family: 'Times New Roman', serif;
        font-size: 12pt;
    }

    body {
        background: white;
        margin: 0;
        padding: 0;
    }

    .app-container {
        display: block;
    }

    #report-content-preview {
        display: none;
    }
}


/* Responsive Design */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    /* Sidebar Mobile */
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        padding: 1rem;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar .logo {
        margin-bottom: 1rem;
        justify-content: space-between;
    }

    /* Mobile Nav Toggle */
    #mobile-menu-toggle {
        display: block;
    }

    /* Hide desktop sidebar toggle on mobile */
    .sidebar-toggle {
        display: none;
    }

    .nav-links {
        display: none;
        /* Hidden by default on mobile */
        margin-top: 1rem;
        width: 100%;
    }

    .nav-links.active {
        display: flex;
    }

    .logo::after {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: 1.5rem;
        width: 100%;
    }

    /* Cards & Grids */
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .card .flex {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .card .flex button,
    .card .flex .btn {
        width: 100%;
    }

    .table-container {
        overflow-x: auto;
    }

    table {
        min-width: 100%;
        /* Changed from 600px to 100% for mobile adaptability */
        width: 100%;
    }

    /* Extras Table Responsive Fix - Stack inputs like cards on mobile */
    #extras-table,
    #extras-table tbody {
        display: block;
        width: 100%;
        min-width: 0;
        /* Override any min-width */
        border-collapse: separate;
        border-spacing: 0;
    }

    #extras-table thead {
        display: none;
        /* Hide table headers on mobile */
    }

    #extras-table tr {
        display: flex;
        flex-direction: column;
        background: #fff;
        /* Plain white background */
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 1rem;
        margin-bottom: 1rem;
        gap: 0.75rem;
        /* Increased gap for better touch targets */
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        width: 100%;
        /* Ensure row takes full container width */
        box-sizing: border-box;
        /* Include padding in width */
    }

    #extras-table td {
        display: block;
        width: 100% !important;
        /* Force full width */
        min-width: 0;
        /* Allow shrinking */
        padding: 0;
        border: none;
        box-sizing: border-box;
    }

    /* Add labels via pseudo-elements mostly for clarity if placeholders aren't enough, 
       but placeholders are present so we focus on layout */

    #extras-table input.form-input {
        width: 100% !important;
        /* Force 100% width */
        min-width: 0;
        /* Allow shrinking to fit container */
        box-sizing: border-box;
        /* Ensure padding doesn't affect width */
        margin: 0;
        max-width: 100%;
        /* Prevent overflowing parent */
    }

    /* Delete Button Area */
    #extras-table td:last-child {
        margin-top: 0.5rem;
        padding-top: 0.75rem;
        border-top: 1px dashed var(--border);
        text-align: right;
    }

    #extras-table td:last-child button {
        width: auto !important;
        /* Override global full-width button rule */
        padding: 0.4rem 1rem;
        font-size: 0.85rem;
        background-color: #fee2e2;
        color: #dc2626;
        border: 1px solid #fecaca;
    }

    #extras-table td:last-child button:hover {
        background-color: #fecaca;
    }

    /* Input Groups */
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    .flex.gap-4 {
        flex-direction: column;
    }

    .modal {
        width: 95%;
        margin: 1rem;
    }
}

/* Footer */
.app-footer {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    text-align: center;
    padding: 1.5rem 2rem;
    margin-top: auto;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.app-footer p {
    margin: 0;
    font-size: 0.9rem;
    opacity: 0.95;
}

.app-footer strong {
    font-weight: 600;
}

@media print {
    .app-footer {
        display: none;
    }

}

/* Grid Layout & Cards */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    padding-bottom: 2rem;
}

.data-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.data-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.card-title-group {
    flex: 1;
    margin-left: 1rem;
}

.card-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.card-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.card-body {
    margin-bottom: 1.5rem;
    flex: 1;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    border-bottom: 1px dashed var(--border);
    padding-bottom: 0.25rem;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-muted);
}

.info-value {
    font-weight: 500;
    color: var(--text);
}

.card-actions {
    display: flex;
    gap: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
    background: var(--surface);
}

/* Badge Styles */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-blue {
    background: #dbeafe;
    color: #1e40af;
}

.badge-green {
    background: #d1fae5;
    color: #065f46;
}

.badge-purple {
    background: #ede9fe;
    color: #5b21b6;
}

.badge-gray {
    background: #f3f4f6;
    color: #4b5563;
}

/* Pagination Controls */
.pagination-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Dashboard Clock */
.dashboard-clock {
    background: var(--surface);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
    transition: var(--transition);
}

.dashboard-clock:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.clock-time {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.clock-date {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

@media (max-width: 640px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .dashboard-clock {
        width: 100%;
        align-items: center;
        text-align: center;
        flex-direction: row;
        justify-content: space-between;
    }
}

/* Student Stats Row */
.stats-container-row {
    background: var(--surface);
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    gap: 2rem;
    align-items: center;
    border: 1px solid var(--border);
    flex-wrap: wrap;
}