:root {
  --bg: #f6f7f9; --card: #ffffff; --text: #1b1f24; --muted: #667085;
  --border: #d9dee5; --accent: #2457d6; --accent-bg: #e8eefc; --ok: #137a3f; --warn: #b26a00; --bad: #c0262d;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --card: #1a1f25; --text: #e7eaee; --muted: #98a2b3;
    --border: #2e3640; --accent: #6b93ff; --accent-bg: #1e2a47; --ok: #43c47a; --warn: #f0a530; --bad: #ff6b6b; }
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 640px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 1.5rem; margin: 0; }
p.sub { color: var(--muted); margin: 0 0 20px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.config { display: flex; gap: 12px; flex-wrap: wrap; }
.config label { flex: 1 1 140px; font-size: .85rem; color: var(--muted); }
input { width: 100%; padding: 8px 10px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Encabezado y usuario */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.userbar { display: flex; align-items: center; gap: 10px; font-size: .85rem; }
.user-name { font-weight: 600; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.user-name { color: var(--text); font-size: .85rem; }
.save-status { color: var(--muted); }
.save-status.saved { color: var(--ok); }
.save-status.offline { color: var(--warn); }

/* Login */
.auth { max-width: 400px; margin: 24px auto; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.auth-tabs button { flex: 1; border-color: transparent; color: var(--muted); }
.auth-tabs button.active { border-color: var(--accent); background: var(--accent-bg); color: var(--text); font-weight: 600; }
#authForm { display: flex; flex-direction: column; gap: 12px; }
#authForm label { font-size: .85rem; color: var(--muted); }
#authNotice { margin-bottom: 12px; }
.auth-title { font-size: 1.1rem; margin: 0 0 12px; }
button.link { border: 0; padding: 2px 0; background: none; color: var(--accent); font-size: .85rem; }
button.link:hover { text-decoration: underline; }
.ok-msg { color: var(--ok); font-size: .9rem; margin: 0; }

/* Mi cuenta */
.account-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.muted-block { display: block; color: var(--muted); font-size: .85rem; margin: 0; }
.account-form { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; margin-top: 4px; border-top: 1px solid var(--border); }
.account-form + .account-form { margin-top: 16px; }
.account-form label { font-size: .85rem; color: var(--muted); }
.account-form button { align-self: flex-start; }
.form-msg { font-size: .85rem; }
.form-msg:empty { display: none; }
.form-msg.ok { color: var(--ok); } .form-msg.bad { color: var(--bad); }
button.danger-btn { color: var(--bad); border-color: var(--bad); }
button.danger-btn:hover { background: var(--bad); color: #fff; }

/* Resumen del semestre */
.semestre .titulo { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.semestre .titulo b { font-size: .95rem; }
.semestre .hint { margin: 8px 0 0; font-size: .8rem; color: var(--muted); text-align: center; }
.semestre .stats { margin-bottom: 0; }

/* Evaluaciones */
/* Orden: ✓ · % · Nota · Evaluación · Fecha · Observación · ✕
   En celular: primera línea ✓ % Nota Evaluación ✕; segunda línea Fecha y Observación. */
.row { display: grid; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border);
  grid-template-columns: 26px 62px 56px minmax(0, 1fr) 36px; column-gap: 6px;
  grid-template-areas: "chk pct nota name del" "date date date obs adj" "files files files files files"; }
#rows .row:last-child { border-bottom: 0; }
.row .chk { grid-area: chk; } .row .ref { grid-area: name; } .row .f { grid-area: date; }
.row .pw { grid-area: pct; } .row .n { grid-area: nota; } .row .del { grid-area: del; }
.row .obs { grid-area: obs; font-size: .9rem; }
.row .adj { grid-area: adj; } .row .adjuntos { grid-area: files; }
.chk { width: 20px; height: 20px; margin: 0 auto; accent-color: var(--ok); cursor: pointer; }
.row .n { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.row:not(.confirmada) .n { border-style: dashed; color: var(--muted); font-weight: 400; }

/* Campo de porcentaje con el símbolo % fijo */
.pw { position: relative; display: block; }
.pw .p { text-align: right; padding-right: 24px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--accent-bg); border-color: var(--accent-bg); }
.pw .p:placeholder-shown { background: var(--bg); border-color: var(--border); font-weight: 400; }
.pw span { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted);
  font-size: .9rem; pointer-events: none; }
.pw .p::-webkit-inner-spin-button, .pw .p::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.pw .p { -moz-appearance: textfield; appearance: textfield; }

.head { display: none; font-size: .8rem; color: var(--muted); padding: 0 0 4px; border: 0; }
.head .hp { text-align: right; padding-right: 24px; }
.head .hn { text-align: right; padding-right: 10px; }

/* Fila de total de porcentajes */
.row.total { grid-template-areas: "sig sum msg msg msg"; border-bottom: 0; border-top: 2px solid var(--border);
  margin-top: 4px; padding: 10px 0 4px; }
.total .sig { grid-area: sig; text-align: center; color: var(--muted); font-weight: 600; }
.total .sum { grid-area: sum; text-align: right; padding-right: 10px; font-weight: 700; font-size: 1.1rem;
  font-variant-numeric: tabular-nums; }
.total .msg { grid-area: msg; font-size: .85rem; }
.total .bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: 4px; }
.total .bar i { display: block; height: 100%; background: var(--warn); border-radius: 3px; transition: width .2s; }
.total.ok .sum, .total.ok .msg { color: var(--ok); } .total.ok .bar i { background: var(--ok); }
.total.warn .sum, .total.warn .msg { color: var(--warn); }
.total.bad .sum, .total.bad .msg { color: var(--bad); } .total.bad .bar i { background: var(--bad); }

/* En pantallas anchas todo va en una sola línea */
@media (min-width: 760px) {
  main { max-width: 900px; }
  .row { grid-template-columns: 28px 82px 74px 1.4fr 150px 1.4fr 44px 36px;
    grid-template-areas: "chk pct nota name date obs adj del" ". files files files files files files ."; }
  .row.head { display: grid; grid-template-areas: none; padding: 0 0 4px; border: 0; }
  .row.total { grid-template-areas: "sig sum msg msg msg msg . ."; }
}
.sim { margin-top: 10px; font-size: .88rem; color: var(--muted); text-align: center; }
.sim b { color: var(--text); }

/* Botones */
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text); padding: 8px 12px; }
button:disabled { opacity: .6; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.small { font-size: .85rem; color: var(--muted); padding: 6px 10px; }
button.del { padding: 0; height: 36px; color: var(--muted); }
button.del:hover, button.danger:hover { color: var(--bad); border-color: var(--bad); }
button.add { width: 100%; border-style: dashed; color: var(--accent); margin-top: 4px; }
.actions { display: flex; justify-content: flex-end; margin-top: 8px; }

/* Resultados */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { text-align: center; }
.stat b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .78rem; color: var(--muted); }
.result { border-radius: 10px; padding: 14px; font-size: 1.05rem; text-align: center; border: 1px solid var(--border); }
.result strong { font-size: 1.8rem; display: block; font-variant-numeric: tabular-nums; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.error { color: var(--bad); font-size: .85rem; margin-top: 8px; }
.error:empty { margin: 0; }

/* Materias */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; }
.tab { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start; text-align: left;
  padding: 8px 14px; background: var(--card); max-width: 280px; }
.tab .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab small { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.tab small.ok { color: var(--ok); } .tab small.warn { color: var(--warn); } .tab small.bad { color: var(--bad); }
.tab.active { border-color: var(--accent); background: var(--accent-bg); }
.tab.new { justify-content: center; border-style: dashed; color: var(--accent); }
.materia-head { display: flex; gap: 8px; align-items: center; }
.materia-head input { font-size: 1.1rem; font-weight: 600; }
.materia-head button { flex: 0 0 auto; font-size: .85rem; color: var(--muted); }

/* Respaldo */
.backup { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: .9rem; }
.backup .sub-inline { display: block; color: var(--muted); font-size: .8rem; }
.backup-actions { display: flex; gap: 8px; }

/* Selector de vista: Materias | Calendario */
.views { display: flex; gap: 4px; padding: 4px; margin-bottom: 16px; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; }
.views button { flex: 1; border-color: transparent; color: var(--muted); }
.views button.active { background: var(--accent-bg); border-color: var(--accent); color: var(--text); font-weight: 600; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px;
  background: var(--warn); color: #fff; font-size: .75rem; font-weight: 700; line-height: 20px; }
.card-title { display: block; font-size: .95rem; margin-bottom: 10px; }
.semestre .proxima { margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--border); font-size: .88rem; text-align: center; }
.semestre .proxima button { font-size: .88rem; }

/* Agenda */
.agenda { display: flex; flex-direction: column; gap: 6px; }
.agenda .vacio { color: var(--muted); font-size: .9rem; margin: 0; }
.ev { --c: var(--accent); display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
  text-align: left; padding: 8px 12px; border-left: 4px solid var(--c); }
.ev:hover { background: var(--bg); }
.ev-fecha { text-align: center; line-height: 1.1; }
.ev-fecha b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.ev-fecha small { display: block; color: var(--muted); font-size: .7rem; text-transform: uppercase; white-space: nowrap; }
.ev-info { min-width: 0; }
.ev-info b, .ev-info small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-info small { color: var(--muted); font-size: .8rem; }
.ev-cuando { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.ev.hoy .ev-cuando { color: var(--bad); font-weight: 700; }
.ev.pronto .ev-cuando { color: var(--warn); font-weight: 600; }
.ev.pasada .ev-cuando { color: var(--bad); }

/* Mes */
.mes-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.mes-head b { flex: 1; }
.mes { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.mes-dow { font-size: .72rem; color: var(--muted); text-align: center; padding-bottom: 2px; }
.dia { min-height: 54px; padding: 3px; border-radius: 6px; background: var(--bg); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dia.otro { opacity: .45; }
.dia.hoy { outline: 2px solid var(--accent); outline-offset: -2px; }
.dia-num { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.dia.hoy .dia-num { color: var(--accent); font-weight: 700; }
.chip { --c: var(--accent); display: block; width: 100%; padding: 1px 4px; border: 0; border-left: 3px solid var(--c);
  border-radius: 3px; background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--text);
  font-size: .7rem; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.hecha { opacity: .55; text-decoration: line-through; }
.leyenda { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px; font-size: .8rem; color: var(--muted); }
.leyenda span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  margin-right: 5px; vertical-align: -1px; background: var(--c); }
@media (min-width: 760px) { .dia { min-height: 78px; } .chip { font-size: .75rem; } }

/* Resalta la evaluación al llegar desde el calendario */
.row.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { background: var(--accent-bg); } 100% { background: transparent; } }

/* Botón de instalar (PWA) */
.top h1 { flex: 1; }
button.install { font-size: .85rem; padding: 6px 12px; border-color: var(--accent); color: var(--accent); }
button.install:hover { background: var(--accent-bg); }
/* Instalada: deja espacio para la barra de estado del celular */
@media (display-mode: standalone) { main { padding-top: max(24px, env(safe-area-inset-top)); } }

/* Periodos */
.semestre .titulo { align-items: center; }
.periodo-sel { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.periodo-sel select { font: inherit; font-weight: 700; font-size: 1rem; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; }
.estado-periodo { font-size: .78rem; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.estado-periodo.curso { background: var(--accent-bg); color: var(--accent); }
.estado-periodo.cerrado { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 10px 14px; margin-bottom: 16px;
  border-radius: 10px; background: var(--accent-bg); border: 1px solid var(--accent); font-size: .9rem; }
input:disabled, button:disabled:not(.tab) { opacity: .6; cursor: not-allowed; }
.hint-center { margin: 8px 0 0; font-size: .8rem; color: var(--muted); text-align: center; }
button.accent { color: var(--accent); border-color: var(--accent); }
.periodos { display: flex; flex-direction: column; gap: 10px; }
.per { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.per.activo { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.per-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.per-nombre { font-size: 1.05rem; font-weight: 700; }
.per-top small { display: block; color: var(--muted); font-size: .8rem; }
.per-prom { text-align: right; }
.per-prom b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.per-prom small { color: var(--muted); font-size: .75rem; }
.per-mats { list-style: none; margin: 10px 0 0; padding: 8px 0 0; border-top: 1px dashed var(--border);
  display: grid; gap: 2px; font-size: .85rem; }
.per-mats li { display: flex; justify-content: space-between; gap: 12px; }
.per-mats li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.per-mats li b { font-variant-numeric: tabular-nums; }
.per-acc { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.per-acc button { font-size: .8rem; padding: 4px 10px; color: var(--muted); }
.per-acc button.abrir { color: var(--accent); border-color: var(--accent); }
.per-acc button.borrar:hover { color: var(--bad); border-color: var(--bad); }

/* Adjuntos */
button.adj { height: 36px; padding: 0 4px; font-size: .95rem; color: var(--muted); white-space: nowrap; }
button.adj.tiene { color: var(--accent); border-color: var(--accent); background: var(--accent-bg); }
button.adj[aria-expanded="true"] { border-color: var(--accent); }
.adj-n { font-size: .75rem; font-weight: 700; margin-left: 1px; }
.adj-n:empty { display: none; }
.adjuntos { margin-top: 2px; padding: 10px; border-radius: 10px; background: var(--bg); border: 1px dashed var(--border); }
.adj-lista { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.adj-item { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 8px; background: var(--card);
  border: 1px solid var(--border); min-width: 0; }
.adj-prev { flex: 0 0 52px; height: 52px; border-radius: 6px; overflow: hidden; display: grid; place-items: center;
  background: var(--bg); text-decoration: none; }
.adj-prev img { width: 100%; height: 100%; object-fit: cover; display: block; }
.adj-ico { font-size: .72rem; font-weight: 800; letter-spacing: .5px; color: #fff; background: var(--muted);
  padding: 4px 6px; border-radius: 4px; }
.adj-ico.pdf { background: #c0262d; } .adj-ico.word { background: #2b579a; }
.adj-ico.excel { background: #217346; } .adj-ico.ppt { background: #c43e1c; }
.adj-info { flex: 1; min-width: 0; font-size: .85rem; }
.adj-info > a { display: block; color: var(--text); text-decoration: none; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adj-info > a:hover { text-decoration: underline; }
.adj-info small { color: var(--muted); font-size: .75rem; }
.adj-info small a { color: var(--accent); }
.adj-del { flex: 0 0 auto; border: 0; padding: 4px 8px; color: var(--muted); }
.adj-del:hover { color: var(--bad); }
.adj-vacio { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: .85rem; }
.adj-add { display: block; margin-top: 8px; padding: 8px; text-align: center; border: 1px dashed var(--accent);
  border-radius: 8px; color: var(--accent); cursor: pointer; font-size: .9rem; }
.adj-add:hover { background: var(--accent-bg); }
.adj-add.ocupado { opacity: .6; pointer-events: none; }
.adj-estado { font-size: .82rem; margin-top: 6px; color: var(--muted); }
.adj-estado:empty { display: none; }
.adj-estado.bad { color: var(--bad); } .adj-estado.ok { color: var(--ok); }
.views button { white-space: nowrap; padding: 8px 6px; }
@media (max-width: 759px) {
  button.adj { font-size: .8rem; padding: 0 2px; }
  .adj-n { font-size: .7rem; }
}
