/* ==========================================================================
   Rutina — estilos globales (mobile-first, modo claro/oscuro automático)
   ========================================================================== */

:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f0f1f8;
  --border: #e2e4ef;
  --text: #1c1e2b;
  --text-muted: #6b6f85;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eceafd;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning-soft: #fef3c7;
  --warning-text: #92400e;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 40, 0.05), 0 4px 16px rgba(20, 22, 40, 0.06);
  --nav-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #20242f;
    --border: #2b3040;
    --text: #e8eaf2;
    --text-muted: #9298ad;
    --primary: #7c74ff;
    --primary-hover: #8f88ff;
    --primary-soft: #262447;
    --success: #22c55e;
    --success-soft: #12301f;
    --danger: #f87171;
    --danger-soft: #3a1a1d;
    --warning-soft: #3a2e12;
    --warning-text: #fcd34d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}

body.con-nav {
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}

h1, h2, h3 {
  line-height: 1.25;
  margin: 0;
}

a {
  color: var(--primary);
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Layout ---------- */

.contenedor {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.cabecera {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 16px 4px;
  max-width: 720px;
  margin: 0 auto;
}

.cabecera h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.tarjeta {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.tarjeta-titulo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tarjeta-titulo h2 {
  font-size: 1.1rem;
  font-weight: 650;
}

.texto-suave {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.fila {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.05s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primario {
  background: var(--primary);
  color: #fff;
}

.btn-primario:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secundario {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-secundario:hover:not(:disabled) {
  border-color: var(--primary);
}

.btn-peligro {
  background: transparent;
  color: var(--danger);
  border-color: var(--border);
}

.btn-peligro:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-fantasma {
  background: transparent;
  color: var(--text-muted);
}

.btn-fantasma:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.85rem;
}

.btn-bloque {
  width: 100%;
}

/* ---------- Formularios ---------- */

.campo {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.campo label,
.etiqueta {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.ayuda {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.mensaje {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 14px;
}

.mensaje-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.mensaje-info {
  background: var(--primary-soft);
  color: var(--primary);
}

.mensaje-aviso {
  background: var(--warning-soft);
  color: var(--warning-text);
}

/* Selector de días de la semana (chips) */
.dias-selector {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.dia-chip {
  position: relative;
}

.dia-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.dia-chip span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.dia-chip input:checked + span {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.dia-chip input:focus-visible + span {
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.atajos-dias {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* ---------- Pestañas ---------- */

.pestanas {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
}

.pestana {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.pestana[aria-selected='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- Pantalla de login ---------- */

.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 16px;
}

.auth-caja {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.marca {
  text-align: center;
  margin-bottom: 24px;
}

.marca-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.marca h1 {
  font-size: 1.6rem;
}

/* ---------- Listas ---------- */

.lista {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.item:first-child {
  border-top: none;
  padding-top: 0;
}

.item-cuerpo {
  flex: 1;
  min-width: 0;
}

.item-nombre {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
  align-items: center;
}

.item-acciones {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.item.archivada .item-nombre {
  color: var(--text-muted);
  text-decoration: line-through;
}

.etiqueta-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.etiqueta-pill.cat {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: transparent;
}

.etiqueta-pill.ok {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}

.vacio {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 8px;
  font-size: 0.95rem;
}

/* ---------- Tabla ---------- */

.tabla-wrap {
  overflow-x: auto;
  margin: 0 -18px;
  padding: 0 18px;
}

.tabla {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.tabla th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
}

.tabla td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tabla tr:last-child td {
  border-bottom: none;
}

.codigo {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 0.85rem;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
}

/* ---------- Interruptor ---------- */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* ---------- Diálogo (modal) ---------- */

dialog.modal {
  border: none;
  padding: 0;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius) var(--radius) 0 0;
  margin: auto auto 0;
  max-height: 92vh;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.2);
}

dialog.modal::backdrop {
  background: rgba(10, 12, 20, 0.5);
}

@media (min-width: 560px) {
  dialog.modal {
    margin: auto;
    border-radius: var(--radius);
  }
}

.modal-cuerpo {
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.modal-cabecera {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-cabecera h2 {
  font-size: 1.15rem;
}

.modal-pie {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* ---------- Navegación inferior ---------- */

.nav-inferior {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-inferior ul {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 720px;
  height: var(--nav-h);
}

.nav-inferior a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 100%;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

.nav-inferior a svg {
  width: 24px;
  height: 24px;
}

.nav-inferior a[aria-current='page'] {
  color: var(--primary);
}

/* ---------- Toast ---------- */

.toast-zona {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease-out;
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Pantallas más grandes ---------- */

@media (min-width: 720px) {
  .contenedor {
    padding: 24px 16px;
  }
  .tarjeta {
    padding: 22px;
  }
  .tabla-wrap {
    margin: 0 -22px;
    padding: 0 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}


/* ==========================================================================
   Vista "Hoy"
   ========================================================================== */

.nav-fecha {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.btn-icono {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
}

.btn-icono svg {
  width: 20px;
  height: 20px;
}

.fecha-actual {
  position: relative;
  flex: 1;
  text-align: center;
  min-width: 0;
}

.fecha-actual-texto {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

.fecha-actual-texto:hover {
  background: var(--surface-2);
}

.fecha-dia {
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: capitalize;
}

.fecha-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* input date invisible encima del texto: un toque abre el selector nativo */
.fecha-actual input[type='date'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: none;
}

.fecha-actual input[type='date']::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.segmentado {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.segmentado button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  min-height: 36px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.segmentado button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

/* Progreso */
.progreso-cabecera {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.progreso-porcentaje {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.barra {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.barra-relleno {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  transition: width 0.35s ease;
}

.barra-relleno.completa {
  background: linear-gradient(90deg, #16a34a, #22c55e);
}

.barra-fina {
  height: 6px;
}

/* Lista de tareas del día */
.tarea-dia {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.tarea-dia:first-child {
  border-top: none;
  padding-top: 2px;
}

.check {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.check-caja {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.check-caja svg {
  width: 16px;
  height: 16px;
  color: #fff;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s, transform 0.15s;
}

.check input:checked + .check-caja {
  background: var(--success);
  border-color: var(--success);
}

.check input:checked + .check-caja svg {
  opacity: 1;
  transform: scale(1);
}

.check input:focus-visible + .check-caja {
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.check:active .check-caja {
  transform: scale(0.92);
}

.check input:checked ~ .item-cuerpo .item-nombre {
  color: var(--text-muted);
  text-decoration: line-through;
}

.estado-texto {
  font-size: 0.75rem;
  font-weight: 600;
}

.estado-texto.pendiente {
  color: var(--text-muted);
}

.estado-texto.hecha {
  color: var(--success);
}

/* Botón flotante */
.fab {
  position: fixed;
  right: max(16px, calc((100vw - 720px) / 2 + 16px));
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 40;
  min-height: 52px;
  padding: 0 20px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
}

body.con-fab {
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 88px);
}

/* ==========================================================================
   Estadísticas
   ========================================================================== */

.nav-mes {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

.nav-mes h2 {
  font-size: 1.15rem;
  text-transform: capitalize;
}

.resumen-global {
  display: flex;
  align-items: center;
  gap: 18px;
}

.anillo {
  --p: 0;
  flex-shrink: 0;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--surface-2) 0);
  display: flex;
  align-items: center;
  justify-content: center;
}

.anillo span {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Calendario mapa de calor */
.calendario {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.cal-cabecera {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  padding-bottom: 4px;
}

.cal-dia {
  aspect-ratio: 1;
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  border: 2px solid transparent;
  transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.1;
}

.cal-dia:active {
  transform: scale(0.94);
}

.cal-dia small {
  font-size: 0.6rem;
  font-weight: 600;
  opacity: 0.85;
}

.cal-dia.vacio-dia {
  background: transparent;
}

.cal-dia.sin-tareas {
  color: var(--text-muted);
}

.cal-dia.futuro {
  opacity: 0.45;
}

.cal-dia.hoy {
  border-color: var(--text);
}

.nivel-0 { background: var(--heat-0); }
.nivel-1 { background: var(--heat-1); }
.nivel-2 { background: var(--heat-2); }
.nivel-3 { background: var(--heat-3); }
.nivel-4 { background: var(--heat-4); color: #fff; }
.nivel-5 { background: var(--heat-5); color: #fff; }

:root {
  --heat-0: #fde2e2;
  --heat-1: #e3f5e9;
  --heat-2: #b6e9c6;
  --heat-3: #7fd69e;
  --heat-4: #34b36a;
  --heat-5: #15803d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --heat-0: #4a1f24;
    --heat-1: #173524;
    --heat-2: #1d5233;
    --heat-3: #217343;
    --heat-4: #22994f;
    --heat-5: #2fc463;
  }
}

.leyenda {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.leyenda i {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
}

/* Desglose por tarea */
.desglose-item {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.desglose-item:first-child {
  border-top: none;
  padding-top: 0;
}

.desglose-fila {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}

.desglose-pct {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cargando {
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.15s;
}
