:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-soft: #dbeafe;
  --accent: #059669;
  --accent-soft: #d1fae5;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); padding-bottom: 84px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.84rem; margin: 0; }
.full-width { width: 100%; }
.container { max-width: 960px; margin: 0 auto; padding: 14px; }
.topbar { position: sticky; top: 0; z-index: 50; background: linear-gradient(135deg, var(--primary-dark), var(--primary)); color: #fff; box-shadow: 0 2px 12px rgba(30,58,138,0.25); }
.topbar-inner { max-width: 960px; margin: 0 auto; padding: 12px 14px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; flex: 1; }
.brand-badge { background: rgba(255,255,255,0.2); padding: 4px 8px; border-radius: 8px; font-size: 0.72rem; font-weight: 800; }
.topbar-logo { width: 58px; height: 58px; object-fit: contain; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.32)); flex-shrink: 0; }
.subject-right-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.btn-mini-doc { background: #1d4ed8; color: #fff; border: 1.5px solid #1e40af; border-radius: 999px; padding: 6px 10px; font-size: 0.9rem; font-weight: 800; cursor: pointer; line-height: 1; box-shadow: 0 2px 6px rgba(29,78,216,0.28); }
.brand h1 { margin: 0; font-size: 1.05rem; }
.brand p { margin: 0; font-size: 0.76rem; opacity: 0.88; }
.btn-back { background: rgba(255,255,255,0.18); color: #fff; border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 700; cursor: pointer; }
.user-session-bar { max-width: 932px; margin: 0 auto; padding: 6px 14px; background: rgba(255,255,255,0.14); border-radius: 10px 10px 0 0; display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; font-weight: 600; }
.btn-session-switch { background: rgba(255,255,255,0.22); color: #fff; border: 0; border-radius: 8px; padding: 4px 10px; font-weight: 700; cursor: pointer; }
.role-nav-menu { max-width: 932px; margin: 0 auto; padding: 6px 14px 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.role-nav-btn { background: rgba(255,255,255,0.14); color: #fff; border: 1px solid rgba(255,255,255,0.25); border-radius: 10px; padding: 7px 12px; font-size: 0.8rem; font-weight: 700; cursor: pointer; }
.role-nav-btn.active { background: #fff; color: var(--primary-dark); border-color: #fff; }

.card { background: var(--surface); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 1rem; }
.school-kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 640px) { .school-kpi-grid { grid-template-columns: repeat(4, 1fr); } }
.kpi-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi-card span { font-size: 0.72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.kpi-card strong { font-size: 1.35rem; font-weight: 900; }
.kpi-card small { font-size: 0.72rem; color: var(--muted); }
.kpi-card.kpi-primary { background: linear-gradient(135deg, #1d4ed8, #1e40af); border-color: #1e40af; color: #fff; }
.kpi-card.kpi-primary span, .kpi-card.kpi-primary small { color: rgba(255,255,255,0.88); }

.section-head h2 { margin: 0 0 2px; font-size: 1.1rem; }
.section-head p { margin: 0 0 12px; font-size: 0.84rem; color: var(--muted); }
.classes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.class-card, .subject-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: 14px; padding: 14px; text-align: left; cursor: pointer; box-shadow: var(--shadow); }
.class-code { font-size: 1.2rem; font-weight: 900; color: var(--primary-dark); }
.class-label { font-size: 0.84rem; font-weight: 700; margin: 2px 0 6px; }
.class-stats { display: inline-block; background: var(--accent-soft); color: var(--accent); font-size: 0.75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }

.class-banner { background: var(--surface); border-radius: 14px; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; box-shadow: var(--shadow); }
.pill { display: inline-block; background: var(--primary-soft); color: var(--primary-dark); font-size: 0.75rem; font-weight: 800; padding: 4px 10px; border-radius: 999px; }
.avg-pill { background: var(--accent-soft); color: var(--accent); margin-left: 6px; }
.subjects-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .subjects-grid { grid-template-columns: 1fr 1fr; } }
.subject-card { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.subject-title { font-weight: 800; font-size: 0.96rem; }
.subject-meta { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.subject-status { font-size: 0.76rem; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-dark); white-space: nowrap; }
.subject-status.done { background: var(--accent-soft); color: var(--accent); }

.lock-banner { background: #f8fafc; border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.lock-banner.is-locked { background: #fef2f2; border-color: #fecaca; }

.search-box input, input, select, textarea { width: 100%; padding: 9px 11px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 0.9rem; font-family: inherit; }
.students-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.student-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 12px; cursor: pointer; }
.student-row.is-done { background: #f0fdf4; border-color: #bbf7d0; }
.student-num { background: var(--primary-soft); color: var(--primary-dark); font-weight: 800; padding: 4px 8px; border-radius: 8px; font-size: 0.8rem; margin-right: 10px; }
.score-pill { font-size: 0.78rem; font-weight: 800; padding: 5px 10px; border-radius: 999px; background: #e2e8f0; }
.score-pill.filled { background: var(--accent); color: #fff; }

.student-sticky-header { position: sticky; top: 64px; z-index: 20; background: var(--surface); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); margin-bottom: 12px; }
.student-id-card { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.score-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.score-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 8px; text-align: center; }
.score-box.highlight { background: var(--primary-soft); border-color: #93c5fd; }
.score-box span { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.score-box strong { font-size: 1.1rem; color: var(--primary-dark); }
.student-questions-list { display: flex; flex-direction: column; gap: 8px; }
.student-q-row { background: var(--surface); border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; }
.opt-group { display: flex; gap: 6px; }
.opt-btn { width: 42px; height: 40px; border-radius: 10px; border: 1.5px solid var(--border); background: #fff; font-weight: 800; cursor: pointer; }
.opt-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.opt-btn.correct { background: #16a34a; color: #fff; border-color: #16a34a; }
.opt-btn.wrong { background: #dc2626; color: #fff; border-color: #dc2626; }
.student-bottom-bar { position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255,255,255,0.96); padding: 12px 16px; border-top: 1px solid var(--border); }

.btn-primary { background: var(--primary); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; cursor: pointer; }
.btn-secondary { background: #e2e8f0; color: var(--text); border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 700; cursor: pointer; }
.btn-sm { padding: 7px 11px; font-size: 0.8rem; }
.form-grid-1 { display: flex; flex-direction: column; gap: 10px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr; gap: 10px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .form-grid-2 { grid-template-columns: 1fr 1fr; } .form-grid-3 { grid-template-columns: 1fr 1fr auto; } }
.table-list { display: flex; flex-direction: column; gap: 8px; }
.table-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #f8fafc; font-size: 0.84rem; flex-wrap: wrap; }
.code-chip { background: var(--primary-soft); color: var(--primary-dark); font-weight: 900; padding: 4px 10px; border-radius: 8px; letter-spacing: 0.12em; }

.question-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.q-item { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--border); border-radius: 10px; padding: 8px; }

.raiox-heatmap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.rx-tile { border: 0; border-radius: 8px; padding: 10px 6px; text-align: center; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.rx-tile-q { font-size: 0.78rem; font-weight: 700; }
.rx-tile-pct { font-size: 1.2rem; font-weight: 900; }
.rx-low { background: #e07040; color: #1f130e; } .rx-warn { background: #f4c0a8; color: #1f130e; } .rx-mid { background: #a8e6ef; } .rx-high { background: #00c4cc; } .rx-none { background: #e2e8f0; color: #64748b; }
.raiox-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 0.76rem; color: var(--muted); }
.rx-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.raiox-detail-box { margin-top: 12px; padding: 12px; border-radius: 10px; background: #f8fafc; border: 1px solid var(--border); font-size: 0.84rem; }

.login-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(15,23,42,0.88); display: flex; align-items: center; justify-content: center; padding: 18px; }
.login-card { width: 100%; max-width: 390px; background: #fff; border-radius: 18px; padding: 24px 20px; text-align: center; }
.login-badge { display: inline-block; font-size: 0.7rem; font-weight: 800; color: var(--primary-dark); background: var(--primary-soft); padding: 4px 10px; border-radius: 999px; margin-bottom: 10px; }
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.login-form input { text-align: center; font-size: 1.5rem; letter-spacing: 0.3em; font-weight: 800; }
.login-error { color: #dc2626; font-size: 0.82rem; font-weight: 700; }

.modal { position: fixed; inset: 0; z-index: 150; display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,0.6); }
.modal-sheet { position: relative; width: 100%; max-width: 560px; max-height: 85vh; background: #fff; border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; }
.modal-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body-pad { padding: 14px 16px; overflow-y: auto; }
.btn-close { background: #f1f5f9; border: 0; border-radius: 8px; padding: 6px 10px; cursor: pointer; font-weight: 800; }
.logs-list { display: flex; flex-direction: column; gap: 8px; }
.log-item { border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: #f8fafc; font-size: 0.8rem; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 0.84rem; font-weight: 700; z-index: 300; }

/* Gráficos de Barras (igual Tertulino) */
.charts-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 18px; }
@media (min-width: 720px) { .charts-grid { grid-template-columns: 1fr 1fr; } }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.chart-head h3 { margin: 0; font-size: 1rem; }
.chart-select { width: auto; padding: 6px 10px; font-size: 0.8rem; font-weight: 700; background: #f8fafc; }
.bar-chart { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 98px 1fr 44px; align-items: center; gap: 8px; font-size: 0.78rem; }
.bar-label { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 16px; background: #f1f5f9; border-radius: 999px; overflow: hidden; border: 1px solid #e2e8f0; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.35s ease; }
.bar-fill.tier-high { background: linear-gradient(90deg, #16a34a, #22c55e); }
.bar-fill.tier-mid  { background: linear-gradient(90deg, #2563eb, #3b82f6); }
.bar-fill.tier-warn { background: linear-gradient(90deg, #d97706, #f59e0b); }
.bar-fill.tier-low  { background: linear-gradient(90deg, #dc2626, #ef4444); }
.bar-val { text-align: right; font-weight: 800; }
