:root {
  --green: #00a878; --green-dark: #007c5b; --green-ink: #0b6b4f; --green-soft: #e6f6f0; --green-tint: #f2fbf8;
  --navy: #162331; --navy-2: #102f3f; --ink: #22292f; --muted: #6d7882; --line: #e4e9ec; --bg: #f4f7f7; --white: #fff;
  --amber: #e99a36; --amber-ink: #8a5310; --amber-soft: #fff4e2;
  --red: #d85b5b; --red-ink: #a33131; --red-soft: #fdecec;
  --blue: #3973b7; --blue-soft: #eaf1fa; --purple: #9066c3;
  --shadow: 0 8px 28px rgba(19, 35, 49, .07); --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.lucide { width: 18px; height: 18px; stroke-width: 2; flex: none; }
.num, td, .kpi .v { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--white); padding: 10px 24px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand img { height: 30px; }
.app-name { border-left: 1px solid var(--line); padding-left: 14px; font-size: 12px; color: var(--muted); line-height: 1.15; white-space: nowrap; }
.app-name b { display: block; color: var(--navy); font-size: 15px; font-weight: 800; }
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.chip { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 13px; }
.chip select { border: 0; background: transparent; font-weight: 600; outline: none; max-width: 230px; cursor: pointer; }
.chip svg { color: var(--green-dark); width: 16px; height: 16px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--green), #4dd9af); color: #fff; font-weight: 800; font-size: 12px; flex: none; }
.user-chip { padding: 4px 10px 4px 4px; }
.user-chip small { display: block; color: var(--muted); font-size: 11px; }

/* ---------- horizontal nav ---------- */
.mainnav { position: sticky; top: 51px; z-index: 39; display: flex; gap: 4px; padding: 8px 20px; background: var(--navy); overflow-x: auto; scrollbar-width: thin; }
.mainnav button { display: flex; align-items: center; gap: 8px; border: 0; background: transparent; color: #aeb8bf; padding: 9px 14px; border-radius: 10px;
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, color .15s; }
.mainnav button:hover { background: #ffffff12; color: #fff; }
.mainnav button.active { background: var(--green); color: #fff; box-shadow: 0 4px 14px #00a87855; }
.mainnav button.active svg { color: #fff; }
.mainnav button svg { color: #71dfbd; }
.mainnav .sep { width: 1px; background: #ffffff1c; margin: 6px 6px; flex: none; }

main { padding: 22px 24px 60px; max-width: 1680px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; color: var(--navy); letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.eyebrow { color: var(--green-dark); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

/* ---------- cards & grid ---------- */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card h3 { margin: 0 0 4px; font-size: 15px; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.card h3 svg { color: var(--green-dark); }
.card .sub { color: var(--muted); font-size: 12px; margin: 0 0 14px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.mt { margin-top: 16px; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 720px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } main { padding: 16px; } .topbar { padding: 10px 16px; } .app-name { display: none; } }

/* ---------- KPIs ---------- */
.kpi { position: relative; overflow: hidden; }
.kpi .k { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .k .ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--green-soft); color: var(--green-dark); }
.kpi .k .ico svg { width: 16px; height: 16px; }
.kpi .v { font-size: 24px; font-weight: 800; color: var(--navy); margin: 10px 0 4px; letter-spacing: -.02em; }
.kpi .d { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.up { color: var(--green-ink) !important; } .down { color: var(--red-ink) !important; }
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 700; }
.b-good { background: var(--green-soft); color: var(--green-ink); } .b-warn { background: var(--amber-soft); color: var(--amber-ink); }
.b-bad { background: var(--red-soft); color: var(--red-ink); } .b-info { background: var(--blue-soft); color: var(--blue); } .b-mute { background: var(--bg); color: var(--muted); }
.meter { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; background: var(--green); border-radius: 99px; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--white); border-radius: 10px; padding: 8px 13px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c9d3d8; background: #fafcfc; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; } .btn.primary:hover { background: var(--green-dark); }
.btn.dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 9px; font-size: 12px; border-radius: 8px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; width: 26px; height: 26px; border-radius: 7px; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); padding: 0; }
.icon-btn:hover { background: #00000010; color: var(--navy); }
.icon-btn svg { width: 15px; height: 15px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 8px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--white); color: var(--navy); box-shadow: 0 1px 4px #0000001a; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 14px; color: var(--ink); background: #fff; font-weight: 500; }
.field input:focus, .field select:focus { outline: 2px solid #00a87855; border-color: var(--green); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 18px; }
.toolbar .grow { flex: 1; }
.toolbar .field input { padding: 6px 9px; }
.stat-inline { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-inline b { font-size: 16px; color: var(--navy); font-weight: 800; }

/* ---------- table generic ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 9px 10px; border-bottom: 1px solid var(--line); background: #fafbfb; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tfoot td { font-weight: 800; background: #fafbfb; border-top: 2px solid var(--line); }
.tbl-wrap { overflow-x: auto; }

/* ---------- cash flow grid ---------- */
.cf-wrap { overflow: auto; max-height: calc(100vh - 290px); min-height: 360px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
table.cf { border-collapse: separate; border-spacing: 0; font-size: 12px; min-width: 100%; }
table.cf th, table.cf td { border-bottom: 1px solid #edf1f3; border-right: 1px solid #f1f4f5; padding: 0 8px; height: 30px; white-space: nowrap; text-align: right; }
table.cf thead th { position: sticky; background: #fafbfb; z-index: 3; color: var(--muted); font-weight: 700; }
table.cf thead tr:first-child th { top: 0; height: 44px; color: var(--navy); font-size: 12px; border-bottom: 0; }
table.cf thead tr:nth-child(2) th { top: 44px; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; height: 24px; }
table.cf thead th.wk small { display: block; font-weight: 500; color: var(--muted); font-size: 10px; }
table.cf thead th.wk.now { background: var(--green-soft); }
table.cf thead th.wk .wk-real { color: var(--green-ink); }
table.cf .sticky { position: sticky; left: 0; z-index: 2; background: inherit; text-align: left; min-width: 290px; max-width: 290px; border-right: 1px solid var(--line); }
table.cf thead .sticky { z-index: 5; background: #fafbfb; }
table.cf tbody tr { background: #fff; }
table.cf td.c-r { background: var(--green-tint); }
table.cf td.c-v { font-size: 11px; color: var(--muted); min-width: 58px; }
table.cf td.c-p, table.cf td.c-r { min-width: 92px; }
table.cf th.c-tot, table.cf td.c-tot { border-left: 2px solid var(--line); }
table.cf tr.sec td { background: #e9f3ef; color: var(--green-ink); font-weight: 800; font-size: 11px; letter-spacing: .07em; text-transform: uppercase; height: 32px; }
table.cf tr.sec td.sticky { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
table.cf tr.rubro td { background: #fbfcfc; font-weight: 700; color: var(--navy); }
table.cf tr.rubro td.c-r { background: #eef8f4; }
table.cf tr.line td.sticky { padding-left: 34px; font-weight: 500; }
table.cf tr.line.hidden { display: none; }
table.cf tr.tot td { font-weight: 800; background: #f6f8f9; color: var(--navy); }
table.cf tr.tot td.c-r { background: #eaf6f1; }
table.cf tr.grand td { background: var(--navy); color: #fff; font-weight: 800; }
table.cf tr.grand td.c-v { color: #c6d4da; }
table.cf tr.grand td.pos { color: #71dfbd; } table.cf tr.grand td.neg { color: #ffb4b4; }
table.cf tr.spacer td { height: 8px; background: #fff; border: 0; }
table.cf td.pos { color: var(--green-ink); } table.cf td.neg { color: var(--red-ink); }
table.cf td.negv { color: var(--red-ink); }
.rb-name { display: flex; align-items: center; gap: 4px; min-width: 0; }
.rb-name .t { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.rb-name .cnt { font-size: 10px; background: var(--line); color: var(--muted); border-radius: 99px; padding: 1px 7px; font-weight: 700; }
.rb-actions { display: inline-flex; opacity: 0; transition: opacity .12s; }
tr:hover .rb-actions { opacity: 1; }
.toggle svg { transition: transform .15s; }
.toggle.closed svg { transform: rotate(-90deg); }
table.cf input.cell { width: 100%; min-width: 80px; border: 0; background: transparent; text-align: right; padding: 0; height: 28px; font-size: 12px; font-variant-numeric: tabular-nums; }
table.cf input.cell:focus { outline: 2px solid var(--green); border-radius: 4px; background: #fff; }
table.cf input.cell::placeholder { color: #c3ccd1; }
table.cf input.lname { border: 0; background: transparent; width: 100%; font-size: 12px; font-weight: 500; padding: 4px 0; }
table.cf input.lname:focus { outline: 2px solid var(--green); border-radius: 4px; background: #fff; }
table.cf input[disabled] { color: inherit; }
.legend-row { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 10px 2px 0; align-items: center; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; border: 1px solid var(--line); }

/* ---------- reco / alerts ---------- */
.reco { display: flex; gap: 12px; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
.reco + .reco { margin-top: 10px; }
.reco .ri { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.reco b { display: block; color: var(--navy); font-size: 13px; margin-bottom: 3px; }
.reco p { margin: 0; font-size: 12.5px; color: #4e5a63; line-height: 1.45; }
.reco.good .ri { background: var(--green-soft); color: var(--green-ink); }
.reco.warn .ri { background: var(--amber-soft); color: var(--amber-ink); }
.reco.bad .ri { background: var(--red-soft); color: var(--red-ink); }
.reco.info .ri { background: var(--blue-soft); color: var(--blue); }

.hero { border-radius: var(--radius); padding: 22px 24px; color: #fff; display: flex; gap: 20px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: linear-gradient(120deg, var(--navy-2), #0d4a3c 60%, var(--green-dark)); box-shadow: var(--shadow); }
.hero.neg { background: linear-gradient(120deg, #3a1f1f, #6b2a2a 60%, #a33b3b); }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.hero small { color: #c6e9dc; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.hero p { margin: 6px 0 0; color: #d8e9e3; font-size: 13px; max-width: 640px; }
.hero .hero-side { display: flex; gap: 22px; flex-wrap: wrap; }
.hero .hero-side div { background: #ffffff14; border: 1px solid #ffffff22; border-radius: 12px; padding: 10px 14px; min-width: 140px; }
.hero .hero-side b { display: block; font-size: 18px; }

.chart-box { position: relative; height: 290px; }
.chart-box.sm { height: 230px; }
.score-ring { display: grid; place-items: center; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--green); }
.note { font-size: 12px; color: var(--muted); line-height: 1.5; }
.note b { color: var(--ink); }
.lock { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--amber-ink); background: var(--amber-soft); border-radius: 8px; padding: 6px 10px; }

/* ---------- company cards ---------- */
.co-card { display: flex; flex-direction: column; gap: 12px; }
.co-card.current { outline: 2px solid var(--green); }
.co-card .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.co-card .row b { color: var(--navy); }
.co-head { display: flex; gap: 12px; align-items: center; }
.co-logo { width: 42px; height: 42px; border-radius: 12px; background: var(--navy); color: #71dfbd; display: grid; place-items: center; font-weight: 800; }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(7, 24, 33, .6); z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal { background: #fff; border-radius: 16px; width: min(560px, 96vw); max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 90px #0006; }
.modal.wide { width: min(860px, 96vw); }
.modal > form { display: flex; flex-direction: column; min-height: 0; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: var(--navy-2); color: #fff; border-bottom: 4px solid var(--green); }
.modal header h3 { margin: 0; font-size: 16px; }
.modal header .icon-btn { color: #fff; }
.modal .mbody { padding: 18px 20px; overflow: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); background: #fafbfb; }
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); display: flex; gap: 8px; align-items: center; animation: tin .2s ease; }
.toast svg { color: #71dfbd; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }
.bank-row { display: grid; grid-template-columns: 1fr 160px 32px; gap: 8px; margin-bottom: 8px; align-items: center; }
.bank-row input { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.check-list label { display: flex; gap: 8px; align-items: center; font-size: 13px; padding: 4px 0; font-weight: 500; color: var(--ink); }
@media print { .topbar, .mainnav, .btn, .icon-btn { display: none !important; } .cf-wrap { max-height: none; overflow: visible; } }

/* ---------- acceso (servidor compartido) ---------- */
.auth { min-height: calc(100vh - 200px); display: grid; place-items: center; }
.auth-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.auth-card h2 { margin: 0; color: var(--navy); }
.auth-card p { margin: 0; }
.auth-card .btn { justify-content: center; padding: 11px; }
.auth-ico { width: 46px; height: auto; }
.auth-err { min-height: 18px; font-size: 13px; margin: 0; }
.user-chip .icon-btn { width: 28px; height: 28px; }

/* pagos recurrentes */
table.cf td.c-rec { background: repeating-linear-gradient(135deg, transparent 0 6px, rgba(0,168,120,.06) 6px 12px); }
table.cf td.c-rec input.cell:disabled { color: var(--ink, #1d2b36); -webkit-text-fill-color: currentColor; opacity: 1; cursor: default; }
.icon-btn.rec-on { color: var(--green); flex: none; }
.cnt-pill { background: var(--green); color: #fff; border-radius: 99px; padding: 0 7px; font-size: 11px; font-weight: 700; margin-left: 2px; }
.rec-prev { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--green-tint); display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.rec-prev span { color: var(--muted); }
.rec-dates { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.rec-dates span { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; font-size: 12px; color: var(--ink, #1d2b36); }

/* líneas de crédito */
.card.credit { display: flex; flex-direction: column; gap: 14px; }
.cl-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.cl-head h3 { margin: 0 0 6px; }
.cl-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.cl-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.cl-stats > div { background: var(--bg); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cl-stats small { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.cl-stats b { font-size: 17px; font-variant-numeric: tabular-nums; }
.cl-stats em { font-style: normal; font-size: 11px; color: var(--muted); }
.cl-bar { height: 8px; border-radius: 99px; background: var(--line); display: flex; overflow: hidden; }
.cl-bar span { background: var(--green); }
.cl-bar span.prog { background: repeating-linear-gradient(135deg, var(--amber) 0 4px, #f5c88a 4px 8px); }
.cl-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; color: var(--muted); }
.cl-meta span { display: inline-flex; align-items: center; gap: 6px; }
.cl-meta b { color: var(--ink); font-weight: 600; }
.cl-meta svg { width: 15px; height: 15px; }
.cl-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cl-det { border-top: 1px solid var(--line); padding-top: 10px; }
.cl-det summary { cursor: pointer; font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; list-style: none; }
.cl-det summary::-webkit-details-marker { display: none; }
.cl-det summary svg { width: 15px; height: 15px; color: var(--green); }
.cl-det .tbl { margin-top: 8px; font-size: 12px; }
.note-sm { display: block; color: var(--muted); font-size: 11px; }
.radio-cards { display: grid; gap: 8px; margin-top: 6px; }
.radio-cards label { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; font-weight: 400; }
.radio-cards label:has(input:checked) { border-color: var(--green); background: var(--green-tint); }
.radio-cards span { display: flex; flex-direction: column; gap: 2px; }
.radio-cards small { color: var(--muted); font-size: 12px; }
@media (max-width: 720px) { .cl-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
