/* Rediseño «Riel nocturno» · controles al estilo iOS (Phil 10/11/2026: ideas 1, 2 y 3, «para todo el site y el portal»).
   Clases que se suman a los controles que ya existen; no reemplazan ningún input ni cambian qué se guarda.
   - .rn-btn-primary   el botón principal de una fila (Guardar): verde, uno solo por fila.
   - .rn-btn-plain     acción que no guarda (Cerrar, Volver): solo texto.
   - .rn-switch        en un <input type="checkbox"> de sí/no: interruptor (verde = sí, gris = no).
   - .rn-seg           grupo de botones para elegir 2 o 3 opciones a la vista (el <select> sigue al lado, oculto).
   - .rn-stepper       − y + alrededor de un <select> de números.
   - .rn-menu          desplegable que se abre desde un botón de la fila (Generar ▾). */

/* ---------- Pastillas de estado de documentos ---------- */
/* Ancho único para que queden en columna, pero que entre el estado más largo: «Próximo a vencer» (Phil 10/11/2026: «no
   entra el texto»). Medído: 104 px en el sitio (theme.css decía 92) y 118 px en el portal (portal.css decía 96). */
html body {
  --doc-badge-w: 108px;
}

html body.p-body {
  --doc-badge-w: 122px;
}

/* «Carga parcial» = faltan documentos obligatorios: ámbar, como «Próximo a vencer» (theme.css y portal.css la pintaban
   igual que «Vigente»). Phil 10/11/2026. */
html body:not(.pdf-export) .doc-badge--partial {
  background: #E67E22;
  color: #fff;
}

html body.p-body .doc-badge--partial {
  background: #C27A2C;
  color: #fff;
}

/* Formularios con documentos: con un archivo elegido, «Sin documento» ya no es cierto (compliance_slots.js pone .has-file). */
html body .compliance-slot.has-file .compliance-slot-meta > .doc-badge--missing {
  display: none;
}

/* ---------- Títulos de las ventanas ---------- */
/* Con la letra del sitio (Phil 10/11/2026: «Letra del sitio», antes Cormorant con serifa). Los títulos grandes de cada página
   siguen con serifa. Vale para las ventanas de app_dialog.js, las de la cotización (.ts-modal) y el visor de documentos. */
html body .app-dialog-title,
html body .delete-modal-title,
html body .ts-modal-box h3,
html body:not(.error-page) .doc-preview-title {
  font-family: var(--rn-font-sans, "Inter", system-ui, sans-serif) !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em;
}

html body .app-dialog-title,
html body .delete-modal-title,
html body .ts-modal-box h3 {
  font-size: 17px !important;
  line-height: 1.3;
}

/* ---------- Botón principal y botón de texto (idea 1) ---------- */
/* html body …: theme.css y las hojas de cada pantalla pintan .btns con !important; este gana por especificidad. */
html body .btns.rn-btn-primary,
html body .savebtns button.rn-btn-primary {
  border-color: var(--rn-action-strong) !important;
  background: var(--rn-action-strong) !important;
  color: #fff !important;
  padding-left: 22px !important;
  padding-right: 22px !important;
}

/* Botones en letra normal, como en la cotización y las fichas: los de guardar de los formularios y los de los listados
   seguían en MAYÚSCULAS espaciadas del estilo viejo (QA 10/11/2026). */
html body:not(.pdf-export) .savebtns .btns,
html body:not(.pdf-export) .title-box .btns.delete-btn,
html body:not(.pdf-export) .filter-lists .filter-clear {
  font-family: var(--rn-font-sans) !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  letter-spacing: 0 !important;
  text-transform: none !important;
}

html body .btns.rn-btn-plain,
html body .savebtns button.rn-btn-plain {
  border-color: transparent !important;
  background: transparent !important;
  box-shadow: none !important;
  color: var(--rn-ink-muted) !important;
}

@media (hover: hover) and (pointer: fine) {
  html body .btns.rn-btn-primary:hover,
  html body .savebtns button.rn-btn-primary:hover {
    border-color: var(--rn-action-strong-hover) !important;
    background: var(--rn-action-strong-hover) !important;
    color: #fff !important;
  }

  html body .btns.rn-btn-plain:hover,
  html body .savebtns button.rn-btn-plain:hover {
    background: var(--rn-surface-sunken) !important;
    color: var(--rn-ink) !important;
  }
}

/* ---------- Desplegable desde un botón (Generar ▾) ---------- */
.rn-menu-wrap {
  position: relative;
  display: inline-flex;
}

/* Botón con flecha: texto y flecha centrados en vertical. La flecha apunta arriba (el menú se abre hacia arriba) y gira al
   abrir. Bootstrap marca abierto el botón (aria-expanded) o el contenedor (.show) según la versión: se miran los dos. */
html body .rn-menu-wrap > .btns {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

.rn-menu-caret {
  display: inline-block;
  flex: none;
  width: 6px;
  height: 6px;
  margin: 0 0 0 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(2px) rotate(225deg);
  transition: transform 150ms ease;
}

.rn-menu-wrap.show .rn-menu-caret,
.rn-menu-wrap > [aria-expanded="true"] .rn-menu-caret {
  transform: translateY(-2px) rotate(45deg);
}

/* Sin Popper: el botón lleva data-toggle + data-display="static" (no data-bs-toggle). Con Popper el menú aparecía a la
   derecha y después saltaba arriba (QA 11/11/2026). */
html body .rn-menu-wrap > .dropdown-menu.rn-menu {
  top: auto;
  bottom: calc(100% + 8px);
  right: 0;
  left: auto;
  min-width: 230px;
  margin: 0;
  padding: 6px;
  border: 0;
  border-radius: 12px;
  background: var(--rn-surface-sheet);
  box-shadow: var(--rn-shadow-menu);
  transform-origin: bottom right;
}

html body .rn-menu-wrap > .dropdown-menu.rn-menu.show {
  animation: rn-menu-pop 160ms cubic-bezier(0.3, 0.7, 0.4, 1);
}

html body .rn-menu > .dropdown-item {
  display: flex !important;
  align-items: center;
  width: 100% !important;
  min-height: 38px;
  margin: 0 !important;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--rn-ink-2);
  font-family: var(--rn-font-sans);
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0;
  text-align: left !important;
  text-transform: none;
  white-space: nowrap;
}

html body .rn-menu > .dropdown-item:hover,
html body .rn-menu > .dropdown-item:focus-visible {
  background: var(--rn-surface-tint);
  color: var(--rn-ink);
  outline: none;
}

@keyframes rn-menu-pop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}

/* ---------- Interruptor (idea 2) ---------- */
/* 36 × 22 (Phil 11/11/2026: «un pelín más chiquitos»; antes 42 × 26). */
/* :not(#rn-no) suma peso de id: theme-part-2.css fija las casillas de los formularios en 16 px con !important. */
html body input[type="checkbox"].rn-switch:not(#rn-no) {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  display: inline-block;
  flex: 0 0 auto !important;
  width: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  height: 22px !important;
  min-height: 22px !important;
  max-height: 22px !important;
  margin: 0;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 999px !important;
  background: #D5D8DC !important;
  box-shadow: none;
  vertical-align: middle;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 180ms ease;
}

html body input[type="checkbox"].rn-switch:not(#rn-no)::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(20, 25, 33, 0.25);
  transition: transform 180ms cubic-bezier(0.3, 0.7, 0.4, 1);
}

html body input[type="checkbox"].rn-switch:not(#rn-no)::after {
  content: none;
}

html body input[type="checkbox"].rn-switch:not(#rn-no):checked {
  background: var(--rn-action-strong) !important;
}

html body input[type="checkbox"].rn-switch:not(#rn-no):checked::before {
  transform: translateX(14px);
}

html body input[type="checkbox"].rn-switch:not(#rn-no):focus {
  outline: none;
}

html body input[type="checkbox"].rn-switch:not(#rn-no):focus-visible {
  outline: 2px solid var(--rn-navy);
  outline-offset: 2px;
}

html body input[type="checkbox"].rn-switch:not(#rn-no):disabled {
  opacity: 0.45;
  cursor: default;
}

/* En los formularios la casilla vive en .destination-input-group, que theme.css deja en 14 px: se agranda al interruptor. */
html body .destination-input-group:has(> input.rn-switch):not(#rn-no) {
  flex: 0 0 auto !important;
  width: 36px !important;
  min-width: 36px !important;
  max-width: none !important;
}

/* Texto primero, interruptor a su derecha, como en el iPhone (Phil 10/11/2026: «las pastillitas van a la derecha de los
   textos, y no a la izq»). theme-part-2.css pone la casilla antes del texto (order 1 / 2) en las filas de los formularios;
   en los <label> que envuelven al interruptor (portal, «No aplica», fichas) el texto queda antes con order. */
html body .form-line-data:has(> .destination-input-group > input.rn-switch):not(#rn-no) {
  justify-content: flex-start;
  gap: 12px;
}

html body .form-line-data:has(> .destination-input-group > input.rn-switch):not(#rn-no) > label {
  order: 1;
  flex: 0 1 auto !important;
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
}

html body .form-line-data:has(> .destination-input-group > input.rn-switch):not(#rn-no) > .destination-input-group {
  order: 2;
}

html body label > input.rn-switch:not(#rn-no) {
  order: 2;
}

html body label:has(> input.rn-switch):not(#rn-no) {
  gap: 10px;
}

/* Celular: cada interruptor al borde derecho de su renglón, todos en la misma línea (como los Ajustes del iPhone). */
@media screen and (max-width: 767.98px) {
  html body .form-line-data:has(> .destination-input-group > input.rn-switch):not(#rn-no) > label {
    flex: 1 1 auto !important;
  }

  /* Portal, precios: «Sin precio cerrado» ocupa el renglón y el interruptor queda al borde. */
  html body .p-basis > label.p-check:has(> input.rn-switch) {
    display: flex;
    justify-content: space-between;
    width: 100%;
  }
}

/* Fichas con edición en el lugar: el label del interruptor es inline; al editar pasa a flex para poder ordenar. */
html body .js-inline-form.is-editing label.js-inline-edit-only:has(> input.rn-switch) {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

/* Barra «No opero» del portal: el interruptor al final de la barra. */
html body .p-na-bar:has(> input.rn-switch) {
  justify-content: space-between;
}

/* ---------- Opciones a la vista (idea 3) ---------- */
.rn-seg {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  max-width: 100%;
  padding: 2px;
  border-radius: 9px;
  background: #E3E5E8;
}

html body .rn-seg > button:not(#rn-no) {
  min-width: 0;
  height: 28px;
  margin: 0;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  box-shadow: none;
  color: var(--rn-ink-2);
  font: 500 12.5px/1 var(--rn-font-sans);
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms ease, box-shadow 150ms ease;
}

html body .rn-seg > button[aria-pressed="true"]:not(#rn-no) {
  background: var(--rn-surface-sheet);
  color: var(--rn-ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(20, 25, 33, 0.14), 0 0 0 0.5px rgba(20, 25, 33, 0.06);
}

html body .rn-seg > button:not(#rn-no):focus {
  outline: none;
}

html body .rn-seg > button:not(#rn-no):focus-visible {
  outline: 2px solid var(--rn-navy);
  outline-offset: 1px;
}

/* Opciones a la vista armadas por rn-seg.js (select[data-rn-seg]): el select queda oculto al lado, salvo que no entren. */
.rn-seg--js {
  overflow: hidden;
  vertical-align: middle;
}

html body .rn-seg--js > button:not(#rn-no) {
  height: 32px;
  padding: 0 14px;
  font-size: 13px;
}

html body .rn-seg--js > button:not(#rn-no):disabled {
  cursor: default;
  opacity: 0.6;
}

.rn-seg--js:not(.rn-seg--nofit) + .fq-select,
.rn-seg--js:not(.rn-seg--nofit) + select {
  display: none !important;
}

.rn-seg.rn-seg--nofit {
  display: none;
}

/* Opciones a la vista con radios (Portal, empty legs: Fecha / Rango de fechas): el radio queda adentro, invisible. */
html body .rn-seg--radio {
  display: inline-grid;
  gap: 0;
  min-height: 0;
  justify-self: start;
}

html body .rn-seg--radio > label:not(#rn-no) {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  height: 32px;
  margin: 0;
  padding: 0 16px;
  border-radius: 7px;
  color: var(--rn-ink-2);
  font: 500 13px/1 var(--rn-font-sans);
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms ease, box-shadow 150ms ease;
}

html body .rn-seg--radio > label > input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

html body .rn-seg--radio > label > span {
  font: inherit !important;
  color: inherit !important;
}

html body .rn-seg--radio > label:not(#rn-no):has(input:checked) {
  background: var(--rn-surface-sheet);
  color: var(--rn-ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(20, 25, 33, 0.14), 0 0 0 0.5px rgba(20, 25, 33, 0.06);
}

html body .rn-seg--radio > label:not(#rn-no):has(input:focus-visible) {
  outline: 2px solid var(--rn-navy);
  outline-offset: 1px;
}

/* ---------- Contador − / + (idea 3) ---------- */
.rn-stepper {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 0 2px;
  border-radius: 8px;
  background: var(--rn-surface-sunken);
}

html body .rn-stepper > .rn-stepper-btn:not(#rn-no) {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  box-shadow: none;
  color: var(--rn-ink);
  font: 500 17px/1 var(--rn-font-sans);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html body .rn-stepper > .rn-stepper-btn:not(#rn-no):active {
  background: var(--rn-surface-selected);
}

html body .rn-stepper > .rn-stepper-btn:not(#rn-no):focus {
  outline: none;
}

html body .rn-stepper > .rn-stepper-btn:not(#rn-no):focus-visible {
  outline: 2px solid var(--rn-navy);
  outline-offset: -2px;
}

@media (hover: hover) and (pointer: fine) {
  html body .rn-stepper > .rn-stepper-btn:not(#rn-no):hover {
    background: var(--rn-surface-sheet);
  }

  html body .rn-seg > button:not(#rn-no):not([aria-pressed="true"]):hover {
    background: rgba(255, 255, 255, 0.55);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rn-menu-caret,
  html body input[type="checkbox"].rn-switch:not(#rn-no),
  html body input[type="checkbox"].rn-switch:not(#rn-no)::before,
  html body .rn-seg > button:not(#rn-no),
  html body .rn-seg--radio > label:not(#rn-no) {
    transition: none;
  }

  html body .rn-menu-wrap > .dropdown-menu.rn-menu.show {
    animation: none;
  }
}
