:root {
  --navy: #0f2f57;
  --navy-2: #163d6e;
  --blue: #1d4f8c;
  --blue-soft: #e8eef7;
  --red: #bc2633;
  --red-soft: #fbe9eb;
  --ink: #1f2430;
  --muted: #667085;
  --line: #e3e7ee;
  --bg: #f4f6fa;
  --card: #ffffff;
  --green: #12805c;
  --green-soft: #e3f5ee;
  --amber: #b25e09;
  --amber-soft: #fdf1e1;
  --gray-soft: #eef0f4;
  --violet: #5b3fb5;
  --violet-soft: #efeafc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); display: flex; min-height: 100vh; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--navy); color: #c9d5e6;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { background: #fff; margin: 16px 16px 6px; border-radius: 8px; padding: 10px 12px; }
.brand img { width: 100%; display: block; }
.brand-sub { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #8fa6c4; padding: 4px 20px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; color: #c9d5e6; padding: 10px 12px;
  border-radius: 8px; margin-bottom: 2px; font-weight: 500; border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: var(--red); }
.sidebar .ic { width: 20px; text-align: center; opacity: .85; font-size: 15px; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d93b2; padding: 16px 12px 6px; }
.sidebar-foot { padding: 14px 20px; font-size: 12px; color: #8fa6c4; border-top: 1px solid rgba(255,255,255,.08); }

/* ---------- layout ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--line); padding: 14px 28px;
  display: flex; align-items: center; gap: 16px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 650; color: var(--navy); }
.crumbs { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.menu-btn { display: none; }
.view { padding: 24px 28px 48px; max-width: 1500px; width: 100%; }
.print-header { display: none; }

/* ---------- elements ---------- */
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; line-height: 1.2;
}
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: #a11f2b; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:hover { background: var(--navy-2); }
.btn-outline { background: #fff; color: var(--navy); border-color: #cfd6e2; }
.btn-outline:hover { background: var(--blue-soft); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--gray-soft); color: var(--ink); }
.btn-danger { background: #fff; color: var(--red); border-color: #efc2c7; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 5px 9px; font-size: 12.5px; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 18px; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.btn-icon:hover { background: var(--gray-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card-h h3 { margin: 0; font-size: 15px; color: var(--navy); font-weight: 650; }
.card-h .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-b { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.g-2 { grid-template-columns: 1.4fr 1fr; }
.g-2e { grid-template-columns: 1fr 1fr; }
.mt { margin-top: 16px; }

.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--blue); }
.kpi.red::before { background: var(--red); }
.kpi.amber::before { background: #e08a1e; }
.kpi.green::before { background: var(--green); }
.kpi.violet::before { background: var(--violet); }
.kpi .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi .val { font-size: 24px; font-weight: 700; margin-top: 6px; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { border-color: #c4cfdf; }

/* ---------- tables ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.toolbar .grow { flex: 1; }
.input, select.input, textarea.input {
  border: 1px solid #cfd6e2; border-radius: 8px; padding: 8px 10px; font: inherit; color: var(--ink); background: #fff; min-width: 0;
}
.input:focus { outline: 2px solid rgba(29, 79, 140, .25); border-color: var(--blue); }
.search { min-width: 240px; padding-left: 32px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23667085' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3.5 3.5'/%3E%3C/svg%3E") no-repeat 10px center; }
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  background: #f8f9fc; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; font-weight: 650; user-select: none;
}
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: var(--navy); }
.tbl td { padding: 9px 12px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
.tbl tbody tr:hover { background: #fafbfd; }
.tbl tr.clickable { cursor: pointer; }
.tbl .num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tfoot td { font-weight: 700; background: #f8f9fc; border-top: 2px solid var(--line); }
.tbl .acts { white-space: nowrap; text-align: right; }
.tbl .acts .btn-icon { font-size: 15px; padding: 3px 6px; }
.tbl .muted, .muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 8px; padding: 10px 18px; justify-content: flex-end; color: var(--muted); font-size: 13px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; white-space: nowrap; letter-spacing: .02em; }
.b-PAGADA { background: var(--green-soft); color: var(--green); }
.b-PENDIENTE { background: var(--blue-soft); color: var(--blue); }
.b-PARCIAL { background: var(--amber-soft); color: var(--amber); }
.b-VENCIDA { background: var(--red-soft); color: var(--red); }
.b-ANULADA { background: var(--gray-soft); color: #586174; text-decoration: line-through; }
.b-POR_EMITIR { background: var(--violet-soft); color: var(--violet); }
.b-NOTA_CREDITO { background: #e6f4f8; color: #136b82; }
.b-OFICIAL { background: var(--blue-soft); color: var(--navy); }
.b-OPERATIVO { background: #fff4e5; color: #8a4b00; }
.b-INACTIVO { background: var(--gray-soft); color: var(--muted); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid #cfd6e2; background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 12.5px; cursor: pointer; font-weight: 600; color: #475066; }
.chip:hover { border-color: var(--blue); }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip .n { opacity: .7; margin-left: 4px; font-weight: 500; }

/* ---------- charts ---------- */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 130px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 14px; background: #f0f2f6; border-radius: 4px; overflow: hidden; display: flex; }
.bar-fill { height: 100%; background: var(--blue); }
.bar-fill.red { background: var(--red); }
.bar-row .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.aging { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.aging .cell { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.aging .cell .t { font-size: 11.5px; color: var(--muted); text-transform: uppercase; font-weight: 650; letter-spacing: .04em; }
.aging .cell .a { font-size: 16px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.aging .cell .p { height: 5px; border-radius: 3px; background: #f0f2f6; margin-top: 8px; overflow: hidden; }
.aging .cell .p span { display: block; height: 100%; }

.cols { display: flex; align-items: flex-end; gap: 10px; height: 210px; padding-top: 10px; }
.cols .c { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.cols .pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.cols .pair div { width: 42%; max-width: 18px; border-radius: 3px 3px 0 0; min-height: 2px; }
.cols .c .m { font-size: 11px; color: var(--muted); }
.col-tip { position: relative; }

/* ---------- forms / modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 25, 45, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 5vh 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal-h { padding: 16px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-h h2 { margin: 0; font-size: 17px; color: var(--navy); }
.modal-h .btn-icon { margin-left: auto; }
.modal-b { padding: 18px 22px; }
.modal-f { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafbfd; border-radius: 0 0 12px 12px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; font-weight: 650; color: #3b4356; margin-bottom: 5px; }
.field .input { width: 100%; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.req::after { content: " *"; color: var(--red); }
.section-t { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--blue); font-weight: 700; border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-top: 6px; }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.alert-warn { background: var(--amber-soft); color: #7a4306; }
.alert-err { background: var(--red-soft); color: #8c1b25; }
.alert-info { background: var(--blue-soft); color: var(--navy); }
.seg { display: inline-flex; border: 1px solid #cfd6e2; border-radius: 8px; overflow: hidden; }
.seg label { padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 13px; border-right: 1px solid #cfd6e2; margin: 0; color: #475066; }
.seg label:last-child { border-right: none; }
.seg input { display: none; }
.seg input:checked + span { color: #fff; }
.seg label:has(input:checked) { background: var(--navy); color: #fff; }

.alloc td { padding: 6px 10px; }
.alloc .input { width: 150px; text-align: right; padding: 6px 8px; }
.totbox { display: flex; gap: 22px; justify-content: flex-end; padding: 10px 4px 0; font-size: 13.5px; }
.totbox b { font-variant-numeric: tabular-nums; }

#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.2); font-size: 13.5px; max-width: 380px; animation: tin .2s ease-out; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- proveedor detalle ---------- */
.prov-head { display: flex; gap: 18px; align-items: flex-start; padding: 18px; flex-wrap: wrap; }
.prov-avatar { width: 54px; height: 54px; border-radius: 12px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px; flex-shrink: 0; }
.prov-head h2 { margin: 0; font-size: 19px; color: var(--navy); }
.prov-meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 6px; }
.prov-head .right { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 18px; overflow-x: auto; }
.tabs button { background: none; border: none; padding: 12px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--navy); border-bottom-color: var(--red); }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 24px; }
.info-grid .k { font-size: 11.5px; text-transform: uppercase; color: var(--muted); font-weight: 650; letter-spacing: .04em; }
.info-grid .v { margin-top: 3px; }

.stmt-h { display: flex; justify-content: space-between; gap: 20px; padding: 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.stmt-h h3 { margin: 0 0 4px; color: var(--navy); }
.stmt-tot { display: grid; grid-template-columns: auto auto; gap: 4px 18px; font-size: 13.5px; }
.stmt-tot .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.stmt-section { padding: 12px 18px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--blue); }

/* ---------- login ---------- */
body.auth-locked .sidebar, body.auth-locked .main { visibility: hidden; }
.login-back { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(135deg, var(--navy) 0%, #1d4f8c 60%, #2a2f45 100%); }
.login-card { background: #fff; width: 100%; max-width: 400px; border-radius: 14px; padding: 30px 28px; box-shadow: 0 24px 60px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 14px; }
.login-card img { width: 100%; max-width: 300px; align-self: center; }
.login-sub { text-align: center; color: var(--muted); font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase; margin-top: -6px; border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.login-card .field .input { width: 100%; padding: 10px 12px; }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; text-align: center; }
.user-box { display: flex; gap: 10px; align-items: center; color: #fff; }
.u-av { width: 34px; height: 34px; border-radius: 50%; background: var(--red); display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0; }
.user-acts { margin-top: 8px; }
.user-acts a { color: #c9d5e6; }

@media (max-width: 1100px) {
  .g-2, .g-2e { grid-template-columns: 1fr; }
  .aging { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
  body.nav-open .sidebar { left: 0; }
  .menu-btn { display: block; }
  .view { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .topbar-actions .btn-outline { display: none; }
  .form { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 110px 1fr 100px; }
  .search { min-width: 0; width: 100%; }
}

@media print {
  body { background: #fff; display: block; }
  .sidebar, .topbar, .toolbar, .no-print, .acts, .pager, .tabs, #toasts, .modal-back { display: none !important; }
  .view { padding: 0; max-width: none; }
  .print-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid var(--navy); padding-bottom: 10px; margin-bottom: 14px; font-size: 12px; text-align: right; }
  .print-header img { height: 48px; }
  .card { box-shadow: none; border: none; }
  .tbl th, .tbl td { padding: 4px 6px; font-size: 11px; }
  .badge { padding: 0; background: none !important; }
  .kpi .val { font-size: 16px; }
  tr { page-break-inside: avoid; }
}
