:root {
  --bg: #f0fdf4;
  --panel: #ecfdf5;
  --ink: #172033;
  --muted: #667085;
  --line: #d6dce8;
  --primary: #0f766e;
  --primary-2: #14b8a6;
  --accent: #1d4ed8;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #15803d;
  --head: #064e3b;
  --head2: #047857;
  --soft: #e3f4f1;
  --cell: #f7fbfa;
  --locked: #eaf3f5;
  --shadow: 0 20px 50px rgba(16,24,40,.10);
  --radius: 18px;
}

/* ── Reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif; overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App layout ──────────────────────────────────────── */
.app { min-height: 100%; display: flex; flex-direction: column; }

/* ── Header ──────────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(15,23,42,.05);
}
.top {
  display: flex; align-items: center;
  gap: 5px 16px; padding: 5px 18px;
  flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  flex: 1 1 100%;
}
.logo {
  width: 42px; height: 42px; border-radius: 14px;
  background: linear-gradient(135deg, #16a34a, #15803d);
  box-shadow: 0 8px 20px rgba(15,118,110,.25);
  display: grid; place-items: center;
  color: #fff; font-weight: 900; flex-shrink: 0;
}
.brand h1 { font-size: 20px; line-height: 1.1; margin: 0; }
.brand small { display: block; color: var(--muted); font-weight: 500; margin-top: 3px; font-size: 13px; }
.toolbar {
  display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; flex: 1 1 100%;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  border: 1px solid #cbd5e1; background: #f8fbfa; color: #0f172a;
  border-radius: 12px; padding: 9px 12px; font-weight: 700;
  cursor: pointer; box-shadow: 0 2px 8px rgba(15,23,42,.04);
  font-size: 13px; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; text-decoration: none;
  transition: .12s; white-space: nowrap;
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15,23,42,.10);
  text-decoration: none;
}
.btn.primary { background: linear-gradient(135deg, var(--primary), #0f8c82); color: #fff; border-color: transparent; }
.btn.blue { background: linear-gradient(135deg, #0d9488, #0f766e); color: #fff; border-color: transparent; }
.btn.danger { background: #fff1f2; color: #be123c; border-color: #fecdd3; }
.btn.purple { background: linear-gradient(135deg, #0369a1, #0284c7); color: #fff; border-color: transparent; }
.btn.orange { background: linear-gradient(135deg, #ea580c, #c2410c); color: #fff; border-color: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12px; }

/* ── Tabs ────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 0 18px 12px; flex-wrap: wrap;
  -webkit-overflow-scrolling: touch;
}
.tab {
  white-space: nowrap;
  border: 1px solid #bbf7d0; background: #f0fdf4; color: #166534;
  padding: 9px 14px; border-radius: 999px; font-weight: 800;
  cursor: pointer; font-size: 13px; transition: .12s; outline: none;
}
.tab:hover { background: #dcfce7; border-color: #86efac; transform: translateY(-1px); }
.tab.active {
  background: #064e3b; color: #fff; border-color: #064e3b;
  box-shadow: 0 4px 12px rgba(6,78,59,.25);
}

.kbd-hint { font-size: 11px; color: var(--muted); padding: 4px 18px 10px; }
kbd {
  background: #e2e8f0; border: 1px solid #cbd5e1; border-radius: 4px;
  padding: 1px 5px; font-family: monospace; font-size: 10px;
}

/* ── Main content ────────────────────────────────────── */
main {
  padding: 8px 18px 18px;
  display: flex; flex-direction: column; gap: 8px;
  overflow-x: hidden;
}

/* ── Sheet (tab content) ─────────────────────────────── */
.sheet {
  display: none; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.sheet.active { display: block; }
.sheet-head {
  display: flex; align-items: center;
  justify-content: space-between; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #eef8f6, #f5faf9);
  flex-wrap: wrap;
}
.sheet-title { font-size: 18px; font-weight: 900; }
.hint { color: var(--muted); font-size: 13px; }

.grid-wrap {
  overflow: auto; max-height: calc(100vh - 240px);
  min-height: 220px;
  background: #f3f8f7;
  -webkit-overflow-scrolling: touch;
}

/* ── Sheet table ─────────────────────────────────────── */
.sheet-table {
  border-collapse: separate; border-spacing: 0;
  width: max-content; min-width: 100%;
  font-size: 12px;
}
.sheet-table th, .sheet-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0; min-width: 28px; height: 30px;
  text-align: center; background: var(--cell);
}
.sheet-table thead { position: sticky; top: 0; z-index: 6; }
.sheet-table thead th { background: #065f46; color: #fff; font-weight: 900; }
.sheet-table .rownum {
  position: sticky; left: 0; z-index: 4;
  background: #f8fafc; font-weight: 900; color: #172033;
  min-width: 40px; max-width: 40px; width: 40px;
}
.sheet-table thead .rownum { background: #065f46; color: #fff; z-index: 9; }
.sheet-table td.rownum input { width: 100%; text-align: center; border: 1px solid transparent; background: transparent; font-weight: 900; font-size: inherit; color: inherit; padding: 2px 0; border-radius: 4px; }
.sheet-table td.rownum input:focus { border-color: var(--primary); background: #fff; outline: none; }
.sheet-table td.rownum input[type="number"]::-webkit-outer-spin-button,
.sheet-table td.rownum input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.sheet-table td.rownum input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.sheet-table .name {
  position: sticky; left: 40px; z-index: 4;
  min-width: 240px; max-width: 240px; text-align: center;
  background: #f8fafc; font-weight: 900; color: #172033;
}
.sheet-table thead .name { background: #065f46; color: #fff; z-index: 9; }
.sheet-table td.name input { text-align: center; width: 236px; max-width: 236px; }
.sheet-table input, .sheet-table select {
  width: 100%; height: 29px; border: 0;
  background: transparent; text-align: center;
  font: inherit; color: #172033; outline: 0;
  padding: 2px 2px; box-sizing: border-box;
}
.sheet-table.sheet-asist td select { padding: 0; min-width: 0; max-width: 100%; }
.sheet-table input:focus, .sheet-table select:focus {
  background: #fff7ed;
  box-shadow: inset 0 0 0 2px #fb923c;
  color: #0f172a;
}
.sheet-table input:disabled {
  background: #f1f5f9 !important;
  color: #94a3b8 !important;
  cursor: not-allowed;
}
.sheet-table th input { color: #fff; }
.sheet-table th input:focus {
  background: rgba(255,255,255,.95) !important;
  color: #0f172a !important;
  box-shadow: inset 0 0 0 2px #fb923c !important;
}

/* ── TH inputs ───────────────────────────────────────── */
.th-input {
  color: #fff !important;
  background: rgba(255,255,255,.15) !important;
  border: 0 !important; border-radius: 4px !important;
  text-align: center !important; font-weight: 900 !important;
}
.th-input::placeholder { color: #fff !important; opacity: .85 !important; }
.th-input:focus {
  color: #0f172a !important;
  background: #fff !important;
  box-shadow: inset 0 0 0 2px #fb923c !important;
}
.th-input:focus::placeholder { color: #94a3b8 !important; opacity: 1 !important; }
.th-input-tit::placeholder { font-size: 8px !important; opacity: .3 !important; font-weight: 400 !important; letter-spacing: 0 !important; }
.th-input-tit:focus::placeholder { opacity: .25 !important; }
.th-input-sm {
  color: #fff !important;
  background: rgba(255,255,255,.18) !important;
  border: 0 !important; border-radius: 3px !important;
  text-align: center !important; font-size: 9px !important;
}
.th-input-sm::placeholder { color: #fff !important; opacity: .85 !important; }
.th-input-sm:focus {
  color: #0f172a !important;
  background: #fff !important;
  box-shadow: inset 0 0 0 2px #fb923c !important;
}
.th-input-sm:focus::placeholder { color: #94a3b8 !important; opacity: 1 !important; }
.valmax-input {
  color: #fef3c7 !important;
  background: rgba(255,255,255,.13) !important;
  font-weight: 900 !important;
}
.valmax-input:focus {
  color: #0f172a !important;
  background: #fff !important;
  box-shadow: inset 0 0 0 2px #d97706 !important;
}
.valmax-input.valmax-lleno {
  color: #fde68a !important;
  background: rgba(255,255,255,.08) !important;
  cursor: not-allowed !important; opacity: .7;
}

/* ── Cell states ─────────────────────────────────────── */
.locked { background: var(--locked) !important; font-weight: 900; }
.nota-roja { color: #b3261e !important; }
.nota-verde { color: #14532d !important; }
.rp-input input.nota-roja { color: #b3261e !important; }
.calc { background: #f0fdf4 !important; color: #14532d !important; font-weight: 900; }
.calc.nota-roja, .locked.nota-roja, .reprobado-cell.nota-roja { color: #b3261e !important; }
.calc.nota-verde, .aprobado-cell.nota-verde { color: #14532d !important; }
td.aprobado-cell.nota-verde { font-weight: 900 !important; color: #14532d !important; background: #f0fdf4 !important; }
td.reprobado-cell.nota-roja { font-weight: 900 !important; color: #7f1d1d !important; background: #fff1f2 !important; }
.sheet-table thead th.calc, .sheet-table thead th.numtot {
  background: #dcfce7 !important; color: #1e3a8a !important;
  font-weight: 900 !important; text-shadow: none !important;
}
.sheet-table thead input.att-num {
  background: #dcfce7 !important; color: #1d4ed8 !important;
  font-weight: 900 !important; -webkit-text-fill-color: #1d4ed8 !important;
  opacity: 1 !important; text-shadow: none !important;
}
.sheet-table thead input.att-num:focus {
  background: #eff6ff !important; color: #1d4ed8 !important;
  -webkit-text-fill-color: #1d4ed8 !important;
}
.month { background: #0f766e !important; color: #fff !important; font-size: 14px; }
.bad { color: #b91c1c !important; }
.good { color: #166534 !important; }
.cell-error input { background: #fef2f2 !important; box-shadow: inset 0 0 0 2px #dc2626 !important; }
.g-mejor { font-weight: 900; color: #172033 !important; background: #fff !important; }
.g-mejor-mal { font-weight: 900; color: #b91c1c !important; background: #fef2f2 !important; }
.g-tenue { color: #9ca3af !important; font-weight: 500 !important; background: #f0fdf4 !important; }
.g-vacio { color: #d1d5db !important; font-weight: 500 !important; background: #f0fdf4 !important; }
.row-name-missing input { background: #fef9c3 !important; box-shadow: inset 0 0 0 2px #ca8a04 !important; }
.row-hidden { display: none; }
.att-sep { background: #1e3a5f !important; border-left: 2px solid #0f2744; min-width: 10px; width: 10px; padding: 0; }
.sheet-table.sheet-asist { min-width: unset; }
.sheet-table .col-final { min-width: 78px; width: 78px; padding: 0 6px; }
.sheet-table th.col-final { font-size: 11px; white-space: nowrap; }

/* ── Summary card (meta fields) ──────────────────────── */
.summary-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px; padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #edf7f5;
}
.metric {
  background: #f8fbfa; border: 1px solid var(--line);
  border-radius: 14px; padding: 12px;
}
.metric span { color: var(--muted); font-size: 12px; font-weight: 700; display: block; margin-bottom: 4px; }
.metric input, .metric select {
  width: 100%; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px;
  font: inherit; color: #172033; background: #fff;
}
.metric input:focus, .metric select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px #d1fae5; outline: none;
}
.metric .big { font-weight: 900; font-size: 18px; color: var(--primary); }

/* ── Search bar ──────────────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: #f8fbfa;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.search-bar input {
  border: 1px solid #cbd5e1; border-radius: 8px;
  padding: 6px 10px; font-size: 13px;
  width: 240px; outline: none;
}
.search-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px #d1fae5;
}
.search-bar label { font-size: 13px; font-weight: 700; color: var(--muted); }

/* ── Toast ───────────────────────────────────────────── */
.toast {
  position: fixed; right: 18px; bottom: 18px;
  background: #064e3b; color: #fff;
  border-radius: 14px; padding: 12px 16px;
  box-shadow: var(--shadow);
  display: none; z-index: 50;
  font-weight: 800; max-width: 420px; line-height: 1.4;
}
.toast.show { display: block; animation: pop .18s ease; }
@keyframes pop {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Wrap ────────────────────────────────────────────── */
.wrap { max-width: 1200px; margin: 0 auto; padding: 22px 18px; }

/* ── Cards ───────────────────────────────────────────── */
.cards {
  display: grid; grid-template-columns: 1fr;
  gap: 16px; margin-top: 16px;
}
.card {
  background: #fff; border: 1px solid var(--line);
  border-radius: 16px; padding: 18px;
  box-shadow: 0 8px 24px rgba(15,23,42,.05);
  display: flex; flex-direction: column; gap: 10px;
}
.card h3 { margin: 0; font-size: 17px; }
.card .meta { color: var(--muted); font-size: 13px; line-height: 1.5; }
.card .pill {
  display: inline-block; background: var(--soft);
  color: var(--primary); font-weight: 800; font-size: 12px;
  padding: 3px 10px; border-radius: 999px;
}
.card .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.card .row > a.btn, .card .row > form { flex: 1 1 auto; }
.card .row > form { display: flex; }
.card .row > form .btn { flex: 1 1 auto; width: 100%; }

/* ── Stat grid ───────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px; margin: 16px 0;
}
.stat {
  background: #fff; border: 1px solid var(--line);
  border-radius: 16px; padding: 10px 16px; text-align: center;
}
.stat .n { font-size: 30px; font-weight: 900; color: var(--primary); white-space: nowrap; }
.stat .l { color: var(--muted); font-size: 13px; font-weight: 700; margin-top: 2px; }

/* ── Tabla (reports, history) ────────────────────────── */
.tabla {
  width: 100%; border-collapse: collapse;
  background: #fff; border-radius: 12px;
  overflow: hidden; font-size: 13px;
  box-shadow: 0 6px 18px rgba(15,23,42,.05);
}
.tabla th, .tabla td { border: 1px solid var(--line); padding: 8px 10px; text-align: center; }
.tabla th { background: #065f46; color: #fff; }
.tabla tr:nth-child(even) td { background: #f8fbfa; }

/* ── Badge / Barra ───────────────────────────────────── */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-weight: 800; font-size: 12px; }
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.no { background: #fee2e2; color: #dc2626; }
.barra { background: #eef2f7; border-radius: 8px; height: 22px; overflow: hidden; position: relative; }
.barra > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); }
.barra em { position: absolute; left: 8px; top: 0; line-height: 22px; font-style: normal; font-weight: 800; font-size: 12px; color: #064e3b; }

/* ── Empty state ─────────────────────────────────────── */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 48px; margin-bottom: 10px; }

/* ── Modal ───────────────────────────────────────────── */
.modal-bg {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.55); z-index: 100;
  overflow: auto; padding: 24px;
}
.modal-bg.show { display: block; }
.modal-box {
  background: #fff; border-radius: 20px;
  max-width: 760px; margin: 0 auto; padding: 26px;
  box-shadow: 0 30px 80px rgba(0,0,0,.25);
}

/* ── Bulletin table ──────────────────────────────────── */
.bulletin-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 8px; }
.bulletin-table th, .bulletin-table td { border: 1px solid var(--line); padding: 5px 8px; text-align: center; }
.bulletin-table th { background: #065f46; color: #fff; }
.bulletin-section h3 { font-size: 14px; font-weight: 900; color: var(--head2); border-bottom: 2px solid var(--line); padding-bottom: 4px; margin: 14px 0 8px; }
.bulletin-final { font-size: 20px; font-weight: 900; text-align: center; padding: 14px; border-radius: 12px; margin-top: 14px; }
.bulletin-final.pass { background: #dcfce7; color: #15803d; }
.bulletin-final.fail { background: #fee2e2; color: #dc2626; }

/* ── Attendance selects colors ───────────────────────── */
select.asis-P { color: #14532d !important; font-weight: 900 !important; background: #f0fdf4 !important; }
select.asis-T { color: #6d28d9 !important; font-weight: 900 !important; background: #f5f3ff !important; }
select.asis-A { color: #7f1d1d !important; font-weight: 900 !important; background: #fff1f2 !important; }
select.asis-E { color: #854d0e !important; font-weight: 900 !important; background: #fef08a !important; }
select.asis-R { color: #1e3a8a !important; font-weight: 900 !important; background: #eff6ff !important; }
select.asis-vacio { color: #94a3b8 !important; background: var(--cell) !important; }

/* ── Nuevo grid (usuarios alta) ──────────────────────── */
.nuevo-grid { display: grid; grid-template-columns: 1fr 1.5fr 1fr 1fr 1fr auto; gap: 8px; align-items: end; }

/* ── Usuarios table ──────────────────────────────────── */
.tabla-usuarios th, .tabla-usuarios td { height: auto; }
.tabla-usuarios .celda-acciones {
  display: flex; flex-direction: column;
  align-items: stretch; gap: 6px; min-width: 130px;
}
.tabla-usuarios .celda-acciones form { display: block !important; width: 100%; margin: 0; }
.tabla-usuarios .celda-acciones .btn { white-space: nowrap; width: 100%; justify-content: center; }
.tabla-usuarios-wrap { overflow: auto; max-height: none; }
.tabla-usuarios { min-width: 900px; }

/* ── Boletin controls ────────────────────────────────── */
.boletin-controls {
  max-width: 720px; flex-direction: row;
  align-items: center; gap: 12px; flex-wrap: wrap;
}
.boletin-controls select {
  min-width: 0; width: 100%; flex: 1;
}
@media(max-width:768px){
  .boletin-controls { flex-direction: column; align-items: stretch; }
  .boletin-controls select { min-width: 0; }
}
@media(max-width:480px){
  .boletin-controls { gap: 8px; }
  .boletin-controls .btn { width: 100%; }
}

/* ── Login / Password pages ──────────────────────────── */
.login-wrap, .pwd-wrap { max-width: 440px; margin: 40px auto; }
@media(max-width:768px){
  .login-wrap, .pwd-wrap { margin: 20px auto; }
}
@media(max-width:480px){
  .login-wrap, .pwd-wrap { margin: 10px auto; padding: 0 4px; }
}

/* ── Index page ──────────────────────────────────────── */
.index-header-row {
  display: flex; justify-content: space-between;
  align-items: center; flex-wrap: wrap;
  gap: 10px; margin-bottom: 12px;
}
.index-anio-form {
  display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap;
}
@media(max-width:480px){
  .index-header-row{flex-direction:column;align-items:stretch}
  .index-anio-form{flex-wrap:wrap}
  .index-anio-form input{width:100%!important;min-width:0}
}

/* ── Historial filter form ───────────────────────────── */
@media(max-width:480px){
  .index-header-row form{width:100%}
  .index-header-row form select{width:100%;flex:1}
}

/* ── Toolbar select ──────────────────────────────────── */
.toolbar select {
  border: 1px solid #bbf7d0; background: #f0fdf4;
  color: #064e3b; border-radius: 12px;
  padding: 8px 12px; font-weight: 700;
  font-size: 13px; cursor: pointer;
  outline: none; transition: .12s;
  min-width: 0;
}
.toolbar select:hover { border-color: #86efac; background: #dcfce7; }
.toolbar select:focus { border-color: #064e3b; box-shadow: 0 0 0 2px #bbf7d0; }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — TABLET (max-width: 1024px)
   ═══════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .brand h1 { font-size: 18px; }
  .brand small { font-size: 12px; }
  .wrap { padding: 16px 12px; }
  main { padding: 6px 12px 14px; }
  .stat .n { font-size: 26px; }

  /* Usuarios: tabla → tarjetas (9 columnas no caben en tablet) */
  .tabla-usuarios-wrap { overflow: visible; }
  .tabla-usuarios { min-width: 0; width: 100%; display: block; background: transparent; box-shadow: none; }
  .tabla-usuarios thead { display: none; }
  .tabla-usuarios tbody, .tabla-usuarios tr, .tabla-usuarios td { display: block; width: 100%; }
  .tabla-usuarios tr {
    background: #fff; border: 1px solid var(--line);
    border-radius: 12px; margin-bottom: 12px;
    padding: 10px 12px;
    box-shadow: 0 4px 12px rgba(15,23,42,.04);
  }
  .tabla-usuarios td {
    border: 0; border-bottom: 1px dashed #e2e8f0;
    padding: 8px 4px; text-align: left;
    display: grid; grid-template-columns: 120px 1fr;
    gap: 8px; align-items: center;
    min-height: 0; height: auto; background: transparent;
  }
  .tabla-usuarios td:last-child { border-bottom: 0; }
  .tabla-usuarios td::before {
    content: attr(data-label); font-weight: 800;
    color: var(--muted); font-size: 12px;
    text-transform: uppercase; letter-spacing: .02em;
  }
  .tabla-usuarios td input[type="text"],
  .tabla-usuarios td input[name="nombre"],
  .tabla-usuarios td input[type="date"],
  .tabla-usuarios td input[type="number"] {
    width: 100%; max-width: 100%; min-width: 0;
  }
  .tabla-usuarios .celda-acciones {
    grid-template-columns: 1fr;
    display: grid; gap: 6px; min-width: 0; padding: 8px 4px;
  }
  .tabla-usuarios .celda-acciones::before { grid-column: 1 / -1; }
  .tabla-usuarios .celda-acciones form { display: block !important; width: 100%; margin: 0; }
  .tabla-usuarios .celda-acciones .btn { width: 100%; justify-content: center; white-space: nowrap; }

  /* Alta rápida: menos columnas */
  .nuevo-grid { grid-template-columns: repeat(2, 1fr); }
  .nuevo-grid .btn { grid-column: 1 / -1; }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — MOBILE LARGE (max-width: 768px)
   ═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* ── Header / Top ─────────────────────────────────── */
  .top { padding: 10px 12px; gap: 10px; }
  .brand { gap: 8px; }
  .logo { width: 36px; height: 36px; border-radius: 10px; font-size: 13px; }
  .brand h1 { font-size: 16px; }
  .brand small { font-size: 11px; margin-top: 2px; }

  .rtp-top-right {
    margin-left: 0;
    position: static;
    order: -1;
    justify-content: flex-end;
  }
  .rtp-user-chip { font-size: 11px; padding: 3px 8px; }
  .rtp-config > summary { padding: 6px 10px; font-size: 12px; }

  .toolbar {
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .toolbar::-webkit-scrollbar { height: 0; }
  .toolbar .btn { font-size: 12px; padding: 7px 10px; flex-shrink: 0; }
  .toolbar select { font-size: 12px; padding: 6px 8px; flex-shrink: 0; }

  /* ── Tabs ─────────────────────────────────────────── */
  .tabs { padding: 0 12px 8px; gap: 4px; }
  .tab { padding: 7px 10px; font-size: 12px; }
  .kbd-hint { padding: 4px 12px 8px; font-size: 10px; }

  /* ── Main / Wrap ──────────────────────────────────── */
  main { padding: 4px 10px 12px; gap: 6px; }
  .wrap { padding: 14px 10px; }

  /* ── Sheet ────────────────────────────────────────── */
  .sheet-head { padding: 10px 12px; gap: 8px; }
  .sheet-title { font-size: 15px; }
  .hint { font-size: 12px; }
  .grid-wrap { max-height: calc(100vh - 220px); }

  /* ── Summary card ─────────────────────────────────── */
  .summary-card {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px; padding: 10px 12px;
  }
  .metric { padding: 8px; border-radius: 10px; }
  .metric span { font-size: 11px; }
  .metric .big { font-size: 16px; }

  /* ── Search bar ───────────────────────────────────── */
  .search-bar { padding: 6px 12px; gap: 6px; }
  .search-bar input { width: 100%; min-width: 0; flex: 1; font-size: 12px; }
  .search-bar label { font-size: 12px; }

  /* ── Stat grid ────────────────────────────────────── */
  .stat-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
  .stat { padding: 8px 10px; border-radius: 12px; }
  .stat .n { font-size: 22px; }
  .stat .l { font-size: 11px; }

  /* ── Cards ────────────────────────────────────────── */
  .cards { gap: 12px; margin-top: 12px; }
  .card { padding: 14px; border-radius: 12px; gap: 8px; }
  .card h3 { font-size: 15px; }
  .card .row { gap: 6px; }
  .card .row .btn { font-size: 11px; padding: 6px 8px; }

  /* ── Buttons ──────────────────────────────────────── */
  .btn { font-size: 12px; padding: 8px 10px; border-radius: 10px; }

  /* ── Form elements ────────────────────────────────── */
  .modal-box { padding: 18px; border-radius: 14px; margin: 10px; }

  /* ── Tabla (reports, history) ──────────────────────── */
  .tabla { font-size: 12px; }
  .tabla th, .tabla td { padding: 6px 8px; }
  .tabla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabla:not(.tabla-usuarios) { min-width: 640px; }

  /* ── Nuevo grid (usuarios alta) ────────────────────── */
  .nuevo-grid { grid-template-columns: 1fr; }
  .nuevo-grid .btn { width: 100%; justify-content: center; }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — MOBILE SMALL (max-width: 480px)
   ═══════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* ── Header ───────────────────────────────────────── */
  .top { padding: 8px 10px; gap: 8px; }
  .brand h1 { font-size: 14px; }
  .brand h1 span { display: none; }
  .brand small { font-size: 10px; display: none; }
  .logo { width: 32px; height: 32px; font-size: 12px; border-radius: 8px; }

  .rtp-user-chip { font-size: 10px; padding: 2px 6px; gap: 4px; }
  .rtp-config > summary { padding: 5px 8px; font-size: 11px; gap: 4px; }

  .toolbar .btn { font-size: 11px; padding: 6px 8px; }
  .toolbar select { font-size: 11px; padding: 5px 6px; }

  /* ── Tabs ─────────────────────────────────────────── */
  .tabs { gap: 3px; padding: 0 10px 6px; }
  .tab { padding: 6px 8px; font-size: 11px; border-radius: 10px; }

  /* ── Main / Wrap ──────────────────────────────────── */
  main { padding: 4px 8px 10px; }
  .wrap { padding: 10px 8px; }

  /* ── Summary card ─────────────────────────────────── */
  .summary-card { grid-template-columns: 1fr; gap: 6px; padding: 8px; }
  .metric { padding: 8px; }
  .metric input { padding: 5px 6px; font-size: 13px; }

  /* ── Stat grid ────────────────────────────────────── */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .stat .n { font-size: 20px; }
  .stat .l { font-size: 10px; }
  .stat { padding: 6px 8px; }

  /* ── Cards ────────────────────────────────────────── */
  .card { padding: 12px; }
  .card h3 { font-size: 14px; }
  .card .row { flex-direction: column; gap: 6px; }
  .card .row .btn { width: 100%; }

  /* ── Buttons ──────────────────────────────────────── */
  .btn { font-size: 11px; padding: 7px 8px; }
  .btn.sm { font-size: 10px; padding: 5px 7px; }

  /* ── Sheet ────────────────────────────────────────── */
  .sheet-title { font-size: 14px; }
  .sheet-head { padding: 8px 10px; }
  .grid-wrap { max-height: calc(100vh - 200px); }
  .sheet-table { font-size: 11px; }
  .sheet-table .name { min-width: 130px; max-width: 130px; width: 130px; }
  .sheet-table col:nth-child(2) { width: 130px !important; }
  .sheet-table td.name input { width: 126px; max-width: 126px; }
  .sheet-head .actions, .sheet-head .hint { font-size: 11px; }

  /* ── Search bar ───────────────────────────────────── */
  .search-bar { flex-direction: column; align-items: stretch; }
  .search-bar input { width: 100%; }
  .search-bar label { font-size: 11px; }

  /* ── Modal ────────────────────────────────────────── */
  .modal-bg { padding: 12px; }
  .modal-box { padding: 16px; border-radius: 12px; max-width: calc(100vw - 24px) !important; }

  /* ── Config menu ──────────────────────────────────── */
  .rtp-config-menu {
    position: fixed;
    left: 8px; right: 8px;
    top: auto; min-width: 0;
    width: auto; max-width: none;
    z-index: 200;
  }
  .rtp-config[open] > .rtp-config-menu { z-index: 200; }

  /* ── Toast ────────────────────────────────────────── */
  .toast {
    left: 10px; right: 10px; bottom: 10px;
    max-width: none; font-size: 12px;
    border-radius: 10px;
  }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — EXTRA SMALL (max-width: 360px)
   ═══════════════════════════════════════════════════════ */
@media (max-width: 360px) {
  .brand h1 { font-size: 13px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat .n { font-size: 18px; }
  .summary-card { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════
   PRINT STYLES
   ═══════════════════════════════════════════════════════ */
@media print {
  header, .tabs, .kbd-hint, .search-bar, .toast, .no-print, .sheet-head .actions { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .sheet { display: block !important; border: 0; box-shadow: none; border-radius: 0; page-break-after: always; }
  .grid-wrap { max-height: none; overflow: visible; }
  .sheet-table th { position: static; }
  .sheet-table .rownum, .sheet-table .name { position: static; }
  .sheet-table th, .sheet-table td { height: 22px; font-size: 9px; }
}
