/* ── RESET & BASE ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

/* ── LAYOUT ───────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr; min-height: 100vh; }
.topbar { grid-column: 1/-1; background: var(--bg2); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 16px; z-index: 100; }
.topbar-logo { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: -0.3px; }
.topbar-logo span { color: var(--accent); }
.topbar-school { font-size: 12px; color: var(--text2); margin-left: 4px; flex-shrink: 0; }
.topbar-spacer { flex: 1; min-width: 8px; }
.topbar-user { color: var(--text2); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#btnSidebarToggle { display: none; }

.sidebar { background: var(--bg2); border-right: 1px solid var(--border); padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius); cursor: pointer; color: var(--text2); font-size: 13px; font-weight: 500; transition: all .15s; border: none; background: none; width: 100%; text-align: left; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: rgba(79,142,247,0.15); color: var(--accent); }
.nav-icon { font-size: 16px; flex-shrink: 0; }
.nav-section { font-size: 10px; font-weight: 600; letter-spacing: 1px; color: var(--text3); padding: 16px 12px 4px; text-transform: uppercase; }
.main { padding: 24px; overflow-y: auto; }

/* ── CARDS ────────────────────────────────────────────────────────────────── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.card-title { font-size: 16px; font-weight: 600; }
.card-subtitle { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ── STATS GRID ───────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-val { font-size: 28px; font-weight: 600; line-height: 1; }
.stat-lbl { font-size: 12px; color: var(--text2); margin-top: 6px; }

/* ── BUTTONS ──────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius); font-size: 13px; font-weight: 500; border: none; transition: all .15s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost { background: var(--bg3); color: var(--text2); border: 1px solid var(--border2); }
.btn-ghost:hover { background: var(--bg4); color: var(--text); }
.btn-danger { background: rgba(248,113,113,0.15); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }
.btn-danger:hover { background: rgba(248,113,113,0.25); }
.btn-success { background: rgba(52,211,153,0.15); color: var(--green); border: 1px solid rgba(52,211,153,0.3); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Toggle tema (en header) */
.theme-toggle { width: 36px; justify-content: center; padding-left: 0; padding-right: 0; }
.theme-toggle .theme-ico { font-size: 14px; line-height: 1; }

/* ── FORM ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 5px; }
.form-control { width: 100%; background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius); padding: 8px 12px; color: var(--text); font-size: 13px; transition: border-color .15s; }
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control option { background: var(--bg3); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── TABLA ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 12px; font-size: 11px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; color: var(--text3); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tr:hover td { background: var(--bg3); }
tr:last-child td { border-bottom: none; }

/* ── BADGES ───────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; }
.badge-area { color: #fff; }
.badge-green { background: rgba(52,211,153,0.15); color: var(--green); }
.badge-amber { background: rgba(251,191,36,0.15); color: var(--amber); }
.badge-red   { background: rgba(248,113,113,0.15); color: var(--red); }
.badge-blue  { background: rgba(79,142,247,0.15); color: var(--accent); }
.badge-gray  { background: var(--bg4); color: var(--text2); }

/* ── HORARIO GRID (filas = horas, columnas = días) ────────────────────────── */
.schedule-grid { display: grid; gap: 0; }
.sched-head { display: grid; grid-template-columns: 48px repeat(5, minmax(72px, 1fr)); background: var(--bg3); border-radius: var(--radius) var(--radius) 0 0; }
.sched-head-cell { padding: 6px 4px; font-size: 11px; font-weight: 600; text-align: center; color: var(--text2); border-right: 1px solid var(--border); }
.sched-head-cell:last-child { border-right: none; }
.sched-corner { font-size: 9px; letter-spacing: 0.02em; line-height: 1.2; padding: 6px 2px !important; }
.sched-row { display: grid; grid-template-columns: 48px repeat(5, minmax(72px, 1fr)); border-bottom: 1px solid var(--border); }
.sched-row:last-child { border-bottom: none; }
.sched-day { padding: 4px 2px; font-size: 12px; font-weight: 600; color: var(--text2); display: flex; align-items: center; background: var(--bg3); border-right: 1px solid var(--border); }
.sched-hour-cell { flex-direction: column; justify-content: center; text-align: center; line-height: 1.15; font-size: 10px; }
.sched-hour-cell .sched-hour-num { font-size: 10px; font-weight: 700; display: block; }
.sched-hour-cell .hora-label { font-size: 8px; font-weight: 500; opacity: 0.88; display: block; }
.sched-cell { min-height: 52px; border-right: 1px solid var(--border); padding: 3px; position: relative; transition: background .1s; cursor: pointer; }
.sched-cell:last-child { border-right: none; }
.sched-cell:hover { background: rgba(79,142,247,0.06); }
.sched-cell.occupied { background: rgba(79,142,247,0.04); }
.sched-cell-empty { display: flex; align-items: center; justify-content: center; }
.sched-cell-empty .sched-cell-add { opacity: 0.35; font-size: 18px; line-height: 1; pointer-events: none; }
.sched-cell-empty:hover .sched-cell-add { opacity: 0.65; }
.slot-card-wrap { position: relative; height: 100%; min-height: 46px; }
.slot-card { border-radius: 6px; padding: 4px 22px 4px 6px; font-size: 11px; font-weight: 500; cursor: grab; transition: opacity .15s; line-height: 1.3; }
.slot-card:hover { opacity: .85; }
.slot-card .slot-curso { font-weight: 600; }
.slot-card .slot-grado { opacity: .8; font-size: 10px; }
.slot-card.dragging { opacity: .4; }
.slot-actions { position: absolute; top: 2px; right: 2px; display: flex; gap: 1px; z-index: 2; }
.slot-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; padding: 0; border: none; border-radius: 4px;
  font-size: 12px; line-height: 1; cursor: pointer;
  background: var(--bg4); color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.slot-btn:hover { background: var(--bg3); }
.slot-btn-danger:hover { background: rgba(248,113,113,0.15); color: var(--red); border-color: rgba(248,113,113,0.35); }

/* ── AUSENCIA PANEL ───────────────────────────────────────────────────────── */
.ausencia-panel { background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 20px; }
.aus-docente-dropdown { position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px; background: var(--bg2); border: 1px solid var(--border2); border-radius: var(--radius); max-height: 260px; overflow-y: auto; z-index: 50; box-shadow: var(--shadow); }
.aus-docente-option:last-child { border-bottom: none !important; }
.aus-hora-chip:has(input:checked) { background: rgba(79,142,247,0.15) !important; border-color: var(--accent) !important; }
.sugerencia-card { background: var(--bg4); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 14px; transition: border-color .15s; }
.sugerencia-card:hover { border-color: var(--border2); }
.sug-score { width: 46px; height: 46px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 17px; font-weight: 700; flex-shrink: 0; }
.sug-score.alta   { background: rgba(52,211,153,0.15); color: var(--green); }
.sug-score.media  { background: rgba(251,191,36,0.15);  color: var(--amber); }
.sug-score.baja   { background: rgba(248,113,113,0.12); color: var(--red); }
.sug-info { flex: 1; }
.sug-nombre { font-weight: 600; font-size: 14px; }
.sug-desglose { font-size: 11px; color: var(--text2); margin-top: 3px; }
.sug-horas { font-size: 11px; color: var(--text3); margin-top: 2px; }
.prio-bar { height: 4px; border-radius: 2px; margin-top: 4px; }

/* ── MODAL ────────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 999; padding: 20px; }
.modal { background: var(--bg2); border: 1px solid var(--border2); border-radius: var(--radius-lg); width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; line-height: 1; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ── TABS ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; background: var(--bg3); border-radius: var(--radius); padding: 3px; margin-bottom: 20px; }
.tab { padding: 7px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; color: var(--text2); border: none; background: none; transition: all .15s; }
.tab.active { background: var(--bg2); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }

/* ── SEARCH ───────────────────────────────────────────────────────────────── */
.search-bar { position: relative; }
.search-bar input { padding-left: 34px; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text3); font-size: 14px; pointer-events: none; }

/* ── DRAG GHOST ───────────────────────────────────────────────────────────── */
.drag-ghost { position: fixed; pointer-events: none; z-index: 9999; opacity: .9; transform: rotate(2deg); }

/* ── AVAILABILITY CHIPS ───────────────────────────────────────────────────── */
.avail-grid { display: grid; grid-template-columns: repeat(11, 1fr); gap: 3px; margin-top: 6px; }
.avail-chip { text-align: center; padding: 3px 0; border-radius: 4px; font-size: 10px; font-weight: 600; font-family: var(--mono); }
.avail-chip.free  { background: rgba(52,211,153,.15); color: var(--green); }
.avail-chip.busy  { background: rgba(248,113,113,.1);  color: var(--text3); }
.avail-chip.warn  { background: rgba(251,191,36,.12);  color: var(--amber); }

/* ── COLOR DOT ────────────────────────────────────────────────────────────── */
.dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* ── TOAST ────────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast { background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius); padding: 12px 16px; font-size: 13px; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow); animation: slideIn .2s ease; max-width: 320px; }
.toast.success { border-color: rgba(52,211,153,.4); }
.toast.error   { border-color: rgba(248,113,113,.4); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── HORA LABELS ──────────────────────────────────────────────────────────── */
.hora-label { font-size: 10px; font-family: var(--mono); color: var(--text3); }

/* ── UTIL ─────────────────────────────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.ml-auto { margin-left: auto; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-3 { margin-bottom: 12px; }
.hidden { display: none !important; }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text2); }
.fw-600 { font-weight: 600; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── LOGIN ────────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg); z-index: 200;
}
.login-screen.hidden { display: none !important; }
#appShell.hidden { display: none !important; }
.login-card { width: 100%; max-width: 400px; }
.login-card .card-header { margin-bottom: 8px; justify-content: center; }
.brand-accent { color: var(--accent); }
.login-card { text-align: center; }
.login-card .card-title { font-size: 22px; font-weight: 700; letter-spacing: -0.2px; }
.login-school { margin-bottom: 18px; }
.login-card form { text-align: center; }
.login-card .form-label { text-align: left; }
.login-meta { margin-top: 14px; line-height: 1.35; }
.login-error { color: var(--red); margin-bottom: 12px; }

.password-field-wrap { position: relative; }
.password-field-wrap .form-control { padding-right: 44px; }
.password-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: var(--bg4); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text2); padding: 6px 10px; font-size: 14px; line-height: 1; cursor: pointer;
}
.password-toggle:hover { color: var(--text); border-color: var(--border2); }

/* ── ESTADOS (Cargando / Error) ───────────────────────────────────────────── */
.loading-state { padding: 40px; text-align: center; color: var(--text2); }
.error-wrap { padding: 24px; max-width: 600px; }
.error-card {
  background: rgba(248,113,113,0.15);
  border: 1px solid rgba(248,113,113,0.4);
  border-radius: 10px;
  padding: 20px;
}
.error-title { font-weight: 600; color: rgba(248,113,113,1); margin-bottom: 8px; }
.error-message { color: var(--text2); font-size: 13px; }
.error-pre { margin-top: 12px; font-size: 11px; overflow: auto; max-height: 150px; }

/* ── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px 1fr; }
  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: min(88vw, 320px);
    transform: translateX(-105%);
    transition: transform .18s ease;
    z-index: 200;
    box-shadow: var(--shadow);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main { padding: 16px; }
  #btnSidebarToggle { display: inline-flex !important; }
  .topbar-school { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 16px; }
  .toast-container { right: 12px; bottom: 12px; }
  .toast { max-width: calc(100vw - 24px); }
}

