/* ============================================================
   Recreos · sistema visual
   Iteración 1 — temas claro/oscuro y tokens
   Iteración 2 — jerarquía, superficies y elevación
   Iteración 3 — animaciones y micro-interacciones
   Iteración 4 — pulido (badges, foco, estados vacíos, scrollbar)
   ============================================================ */

/* ---------- tokens: tema claro (por defecto) ---------- */
:root {
  color-scheme: light dark;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e7eaef;
  --panel: var(--surface);
  --panel-2: var(--surface-2);
  --border: #dbe0e6;
  --border-strong: #c4ccd4;

  --text: #1b2028;
  --text-soft: #3c444e;
  --muted: #656d78;

  --accent: #1f6feb;
  --accent-soft: rgba(31, 111, 235, 0.10);

  --ok: #1a7f37;
  --warn: #9a6700;
  --danger: #cf222e;
  --prep: #6e7781;

  --c1: #0e7490;        /* Primer Ciclo — cian/petróleo */
  --c1-soft: rgba(14, 116, 144, 0.09);
  --c1-line: rgba(14, 116, 144, 0.28);
  --c2: #9333ea;        /* Segundo Ciclo — violeta */
  --c2-soft: rgba(147, 51, 234, 0.08);
  --c2-line: rgba(147, 51, 234, 0.26);

  --shadow-sm: 0 1px 2px rgba(16, 22, 26, 0.06), 0 1px 3px rgba(16, 22, 26, 0.07);
  --shadow-md: 0 4px 14px rgba(16, 22, 26, 0.10), 0 2px 4px rgba(16, 22, 26, 0.06);
  --shadow-lg: 0 16px 40px rgba(16, 22, 26, 0.18), 0 4px 10px rgba(16, 22, 26, 0.08);

  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 8px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- tokens: tema oscuro ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2333;
    --surface-3: #232d3b;
    --border: #2b323c;
    --border-strong: #444c56;

    --text: #e6edf3;
    --text-soft: #c9d1d9;
    --muted: #9198a1;

    --accent: #4c8dff;
    --accent-soft: rgba(76, 141, 255, 0.15);

    --ok: #3fb950;
    --warn: #d29922;
    --danger: #f85149;
    --prep: #8b949e;

    --c1: #56d0ec;
    --c1-soft: rgba(86, 208, 236, 0.12);
    --c1-line: rgba(86, 208, 236, 0.30);
    --c2: #d8a0f5;
    --c2-soft: rgba(216, 160, 245, 0.11);
    --c2-line: rgba(216, 160, 245, 0.28);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6), 0 6px 14px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2333;
  --surface-3: #232d3b;
  --border: #2b323c;
  --border-strong: #444c56;

  --text: #e6edf3;
  --text-soft: #c9d1d9;
  --muted: #9198a1;

  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.15);

  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --prep: #8b949e;

  --c1: #56d0ec;
  --c1-soft: rgba(86, 208, 236, 0.12);
  --c1-line: rgba(86, 208, 236, 0.30);
  --c2: #d8a0f5;
  --c2-soft: rgba(216, 160, 245, 0.11);
  --c2-line: rgba(216, 160, 245, 0.28);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6), 0 6px 14px rgba(0, 0, 0, 0.4);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s var(--ease), color 0.3s var(--ease);
}

a { color: var(--accent); text-decoration: none; transition: color 0.15s var(--ease); }
a:hover { text-decoration: underline; }

h1 { font-size: 25px; font-weight: 700; letter-spacing: -0.021em; }
h2 { font-size: 21px; font-weight: 650; letter-spacing: -0.015em; }
h3 { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent-soft); }

/* scrollbar sutil */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- botones ---------- */
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 13px;
  border-radius: var(--r-sm);
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease),
              box-shadow 0.15s var(--ease), transform 0.08s var(--ease), color 0.15s var(--ease);
}
button:hover { border-color: var(--border-strong); background: var(--surface-2); }
button:active { transform: translateY(1px) scale(0.99); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.ok:hover { filter: brightness(1.08); background: var(--ok); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); border-color: var(--border); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
button.tiny { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ---------- formularios ---------- */
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input[readonly] { color: var(--muted); background: var(--surface-2); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; font-weight: 500; }

/* ---------- topbar ---------- */
header.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 16px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
header.topbar .brand { font-weight: 750; font-size: 16px; letter-spacing: -0.01em; }
header.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
header.topbar nav button {
  background: transparent;
  border-color: transparent;
  color: var(--text-soft);
  padding: 7px 12px;
}
header.topbar nav button:hover { background: var(--surface-2); color: var(--text); }
header.topbar nav button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
header.topbar .who { color: var(--muted); font-size: 13px; }
.theme-toggle { font-size: 15px; line-height: 1; padding: 7px 10px; }
.theme-toggle:hover { transform: rotate(-12deg) scale(1.06); }

/* ---------- layout ---------- */
main { padding: 20px 16px 48px; max-width: 1220px; margin: 0 auto; animation: fade-in 0.3s var(--ease) both; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

/* ---------- leyenda ---------- */
.leyenda {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
  margin-bottom: 18px; flex-wrap: wrap;
}
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot.en_preparacion { background: var(--prep); }
.dot.en_curso { background: var(--warn); }
.dot.terminada { background: var(--ok); }
.leyenda-sep { width: 1px; height: 14px; background: var(--border-strong); margin: 0 6px; }
.leyenda-ciclo { display: inline-flex; align-items: center; gap: 5px; margin-right: 4px; font-weight: 600; }
.leyenda-ciclo.ciclo-primer_ciclo { color: var(--c1); }
.leyenda-ciclo.ciclo-primer_ciclo .dot { background: var(--c1); border-radius: 999px; }
.leyenda-ciclo.ciclo-segundo_ciclo { color: var(--c2); }
.leyenda-ciclo.ciclo-segundo_ciclo .dot { background: var(--c2); border-radius: 999px; }

/* ---------- calendario ---------- */
.week { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; }
@media (max-width: 900px) { .week { grid-template-columns: 1fr; gap: 22px; } }

.day-col {
  padding: 4px 6px 8px;
  border-radius: var(--r-lg);
  animation: fade-in-up 0.32s var(--ease) both;
}
.day-col:nth-child(1) { animation-delay: 0.02s; }
.day-col:nth-child(2) { animation-delay: 0.05s; }
.day-col:nth-child(3) { animation-delay: 0.08s; }
.day-col:nth-child(4) { animation-delay: 0.11s; }
.day-col:nth-child(5) { animation-delay: 0.14s; }
.day-col h3 {
  margin: 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 2px 8px;
  border-bottom: 1px solid var(--border);
}
.day-col h3 .d-nombre { font-size: 15px; font-weight: 700; }
.day-col h3 .d-fecha { font-size: 12px; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.day-col.hoy {
  background: var(--accent-soft);
  outline: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.day-col.hoy h3 { border-bottom-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.day-col.hoy h3 .d-nombre { color: var(--accent); }
.day-col.hoy h3 .d-nombre::after {
  content: "hoy";
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--accent); color: #fff;
  padding: 1px 5px; border-radius: 999px; margin-left: 7px; vertical-align: middle;
}

/* grupo por ciclo — franja de identidad */
.ciclo-grupo {
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  padding: 10px 0 2px 12px;
  margin-bottom: 16px;
}
.ciclo-grupo.ciclo-primer_ciclo {
  border-left-color: var(--c1);
  background: linear-gradient(96deg, var(--c1-soft), transparent 60%);
}
.ciclo-grupo.ciclo-segundo_ciclo {
  border-left-color: var(--c2);
  background: linear-gradient(96deg, var(--c2-soft), transparent 60%);
}
.ciclo-tag { display: flex; flex-direction: column; gap: 1px; margin-bottom: 10px; }
.ciclo-tag .ciclo-nombre {
  font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.09em; text-transform: uppercase;
}
.ciclo-primer_ciclo .ciclo-tag .ciclo-nombre { color: var(--c1); }
.ciclo-segundo_ciclo .ciclo-tag .ciclo-nombre { color: var(--c2); }
.ciclo-tag .ciclo-detalle { font-size: 11px; color: var(--muted); }

.bloque {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 11px 11px 9px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.18s var(--ease), border-color 0.18s var(--ease);
}
.ciclo-primer_ciclo .bloque { border-color: var(--c1-line); }
.ciclo-segundo_ciclo .bloque { border-color: var(--c2-line); }
.bloque-h {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; margin-bottom: 9px;
}
.bloque-h .bloque-nombre { font-size: 13px; font-weight: 650; color: var(--text); }
.bloque-h .bloque-hora {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.add-mini {
  width: 100%; font-size: 12px; padding: 6px;
  background: transparent; border-style: dashed; border-color: var(--border);
  color: var(--muted);
}
.add-mini:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- tarjetas de actividad ---------- */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--prep);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  margin-bottom: 7px;
  cursor: pointer;
  transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease), border-color 0.16s var(--ease);
}
.card.en_curso { border-left-color: var(--warn); }
.card.terminada { border-left-color: var(--ok); }
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.card:active { transform: translateY(0); }
.card .t { font-weight: 650; font-size: 14px; line-height: 1.3; margin-bottom: 3px; letter-spacing: -0.01em; }
.card .m { font-size: 12px; color: var(--muted); }
.card .badges { margin: 5px 0 3px; display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- badges (chips suaves) ---------- */
.badge {
  font-size: 11px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid transparent; background: var(--surface-3);
  color: var(--muted); white-space: nowrap; font-weight: 550;
}
.badge.en_preparacion { color: var(--prep); background: color-mix(in srgb, var(--prep) 14%, transparent); }
.badge.en_curso { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.badge.terminada { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.badge.mine { color: var(--accent); background: var(--accent-soft); }

.p-wrap { margin-top: 4px; }
.p-linea { font-size: 12px; margin-top: 3px; }
.pill {
  display: inline-block; background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 1px 8px; font-size: 11px; margin: 2px 3px 0 0;
}

/* ---------- lista ---------- */
.sec-h {
  margin: 22px 0 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
  color: var(--text-soft);
}
.lista-item {
  display: flex; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--prep);
  border-radius: var(--r-md);
  padding: 11px 13px;
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease), border-color 0.16s var(--ease);
}
.lista-item.en_curso { border-left-color: var(--warn); }
.lista-item.terminada { border-left-color: var(--ok); }
.lista-item.hoy { outline: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.lista-item.ciclo-primer_ciclo { border-right: 3px solid var(--c1); }
.lista-item.ciclo-segundo_ciclo { border-right: 3px solid var(--c2); }
.lista-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.lista-item:active { transform: translateY(0); }
.li-fecha {
  min-width: 96px; display: flex; flex-direction: column;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.li-main .t {
  font-weight: 650; font-size: 15px; letter-spacing: -0.01em;
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
}
.li-main .m { font-size: 12px; color: var(--muted); margin: 3px 0; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(9, 12, 16, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px; z-index: 50; overflow: auto;
  animation: fade-in 0.16s var(--ease) both;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  width: 100%; max-width: 520px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.22s var(--spring) both;
}
.modal h2 { margin: 0 0 14px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.actions .spacer { flex: 1; }

.segmented { display: flex; gap: 6px; }
.segmented button { flex: 1; }
.segmented button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.part-list { display: flex; flex-direction: column; gap: 5px; }
.part-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.part-row .muted { flex: 1; font-size: 12px; }

.adj-list { display: flex; flex-wrap: wrap; gap: 10px; }
.adj { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; max-width: 140px; }
.thumb {
  width: 120px; height: 90px; object-fit: cover;
  border-radius: var(--r-sm); border: 1px solid var(--border);
  transition: transform 0.16s var(--ease);
}
.thumb:hover { transform: scale(1.03); }

.recur {
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 12px; margin-top: 14px; background: var(--surface-2);
}
.recur-h { display: flex; align-items: center; margin: 0; color: var(--text); font-size: 14px; }
.recur-detalle { animation: fade-in-up 0.2s var(--ease) both; }
.dias { display: flex; gap: 12px; flex-wrap: wrap; }
.dia { display: flex; align-items: center; margin: 4px 0; color: var(--text); font-size: 13px; }

/* ---------- tabla ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
tr.clickable { cursor: pointer; transition: background 0.14s var(--ease); }
tr.clickable:hover { background: var(--surface-2); }

/* ---------- sync ---------- */
.sync-guia {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 4px 16px 14px; margin: 16px 0;
  box-shadow: var(--shadow-sm);
}
.sync-guia h3 { margin: 16px 0 4px; }
.sync-guia ol, .sync-guia li { font-size: 14px; color: var(--text-soft); }

/* ---------- login ---------- */
.login-wrap {
  max-width: 372px; margin: 12vh auto; padding: 28px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: modal-in 0.3s var(--spring) both;
}
.login-wrap h1 { margin-top: 0; }

/* ---------- utilidades ---------- */
.error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 1em; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.toast {
  position: fixed; bottom: 20px; left: 50%;
  background: var(--surface); border: 1px solid var(--border);
  padding: 11px 18px; border-radius: var(--r-md); z-index: 80;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.28s var(--spring) both;
}

/* ---------- keyframes ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
