:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #5d6475;
  --accent: #e4572e;
  --accent-text: #ffffff;
  --border: #dde1ea;
  --error: #b42318;
  --notice-bg: #fff4d6;
  --notice-text: #5a4300;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #1a1d24;
    --text: #eef0f4;
    --muted: #a0a7b8;
    --accent: #ff7a50;
    --accent-text: #111;
    --border: #2b303b;
    --error: #ff8a80;
    --notice-bg: #3a3012;
    --notice-text: #ffe8a3;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.page { max-width: 640px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 420px; }
.brand { font-size: 2rem; margin: 24px 0 16px; }
.muted { color: var(--muted); }
.ai-notice {
  position: sticky; top: 0; z-index: 10; margin: 0;
  padding: 6px 16px; text-align: center; font-size: 0.85rem;
  background: var(--notice-bg); color: var(--notice-text);
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.stack { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
input, select, textarea {
  font: inherit; font-size: 17px; font-weight: 400; /* ≥16px: Safari no hace zoom al enfocar */
  min-height: 48px; padding: 10px 12px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
button { font: inherit; cursor: pointer; }
.btn-primary {
  min-height: 52px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; min-height: 48px; }
.error { color: var(--error); font-weight: 600; }
a { color: var(--accent); }
a.btn-primary { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.btn-secondary {
  min-height: 48px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.card {
  display: flex; flex-direction: column; gap: 12px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.ctx { padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.ctx p { margin: 4px 0; }
.ok { color: #1a7f37; font-weight: 700; }
@media (prefers-color-scheme: dark) { .ok { color: #6fdd8b; } }
textarea { resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row input { width: 100%; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 10px; min-height: 48px; font-weight: 600; }
label.check input { width: 24px; height: 24px; min-height: 0; }
.file-btn {
  flex-direction: row; justify-content: center; align-items: center; min-height: 48px;
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}
.file-btn input { max-width: 55%; min-height: 0; border: 0; padding: 0; font-size: 14px; }
.photo-preview { max-width: 100%; max-height: 240px; object-fit: contain; border-radius: 10px; }
#materia-form { margin-bottom: 16px; }
.hint { margin: -8px 0 0; font-size: 0.9rem; }
h2.section { margin: 24px 0 8px; }
.alert-box {
  padding: 12px 16px; border-radius: var(--radius); font-weight: 700;
  background: var(--notice-bg); color: var(--error); border: 1px solid var(--error);
}

/* --- Pantallas de Mateo -------------------------------------------------------- */
body.alumno { padding: 0; }
.app-shell {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.app-shell .ai-notice { padding-top: calc(6px + env(safe-area-inset-top)); flex: none; }
.app-main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; width: 100%; }
.tabbar {
  flex: none; display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--border); background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 56px; font-size: 0.8rem; color: var(--muted); text-decoration: none;
}
.tabbar a span { font-size: 1.3rem; line-height: 1.2; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.small { font-size: 0.9rem; }
.center { text-align: center; }

.mission { margin-bottom: 16px; }
.mission h2 { font-size: 1.3rem; margin: 0; }
.mission p { margin: 0; }
.mission-kicker { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.btn-launch { min-height: 64px; font-size: 1.15rem; margin-top: 8px; }

.app-main.chat { display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; overflow: hidden; }
.chat-head { padding: 10px 16px; border-bottom: 1px solid var(--border); flex: none; }
.messages {
  flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px;
  overscroll-behavior: contain;
}
.bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble p, .bubble ul, .bubble ol { margin: 0 0 8px; white-space: normal; }
.bubble > :last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { padding-left: 20px; }
.bubble code { font-size: 0.9em; background: var(--bg); padding: 0 4px; border-radius: 4px; }
.bubble.prof { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.bubble.typing::after { content: "• • •"; color: var(--muted); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.chat-error { margin: 0 16px; flex: none; }
.quick { display: flex; gap: 8px; overflow-x: auto; padding: 8px 16px 0; flex: none; }
.chip {
  flex: none; min-height: 48px; padding: 0 16px; border-radius: 24px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 0.95rem;
}
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 16px 10px; flex: none; }
.composer textarea { flex: 1; min-height: 48px; max-height: 140px; resize: none; border-radius: 24px; padding: 12px 16px; }
.btn-send {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-text); font-size: 1.2rem;
}
button:disabled, textarea:disabled { opacity: 0.5; }

/* --- Panel: navegación, historial y alertas ------------------------------------ */
.admin-nav {
  display: flex; gap: 4px; overflow-x: auto; padding: 0 12px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.admin-nav a {
  display: flex; align-items: center; min-height: 48px; padding: 0 12px;
  color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent;
}
.admin-nav a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
a.alert-box { display: block; text-decoration: none; }
.session-row {
  display: flex; align-items: center; gap: 8px; min-height: 48px; color: var(--text);
  text-decoration: none; border-bottom: 1px solid var(--border);
}
.session-row > span:first-child { flex: 1; }
.card-row { padding: 0 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
.badge { font-size: 0.85rem; font-weight: 700; color: var(--error); }
.transcript { padding: 0; overflow: visible; }
.transcript .bubble { max-width: 92%; }
.bubble .meta { font-size: 0.75rem; opacity: 0.75; margin-bottom: 4px; }
.bubble.flagged { outline: 3px solid var(--error); outline-offset: 2px; }
.bubble .flag { margin: 8px 0 0; font-weight: 700; white-space: normal; }
.alert-card { margin-bottom: 12px; border-color: var(--error); }
.alert-card.reviewed { border-color: var(--border); opacity: 0.75; }
.alert-card p { margin: 0; }
blockquote { margin: 0; padding: 8px 12px; border-left: 3px solid var(--border); white-space: pre-wrap; }
.actions { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.danger-zone { margin-top: 24px; }
.danger { color: var(--error); }
.transcript .bubble { white-space: normal; }
.transcript [data-md] { white-space: pre-wrap; }
.alert-box { margin: 0 0 16px; }
.quick { scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.day-picker { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 8px; scrollbar-width: none; }
.day-picker::-webkit-scrollbar { display: none; }
.day-picker a {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 52px; min-height: 56px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); text-decoration: none; font-size: 0.8rem;
}
.day-picker a strong { font-size: 1.1rem; }
.day-picker a[aria-current="page"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.eval-info { padding: 12px; border-radius: 10px; background: var(--bg); border: 1px dashed var(--border); }
.eval-info a { display: inline-block; margin-top: 6px; }
.eval-card { margin-bottom: 12px; }
.eval-card p { margin: 0; }
fieldset.chapters { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; margin: 0; }
fieldset.chapters legend { font-weight: 600; padding: 0 4px; }
fieldset.chapters label.check { font-weight: 400; }
.card + .card { margin-top: 16px; }
.eval-badge { font-weight: 700; color: var(--accent); }
.admin-nav { padding: 0 4px; gap: 0; scrollbar-width: none; }
.admin-nav::-webkit-scrollbar { display: none; }
.admin-nav a { padding: 0 9px; font-size: 0.95rem; }
