* { box-sizing: border-box; }

/* Bug real confirmado 2026-08-12 (Beatriz: "el boton se queda como
   procesando y ni siquiera le he dado click"): cualquier regla de clase que
   fije "display" en un elemento (ej. .ac-btn-spinner { display:
   inline-block }) le gana en cascada al [hidden] por defecto del navegador
   (que es una regla de user-agent, siempre pierde contra CUALQUIER regla de
   autor sin importar el orden/especificidad) - el spinner de "Pagar" se veia
   SIEMPRE visible aunque tuviera el atributo hidden. Regla global para que
   hidden gane siempre, sin tener que acordarse de esto por cada clase nueva. */
[hidden] { display: none !important; }

/* Auditoria de UX 2026-08-13: las tablas anchas (Nomina, Facturas, etc.) ya
   envuelven su <table> en un contenedor con overflow-x:auto, pero en Windows/
   Chrome el scrollbar nativo queda oculto hasta que el mouse pasa encima -
   nada avisaba que habia mas columnas/iconos de acciones a la derecha, asi
   que se veian "cortados" en vez de "hay que deslizar". Se deja visible y
   delgado siempre, en vez de solo al pasar el mouse. */
*::-webkit-scrollbar { height: 8px; width: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
* { scrollbar-width: thin; }

:root {
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;
  --container-max: 1400px;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --bg-app: #f4f5f7;
  --bg-panel: #ffffff;
  --bg-panel-hover: #fafbff;
  --bg-input: #ffffff;
  --bg-sidebar: #0d2f9e;
  --bg-sidebar-hover: #0a2480;

  --text-primary: #1a1a1a;
  --text-muted: #59606d;
  --text-on-sidebar: #cbd5e1;

  --border-color: #e5e7eb;
  --border-input: #d0d3d9;

  --accent: #1450e6;
  --accent-hover: #0f3fc2;
  --accent-soft: #eaf0ff;
  --accent-gradient: linear-gradient(135deg, #3b6cf0, #1450e6);
  --brand-yellow: #ffc82c;
  --brand-yellow-dark: #f5a800;

  --danger: #c0292d;
  --danger-soft: #fdecec;
  --success: #1a7f37;
  --success-soft: #e6f6ec;
  --warning: #92600a;
  --warning-soft: #fff7e6;
  --purple: #6d28d9;
  --purple-soft: #f1eafe;

  --chat-mio: #1450e6;
  --chat-otro-bg: #f4f5f7;
  --chat-otro-border: #e5e7eb;
}

:root[data-theme="dark"] {
  --bg-app: #0d0f13;
  --bg-panel: #171a21;
  --bg-panel-hover: #1c2029;
  --bg-input: #12151b;
  --bg-sidebar: #081f78;
  --bg-sidebar-hover: #06175c;

  --text-primary: #e5e7eb;
  --text-muted: #9ba3b0;
  --text-on-sidebar: #b6c0d1;

  --border-color: #262b36;
  --border-input: #2e3440;

  --accent: #5b86ff;
  --accent-hover: #7fa0ff;
  --accent-soft: #16244a;
  --accent-gradient: linear-gradient(135deg, #5b86ff, #1450e6);
  --brand-yellow: #ffc82c;
  --brand-yellow-dark: #f5a800;

  --danger: #f2555a;
  --danger-soft: #3a1518;
  --success: #3ecf6d;
  --success-soft: #10301c;
  --warning: #f0b429;
  --warning-soft: #3a2a08;
  --purple: #a78bfa;
  --purple-soft: #241b3f;

  --chat-mio: #5b86ff;
  --chat-otro-bg: #1c2029;
  --chat-otro-border: #262b36;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-app: #0d0f13;
    --bg-panel: #171a21;
    --bg-panel-hover: #1c2029;
    --bg-input: #12151b;
    --bg-sidebar: #081f78;
    --bg-sidebar-hover: #06175c;
    --text-primary: #e5e7eb;
    --text-muted: #9ba3b0;
    --text-on-sidebar: #b6c0d1;
    --border-color: #262b36;
    --border-input: #2e3440;
    --accent: #5b86ff;
    --accent-hover: #7fa0ff;
    --accent-soft: #16244a;
    --accent-gradient: linear-gradient(135deg, #5b86ff, #1450e6);
    --brand-yellow: #ffc82c;
    --brand-yellow-dark: #f5a800;
    --danger: #f2555a;
    --danger-soft: #3a1518;
    --success: #3ecf6d;
    --success-soft: #10301c;
    --warning: #f0b429;
    --warning-soft: #3a2a08;
    --purple: #a78bfa;
    --purple-soft: #241b3f;

    --chat-mio: #5b86ff;
    --chat-otro-bg: #1c2029;
    --chat-otro-border: #262b36;
  }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}
.card h1 { font-size: 1.3rem; margin-bottom: 20px; }

label { display: block; font-size: 0.85rem; margin: 12px 0 4px; color: var(--text-primary); }
input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--bg-input);
  color: var(--text-primary);
}
/* Checkbox/radio NO deben heredar el "width:100%" de arriba (pensado para
   inputs de texto) - dentro de una fila flex, eso los hace intentar ocupar
   todo el ancho disponible del contenedor, empujando/apachurrando lo demas
   (bug real, confirmado 2026-08-03 en el checklist de facturas del
   Complemento de Pago: el checkbox se veia centrado con espacio de sobra y
   el texto de la factura quedaba amontonado a la derecha). */
input[type="checkbox"], input[type="radio"] {
  width: auto;
  padding: 0;
  flex-shrink: 0;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
/* --- Asistente de Compra: validacion inline y spinner de pago --- */
.ac-invalid {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
}
.ac-invalid:focus {
  outline-color: #dc2626;
}
.ac-field-err {
  display: block;
  color: #dc2626;
  font-size: 0.75rem;
  min-height: 1.1em;
  margin-top: 3px;
}
.ac-card-group {
  background: var(--bg-soft, #f7f9fc);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 10px);
  padding: 14px 16px 4px;
  margin-bottom: 14px;
}
.ac-tj-marca {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 2px 8px;
  border-radius: 5px;
  color: #fff;
}
.ac-tj-marca.visa { background: #1a1f71; }
.ac-tj-marca.mastercard { background: linear-gradient(90deg, #eb001b 0 50%, #f79e1b 50% 100%); }
.ac-tj-marca.amex { background: #2e77bb; }
.ac-btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ac-spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 8px;
}
@keyframes ac-spin {
  to { transform: rotate(360deg); }
}
/* Campos automaticos/informativos (readonly o disabled) - no deben verse
   como un campo en blanco por llenar, sino como texto ya resuelto (fondo
   plano, sin borde visible, cursor normal). Aplica en todo el sitio: los
   domicilios auto-derivados de Comercio Exterior/Datos Fiscales/Clientes,
   selects bloqueados por una fraccion arancelaria capturada, etc. */
input[readonly], input:disabled, select:disabled {
  background: var(--bg-panel-hover);
  border-color: transparent;
  color: var(--text-secondary, var(--text-primary));
  cursor: default;
}
input[readonly]:focus, input:disabled:focus, select:disabled:focus {
  outline: none;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.95rem;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s;
}
button:hover { background: var(--accent-hover); }
button.secondary { background: var(--bg-sidebar-hover); color: var(--text-primary); }
:root:not([data-theme="dark"]) button.secondary { background: #6b7280; color: #fff; }
.error { color: var(--danger); font-size: 0.85rem; margin-top: 10px; min-height: 1em; }

/* Campo con error de validacion (se marca en rojo al validar y se limpia al
   escribir/volver a validar). Aplica a inputs y selects de Carta Porte y a
   cualquier campo que el JS marque con esta clase. */
.campo-invalido { border-color: var(--danger) !important; box-shadow: 0 0 0 1px var(--danger) inset; }
.campo-invalido:focus { outline: none; border-color: var(--danger) !important; }

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
}
.container { padding: 24px; max-width: 1100px; margin: 0 auto; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="search"],
.toolbar input[type="text"] { flex: 1; min-width: 200px; }
.toolbar input[type="date"] { width: auto; }
.toolbar select { width: auto; flex: 0 0 auto; min-width: 160px; }
.toolbar label { margin: 0; }

table { width: 100%; border-collapse: collapse; background: var(--bg-panel); border-radius: var(--radius-md); overflow: hidden; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; }
/* Separacion entre botones de accion (Editar/Bloquear-Desactivar/Eliminar,
   etc.) dentro de una misma celda - sin esto quedaban pegados uno contra
   otro, solo separados por su propio padding (Beatriz, 2026-08-04). */
td button + button,
td .icon-btn + .icon-btn { margin-left: 8px; }
th { background: var(--bg-app); font-weight: 600; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--bg-panel-hover); }

/* Columna de acciones "pegada" al borde derecho cuando la tabla es mas ancha
   que el contenedor (scroll horizontal) - sin esto, los iconos de Editar/
   Timbrar/Cancelar quedan fuera de vista sin ninguna pista de que hay que
   scrollear para llegar a ellos (Beatriz, 2026-08-15: revision de UX,
   encontrado en Facturas y Nomina a 1440px de ancho). Se aplica solo a las
   tablas que se marcan con esta clase, no a todas - la mayoria ya caben
   completas sin scroll. */
.tabla-sticky-acciones {
  /* table { overflow: hidden } (arriba, para redondear esquinas) rompe
     position:sticky en las celdas - un ancestro con overflow distinto de
     visible entre la celda sticky y el contenedor con scroll la recorta.
     Se desactiva solo aqui; el contenedor envolvente (overflow-x:auto)
     sigue siendo el que controla el scroll horizontal. */
  overflow: visible;
}
.tabla-sticky-acciones th:last-child,
.tabla-sticky-acciones td:last-child {
  position: sticky;
  right: 0;
  box-shadow: -6px 0 8px -6px rgba(0, 0, 0, 0.35);
}
.tabla-sticky-acciones th:last-child { background: var(--bg-app); }
.tabla-sticky-acciones td:last-child { background: var(--bg-panel); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 500; }
.badge.activo { background: var(--success-soft); color: var(--success); }
.badge.inactivo { background: var(--bg-app); color: var(--text-muted); }

dialog { border: none; border-radius: var(--radius-lg); padding: 0; max-width: 420px; width: 90%; background: var(--bg-panel); color: var(--text-primary); box-shadow: var(--shadow-md); }
/* Dialogos con contenido interno scrollable + pie fijo (ej. #comex-dialog):
   el flex SOLO se aplica cuando el <dialog> esta realmente abierto
   ([open]) - ponerlo directo en el elemento (inline o sin el selector
   [open]) pisa la regla nativa del navegador "dialog:not([open]) {
   display:none }" y lo deja flotando visible aunque este cerrado (bug
   real, confirmado 2026-08-03: el dialogo de Comercio Exterior se quedaba
   trabado sobre cualquier pagina). */
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(10, 12, 16, 0.5); }
.dialog-body { padding: 26px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.link-btn { background: none; color: var(--danger); padding: 4px 8px; }
.link-btn:hover { background: var(--danger-soft); }

/* ---- Shell: sidebar + topbar ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: linear-gradient(165deg, var(--bg-sidebar) 0%, var(--bg-sidebar-hover) 130%);
  color: var(--text-on-sidebar);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  transition: width 0.15s ease;
}
.sidebar.collapsed { width: 72px; }
.sidebar.collapsed .label,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .sidebar-brand span:not(.logo-dot),
.sidebar.collapsed .sidebar-footer .label {
  display: none;
}
.sidebar.collapsed .sidebar-link { justify-content: center; padding: 10px; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 0 0 20px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid var(--bg-sidebar-hover);
  margin-bottom: 12px;
}
.sidebar-brand .logo-dot {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: #fff;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.sidebar-brand .logo-dot svg {
  width: 18px;
  height: 18px;
  color: var(--bg-sidebar);
}
.sidebar-brand .brand-mx { color: var(--brand-yellow); }
.sidebar-brand .brand-logo {
  max-width: 100%;
  max-height: 56px;
  width: auto;
  height: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar.collapsed .sidebar-brand .brand-logo { display: none; }
.login-logo {
  display: block;
  max-width: 240px;
  max-height: 60px;
  width: auto;
  height: auto;
  object-fit: contain;
  margin: 0 auto 14px;
}
.user-menu-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.user-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-color, inherit);
  padding: 5px 8px;
  border-radius: var(--radius-sm, 8px);
  font-weight: 600;
  transition: background 0.15s;
}
.user-menu-btn:hover { background: var(--bg-panel-hover, rgba(0,0,0,0.05)); }
.user-menu-btn .user-menu-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}
.user-menu-btn .user-menu-chevron { opacity: 0.6; transition: transform 0.15s; }
.user-menu-btn[aria-expanded="true"] .user-menu-chevron { transform: rotate(180deg); }
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-blue, #2563eb), var(--brand-yellow, #f59e0b));
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.user-avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-avatar-inicial {
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
}
.user-menu-panel {
  top: calc(100% + 8px);
  right: 0;
  left: auto;
  width: 200px;
  padding: 6px;
}
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-color, inherit);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 9px 12px;
  border-radius: var(--radius-sm, 8px);
  text-align: left;
}
.user-menu-item:hover { background: var(--bg-panel-hover, rgba(0,0,0,0.06)); }
.user-menu-item-danger { color: #e11d48; }
.user-menu-item-danger:hover { background: rgba(225, 29, 72, 0.1); }
.user-mini {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}
.user-logout-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm, 8px);
  background: transparent !important;
  color: var(--text-muted) !important;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.user-logout-icon:hover {
  color: #e11d48 !important;
  background: rgba(225, 29, 72, 0.09) !important;
}
.user-logout-icon svg { display: block; width: 17px; height: 17px; stroke: currentColor; }

/* ===== Chat flotante (esquina inferior izquierda) ===== */
.chat-launcher {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 12px;
  border: none;
  border-radius: 14px;
  background: var(--accent-gradient) !important;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s, box-shadow 0.15s;
}
.chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  background: var(--accent-hover) !important;
}
.chat-launcher-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-launcher-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}
.chat-launcher-title { font-weight: 700; font-size: 0.95rem; }
.chat-launcher-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.9);
}
.chat-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: chat-pulse 1.6s infinite;
}
@keyframes chat-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
.chat-launcher-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* ===== Estado fuera de horario del chat (portal) ===== */
.chat-launcher-status.offline .chat-online-dot {
  background: var(--text-muted);
  box-shadow: none;
  animation: none;
}
.chat-launcher-status.offline { color: rgba(255, 255, 255, 0.85); }

.aviso-fuera-horario {
  background: rgba(250, 204, 21, 0.14);
  border: 1px solid var(--brand-yellow, #facc15);
  border-radius: var(--radius-md, 10px);
  padding: 10px 14px;
  font-size: 0.88rem;
  color: var(--text-primary);
}

/* ===== Switch "En linea / Fuera de horario" (panel admin) ===== */
.estado-chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 10px);
  background: var(--bg-panel, #fff);
}
.estado-chat-etiqueta {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--success, #16a34a);
  white-space: nowrap;
}
.estado-chat-etiqueta.offline { color: var(--text-muted); }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-track {
  position: absolute;
  inset: 0;
  background: var(--bg-sidebar-hover, #d1d5db);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch input:checked + .switch-track { background: var(--success, #16a34a); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(20px); }

/* ===== Contorno amarillo para resaltar el boton de chat ===== */
.chat-launcher {
  border: 2px solid var(--brand-yellow, #facc15);
}
.chat-launcher:hover { border-color: var(--brand-yellow); }.sidebar-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.55);
  padding: 14px 20px 6px;
}
/* Secciones colapsables del sidebar (ej. "Catalogos", que junta 8 vistas y
   hacia la lista muy larga) - boton en vez de div, mismo look visual. */
.sidebar-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
}
.sidebar-section-toggle .chevron { transition: transform 0.15s ease; flex-shrink: 0; }
.sidebar-section-toggle[aria-expanded="false"] .chevron { transform: rotate(-90deg); }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 20px;
  color: var(--text-on-sidebar);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
  border-top: none;
  border-right: none;
  border-bottom: none;
}
.sidebar-link svg { flex-shrink: 0; width: 18px; height: 18px; }
.sidebar-link:hover { background: var(--bg-sidebar-hover); color: #fff; }
.sidebar-link.active {
  background: var(--bg-sidebar-hover);
  color: #fff;
  border-left-color: var(--brand-yellow);
}
.sidebar-link.disabled { opacity: 0.45; cursor: default; }
.sidebar-link.disabled:hover { background: none; color: var(--text-on-sidebar); }
.sidebar-link .soon-tag {
  margin-left: auto;
  font-size: 0.62rem;
  text-transform: uppercase;
  background: var(--bg-sidebar-hover);
  padding: 2px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}
.sidebar.collapsed .soon-tag { display: none; }
.sidebar-footer { margin-top: auto; padding: 16px 20px 0; border-top: 1px solid var(--bg-sidebar-hover); }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1; }
.topbar-title { font-weight: 600; font-size: 1.05rem; white-space: nowrap; }
.topbar-user { display: flex; align-items: center; gap: 14px; font-size: 0.9rem; color: var(--text-muted); flex-shrink: 0; }

.hamburger-btn, .theme-btn, .bell-btn {
  background: none;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.hamburger-btn:hover, .theme-btn:hover, .bell-btn:hover { background: var(--bg-app); color: var(--text-primary); }

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 320px;
  flex: 1;
  min-width: 0;
}
.topbar-search:hover { border-color: var(--accent); }
.topbar-search span.hint {
  margin-left: auto;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.bell-wrap { position: relative; }
.bell-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 0.62rem;
  min-width: 15px;
  height: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}
.notif-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 320px;
  max-height: 380px;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: none;
  z-index: 20;
}
.notif-panel.open { display: block; }
.notif-panel h4 { margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; }
.notif-item { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border-color); font-size: 0.85rem; }
.notif-item:last-child { border-bottom: none; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.notif-dot.warn { background: var(--warning); }
.notif-dot.bad { background: var(--danger); }
.notif-dot.ok { background: var(--success); }
.notif-empty { padding: 20px 16px; color: var(--text-muted); font-size: 0.85rem; text-align: center; }
/* Panel de notificaciones de la campana: las no leidas resaltan y cada item
   es clicable para marcarlas como leidas (ver dashboard.js). */
.notif-item { cursor: pointer; }
.notif-item:hover { background: var(--bg-panel-hover); }
.notif-item.no-leida { background: var(--accent-soft); }
.notif-item.no-leida:hover { background: var(--bg-panel-hover); }

.view { display: none; padding: var(--space-4); }
.view.active { display: block; }
.view-inner { max-width: var(--container-max); margin: 0 auto; }

/* ---- Encabezado de pantalla (breadcrumb + titulo + descripcion + acciones) ---- */
.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.view-breadcrumb { color: var(--text-muted); font-size: 0.8rem; margin: 0 0 6px; }
.view-header-text h1,
.view-title { font-size: 1.4rem; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
.view-description { color: var(--text-muted); font-size: 0.88rem; margin: 0; }
.view-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

/* ---- Tarjetas de KPI ---- */
.viz-root {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --viz-grid: #e1e0d9;
  --viz-axis: #c3c2b7;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --viz-grid: #2c2c2a;
    --viz-axis: #383835;
  }
}
:root[data-theme="dark"] .viz-root {
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --viz-grid: #2c2c2a;
  --viz-axis: #383835;
}
.viz-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 0.8rem; color: var(--text-muted); }
.viz-legend-item { display: flex; align-items: center; gap: 6px; }
.viz-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.viz-eje-texto { font-size: 9px; fill: var(--text-muted, #8a8a80); }
.viz-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-panel, #fff);
  border: 1px solid var(--border-color, #ddd);
  border-radius: var(--radius-sm, 6px);
  padding: 6px 10px;
  font-size: 0.78rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  z-index: 5;
}
.viz-tooltip strong { display: block; margin-bottom: 3px; }
.viz-tooltip div { display: flex; align-items: center; gap: 5px; }
.stat-delta { font-size: 0.78rem; margin-top: 4px; font-weight: 600; }
.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }
.stat-delta.flat { color: var(--text-muted); }
.inicio-2col { display: grid; grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) {
  .inicio-2col { grid-template-columns: 1fr; }
}
/* Rediseñado 2026-08-17 (Beatriz: "este indicador se veria mejor asi, se le
   entiende mas" - mockup con un contador circular por color de riesgo,
   etiqueta del rango, y el monto+numero de facturas alineados a la derecha,
   en vez de la barra de progreso anterior). */
.aging-bucket { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; }
.aging-bucket:last-child { border-bottom: none; }
.aging-bucket .aging-contador { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; }
.aging-bucket .aging-contador.riesgo-bajo { background: var(--success-soft); color: var(--success); }
.aging-bucket .aging-contador.riesgo-medio { background: var(--warning-soft); color: var(--warning); }
.aging-bucket .aging-contador.riesgo-alto { background: var(--danger-soft); color: var(--danger); }
.aging-bucket .aging-label { flex: 1; color: var(--text); }
.aging-bucket .aging-lado-derecho { text-align: right; flex-shrink: 0; }
.aging-bucket .aging-valor { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.aging-bucket .aging-cantidad { display: block; font-size: 0.78rem; color: var(--text-muted); }
.actividad-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border-color); font-size: 0.85rem; }
.actividad-item:last-child { border-bottom: none; }
.actividad-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.actividad-dot.ok { background: var(--success); }
.actividad-dot.error { background: var(--danger); }
.actividad-dot.info { background: var(--accent); }
.actividad-item .actividad-fecha { color: var(--text-muted); font-size: 0.76rem; display: block; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.stat-card .stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
}
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; white-space: nowrap; }

/* KPIs de cotizaciones: evitar que las cards se estrenen / "se coman espacios"
   en tablets y especialmente en móvil. El .stats-grid global usa minmax(180px);
   aquí bajamos el mínimo y forzamos 1 columna cuando el viewport es estrecho. */
#cot-kpi-grid {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
@media (max-width: 560px) {
  #cot-kpi-grid { grid-template-columns: 1fr; }
}


.panel {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.panel h2, .panel h3 { margin-top: 0; }
.muted { color: var(--text-muted); font-size: 0.85rem; }

/* ===== Chat de soporte: burbujas de mensaje ===== */
.chat-msg {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  max-width: 78%;
  word-wrap: break-word;
  position: relative;
}
.chat-msg-mio {
  background: var(--accent);
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.chat-msg-mio .chat-msg-author { color: rgba(255,255,255,0.75); }
.chat-msg-mio .chat-msg-time { color: rgba(255,255,255,0.6); }
.chat-msg-otro {
  background: var(--bg-app);
  color: var(--text-primary);
  margin-right: auto;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
}
.chat-msg-otro .chat-msg-author { color: var(--accent); }
.chat-msg-otro .chat-msg-time { color: var(--text-muted); }
.chat-msg-author { font-size: 0.72rem; font-weight: 600; margin-bottom: 2px; }
.chat-msg-time { font-size: 0.68rem; white-space: nowrap; }
.chat-msg-text { white-space: pre-wrap; font-size: 0.88rem; line-height: 1.45; }
.chat-msg-adjunto { margin-top: 6px; }
.chat-msg-adjunto img { max-width: 220px; max-height: 160px; border-radius: var(--radius-sm); cursor: pointer; }
.chat-msg-adjunto a { color: inherit; text-decoration: underline; font-size: 0.82rem; }
/* Dark mode: burbujas del otro con fondo más claro */
:root[data-theme="dark"] .chat-msg-otro { background: var(--bg-panel-hover); border-color: var(--border-color); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chat-msg-otro { background: var(--bg-panel-hover); border-color: var(--border-color); }
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 28px 16px;
  text-align: center;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-app);
}
.empty-state::before {
  content: "📭";
  display: block;
  font-size: 1.6rem;
  margin-bottom: 6px;
  opacity: 0.7;
}
.paginador { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; margin-top: 4px; border-top: 1px solid var(--border-color); font-size: 0.85rem; }
.paginador button:disabled { opacity: 0.5; cursor: default; }

/* ---- Estado del servicio ---- */
.status-list { list-style: none; margin: 0; padding: 0; }
.status-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 0.88rem; border-bottom: 1px solid var(--border-color); }
.status-list li:last-child { border-bottom: none; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.status-list .estado-txt { margin-left: auto; color: var(--success); font-size: 0.8rem; font-weight: 500; }

/* ---- Badges de estado de PAC / facturas ---- */
.badge.principal { background: var(--accent-soft); color: var(--accent); }
.badge.secundario { background: var(--success-soft); color: var(--success); }
.badge.fuera_de_flujo { background: var(--bg-app); color: var(--text-muted); }
.badge.pac-inactivo { background: var(--danger-soft); color: var(--danger); }
.badge.timbrada { background: var(--success-soft); color: var(--success); }
.badge.pendiente { background: var(--warning-soft); color: var(--warning); }
.badge.error { background: var(--danger-soft); color: var(--danger); }
.badge.cancelacion_pendiente { background: var(--warning-soft); color: var(--warning); }
.badge.cancelada { background: var(--bg-app); color: var(--text-muted); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--border-input); border-radius: 999px; cursor: pointer; transition: 0.15s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: 0.15s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.icon-btn {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 9px;
  margin: 0 2px;
  font-size: 1.05rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---- Command palette ---- */
#command-palette { max-width: 480px; padding: 0; }
#command-palette .cp-input-row { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid var(--border-color); }
#command-palette .cp-input-row input { border: none; padding: 4px; font-size: 1rem; }
#command-palette .cp-input-row input:focus { outline: none; }
.cp-results { list-style: none; margin: 0; padding: 8px; max-height: 320px; overflow-y: auto; }
.cp-results li {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.cp-results li:hover, .cp-results li.selected { background: var(--accent-soft); color: var(--accent); }
.cp-empty { padding: 16px; color: var(--text-muted); font-size: 0.85rem; text-align: center; }

/* ---- Toasts (mensajes emergentes) ---- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 340px;
}
.toast {
  background: var(--bg-panel);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 12px 16px;
  font-size: 0.88rem;
  border-left: 4px solid var(--danger);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
  cursor: pointer;
  white-space: pre-wrap;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--accent); }

.help-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.help-card { background: var(--bg-panel); border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow-sm); }
.help-card h4 { margin: 0 0 8px; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { width: 250px; }
  .sidebar.collapsed .label,
  .sidebar.collapsed .sidebar-section-title,
  .sidebar.collapsed .sidebar-brand span:not(.logo-dot) { display: initial; }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 25;
  }
  .sidebar-overlay.open { display: block; }
  .topbar-search { display: none; }
}

/* ============ Formularios compactos (Nueva factura y similares) ============ */
.nf-grid { display: block; }
.nf-grid-main { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.nf-compact { padding: 14px 16px; margin-bottom: 12px; }
.nf-compact h3 { margin: 0 0 8px; font-size: 1rem; }
.nf-compact label { margin: 6px 0 3px; font-size: 0.78rem; }
.nf-compact input, .nf-compact select { padding: 7px 9px; font-size: 0.88rem; }
.nf-fields-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0 12px;
}
/* Reserva espacio para 2 renglones de etiqueta - si una etiqueta de la fila
   envuelve a 2 lineas y la de al lado a 1, sin esto el campo de la etiqueta
   corta queda mas arriba que el de la etiqueta larga (se ve descuadrado). */
.nf-fields-grid > div > label { min-height: 2.2em; display: block; }
@media (max-width: 1100px) {
  .nf-fields-grid { grid-template-columns: repeat(2, 1fr); }
}
/* Variante para grupos de campos con titulos/valores cortos (ej. Serie,
   Folio) mezclados con campos que necesitan mas ancho (ej. Cliente,
   Fecha) - en vez de 4 columnas fijas de igual ancho, cada campo ocupa
   solo el minimo que necesita y caben mas por renglon en pantallas
   anchas (Beatriz, 2026-08-03: "optimiza los campos de arriba para que
   queden en espacios mas pequeños si son titulos y de poca informacion").
   Solo se usa donde se agrega explicitamente (nf-fields-grid-auto), no
   cambia el resto de los formularios del sitio que ya usan .nf-fields-grid. */
/* Piso subido de 150px a 200px (auditoria de UX 2026-08-13): con 150px, un
   select con texto normal del catalogo del SAT ("PUE - Una exhibicion",
   "D01 - Honorarios medicos") quedaba visualmente cortado a la mitad en
   pantallas anchas (auto-fit metia demasiadas columnas angostas por
   renglon) - el usuario no podia confirmar de un vistazo que campo eligio
   antes de timbrar. */
.nf-fields-grid-auto { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
@media (max-width: 1100px) {
  .nf-fields-grid-auto { grid-template-columns: repeat(2, 1fr); }
}
/* Nota historica (Beatriz, 2026-08-13): "Tipo de comprobante" antes vivia
   aislado en su propio renglon de ancho completo porque el contenido de alto
   variable que traia adentro (nota de Traslado/Nomina, panel "Es Factura
   Global" con Periodicidad/Meses/Año) estiraba el renglon completo y dejaba
   huecos en blanco bajo Cliente/Serie/Fecha/Sucursal. Se resolvio distinto
   (Beatriz pidio que Tipo de comprobante/Moneda/Metodo/Forma de pago vayan
   en el mismo renglon): ese contenido variable se saco del <div> del select
   y se movio a su PROPIO bloque aparte con grid-column:1/-1 despues de
   Condiciones de pago (ver portal.html) - el select de Tipo de comprobante
   volvio a ser una celda normal, ya no necesita reglas especiales aqui.
*/
/* Grupos de campos mayormente de solo lectura/informativos (ej. domicilio
   del emisor/receptor en Comercio Exterior) - mas juntos, sin el espacio
   generoso pensado para campos que si se capturan a mano (Beatriz,
   2026-08-03: "el texto es informativo la mayoria"). */
.nf-fields-grid-compacto { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 2px 10px; }
.nf-fields-grid-compacto > div > label { min-height: 0; margin: 0 0 1px; font-size: 0.72rem; }

/* Marca de campo obligatorio (asterisco rojo, con tooltip nativo via title)
   e icono de ayuda para reglas no obvias (ej. condicionales, formato exigido
   por el SAT) - Beatriz, 2026-08-05: "mostrar los campos obligatorios... y
   un icono de ayuda para los obligatorios si consideras necesario". */
.campo-requerido { color: var(--danger, #c0392b); font-weight: 700; margin-left: 2px; cursor: help; }
.campo-ayuda {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; margin-left: 4px;
  background: var(--text-muted, #888); color: #fff; font-size: 0.68rem;
  font-style: normal; font-weight: 700; cursor: help; flex-shrink: 0;
}
/* Generalizado de ".dialog-body details" a "details" a secas (Beatriz,
   2026-08-15: revision de UX - Nomina/Retenciones tenian un parrafo
   instructivo largo siempre visible en la vista, no solo en dialogos) para
   poder reusar el mismo <details> colapsable fuera de un dialog tambien. */
details { margin-bottom: 6px; }
details summary { cursor: pointer; list-style: none; padding: 4px 0; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸ "; font-size: 0.8em; color: var(--text-muted, #888); }
details[open] summary::before { content: "▾ "; }
.nf-fields-grid-compacto input, .nf-fields-grid-compacto select { padding: 5px 8px; font-size: 0.82rem; }

/* ---- Barra de navegacion rapida del formulario de Nomina (Percepciones/
   Deducciones/Otros pagos/Incapacidades) - identidad propia con subrayado de
   color, distinta del look en caja de "Nueva factura" (Beatriz, 2026-08-11:
   "no tomes la misma de factura"). Ya NO oculta secciones (Beatriz volvio a
   mandar el mockup: las 4 se ven a la vez) - un click solo hace scroll hasta
   ese panel; "active" se le pone al que se clickeo, nada mas cosmetico. ---- */
.nomina-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border-input); margin-bottom: 14px; overflow-x: auto; }
.nomina-tab-btn {
  background: none;
  border: none;
  color: var(--text-muted, #888);
  font-size: 0.86rem;
  font-weight: 600;
  padding: 8px 4px;
  margin-bottom: -2px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  cursor: pointer;
  white-space: nowrap;
}
.nomina-tab-btn:hover { background: none; color: var(--accent); }
.nomina-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.nomina-tab-panel { padding-top: 2px; scroll-margin-top: 16px; }

/* Version generica del mismo patron de pestañas de arriba (.nomina-tab-*),
   para reusar en cualquier otra vista con varias secciones largas sin
   copiar/pegar los estilos con un nombre que no le corresponde (Beatriz,
   2026-08-15: revision de UX - Contabilidad tenia 6 secciones en una sola
   pagina de scroll interminable, sin pestañas). */
.view-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border-input); margin-bottom: 14px; overflow-x: auto; }
.view-tab-btn {
  background: none;
  border: none;
  color: var(--text-muted, #888);
  font-size: 0.86rem;
  font-weight: 600;
  padding: 8px 10px;
  margin-bottom: -2px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  cursor: pointer;
  white-space: nowrap;
}
.view-tab-btn:hover { background: none; color: var(--accent); }
.view-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.view-tab-panel { display: none; }
.view-tab-panel.active { display: block; }
.nomina-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.nomina-panel-header h3 { margin: 0; }

/* Tabla de Percepciones/Deducciones/Otros pagos: clave y concepto van en
   columnas separadas (antes iban apiladas en una sola celda y se veian como
   un campo duplicado - Beatriz, 2026-08-11: "pareciera como duplicado"). */
.nomina-tabla th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text-muted); }
.nomina-tabla select.np-clave,
.nomina-tabla select.nd-clave,
/* ---- Estilos para el Selector de Pestañas (Tabs) del proceso de pago ---- */
.tab-btn {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  flex: 1;
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.tab-btn:hover:not(.active) {
  background: var(--bg-panel-hover);
}

.nomina-tabla select.no-clave { width: 100%; min-width: 76px; font-size: 0.82rem; padding: 6px 4px; }

/* El concepto se autocompleta con la descripcion del catalogo al elegir la
   clave - se muestra como texto (negritas), sin caja de input visible, y
   solo toma apariencia de campo editable al hacer foco/hover. */
.nomina-tabla input.np-concepto,
.nomina-tabla input.nd-concepto,
.nomina-tabla input.no-concepto {
  border: 1px solid transparent;
  background: transparent;
  padding: 2px 4px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  width: 100%;
}
.nomina-tabla input.np-concepto:hover,
.nomina-tabla input.nd-concepto:hover,
.nomina-tabla input.no-concepto:hover { border-color: var(--border-input); }
.nomina-tabla input.np-concepto:focus,
.nomina-tabla input.nd-concepto:focus,
.nomina-tabla input.no-concepto:focus { background: var(--bg-input); border-color: var(--accent); }
.nomina-concepto-catalogo { font-size: 0.74rem; color: var(--text-muted); padding: 0 4px; }

.nomina-importe-calc { font-weight: 600; text-align: right; padding-right: 10px; }
.nomina-color-percepciones { color: var(--success); }
.nomina-color-deducciones { color: var(--danger); }
.nomina-tfoot-label { text-align: right; font-weight: 600; padding: 8px 10px; }
.nomina-tfoot-valor { font-weight: 700; text-align: right; padding: 8px 10px; }

.nomina-top-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .nomina-top-grid { grid-template-columns: 1fr; } }
.nomina-empleado-resumen {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-input);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.nomina-empleado-resumen > div { display: flex; flex-direction: column; }
.nomina-empleado-resumen span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.02em; }
.nomina-empleado-resumen strong { color: var(--text-primary); font-weight: 600; font-size: 0.88rem; }
.perfil-columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 800px) {
  .perfil-columnas { grid-template-columns: 1fr; }
}

/* ---- Mi Perfil: filas de detalle (Nombre / Correo / Rol) ---- */
.perfil-fila {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}
.perfil-fila:last-child { border-bottom: none; }
.perfil-fila-etiqueta { color: var(--text-muted); font-size: 0.85rem; flex-shrink: 0; }
.perfil-fila-valor {
  font-size: 0.9rem;
  font-weight: 600;
  text-align: right;
  word-break: break-word;
  min-width: 0;
}

/* ---- Mi Perfil: esqueleto de carga ---- */
.perfil-skeleton {
  display: inline-block;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--border-color) 25%, var(--bg-app) 50%, var(--border-color) 75%);
  background-size: 200% 100%;
  animation: perfil-skeleton-load 1.3s ease-in-out infinite;
  vertical-align: middle;
}
@keyframes perfil-skeleton-load {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Mi Perfil: Avatar ---- */
.perfil-avatar-wrap { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 14px; }
.perfil-avatar-btn {
  position: relative;
  padding: 4px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: none;
  cursor: pointer;
  width: 100%;
  aspect-ratio: 1/1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, border-color 0.12s;
}
.perfil-avatar-btn:hover { transform: scale(1.08); }
.perfil-avatar-btn.seleccionado { border-color: var(--accent); }
.perfil-avatar-btn img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.perfil-avatar-check {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: var(--accent);
  color: #fff;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  border: 2px solid var(--bg-panel);
}

/* ---- Campos de contraseña con boton mostrar/ocultar (Perfil y Config. de correo) ---- */
.perfil-columnas .input-wrap,
#view-correo .input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.perfil-columnas .input-wrap > input,
#view-correo .input-wrap > input {
  width: 100%;
  padding-right: 42px;
}
.perfil-columnas .pw-toggle,
#view-correo .pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.perfil-columnas .pw-toggle:hover,
#view-correo .pw-toggle:hover { background: var(--bg-app); color: var(--text-primary); }

.nf-tabla-conceptos th, .nf-tabla-conceptos td { padding: 5px 6px; font-size: 0.82rem; }
.nf-tabla-conceptos input, .nf-tabla-conceptos select { padding: 5px 6px; font-size: 0.82rem; }
.nf-c-check { font-size: 0.68rem; margin-top: 2px; min-height: 14px; }
.nf-c-check.valido { color: var(--success); }
.nf-c-check.invalido { color: var(--danger); }
#nf-producto-resultados .nf-producto-opcion,
#cotizacion-producto-resultados .nf-producto-opcion,
.combobox-resultados .combobox-opcion {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}
#nf-producto-resultados .nf-producto-opcion:last-child,
#cotizacion-producto-resultados .nf-producto-opcion:last-child,
.combobox-resultados .combobox-opcion:last-child { border-bottom: none; }
#nf-producto-resultados .nf-producto-opcion:hover,
#cotizacion-producto-resultados .nf-producto-opcion:hover,
.combobox-resultados .combobox-opcion:hover { background: var(--bg-app); }
#nf-producto-resultados .nf-producto-opcion .muted,
#cotizacion-producto-resultados .nf-producto-opcion .muted { font-size: 0.75rem; }
.combobox-resultados {
  display: none;
  position: absolute;
  z-index: 5;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 240px;
  overflow-y: auto;
}
.combobox-sin-resultados { padding: 10px; font-size: 0.82rem; color: var(--text-muted); }

/* ============ Selector de impuestos (agregar + tags) ============ */
.selector-impuestos { min-width: 170px; }
.selector-impuestos-agregar { width: 100%; }
.selector-impuestos-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.selector-impuestos-tags:empty { margin-top: 0; }
.tag-impuesto {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--accent-soft);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 2px 4px 2px 10px;
  font-size: 0.76rem;
  white-space: nowrap;
}
.tag-impuesto-quitar {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
}
.tag-impuesto-quitar:hover { background: var(--danger-soft); color: var(--danger); }
.nf-tabla-conceptos .selector-impuestos { min-width: 150px; max-width: 180px; }
.nf-tabla-conceptos .selector-impuestos-agregar { font-size: 0.78rem; padding: 4px 6px; }
.nf-tabla-conceptos .tag-impuesto { font-size: 0.72rem; white-space: normal; word-break: break-word; }

/* Cotizacion dialog: conceptos table refinements */
#cotizacion-dialog .nf-tabla-conceptos input[type="number"] { text-align: right; }
#cotizacion-dialog .nf-tabla-conceptos td { vertical-align: top; padding: 4px 5px; }
#cotizacion-dialog .nf-tabla-conceptos td:first-child { padding-left: 8px; }
#cotizacion-dialog .cq-c-importe { padding-top: 8px; }
#cotizacion-dialog .cq-c-borrar:hover { background: var(--danger-soft); border-radius: 4px; }

/* ============ Sistema de diseno: componentes base ============ */

/* Card: encabezado interno de un .panel (icono opcional + titulo + descripcion) */
.panel-lg { padding: var(--space-5); }
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.panel-header-text { min-width: 0; }
.panel-title { font-size: 1rem; font-weight: 600; margin: 0 0 2px; }
.panel-description { color: var(--text-muted); font-size: 0.8rem; margin: 0; }
.panel-icon {
  width: 36px; height: 36px; border-radius: var(--radius-md);
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* Boton destructivo explicito */
button.danger { background: var(--danger); color: #fff; }
button.danger:hover { filter: brightness(0.92); }
button.ghost { background: none; color: var(--text-primary); border: 1px solid var(--border-input); }
button.ghost:hover { background: var(--bg-app); }
button:disabled { opacity: 0.55; cursor: default; pointer-events: none; }

/* Alerta */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  border: 1px solid transparent;
  margin-bottom: var(--space-3);
}
.alert-icon { flex-shrink: 0; line-height: 1.3; }
.alert-body { min-width: 0; }
.alert-title { font-weight: 600; margin: 0 0 2px; }
.alert-info { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }

/* Tooltip (solo CSS, atributo data-tooltip) */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: #111827;
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.35;
  padding: 5px 9px;
  border-radius: 6px;
  white-space: normal;
  max-width: 280px;
  width: max-content;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s, transform 0.12s;
  z-index: 40;
}
[data-tooltip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Dropdown / menu flotante generico */
.menu {
  position: absolute;
  z-index: 20;
  min-width: 180px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  list-style: none;
  margin: 0;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-primary);
  background: none;
  width: 100%;
  border: none;
  text-align: left;
}
.menu-item:hover { background: var(--bg-app); }
/* "background: none" explicito (no solo heredado de .menu-item) - sin esto,
   la regla global "button.danger { background: var(--danger); color: #fff }"
   le gana el fondo (misma especificidad que .menu-item, pero .menu-item.danger
   le gana el color de texto), dejando texto rojo sobre fondo rojo, ilegible
   (bug real, confirmado 2026-08-03 en el menu de acciones de Facturas). */
.menu-item.danger { color: var(--danger); background: none; }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-divider { border: none; border-top: 1px solid var(--border-color); margin: 6px 0; }

/* Valor de solo lectura (vista "guardado" antes de Editar) */
.fiscal-valor {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-primary);
  min-height: 1.3em;
}

/* Grid de formulario con anchos variables segun importancia del campo */
.form-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0 var(--space-3);
}
.form-grid > .f-2 { grid-column: span 2; }
.form-grid > .f-3 { grid-column: span 3; }
.form-grid > .f-4 { grid-column: span 4; }
.form-grid > .f-6 { grid-column: span 6; }
.form-grid > .f-8 { grid-column: span 8; }
.form-grid > .f-12 { grid-column: span 12; }
@media (max-width: 900px) {
  .form-grid > [class*="f-"] { grid-column: span 12; }
}

/* Campos numericos del modulo de Nomina (gravado/exento/importe): mas anchos
   y legibles para que se alcance a leer bien lo capturado (2026-08-12). */
#nom-perc-gravado, #nom-perc-exento, #nom-ded-importe, #nom-op-importe,
.np-gravado, .np-exento {
  min-width: 120px;
  font-size: 1rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.log-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.log-tabs .tab-btn { flex: 0 1 auto; }
.log-panel { margin-top: 2px; }
