:root {
  --brand: #b3122e; --brand-d: #8e0e24; --brand-l: #fbe9ec;
  --bg: #eef0f3; --card: #fff; --text: #1d2330; --muted: #6b7383; --line: #e3e6eb; --soft: #f6f7f9;
  --green: #2e9b45; --red: #d0103a; --blue: #1e8fe0; --amber: #c27c00;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 8px rgba(16,24,40,.05);
  --side: 230px; --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: "Roboto", "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); -webkit-text-size-adjust: 100%; }
a { color: var(--blue); text-decoration: none; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 17px; margin: 0; }
h4 { font-size: 14px; margin: 14px 0 8px; font-weight: 600; color: #333a48; }
.muted { color: var(--muted); } .small { font-size: 12px; } .b { font-weight: 600; } .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.r { text-align: right; } .c { text-align: center; } .center { text-align: center; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.mt { margin-top: 12px; } .mb { margin-bottom: 8px; } .grow { flex: 1; }
.row { display: flex; align-items: center; } .gap { gap: 8px; } .wrap { flex-wrap: wrap; }
.green, .txt-green { color: var(--green); } .red, .txt-red { color: var(--red); } .blue, .txt-blue { color: var(--blue); } .amber, .txt-amber { color: var(--amber); }
.big { font-size: 20px; }

/* Botones e inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; min-height: 36px; }
.btn:hover { border-color: #c9ced6; background: var(--soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #f2c2cc; }
.btn.danger:not(.ghost) { background: var(--red); color: #fff; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.icon { padding: 4px 8px; min-height: 30px; border-color: transparent; background: transparent; }
.btn.xs { min-height: 24px; padding: 2px 6px; font-size: 12px; }
.btn.block { width: 100%; justify-content: flex-start; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input { width: 100%; border: 1px solid #d5d9e0; border-radius: 8px; padding: 8px 10px; font: inherit; background: #fff; color: var(--text); min-height: 36px; }
.input:focus { outline: 2px solid rgba(179,18,46,.25); border-color: var(--brand); }
.input.sm { width: auto; min-height: 30px; padding: 4px 8px; font-size: 13px; }
.input.r { text-align: right; }
select.input { padding-right: 24px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field em { color: var(--brand); font-style: normal; margin-left: 2px; }
.field.check { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 8px; }
.grid-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: 1 / -1; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); background: #1d2330; color: #cfd5df; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; }
.brand b { display: block; color: #fff; font-size: 15px; } .brand small { color: #9aa3b2; font-size: 11px; }
.side-logo { flex-direction: column; align-items: flex-start; gap: 8px; }
.side-logo img { width: 150px; height: auto; }
.top-logo { height: 30px; width: auto; }
.input.upper { text-transform: uppercase; }
.btn.center-txt { justify-content: center; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.table tr.cancelada td { opacity: .55; text-decoration: line-through; }
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo img { width: 230px; max-width: 80%; height: auto; display: block; margin: 0 auto 8px; }
.login-logo small { color: var(--muted); }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.side nav { flex: 1; overflow: auto; padding: 4px 8px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; color: #cfd5df; border-radius: 8px; margin-bottom: 2px; }
.side nav a:hover { background: rgba(255,255,255,.06); }
.side nav a.on { background: var(--brand); color: #fff; }
.ic { width: 20px; text-align: center; display: inline-block; }
.side-foot { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-foot .btn { color: #cfd5df; border-color: rgba(255,255,255,.15); }
.main { margin-left: var(--side); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 10; background: rgba(238,240,243,.92); backdrop-filter: blur(8px); display: flex; align-items: center; gap: 10px; padding: 10px 24px; border-bottom: 1px solid var(--line); }
.emp-switch { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.emp-switch button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.emp-switch button small { font-weight: 400; opacity: .8; }
.emp-switch button.on { background: var(--brand); color: #fff; }
.emp-one { font-weight: 600; }
.content { padding: 20px 24px 40px; max-width: 1600px; width: 100%; }
.content.loading { opacity: .6; pointer-events: none; }
.page-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.bottom, .sheet-bg, .show-m { display: none; }

/* Tarjetas */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card.soft { background: var(--soft); box-shadow: none; border: 1px solid var(--line); }
.card-t { font-size: 16px; }
.hero { padding: 10px 24px; }
.hero-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; text-align: center; }
.hero-grid > div { padding: 8px 0; }
.hero-l { font-weight: 700; font-size: 18px; text-transform: uppercase; padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.hero-v { font-weight: 700; font-size: 22px; }
.hero-sel { width: auto; font-weight: 700; font-size: 16px; text-transform: uppercase; border: 0; text-align: center; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.kpi.clickable { cursor: pointer; } .kpi.sel { outline: 2px solid var(--brand); }
.kpi-l { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-v { font-size: 19px; font-weight: 700; margin-top: 4px; }
.kpi-s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.summary { display: flex; flex-wrap: wrap; gap: 8px 24px; padding: 10px 0; }
.summary > div { display: flex; flex-direction: column; }
.summary span { font-size: 12px; color: var(--muted); } .summary b { font-size: 16px; }
.alert { background: #fff7e0; border: 1px solid #f3dd9b; border-radius: 8px; padding: 8px 12px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eceef2; color: #4b5262; white-space: nowrap; }
.badge.red { background: #fde7ec; color: var(--red); } .badge.green { background: #e3f5e7; color: var(--green); } .badge.blue { background: #e3f1fc; color: var(--blue); } .badge.amber { background: #fff1d6; color: var(--amber); }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 12px; font: inherit; cursor: pointer; } .seg button.on { background: var(--brand); color: #fff; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--soft); border: 1px solid var(--line); border-radius: 99px; padding: 2px 4px 2px 10px; font-size: 12px; }
.adjuntos { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.xml-drop { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px dashed #cfd4dc; border-radius: 10px; margin-bottom: 14px; background: var(--soft); flex-wrap: wrap; }
.logo-prev { max-height: 60px; max-width: 200px; margin-top: 6px; object-fit: contain; }
.cols-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px; }
.cols-2 .grid-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.sticky { position: sticky; top: 0; }
.breakdown td { padding: 5px 4px; } .breakdown tr.sep td { border-top: 1px solid #cfd4dc; } .breakdown tr.total td { font-size: 16px; }

/* Tablas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: #4b5262; text-transform: uppercase; letter-spacing: .02em; padding: 9px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; background: #fafbfc; position: sticky; top: 0; }
.table th.sortable { cursor: pointer; user-select: none; } .table th.r { text-align: right; }
.table td { padding: 8px 10px; border-bottom: 1px solid #eef0f3; vertical-align: middle; }
.table.dense td { padding: 5px 8px; }
.table tbody tr:nth-child(even) { background: #fbfbfc; }
.table tr.clickable { cursor: pointer; } .table tr.clickable:hover { background: var(--brand-l); }
.table tfoot td { border-top: 2px solid var(--line); background: #fafbfc; }
.table td.empty { text-align: center; color: var(--muted); padding: 24px; }
.table.lines td { padding: 4px 6px; } .table.lines .input { min-height: 32px; padding: 4px 8px; min-width: 70px; }
.dt-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.dt-search { max-width: 260px; }
.acciones { display: flex; gap: 4px; justify-content: flex-end; }

/* Flujo */
.flujo-wrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--line); border-radius: 8px; }
.flujo { border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.flujo th, .flujo td { padding: 5px 9px; white-space: nowrap; text-align: right; border-bottom: 1px solid #eef0f3; min-width: 92px; }
.flujo th { position: sticky; top: 0; background: #fafbfc; z-index: 2; font-weight: 600; border-bottom: 2px solid var(--line); }
.flujo .sticky-col { position: sticky; left: 0; background: #fff; text-align: left; z-index: 1; min-width: 210px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--line); }
.flujo th.sticky-col { z-index: 3; background: #fafbfc; }
.flujo th.hoy { background: var(--brand); color: #fff; }
.flujo td.pasado, .flujo th.pasado { background: #f6f8fb; }
.flujo tr.saldo td { font-weight: 700; background: #f1f3f6; }
.flujo tr.saldo.final td { background: #1d2330; color: #fff; } .flujo tr.saldo.final td.neg { color: #ff8da1; }
.flujo tr.bloque td { font-weight: 600; background: #fafafa; cursor: pointer; }
.flujo tr.fila td.sticky-col { padding-left: 22px; color: #4b5262; }
.flujo td.neg { color: var(--red); }
.flujo td.link { cursor: pointer; text-decoration: underline dotted; }
.flujo.pnl tr.sub td { background: #f1f3f6; } .flujo.pnl tr.grupo td { background: #fafafa; } .flujo.pnl tr.total td { background: #1d2330; color: #fff; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 4px 0 10px; vertical-align: middle; }
.dot.real { background: #e6eaf0; border: 1px solid #c5ccd6; } .dot.proy { background: #fff; border: 1px solid #c5ccd6; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(16,20,28,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 16px; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); display: flex; flex-direction: column; max-height: 92vh; }
.modal.wide { max-width: 860px; } .modal.xl { max-width: 1180px; }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-b { padding: 16px 18px; overflow: auto; }
.modal-f { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #1d2330, #3a1420); }
.login-card { background: #fff; border-radius: 16px; padding: 28px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card .field { margin-bottom: 12px; }
.brand.big { padding: 0 0 16px; } .brand.big b { color: var(--text); font-size: 18px; } .brand.big small { color: var(--muted); }
.splash { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 36px; height: 36px; border: 3px solid #ddd; border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast { background: #1d2330; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.error { background: var(--red); }

/* Móvil */
@media (max-width: 900px) {
  .grid-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-2 { grid-template-columns: 1fr; }
  .hero-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  :root { font-size: 15px; }
  .side { display: none; }
  .main { margin-left: 0; }
  .top { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .content { padding: 12px 12px calc(84px + var(--safe-b)); }
  .hide-m { display: none; } .show-m { display: inline-flex; }
  .emp-switch button { padding: 6px 10px; }
  h1 { font-size: 20px; }
  .grid-form, .cols-2 .grid-form { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .hero { padding: 6px 12px; }
  .hero-l { font-size: 13px; padding-bottom: 6px; margin-bottom: 6px; }
  .hero-v { font-size: 17px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-v { font-size: 16px; }
  .card { padding: 12px; border-radius: 10px; }
  .dt-search { max-width: none; flex: 1 1 100%; }
  /* tablas como tarjetas */
  .table.resp thead { display: none; }
  .table.resp, .table.resp tbody, .table.resp tr, .table.resp td, .table.resp tfoot { display: block; width: 100%; }
  .table.resp tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; padding: 6px 10px; background: #fff !important; }
  .table.resp td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 3px 0; text-align: right; }
  .table.resp td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; font-weight: 500; }
  .table.resp td:empty { display: none; }
  .table.resp td.acciones { justify-content: flex-end; padding-top: 6px; } .table.resp td.acciones::before { content: none; }
  .table.resp td.empty::before { content: none; } .table.resp td.empty { justify-content: center; }
  .table.lines thead { display: none; }
  .table.lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; padding: 6px; }
  .table.lines td { display: flex; flex-direction: column; border: 0; padding: 2px; }
  .table.lines td[data-label]::before { content: attr(data-label); font-size: 11px; color: var(--muted); }
  .table.lines tfoot tr { display: flex; flex-wrap: wrap; }
  .modal-bg { padding: 0; align-items: stretch; }
  .modal, .modal.wide, .modal.xl { max-width: none; max-height: none; min-height: 100%; border-radius: 0; }
  .modal-h { padding-top: calc(14px + env(safe-area-inset-top, 0px)); position: sticky; top: 0; background: #fff; z-index: 2; }
  .modal-f { position: sticky; bottom: 0; background: #fff; padding-bottom: calc(12px + var(--safe-b)); }
  .bottom { display: flex; position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); z-index: 30; padding-bottom: var(--safe-b); }
  .bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; color: var(--muted); font-size: 11px; }
  .bottom a .ic { font-size: 18px; } .bottom a.on { color: var(--brand); }
  .sheet-bg { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 29; }
  .sheet { position: absolute; left: 0; right: 0; bottom: calc(58px + var(--safe-b)); background: #fff; border-radius: 16px 16px 0 0; padding: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
  .sheet a { display: flex; gap: 8px; align-items: center; padding: 12px; border-radius: 10px; color: var(--text); background: var(--soft); }
  .toasts { left: 12px; right: 12px; bottom: calc(70px + var(--safe-b)); }
  .flujo-wrap { max-height: calc(100vh - 260px); }
}
