:root {
  --bg: #f4f6f8; --card: #fff; --text: #1c2630; --soft: #66737f; --line: #e1e6eb;
  --brand: #1f5f8b; --brand-text: #fff;
  --ok: #17794a; --ok-bg: #e2f4ea; --warn: #8a5a00; --warn-bg: #fdf0d0;
  --bad: #b3261e; --bad-bg: #fde4e1; --info: #1f5f8b; --info-bg: #e1eef7; --muted-bg: #eceff2;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171c; --card: #1b232b; --text: #e8edf1; --soft: #97a4b0; --line: #2c3742;
    --brand: #4d9fd1; --brand-text: #08131b;
    --ok: #6fd19d; --ok-bg: #173527; --warn: #f0c261; --warn-bg: #3b2f10;
    --bad: #ff9a92; --bad-bg: #44201d; --info: #8cc4e8; --info-bg: #1a3345; --muted-bg: #27313b;
  }
}
:root[data-theme="dark"] {
    --bg: #12171c; --card: #1b232b; --text: #e8edf1; --soft: #97a4b0; --line: #2c3742;
    --brand: #4d9fd1; --brand-text: #08131b;
    --ok: #6fd19d; --ok-bg: #173527; --warn: #f0c261; --warn-bg: #3b2f10;
    --bad: #ff9a92; --bad-bg: #44201d; --info: #8cc4e8; --info-bg: #1a3345; --muted-bg: #27313b;
  }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.02rem; margin: 0; }
h3 { font-size: 1.15rem; margin: 0; }
p { margin: 0 0 .6rem; }
a { color: var(--brand); }

/* Estructura: barra lateral en pantallas anchas, barra inferior en el celular */
#app { display: flex; min-height: 100dvh; }
#nav {
  width: 210px; flex: none; padding: 20px 12px; background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100dvh;
}
#nav .brand { font-weight: 700; font-size: 1.15rem; padding: 4px 12px 16px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--soft); text-decoration: none; font-weight: 500;
}
#nav a.active { background: var(--info-bg); color: var(--info); }
#nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#main { flex: 1; min-width: 0; padding: 24px; max-width: 1000px; margin: 0 auto; }

@media (max-width: 699px) {
  #app { display: block; }
  #nav {
    position: fixed; inset: auto 0 0 0; z-index: 5; width: auto; height: auto; flex-direction: row;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line);
  }
  #nav .brand, #nav a[data-nav=ajustes] { display: none; }
  .only-mobile { display: inline-block !important; }
  #nav { gap: 0; padding-left: max(4px, env(safe-area-inset-left)); padding-right: max(4px, env(safe-area-inset-right)); }
  #nav a { flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 0; font-size: .68rem; }
  #nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  #main { padding: calc(16px + env(safe-area-inset-top)) 16px calc(90px + env(safe-area-inset-bottom)); }
}

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.page-head p { color: var(--soft); margin: 2px 0 0; }
.back { font-size: .9rem; text-decoration: none; }
.loading, .empty { color: var(--soft); padding: 8px 0; margin: 0; }
.soft { color: var(--soft); font-weight: 400; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.today { border-color: var(--brand); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h2::first-letter { text-transform: uppercase; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat span { display: block; color: var(--soft); font-size: .82rem; }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--bad); }

/* Botones */
.btn {
  font: inherit; font-weight: 600; font-size: .92rem; padding: 9px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text); white-space: nowrap;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.btn.small { padding: 6px 10px; font-size: .82rem; }
.btn.ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.btn.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.btn.warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: none; color: var(--soft); font-size: 1.1rem; padding: 6px 8px; cursor: pointer; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 16px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { font: inherit; font-size: .9rem; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--soft); cursor: pointer; }
.tab.active { background: var(--info-bg); color: var(--info); border-color: transparent; font-weight: 600; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.info { color: var(--info); background: var(--info-bg); }
.badge.muted { color: var(--soft); background: var(--muted-bg); }

/* Listas */
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 180px; }
.row-title { font-weight: 600; }
.row-title .time { display: inline-block; min-width: 3.4em; color: var(--brand); font-variant-numeric: tabular-nums; }
.row-title .amount { margin-left: 6px; font-variant-numeric: tabular-nums; }
.row-sub { color: var(--soft); font-size: .86rem; }
.row-notes { font-size: .9rem; margin-top: 2px; white-space: pre-wrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.clickable { cursor: pointer; }

.facts { margin: 0; display: grid; gap: 10px; }
.facts dt { color: var(--soft); font-size: .82rem; }
.facts dd { margin: 0; }

/* Tabla de estudiantes: se convierte en tarjetas en el celular */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th { text-align: left; color: var(--soft); font-weight: 500; font-size: .8rem; padding: 6px 10px; white-space: nowrap; }
td { padding: 10px; border-top: 1px solid var(--line); vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 699px) {
  thead { display: none; }
  tr { display: block; padding: 10px 0; border-top: 1px solid var(--line); }
  tr:first-child { border-top: 0; }
  td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 2px 0; text-align: right; }
  td::before { content: attr(data-label); color: var(--soft); font-size: .82rem; text-align: left; }
  td:first-child::before { content: none; }
  td:first-child { font-size: 1.02rem; }
}

/* Formularios */
label { font-size: .85rem; color: var(--soft); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 10px; width: 100%; min-height: 42px;
}
textarea { resize: vertical; }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: .95rem; }
.inline { display: inline-flex; align-items: center; gap: 8px; }
.inline input { width: auto; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field small { color: var(--soft); font-size: .78rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; overflow-y: auto; }
.field.full, .form-section { grid-column: 1 / -1; }
.form-section { margin: 8px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: .95rem; }
.sched { display: grid; gap: 6px; }
.sched-row { display: grid; grid-template-columns: 1.3fr 1.1fr .8fr auto auto; gap: 6px; align-items: center; }
.sched .unit { color: var(--soft); font-size: .85rem; }
.sched + .btn { align-self: flex-start; margin-top: 4px; }

dialog {
  border: 0; padding: 0; border-radius: 16px; background: var(--card); color: var(--text);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.modal-form { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal-form header, .modal-form footer { display: flex; align-items: center; gap: 8px; padding: 14px 16px; }
.modal-form header { justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-form footer { border-top: 1px solid var(--line); }
.spacer { flex: 1; }

.receipt-data { display: grid; gap: 8px; background: var(--bg); border-radius: 10px; padding: 12px; }
.receipt-data div { display: flex; align-items: center; gap: 10px; }
.receipt-data span { color: var(--soft); font-size: .82rem; width: 112px; flex: none; }
.receipt-step { margin: 14px 0 6px; font-size: .95rem; }
.receipt-links { margin: 14px 0 0; }
.receipt-links a { text-decoration: none; }
.receipt-data b { flex: 1; word-break: break-word; }

.login { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 14px; }
.error { color: var(--bad); margin: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 20;
}

/* Ingresos */
.only-mobile { display: none; text-decoration: none; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.small { font-size: .82rem; }
.split { display: flex; justify-content: space-between; gap: 12px; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter { height: 8px; margin: 6px 0 4px; }
.meter span { display: block; height: 100%; min-width: 3px; background: var(--brand); border-radius: 0 4px 4px 0; }
.bars { display: flex; gap: 2px; padding-top: 4px; }
.bar-col { flex: 1; min-width: 0; padding: 0; border: 0; background: none; color: var(--soft); font: inherit; cursor: pointer; }
.bar-area { height: 152px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; border-bottom: 1px solid var(--line); }
.bar { display: block; width: min(70%, 30px); background: var(--brand); opacity: .45; border-radius: 4px 4px 0 0; }
.bar-val { font-size: .72rem; font-variant-numeric: tabular-nums; color: var(--text); margin-bottom: 3px; }
.bar-lab { display: block; font-size: .72rem; padding-top: 5px; }
.bar-col:hover .bar, .bar-col.on .bar { opacity: 1; }
.bar-col.on .bar-lab { color: var(--text); font-weight: 700; }

.last-class { background: var(--bg); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; font-size: .92rem; }

/* Chips (habilidades trabajadas) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: .88rem; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }
.chip.active { background: var(--brand); border-color: var(--brand); color: var(--brand-text); font-weight: 600; }
.row-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 3px 0; }
.tag-meters { max-width: 420px; }

/* Color = estado: verde hecho/al día · ámbar pendiente · rojo requiere atención · azul programado · gris sin acción */
.row[class*="tone-"] { position: relative; padding-left: 14px; }
.row[class*="tone-"]::before { content: ""; position: absolute; left: 0; top: 11px; bottom: 11px; width: 4px; border-radius: 4px; background: var(--tone); }
.tone-ok { --tone: var(--ok); } .tone-warn { --tone: var(--warn); } .tone-bad { --tone: var(--bad); }
.tone-info { --tone: var(--brand); } .tone-muted { --tone: var(--soft); }
.tone-muted::before { opacity: .45; }
.stat.ok b { color: var(--ok); }
.stat.zero b { color: var(--soft); }

/* Progreso de simulacros */
.score-chart { display: block; width: 100%; max-width: 520px; height: auto; margin-bottom: 8px; overflow: visible; }
.score-chart .trend { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.score-chart circle { fill: var(--brand); stroke: var(--bg); stroke-width: 2; }
.score-chart .goal { stroke: var(--soft); stroke-width: 1; stroke-dasharray: 4 4; }
.score-chart text { font-size: 11px; fill: var(--soft); }
.score-chart text.val { fill: var(--text); font-weight: 700; font-size: 12px; }
.parts-progress { display: grid; gap: 6px; max-width: 520px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }

/* Calendario (vista de mes) */
.cal-title { min-width: 9.5em; text-align: center; font-size: 1.05rem; }
.cal-title::first-letter { text-transform: uppercase; }
.cal-card { padding: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cal-head span { text-align: center; font-size: .75rem; color: var(--soft); padding: 2px 0 6px; }
.cal-cell {
  font: inherit; color: var(--text); background: none; border: 1px solid transparent; border-radius: 12px; cursor: pointer;
  min-height: 58px; padding: 5px 2px; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0;
}
.cal-cell.out { opacity: .38; }
.cal-num { font-size: .9rem; font-variant-numeric: tabular-nums; width: 26px; height: 26px; line-height: 26px; text-align: center; border-radius: 50%; }
.cal-cell.today .cal-num { background: var(--brand); color: var(--brand-text); font-weight: 700; }
.cal-cell.sel { border-color: var(--brand); background: var(--info-bg); }
.cal-dots { display: flex; gap: 3px; align-items: center; min-height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--tone); }
.tone-muted.dot { opacity: .5; }
.cal-dots .more, .cal-line.more { font-size: .65rem; font-style: normal; color: var(--soft); }
.cal-marks { display: flex; gap: 4px; min-height: 12px; }
.mark { font-style: normal; font-size: .62rem; font-weight: 700; line-height: 12px; color: var(--tone); }
.cal-lines { display: none; }
@media (min-width: 900px) {
  .cal-cell { min-height: 104px; align-items: stretch; padding: 6px; }
  .cal-dots { display: none; }
  .cal-lines { display: grid; gap: 2px; }
  .cal-line { font-size: .74rem; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 7px; border-left: 3px solid var(--tone); border-radius: 2px; }
  .cal-line.more { border: 0; }
  .cal-marks { margin-top: auto; }
}
