/* ==========================================================================
   LOGIX · Sistema de diseño
   Identidad: almacén industrial. Tinta azul acero, amarillo de señalización
   (marcas de piso y etiquetas de rack), superficies de concreto claro.
   Todos los colores son tokens: el modo oscuro solo redefine variables.
   ========================================================================== */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --surface-3: #e9edf2;
  --ink: #13233a;          /* títulos, sidebar */
  --ink-2: #1c3150;
  --text: #1d2a3a;
  --muted: #5b6b7f;
  --line: #d8dee6;
  --line-strong: #c3ccd7;
  --signal: #f2b705;       /* amarillo señalización */
  --signal-soft: #fff4cc;
  --signal-ink: #3a2c00;
  --ok: #1f9d6b;   --ok-soft: #dff4ea;
  --bad: #d64545;  --bad-soft: #fbe3e3;
  --info: #2f6fde; --info-soft: #e1ebfc;
  --warn: #b86e00; --warn-soft: #fdeed6;
  --shadow: 0 1px 2px rgba(19, 35, 58, .06), 0 2px 8px rgba(19, 35, 58, .05);
  --shadow-lg: 0 10px 30px rgba(19, 35, 58, .16);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 264px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 60px;
  --font: 'Plex', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-cond: 'PlexCond', 'Plex', 'Arial Narrow', sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d141f;
  --surface: #142033;
  --surface-2: #19273d;
  --surface-3: #213149;
  --ink: #e9eef5;
  --ink-2: #c9d4e2;
  --text: #d6dee8;
  --muted: #8d9bb0;
  --line: #26364f;
  --line-strong: #33476a;
  --signal-soft: #3a2f0a;
  --signal-ink: #ffe28a;
  --ok-soft: #12352a; --bad-soft: #3d1c1f; --info-soft: #172c52; --warn-soft: #3a2a10;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.45);
  color-scheme: dark;
}

/* ---------- Base ---------- */
html, body { height: 100%; }
body { font-family: var(--font); font-size: 14.5px; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, h5, .cond { font-family: var(--font-cond); color: var(--ink); letter-spacing: .005em; }
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.4rem; font-weight: 600; }
h3 { font-size: 1.15rem; font-weight: 600; }
a { color: var(--info); }
.text-muted, .muted { color: var(--muted) !important; }
.small-label { font-size: .78rem; color: var(--muted); font-weight: 500; }
.num { font-variant-numeric: tabular-nums; }
.docnum { font-family: var(--font-cond); font-weight: 700; color: var(--ink); letter-spacing: .02em; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
::selection { background: var(--signal); color: var(--signal-ink); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Bootstrap ajustado a tokens */
.form-control, .form-select { background-color: var(--surface); color: var(--text); border-color: var(--line-strong); border-radius: var(--radius-sm); font-size: .95rem; }
.form-control:focus, .form-select:focus { border-color: var(--ink-2); box-shadow: 0 0 0 3px rgba(242, 183, 5, .35); background-color: var(--surface); color: var(--text); }
.form-control::placeholder { color: var(--muted); opacity: .75; }
.form-label { font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
.form-check-input:checked { background-color: var(--ink); border-color: var(--ink); }
:root[data-theme="dark"] .form-check-input:checked { background-color: var(--signal); border-color: var(--signal); }
.input-group-text { background: var(--surface-2); border-color: var(--line-strong); color: var(--muted); }
.btn { border-radius: var(--radius-sm); font-weight: 500; }
.btn-primary { --bs-btn-bg: #13233a; --bs-btn-border-color: #13233a; --bs-btn-hover-bg: #1c3150; --bs-btn-hover-border-color: #1c3150; --bs-btn-active-bg: #0b1626; --bs-btn-disabled-bg: #13233a; }
:root[data-theme="dark"] .btn-primary { --bs-btn-bg: #f2b705; --bs-btn-border-color: #f2b705; --bs-btn-color: #241b00; --bs-btn-hover-bg: #ffc61a; --bs-btn-hover-color: #241b00; --bs-btn-hover-border-color: #ffc61a; --bs-btn-active-bg: #d9a400; --bs-btn-active-color: #241b00; }
.btn-signal { background: var(--signal); color: #241b00; border: 0; font-weight: 600; }
.btn-signal:hover { background: #ffc61a; color: #241b00; }
.btn-ghost { background: transparent; border: 1px solid var(--line-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-icon { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.dropdown-menu { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow-lg); border-radius: var(--radius); }
.dropdown-item { color: var(--text); }
.dropdown-item:hover { background: var(--surface-2); color: var(--ink); }
.modal-content { background: var(--surface); color: var(--text); border: 0; border-radius: 12px; box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--line); padding: 1rem 1.25rem; }
.modal-header .modal-title { font-family: var(--font-cond); font-weight: 600; color: var(--ink); }
.modal-footer { border-top: 1px solid var(--line); }
:root[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
.nav-tabs { border-bottom-color: var(--line); }
.nav-tabs .nav-link { color: var(--muted); border: 0; border-bottom: 3px solid transparent; font-weight: 500; }
.nav-tabs .nav-link.active { color: var(--ink); background: transparent; border-bottom-color: var(--signal); }
.progress { background: var(--surface-3); height: 8px; border-radius: 4px; }

/* ---------- Layout de aplicación ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 1040;
  background: #13233a; color: #c8d3e1; display: flex; flex-direction: column;
  transition: width .2s ease, transform .25s ease;
}
:root[data-theme="dark"] .sidebar { background: #0a111b; border-right: 1px solid var(--line); }
.sidebar-brand { height: var(--topbar-h); display: flex; align-items: center; gap: 10px; padding: 0 18px; border-bottom: 1px solid rgba(255,255,255,.07); flex-shrink: 0; }
.brand-mark { width: 34px; height: 34px; border-radius: 7px; background: var(--signal); color: #13233a; display: grid; place-items: center; font-family: var(--font-cond); font-weight: 700; font-size: 1.1rem; flex-shrink: 0; position: relative; overflow: hidden; }
.brand-mark::after { content: ''; position: absolute; inset: auto 0 0 0; height: 6px; background: repeating-linear-gradient(135deg, #13233a 0 5px, transparent 5px 10px); opacity: .85; }
.brand-text { font-family: var(--font-cond); font-weight: 700; color: #fff; font-size: 1.2rem; letter-spacing: .06em; white-space: nowrap; }
.brand-company { font-size: .72rem; color: #8ea0b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; display: block; letter-spacing: 0; font-family: var(--font); font-weight: 400; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 10px 24px; scrollbar-width: thin; scrollbar-color: #2a3f5e transparent; }
.nav-group { margin-bottom: 2px; }
.nav-group-btn {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 0; background: none;
  color: #9fb0c6; font-size: .86rem; font-weight: 600; border-radius: 8px; text-align: left;
}
.nav-group-btn:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-group-btn .bi:first-child { font-size: 1.1rem; width: 22px; text-align: center; }
.nav-group-btn .chev { margin-left: auto; font-size: .75rem; transition: transform .2s; }
.nav-group.open .nav-group-btn { color: #fff; }
.nav-group.open .nav-group-btn .chev { transform: rotate(90deg); }
.nav-items { display: none; padding: 2px 0 8px 0; }
.nav-group.open .nav-items { display: block; }
.nav-link-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px 8px 46px; color: #b7c4d6; text-decoration: none;
  font-size: .9rem; border-radius: 7px; position: relative; white-space: nowrap;
}
.nav-link-item .bi { display: none; }
.nav-link-item:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-link-item.active { color: #fff; background: rgba(242, 183, 5, .12); }
.nav-link-item.active::before { content: ''; position: absolute; left: 30px; top: 9px; bottom: 9px; width: 3px; border-radius: 2px; background: var(--signal); }
.sidebar-foot { padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.07); font-size: .75rem; color: #7f91a9; flex-shrink: 0; white-space: nowrap; overflow: hidden; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; transition: margin-left .2s ease; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  height: var(--topbar-h); position: sticky; top: 0; z-index: 1030; background: var(--surface);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 0 18px;
}
.topbar .crumb { font-family: var(--font-cond); font-weight: 600; color: var(--ink); font-size: 1.08rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .crumb small { font-family: var(--font); font-weight: 400; color: var(--muted); font-size: .8rem; margin-right: 6px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar .btn-icon { border: 0; background: transparent; color: var(--muted); border-radius: 8px; position: relative; font-size: 1.15rem; }
.topbar .btn-icon:hover { background: var(--surface-2); color: var(--ink); }
.dot-badge { position: absolute; top: 5px; right: 5px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--bad); color: #fff; font-size: .62rem; font-weight: 700; display: grid; place-items: center; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 22px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.user-chip img, .avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--surface-3); }
.avatar-lg { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; background: var(--surface-3); }
.content { padding: 22px; flex: 1; }
.content-loading { opacity: .45; pointer-events: none; transition: opacity .15s; }

/* Colapsado (escritorio): riel de íconos, el contenido crece */
body.sb-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sb-collapsed .main { margin-left: var(--sidebar-w-collapsed); }
body.sb-collapsed .brand-text, body.sb-collapsed .nav-group-btn span, body.sb-collapsed .nav-group-btn .chev, body.sb-collapsed .sidebar-foot { display: none; }
body.sb-collapsed .sidebar-brand { justify-content: center; padding: 0; }
body.sb-collapsed .nav-group-btn { justify-content: center; padding: 11px 0; }
body.sb-collapsed .nav-items { display: none !important; }
body.sb-collapsed .nav-group { position: relative; }
body.sb-collapsed .nav-group:hover .nav-items {
  display: block !important; position: absolute; left: calc(100% + 6px); top: 0; width: 230px; background: #1a2d49;
  border-radius: 10px; padding: 8px; box-shadow: var(--shadow-lg); z-index: 1050;
}
body.sb-collapsed .nav-group:hover .nav-link-item { padding-left: 14px; }
body.sb-collapsed .nav-group:hover .nav-link-item.active::before { left: 4px; }
body.sb-collapsed .sidebar-nav { overflow: visible; }

/* Móvil: sidebar como panel deslizable */
.sb-backdrop { display: none; }
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); width: 280px; }
  .main, body.sb-collapsed .main { margin-left: 0; }
  body.sb-open .sidebar { transform: none; }
  body.sb-open .sb-backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 14, 24, .5); z-index: 1035; }
  body.sb-collapsed .sidebar { width: 280px; }
  body.sb-collapsed .brand-text, body.sb-collapsed .nav-group-btn span, body.sb-collapsed .nav-group-btn .chev, body.sb-collapsed .sidebar-foot { display: initial; }
  .content { padding: 14px; }
  .topbar { padding: 0 10px; }
  .user-chip .uname { display: none; }
}

/* ---------- Encabezado de página ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 1.6rem; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; max-width: 70ch; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Paneles ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 1.02rem; }
.panel-body { padding: 16px; }
.panel-flush .panel-body { padding: 0; }

/* Barra de filtros */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.toolbar .search { position: relative; flex: 1 1 260px; max-width: 420px; }
.toolbar .search .bi { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.toolbar .search input { padding-left: 34px; }
.toolbar .form-select { width: auto; min-width: 150px; flex: 0 1 auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-filter { border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 18px; padding: 4px 12px; font-size: .84rem; }
.chip-filter.active { background: var(--ink); border-color: var(--ink); color: #fff; }
:root[data-theme="dark"] .chip-filter.active { background: var(--signal); border-color: var(--signal); color: #241b00; }

/* ---------- Tarjetas de registro (reemplazan tablas) ---------- */
.rec-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.rec-grid.wide { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
.rec-grid.list { grid-template-columns: 1fr; }
@media (max-width: 575.98px) { .rec-grid, .rec-grid.wide { grid-template-columns: 1fr; } }
.rec {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; position: relative; overflow: hidden; cursor: default;
}
.rec.clickable { cursor: pointer; }
.rec.clickable:hover { border-color: var(--line-strong); box-shadow: 0 4px 14px rgba(19,35,58,.1); }
.rec-top { display: flex; gap: 12px; padding: 14px 14px 10px; align-items: flex-start; }
.rec-thumb { width: 54px; height: 54px; border-radius: 8px; object-fit: cover; background: var(--surface-3); flex-shrink: 0; display: grid; place-items: center; color: var(--muted); font-size: 1.4rem; }
.rec-title { font-weight: 600; color: var(--ink); line-height: 1.3; margin: 0; font-size: .97rem; }
.rec-sub { color: var(--muted); font-size: .83rem; margin-top: 2px; }
.rec-body { padding: 0 14px 12px; font-size: .88rem; }
.rec-kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.rec-kv.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.rec-kv > div { min-width: 0; }
.rec-kv .k { display: block; font-size: .72rem; color: var(--muted); }
.rec-kv .v { display: block; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-foot { margin-top: auto; display: flex; align-items: center; gap: 6px; padding: 9px 12px; border-top: 1px solid var(--line); background: var(--surface-2); }
.rec-foot .btn { padding: 3px 10px; font-size: .82rem; }
.rec-foot .spacer { flex: 1; }
/* Tira de etiqueta: borde izquierdo de color según estado (como etiqueta de rack) */
.rec[data-tone]::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.rec[data-tone="ok"]::before { background: var(--ok); }
.rec[data-tone="bad"]::before { background: var(--bad); }
.rec[data-tone="info"]::before { background: var(--info); }
.rec[data-tone="warn"]::before { background: var(--signal); }
.rec[data-tone="mute"]::before { background: var(--line-strong); }

/* Estado */
.st { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 12px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.st::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-ok { background: var(--ok-soft); color: var(--ok); }
.st-bad { background: var(--bad-soft); color: var(--bad); }
.st-info { background: var(--info-soft); color: var(--info); }
.st-warn { background: var(--signal-soft); color: var(--warn); }
:root[data-theme="dark"] .st-warn { color: var(--signal); }
.st-mute { background: var(--surface-3); color: var(--muted); }
.grade { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; font-family: var(--font-cond); font-weight: 700; font-size: 1rem; }
.grade-A { background: var(--ok); color: #fff; } .grade-B { background: var(--info); color: #fff; }
.grade-C { background: var(--signal); color: #241b00; } .grade-D { background: var(--bad); color: #fff; }
.grade-none { background: var(--surface-3); color: var(--muted); }

/* ---------- Detalle de documento ---------- */
.doc-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); }
.doc-head .docnum { font-size: 1.5rem; }
.doc-meta { display: grid; gap: 12px 18px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); padding: 16px; }
.doc-meta .k { font-size: .74rem; color: var(--muted); display: block; }
.doc-meta .v { font-weight: 500; }
.lines { border-top: 1px solid var(--line); }
.line { display: grid; grid-template-columns: 56px minmax(0, 1fr) 110px 120px 120px; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.line.head { background: var(--surface-2); font-size: .74rem; color: var(--muted); font-weight: 600; padding-top: 8px; padding-bottom: 8px; }
.line .r { text-align: right; }
.line img { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--surface-3); }
.line .ln-name { font-weight: 500; color: var(--ink); }
.line .ln-sub { font-size: .78rem; color: var(--muted); }
@media (max-width: 767.98px) {
  .line { grid-template-columns: 44px 1fr 1fr; grid-template-areas: "img name name" "img a b" "img c c"; }
  .line.head { display: none; }
  .line > :nth-child(1) { grid-area: img; } .line > :nth-child(2) { grid-area: name; }
  .line > :nth-child(3) { grid-area: a; text-align: left; } .line > :nth-child(4) { grid-area: b; }
  .line > :nth-child(5) { grid-area: c; }
  .line [data-label]::before { content: attr(data-label) ' '; color: var(--muted); font-size: .74rem; }
}
.totals { margin-left: auto; width: 100%; max-width: 340px; padding: 12px 16px; }
.totals .t-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: .92rem; }
.totals .t-row.grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; font-family: var(--font-cond); font-weight: 700; font-size: 1.15rem; color: var(--ink); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: .88rem; }
.timeline li::before { content: ''; position: absolute; left: 5px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft); }
.timeline li::after { content: ''; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }

/* ---------- Editor de líneas ---------- */
.le-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px 130px 110px 40px; gap: 8px; align-items: start; padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--surface-2); }
.le-row.no-price { grid-template-columns: minmax(0, 1fr) 130px 40px; }
.le-row .le-info { font-size: .76rem; color: var(--muted); margin-top: 4px; }
.le-row .le-total { padding-top: 7px; text-align: right; font-weight: 600; }
.le-head { display: grid; grid-template-columns: minmax(0, 1fr) 110px 130px 110px 40px; gap: 8px; padding: 0 10px 4px; font-size: .74rem; color: var(--muted); font-weight: 600; }
.le-head.no-price { grid-template-columns: minmax(0, 1fr) 130px 40px; }
@media (max-width: 767.98px) {
  .le-head { display: none; }
  .le-row, .le-row.no-price { grid-template-columns: 1fr 1fr; }
  .le-row > :first-child { grid-column: 1 / -1; }
  .le-row .le-total { text-align: left; }
  .le-row [data-label]::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); }
}

/* ---------- KPIs y gráficos ---------- */
.kpi-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); position: relative; }
.kpi .k { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .v { font-family: var(--font-cond); font-weight: 700; font-size: 1.65rem; color: var(--ink); margin-top: 4px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.kpi.kpi-alert .v { color: var(--bad); }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: .86rem; }
.bar-row .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.bar-track { height: 10px; background: var(--surface-3); border-radius: 5px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; background: var(--ink-2); border-radius: 5px; }
:root[data-theme="dark"] .bar-fill { background: #6f8fbf; }
.bar-fill.signal { background: var(--signal); } .bar-fill.ok { background: var(--ok); } .bar-fill.bad { background: var(--bad); }
.bar-row .val { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.spark { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.spark .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.spark .b { width: 100%; max-width: 34px; background: var(--ink-2); border-radius: 4px 4px 0 0; min-height: 2px; }
:root[data-theme="dark"] .spark .b { background: #6f8fbf; }
.spark .col:last-child .b { background: var(--signal); }
.spark .l { font-size: .68rem; color: var(--muted); }

/* ---------- Lista simple ---------- */
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.mini-list li:last-child { border-bottom: 0; }
.mini-list .grow { flex: 1; min-width: 0; }
.mini-list .t { font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-list .s { font-size: .78rem; color: var(--muted); }

/* ---------- Vacío ---------- */
.empty { text-align: center; padding: 48px 16px; color: var(--muted); grid-column: 1 / -1; }
.empty .bi { font-size: 2.4rem; display: block; margin-bottom: 8px; color: var(--line-strong); }
.empty h4 { font-family: var(--font); font-size: 1rem; color: var(--text); font-weight: 600; }

/* Paginación */
.pager { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 16px; font-size: .86rem; color: var(--muted); }

/* Carga de imagen */
.img-drop { border: 1.5px dashed var(--line-strong); border-radius: 10px; padding: 10px; display: flex; gap: 12px; align-items: center; background: var(--surface-2); }
.img-drop img { width: 72px; height: 72px; border-radius: 8px; object-fit: cover; background: var(--surface-3); }
.gallery { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.gallery a { display: block; border-radius: 8px; overflow: hidden; aspect-ratio: 4/3; background: var(--surface-3); }
.gallery img { width: 100%; height: 100%; object-fit: cover; }

/* Notificaciones */
.notif-menu { width: 340px; max-height: 420px; overflow-y: auto; padding: 0; }
.notif-item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); font-size: .86rem; }
.notif-item.unread { background: var(--signal-soft); }
.notif-item .t { font-weight: 600; color: var(--ink); }
.notif-item .d { font-size: .74rem; color: var(--muted); }

/* ---------- Asistente IA ---------- */
.ai-fab { position: fixed; right: 18px; bottom: 18px; z-index: 1045; width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--ink); color: var(--signal); font-size: 1.4rem; box-shadow: var(--shadow-lg); }
:root[data-theme="dark"] .ai-fab { background: var(--signal); color: #241b00; }
.ai-panel { position: fixed; right: 18px; bottom: 84px; width: min(420px, calc(100vw - 24px)); height: min(600px, calc(100vh - 110px)); z-index: 1046; display: none; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.ai-panel.open { display: flex; }
.ai-head { padding: 12px 14px; background: var(--ink); color: #fff; display: flex; align-items: center; gap: 10px; }
:root[data-theme="dark"] .ai-head { background: #0a111b; }
.ai-head .t { font-family: var(--font-cond); font-weight: 600; }
.ai-head .s { font-size: .74rem; opacity: .7; }
.ai-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); }
.ai-msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: .9rem; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.ai-msg.user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 4px; }
:root[data-theme="dark"] .ai-msg.user { background: #2a4b7c; }
.ai-msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.ai-sugg { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; }
.ai-sugg button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 14px; font-size: .78rem; padding: 3px 10px; }
.ai-form { display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.ai-form textarea { resize: none; height: 42px; }

/* Select2 en tema */
.select2-container--bootstrap-5 .select2-selection { background-color: var(--surface); border-color: var(--line-strong); color: var(--text); min-height: 38px; }
.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered { color: var(--text); }
.select2-container--bootstrap-5 .select2-dropdown { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--highlighted { background: var(--ink); color: #fff; }
.select2-container--bootstrap-5 .select2-dropdown .select2-search .select2-search__field { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.select2-container--bootstrap-5.select2-container--focus .select2-selection, .select2-container--bootstrap-5.select2-container--open .select2-selection { border-color: var(--ink-2); box-shadow: 0 0 0 3px rgba(242,183,5,.35); }
.select2-container { width: 100% !important; }
.s2-opt { display: flex; gap: 8px; align-items: center; }
.s2-opt img { width: 28px; height: 28px; border-radius: 5px; object-fit: cover; }
.s2-opt .s { font-size: .74rem; opacity: .75; }

/* TinyMCE */
.tox-tinymce { border-radius: var(--radius-sm) !important; border-color: var(--line-strong) !important; }
.rich-view { font-size: .92rem; line-height: 1.55; }
.rich-view p:last-child { margin-bottom: 0; }

/* Utilidades */
.gap-2 { gap: .5rem; }
.hr { height: 1px; background: var(--line); margin: 14px 0; }
.legal-note { font-size: .8rem; color: var(--muted); background: var(--surface-2); border-left: 3px solid var(--signal); padding: 8px 12px; border-radius: 0 6px 6px 0; }
.alert-soft { padding: 10px 14px; border-radius: 8px; font-size: .88rem; }
.alert-soft.warn { background: var(--signal-soft); color: var(--signal-ink); }
.alert-soft.bad { background: var(--bad-soft); color: var(--bad); }
.alert-soft.info { background: var(--info-soft); color: var(--info); }
.alert-soft.ok { background: var(--ok-soft); color: var(--ok); }
.score-ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; background: conic-gradient(var(--c, var(--ok)) calc(var(--p) * 1%), var(--surface-3) 0); display: grid; place-items: center; flex-shrink: 0; }
.score-ring span { width: 50px; height: 50px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-family: var(--font-cond); font-weight: 700; color: var(--ink); }
.swal2-popup { font-family: var(--font) !important; border-radius: 14px !important; }
:root[data-theme="dark"] .swal2-popup { background: var(--surface) !important; color: var(--text) !important; }
:root[data-theme="dark"] .swal2-title, :root[data-theme="dark"] .swal2-content { color: var(--text) !important; }
.swal2-styled.swal2-confirm { background-color: #13233a !important; }
.cmp-col { min-width: 220px; }
.cmp-scroll { overflow-x: auto; }
.cmp-grid { display: grid; gap: 10px; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); }
.cmp-card { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.cmp-card.win { border: 2px solid var(--ok); }
.cmp-card .cmp-h { padding: 12px; border-bottom: 1px solid var(--line); }
.cmp-card .cmp-r { display: flex; justify-content: space-between; gap: 8px; padding: 6px 12px; font-size: .85rem; border-bottom: 1px dashed var(--line); }
.cmp-card .cmp-r.best { background: var(--ok-soft); }

/* Líneas dinámicas (App.linesView) en móvil */
@media (max-width: 767.98px) {
  .lines-dyn .line { display: flex !important; flex-wrap: wrap; gap: 4px 14px; }
  .lines-dyn .line.head { display: none !important; }
  .lines-dyn .line > div:nth-child(1):has(img) { flex: 0 0 44px; }
  .lines-dyn .line > div:not([data-label]):not(:has(img)) { flex: 1 1 calc(100% - 60px); }
  .lines-dyn .line > div[data-label] { flex: 1 1 40%; text-align: left; }
}
.min-w-0 { min-width: 0; }
/* Selector segmentado (también usado en formularios internos) */
.ruc-toggle { display: flex; gap: 4px; background: var(--surface-3); padding: 4px; border-radius: 8px; }
.ruc-toggle label { flex: 1; text-align: center; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: .86rem; color: var(--muted); margin: 0; }
.ruc-toggle input { display: none; }
.ruc-toggle input:checked + label { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
@media (max-width: 575.98px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .v { font-size: 1.2rem; }
  .kpi .k, .kpi .s { font-size: .72rem; }
  .page-head h1 { font-size: 1.35rem; }
}
