:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --ink: #0f1512;
  --ink-2: #2a332f;
  --muted: #66716c;
  --line: #e2e8e5;
  --line-strong: #cfd8d3;
  --accent: #00e676;
  --accent-hover: #13c76a;
  --accent-strong: #00a65a;
  --accent-ink: #04241a;
  --accent-soft: #e6fbf0;
  --amber: #b7791f;
  --amber-soft: #fff6e0;
  --amber-line: #f8d685;
  --red: #c2362f;
  --red-soft: #fdeeed;
  --side: #0f1115;
  --side-2: #181b21;
  --side-ink: #e9eeec;
  --side-muted: #8b949e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(16 24 20 / 4%), 0 8px 24px rgb(16 24 20 / 5%);
  --font: "Manrope", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", Consolas, ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1 { margin: 2px 0 4px; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 15px; font-weight: 700; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.eyebrow { color: var(--accent-strong); font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; }

/* ---------- Barra superior (Mis empresas) ---------- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 28px; padding: 12px max(20px, calc((100% - 1180px) / 2)); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { height: 34px; }
.brand-tag { padding-left: 12px; border-left: 1px solid var(--line); color: var(--muted); font-weight: 600; font-size: 13px; }
.topnav { display: flex; gap: 6px; flex: 1; }
.topnav a { padding: 7px 12px; border-radius: var(--radius-sm); font-weight: 600; color: var(--muted); }
.topnav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.page { max-width: 1180px; margin: 0 auto; padding: 28px 20px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.footnote { margin-top: 14px; }

/* ---------- Pastillas, insignias ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.pill-ok { color: var(--accent-ink); border-color: #b9f6ca; background: var(--accent-soft); }
.pill-ok .dot { background: var(--accent); box-shadow: 0 0 0 3px rgb(0 230 118 / 20%); }
.pill-dark { background: var(--side-2); border-color: #2a2f37; color: var(--side-muted); }
.pill-dark.pill-ok { color: #b9f6ca; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pending { background: var(--amber-soft); color: var(--amber); }
.badge-done { background: var(--accent-soft); color: var(--accent-strong); }
.badge-note { background: #eef1f6; color: #4b5563; }
.erp { display: inline-block; padding: 3px 8px; border-radius: 6px; background: #e8f1fd; color: #1d5fbf; font-weight: 700; font-size: 12px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.kpis-4 { grid-template-columns: repeat(4, 1fr); }
.kpi { display: flex; flex-direction: column; gap: 4px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi-value { font: 600 26px var(--mono); letter-spacing: -0.02em; }
.kpi-green { color: var(--accent-strong); }
.kpi-amber { color: var(--amber); }
.kpi-foot { color: var(--muted); font-size: 12px; }

/* ---------- Tarjetas y tablas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-tools { display: flex; gap: 10px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; margin: 0 -20px; }
.table { width: 100%; border-collapse: collapse; }
.table th { padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font: 500 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; text-align: left; white-space: nowrap; }
.table td { padding: 12px 20px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table .num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.table .actions-col { text-align: right; white-space: nowrap; }
.cell-main { display: block; font-weight: 700; }
.cell-sub { display: block; color: var(--muted); font-size: 12px; }
.siigo-number { margin-top: 6px; padding-left: 4px; color: var(--accent-strong); font-weight: 600; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 36px 16px 20px; text-align: center; color: var(--muted); }
.empty strong { color: var(--ink); font-size: 15px; }
.empty .btn { margin-top: 8px; }

/* ---------- Controles ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer; font-weight: 700; font-size: 13px; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--ink); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: var(--ink-2); }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { border-color: var(--ink-2); }
.btn-danger { background: var(--surface); border-color: #f1c4c1; color: var(--red); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.icon-btn { border: 0; background: transparent; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; }
.search { min-width: 240px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 600; }
.field input, .field select, .line-select, .line-search { width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500; }
input:focus, select:focus, .search:focus { outline: 2px solid rgb(0 230 118 / 45%); outline-offset: 1px; border-color: var(--accent-strong); }
.form-row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.form-row .grow { flex: 1 1 280px; }
.steps { margin: 0 0 14px; padding-left: 20px; color: var(--muted); line-height: 1.6; }
.steps strong { color: var(--ink); }
#watchStatus { margin: 10px 0 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 16px 0 4px; }
.span-2 { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink-2); }
.check input { width: 16px; height: 16px; accent-color: var(--accent-strong); }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 8px; }
.modal-wide { width: min(760px, 100%); }
.account-tree { height: 340px; overflow-y: auto; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-size: 13px; }
.acct { display: grid; grid-template-columns: minmax(150px, 34%) 1fr; gap: 12px; padding: 6px 12px; border-bottom: 1px solid var(--line, #eef0ee); }
.acct .code { font-family: var(--mono); }
.acct-major { color: var(--ink-2); cursor: pointer; }
.acct-major .code::before { content: "▾ "; color: var(--muted); }
.acct-aux { cursor: pointer; }
.acct-aux:hover { background: #f0fbf5; }
.acct-aux.selected { background: #dff7ea; font-weight: 700; }
.acct-empty { padding: 18px 12px; color: var(--muted); }
.tree-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.list-select { width: 100%; padding: 6px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-size: 13px; }
.message { min-height: 0; margin-top: 10px; color: var(--red); font-weight: 600; font-size: 13px; }
.message:empty { display: none; }
.message.ok { color: var(--accent-strong); margin: 0 0 12px; }
.tabs { display: flex; gap: 4px; margin: -4px 0 16px; border-bottom: 1px solid var(--line); }
.tab { padding: 8px 14px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-weight: 700; cursor: pointer; margin-bottom: -1px; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--muted); font-weight: 700; font-size: 12px; cursor: pointer; }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: #edf1ef; }
.segmented button { padding: 6px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 700; font-size: 12px; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 10%); }

/* ---------- Espacio de trabajo ---------- */
.workspace { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 18px 16px; background: var(--side); color: var(--side-ink); }
.side-logo { padding: 10px; border-radius: 10px; background: #fff; }
.side-logo img { display: block; width: 100%; }
.side-back { padding: 8px 10px; border: 1px solid #2a2f37; border-radius: var(--radius-sm); background: transparent; color: var(--side-muted); font-weight: 700; text-align: left; cursor: pointer; }
.side-back:hover { color: var(--side-ink); border-color: #3a414b; }
.side-company { display: flex; flex-direction: column; gap: 4px; padding: 14px; border-radius: 10px; background: var(--side-2); }
.side-company strong { font-size: 15px; line-height: 1.3; }
.side-company .pill { align-self: flex-start; margin-top: 6px; }
.side-label { color: var(--side-muted); font: 500 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.side-muted { color: var(--side-muted); font-size: 12px; font-family: var(--mono); }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav .side-label { margin-bottom: 4px; }
.side-nav a { padding: 9px 12px; border-radius: var(--radius-sm); color: var(--side-muted); font-weight: 700; }
.side-nav a.active { background: rgb(0 230 118 / 12%); color: var(--accent); }
.side-foot { margin-top: auto; }
.work { min-width: 0; padding: 26px 28px 110px; }

/* ---------- Detalle ---------- */
.detail-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 10px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { color: var(--muted); font: 500 11px var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.facts dd { margin: 3px 0 0; font-weight: 700; overflow-wrap: anywhere; }
.facts .wide { grid-column: 1 / -1; }
.facts .cufe { font: 500 12px var(--mono); color: var(--ink-2); }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 16px; padding: 22px; border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-2); text-align: center; cursor: pointer; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent-strong); background: var(--accent-soft); }
.dropzone input { display: none; }
.dropzone span { color: var(--muted); font-size: 12px; }
.items-table td { padding: 10px 20px; }
.items-table .line-desc { font-weight: 600; }
.line-pick { display: grid; gap: 6px; min-width: 240px; }
.line-select { padding: 7px 10px; font-size: 13px; }
.line-search { padding: 6px 10px; font-size: 12px; }
.line-puc { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 170px; width: 100%; padding: 6px 10px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-size: 12px; text-align: left; cursor: pointer; }
.line-puc:hover:not(:disabled) { border-color: var(--ink-2); }
.line-puc:disabled { cursor: default; opacity: .7; }
.line-puc.own { border-style: solid; border-color: var(--accent-strong); background: var(--accent-soft); }
.line-puc .mono, .line-puc strong { font-family: var(--mono); }
.items-note { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; }
.puc-display { display: flex; flex-direction: column; gap: 2px; }
.puc-display strong { font: 600 20px var(--mono); }
.puc-empty { color: var(--amber); font-weight: 700; }
#paymentHint { margin-top: 8px; }
.note-fields { display: grid; gap: 12px; }
.note-fields details { border-top: 1px dashed var(--line); padding-top: 10px; }
.note-fields details summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 10px; }
.note-fields details .field { margin-bottom: 10px; }
#noteHint.warn { color: var(--amber); font-weight: 600; }
.wh-row { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.wh-row:first-child { padding-top: 0; }
.wh-row:last-child { border-bottom: 0; margin-bottom: 10px; }
.wh-row select { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); font-size: 13px; }
.wh-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.wh-head .mono { font-weight: 500; }
.wh-note { font-size: 12px; color: var(--muted); }
.auth-view { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 18px 50px rgb(0 0 0 / 8%); }
.auth-card img { height: 44px; align-self: flex-start; }
.auth-card h1 { font-size: 22px; font-weight: 800; }
.auth-card .btn { margin-top: 4px; padding: 11px 16px; }
.user-box { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.company-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin-top: 8px; max-height: 220px; overflow: auto; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.company-checks .check { font-weight: 500; font-size: 13px; }
.th-wrap { overflow-x: auto; margin: 12px 0 10px; }
.th-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.th-table th { text-align: left; color: var(--muted); font-weight: 700; padding: 4px 4px 6px; white-space: nowrap; }
.th-table td { padding: 3px 4px; }
.th-table input { width: 100%; min-width: 64px; padding: 6px 7px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); font-family: "JetBrains Mono", monospace; font-size: 12px; }
.th-table input[type="date"] { min-width: 128px; }
.th-table td:nth-child(8) input { min-width: 160px; font-family: inherit; }
.th-sub { margin: 18px 0 8px; font-size: 14px; font-weight: 800; }
.wh-note.ok { color: var(--accent-strong); font-weight: 600; }
.wh-note.warn { color: var(--amber); font-weight: 600; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; margin: 0; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; font-family: var(--mono); }
.totals .sep { grid-column: 1 / -1; height: 1px; background: var(--line); margin: 2px 0; }
.totals .strong { color: var(--ink); font-weight: 800; }
.totals dd.strong { font-weight: 600; }
.totals .neg { color: var(--red); }
.entry { width: 100%; border-collapse: collapse; font-size: 12px; }
.entry th { padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--muted); font: 500 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; text-align: left; }
.entry td { padding: 7px 0; border-bottom: 1px dashed var(--line); vertical-align: top; }
.entry td:first-child, .entry th:first-child { padding-right: 12px; white-space: nowrap; }
.entry .num { text-align: right; font-family: var(--mono); white-space: nowrap; padding-left: 8px; }
.entry tfoot td { border-bottom: 0; font-weight: 800; }
.balance { margin-top: 10px; padding: 8px 10px; border-radius: var(--radius-sm); font-weight: 700; font-size: 12px; }
.balance.ok { background: var(--accent-soft); color: var(--accent-strong); }
.balance.bad { background: var(--red-soft); color: var(--red); }
.alert { margin-bottom: 12px; padding: 12px 14px; border: 1px solid var(--amber-line); border-left-width: 4px; border-radius: var(--radius-sm); background: var(--amber-soft); color: #6b4a10; font-weight: 600; font-size: 13px; }
.alert.info { border-color: #b9f6ca; background: var(--accent-soft); color: var(--accent-ink); }
.action-bar { position: fixed; right: 0; bottom: 0; left: 248px; z-index: 4; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 28px calc(12px + env(safe-area-inset-bottom, 0px)); background: rgb(255 255 255 / 92%); border-top: 1px solid var(--line); backdrop-filter: blur(8px); }
.action-bar .message { margin: 0; }
.action-buttons { display: flex; gap: 10px; margin-left: auto; flex-wrap: wrap; }

/* ---------- Modales ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgb(15 17 21 / 55%); }
.modal-card { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 22px 24px; border-radius: 16px; background: var(--surface); box-shadow: 0 24px 60px rgb(0 0 0 / 25%); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.modal-head h2 { font-size: 19px; font-weight: 800; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Pantallas angostas ---------- */
@media (max-width: 1100px) {
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side-logo, .side-nav, .side-foot { display: none; }
  .side-company { flex: 1; }
  .action-bar { left: 0; padding-inline: 16px; }
  .work { padding: 20px 16px 140px; }
  .kpis, .kpis-4 { grid-template-columns: 1fr 1fr; }
  .facts { grid-template-columns: 1fr 1fr; }
  .topbar { gap: 12px; flex-wrap: wrap; }
  .brand-tag, .topnav { display: none; }
  .search { min-width: 0; flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Conciliación DIAN vs. causado ---------- */
.side-nav a { cursor: pointer; text-decoration: none; }
.side-nav a:not(.active):hover { color: #fff; }
.side-nav .side-label + a, .side-nav a + .side-label { margin-top: 10px; }
.kpi-sub { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.recon-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge-review { background: #fde8e8; color: #b42318; }
.recon-notes { margin-top: 0; }

/* ---------- Historial de lo causado ---------- */
.table tfoot td { font-weight: 800; border-top: 2px solid var(--line-strong); border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.cell-neg { color: var(--red); }

/* Proveedor de confianza (causación automática) */
.trust-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.cell-sub.auto-ok { color: var(--accent-strong); font-weight: 600; }
.cell-sub.auto-review { color: #b42318; }

/* ---------- Selección de facturas (solo administrador): marcar causadas a mano ---------- */
.bulk-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface-2); font-weight: 600; font-size: 13px; }
.bulk-bar #bulkCount { margin-right: auto; }
.table .select-col { width: 36px; padding-right: 0; }
.table .select-col input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent-strong); }
.table tbody tr.selected { background: var(--accent-soft); }
.badge-manual { background: #eef2ff; color: #3730a3; }
.cell-sub.manual-by { color: #3730a3; }

/* ---------- Modo web: arrastrar ZIP de la DIAN a la tarjeta ---------- */
.card.drop-target { outline: 2px dashed var(--accent-strong); outline-offset: -6px; }
/* Fila con campo de solo lectura y botón Copiar (modal Extensión DIAN) */
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { flex: 1; min-width: 0; font-family: Consolas, monospace; font-size: 12px; }

