/* ----------------------------------------------------------------------------
   ACE NUTRITIONS. — Hoja de Componente 21
   Extraida de `tokens.css` en la Iteracion 07.7 (Regla #011).
   El ORDEN de carga en `app-shell.html` reproduce el del archivo original:
   la cascada CSS depende de el y no debe alterarse.
   -------------------------------------------------------------------------- */
/* ==========================================================================
   ARMONÍA VISUAL EN /STUDIO Y SISTEMA DE DISEÑO UNIFICADO DE CONTROLES
   (Checkboxes, Radios, Switches, Sliders, Selects, Swatches y Simetría de Paneles)
   ========================================================================== */

/* 1. CHECKBOXES Y RADIOS VECTORIALES CON TEMA (CERO CONTROLES NATIVOS SIN TEMA) */
input[type="checkbox"]:not(.cz-switch-input),
input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  vertical-align: middle;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.12s ease;
}

input[type="checkbox"]:not(.cz-switch-input) {
  border-radius: 5px;
}

input[type="radio"] {
  border-radius: 999px;
}

input[type="checkbox"]:not(.cz-switch-input):hover,
input[type="radio"]:hover {
  border-color: var(--jade);
  box-shadow: 0 0 0 3px var(--jade-soft);
}

input[type="checkbox"]:not(.cz-switch-input):focus-visible,
input[type="radio"]:focus-visible {
  outline: none;
  border-color: var(--jade);
  box-shadow: 0 0 0 3px var(--jade-soft);
}

input[type="checkbox"]:not(.cz-switch-input):checked {
  background: var(--jade);
  border-color: var(--jade);
}

input[type="checkbox"]:not(.cz-switch-input):checked::after {
  content: "";
  display: block;
  width: 5px;
  height: 9px;
  border-right: 2px solid rgb(255, 255, 255);
  border-bottom: 2px solid rgb(255, 255, 255);
  transform: rotate(45deg) translate(-0.5px, -1px);
}

input[type="radio"]:checked {
  border-color: var(--jade);
  background: var(--bg-surface);
}

input[type="radio"]:checked::after {
  content: "";
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--jade);
}

/* Adaptación automática para vistas oscuras (/landing, /auth/*, /calculadora) */
body[data-active-page="landing"] input[type="checkbox"]:not(.cz-switch-input),
body[data-active-page^="auth"] input[type="checkbox"]:not(.cz-switch-input),
body[data-active-page="calculator"] input[type="checkbox"]:not(.cz-switch-input),
body[data-active-page="landing"] input[type="radio"],
body[data-active-page^="auth"] input[type="radio"],
body[data-active-page="calculator"] input[type="radio"] {
  background: rgb(11, 14, 20);
  border-color: rgba(148, 163, 184, 0.45);
}

body[data-active-page="landing"] input[type="checkbox"]:not(.cz-switch-input):hover,
body[data-active-page^="auth"] input[type="checkbox"]:not(.cz-switch-input):hover,
body[data-active-page="calculator"] input[type="checkbox"]:not(.cz-switch-input):hover {
  border-color: rgb(34, 199, 240);
  box-shadow: 0 0 0 3px rgba(34, 199, 240, 0.18);
}

body[data-active-page="landing"] input[type="checkbox"]:not(.cz-switch-input):checked,
body[data-active-page^="auth"] input[type="checkbox"]:not(.cz-switch-input):checked,
body[data-active-page="calculator"] input[type="checkbox"]:not(.cz-switch-input):checked {
  background: rgb(34, 199, 240);
  border-color: rgb(34, 199, 240);
}

body[data-active-page="landing"] input[type="checkbox"]:not(.cz-switch-input):checked::after,
body[data-active-page^="auth"] input[type="checkbox"]:not(.cz-switch-input):checked::after,
body[data-active-page="calculator"] input[type="checkbox"]:not(.cz-switch-input):checked::after {
  border-right-color: rgb(4, 16, 22);
  border-bottom-color: rgb(4, 16, 22);
}

/* 2. TARJETAS INTERACTIVAS DE CHECKBOX Y RADIO (.ace-check-grid, .ace-check-card, .ace-check-item) */
.ace-check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ace-check-card,
.ace-check-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--bg-studio);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.ace-check-card:hover,
.ace-check-item:hover {
  border-color: var(--jade);
  background: var(--bg-surface);
}

.ace-check-card:has(input:checked),
.ace-check-item:has(input:checked) {
  border-color: var(--jade);
  background: var(--jade-soft);
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.08);
}

.ace-check-card-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ace-check-card-copy strong {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}

.ace-check-card-copy small {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-secondary);
  line-height: 1.25;
}

.ace-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
}

/* 3. TOGGLE SWITCHES DEL SISTEMA DE DISEÑO (.cz-switch-label + .cz-switch-input + .cz-switch-track) */
.cz-switch-label {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--bg-studio);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  width: 100%;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.cz-switch-label:hover {
  border-color: var(--jade);
}

.cz-switch-label:has(.cz-switch-input:checked) {
  border-color: var(--jade);
  background: var(--jade-soft);
}

.cz-switch-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.cz-switch-label .cz-switch-track {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.18s ease;
}

.cz-switch-label .cz-switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgb(255, 255, 255);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.28);
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.cz-switch-input:checked + .cz-switch-track {
  background: var(--jade);
}

.cz-switch-input:checked + .cz-switch-track::after {
  transform: translateX(18px);
}

.cz-switch-input:focus-visible + .cz-switch-track {
  box-shadow: 0 0 0 3px var(--jade-soft);
}

/* 4. SLIDERS (INPUT RANGE), CONTROL SEGMENTADO Y COMPONENTES DEL SHOWCASE (#czDesignSystemContainer) */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: var(--border-med);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--jade);
  border: 2px solid rgb(255, 255, 255);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.25);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.12);
  box-shadow: 0 0 0 4px var(--jade-soft);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--jade);
  border: 2px solid rgb(255, 255, 255);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.25);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.cz-ds-range-demo {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cz-ds-range-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cz-segmented-btn {
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.cz-segmented-btn:hover {
  color: var(--ink);
}

.cz-segmented-btn.is-active {
  background: var(--jade);
  color: rgb(255, 255, 255);
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.24);
}

/* Swatches y Diagrama de Estructura en #tab-design-system */
.cz-ds-showcase {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.cz-ds-swatch-Sample {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border-med);
  flex-shrink: 0;
  display: inline-block;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
}

.cz-swatch-coral {
  background: var(--coral);
}

.cz-ds-shell-diagram {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--border-med);
  background: var(--bg-studio);
}

.cz-ds-shell-sidebar-preview {
  padding: 12px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-secondary);
}

.cz-ds-shell-sidebar-preview strong,
.cz-ds-shell-nav-preview strong,
.cz-ds-shell-chead-preview strong,
.cz-ds-shell-cbody-preview strong {
  color: var(--ink);
  font-weight: 700;
}

.cz-ds-shell-main-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cz-ds-shell-nav-preview,
.cz-ds-shell-chead-preview,
.cz-ds-shell-cbody-preview {
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  font-size: 11.5px;
  color: var(--ink-secondary);
}

.cz-ds-shell-cbody-preview {
  border-color: var(--jade);
  background: var(--jade-soft);
  color: var(--ink);
  min-height: 54px;
  display: flex;
  align-items: center;
}

/* 5. ARMONÍA VISUAL Y ALINEACIÓN SIMÉTRICA DE PANELES EN /STUDIO Y VISTAS SECUNDARIAS */
.ace-app-main {
  gap: 12px;
}

.ace-workspace-content,
.ace-content-body {
  gap: 14px;
}

#protectedWorkspaceBar.ace-protected-workspace-bar,
#aceContentHeader.ace-content-header,
#markyHappyPathBar.ace-happy-path-compact {
  margin-bottom: 0;
  border-radius: 14px;
  padding: 12px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.025);
}

/* Simetría 50/50 exacta y alturas iguales en todas las cuadrículas de 2 y 3 columnas */
.ace-grid-2,
.ace-studio-main-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: stretch;
}

.ace-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  align-items: stretch;
}

.ace-grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}

/* Cuando un .ace-grid-4 vive dentro de una columna de mitad de pantalla, usar matriz 2x2 limpia */
.ace-studio-main-grid .ace-grid-4,
.ace-grid-2 .ace-grid-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* Unificar tarjetas .ace-card y .ace-card-elevated para evitar bordes dispares o alturas desiguales */
body:not([data-active-page="landing"]):not([data-active-page^="auth"]):not([data-active-page="calculator"]) .ace-card,
body:not([data-active-page="landing"]):not([data-active-page^="auth"]):not([data-active-page="calculator"]) .ace-card-elevated {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.035);
  display: flex;
  flex-direction: column;
}

body:not([data-active-page="landing"]):not([data-active-page^="auth"]):not([data-active-page="calculator"]) .ace-card-header {
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

body:not([data-active-page="landing"]):not([data-active-page^="auth"]):not([data-active-page="calculator"]) .ace-kpi-box {
  border-radius: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border-soft);
  background: var(--bg-studio);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

@media (max-width: 980px) {
  .ace-grid-2,
  .ace-grid-3,
  .ace-grid-4,
  .ace-studio-main-grid,
  .ace-check-grid,
  .cz-ds-shell-diagram {
    /*
     * `minmax(0, 1fr)` y no `1fr`: una pista `1fr` equivale a
     * `minmax(auto, 1fr)`, y ese `auto` es el tamaño MINIMO del contenido, no
     * cero. Basta un hijo ancho —una grafica, una tabla, un bloque de codigo—
     * para que la columna se niegue a encoger y estire la cuadricula entera
     * mas alla de la pantalla. La regla de escritorio de este mismo proyecto
     * ya lo hacia bien; el repliegue a una columna se habia quedado sin ello.
     */
    grid-template-columns: minmax(0, 1fr);
  }
}
