:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --text: #1c1c1e;
  --muted: #6a6a70;
  --line: #e4e4df;
  --accent: #2f54d6;
  --on-accent: #ffffff;
  --ok: #2b8a3e;
  --on-ok: #ffffff;
  --warn: #c2410c;
  --fc: #2f54d6;
  --fp: #0b7c8a;
  --poo: #6d3fd8;
  --est: #c4450c;
  --gen: #5c6370;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1a1a1d;
    --surface-2: #232327;
    --text: #ececef;
    --muted: #9b9ba3;
    --line: #2d2d32;
    --accent: #8ea6ff;
    --on-accent: #111113;
    --ok: #69db7c;
    --on-ok: #111113;
    --warn: #ff9f66;
    --fc: #8ea6ff;
    --fp: #4fd1dc;
    --poo: #b197fc;
    --est: #ff9f66;
    --gen: #a0a6b0;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3, h4 { letter-spacing: -0.01em; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; line-height: 1.25; }
.brand strong { font-size: 16px; }
.brand span { font-size: 12.5px; color: var(--muted); }
.account { display: flex; align-items: center; gap: 10px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; }
.sync { font-size: 12.5px; color: var(--muted); }
.sync-error, .sync-offline { color: var(--warn); }

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 16px 64px;
  display: grid;
  gap: 16px;
}
.loading { text-align: center; padding: 15vh 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.stack { display: grid; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Resumen */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.stat p { margin: 4px 0 0; }
.big {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.big span { font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; }

.bar { height: 6px; margin-top: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: inherit; background: var(--c, var(--accent)); transition: width 0.3s; }
.bar-ok { --c: var(--ok); }

.timer { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.timer select { flex: 1; min-width: 0; }
.timer-display { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; }
.timer.is-running .timer-display { color: var(--ok); }

.progress-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.prog { padding: 14px 16px; }
.prog-head { display: flex; justify-content: space-between; align-items: center; }
.prog-name { margin: 8px 0 0; font-weight: 600; font-size: 14px; }
.course-link { font-size: 12.5px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.course-link:hover { text-decoration: underline; }
.prog p.small { margin: 8px 0 0; }

/* Colores por asignatura */
.tone-fc, .tag-fc { --c: var(--fc); }
.tone-fp, .tag-fp { --c: var(--fp); }
.tone-poo, .tag-poo { --c: var(--poo); }
.tone-est, .tag-est { --c: var(--est); }
.tone-gen, .tag-gen { --c: var(--gen); }

.tag {
  display: inline-block;
  flex: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 1px 7px;
  border-radius: 6px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
}
.chip {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 9px;
  border-radius: 99px;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}
.chip-exam { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip-now { background: var(--accent); color: var(--on-accent); }

/* Esta semana */
.week-now-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.week-now h2 { margin: 0; font-size: 20px; }
.note { margin: 10px 0 0; padding: 8px 12px; background: var(--surface-2); border-radius: 10px; font-size: 14px; }
.overdue { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.overdue summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--warn); }

/* Casillas */
.checks { display: grid; gap: 1px; margin-top: 8px; }
.check {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  margin: 0 -8px;
  border-radius: 10px;
  cursor: pointer;
}
.check:hover { background: var(--surface-2); }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.box {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1.5px solid color-mix(in srgb, var(--muted) 55%, transparent);
  border-radius: 6px;
  background: var(--surface);
  transition: background 0.15s, border-color 0.15s;
}
.check input:checked + .box { background: var(--ok); border-color: var(--ok); }
.check input:checked + .box::after {
  content: "";
  width: 10px;
  height: 5px;
  border-left: 2px solid var(--on-ok);
  border-bottom: 2px solid var(--on-ok);
  transform: translateY(-1px) rotate(-45deg);
}
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
.check .label { min-width: 0; }
.check.is-done .label { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }

/* Pestañas */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  background: var(--surface-2);
  border-radius: 12px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Semanas */
.group-title { margin: 8px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.weeks, .milestones, .links, .breakdown { list-style: none; margin: 0; padding: 0; }
.weeks { display: grid; gap: 10px; margin-bottom: 16px; }
.week { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.week.is-now { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.week.is-past { opacity: 0.7; }
.week-exam { background: color-mix(in srgb, var(--warn) 5%, var(--surface)); }
.week-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.week-meta .count { margin-left: auto; }

/* Asignaturas */
.subject { display: grid; gap: 12px; }
.subject-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.subject-head h3 { margin: 0; font-size: 17px; }
.subject-head .muted { margin-left: auto; }
.facts { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 14px; }
.exam-pick { display: flex; flex-wrap: wrap; gap: 12px; padding: 12px; background: var(--surface-2); border-radius: 10px; }
.exam-pick label { flex: 1 1 200px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px 28px; }
.cols h4 { margin: 4px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

/* Formularios */
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
select, input[type="date"], input[type="number"], input[type="url"], input:not([type]) {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}
select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.form-row label { flex: 1 1 160px; }
.form-row .grow { flex: 3 1 240px; }
.form-title { flex-basis: 100%; margin: 0; font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-stop { background: var(--warn); border-color: var(--warn); color: var(--on-accent); }
.btn-stop:hover { background: color-mix(in srgb, var(--warn) 88%, black); }
.btn-small { padding: 6px 12px; font-size: 14px; }
.btn-ghost { font: inherit; font-size: 13px; padding: 4px 6px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.btn-ghost:hover { color: var(--text); }

/* Fechas */
.milestones { display: grid; gap: 10px; margin-bottom: 12px; }
.ms {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.ms-date { display: flex; flex-direction: column; gap: 2px; }
.ms-body p { margin: 0; }
.ms-body .checks { margin-top: 4px; }
.ms.is-past { opacity: 0.55; }
.ms-exam { border-left: 3px solid var(--warn); }

/* Recursos */
.links { display: grid; gap: 2px; margin-top: 8px; }
.links li { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.links li:last-child { border-bottom: 0; }
.links a { font-weight: 500; text-decoration: none; overflow-wrap: anywhere; }
.links a:hover { text-decoration: underline; }
.links .host { flex: none; }
.links .btn-ghost { margin-left: auto; }

.res-title { margin: 14px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

/* Google Drive */
.drive-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 12px; font-size: 14px; }
.drive-bar.card { justify-content: space-between; }
.drive-bar-text { flex: 1 1 320px; }
.drive-bar-text p { margin: 0 0 4px; }
.drive-bar .error { flex-basis: 100%; margin: 0; }
.drive-bar.is-on { padding: 0 2px; }
.drive-bar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.drive-box { margin-top: 6px; }
.drive-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.drive-head .res-title { margin: 8px 0 0; }
.drive-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.drive-actions label.btn { display: inline-flex; color: var(--text); font-size: 14px; }
.resource { transition: border-color 0.15s, background 0.15s; }
.resource.is-over { border-color: var(--accent); border-style: dashed; background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
/* Árbol de carpetas */
.tree { list-style: none; margin: 0; padding: 0; }
.drive-box > .tree { margin-top: 6px; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 3px 6px 3px calc(6px + var(--depth, 0) * 20px);
  border-radius: 8px;
}
.tree-row:hover { background: var(--surface-2); }
.tree-item[draggable="true"] > .tree-row { cursor: grab; }
.tree-item.is-over > .tree-row { background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.tree-msg { padding: 6px 6px 6px calc(6px + var(--depth, 0) * 20px + 28px); }
.tree-toggle {
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.tree-toggle::before { content: "▸"; display: inline-block; transition: transform 0.15s; }
.is-open > .tree-row .tree-toggle::before { transform: rotate(90deg); }
.tree-name {
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.tree-name::before { content: ""; display: inline-block; width: 14px; height: 11px; margin-right: 8px; border-radius: 2px 3px 3px 3px; background: color-mix(in srgb, var(--accent) 55%, var(--surface)); vertical-align: -1px; }
.tree-meta { flex: none; }
.tree-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; opacity: 0; transition: opacity 0.15s; }
.tree-row:hover .tree-actions, .tree-row:focus-within .tree-actions { opacity: 1; }
@media (hover: none) { .tree-actions { opacity: 1; } }
.tree-actions label.btn-ghost { display: inline; cursor: pointer; font-weight: 400; }
.file-open {
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 500;
  color: var(--accent);
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.file-open:hover { text-decoration: underline; }

/* Visor PDF */
body.viewer-open { overflow: hidden; }
.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.viewer[hidden] { display: none; }
.viewer-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.viewer-name { flex: 1 1 160px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; }
.viewer-status { font-size: 13px; color: var(--muted); }
.viewer-status.is-ok { color: var(--ok); }
.viewer-status.is-dirty, .viewer-status.is-warn { color: var(--warn); }
.viewer-status.is-error { color: var(--warn); font-weight: 600; }
.viewer-actions { display: flex; align-items: center; gap: 8px; }
.viewer-select { width: auto; padding: 5px 8px; font-size: 13.5px; }
.viewer-frame { flex: 1; width: 100%; border: 0; background: var(--surface-2); }
.ext {
  flex: none;
  min-width: 38px;
  font-size: 10.5px;
  font-weight: 700;
  text-align: center;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
}
.drop-hint { padding: 10px 0 2px; }

/* Tiempo */
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.chart-head p { margin: 0; }
.goal { display: flex; align-items: center; gap: 8px; }
.goal input { width: 72px; }
.hchart { position: relative; display: flex; align-items: flex-end; gap: 6px; height: 160px; margin-top: 18px; border-bottom: 1px solid var(--line); }
.hbar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.hbar-stack { display: flex; flex-direction: column-reverse; min-height: 2px; border-radius: 5px 5px 0 0; overflow: hidden; background: var(--surface-2); }
.hbar-stack span { background: var(--c); min-height: 2px; }
.goal-line { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--muted); pointer-events: none; }
.goal-line em { position: absolute; right: 0; top: -18px; font-size: 11.5px; font-style: normal; color: var(--muted); }
.hlabels { display: flex; gap: 6px; margin-top: 6px; }
.hlabels span { flex: 1; font-size: 11px; color: var(--muted); text-align: center; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.breakdown { display: grid; gap: 6px; margin-top: 8px; }
.breakdown li { display: flex; align-items: center; gap: 8px; }
.breakdown strong { margin-left: auto; font-variant-numeric: tabular-nums; }

.term-hint { margin: 16px 0 0; text-align: center; font-size: 13.5px; color: var(--muted); }
.term-hint .btn-ghost { color: var(--accent); }

/* Acceso */
.login { max-width: 420px; margin: 10vh auto 0; text-align: center; padding: 32px 24px; }
.login h1 { margin: 0 0 8px; font-size: 22px; }
.login .btn { margin-top: 12px; }
.error { color: var(--warn); font-size: 14px; }

@media (max-width: 560px) {
  .big { font-size: 32px; }
  .ms { grid-template-columns: 1fr; gap: 4px; }
  .hlabels span { font-size: 10px; }
}
