@font-face { font-family: 'Fraunces'; src: url('/fonts/fraunces-latin-wght-normal.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'DM Sans'; src: url('/fonts/dm-sans-latin-wght-normal.woff2') format('woff2'); font-weight: 100 1000; font-display: swap; }

:root {
  --ink: #372026; --ink-soft: #5c464b; --muted: #7a6a6d;
  --carmin: #C8192F; --carmin-dark: #A5122A; --salmon: #F09E8F; --salmon-soft: #FBE3DD; --pistacho: #D8EFB7; --crema: #EDF4D6;
  --bg: #F6F8EC; --card: #FFFFFF; --line: #E4E8D4; --line-strong: #CFD6B8;
  --ok-bg: #DDF0C3; --ok-fg: #2B4A12; --warn-bg: #FBE3DD; --warn-fg: #7A2A1A; --bad-bg: #F9D5DA; --bad-fg: #8E0F20;
  --radius: 14px; --shadow: 0 1px 2px rgba(55,32,38,.06), 0 4px 14px rgba(55,32,38,.05);
  --font: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif; --serif: 'Fraunces', Georgia, serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 1.9rem; line-height: 1.15; } h2 { font-size: 1.2rem; margin-bottom: .6rem; }
p { margin: .3rem 0 .6rem; } a { color: var(--carmin); } a:hover { color: var(--carmin-dark); }
.num { font-variant-numeric: tabular-nums; } .muted { color: var(--muted); } .small { font-size: .85rem; }
.neg-text { color: var(--carmin); } .ok-text { color: #2f6b12; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid rgba(200,25,47,.45); outline-offset: 2px; }

/* ---------- estructura ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; height: 100vh; }
.side { background: var(--ink); color: var(--crema); display: flex; flex-direction: column; padding: 18px 14px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 16px; }
.brand img { border-radius: 50%; } .brand b { font-family: var(--serif); font-size: 1.15rem; display: block; line-height: 1.1; } .brand small { color: var(--salmon); font-weight: 600; letter-spacing: .04em; }
.ent-pick { display: block; margin: 0 4px 14px; } .ent-pick span { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: #c9b7bb; margin-bottom: 4px; }
.ent-pick select { width: 100%; background: rgba(237,244,214,.1); color: var(--crema); border: 1px solid rgba(237,244,214,.25); border-radius: 8px; padding: 7px 8px; }
.ent-pick select option { color: var(--ink); }
.nav-group { margin-bottom: 12px; } .nav-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .09em; color: #b9a3a8; padding: 0 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--crema); text-decoration: none; font-weight: 500; }
.nav a .ico { width: 20px; text-align: center; opacity: .8; }
.nav a:hover { background: rgba(237,244,214,.08); } .nav a.on { background: rgba(237,244,214,.15); box-shadow: inset 3px 0 0 var(--salmon); font-weight: 700; }
.side-foot { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid rgba(237,244,214,.15); font-size: .85rem; }
.sync { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; } .dot-sync { width: 9px; height: 9px; border-radius: 50%; background: #9ccc65; flex: none; }
.dot-sync.off { background: #bdbdbd; } .dot-sync.err { background: var(--salmon); } .dot-sync.sync { background: #ffd54f; }
.who { display: flex; justify-content: space-between; align-items: center; color: #d9cbce; }
.link { background: none; border: 0; color: var(--salmon); cursor: pointer; text-decoration: underline; padding: 0; }
main#view { overflow-y: auto; height: 100vh; outline: none; }
.page { padding: 28px 34px 60px; max-width: 1280px; margin: 0 auto; } .page.narrow { max-width: 860px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 18px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; } .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- tarjetas ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; } .card-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; } .grid2 > .card { margin-bottom: 0; } .span2 { grid-column: span 2; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-label { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-family: var(--serif); font-size: 1.85rem; font-weight: 600; margin: 4px 0 2px; line-height: 1.1; } .stat-sub { font-size: .82rem; color: var(--muted); }
.stat.neg .stat-value { color: var(--carmin); } .stat.pos .stat-value { color: #2f6b12; } .stat.warn { border-color: var(--salmon); background: #FFF8F6; }
.delta { font-size: .8rem; } .delta.up { color: #2f6b12; } .delta.down { color: var(--carmin); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 18px; margin: 8px 0 0; }
.kpi { border-left: 3px solid var(--pistacho); padding-left: 10px; cursor: help; } .kpi dt { font-size: .78rem; color: var(--muted); font-weight: 600; } .kpi dd { margin: 0; font-family: var(--serif); font-size: 1.35rem; font-weight: 600; } .kpi small { color: var(--muted); font-size: .78rem; display: block; }
.callout { background: var(--crema); border: 1px solid var(--line-strong); border-radius: 12px; padding: 12px 16px; margin: 0 0 18px; } .callout.ok { background: var(--ok-bg); } .callout.err { background: var(--bad-bg); }
details { margin-top: 12px; } summary { cursor: pointer; font-weight: 600; color: var(--ink-soft); }

/* ---------- tablas ---------- */
.table-wrap { overflow-x: auto; margin-top: 8px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; background: #FBFCF5; position: sticky; top: 0; }
.tbl th.sortable { cursor: pointer; user-select: none; } .tbl th.sortable:hover { color: var(--ink); }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.tbl .r { text-align: right; } .tbl td.trunc { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .tbl td.empty { text-align: center; color: var(--muted); padding: 28px; }
.tbl tbody tr:hover { background: #FAFBF3; } .tbl tr.void td { opacity: .5; text-decoration: line-through; }
.tbl tfoot td { font-weight: 700; background: #FBFCF5; border-top: 2px solid var(--line); }
.row-actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; white-space: nowrap; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); } .badge.warn { background: var(--warn-bg); color: var(--warn-fg); } .badge.bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge.neutral { background: var(--crema); color: var(--ink-soft); } .badge.muted { background: #ECE8E8; color: #6b5d60; }

/* ---------- controles ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line-strong); background: #fff; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink); }
.btn:hover { background: var(--crema); } .btn.primary { background: var(--carmin); border-color: var(--carmin); color: #fff; } .btn.primary:hover { background: var(--carmin-dark); }
.btn.ghost { background: transparent; } .btn.danger { background: var(--carmin); color: #fff; border-color: var(--carmin); } .btn.small { padding: 4px 10px; font-size: .82rem; } .btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 4px 7px; border-radius: 7px; font-size: 1rem; color: var(--ink-soft); } .icon-btn:hover { background: var(--crema); }
input[type=text], input[type=search], input[type=date], input[type=password], select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; }
input.ro { background: #F3F4EA; }
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; } .filters input[type=search] { max-width: 320px; } .filters select { width: auto; min-width: 150px; }
.page-head select { width: auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; } .tab { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: #fff; cursor: pointer; font-weight: 600; } .tab.on { background: var(--ink); color: var(--crema); border-color: var(--ink); }

/* ---------- formularios y modales ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(55,32,38,.55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.3); } .modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 6px; } .modal-head h2 { margin: 0; font-size: 1.25rem; } .modal-body { padding: 8px 20px 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; } .form-grid > * { min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; } .field.wide, .form-heading, .total-box, .form-error, .form-actions, .mini-list { grid-column: 1 / -1; }
.field .lbl { font-size: .8rem; font-weight: 700; color: var(--ink-soft); } .field small { color: var(--muted); font-size: .78rem; }
.field.check { flex-direction: row; align-items: center; gap: 8px; } .field.check input { width: 18px; height: 18px; accent-color: var(--carmin); }
.check.inline { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; }
.form-heading { font-family: var(--serif); font-weight: 600; margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.total-box { display: flex; gap: 22px; background: var(--crema); border-radius: 10px; padding: 10px 14px; justify-content: flex-end; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; } .form-actions.left { justify-content: flex-start; margin-top: 12px; }
.form-error { color: var(--carmin); font-weight: 600; min-height: 1.2em; }
.mini-list { background: #FAFBF3; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; } .mini-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 4px 0; border-bottom: 1px dashed var(--line); } .mini-row:last-child { border: 0; }
.ent-row { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; } .ent-row input[type=text] { max-width: 300px; }
.steps { padding-left: 20px; } .steps li { margin: 6px 0; } .errs { max-height: 220px; overflow: auto; font-size: .85rem; color: var(--bad-fg); }

/* ---------- gráficos ---------- */
.chart svg { width: 100%; height: auto; display: block; } .chart .ax { font-size: 11px; fill: #7A6A6D; }
.chart .pt .guide, .chart .pt .dot { opacity: 0; } .chart .pt:hover .guide, .chart .pt:hover .dot { opacity: 1; }
.chart .hit:hover { fill: rgba(55,32,38,.05); }
.legend { display: flex; gap: 18px; font-size: .85rem; margin: 4px 0 6px; } .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
#tip { position: fixed; display: none; pointer-events: none; z-index: 100; background: var(--ink); color: #fff; padding: 8px 11px; border-radius: 9px; font-size: .82rem; line-height: 1.5; max-width: 260px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
#tip .dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }
.hbars { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; } .hrow { display: grid; grid-template-columns: minmax(90px, 34%) 1fr 90px; align-items: center; gap: 10px; font-size: .85rem; }
.hname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .htrack { background: #F1F4E4; border-radius: 4px; height: 12px; } .hfill { height: 100%; border-radius: 4px; } .hval { text-align: right; }

/* ---------- listas de datos ---------- */
.rows > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); } .rows dt { color: var(--ink-soft); } .rows dd { margin: 0; font-weight: 600; }
.rows .sub dt { font-size: .78rem; color: var(--muted); padding-left: 14px; } .rows .sub { border: 0; padding: 0 0 4px; } .rows .total { border-top: 2px solid var(--ink); border-bottom: 0; font-size: 1.05rem; }
.deadlines { list-style: none; padding: 0; margin: 0; } .deadlines li { display: grid; grid-template-columns: 100px 1fr auto; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); } .when { font-weight: 700; }
.glossary > div { padding: 10px 0; border-bottom: 1px solid var(--line); } .glossary dt { font-weight: 700; font-family: var(--serif); } .glossary dd { margin: 2px 0 0; color: var(--ink-soft); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 20px; }
.login-card { background: #fff; border-radius: 20px; padding: 32px 30px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-card img { align-self: center; border-radius: 50%; } .login-card .field { text-align: left; } .login-card p { margin: -8px 0 4px; }

#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); transition: opacity .3s, transform .3s; } .toast.err { background: var(--carmin); } .toast.out { opacity: 0; transform: translateY(6px); }

@media (max-width: 1000px) { .grid2 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } .shell { grid-template-columns: 200px 1fr; } .page { padding: 20px 16px 50px; } }
@media (max-width: 720px) { .shell { grid-template-columns: 1fr; height: auto; } .side { position: static; } main#view { height: auto; } .form-grid { grid-template-columns: 1fr; } }
@media print { .side, .actions, .filters, .row-actions { display: none !important; } .shell { display: block; height: auto; } main#view { height: auto; overflow: visible; } body { background: #fff; } .card { box-shadow: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- importación de PDF ---------- */
.dropzone { border: 2px dashed var(--line-strong); border-radius: 14px; padding: 26px; text-align: center; cursor: pointer; background: #FBFCF5; margin: 6px 0 14px; }
.dropzone:hover, .dropzone.over { border-color: var(--carmin); background: var(--salmon-soft); }
.inline-label { display: inline-flex; align-items: center; gap: 8px; font-size: .85rem; font-weight: 600; color: var(--ink-soft); } .inline-label select, .inline-label input { width: auto; }
.pdf-tbl input, .pdf-tbl select { padding: 5px 7px; font-size: .85rem; } .pdf-tbl input.w90 { width: 84px; } .pdf-tbl input.w180 { width: 150px; } .pdf-tbl td { vertical-align: top; }
.warn-in { border-color: var(--carmin) !important; background: #FFF4F5; }
.rawtext { white-space: pre-wrap; background: #FAFBF3; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: .75rem; max-height: 220px; overflow: auto; margin: 6px 0 0; }
.pdf-tbl tr.detail td { padding: 0 10px 6px; border-bottom: 1px solid var(--line); white-space: normal; } .pdf-tbl tr.detail details { margin: 0; }

/* tarjetas desplegables en tablas */
.tbl tr.open > td { background: #FAFBF3; }
.tbl tr.detail-row:hover { background: transparent; }
.tbl tr.detail-row > td { white-space: normal; padding: 0; background: #FBFCF5; }
.inv-card { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 22px; padding: 12px 16px 14px 44px; }
.inv-card .kv { display: flex; flex-direction: column; gap: 2px; } .inv-card .k { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); } .inv-card .v { font-size: .92rem; word-break: break-word; }
.cli-card { padding: 10px 16px 14px 44px; } .cli-card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.cli-card .table-wrap { background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.icon-btn.chev { width: 26px; padding: 0; } .stage-cell { display: inline-flex; gap: 4px; align-items: center; flex-wrap: nowrap; }
.link.plain { text-decoration: none; color: inherit; font: inherit; font-weight: 600; text-align: left; } .link.plain:hover { color: var(--salmon); text-decoration: underline; }
.tbl td .link { color: var(--ink); text-decoration: none; font-weight: 600; } .tbl td .link:hover { color: var(--salmon); text-decoration: underline; }
.tbl td.trunc { max-width: 170px; } .tbl th, .tbl td { padding-left: 8px; padding-right: 8px; }
.page-head.stack { flex-direction: column; align-items: flex-start; gap: 14px; } .page-head.stack .actions { justify-content: flex-start; }
.pdf-tbl select { min-width: 66px; } .pdf-tbl select.w150 { min-width: 150px; }
.field[hidden] { display: none; }
.manual-note { color: var(--muted); margin: 0 0 6px; }
.badge.light-verde { background: var(--ok-bg); color: var(--ok-fg); } .badge.light-amarillo { background: #FFF0B8; color: #6b5200; } .badge.light-rojo { background: var(--bad-bg); color: var(--bad-fg); }
.link.back { display: inline-block; margin-bottom: 6px; font-weight: 600; }
.cli-detail .wrap { white-space: normal; display: block; max-width: 46ch; }
.cli-detail .page-head .actions { align-items: center; gap: 8px; }
.toissue { background: var(--card, #fff); border: 1px solid var(--line, #e7dfdf); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; }
.toissue summary { cursor: pointer; padding: 4px 0; } .toissue[open] summary { margin-bottom: 8px; }
