/* ============================================================
   Organizador de Finales — Studentlab · v2.0
   Sistema visual de Studentlab: papel cuadriculado, acento azul
   (#2B5FE3) y verde de identidad (#12A37B) como secundario.
   ============================================================ */

:root {
  /* Superficies */
  --paper: #f4f5f0;
  --surface: #ffffff;
  --surface-2: #f6f7f2;
  --line: #e3e6dd;

  /* Tinta */
  --ink: #16202e;
  --ink-soft: #4d586a;
  --ink-faint: #8a93a3;

  /* Acentos Studentlab */
  --blue: #2b5fe3;
  --blue-dark: #16367f;
  --blue-soft: #e9effd;
  --green: #12a37b;
  --green-dark: #0c7a5c;
  --green-soft: #e4f4ee;

  /* Escala de calor (urgencia). heat-0 = verde de identidad. */
  --heat-0: #12a37b;
  --heat-1: #6fae34;
  --heat-2: #e7b53f;
  --heat-3: #ef8a3c;
  --heat-4: #e0524d;

  /* Tipografía */
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, monospace;

  /* Forma */
  --radius: 18px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(22, 32, 46, 0.04), 0 10px 26px rgba(22, 32, 46, 0.07);
  --shadow-sm: 0 1px 2px rgba(22, 32, 46, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  padding: 24px clamp(14px, 4vw, 48px) 60px;

  /* Papel cuadriculado de Studentlab */
  background-color: #f4f5f0;
  background-image:
    linear-gradient(rgba(43, 95, 227, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(43, 95, 227, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(43, 95, 227, 0.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(43, 95, 227, 0.10) 1px, transparent 1px);
  background-size: 28px 28px, 28px 28px, 140px 140px, 140px 140px;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.01em; }

/* ---------- Barra de navegación al sitio ---------- */
.site-nav { max-width: 1240px; margin: 0 auto 18px; }
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-display); font-size: 0.85rem; font-weight: 600;
  color: var(--blue); text-decoration: none;
  padding: 7px 14px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-sm); transition: all .15s;
}
.back-link:hover { border-color: var(--blue); background: var(--blue-soft); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 20px; max-width: 1240px; margin: 0 auto 26px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand__mark {
  width: 40px; height: 40px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  filter: drop-shadow(0 4px 10px rgba(18, 163, 123, 0.30));
}
.brand__mark svg { display: block; }
.brand__title { font-size: 1.4rem; }
.brand__sub { color: var(--ink-soft); font-size: 0.88rem; }

.topbar__stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 14px; min-width: 84px; box-shadow: var(--shadow-sm);
}
.stat__num { font-family: var(--font-mono); font-size: 1.25rem; font-weight: 700; display: block; line-height: 1.1; }
.stat__lbl { font-family: var(--font-mono); font-size: 0.68rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- Layout ---------- */
.layout {
  max-width: 1240px; margin: 0 auto;
  display: grid; grid-template-columns: 340px 1fr; gap: 24px; align-items: start;
}
.col { display: flex; flex-direction: column; gap: 24px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.panel__title { font-size: 1.05rem; }
.panel__note { font-family: var(--font-mono); color: var(--ink-faint); font-size: 0.74rem; }
.panel__head, .cards-head, .calendar__head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px;
}
.cards-head { padding: 0 2px; }

/* ---------- Formulario ---------- */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 6px;
}
.field input {
  width: 100%; font-family: var(--font-body); font-size: 0.95rem; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 13px; transition: border-color .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.panel-form .panel__title { margin-bottom: 18px; }

.difficulty-picker { display: flex; gap: 8px; }
.diff-dot {
  flex: 1; height: 40px; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: var(--radius-sm); font-family: var(--font-mono); font-weight: 700;
  color: var(--ink-soft); cursor: pointer; transition: all .15s;
}
.diff-dot:hover { border-color: var(--blue); color: var(--blue); }
.diff-dot[aria-checked="true"] {
  background: var(--ink); color: #fff; border-color: var(--ink); transform: translateY(-1px);
}

.btn {
  font-family: var(--font-display); font-size: 0.95rem; font-weight: 600;
  border: none; border-radius: var(--radius-sm); padding: 13px; cursor: pointer; transition: all .15s;
}
.btn--primary { width: 100%; background: var(--blue); color: #fff; box-shadow: 0 4px 12px rgba(43, 95, 227, 0.26); }
.btn--primary:hover { background: var(--blue-dark); transform: translateY(-1px); }
.btn--primary:active { transform: translateY(0); }
.btn--ghost { background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--line); }
.btn--ghost:hover { border-color: var(--ink-faint); color: var(--ink); }
.btn--soft { width: 100%; background: var(--blue-soft); color: var(--blue-dark); }
.btn--soft:hover { background: #dce7fc; }

.form-actions { display: flex; gap: 10px; }
.form-actions .btn { flex: 1; }

.form-hint { color: var(--heat-4); font-size: 0.83rem; margin-top: 10px; }

/* ---------- Ranking ---------- */
.ranking { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.rank-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--heat-0);
}
.rank-item__pos { font-family: var(--font-mono); font-weight: 700; color: var(--ink-faint); width: 18px; text-align: center; }
.rank-item__body { flex: 1; min-width: 0; }
.rank-item__name { font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-item__meta { font-size: 0.76rem; color: var(--ink-soft); }
.rank-level { font-family: var(--font-display); font-size: 0.66rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.rank-item__score { font-family: var(--font-mono); font-weight: 700; font-size: 0.95rem; }

/* ---------- Tarjetas de materia ---------- */
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 16px; }
.subject-card {
  background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--heat-0);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px; position: relative;
}
.subject-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.subject-card__heading { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.subject-card__actions { display: flex; gap: 2px; flex-shrink: 0; }
.subject-card__name { font-size: 1.02rem; line-height: 1.25; }
.subject-card__date { color: var(--ink-soft); font-size: 0.8rem; margin-top: -6px; }

.urgency-tag {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-display); font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px 9px 3px 7px; border-radius: 99px; color: #fff;
}
.urgency-tag::before { content: ""; width: 6px; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.85); }

.icon-btn {
  border: none; background: transparent; color: var(--ink-faint);
  font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 7px; transition: all .15s;
}
.icon-btn:hover { color: var(--heat-4); background: #fdecec; }
.subject-card__edit:hover { color: var(--blue); background: var(--blue-soft); }

.countdown { display: flex; gap: 6px; }
.countdown__unit {
  flex: 1; text-align: center; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 4px;
}
.countdown__num { display: block; font-family: var(--font-mono); font-weight: 700; font-size: 1.3rem; line-height: 1; }
.countdown__lbl { font-family: var(--font-mono); font-size: 0.62rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.04em; }

.heat { display: flex; align-items: center; gap: 10px; }
.heat__bar { flex: 1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.heat__fill { display: block; height: 100%; border-radius: 99px; transition: width .4s ease; }
.heat__value { font-family: var(--font-mono); font-weight: 700; font-size: 0.85rem; min-width: 34px; text-align: right; }

.subject-card__foot { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; padding: 5px 10px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-soft);
}
.chip--hours { color: var(--blue-dark); background: var(--blue-soft); border-color: transparent; }
.chip--warn { color: #fff; background: var(--heat-3); border-color: transparent; }

/* Preparación (promedio de dominancia de temas) — acento verde */
.prep { display: flex; flex-direction: column; gap: 5px; }
.prep[hidden] { display: none; }
.prep__head { display: flex; align-items: baseline; justify-content: space-between; }
.prep__label { font-family: var(--font-mono); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.prep__value { font-family: var(--font-mono); font-weight: 700; font-size: 0.85rem; color: var(--green-dark); }
.prep__bar { height: 8px; background: var(--green-soft); border-radius: 99px; overflow: hidden; }
.prep__fill { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width .35s ease; }

.subject-card__themes { font-size: 0.88rem; padding: 10px; }

.subject-card.is-past { opacity: 0.62; }
.subject-card.is-past .countdown__num { color: var(--ink-faint); }

/* Estado vacío */
.empty {
  grid-column: 1 / -1; text-align: center; padding: 40px 20px;
  color: var(--ink-soft); border: 1.5px dashed var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, 0.5);
}
.empty strong { display: block; font-family: var(--font-display); color: var(--ink); margin-bottom: 4px; }

/* ---------- Calendario ---------- */
.calendar__nav { display: flex; align-items: center; gap: 10px; }
.calendar__label { font-family: var(--font-display); font-weight: 600; min-width: 130px; text-align: center; text-transform: capitalize; }
.nav-btn {
  width: 30px; height: 30px; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 8px; cursor: pointer; font-size: 1.1rem; color: var(--ink-soft); transition: all .15s;
}
.nav-btn:hover { border-color: var(--blue); color: var(--blue); }

.calendar__weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 8px; }
.calendar__weekdays span { text-align: center; font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700; color: var(--ink-faint); text-transform: uppercase; }

.calendar__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-day {
  aspect-ratio: 1 / 1; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 0.85rem; cursor: default; position: relative; transition: all .15s;
}
.cal-day.is-empty { border: none; background: transparent; }
.cal-day.is-today { box-shadow: inset 0 0 0 2px var(--blue); font-weight: 700; }
.cal-day.has-exam { cursor: pointer; }
.cal-day.has-exam:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.cal-day.is-selected { background: var(--ink); color: #fff; border-color: var(--ink); }
.cal-dots { display: flex; gap: 3px; }
.cal-dot { width: 6px; height: 6px; border-radius: 99px; }

.calendar__detail { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); min-height: 40px; }
.calendar__detail-empty { color: var(--ink-faint); font-size: 0.85rem; }
.cal-detail-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 0.9rem; }
.cal-detail-item .dot { width: 10px; height: 10px; border-radius: 99px; flex-shrink: 0; }
.cal-detail-item .name { font-weight: 600; }
.cal-detail-item .time { color: var(--ink-soft); margin-left: auto; font-family: var(--font-mono); font-size: 0.82rem; }

/* ---------- Modal de Temas ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(22, 32, 46, 0.45); backdrop-filter: blur(2px); }
.modal__panel {
  position: relative; width: min(560px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(22, 32, 46, 0.30); padding: 24px;
  animation: modal-in .18s ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal__title { font-size: 1.2rem; }
.modal__sub { color: var(--ink-soft); font-size: 0.85rem; margin-top: 2px; }

.prep--modal { margin-bottom: 18px; padding: 12px 14px; background: var(--green-soft); border-radius: var(--radius-sm); }

.theme-add { display: flex; gap: 8px; margin-bottom: 8px; }
.theme-add input {
  flex: 1; font-family: var(--font-body); font-size: 0.95rem; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px;
}
.theme-add input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.theme-add .btn { width: auto; flex-shrink: 0; }
.theme-legend { font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-faint); margin-bottom: 14px; }

.theme-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.theme-empty { color: var(--ink-faint); font-size: 0.88rem; text-align: center; padding: 18px; border: 1.5px dashed var(--line); border-radius: var(--radius-sm); }
.theme-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  border-left: 4px solid var(--heat-4);
}
.theme-item__body { flex: 1; min-width: 0; }
.theme-item__name { font-weight: 600; font-size: 0.95rem; word-break: break-word; }
.theme-item__hint { font-family: var(--font-mono); font-size: 0.68rem; color: var(--ink-faint); }
.dom-picker { display: flex; gap: 4px; margin-top: 6px; }
.dom-dot {
  width: 26px; height: 26px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 7px; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700;
  color: var(--ink-faint); cursor: pointer; transition: all .12s;
}
.dom-dot:hover { border-color: var(--green); }
.dom-dot.is-on { background: var(--green); border-color: var(--green); color: #fff; }
.theme-item__del { flex-shrink: 0; }

/* ---------- Footer ---------- */
.appfoot {
  max-width: 1240px; margin: 32px auto 0; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; font-size: 0.82rem; color: var(--ink-faint);
}
.link-btn { background: none; border: none; color: var(--ink-soft); cursor: pointer; text-decoration: underline; font-size: 0.82rem; font-family: var(--font-body); }
.link-btn:hover { color: var(--heat-4); }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .col--left { order: 2; }
}
@media (max-width: 480px) {
  .subject-grid { grid-template-columns: 1fr; }
  .topbar__stats { width: 100%; }
  .stat { flex: 1; min-width: 0; }
  .modal__panel { padding: 18px; }
  .theme-add { flex-wrap: wrap; }
  .theme-add .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
