/* ──────────────────────────────────────────────────────
   School Management System — base styles
─────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Anuphan:wght@300;400;500;600;700&family=Inter:wght@400;500;600;700;800&display=swap');

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Inter', 'Anuphan', 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: #0F172A;
    line-height: 1.65;
    background: #F8FAFC;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'kern' 1, 'liga' 1;
    text-rendering: optimizeLegibility;
}

/* Make Latin digits + alphabet use Inter for that crisp modern look,
   while Thai keeps IBM Plex Sans Thai (set above). The browser picks
   the first font in the stack that covers each character. */
h1, h2, h3, h4 { letter-spacing: -0.015em; font-weight: 700; }
h1 { letter-spacing: -0.02em; }
strong, b { font-weight: 600; }

a { color: #7c3aed; text-decoration: none; }
a:hover { text-decoration: underline; }

code { background: #F1F5F9; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }

/* ── Admin shell ───────────────────────────── */
.admin-body { background: #F1F5F9; }
.admin-shell { display: flex; min-height: 100vh; }

.admin-sidebar {
    width: 240px;
    background: #0F172A;
    color: #CBD5E1;
    display: flex;
    flex-direction: column;
    position: sticky; top: 0;
    height: 100vh;
    overflow-y: auto;
}
.admin-brand { padding: 20px 18px; border-bottom: 1px solid #1E293B; display: flex; align-items: center; gap: 12px; }
.admin-brand .logo { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, #7c3aed, #6d28d9); display: flex; align-items: center; justify-content: center; font-size: 22px; }
.admin-brand .brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.admin-brand .brand-text strong { color: white; font-size: 0.95rem; }
.admin-brand .brand-text span { color: #64748B; font-size: 0.75rem; }

.admin-nav { flex: 1; padding: 12px 0; }
.admin-nav a {
    display: block;
    padding: 9px 18px;
    color: #94A3B8;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.admin-nav a:hover { background: #1E293B; color: white; text-decoration: none; }
.admin-nav a.active { background: #1E293B; color: white; border-left-color: #7c3aed; }
.admin-nav .nav-group {
    padding: 12px 18px 4px;
    font-size: 0.7rem;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.admin-user { padding: 14px 18px; border-top: 1px solid #1E293B; }
.admin-user .user-info strong { display: block; color: white; font-size: 0.85rem; }
.admin-user .user-info span { display: block; color: #64748B; font-size: 0.75rem; margin-top: 2px; }
.admin-user .logout { display: inline-block; margin-top: 10px; font-size: 0.8rem; color: #94A3B8; }
.admin-user .logout:hover { color: #EF4444; }

.admin-main { flex: 1; min-width: 0; }
.admin-topbar { background: white; border-bottom: 1px solid #E2E8F0; padding: 16px 28px; display: flex; align-items: center; justify-content: space-between; }
.admin-topbar h1 { margin: 0; font-size: 1.25rem; color: #0F172A; }
.admin-topbar .topbar-meta { display: flex; gap: 8px; }

.badge { display: inline-block; padding: 4px 12px; background: #FAF5FF; color: #5b21b6; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.badge-soft { background: #F1F5F9; color: #475569; }

.admin-body-inner { padding: 28px; }

/* ── Stats grid ───────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card { background: white; padding: 22px 24px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); position: relative; overflow: hidden; }
.stat-card .stat-icon { font-size: 28px; margin-bottom: 8px; }
.stat-card .stat-num { font-size: 1.9rem; font-weight: 800; color: #0F172A; line-height: 1.1; letter-spacing: -0.5px; }
.stat-card .stat-label { color: #64748B; font-size: 0.85rem; margin-top: 4px; }

/* ── Getting started ───────────────────────── */
.getting-started { background: white; padding: 24px 28px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.getting-started h2 { margin: 0 0 16px; font-size: 1.1rem; color: #0F172A; }
.getting-started ol { padding-left: 22px; margin: 0; }
.getting-started li { padding: 8px 0; font-size: 0.95rem; color: #334155; border-bottom: 1px solid #F1F5F9; }
.getting-started li:last-child { border-bottom: none; }

/* ── Generic UI ───────────────────────────── */
.btn { display: inline-block; padding: 9px 18px; border-radius: 8px; font-weight: 600; font-size: 0.9rem; cursor: pointer; border: none; transition: all 0.15s; font-family: inherit; }
.btn-primary { background: #7c3aed; color: white; }
.btn-primary:hover { background: #6d28d9; color: white; text-decoration: none; }
.btn-ghost { background: #F1F5F9; color: #475569; }
.btn-danger { background: #FEE2E2; color: #991B1B; }

table.data-table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
table.data-table th, table.data-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid #F1F5F9; font-size: 0.9rem; }
table.data-table th { background: #F8FAFC; font-weight: 700; color: #475569; font-size: 0.8rem; letter-spacing: 0.02em; text-transform: uppercase; }
table.data-table tr:hover { background: #FAFBFC; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-success { background: #D1FAE5; color: #065F46; }
.alert-error { background: #FEE2E2; color: #991B1B; }
.alert-info { background: #DBEAFE; color: #1E40AF; }

/* ── Sidebar toggle (hamburger) — hidden on desktop ───────── */
.sidebar-toggle {
    display: none;
    background: transparent;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    width: 40px; height: 40px;
    align-items: center; justify-content: center;
    cursor: pointer;
    color: #475569;
    font-size: 1.2rem;
    padding: 0;
    flex-shrink: 0;
}
.sidebar-toggle:hover { background: #F1F5F9; }
.sidebar-toggle:active { background: #E2E8F0; }

/* Backdrop — only shown on mobile when sidebar is open */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 998;
    animation: fadeIn 0.18s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Responsive: tablet/mobile ───────────────────────────── */
@media (max-width: 1024px) {
    /* Sidebar becomes off-screen drawer */
    .admin-sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 270px; max-width: 80vw;
        height: 100vh;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.25s ease-out, box-shadow 0.25s ease-out;
        box-shadow: none;
    }
    body.sidebar-open .admin-sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.25);
    }
    body.sidebar-open .sidebar-backdrop { display: block; }

    /* Prevent body scroll when drawer is open */
    body.sidebar-open { overflow: hidden; }

    /* Show hamburger */
    .sidebar-toggle { display: inline-flex; }

    /* Tighter topbar + main padding */
    .admin-topbar { padding: 12px 16px; gap: 10px; }
    .admin-topbar h1 { font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .admin-topbar .topbar-meta { flex-shrink: 0; }
    .admin-topbar .topbar-meta .badge { font-size: 0.72rem; padding: 3px 9px; }

    .admin-body-inner { padding: 16px; }
    .admin-main { width: 100%; }
}

/* ── Small phones ───────────────────────────── */
@media (max-width: 480px) {
    .admin-body-inner { padding: 12px; }
    .admin-topbar { padding: 10px 12px; }
    .admin-topbar h1 { font-size: 1rem; }
    /* Hide secondary topbar meta (year/term badges) on tiny screens to save room */
    .admin-topbar .topbar-meta .badge-soft { display: none; }

    /* Responsive tables: horizontal scroll inside card */
    table.data-table { font-size: 0.85rem; }
    table.data-table th, table.data-table td { padding: 8px 10px; }

    /* Stat cards smaller */
    .stat-card { padding: 16px; }
    .stat-card .stat-num { font-size: 1.5rem; }
}

/* ── Modal overlays: ensure they sit above sidebar drawer ───────── */
[style*="z-index:1000"] { z-index: 1100 !important; }
