/* ============================================================================
 *  ENTERPRISE · rediseño de NeatFix (2026-10-16)
 *  Maqueta aprobada por Ferran: «2 · Final» del lienzo de direcciones
 *  (estilo panel de Stripe: navegación superior, mucho blanco, líneas finas,
 *  Instrument Sans, el naranja solo como acento).
 *
 *  Se carga la ÚLTIMA (después de editorial/motion/a11y) y retunea los
 *  componentes compartidos. Las capas anteriores siguen ahí; esta gana por
 *  orden. Para volver al aspecto anterior bastaría con quitar el <link>
 *  (y deshacer tokens.css, shell.css y el marcado del shell).
 * ========================================================================= */

:root {
  --btn-height:   40px;   /* escritorio; en móvil/táctil sube a 44 (abajo) */
  --input-height: 40px;
  --radius-ctl:   6px;    /* botones y campos */
  --radius-box:   10px;   /* tarjetas y tablas */
  --ring-focus:   0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}

/* ── TIPOGRAFÍA ───────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 { font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
h4 { font-size: 16px; }

a { color: var(--brand-ink); font-weight: 600; }

/* Las etiquetas en mayúsculas espaciadas eran del sistema anterior. */
.caption-allcaps {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--on-surface-variant);
}

/* ── BOTONES ──────────────────────────────────────────────────────────── */
.btn {
  min-height: var(--btn-height);
  padding: 0 14px;
  gap: 6px;
  border-radius: var(--radius-ctl);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0;
}
.btn:active { transform: none; }
.btn .ms { font-size: 18px; }

.btn-filled { background: var(--brand); color: #fff; border: 1px solid var(--brand); }
.btn-filled:hover:not(:disabled) { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn-filled:disabled { background: var(--surface-container); border-color: var(--surface-container); color: var(--on-surface-muted); }

.btn-outlined {
  background: var(--surface);
  border: 1px solid var(--outline);
  color: var(--on-surface);
  box-shadow: 0 1px 1px rgba(16, 24, 40, 0.04);
}
.btn-outlined .ms { color: var(--on-surface-variant); }
.btn-outlined:hover:not(:disabled) { background: var(--surface-container-low); border-color: var(--outline); }

.btn-text { color: var(--brand-ink); }
.btn-text:hover:not(:disabled) { background: var(--surface-container-low); }

.btn-danger { border-radius: var(--radius-ctl); }

/* Botón principal grande (acción primaria del técnico: iniciar, cerrar…). */
.btn-xl {
  min-height: 52px;
  height: 52px;
  padding: 0 22px;
  font-size: 16px;
}
.btn-xl .ms { font-size: 22px; }

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-ctl);
  border: 1px solid var(--outline);
  background: var(--surface);
}
.btn-icon:hover:not(:disabled) { background: var(--surface-container-low); border-color: var(--outline); }

.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13.5px; }

/* ── CAMPOS ───────────────────────────────────────────────────────────── */
.field { gap: 6px; }
.field > label, .field > .label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--on-surface);
}
.field .help  { font-size: 13px; color: var(--on-surface-variant); }
.field .error { font-size: 13px; }

.input, .textarea, .select {
  min-height: var(--input-height);
  padding: 8px 12px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-ctl);
  background-color: var(--surface);
  font-size: 15px;
  font-weight: 400;
  box-shadow: 0 1px 1px rgba(16, 24, 40, 0.03);
}
.textarea { min-height: 96px; line-height: 1.5; }
/* Móvil y pantallas táctiles: zonas de toque de 44 px (como en main) y letra
 * de 16 px en los campos, que por debajo Safari de iOS amplía la página al
 * enfocarlos y no la devuelve a su tamaño. */
@media (max-width: 900px), (pointer: coarse) {
  :root { --btn-height: 44px; --input-height: 44px; }
  .input, .textarea, .select { font-size: 16px; }
}
.select { padding-right: 36px; background-position: right 10px center; }
.input:hover:not(:focus):not(:disabled),
.textarea:hover:not(:focus):not(:disabled),
.select:hover:not(:focus):not(:disabled) { background-color: var(--surface); border-color: var(--on-surface-muted); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--brand);
  box-shadow: var(--ring-focus);
}
.input::placeholder, .textarea::placeholder { color: var(--on-surface-muted); opacity: 1; }

.checkbox { font-size: 15px; }

/* ── TARJETAS ─────────────────────────────────────────────────────────── */
.card, .hero-card, .panel {
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-box);
  box-shadow: none;
  padding: 18px 20px;
}
.card-sm { padding: 14px 16px; }
.card-elevated { box-shadow: none; }

/* ── ETIQUETAS DE ESTADO ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0;
  height: 22px;
  padding: 0 7px;
  border: 0;
  border-radius: 4px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1;
  white-space: nowrap;
}
.badge::before { display: none !important; }
.badge-asignar,
.badge-pendiente_aceptacion,
.badge-programado,
.badge-en_curso,
.badge-cerrado,
.badge-cancelado,
.badge-cobrado,
.badge-pendiente,
.badge-provisional,
.badge-parcial { border: 0; }
.badge-asignar              { background: var(--pill-warn-bg);    color: var(--pill-warn-fg); }
.badge-pendiente_aceptacion { background: var(--pill-neutral-bg); color: var(--pill-neutral-fg); }
.badge-programado           { background: var(--pill-info-bg);    color: var(--pill-info-fg); }
.badge-en_curso             { background: var(--pill-violet-bg);  color: var(--pill-violet-fg); }
.badge-cerrado              { background: var(--pill-success-bg); color: var(--pill-success-fg); }
.badge-cancelado            { background: var(--pill-danger-bg);  color: var(--pill-danger-fg); }

.pill { border-radius: 4px; font-weight: 600; }
.pill::before { display: none; }
.pill-info { background: var(--pill-info-bg); color: var(--pill-info-fg); }
.pill-brand { background: color-mix(in srgb, var(--brand) 10%, #fff); color: var(--brand-ink); }

/* ── TABLAS ───────────────────────────────────────────────────────────── */
.table {
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}
/* Caja blanca con línea fina sobre el fondo gris de la página (variante A,
 * 2026-10-20). En el móvil, donde las filas pasan a tarjetas, se quita
 * (sats.css, visitas.css y .ent-table abajo). */
.dt-scroll {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-box);
  box-shadow: none;
}
.table thead th,
.dt-table thead th {
  background: var(--table-head);
  color: var(--ink);
  font-family: var(--font-base);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-2);
}
.table tbody td {
  padding: 13px 12px;
  font-size: 14.5px;
  border-bottom: 1px solid var(--table-line);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-container-low); }

/* Fila de filtros por columna, en el mismo gris que la cabecera. */
.dt-filter th {
  padding: 8px 6px 10px;
  background: var(--table-head);
  border-bottom: 1px solid var(--line-2);
}
.dt-filter th:first-child { padding-left: 12px; }
.dt-filter .select, .dt-filter .dt-f {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13.5px;
  border-radius: var(--radius-ctl);
  box-shadow: none;
}
.dt-filter .select { padding-right: 28px; background-position: right 6px center; }
/* Campos de texto/número/fecha del filtro: el mismo borde fino que los
   desplegables (sin esto salía el borde grueso por defecto del navegador). */
.dt-filter input.dt-f {
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
}
.dt-filter input.dt-f:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring-focus); }
.dt-fc .dt-op {
  min-height: 32px;
  padding: 2px 4px;
  font-size: 13px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-ctl);
  background: var(--surface);
  color: var(--on-surface-variant);
}
.dt-ar { font-size: 9px; margin-left: 3px; color: var(--on-surface-muted); }

/* Pie con paginación */
.st-foot { padding: 12px 4px; font-size: 13.5px; color: var(--on-surface-variant); }

/* ── TABLAS DE ADMIN (.ent-table: Clientes y Usuarios) ────────────────────
 * Mismo aspecto que el listado de SATs (D2-SATs): cabecera de 40 px en gris,
 * filas de ~54 px con línea fina, hover --soft y pie Anterior/Siguiente.
 * SATs y Visitas siguen con sus reglas propias (sats.css / visitas.css).
 * En el móvil (≤ 600 px) cada fila es una tarjeta; el papel de cada celda lo
 * dice su tdClass:
 *   .ent-c-pre    pieza corta delante del título (código)
 *   .ent-c-title  título de la tarjeta (nombre), se corta con «…»
 *   .ent-c-badge  etiqueta de estado, a la derecha de la primera línea
 *   .ent-c-line   línea propia debajo (email)
 *   .ent-c-meta   datos pequeños en una línea, separados por «·»
 * Una celda sin dato lleva <span class="ent-vacio">—</span> y en la tarjeta
 * no se pinta. */
.ent-table thead .dt-sort th { height: 40px; padding-top: 0; padding-bottom: 0; color: var(--ink); }
.ent-table tbody td { padding-top: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--table-line); }
.ent-table tbody tr:last-child td { border-bottom: 0; }
.ent-table tbody tr:hover { background: var(--soft); }
.ent-table .ent-nombre { font-weight: 600; color: var(--ink); }
.ent-table .ent-vacio { color: var(--ink-3); }
.ent-table .col-estado { width: 1%; white-space: nowrap; }
.dt-scroll:has(> .ent-table) ~ .st-foot { border-top: 0; margin-top: 0; padding: 14px 4px; }
.dt-scroll:has(> .ent-table) ~ .st-foot :is(.st-count, .st-pageinfo) { font-size: 13.5px; color: var(--ink-2); }
.dt-scroll:has(> .ent-table) ~ .st-foot .btn-sm {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}
.dt-scroll:has(> .ent-table) ~ .st-foot .btn-sm:disabled { color: var(--ink-3); background: var(--surface); }

/* Modo tabla: los filtros no ensanchan la tabla, ocupan su columna. */
@media (min-width: 601px) {
  .ent-table .dt-filter .select,
  .ent-table .dt-filter .dt-f { width: 100%; min-width: 0; }
  .ent-table .dt-filter .dt-fc { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
  .ent-table .dt-filter .dt-fc .dt-op { flex: none; }
  .ent-table .dt-filter .dt-fc .dt-f { flex: 1 1 64px; }
  /* Que «Todos» del estado y el operador + texto del código quepan. */
  .ent-table .dt-filter .select { min-width: 108px; }
}
@media (min-width: 901px) {
  .ent-table .dt-filter .dt-fc { flex-wrap: nowrap; }
  .ent-table .dt-filter th { min-width: 160px; }
}

@media (max-width: 600px) {
  .dt-scroll:has(> .ent-table) { overflow: visible; background: transparent; border: 0; border-radius: 0; }
  .dt-scroll:has(> .ent-table) ~ .st-foot .btn-sm { min-height: 44px; }
  .ent-table,
  .ent-table thead,
  .ent-table tbody { display: block; width: 100%; }
  .ent-table { border: 0; border-radius: 0; overflow: visible; }

  /* La cabecera queda en dos piezas: la fila de ordenar como chips (los
   * mismos <th class="dt-so"> de siempre, con su clic y su flecha) que se
   * desplaza de lado, y debajo los filtros en un panel de dos columnas, cada
   * uno con la etiqueta de su columna. */
  .ent-table thead { margin-bottom: 4px; }
  .ent-table thead .dt-sort {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 0 0 10px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .ent-table thead .dt-sort::-webkit-scrollbar { display: none; }
  .ent-table thead .dt-sort th:not(.dt-so) { display: none; }
  .ent-table thead .dt-sort th.dt-so {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 2px;
    height: auto;
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--line-2);
    border-radius: 999px;
    background: var(--surface);
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-2);
    white-space: nowrap;
  }
  /* La columna por la que se ordena ahora (la única con flecha). */
  .ent-table thead .dt-sort th.dt-so:has(.dt-ar) {
    border-color: var(--brand);
    color: var(--brand-ink);
    background: color-mix(in srgb, var(--brand) 6%, var(--surface));
  }
  .ent-table thead .dt-filter {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 12px;
    padding: 12px 14px;
    background: var(--soft);
    border: 1px solid var(--line);
    border-radius: 8px;
  }
  .ent-table thead .dt-filter th {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding: 0;
    border: 0;
    background: none;
  }
  .ent-table thead .dt-filter th:empty { display: none; }
  .ent-table thead .dt-filter th::before {
    content: attr(data-label);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-2);
  }
  .ent-table .dt-filter .select,
  .ent-table .dt-filter .dt-f,
  .ent-table .dt-fc .dt-op { min-height: 44px; font-size: 16px; }
  .ent-table .dt-filter .select,
  .ent-table .dt-filter .dt-f { width: 100%; min-width: 0; }
  .ent-table .dt-filter .dt-fc { display: flex; gap: 4px; min-width: 0; }
  .ent-table .dt-filter .dt-fc .dt-op { flex: none; }
  .ent-table .dt-filter .dt-fc .dt-f { flex: 1 1 0; }

  /* Estado vacío (fila sin data-ri). */
  .ent-table tbody tr:not([data-ri]),
  .ent-table tbody tr:not([data-ri]) td { display: block; border: 0; }

  /* Fila tarjeta: «pre · título … estado» / línea / meta · meta. */
  .ent-table tbody tr[data-ri] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 8px;
    row-gap: 3px;
    min-height: 44px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }
  .ent-table tbody tr[data-ri]:hover { background: transparent; }
  .ent-table tbody tr[data-ri]:active { background: var(--soft); }
  .ent-table tbody tr[data-ri]::before { content: ''; order: 4; flex-basis: 100%; height: 0; }
  .ent-table tbody tr[data-ri] td {
    display: block;
    order: 6;
    width: auto;
    min-width: 0;
    padding: 0;
    border: 0;
    text-align: left;
    font-size: 13.5px;
    color: var(--ink-2);
  }
  .ent-table tbody tr[data-ri] td::before { content: none; }
  .ent-table tbody tr[data-ri] td.td-ellipsis { max-width: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ent-table tbody tr[data-ri] td.ent-c-pre { order: 1; flex: none; font-size: 13px; }
  .ent-table tbody tr[data-ri] td.ent-c-title { order: 2; flex: 1 1 0; font-size: 15px; color: var(--ink); }
  .ent-table tbody tr[data-ri] td.ent-c-badge { order: 3; flex: none; margin-left: auto; }
  .ent-table tbody tr[data-ri] td.ent-c-line { order: 5; flex: 0 0 100%; }
  .ent-table tbody tr[data-ri] td.ent-c-meta:has(.ent-vacio) { display: none; }
  .ent-table tbody tr[data-ri] td.ent-c-meta:not(:has(.ent-vacio)) ~ td.ent-c-meta::before { content: '·'; margin-right: 8px; }
}

/* ── VENTANAS (diálogo centrado y panel lateral) ──────────────────────── */
.modal-overlay { background: rgba(16, 24, 40, 0.40); }
.modal { border-radius: var(--radius-box); }
.modal-overlay.center .modal { border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(16, 24, 40, 0.08); }
.modal-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.modal-body { font-size: 15px; }
.modal-overlay.drawer .modal { border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(16, 24, 40, 0.06); }
.modal-overlay.drawer .modal-title { font-size: 18px; padding: 18px 56px 18px 24px; }   /* hueco para la X */
.modal-overlay.drawer .modal-body { padding: 20px 24px; }
.modal-overlay.drawer .modal-actions { padding: 14px 24px; }
.modal-close { border-radius: var(--radius-ctl); }

/* Móvil (≤ 600 px): TODA ventana (panel o diálogo) a pantalla completa.
   Columna de 100dvh: título arriba, cuerpo con scroll y pie con los botones
   como último hijo de la columna (no position:fixed al viewport: así, con el
   teclado abierto, el botón de confirmar se alcanza desplazando y no queda
   detrás del teclado de iOS). z-index --z-modal (1000) > pestañas (30), botón
   fijo y hoja ⋮ del detalle (20/40); la firma (.sig-overlay) va por encima. */
@media (max-width: 600px) {
  .modal-overlay,
  .modal-overlay:is(.center, .drawer) { padding: 0; align-items: stretch; justify-content: stretch; }
  .modal-overlay:is(.center, .drawer) .modal,
  .modal-overlay:is(.center, .drawer) .modal:is(.wide, .xwide, .xxwide) {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: 100dvh;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    transform: translateY(12px);
  }
  .modal-overlay:is(.center, .drawer).open .modal { transform: translateY(0); }
  .modal-overlay:is(.center, .drawer) .modal-title {
    flex: none;
    margin: 0;
    padding: 14px 60px 14px 16px;   /* hueco a la derecha para la X */
    padding-top: max(14px, env(safe-area-inset-top));
    font-size: 17px;
    line-height: 1.3;
    border-bottom: 1px solid var(--line);
  }
  .modal-overlay:is(.center, .drawer) .modal-close {
    top: max(4px, calc(env(safe-area-inset-top) - 10px));
    right: 4px;
    width: 44px; height: 44px;
  }
  .modal-overlay:is(.center, .drawer) .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
  }
  /* Sin título (raro): que el cuerpo no quede debajo de la X. */
  .modal-overlay:is(.center, .drawer) .modal-close + .modal-body { padding-top: 56px; }
  .modal-overlay:is(.center, .drawer) .modal-actions {
    flex: none;
    margin: 0;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--surface);
  }
  .modal-overlay:is(.center, .drawer) .modal-actions-left { width: 100%; margin-right: 0; }
  .modal-overlay:is(.center, .drawer) .modal-actions-left .btn { flex: 1; min-height: 44px; }
  /* Cancelar a la izquierda; el primario a la derecha y más ancho. */
  .modal-overlay:is(.center, .drawer) .modal-actions > .btn { flex: 1 1 0; min-height: 44px; }
  .modal-overlay:is(.center, .drawer) .modal-actions > .btn-filled,
  .modal-overlay:is(.center, .drawer) .modal-actions > .btn-danger { flex-grow: 2; }
}

/* ── ESTADO VACÍO ─────────────────────────────────────────────────────── */
.empty-state .icon-circle {
  width: 48px;
  height: 48px;
  background: var(--surface-container-low);
  color: var(--on-surface-variant);
  border: 1px solid var(--outline-variant);
  box-shadow: none;
}
.empty-state .icon-circle .ms { font-size: 24px; }
.empty-state.mini .icon-circle { width: 40px; height: 40px; box-shadow: none; }
.empty-state.mini .icon-circle .ms { font-size: 21px; }
.empty-state .title { font-size: 16px; font-weight: 600; letter-spacing: 0; }
.empty-state .subtitle { font-size: 14px; }

/* ── VARIOS ───────────────────────────────────────────────────────────── */
.filter-chip { border-radius: 999px; box-shadow: none; border: 1px solid var(--outline); }
.snackbar { border-radius: 8px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ── LISTADOS EN EL MÓVIL SOBRE EL FONDO GRIS (variante A, 2026-10-20) ────
 * Donde las tablas pasan a filas-tarjeta, la caja de .dt-scroll se quita y
 * las filas van juntas en un bloque blanco, con margen interior para que no
 * toquen el borde (ni se corte la casilla de imprimir de SATs). Los ids
 * suben la especificidad por encima de sats.css / visitas.css, que cargan
 * después. */
@media (max-width: 640px) {
  #sats-table .dt-scroll,
  #v-list-table .dt-scroll { background: transparent; border: 0; border-radius: 0; }
  #sats-table .sats-table tbody,
  #v-list-table .visitas-table tbody {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-box);
    overflow: hidden;
  }
  #sats-table .sats-table tbody tr[data-ri],
  #v-list-table .visitas-table tbody tr[data-ri] { padding: 12px 14px; }
  #sats-table .sats-table tbody tr[data-ri]:last-child,
  #v-list-table .visitas-table tbody tr[data-ri]:last-child { border-bottom: 0; }
  .horas-table tbody tr { background: var(--surface); }
}
@media (max-width: 600px) {
  .ent-table tbody {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-box);
    overflow: hidden;
  }
  .ent-table tbody tr[data-ri] { padding: 12px 14px; }
  .ent-table tbody tr[data-ri]:last-child { border-bottom: 0; }
}
