/* ============================================================
   THEME LAYER — modo oscuro editorial
   Estrategia: los tokens --ink/--paper son semánticos (frente /
   fondo), así que el swap invierte todo el sitio y con él el
   ritmo de paneles invertidos (contact, commerce-lab, plataforma),
   que pasan a claros sobre fondo oscuro. Los valores hardcodeados
   se corrigen con overrides quirúrgicos. Sin flash: el atributo
   data-theme lo fija un script inline en <head> antes del pintado.
   ============================================================ */

:root { color-scheme: light; }

:root[data-theme="dark"] {
  --ink: #e8e2d5;
  --paper: #191b17;
  --paper-deep: #131511;
  --sage: #8b9b7d;
  --sage-dark: #a8b699;
  --clay: #cf8a6c;
  --cyan: #8fb1b5;
  --ochre: #c7a86b;
  --plum: #a98b9f;
  --line: rgba(232, 226, 213, 0.16);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* ---------- Overrides de valores hardcodeados ---------- */

/* Botones y chips */
[data-theme="dark"] .button:hover { box-shadow: 0 10px 0 rgba(232, 226, 213, 0.12); }
[data-theme="dark"] .button-ghost { background: rgba(232, 226, 213, 0.07); }
[data-theme="dark"] .tech-list li { background: rgba(232, 226, 213, 0.08); }

/* Superficies de tarjeta: beige claro → tinte sutil sobre oscuro */
[data-theme="dark"] .project-card { background: rgba(232, 226, 213, 0.05); }
[data-theme="dark"] .commerce-lab { background: #20221e; }

/* La consola del hero conserva su look de terminal; solo separamos el borde */
[data-theme="dark"] .hero-console { border-color: rgba(232, 226, 213, 0.22); }

/* Paneles invertidos que ahora quedan claros: textos apagados oscuros */
[data-theme="dark"] .commerce-lab-code { color: #b19258; }
[data-theme="dark"] .commerce-lab h3 span { -webkit-text-stroke: 1px rgba(23, 25, 22, 0.6); }
[data-theme="dark"] .commerce-lab-intro { color: #5c5f55; }
[data-theme="dark"] .contact-code { -webkit-text-stroke: 1px rgba(23, 25, 22, 0.45); }
[data-theme="dark"] .contact-copy > p:not(.kicker) { color: #5c5f55; }
[data-theme="dark"] .button-dark { border-color: rgba(23, 25, 22, 0.45); }
[data-theme="dark"] .social-link { border-color: rgba(23, 25, 22, 0.45); }
[data-theme="dark"] .service-sheet-platform .service-tag,
[data-theme="dark"] .service-sheet-platform .service-deliverables li::marker { color: #5f6553; }
[data-theme="dark"] .service-sheet-platform .service-footer p { color: #6a6a5e; }

/* Caso de estudio: panel de arquitectura ahora claro */
[data-theme="dark"] .architecture-clients > div,
[data-theme="dark"] .architecture-layer { border-color: rgba(23, 25, 22, 0.35); }
[data-theme="dark"] .architecture small { color: #5f6553; }
[data-theme="dark"] .architecture figcaption { color: #5c5f55; }

/* Textos apagados sobre paper (ahora oscuro) */
[data-theme="dark"] .technology-breakdown dd { color: rgba(232, 226, 213, 0.68); }
[data-theme="dark"] .ledger-stats { color: rgba(232, 226, 213, 0.6); }
[data-theme="dark"] .project-host { text-decoration-color: rgba(168, 182, 153, 0.45); }
[data-theme="dark"] .project-link.subtle { color: rgba(232, 226, 213, 0.62); }
[data-theme="dark"] .project-state { border-color: rgba(168, 182, 153, 0.4); }

/* El mock del teléfono permanece oscuro en ambos temas */
[data-theme="dark"] .phone-frame { background: #171916; color: #e7e1d4; }

/* Acentos */
[data-theme="dark"] .hero-intro strong { background: linear-gradient(transparent 58%, rgba(207, 138, 108, 0.32) 58%); }
[data-theme="dark"] .status-dot {
  box-shadow: 0 0 0 5px rgba(168, 182, 153, 0.16);
  --status-pulse-color: rgba(168, 182, 153, 0.35);
}

/* ---------- Botón de tema ---------- */

.theme-toggle {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
  transition-property: background-color, color, border-color;
  transition-duration: 200ms;
  transition-timing-function: ease-out;
}

.theme-toggle:hover { color: var(--paper); background: var(--ink); }

.theme-toggle svg { width: 20px; height: 20px; overflow: visible; }

:root:not([data-theme="dark"]) .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }

@keyframes theme-icon-in {
  from { transform: rotate(-120deg) scale(0.55); opacity: 0; }
}

:root[data-theme="dark"] .theme-toggle .icon-moon,
:root:not([data-theme="dark"]) .theme-toggle .icon-sun {
  animation: theme-icon-in 320ms cubic-bezier(.2, .75, .25, 1) both;
}

/* Cabecera del caso de estudio: el link conserva su métrica junto al botón */
.case-header-actions { display: flex; align-items: center; gap: 0.75rem; }
.case-header-actions > a { min-height: 44px; display: inline-flex; align-items: center; font-size: 0.8rem; text-underline-offset: 5px; }

/* ---------- Transición suave durante el cambio de tema ---------- */

html.theme-anim,
html.theme-anim body,
html.theme-anim body * {
  transition-property: background-color, color, border-color, box-shadow, fill, stroke !important;
  transition-duration: 240ms !important;
  transition-timing-function: ease-out !important;
}

@media (prefers-reduced-motion: reduce) {
  html.theme-anim,
  html.theme-anim body,
  html.theme-anim body *,
  .theme-toggle,
  :root[data-theme="dark"] .theme-toggle .icon-moon,
  :root:not([data-theme="dark"]) .theme-toggle .icon-sun {
    transition: none !important;
    animation: none !important;
  }
}
