/* ============================================================
   SSN — School Management System
   Responsive + Dark Mode CSS
   ============================================================ */

/* --- CSS Variables (Light Mode) --- */
:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #64748b;
    --accent: #f59e0b;
    --bg-main: #f0f2f5;
    --bg-sidebar: #1e293b;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-white: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 16px;
    --shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --shadow-sm: 0 4px 6px rgba(0,0,0,0.05);
    --input-bg: #ffffff;
    --table-head-bg: #f8fafc;
    --nav-label-color: #64748b;
    --top-bar-bg: transparent;
}

/* --- Dark Mode Variables --- */
body.dark-mode {
    --bg-main: #0f172a;
    --bg-sidebar: #020617;
    --bg-card: rgba(30, 41, 59, 0.95);
    --bg-white: #1e293b;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -2px rgba(0,0,0,0.2);
    --shadow-sm: 0 4px 6px rgba(0,0,0,0.2);
    --input-bg: #0f172a;
    --table-head-bg: #0f172a;
    --nav-label-color: #475569;
    --top-bar-bg: rgba(15, 23, 42, 0.6);
}

/* --- Base Reset --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Hind Siliguri', 'Outfit', sans-serif;
    color: var(--text-main);
    background: var(--bg-main);
    transition: background 0.3s ease, color 0.3s ease;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #4f46e5 0%, #312e81 100%);
}

body.dark-mode .login-page {
    background: linear-gradient(135deg, #1e1b4b 0%, #020617 100%);
}

.login-container {
    width: 100%;
    max-width: 450px;
    padding: 20px;
}

.glass {
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.18);
}

body.dark-mode .glass {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(255,255,255,0.08);
}

.login-card {
    padding: 3rem;
    border-radius: 24px;
    box-shadow: 0 8px 32px 0 rgba(0,0,0,0.3);
    text-align: center;
}

.login-logo { width: 80px; margin-bottom: 1.5rem; }

.login-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--bg-sidebar);
}
body.dark-mode .login-header h2 { color: #e2e8f0; }

.login-header p { color: var(--text-muted); margin-bottom: 2rem; }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { margin-bottom: 1.5rem; text-align: left; }
label { display: block; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-main); }

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.2s;
    background: var(--input-bg);
    color: var(--text-main);
    min-height: 44px;
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79,70,229,0.1);
    outline: none;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #4338ca; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,70,229,0.3); }
.btn-block { width: 100%; }

.alert { padding: 1rem; border-radius: 12px; margin-bottom: 1.5rem; font-size: 0.875rem; }
.alert-danger { background: #fee2e2; color: #dc2626; border: 1px solid #fecaca; }
body.dark-mode .alert-danger { background: rgba(220,38,38,0.2); border-color: rgba(220,38,38,0.4); }

/* ============================================================
   MAIN LAYOUT — SIDEBAR + CONTENT
   ============================================================ */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    color: white;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    top: 0;
    left: 0;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 3rem;
}
.sidebar-logo { width: 40px; flex-shrink: 0; }
.sidebar-header h3 { font-size: 1.1rem; font-weight: 700; line-height: 1.3; }

/* --- Nav Items --- */
.side-nav { flex: 1; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 12px;
    margin-bottom: 0.25rem;
    transition: all 0.2s;
    font-size: 0.95rem;
}
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,0.1); color: white; }
.nav-item.active { background: var(--primary); }

.nav-section-label {
    margin: 1.5rem 0 0.5rem 1rem;
    font-size: 0.7rem;
    color: var(--nav-label-color);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.sidebar-footer { margin-top: auto; padding-top: 1rem; }

/* --- Content Area --- */
.content-area {
    flex: 1;
    margin-left: 280px;
    padding: 2.5rem;
    min-width: 0;
    transition: margin-left 0.3s ease;
}

/* --- Top Bar --- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    gap: 1rem;
    background: var(--top-bar-bg);
}
.top-bar h2 { font-weight: 700; color: var(--text-main); font-size: clamp(1.1rem, 3vw, 1.5rem); }

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-white);
    padding: 0.5rem 1rem;
    border-radius: 30px;
    box-shadow: var(--shadow);
    flex-shrink: 0;
    border: 1px solid var(--border);
}

/* --- Dark Mode Toggle Button --- */
.dark-mode-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: var(--bg-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}
.dark-mode-toggle:hover { transform: scale(1.1); border-color: var(--primary); }

/* --- Hamburger Menu Button (mobile only) --- */
.mobile-menu-btn {
    display: none;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: var(--bg-white);
    cursor: pointer;
    font-size: 1.25rem;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    transition: all 0.2s;
    flex-shrink: 0;
}

/* --- Sidebar Overlay (mobile) --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ============================================================
   DASHBOARD — STAT CARDS
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-white);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-bottom: 4px solid var(--primary);
    border: 1px solid var(--border);
    border-bottom: 4px solid var(--primary);
}
.stat-title { font-size: 0.875rem; color: var(--text-muted); font-weight: 600; }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--text-main); }

/* ============================================================
   DASHBOARD MAIN GRID
   ============================================================ */
.dashboard-main-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
}

.dashboard-left { display: flex; flex-direction: column; gap: 2rem; }
.dashboard-right { display: flex; flex-direction: column; gap: 2rem; }

/* ============================================================
   REPORT PAGE GRIDS
   ============================================================ */
.report-filter-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    align-items: flex-end;
}

.report-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    margin-bottom: 2rem;
}

/* ============================================================
   STUDENTS PAGE GRID
   ============================================================ */
.students-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 2rem;
}

/* ============================================================
   CARDS & TABLES
   ============================================================ */
.card {
    background: var(--bg-white);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

/* Scrollable table wrapper */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Generic table dark mode */
body.dark-mode table thead tr {
    background: var(--table-head-bg) !important;
    color: var(--text-muted) !important;
}
body.dark-mode table td,
body.dark-mode table th {
    color: var(--text-main);
    border-color: var(--border) !important;
}
body.dark-mode .card,
body.dark-mode [style*="background: white"],
body.dark-mode [style*="background:white"] {
    background: var(--bg-white) !important;
    color: var(--text-main);
    border-color: var(--border);
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    .sidebar, .top-bar, .no-print, .dark-mode-toggle, .mobile-menu-btn { display: none !important; }
    .content-area { margin-left: 0 !important; padding: 0; }
}

/* ============================================================
   RESPONSIVE — TABLET (≤ 1024px)
   ============================================================ */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-main-grid { grid-template-columns: 1fr; }
    .report-filter-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   RESPONSIVE — MOBILE (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {

    /* Sidebar: hidden off-screen, toggle via JS */
    .sidebar {
        transform: translateX(-100%);
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }
    body.sidebar-open .sidebar-overlay {
        display: block;
    }

    /* Content fills full width */
    .content-area {
        margin-left: 0;
        padding: 1.25rem;
    }

    /* Show hamburger */
    .mobile-menu-btn { display: flex; }

    /* Top bar adjustments */
    .top-bar { margin-bottom: 1.5rem; }
    .username-text { display: none; }

    /* Stats — 2 columns on tablet/mobile */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
    .stat-value { font-size: 1.4rem; }

    /* Report grids */
    .report-filter-grid { grid-template-columns: 1fr 1fr; gap: 1rem; }
    .report-stats-grid { grid-template-columns: 1fr; gap: 1rem; }

    /* Students: stack vertically */
    .students-grid { grid-template-columns: 1fr; }

    /* Login card */
    .login-card { padding: 2rem 1.5rem; }

    /* Tighter card paddings */
    .card { border-radius: 12px; }
}

/* ============================================================
   RESPONSIVE — SMALL MOBILE (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {

    .content-area { padding: 1rem; }

    /* Stats — single column */
    .stats-grid { grid-template-columns: 1fr; }

    /* Report filter — single column */
    .report-filter-grid { grid-template-columns: 1fr; }

    .login-card { padding: 1.5rem 1rem; }
    .login-header h2 { font-size: 1.4rem; }

    /* Sidebar narrower on very small phones */
    .sidebar { width: 260px; }

    /* Buttons — full touch targets */
    .btn { padding: 0.75rem 1rem; font-size: 0.95rem; }
}

/* ============================================================
   DARK MODE — GLOBAL OVERRIDES
   Catches any remaining inline "background: white" on .card divs
   ============================================================ */
body.dark-mode .card,
body.dark-mode .glass-card {
    background: var(--bg-white) !important;
    color: var(--text-main) !important;
    border-color: var(--border) !important;
}

body.dark-mode .form-control,
body.dark-mode select.form-control,
body.dark-mode textarea.form-control {
    background: var(--input-bg) !important;
    color: var(--text-main) !important;
    border-color: var(--border) !important;
}

body.dark-mode label {
    color: var(--text-main);
}

body.dark-mode h1, body.dark-mode h2,
body.dark-mode h3, body.dark-mode h4 {
    color: var(--text-main);
}

/* Catch inline "background: white" on any div/section inside content-area */
body.dark-mode .content-area [style*="background: white"]:not(.receipt-paper):not(.receipt-paper *),
body.dark-mode .content-area [style*="background:white"]:not(.receipt-paper):not(.receipt-paper *) {
    background: var(--bg-white) !important;
    color: var(--text-main) !important;
}

/* ============================================================
   RECEIPT PAPER — Always light (paper look), never dark mode
   ============================================================ */
body.dark-mode .receipt-paper,
body.dark-mode .receipt-paper *,
body.dark-mode .receipt-container {
    background: white !important;
    color: #000 !important;
    border-color: #000 !important;
}

/* Table cells */
body.dark-mode td, body.dark-mode th {
    color: var(--text-main);
    border-color: var(--border) !important;
}
body.dark-mode thead tr {
    background: var(--table-head-bg) !important;
}
body.dark-mode tbody tr:hover {
    background: rgba(255,255,255,0.04);
}

/* Quick actions gradient card — keep it, just adjust text */
body.dark-mode .user-profile {
    background: var(--bg-white);
    border-color: var(--border);
}

/* Auth page inputs in dark mode */
body.dark-mode .login-card {
    background: rgba(30, 41, 59, 0.95) !important;
}
body.dark-mode .login-header h2 { color: #e2e8f0; }

/* Section labels (nav) */
body.dark-mode .nav-section-label { color: #475569; }

/* Alert dark mode */
body.dark-mode .alert-danger {
    background: rgba(220,38,38,0.2);
    border-color: rgba(220,38,38,0.4);
    color: #fca5a5;
}

