/*
 * Portal Contador — same visual language as the tenant app (frontend/src/index.css):
 * navy chrome, card panels, gold wordmark, accent #5b74b8, 10 px radius, uppercase
 * 11 px table heads, pills. Desktop: sidebar (240 px) + main; ≤ 1400 px: sticky top
 * bar with the nav as a wrapping tab row; ≤ 640 px: tables become cards, actions go
 * full width, 48 px tap targets, 16 px inputs (no iOS zoom).
 */
:root {
  color-scheme: dark;
  --bg: #101426;
  --bg-card: #161a2d;
  --bg-card-hover: #1c223c;
  --bg-input: #12162a;
  --border: #2c3450;
  --border-focus: #5b74b8;
  --text: #e8eaf2;
  --text-muted: #8b91a8;
  --text-dim: #5c6380;
  --accent: #5b74b8;
  --accent-hover: #7c90c8;
  --gold: #d4a853;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 10px;
  /* Text tones that clear WCAG AA on the card background (the raw accent /
     danger are 3.8:1 / 4.6:1 there: fine for borders and fills, not for 13 px text). */
  --accent-text: #8fa3d9;
  --danger-text: #f87171;
  --dim-text: #7d85a0;
  /* Aliases kept for the SPA's older class names. */
  --ink: var(--text);
  --muted: var(--text-muted);
  --line: var(--border);
  --bad: var(--danger);
  --warn: var(--warning);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--accent-hover); }
.skip { position: absolute; left: 8px; top: 8px; transform: translateY(-300%); background: var(--bg-card); color: var(--text); padding: 8px 12px; border-radius: var(--radius); z-index: 50; }
.skip:focus { transform: none; }

/* ── Shell: sidebar + main (desktop), top bar (≤ 1400 px) ── */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.bar {
  width: 240px; flex-shrink: 0; display: flex; flex-direction: column; gap: 0;
  background: var(--bg-card); border-right: 1px solid var(--border);
  padding: 24px 0 8px; padding-top: max(24px, env(safe-area-inset-top));
  height: 100vh; height: 100dvh; position: sticky; top: 0; overflow: hidden;
}
.brand { display: grid; gap: 14px; min-width: 0; padding: 0 16px; margin-bottom: 18px; color: var(--text); }
.brand .mark { height: 20px; width: auto; display: block; padding: 0 4px; }
.firm-card { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.firm-card img { width: 36px; height: 36px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; }
.firm-card img[hidden] { display: none; }
.firm-text { display: grid; gap: 1px; min-width: 0; }
.firm-text strong { font-weight: 700; font-size: 13px; line-height: 1.25; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.firm-sub { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.tabs { display: flex; flex-direction: column; gap: 0; flex: 1 1 auto; min-height: 0; overflow-y: auto; background: transparent; border: 0; padding: 0; }
.tabs button {
  display: flex; align-items: center; justify-content: flex-start; gap: 12px; width: calc(100% - 16px); margin: 1px 8px; text-align: left; line-height: 1;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--text-muted); font: inherit; font-size: 14px; font-weight: 400; min-height: 44px; padding: 10px 24px; cursor: pointer;
}
.tabs button:hover { color: var(--text); background: var(--bg-card-hover); }
.tabs button.on { color: var(--text); font-weight: 600; background: #5b74b826; }
.tabs button.on svg { color: var(--accent-text); }
.tabs button svg { width: 18px; height: 18px; flex: 0 0 18px; display: block; }
.who { flex-shrink: 0; margin-top: auto; border-top: 1px solid var(--border); padding: 10px 16px 4px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.who span { color: var(--text-muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 8px; }
.who button { min-height: 40px; padding: 0 16px; justify-content: flex-start; background: transparent; border: 0; color: var(--text-muted); font-weight: 500; }
.who button:hover { color: var(--text); background: var(--bg-card-hover); filter: none; }

main { flex: 1; min-width: 0; padding: 32px; overflow-y: auto; display: grid; gap: 16px; align-content: start; max-width: 1280px; width: 100%; margin: 0 auto; padding-bottom: max(32px, env(safe-area-inset-bottom)); }
main:focus { outline: none; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
h1 { font-size: 22px; font-weight: 700; margin: 0; }
h2 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin: 0 0 10px; }
p { margin: 0 0 8px; }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; min-width: 0; }
.narrow { max-width: 440px; width: 100%; margin: 32px auto 0; }
.kpis, .grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi { min-width: 0; overflow: hidden; }
.kpi .muted { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; overflow-wrap: anywhere; }
.kpi strong { display: block; font-size: clamp(17px, 1.6vw, 24px); font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.2; }
.kpis.three { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.muted { color: var(--text-muted); font-size: .92rem; }
.bad { color: var(--danger-text); }
.warn { color: var(--warning); }
.warn-note { color: var(--warning); font-size: .86rem; margin-top: 2px; white-space: normal; cursor: help; }
.ok, td.ok, p.ok { color: var(--success); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stack { display: grid; gap: 10px; }
.spread { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; }

label { display: grid; gap: 6px; font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
label > input, label > select { text-transform: none; letter-spacing: 0; }
input, select {
  /* 16px minimum: iOS zooms the page on focus below that. */
  min-height: 48px; width: 100%; font: inherit; font-size: 1rem; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); color: var(--text);
  transition: border-color .15s;
}
input::placeholder { color: var(--dim-text); }
input:focus, select:focus { outline: none; border-color: var(--border-focus); }
input[type="color"] { padding: 4px; width: 72px; }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; min-height: 0; padding: 0; margin: 0; accent-color: var(--accent); }
main p a { display: inline-block; padding: 8px 4px; margin: -8px -4px; min-height: 32px; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Buttons follow the tenant app (frontend/src/index.css): .btn-primary filled accent,
   .btn-outline bordered with muted text, .btn-sm 12 px; here as default / .ghost / .small. */
button, .btn {
  min-height: 44px; padding: 0 20px; font: inherit; font-size: 14px; font-weight: 500; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: all .15s ease; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); transform: translateY(-1px); }
button.ghost, .btn.ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
button.ghost:hover, .btn.ghost:hover { background: transparent; border-color: var(--accent); color: var(--accent-text); transform: none; }
button.danger { background: transparent; color: var(--danger-text); border-color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
button.ghost.small { color: var(--text-muted); }
@media (hover: none) { button:hover, .btn:hover { transform: none; } }

.msg { margin: 32px auto 0; width: calc(100% - 64px); max-width: 1216px; padding: 12px 14px; border-radius: var(--radius); background: var(--bg-card); border: 1px solid var(--gold); color: var(--text); }
.msg:not([hidden]) + main { padding-top: 16px; }
@media (max-width: 1400px) { .msg { margin-top: 20px; width: calc(100% - 40px); } }
@media (max-width: 640px) { .msg { margin-top: 12px; width: calc(100% - 24px); } }
.msg.err { background: rgba(239, 68, 68, .1); border-color: var(--danger); color: #ffd5da; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 12px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); background: var(--bg-card); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-card-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.qr { width: 180px; height: 180px; background: #fff; border-radius: var(--radius); padding: 8px; }
.code { font-family: "SF Mono", "Fira Code", ui-monospace, monospace; font-size: 12.5px; word-break: break-all; }
.pill { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; background: #5b74b822; color: var(--accent-text); }
.pill.bad { background: #ef444422; color: var(--danger-text); }
.pill.warn { background: #f59e0b22; color: var(--warning); }
.pill.ok { background: #22c55e22; color: var(--success); }
.company h2 { margin-bottom: 2px; }
.company .figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.company .figures div { background: var(--bg-input); border-radius: 8px; padding: 6px 8px; }
.company .figures strong { display: block; font-variant-numeric: tabular-nums; }
.ts { min-height: 70px; }

/* ── Workspace: Empresas grid, batch bar, company view ── */
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
label.inline { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); }
label.inline input[type="checkbox"] { width: 18px; height: 18px; }
input.period { max-width: 130px; }
input[type="search"] { max-width: 420px; }

table.grid-table { font-size: 13.5px; }
table.grid-table tr.clickable { cursor: pointer; }
table.grid-table tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
table.grid-table tr.clickable:hover td.name strong { color: var(--accent-text); text-decoration: underline; }
tr.clickable { cursor: pointer; }
tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
table.grid-table th.check, table.grid-table td.check { width: 34px; text-align: center; }

/* Form fields in toolbars and dialogs: caption above the control, same as the tenant app. */
label.field { display: grid; gap: 4px; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); min-width: 0; }
label.field > .cap { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
label.field > input, label.field > select, label.field > .with-list > input { width: 100%; min-width: 0; }
label.field .with-list { display: block; }
label.field.compact > select, label.field.compact > input { min-height: 40px; padding: 6px 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px 14px; align-items: end; }
.toolbar > label.field { flex: 0 1 220px; min-width: 160px; }
.toolbar > label.field.grow { flex: 1 1 260px; }
.toolbar > label.inline { align-self: end; min-height: 48px; }
.toolbar > button { align-self: end; }
.toolbar > .toolbar-actions { display: flex; gap: 8px; margin-left: auto; align-self: end; flex-wrap: wrap; }
.toolbar input[type="search"] { max-width: none; }

/* Segmented report picker (Contabilidad / Impuestos): groups with a caption, each option a two-line chip. */
.seg-groups { display: flex; flex-wrap: wrap; gap: 10px 22px; }
.seg-group { display: grid; gap: 6px; }
.seg-cap { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg .chip { display: inline-grid; grid-template-columns: auto; justify-items: start; gap: 1px; min-height: 44px; padding: 5px 14px; border-radius: var(--radius); line-height: 1.2; text-align: left; }
.seg .chip span { font-size: 13.5px; font-weight: 600; color: var(--text); }
.seg .chip small { font-size: 11px; color: var(--text-muted); }
.seg .chip.on { background: var(--accent); border-color: var(--accent); }
.seg .chip.on span, .seg .chip.on small { color: #fff; }
.seg .chip:hover:not(.on) { border-color: var(--accent); background: var(--bg-card-hover); }

/* Dialog steps (MUISCA, exógena) */
.steps { gap: 8px; }
.steps .step { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 6px 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.step-head { display: contents; }
.step-head > div { grid-column: 2; }
.step-n { grid-column: 1; grid-row: 1 / span 2; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; }
.step-head strong { display: block; font-size: 14.5px; }
.step-head .muted { font-size: 12.5px; }
.step-body { grid-column: 2; display: grid; gap: 10px; }
.step-body .grid.two { gap: 10px 12px; }
.step-body .consent { background: transparent; }
.dialog-actions { justify-content: flex-end; }
.dialog-actions > button { min-width: 220px; }
.note { border: 1px solid #f59e0b55; padding: 8px 12px; background: #f59e0b0d; border-radius: var(--radius); font-size: 13.5px; color: var(--text); }
dialog.modal label.field > input, dialog.modal label.field > select { width: 100%; }
dialog.modal .creds input, dialog.modal .creds select { min-height: 44px; }

/* Exógena formats: one aligned row each */
.fmt-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.fmt { display: grid; grid-template-columns: 22px 44px minmax(0, 1fr); gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-card); cursor: pointer; text-transform: none; letter-spacing: 0; font-size: 13.5px; color: var(--text); min-height: 44px; }
.fmt:hover { border-color: var(--accent); }
.fmt:has(input:checked) { border-color: #5b74b880; background: #5b74b810; }
.fmt input { margin: 0; }
.fmt-code { font-family: "SF Mono", "Fira Code", ui-monospace, monospace; font-weight: 700; font-size: 13px; color: var(--accent-text); }
.fmt-name { min-width: 0; overflow-wrap: anywhere; }
.row.fmt-tools { gap: 6px; }
.row.fmt-tools > button { flex: 0 0 auto; min-height: 32px; }

/* ¿Quién firma? */
.modes { display: grid; gap: 8px; }
.mode { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 10px; align-items: start; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); cursor: pointer; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); }
.mode:hover { border-color: var(--accent); }
.mode:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: #5b74b812; }
.mode input { margin-top: 2px; }
.mode-text { display: grid; gap: 2px; min-width: 0; }
.mode-text strong { font-size: 14px; }
.mode-text .muted { font-size: 12.5px; line-height: 1.4; }
.creds { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px 12px; }
.creds label.field:last-child { grid-column: 1 / -1; }
p.small { font-size: 12px; margin: 0; }
.step[hidden] { display: none; }
.ok-note { border-color: #22c55e55; background: #22c55e0d; }

/* Exportar dialog */
.export-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.export-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 14px; align-items: center; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.export-list .export-main { min-width: 0; }
.export-list .export-main strong { display: block; }
.export-list .export-main .muted { font-size: 12.5px; line-height: 1.35; }
.export-list .export-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.export-list .export-actions button { min-height: 34px; padding: 0 12px; min-width: 58px; }

/* MUISCA queue: one card per company */
.queue { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.queue-item { display: grid; grid-template-columns: minmax(160px, 1.6fr) minmax(110px, 1fr) minmax(110px, 1fr) auto; gap: 6px 14px; align-items: center; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.queue-item .q-status { grid-column: 1 / -1; }
.queue-item .q-act { grid-column: 4; grid-row: 1; }
.queue-item .q-fig { display: grid; gap: 2px; }
.queue-item .q-fig .cap { font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.queue-item .q-fig strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.queue-item .q-status { font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.queue-item .q-status.ok { color: var(--success); }
.queue-item .q-status.bad { color: var(--danger-text); }
.queue-item .q-status.warn { color: var(--warning); }
.queue-item .q-act:empty { display: none; }

/* Report tables: toolbar (Copiar · CSV · XLSX) + horizontal scroll inside the card, never the page. */
.report { display: grid; gap: 8px; min-width: 0; }
.report-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.report-title { margin: 0 0 4px; font-size: 15px; font-weight: 700; letter-spacing: .01em; text-transform: none; color: var(--text); }
.report-bar .tools { gap: 6px; }
.report-bar .tools button { min-height: 32px; padding: 0 10px; font-size: 12px; }
.scroll { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.scroll > table { min-width: 100%; }
table.cards td.code { font-family: "SF Mono", "Fira Code", ui-monospace, monospace; font-size: 12.5px; white-space: nowrap; }
table.cards td { overflow-wrap: anywhere; }
table.cards td.num { white-space: nowrap; }
tr.lvl-group td { font-weight: 650; background: #5b74b80e; }
tr.indent td:first-child { padding-left: 32px; color: var(--text-muted); }
tr.unposted td { background: #f59e0b0c; }
.flat-only { display: none; }
select.period { width: auto; min-width: 200px; }
details.plain { border: 0; padding: 0; background: transparent; }
details.plain > summary { cursor: pointer; color: var(--accent-text); min-height: 36px; display: flex; align-items: center; font-size: 13.5px; }

/* Libro diario: one block per asiento */
article.entry { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); overflow: hidden; }
article.entry .entry-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
article.entry .entry-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
article.entry .entry-title strong { overflow-wrap: anywhere; }
article.entry .entry-meta { display: flex; gap: 12px; align-items: center; font-variant-numeric: tabular-nums; }
article.entry table { font-size: 13px; }
article.entry th { background: transparent; }

/* Próximos vencimientos: cards, not a table */
.due-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.due-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); align-items: center; }
.due-list li.soon { border-color: var(--warning); }
.due-list .due-main { min-width: 0; }
.due-list .due-main strong { display: block; overflow-wrap: anywhere; }
.due-list .due-amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.due-list .due-actions { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.due-list .due-actions .filing { flex: 1 1 auto; }

/* Ranking (top clientes / proveedores) */
ol.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; counter-reset: rank; }
ol.rank li { display: grid; gap: 4px; }
ol.rank .rank-row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
ol.rank .rank-name { min-width: 0; overflow-wrap: anywhere; }
ol.rank .rank-name::before { counter-increment: rank; content: counter(rank) ". "; color: var(--text-muted); }
ol.rank .rank-row strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
progress.meter { width: 100%; height: 6px; appearance: none; -webkit-appearance: none; border: 0; background: var(--bg-input); border-radius: 3px; overflow: hidden; }
progress.meter::-webkit-progress-bar { background: var(--bg-input); border-radius: 3px; }
progress.meter::-webkit-progress-value { background: var(--accent); border-radius: 3px; }
progress.meter::-moz-progress-bar { background: var(--accent); border-radius: 3px; }

/* 12-month chart (HTML/CSS) */
.legend { display: flex; gap: 6px 14px; align-items: center; color: var(--text-muted); font-size: 12.5px; margin-bottom: 10px; flex-wrap: wrap; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }
.sw.ing { background: linear-gradient(180deg, #7c90c8, var(--accent)); }
.sw.gas { background: linear-gradient(180deg, #a3a9bf, #6f7690); }
.chart { display: grid; gap: 14px; }
.ch-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.ch-stat { display: grid; gap: 2px; padding: 8px 12px; border-radius: 8px; background: var(--bg-input); border: 1px solid var(--border); min-width: 0; }
.ch-stat span { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.ch-stat strong { font-size: 15px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ch-body { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px; height: 240px; }
.ch-axis { display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end; padding-bottom: 22px; font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.ch-axis span { transform: translateY(50%); line-height: 1; }
.ch-axis span:first-child { transform: translateY(0); }
.ch-plot { position: relative; min-width: 0; }
.ch-grid { position: absolute; inset: 0 0 22px 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.ch-grid i { display: block; border-top: 1px dashed #2c345099; }
.ch-grid i:last-child { border-top: 1px solid var(--border); }
.ch-cols { position: absolute; inset: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; }
.ch-col { position: relative; display: grid; grid-template-rows: minmax(0, 1fr) 22px; border-radius: 8px; outline: none; cursor: default; }
.ch-col:hover, .ch-col:focus-visible { background: #5b74b812; }
.ch-col.on { background: #d4a85314; }
.ch-col.on .ch-label { color: var(--gold); font-weight: 700; }
.ch-bars { display: flex; align-items: flex-end; justify-content: center; gap: 3px; padding: 0 12%; min-height: 0; }
.ch-bar { display: block; width: 50%; max-width: 22px; min-height: 2px; border-radius: 4px 4px 1px 1px; transition: height .4s ease; }
.ch-bar.ing { background: linear-gradient(180deg, #7c90c8, var(--accent)); }
.ch-bar.gas { background: linear-gradient(180deg, #a3a9bf, #6f7690); }
.ch-label { align-self: center; text-align: center; font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.ch-tip { position: absolute; bottom: calc(100% - 14px); left: 50%; transform: translateX(-50%); z-index: 5; display: none; min-width: 190px; padding: 10px 12px; border-radius: 8px; background: #0b0e1c; border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0, 0, 0, .45); font-size: 12px; line-height: 1.5; white-space: nowrap; pointer-events: none; }
.ch-tip strong { display: block; margin-bottom: 4px; font-size: 12.5px; }
.ch-tip b { font-variant-numeric: tabular-nums; }
.ch-col:hover .ch-tip, .ch-col:focus-visible .ch-tip { display: block; }
.ch-col:first-child .ch-tip, .ch-col:nth-child(2) .ch-tip { left: 0; transform: none; }
.ch-col:last-child .ch-tip, .ch-col:nth-last-child(2) .ch-tip { left: auto; right: 0; transform: none; }
@media (prefers-reduced-motion: reduce) { .ch-bar { transition: none; } }

/* Split bars (activos por categoría, conciliación cruzado / pendiente) */
.hbars { display: grid; gap: 12px; }
.hb-row { display: grid; gap: 4px; min-width: 0; }
.hb-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; min-width: 0; }
.hb-label { font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.hb-head strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hb-track { height: 10px; border-radius: 5px; background: var(--bg-input); overflow: hidden; }
.hb-bar { display: flex; height: 100%; border-radius: 5px; overflow: hidden; transition: width .4s ease; }
.hb-bar .hb-a, .sw.hb-a { background: linear-gradient(90deg, #a3a9bf, #6f7690); }
.hb-bar .hb-b, .sw.hb-b { background: linear-gradient(90deg, #7c90c8, var(--accent)); }
.hb-bar .hb-a { display: block; height: 100%; transition: width .4s ease; }
.hb-bar .hb-b { display: block; height: 100%; flex: 1; }
@media (prefers-reduced-motion: reduce) { .hb-bar, .hb-bar .hb-a { transition: none; } }
@media (max-width: 640px) { .hb-head { flex-direction: column; gap: 0; } }

/* Documentos del periodo: stat tiles */
.doc-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 8px; }
.doc-stat { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 0 10px; align-items: center; text-align: left; min-height: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); color: var(--text); font: inherit; cursor: pointer; transition: border-color .15s, background .15s; }
.doc-stat:hover { border-color: var(--accent); background: var(--bg-card-hover); transform: none; }
.doc-stat.static { cursor: default; }
.doc-stat.static:hover { border-color: var(--border); background: var(--bg-input); }
.doc-stat .n { grid-row: 1 / span 2; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent-text); min-width: 32px; text-align: center; }
.doc-stat .l { font-size: 13.5px; font-weight: 600; }
.doc-stat .s { font-size: 11.5px; color: var(--text-muted); }
.row.actions { gap: 8px; }

/* Portfolio strip (Empresas) + company dashboard: tappable KPIs */
.kpis.portfolio { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpis.portfolio[hidden] { display: none; }
button.kpi.tap, article.kpi { text-align: left; }
button.kpi.tap { display: block; width: 100%; min-height: 0; font: inherit; color: var(--text); cursor: pointer; }
button.kpi.tap:hover { background: var(--bg-card-hover); border-color: var(--accent); }
button.kpi.tap.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.kpi.warn strong { color: var(--warning); }
.kpi.bad strong { color: var(--danger-text); }
.kpi .hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; line-height: 1.35; white-space: normal; overflow-wrap: anywhere; }
button.kpi.tap { white-space: normal; height: auto; }
button.kpi.tap .muted, button.kpi.tap strong { white-space: normal; }
.company-head { min-width: 0; }
.spread > label.field.compact { flex: 0 0 auto; }
.headline { font-size: 15px; line-height: 1.5; padding: 12px 16px; border: 1px solid var(--border); background: var(--bg-card); border-radius: var(--radius); margin: 0; }
.company-head .pills { margin-top: 8px; }
.checklist li.clickable { cursor: pointer; border-radius: 8px; }
.checklist li.clickable:hover { background: var(--bg-card-hover); }
.checklist li.bad-item .tick { color: var(--danger-text); }
.chip.static { cursor: default; }
.chip strong { margin-left: 4px; color: var(--text); }
.chip.on strong { color: #fff; }

table.grid-table td.name { min-width: 180px; }
table.grid-table td.actions { white-space: nowrap; }
table.grid-table tr.selected td { background: #5b74b814; }
table.grid-table td.wide { font-style: italic; }
button.sort {
  min-height: 0; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  text-align: inherit; cursor: pointer; white-space: nowrap;
}
button.sort:hover { background: transparent; color: var(--text); text-decoration: underline; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; }

.batch { background: var(--bg-card); border: 1px solid var(--accent); border-radius: var(--radius); padding: 12px 16px; display: grid; gap: 10px; position: sticky; top: 16px; z-index: 4; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
.batch[hidden] { display: none; }
/* Results stay inside the bar with their own scroll, so the bar never grows past the viewport and hides the grid. */
.batch .batch-out:not(:empty) { max-height: 40vh; overflow: auto; border-top: 1px solid var(--border); padding-top: 10px; }

.subtabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0; border-bottom: 1px solid var(--border); }
.subtabs button {
  border: 0; border-radius: 8px 8px 0 0; background: transparent; font: inherit; font-size: 13px; color: var(--text-muted); min-height: 44px; padding: 0 16px;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.subtabs button:hover { background: var(--bg-card-hover); color: var(--text); }
.subtabs button.on { color: var(--accent-text); background: var(--bg-card-hover); border-bottom-color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 36px; padding: 0 14px; font-size: 12.5px; font-weight: 500; background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px; }
.chip:hover { color: var(--text); border-color: var(--accent); background: var(--bg-card); }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

tr.total td { font-weight: 650; border-top: 2px solid var(--border); }
tfoot td { font-weight: 650; }
details.entry { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 12px; background: var(--bg-input); }
details.entry summary { cursor: pointer; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; min-height: 36px; }
details.entry summary .num { margin-left: auto; font-variant-numeric: tabular-nums; }

.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.checklist li { display: grid; grid-template-columns: 24px 1fr; gap: 4px 6px; align-items: start; }
.checklist li .tick { font-weight: 700; text-align: center; }
.checklist li.ok .tick { color: var(--success); }
.checklist li.todo .tick { color: var(--warning); }
.checklist li .muted { grid-column: 2; }

/* Calendario rows + filing status */
tr.past { opacity: .6; }
tr.soon td:first-child { font-weight: 650; }
.filing { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filing-bar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.filing-bar label.field > .filing { display: flex; }
.filing-bar .filing select { min-height: 40px; }
.filing-bar > button { min-height: 40px; }
.filing select, .filing input { min-height: 40px; width: auto; padding: 6px 10px; font-size: 13px; }
.filing input.formnum { max-width: 150px; }
.filing select.borrador { border-color: var(--warning); }
.filing select.listo { border-color: var(--accent); }
.filing select.presentado_pendiente_pago { border-color: var(--danger); }
.filing select.presentado { border-color: var(--success); }

/* Wide tables scroll inside the card on narrow desktops instead of breaking the layout. */
@media (min-width: 641px) {
  .card > table, .stack > table, .stack > div:not(.scroll) > table { display: block; overflow-x: auto; max-width: 100%; }
  table.grid-table { display: block; overflow-x: auto; }
}

/* ≤ 1400 px: the tenant app flips its sidebar into a sticky top bar; so do we. */
@media (max-width: 1400px) {
  .shell { flex-direction: column; }
  .bar {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "brand who" "nav nav";
    width: 100%; height: auto; max-height: none; border-right: none; border-bottom: 1px solid var(--border);
    padding: 10px 16px 0; padding-top: max(10px, env(safe-area-inset-top)); column-gap: 12px; row-gap: 4px; align-items: center; overflow: visible; z-index: 30;
  }
  .brand { grid-area: brand; margin-bottom: 0; padding: 0; display: flex; align-items: center; gap: 12px; }
  .brand .mark { height: 18px; padding: 0; flex: 0 0 auto; }
  .firm-card { padding: 0 0 0 12px; border: 0; border-left: 1px solid var(--border); border-radius: 0; background: transparent; gap: 8px; }
  .firm-card img { width: 28px; height: 28px; border-radius: 6px; }
  .firm-text strong { -webkit-line-clamp: 1; }
  .tabs { grid-area: nav; flex-direction: row; flex-wrap: wrap; overflow: visible; }
  .tabs button { width: auto; margin: 0; border-radius: 0; border-bottom: 2px solid transparent; padding: 8px 14px; min-height: 42px; }
  .tabs button.on { border-bottom-color: var(--accent); background: transparent; color: var(--accent-text); }
  .who { grid-area: who; flex-direction: row; align-items: center; margin: 0; border: 0; padding: 0; }
  .who button { min-height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius); }
  main { padding: 20px; }
  .batch { top: 8px; }
}

/* Mobile: tables become cards, actions go full width. */
@media (max-width: 640px) {
  main { padding: 12px; gap: 12px; }
  .card { padding: 16px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpis .kpi { padding: 12px; }
  .kpis.portfolio { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpis.portfolio .kpi strong { font-size: 18px; }
  .kpi strong { font-size: 17px; }
  .kpi .hint { display: none; }
  .toolbar > label.field, .toolbar > label.field.grow { flex: 1 1 100%; }
  .toolbar > button, .toolbar > .toolbar-actions { width: 100%; }
  .toolbar > .toolbar-actions > button { flex: 1 1 auto; }
  select.period { width: 100%; }
  .seg-groups { gap: 10px; }
  .seg .chip { min-height: 40px; padding: 4px 12px; }
  .queue-item { grid-template-columns: 1fr 1fr; }
  .creds { grid-template-columns: 1fr; }
  .fmt-grid { grid-template-columns: 1fr; }
  .export-list li { grid-template-columns: 1fr; }
  .export-list .export-actions { justify-content: flex-start; }
  .export-list .export-actions button { flex: 1 1 auto; }
  .queue-item .q-who, .queue-item .q-status, .queue-item .q-act { grid-column: 1 / -1; }
  .dialog-actions > button { width: 100%; }
  .filing-bar { width: 100%; }
  .filing-bar > label.field { flex: 1 1 100%; }
  .filing-bar > button { width: 100%; }
  .steps .step { padding: 12px; }
  .row.actions > button { flex: 1 1 45%; }
  .report-bar .tools { width: 100%; }
  .report-bar .tools button { flex: 1 1 auto; min-height: 36px; }
  .due-list li { grid-template-columns: 1fr; }
  .due-list .due-amount { text-align: left; }
  article.entry .entry-meta { width: 100%; justify-content: space-between; }
  .ch-body { height: 200px; grid-template-columns: 48px minmax(0, 1fr); }
  .ch-label { font-size: 10px; }
  .ch-bars { padding: 0 6%; gap: 2px; }
  .ch-stats { grid-template-columns: 1fr 1fr; }
  .doc-stats { grid-template-columns: 1fr 1fr; }
  .headline { font-size: 14px; padding: 10px 12px; }
  /* Report tables keep their columns on phones (they scroll inside the card); the Empresas grid still stacks as cards. */
  .report table.cards thead { display: table-header-group; }
  .report table.cards tr { display: table-row; padding: 0; border-bottom: 0; }
  .report table.cards td { display: table-cell; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
  .report table.cards td:first-child { white-space: normal; min-width: 120px; max-width: 200px; }
  .report table.cards td::before { content: none; }
  .report table.cards td.num { text-align: right; }
  .report table.cards td.code { white-space: nowrap; }
  .report table.cards td div.muted { white-space: normal; max-width: 220px; }
  .report table.cards tfoot tr { display: table-row; }
  article.entry table.cards thead { display: table-header-group; }
  article.entry table.cards tr { display: table-row; padding: 0; }
  article.entry table.cards td { display: table-cell; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
  article.entry table.cards td::before { content: none; }
  article.entry table.cards td.num { text-align: right; }
  .grid { grid-template-columns: 1fr; }
  .row > button, .row > .btn { flex: 1 1 100%; }
  .row > button.small { flex: 1 1 auto; }
  table.cards thead { display: none; }
  table.cards tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  table.cards tbody tr:hover td { background: transparent; }
  table.cards td { border: 0; padding: 2px 0; }
  table.cards td::before { content: attr(data-l); display: block; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 1px; }
  table.cards tr { padding: 12px 0; }
  table.cards td.name strong, table.cards td.wide { font-size: 15px; }
  table.cards td.num { text-align: left; }
  table.cards td.check { grid-column: 1 / -1; width: auto; text-align: left; }
  table.cards td.name, table.cards td.wide, table.cards td.actions, table.cards td[colspan] { grid-column: 1 / -1; }
  table.cards td.actions .row > button { flex: 1 1 45%; }
  table.cards tfoot tr { grid-template-columns: 1fr 1fr; }
  table.cards tfoot td::before { content: none; }
  .subtabs { margin: 0; }
  .filing { width: 100%; }
  .filing select { flex: 1 1 100%; }
  .filing input.formnum { max-width: none; flex: 1 1 100%; }
  .filing select, .filing input { font-size: 1rem; min-height: 44px; }
  .who span { display: none; }
  .pill, .chip, button.sort, table.cards td::before { font-size: 12px; }
  .batch { position: static; box-shadow: none; }
  .batch .batch-out:not(:empty) { max-height: none; overflow: visible; }
}

/* Landscape phones (short viewports): nothing sticky — the chrome would eat half the screen. */
@media (max-height: 520px) and (orientation: landscape) {
  .bar { position: static; }
  .batch { position: static; box-shadow: none; }
  main { padding: 12px 16px; gap: 12px; }
  .msg { margin-top: 12px; }
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpis.portfolio { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .kpi strong { font-size: 17px; }
  .kpi .hint { display: none; }
  .ch-body { height: 170px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  dialog.modal, dialog.modal.wide { max-height: 100vh; height: 100vh; margin: 0; width: 100vw; max-width: 100vw; border-radius: 0; inset: 0; }
  dialog.modal .modal-body { padding: 10px 16px; }
}
@media (prefers-reduced-motion: no-preference) { button { transition: all .15s ease; } }

/* Modal (MUISCA presentar, exógena): full-height sheet on phones, centred card on desktop. */
dialog.modal { border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 24px); background: var(--bg-card); color: var(--text); box-shadow: 0 24px 64px rgba(0, 0, 0, .5); display: flex; flex-direction: column; overflow: hidden; }
dialog.modal:not([open]) { display: none; }
dialog.modal.wide { width: min(960px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(9, 12, 20, .62); backdrop-filter: blur(3px); }
dialog.modal .modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px 12px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
dialog.modal .modal-title { min-width: 0; }
dialog.modal .modal-title .muted { margin-top: 2px; font-size: 13px; }
dialog.modal .modal-head button.x { min-height: 36px; min-width: 36px; padding: 0; font-size: 16px; border-color: transparent; flex: 0 0 auto; }
dialog.modal .modal-head button.x:hover { border-color: var(--border); }
dialog.modal .modal-body { padding: 16px 20px; overflow: auto; flex: 1 1 auto; min-height: 0; }
dialog.modal .modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); flex: 0 0 auto; background: var(--bg-card); }
dialog.modal .modal-foot .dialog-actions { justify-content: space-between; align-items: center; }
dialog.modal .modal-foot .flow { font-size: 12.5px; }
dialog.modal h2 { margin: 0; font-size: 17px; font-weight: 700; }
dialog.modal label.inline { display: flex; align-items: flex-start; gap: 8px; }
dialog.modal label.chip { align-items: center; cursor: pointer; }
dialog.modal label.consent { font-size: .85rem; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
dialog.modal label.consent input { margin-top: 3px; flex: 0 0 auto; }
dialog.modal input, dialog.modal select { width: 100%; }
dialog.modal details summary { cursor: pointer; min-height: 36px; display: flex; align-items: center; }
dialog.modal .pse { border: 1px solid #f59e0b55; background: #f59e0b0d; border-radius: var(--radius); padding: 8px 12px; }
@media (max-width: 640px) {
  dialog.modal, dialog.modal.wide { width: 100vw; max-width: 100vw; max-height: 100vh; height: 100vh; margin: 0; border-radius: 0; inset: 0; }
  dialog.modal .modal-head { padding: 12px 14px 10px; }
  dialog.modal .modal-body { padding: 12px 14px; }
  dialog.modal .modal-foot { padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  dialog.modal .modal-foot .dialog-actions { flex-direction: column-reverse; align-items: stretch; }
  dialog.modal .modal-foot .flow { text-align: center; }
  dialog.modal .grid.two { grid-template-columns: 1fr; }
}

/* ── Resumen (portfolio) ── */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.kpi.good strong { color: var(--success); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .muted { font-size: 13px; }
p.muted.small { font-size: 12.5px; line-height: 1.45; margin: 4px 0 0; }
.pay-row { gap: 10px; }
.sub-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.sub-fig { display: grid; gap: 2px; align-content: start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-input); min-width: 0; }
.sub-fig strong { font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.sub-fig span { font-size: 12px; color: var(--text-muted); line-height: 1.3; }
.sub-fig.bad strong { color: var(--danger-text); }
.sub-fig.warn strong { color: var(--warning); }
.sub-fig.ok strong { color: var(--success); }
.sub-list, .comm-list { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 8px; }
.sub-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px 14px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.sub-list li.late { border-color: #ef444499; }
.sub-list li.soon { border-color: #f59e0b80; }
.sub-main { min-width: 0; }
.sub-main strong { display: block; overflow-wrap: anywhere; }
.sub-main .muted { font-size: 12.5px; }
.sub-state { display: grid; justify-items: end; gap: 3px; text-align: right; }
.sub-when { font-size: 12px; white-space: nowrap; }
.sub-when.muted { font-size: 12px; }
.comm-list li { display: grid; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.comm-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.comm-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.comm-pct { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent-text); white-space: nowrap; min-width: 40px; text-align: right; }
.comm-figs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.comm-figs span { display: grid; gap: 1px; min-width: 0; }
.comm-figs small { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.comm-figs b { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 650; }
/* Referral: text + link field (copy inside) + one share row on the left, QR on the right. */
.ref { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px 20px; align-items: center; }
.ref-body { min-width: 0; display: grid; gap: 10px; }
.ref-sub { margin: 0; font-size: 13px; line-height: 1.45; }
.ref-field { display: flex; align-items: stretch; min-width: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); overflow: hidden; }
.ref-field:focus-within { border-color: var(--border-focus); }
.ref-link { flex: 1 1 auto; min-width: 0; margin: 0; padding: 10px 12px; border: 0; background: none; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: copy; align-self: center; }
button.ref-copy { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 0 14px; border: 0; border-left: 1px solid var(--border); border-radius: 0; background: var(--accent); color: #fff; font-weight: 600; }
button.ref-copy:hover { transform: none; background: var(--accent-hover); }
button.ref-copy.done { background: var(--success); }
button.ref-copy .ico, .share-btn .ico { width: 16px; height: 16px; display: inline-grid; }
button.ref-copy svg, .share-btn svg { width: 16px; height: 16px; }
.share-row { display: flex; flex-wrap: wrap; gap: 8px; }
.share-row .share-btn { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 12px; font-size: 13.5px; color: var(--text); }
.share-row .share-btn .ico { color: var(--text-muted); }
.share-row .share-btn:hover .ico { color: var(--accent-text); }
.ref-qr { margin: 0; display: grid; justify-items: center; gap: 4px; padding: 10px; border-radius: 12px; background: #fff; }
.ref-qr figcaption { font-size: 10.5px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: #5c6380; }

/* ── Company quick actions: Exportar last, filled, never cut ── */
.quick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.quick > button { flex: 0 0 auto; }
.quick > .export-btn { margin-left: auto; min-width: 140px; }
.head-actions { justify-content: flex-end; }

/* ── Empresas list ── */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 14px; }
.page-title { min-width: 0; flex: 1 1 320px; }
.page-title h2 { margin: 0 0 4px; }
.page-title p { margin: 0; }
.page-head > button { flex: 0 0 auto; }
.list-card { padding: 8px 0 4px; }
.list-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 20px 8px; font-size: 13px; }
.list-card .empty { padding: 16px 20px; }
table.grid-table th.check, table.grid-table td.check { width: 44px; padding-left: 20px; padding-right: 4px; }
table.grid-table td { vertical-align: middle; }
table.grid-table td.name { min-width: 200px; }
table.grid-table td.name strong { display: block; font-size: 14.5px; }
table.grid-table td.name .muted { font-size: 12.5px; }
table.grid-table td.alerts { min-width: 220px; max-width: 360px; }
table.grid-table td.alerts .pill, .company-head .pills .pill { text-transform: none; letter-spacing: 0; font-size: 12px; font-weight: 600; padding: 3px 9px; }
table.grid-table td.estimate strong { font-variant-numeric: tabular-nums; }
.due-cell strong, .plan-cell .muted { display: block; }
.due-cell div, .plan-cell .muted { font-size: 12.5px; }
.plan-cell { display: grid; gap: 4px; justify-items: start; }
.plan-cell .muted.bad { color: var(--danger-text); }
.plan-cell .muted.warn { color: var(--warning); }
table.grid-table td.actions { padding-right: 20px; }
table.grid-table td.actions .row { flex-wrap: nowrap; justify-content: flex-end; }
table.grid-table th:last-child { padding-right: 20px; }

/* ≤ 1100 px: each company is a card — name and actions on top, alerts, next form + estimate, plan. */
@media (max-width: 1100px) {
  table.grid-table, table.grid-table tbody { display: block; overflow: visible; }
  table.grid-table thead { display: none; }
  table.cards.grid-table tr {
    display: grid; grid-template-columns: 30px minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px 14px; align-items: start;
    grid-template-areas: "check name name actions" ". alerts alerts alerts" ". due estimate plan";
    padding: 14px 16px; border-bottom: 1px solid var(--border);
  }
  table.cards.grid-table tbody tr:last-child { border-bottom: 0; }
  table.cards.grid-table td { display: block; padding: 0; border: 0; max-width: none; min-width: 0; text-align: left; }
  table.cards.grid-table tbody tr:hover td { background: transparent; }
  table.cards.grid-table tr:hover { background: var(--bg-card-hover); }
  table.cards.grid-table tr.selected { background: #5b74b814; }
  table.cards.grid-table td.check { grid-area: check; width: auto; padding: 2px 0 0; }
  table.cards.grid-table td.name { grid-area: name; }
  table.cards.grid-table td.actions { grid-area: actions; padding: 0; }
  table.cards.grid-table td.alerts, table.cards.grid-table td.wide { grid-area: alerts; }
  table.cards.grid-table td.due { grid-area: due; }
  table.cards.grid-table td.estimate { grid-area: estimate; }
  table.cards.grid-table td.plan { grid-area: plan; }
  table.cards.grid-table td.due::before, table.cards.grid-table td.estimate::before, table.cards.grid-table td.plan::before {
    content: attr(data-l); display: block; color: var(--text-muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 3px;
  }
  table.cards.grid-table td.name::before, table.cards.grid-table td.alerts::before, table.cards.grid-table td.wide::before, table.cards.grid-table td.actions::before, table.cards.grid-table td.check::before { content: none; }
  .list-head { padding: 6px 16px 8px; }
}

@media (max-width: 640px) {
  .sub-strip { grid-template-columns: 1fr 1fr; }
  .sub-list li { grid-template-columns: minmax(0, 1fr) auto; }
  .sub-act { grid-column: 1 / -1; }
  .sub-act button { width: 100%; }
  .ref { grid-template-columns: 1fr; }
  .ref-qr { justify-self: center; }
  .welcome .ref .qr { width: 132px; height: 132px; }
  .share-row { display: grid; grid-template-columns: 1fr 1fr; }
  .share-row .share-btn { justify-content: center; min-height: 44px; }
  .pay-row > button { flex: 1 1 100%; }
  .quick { display: grid; grid-template-columns: 1fr 1fr; }
  .quick > button { width: 100%; white-space: normal; line-height: 1.2; min-height: 44px; padding: 6px 10px; }
  .quick > .export-btn { grid-column: 1 / -1; margin-left: 0; }
  .head-actions { width: 100%; }
  .page-head > button { width: 100%; }
  table.cards.grid-table tr {
    grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "check name name" ". alerts alerts" ". due estimate" ". plan plan" ". actions actions";
    padding: 14px 12px;
  }
  table.cards.grid-table td.actions .row { justify-content: stretch; }
  table.cards.grid-table td.actions .row > button { flex: 1 1 45%; }
  .list-head { padding: 6px 12px 8px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .sub-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1101px) {
  /* The Empresas list fits (five data columns): a real table at full width, no inner scroll. */
  .stack > table.grid-table, table.grid-table { display: table; overflow: visible; }
}

/* "Lo próximo" callout on the company Resumen */
.next-card { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 10px 24px; align-items: center; padding: 14px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); }
.next-card.soon { border-color: #f59e0b66; background: #f59e0b0a; }
.next-card > div { display: grid; gap: 2px; min-width: 0; }
.next-cap { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.next-days { font-size: 18px; line-height: 1.2; }
.next-card.soon .next-days { color: var(--warning); }
.next-what strong { font-size: 15px; overflow-wrap: anywhere; }
.next-amount { text-align: right; }
.next-amount strong { font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.next-act { display: flex !important; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 900px) {
  .next-card { grid-template-columns: minmax(0, 1fr) auto; }
  .next-what { grid-column: 1 / -1; grid-row: 2; }
  .next-act { grid-column: 1 / -1; justify-content: stretch; }
  .next-act > button { flex: 1 1 45%; }
}

.deep-card { display: flex; justify-content: space-between; align-items: center; gap: 12px 16px; flex-wrap: wrap; border-color: var(--accent); }
.deep-card p { margin: 2px 0 0; }
@media (max-width: 640px) { .deep-card > button { width: 100%; } }

/* Resumen: welcome + referral on top */
.welcome { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 20px 28px; align-items: center; }
.welcome h1 { font-size: 22px; margin: 0 0 6px; overflow-wrap: anywhere; }
.welcome-text p { margin: 0 0 10px; }
.welcome-facts { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.welcome-facts li { font-size: 13px; padding: 5px 10px; border-radius: 999px; background: var(--bg-input); border: 1px solid var(--border); }
.welcome .ref { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.welcome .ref .qr { width: 116px; height: 116px; }
.ref-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ref-head strong { font-size: 15px; }
@media (max-width: 900px) {
  .welcome { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .welcome h1 { font-size: 19px; }
}

/* Documentos: per-row files + bulk download */
.doc-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.doc-bar .row { margin-left: auto; }
td.doc-actions .row { flex-wrap: nowrap; justify-content: flex-end; gap: 6px; }
td.doc-actions button { min-height: 32px; padding: 0 10px; }
@media (max-width: 640px) {
  .doc-bar .row { width: 100%; }
  .doc-bar .row > button { flex: 1 1 100%; }
  .report table.cards td.doc-actions { white-space: nowrap; }
}

/* Resumen: festivos + TRM strip */
.ref-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.ref-tile { display: grid; gap: 3px; align-content: start; padding: 14px 18px; min-width: 0; }
.ref-cap { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.ref-tile strong { font-size: 17px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ref-tile .muted { font-size: 12.5px; }
.ref-tile .small-line { font-size: 12px; }
@media (max-width: 900px) { .ref-strip { grid-template-columns: 1fr 1fr; } .ref-strip .ref-tile:first-child { grid-column: 1 / -1; } }
@media (max-width: 640px) { .ref-strip { gap: 8px; } .ref-tile { padding: 12px; } .ref-tile strong { font-size: 15px; } }

/* Cierre: twelve month tiles */
.months { list-style: none; margin: 0 0 8px; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.month { display: grid; gap: 4px; align-content: start; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); min-width: 0; min-height: 84px; }
.month-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px 6px; min-width: 0; }
.month-head strong { font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.month-head .pill { text-transform: none; letter-spacing: 0; font-size: 11.5px; padding: 2px 8px; white-space: nowrap; }
.month-n { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.month-by { font-size: 11.5px; color: var(--text-dim); overflow-wrap: anywhere; }
.month.open { border-color: #f59e0b66; background: #f59e0b0a; }
.month.running { border-style: dashed; }
.month.future { opacity: .45; }
.month > button { margin-top: 4px; min-height: 34px; width: 100%; }
@media (max-width: 1100px) and (min-width: 641px) { .months { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .months { grid-template-columns: 1fr 1fr; } }

/* Enviar por correo */
textarea { width: 100%; font: inherit; font-size: 1rem; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); color: var(--text); resize: vertical; min-height: 120px; }
textarea:focus { outline: none; border-color: var(--border-focus); }
input.readonly { color: var(--text-muted); background: var(--bg-card); }
.attach-list { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.attach-list .cap { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.attach-list ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.attach-list li { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; min-width: 0; }
.attach-list li .code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Guía */
.guide-head h1 { margin: 0 0 4px; }
.guide-toc { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.guide-toc a { padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; font-size: 13px; color: var(--text); }
.guide-toc a:hover { border-color: var(--accent); color: var(--accent-text); }
.guide-sec { scroll-margin-top: 80px; display: grid; gap: 10px; }
.guide-sec h2 { margin: 0; }
.guide-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.guide-list li { display: grid; gap: 3px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.guide-list li span { color: var(--text-muted); font-size: 13.5px; }
.guide-steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.guide-example { padding: 12px 14px; border: 1px solid #22c55e55; background: #22c55e0d; border-radius: var(--radius); display: grid; gap: 4px; }
.guide-sec details { border-top: 1px solid var(--border); padding: 4px 0; }
.guide-sec details summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; font-weight: 600; }
.guide-sec details p { color: var(--text-muted); }
a.btn { min-height: 44px; }
@media (max-width: 640px) { .guide-list { grid-template-columns: 1fr; } }
/* Lucas inside the Guía: static search, answer cards with their source. */
.lucas-card { display: grid; gap: 10px; scroll-margin-top: 80px; }
.lucas-card h2 { margin: 0; }
.lucas-form { display: flex; gap: 8px; min-width: 0; }
.lucas-form input { flex: 1 1 auto; min-width: 0; }
.lucas-form button { flex: 0 0 auto; min-height: 48px; }
.lucas-chips .chip { min-height: 36px; }
.lucas-results { display: grid; gap: 8px; min-width: 0; }
.lucas-results:empty { display: none; }
.lucas-answer { display: grid; gap: 6px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); min-width: 0; }
.lucas-answer-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.lucas-answer-head strong { overflow-wrap: anywhere; }
.lucas-answer p { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.lucas-more { display: inline-flex; align-items: center; min-height: 32px; font-size: 13.5px; }

button.pill-btn { min-height: 0; border: 0; cursor: pointer; font: inherit; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; padding: 3px 10px; }
button.pill-btn:hover { filter: brightness(1.15); transform: none; }
.pill.code-pill { font-family: "SF Mono", ui-monospace, monospace; text-transform: none; letter-spacing: 0; }
@media (max-width: 640px) { button.pill-btn { min-height: 32px; } }

/* ── Intake (/registro → documentos) ── */
/* Public screens (sign-in, intake, approval): slim top bar instead of the empty sidebar. */
body.public .shell { flex-direction: column; }
body.public .bar { display: flex; flex-direction: row; align-items: center; justify-content: space-between; width: 100%; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px 20px; padding-top: max(12px, env(safe-area-inset-top)); overflow: visible; }
body.public .brand { display: flex; align-items: center; gap: 12px; margin: 0; padding: 0; }
body.public .brand .mark { height: 18px; padding: 0; }
body.public .firm-card { padding: 0 0 0 12px; border: 0; border-left: 1px solid var(--border); border-radius: 0; background: transparent; }
body.public .firm-card img { display: none; }
body.public .tabs { display: none; }
body.public .who { flex-direction: row; align-items: center; margin: 0; border: 0; padding: 0; }
body.public .who span { display: none; }
body.public .who button { border: 1px solid var(--border); border-radius: var(--radius); }
body.public main { padding: 24px 20px 40px; }
.intake { max-width: 920px; width: 100%; margin: 8px auto 0; }
.intake-head { display: grid; gap: 6px; justify-items: start; }
.intake-head h1 { font-size: clamp(22px, 3vw, 28px); letter-spacing: -.01em; }
.intake-head p { margin: 0; max-width: 60ch; }
.intake-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(260px, 1fr); gap: 16px; align-items: start; }
.intake-links { display: grid; gap: 12px; }
.intake-links p { margin: 0; }
.narrow-in { max-width: 520px; width: 100%; }
button.wide { width: 100%; min-height: 48px; font-size: 15px; }
.needs { display: grid; gap: 12px; }
.needs h3 { margin: 0; }
.needs-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.needs-list li { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px; align-items: center; }
.needs-list strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.3; }
.needs-list small { display: block; font-size: 12.5px; color: var(--text-muted); line-height: 1.35; }
.ico { width: 36px; height: 36px; border-radius: 10px; background: #5b74b81f; color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; }
.ico svg { width: 20px; height: 20px; }
.needs-foot { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px; align-items: center; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); line-height: 1.4; }
.needs-foot .ico { background: #22c55e1a; color: var(--success); }
fieldset.group { border: 0; padding: 0; margin: 6px 0 0; min-width: 0; }
fieldset.group legend { padding: 0; margin: 0 0 10px; font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--text-muted); }
.code-row { display: grid; grid-template-columns: minmax(0, 220px) auto; gap: 12px; align-items: end; }
.code-row a { padding-bottom: 4px; }
input.otp { font-family: "SF Mono", ui-monospace, monospace; font-size: 22px; letter-spacing: .3em; text-align: center; }
.muted.small, p.small, span.small, a.small { font-size: 12.5px; }
label.consent { white-space: normal; align-items: flex-start; font-size: 13px; color: var(--text-muted); line-height: 1.45; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
label.consent input { margin-top: 2px; flex: 0 0 auto; }
.notice.ok { border-color: #22c55e66; background: rgba(34, 197, 94, .07); }
.stepper { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stepper li { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); color: var(--text-muted); font-size: 13px; min-width: 0; }
.stepper .dot { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.stepper .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stepper li.now { border-color: var(--accent); color: var(--text); }
.stepper li.now .dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.stepper li.done { color: var(--text); }
.stepper li.done .dot { background: #22c55e22; border-color: transparent; color: var(--success); }
.intake-bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.intake-bar h2 { margin-bottom: 2px; }
.intake-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.intake-foot p { margin: 0; flex: 1 1 260px; }
.doc-slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.doc-slot { border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px; background: var(--bg-input); display: grid; gap: 8px; align-content: start; min-width: 0; }
.doc-slot.has { border-style: solid; }
.doc-slot.rejected { border-color: var(--danger); }
.doc-slot-head { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 10px; align-items: start; }
.doc-slot-head strong { display: block; font-size: 14px; line-height: 1.3; }
.doc-slot-head .muted { display: block; overflow-wrap: anywhere; }
.doc-mark { width: 24px; height: 24px; border-radius: 50%; border: 1px dashed var(--border); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.doc-mark.ok { border: 0; background: #22c55e22; color: var(--success); }
.doc-mark.bad { border: 0; background: #ef444422; color: var(--danger-text); }
.doc-actions { align-items: flex-end; }
.doc-actions label.field { flex: 1 1 160px; }
.doc-slot p { margin: 0; }
.upbar { height: 4px; border-radius: 4px; background: var(--border); overflow: hidden; }
.upbar span { display: block; height: 100%; width: 40%; background: var(--accent); animation: upbar 1.1s ease-in-out infinite; }
@keyframes upbar { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) { .upbar span { animation: none; width: 100%; } }
.notice.bad { border-color: var(--danger); background: rgba(239, 68, 68, .08); }
.notice p { margin: 4px 0 0; }
.notice.sim { padding: 10px 14px; border: 1px solid var(--warning); border-radius: var(--radius); background: rgba(245, 158, 11, .08); font-size: 13.5px; line-height: 1.45; overflow-wrap: anywhere; }
.notice.sim strong { color: var(--warning); }
.demo-card { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); color: var(--text); text-decoration: none; }
.demo-card:hover { border-color: var(--gold); background: var(--bg-card-hover); }
.demo-card strong { display: block; font-size: 14.5px; }
.demo-card .muted { font-size: 12.5px; display: block; }
.demo-tag { font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: #1a1204; background: var(--gold); border-radius: 6px; padding: 4px 8px; }
.demo-go { color: var(--gold); font-size: 18px; }
@media (max-width: 760px) {
  .intake { margin-top: 0; }
  .intake-grid, .doc-slots { grid-template-columns: 1fr; }
  body.public main { padding: 16px 14px 32px; }
  body.public .firm-card { display: none; }
  .code-row { grid-template-columns: 1fr; gap: 4px; }
  .code-row a { padding-bottom: 0; }

  .stepper { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .stepper li { flex-direction: column; gap: 4px; padding: 8px 4px; font-size: 11px; text-align: center; }
  .stepper .lbl { white-space: normal; }
  .intake-foot > button { width: 100%; }
}

/* Empresas: portfolio tiles of equal height; pinned companies */
.kpis.portfolio button.kpi.tap { display: flex; flex-direction: column; justify-content: space-between; gap: 6px; min-height: 104px; }
.kpis.portfolio .kpi .muted { line-height: 1.25; min-height: 2.5em; }
.kpis.portfolio .kpi strong { margin-top: 0; }
.kpi-sub { font-size: 12px; color: var(--text-muted); line-height: 1.3; }
.kpis.portfolio .kpi.ok strong { color: var(--success); }
.kpis.portfolio .kpi.warn strong { color: var(--warning); }
.kpis.portfolio .kpi.bad strong { color: var(--danger-text); }
.name-line { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.name-line .name-text { min-width: 0; }
.name-line strong { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* Pin: fixed 22 px slot so every name starts at the same x; only the pinned rows show it. */
button.pin { flex: 0 0 22px; width: 22px; height: 22px; min-height: 22px; min-width: 22px; margin-top: -1px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--text-dim); display: inline-grid; place-items: center; opacity: 0; transition: opacity .15s, color .15s, background .15s; }
button.pin .ico, button.pin svg { width: 15px; height: 15px; display: block; }
button.pin svg { transform: rotate(35deg); }
tr:hover button.pin, button.pin:focus-visible { opacity: .55; }
button.pin:hover { opacity: 1; color: var(--gold); background: #d4a85318; transform: none; }
button.pin.on { opacity: 1; color: var(--gold); }
button.pin.on svg .head { fill: currentColor; }
/* The last pinned row closes the group with a slightly stronger rule. */
@media (min-width: 641px) { table.grid-table tbody tr.pinned + tr:not(.pinned) > td { box-shadow: inset 0 1px 0 #d4a85340; } }
@media (hover: none) { button.pin { opacity: .35; } }
@media (max-width: 640px) { .kpis.portfolio button.kpi.tap { min-height: 92px; } .kpis.portfolio .kpi .muted { min-height: 0; } button.pin { flex-basis: 32px; width: 32px; height: 32px; min-width: 32px; margin: -5px 0 0 -6px; } }
.code-row a.small { display: inline-flex; align-items: center; min-height: 40px; padding: 0 4px; }

/* A name that opens the company (Calendario): reads as text, acts as a link. */
button.linkish { display: inline-flex; align-items: center; min-height: 32px; padding: 0; border: 0; background: none; color: var(--text); font: inherit; font-weight: 600; text-align: left; text-decoration: underline; text-decoration-color: #ffffff30; text-underline-offset: 3px; cursor: pointer; }
button.linkish:hover, button.linkish:focus-visible { color: var(--gold); text-decoration-color: currentColor; background: none; transform: none; }

/* Sign-in entrance: pitch on the left, sign-in + create account + demo on the right. */
.entry { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 420px); gap: 40px; align-items: center; max-width: 980px; width: 100%; margin: 40px auto 0; }
.entry-tag { display: inline-block; font-size: 11.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--gold); border: 1px solid #d4a85355; border-radius: 999px; padding: 4px 10px; }
.entry-pitch h1 { font-size: 38px; line-height: 1.1; letter-spacing: -.5px; margin: 14px 0 12px; }
.entry-pitch h1 em { font-style: normal; color: var(--gold); }
.entry-pitch > p { font-size: 16px; line-height: 1.5; margin: 0 0 20px; max-width: 46ch; }
.entry-perks { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.entry-perks li { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; align-items: start; }
.entry-perks strong { display: block; font-size: 15px; }
.entry-perks small { display: block; font-size: 13px; color: var(--text-muted); line-height: 1.4; }
.entry-check { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: #22c55e1a; color: var(--success); font-weight: 700; font-size: 14px; }
.entry-side { display: grid; gap: 12px; }
.entry-card { padding: 22px; }
.entry-card h2 { margin: 0 0 4px; font-size: 20px; }
.entry-card > p { margin: 0 0 14px; font-size: 13.5px; }
.entry-card button.wide { width: 100%; min-height: 48px; font-size: 15.5px; }
.entry-alt { display: grid; gap: 8px; }
a.entry-link { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); color: var(--text); text-decoration: none; transition: border-color .15s, background .15s; }
a.entry-link:hover { border-color: var(--accent); background: var(--bg-card-hover); }
a.entry-link.demo:hover { border-color: var(--gold); }
a.entry-link strong { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
a.entry-link small { display: block; margin-top: 3px; font-size: 12.5px; color: var(--text-muted); line-height: 1.35; }
a.entry-link .demo-tag { font-size: 10px; padding: 3px 6px; }
.entry-go { color: var(--accent-text); font-size: 18px; }
a.entry-link.demo .entry-go { color: var(--gold); }
@media (max-width: 860px) {
  .entry { grid-template-columns: 1fr; gap: 20px; margin-top: 16px; max-width: 520px; }
  .entry-pitch h1 { font-size: 28px; margin: 10px 0 8px; }
  .entry-pitch > p { font-size: 15px; margin-bottom: 0; }
  .entry-perks { display: none; }
}
@media (max-width: 640px) {
  .entry-pitch h1 { font-size: 25px; }
  .entry-card { padding: 18px 16px; }
}

/* /registro: verified e-mail line, Colombian mobile with flag */
.verified { margin: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.phone-co { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); overflow: hidden; }
.phone-co:focus-within { border-color: var(--border-focus); }
.phone-co .phone-cc { display: grid; place-items: center; padding: 0 10px; border-right: 1px solid var(--border); font-size: 16px; }
.phone-co input { border: 0; border-radius: 0; background: transparent; flex: 1 1 auto; min-width: 0; }
.phone-co input:focus { outline: none; box-shadow: none; }

/* Intake sent: thank-you + read-only summary */
.card.thanks { max-width: 620px; width: 100%; margin: 0 auto; text-align: center; display: grid; gap: 10px; justify-items: center; padding: 32px 24px; }
.thanks h1 { font-size: 24px; margin: 4px 0 0; }
.thanks p { margin: 0; max-width: 48ch; line-height: 1.5; }
.thanks-ico { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; font-weight: 700; color: var(--success); background: #22c55e1a; border: 1px solid #22c55e55; }
.thanks-sum { width: 100%; margin: 12px 0 0; padding-top: 14px; border-top: 1px solid var(--border); display: grid; gap: 8px; text-align: left; }
.thanks-sum > div { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; }
.thanks-sum dt { color: var(--text-muted); font-size: 13px; }
.thanks-sum dd { margin: 0; overflow-wrap: anywhere; }
.thanks-docs { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.thanks-docs .ok { color: var(--success); font-weight: 700; }
@media (max-width: 640px) { .card.thanks { padding: 24px 16px; } .thanks h1 { font-size: 20px; } .thanks-sum > div { grid-template-columns: 1fr; gap: 2px; } }

.support-msg { margin: 0; padding: 10px 12px; border-left: 3px solid var(--border); background: var(--bg-input); border-radius: 0 8px 8px 0; color: var(--text-muted); white-space: pre-wrap; overflow-wrap: anywhere; }
a.terms-link { display: inline-flex; align-items: center; min-height: 32px; font-size: 13px; color: var(--accent-text); width: fit-content; }

/* Documentos: DIAN state and Libro never wrap */
td[data-l="Estado DIAN"] .pill, td[data-l="Libro"] > span { white-space: nowrap; }
@media (min-width: 641px) { td[data-l="Estado DIAN"], td[data-l="Libro"] { white-space: nowrap; width: 1%; } }

/* Soporte: sidebar button (next to Salir) + dialog */
#help { position: relative; }
#help svg { flex: 0 0 18px; }
/* `.who span` (e-mail line) sets padding / overflow on every span: reset them, or the dot becomes an oval. */
.who #help .help-dot { display: block; position: absolute; top: 8px; left: 27px; box-sizing: content-box; width: 8px; height: 8px; min-width: 8px; padding: 0; margin: 0; overflow: visible; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 2px var(--bg-card); flex: none; line-height: 0; }
.who #help .help-dot[hidden] { display: none; }
.field-label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.seg-opt { position: relative; display: inline-flex; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-opt span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13.5px; font-weight: 600; }
.seg-opt input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg-opt input:focus-visible + span { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.support-state { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#support textarea { width: 100%; min-height: 104px; resize: vertical; }

/* Legal footer on sign-in / registro */
.legal-foot { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }
.legal-foot .row { gap: 4px 14px; flex-wrap: wrap; }
.legal-foot a { color: var(--accent-text); display: inline-flex; align-items: center; min-height: 32px; }
.legal-links { gap: 4px 16px; flex-wrap: wrap; }
.support-access { display: grid; gap: 4px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.support-access.on { border-color: #22c55e66; }
.support-access .row { margin-top: 6px; }

/* Contabilidad → Registrar: nuevo asiento, saldos iniciales, plan de cuentas */
.entry-lines { display: grid; gap: 8px; }
.entry-line { display: grid; grid-template-columns: minmax(120px, 1.2fr) minmax(0, 1.6fr) minmax(100px, 1fr) minmax(100px, 1fr) auto; gap: 8px; align-items: end; }
.entry-line .acc-name { align-self: center; overflow-wrap: anywhere; }
.entry-line input { width: 100%; min-height: 44px; }
.entry-totals { display: flex; flex-wrap: wrap; gap: 8px 22px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); font-variant-numeric: tabular-nums; }
.entry-totals > span { display: grid; gap: 2px; }
.entry-totals small { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.entry-totals .bad b, .entry-totals .bad small { color: var(--danger-text); }
.entry-totals .ok b { color: var(--success); }
/* Comprobantes: cuenta · tercero · concepto · débito · crédito per line, type + number + date on the head. */
.voucher-lines .entry-line { grid-template-columns: minmax(110px, .9fr) minmax(0, 1.1fr) minmax(140px, 1.2fr) minmax(140px, 1.4fr) minmax(96px, .8fr) minmax(96px, .8fr) auto; }
/* Marcación (CNT): base / cheque appear only when the account asks; the hint spans the row. */
.entry-line .mark-field.hide { display: none; }
.entry-line .mark-need { grid-column: 1 / -1; }
.entry-line .mark-need:empty { display: none; }
.mark-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.pill.mark { font-size: 10px; padding: 2px 8px; text-transform: none; letter-spacing: 0; }
.pill.mark.inh { background: transparent; border: 1px dashed var(--border); color: var(--text-muted); }
.marks-grid { display: grid; gap: 10px; }
.mark-row { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.mark-row p { margin: 2px 0 0; }
.mark-row select { min-height: 44px; width: 100%; }
@media (max-width: 640px) { .mark-row { grid-template-columns: 1fr; gap: 8px; } }
.voucher-head .voucher-number { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border: 1px dashed var(--border); border-radius: var(--radius); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 650; white-space: nowrap; }
.entry.voucher .entry-meta { gap: 10px; align-items: center; }
/* Simplificado / Detallado switch next to the report filters. */
.mode-seg .chip { min-height: 40px; padding: 4px 12px; }
/* Tree reports (balance detallado, ESF / ERI por cuentas, informe tributario): indent by level, weight by depth. */
.report.tree tr.lvl-1 td { font-weight: 700; background: #5b74b816; }
.report.tree tr.lvl-section td { font-weight: 700; background: #5b74b822; letter-spacing: .3px; }
.report.tree tr.lvl-2 td { font-weight: 650; background: #5b74b80a; }
.report.tree tr.lvl-2 td:first-child { padding-left: 16px; }
.report.tree tr.lvl-3 td:first-child { padding-left: 28px; }
.report.tree tr.lvl-4 td:first-child { padding-left: 40px; }
.report.tree tr.lvl-5 td:first-child { padding-left: 52px; }
.report.tree tr.lvl-5 td, .report.tree tr.lvl-third td { color: var(--text-muted); }
.report.tree tr.lvl-third td:first-child { padding-left: 64px; }
.report.tree tr.total.grand td { border-top: 3px double var(--border); font-weight: 750; }
.report.tree tr.total td:first-child { padding-left: 0; }
.report.tree tr.total.lvl-2 td:first-child { padding-left: 16px; }
.report.tree tr.total.lvl-3 td:first-child { padding-left: 28px; }
.report.tree tr.total.lvl-4 td:first-child { padding-left: 40px; }
/* Columnario: the wide D/C-per-account grid on desktop, one block per comprobante type on phones. */
.report.columnario th, .report.columnario td { white-space: nowrap; }
.columnario-blocks { display: none; }
@media (max-width: 760px) {
  .report.columnario .scroll { display: none; }
  .columnario-blocks { display: grid; }
  .report.tree tr.lvl-2 td:first-child, .report.tree tr.lvl-3 td:first-child, .report.tree tr.lvl-4 td:first-child, .report.tree tr.lvl-5 td:first-child, .report.tree tr.lvl-third td:first-child, .report.tree tr.total td:first-child { padding-left: 0; }
  .report.tree tr.lvl-2 td:first-child::after { content: " · grupo"; color: var(--text-muted); font-weight: 400; }
}
textarea.mono { width: 100%; min-height: 150px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
tr.inactive td { opacity: .6; }
td.acc-l4 { padding-left: 18px; }
td.acc-l6, td.acc-l8, td.acc-l10 { padding-left: 30px; }
td.doc-actions { white-space: nowrap; }
td.doc-actions button + button { margin-left: 6px; }
@media (max-width: 640px) {
  .entry-line { grid-template-columns: 1fr 1fr; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); }
  .entry-line > label:first-child { grid-column: 1 / -1; }
  .entry-line .acc-name { grid-column: 1 / -1; }
  .entry-line > button { grid-column: 1 / -1; justify-self: end; }
  td.acc-l4, td.acc-l6, td.acc-l8, td.acc-l10 { padding-left: 0; }
  td.doc-actions { white-space: normal; }
  td.doc-actions button { margin: 4px 6px 0 0; }
}

/* Report picker as a native select: phones only (the chips stay on tablets and desktop). */
.seg-select { display: none; }
.tabs[hidden] { display: none !important; }

/* ── Phone pass (≤ 640 px): one-row header, bottom tab bar, every tab laid out for a thumb ── */
@media (max-width: 640px) {
  /* Header: brand + firm on the left, Soporte / Salir as icons on the right. */
  /* One 56 px row: wordmark · logo + firm (one line each, never wrapping) · two borderless icon buttons. */
  .bar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "brand who"; min-height: 56px; padding: 6px 6px 6px 12px; padding-top: max(6px, env(safe-area-inset-top)); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); column-gap: 4px; row-gap: 0; }
  .brand { gap: 9px; min-width: 0; overflow: hidden; }
  .brand .mark { height: 14px; flex: 0 0 auto; }
  .firm-card { flex: 1 1 auto; min-width: 0; padding-left: 9px; gap: 8px; }
  .firm-card img { width: 28px; height: 28px; }
  .firm-text { gap: 0; }
  .firm-text strong { font-size: 13.5px; line-height: 1.2; }
  .firm-sub { display: flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 11px; line-height: 1.3; }
  .firm-sub .demo-badge { margin-left: 0; padding: 0 6px; font-size: 9px; line-height: 14px; }
  .who { gap: 0; }
  .who button { font-size: 0; gap: 0; width: 44px; min-width: 44px; min-height: 44px; padding: 0; justify-content: center; border: 0; border-radius: 10px; color: var(--text-muted); }
  .who button:hover, .who button:active { background: var(--bg-card-hover); color: var(--text); }
  .who button svg { width: 21px; height: 21px; flex: 0 0 21px; }
  .who #help .help-dot { top: 9px; left: 27px; }

  /* Bottom tab bar: the five sections always one tap away, icon + label. */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; grid-area: auto;
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0;
    padding: 0 4px env(safe-area-inset-bottom); background: var(--bg-card);
    border-top: 1px solid var(--border); box-shadow: 0 -6px 18px rgba(0, 0, 0, .28);
  }
  .tabs button {
    flex-direction: column; justify-content: center; gap: 3px; width: auto; min-width: 0; min-height: 56px; margin: 0;
    padding: 6px 2px 5px; font-size: 11px; line-height: 1.1; text-align: center;
    border: 0; border-top: 2px solid transparent; border-radius: 0;
  }
  .tabs button svg { display: block; width: 21px; height: 21px; flex: 0 0 21px; }
  .tabs button.on { border-top-color: var(--accent); background: transparent; color: var(--text); font-weight: 600; }
  main { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* Toolbars: two controls per row; search / wide fields and actions take the full row. */
  .toolbar { gap: 8px 10px; }
  .toolbar > label.field { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .toolbar > label.field.grow, .toolbar > p, .toolbar > .grow { flex: 1 1 100%; }
  .toolbar > label.inline { flex: 1 1 auto; min-height: 44px; }

  /* Company view: back · Abrir app · Exportar on one row, the five sections as a 3 + 2 grid, period full width. */
  .head-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .head-actions > button { width: 100%; padding: 0 6px; }
  .sub-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 4px; }
  .sub-row > label.field.compact { width: 100%; }
  .subtabs { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; overflow: visible; border-bottom: 0; }
  .subtabs button { grid-column: span 2; min-height: 40px; padding: 0 4px; font-size: 13px; border: 1px solid var(--border); border-radius: 8px; justify-content: center; }
  .subtabs button:nth-child(n + 4) { grid-column: span 3; }
  .subtabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

  /* Contabilidad / Impuestos: one select instead of a wall of chips. */
  .seg-select { display: block; }
  .seg-groups { display: none; }
  .seg-select label.field > select { font-weight: 600; }

  /* Empresas batch bar: period + main action full width, the rest two per row. */
  .batch { padding: 12px; }
  .batch-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .batch-actions > select, .batch-actions > button:first-of-type, .batch-actions > button:last-child { grid-column: 1 / -1; }
  .batch-actions > button { width: 100%; white-space: normal; line-height: 1.2; min-height: 44px; padding: 6px 10px; }

  /* Report tables keep their columns and scroll sideways; the first column stays put. */
  .report .scroll table.cards td:first-child, .report .scroll table.cards th:first-child { position: sticky; left: 0; z-index: 1; background-color: var(--bg-card); box-shadow: 1px 0 0 var(--border); }
  .report .scroll table.cards tr.lvl-group td:first-child { background-image: linear-gradient(#5b74b80e, #5b74b80e); }
  .report .scroll table.cards tr.unposted td:first-child { background-image: linear-gradient(#f59e0b0c, #f59e0b0c); }
  .report table.cards td { padding: 9px 10px; }
  .report-bar .tools { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }

  /* Documentos and Calendario: one card per row (2–3 short lines) instead of an 8-column scroll. */
  .report.docs .scroll, .report.cal .scroll { overflow: visible; }
  .report.docs table.cards, .report.cal table.cards, .report.docs table.cards tbody, .report.cal table.cards tbody, .report.docs table.cards tfoot, .report.cal table.cards tfoot { display: block; }
  .report.docs table.cards thead, .report.cal table.cards thead { display: none; }
  .report.docs table.cards tr, .report.cal table.cards tr { display: grid; gap: 4px 12px; align-items: start; padding: 12px 2px; border-bottom: 1px solid var(--border); }
  .report.docs table.cards td, .report.cal table.cards td { display: block; position: static; padding: 0; border: 0; min-width: 0; max-width: none; white-space: normal; background: none; box-shadow: none; }
  .report.docs table.cards td::before, .report.cal table.cards td::before { content: none; }
  .report.docs table.cards td div.muted, .report.cal table.cards td div.muted { max-width: none; font-size: 12.5px; }

  .report.docs table.cards tbody tr { grid-template-columns: 28px auto auto minmax(0, 1fr); grid-template-areas: "check num num total" ". ter ter ter" ". date st book" ". act act act"; }
  .report.docs table.cards tbody tr:not(:has(td.check)) { grid-template-columns: auto auto minmax(0, 1fr); grid-template-areas: "num num total" "ter ter ter" "date st book"; }
  .report.docs td.check { grid-area: check; padding-top: 1px; }
  .report.docs td[data-l="Número"] { grid-area: num; }
  .report.docs td[data-l="Número"] .code { font-size: 13.5px; font-weight: 600; }
  .report.docs td[data-l="Total"] { grid-area: total; text-align: right; font-weight: 650; }
  .report.docs td[data-l="Tercero"] { grid-area: ter; overflow-wrap: anywhere; }
  .report.docs td[data-l="Fecha"] { grid-area: date; font-size: 12.5px; color: var(--text-muted); align-self: center; }
  .report.docs td[data-l="Estado DIAN"], .report.docs td[data-l="Medio de pago"] { grid-area: st; align-self: center; }
  .report.docs td[data-l="Libro"] { grid-area: book; font-size: 12.5px; align-self: center; }
  .report.docs td.doc-actions { grid-area: act; }
  .report.docs td.doc-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .report.docs td.doc-actions button { margin: 2px 0 0; min-height: 40px; width: 100%; }
  .report.docs td.doc-actions button + button { margin-left: 0; }
  .report.docs table.cards tfoot tr { grid-template-columns: minmax(0, 1fr) auto; }
  .report.docs table.cards tfoot td.check { display: none; }
  .report.docs table.cards tfoot td.num { text-align: right; }
  .report.docs table.cards tfoot td:not([colspan]):not(.num) { grid-column: 1 / -1; }

  .report.cal table.cards tbody tr { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "emp due" "form per" "st st"; }
  .report.cal table.cards tbody tr:not(:has(td[data-l="Empresa"])) { grid-template-areas: "form due" "per per" "st st"; }
  .report.cal td[data-l="Empresa"] { grid-area: emp; }
  .report.cal td[data-l="Empresa"] button.linkish { font-size: 15px; white-space: normal; }
  .report.cal td[data-l="Vence"] { grid-area: due; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .report.cal td[data-l="Formulario"] { grid-area: form; }
  .report.cal td[data-l="Periodo"] { grid-area: per; font-size: 12.5px; color: var(--text-muted); text-align: right; }
  .report.cal tbody tr:not(:has(td[data-l="Empresa"])) td[data-l="Periodo"] { text-align: left; }
  .report.cal td[data-l="Estado"] { grid-area: st; margin-top: 4px; }

  /* Cierre: compact month tiles. */
  .month { min-height: 0; padding: 8px 10px; }
  .month > button { min-height: 36px; }

  /* Dialogs: header clears the notch, footer stays on screen with the thumb. */
  dialog.modal .modal-head { padding-top: max(12px, env(safe-area-inset-top)); }
  dialog.modal .modal-foot .dialog-actions > button { min-width: 0; min-height: 48px; }
  .fmt-grid { grid-template-columns: 1fr; }
  .step-body .grid.two { grid-template-columns: 1fr; }
}

/* Small phones (≤ 359 px): tighter grids, no clipping. */
@media (max-width: 359px) {
  main { padding-left: 8px; padding-right: 8px; }
  .card { padding: 12px; }
  .tabs button { font-size: 10px; }
  .subtabs button { font-size: 12px; }
  .head-actions > button { font-size: 12px; padding: 0 4px; }
  .report-bar .tools { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar > label.field { flex-basis: 100%; }
  .kpis, .kpis.portfolio { gap: 6px; }
}
/* Narrow phones (< 390 px, e.g. 360 / 375): the firm name needs the room more than the wordmark does. */
@media (max-width: 389px) {
  .brand .mark { display: none; }
  .firm-card { border-left: 0; padding-left: 0; }
}

/* Criterios del contador: open cases first, full-border card (no side stripe). */
.crit-card.has-open { border-color: #f59e0b66; }
.crit-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.crit-case { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); }
.crit-case.open { background: rgba(245, 158, 11, .06); }
.crit-main { display: grid; gap: 3px; min-width: 0; }
.crit-title { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.crit-reason { color: var(--text); overflow-wrap: anywhere; }
.crit-case > button { min-height: 36px; }
@media (max-width: 640px) {
  .crit-case { grid-template-columns: 1fr; }
  .crit-case > button { width: 100%; min-height: 44px; }
}
/* Wave 2 inputs (CSP style-src self: no inline style attributes) */
input.in-upper { text-transform: uppercase; }
input.in-days { width: 5.5em; }
input.in-account { width: 9em; }
