/* ═══════════════════════════════════════════════════════════════════════════
 * FINO · CONTROLES (pautas de interfaz de Apple — Human Interface Guidelines)
 *
 * Da diseño propio a TODOS los controles nativos que no tenían (select, input,
 * fechas, checkbox, radio, textarea, rango, archivo) en las vistas y módulos de
 * la app. No se usa en la landing ni en los legales.
 *
 * Principios HIG aplicados:
 *   · Área de toque mínima de 44 px en pantallas táctiles (40 px con mouse).
 *   · Selectores con la lista NATIVA del sistema (rueda en iOS, menú en Mac)
 *     pero control cerrado con el estilo de FINO y chevrón propio.
 *   · Foco siempre visible, estados claros (hover, activo, deshabilitado, error).
 *   · Texto de entrada a 16 px en móvil (evita el zoom automático de iOS).
 *   · Tipografía fluida con clamp(): los títulos y cifras se ajustan al ancho.
 *   · Movimiento corto y suave; se desactiva si el sistema pide menos movimiento.
 *
 * Todo va dentro de :where(), con especificidad CERO: cualquier clase o estilo
 * en línea que ya exista gana. Excluidos a propósito: campos .fl (etiqueta
 * flotante), interruptores .switch y selectores de indicativo .tel-cc.
 * ═══════════════════════════════════════════════════════════════════════════ */

:root{
  --hig-alto: 40px;
  --hig-radio: 12px;
  --hig-borde: var(--line-2, #E7DCC9);
  --hig-fondo: var(--card, #fff);
  --hig-fondo-hover: #FFFDFA;
  --hig-texto: var(--ink, #0B0F19);
  --hig-sutil: var(--muted, #6B7280);
  --hig-acento: var(--coral, #FF5A5F);
  --hig-anillo: 0 0 0 4px rgba(255, 90, 95, .16);
  --hig-sombra: 0 1px 2px rgba(11, 15, 25, .04);
  --hig-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1.5 1.75 6 6.25l4.5-4.5' fill='none' stroke='%236B7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --hig-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.4 6.6 11.3 12.5 4.9' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --hig-dash: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8h8' stroke='%23fff' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E");
  color-scheme: light;
}
@media (pointer: coarse){ :root{ --hig-alto: 44px; } }

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

/* ── Campos de texto, números, fechas y selects ─────────────────────────── */
:where(
  select:not([multiple]):not([size]):not(.fl *):not(.tel-cc),
  input:is([type="text"], [type="search"], [type="email"], [type="tel"], [type="url"], [type="password"],
           [type="number"], [type="date"], [type="month"], [type="week"], [type="time"], [type="datetime-local"], :not([type])):not(.fl *),
  textarea:not(.fl *)
){
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  min-height: var(--hig-alto);
  padding: 0 14px;
  border: 1px solid var(--hig-borde);
  border-radius: var(--hig-radio);
  background-color: var(--hig-fondo);
  color: var(--hig-texto);
  font: inherit;
  font-size: 14px;
  line-height: 1.3;
  box-shadow: var(--hig-sombra);
  outline: none;
  max-width: 100%;
  transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}
:where(textarea:not(.fl *)){ padding: 10px 14px; min-height: 88px; line-height: 1.5; resize: vertical; }

:where(select:not([multiple]):not([size]):not(.fl *):not(.tel-cc)){
  padding-right: 38px;
  background-image: var(--hig-chevron);
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* El chevrón debe sobrevivir a reglas viejas tipo «.form-row select{background:…}» */
select:not([multiple]):not([size]):not(.fl select):not(.tel-cc){
  -webkit-appearance: none; appearance: none;
  background-image: var(--hig-chevron);
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
}
/* Selector de indicativo de país: mismo chevrón, compacto */
select.tel-cc{
  -webkit-appearance: none; appearance: none; cursor: pointer;
  background-image: var(--hig-chevron); background-repeat: no-repeat; background-position: right 8px center; background-size: 10px 7px;
  padding-right: 24px !important; border-radius: var(--hig-radio) !important;
}
/* Espacio para el chevrón en los selects de formularios y filtros (incluye formularios de Nómina) */
.form-row select, .panel-head select, .nm-field select{ padding-right: 38px !important; text-overflow: ellipsis; }

/* Casillas, círculos e interruptores dentro de formularios con reglas genéricas de «input»
   (ej. .nm-field input): no deben heredar relleno ni bordes de campo de texto. */
input[type="radio"]{ padding: 0 !important; min-height: 0 !important; border-radius: 50% !important; box-shadow: none; }
input[type="radio"]:checked{ border: 6px solid var(--hig-acento) !important; background: #fff !important; }
input[type="checkbox"]:not(.switch *):not([role="switch"]){ padding: 0 !important; min-height: 0 !important; border-radius: 6px !important; }
input[type="checkbox"]:not(.switch *):not([role="switch"]):checked{
  background-color: var(--hig-acento) !important; border-color: var(--hig-acento) !important;
  background-image: var(--hig-check) !important; background-position: center !important; background-size: 14px !important; background-repeat: no-repeat !important;
}
input[type="checkbox"][role="switch"]{ padding: 0 !important; min-height: 0 !important; border: 0 !important; border-radius: 99px !important; width: 44px !important; height: 26px !important; }
/* Selects compactos que ya definen su propio relleno (ej. unidad en el carrito) */
.unit-sel, select.inp, select.dian-filter{ background-position: right 8px center; padding-right: 26px; }
:where(select[multiple], select[size]){
  border: 1px solid var(--hig-borde); border-radius: var(--hig-radio); padding: 6px;
  background: var(--hig-fondo); font: inherit; font-size: 14px; outline: none;
}
:where(select option){ font-size: 14px; }

:where(select, input, textarea):hover:not(:disabled):not(:focus){ border-color: #D9CBB3; }
:where(select, input, textarea):focus-visible,
:where(select, input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea):focus{
  border-color: var(--hig-acento);
  box-shadow: var(--hig-anillo);
}
:where(select, input, textarea):disabled{ opacity: .45; cursor: not-allowed; }
:where(input, textarea)::placeholder{ color: var(--muted-2, #9CA3AF); opacity: 1; }
:where(input[readonly]:not([type="checkbox"]):not([type="radio"]):not(.fl *)){ background-color: var(--ink-soft, #F5F2EC); }
:where(input, textarea, select)[aria-invalid="true"],
:where(input, textarea, select):user-invalid{ border-color: var(--red, #DC2626); }

/* Búsqueda: lupa y sin decoraciones del navegador */
:where(input[type="search"]:not([class]):not(.fl *)){
  padding-left: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center; background-size: 16px;
}
input[type="search"]::-webkit-search-decoration{ -webkit-appearance: none; }
input[type="search"]::-webkit-search-cancel-button{
  -webkit-appearance: none; height: 16px; width: 16px; cursor: pointer; opacity: .55;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' fill='%239CA3AF'/%3E%3Cpath d='m8.5 8.5 7 7m0-7-7 7' stroke='%23fff' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") center/16px no-repeat;
}

/* Números: sin flechitas (se escribe o se usa el teclado numérico) */
:where(input[type="number"]){ -moz-appearance: textfield; font-variant-numeric: tabular-nums; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button{ -webkit-appearance: none; margin: 0; }

/* Fechas y horas: ícono de calendario con el color de la marca */
:where(input:is([type="date"], [type="month"], [type="week"], [type="time"], [type="datetime-local"]):not(.fl *)){
  font-variant-numeric: tabular-nums; cursor: pointer; padding-right: 10px;
}
input:is([type="date"], [type="month"], [type="week"], [type="time"], [type="datetime-local"])::-webkit-calendar-picker-indicator{
  cursor: pointer; opacity: .55; border-radius: 6px; padding: 4px; margin-left: 4px; transition: opacity .15s, background-color .15s;
}
input:is([type="date"], [type="month"], [type="week"], [type="time"], [type="datetime-local"])::-webkit-calendar-picker-indicator:hover{
  opacity: 1; background-color: var(--bg-mute, #FFF4E8);
}
input:is([type="date"], [type="month"], [type="time"])::-webkit-datetime-edit{ padding: 0; }

/* ── Casillas (checkbox) ────────────────────────────────────────────────── */
:where(input[type="checkbox"]:not(.switch *):not([role="switch"])){
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; flex-shrink: 0; margin: 0;
  border: 1.5px solid #CFC3AE; border-radius: 6px;
  background: #fff center / 14px no-repeat;
  vertical-align: middle; cursor: pointer; position: relative;
  transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
:where(input[type="checkbox"]:not(.switch *):not([role="switch"])):checked{
  background-color: var(--hig-acento); border-color: var(--hig-acento); background-image: var(--hig-check);
}
:where(input[type="checkbox"]:not(.switch *):not([role="switch"])):indeterminate{
  background-color: var(--hig-acento); border-color: var(--hig-acento); background-image: var(--hig-dash);
}
:where(input[type="checkbox"], input[type="radio"]):active:not(:disabled){ transform: scale(.92); }
:where(input[type="checkbox"], input[type="radio"]):focus-visible{ outline: none; box-shadow: var(--hig-anillo); }
:where(input[type="checkbox"], input[type="radio"]):disabled{ opacity: .4; cursor: not-allowed; }

/* ── Opciones (radio) ───────────────────────────────────────────────────── */
:where(input[type="radio"]){
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; flex-shrink: 0; margin: 0;
  border: 1.5px solid #CFC3AE; border-radius: 50%; background: #fff;
  vertical-align: middle; cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
:where(input[type="radio"]):checked{ border: 6px solid var(--hig-acento); background: #fff; }

/* ── Interruptor tipo iOS: <input type="checkbox" role="switch"> ────────── */
:where(input[type="checkbox"][role="switch"]){
  -webkit-appearance: none; appearance: none;
  width: 44px; height: 26px; flex-shrink: 0; margin: 0;
  border-radius: 99px; background: #E3DACB; position: relative; cursor: pointer;
  vertical-align: middle; transition: background-color .2s ease;
}
:where(input[type="checkbox"][role="switch"])::before{
  content: ''; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, .2); transition: transform .22s cubic-bezier(.3, .7, .4, 1.2);
}
:where(input[type="checkbox"][role="switch"]):checked{ background: var(--mint, #0DBC79); }
:where(input[type="checkbox"][role="switch"]):checked::before{ transform: translateX(18px); }

/* ── Deslizador (range) ─────────────────────────────────────────────────── */
:where(input[type="range"]){
  -webkit-appearance: none; appearance: none; height: 28px; background: transparent; cursor: pointer; accent-color: var(--hig-acento);
}
input[type="range"]::-webkit-slider-runnable-track{ height: 4px; border-radius: 99px; background: #E7DCC9; }
input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance: none; width: 24px; height: 24px; margin-top: -10px; border-radius: 50%;
  background: #fff; border: .5px solid rgba(0, 0, 0, .04); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 3px 8px rgba(0, 0, 0, .15);
}
input[type="range"]::-moz-range-track{ height: 4px; border-radius: 99px; background: #E7DCC9; }
input[type="range"]::-moz-range-progress{ height: 4px; border-radius: 99px; background: var(--hig-acento); }
input[type="range"]::-moz-range-thumb{ width: 24px; height: 24px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 3px 8px rgba(0, 0, 0, .15); }

/* ── Archivos: el botón del sistema con estilo FINO ─────────────────────── */
:where(input[type="file"]){ font: inherit; font-size: 13px; color: var(--hig-sutil); max-width: 100%; }
input[type="file"]::file-selector-button{
  font: inherit; font-size: 13px; font-weight: 600; margin-right: 10px; padding: 9px 14px; min-height: 36px;
  border: 1px solid var(--hig-borde); border-radius: 10px; background: #fff; color: var(--hig-texto); cursor: pointer;
  transition: background-color .15s, border-color .15s;
}
input[type="file"]::file-selector-button:hover{ background: var(--bg-mute, #FFF4E8); border-color: #D9CBB3; }

/* Botones sin clase (los hay en algunos módulos) */
:where(button:not([class])){
  min-height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--hig-borde);
  background: #fff; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
:where(button:not([class])):focus-visible{ outline: none; box-shadow: var(--hig-anillo); }

/* Etiquetas que envuelven casillas: toda la fila es tocable */
:where(label:has(> input[type="checkbox"], > input[type="radio"])){ cursor: pointer; -webkit-user-select: none; user-select: none; }

/* Selección de texto con el color de la marca */
::selection{ background: rgba(255, 90, 95, .2); }

/* ── Tipografía fluida (textos responsive) ──────────────────────────────── */
.page-title{ font-size: clamp(1.55rem, 1.05rem + 1.9vw, 2.2rem) !important; line-height: 1.12; overflow-wrap: anywhere; }
.page-title small{ font-size: clamp(.72rem, .66rem + .25vw, .82rem); }
.panel-head h3, .modal-head h3{ font-size: clamp(1rem, .92rem + .35vw, 1.15rem); overflow-wrap: anywhere; }
.kpi .val{ font-size: clamp(1.25rem, .95rem + 1.2vw, 1.75rem); }
.kpi .lbl{ font-size: clamp(.68rem, .64rem + .2vw, .76rem); }
.data th{ font-size: clamp(.62rem, .6rem + .15vw, .7rem); }
.data td{ font-size: clamp(.8rem, .76rem + .2vw, .875rem); }
.modal-body{ font-size: clamp(.875rem, .84rem + .15vw, .94rem); }
.empty{ font-size: clamp(.84rem, .8rem + .2vw, .92rem); }

/* Filtros en fila (selects/inputs sueltos junto a botones): envuelven bien en móvil */
.panel-head > div:has(> select, > input){ flex-wrap: wrap; }

/* ── Pantallas táctiles y móvil ─────────────────────────────────────────── */
@media (pointer: coarse), (max-width: 920px){
  :where(
    select:not(.fl *):not(.tel-cc),
    input:is([type="text"], [type="search"], [type="email"], [type="tel"], [type="url"], [type="password"],
             [type="number"], [type="date"], [type="month"], [type="week"], [type="time"], [type="datetime-local"], :not([type])):not(.fl *),
    textarea:not(.fl *)
  ){ font-size: 16px; }
  :where(input[type="checkbox"]:not(.switch *):not([role="switch"]), input[type="radio"]){ width: 22px; height: 22px; }
}
@media (max-width: 640px){
  .panel-head{ flex-wrap: wrap; gap: 10px; }
  .panel-head > div:has(> select, > input) > :is(select, input:not([type="checkbox"]):not([type="radio"]), .search){
    flex: 1 1 140px; min-width: 0; width: auto !important;
  }
}

@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{ transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
