:root {
  --brown: #4D3921;        /* UVICA wordmark brown */
  --green: #74AB42;        /* UVICA leaf green */
  --lime: #A0BF38;         /* UVICA accent lime */
  --green-dark: #5f8f34;
  --bg: #4D3921;           /* topbar / dark ground = brand brown */
  --panel: #ffffff;
  --muted: #6f6a5d;        /* warm neutral */
  --border: #e7e4d8;       /* warm hairline */
  --primary: #74AB42;
  --primary-dark: #5f8f34;
  --ok: #16a34a;
  --err: #dc2626;
  --soft: #f7f7f1;         /* warm off-white */
  --heading: "Montserrat", system-ui, sans-serif;
  --body: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--body);
  color: #2c2a22;
  background: var(--soft);
}
h1, h2, h3, h4, .brand { font-family: var(--heading); }
.hidden { display: none !important; }
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
}
button:hover { background: var(--primary-dark); }
button.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); }
button.ghost:hover { background: rgba(255,255,255,.12); }

/* Login */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1100px 560px at 8% -12%, #7fb549 0%, transparent 55%),
              linear-gradient(140deg, #3f6b25, #4D3921 78%);
}
.login-shell {
  width: 100%; max-width: 860px; display: grid; grid-template-columns: 1fr 1fr;
  background: #fff; border-radius: 20px; overflow: hidden;
  box-shadow: 0 30px 70px rgba(0,0,0,.45);
}

/* Brand panel */
.login-brand {
  background: linear-gradient(158deg, #7fb549 0%, #5f8f34 55%, #3f6b25 100%);
  color: #fff; padding: 42px 36px; display: flex; flex-direction: column; gap: 14px;
  position: relative; overflow: hidden;
}
.login-brand::after {
  content: ""; position: absolute; right: -60px; bottom: -60px; width: 220px; height: 220px;
  border-radius: 50%; background: rgba(160,191,56,.35); filter: blur(10px);
}
.brand-logo {
  background: #fff; border-radius: 14px; padding: 14px 18px; align-self: flex-start;
  box-shadow: 0 8px 20px rgba(0,0,0,.18);
}
.brand-logo img { display: block; height: 46px; width: auto; }
.brand-tag { margin: 4px 0 0; font-style: italic; color: #eaf3da; font-size: 14px; font-family: var(--body); }
.login-brand h2 { margin: 14px 0 0; font-size: 22px; font-weight: 700; position: relative; }
.brand-lead { margin: 0; color: #eaf3da; font-size: 14px; line-height: 1.55; font-family: var(--body); position: relative; }
.brand-points { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 10px; position: relative; }
.brand-points li { position: relative; padding-left: 26px; font-size: 14px; color: #f3f8ea; font-family: var(--body); }
.brand-points li::before {
  content: "✓"; position: absolute; left: 0; top: -1px; width: 18px; height: 18px;
  background: #fff; color: #5f8f34; border-radius: 50%; font-size: 11px; font-weight: 800;
  display: grid; place-items: center;
}
.brand-foot { margin-top: auto; font-size: 12px; color: #dcecc9; letter-spacing: .3px; font-family: var(--body); position: relative; font-variant-numeric: tabular-nums; }

/* Form panel */
.login-form { padding: 44px 40px; display: flex; flex-direction: column; gap: 15px; }
.login-form h1 { margin: 0; font-size: 24px; }
.form-sub { margin: -8px 0 8px; color: var(--muted); font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #334155; }
.field input {
  padding: 12px 13px; border: 1px solid var(--border); border-radius: 10px; font-size: 15px;
  transition: border-color .15s, box-shadow .15s; width: 100%;
}
.field input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(116,171,66,.22);
}
.pw-wrap { position: relative; display: block; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; color: var(--primary); padding: 6px 10px; font-size: 13px; border-radius: 8px;
}
.pw-toggle:hover { background: #eef4e3; }
.form-row { display: flex; justify-content: space-between; align-items: center; }
.remember { display: flex; align-items: center; gap: 7px; font-size: 13px; color: #475569; font-weight: 500; cursor: pointer; }
.btn-primary {
  margin-top: 4px; padding: 12px; font-size: 15px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-primary:disabled { opacity: .7; cursor: default; }
.spinner {
  width: 16px; height: 16px; border: 2.5px solid rgba(255,255,255,.5);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error {
  color: var(--err); font-size: 14px; margin: 0; padding: 10px 12px;
  background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px;
}
.login-foot { margin: 6px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

@media (max-width: 720px) {
  .login-shell { grid-template-columns: 1fr; max-width: 420px; }
  .login-brand { display: none; }
}

/* Topbar */
.topbar {
  background: var(--bg); color: #fff; display: flex; justify-content: space-between;
  align-items: center; padding: 12px 24px;
  background-image: linear-gradient(90deg, #4D3921, #3c2d1a);
}
.brand { font-weight: 700; letter-spacing: .5px; display: flex; align-items: center; gap: 12px; }
.topbar-logo {
  height: 30px; width: auto; background: #fff; padding: 5px 9px; border-radius: 8px;
}
.brand span { color: #dbe8c4; font-weight: 600; font-size: 15px; }
.user-box { display: flex; align-items: center; gap: 14px; font-size: 14px; }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px;
}
.card .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .5px; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* KPI cards */
.card.kpi { transition: transform .1s, box-shadow .1s; }
.card.kpi[onclick] { cursor: pointer; }
.card.kpi[onclick]:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,.08); }
.card.kpi.action { border-left: 4px solid var(--primary); }
.card.kpi.action .value { color: var(--green-dark); }
.card.kpi.warn { border-left: 4px solid #f59e0b; }
.card.kpi.warn .value { color: #b45309; }

/* Monthly bar chart */
.seg { display: inline-flex; gap: 4px; }
.seg-btn { background: #eef2e6; color: #4a6b25; border: 1px solid var(--border); padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.seg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chart-legend { display: flex; gap: 18px; font-size: 13px; color: var(--muted); margin: 2px 2px 12px; }
.chart-legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw-total { background: var(--green); }
.sw-canc { background: #3b82f6; }
.sw-saldo { background: #f59e0b; }
.barchart { display: flex; gap: 22px; align-items: flex-end; height: 230px; padding: 8px 6px 0; overflow-x: auto; border-bottom: 1px solid var(--border); }
.bc-month { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1 0 auto; min-width: 64px; }
.bc-bars { display: flex; align-items: flex-end; justify-content: center; gap: 2px; height: 190px; }
.bc-bar { width: 18px; border-radius: 4px 4px 0 0; min-height: 2px; transition: height .3s; cursor: default; }
.bc-bar.total { background: var(--green); }
.bc-bar.canc { background: #3b82f6; }
.bc-bar.saldo { background: #f59e0b; }
.bc-bar:hover { filter: brightness(1.08); }
.bc-label { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Saldo split (Dólares / Soles) */
.saldo-split { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.saldo-split > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.saldo-split .cur-tag { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.saldo-split .cur-val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Invoice consultation table */
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type=search] { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; min-width: 220px; }
.filters select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; font-size: 14px; }
.sub-ruc { color: var(--muted); font-size: 12px; }
/* Long-text cells: clipped to keep every column on screen; click to expand. */
td.clip { max-width: 230px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; cursor: zoom-in; }
td.clip.open { white-space: normal; max-width: none; cursor: zoom-out;
  overflow: visible; }
.sunat-dots { display: inline-flex; gap: 4px; }
td.num.neg { color: var(--err); }
.badge.pay-pend { background: #fef3c7; color: #92400e; }
.badge.pay-part { background: #dbeafe; color: #1e40af; }
.badge.pay-ok { background: #dcfce7; color: #166534; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.panel-head h2 { margin: 0; font-size: 17px; }
.panel-head input[type=search] { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; min-width: 240px; }

.upload-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.upload-row input[type=file] { font-size: 14px; }
#upload-status { font-size: 14px; color: var(--muted); }
.import-result { margin-top: 14px; padding: 12px; border-radius: 8px; background: var(--soft); font-size: 14px; }
.import-result ul { margin: 6px 0 0; padding-left: 18px; color: var(--err); }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--soft); }
.badge { padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.open { background: #e8f0d8; color: #4a6b25; }
.badge.closed { background: #e9e7df; color: #6f6a5d; }
.badge.muted { background: #eef0f2; color: #6b7280; }

/* Reconciliation: orders ↔ emailed invoices */
.panel-hint { color: var(--muted); font-size: 13px; margin: -4px 0 12px; }
.expander {
  background: none; border: none; cursor: pointer; font-size: 13px;
  color: var(--primary); padding: 0 4px; line-height: 1;
}
tr.recon-detail > td { background: var(--soft); padding: 0 12px 12px 12px; }
tr.recon-detail:hover { background: var(--soft); }
table.subtable { margin: 6px 0 2px; background: var(--card, #fff); border-radius: 8px; }
table.subtable th { font-size: 11px; }
table.subtable td, table.subtable th { padding: 7px 10px; }
.link { color: var(--primary); cursor: pointer; text-decoration: underline; background: none; padding: 0; font-weight: 600; }
.empty { color: var(--muted); padding: 16px; text-align: center; }

/* Tabs */
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent; color: #cbd5e1; border: none; border-radius: 8px;
  padding: 8px 14px; font-weight: 600; font-size: 14px;
}
.tab:hover { background: rgba(255,255,255,.1); color: #fff; }
.tab.active { background: var(--primary); color: #fff; }
.pill { background: #ef4444; color: #fff; border-radius: 999px; padding: 1px 7px; font-size: 11px; margin-left: 4px; }
.view { display: block; }

button.ghost.dark { color: var(--primary); border-color: var(--primary); }
.file-lbl { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); font-weight: 600; gap: 4px; }

/* State badges */
.state { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.state.MATCH_PENDING_APPROVAL { background: #fef3c7; color: #92400e; }
.state.MATCH_FAILED { background: #fee2e2; color: #991b1b; }
.state.STRUCTURE_OK, .state.SUNAT_OK { background: #dbeafe; color: #1e40af; }
.state.APPROVED { background: #dcfce7; color: #166534; }
.state.REJECTED, .state.ERROR { background: #fee2e2; color: #991b1b; }
.state.DONE, .state.SENT_TO_ERP { background: #e0e7ff; color: #3730a3; }

/* Detail drawer */
.drawer { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 22px; }
.drawer h3 { margin: 0 0 4px; }
.drawer .kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 10px 20px; margin: 14px 0; }
.drawer .kv div { font-size: 14px; }
.drawer .kv .k { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.drawer .kv .kv-wide { grid-column: 1 / -1; }
.drawer .kv .kv-wide .link { margin-left: 6px; }
/* The order reference is THE field the reviewer compares against candidates —
   give it a highlighted chip so it jumps out of the kv grid. */
.ref-chip { display: inline-block; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700; font-size: 13.5px; color: var(--brown);
  background: #eef6e2; border: 1.5px solid var(--primary);
  padding: 2px 10px; border-radius: 8px; letter-spacing: .02em; }
.checks { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--err); }
.dot.warn { background: #d97706; }
.dot.skip { background: #cbd5e1; }
.cand { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 8px 0; }
.cand.best { border-color: var(--primary); background: #f1f6e8; }
/* every XML field agrees with the order → paint it clearly OK */
.cand-ok { border-color: #16a34a; border-width: 1.5px; background: #ecfdf3;
  box-shadow: 0 0 0 1px #16a34a inset; }
.cmp { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; }
.cmp-chip { font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 4px; }
.cmp-chip.ok { background: #dcfce7; color: #166534; }
.cmp-chip.warn { background: #fef3c7; color: #92400e; }
/* field-by-field match grid: Factura ↔ Orden, with the fuzzy weight of each */
.mgrid { margin: 9px 0 3px; border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; background: var(--panel); }
.mg-row { display: grid; grid-template-columns: 84px 1fr 20px 1fr 78px;
  align-items: center; gap: 6px; padding: 5px 10px; font-size: 12.5px;
  border-top: 1px solid var(--hair-2, #efece0); }
.mg-row:first-child { border-top: 0; }
.mg-head { background: var(--panel-2, #f6f4ea); color: var(--muted);
  font-size: 10.5px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.mg-f { color: var(--muted); font-weight: 700; }
.mg-v { font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.mg-ic { text-align: center; font-weight: 900; }
.mg-ic.ok { color: #16a34a; }
.mg-ic.no { color: #c9c4b4; }
.mg-w { text-align: right; color: var(--muted); font-size: 11px; display: flex;
  flex-direction: column; align-items: flex-end; line-height: 1.25; }
.mg-w b { color: var(--primary); font-variant-numeric: tabular-nums; }
.mg-det { font-size: 10px; color: var(--muted); }
.mg-row.on { background: color-mix(in srgb, var(--primary) 7%, transparent); }
.mg-row.on .mg-f { color: var(--brown); }
.mg-row.off .mg-v { color: var(--muted); }
@media (max-width: 520px) {
  .mg-row { grid-template-columns: 68px 1fr 18px 1fr 54px; font-size: 11.5px; padding: 5px 8px; }
}
/* recurring monthly cost → provision without an order */
.recur-banner { display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: #eef6ff; border: 1px solid #bcdcff; border-radius: 10px; padding: 12px 14px;
  margin: 12px 0; font-size: 13.5px; }
.recur-banner .approve { white-space: nowrap; }
.sin-orden-last { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border);
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
button.approve.secondary { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.approve.secondary:hover { background: var(--soft); color: var(--body); }
.approve-dialog { max-width: 800px; width: 92%; display: flex; flex-direction: column; max-height: 88vh; }
.approve-body { padding: 16px 20px; overflow-y: auto; }
.approve-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--border); }
.approve-foot .approve { min-width: 220px; }
.cand .cand-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.cand .score { font-weight: 700; color: var(--primary); }
.cand .reasons { color: var(--muted); font-size: 13px; margin-top: 4px; }
/* partial-billing gauge: a ring split into provisioned (blue) + this invoice
   (green) + free remainder (track). Background is set inline per candidate. */
.oring { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.oring-ring { position: relative; width: 46px; height: 46px; border-radius: 50%;
  flex: 0 0 auto; background: var(--border); }
.oring-ring::before { content: ""; position: absolute; inset: 6px; border-radius: 50%;
  background: var(--panel, #fff); }
.oring-pct { position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 800; color: var(--primary);
  font-variant-numeric: tabular-nums; }
.oring-meta { display: flex; flex-direction: column; gap: 2px; font-size: 12px;
  color: var(--muted); }
.oring-leg { display: inline-flex; align-items: center; gap: 6px; }
.oring-leg b { color: var(--brown); font-variant-numeric: tabular-nums; }
.oring-leg i { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.oring-leg i.d-blue { background: #2c6e9b; }
.oring-leg i.d-green { background: var(--primary); }
.oring-leg i.d-amber { background: #d97706; }
.oring-over { color: #d97706; font-weight: 700; }
.cand .mtype { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.drawer-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
button.danger { background: var(--err); }
button.danger:hover { background: #b91c1c; }
button.approve { background: var(--ok); }
button.approve:hover { background: #15803d; }
.close-x { cursor: pointer; color: var(--muted); font-size: 22px; line-height: 1; margin-left: auto; }
/* Invoice detail modal — opens over the worklist, easy to go back */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(20, 32, 24, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; }
.modal-dialog { width: 100%; max-width: 780px; margin: auto; padding-top: 0;
  max-height: calc(100vh - 80px); overflow-y: auto;
  box-shadow: 0 18px 50px rgba(10, 20, 14, .35); }
body.modal-open { overflow: hidden; }
.modal-dialog.textview { background: #fff; border: 1px solid var(--border);
  border-radius: 12px; max-width: 680px; padding: 0; overflow: hidden; }
.textview-head { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel, #fff); }
.textview-head h3 { margin: 0; font-size: 15px; }
.textview-body { margin: 0; padding: 18px; white-space: pre-wrap; word-break: break-word;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--brown, #333); max-height: 60vh; overflow-y: auto; }
.modal-bar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0;
  margin: 0 -22px 14px; padding: 13px 18px; background: var(--panel, #fff);
  border-bottom: 1px solid var(--border); border-radius: 12px 12px 0 0; z-index: 2; }
.modal-back { cursor: pointer; border: 1px solid var(--primary); background: var(--primary);
  color: #fff; font-weight: 700; font-size: 13px; padding: 7px 14px; border-radius: 8px; }
.modal-back:hover { filter: brightness(.95); }
.modal-back-hint { color: var(--muted); font-size: 12.5px; }
.erp-pre { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 8px; overflow-x: auto; font-size: 12px; margin-top: 10px; }

/* --- Facturas por procesar (worklist) --- */
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.bad { background: #fde2e1; color: #9b2c2c; }
.pending-counts { display: flex; gap: 8px; flex-wrap: wrap; }
.pending-counts .pc { font-size: 12.5px; font-weight: 600; padding: 3px 10px;
  border-radius: 999px; background: #eef0f2; color: #55606c; }
.pending-counts .pc.warn { background: #fef3c7; color: #92400e; }
.pending-counts .pc.bad { background: #fde2e1; color: #9b2c2c; }
.pending-counts .pc.total { background: #e6efe6; color: #2f6a43; }
.pending-table tr.clickable { cursor: pointer; }
.pending-table tr.clickable:hover td { background: #f6faf5; }
.pending-table .desc-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.pending-table .fecha-cell { white-space: nowrap; }
.pending-table .agedays { margin-left: 6px; font-size: 11px; font-weight: 700;
  color: var(--muted); background: #eef2ee; padding: 1px 6px; border-radius: 999px; }
/* four boxes, oldest first; each scrolls on its own with a sticky header */
.pending-boxes { display: flex; flex-direction: column; gap: 16px; }
.pbox { border: 1px solid #e2e8e0; border-radius: 12px; overflow: hidden; background: var(--panel); }
.pbox-head { display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px; font-weight: 700; font-size: 12.5px; letter-spacing: .03em;
  text-transform: uppercase; color: #55606c; background: #f0f3ef;
  border-bottom: 1px solid #e2e8e0; }
.pbox-count { font-size: 12px; background: #fff; border: 1px solid #dfe5df;
  color: #55606c; padding: 1px 9px; border-radius: 999px; }
.pbox-bad .pbox-head { background: #fde2e1; color: #9b2c2c; }
.pbox-bad .pbox-count { background: #fff; color: #9b2c2c; border-color: #f3c9c7; }
.pbox-warn .pbox-head { background: #fef3c7; color: #92400e; }
.pbox-warn .pbox-count { background: #fff; color: #92400e; border-color: #f0dfa6; }
.pbox-scroll { max-height: 40vh; overflow-y: auto; }
.pbox-scroll table { margin: 0; }
.pbox-scroll thead th { position: sticky; top: 0; z-index: 2; background: #fff;
  box-shadow: inset 0 -1px 0 #e2e8e0; }
.pbox-empty { padding: 16px; color: var(--muted); font-size: 13px; text-align: center; }
.pbox-more { padding: 8px 14px; font-size: 12px; color: var(--muted);
  border-top: 1px solid #eef0f2; background: #fafbfa; }
.pending-table td .sub { color: var(--muted); font-size: 11.5px; }

/* --- Revisión y envío (provisión) --- */
.review-panel { margin-top: 6px; }
.rev-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin: 6px 0 14px; }
.rev-grid .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.rev-panel h5, .review-panel h5 { margin: 14px 0 6px; font-size: 13px; }
.rev-lines { display: flex; flex-direction: column; gap: 6px; }
.rev-line { display: flex; flex-direction: column; gap: 7px;
  background: #f6faf5; border: 1px solid #e2e8e0; border-radius: 8px; padding: 8px 12px; font-size: 13.5px; }
.rev-top { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.rev-desc { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rev-cta { white-space: nowrap; color: var(--muted); }
.conf { font-weight: 700; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; margin-left: 4px; }
.conf.ok { background: #dcfce7; color: #166534; }
.conf.warn { background: #fef3c7; color: #92400e; }
/* clickable top-3 accounts */
.cta-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cta-chip { display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: #fff; border: 1px solid #d5ddd4; border-radius: 999px; padding: 3px 10px;
  font-size: 12px; color: var(--ink); }
.cta-chip .s { color: var(--muted); }
.cta-chip .pct { font-weight: 700; color: #166534; font-variant-numeric: tabular-nums; }
.cta-chip:hover { border-color: var(--accent); }
.cta-chip.on { background: #eaf6ee; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cta-chip.on .s { color: var(--ink); }
/* prominent one-click chips for the high-probability accounts (>50%) */
.cta-sug { display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: #f0fdf4; color: var(--brown); border: 1.5px solid #86c99e;
  border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 700;
  font-family: ui-monospace, Menlo, monospace; }
.cta-sug .s { color: var(--muted); font-weight: 500; font-family: var(--body); font-size: 11px; }
.cta-sug .pct { font-weight: 800; color: #166534; font-variant-numeric: tabular-nums; }
.cta-sug .n { color: var(--muted); font-weight: 500; font-size: 10.5px; }
.cta-sug:hover { border-color: #16a34a; background: #dcfce7; }
.cta-sug.on { background: #bbf7d0; border-color: #16a34a; box-shadow: 0 0 0 1px #16a34a inset; }
.ccosto-input { width: 100%; padding: 10px 12px; border: 1.5px solid #cbd5cb; border-radius: 9px;
  font-size: 14px; box-sizing: border-box; }
.ccosto-input:focus { outline: none; border-color: var(--accent, #2f7d4f); }
.review-panel .hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.review-panel .needs { color: #9b2c2c; font-size: 13px; margin: 10px 0 0; font-weight: 600; }
.review-panel .muted { color: var(--muted); font-weight: 400; }

/* --- Vista de gerencia --- */
button.approve.sm { padding: 5px 12px; font-size: 12.5px; }
#mgmt-table .sub { color: var(--muted); font-size: 11.5px; }
#mgmt-table td.mgmt-act { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }

/* --- Detalle expandible en gerencia --- */
#mgmt-table tr.clickable{cursor:pointer}
#mgmt-table tr.clickable:hover td{background:#f6faf5}
tr.mgmt-detail > td{background:#f3f6f2;padding:14px 16px}
.mgmt-hl{display:grid;grid-template-columns:repeat(4,1fr);gap:12px 20px}
.mgmt-hl .wide{grid-column:span 2}
.mgmt-hl .k{color:var(--muted);font-size:11px;text-transform:uppercase;letter-spacing:.03em;margin-bottom:2px}
.mgmt-hl .sub{color:var(--muted);font-size:11.5px;margin-top:2px}
@media(max-width:720px){.mgmt-hl{grid-template-columns:1fr 1fr}}

/* --- Gerencia: fila compacta + detalle factura×orden --- */
#mgmt-table td{padding:8px 10px}
.caret{color:var(--accent,#2f7d4f);font-weight:700;margin-right:7px;font-size:11px}
tr.mgmt-detail > td{background:#f3f6f2;padding:14px 16px}
.prov-line{display:flex;gap:24px;flex-wrap:wrap;font-size:13px;padding-bottom:10px;margin-bottom:12px;border-bottom:1px solid #dfe6de}
.prov-line .sub{color:var(--muted);font-size:11.5px}
.two-col{display:grid;grid-template-columns:1fr 1fr;gap:18px}
.col h5{margin:0 0 8px;font-size:12px;text-transform:uppercase;letter-spacing:.05em;color:var(--accent,#2f7d4f)}
.hl2{display:grid;grid-template-columns:1fr 1fr;gap:8px 14px;font-size:12.5px}
.hl2 .k, .glosa-row .k{color:var(--muted);font-size:10px;text-transform:uppercase;letter-spacing:.03em;margin-bottom:1px}
.lineas{margin-top:10px;display:flex;flex-direction:column;gap:4px}
.lineas .ln{display:flex;justify-content:space-between;gap:10px;font-size:12px;background:#fff;border:1px solid #e2e8e0;border-radius:6px;padding:5px 9px}
.lineas .ln span:first-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.glosa-row{margin-top:12px;font-size:12px;color:var(--ink)}
@media(max-width:720px){.two-col{grid-template-columns:1fr}.hl2{grid-template-columns:1fr}}

.rev-line-list { margin: 8px 0 0; padding-left: 18px; color: var(--muted);
  font-size: 12.5px; max-height: 180px; overflow-y: auto; }
.rev-line-list li { margin: 2px 0; }

/* Review panel: step cards + fundo suggestion chips */
.rev-step { border: 1.5px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin: 12px 0;
  transition: box-shadow .2s, border-color .2s, background .2s, opacity .2s; }
/* State: todo = orange (falta seleccionar y confirmar), confirmed = blue (✓).
   Each step has its own Confirmar button; order→cuenta→ccosto→resumen+enviar. */
.rev-step.todo      { border-color: #d97706; background: #fffdf5; }
.rev-step.confirmed { border-color: #2563eb; background: #eef4ff; }
.rev-step-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.rev-step-head h5 { margin: 0; }
.rev-step-n { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; }
.rev-step.todo .rev-step-n { background: #d97706; }
.rev-step.confirmed .rev-step-n { background: #2563eb; }
.rev-step-tag { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.rev-step.todo .rev-step-tag { color: #b45309; }
.rev-step.confirmed .rev-step-tag { color: #1d4ed8; }
.step-confirm { margin-top: 10px; }
.confirm-btn { background: #d97706; color: #fff; border: none; border-radius: 8px;
  padding: 8px 16px; font-weight: 700; font-size: 13px; cursor: pointer; }
.confirm-btn:hover:not(:disabled) { background: #b45309; }
.confirm-btn:disabled { cursor: default; opacity: .55; }
.confirm-btn.is-confirmed { background: #2563eb; opacity: 1; }
/* "listo para enviar" summary: UVICA green — visually distinct from the blue
   confirmed steps above it (blue = paso confirmado, green = todo listo). */
.rev-summary { border: 1.5px solid var(--primary); background: #f2f8e9; border-radius: 12px;
  padding: 12px 14px; margin: 12px 0; box-shadow: 0 0 0 3px rgba(116, 171, 66, .15); }
.rev-summary .confirmed-n { background: var(--primary); }
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px;
  margin: 10px 0; font-size: 13px; }
.sum-grid .k { color: var(--muted); font-size: 11px; display: block; }
.sum-grid b { font-family: ui-monospace, Menlo, monospace; }
/* the three main matches, highlighted at the top of the summary */
.sum-main { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 10px 0; padding: 10px 12px; background: #fff; border: 1px solid #cfe3b6;
  border-radius: 8px; }
.sum-main .k { color: var(--muted); font-size: 11px; display: block; margin-bottom: 2px; }
.sum-main b { font-family: ui-monospace, Menlo, monospace; font-size: 14px; color: var(--green-dark); }
.sum-sep { font-weight: 800; font-size: 11.5px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; margin: 12px 0 4px; }
.sum-grid .sub { color: var(--muted); font-size: 11px; }
.sum-lines { display: flex; flex-direction: column; gap: 4px; }
.sum-line { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px;
  padding: 4px 0; border-bottom: 1px dashed var(--border); }
.sum-line .sl-desc { color: var(--brown); }
.sum-line .sl-val { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sum-line .sl-val b { color: var(--ink); }
.ord-summary { padding: 8px 10px; border: 1px solid #dbe6fb; border-radius: 8px;
  background: #fff; margin-bottom: 8px; }
.ord-summary strong { font-family: ui-monospace, Menlo, monospace; }
.ord-summary .sub { color: var(--muted); font-size: 11.5px; }
.fundo-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.fundo-lbl { font-size: 11.5px; font-weight: 700; color: var(--muted); margin-right: 2px; }
.fundo-chip { background: #fff; color: var(--brown); border: 1.5px solid var(--border);
  border-radius: 999px; padding: 4px 11px; font-size: 12px; font-weight: 700;
  font-family: ui-monospace, Menlo, monospace; }
.fundo-chip .s { color: var(--muted); font-weight: 500; font-family: var(--body); font-size: 11px; }
.fundo-chip:hover { border-color: var(--primary); background: #f3f8ec; }
.fundo-chip.on { border-color: var(--primary); background: #eaf3de; box-shadow: 0 0 0 1px var(--primary) inset; }
/* finca (farm) filter chips: predicted farm narrows the lote picker */
.finca-chip { background: #fff8ee; color: var(--brown); border: 1.5px solid #e6c98a;
  border-radius: 999px; padding: 4px 11px; font-size: 12px; font-weight: 700;
  font-family: ui-monospace, Menlo, monospace; cursor: pointer; }
.finca-chip .s { color: var(--muted); font-weight: 500; font-family: var(--body); font-size: 11px; }
.finca-chip .pct { font-weight: 700; color: #b45309; font-variant-numeric: tabular-nums; }
.finca-chip .n { color: var(--muted); font-weight: 500; font-size: 10.5px; }
.finca-chip:hover { border-color: #d97706; background: #fdecc8; }
.finca-chip.on { border-color: #d97706; background: #fbe0a6; box-shadow: 0 0 0 1px #d97706 inset; }
.finca-chip.all { background: #fff; border-color: var(--border); color: var(--muted); }
.finca-chip.all:hover { border-color: var(--primary); color: var(--brown); }
/* manual override search boxes (cuenta / orden) */
.manual-search { margin-top: 8px; }
.manual-search input { width: 100%; box-sizing: border-box; padding: 7px 10px;
  border: 1.5px solid var(--border); border-radius: 8px; font-size: 12.5px;
  font-family: var(--body); background: #fff; }
.manual-search input:focus { outline: none; border-color: var(--primary); }
.order-manual { margin: 8px 0; }
.order-results { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.order-result { display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fafaf7; }
.order-result strong { font-family: ui-monospace, Menlo, monospace; }
.order-result .sub { color: var(--muted); font-size: 11px; }
.order-result .approve { flex: none; padding: 6px 12px; font-size: 12px; }
.ord-cands-lbl { display: block; margin: 10px 0 6px; }
/* multi cost-center via "Agregar" */
.cc-add-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.cc-add-row .ccosto-input { flex: 1; margin: 0; }
.add-btn { flex: none; background: #16a34a; color: #fff; border: none; border-radius: 8px;
  padding: 8px 14px; font-weight: 700; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.add-btn:hover { background: #15803d; }
.ccosto-added { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 2px; }
.cc-chip { display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border: 1px solid #dbe6fb; border-radius: 8px; background: #eef4ff; font-size: 12px; }
.cc-chip .cc-line { color: var(--muted); font-size: 11px; }
.cc-chip b { font-family: ui-monospace, Menlo, monospace; }
.cc-chip .cc-x { margin-left: auto; border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 13px; padding: 0 4px; }
.cc-chip .cc-x:hover { color: var(--err); }
.warn-hint { color: #b45309; }

/* ---- Órdenes: abierto vs provisionado (US$) dashboard ---- */
.sub-note { font-weight: 500; font-size: 12px; color: var(--muted); }
.spend-body { display: flex; flex-direction: column; gap: 14px; }
.spend-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.spend-tiles .stat { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: #fff; }
.stat-k { font-size: 11.5px; color: var(--muted); font-weight: 700; }
.stat-v { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 3px 0; }
.stat-v.prov { color: #0e7490; }
.stat-v.open { color: #b45309; }
.stat-s { font-size: 11px; color: var(--muted); }
.spend-cols { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; }
@media (max-width: 780px) { .spend-cols, .spend-tiles { grid-template-columns: 1fr; } }
.spend-col h4 { margin: 0 0 8px; font-size: 12.5px; color: var(--brown); }
/* horizontal stacked bars by zone */
.sb { display: flex; flex-direction: column; gap: 7px; }
.sb-row { display: grid; grid-template-columns: 74px 1fr 92px; align-items: center; gap: 8px; }
.sb-lbl { font-size: 12px; color: var(--ink); font-weight: 600; }
.sb-track { background: #f0efe9; border-radius: 5px; overflow: hidden; }
.sb-bar { display: flex; height: 16px; min-width: 2px; }
.sb-seg { display: inline-block; height: 100%; }
.sb-seg.prov { background: #0e7490; }
.sb-seg.open { background: #f59e0b; }
.sb-val { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
/* vertical monthly stacked bars */
.mchart { display: flex; align-items: flex-end; gap: 5px; height: 150px; padding-top: 4px; }
.mc { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.mc-bar { width: 68%; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 3px 3px 0 0; overflow: hidden; }
.mc-seg { width: 100%; }
.mc-seg.prov { background: #0e7490; }
.mc-seg.open { background: #f59e0b; }
.mc-lbl { font-size: 9px; color: var(--muted); margin-top: 3px; transform: rotate(-45deg); white-space: nowrap; }

/* ---- Stacked area chart (Resumen visual) ---- */
.areachart { width: 100%; height: auto; display: block; overflow: visible; }
.areachart .gl { stroke: #ece9df; stroke-width: 1; }
.areachart .gy { fill: #a29b8d; font-size: 10px; text-anchor: end; font-variant-numeric: tabular-nums; }
.areachart .gx { fill: #6f6a5d; font-size: 11px; text-anchor: middle; font-weight: 600; }
.areachart .ar-canc { fill: #0e7490; fill-opacity: .88; }
.areachart .ar-saldo { fill: #f59e0b; fill-opacity: .82; }
.areachart .tl { fill: none; stroke: #0c5a70; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.areachart .td { fill: #fff; stroke: #0c5a70; stroke-width: 2; }
.areachart .tv { fill: #4D3921; font-size: 10.5px; font-weight: 700; text-anchor: middle; font-variant-numeric: tabular-nums; }

/* account predetermined by the goods purchase order */
.oc-cuenta-note { margin: 4px 0 8px; padding: 8px 11px; background: #eef4ff;
  border: 1px solid #cdddfb; border-radius: 8px; font-size: 12.5px; color: var(--brown); }
.oc-cuenta-note b { color: #1d4ed8; font-family: ui-monospace, Menlo, monospace; }

/* design-version selector (topbar) */
.ui-version { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.3);
  border-radius: 6px; padding: 4px 6px; font-size: 12px; }
.ui-version option { color: #222; }

/* Nisira dev-login monitor banner — always visible: green = ok, red = waiting */
.erp-ready { border-radius: 10px; padding: 12px 16px; font-size: 14.5px; }
.erp-ready.ok { background: #eaf6e2; border: 1.5px solid #74AB42; color: #2f5218;
  box-shadow: 0 0 0 3px rgba(116,171,66,.15); }
.erp-ready.bad { background: #fdeceb; border: 1.5px solid #dc2626; color: #8a1c1c;
  box-shadow: 0 0 0 3px rgba(220,38,38,.12); }
.erp-ready code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.erp-ready .sub { color: inherit; opacity: .8; font-size: 12.5px; margin-left: 6px; }

/* management revision note + management action buttons */
.revision-note { background: #fff4e6; border: 1px solid #f5c88a; border-left: 3px solid #d97706;
  color: #7c4a03; border-radius: 8px; padding: 10px 14px; margin: 4px 0 12px; font-size: 14px; }
button.danger.sm { padding: 5px 12px; font-size: 12.5px; }
button.ghost.dark.sm { padding: 5px 12px; font-size: 12.5px; }
#mgmt-table td.mgmt-act { flex-wrap: wrap; }

/* priority bucket: invoices sent back by management */
.pbox-revision { border: 1.5px solid #d97706; box-shadow: 0 0 0 3px rgba(217,119,6,.12); }
.pbox-revision .pbox-head { background: #fff4e6; color: #92400e; }
.pc.revision { background: #fde3c4; color: #92400e; font-weight: 700; }

/* reference (XML) matches the matched order number — confirmation highlight */
.ref-hit { background: #dcfce7; color: #166534; font-weight: 700;
  padding: 1px 7px; border-radius: 5px; }

/* confirmed order tag (step 1) — no re-confirm button */
.ord-confirmed-tag { color: #166534; font-weight: 700; font-size: 13.5px;
  background: #dcfce7; padding: 5px 12px; border-radius: 6px; display: inline-block; }

/* toast notifications (non-blocking, auto-dismiss) */
#toast-host { position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 4000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { padding: 11px 20px; border-radius: 10px; font-weight: 600; font-size: 14.5px;
  color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.2); opacity: 0; transform: translateY(-12px);
  transition: opacity .28s, transform .28s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { background: #16a34a; }
.toast-warn { background: #ea8a1e; }
.toast-err { background: #dc2626; }

/* loading state for the pending buckets */
.loading-box { display:flex; align-items:center; gap:10px; justify-content:center;
  padding:40px 16px; color:var(--muted); font-size:15px; }
.loading-box.err { color:var(--err); }
.loading-box .spin { width:18px; height:18px; border:2.5px solid var(--border);
  border-top-color:var(--primary); border-radius:50%; animation:spin .7s linear infinite; display:inline-block; }
