/* ==========================================================================
   HUB-APP.CSS — Hoja de estilos por capas (@layer) de Rutakipu Hub
   Proyecto: Rutakipu Hub (API-SHALOM)
   Tablas BD afectadas: Ninguna
   Última actualización: 2026-11-05
   ========================================================================== */

/* --- CAPA BASE Y RESET RESPONSIVE --- */
@layer base {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html,
  body {
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    background-color: var(--canvas);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: var(--fs-body);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  h1,
  h2,
  h3,
  h4 {
    margin: 0;
    font-family: var(--font-display);
    color: var(--ink);
    letter-spacing: -0.015em;
  }

  p {
    margin: 0;
  }

  a {
    color: var(--brand-strong);
    text-decoration: none;
  }

  button,
  input,
  select,
  textarea {
    font-family: inherit;
    font-size: var(--fs-input);
    color: inherit;
  }

  code,
  pre,
  .mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

  .tnum {
    font-variant-numeric: tabular-nums;
  }

  input:-webkit-autofill,
  input:-webkit-autofill:hover,
  input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--ink);
    -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset;
    transition: background-color 6000s ease-in-out 0s;
  }

  :focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
  }
}

/* --- CAPA LAYOUT: SHELL CONSOLA Y LOGIN 2FA --- */
@layer layout {
  /* Shell Principal */
  .app-shell {
    display: grid;
    grid-template-columns: 244px minmax(0, 1fr);
    min-height: 100dvh;
    width: 100%;
    max-width: 100vw;
  }

  .app-sidebar {
    position: sticky;
    top: 0;
    height: 100dvh;
    background-color: var(--side-bg);
    background-image:
      linear-gradient(rgba(148, 163, 184, 0.04) 1px, transparent 1px),
      linear-gradient(90deg, rgba(148, 163, 184, 0.04) 1px, transparent 1px);
    background-size: 24px 24px;
    color: var(--side-ink);
    border-right: 1px solid var(--side-line);
    display: flex;
    flex-direction: column;
    z-index: var(--z-sidebar);
    min-width: 0;
    overflow-y: auto;
  }

  .side-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--side-line);
  }

  .side-brand img {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
  }

  .side-brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .side-brand-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 15px;
    color: var(--side-ink-strong);
  }

  .hub-chip {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--brand);
    color: var(--on-brand);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
  }

  .side-brand-sub {
    font-size: 11px;
    color: var(--side-ink);
  }

  .side-nav {
    flex: 1;
    padding: 10px 10px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .side-group-label {
    padding: 0 10px 4px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #64748B;
  }

  .side-group-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .side-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 40px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--side-ink);
    font-size: 13.5px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  }

  .side-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.88;
  }

  .side-link:hover {
    background: rgba(148, 163, 184, 0.09);
    color: var(--side-ink-strong);
  }

  .side-link.is-active {
    background: linear-gradient(90deg, rgba(217, 119, 6, 0.22), rgba(217, 119, 6, 0.06));
    color: #FFFFFF;
    font-weight: 600;
  }

  .side-link.is-active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--brand);
    box-shadow: 0 0 10px rgba(240, 162, 59, 0.65);
  }

  .side-badge {
    margin-left: auto;
    padding: 1px 7px;
    border-radius: var(--r-pill);
    background: rgba(245, 158, 11, 0.2);
    color: #FBBF24;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
  }

  .side-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--side-line);
    background: rgba(8, 14, 26, 0.45);
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .session-meter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11.5px;
    color: var(--side-ink);
  }

  .app-workspace {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
    min-height: 100dvh;
  }

  .app-topbar {
    position: sticky;
    top: 0;
    height: 56px;
    padding: 0 var(--gutter);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: var(--z-topbar);
    min-width: 0;
  }

  .topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
  }

  .topbar-view-title {
    font-size: 15px;
    white-space: nowrap;
  }

  .topbar-title-short {
    display: none;
  }

  .topbar-search {
    position: relative;
    width: 300px;
    max-width: 34vw;
    min-width: 0;
  }

  .topbar-search input {
    width: 100%;
    height: 36px;
    padding: 0 34px 0 34px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 13px;
  }

  .topbar-search svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    color: var(--muted);
    pointer-events: none;
  }

  .topbar-kbd {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 5px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
  }

  .topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  .app-main {
    flex: 1;
    padding: 14px var(--gutter) 28px;
    min-width: 0;
    max-width: 100%;
  }

  .bottom-nav {
    display: none;
  }

  .sidebar-scrim {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.52);
    z-index: 45;
  }

  /* Cortes de Shell */
  @media (max-width: 1399px) and (min-width: 1181px) {
    .app-shell {
      grid-template-columns: 220px minmax(0, 1fr);
    }
    .side-link {
      min-height: 38px;
      font-size: 13px;
    }
    .topbar-search {
      width: 250px;
    }
  }

  @media (max-width: 1180px) and (min-width: 901px) {
    .app-shell {
      grid-template-columns: 76px minmax(0, 1fr);
    }
    .side-brand {
      justify-content: center;
      padding: 12px 6px;
    }
    .side-brand-text,
    .side-group-label,
    .side-badge,
    .side-footer .session-label {
      display: none;
    }
    .side-nav {
      padding: 8px 6px;
      gap: 6px;
    }
    .side-link {
      flex-direction: column;
      justify-content: center;
      gap: 3px;
      padding: 6px 4px;
      min-height: 52px;
      font-size: 10.5px;
      text-align: center;
    }
    .side-footer {
      align-items: stretch;
      padding: 8px 6px;
    }
    .topbar-search {
      width: 210px;
    }
  }

  @media (max-width: 900px) {
    .app-shell {
      grid-template-columns: minmax(0, 1fr);
    }
    .app-sidebar {
      position: fixed;
      left: 0;
      top: 0;
      bottom: 0;
      width: min(280px, 84vw);
      visibility: hidden;
      transform: translateX(-104%);
      transition: transform var(--dur-med) var(--ease-out), visibility var(--dur-med);
      box-shadow: var(--sh-3);
    }
    .app-sidebar.is-open {
      visibility: visible;
      transform: translateX(0);
    }
    .topbar-search {
      display: none;
    }
    .app-main {
      padding: 12px var(--gutter) 84px;
    }
    .bottom-nav {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      height: 62px;
      background: var(--surface);
      border-top: 1px solid var(--border);
      display: grid;
      grid-template-columns: repeat(5, minmax(0, 1fr));
      z-index: var(--z-topbar);
      padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .bottom-nav-btn {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 2px;
      min-height: 44px;
      border: 0;
      background: transparent;
      color: var(--muted);
      font-size: 11px;
      font-weight: 600;
      cursor: pointer;
    }
    .bottom-nav-btn svg {
      width: 19px;
      height: 19px;
    }
    .bottom-nav-btn.is-active {
      color: var(--brand-strong);
    }
  }

  @media (max-width: 600px) {
    .app-topbar {
      height: 52px;
      padding: 0 12px;
      gap: 8px;
    }
    .topbar-right {
      gap: 6px;
    }
    .app-main {
      padding: 10px 12px 82px;
    }
  }
}

/* --- CAPA COMPONENTES --- */
@layer components {
  /* Cabecera compacta de sección (1 fila anti-relleno) */
  .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    min-width: 0;
  }

  .section-title-wrap {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
  }

  .section-header h1 {
    font-size: clamp(18px, 1.4vw + 12px, 22px);
    line-height: 1.2;
    font-weight: 700;
    color: var(--ink);
  }

  .section-sub {
    font-size: 12.5px;
    color: var(--muted);
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  @media (max-width: 900px) {
    .section-sub {
      display: none;
    }
  }

  /* Botones vivos (carbón sobre ámbar) */
  .btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 0 14px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition:
      transform var(--dur-fast) var(--ease-spring),
      background-color var(--dur-fast) var(--ease-out),
      border-color var(--dur-fast) var(--ease-out),
      box-shadow var(--dur-fast) var(--ease-out);
  }

  .btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  .btn-primary {
    background-color: var(--brand);
    color: var(--on-brand);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 1px 2px rgba(15, 23, 42, 0.12);
  }

  .btn-primary:hover {
    background-color: var(--brand-hover);
    transform: translateY(-1px);
    box-shadow: var(--sh-brand);
  }

  .btn-primary:active {
    background-color: var(--brand-press);
    transform: scale(0.98);
  }

  .btn-secondary {
    background-color: var(--surface);
    color: var(--ink);
    border-color: var(--border-strong);
  }

  .btn-secondary:hover {
    border-color: var(--brand);
    background-color: var(--brand-tint);
    color: var(--brand-strong);
  }

  .btn-ghost {
    background-color: transparent;
    color: var(--ink-2);
  }

  .btn-ghost:hover {
    background-color: var(--sunken);
    color: var(--ink);
  }

  .btn-danger-quiet {
    background-color: var(--danger-tint);
    color: var(--danger-ink);
    border-color: rgba(239, 68, 68, 0.25);
  }

  .btn-danger-quiet:hover {
    background-color: rgba(239, 68, 68, 0.22);
  }

  .btn-danger-solid {
    background-color: var(--danger-fill);
    color: #FFFFFF;
  }

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

  .btn-icon {
    min-width: 38px;
    min-height: 38px;
    padding: 0;
  }

  .btn-sidebar-logout {
    width: 100%;
    background-color: rgba(148, 163, 184, 0.12);
    color: var(--side-ink-strong);
    border-color: var(--side-line);
  }

  .btn-sidebar-logout:hover {
    background-color: rgba(240, 162, 59, 0.18);
    border-color: rgba(240, 162, 59, 0.45);
    color: #FFFFFF;
  }

  .btn-sidebar-logout .logout-short {
    display: none;
  }

  @media (max-width: 1180px) and (min-width: 901px) {
    .btn-sidebar-logout {
      flex-direction: column;
      gap: 3px;
      padding: 6px 4px;
      min-height: 46px;
      font-size: 10.5px;
    }
    .btn-sidebar-logout .logout-text {
      display: none;
    }
    .btn-sidebar-logout .logout-short {
      display: inline;
    }
  }

  .mobile-menu-btn {
    display: none;
  }

  @media (max-width: 900px) {
    .mobile-menu-btn {
      display: inline-flex;
      min-width: 42px;
      min-height: 42px;
    }
  }

  [data-theme="light"] #themeIconSun {
    display: none;
  }

  [data-theme="dark"] #themeIconMoon {
    display: none;
  }

  .btn[aria-disabled="true"],
  .btn:disabled {
    opacity: 0.52;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }

  /* Píldora de telemetría viva (única animación infinita permitida) */
  .telemetry-wrap {
    position: relative;
  }

  .telemetry-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 36px;
    padding: 0 11px;
    border-radius: var(--r-pill);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
  }

  .telemetry-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55);
    animation: radarPulse 2.2s infinite var(--ease-out);
  }

  .telemetry-pill[data-status="LENTO"] .telemetry-dot {
    background: var(--warning);
  }

  .telemetry-pill[data-status="DEGRADADO"] .telemetry-dot {
    background: var(--danger);
    animation: none;
  }

  @keyframes radarPulse {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
    70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
  }

  .telemetry-popover {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 280px;
    padding: 12px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--sh-2);
    z-index: var(--z-dropdown);
  }

  @media (max-width: 600px) {
    .telemetry-label-long {
      display: none;
    }
  }

  .telemetry-chevron {
    flex-shrink: 0;
    opacity: 0.72;
  }

  @media (max-width: 480px) {
    .telemetry-prefix {
      display: none;
    }
    .telemetry-pill {
      padding: 0 9px;
      gap: 5px;
    }
  }

  /* Acciones Topbar v1.1.0 y cabecera ejecutiva del Dashboard */
  .btn-topbar-key {
    background-color: #0F172A;
    color: #F8FAFC;
    border-color: #0F172A;
    padding: 0 12px;
    min-height: 36px;
    font-size: 13px;
  }

  .btn-topbar-key:hover {
    background-color: #1E293B;
    border-color: #1E293B;
    transform: translateY(-1px);
  }

  [data-theme="dark"] .btn-topbar-key {
    background-color: var(--surface-2);
    color: var(--ink);
    border-color: var(--border-strong);
  }

  [data-theme="dark"] .btn-topbar-key:hover {
    border-color: var(--brand);
    background-color: var(--brand-tint);
    color: var(--brand-strong);
  }

  @media (max-width: 640px) {
    .btn-topbar-key {
      display: none;
    }
  }

  .btn-topbar-agencias {
    display: none;
    min-height: 36px;
    padding: 0 12px;
    font-size: 13px;
  }

  .app-shell[data-route="agencias"] .btn-topbar-agencias {
    display: inline-flex;
  }

  .app-shell[data-route="agencias"] #btnTopCreateKey {
    display: none;
  }

  .app-shell[data-route="agencias"] .topbar-view-title {
    font-size: 17.5px;
    font-weight: 800;
    letter-spacing: -0.02em;
  }

  @media (max-width: 680px) {
    .app-shell[data-route="agencias"] .btn-topbar-agencias {
      display: none;
    }
    .app-shell[data-route="agencias"] .topbar-view-title {
      font-size: 15px;
    }
  }

  @media (max-width: 420px) {
    .topbar-title-long {
      display: none;
    }
    .topbar-title-short {
      display: inline;
    }
  }

  @keyframes hubSpin320 {
    to {
      transform: rotate(360deg);
    }
  }

  #btnTopRefresh.is-spinning svg {
    animation: hubSpin320 320ms var(--ease-out);
  }

  .section-header--dash .section-title-wrap {
    align-items: center;
  }

  .dash-pulse-badge {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--brand-tint);
    border: 1px solid rgba(217, 119, 6, 0.28);
    color: var(--brand-strong);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .dash-title-stack {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
  }

  .hub-meta-chip {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 9px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
  }

  .hub-role-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 28px;
    padding: 0 10px;
    border-radius: var(--r-pill);
    background: var(--brand-tint);
    border: 1px solid rgba(217, 119, 6, 0.28);
    color: var(--brand-strong);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
  }

  .sync-txt-short {
    display: none;
  }

  @media (max-width: 1180px) {
    .section-header--dash .section-sub {
      display: none;
    }
  }

  @media (max-width: 960px) {
    .hub-role-chip {
      display: none;
    }
  }

  @media (max-width: 768px) {
    #dashVersionChip {
      display: none;
    }
  }

  @media (max-width: 480px) {
    .dash-pulse-badge {
      display: none;
    }
  }

  @media (max-width: 420px) {
    .sync-txt-long {
      display: none;
    }
    .sync-txt-short {
      display: inline;
    }
  }

  /* Barra de filtros y carrusel de píldoras */
  .toolbar-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    min-width: 0;
  }

  .pill-rail {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    max-width: 100%;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    min-height: 34px;
    padding: 0 11px;
    border-radius: var(--r-pill);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-2);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
  }

  .pill:hover {
    border-color: var(--brand);
    color: var(--ink);
  }

  .pill.is-active {
    background: var(--brand-tint-2);
    border-color: var(--brand);
    color: var(--brand-strong);
  }

  #agenciasStatusRail .pill.is-active {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--on-brand);
    font-weight: 700;
  }

  .toolbar-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    min-width: 0;
  }

  .input-ctrl,
  .select-ctrl {
    min-height: 36px;
    padding: 0 11px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--ink);
    min-width: 0;
  }

  .input-ctrl:focus,
  .select-ctrl:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.18);
  }

  @media (max-width: 820px) {
    .toolbar-bar {
      flex-direction: column;
      align-items: stretch;
      gap: 8px;
    }
    .pill-rail {
      padding-right: 18px;
      -webkit-mask-image: linear-gradient(90deg, rgba(15, 23, 42, 1) calc(100% - 22px), transparent);
      mask-image: linear-gradient(90deg, rgba(15, 23, 42, 1) calc(100% - 22px), transparent);
    }
    .toolbar-inputs {
      width: 100%;
    }
    .toolbar-inputs .input-ctrl,
    .toolbar-inputs .select-ctrl {
      flex: 1;
    }
  }

  @media (max-width: 480px) {
    .toolbar-inputs {
      flex-direction: column;
      align-items: stretch;
      gap: 6px;
    }
    .toolbar-inputs .input-ctrl,
    .toolbar-inputs .select-ctrl {
      width: 100%;
      flex: none;
    }
  }

  /* Insignias de estado */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
  }

  .badge-success { background: var(--success-tint); color: var(--success-ink); }
  .badge-warning { background: var(--warning-tint); color: var(--warning-ink); }
  .badge-danger { background: var(--danger-tint); color: var(--danger-ink); }
  .badge-info { background: var(--info-tint); color: var(--info-ink); }
  .badge-neutral { background: var(--sunken); color: var(--muted); }

  /* Tarjetas y Tablas densas */
  .surface-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--sh-1);
    min-width: 0;
    max-width: 100%;
  }

  .table-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-radius: var(--r-md);
  }

  .hub-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
  }

  .hub-table th {
    padding: 9px 12px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }

  .hub-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--ink);
  }

  .hub-table tbody tr:hover {
    background: var(--surface-2);
  }

  .hub-table tbody tr:last-child td {
    border-bottom: 0;
  }

  .row-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  /* Barra de cuota */
  .quota-meter {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 108px;
  }

  .quota-track {
    height: 6px;
    border-radius: 99px;
    background: var(--sunken);
    overflow: hidden;
  }

  .quota-fill {
    height: 100%;
    border-radius: 99px;
    background: var(--brand);
  }

  /* Tarjetas móviles para <= 768px */
  .mobile-cards {
    display: none;
    flex-direction: column;
    gap: 8px;
  }

  .m-card {
    padding: 12px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
  }

  .m-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
  }

  .m-card-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--ink);
    overflow-wrap: anywhere;
  }

  .m-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 12.5px;
    color: var(--muted);
  }

  .m-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
  }

  @media (max-width: 768px) {
    .responsive-data .table-scroll {
      display: none;
    }
    .responsive-data .mobile-cards {
      display: flex;
    }
  }

  /* Objetivos táctiles >= 44px en teléfonos (<= 680px) */
  @media (max-width: 680px) {
    button,
    a[href],
    [role="button"],
    input,
    select,
    .btn,
    .btn-sm,
    .btn-icon,
    .pill,
    .telemetry-pill,
    .input-ctrl,
    .select-ctrl,
    .bottom-nav-btn {
      min-height: 44px;
      min-width: 44px;
    }
    .btn-sm {
      padding: 0 12px;
    }
    .pill {
      padding: 0 13px;
    }
  }

  /* Drawer / Bottom-sheet de inspección (#keyDetalle) */
  .drawer-scrim {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.48);
    z-index: var(--z-drawer);
  }

  .hub-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(440px, 92vw);
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--sh-3);
    z-index: calc(var(--z-drawer) + 1);
    display: flex;
    flex-direction: column;
  }

  .drawer-head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .drawer-foot {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  @media (max-width: 680px) {
    .hub-drawer {
      top: auto;
      left: 0;
      right: 0;
      width: 100%;
      max-height: 88dvh;
      border-left: 0;
      border-top: 1px solid var(--border);
      border-radius: var(--r-lg) var(--r-lg) 0 0;
    }
  }

  /* Modales nativos <dialog> (destructivo siempre a la izquierda) */
  .hub-modal {
    width: min(540px, calc(100vw - 24px));
    max-height: 90dvh;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--sh-3);
  }

  .hub-modal::backdrop {
    background: rgba(15, 23, 42, 0.58);
  }

  .modal-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .modal-body {
    padding: 16px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .modal-foot {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .modal-foot-right {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
  }

  .form-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
  }

  .form-field label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-2);
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .form-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  @media (max-width: 600px) {
    .form-grid-2 {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  /* Toasts */
  .toast-region {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(360px, calc(100vw - 32px));
    pointer-events: none;
  }

  .toast-item {
    pointer-events: auto;
    padding: 12px 14px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--brand);
    box-shadow: var(--sh-2);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
  }

  .toast-item.toast-success { border-left-color: var(--success); }
  .toast-item.toast-warning { border-left-color: var(--warning); }
  .toast-item.toast-error { border-left-color: var(--danger); }

  @media (max-width: 900px) {
    .toast-region {
      bottom: 74px;
    }
  }

  /* Loader Kipu y estado Courier (.cs) */
  .kipu-cord {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .kipu-knot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand);
  }
}

/* --- CAPA MÓDULOS: VISTAS DEL HUB Y LOGIN 2FA --- */
@layer modules {
  /* 1. Dashboard v1.1.0 (#hubSalud + 6 KPIs + Gráfico 30d + Alertas + Radar/Clientes) */
  .health-strip {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
  }

  .health-card {
    padding: 11px 12px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
  }

  .health-card-top {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
  }

  .health-icon {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--sunken);
    color: var(--ink-2);
  }

  .health-icon[data-tone="emerald"] {
    background: var(--success-tint);
    color: var(--success-ink);
  }

  .health-icon[data-tone="amber"] {
    background: var(--brand-tint);
    color: var(--brand-strong);
  }

  .health-icon[data-tone="info"] {
    background: rgba(59, 130, 246, 0.14);
    color: #2563EB;
  }

  [data-theme="dark"] .health-icon[data-tone="info"] {
    color: #60A5FA;
  }

  .health-cap-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.25;
  }

  .health-sub {
    font-size: 11.5px;
    color: var(--muted);
    min-width: 0;
  }

  .health-foot {
    margin-top: auto;
    padding-top: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
  }

  .health-meta {
    font-size: 11.5px;
    color: var(--ink-2);
    min-width: 0;
  }

  .health-spark {
    flex-shrink: 0;
    display: block;
  }

  .kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
  }

  .kpi-card {
    padding: 11px 12px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
  }

  .kpi-head {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }

  .kpi-icon {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--sunken);
    color: var(--ink-2);
  }

  .kpi-icon[data-tone="amber"] {
    background: var(--brand-tint);
    color: var(--brand-strong);
  }

  .kpi-icon[data-tone="emerald"] {
    background: var(--success-tint);
    color: var(--success-ink);
  }

  .kpi-icon[data-tone="danger"] {
    background: var(--danger-tint);
    color: var(--danger-ink);
  }

  .kpi-icon[data-tone="info"] {
    background: rgba(59, 130, 246, 0.14);
    color: #2563EB;
  }

  [data-theme="dark"] .kpi-icon[data-tone="info"] {
    color: #60A5FA;
  }

  .kpi-icon[data-tone="violet"] {
    background: rgba(99, 102, 241, 0.14);
    color: #4338CA;
  }

  [data-theme="dark"] .kpi-icon[data-tone="violet"] {
    background: rgba(129, 140, 248, 0.16);
    color: #A5B4FC;
  }

  .kpi-label {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 11.5px;
    line-height: 1.25;
    font-weight: 600;
    color: var(--muted);
    white-space: normal;
    overflow-wrap: normal;
  }

  .kpi-main {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px 6px;
    min-width: 0;
  }

  .kpi-value {
    flex: 0 0 auto;
    max-width: 100%;
    font-family: var(--font-display);
    font-size: clamp(18px, 1.05vw + 7px, 22px);
    line-height: 1.15;
    font-weight: 700;
    color: var(--ink);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .kpi-trend {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    border-radius: var(--r-pill);
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .kpi-trend--up {
    background: var(--success-tint);
    color: var(--success-ink);
  }

  .kpi-trend--warn {
    background: var(--warning-tint);
    color: var(--warning-ink);
  }

  .kpi-trend--danger {
    background: var(--danger-tint);
    color: var(--danger-ink);
  }

  .kpi-trend--neutral {
    background: var(--sunken);
    color: var(--muted);
  }

  .kpi-delta {
    font-size: 11px;
    color: var(--muted);
    min-width: 0;
  }

  .dash-lower-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 350px;
    gap: 12px;
    align-items: stretch;
  }

  .chart-box,
  .dash-panel-card {
    padding: 14px;
    min-width: 0;
    display: flex;
    flex-direction: column;
  }

  .dash-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    min-width: 0;
  }

  .panel-head-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .panel-icon-amber {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--brand-tint);
    color: var(--brand-strong);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .panel-h2 {
    font-size: 14.5px;
    line-height: 1.25;
  }

  .panel-sub {
    font-size: 11.5px;
    color: var(--muted);
  }

  .chart-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-bottom: 10px;
  }

  .chart-head-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 14px;
  }

  .chart-summary-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--r-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 12px;
  }

  .chart-summary-label {
    color: var(--muted);
    font-size: 11px;
  }

  .chart-summary-val {
    font-size: 13.5px;
    color: var(--ink);
  }

  .chart-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 9px;
    font-size: 11.5px;
    color: var(--muted);
  }

  .legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    margin-right: 4px;
  }

  .legend-line-amber {
    display: inline-block;
    width: 12px;
    height: 2.5px;
    border-radius: 99px;
    background: var(--brand);
    vertical-align: middle;
    margin-right: 4px;
  }

  .alert-count-badge {
    min-width: 24px;
    height: 24px;
    padding: 0 7px;
    border-radius: var(--r-pill);
    background: var(--brand);
    color: var(--on-brand);
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .alert-count-badge[data-zero="true"] {
    background: var(--success-tint);
    color: var(--success-ink);
  }

  .alert-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .alert-row {
    padding: 10px 11px;
    border-radius: var(--r-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 9px;
    min-width: 0;
  }

  .alert-row[data-severity="WARNING"] {
    background: var(--warning-tint);
    border-color: rgba(245, 158, 11, 0.28);
  }

  .alert-row[data-severity="DANGER"] {
    background: var(--danger-tint);
    border-color: rgba(239, 68, 68, 0.26);
  }

  .alert-row-icon,
  .radar-pin {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--surface);
    color: var(--brand-strong);
  }

  .alert-row[data-severity="DANGER"] .alert-row-icon,
  .radar-pin[data-tone="danger"] {
    color: var(--danger-ink);
    background: var(--danger-tint);
  }

  .radar-pin[data-tone="emerald"] {
    color: var(--success-ink);
    background: var(--success-tint);
  }

  .radar-pin[data-tone="info"] {
    color: #2563EB;
    background: rgba(59, 130, 246, 0.14);
  }

  [data-theme="dark"] .radar-pin[data-tone="info"] {
    color: #60A5FA;
  }

  .radar-pin[data-tone="amber"] {
    color: var(--brand-strong);
    background: var(--brand-tint);
  }

  .radar-pin[data-tone="violet"] {
    color: #4338CA;
    background: rgba(99, 102, 241, 0.14);
  }

  [data-theme="dark"] .radar-pin[data-tone="violet"] {
    color: #A5B4FC;
    background: rgba(129, 140, 248, 0.16);
  }

  .alert-row-body {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .dash-band-4 {
    margin-top: 12px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: stretch;
  }

  .client-usage-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
  }

  .client-usage-row {
    padding: 9px 11px;
    border-radius: var(--r-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  .client-usage-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .client-usage-icon[data-type="internal"] {
    color: var(--success-ink);
  }

  .client-usage-icon[data-type="external"] {
    color: var(--brand-strong);
  }

  .client-usage-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .client-usage-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
  }

  .client-usage-name {
    font-size: 13px;
    color: var(--ink);
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .client-usage-pct {
    font-size: 12.5px;
    color: var(--ink);
    flex-shrink: 0;
  }

  .client-usage-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
  }

  .client-usage-track {
    flex: 1 1 90px;
    max-width: 180px;
    height: 6px;
    border-radius: 99px;
    background: var(--sunken);
    overflow: hidden;
  }

  .client-usage-fill {
    display: block;
    height: 100%;
    border-radius: 99px;
    background: #10B981;
  }

  .client-usage-fill[data-type="external"] {
    background: var(--brand);
  }

  @media (max-width: 1180px) and (min-width: 901px) {
    .health-strip {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .kpi-grid {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  @media (max-width: 1180px) {
    .dash-lower-grid {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  @media (max-width: 900px) and (min-width: 641px) {
    .health-strip {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .health-strip > .health-card:nth-child(5) {
      grid-column: 1 / -1;
    }
    .kpi-grid {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  @media (max-width: 900px) {
    .dash-band-4 {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  @media (max-width: 640px) {
    .health-strip {
      grid-template-columns: minmax(0, 1fr);
    }
    .kpi-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  /* 2. Radar Ejecutivo Multi-Courier v1.4.0 (#viewAgencias) */
  .health-card[data-dash-courier] {
    cursor: pointer;
    transition: border-color var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast);
  }

  .health-card[data-dash-courier]:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
  }

  .agencias-top-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
    min-width: 0;
  }

  .agencias-top-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 12px;
    min-width: 0;
    flex: 1 1 auto;
  }

  .ag-courier-rail {
    gap: 4px;
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    flex-shrink: 0;
  }

  .ag-courier-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 700;
  }

  .ag-courier-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--brand);
  }

  .ag-courier-dot[data-courier="SHALOM"] {
    background: #10B981;
  }

  .ag-courier-dot[data-courier="MARVISUR"] {
    background: #F59E0B;
  }

  .ag-courier-dot[data-courier="OLVA"] {
    background: #3B82F6;
  }

  .ag-courier-pill.is-active .ag-courier-dot {
    background: var(--on-brand);
  }

  .ag-courier-count {
    padding: 1px 6px;
    border-radius: var(--r-pill);
    background: rgba(15, 23, 42, 0.08);
    font-size: 11px;
    font-weight: 700;
  }

  [data-theme="dark"] .ag-courier-count {
    background: rgba(255, 255, 255, 0.12);
  }

  .ag-courier-pill.is-active .ag-courier-count {
    background: rgba(15, 23, 42, 0.18);
    color: var(--on-brand);
  }

  .agencias-subline {
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.35;
    min-width: 0;
  }

  .ag-sub-compact {
    display: none;
  }

  .agencias-mobile-actions {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .ag-kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 8px;
  }

  .ag-kpi-card {
    padding: 9px 11px;
    gap: 4px;
    cursor: pointer;
    text-align: left;
    transition: border-color var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast);
  }

  .ag-kpi-card:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
  }

  .ag-kpi-card.is-active {
    border-color: var(--brand);
    box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.16);
  }

  .ag-kpi-modes {
    font-size: 12px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.25;
    white-space: normal;
  }

  .agencias-rail-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    min-width: 0;
  }

  .agencias-filter-toggle {
    display: none;
    flex-shrink: 0;
    gap: 5px;
  }

  .ag-filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--r-pill);
    background: var(--brand);
    color: var(--on-brand);
    font-size: 11px;
    font-weight: 700;
  }

  .agencias-filters-bar {
    display: grid;
    grid-template-columns:
      minmax(115px, 1.05fr)
      minmax(110px, 1fr)
      minmax(108px, 0.92fr)
      minmax(96px, 0.82fr)
      minmax(145px, 1.35fr)
      auto
      auto;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    margin-bottom: 10px;
  }

  .agencias-filters-bar .select-ctrl,
  .agencias-filters-bar .input-ctrl {
    min-height: 34px;
    font-size: 12.5px;
    padding: 0 9px;
    width: 100%;
  }

  .ag-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .ag-search-wrap svg {
    position: absolute;
    left: 9px;
    color: var(--muted);
    pointer-events: none;
  }

  .ag-search-wrap .input-ctrl {
    padding-left: 29px;
  }

  .ag-switch-label {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-2);
    white-space: nowrap;
    user-select: none;
    padding: 0 4px;
  }

  .ag-switch-input {
    position: absolute;
    width: 1px;
    height: 1px;
    min-width: 0;
    min-height: 0;
    margin: 0;
    opacity: 0;
    pointer-events: none;
  }

  .ag-switch-track {
    position: relative;
    width: 34px;
    height: 19px;
    border-radius: var(--r-pill);
    background: var(--border-strong);
    flex-shrink: 0;
    transition: background-color var(--dur-fast);
  }

  .ag-switch-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.25);
    transition: transform var(--dur-fast);
  }

  .ag-switch-input:checked + .ag-switch-track {
    background: var(--brand);
  }

  .ag-switch-input:checked + .ag-switch-track::after {
    transform: translateX(15px);
  }

  .ag-switch-input:focus-visible + .ag-switch-track {
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.24);
  }

  .ag-switch-short,
  .ag-clear-short {
    display: none;
  }

  .agencias-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 308px;
    gap: 12px;
    align-items: start;
  }

  .agencias-list-col {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .agencias-side-col {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .agencias-exec-table {
    table-layout: auto;
  }

  .agencias-exec-table th {
    padding: 8px 8px;
    font-size: 10.5px;
    letter-spacing: 0.04em;
    white-space: nowrap;
  }

  .agencias-exec-table td {
    padding: 8px 8px;
    font-size: 12.5px;
  }

  .ag-name-link {
    background: transparent;
    border: 0;
    padding: 0;
    font-size: 12.5px;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    line-height: 1.3;
  }

  .ag-name-link:hover {
    color: var(--brand-strong);
    text-decoration: underline;
  }

  .ag-addr-cell {
    font-size: 11.5px;
    color: var(--ink-2);
    line-height: 1.35;
    max-width: 260px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .ag-mod-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .ag-mod-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ink-2);
    white-space: nowrap;
  }

  .ag-mod-icon[data-mod="air"] {
    color: var(--brand-strong);
  }

  .ag-mod-icon[data-mod="delivery"] {
    color: var(--success-ink);
  }

  .ag-mod-icon[data-mod="store"] {
    color: var(--info-ink);
  }

  .ag-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
  }

  .ag-status-pill[data-st="ACTIVA"] {
    background: var(--success-tint);
    color: var(--success-ink);
  }

  .ag-status-pill[data-st="REABIERTA"] {
    background: var(--info-tint);
    color: var(--info-ink);
  }

  .ag-status-pill[data-st="NUEVA"] {
    background: rgba(99, 102, 241, 0.14);
    color: #4338CA;
  }

  [data-theme="dark"] .ag-status-pill[data-st="NUEVA"] {
    background: rgba(129, 140, 248, 0.18);
    color: #A5B4FC;
  }

  .ag-status-pill[data-st="CAIDA"] {
    background: var(--danger-tint);
    color: var(--danger-ink);
  }

  .ag-row-actions {
    gap: 2px;
  }

  .ag-act-btn {
    width: 28px;
    height: 28px;
    min-height: 28px;
    padding: 0;
    border-radius: var(--r-xs);
    color: var(--muted);
  }

  .ag-act-btn:hover {
    color: var(--ink);
    background: var(--sunken);
  }

  .agencias-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--r-md) var(--r-md);
  }

  .ag-page-info {
    font-size: 12px;
    color: var(--muted);
  }

  .ag-page-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
  }

  .ag-page-size-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
  }

  .select-ctrl--sm {
    min-height: 30px;
    padding: 0 8px;
    font-size: 12px;
  }

  .ag-page-nav {
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }

  .ag-page-btn {
    min-width: 30px;
    height: 30px;
    padding: 0 7px;
    border-radius: var(--r-xs);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color var(--dur-fast), background-color var(--dur-fast);
  }

  .ag-page-btn:hover:not(:disabled) {
    border-color: var(--brand);
    color: var(--ink);
  }

  .ag-page-btn.is-active {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--on-brand);
    font-weight: 700;
  }

  .ag-page-btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
  }

  .ag-page-ellipsis {
    padding: 0 4px;
    color: var(--muted);
    font-size: 12px;
  }

  .ag-event-item {
    width: 100%;
    cursor: pointer;
    text-align: left;
    transition: border-color var(--dur-fast), background-color var(--dur-fast);
  }

  .ag-event-item:hover {
    border-color: var(--brand);
  }

  .ag-ev-prefix[data-tone="emerald"] { color: var(--success-ink); }
  .ag-ev-prefix[data-tone="violet"] { color: #4338CA; }
  [data-theme="dark"] .ag-ev-prefix[data-tone="violet"] { color: #A5B4FC; }
  .ag-ev-prefix[data-tone="danger"] { color: var(--danger-ink); }
  .ag-ev-prefix[data-tone="amber"] { color: var(--brand-strong); }

  .ag-calm-box {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    background: var(--success-tint);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: var(--ink);
  }

  .ag-top-depts {
    display: flex;
    flex-direction: column;
    gap: 7px;
  }

  .ag-dept-bar-row {
    width: 100%;
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr) 34px;
    align-items: center;
    gap: 8px;
    padding: 5px 7px;
    border-radius: var(--r-xs);
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    text-align: left;
    transition: background-color var(--dur-fast), border-color var(--dur-fast);
  }

  .ag-dept-bar-row:hover {
    background: var(--surface-2);
    border-color: var(--border);
  }

  .ag-dept-bar-row.is-active {
    background: var(--brand-tint);
    border-color: var(--brand);
  }

  .ag-dept-name {
    font-size: 12.5px;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ag-dept-track {
    height: 8px;
    border-radius: var(--r-pill);
    background: var(--sunken);
    overflow: hidden;
  }

  .ag-dept-fill {
    display: block;
    height: 100%;
    border-radius: var(--r-pill);
    background: var(--success);
  }

  .ag-dept-count {
    font-size: 12px;
    color: var(--ink);
    text-align: right;
  }

  .ag-changes-tiles {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .ag-change-tile {
    padding: 10px 6px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    transition: transform var(--dur-fast), border-color var(--dur-fast);
  }

  .ag-change-tile:hover {
    transform: translateY(-1px);
    border-color: var(--brand);
  }

  .ag-change-tile[data-tone="emerald"] {
    background: var(--success-tint);
    border-color: rgba(16, 185, 129, 0.24);
    color: var(--success-ink);
  }

  .ag-change-tile[data-tone="violet"] {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.24);
    color: #4338CA;
  }

  [data-theme="dark"] .ag-change-tile[data-tone="violet"] {
    background: rgba(129, 140, 248, 0.16);
    border-color: rgba(129, 140, 248, 0.28);
    color: #A5B4FC;
  }

  .ag-change-tile[data-tone="danger"] {
    background: var(--danger-tint);
    border-color: rgba(239, 68, 68, 0.24);
    color: var(--danger-ink);
  }

  .ag-tile-icon {
    display: inline-flex;
  }

  .ag-tile-val {
    font-family: var(--font-display);
    font-size: 19px;
    line-height: 1.1;
    color: var(--ink);
  }

  .ag-tile-lbl {
    font-size: 11px;
    font-weight: 600;
    color: var(--ink-2);
  }

  .ag-empty-state {
    padding: 28px 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }

  @media (max-width: 1320px) {
    .ag-switch-long,
    .ag-clear-long {
      display: none;
    }
    .ag-switch-short,
    .ag-clear-short {
      display: inline;
    }
  }

  @media (max-width: 1180px) {
    .ag-kpi-grid {
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 7px;
    }
    .ag-kpi-card {
      padding: 7px 10px;
      gap: 3px;
    }
    .agencias-filters-bar {
      grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(125px, 1.2fr) auto auto;
      gap: 6px;
      padding: 7px 8px;
      margin-bottom: 8px;
    }
    .agencias-layout {
      grid-template-columns: minmax(0, 1fr);
    }
    .agencias-side-col {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 10px;
    }
  }

  @media (max-width: 860px) {
    .agencias-filter-toggle {
      display: inline-flex;
    }
    .agencias-filters-bar {
      display: none;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 8px;
      padding: 10px;
    }
    .agencias-filters-bar.is-open {
      display: grid;
    }
    .agencias-side-col {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  @media (max-width: 680px) {
    .agencias-top-strip {
      flex-direction: column;
      align-items: stretch;
      gap: 6px;
    }
    .agencias-subline {
      font-size: 11.5px;
      white-space: normal;
      overflow: visible;
      text-overflow: clip;
    }
    .ag-sub-full {
      display: none;
    }
    .ag-sub-compact {
      display: inline;
    }
    .agencias-mobile-actions {
      display: grid;
    }
    .ag-kpi-grid {
      display: flex;
      overflow-x: auto;
      gap: 8px;
      padding-bottom: 2px;
      scrollbar-width: thin;
      -webkit-mask-image: linear-gradient(90deg, rgba(15, 23, 42, 1) calc(100% - 22px), transparent);
      mask-image: linear-gradient(90deg, rgba(15, 23, 42, 1) calc(100% - 22px), transparent);
    }
    .ag-kpi-card {
      flex: 0 0 156px;
      min-width: 156px;
    }
    .ag-switch-input {
      min-width: 0;
      min-height: 0;
    }
    .agencias-filters-bar {
      grid-template-columns: minmax(0, 1fr);
    }
    .ag-switch-long,
    .ag-clear-long {
      display: inline;
    }
    .ag-switch-short,
    .ag-clear-short {
      display: none;
    }
    .agencias-pagination {
      flex-direction: column;
      align-items: stretch;
    }
    .ag-page-controls {
      justify-content: space-between;
    }
  }

  /* 3. Inspector JSON de Webhooks y llave emitida */
  .secret-key-box {
    padding: 12px;
    border-radius: var(--r-sm);
    background: var(--sunken);
    border: 1px dashed var(--brand);
    font-family: var(--font-mono);
    font-size: 13px;
    word-break: break-all;
    color: var(--ink);
  }

  .json-pre {
    margin: 0;
    padding: 12px;
    border-radius: var(--r-sm);
    background: var(--sunken);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
  }

  /* 4. Configuración dinámica */
  .config-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .config-item {
    padding: 12px 14px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
  }

  .config-foot-bar {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
  }

  @media (max-width: 820px) {
    .config-grid {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  /* 5. Login 2FA Escénico «Centro de Control Logístico» v1.3.0 (login.html) */
  .login-page {
    position: relative;
    isolation: isolate;
    min-height: 100dvh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    background-color: #081121;
    display: grid;
    grid-template-columns: minmax(0, 1.12fr) minmax(400px, 464px);
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px 36px;
    padding: 22px 48px 18px;
  }

  .login-bg-photo {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center bottom;
    z-index: -3;
    pointer-events: none;
    user-select: none;
  }

  .login-bg-vignette {
    position: fixed;
    inset: 0;
    z-index: -2;
    pointer-events: none;
    background:
      radial-gradient(circle at 18% 24%, rgba(8, 17, 33, 0.72) 0%, rgba(8, 17, 33, 0.34) 48%, rgba(8, 17, 33, 0.78) 100%),
      linear-gradient(90deg, rgba(8, 17, 33, 0.84) 0%, rgba(8, 17, 33, 0.44) 52%, rgba(8, 17, 33, 0.74) 100%),
      linear-gradient(180deg, rgba(8, 17, 33, 0.45) 0%, rgba(8, 17, 33, 0.12) 58%, rgba(8, 17, 33, 0.86) 100%);
  }

  .login-corner-wave {
    position: fixed;
    z-index: -1;
    pointer-events: none;
  }

  .login-corner-wave--tl {
    top: 0;
    left: 0;
    width: clamp(180px, 21vw, 300px);
    height: auto;
  }

  .login-corner-wave--br {
    right: 0;
    bottom: 0;
    width: clamp(150px, 17vw, 240px);
    height: auto;
  }

  /* Columna Izquierda Escénica */
  .login-scene-pane {
    position: relative;
    min-width: 0;
    max-width: 620px;
    color: #F8FAFC;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
  }

  .scene-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
  }

  .scene-brand img {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    filter: drop-shadow(0 6px 14px rgba(217, 119, 6, 0.28));
  }

  .scene-brand-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }

  .scene-brand-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 800;
    line-height: 1.1;
    color: #F8FAFC;
    letter-spacing: -0.02em;
  }

  .scene-brand-title .hub-chip,
  .login-card-brand-name .hub-chip {
    padding: 2px 8px;
    border-radius: 6px;
    background: linear-gradient(180deg, #F59E0B 0%, #D97706 100%);
    color: #0F172A;
    font-family: var(--font-display);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.01em;
  }

  .scene-brand-sub {
    font-size: 12.5px;
    color: #CBD5E1;
  }

  .scene-hero-copy {
    display: flex;
    align-items: stretch;
    gap: 14px;
    min-width: 0;
  }

  .scene-accent-slash {
    width: 5px;
    border-radius: 99px;
    background: linear-gradient(180deg, #FBBF24 0%, #D97706 100%);
    transform: skewX(-11deg);
    flex-shrink: 0;
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.45);
  }

  .scene-hero-text {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
  }

  .scene-hero-copy h2 {
    color: #F8FAFC;
    font-size: clamp(28px, 2.3vw + 10px, 40px);
    line-height: 1.08;
    font-weight: 800;
    letter-spacing: -0.025em;
  }

  .scene-amber-word {
    display: block;
    color: #F59E0B;
  }

  .scene-hero-copy p {
    color: #CBD5E1;
    font-size: 14.5px;
    line-height: 1.45;
    max-width: 44ch;
  }

  .scene-feature-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    max-width: 520px;
  }

  .scene-feature-tile {
    padding: 11px 8px;
    border-radius: 12px;
    background: rgba(13, 24, 44, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.22);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
    color: #E2E8F0;
    font-size: 11.5px;
    font-weight: 600;
    min-width: 0;
    transition: border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  }

  .scene-feature-tile svg {
    color: #F59E0B;
    flex-shrink: 0;
  }

  .scene-feature-tile:hover {
    border-color: rgba(245, 158, 11, 0.52);
    transform: translateY(-2px);
  }

  .scene-stage {
    position: relative;
    width: 100%;
    max-width: 520px;
  }

  .scene-stage svg {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
  }

  /* Estados reactivos y animaciones 60fps de #loginSceneSvg */
  @keyframes routeBeamTravel {
    0% {
      stroke-dashoffset: 104;
      opacity: 0;
    }
    12% {
      opacity: 1;
    }
    88% {
      opacity: 1;
    }
    100% {
      stroke-dashoffset: 0;
      opacity: 0;
    }
  }

  @keyframes pinFloatIdle {
    0%,
    100% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(-3px);
    }
  }

  .route-beam-dot {
    stroke-dasharray: 2.5 108;
    animation: routeBeamTravel 2.8s linear infinite;
  }

  .scene-gps-pin {
    animation: pinFloatIdle 3.2s ease-in-out infinite;
  }

  #hubScanRing {
    transform-box: fill-box;
    transform-origin: center;
    opacity: 0.42;
    transition: opacity var(--dur-med) var(--ease-out), transform var(--dur-slow) var(--ease-out);
  }

  .login-scene-pane[data-scene-state="scanning"] #hubScanRing {
    opacity: 1;
    transform: scale(1.1);
  }

  #shutterGate {
    transform: translateY(155px);
    opacity: 0;
    transition: transform 280ms var(--ease-out), opacity 220ms var(--ease-out);
  }

  .login-scene-pane[data-scene-state="privacy"] #shutterGate {
    transform: translateY(0);
    opacity: 1;
  }

  .login-scene-pane[data-scene-state="peek"] #shutterGate {
    transform: translateY(38px);
    opacity: 0.95;
  }

  .totp-node-link {
    stroke: rgba(245, 158, 11, 0.22);
    stroke-width: 1.6;
    stroke-dasharray: 4 4;
    transition: stroke 180ms ease, stroke-width 180ms ease;
  }

  .totp-node-link.is-lit {
    stroke: #10B981;
    stroke-width: 2.8;
    stroke-dasharray: none;
  }

  .login-scene-pane[data-scene-paused="true"] .route-beam-dot,
  .login-scene-pane[data-scene-paused="true"] .scene-gps-pin,
  .login-scene-pane[data-scene-paused="true"] ~ .login-dock .dock-health-dot {
    animation-play-state: paused;
  }

  /* Columna Derecha y Tarjeta Glassmorphic */
  .login-form-pane {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
  }

  .login-card {
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 456px;
    padding: 24px 26px 22px;
    border-radius: 20px;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    display: flex;
    flex-direction: column;
    gap: 13px;
    min-width: 0;
  }

  .login-card::before {
    content: "";
    position: absolute;
    top: -54px;
    right: -54px;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(245, 158, 11, 0.34) 0%, rgba(245, 158, 11, 0) 70%);
    pointer-events: none;
  }

  /* Tema Oscuro (por defecto en login.html, fiel a ref-login-v1-3.webp) */
  [data-theme="dark"] .login-card {
    background: linear-gradient(165deg, rgba(16, 28, 52, 0.88) 0%, rgba(10, 19, 36, 0.94) 100%);
    border: 1px solid rgba(148, 163, 184, 0.26);
    box-shadow: 0 24px 52px -12px rgba(2, 6, 23, 0.72), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    color: #F8FAFC;
  }

  /* Tema Claro (cristal perla esmerilado con contraste AA verificado) */
  [data-theme="light"] .login-card {
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.95) 0%, rgba(244, 247, 252, 0.97) 100%);
    border: 1px solid rgba(217, 119, 6, 0.30);
    box-shadow: 0 24px 48px -12px rgba(15, 23, 42, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    color: #0F172A;
  }

  .login-theme-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
  }

  [data-theme="dark"] .login-theme-btn {
    background: rgba(15, 29, 53, 0.75);
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: #CBD5E1;
  }

  [data-theme="dark"] .login-theme-btn:hover {
    border-color: #F59E0B;
    color: #FBBF24;
  }

  [data-theme="light"] .login-theme-btn {
    background: #F8FAFC;
    border: 1px solid #CBD5E1;
    color: #334155;
  }

  [data-theme="light"] .login-theme-btn:hover {
    border-color: #D97706;
    color: #B45309;
  }

  [data-theme="light"] .login-theme-sun {
    display: none;
  }

  [data-theme="dark"] .login-theme-moon {
    display: none;
  }

  .login-card-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 5px;
    padding: 0 32px;
  }

  .login-card-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
  }

  .login-card-brand img {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
  }

  .login-card-brand-name {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-display);
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.02em;
  }

  [data-theme="dark"] .login-card-brand-name,
  [data-theme="dark"] .login-card-head h1 {
    color: #F8FAFC;
  }

  [data-theme="light"] .login-card-brand-name,
  [data-theme="light"] .login-card-head h1 {
    color: #0F172A;
  }

  .login-card-head h1 {
    font-size: 19px;
    font-weight: 700;
    line-height: 1.2;
  }

  .login-step-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--r-pill);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  [data-theme="dark"] .login-step-chip {
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.34);
    color: #FBBF24;
  }

  [data-theme="light"] .login-step-chip {
    background: #FFF7ED;
    border: 1px solid rgba(217, 119, 6, 0.32);
    color: #9A3412;
  }

  .login-subtitle {
    font-size: 12.5px;
    line-height: 1.35;
  }

  [data-theme="dark"] .login-subtitle {
    color: #CBD5E1;
  }

  [data-theme="light"] .login-subtitle {
    color: #475569;
  }

  .login-form-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
  }

  .login-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 600;
  }

  [data-theme="dark"] .login-label {
    color: #E2E8F0;
  }

  [data-theme="dark"] .login-label svg {
    color: #F59E0B;
  }

  [data-theme="light"] .login-label {
    color: #334155;
  }

  [data-theme="light"] .login-label svg {
    color: #B45309;
  }

  .login-field-wrap {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .login-field-icon {
    position: absolute;
    left: 13px;
    pointer-events: none;
    flex-shrink: 0;
  }

  [data-theme="dark"] .login-field-icon {
    color: #94A3B8;
  }

  [data-theme="light"] .login-field-icon {
    color: #64748B;
  }

  .login-input {
    width: 100%;
    min-height: 44px;
    padding: 0 14px 0 40px;
    border-radius: 10px;
    font-size: 14px;
    transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background-color var(--dur-fast);
  }

  .login-input--pass {
    padding-right: 46px;
  }

  [data-theme="dark"] .login-input {
    background-color: #0F1D35;
    border: 1px solid rgba(148, 163, 184, 0.28);
    color: #F8FAFC;
  }

  [data-theme="dark"] .login-input::placeholder {
    color: #94A3B8;
  }

  [data-theme="light"] .login-input {
    background-color: #FFFFFF;
    border: 1px solid #CBD5E1;
    color: #0F172A;
  }

  [data-theme="light"] .login-input::placeholder {
    color: #64748B;
  }

  .login-input:focus {
    border-color: #F59E0B;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22);
    outline: none;
  }

  /* Neutralización explícita de -webkit-autofill por tema */
  [data-theme="dark"] .login-input:-webkit-autofill,
  [data-theme="dark"] .login-input:-webkit-autofill:hover,
  [data-theme="dark"] .login-input:-webkit-autofill:focus {
    -webkit-text-fill-color: #F8FAFC;
    -webkit-box-shadow: 0 0 0 1000px #0F1D35 inset;
    caret-color: #F8FAFC;
  }

  [data-theme="light"] .login-input:-webkit-autofill,
  [data-theme="light"] .login-input:-webkit-autofill:hover,
  [data-theme="light"] .login-input:-webkit-autofill:focus {
    -webkit-text-fill-color: #0F172A;
    -webkit-box-shadow: 0 0 0 1000px #FFFFFF inset;
    caret-color: #0F172A;
  }

  .eye-btn {
    position: absolute;
    right: 4px;
    background: transparent;
    border: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    cursor: pointer;
    transition: color var(--dur-fast), background-color var(--dur-fast);
  }

  [data-theme="dark"] .eye-btn {
    color: #94A3B8;
  }

  [data-theme="dark"] .eye-btn:hover {
    color: #F8FAFC;
    background: rgba(148, 163, 184, 0.12);
  }

  [data-theme="light"] .eye-btn {
    color: #64748B;
  }

  [data-theme="light"] .eye-btn:hover {
    color: #0F172A;
    background: #F1F5F9;
  }

  /* Fila auxiliar: Recordar correo + ¿Olvidaste tu contraseña? */
  .login-aux-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
  }

  .login-remember {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
  }

  [data-theme="dark"] .login-remember {
    color: #CBD5E1;
  }

  [data-theme="light"] .login-remember {
    color: #334155;
  }

  .login-remember-input {
    position: absolute;
    width: 1px;
    height: 1px;
    min-width: 0;
    min-height: 0;
    margin: 0;
    opacity: 0;
    pointer-events: none;
  }

  .login-remember-box {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color var(--dur-fast), border-color var(--dur-fast);
  }

  .login-remember-box svg {
    opacity: 0;
    transform: scale(0.75);
    transition: opacity var(--dur-fast), transform var(--dur-fast);
  }

  [data-theme="dark"] .login-remember-box {
    background: #0F1D35;
    border: 1.5px solid rgba(148, 163, 184, 0.42);
    color: #0F172A;
  }

  [data-theme="light"] .login-remember-box {
    background: #FFFFFF;
    border: 1.5px solid #94A3B8;
    color: #0F172A;
  }

  .login-remember-input:checked + .login-remember-box {
    background: linear-gradient(180deg, #F59E0B 0%, #D97706 100%);
    border-color: #F59E0B;
    color: #0F172A;
  }

  .login-remember-input:checked + .login-remember-box svg {
    opacity: 1;
    transform: scale(1);
  }

  .login-remember-input:focus-visible + .login-remember-box {
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.35);
  }

  .login-forgot-btn {
    background: transparent;
    border: 0;
    padding: 2px 4px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: color var(--dur-fast);
  }

  [data-theme="dark"] .login-forgot-btn {
    color: #CBD5E1;
  }

  [data-theme="dark"] .login-forgot-btn:hover {
    color: #FBBF24;
    text-decoration: underline;
  }

  [data-theme="light"] .login-forgot-btn {
    color: #B45309;
  }

  [data-theme="light"] .login-forgot-btn:hover {
    color: #92400E;
    text-decoration: underline;
  }

  /* CTA Primario Ámbar con texto carbón (#0F172A, contraste AA > 6.6:1) */
  .login-submit-btn {
    width: 100%;
    min-height: 46px;
    border-radius: 11px;
    background: linear-gradient(180deg, #FBBF24 0%, #F59E0B 48%, #D97706 100%);
    border: 1px solid #F59E0B;
    color: #0F172A;
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.01em;
    box-shadow: 0 10px 24px -6px rgba(217, 119, 6, 0.52), inset 0 1px 0 rgba(255, 255, 255, 0.42);
  }

  .login-submit-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #FCD34D 0%, #F59E0B 52%, #EA8A0A 100%);
    transform: translateY(-1px);
    box-shadow: 0 14px 28px -6px rgba(245, 158, 11, 0.62), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  }

  .login-submit-btn:active:not(:disabled) {
    transform: scale(0.985);
  }

  /* Bloque Acceso Rápido (5 mosaicos) */
  .login-quick-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 2px;
    min-width: 0;
  }

  .login-quick-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11.5px;
    font-weight: 600;
  }

  .login-quick-divider::before,
  .login-quick-divider::after {
    content: "";
    flex: 1;
    height: 1px;
  }

  [data-theme="dark"] .login-quick-divider {
    color: #CBD5E1;
  }

  [data-theme="dark"] .login-quick-divider::before,
  [data-theme="dark"] .login-quick-divider::after {
    background: rgba(148, 163, 184, 0.2);
  }

  [data-theme="light"] .login-quick-divider {
    color: #475569;
  }

  [data-theme="light"] .login-quick-divider::before,
  [data-theme="light"] .login-quick-divider::after {
    background: #CBD5E1;
  }

  .login-quick-hint {
    text-align: center;
    font-size: 11.5px;
    font-weight: 600;
  }

  [data-theme="dark"] .login-quick-hint {
    color: #FBBF24;
  }

  [data-theme="light"] .login-quick-hint {
    color: #9A3412;
  }

  .quick-access-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 7px;
    min-width: 0;
  }

  .quick-tile {
    padding: 8px 3px;
    min-height: 56px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    min-width: 0;
    transition: border-color var(--dur-fast), background-color var(--dur-fast), transform var(--dur-fast);
  }

  .quick-tile span {
    font-size: 10px;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.015em;
    white-space: nowrap;
  }

  [data-theme="dark"] .quick-tile {
    background: rgba(15, 29, 53, 0.78);
    border: 1px solid rgba(148, 163, 184, 0.22);
    color: #E2E8F0;
  }

  [data-theme="dark"] .quick-tile svg {
    color: #F59E0B;
  }

  [data-theme="dark"] .quick-tile:hover {
    border-color: rgba(245, 158, 11, 0.55);
    transform: translateY(-1px);
  }

  [data-theme="dark"] .quick-tile[aria-pressed="true"] {
    background: rgba(245, 158, 11, 0.18);
    border-color: #F59E0B;
    color: #FFFFFF;
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35);
  }

  [data-theme="light"] .quick-tile {
    background: #F8FAFC;
    border: 1px solid #CBD5E1;
    color: #1E293B;
  }

  [data-theme="light"] .quick-tile svg {
    color: #B45309;
  }

  [data-theme="light"] .quick-tile:hover {
    border-color: #D97706;
    background: #FFF7ED;
    transform: translateY(-1px);
  }

  [data-theme="light"] .quick-tile[aria-pressed="true"] {
    background: #FEF3C7;
    border-color: #D97706;
    color: #0F172A;
    box-shadow: 0 0 0 1px rgba(217, 119, 6, 0.30);
  }

  [data-theme="light"] .quick-tile[aria-pressed="true"] svg {
    color: #92400E;
  }

  /* Paso 2 TOTP y Alertas */
  .caps-warning {
    padding: 6px 10px;
    border-radius: var(--r-xs);
    background: var(--warning-tint);
    color: var(--warning-ink);
    font-size: 12px;
    font-weight: 600;
  }

  .alert-box {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 500;
  }

  .alert-danger {
    background: var(--danger-tint);
    color: var(--danger-ink);
    border: 1px solid rgba(239, 68, 68, 0.32);
  }

  .otp-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
  }

  .otp-digit {
    width: 100%;
    min-width: 0;
    height: 50px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 700;
    border-radius: 10px;
  }

  [data-theme="dark"] .otp-digit {
    background: #0F1D35;
    border: 1px solid rgba(148, 163, 184, 0.32);
    color: #F8FAFC;
  }

  [data-theme="light"] .otp-digit {
    background: #FFFFFF;
    border: 1px solid #CBD5E1;
    color: #0F172A;
  }

  .otp-digit:focus {
    border-color: #F59E0B;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.24);
    outline: none;
  }

  .login-step2-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .login-back-btn {
    min-height: 46px;
  }

  .login-verify-btn {
    flex: 1;
  }

  /* Dock Inferior de Garantías y Salud */
  .login-dock {
    grid-column: 1 / -1;
    justify-self: center;
    width: fit-content;
    max-width: 100%;
    padding: 8px 18px;
    border-radius: var(--r-pill);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px 14px;
    font-size: 12px;
    font-weight: 500;
  }

  [data-theme="dark"] .login-dock {
    background: rgba(10, 19, 36, 0.84);
    border: 1px solid rgba(148, 163, 184, 0.22);
    color: #CBD5E1;
  }

  [data-theme="light"] .login-dock {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(203, 213, 225, 0.88);
    color: #1E293B;
    box-shadow: 0 8px 24px -8px rgba(15, 23, 42, 0.28);
  }

  .dock-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
  }

  [data-theme="dark"] .dock-item svg {
    color: #E2E8F0;
  }

  [data-theme="light"] .dock-item svg {
    color: #334155;
  }

  .dock-health-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #10B981;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55);
    animation: radarPulse 2.4s infinite var(--ease-out);
    flex-shrink: 0;
  }

  .dock-health-dot[data-state="degraded"] {
    background: #F59E0B;
    animation: none;
  }

  .dock-health-dot[data-state="offline"] {
    background: #EF4444;
    animation: none;
  }

  .dock-sep {
    width: 1px;
    height: 14px;
    background: rgba(148, 163, 184, 0.28);
  }

  .dock-version {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--r-pill);
    background: linear-gradient(180deg, #FBBF24 0%, #D97706 100%);
    color: #0F172A;
    font-size: 11.5px;
    font-weight: 800;
  }

  /* Modal Zero-Trust de Recuperación */
  .login-recover-modal {
    max-width: 480px;
  }

  .login-recover-title {
    font-size: 16px;
  }

  .login-recover-desc {
    font-size: 13px;
    line-height: 1.5;
    color: var(--ink-2);
  }

  .login-recover-cmd-box {
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--sunken);
    border: 1px dashed var(--brand);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
  }

  .login-recover-cmd-box code {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
  }

  .login-recover-close {
    width: auto;
    min-height: 44px;
    padding: 0 20px;
  }

  /* Densidad vertical para Laptop 1366x768 y Tablet-H 1080x820 */
  @media (max-height: 820px) and (min-width: 901px) {
    .login-page {
      padding: 14px 36px 12px;
      gap: 10px 28px;
    }
    .login-scene-pane {
      gap: 12px;
    }
    .scene-hero-copy h2 {
      font-size: clamp(26px, 2.1vw + 8px, 34px);
    }
    .scene-feature-tile {
      padding: 8px 6px;
      gap: 4px;
    }
    .scene-stage {
      max-width: 468px;
    }
    .login-card {
      padding: 18px 22px 16px;
      gap: 10px;
    }
    .login-form-stack {
      gap: 9px;
    }
    .login-input {
      min-height: 41px;
    }
    .login-submit-btn {
      min-height: 43px;
    }
    .quick-tile {
      min-height: 50px;
      padding: 6px 2px;
    }
    .login-dock {
      padding: 6px 16px;
    }
  }

  /* Tablet Horizontal (1080x820) */
  @media (max-width: 1180px) and (min-width: 901px) {
    .login-page {
      grid-template-columns: minmax(0, 1fr) minmax(392px, 424px);
      padding: 16px 24px 14px;
      gap: 12px 22px;
    }
    .scene-hero-copy h2 {
      font-size: 30px;
    }
    .scene-hero-copy p {
      font-size: 13.5px;
    }
    .login-card {
      padding: 18px 18px 16px;
    }
    .quick-access-grid {
      gap: 5px;
    }
    .quick-tile {
      padding: 7px 2px;
    }
    .quick-tile span {
      font-size: 9.8px;
      letter-spacing: -0.02em;
    }
  }

  /* Tablet Vertical (768x1024, <= 900px) */
  @media (max-width: 900px) {
    .login-page {
      grid-template-columns: minmax(0, 1fr);
      grid-template-rows: auto auto auto;
      align-content: start;
      padding: 20px 20px 28px;
      gap: 16px;
    }
    .login-corner-wave--tl {
      width: 120px;
    }
    .login-corner-wave--br {
      width: 110px;
    }
    .login-scene-pane {
      max-width: 480px;
      width: 100%;
      margin: 0 auto;
      gap: 12px;
    }
    .scene-hero-copy h2 {
      font-size: 28px;
    }
    .scene-amber-word {
      display: inline;
    }
    .scene-feature-grid {
      max-width: 100%;
    }
    .scene-stage {
      max-width: 420px;
      margin: 0 auto;
    }
    .login-card {
      max-width: 460px;
      padding: 22px 22px 20px;
    }
    .login-input {
      font-size: 16px;
      min-height: 48px;
    }
    .login-dock {
      max-width: 540px;
      border-radius: 16px;
      padding: 10px 14px;
      gap: 6px 12px;
    }
    .dock-sep {
      display: none;
    }
  }

  /* Teléfonos iPhone (390x844) y Android (360x800, <= 680px) */
  @media (max-width: 680px) {
    .login-page {
      padding: 12px 12px max(18px, env(safe-area-inset-bottom));
      gap: 8px;
    }
    .login-corner-wave {
      display: none;
    }
    .login-scene-pane {
      gap: 6px;
    }
    .scene-brand img {
      width: 34px;
      height: 34px;
    }
    .scene-brand-title {
      font-size: 19px;
    }
    .scene-brand-sub {
      font-size: 11.5px;
    }
    .scene-hero-copy {
      gap: 10px;
    }
    .scene-hero-copy h2 {
      font-size: 20px;
      line-height: 1.18;
    }
    .scene-hero-copy p,
    .scene-feature-grid,
    .login-card-brand {
      display: none;
    }
    .scene-stage {
      max-width: 280px;
    }
    .login-card {
      padding: 14px;
      border-radius: 16px;
      gap: 9px;
    }
    .login-card-head {
      padding: 0 38px;
      gap: 4px;
    }
    .login-theme-btn {
      top: 10px;
      right: 10px;
      width: 44px;
      height: 44px;
      min-width: 44px;
      min-height: 44px;
    }
    .login-input {
      font-size: 16px;
      min-height: 48px;
    }
    .eye-btn {
      right: 2px;
      width: 44px;
      height: 44px;
      min-width: 44px;
      min-height: 44px;
    }
    .login-aux-row {
      gap: 4px 8px;
    }
    .login-remember {
      min-height: 44px;
      min-width: 44px;
      padding: 4px 2px;
    }
    .login-remember-input {
      min-width: 0;
      min-height: 0;
      width: 1px;
      height: 1px;
    }
    .login-forgot-btn {
      min-height: 44px;
      min-width: 44px;
      display: inline-flex;
      align-items: center;
      padding: 0 4px;
    }
    .login-submit-btn,
    .login-back-btn {
      min-height: 48px;
      min-width: 44px;
    }
    /* Bento 3 + 2 en Acceso rápido: cero truncamiento en 360px */
    .quick-access-grid {
      grid-template-columns: repeat(6, minmax(0, 1fr));
      gap: 6px;
    }
    .quick-tile {
      min-height: 52px;
      min-width: 44px;
      padding: 7px 4px;
    }
    .quick-tile:nth-child(-n+3) {
      grid-column: span 2;
    }
    .quick-tile:nth-child(n+4) {
      grid-column: span 3;
    }
    .quick-tile span {
      font-size: 11px;
      letter-spacing: 0;
    }
    .otp-grid {
      gap: 6px;
    }
    .otp-digit {
      min-width: 0;
      min-height: 48px;
      height: 50px;
    }
    .login-recover-x,
    .login-recover-close {
      min-height: 44px;
      min-width: 44px;
    }
    .login-dock {
      font-size: 11.5px;
      padding: 9px 12px;
      gap: 6px 10px;
    }
  }

  /* Respeto estricto a prefers-reduced-motion */
  @media (prefers-reduced-motion: reduce) {
    .route-beam-dot,
    .scene-gps-pin,
    .dock-health-dot,
    .telemetry-dot {
      animation: none;
    }
    #shutterGate,
    #hubScanRing,
    .totp-node-link,
    .quick-tile,
    .scene-feature-tile,
    .login-submit-btn {
      transition: none;
    }
  }
}

/* --- CAPA UTILIDADES --- */
@layer utilities {
  [hidden] {
    display: none;
  }

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .text-muted { color: var(--muted); }
  .text-warning { color: var(--warning-ink); }
  .text-danger { color: var(--danger-ink); }
  .text-success { color: var(--success-ink); }
  .fw-600 { font-weight: 600; }
  .fw-700 { font-weight: 700; }
}
