/* ============================================================
   Sistema de gestión · estilos
   Todos los colores y tamaños salen de las variables de :root.
   Para cambiar la apariencia basta con editar este bloque.
   ============================================================ */
:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --line: #dfe4eb;
  --line-strong: #c9d1dc;
  --ink: #172033;
  --ink-2: #44506a;
  --muted: #6b7690;

  --side: #121c2d;
  --side-2: #1a2740;
  --side-ink: #a9b4c7;
  --side-ink-hi: #ffffff;

  --accent: #1f5fd6;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefc;
  --ok: #17803d;
  --ok-soft: #e3f4ea;
  --warn: #a96400;
  --warn-soft: #fff1d6;
  --bad: #c2371f;
  --bad-soft: #fde8e4;
  --info: #0e7490;
  --info-soft: #dff3f8;

  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(18, 28, 45, .06);
  --shadow-pop: 0 12px 40px rgba(18, 28, 45, .22);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --side-w: 232px;
  --top-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.mono { font-variant-numeric: tabular-nums; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 8px; }
.spread { justify-content: space-between; }

/* ---------- Arranque / login ---------- */
#boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); color: var(--muted); z-index: 50; }
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 1fr) minmax(360px, 480px); }
.login-art { background: var(--side); color: var(--side-ink); padding: 56px; display: flex; flex-direction: column; justify-content: flex-end; }
.login-art h1 { color: #fff; font-size: 30px; max-width: 14em; line-height: 1.2; }
.login-art p { max-width: 30em; margin: 14px 0 0; }
.login-form { display: grid; align-content: center; padding: 48px; background: var(--surface); }
.login-form form { display: grid; gap: 14px; max-width: 340px; width: 100%; margin: 0 auto; }
.login-form h2 { font-size: 22px; margin-bottom: 4px; }
.setup-box { max-width: 640px; margin: 10vh auto; background: var(--surface); padding: 32px; border-radius: var(--radius-lg); border: 1px solid var(--line); }
.setup-box code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-head { padding: 18px 18px 14px; color: var(--side-ink-hi); font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.07); min-height: var(--top-h); }
.side-head .dot { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; flex: none; }
.side-head .dot svg { width: 16px; height: 16px; stroke: #fff; }
.nav { padding: 10px 8px; overflow: auto; flex: 1; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin-bottom: 2px; border-radius: var(--radius); color: var(--side-ink); font-weight: 500; }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--side-2); color: var(--side-ink-hi); }
.nav a.active { background: var(--accent); color: #fff; }
.nav .sep { height: 1px; background: rgba(255,255,255,.07); margin: 8px 6px; }
.side-foot { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.07); font-size: 12.5px; }
.side-foot b { display: block; color: var(--side-ink-hi); font-weight: 600; }
.side-foot button { margin-top: 8px; background: none; border: 0; color: var(--side-ink); padding: 0; cursor: pointer; text-decoration: underline; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: var(--top-h); background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.search { position: relative; width: min(380px, 40vw); }
.search input { width: 100%; height: 36px; padding: 0 12px 0 36px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); }
.search svg { position: absolute; left: 11px; top: 9px; width: 18px; height: 18px; color: var(--muted); }
.search-results { position: absolute; top: 42px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop); max-height: 60vh; overflow: auto; z-index: 30; }
.search-results a { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; color: var(--ink); border-bottom: 1px solid var(--line); }
.search-results a:hover { background: var(--accent-soft); }
.search-results .grp { padding: 7px 12px; font-size: 12px; color: var(--muted); background: var(--surface-2); font-weight: 600; }
.content { padding: 24px; flex: 1; min-width: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 24px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 16px; color: var(--ink-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-h h3 { font-size: 15px; }
.card-b { padding: 18px; }
.card-b.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 34px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #1a52bb; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { background: #136a33; }
.btn.danger { color: var(--bad); border-color: #e8b9b0; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { width: 28px; height: 28px; padding: 0; }

label.f { display: grid; gap: 5px; font-weight: 500; color: var(--ink-2); font-size: 13px; }
label.f > span small { color: var(--muted); font-weight: 400; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], input[type=month], input[type=search], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); font-weight: 400; color: var(--ink);
}
textarea { height: auto; min-height: 70px; padding: 8px 10px; resize: vertical; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
label.chk { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--ink); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.filters label.f { min-width: 140px; }
.filters .grow label.f { min-width: 200px; }

.tbl-wrap { overflow: auto; max-height: 70vh; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #f8faff; }
.tbl tr.click { cursor: pointer; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl td.act { text-align: right; white-space: nowrap; }
.tbl tfoot td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--line-strong); }
.tbl input, .tbl select { height: 30px; }
.tbl.compact td, .tbl.compact th { padding: 7px 10px; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink-2); font-size: 15px; margin-bottom: 4px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cc; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #f1d49b; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: #f2c4bb; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: #b5dfe9; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: #c4d6f7; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }

/* KPIs */
.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px 16px; border-left: 4px solid var(--accent); box-shadow: var(--shadow); }
.kpi.ok { border-left-color: var(--ok); } .kpi.warn { border-left-color: #d98a00; } .kpi.bad { border-left-color: var(--bad); } .kpi.info { border-left-color: var(--info); }
.kpi .l { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .v { font-size: 25px; font-weight: 650; margin-top: 4px; letter-spacing: -.02em; }
.kpi .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* Panel de alertas */
.alerts .al { display: flex; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); align-items: flex-start; cursor: pointer; }
.alerts .al:last-child { border-bottom: 0; }
.alerts .al:hover { background: var(--surface-2); }
.alerts .al .ic { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--warn-soft); color: var(--warn); }
.alerts .al .ic.bad { background: var(--bad-soft); color: var(--bad); }
.alerts .al .ic.info { background: var(--info-soft); color: var(--info); }
.alerts .al .ic svg { width: 15px; height: 15px; }
.alerts .al b { display: block; font-size: 13.5px; }
.alerts .al span { color: var(--muted); font-size: 12.5px; }

/* Gráficos */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); font-family: var(--font); }
.chart .val { fill: var(--ink-2); font-weight: 600; }
.bars-h .r { display: grid; grid-template-columns: 150px 1fr 90px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.bars-h .bar { height: 10px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; }
.bars-h .bar i { display: block; height: 100%; background: var(--accent); }

/* Modal */
#modals .scrim { position: fixed; inset: 0; background: rgba(18, 28, 45, .5); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow: auto; z-index: 100; }
.modal { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); width: 100%; max-width: 560px; display: flex; flex-direction: column; max-height: 90vh; }
.modal.md { max-width: 720px; } .modal.lg { max-width: 940px; } .modal.xl { max-width: 1180px; }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-h h3 { font-size: 17px; }
.modal-b { padding: 20px; overflow: auto; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--radius); box-shadow: var(--shadow-pop); max-width: 420px; animation: tin .18s ease-out; }
.toast.ok { background: #136a33; } .toast.bad { background: #a52d19; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.callout { padding: 12px 14px; border-radius: var(--radius); background: var(--info-soft); color: #0b5568; border: 1px solid #b5dfe9; }
.callout.warn { background: var(--warn-soft); color: #7a4800; border-color: #f1d49b; }
.callout.bad { background: var(--bad-soft); color: #8c2512; border-color: #f2c4bb; }
.summary { display: grid; gap: 6px; }
.summary .li { display: flex; justify-content: space-between; gap: 16px; }
.summary .li.tot { border-top: 1px solid var(--line-strong); padding-top: 8px; margin-top: 4px; font-weight: 700; font-size: 16px; }
.cost-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-2); margin: 8px 0 4px; }
.cost-bar i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend b { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

/* ---------- Documentos imprimibles ---------- */
#print-root { display: none; }
.doc-sheet { background: #fff; color: #111; width: 190mm; margin: 0 auto; padding: 0; font-size: 12px; line-height: 1.4; }
.doc-sheet .dh { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #111; padding-bottom: 12px; margin-bottom: 14px; }
.doc-sheet .dh h1 { font-size: 20px; }
.doc-sheet .dh .t { text-align: right; }
.doc-sheet .dh .t .n { font-size: 20px; font-weight: 700; }
.doc-sheet .box { border: 1px solid #bbb; padding: 8px 10px; border-radius: 3px; margin-bottom: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; }
.doc-sheet table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.doc-sheet th { text-align: left; background: #eee; padding: 6px 8px; font-size: 11px; border-bottom: 1px solid #999; }
.doc-sheet td { padding: 6px 8px; border-bottom: 1px solid #ddd; }
.doc-sheet .num { text-align: right; }
.doc-sheet .tot { margin-left: auto; width: 240px; }
.doc-sheet .tot div { display: flex; justify-content: space-between; padding: 3px 0; }
.doc-sheet .tot .g { border-top: 2px solid #111; font-size: 15px; font-weight: 700; margin-top: 4px; padding-top: 6px; }
.doc-sheet .firmas { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 60px; }
.doc-sheet .firmas div { border-top: 1px solid #111; padding-top: 4px; text-align: center; }
.doc-sheet .pie { margin-top: 24px; text-align: center; color: #555; font-size: 11px; }
.doc-preview { background: #d9dee6; padding: 20px; border-radius: var(--radius); overflow: auto; }
.doc-preview .doc-sheet { padding: 12mm; box-shadow: var(--shadow-pop); min-height: 120mm; }
.labels-sheet { display: flex; flex-wrap: wrap; gap: 3mm; background: #fff; }
.label { background: #fff; color: #000; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 2.5mm; break-inside: avoid; page-break-inside: avoid; }
.label .code { align-self: flex-end; max-width: 100%; }
.label .code svg { display: block; max-width: 100%; height: auto; }
.label .lines div { line-height: 1.15; word-break: break-word; }
.label .row-l { display: flex; justify-content: space-between; gap: 2mm; align-items: flex-end; height: 100%; }
.label-preview { background: #d9dee6; padding: 24px; border-radius: var(--radius); display: grid; place-items: center; min-height: 200px; }
.label-preview .label { box-shadow: var(--shadow-pop); }

@media print {
  body { background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  .doc-sheet { width: auto; }
  .no-print { display: none !important; }
}

@media (max-width: 1100px) {
  :root { --side-w: 64px; }
  .side-head span, .nav a span, .side-foot { display: none; }
  .nav a { justify-content: center; padding: 11px; }
  .g-main { grid-template-columns: minmax(0, 1fr); }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .content { padding: 14px; }
  .top { padding: 0 12px; }
  .g2, .g3, .g4, .form-grid, .form-grid.c3, .form-grid.c4 { grid-template-columns: minmax(0, 1fr); }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .bars-h .r { grid-template-columns: 100px 1fr 80px; }
  .top .btn span { display: none; }
}
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* Etiquetas en rollo: una por página */
.labels-sheet.roll { display: block; gap: 0; }
.labels-sheet.roll .label { page-break-after: always; break-after: page; }

/* Ajustes finales */
.search input, .search input[type="search"] { padding-left: 38px !important; }
.search svg { pointer-events: none; }
.icon-btn svg, .btn.icon-btn svg { width: 16px; height: 16px; flex: none; }
.legend b { vertical-align: -1px; }

/* ---------- Celular y tablet (ajustes de uso táctil) ---------- */
.g2 > *, .g3 > *, .g4 > *, .g-main > *, .form-grid > *, .kpis > * { min-width: 0; }
.card { min-width: 0; max-width: 100%; }
.card-b svg, .card svg.chart { max-width: 100%; height: auto; }
.modal { max-width: 100%; }
@media (max-width: 1100px) {
  .tbl-wrap, .card-b.flush { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  input, select, textarea { font-size: 16px; } /* evita el zoom automático en iPhone */
  .btn, .tabs a { min-height: 40px; }
}
@media (max-width: 720px) {
  .app { display: block; padding-bottom: 66px; }
  .side { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; top: auto; height: 58px; flex-direction: row;
    border-top: 1px solid rgba(255,255,255,.1); padding-bottom: env(safe-area-inset-bottom); box-sizing: content-box; }
  .side-head, .side-foot { display: none; }
  .nav { display: flex; flex: 1; padding: 6px; gap: 2px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: 0 0 auto; flex-direction: column; justify-content: center; gap: 2px; margin: 0; padding: 4px 10px; min-width: 62px; font-size: 10.5px; }
  .nav a span { display: block; }
  .page-head { align-items: flex-start; }
  .page-head h1 { font-size: 21px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; } .kpi .v { font-size: 20px; }
  .search { width: auto; flex: 1; }
  .top { gap: 8px; }
  .card-b { padding: 14px; }
  .modal-wrap, .overlay { padding: 0; }
  .toasts, #toasts { bottom: 74px; }
}
@media (max-width: 380px) { .kpis { grid-template-columns: 1fr; } }
.label-preview { overflow: auto; max-width: 100%; }
@media (max-width: 720px) { .label-preview { padding: 12px; place-items: start; } }
.tbl td.num, .tbl td.act, .tbl td b { white-space: nowrap; }
@media (max-width: 720px) { .search input::placeholder { font-size: 14px; } }
@media (max-width: 1100px) { .grid[style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; } }