/* SchoolGuard Pro - Responsive Design System */
:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: rgba(255,255,255,0.04);
    --bg-card-hover: rgba(255,255,255,0.07);
    --bg-sidebar: #0c1222;
    --border: rgba(255,255,255,0.08);
    --border-active: rgba(59,130,246,0.4);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-glow: rgba(59,130,246,0.15);
    --success: #10b981;
    --success-bg: rgba(16,185,129,0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245,158,11,0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239,68,68,0.1);
    --info: #06b6d4;
    --radius: 0.75rem;
    --radius-lg: 1rem;
    --shadow: 0 4px 24px rgba(0,0,0,0.2);
    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --sidebar-width: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg-primary); color: var(--text-primary); min-height: 100dvh; overflow-x: hidden; -webkit-font-smoothing: antialiased; }

/* ===== LAYOUT ===== */
.app-container { display: flex; flex-direction: column; min-height: 100dvh; }

/* Header */
.app-header { position: sticky; top: 0; z-index: 100; background: rgba(15,23,42,0.85); backdrop-filter: blur(20px) saturate(180%); border-bottom: 1px solid var(--border); padding: calc(var(--safe-top) + 0.75rem) 1rem 0.75rem; }
.header-inner { display: flex; align-items: center; justify-content: space-between; max-width: 1400px; margin: 0 auto; }
.header-brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 800; font-size: 1.1rem; color: var(--text-primary); }
.header-brand .icon { font-size: 1.4rem; }
.header-right { display: flex; align-items: center; gap: 0.75rem; }
.header-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; cursor: pointer; }
.header-role { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* Desktop sidebar - hidden on mobile */
.app-sidebar { display: none; }

/* Main content */
.app-main { flex: 1; padding: 1rem; padding-bottom: calc(5rem + var(--safe-bottom)); max-width: 1000px; margin: 0 auto; width: 100%; }

/* Bottom nav - mobile only */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; background: rgba(15,23,42,0.92); backdrop-filter: blur(20px); border-top: 1px solid var(--border); padding: 0.5rem 0 calc(0.5rem + var(--safe-bottom)); display: flex; justify-content: space-around; }
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; padding: 0.4rem 0.75rem; border-radius: var(--radius); cursor: pointer; transition: all 0.2s; color: var(--text-muted); text-decoration: none; font-size: 0.65rem; font-weight: 600; min-width: 60px; }
.nav-item i { font-size: 1.15rem; }
.nav-item.active { color: var(--accent); }
.nav-item.active i { filter: drop-shadow(0 0 6px var(--accent)); }

/* Sidebar nav items */
.sidebar-nav-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 1rem; border-radius: var(--radius); cursor: pointer; transition: all 0.15s; color: var(--text-muted); text-decoration: none; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.2rem; }
.sidebar-nav-item:hover { background: var(--bg-card-hover); color: var(--text-secondary); }
.sidebar-nav-item.active { background: var(--accent-glow); color: var(--accent); }
.sidebar-nav-item i { width: 20px; text-align: center; font-size: 0.95rem; }
.sidebar-section { padding: 0.5rem 1rem; font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-top: 0.75rem; }

/* ===== CARDS ===== */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem; margin-bottom: 1rem; transition: all 0.2s; }
.card:hover { background: var(--bg-card-hover); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.card-subtitle { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.15rem; }

/* ===== STATS GRID ===== */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin-bottom: 1.25rem; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; }
.stat-value { font-size: 1.75rem; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.35rem; font-weight: 600; }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.info .stat-value { color: var(--info); }
.stat-card.accent .stat-value { color: var(--accent); }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.7rem 1.25rem; border: none; border-radius: var(--radius); font-family: var(--font); font-weight: 600; font-size: 0.85rem; cursor: pointer; transition: all 0.2s; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #2563eb; box-shadow: 0 4px 15px var(--accent-glow); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #000; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 0.45rem 0.75rem; font-size: 0.75rem; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.3px; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 0.75rem 1rem; background: rgba(255,255,255,0.05); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-primary); font-family: var(--font); font-size: 0.95rem; transition: all 0.2s; }
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 1rem center; padding-right: 2.5rem; }
.form-select option { background: var(--bg-secondary); color: var(--text-primary); }
.form-textarea { min-height: 80px; resize: vertical; }
.form-row { display: flex; gap: 0.75rem; }
.form-row .form-group { flex: 1; }

/* ===== STUDENT LIST ===== */
.student-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 0.5rem; transition: all 0.2s; cursor: pointer; }
.student-item:hover { background: var(--bg-card-hover); }
.student-avatar { width: 42px; height: 42px; border-radius: 50%; background: linear-gradient(135deg, #3b82f6, #8b5cf6); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0; overflow: hidden; }
.student-avatar img { width: 100%; height: 100%; object-fit: cover; }
.student-info { flex: 1; min-width: 0; }
.student-name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.student-meta { font-size: 0.75rem; color: var(--text-muted); }
.student-status { flex-shrink: 0; }
.student-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

/* ===== BADGES ===== */
.badge { display: inline-flex; align-items: center; padding: 0.2rem 0.6rem; border-radius: 99px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: rgba(6,182,212,0.1); color: var(--info); }
.badge-bus { background: rgba(139,92,246,0.1); color: #8b5cf6; }
.badge-van { background: rgba(236,72,153,0.1); color: #ec4899; }
.badge-self { background: rgba(107,114,128,0.1); color: #9ca3af; }

/* ===== TOGGLE / CHECKBOX ===== */
.check-toggle { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.check-toggle input { display: none; }
.check-box { width: 24px; height: 24px; border-radius: 6px; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; transition: all 0.2s; flex-shrink: 0; }
.check-toggle input:checked + .check-box { background: var(--success); border-color: var(--success); }
.check-toggle input:checked + .check-box::after { content: '✓'; color: #fff; font-size: 0.8rem; font-weight: 700; }

/* ===== TABS ===== */
.tabs { display: flex; gap: 0.25rem; background: rgba(255,255,255,0.03); padding: 0.25rem; border-radius: var(--radius); margin-bottom: 1rem; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab { flex: 1; padding: 0.6rem 0.75rem; text-align: center; border-radius: calc(var(--radius) - 2px); font-size: 0.8rem; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: all 0.2s; white-space: nowrap; min-width: fit-content; }
.tab.active { background: var(--accent); color: #fff; }

/* ===== SEARCH BAR ===== */
.search-bar { position: relative; margin-bottom: 1rem; }
.search-bar input { width: 100%; padding: 0.75rem 1rem 0.75rem 2.75rem; background: rgba(255,255,255,0.05); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-primary); font-family: var(--font); font-size: 0.9rem; }
.search-bar i { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

/* ===== MODAL ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); z-index: 200; display: none; align-items: flex-end; justify-content: center; }
.modal-overlay.active { display: flex; }
.modal { background: var(--bg-secondary); border-radius: 1.25rem 1.25rem 0 0; width: 100%; max-width: 540px; max-height: 85dvh; overflow-y: auto; padding: 1.5rem; animation: slideUp 0.3s ease; }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; display: flex; align-items: center; justify-content: space-between; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-card); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted); }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ===== TOAST ===== */
.toast-container { position: fixed; top: calc(var(--safe-top) + 1rem); right: 1rem; z-index: 300; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { padding: 0.85rem 1.25rem; border-radius: var(--radius); font-size: 0.85rem; font-weight: 500; animation: toastIn 0.3s ease; max-width: 360px; }
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== OTP ===== */
.otp-input-group { display: flex; gap: 0.5rem; justify-content: center; margin: 1rem 0; }
.otp-digit { width: 48px; height: 56px; text-align: center; font-size: 1.5rem; font-weight: 700; background: rgba(255,255,255,0.05); border: 2px solid var(--border); border-radius: var(--radius); color: var(--text-primary); font-family: var(--font); }
.otp-digit:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-glow); }

/* ===== PAGE SECTIONS ===== */
.page-section { display: none; }
.page-section.active { display: block; }
.page-title { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.5px; margin-bottom: 0.25rem; }
.page-desc { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 1.25rem; }

/* ===== LOADING ===== */
.loading { display: flex; align-items: center; justify-content: center; padding: 3rem; color: var(--text-muted); }
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin-right: 0.75rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TABLE ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th { text-align: left; padding: 0.6rem; color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 0.6rem; border-bottom: 1px solid rgba(255,255,255,0.03); }
.data-table tr:hover { background: var(--bg-card-hover); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: 0.3; }
.empty-state p { font-size: 0.9rem; }

/* ===== QR SCANNER ===== */
.scanner-frame { width: 100%; max-width: 320px; aspect-ratio: 1; margin: 0 auto; border-radius: var(--radius-lg); overflow: hidden; position: relative; background: #000; }
.scanner-frame video { width: 100%; height: 100%; object-fit: cover; }
.scanner-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.scanner-target { width: 200px; height: 200px; border: 2px solid var(--accent); border-radius: 1rem; box-shadow: 0 0 0 9999px rgba(0,0,0,0.5); }

/* ===== MISC ===== */
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--success); display: inline-block; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16,185,129,0.7); } 70% { box-shadow: 0 0 0 8px rgba(16,185,129,0); } 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); } }

.upload-area { border: 2px dashed var(--border); border-radius: var(--radius-lg); padding: 2rem; text-align: center; cursor: pointer; transition: all 0.2s; }
.upload-area:hover { border-color: var(--accent); background: var(--accent-glow); }
.upload-area input[type="file"] { display: none; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== RESPONSIVE — TABLET ===== */
@media (min-width: 768px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
    .app-main { padding: 1.5rem; }
    .modal { border-radius: var(--radius-lg); max-height: 80vh; margin-bottom: 2rem; }
    .modal-overlay { align-items: center; }
}

/* ===== RESPONSIVE — DESKTOP ===== */
@media (min-width: 1024px) {
    .bottom-nav { display: none; }
    .app-container { flex-direction: row; flex-wrap: wrap; }
    .app-header { width: 100%; flex-shrink: 0; }

    .app-sidebar {
        display: flex;
        flex-direction: column;
        width: var(--sidebar-width);
        background: var(--bg-sidebar);
        border-right: 1px solid var(--border);
        height: calc(100dvh - 57px);
        position: sticky;
        top: 57px;
        overflow-y: auto;
        padding: 1rem 0.75rem;
        flex-shrink: 0;
    }

    .app-body-wrap {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
    }

    .app-main {
        flex: 1;
        padding: 2rem 2.5rem;
        padding-bottom: 2rem;
        max-width: 1000px;
        margin: 0;
    }

    .sidebar-brand { display: none; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
    .student-item { padding: 0.85rem 1rem; }
}

@media (min-width: 1280px) {
    .app-main { max-width: 1100px; }
}
