/* =====================================================================
   DTE Manager — Design tokens + component styles
   Basado en design_handoff_dashboard_contable/reference/styles.css
   ===================================================================== */

/* Fuentes: /fonts/fonts.css (servidas desde ContaBot, enlazadas en index.html). */

/* ── Theme tokens ─────────────────────────────────────────────────────
   Paleta de énfasis (Coolors): #E63946 rojo vivo (acento primario),
   #457B9D azul acero + #A8DADC cian claro (énfasis secundario/--info),
   #1D3557 azul marino (base de las superficies dark), #F1FAEE blanco
   hueso (tinte de las superficies light). Neutros derivados por tema. */
[data-theme="dark"] {
  --bg-0: #0c1524;
  --bg-1: #111d31;
  --bg-2: #16263f;
  --bg-3: #1d3557;   /* navy de la paleta como superficie elevada */
  --bg-4: #264268;
  --border: #24395c;
  --border-strong: #33507c;
  --text:   #e8edf5;
  --text-2: #a4b3ca;
  --text-3: #7189a8;
  --text-mute: #59708f;
  --sidebar: #0e1929;
  --sidebar-hover: #16253d;
  --sidebar-active: #1d3557;
  --positive: #34d399;
  --negative: #f87171;
  --warning:  #fbbf24;
  --info:     #a8dadc;   /* cian claro de la paleta */
  --err:      #f87171;
  --ok:       #34d399;   /* alias de --positive para toasts/badges */
  --surface:  #16263f;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.45);
  --row-alt: #16263f;
}

[data-theme="light"] {
  /* Superficies claras NEUTRAS (gris apenas frío): el tinte hacia el blanco
     hueso #F1FAEE de la paleta leía como VERDE en las tarjetas del dashboard
     (feedback del usuario). El énfasis de la paleta en el tema claro queda
     en --accent (#e63946) y --info (#457b9d). */
  --bg-0: #f3f4f6;
  --bg-1: #ffffff;
  --bg-2: #f5f6f8;   /* tarjetas (.card) — gris claro neutro */
  --bg-3: #e9ebee;
  --bg-4: #dcdfe4;
  --border: #e3e5e9;
  --border-strong: #c9cdd4;
  --text:   #1a1a1a;
  --text-2: #5a6069;
  --text-3: #7e858f;
  --text-mute: #a6abb4;
  --sidebar: #eef0f3;
  --sidebar-hover: #e4e7eb;
  --sidebar-active: #d8dce1;
  --positive: #0a8c5b;
  --negative: #c43d3d;
  --warning:  #b45309;
  --info:     #457b9d;   /* azul acero de la paleta */
  --err:      #c43d3d;
  --ok:       #0a8c5b;   /* alias de --positive para toasts/badges */
  --surface:  #ffffff;
  --shadow-sm: 0 1px 2px rgba(20,25,35,0.06);
  --shadow-md: 0 4px 14px rgba(20,25,35,0.08);
  --row-alt: #f5f6f8;
}

:root {
  --accent: #e63946;
  --accent-hover: #ec5762;
  --accent-soft: rgba(230,57,70,0.12);
  /* Color secundario de gráficas/BI (2ª serie): lo fija app.js según el acento
     elegido (ACCENT_PRESETS[].second). Default = acero, el par del rojo. */
  --accent-2: #457b9d;
  --accent-2-soft: rgba(69,123,157,0.12);
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --rail: 64px;
  --sidebar-expanded: 224px;
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
}

/* ── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-sans);
  font-size: 13px;
  background: var(--bg-1);
  color: var(--text);
  line-height: 1.5;
}
button { background: none; border: none; font: inherit; cursor: pointer; color: inherit; }
input, select { font: inherit; color: inherit; background: none; border: none; outline: none; }
a { color: inherit; text-decoration: none; }
svg { display: block; }

/* ── App shell ──────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar slot ───────────────────────────────────────────────────── */
.sidebar-slot {
  /* Oculto — la navegación se movió al topbar como nav horizontal */
  display: none;
}

/* Hover-expand: slot is fixed at rail width; sidebar overlays on hover */
.sidebar-slot.hover-expand { width: var(--rail); }
.sidebar-slot.hover-expand .sidebar {
  position: absolute;
  /* Sidebar flotante:
     · Arriba: 24px (≈2vh)
     · Abajo: 100px — el dock de macOS ocupa los últimos ~80px del viewport,
       así que 2vh quedaba detrás del dock. 100px asegura un gap visible. */
  inset: 24px auto 100px 0;
  width: var(--rail);
  overflow: hidden;
  /* Solo esquinas derechas redondeadas — el lado izquierdo queda pegado al borde */
  border-radius: 0 14px 14px 0;
  /* Sombra al lado derecho que crea el efecto flotante */
  box-shadow: 8px 0 24px rgba(0,0,0,0.30),
              2px 2px 6px rgba(0,0,0,0.15);
  transition: width .18s ease, box-shadow .18s ease;
}
.sidebar-slot.hover-expand:hover .sidebar {
  width: var(--sidebar-expanded);
  box-shadow: 12px 0 36px rgba(0,0,0,0.45),
              4px 4px 10px rgba(0,0,0,0.25);
}
/* Prevent the expanding/collapsing sidebar from intercepting clicks in the content area.
   Nav items and action rows restore pointer-events so they remain clickable at all times. */
.sidebar-slot.hover-expand:not(:hover) .sidebar { pointer-events: none; }
.sidebar-slot.hover-expand .nav-item,
.sidebar-slot.hover-expand .nav-action { pointer-events: auto; }
[data-theme="light"] .sidebar-slot.hover-expand .sidebar {
  box-shadow: 0 8px 24px rgba(50,40,20,0.10),
              0 2px 6px rgba(50,40,20,0.06);
}
[data-theme="light"] .sidebar-slot.hover-expand:hover .sidebar {
  box-shadow: 0 14px 36px rgba(50,40,20,0.14),
              0 4px 10px rgba(50,40,20,0.08);
}

/* At rest: hide text and secondary elements, center icon-only items */
.sidebar-slot.hover-expand:not(:hover) .nav-label,
.sidebar-slot.hover-expand:not(:hover) .nav-badge,
.sidebar-slot.hover-expand:not(:hover) .user-info,
.sidebar-slot.hover-expand:not(:hover) .sidebar-section,
.sidebar-slot.hover-expand:not(:hover) .foot-controls,
.sidebar-slot.hover-expand:not(:hover) .nav-action { display: none; }

.sidebar-slot.hover-expand:not(:hover) .nav-item {
  justify-content: center;
  padding: 0;
  margin: 1px 12px;
  gap: 0;
}
.sidebar-slot.hover-expand:not(:hover) .user-pill {
  justify-content: center;
  padding: 8px 0;
}

/* ── Sidebar body ───────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  height: 100%;
}

#nav-rail {
  flex: 1;
  overflow-y: auto; overflow-x: hidden;
  padding: 16px 0 8px;
}
#nav-rail::-webkit-scrollbar { width: 3px; }
#nav-rail::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-section {
  /* Cabecera más compacta — menos ruido visual */
  padding: 18px 16px 6px;
  font-size: 10px; font-weight: 700;
  letter-spacing: .12em;
  /* Color de acento pero más tenue por defecto */
  color: var(--accent);
  opacity: .65;
  text-transform: uppercase;
  white-space: nowrap;
  transition: opacity .15s;
}
/* Sección del menú activo: label más brillante */
.sidebar-section.active {
  opacity: 1;
}
/* Primera sección sin padding-top extra */
#nav-rail > .sidebar-section:first-child {
  padding-top: 6px;
}

/* Nav items */
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px; height: 34px; margin: 1px 8px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  position: relative;
  transition: background .12s, color .12s;
}
.nav-item .icn { flex-shrink: 0; opacity: .75; transition: opacity .12s, color .12s; }
.nav-item:hover { background: var(--sidebar-hover); color: var(--text); }
.nav-item:hover .icn { opacity: 1; }
.nav-item.active {
  background: var(--sidebar-active);
  color: var(--text);
  font-weight: 600;
}
.nav-item.active .icn { color: var(--accent); opacity: 1; }
/* Indicador izquierdo en el item activo */
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -2px; top: 8px; bottom: 8px;
  width: 3px; background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 999px; line-height: 1.4;
}

/* Import action rows (hidden at rest) */
.nav-action {
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; height: 28px; margin: 1px 8px;
  border-radius: var(--r-sm);
  color: var(--text-3);
  font-size: 11px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background .1s, color .1s;
}
.nav-action .icn { flex-shrink: 0; opacity: 0.7; }
.nav-action:hover { background: var(--sidebar-hover); color: var(--text-2); }
.nav-action.primary { color: var(--accent); }
.nav-action.primary:hover { color: var(--accent-hover); }
.nav-action .nav-label { flex: 1; }
.status-dot {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--negative); flex-shrink: 0;
}
.status-dot.ok { background: var(--positive); }

/* Sidebar footer */
.sidebar-foot {
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding: 8px;
}
.user-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 4px; border-radius: var(--r-md);
  cursor: default;
}
.user-pill:hover { background: var(--sidebar-hover); }
.user-pill .avatar {
  width: 30px; height: 30px; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.user-info .uname { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; }
.user-info .urole { font-size: 11px; color: var(--text-3); margin-top: 1px; white-space: nowrap; }

.foot-controls {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 4px 0;
}
.foot-ctrl-btn {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  display: grid; place-items: center;
  color: var(--text-3);
  transition: background .1s, color .1s;
}
.foot-ctrl-btn:hover { background: var(--sidebar-hover); color: var(--text-2); }
.accent-row { display: flex; align-items: center; gap: 4px; margin-left: 4px; }
.accent-swatch {
  width: 14px; height: 14px; border-radius: 999px;
  cursor: pointer; border: 2px solid transparent;
  transition: transform .1s;
}
.accent-swatch:hover { transform: scale(1.2); }
.accent-swatch.active { border-color: var(--text); }

/* ── Content area ───────────────────────────────────────────────────── */
#content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  position: relative;     /* habilita el ::before del backdrop blur */
}

/* Overlay borroso sobre TODO el viewport cuando el sidebar está expandido.
   Usa position:fixed para cubrir hasta los bordes (incluyendo los 2vh arriba
   y abajo del sidebar flotante). El sidebar queda nítido encima gracias al
   z-index alto del .sidebar-slot (100) > este blur (50). */
#content-area::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px) saturate(100%);
  -webkit-backdrop-filter: blur(0px) saturate(100%);
  transition: backdrop-filter .22s ease, -webkit-backdrop-filter .22s ease,
              background .22s ease;
}
.sidebar-slot.hover-expand:hover ~ #content-area::before {
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(6px) saturate(115%);
  -webkit-backdrop-filter: blur(6px) saturate(115%);
}
[data-theme="light"] .sidebar-slot.hover-expand:hover ~ #content-area::before {
  background: rgba(80, 70, 50, 0.10);
}

/* ── Top bar ────────────────────────────────────────────────────────── */
#topbar {
  height: 60px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}
.tb-title {
  flex-shrink: 0;
  width: 220px;
  overflow: hidden;
  /* PC: el título de la pantalla va en #page-head (opción A del menú,
     2026-10-09). Solo el teléfono lo muestra en la barra (ver ≤ 700 px). */
  display: none;
}

/* ── Encabezado de la página: «Grupo › Pantalla» + avisos de la vista ── */
.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px 0;
  background: var(--bg-1);
  flex-shrink: 0;
}
.ph-crumb {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  color: var(--text-3);
}
.ph-grp { white-space: nowrap; }
.ph-sep { opacity: .6; }
.ph-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ph-aside { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ph-aside:empty { display: none; }
@media (min-width: 701px) {
  #page-head ~ #main { padding-top: 12px; }
  #page-head ~ #main:has(> .doc-toolbar) { padding-top: 6px; }
}
.tb-title h2 {
  font-size: 16px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tb-title p  {
  font-size: 12px; color: var(--text-3); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Bloque de controles a la derecha del nav */
.tb-right-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* (El pill del usuario logueado del topbar se retiró — a pedido del usuario
   ya no se muestra nombre/rol/avatar en la esquina superior derecha; solo
   queda el botón de cerrar sesión.) */

/* Botón con el dot del color de acento actual */
.tb-accent-current {
  border-radius: var(--r-md);
}
.tb-accent-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}
.tb-accent-group {
  position: relative;
}
.tb-accent-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,.4);
  z-index: 270;
  flex-direction: row;
  flex-wrap: wrap;               /* 8 acentos → 2 filas de 4 */
  width: calc(4 * 22px + 3 * 6px + 16px);
  gap: 6px;
  animation: tb-drop-in .14s ease-out;
}
.tb-accent-dropdown.open { display: flex; }
.tb-accent-swatch {
  width: 22px; height: 22px; border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .12s, transform .12s;
}
.tb-accent-swatch:hover { transform: scale(1.1); }
.tb-accent-swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--border);
}

/* ── Nav horizontal (sustituye al sidebar vertical) ─────────────────── */
.tb-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  justify-content: flex-start;
  min-width: 0;
  /* MUST stay `visible` — los dropdowns son `position: absolute` y un
     `overflow: hidden/auto/scroll` aquí los clippearía. El no-solapamiento
     se logra con flex-shrink:0 en los grupos (abajo). */
  overflow: visible;
}
.tb-nav-group {
  position: relative;
  /* Sin esto, el flex contracta el botón mientras su contenido
     `white-space: nowrap` se desborda y solapa al siguiente. */
  flex-shrink: 0;
}
.tb-nav-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 9px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.tb-nav-btn:hover {
  background: var(--bg-3);
  color: var(--text);
}
.tb-nav-group.active .tb-nav-btn {
  color: var(--accent);
  font-weight: 600;
  background: rgba(255,255,255,.04);
}
[data-theme="light"] .tb-nav-group.active .tb-nav-btn {
  background: rgba(0,0,0,.04);
}
.tb-nav-dropdown {
  position: absolute;
  /* Sin gap real entre botón y dropdown (evita flicker al pasar el mouse).
     El espacio visual lo da el margin-top dentro del dropdown. */
  top: 100%;
  left: 0;
  margin-top: 6px;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 12px 32px rgba(0,0,0,.40),
              0 4px 8px rgba(0,0,0,.20);
  z-index: 250;
  display: none;
  animation: tb-drop-in .14s ease-out;
  /* Menús largos (Contabilidad: 4 bloques + 7 reportes) se salían por abajo
     del viewport en pantallas de 13" y los últimos ítems quedaban
     inalcanzables (2026-09-14). Tope = alto de la ventana menos el topbar
     (~84px) y un margen; el resto se desplaza con scroll dentro del menú. */
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* Puente invisible entre el botón y el dropdown — captura el mouse al
   moverse del botón al dropdown sin que se cierre por el gap visual. */
.tb-nav-dropdown::before {
  content: '';
  position: absolute;
  top: -8px; left: 0; right: 0;
  height: 8px;
}
[data-theme="light"] .tb-nav-dropdown {
  box-shadow: 0 12px 28px rgba(50,40,20,.15),
              0 4px 8px rgba(50,40,20,.08);
}
@keyframes tb-drop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* Los dropdowns del nav abren SOLO por click (clase `.open`, gestionada en
   `wireHorizontalNav`), NUNCA por hover: el JS garantiza que haya UN solo
   grupo abierto a la vez, así que pasar el cursor por otro grupo ya no abre un
   segundo dropdown encima (bug de menús superpuestos). */
.tb-nav-group.open .tb-nav-dropdown { display: block; }

/* El dropdown de "Más" es SIEMPRE el grupo más a la derecha de la nav
   (`collapseNavOverflow` lo agrega al final). Con `left: 0` se abría
   extendiéndose hacia la derecha y se salía del viewport: la parte visible
   quedaba pegada al borde y, al mover el cursor hacia una opción, se salía del
   área hoverable y el menú "desaparecía". Alinearlo a la DERECHA lo mantiene
   entero dentro de pantalla, con el mismo puente `::before` sirviendo el gap. */
.tb-nav-group[data-group="_more"] .tb-nav-dropdown {
  left: auto;
  right: 0;
}
/* «Más» (ventanas de menos de ~1280 px): panel fijo bajo la barra con una
   columna por grupo y su nombre arriba; los reportes quedan dentro de su
   grupo. Fijo y anclado a la izquierda porque la barra empieza a la izquierda
   y «Más» queda a media pantalla: alineado a su botón se salía de la ventana.
   Columnas CSS (no grid): un grupo largo (Contabilidad) no empuja a los
   demás hacia abajo. */
.tb-nav-group[data-group="_more"] .tb-nav-dropdown.tb-more {
  position: fixed;
  top: 56px;
  left: 24px;
  right: auto;
  width: min(760px, calc(100vw - 48px));
  padding: 10px;
}
.tb-more-cols { column-width: 200px; column-gap: 16px; }
.tb-more-col { break-inside: avoid; display: flex; flex-direction: column; margin-bottom: 8px; }
.tb-more-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 6px 10px 4px;
}

/* Engrane ⚙ (Configuración y Sistema) en los controles de la derecha. */
.tb-gear-btn { width: 32px; padding: 0; justify-content: center; }
.tb-gear .tb-nav-dropdown { left: auto; right: 0; min-width: 220px; }
.tb-nav-sep-label.first { margin-top: 0; border-top: none; }

/* Cuando hay un dropdown abierto (por click), aplicar blur al contenido
   debajo del topbar. Usa :has() para detectar el estado desde el padre.
   El topbar (donde vive el nav) NO se desenfoca. */
#topbar:has(.tb-nav-group.open) ~ #main,
#topbar:has(.tb-nav-group.open) ~ .tb-extras-row {
  filter: blur(0);
  transition: filter .2s ease;
}

/* Overlay borroso global cuando el nav está activo */
#tb-nav-blur {
  position: fixed;
  inset: 60px 0 0 0;     /* debajo del topbar (60px) */
  z-index: 200;
  pointer-events: none;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px) saturate(100%);
  -webkit-backdrop-filter: blur(0px) saturate(100%);
  opacity: 0;
  transition: backdrop-filter .22s ease, -webkit-backdrop-filter .22s ease,
              background .22s ease, opacity .22s ease;
}
#topbar:has(.tb-nav-group.open) ~ #tb-nav-blur,
body:has(.tb-nav-group.open) #tb-nav-blur {
  opacity: 1;
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(6px) saturate(115%);
  -webkit-backdrop-filter: blur(6px) saturate(115%);
}
[data-theme="light"] body:has(.tb-nav-group.open) #tb-nav-blur {
  background: rgba(80, 70, 50, 0.10);
}

/* El dropdown necesita estar por encima del overlay */
.tb-nav-dropdown { z-index: 260; }
.tb-nav-item {
  display: block;
  padding: 7px 12px;
  font-size: 12px;
  color: var(--text-2);
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .1s, color .1s;
}
/* Logo de ContaBot antes del nombre de los bots (RPA) — `BOT_MARK` en app.js. */
.bot-mark { display: inline-block; width: 14px; height: 14px; flex-shrink: 0; vertical-align: -2px; margin-right: 6px; }
.nav-item .icn .bot-mark { width: 16px; height: 16px; margin-right: 0; vertical-align: middle; }
.mm-item .bot-mark { margin-right: 0; }
.tb-nav-item:hover {
  background: var(--bg-3);
  color: var(--text);
}
.tb-nav-item.active {
  color: var(--accent);
  font-weight: 600;
  background: rgba(255,255,255,.04);
}
[data-theme="light"] .tb-nav-item.active {
  background: rgba(0,0,0,.04);
}

/* Separador entre items de navegación e items de acción (importación) */
.tb-nav-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

/* Separador con etiqueta — usado para la sub-sección de Reportes dentro
   de un grupo. Tiene la línea + texto pequeño que distingue visualmente
   los reportes de las funciones operativas del grupo. */
/* Bloque temático dentro de un desplegable (p. ej. Contabilidad: Libros ·
   Terceros · IVA · Activos). Separador en el color de acento del tema. */
.tb-nav-block-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 8px 10px 3px;
  margin-top: 4px;
}
.tb-nav-block-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--accent);
  opacity: .45;
}
.tb-nav-block-label.first { margin-top: 0; padding-top: 4px; }

.tb-nav-sep-label {
  position: relative;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 6px 10px 4px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

/* Items de reporte: mismo dropdown pero look más sutil para distinguirlos
   de los items operativos. */
.tb-nav-item.tb-nav-report {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
}
.tb-nav-item.tb-nav-report:hover {
  color: var(--text);
  background: var(--bg-3);
}
.tb-nav-item.tb-nav-report.active {
  color: var(--accent);
  font-weight: 600;
  background: rgba(255,255,255,.04);
}
[data-theme="light"] .tb-nav-item.tb-nav-report.active {
  background: rgba(0,0,0,.04);
}
.tb-nav-report-icn {
  display: inline-flex;
  align-items: center;
  opacity: 0.7;
  flex-shrink: 0;
}

/* Acciones de importación dentro del dropdown */
.tb-nav-item.tb-nav-action {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
}
.tb-nav-item.tb-nav-action.primary {
  color: var(--accent);
}
.tb-nav-item.tb-nav-action:hover {
  color: var(--text);
  background: var(--bg-3);
}
/* Indicador de conexión Gmail/Outlook al lado de la opción */
.tb-nav-dot {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--negative);
  margin-left: auto;
  flex-shrink: 0;
}
.tb-nav-dot.ok {
  background: var(--positive);
}

/* Sub-row con los pills/cards de la vista activa (debajo del topbar) */
.tb-extras-row {
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-shrink: 0;
}
/* Compras → Documentos: resumen en UNA fila de tarjetas compactas, separadas,
   redondeadas y "flotando" (sombra suave; se elevan al pasar el cursor) —
   usuario 2026-09-26. Antes: 2 filas de tarjetas grandes. */
.doc-kpis {
  display: flex; flex-wrap: wrap; flex: 1; min-width: 0; gap: 8px;
}
/* Menos aire entre la franja y la barra de filtros (usuario 2026-09-26: "hay
   mucho espacio entre las tarjetas y los filtros"): 31 px → ~13 px. */
.tb-extras-row:has(.doc-kpis) { padding-bottom: 8px; }
#main:has(> .doc-toolbar) { padding-top: 6px; }
.doc-kpi {
  flex: 1 1 112px; min-width: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 6px 12px; display: flex; flex-direction: column;
  justify-content: center; line-height: 1.25; cursor: default;
  box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 16px -6px rgba(0,0,0,.14);
  transition: transform .15s ease, box-shadow .15s ease;
}
.doc-kpi:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0,0,0,.06), 0 12px 24px -8px rgba(0,0,0,.22);
}
/* Tarjeta que filtra la tabla (clic): cursor de mano; la elegida, con el
   contorno y un anillo del color de énfasis. */
.doc-kpi.clickable { cursor: pointer; }
.doc-kpi.on {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent),
              0 6px 16px -6px rgba(0,0,0,.14);
}
[data-theme="dark"] .doc-kpi { box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 16px -6px rgba(0,0,0,.6); }
.doc-kpi-l {
  font-size: 9.5px; color: var(--text-3); text-transform: uppercase;
  letter-spacing: .05em; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.doc-kpi-v {
  font-size: 14px; font-weight: 700; color: var(--text);
  font-family: var(--font-mono); white-space: nowrap; letter-spacing: -.01em;
}
.doc-kpi.accent .doc-kpi-v { color: var(--accent); }
.tb-ghost {
  width: 34px; height: 34px;
  border-radius: var(--r-md);
  display: grid; place-items: center;
  color: var(--text-3);
  transition: background .12s, color .12s;
}
.tb-ghost:hover { background: var(--bg-3); color: var(--text); }
/* Botón ghost con TEXTO (no ícono): anula el ancho fijo de 34px para que la
   etiqueta no se desborde ni se encime con el botón siguiente. Usa inline-flex
   (como .tb-primary) para encoger de forma predecible al contenido. */
.tb-ghost.has-label {
  display: inline-flex; align-items: center; justify-content: center;
  width: auto; padding: 0 12px; gap: 6px; white-space: nowrap;
}
.tb-primary {
  display: flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: var(--r-md);
  background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 600;
  transition: background .12s;
}
.tb-primary:hover { background: var(--accent-hover); }
.tb-pill {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px;
  border-radius: var(--r-md);
  background: var(--bg-3);
  border: 1px solid var(--border);
  font-size: 12px; font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: background .12s;
}
.tb-pill:hover { background: var(--bg-4); }
.tb-pill.active { background: var(--accent); color: #fff; border-color: transparent; }

/* Pill del nombre de la empresa en el topbar: sin este límite, un nombre de
   empresa largo crece sin tope y aplasta el nav horizontal, tapando el
   botón de tema/acento a su izquierda (mismo problema que .tb-user-pill ya
   resuelve para el nombre de usuario). */
.tb-right-controls .tb-pill {
  max-width: 220px;
}
.tb-right-controls .tb-pill span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.tb-sep { width: 1px; height: 20px; background: var(--border); }

/* ── Progress bar ───────────────────────────────────────────────────── */
#progress-bar {
  height: 3px;
  background: var(--bg-3);
  flex-shrink: 0;
  overflow: hidden;
  display: none;
}
#progress-bar.visible { display: block; }
#progress-bar-inner {
  height: 100%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  animation: indeterminate 1.4s linear infinite;
  width: 30%;
}
/* Modo determinado: el ancho lo fija JS (window.appProgress) según correos
   procesados / total; sin animación de deslizado, transición suave al crecer. */
#progress-bar-inner.determinate {
  animation: none;
  transform: none;
  width: 0;
  transition: width .25s ease;
}
@keyframes indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* Etiqueta de avance (pill flotante) — muestra "Importando… 12 / 40". Aparece
   solo mientras corre un job con progreso cuantificado. */
#progress-label {
  display: none;
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 500;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  white-space: nowrap;
  pointer-events: none;
}
#progress-label.visible { display: flex; align-items: center; gap: 10px; pointer-events: auto; }
/* Botón "Cancelar" de la barra: sólo para jobs cancelables (validar contra
   Hacienda, depurar cola de PDF) — clase `.cancellable` puesta por app.js. */
#progress-cancel {
  display: none;
  height: 22px; padding: 0 10px;
  border: 1px solid var(--negative); border-radius: 999px;
  background: transparent; color: var(--negative);
  font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
}
#progress-cancel:hover { background: var(--negative); color: #fff; }
#progress-cancel:disabled { opacity: .5; cursor: default; }
#progress-label.cancellable #progress-cancel { display: inline-block; }

/* ── Main scroll area ───────────────────────────────────────────────── */
#main {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 32px;
  background: var(--bg-1);
}
#main::-webkit-scrollbar { width: 6px; }
#main::-webkit-scrollbar-track { background: transparent; }
#main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#main::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ── Cards ──────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
}
[data-theme="light"] .card { box-shadow: var(--shadow-sm); }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-title { font-size: 13px; font-weight: 600; letter-spacing: -.005em; }
.card-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ── Filter bar ─────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.filter-label { font-size: 11px; font-weight: 600; color: var(--text-3); white-space: nowrap; }
.filter-input {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text);
  height: 30px;
}
.filter-input::placeholder { color: var(--text-3); }
.filter-input:focus { border-color: var(--accent); outline: none; }
select.filter-input { cursor: pointer; }
.filter-sep { width: 1px; height: 18px; background: var(--border); }

/* ── Table ──────────────────────────────────────────────────────────── */
.tbl-wrap {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  /* Con la ventana angosta la tabla completa (encabezado + filas) hace scroll
     horizontal AQUÍ: `.tbl-head-row` y `.tbl-body` miden como mínimo la suma
     de sus columnas (min-content), así que nunca se desalinean ni el cuerpo
     se desplaza solo (QA Planillas 2026-09-20). */
  overflow-x: auto;
  overflow-y: hidden;
}
.tbl-head-row {
  display: grid;
  border-bottom: 1px solid var(--border);
  background: var(--bg-3);
  min-width: min-content;
}
.tbl-h {
  padding: 8px 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text-3);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}
.tbl-h.sortable { cursor: pointer; user-select: none; }
.tbl-h.sortable:hover { color: var(--text); }
.tbl-h.sorted { color: var(--accent); }
.tbl-h .sort-ind { font-size: 9px; }
.tbl-body { overflow-y: auto; min-width: min-content; }
.tbl-body::-webkit-scrollbar { width: 4px; }
.tbl-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.tbl-row {
  display: grid;
  align-items: center;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  cursor: default;
}
.tbl-row:last-child { border-bottom: none; }
.tbl-row:hover { background: var(--bg-3); }
.tbl-row.alt { background: var(--row-alt); }
.tbl-row.alt:hover { background: var(--bg-3); }
/* Inventario → importar desde un DTE: filas alternadas con hover por CSS (antes
   onmouseover/onmouseout en línea, incompatibles con la CSP sin 'unsafe-inline'). */
.imp-dte-row { background: transparent; }
.imp-dte-row.alt { background: var(--bg-2); }
.imp-dte-row:hover { background: var(--bg-3); }
.tbl-c {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tbl-c.muted { color: var(--text-3); }
.tbl-c.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tbl-c.right { text-align: right; }
.tbl-empty {
  padding: 40px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

/* ── KPI cards strip ────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
.kpi-label {
  font-size: 10px; text-transform: uppercase;
  letter-spacing: .06em; font-weight: 700; color: var(--text-3);
}
.kpi-value {
  font-family: var(--font-mono); font-size: 24px;
  font-weight: 600; letter-spacing: -.02em;
  color: var(--text); margin-top: 8px;
}
.kpi-value .cur { font-size: 13px; color: var(--text-3); margin-right: 2px; vertical-align: 2px; }
.kpi-delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px; margin-top: 8px;
}
.kpi-delta.pos { color: var(--positive); background: color-mix(in srgb, var(--positive) 14%, transparent); }
.kpi-delta.neg { color: var(--negative); background: color-mix(in srgb, var(--negative) 14%, transparent); }
.kpi-delta.neu { color: var(--text-2);   background: var(--bg-3); }

/* ── Badges / pills ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.badge.ok      { color: var(--positive); background: color-mix(in srgb, var(--positive) 14%, transparent); }
.badge.warn    { color: var(--warning);  background: color-mix(in srgb, var(--warning)  16%, transparent); }
.badge.err     { color: var(--negative); background: color-mix(in srgb, var(--negative) 14%, transparent); }
.badge.mute    { color: var(--text-2);   background: var(--bg-3); }
.badge.info    { color: var(--info);     background: color-mix(in srgb, var(--info)     14%, transparent); }
.badge.accent  { color: #fff; background: var(--accent); }

/* Segmented control */
.seg {
  display: inline-flex;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 3px; gap: 2px;
}
.seg button {
  height: 26px; padding: 0 10px;
  border-radius: 5px;
  font-size: 12px; font-weight: 500;
  color: var(--text-2);
  transition: background .1s, color .1s;
}
.seg button.active {
  background: var(--bg-1); color: var(--text);
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .seg button.active { background: var(--bg-4); }

/* ── Log view ───────────────────────────────────────────────────────── */
#log-box {
  /* Tarjetas por proceso (views/log.js, 2026-09-13). El scroll vive dentro
     del div para que el auto-scroll al último evento funcione. */
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* Ocupa TODO el alto disponible de #main (el wrapper de views/log.js es
     una columna flex de height:100%): antes un max-height fijo dejaba una
     franja vacía abajo. */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 2px 12px;
  user-select: text;
  -webkit-user-select: text;
}

/* ── Dashboard ──────────────────────────────────────────────────────── */
.dash-kpi { padding: 16px 18px; }
.dash-split { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.dash-kpi .kpi-value { font-family: var(--font-mono); font-size: 28px; font-weight: 600; letter-spacing: -.02em; color: var(--text); }
.dash-kpi .kpi-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--text-3); }
.dash-kpi svg { display: block; width: 100% !important; }

/* ── Misc utilities ─────────────────────────────────────────────────── */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }
.mt-16 { margin-top: 16px; }
.mt-8  { margin-top: 8px; }
.text-3 { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.mono { font-family: var(--font-mono); }
.num  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.bold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stub-view {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 60vh; gap: 12px;
  color: var(--text-3); font-size: 14px;
}
.stub-view svg { opacity: .4; }

/* ── Period selector ────────────────────────────────────────────────── */
.period-bar {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px;
}

/* Compras → Documentos: UNA barra (período + búsqueda + filtros + acciones).
   Cada control con su título encima (.tf-l) en vez de a la izquierda. La
   búsqueda mide poco y, mientras se escribe, se alarga SOBRE los filtros
   (posición absoluta: no empuja nada ni parte la fila). */
.doc-toolbar { align-items: flex-end; gap: 6px 7px; flex-wrap: wrap; padding: 8px 14px; }
.doc-toolbar .tf { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.doc-toolbar .tf-l {
  font-size: 9.5px; font-weight: 600; color: var(--accent); text-transform: uppercase;
  letter-spacing: .05em; white-space: nowrap; line-height: 1;
}
.doc-toolbar .seg { height: 30px; }
.doc-toolbar .tf-reset { width: 30px; height: 30px; }
.doc-toolbar .tf-sep { align-self: center; margin-top: 12px; }
.doc-toolbar .spacer { flex: 1; }
.doc-search-box { position: relative; width: 130px; height: 30px; }
/* El buscador SOBRESALE (usuario 2026-09-26): contorno y lupa en el color de
   énfasis siempre; anillo al escribir; fondo teñido cuando tiene texto. */
.doc-search-box input {
  position: absolute; left: 0; top: 0; width: 130px; z-index: 5;
  border: 1.5px solid var(--accent); background-color: var(--surface);
  padding-left: 28px; font-weight: 500;
  transition: width .18s ease, box-shadow .18s ease;
}
.doc-search-box input::placeholder { color: var(--text-2); }
.doc-search-box .doc-search-ico {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  z-index: 6; color: var(--accent); pointer-events: none; display: flex;
}
.doc-search-box input:focus {
  width: 260px; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent),
              0 4px 14px rgba(0,0,0,.12);
}
.doc-search-box input:not(:placeholder-shown):not(:focus) {
  background-color: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
.doc-toolbar select.filter-input.is-set { border-color: var(--accent); font-weight: 600; }

/* ── Print ──────────────────────────────────────────────────────────── */
/* La orientación de la página se inyecta dinámicamente desde el JS antes de
   llamar window.print() (los named-pages no funcionan en pywebview/WebKit).
   El default sin override es A4 vertical, que es lo que usan las partidas. */
@media print {
  @page { size: A4 portrait; margin: 1.8cm 2cm; }
  body * { visibility: hidden !important; }
  #jn-print-area, #jn-print-area *,
  #bg-print-runtime, #bg-print-runtime * { visibility: visible !important; }
  #jn-print-area,
  #bg-print-runtime {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    background: #fff !important;
    color: #000 !important;
  }
  /* En el balance: fuerza colores imprimibles (los del tema oscuro no salen bien) */
  #bg-print-runtime * {
    color: #000 !important;
    background: #fff !important;
    box-shadow: none !important;
  }
  #bg-print-runtime #bg-print-area {
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }
  #bg-print-runtime .bg-account-table th,
  #bg-print-runtime .bg-account-table .total-row td {
    border-color: #000 !important;
  }
  #bg-print-runtime .bg-firmas-table .firma-line {
    border-top-color: #000 !important;
  }
}

/* ── Number input — hide spinners ───────────────────────────────────── */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* ── Scrollbar global ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* App instalada en iPhone horizontal (viewport-fit=cover, 2026-09-23): que
   la muesca no tape los bordes. En navegadores y en vertical valen 0. */
body { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }

/* ── Teléfono (≤ 700 px): encabezado compacto + barra inferior + hoja "Menú" ──
   Móvil fase 4 (2026-09-23). En el teléfono el nav horizontal y los controles
   de la derecha se montaban uno encima del otro: se ocultan y la navegación
   pasa a la barra de abajo (app.js::renderBottomNav / openMobileMenu). La
   empresa se muestra bajo el título (toca para cambiarla). En PC nada cambia. */
.tb-co, #bottom-nav { display: none; }
@media (max-width: 700px) {
  :root { --bnav-h: 58px; }
  #app { height: 100vh; height: 100dvh; }
  #content-area { padding-bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0px)); }
  #topbar { height: auto; min-height: 54px; padding: 6px 8px 6px 16px; gap: 8px; }
  .tb-title { display: block; width: auto; flex: 1; min-width: 0; }
  /* El título va en la barra: del encabezado de página solo quedan los avisos
     de la vista (si hay). */
  .page-head { padding: 8px 12px 0; }
  .page-head .ph-crumb { display: none; }
  .page-head:not(:has(.ph-aside > *)) { display: none; }
  .tb-title h2 { font-size: 17px; }
  .tb-title .tb-sub { display: none; }
  .tb-co {
    display: flex; align-items: center; gap: 4px; max-width: 100%;
    font-size: 12px; color: var(--text-3); margin-top: 1px; padding: 0;
  }
  .tb-co span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tb-co svg { flex-shrink: 0; opacity: .7; }
  #tb-nav, #tb-gear, #tb-theme-btn, .tb-accent-group, #tb-company-pill, #tb-sucursal-pill, #tb-logout { display: none; }
  #tb-help { width: 40px !important; height: 40px !important; }
  .tb-extras-row { padding: 8px 12px; overflow-x: auto; }
  .doc-kpis { flex-wrap: nowrap; flex: 0 0 auto; }
  /* Teléfono: la búsqueda ocupa su propio renglón (no se alarga encima). */
  .doc-toolbar .doc-search { flex: 1 1 100%; }
  .doc-search-box { width: 100%; }
  .doc-search-box input, .doc-search-box input:focus { position: static; width: 100%; }
  .doc-kpi { flex: 0 0 auto; }
  /* Tablero: 4 indicadores en fila no caben a 360 px (la 4.ª tarjeta se salía
     98 px y la pantalla se desplazaba a lo ancho; prueba de pantalla 2026-10-27). */
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .dash-kpi { padding: 12px 12px; min-width: 0; }
  .dash-kpi .kpi-value { font-size: 20px; overflow-wrap: anywhere; }
  .dash-split { grid-template-columns: minmax(0, 1fr); }

  #bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 65;
    height: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: var(--bg-1); border-top: 1px solid var(--border);
  }
  .bn-tab {
    flex: 1 1 0; min-width: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px;
    color: var(--text-3); -webkit-tap-highlight-color: transparent;
  }
  .bn-ic { display: grid; place-items: center; width: 52px; height: 28px; border-radius: 14px; transition: background .15s; }
  .bn-ic svg { width: 22px; height: 22px; }
  .bn-lbl { font-size: 11px; font-weight: 500; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bn-tab.active { color: var(--accent); }
  .bn-tab.active .bn-ic { background: var(--accent-soft); }
  .bn-tab.active .bn-lbl { font-weight: 600; }
  .bn-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; border-radius: 10px; }
  /* Con el teclado abierto la barra solo estorba: se esconde mientras se escribe.
     Salvo con la hoja "Menú" abierta: al tocar un resultado de la búsqueda el
     campo pierde el foco, la barra volvía y la hoja se corría antes del toque. */
  body:not(:has(#m-menu)):has(input:not([type=checkbox]):not([type=radio]):not([type=button]):focus, textarea:focus) #bottom-nav { display: none; }
  body:not(:has(#m-menu)):has(input:not([type=checkbox]):not([type=radio]):not([type=button]):focus, textarea:focus) #content-area { padding-bottom: 0; }
  body:not(:has(#m-menu)):has(input:not([type=checkbox]):not([type=radio]):not([type=button]):focus, textarea:focus) { --bnav-h: 0px; }
  /* La hoja "Menú" se abre ENCIMA de la barra: la barra sigue tocable
     (Menú la cierra; una pestaña navega directo). */
  body .mm-ov { bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0px)); }
  body .mm-ov .mm-sheet { padding-bottom: 0; max-height: calc(100% - 24px); }
}

/* Hoja "Menú" (solo se abre desde la barra inferior) */
.mm-ov {
  position: fixed; inset: 0; z-index: 250; display: flex; align-items: flex-end;
  background: rgba(0, 0, 0, .45);
}
.mm-sheet {
  width: 100%; max-height: 88vh; max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--bg-1); border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .35);
  animation: mm-up .18s ease-out;
}
@keyframes mm-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .mm-sheet { animation: none; } }
.mm-grab { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 8px auto 2px; flex-shrink: 0; }
.mm-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px 8px 12px; flex-shrink: 0; }
.mm-co {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  color: var(--text-2);
}
.mm-co svg { flex-shrink: 0; }
.mm-co span { min-width: 0; }
.mm-co b { display: block; font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mm-co small { display: block; font-size: 11.5px; color: var(--text-3); }
.mm-x { width: 44px; height: 44px; border-radius: 12px; font-size: 26px; line-height: 1; color: var(--text-2); flex-shrink: 0; }
.mm-search {
  margin: 0 12px 6px; height: 42px; padding: 0 14px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  font-size: 16px;   /* ≥ 16 px: iOS no hace zoom al enfocar */
}
.mm-search:focus { border-color: var(--accent); }
.mm-body { overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 16px; }
.mm-grp h3 {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-3); padding: 14px 10px 4px;
}
.mm-item {
  width: 100%; min-height: 44px; display: flex; align-items: center; gap: 12px;
  padding: 0 10px; border-radius: 10px; text-align: left; font-size: 15px; color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.mm-item svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--text-3); }
.mm-item:active { background: var(--bg-3); }
.mm-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mm-item.active svg { color: var(--accent); }
.mm-item[hidden], .mm-grp[hidden], .mm-empty[hidden] { display: none; }
.mm-soon { font-size: 11px; color: var(--text-3); font-weight: 400; }
.mm-suc { margin: 0 12px 6px; width: auto; border: 1px solid var(--border); flex-shrink: 0; }
.mm-empty { padding: 28px 16px; text-align: center; color: var(--text-3); font-size: 14px; }
.mm-accents { display: flex; flex-wrap: wrap; gap: 12px; padding: 8px 10px 10px; }
.mm-sw { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; }
.mm-sw.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg-1) inset; }
.mm-user { padding: 10px 10px 2px; font-size: 12px; color: var(--text-3); overflow-wrap: anywhere; }
.mm-logout, .mm-logout svg { color: var(--err, #e5484d); }
