:root {
  --bg: #f6f3ee;
  --surface: #fffdf9;
  --surface-2: #f0ebe3;
  --border: #e2dacd;
  --text: #1f2430;
  --muted: #6b6f7b;
  --accent: #8a3b2e;
  --accent-soft: #f3e1dc;
  --ok: #2f7a50;
  --ok-soft: #e1f0e6;
  --warn: #9a6a12;
  --warn-soft: #f7ecd2;
  --bad: #b13a2a;
  --bad-soft: #f8e0db;
  --hw: #b4530a;
  --hw-soft: #fde8d4;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 6px 20px rgba(40, 30, 20, .06);
  --radius: 14px;
  --serif: "Source Serif 4", Georgia, serif;
  --display: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c; --surface: #1f2126; --surface-2: #272a31; --border: #343843;
    --text: #e9e6e1; --muted: #9aa0ab; --accent: #e08a74; --accent-soft: #3a2621;
    --ok: #7cc79a; --ok-soft: #1f3327; --warn: #e3b75c; --warn-soft: #3a3020;
    --bad: #ef8a7a; --bad-soft: #3d2420; --hw: #f4a261; --hw-soft: #3d2a19; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); font-weight: 650; letter-spacing: -.01em; margin: 0; }
.muted { color: var(--muted); }
.container { max-width: 1180px; margin: 0 auto; padding: 28px 20px 60px; }

/* Marca */
.brand { font-family: var(--display); font-weight: 650; font-size: 21px; color: var(--text); text-decoration: none; }
.brand span { color: var(--accent); }
.brand.big { font-size: 34px; }

/* Barra superior */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--surface-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 5px 12px; border-radius: 999px; font: 500 13px var(--sans); cursor: pointer; text-decoration: none; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.on .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.pill.credits { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* Botones y formularios */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 9px 16px; border-radius: 10px; font: 500 14px var(--sans);
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.field { display: grid; gap: 5px; font-weight: 500; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
input, select, textarea { font: 15px var(--sans); color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
textarea { font: 13px/1.45 ui-monospace, Consolas, monospace; min-height: 120px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > .field { flex: 1; min-width: 160px; }
.error { color: var(--bad); background: var(--bad-soft); padding: 8px 12px; border-radius: 8px; font-size: 14px; }

/* Acceso */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 32px; box-shadow: var(--shadow); }
.auth-card .tabs { margin: 22px 0 18px; }

/* Cabecera de página */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 30px; }
.page-head p { margin: 4px 0 0; }
.crumb { font-size: 13px; color: var(--muted); text-decoration: none; }

/* Tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.subject-card { display: flex; flex-direction: column; gap: 10px; min-height: 150px; text-decoration: none; color: var(--text);
  transition: transform .15s, border-color .15s; }
.subject-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.subject-card h3 { font-size: 19px; line-height: 1.25; }
.subject-card .meta { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.subject-card.new { border-style: dashed; box-shadow: none; background: transparent; align-items: center; justify-content: center; color: var(--muted); cursor: pointer; font-weight: 500; }
.subject-card.new .plus { font-size: 30px; line-height: 1; color: var(--accent); }
.tag { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

/* Sesión del campus */
.campus-box { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 26px; }
.campus-box h3 { font-size: 17px; }
.campus-box p { margin: 3px 0 0; font-size: 14px; }
.campus-box.on { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }

/* Pestañas */
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 11px; }
.tab { border: 0; background: transparent; padding: 7px 16px; border-radius: 8px; font: 500 14px var(--sans); color: var(--muted); cursor: pointer; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tabs.small .tab { padding: 6px 14px; }
.auth-card .tabs { display: flex; } .auth-card .tab { flex: 1; }

/* Biblioteca de la asignatura */
.library { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
.lecture-list { padding: 10px; max-height: calc(100vh - 220px); overflow: auto; position: sticky; top: 76px; }
.lecture-list input { margin-bottom: 8px; }
.lecture-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: 10px;
  cursor: pointer; color: var(--text); font: 14px var(--sans); }
.lecture-item:hover { background: var(--surface-2); }
.lecture-item.active { background: var(--accent-soft); }
.lecture-item .t { font-weight: 600; display: block; }
.lecture-item .d { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.reader { padding: 28px 36px; min-height: 60vh; }
.reader-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 22px; }
.reader-head h2 { font-size: 24px; }
.prose { font: 17px/1.7 var(--serif); max-width: 74ch; }
.prose h1, .prose h2, .prose h3 { font-family: var(--display); margin: 1.5em 0 .5em; line-height: 1.25; }
.prose h2 { font-size: 22px; } .prose h3 { font-size: 18px; }
.prose p, .prose ul, .prose ol { margin: 0 0 1em; }
.prose li { margin: .2em 0; }
.prose mark { background: var(--warn-soft); color: inherit; padding: 0 2px; border-radius: 3px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* Peticiones */
.jobs { display: grid; gap: 10px; }
.job { padding: 14px 16px; }
.job-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.job-top .grow { flex: 1; min-width: 180px; }
.status { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.status.running, .status.queued { background: var(--warn-soft); color: var(--warn); }
.status.done { background: var(--ok-soft); color: var(--ok); }
.status.failed, .status.session_expired, .status.no_credits { background: var(--bad-soft); color: var(--bad); }
.progress { height: 5px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s; }
.progress.indeterminate > div { width: 30% !important; animation: slide 1.4s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.job details { margin-top: 8px; font-size: 13px; }
.job pre { white-space: pre-wrap; font: 12px/1.5 ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 260px; overflow: auto; }
.job .err { color: var(--bad); font-size: 14px; margin: 8px 0 0; }
.section-title { font-size: 18px; margin: 34px 0 12px; }

/* Créditos */
.packs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.pack { text-align: center; }
.pack .price { font-family: var(--display); font-size: 30px; margin: 6px 0; }
.balance { font-family: var(--display); font-size: 44px; line-height: 1; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.selected td { background: var(--accent-soft); }
tfoot td, tfoot th { border-bottom: 0; }
tfoot th { color: var(--text); font-weight: 600; }
.auth-title { font-size: 20px; margin: 22px 0 14px; }
.card table { display: table; }
@media (max-width: 860px) { .card:has(> table) { overflow-x: auto; } }
.pos { color: var(--ok); } .neg { color: var(--bad); }

/* Modal y avisos */
dialog { border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(20, 15, 10, .45); }
#modal-body { padding: 26px; }
#modal-body h2 { font-size: 22px; margin-bottom: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.hint { font-size: 13px; color: var(--muted); }
.steps { margin: 8px 0 14px; padding-left: 20px; font-size: 14px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px;
  border-radius: 10px; font-size: 14px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }

@media (max-width: 860px) {
  .library { grid-template-columns: 1fr; }
  .lecture-list { position: static; max-height: 300px; }
  .reader { padding: 20px 18px; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .topbar-right { margin-left: 0; width: 100%; }
  .container { padding: 20px 16px 50px; }
  #campus-pill-text { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ---------- Navegación ---------- */
.nav a { display: inline-flex; align-items: center; gap: 6px; }
.nav-badge { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.nav-badge.bad { background: var(--bad-soft); color: var(--bad); }
.nav-badge:empty { display: none; }
.user { position: relative; }
.avatar { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font: 600 15px var(--sans); cursor: pointer; }
.user-menu, .dropdown-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 230px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; display: grid; gap: 2px; }
.user-menu b { padding: 4px 10px 0; }
.user-menu .hint { padding: 0 10px 4px; }
.user-menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; width: 100%; }
.user-menu button, .dropdown-menu button { text-align: left; border: 0; background: transparent; color: var(--text); padding: 8px 10px; border-radius: 8px;
  font: 14px var(--sans); cursor: pointer; display: grid; gap: 2px; }
.user-menu button:hover, .dropdown-menu button:hover { background: var(--surface-2); }
.dropdown { position: relative; }
.dropdown-menu { min-width: 260px; }

/* ---------- Etiquetas y fechas ---------- */
.chip { display: inline-flex; align-items: center; font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.warn, .tag.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.hw { background: var(--hw-soft); color: var(--hw); }
.hint .kind-obligatoria { color: var(--bad); }
.hint .kind-deberes { color: var(--hw); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; line-height: 20px; text-align: center; }

/* ---------- Portada ---------- */
.home-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.home-grid .side { position: sticky; top: 76px; }
.side h3 { font-size: 16px; margin-bottom: 8px; }
.up-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 6px; border-radius: 8px; text-decoration: none; color: var(--text); }
.up-item:hover { background: var(--surface-2); }
.up-text { display: grid; gap: 1px; font-size: 14px; min-width: 0; }
.up-item .chip { margin-top: 1px; flex-shrink: 0; }

/* ---------- Asignatura ---------- */
.subject-tabs { display: flex; flex-wrap: wrap; margin-bottom: 18px; }
.subject-tabs .tab { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
#jobs:not(:empty) { margin-bottom: 18px; }
.group-title { font-size: 15px; font-family: var(--sans); font-weight: 600; margin: 18px 0 8px; }
.tasks-layout { display: grid; grid-template-columns: 1fr 360px; gap: 18px; align-items: start; }
.task { display: flex; gap: 12px; align-items: flex-start; padding: 10px 8px; border-top: 1px solid var(--border); }
.task .check { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.task-main { flex: 1; min-width: 0; }
.task-top { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.task.done .task-top b { text-decoration: line-through; color: var(--muted); }
.task.kind-obligatoria:not(.done) { box-shadow: inset 3px 0 var(--bad); }
.task.kind-deberes:not(.done) { box-shadow: inset 3px 0 var(--hw); }
details.past { margin: 4px 0 6px; }
details.past summary { cursor: pointer; padding: 4px 8px; }
details.past .task { opacity: .7; }
.task-actions { display: flex; gap: 2px; opacity: .55; }
.task:hover .task-actions { opacity: 1; }
.history { margin: 4px 0 0; font-size: 13px; color: var(--warn); }
.notice { padding: 12px 0; border-top: 1px solid var(--border); }
.notice p { margin: 6px 0; font-size: 14px; }
.prose.small { font-size: 15px; line-height: 1.6; }
.resource-group { margin-bottom: 14px; }
.resource { display: flex; gap: 12px; align-items: center; padding: 9px 4px; border-top: 1px solid var(--border); }
.r-icon { font-size: 20px; }
.r-main { flex: 1; display: grid; min-width: 0; }
.r-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-actions { display: flex; gap: 6px; flex-shrink: 0; }
label.btn { cursor: pointer; }
.plan-layout { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
.plan-layout > aside { position: sticky; top: 76px; }

@media (max-width: 960px) {
  .home-grid, .tasks-layout, .plan-layout { grid-template-columns: 1fr; }
  .home-grid .side, .plan-layout > aside { position: static; }
}
@media (max-width: 860px) {
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .topbar-right { width: auto; margin-left: auto; }
  .resource { flex-wrap: wrap; }
  .r-actions { width: 100%; justify-content: flex-end; }
}
