/* ============================================================
   OnAxis ERP · controls.css  v1.0
   Controles de selección: check, radio, switch, segmented,
   slider y stepper. Todo color vía tokens (css/tokens.css).
   Única excepción documentada: #16161A como tinta de la
   palomita/barra sobre fondo dorado.
   ============================================================ */

/* ============================================================
   CHECKBOX .check
   <label class="check">
     <input type="checkbox">
     <span class="check__box"></span>
     <span class="check__label">…</span>
   </label>
   ============================================================ */
.check{
  position: relative;
  display: inline-flex;
  align-items: flex-start;
  gap: var(--sp-2);
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-body);
  color: var(--ink);
}

/* Input oculto pero accesible (nunca display:none) */
.check > input{
  position: absolute;
  top: 0; left: 0;
  width: 18px;
  height: 18px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

/* Caja */
.check__box{
  flex: none;
  position: relative;
  width: 18px;
  height: 18px;
  margin-top: 1px;               /* alineación óptica con la 1a línea (lh 1.5) */
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--bg-1);
  transition: background var(--t-fast), border-color var(--t-fast),
              box-shadow var(--t-fast), transform var(--t-fast);
}

/* Palomita: dos bordes rotados 45°, nítida a 1x y 2x.
   #16161A permitido: tinta sobre dorado (excepción del contrato). */
.check__box::after{
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 9px;
  border-right: 2px solid #16161A;
  border-bottom: 2px solid #16161A;
  transform: translate(-50%, -58%) rotate(45deg) scale(0);
  transform-origin: center;
  transition: transform var(--t-fast);
}

.check__label{
  line-height: var(--lh-body);
}

/* Hover */
.check:hover > input:not(:disabled):not(:checked) + .check__box{
  border-color: var(--muted-2);
}
.check:hover > input:checked:not(:disabled) + .check__box{
  background: var(--gold-deep);
}

/* Active: micro-compresión */
.check:active > input:not(:disabled) + .check__box{
  transform: scale(.94);
}

/* Checked */
.check > input:checked + .check__box{
  background: var(--gold);
  border-color: var(--gold-deep);
}
.check > input:checked + .check__box::after{
  transform: translate(-50%, -58%) rotate(45deg) scale(1);
}

/* Indeterminado: barra horizontal tinta sobre dorado */
.check > input:indeterminate + .check__box{
  background: var(--gold);
  border-color: var(--gold-deep);
}
.check > input:indeterminate + .check__box::after{
  width: 8px;
  height: 2px;
  border: 0;
  border-radius: 1px;
  background: #16161A;
  transform: translate(-50%, -50%) scale(1);
}

/* Foco visible en la caja */
.check > input:focus-visible + .check__box{
  border-color: var(--gold-deep);
  box-shadow: var(--sh-focus);
}

/* Deshabilitado */
.check:has(> input:disabled){
  opacity: .5;
  pointer-events: none;
}

/* Denso .check--sm: caja 15px */
.check--sm{
  font-size: var(--fs-small);
}
.check--sm > input{
  width: 15px;
  height: 15px;
}
.check--sm .check__box{
  width: 15px;
  height: 15px;
  margin-top: 2px;
  border-radius: 4px;            /* proporcional a la caja de 15px */
}
.check--sm .check__box::after{
  width: 4px;
  height: 8px;
}
.check--sm > input:indeterminate + .check__box::after{
  width: 7px;
  height: 2px;
}

/* ============================================================
   RADIO .radio — mismo patrón que .check, geometría circular
   Checked: bg claro, borde 2px dorado profundo, punto 8px
   ============================================================ */
.radio{
  position: relative;
  display: inline-flex;
  align-items: flex-start;
  gap: var(--sp-2);
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-body);
  color: var(--ink);
}

.radio > input{
  position: absolute;
  top: 0; left: 0;
  width: 18px;
  height: 18px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.radio__box{
  flex: none;
  position: relative;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--bg-1);
  transition: background var(--t-fast), border-color var(--t-fast),
              box-shadow var(--t-fast), transform var(--t-fast);
}

/* Punto interior */
.radio__box::after{
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold-deep);
  transform: translate(-50%, -50%) scale(0);
  transition: transform var(--t-fast);
}

.radio__label{
  line-height: var(--lh-body);
}

/* Hover / active */
.radio:hover > input:not(:disabled):not(:checked) + .radio__box{
  border-color: var(--muted-2);
}
.radio:hover > input:checked:not(:disabled) + .radio__box::after{
  transform: translate(-50%, -50%) scale(1.15);
}
.radio:active > input:not(:disabled) + .radio__box{
  transform: scale(.94);
}

/* Checked: dona dorada, punto 8px */
.radio > input:checked + .radio__box{
  border: 2px solid var(--gold-deep);
  background: var(--bg-1);
}
.radio > input:checked + .radio__box::after{
  transform: translate(-50%, -50%) scale(1);
}

/* Foco visible */
.radio > input:focus-visible + .radio__box{
  border-color: var(--gold-deep);
  box-shadow: var(--sh-focus);
}

/* Deshabilitado */
.radio:has(> input:disabled){
  opacity: .5;
  pointer-events: none;
}

/* ---------- Variante tarjeta .radio-card ---------- */
.radio-card{
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--bg-1);
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast), border-color var(--t-fast),
              box-shadow var(--t-fast);
}

.radio-card > input{
  position: absolute;
  top: var(--sp-4); left: var(--sp-4);
  width: 18px;
  height: 18px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.radio-card:hover{
  border-color: var(--muted-2);
}

/* Seleccionada: por estado nativo o clase .is-on */
.radio-card:has(> input:checked),
.radio-card.is-on{
  border-color: var(--gold-deep);
  background: var(--gold-tint);
  box-shadow: inset 0 0 0 1px var(--gold-deep);   /* refuerza a 2px sin mover layout */
}

.radio-card:has(> input:focus-visible){
  outline: 2px solid var(--gold-deep);
  outline-offset: 2px;
}

.radio-card:has(> input:disabled){
  opacity: .5;
  pointer-events: none;
}

/* ============================================================
   SWITCH .switch — pista 36×20, thumb 16, viaje 16px
   <label class="switch">
     <input type="checkbox">
     <span class="switch__track"></span>
     <span class="switch__state"></span>  (solo .switch--labeled)
     <span class="switch__label">…</span>
   </label>
   ============================================================ */
.switch{
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-body);
  color: var(--ink);
}

.switch > input{
  position: absolute;
  top: 0; left: 0;
  width: 36px;
  height: 20px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch__track{
  flex: none;
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: var(--r-pill);
  background: var(--neutral-line);
  transition: background var(--t-fast), box-shadow var(--t-fast);
}

/* Thumb: blanco cálido constante en ambos temas (token --side-ink) */
.switch__track::before{
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: var(--r-pill);
  background: var(--side-ink);
  box-shadow: var(--sh-1);
  transition: transform var(--t-fast), width var(--t-fast);
}

/* Hover en pista */
.switch:hover > input:not(:disabled):not(:checked) + .switch__track{
  background: color-mix(in srgb, var(--neutral-line), var(--ink) 14%);
}
.switch:hover > input:checked:not(:disabled) + .switch__track{
  background: var(--gold-deep);
}

/* Active: el thumb se estira (estilo iOS) */
.switch:active > input:not(:disabled) + .switch__track::before{
  width: 19px;
}
.switch:active > input:checked:not(:disabled) + .switch__track::before{
  transform: translateX(13px);
}

/* ON */
.switch > input:checked + .switch__track{
  background: var(--gold);
}
.switch > input:checked + .switch__track::before{
  transform: translateX(16px);
}

/* Foco visible */
.switch > input:focus-visible + .switch__track{
  box-shadow: var(--sh-focus);
}

/* Deshabilitado */
.switch:has(> input:disabled){
  opacity: .5;
  pointer-events: none;
}

.switch__label{
  line-height: var(--lh-body);
}

/* Variante con etiqueta de estado ON/OFF (.u-label) */
.switch--labeled .switch__state{
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
  font-weight: 500;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted-2);
  min-width: 28px;
  transition: color var(--t-fast);
}
.switch--labeled .switch__state::after{
  content: "OFF";
}
.switch--labeled > input:checked ~ .switch__state{
  color: var(--gold-ink);
}
.switch--labeled > input:checked ~ .switch__state::after{
  content: "ON";
}

/* ============================================================
   SEGMENTED .segmented — grupo tipo pestañas compactas
   ============================================================ */
.segmented{
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--panel-2);
  border-radius: var(--r-sm);
}

.segmented__btn{
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  height: 28px;
  padding-inline: var(--sp-3);
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  font: inherit;
  font-size: var(--fs-small);
  font-weight: 500;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast),
              box-shadow var(--t-fast);
}

.segmented__btn:hover{
  color: var(--ink);
  background: color-mix(in srgb, var(--bg-1) 45%, transparent);
}

.segmented__btn:active{
  background: color-mix(in srgb, var(--bg-1) 70%, transparent);
}

.segmented__btn:focus-visible{
  outline: 2px solid var(--gold-deep);
  outline-offset: 2px;
}

/* Segmento activo: superficie elevada */
.segmented__btn.is-on{
  background: var(--bg-1);
  color: var(--ink);
  box-shadow: var(--sh-1);
}

.segmented__btn:disabled{
  opacity: .5;
  pointer-events: none;
}

/* ============================================================
   SLIDER .slider — input[type=range] cross-browser
   El progreso dorado lo pinta un gradiente con --val:
   JS actualiza  el.style.setProperty('--val', pct + '%')
   ============================================================ */
.slider{
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;                 /* zona táctil; la pista mide 4px */
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

/* --- Pista (WebKit/Blink) --- */
.slider::-webkit-slider-runnable-track{
  height: 4px;
  border-radius: var(--r-pill);
  background: linear-gradient(
    to right,
    var(--gold-deep) var(--val, 50%),
    var(--neutral-line) var(--val, 50%)
  );
}

/* --- Thumb (WebKit/Blink): 16px, centrado en pista de 4px --- */
.slider::-webkit-slider-thumb{
  -webkit-appearance: none;
  box-sizing: border-box;
  width: 16px;
  height: 16px;
  margin-top: -6px;             /* (16 − 4) / 2 */
  border: 2px solid var(--gold-deep);
  border-radius: 50%;
  background: var(--bg-1);
  box-shadow: var(--sh-1);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}

/* --- Pista (Firefox) --- */
.slider::-moz-range-track{
  height: 4px;
  border-radius: var(--r-pill);
  background: linear-gradient(
    to right,
    var(--gold-deep) var(--val, 50%),
    var(--neutral-line) var(--val, 50%)
  );
}

/* --- Thumb (Firefox) --- */
.slider::-moz-range-thumb{
  box-sizing: border-box;
  width: 16px;
  height: 16px;
  border: 2px solid var(--gold-deep);
  border-radius: 50%;
  background: var(--bg-1);
  box-shadow: var(--sh-1);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}

/* Hover / active en thumb */
.slider:hover::-webkit-slider-thumb{ transform: scale(1.12); }
.slider:hover::-moz-range-thumb{ transform: scale(1.12); }
.slider:active::-webkit-slider-thumb{ transform: scale(1.04); }
.slider:active::-moz-range-thumb{ transform: scale(1.04); }

/* Foco visible: anillo en el thumb, sin outline en el input */
.slider:focus-visible{
  outline: none;
}
.slider:focus-visible::-webkit-slider-thumb{
  box-shadow: var(--sh-focus);
}
.slider:focus-visible::-moz-range-thumb{
  box-shadow: var(--sh-focus);
}

/* Deshabilitado */
.slider:disabled{
  opacity: .5;
  pointer-events: none;
}

/* ============================================================
   STEPPER .stepper — btn − / input numérico / btn +
   Bordes colapsados (patrón .btn-group), radios solo en extremos
   ============================================================ */
.stepper{
  display: inline-flex;
  align-items: stretch;
  height: var(--ctl-h);
}

.stepper__btn{
  appearance: none;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ctl-h);          /* cuadrado: ancho = altura */
  height: 100%;
  padding: 0;
  border: 1px solid var(--line-strong);
  background: var(--bg-1);
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-emph);
  line-height: 1;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast),
              border-color var(--t-fast);
}

.stepper__btn:first-child{
  border-radius: var(--r-sm) 0 0 var(--r-sm);
}
.stepper__btn:last-child{
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  margin-left: -1px;
}

.stepper__btn:hover{
  z-index: 1;                   /* el borde hover gana sobre el colapsado */
  background: var(--panel);
  border-color: var(--gold-deep);
  color: var(--ink);
}

.stepper__btn:active{
  background: var(--panel-2);
}

.stepper__btn:focus-visible{
  z-index: 2;
  outline: 2px solid var(--gold-deep);
  outline-offset: 2px;
}

.stepper__btn:disabled{
  opacity: .5;
  pointer-events: none;
}

/* Campo numérico central: mono, centrado, 56px */
.stepper__input{
  position: relative;
  width: 56px;
  height: 100%;
  margin-left: -1px;
  padding: 0 var(--sp-1);
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--bg-1);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--fs-body);
  font-variant-numeric: tabular-nums;
  text-align: center;
  -moz-appearance: textfield;
  appearance: textfield;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

/* Sin flechas nativas del input number */
.stepper__input::-webkit-inner-spin-button,
.stepper__input::-webkit-outer-spin-button{
  -webkit-appearance: none;
  margin: 0;
}

.stepper__input:hover{
  z-index: 1;
}

.stepper__input:focus-visible{
  z-index: 2;
  outline: none;
  border-color: var(--gold-deep);
  box-shadow: var(--sh-focus);
}

.stepper__input:disabled{
  opacity: .5;
  pointer-events: none;
  background: var(--panel-2);
}
