/* ============================================================
   La Frutología — Plataforma de Gestión Logística Operativa
   Sistema de diseño operativo (SaaS B2B). Flat, sin sombras,
   sin iconos decorativos. CSS propio, sin CDN.
   ============================================================ */

@font-face {
  font-family: 'InterVariable';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/assets/fonts/InterVariable.woff2') format('woff2');
}

:root {
  /* Lienzo y superficies */
  --color-canvas:     #f5f7f8;   /* fondo de la app */
  --color-surface:    #ffffff;   /* paneles, cards, tablas */
  --color-bg-subtle:  #f1f3f5;   /* hover de filas, fondos secundarios */
  --color-bg-muted:   #e9ecef;   /* disabled, estados pasivos */
  --color-border:     #dde1e5;   /* bordes sutiles */
  --color-border-soft:#e7eaed;
  --color-border-strong:#c7ccd1;

  /* Texto */
  --color-text-primary:   #16191c;
  --color-text-secondary: #5c636a;
  --color-text-tertiary:  #868d94;
  --color-text-inverse:   #ffffff;

  /* Acciones */
  --color-green:       #047857;
  --color-green-hover: #0a8c66;
  --color-green-active:#03624a;
  --color-green-soft:  #ecfdf5;
  --color-green-line:  #a7e3cb;
  --color-green-text:  #065f46;
  --color-blue:        #0369a1;
  --color-blue-hover:  #075a8a;
  --color-blue-soft:   #eff6ff;
  --color-blue-text:   #075985;
  --color-red:         #c0382e;
  --color-red-hover:   #a52f26;
  --color-red-soft:    #fdf2f1;
  --color-red-text:    #8f261f;
  --color-amber:       #a25c0a;
  --color-amber-soft:  #fdf7e8;
  --color-amber-text:  #7a4708;
  --color-slate-soft:  #f1f3f5;
  --color-slate-text:  #5c636a;

  /* Tipografía */
  --font-family: 'InterVariable', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --fs-h1: 1.625rem; --fs-h2: 1.1875rem; --fs-h3: 1rem;
  --fs-body: 0.9375rem; --fs-sm: 0.8125rem; --fs-xs: 0.75rem; --fs-2xs: 0.6875rem;

  /* Espaciado base 4px */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px;
  --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px; --s16: 64px;

  /* Bordes */
  --r-sm: 5px; --r-md: 8px; --r-lg: 10px; --r-pill: 999px;

  --header-h: 56px;
  --sidebar-w: 232px;
  --content-max: 1240px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-family);
  font-size: var(--fs-body);
  line-height: 1.55;
  letter-spacing: -0.006em;
  color: var(--color-text-primary);
  background: var(--color-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv05', 'cv08', 'tnum' off;
}
::selection { background: var(--color-green-soft); color: var(--color-green-text); }
a { color: var(--color-blue); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1,h2,h3 { line-height: 1.25; color: var(--color-text-primary); margin: 0; letter-spacing: -0.02em; }
h1 { font-size: var(--fs-h1); font-weight: 650; }
h2 { font-size: var(--fs-h2); font-weight: 650; margin: var(--s8) 0 var(--s3); }
h2:first-child { margin-top: 0; }
h3 { font-size: var(--fs-h3); font-weight: 600; }
p { margin: 0 0 var(--s3); }
small { font-size: var(--fs-sm); }
hr { border: none; border-top: 1px solid var(--color-border-soft); margin: var(--s6) 0; }

:where(a,button,.btn,summary,input,select,textarea):focus-visible {
  outline: 2px solid var(--color-green);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ----------------------- layout: header + sidebar + main ----------------------- */
.app-header {
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 20;
}
.app-header-inner { height: 100%; display: flex; align-items: center; gap: var(--s5); padding: 0 var(--s6); }
.app-brand { display: flex; align-items: center; gap: var(--s3); white-space: nowrap; }
.app-brand:hover { text-decoration: none; }
.app-brand .mark {
  width: 22px; height: 22px; border-radius: var(--r-sm);
  background: var(--color-green);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 12px; letter-spacing: -0.04em;
}
.app-brand .name { font-weight: 650; font-size: 0.9375rem; color: var(--color-text-primary); letter-spacing: -0.015em; }
.app-brand .name b { font-weight: 650; }
.app-brand .name .light { color: var(--color-text-tertiary); font-weight: 450; }
.app-header-spacer { flex: 1; }
.app-header-meta { font-size: var(--fs-xs); color: var(--color-text-tertiary); }
.user-chip { display: flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s3) var(--s1) var(--s1); border: 1px solid var(--color-border); border-radius: var(--r-pill); background: var(--color-surface); }
.user-chip .avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--color-bg-muted); color: var(--color-text-secondary); display: inline-flex; align-items: center; justify-content: center; font-size: var(--fs-2xs); font-weight: 700; letter-spacing: 0; }
.user-chip .who { font-size: var(--fs-sm); color: var(--color-text-secondary); }
.user-chip .who b { color: var(--color-text-primary); font-weight: 550; }

.app-body { display: flex; align-items: stretch; min-height: calc(100vh - var(--header-h)); }
.app-sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--color-surface); border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column;
}
.app-nav { padding: var(--s3) var(--s3) var(--s2); flex: 1; }
.app-nav-section { padding: var(--s4) var(--s3) var(--s1); font-size: var(--fs-2xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.09em; color: var(--color-text-tertiary); }
.app-nav-item {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3); margin: 1px 0;
  color: var(--color-text-secondary); font-weight: 450; font-size: var(--fs-body);
  border-radius: var(--r-sm);
  transition: background-color 120ms ease, color 120ms ease;
}
.app-nav-item:hover { background: var(--color-bg-subtle); text-decoration: none; color: var(--color-text-primary); }
.app-nav-item.activo { background: var(--color-green-soft); color: var(--color-green-text); font-weight: 600; }
.app-nav-item .glyph {
  width: 16px; height: 16px; flex: 0 0 16px; border-radius: 3px;
  border: 1.5px solid currentColor; opacity: .55;
}
.app-nav-item.activo .glyph { opacity: .9; background: currentColor; }
.app-sidebar-foot { padding: var(--s3); border-top: 1px solid var(--color-border-soft); font-size: var(--fs-2xs); color: var(--color-text-tertiary); }

.app-main { flex: 1 1 auto; min-width: 0; padding: var(--s8) var(--s8) var(--s12); }
.app-main-inner { max-width: var(--content-max); margin: 0 auto; }
.app-footer { max-width: var(--content-max); margin: var(--s12) auto 0; padding-top: var(--s4); border-top: 1px solid var(--color-border-soft); color: var(--color-text-tertiary); font-size: var(--fs-xs); }

/* Botón hamburguesa: sólo visible cuando el navbar colapsa (<1024px) */
.nav-toggle { display: none; }
.app-sidebar-backdrop { display: none; }

/* ----- <1024px: el navbar colapsa a drawer lateral. Desktop (≥1024) = sidebar fija. ----- */
@media (max-width: 1023px) {
  :root { --header-h: 52px; }
  .app-header-inner, .app-main { padding-left: var(--s4); padding-right: var(--s4); }
  .app-main { padding-top: var(--s5); }
  .user-chip .who { display: none; }

  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; padding: 0; border-radius: var(--r-sm);
    background: var(--color-surface); border: 1px solid var(--color-border);
    color: var(--color-text-primary); cursor: pointer;
    font-size: 18px; line-height: 1;
  }
  .nav-toggle:hover { background: var(--color-bg-subtle); }

  /* La sidebar se vuelve un drawer fijo fuera de pantalla por defecto */
  .app-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(80vw, 320px); max-width: 320px;
    z-index: 50; padding-top: var(--header-h);
    border-bottom: none; border-right: 1px solid var(--color-border);
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: 4px 0 20px -4px rgba(0,0,0,0.15);
    overflow-y: auto;
  }
  .app-sidebar .app-nav {
    flex-direction: column; flex-wrap: nowrap; gap: 2px;
    padding: var(--s3) var(--s2);
  }
  .app-sidebar .app-nav-section { display: block; }
  .app-sidebar .app-nav-item { width: 100%; padding: var(--s3); }
  .app-sidebar-foot { display: block; }

  /* Estado abierto */
  body.nav-open .app-sidebar { transform: translateX(0); }
  body.nav-open .app-sidebar-backdrop {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,0.4); z-index: 40;
    animation: nav-fade-in 200ms ease;
  }
  body.nav-open { overflow: hidden; }

  /* Compactar header en móvil estrecho */
  .app-header-inner { gap: var(--s2); padding: 0 var(--s3); }
  .app-brand .name .light { display: none; }
  .app-brand .name b { font-size: 0.875rem; }
}
@keyframes nav-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ----------------------- encabezado de página ----------------------- */
.crumbs { font-size: var(--fs-xs); color: var(--color-text-tertiary); margin-bottom: var(--s2); }
.crumbs a { color: var(--color-text-tertiary); }
.crumbs a:hover { color: var(--color-blue); }
.page-head { margin-bottom: var(--s6); }
.head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s4); }
.head-row h1, .head-row h2 { margin: 0; }
.subtitulo { color: var(--color-text-secondary); font-size: var(--fs-sm); margin: var(--s1) 0 var(--s5); max-width: 70ch; }
.section-title { font-size: var(--fs-2xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-tertiary); margin: var(--s6) 0 var(--s3); }
.muted { color: var(--color-text-secondary); }
.dim { color: var(--color-text-tertiary); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--color-text-secondary); }
code { font-family: var(--font-mono); font-size: 0.84em; background: var(--color-bg-subtle); border: 1px solid var(--color-border-soft); padding: 1px 5px; border-radius: var(--r-sm); }

/* ----------------------- cards ----------------------- */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-md); padding: var(--s6); margin-bottom: var(--s5);
}
.card.compact { padding: var(--s4) var(--s5); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--color-border-soft); }
.card-head h3 { margin: 0; }
.card-head .count { font-size: var(--fs-sm); color: var(--color-text-tertiary); font-variant-numeric: tabular-nums; }
/* overflow-x:auto → en mobile las data-tables anchas se scrollean horizontalmente en vez de cortar
   columnas (antes `overflow:hidden` las clipeaba y quedaban inalcanzables). overflow-y:hidden mantiene
   el clip del border-radius arriba/abajo. */
.tabla-card { padding: 0; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }

/* stat / metric cards */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--s4); margin-bottom: var(--s6); }
.metric {
  display: flex; flex-direction: column; gap: var(--s1);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-md); padding: var(--s5);
  transition: border-color 120ms ease, background-color 120ms ease;
}
.metric:hover { border-color: var(--color-border-strong); background: var(--color-surface); text-decoration: none; }
.metric .l { color: var(--color-text-tertiary); font-size: var(--fs-2xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.07em; order: -1; }
.metric .n { font-size: 1.75rem; font-weight: 600; color: var(--color-text-primary); line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.metric .sub { font-size: var(--fs-xs); color: var(--color-text-tertiary); }

/* ----------------------- listas de definición ----------------------- */
dl.kv { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: var(--s2) var(--s6); margin: 0; }
dl.kv dt { color: var(--color-text-tertiary); font-size: var(--fs-sm); font-weight: 500; }
dl.kv dd { margin: 0; color: var(--color-text-primary); }

/* ----------------------- tablas ----------------------- */
table { width: 100%; border-collapse: collapse; font-size: var(--fs-body); }
table thead th {
  text-align: left; font-weight: 650; font-size: var(--fs-2xs);
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-tertiary);
  background: var(--color-bg-subtle); padding: var(--s3); border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
table tbody td { padding: var(--s3); border-bottom: 1px solid var(--color-border-soft); color: var(--color-text-primary); vertical-align: top; }
table tbody tr { transition: background-color 90ms ease; }
table tbody tr:hover { background: var(--color-bg-subtle); }
table tbody tr:last-child td { border-bottom: none; }
table tbody td.num, table thead th.num { text-align: right; font-variant-numeric: tabular-nums; }
table tbody td a { font-weight: 500; }
.vacio { color: var(--color-text-tertiary); font-style: italic; padding: var(--s5) var(--s3); }
.empty-state { text-align: center; padding: var(--s10) var(--s6); }
.empty-state h3 { color: var(--color-text-secondary); margin-bottom: var(--s1); }
.empty-state p { color: var(--color-text-tertiary); margin-bottom: var(--s4); }

/* ----------------------- botones ----------------------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  font-family: inherit; font-size: var(--fs-body); font-weight: 550; line-height: 1.2;
  padding: 8px 16px; border-radius: var(--r-sm); cursor: pointer; white-space: nowrap;
  background: var(--color-surface); color: var(--color-text-primary); border: 1px solid var(--color-border);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover { background: var(--color-bg-subtle); border-color: var(--color-border-strong); text-decoration: none; }
.btn:active { background: var(--color-bg-muted); }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--color-bg-muted); color: var(--color-text-tertiary); border-color: var(--color-border); cursor: not-allowed; }
.btn-primary { background: var(--color-green); border-color: var(--color-green); color: var(--color-text-inverse); }
.btn-primary:hover { background: var(--color-green-hover); border-color: var(--color-green-hover); }
.btn-primary:active { background: var(--color-green-active); border-color: var(--color-green-active); }
.btn-secondary { background: transparent; color: var(--color-blue); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-blue-soft); border-color: var(--color-blue); }
.btn-ghost { background: transparent; border-color: transparent; font-weight: 500; color: var(--color-text-secondary); }
.btn-ghost:hover { background: var(--color-bg-subtle); color: var(--color-text-primary); border-color: transparent; }
.btn-danger { background: var(--color-surface); border-color: var(--color-border); color: var(--color-red); }
.btn-danger:hover { background: var(--color-red-soft); border-color: var(--color-red); }
.btn-sm { padding: 5px 11px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.acciones { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.acciones form { display: inline; margin: 0; }

/* ----------------------- formularios ----------------------- */
.form-field { margin-bottom: var(--s4); }
.form-field > label { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--color-text-secondary); margin-bottom: 5px; }
.form-field > label .req { color: var(--color-red); font-weight: 600; }
.form-field input[type="text"], .form-field input[type="number"], .form-field input[type="date"],
.form-field input[type="time"], .form-field input[type="email"], .form-field input[type="search"],
.form-field input[type="password"], .form-field input[type="tel"],
.form-field select, .form-field textarea {
  width: 100%; max-width: 480px; padding: 8px 11px; font-family: inherit; font-size: var(--fs-body); line-height: 1.45;
  background: var(--color-surface); color: var(--color-text-primary);
  border: 1px solid var(--color-border-strong); border-radius: var(--r-sm);
  transition: border-color 120ms ease, background-color 120ms ease;
}
.form-field textarea { min-height: 86px; resize: vertical; }
.form-field input:hover:not(:disabled), .form-field select:hover:not(:disabled), .form-field textarea:hover:not(:disabled) { border-color: var(--color-text-tertiary); }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: var(--color-green); outline: none; box-shadow: 0 0 0 1px var(--color-green); }
.form-field input:disabled, .form-field select:disabled, .form-field textarea:disabled { background: var(--color-bg-muted); color: var(--color-text-tertiary); border-color: var(--color-border); }
.form-field input::placeholder, .form-field textarea::placeholder { color: var(--color-text-tertiary); }
.form-field input.full, .form-field select.full, .form-field textarea.full { max-width: none; }
.form-field input[type="checkbox"] { width: 16px; height: 16px; max-width: none; vertical-align: -2px; accent-color: var(--color-green); margin-right: 6px; }
.form-field .hint { font-size: var(--fs-xs); color: var(--color-text-tertiary); margin-top: 5px; }
.form-row { display: flex; gap: var(--s4); flex-wrap: wrap; }
.form-row > .form-field { flex: 1; min-width: 180px; }
.form-actions { display: flex; gap: var(--s2); align-items: center; margin-top: var(--s5); padding-top: var(--s5); border-top: 1px solid var(--color-border-soft); }
select { appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--color-text-secondary) 50%), linear-gradient(135deg, var(--color-text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 15px) center, calc(100% - 10px) center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  padding-right: 30px !important;
}

/* ----------------------- badges / pills de estado ----------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px 2px 7px; border-radius: var(--r-pill);
  font-size: var(--fs-2xs); font-weight: 650; letter-spacing: 0.02em; line-height: 1.6; white-space: nowrap;
  background: var(--color-slate-soft); color: var(--color-slate-text);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-verde    { background: var(--color-green-soft); color: var(--color-green-text); }
.badge-amarillo { background: var(--color-amber-soft); color: var(--color-amber-text); }
.badge-rojo     { background: var(--color-red-soft);   color: var(--color-red-text); }
.tag { display: inline-block; padding: 1px 7px; border-radius: var(--r-sm); font-size: var(--fs-xs); background: var(--color-bg-subtle); border: 1px solid var(--color-border-soft); color: var(--color-text-secondary); }

/* ----------------------- alertas ----------------------- */
.alert { border-radius: var(--r-md); padding: var(--s3) var(--s4); margin-bottom: var(--s5); font-size: var(--fs-sm); border: 1px solid; line-height: 1.5; }
.alert strong { font-weight: 650; }
.alert ul { margin: var(--s2) 0 0; padding-left: 18px; }
.alert-error { background: var(--color-red-soft);   border-color: var(--color-red);   color: var(--color-red-text); }
.alert-ok    { background: var(--color-green-soft); border-color: var(--color-green); color: var(--color-green-text); }
.alert-info  { background: var(--color-blue-soft);  border-color: var(--color-blue);  color: var(--color-blue-text); }

/* ----------------------- paginación / toolbar / filtros ----------------------- */
.pager { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s4); font-size: var(--fs-sm); color: var(--color-text-tertiary); }
.pager .info { font-variant-numeric: tabular-nums; }
.pager a { padding: 5px 11px; border: 1px solid var(--color-border); border-radius: var(--r-sm); background: var(--color-surface); color: var(--color-text-primary); font-weight: 500; }
.pager a:hover { background: var(--color-bg-subtle); border-color: var(--color-border-strong); text-decoration: none; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s3); flex-wrap: wrap; }
.filtros { display: flex; gap: var(--s3); align-items: flex-end; flex-wrap: wrap; margin-bottom: var(--s4); padding: var(--s4); background: var(--color-surface); border: 1px solid var(--color-border-soft); border-radius: var(--r-md); }
.filtros .form-field { margin-bottom: 0; }
.filtros label { margin-bottom: 4px; font-size: var(--fs-xs); }
.filtros input, .filtros select { max-width: 220px; padding: 6px 10px; }

/* ----------------------- previsualización de etiqueta ----------------------- */
.etiqueta-preview {
  border: 1px dashed var(--color-border-strong); background: var(--color-surface);
  border-radius: var(--r-md); padding: var(--s5); max-width: 420px; margin: var(--s2) 0 0;
  background-image: repeating-linear-gradient(45deg, transparent, transparent 9px, rgba(0,0,0,.012) 9px, rgba(0,0,0,.012) 10px);
}
.etiqueta-preview .lbl h1 { font-size: 1.0625rem; font-weight: 650; margin: 0 0 var(--s1); letter-spacing: -0.01em; }
.etiqueta-preview .lbl h2 { font-size: var(--fs-sm); font-weight: 400; color: var(--color-text-secondary); margin: 0 0 var(--s2); letter-spacing: 0; text-transform: none; }
.etiqueta-preview .lbl p { margin: 3px 0; }
.etiqueta-preview img { max-height: 24px; }

/* ----------------------- pasos del flujo (home) ----------------------- */
.flow { display: grid; gap: var(--s2); counter-reset: paso; margin: 0; padding: 0; list-style: none; }
.flow li { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s2) 0; }
.flow li::before { counter-increment: paso; content: counter(paso); flex: 0 0 24px; width: 24px; height: 24px; border-radius: 50%; background: var(--color-bg-subtle); color: var(--color-text-secondary); font-size: var(--fs-xs); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.flow li .t { font-weight: 600; }
.flow li .d { color: var(--color-text-secondary); font-size: var(--fs-sm); }
.flow li.pendiente::before { background: var(--color-amber-soft); color: var(--color-amber-text); }

/* ----------------------- modo oscuro -----------------------
   Variables compartidas por el modo oscuro: aplican cuando el usuario eligió
   "oscuro" (data-theme="dark") o cuando el SO está en oscuro y no forzó "claro".
*/
:root[data-theme="dark"],
:root[data-theme="auto"] { color-scheme: light dark; }
:root[data-theme="dark"] {
  --color-canvas:#0f1115; --color-surface:#181b20; --color-bg-subtle:#20242b; --color-bg-muted:#2a2f37;
  --color-border:#2d333b; --color-border-soft:#262b33; --color-border-strong:#3b424b;
  --color-text-primary:#e7eaed; --color-text-secondary:#a4abb3; --color-text-tertiary:#7c848c; --color-text-inverse:#0f1115;
  --color-green:#10b981; --color-green-hover:#34d399; --color-green-active:#0ea372; --color-green-soft:#0e2a22; --color-green-line:#1f5a44; --color-green-text:#6ee7b7;
  --color-blue:#38bdf8; --color-blue-hover:#5cc8f9; --color-blue-soft:#0b2433; --color-blue-text:#7dd3fc;
  --color-red:#f87171; --color-red-hover:#fb8b8b; --color-red-soft:#2a1515; --color-red-text:#fca5a5;
  --color-amber:#d8a23f; --color-amber-soft:#2b2110; --color-amber-text:#f0c97e;
  --color-slate-soft:#20242b; --color-slate-text:#a4abb3;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-canvas:#0f1115; --color-surface:#181b20; --color-bg-subtle:#20242b; --color-bg-muted:#2a2f37;
    --color-border:#2d333b; --color-border-soft:#262b33; --color-border-strong:#3b424b;
    --color-text-primary:#e7eaed; --color-text-secondary:#a4abb3; --color-text-tertiary:#7c848c; --color-text-inverse:#0f1115;
    --color-green:#10b981; --color-green-hover:#34d399; --color-green-active:#0ea372; --color-green-soft:#0e2a22; --color-green-line:#1f5a44; --color-green-text:#6ee7b7;
    --color-blue:#38bdf8; --color-blue-hover:#5cc8f9; --color-blue-soft:#0b2433; --color-blue-text:#7dd3fc;
    --color-red:#f87171; --color-red-hover:#fb8b8b; --color-red-soft:#2a1515; --color-red-text:#fca5a5;
    --color-amber:#d8a23f; --color-amber-soft:#2b2110; --color-amber-text:#f0c97e;
    --color-slate-soft:#20242b; --color-slate-text:#a4abb3;
  }
}

/* =================================================================
   Capa premium — añadida 2026-05-14
   Bandeja de Tareas, hero, chips, popovers, role pills, notif dot.
   ================================================================= */

/* Hero del page-head para la bandeja y el dashboard */
.page-head-hero {
  display: grid; grid-template-columns: 1fr auto; gap: var(--s6);
  align-items: end;
  padding: var(--s6) var(--s6);
  background:
    radial-gradient(1200px 200px at -10% -50%, rgba(6,150,105,.08), transparent 60%),
    linear-gradient(180deg, var(--color-surface) 0%, var(--color-bg-subtle) 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--r-lg);
  margin-bottom: var(--s6);
}
.page-head-hero .kicker {
  display: inline-block; font-size: var(--fs-2xs); font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--color-green-text); background: var(--color-green-soft);
  padding: 3px 10px; border-radius: var(--r-pill); margin-bottom: var(--s2);
}
.page-head-hero h1 { font-size: 1.875rem; margin: 0; }
.page-head-hero .subtitulo { margin: var(--s2) 0 0; }
.hero-stats { display: flex; gap: var(--s3); }
.hero-stats .stat {
  min-width: 110px; padding: var(--s3) var(--s4);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-md); display: flex; flex-direction: column; gap: 2px;
}
.hero-stats .stat .n { font-size: 1.625rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-stats .stat .l { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-tertiary); }
.hero-stats .stat-urgente { border-color: var(--color-red); }
.hero-stats .stat-urgente .n { color: var(--color-red); }
.hero-stats .stat-alta { border-color: var(--color-amber); }
.hero-stats .stat-alta .n { color: var(--color-amber); }
.hero-stats .stat-total .n { color: var(--color-green); }
.page-head-hero .hero-actions { margin-top: var(--s3); }
.req-card-trace { margin-top: var(--s1); }
.req-tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--color-border); margin-bottom: var(--s4); }
.req-tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: var(--s2) var(--s3); font: inherit; font-weight: 600; color: var(--color-text-tertiary); cursor: pointer; }
.req-tab.on { color: var(--color-text-primary); border-bottom-color: var(--color-green); }

@media (max-width: 720px) {
  .page-head-hero { grid-template-columns: 1fr; }
  .hero-stats { flex-wrap: wrap; }
}

/* Barra de filtros */
.filtros-bar {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-md); padding: var(--s4); margin-bottom: var(--s5);
  display: flex; flex-direction: column; gap: var(--s3);
}
.filtros-buscar { display: flex; gap: var(--s2); align-items: center; }
.filtros-buscar input[type=search] {
  flex: 1; min-width: 0; padding: 8px 12px; border: 1px solid var(--color-border);
  border-radius: var(--r-sm); font: inherit; background: var(--color-surface); color: var(--color-text-primary);
}
.filtros-buscar input[type=search]:focus { outline: 2px solid var(--color-green); outline-offset: 1px; }
.filtros-chips { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.chips-label { font-size: var(--fs-xs); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 650; margin-right: var(--s1); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-pill);
  background: var(--color-bg-subtle); border: 1px solid var(--color-border-soft);
  font-size: var(--fs-sm); color: var(--color-text-secondary);
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.chip:hover { text-decoration: none; background: #fff; color: var(--color-text-primary); border-color: var(--color-border); }
.chip em { font-style: normal; font-variant-numeric: tabular-nums; color: var(--color-text-tertiary); font-size: var(--fs-2xs); padding: 1px 6px; background: rgba(0,0,0,0.04); border-radius: var(--r-pill); }
.chip.on { background: var(--color-green-soft); color: var(--color-green-text); border-color: var(--color-green-line); font-weight: 600; }
.chip.on em { background: rgba(6,150,105,0.18); color: var(--color-green-text); }
.chip-prio-urgente.on { background: var(--color-red-soft); color: var(--color-red-text); border-color: var(--color-red); }
.chip-prio-alta.on { background: var(--color-amber-soft); color: var(--color-amber-text); border-color: var(--color-amber); }

/* Grid de tareas */
.tareas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--s4); }
.tarea-card {
  display: block; padding: var(--s5); background: var(--color-surface);
  border: 1px solid var(--color-border); border-left: 4px solid var(--color-border-strong);
  border-radius: var(--r-md);
  transition: transform 120ms ease, box-shadow 160ms ease, border-color 120ms ease;
}
.tarea-card:hover {
  text-decoration: none; transform: translateY(-1px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.02), 0 8px 20px -8px rgba(15,23,42,0.12);
  border-color: var(--color-green-line);
}
.tarea-prio-urgente { border-left-color: var(--color-red); }
.tarea-prio-alta    { border-left-color: var(--color-amber); }
.tarea-prio-media   { border-left-color: var(--color-blue); }
.tarea-prio-baja    { border-left-color: var(--color-border-strong); }
.tarea-card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); }
.tarea-cat { font-size: var(--fs-2xs); font-weight: 700; padding: 3px 8px; border-radius: var(--r-pill); background: var(--color-bg-subtle); color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.06em; }
.tarea-prio { font-size: var(--fs-2xs); font-weight: 700; padding: 3px 8px; border-radius: var(--r-pill); text-transform: uppercase; letter-spacing: 0.06em; }
.prio-urgente { background: var(--color-red-soft); color: var(--color-red-text); }
.prio-alta    { background: var(--color-amber-soft); color: var(--color-amber-text); }
.prio-media   { background: var(--color-blue-soft); color: var(--color-blue-text); }
.prio-baja    { background: var(--color-bg-subtle); color: var(--color-text-tertiary); }
.tarea-titulo { font-size: 1.0625rem; margin: 0 0 var(--s1); color: var(--color-text-primary); font-weight: 650; }
.tarea-desc { font-size: var(--fs-sm); color: var(--color-text-secondary); margin: 0 0 var(--s3); }
.tarea-meta { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); font-size: var(--fs-xs); color: var(--color-text-tertiary); }
.meta-item { display: inline-flex; align-items: center; gap: 4px; }
.meta-fecha { color: var(--color-text-secondary); font-variant-numeric: tabular-nums; }
.meta-sla   { color: var(--color-amber-text); }

/* Categorías — color de chip */
.chip-cat-planificacion { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.chip-cat-aprobacion    { background: #f5f3ff; color: #5b21b6; border-color: #ddd6fe; }
.chip-cat-consolidacion { background: #ecfeff; color: #155e75; border-color: #a5f3fc; }
.chip-cat-etiquetado    { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.chip-cat-despacho      { background: #ecfdf5; color: #065f46; border-color: #a7e3cb; }
.chip-cat-diseno        { background: #fdf2f8; color: #9d174d; border-color: #fbcfe8; }
.chip-cat-maestro       { background: #f1f5f9; color: #334155; border-color: #cbd5e1; }

/* Empty state */
.empty-state { text-align: center; padding: var(--s12) var(--s6); }
.empty-state .empty-mark { width: 56px; height: 56px; margin: 0 auto var(--s4); border-radius: 50%; background: var(--color-green-soft); color: var(--color-green); display: inline-flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 700; }
.empty-state h3 { font-size: 1.125rem; margin: 0 0 var(--s2); }
.empty-state p  { color: var(--color-text-secondary); max-width: 50ch; margin: 0 auto var(--s4); }

/* Header: cliente en contexto (botón KAM global). Hidden por default; lo muestra
   shell.js cuando setClientContext() recibe un cliente desde la page actual. */
.kam-ctx-btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  height: 32px; padding: 0 var(--s3);
  border: 1px solid var(--color-border); border-radius: var(--r-sm);
  background: var(--color-surface); color: var(--color-text-primary);
  cursor: pointer; font-size: var(--fs-sm); font-weight: 500;
  max-width: 280px;
}
.kam-ctx-btn:hover { background: var(--color-bg-subtle); }
.kam-ctx-btn[hidden] { display: none; }
.kam-ctx-icon { line-height: 1; }
.kam-ctx-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kam-ctx-name { font-weight: 600; }
@media (max-width: 720px) {
  /* Tap targets cómodos en touch (iOS HIG ≥44px): chips de filtro/categoría y botones chicos eran
     difíciles de tocar (~20-28px). .chip/.btn ya son inline-flex centrados → min-height agranda el área
     sin romper layout. */
  .chip, .btn-sm { min-height: 40px; }
  .btn { min-height: 44px; }
  .kam-ctx-btn .kam-ctx-label { display: none; }
  .kam-ctx-btn { padding: 0; width: 32px; justify-content: center; }
}

/* ----------------------- breakpoint táctil global (≤1079) ----------------------- */
/* Design rationale: tablets y teléfonos en horizontal (≈1024-1080) son dispositivos táctiles y el menú
   ya pasa a drawer a 1023px → tratamos toda esa franja como "pantalla chica/táctil". form-field y filtros
   son las definiciones ÚNICAS de inputs reusadas por todas las vistas (mismo diseño), así que un solo
   bloque las cubre a todas. Inputs a ancho completo (se quita el cap de 480px de escritorio) y la barra de
   filtros (inputs capados a 220px → apretados en touch) pasa a columna full-width. */
@media (max-width: 1079px) {
  /* input[type] (0,2,1) empata la especificidad del cap de escritorio .form-field input[type="text"]
     y, al ir después, gana — cubriendo todos los tipos sin repetir la lista ni usar !important. */
  .form-field input[type], .form-field select, .form-field textarea { max-width: none; }
  .filtros { flex-direction: column; align-items: stretch; }
  .filtros .form-field { width: 100%; }
  .filtros input[type], .filtros select { max-width: none; }
}

/* Header: icon-btn, popovers, notif dot */
.icon-btn {
  position: relative; width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--color-border); border-radius: var(--r-sm);
  background: var(--color-surface); color: var(--color-text-secondary);
  cursor: pointer; padding: 0; font-size: 14px;
}
.icon-btn:hover { background: var(--color-bg-subtle); color: var(--color-text-primary); }
.icon-glyph { line-height: 1; }
.notif-dot { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--color-red); border: 2px solid var(--color-surface); }

.header-menu { position: relative; }
.header-menu > summary { list-style: none; cursor: pointer; }
.header-menu > summary::-webkit-details-marker { display: none; }
.header-menu[open] > summary .user-chip,
.header-menu[open] > summary.icon-btn { background: var(--color-bg-subtle); }

.popover {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 320px; max-width: 380px;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  box-shadow: 0 10px 30px -10px rgba(15,23,42,0.18), 0 2px 6px -2px rgba(15,23,42,0.06);
  padding: var(--s2); z-index: 30;
}
.popover-right { right: 0; }
/* Referencia a cliente con menú inline (reusa .popover/.popover-row del navbar). El popover ancla a la
   izquierda del nombre (no right:0 como el navbar) y es más angosto para listas/tablas. */
.client-ref { position: relative; display: inline-block; }
.client-ref > summary { list-style: none; cursor: pointer; color: var(--color-green-text); }
.client-ref > summary::-webkit-details-marker { display: none; }
.client-ref > summary:hover { text-decoration: underline; }
.client-ref[open] > summary { font-weight: 600; }
.client-ref .popover { right: auto; left: 0; min-width: 220px; max-width: 300px; }
/* Cabecera de identidad del panel de usuario: nombre + cargo siempre visibles (clave en mobile,
   donde el chip del header oculta .who). */
.popover-id { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3) var(--s3); border-bottom: 1px solid var(--color-border-soft); margin-bottom: var(--s1); }
.popover-id .avatar-lg { width: 36px; height: 36px; border-radius: 50%; flex: 0 0 36px; display: inline-flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--color-green), #047857); color: #fff; font-weight: 700; font-size: 13px; }
.popover-id .row-text { display: flex; flex-direction: column; min-width: 0; }
.popover-id .row-text b { font-weight: 650; }
.popover-id .row-text .muted { font-size: var(--fs-xs); color: var(--color-text-tertiary); }
.popover-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--color-border-soft); margin-bottom: var(--s1); }
.popover-head .muted { font-size: var(--fs-xs); }
.popover-row {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s2) var(--s3); border-radius: var(--r-sm);
  color: var(--color-text-primary);
}
.popover-row:hover { background: var(--color-bg-subtle); text-decoration: none; }
.popover-row.on { background: var(--color-green-soft); }
.popover-row .row-text { display: flex; flex-direction: column; }
.popover-row .row-text b { font-weight: 600; }
.popover-row .row-text .muted { font-size: var(--fs-xs); }
.popover-row .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: 0 0 10px; }
.dot-urgente { background: var(--color-red); }
.dot-media   { background: var(--color-blue); }
.popover-empty { padding: var(--s5); text-align: center; color: var(--color-text-secondary); font-size: var(--fs-sm); }
.popover-foot { display: block; padding: var(--s2) var(--s3); border-top: 1px solid var(--color-border-soft); margin-top: var(--s1); font-size: var(--fs-sm); color: var(--color-green-text); text-align: center; }
.popover-foot.muted { color: var(--color-text-tertiary); font-size: var(--fs-xs); text-align: center; }

/* Iniciales con color por rol */
.rol-mark { width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; flex: 0 0 24px; }
.rol-admin        { background: #475569; }
.rol-gerente      { background: #7c3aed; }
.rol-vendedor     { background: #0369a1; }
.rol-gestor_rutas { background: #059669; }
.rol-empaquetador { background: #ca8a04; }
.rol-despachador  { background: #b45309; }

.rol-pill {
  display: inline-block; padding: 3px 10px; border-radius: var(--r-pill);
  font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: #fff; margin-bottom: var(--s2);
}
.rol-pill.rol-admin        { background: #475569; }
.rol-pill.rol-gerente      { background: #7c3aed; }
.rol-pill.rol-vendedor     { background: #0369a1; }
.rol-pill.rol-gestor_rutas { background: #059669; }
.rol-pill.rol-empaquetador { background: #ca8a04; }
.rol-pill.rol-despachador  { background: #b45309; }

/* Sidebar: iconos + badges */
.nav-icon { width: 18px; display: inline-block; text-align: center; color: var(--color-text-tertiary); font-size: 13px; }
.app-nav-item.activo .nav-icon { color: var(--color-green); }
.nav-label { flex: 1; }
.nav-badge {
  min-width: 20px; padding: 1px 6px; border-radius: var(--r-pill);
  background: var(--color-bg-muted); color: var(--color-text-secondary);
  font-size: var(--fs-2xs); font-weight: 700; text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav-badge.badge-urgente { background: var(--color-red); color: #fff; }

/* Avatar premium en user-chip */
.user-chip .avatar { background: linear-gradient(135deg, var(--color-green), #047857); color: #fff; font-weight: 700; }
/* Chip de EMPRESA (scope): cuadrado redondeado neutro con ícono de edificio, para que NO se confunda
   con el avatar redondo verde de la persona/rol (eran dos chips casi idénticos en el header). */
.user-chip.scope-chip .avatar.avatar-empresa { background: var(--color-bg-muted); border-radius: 7px; font-size: 14px; }
.user-chip .who .muted { font-size: var(--fs-2xs); color: var(--color-text-tertiary); display: block; }

/* Dashboard premium: timeline operativo */
.ops-timeline { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--s2); margin: var(--s5) 0 var(--s3); }
.ops-step {
  padding: var(--s3); border: 1px solid var(--color-border); border-radius: var(--r-md);
  background: var(--color-surface); position: relative;
}
.ops-step .ops-num { font-size: var(--fs-2xs); font-weight: 700; color: var(--color-text-tertiary); }
.ops-step .ops-title { display: block; font-weight: 650; font-size: var(--fs-sm); margin-top: 2px; }
.ops-step .ops-count { display: block; font-size: 1.25rem; font-weight: 700; color: var(--color-green); font-variant-numeric: tabular-nums; margin-top: var(--s1); }
.ops-step.activa { border-color: var(--color-green); background: linear-gradient(180deg, #fff, #f6fffb); }
@media (max-width: 1100px) { .ops-timeline { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px)  { .ops-timeline { grid-template-columns: repeat(2, 1fr); } }

/* Métricas premium (extiende .metric) */
.metric { transition: transform 120ms ease, border-color 120ms ease; }
.metric:hover { transform: translateY(-1px); border-color: var(--color-green-line); }
.metric .l { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-tertiary); font-weight: 650; }
.metric .n { font-size: 1.75rem; font-weight: 700; line-height: 1.1; color: var(--color-text-primary); font-variant-numeric: tabular-nums; margin: var(--s1) 0 2px; }
.metric .sub { font-size: var(--fs-xs); color: var(--color-text-secondary); }

/* Tareas top en home */
.tareas-top { display: flex; flex-direction: column; gap: var(--s2); }
.tareas-top .tarea-mini { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r-sm); }
.tareas-top .tarea-mini:hover { background: var(--color-bg-subtle); text-decoration: none; }
.tareas-top .tarea-mini .pill { font-size: var(--fs-2xs); padding: 2px 8px; border-radius: var(--r-pill); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }

/* Print: limpio para hojas de ruta y guías */
@media print {
  .app-header, .app-sidebar, .app-footer, .filtros-bar, .tarea-card-head .tarea-prio { display: none !important; }
  .app-main { padding: 0; }
  .card, .tarea-card { box-shadow: none; border-color: #999; }
  body { background: #fff; }
}

/* ----------------- Módulo Usuarios y roles ----------------- */
.usuarios-roles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: var(--s4); }
.rol-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-md); padding: var(--s5);
  display: flex; flex-direction: column; gap: var(--s4);
}
.rol-card-head { display: grid; grid-template-columns: 40px 1fr auto; gap: var(--s3); align-items: start; }
.rol-card-head .rol-mark { width: 40px; height: 40px; font-size: 16px; }
.rol-card-title h3 { margin: 0; font-size: 1rem; }
.rol-card-title p  { margin: 2px 0 0; font-size: var(--fs-xs); line-height: 1.4; }
.rol-card-stats { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.badge-soft {
  font-size: var(--fs-2xs); font-weight: 650; padding: 2px 8px;
  background: var(--color-bg-subtle); color: var(--color-text-secondary);
  border-radius: var(--r-pill); white-space: nowrap;
}
a.badge-soft:hover { background: var(--color-green-soft); color: var(--color-green-text); text-decoration: none; }
.badge-soft.badge-urgente { background: var(--color-red-soft); color: var(--color-red-text); }
.miembros-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--s1); }
/* Flex (no grid de columnas fijas): el grid 28px/1fr/auto asumía siempre un avatar en la col 1;
   en los usos sin avatar (diseños, puntos/reglas de cliente) el .miembro-info caía en la col de 28px
   y el texto se partía una palabra por línea. Con flex, avatar (si hay) + info(flex:1) + acción fluyen. */
.miembro {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2); border-radius: var(--r-sm);
  background: var(--color-bg-subtle);
}
.avatar-sm { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--color-green), #047857); color: #fff; font-weight: 700; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; }
.miembro-info { display: flex; flex-direction: column; line-height: 1.2; flex: 1 1 auto; min-width: 0; }
.miembro-info b { font-size: var(--fs-sm); font-weight: 600; }
.miembro-info .muted { font-size: var(--fs-2xs); }
.miembro-estado { font-size: var(--fs-2xs); font-weight: 700; padding: 2px 8px; border-radius: var(--r-pill); background: var(--color-bg-muted); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; }
.miembro-estado.on { background: var(--color-green-soft); color: var(--color-green-text); }
.miembros-vacio { padding: var(--s4); text-align: center; border: 1px dashed var(--color-border); border-radius: var(--r-sm); }
.rol-card-foot { border-top: 1px solid var(--color-border-soft); padding-top: var(--s3); }
.small { font-size: var(--fs-xs); }

.rol-modulos { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding-top: var(--s2); border-top: 1px dashed var(--color-border-soft); }
.rol-modulos .chips-label { margin-right: var(--s2); }
.chip-mod { font-size: var(--fs-2xs); padding: 2px 8px; border-radius: var(--r-pill); background: var(--color-blue-soft); color: var(--color-blue-text); font-weight: 600; }

/* ----------------- Módulo Bodega ----------------- */
.view-toggle { display: inline-flex; gap: 4px; padding: 4px; background: var(--color-bg-subtle); border: 1px solid var(--color-border); border-radius: var(--r-md); margin-bottom: var(--s4); }
.view-toggle button[aria-pressed="true"] { background: var(--color-surface); color: var(--color-text-primary); border-color: var(--color-border); }
.hidden { display: none !important; }
.bodega-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s4); }
.prod-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-md); padding: var(--s4); display: flex; flex-direction: column; gap: var(--s2); transition: transform 120ms ease, border-color 120ms ease; }
.prod-card:hover { transform: translateY(-1px); border-color: var(--color-green-line); }
.prod-card.prod-alerta { border-left: 4px solid var(--color-amber); }
.prod-card.prod-sin-stock { border-left: 4px solid var(--color-red); }
.prod-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.prod-cat { font-size: var(--fs-2xs); font-weight: 700; padding: 2px 8px; border-radius: var(--r-pill); text-transform: uppercase; letter-spacing: 0.06em; }
.prod-sku { font-size: var(--fs-2xs); color: var(--color-text-tertiary); }
.prod-nombre { margin: 0; font-size: 1rem; font-weight: 650; }
.prod-desc { margin: 0; font-size: var(--fs-xs); color: var(--color-text-secondary); line-height: 1.45; }
.prod-precio { font-size: 1.25rem; font-weight: 700; color: var(--color-text-primary); font-variant-numeric: tabular-nums; }
.prod-stock { padding-top: var(--s2); border-top: 1px dashed var(--color-border-soft); display: flex; flex-direction: column; gap: 6px; }
.stock-row { display: flex; align-items: baseline; justify-content: space-between; }
.stock-label { font-size: var(--fs-xs); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 650; }
.stock-value { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stock-bar { height: 6px; background: var(--color-bg-muted); border-radius: var(--r-pill); overflow: hidden; }
.stock-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--color-green), #34d399); transition: width 200ms ease; }
.prod-alerta .stock-bar > span { background: linear-gradient(90deg, var(--color-amber), #f4b452); }
.prod-sin-stock .stock-bar > span { background: var(--color-red); }
.stock-meta { font-size: var(--fs-xs); }

/* Compensación dentro de bnx-data-grid: respetar paleta */
bnx-data-grid { display: block; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-md); padding: var(--s2); }

/* ----------------- Módulo Empaque ----------------- */
.ruta-empaque { margin-bottom: var(--s5); }
.ruta-empaque-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; padding-bottom: var(--s4); border-bottom: 1px solid var(--color-border-soft); margin-bottom: var(--s4); }
.ruta-fecha { font-size: var(--fs-xs); font-weight: 700; color: var(--color-green-text); background: var(--color-green-soft); padding: 2px 10px; border-radius: var(--r-pill); display: inline-block; margin-bottom: 4px; letter-spacing: 0.04em; }
.ruta-nombre { font-size: 1.125rem; margin: 0 0 var(--s1); }
.ruta-meta { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; font-size: var(--fs-sm); }
.ruta-progreso { display: flex; align-items: center; gap: var(--s2); min-width: 200px; }
.progreso-bar { flex: 1; height: 8px; background: var(--color-bg-muted); border-radius: var(--r-pill); overflow: hidden; }
.progreso-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--color-green), #34d399); transition: width 200ms ease; }
.progreso-pct { font-size: var(--fs-sm); font-weight: 700; color: var(--color-green-text); font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; }

.cajas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: var(--s3); }
.caja-card { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s4); background: var(--color-surface); border: 1px solid var(--color-border); border-left: 4px solid var(--color-amber); border-radius: var(--r-md); transition: border-color 120ms ease, transform 120ms ease; }
.caja-card:hover { transform: translateY(-1px); }
.caja-card.lista { border-left-color: var(--color-green); opacity: 0.85; background: linear-gradient(180deg, #f9fefb, #f4fbf7); }
.caja-head { display: flex; align-items: center; gap: var(--s2); justify-content: space-between; }
.caja-num { font-size: 1.25rem; font-weight: 700; color: var(--color-text-primary); }
.caja-parada { font-size: var(--fs-xs); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 650; }
.caja-estado { font-size: var(--fs-2xs); font-weight: 700; padding: 3px 10px; border-radius: var(--r-pill); text-transform: uppercase; letter-spacing: 0.06em; }
.caja-estado.lista { background: var(--color-green-soft); color: var(--color-green-text); }
.caja-estado.pendiente { background: var(--color-amber-soft); color: var(--color-amber-text); }
.caja-cliente { display: flex; flex-direction: column; gap: 2px; }
.caja-cliente b { font-size: var(--fs-body); }
.caja-direccion { line-height: 1.3; }
.caja-productos { display: flex; align-items: baseline; justify-content: space-between; padding: var(--s2) 0; border-top: 1px dashed var(--color-border-soft); border-bottom: 1px dashed var(--color-border-soft); }
.caja-productos strong { font-size: 1.0625rem; }
.caja-exclusiones, .caja-instr { padding: var(--s2); border-radius: var(--r-sm); font-size: var(--fs-xs); }
.caja-exclusiones { background: var(--color-amber-soft); color: var(--color-amber-text); border: 1px solid #f4d29a; }
.caja-exclusiones ul { margin: var(--s1) 0 0; padding-left: var(--s4); }
.caja-exclusiones li { font-weight: 600; }
.caja-instr { background: var(--color-blue-soft); color: var(--color-blue-text); border: 1px solid #b0d8f0; }
.caja-instr p { margin: var(--s1) 0 0; }
.caja-tag { display: inline-block; font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.caja-tag.warn { color: var(--color-amber-text); }
.caja-tag.info { color: var(--color-blue-text); }
.caja-notas { font-size: var(--fs-xs); padding: 4px 0; }
.caja-foot { display: flex; justify-content: flex-end; padding-top: var(--s2); border-top: 1px solid var(--color-border-soft); }

/* Requerimientos operativos en la caja de empaque (F2): tipificaciones dirigidas al etiquetador,
   resaltadas y con efecto. suppress_label ("solo guías") tiñe la caja y bloquea la impresión. */
.caja-reqs { display: flex; flex-direction: column; gap: var(--s1); }
.caja-req { padding: var(--s2); border-radius: var(--r-sm); font-size: var(--fs-xs); border: 1px solid var(--color-border-soft); line-height: 1.35; }
.caja-req.is-warn { background: var(--color-amber-soft); color: var(--color-amber-text); border-color: #f4d29a; }
.caja-req.is-info { background: var(--color-blue-soft); color: var(--color-blue-text); border-color: #b0d8f0; }
.caja-req.is-suppress { background: var(--color-red-soft); color: var(--color-red-text); border-color: #f0c0bc; font-weight: 650; }
.caja-card.suppress { border-left-color: var(--color-red); }

/* Tirilla "chiquita": las cajas a armar en modo compacto. El operador de etiquetas ve su tirilla pequeña
   y al SELECCIONAR una caja se abre el aside con el detalle (mismo componente que empaque). El estado
   .selected resalta SIN cambiar dimensiones (box-shadow inset + fondo), así la altura de las otras cajas
   del grid no se mueve. Solo aplica a la tirilla (modificador tir-mini), no a la grilla de empaque. */
.cajas-grid.tir-mini { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s2); }
.cajas-grid.tir-mini .caja-card { padding: var(--s2) var(--s3); gap: 2px; cursor: pointer; }
.cajas-grid.tir-mini .caja-num { font-size: 1rem; }
.cajas-grid.tir-mini .caja-cliente b { font-size: 0.8125rem; }
.cajas-grid.tir-mini .caja-direccion { font-size: var(--fs-2xs); }
.cajas-grid.tir-mini .caja-productos { padding: 3px 0; border-top: none; }
.cajas-grid.tir-mini .caja-productos strong { font-size: 0.9375rem; }
.cajas-grid.tir-mini .caja-card.selected { background: var(--color-amber-soft); box-shadow: inset 0 0 0 2px var(--color-amber); }

/* Tirilla: paneles colapsables (details) con contenido scrollable, para que la vista no sea un muro largo.
   Mismo patrón que "Documento de ruta": click en el título expande/colapsa; la lista hace scroll adentro.
   El triángulo ▸ reemplaza el marcador nativo del <summary>. */
.tir-scroll { max-height: 44vh; overflow-y: auto; overscroll-behavior: contain; }
details.tir-panel > summary { cursor: pointer; list-style: none; display: flex; align-items: baseline; gap: var(--s2); }
details.tir-panel > summary::-webkit-details-marker { display: none; }
details.tir-panel > summary::before { content: '▸'; color: var(--color-text-tertiary); transition: transform 120ms ease; align-self: center; }
details.tir-panel[open] > summary::before { transform: rotate(90deg); }

/* Totales por tipo: filas limpias (tipo → cantidad a la derecha), separadores de sección y grupos
   count_by_client (OTROS, FRUTAS INDIVIDUALES…) con sub-líneas legibles. Sin marcadores ni columnas. */
.tir-totals-list { display: flex; flex-direction: column; gap: 2px; margin-top: var(--s2); }
.tt-sep { font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; font-size: var(--fs-xs); color: var(--color-text-tertiary); margin: var(--s3) 0 2px; }
.tt-row { display: flex; align-items: baseline; gap: var(--s2); padding: 3px 0; border-bottom: 1px dashed var(--color-border-soft); }
.tt-row .tt-label { font-weight: 650; }
.tt-row .tt-qty { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.tt-grp { padding: 4px 0; border-bottom: 1px dashed var(--color-border-soft); }
.tt-grp-head { display: flex; align-items: baseline; gap: var(--s2); }
.tt-grp-head span { margin-left: auto; }
.tt-grp-lines { display: flex; flex-direction: column; gap: 1px; margin: 3px 0 0 var(--s3); }
.tt-line { font-size: var(--fs-xs); color: var(--color-text-secondary); padding: 1px 0; }
.tir-lines { margin: var(--s2) 0 0; padding-left: var(--s4); }
.tir-lines li { padding: 1px 0; }

/* Etiquetas por punto de entrega: una fila por punto (cliente · punto · Nº cajas) + chips del desglose de
   tipos. Antes iba con estilos inline y el desglose como texto plano — ahora clases + chips. */
.tir-punto-list { list-style: none; margin: var(--s2) 0 0; padding: 0; }
.tir-punto-list > li { padding: var(--s2) 0; border-bottom: 1px solid var(--color-border-soft); }
.tir-punto-list > li:last-child { border-bottom: 0; }
.tir-punto-row { display: flex; align-items: baseline; gap: var(--s2); }
.tir-punto-row .tir-punto-caja { margin-left: auto; }
.tir-punto-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tir-punto-chip { font-size: var(--fs-2xs); padding: 2px 8px; border-radius: var(--r-pill); background: var(--color-surface-alt, #f1f5f9); color: var(--color-text-secondary); white-space: nowrap; }
.tir-punto-chip b { color: var(--color-text-primary); font-weight: 700; }

/* Vista "Por cliente" de la tirilla: un panel por cliente con header limpio (nombre + punto a la
   izquierda, stats a la derecha), acento a la izquierda. Estética de las barras de resumen del día. */
.tir-cli-panel { padding: 0; overflow: hidden; border-left: 3px solid var(--color-green, #16a34a); }
.tir-cli-panel > .tir-cli-head { list-style: none; cursor: pointer; display: flex; align-items: center;
  gap: var(--s3); flex-wrap: wrap; padding: var(--s3) var(--s3) var(--s3) var(--s4); }
.tir-cli-panel > .tir-cli-head::-webkit-details-marker { display: none; }
.tir-cli-panel[open] > .tir-cli-head { border-bottom: 1px solid var(--color-border-soft); }
.tir-cli-panel > .tir-cli-head:hover { background: var(--color-surface-alt, #f8fafc); }
.tir-cli-id { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; min-width: 0; }
.tir-cli-name { font-size: 1.0625rem; font-weight: 700; color: var(--color-text-primary); }
.tir-cli-punto { white-space: nowrap; }
.tir-cli-stats { display: flex; align-items: center; gap: var(--s3); margin-left: auto; flex-wrap: wrap; }
.tir-cli-stat { font-size: var(--fs-xs); color: var(--color-text-tertiary); white-space: nowrap; }
.tir-cli-stat b { font-size: 1.0625rem; font-weight: 700; color: var(--color-text-primary); margin-right: 3px; }
.tir-cli-chips { display: flex; flex-wrap: wrap; gap: 4px; padding: var(--s2) var(--s3) 0 var(--s4); }
.tir-cli-panel > .tir-scroll { padding: var(--s2) var(--s3) var(--s3) var(--s4); }

/* Trazabilidad de requerimiento (F2 lifecycle): <details> expandible con la línea de tiempo. */
.req-trace { margin-top: var(--s1); }
.req-trace > summary { cursor: pointer; font-size: var(--fs-2xs); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; }
.req-trace-body { padding: var(--s2) 0 0; }
.req-trace-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s1); }
.req-trace-item { display: flex; gap: var(--s2); align-items: flex-start; }
.req-trace-icon { flex: 0 0 auto; width: 1.2em; text-align: center; }
.req-trace-main { display: flex; flex-direction: column; line-height: 1.3; }
.req-trace-main .block { display: block; }
.req-trace-item.stage-cancelled { opacity: 0.6; }
.req-trace-reason {
  margin: 4px 0 2px;
  padding: 4px 8px;
  border-left: 2px solid var(--color-border);
  background: var(--color-bg-subtle);
  font-size: var(--fs-xs);
  font-style: italic;
  color: var(--color-text-secondary);
  white-space: pre-wrap;
}
/* "Otras notas del mismo destino" debajo de la línea de vida de la trazabilidad. */
.req-related { margin-top: var(--s3); padding-top: var(--s2); border-top: 1px dashed var(--color-border-soft); }
.req-related-head { text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; margin-bottom: var(--s1); }
.req-related-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.req-related-item { padding: var(--s2); border: 1px solid var(--color-border-soft); border-radius: var(--r-sm); background: var(--color-bg-subtle); }
.req-related-body { font-size: var(--fs-sm); color: var(--color-text-primary); }

/* KAM notes — cards reutilizables del cliente (componente kam-notes.js). */
.kam-notes { display: flex; flex-direction: column; gap: var(--s2); }
.kam-card { padding: var(--s2) var(--s3); border: 1px solid var(--color-border); border-left: 3px solid var(--color-border); border-radius: var(--r-sm); background: var(--color-surface); }
.kam-card.is-active { border-left-color: var(--color-green); background: linear-gradient(180deg, #f9fefb, #fff); }
.kam-card-head { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; margin-bottom: var(--s1); }
.kam-card-head .kam-meta { flex: 1; }
.kam-card-body { font-size: var(--fs-sm); }
.kam-card-kinds { display: flex; gap: var(--s1); flex-wrap: wrap; margin-top: var(--s1); }
.kam-card-trace { margin-top: var(--s1); }

/* Carrusel horizontal magnético de cards KAM (aside de empaque). Cada card ocupa ~86% del ancho
   dejando un peek lateral que insinúa que hay más; scroll-snap mandatory las "engancha" al soltar. */
.kam-carousel { display: flex; flex-direction: row; flex-wrap: nowrap; gap: var(--s2);
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scroll-padding: 0 var(--s2);
  padding-bottom: 6px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.kam-carousel > .kam-card { flex: 0 0 86%; scroll-snap-align: start; min-width: 0; }
.kam-carousel > .empty-state, .kam-carousel > p { flex: 0 0 100%; }

/* Link de ruta como AFFORDANCE de edición: el nombre no es solo texto coloreado, lleva un lápiz
   (señal de "editable") y al hover toma fondo suave + subrayado, leyéndose como acción (no como link pasivo). */
.ruta-edit-link { display: inline-flex; align-items: center; gap: 5px; text-decoration: none;
  border-radius: var(--r-sm); padding: 1px 6px; margin: -1px -6px; transition: background .12s ease; }
.ruta-edit-link:hover, .ruta-edit-link:focus-visible { background: var(--color-blue-soft); text-decoration: underline; outline: none; }
.ruta-edit-ico { font-size: .8em; opacity: .5; transition: opacity .12s ease; }
.ruta-edit-link:hover .ruta-edit-ico, .ruta-edit-link:focus-visible .ruta-edit-ico { opacity: 1; }

/* ----------------- Sidebar de notas context-aware ----------------- */
.notes-toggle { position: relative; }
.notes-toggle .notes-badge { position: absolute; top: -2px; right: -2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--color-red); color: #fff; font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.notes-sidebar-panel { margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(440px, 100vw); max-width: 100vw; border: 0; border-left: 1px solid var(--color-border); border-radius: 0; padding: 0; box-shadow: -12px 0 40px -20px rgba(15,23,42,0.3); display: flex; flex-direction: column; }
.notes-sidebar-panel::backdrop { background: rgba(15,23,42,0.3); backdrop-filter: blur(1px); }
.notes-sidebar-panel .ns-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--color-border); }
.notes-sidebar-panel .ns-list { flex: 1; overflow: auto; padding: var(--s3) var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.ns-card { border: 1px solid var(--color-border); border-left: 3px solid var(--color-border); border-radius: var(--r-sm); background: var(--color-surface); padding: var(--s2) var(--s3); }
.ns-card .ns-card-top { display: flex; align-items: center; gap: var(--s2); justify-content: space-between; margin-bottom: 4px; }
.ns-card .ns-cli { font-weight: 600; }
.ns-card .ns-body { font-size: var(--fs-sm); margin: 2px 0; }
.ns-card .ns-actions { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s2); }
.ns-card .ns-reply { margin-top: var(--s2); }
.kam-btn { background: var(--color-amber-soft); color: var(--color-amber-text); border-color: #f4d29a; }
.kam-btn:hover { background: #f9e5b8; }

/* ----------------- Inputs de fecha (date picker estilizado) ----------------- */
input[type="date"], input[type="datetime-local"], input[type="time"] {
  appearance: none; -webkit-appearance: none;
  padding: 8px 36px 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  background: var(--color-surface)
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23047857' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'/><line x1='16' y1='2' x2='16' y2='6'/><line x1='8' y1='2' x2='8' y2='6'/><line x1='3' y1='10' x2='21' y2='10'/></svg>")
    no-repeat right 10px center;
  font: inherit; color: var(--color-text-primary);
  font-variant-numeric: tabular-nums;
  min-height: 38px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input[type="date"]:hover { border-color: var(--color-green-line); }
input[type="date"]:focus { outline: none; border-color: var(--color-green); box-shadow: 0 0 0 3px rgba(6,150,105,0.18); }
input[type="date"]::-webkit-calendar-picker-indicator {
  opacity: 0; cursor: pointer; position: absolute; right: 0; width: 36px; height: 100%;
}

/* ----------------- Responsive global ----------------- */
@media (max-width: 1000px) {
  .page-head-hero { padding: var(--s5); }
  .page-head-hero h1 { font-size: 1.5rem; }
  .hero-stats .stat { min-width: 90px; }
  .hero-stats .stat .n { font-size: 1.35rem; }
}
@media (max-width: 760px) {
  :root { --s8: 24px; }
  .app-main { padding: var(--s5) var(--s4) var(--s10); }
  .page-head-hero { grid-template-columns: 1fr; padding: var(--s4); }
  .hero-stats { flex-wrap: wrap; gap: var(--s2); }
  .hero-stats .stat { flex: 1 1 calc(50% - var(--s2)); min-width: 0; }
  .filtros-bar { padding: var(--s3); }
  .filtros-chips { gap: 4px; }
  .chip { font-size: var(--fs-xs); padding: 3px 8px; }
  .tareas-grid, .cajas-grid, .usuarios-roles-grid, .bodega-grid { grid-template-columns: 1fr; }
  .ruta-empaque-head { flex-direction: column; }
  .ruta-progreso { width: 100%; }
  /* right:0 + tope de ancho al viewport: los menús del header están pegados al borde derecho,
     un right negativo empujaba el popover fuera de pantalla (overflow + scroll horizontal). */
  .popover { min-width: 240px; max-width: calc(100vw - 24px); right: 0; }
  .user-chip .who { display: none; }
  .miembro { flex-wrap: wrap; }
  .miembro-estado { flex-basis: 100%; }
}
@media (max-width: 480px) {
  .app-header-inner { padding: 0 var(--s3); gap: var(--s2); }
  .icon-btn { width: 30px; height: 30px; }
  .hero-stats .stat .n { font-size: 1.2rem; }
  .app-nav-item { padding: var(--s3) var(--s3); font-size: 0.9375rem; }
  .nav-icon { width: 22px; }
}

/* ----------------- Módulo Diseños de etiqueta ----------------- */
.disenos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s3); margin-top: var(--s3); }
.diseno-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-md); padding: var(--s3); display: flex; flex-direction: column; gap: var(--s2); }
.diseno-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }
.diseno-head h4 { margin: 2px 0 0; font-size: var(--fs-body); font-weight: 650; }
.diseno-preview-mini { background: #fafafa; border: 1px solid var(--color-border-soft); border-radius: var(--r-sm); overflow: hidden; height: 200px; }
.diseno-preview-mini iframe { width: 100%; height: 100%; border: 0; pointer-events: none; }
.diseno-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); border-top: 1px solid var(--color-border-soft); padding-top: var(--s2); }
.acciones-inline { display: inline-flex; gap: 4px; }

.diseno-editor { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); margin-top: var(--s5); }
.diseno-editor .card { margin: 0; }
.diseno-form textarea { width: 100%; font-family: var(--font-mono); font-size: var(--fs-sm); border: 1px solid var(--color-border); border-radius: var(--r-sm); padding: var(--s3); resize: vertical; background: #fafbfc; }
.diseno-form textarea:focus { outline: none; border-color: var(--color-green); box-shadow: 0 0 0 3px rgba(6,150,105,0.18); background: #fff; }
.preview-frame-wrap { background: repeating-conic-gradient(#fafafa 0% 25%, #fff 0% 50%) 50% / 16px 16px; border: 1px solid var(--color-border-soft); border-radius: var(--r-sm); min-height: 340px; padding: var(--s3); display: flex; align-items: center; justify-content: center; }
.preview-frame-wrap iframe { width: 100%; min-height: 320px; border: 0; background: #fff; border-radius: var(--r-sm); box-shadow: 0 2px 12px -4px rgba(0,0,0,0.1); }
@media (max-width: 880px) {
  .diseno-editor { grid-template-columns: 1fr; }
}

/* ----------------- Módulo POS (Punto de Venta) ----------------- */
.pos-shell { display: grid; grid-template-columns: 1fr 380px; gap: var(--s4); height: calc(100vh - var(--header-h) - var(--s8) * 2); }
.pos-catalogo { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-md); padding: var(--s4); display: flex; flex-direction: column; min-height: 0; }
.pos-cat-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); flex-wrap: wrap; }
.pos-cat-head .kicker { display: block; font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.12em; color: var(--color-green-text); margin-bottom: 2px; font-weight: 700; }
.pos-cat-head h1 { margin: 0; font-size: 1.5rem; }
.pos-cat-head input[type=search] { min-width: 240px; padding: 8px 12px; border: 1px solid var(--color-border); border-radius: var(--r-sm); font: inherit; }
.pos-cat-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: var(--s3); }
.pos-cat-chips .chip { border: none; cursor: pointer; }
.pos-cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--s2); overflow: auto; padding-right: 4px; flex: 1; min-height: 0; align-content: start; }
.pos-prod { display: flex; flex-direction: column; gap: 4px; align-items: stretch; text-align: left; padding: var(--s3); border: 1px solid var(--color-border); border-radius: var(--r-md); background: var(--color-surface); color: var(--color-text-primary); cursor: pointer; transition: transform 80ms ease, border-color 120ms ease, box-shadow 120ms ease; }
.pos-prod:hover:not(:disabled) { border-color: var(--color-green); box-shadow: 0 4px 14px -6px rgba(6,150,105,0.25); transform: translateY(-1px); }
.pos-prod:active:not(:disabled) { transform: scale(0.98); }
.pos-prod.sin-stock { opacity: 0.55; cursor: not-allowed; background: var(--color-bg-subtle); }
.pos-prod.sin-stock-warn { border-color: var(--color-red); }
.pos-prod.sin-stock-warn .pos-prod-stock.agotado { color: var(--color-red); font-weight: 700; }
.pos-prod-cat { font-size: var(--fs-2xs); font-weight: 700; color: var(--color-blue-text); background: var(--color-blue-soft); padding: 2px 6px; border-radius: var(--r-pill); display: inline-block; align-self: flex-start; text-transform: uppercase; letter-spacing: 0.06em; }
.pos-prod-nombre { font-weight: 650; font-size: var(--fs-sm); line-height: 1.2; flex: 1; }
.pos-prod-precio { font-weight: 700; font-size: 1.05rem; color: var(--color-text-primary); font-variant-numeric: tabular-nums; }
.pos-prod-precio small { font-weight: 400; color: var(--color-text-tertiary); }
.pos-prod-stock { font-size: var(--fs-2xs); color: var(--color-text-tertiary); }
.pos-prod-stock.agotado { color: var(--color-red); font-weight: 700; }

.pos-carrito { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-md); padding: var(--s4); display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.pos-carrito-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s3); }
.pos-carrito-head h2 { margin: 0; }
.pos-cat-search { display: flex; align-items: center; gap: var(--s2); flex: 1; max-width: 440px; padding: 7px 14px; border: 1px solid var(--color-border); border-radius: var(--r-pill); background: var(--color-surface); }
.pos-cat-search:focus-within { border-color: var(--color-green); box-shadow: 0 0 0 3px var(--color-green-soft); }
.pos-cat-search .search-ico { color: var(--color-text-tertiary); font-size: 1.05em; }
.pos-cat-search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font: inherit; color: var(--color-text-primary); }
.pos-cliente-wrap { margin-bottom: var(--s3); }
.pos-cliente-wrap label { display: block; font-size: var(--fs-xs); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; margin-bottom: 4px; }
.pos-cliente-input { display: flex; gap: 4px; }
.pos-cliente-input input { flex: 1; padding: 8px 12px; border: 1px solid var(--color-border); border-radius: var(--r-sm); font: inherit; background: var(--color-surface); color: var(--color-text-primary); }
.pos-cliente-resultados { margin-top: 4px; border: 1px solid var(--color-border); border-radius: var(--r-sm); max-height: 200px; overflow: auto; background: var(--color-surface); color: var(--color-text-primary); }
.pos-cli-row { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--color-border-soft); }
.pos-cli-row:hover { background: var(--color-bg-subtle); }
.pos-cli-row:last-child { border-bottom: none; }
.pos-cli-vacio { padding: var(--s3); text-align: center; color: var(--color-text-secondary); font-size: var(--fs-sm); }
.pos-cliente-seleccion { margin-top: 6px; display: flex; align-items: center; gap: var(--s2); }
.pos-fila { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-bottom: var(--s3); }
.pos-fila .form-field { margin: 0; }
.pos-fila .form-field label { font-size: var(--fs-xs); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; margin-bottom: 4px; display: block; }
.pos-fila select { width: 100%; padding: 8px 12px; border: 1px solid var(--color-border); border-radius: var(--r-sm); font: inherit; min-height: 38px; }

.pos-lineas { list-style: none; padding: 0; margin: 0 0 var(--s2); display: flex; flex-direction: column; gap: 6px; }
.pos-linea { display: grid; grid-template-columns: 1fr auto auto 24px; gap: 8px; padding: 8px; background: var(--color-bg-subtle); border-radius: var(--r-sm); align-items: center; }
.pl-info { min-width: 0; display: flex; flex-direction: column; }
.pl-info b { font-size: var(--fs-sm); font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-info .muted { font-size: var(--fs-2xs); }
.pl-qty { display: inline-flex; align-items: center; gap: 2px; }
.pl-btn { width: 26px; height: 26px; border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text-primary); border-radius: var(--r-sm); cursor: pointer; font-size: 14px; line-height: 1; }
.pl-btn:hover { background: var(--color-bg-subtle); }
.pl-input { width: 50px; text-align: center; padding: 4px; border: 1px solid var(--color-border); border-radius: var(--r-sm); font: inherit; font-variant-numeric: tabular-nums; }
.pos-linea-qty { text-align: center; padding: 5px 6px; border: 1px solid var(--color-border); border-radius: var(--r-sm); font: inherit; font-variant-numeric: tabular-nums; background: var(--color-surface); color: var(--color-text-primary); }
.pos-linea-qty:focus { outline: none; border-color: var(--color-green); box-shadow: 0 0 0 3px var(--color-green-soft); }
.pl-sub { font-weight: 700; font-variant-numeric: tabular-nums; font-size: var(--fs-sm); min-width: 60px; text-align: right; }
.pl-del { width: 22px; height: 22px; border: none; background: transparent; cursor: pointer; color: var(--color-text-tertiary); font-size: 16px; }
.pl-del:hover { color: var(--color-red); }

.pos-vacio { text-align: center; padding: var(--s5); color: var(--color-text-secondary); }
.pos-total { display: flex; justify-content: space-between; align-items: baseline; padding: var(--s3) 0; border-top: 2px solid var(--color-border); margin-top: auto; }
.pos-total span { font-size: var(--fs-xs); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 650; }
.pos-total strong { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--color-green); }
.pos-obs { width: 100%; padding: 8px; border: 1px solid var(--color-border); border-radius: var(--r-sm); font: inherit; font-size: var(--fs-sm); resize: vertical; margin-bottom: var(--s2); }
.pos-btn-confirmar { width: 100%; padding: 14px; font-size: 1rem; font-weight: 650; }
.pos-btn-confirmar:disabled { opacity: 0.5; cursor: not-allowed; }
.pos-msg { margin-top: var(--s2); min-height: 24px; font-size: var(--fs-sm); }
.msg-ok  { color: var(--color-green-text); }
.msg-err { color: var(--color-red-text); }

/* Modal */
/* Modal base: crece al contenido en horizontal (solo margen contra viewport),
   trunca en vertical con scroll interno del body. Páginas con min-width inline
   (rutas.js, ruta_detalle.js, kam-drawer) siguen funcionando — el techo lo levantamos,
   los pisos los respetamos. */
/* Tamaño por variables: --modal-w/--modal-h dan un default cómodo y cada modal puede sobreescribirlas
   inline (style="--modal-w:720px") para variar ancho/alto. En mobile el default pasa a fullscreen, pero
   un modal que fije sus variables inline las conserva (la inline gana a la regla del media query). */
.pos-modal {
  --modal-w: 560px;
  --modal-h: auto;
  padding: 0; border: 0; border-radius: var(--r-md);
  width: min(var(--modal-w), calc(100vw - 32px));
  height: var(--modal-h);
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.3);
  /* El scroll lo maneja solo .pos-modal-body. Sin esto, al crecer el contenido el <dialog> mostraba su
     propia barra y encogía el body 15px → reflow de los grids `auto-fit`. */
  overflow: hidden;
}
.pos-modal::backdrop { background: rgba(15,23,42,0.4); backdrop-filter: blur(2px); }
/* scrollbar-gutter: stable → reserva el ancho del scrollbar siempre. Sin esto, al revelar un sub-panel
   (ej. marcar un kind en el modal Tipificar) aparece el scrollbar, baja el ancho de contenido y los grids
   `auto-fit` saltan de columnas (las opciones cambian de tamaño). */
.pos-modal-body { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s5); max-height: calc(100dvh - 32px); overflow: auto; scrollbar-gutter: stable; }
/* La nota/tipificación necesita más aire (editor markdown + opciones avanzadas). */
.typify-modal { --modal-w: 720px; }

@media (max-width: 720px) {
  .pos-modal {
    --modal-w: 100vw; --modal-h: 100dvh;
    width: var(--modal-w); height: var(--modal-h);
    max-width: 100vw; max-height: 100dvh;
    border-radius: 0;
  }
  .pos-modal-body { max-height: 100dvh; }
}
.pos-modal-body h3 { margin: 0 0 var(--s1); }
.pos-modal-foot { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s4); }
.pos-modal .form-field { margin-bottom: var(--s3); }
.pos-modal .form-field label { display: block; font-size: var(--fs-xs); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; margin-bottom: 4px; }

/* Diálogos alert/confirm/prompt (components/dialog.js): hereda .pos-modal (backdrop, scroll), acotado. */
.lf-dialog .lf-dialog-body { min-width: min(420px, 92vw); max-width: 480px; gap: var(--s3); }
.lf-dialog-title { margin: 0; font-size: var(--fs-lg); font-weight: 650; }
.lf-dialog-msg { margin: 0; color: var(--color-text-secondary); line-height: 1.5; white-space: pre-line; }
.lf-dialog-input { width: 100%; }
.lf-dialog-foot { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s2); }
.pos-modal .form-field input { width: 100%; padding: 8px 12px; border: 1px solid var(--color-border); border-radius: var(--r-sm); font: inherit; }

/* ----------------- Typify modal (tipificación de notas KAM) ----------------- */
/* `.tp-input` = clase de input reutilizable CENTRALIZADA (antes estaba scoped a .typify-modal, así que
   fuera del modal — ej. el schedule-picker montado en cliente_detalle — sus inputs quedaban sin estilo).
   Ahora es global: cualquier input/select/textarea con .tp-input toma el mismo look que `.form-field input`.
   Los date/time mantienen su estilo propio (regla `input[type=date]` gana por especificidad). */
.tp-input {
  width: 100%; padding: 8px 12px; font: inherit; font-size: var(--fs-body); line-height: 1.45;
  background: var(--color-surface); color: var(--color-text-primary);
  border: 1px solid var(--color-border-strong); border-radius: var(--r-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.tp-input:hover:not(:disabled) { border-color: var(--color-text-tertiary); }
.tp-input:focus { border-color: var(--color-green); outline: none; box-shadow: 0 0 0 1px var(--color-green); }
.tp-input:disabled { background: var(--color-bg-muted); color: var(--color-text-tertiary); border-color: var(--color-border); }
.tp-input::placeholder { color: var(--color-text-tertiary); }
/* Grilla de "efectos" del modal de requerimiento — cards minimalistas con :has()
   para el estado checked. El checkbox nativo queda oculto pero focuseable (a11y). */
.typify-modal .tp-kinds {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s2);
  width: 100%;
}
/* Subtítulo de grupo de efectos: agrupa los kinds para que la lista no abrume. */
.typify-modal .tp-kind-group-label { font-size: var(--fs-xs); font-weight: 650; color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; margin: var(--s3) 0 4px; }
.typify-modal .tp-kind-group-label:first-of-type { margin-top: var(--s1); }
.typify-modal .tp-kind-group-label small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.typify-modal .tp-kind-opt {
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: var(--s3);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: var(--fs-sm); font-weight: 500;
  color: var(--color-text-primary);
  user-select: none;
  transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.typify-modal .tp-kind-opt:hover {
  border-color: var(--color-text-tertiary);
  background: var(--color-bg-subtle);
}
.typify-modal .tp-kind-opt input[type="checkbox"] {
  position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none;
}
.typify-modal .tp-kind-opt:has(input[type="checkbox"]:checked) {
  border-color: var(--color-green);
  background: var(--color-green-soft);
}
.typify-modal .tp-kind-opt:has(input[type="checkbox"]:focus-visible) {
  outline: 2px solid var(--color-green);
  outline-offset: 2px;
}
.typify-modal .tp-kind-opt span {
  display: flex; flex-direction: column; gap: 2px;
}
.typify-modal .tp-kind-opt small {
  color: var(--color-text-tertiary); font-weight: normal; font-size: var(--fs-xs);
}
.typify-modal label.tp-inline { display: flex; align-items: center; gap: 5px; margin: 0; font-weight: 450; text-transform: none; letter-spacing: 0; color: var(--color-text-primary); }

/* ----------------- Markdown editor + render (front/assets/md.js) ----------------- */
.md-editor { border: 1px solid var(--color-border); border-radius: var(--r-sm); overflow: hidden; background: var(--color-surface); }
.md-toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 6px; background: var(--color-bg-subtle); border-bottom: 1px solid var(--color-border); }
.md-toolbar button { border: 1px solid transparent; background: transparent; color: var(--color-text-secondary); border-radius: var(--r-sm); padding: 3px 8px; font-size: var(--fs-sm); cursor: pointer; line-height: 1.4; }
.md-toolbar button:hover { background: var(--color-surface); border-color: var(--color-border); color: var(--color-text-primary); }
.md-toolbar .md-toggle.on { background: var(--color-green-soft); border-color: var(--color-green-line); color: var(--color-green-text); }
/* max-width:none anula el cap de `.form-field textarea` (max-width:480px): dentro de un .form-field el
   editor debe ocupar todo el ancho del contenedor, no quedar angosto a 480px. */
.md-editor .md-ta { width: 100%; max-width: none; border: 0; outline: none; padding: 10px 12px; font-size: var(--fs-sm); background: var(--color-surface); color: var(--color-text-primary); display: block; }
.md-editor .md-preview { padding: 10px 12px; overflow: auto; }

.md-body { color: var(--color-text-primary); line-height: 1.55; word-break: break-word; }
.md-body > :first-child { margin-top: 0; }
.md-body > :last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { margin: var(--s3) 0 var(--s2); line-height: 1.25; }
.md-body h1 { font-size: 1.3em; } .md-body h2 { font-size: 1.15em; } .md-body h3 { font-size: 1.05em; } .md-body h4 { font-size: 1em; }
.md-body p { margin: var(--s2) 0; }
.md-body ul, .md-body ol { margin: var(--s2) 0; padding-left: 1.4em; }
.md-body li { margin: 2px 0; }
.md-body a { color: var(--color-blue, #2563eb); }
.md-body img.md-img, .md-img { max-width: 100%; height: auto; border-radius: var(--r-sm); }
.md-body code { font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.9em; background: var(--color-bg-subtle); padding: 1px 5px; border-radius: var(--r-sm); }
.md-body pre { background: var(--color-bg-subtle); padding: var(--s3); border-radius: var(--r-sm); overflow: auto; }
.md-body pre code { background: none; padding: 0; }
.md-body blockquote { margin: var(--s2) 0; padding: 4px 12px; border-left: 3px solid var(--color-border-strong); color: var(--color-text-secondary); }
.md-body table { border-collapse: collapse; margin: var(--s2) 0; font-size: var(--fs-sm); }
.md-body th, .md-body td { border: 1px solid var(--color-border); padding: 4px 8px; text-align: left; }
.md-body th { background: var(--color-bg-subtle); }
.md-body hr { border: none; border-top: 1px solid var(--color-border); margin: var(--s3) 0; }

/* ----------------- Navegador de fechas (rutas de despacho) ----------------- */
.date-nav { display: flex; align-items: center; gap: var(--s2); margin: var(--s4) 0; flex-wrap: wrap; }
.date-arrow { width: 34px; height: 46px; border: 1px solid var(--color-border); border-radius: var(--r-sm); background: var(--color-surface); color: var(--color-text-secondary); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.date-arrow:hover { background: var(--color-bg-subtle); color: var(--color-text-primary); }
.date-rail { display: flex; gap: 6px; flex: 1; min-width: 0; }
.date-cell { flex: 1; min-width: 42px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border: 1px solid var(--color-border); border-radius: var(--r-md); background: var(--color-surface); cursor: pointer; transition: background .12s, border-color .12s; }
.date-cell em { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-tertiary); font-style: normal; font-weight: 650; }
.date-cell b { font-size: 1.15rem; font-weight: 700; color: var(--color-text-primary); font-variant-numeric: tabular-nums; }
.date-cell:hover { border-color: var(--color-border-strong); background: var(--color-bg-subtle); }
.date-cell.today { border-color: var(--color-green-line); }
.date-cell.today b { color: var(--color-green); }
.date-cell.on { background: var(--color-green); border-color: var(--color-green); }
.date-cell.on em, .date-cell.on b { color: var(--color-text-inverse); }
.date-jump { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; height: 46px; border: 1px solid var(--color-border); border-radius: var(--r-sm); background: var(--color-surface); }
.date-jump input { border: 0; outline: none; background: transparent; font: inherit; color: var(--color-text-primary); }

.plan-summary { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; padding: var(--s3) var(--s4); margin-bottom: var(--s4); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-md); border-left: 3px solid var(--color-green); }
.plan-date { font-size: 1.15rem; font-weight: 700; color: var(--color-text-primary); }
.plan-stats { display: flex; align-items: center; gap: var(--s4); }
.plan-stat { font-size: var(--fs-sm); color: var(--color-text-secondary); }
.plan-stat b { font-size: 1.15rem; color: var(--color-text-primary); font-variant-numeric: tabular-nums; margin-right: 3px; }

/* ----------------- Schedule picker (RRULE de negocio + rango) ----------------- */
.sched-picker { display: flex; flex-direction: column; gap: var(--s3); }
.sched-block { display: flex; flex-direction: column; gap: 6px; }
/* [hidden] + flex gotcha: display:flex gana sobre el display:none de la UA stylesheet, así que
   syncUI() (el.hidden=true) no ocultaba los bloques solo-mensuales en modo semanal. */
.sched-block[hidden] { display: none; }
.sched-label { font-size: var(--fs-xs); color: var(--color-text-tertiary); text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }
.sched-seg { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--r-sm); overflow: hidden; width: fit-content; }
.sched-seg button { border: 0; background: var(--color-surface); color: var(--color-text-secondary); padding: 6px 14px; cursor: pointer; font: inherit; font-size: var(--fs-sm); border-right: 1px solid var(--color-border); }
.sched-seg button:last-child { border-right: 0; }
.sched-seg button.on { background: var(--color-green); color: var(--color-text-inverse); }
.sched-dows { display: flex; gap: 4px; flex-wrap: wrap; }
.sched-dows button { width: 40px; height: 36px; border: 1px solid var(--color-border); border-radius: var(--r-sm); background: var(--color-surface); color: var(--color-text-secondary); cursor: pointer; font: inherit; font-size: var(--fs-sm); }
.sched-dows button.on { background: var(--color-green); border-color: var(--color-green); color: var(--color-text-inverse); }
/* Semana(s) del mes (BYSETPOS 1°–4°/Último): mismo patrón visual que los días — sin esto los botones
   togglean la clase .on pero no se veían marcados. */
.sched-setpos { display: flex; gap: 4px; flex-wrap: wrap; }
.sched-setpos button { min-width: 40px; height: 36px; padding: 0 10px; border: 1px solid var(--color-border); border-radius: var(--r-sm); background: var(--color-surface); color: var(--color-text-secondary); cursor: pointer; font: inherit; font-size: var(--fs-sm); }
.sched-setpos button.on { background: var(--color-green); border-color: var(--color-green); color: var(--color-text-inverse); }
.sched-range { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.sched-range input.tp-input { width: auto; }
.sched-row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.sched-row input.tp-input { width: auto; }

/* ----------------- Date popover (calendario + "Ir a" semántico) ----------------- */
/* Posición (fixed + top/left relativos al botón) la fija date-popover.js en JS; ver el rationale ahí
   (CSS anchor positioning resultaba frágil y caía a la esquina del viewport). */
.date-pop { margin: 0; border: 1px solid var(--color-border); border-radius: var(--r-md); background: var(--color-surface); box-shadow: 0 12px 40px -8px rgba(0,0,0,0.28); padding: var(--s3); width: 290px; }
.date-pop-nlp { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--s3); }
.date-pop-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s2); }
.date-pop-head b { font-size: var(--fs-sm); text-transform: capitalize; }
.date-pop-head .date-arrow { width: 30px; height: 30px; font-size: 1.1rem; }
.date-pop-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.date-pop-grid .dp-dow { text-align: center; font-size: var(--fs-2xs); color: var(--color-text-tertiary); font-weight: 650; padding: 2px 0; }
.dp-day { aspect-ratio: 1; border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: var(--color-text-primary); cursor: pointer; font: inherit; font-size: var(--fs-sm); }
.dp-day:hover { background: var(--color-bg-subtle); }
.dp-day.today { border-color: var(--color-green-line); color: var(--color-green); font-weight: 700; }
.dp-day.sel { background: var(--color-green); color: var(--color-text-inverse); border-color: var(--color-green); }
/* Estado de despacho por día (calendario coloreado): punto indicador, coexiste con .sel/.today. */
.dp-day.dp-dispatch, .dp-day.dp-dispatch-proj, .dp-day.dp-skip, .dp-day.dp-block { position: relative; }
.dp-day.dp-dispatch::after, .dp-day.dp-dispatch-proj::after, .dp-day.dp-skip::after, .dp-day.dp-block::after {
  content: ''; position: absolute; left: 50%; bottom: 3px; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%;
}
.dp-day.dp-dispatch::after { background: var(--color-green); }
.dp-day.dp-dispatch-proj::after { background: transparent; box-shadow: inset 0 0 0 1.5px var(--color-green); }
.dp-day.dp-skip::after { background: var(--color-amber); }
.dp-day.dp-block::after { background: var(--color-red); }
.dp-day.sel::after { background: var(--color-text-inverse) !important; box-shadow: none !important; }
/* Leyenda del calendario: misma codificación de color que los puntos de día. */
.cal-legend .cal-dot { display: inline-flex; align-items: center; gap: 5px; }
.cal-legend .cal-dot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.cal-legend .cal-dispatch::before { background: var(--color-green); }
.cal-legend .cal-proj::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--color-green); }
.cal-legend .cal-skip::before { background: var(--color-amber); }
.cal-legend .cal-block::before { background: var(--color-red); }

/* Tabs de la ficha de cliente (clientes/:id) — un panel a la vez. */
.cli-tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--color-border); margin: var(--s4) 0 var(--s3); }
.cli-tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 14px; cursor: pointer; font: inherit; font-size: var(--fs-sm); color: var(--color-text-secondary); display: inline-flex; align-items: center; gap: 6px; }
.cli-tab:hover { color: var(--color-text-primary); }
.cli-tab.active { color: var(--color-green); border-bottom-color: var(--color-green); font-weight: 600; }
.cli-tab-count { background: var(--color-bg-subtle); color: var(--color-text-secondary); border-radius: 999px; font-size: var(--fs-2xs); padding: 0 6px; min-width: 18px; text-align: center; }
.cli-tab.active .cli-tab-count { background: var(--color-green); color: var(--color-text-inverse); }
.cli-tab-panel[hidden] { display: none; }

@media (max-width: 1000px) {
  /* En pantallas chicas el POS deja de ser 2 paneles de altura fija con scroll interno (catálogo |
     carrito) y pasa a UNA columna que fluye: catálogo completo arriba, carrito debajo, la página
     scrollea como una sola. Antes el carrito (position:sticky;bottom:0) flotaba PINNEADO al fondo del
     viewport y se superponía al catálogo, tapando los productos ("bloques cortados" en mobile). */
  .pos-shell { grid-template-columns: 1fr; height: auto; }
  .pos-catalogo { min-height: auto; }
  .pos-cat-grid { overflow: visible; flex: none; min-height: auto; }
  .pos-carrito { position: static; max-height: none; overflow: visible; }
}

/* ----------------- Dashboard home ----------------- */
.dashboard-2col { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--s4); margin-top: var(--s5); }
.dashboard-2col .card { margin: 0; }
.kpi-list { display: flex; flex-direction: column; gap: 2px; }
.kpi-row { display: flex; justify-content: space-between; align-items: center; padding: var(--s3); border-radius: var(--r-sm); color: var(--color-text-primary); }
.kpi-row:hover { background: var(--color-bg-subtle); text-decoration: none; }
.kpi-row .kpi-label { color: var(--color-text-secondary); font-size: var(--fs-sm); }
.kpi-row .kpi-value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-row.alerta { background: var(--color-amber-soft); }
.kpi-row.alerta .kpi-value { color: var(--color-amber-text); }
.tareas-top { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.tareas-top .tarea-mini { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r-sm); }
.tareas-top .tarea-mini b { display: block; font-size: var(--fs-sm); font-weight: 600; }
.tareas-top .tarea-mini .muted { display: block; font-size: var(--fs-2xs); line-height: 1.3; }
@media (max-width: 880px) { .dashboard-2col { grid-template-columns: 1fr; } }

/* =================================================================
   DataGrid (bnx-data-grid) — overrides para usar paleta del proyecto
   ================================================================= */
bnx-data-grid {
  display: block;
  /* mapeo de las vars que usa DataGrid → vars del proyecto */
  --color-border-subtle: var(--color-border);
  --color-gray-50: var(--color-bg-subtle);
  --color-white: var(--color-surface);
  --color-text-primary: var(--color-text-primary);
  --color-text-secondary: var(--color-text-secondary);
  --color-text-tertiary: var(--color-text-tertiary);
  --color-brand-primary: var(--color-green);
  --radius-lg: var(--r-md);
  --text-size-sm: var(--fs-sm);
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
}
bnx-data-grid .bnx-dg-spreadsheet-container {
  border-radius: var(--r-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: 0 1px 0 rgba(15,23,42,0.02);
}
bnx-data-grid .bnx-dg-spreadsheet th {
  padding: 10px 14px !important;
  font-size: var(--fs-2xs) !important;
  letter-spacing: 0.08em;
  color: var(--color-text-tertiary) !important;
  background: var(--color-bg-subtle) !important;
  border-bottom: 1px solid var(--color-border) !important;
}
bnx-data-grid .bnx-dg-spreadsheet td {
  padding: 10px 14px !important;
  font-size: var(--fs-sm);
  border-bottom: 1px solid var(--color-border-soft) !important;
  vertical-align: middle;
}
bnx-data-grid .bnx-dg-spreadsheet tbody tr:hover td {
  background: var(--color-bg-subtle) !important;
}
bnx-data-grid .bnx-dg-spreadsheet tbody tr:last-child td { border-bottom: none !important; }
bnx-data-grid .bnx-dg-spreadsheet td a {
  color: var(--color-green-text);
  font-weight: 600;
}
bnx-data-grid .bnx-dg-spreadsheet td a:hover { text-decoration: underline; text-underline-offset: 2px; }
bnx-data-grid .bnx-dg-cell-number,
bnx-data-grid .bnx-dg-cell-currency {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}
bnx-data-grid .bnx-dg-cell-html .tarea-prio { font-size: var(--fs-2xs); padding: 2px 8px; border-radius: var(--r-pill); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
bnx-data-grid .bnx-dg-empty-row td { padding: var(--s8) !important; text-align: center; color: var(--color-text-tertiary); font-style: italic; }

/* Responsive: scroll horizontal en móvil */
@media (max-width: 760px) {
  bnx-data-grid .bnx-dg-spreadsheet { font-size: var(--fs-xs); }
  bnx-data-grid .bnx-dg-spreadsheet th,
  bnx-data-grid .bnx-dg-spreadsheet td { padding: 8px 10px !important; }
}

/* ----------------- Listas de ranking (reportes) ----------------- */
.rank-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.rank-list li { display: grid; grid-template-columns: 28px 1fr auto; gap: var(--s2); align-items: center; padding: var(--s2) var(--s3); border-radius: var(--r-sm); }
.rank-list li:hover { background: var(--color-bg-subtle); }
.rank-pos { width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--color-green-soft); color: var(--color-green-text); font-weight: 700; font-size: var(--fs-xs); }
.rank-list li:nth-child(1) .rank-pos { background: #fef3c7; color: #92400e; }
.rank-list li:nth-child(2) .rank-pos { background: #e0e7ff; color: #3730a3; }
.rank-list li:nth-child(3) .rank-pos { background: #fce7f3; color: #831843; }
.rank-info { display: flex; flex-direction: column; min-width: 0; color: var(--color-text-primary); }
.rank-info:hover { text-decoration: none; }
.rank-info b { font-size: var(--fs-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-value { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--color-green); }

/* ── Tirilla de ruta (front/pages/tirilla.js) ───────────────────────────────── */
.tir-summary { margin-bottom: var(--s4); }
.tir-sum-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: var(--s4); }
.tir-sum-grid > div { display: flex; flex-direction: column; gap: 2px; }
.tir-sum-k { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 650; color: var(--color-text-tertiary); }
.tir-sum-v { font-size: 1.0625rem; font-weight: 650; color: var(--color-text-primary); }
.tir-doc { margin-bottom: var(--s5); }
.tir-doc table { font-size: var(--fs-sm); }
.tir-doc-tipos { min-width: 14rem; }
.tir-doc-chip { display: inline-block; padding: 1px var(--s2); margin: 1px; border-radius: var(--radius-sm, 4px);
  background: var(--color-bg-subtle); border: 1px solid var(--color-border-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tok-faint { color: var(--color-text-muted, #9ca3af); }
.tir-totals { margin-bottom: var(--s5); }
.tir-totals-list { margin: var(--s2) 0 0; padding-left: var(--s5); columns: 2; column-gap: var(--s6); }
.tir-totals-list li { break-inside: avoid; padding: 2px 0; font-variant-numeric: tabular-nums; }
.tir-group { margin-bottom: var(--s5); }
.tir-group-title { margin: 0 0 var(--s2); display: flex; align-items: baseline; gap: var(--s2); }
.tir-lines { margin: 0 0 var(--s2); padding-left: var(--s5); }
.tir-lines li { padding: 1px 0; }
.tir-print-preview { margin-top: var(--s4); }
.tir-print-preview > summary { cursor: pointer; font-weight: 600; color: var(--color-text-secondary); user-select: none; }
.tir-print-preview > summary:hover { color: var(--color-text-primary); }
@media (max-width: 640px) { .tir-totals-list { columns: 1; } }

/* Aside de orden de entrega (ruta_detalle): drawer pegado a la derecha, alto completo — cómodo en mobile. */
.order-aside { margin: 0 0 0 auto; max-height: 100dvh; border-radius: 0; }
.order-aside .pos-modal-body { max-height: 100dvh; min-height: 100dvh; }
@media (max-width: 720px) { .order-aside { width: 100vw; } }
