:root {
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --primary: #1261f3;
    --primary-hover: #0d4ec9;
    --primary-light: #e8f0fe;
    --text: #112442;
    --text-muted: #64748b;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --sidebar-bg: linear-gradient(160deg, #07172e, #0b2551);
    --success: #10b981;
    --success-bg: #d1fae5;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --radius: 12px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Botones y Controles */
button, .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font-family: inherit; font-size: 14px; font-weight: 600;
    padding: 10px 18px; border-radius: var(--radius); border: 0;
    cursor: pointer; transition: all 0.2s ease; text-decoration: none;
}
.btn-primary, button:not(.btn) { background: var(--primary); color: #fff; }
.btn-primary:hover, button:not(.btn):hover { background: var(--primary-hover); }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-secondary:hover { background: #cbd5e1; text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; text-decoration: none; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f1f5f9; text-decoration: none; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

input, select, textarea {
    font-family: inherit; font-size: 14px; border: 1px solid var(--border);
    border-radius: var(--radius); padding: 10px 14px; background: #fff;
    color: var(--text); outline: none; transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(18,97,243,0.12); }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: #334155; }

/* Tipografía */
h1 { font-size: 24px; margin: 4px 0; font-weight: 700; color: #0f172a; }
h2 { font-size: 18px; margin: 0 0 16px; font-weight: 600; color: #1e293b; }
h3 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.muted, small { color: var(--text-muted); }

/* Layout Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 260px; flex: none; background: var(--sidebar-bg); color: #cbd5e1;
    display: flex; flex-direction: column; padding: 24px 16px;
}
.brand img { width: 180px; max-width: 100%; margin-bottom: 28px; }
.sidebar nav { display: grid; gap: 4px; }
.sidebar nav a {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px;
    border-radius: 10px; font-size: 13.5px; font-weight: 500; color: #94a3b8;
    transition: all 0.15s ease;
}
.sidebar nav a:hover, .sidebar nav a.selected { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.sidebar nav a.selected { background: var(--primary); font-weight: 600; }
.sidebar nav a svg, .sidebar nav a img { width: 18px; height: 18px; opacity: 0.85; }
.sidebar nav a.selected svg, .sidebar nav a.selected img { opacity: 1; }
.sidebar .nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; margin: 16px 14px 6px; font-weight: 700; }
.sidetip {
    margin-top: auto; padding: 14px; font-size: 12px; background: rgba(255,255,255,0.04);
    border-radius: 10px; border: 1px solid rgba(255,255,255,0.06);
}

.main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.top {
    padding: 16px 32px; background: #fff; display: flex; justify-content: space-between;
    align-items: center; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.top .menu { display: none; background: transparent; color: var(--text); border: 1px solid var(--border); padding: 8px 12px; }
.top .userchip { display: flex; align-items: center; gap: 12px; font-size: 13px; font-weight: 500; }
.avatar {
    display: grid; place-items: center; background: var(--primary-light); color: var(--primary);
    border-radius: 50%; height: 36px; width: 36px; font-weight: 700; font-size: 14px;
}
.content { max-width: 1400px; width: 100%; margin: 0 auto; padding: 28px 32px; }

/* Tarjetas y Estadísticas */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat, .panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,0.03); }
.stat { padding: 20px; display: grid; gap: 8px; }
.stat strong { font-size: 28px; color: #0f172a; font-weight: 700; }
.stat span { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.stat small { font-size: 12px; color: #94a3b8; }
.panel { margin-top: 20px; padding: 24px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }

/* Tablas */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: #64748b; font-weight: 600; background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #fbfcfe; }

/* Badges / Pills */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 9999px; font-size: 12px; font-weight: 600; }
.pill-success { background: var(--success-bg); color: #065f46; }
.pill-warning { background: var(--warning-bg); color: #92400e; }
.pill-danger { background: var(--danger-bg); color: #991b1b; }
.pill-info { background: var(--primary-light); color: var(--primary-hover); }
.pill-neutral { background: #f1f5f9; color: #475569; }

/* Formularios y Búsquedas */
.inlineform { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.gridform { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin: 16px 0; }
.searchbox { display: flex; align-items: center; gap: 8px; max-width: 380px; }

/* Notificaciones y Avisos */
.notice { background: #eff6ff; border-left: 4px solid var(--primary); border-radius: 6px; padding: 14px 16px; margin: 16px 0; font-size: 13.5px; }
.notice-success { background: #f0fdf4; border-left-color: var(--success); }
.notice-warning { background: #fffbeb; border-left-color: var(--warning); }
.notice-danger { background: #fef2f2; border-left-color: var(--danger); }

/* Autenticación */
.auth { min-height: 100vh; background: radial-gradient(circle at 10% 10%, #1e40af, #07172e 60%); display: grid; place-items: center; padding: 20px; }
.authbox { width: min(440px, 100%); background: #fff; border-radius: 20px; padding: 36px; box-shadow: 0 25px 60px rgba(0,0,0,0.25); }
.authbox img { width: 190px; margin-bottom: 12px; }
.authbox p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.authbox form { display: grid; gap: 16px; margin-top: 24px; }

/* Credencial Escolar Imprimible */
.id-card {
    width: 320px; border: 2px solid #e2e8f0; border-radius: 16px; padding: 20px;
    background: #fff; text-align: center; box-shadow: 0 10px 25px rgba(0,0,0,0.06); margin: 16px auto;
}
.id-card-header { border-bottom: 2px solid #f1f5f9; padding-bottom: 12px; margin-bottom: 14px; }
.id-card-header img { width: 140px; }
.id-card-photo { width: 90px; height: 90px; border-radius: 50%; object-fit: cover; margin: 0 auto 10px; border: 3px solid var(--primary-light); }
.id-card-name { font-size: 18px; font-weight: 700; color: #0f172a; margin: 4px 0; }
.id-card-grade { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-bottom: 12px; }
.id-card-qr { width: 160px; height: 160px; margin: 10px auto; }
.id-card-hint { font-family: monospace; font-size: 12px; color: #64748b; letter-spacing: 0.1em; }

/* Modales */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,0.6); backdrop-filter: blur(4px);
    display: none; place-items: center; z-index: 100; padding: 16px;
}
.modal-backdrop.active { display: grid; }
.modal { background: #fff; border-radius: 16px; max-width: 550px; width: 100%; padding: 26px; box-shadow: 0 20px 40px rgba(0,0,0,0.2); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-close { background: transparent; color: #64748b; border: 0; font-size: 20px; cursor: pointer; padding: 4px 8px; }

/* Pulsador de estado en vivo */
.pulse-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 0 rgba(16,185,129,0.7); animation: pulse 1.6s 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); } }

/* Responsivo */
@media (max-width: 900px) {
    .sidebar { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform 0.25s ease; box-shadow: 10px 0 30px rgba(0,0,0,0.2); }
    .sidebar.show { transform: translateX(0); }
    .top .menu { display: block; }
    .top { padding: 14px 18px; }
    .content { padding: 16px; }
    .stats { grid-template-columns: repeat(2, 1fr); gap: 12px; }
}
@media (max-width: 480px) {
    .stats { grid-template-columns: 1fr; }
    .top .userchip span:not(.avatar) { display: none; }
}

@media print {
    body { background: #fff; }
    .sidebar, .top, button, .btn, .inlineform, .panel-header { display: none !important; }
    .content { padding: 0; }
    .id-card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
}
