:root {
  --ink: #15243a;
  --muted: #6c7a8d;
  --line: #e3e8ef;
  --surface: #ffffff;
  --canvas: #f4f6f9;
  --navy: #17365d;
  --blue: #2e6fbb;
  --blue-soft: #eaf2fb;
  --red: #df5b66;
  --red-soft: #fcecef;
  --teal: #35a48f;
  --teal-soft: #e7f7f3;
  --amber: #d79528;
  --shadow: 0 7px 22px rgba(25, 43, 70, .07);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }

.topbar { height: 68px; padding: 0 26px; background: var(--navy); color: white; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 30; box-shadow: 0 4px 14px rgba(12, 31, 55, .18); }
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 37px; height: 37px; display: grid; place-items: center; border-radius: 10px; background: #fff; color: var(--navy); font-weight: 850; font-size: 21px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: .1px; }
.brand small { font-size: 10.5px; margin-top: 1px; color: #bdcbe0; }
.topbar-actions { display: flex; gap: 12px; align-items: center; }
.module-nav { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 10px; background: rgba(255,255,255,.08); }
.module-tab { border: 0; border-radius: 7px; padding: 8px 11px; background: transparent; color: #c5d2e4; font-size: 11px; font-weight: 700; white-space: nowrap; }
.module-tab:hover { color: white; background: rgba(255,255,255,.08); }
.module-tab.active { background: white; color: var(--navy); box-shadow: 0 2px 7px rgba(7,24,45,.18); }
.private-pill { font-size: 12px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); border-radius: 999px; padding: 7px 11px; display: flex; align-items: center; gap: 7px; }
.private-pill span { width: 7px; height: 7px; background: #78d4a3; border-radius: 50%; box-shadow: 0 0 0 3px rgba(120,212,163,.14); }
.icon-button { border: 0; background: transparent; color: inherit; font-size: 21px; line-height: 1; }
#mobileFilters { display: none; }

.app-shell { display: grid; grid-template-columns: 246px 1fr; min-height: calc(100vh - 68px); }
.app-shell.compact { grid-template-columns: 1fr; }
.filter-panel { padding: 26px 20px; background: #fff; border-right: 1px solid var(--line); position: sticky; top: 68px; height: calc(100vh - 68px); overflow-y: auto; }
.filter-panel.hidden { display: none; }
.filter-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 24px; }
.filter-heading h2 { margin: 3px 0 0; font-size: 19px; }
.eyebrow { color: var(--blue); letter-spacing: .11em; font-size: 9.5px; line-height: 1.2; font-weight: 800; margin: 0; }
.text-button { border: 0; background: none; color: var(--blue); padding: 4px 0; font-size: 12px; font-weight: 700; }
.field { display: grid; gap: 7px; margin-bottom: 17px; }
.field > span { font-size: 11px; color: #526175; font-weight: 700; }
.date-range-field { border: 0; padding: 0; min-width: 0; }
.date-range-field > legend { padding: 0; margin-bottom: 7px; font-size: 11px; color: #526175; font-weight: 700; }
.date-range { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.date-range label { display: grid; gap: 5px; min-width: 0; }
.date-range label span { font-size: 9px; color: var(--muted); font-weight: 700; }
.date-range input { min-width: 0; padding: 9px 6px; font-size: 10px; }
input, select { width: 100%; border: 1px solid #d8dfe8; border-radius: 8px; padding: 10px 11px; background: white; color: var(--ink); outline: none; font-size: 12px; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46,111,187,.1); }
.search-field input { background: #f8fafc; }
.filter-summary { margin-top: 25px; background: #f1f6fb; border: 1px solid #dae8f5; border-radius: 11px; padding: 14px; }
.filter-summary span, .filter-summary small, .filter-summary strong { display: block; }
.filter-summary span { font-size: 10px; color: var(--muted); text-transform: uppercase; font-weight: 750; letter-spacing: .08em; }
.filter-summary strong { margin: 6px 0 2px; font-size: 15px; }
.filter-summary small { font-weight: 650; color: var(--blue); }

.content { min-width: 0; padding: 30px 34px 24px; max-width: 1520px; width: 100%; margin: 0 auto; }
.module-view { display: none; animation: view-in .24s ease; }
.module-view.active { display: block; }
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
.page-intro { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 20px; }
.page-intro h1 { font-size: clamp(25px, 2.6vw, 36px); margin: 6px 0 5px; letter-spacing: -.035em; }
.subtitle { color: var(--muted); margin: 0; font-size: 13px; }
.intro-actions { display: flex; gap: 14px; align-items: center; }
.report-actions { display: flex; gap: 8px; align-items: center; }
.secondary-button { background: white; color: var(--navy); border: 1px solid #d5dde7; border-radius: 8px; padding: 10px 14px; font-size: 12px; font-weight: 750; box-shadow: 0 2px 4px rgba(20,36,58,.03); }
.secondary-button:hover { border-color: var(--blue); color: var(--blue); }
.primary-button { background: var(--blue); color: white; border: 1px solid var(--blue); border-radius: 8px; padding: 10px 14px; font-size: 12px; font-weight: 750; box-shadow: 0 4px 10px rgba(46,111,187,.18); }
.primary-button:hover { background: #245f9f; border-color: #245f9f; }
.as-of { padding-left: 14px; border-left: 1px solid var(--line); }
.as-of span, .as-of strong { display: block; text-align: right; }
.as-of .demo-label { display: block; width: fit-content; margin: 0 0 4px auto; padding: 2px 7px; border-radius: 999px; background: #fff0cd; color: #97620e; font-size: 8px; letter-spacing: .11em; line-height: 1.5; }
.as-of span { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.as-of strong { font-size: 12px; margin-top: 2px; }

.model-notice { display: flex; gap: 10px; align-items: center; background: #fff8e8; border: 1px solid #f0dfb8; border-radius: 10px; padding: 10px 13px; margin-bottom: 18px; color: #6f551e; }
.model-notice p { margin: 0; font-size: 11.5px; line-height: 1.45; }
.mixed-notice { background: #edf6ff; border-color: #cfe2f5; color: #34536f; }
.notice-icon { flex: 0 0 auto; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: #e8bd62; color: white; font-size: 11px; font-weight: 900; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.kpi-card { min-width: 0; border-radius: var(--radius); background: white; border: 1px solid var(--line); padding: 17px 18px 15px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi-card::after { content: ""; height: 3px; position: absolute; bottom: 0; left: 0; right: 0; background: var(--blue); }
.kpi-card.overdue::after { background: var(--red); }
.kpi-card.current::after { background: var(--teal); }
.kpi-card.clients::after { background: #8d74c9; }
.kpi-card.payable::after { background: var(--amber); }
.kpi-card.sales::after { background: #4c86d9; }
.kpi-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: #526175; font-size: 11px; font-weight: 700; }
.mini-icon { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 7px; background: var(--blue-soft); color: var(--blue); font-size: 11px; font-weight: 850; }
.overdue .mini-icon { background: var(--red-soft); color: var(--red); }
.current .mini-icon { background: var(--teal-soft); color: var(--teal); }
.clients .mini-icon { background: #f0ecf9; color: #7e64bd; }
.payable .mini-icon { background: #fff3dc; color: #b27413; }
.sales .mini-icon { background: #eaf2ff; color: #3471c6; }
.data-tag { border-radius: 999px; padding: 4px 7px; font-size: 8px; letter-spacing: .04em; text-transform: uppercase; }
.data-tag.validated { background: var(--teal-soft); color: #247a69; }
.data-tag.modeled { background: #fff3dc; color: #946214; }
.kpi-card > strong { display: block; margin: 13px 0 5px; font-size: clamp(18px, 1.7vw, 25px); letter-spacing: -.025em; white-space: nowrap; }
.kpi-card > small { display: block; font-size: 10.5px; color: var(--muted); }
.kpi-card > small b { color: var(--red); }

.analysis-grid { display: grid; grid-template-columns: minmax(330px, .86fr) minmax(420px, 1.14fr); gap: 14px; margin-bottom: 14px; }
.panel { background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 19px; box-shadow: var(--shadow); min-width: 0; }
.panel-heading { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 17px; }
.panel-heading h2 { margin: 4px 0 0; font-size: 16px; letter-spacing: -.015em; }
.panel-heading > small { color: var(--muted); font-size: 10px; }
.status-content { display: grid; grid-template-columns: 145px 1fr; align-items: center; gap: 20px; }
.donut { width: 138px; height: 138px; border-radius: 50%; display: grid; place-items: center; position: relative; background: conic-gradient(var(--red) 0 55.4%, var(--teal) 55.4% 100%); }
.donut::after { content: ""; position: absolute; inset: 16px; border-radius: 50%; background: white; }
.donut > div { z-index: 1; text-align: center; }
.donut strong, .donut span { display: block; }
.donut strong { font-size: 23px; letter-spacing: -.03em; }
.donut span { font-size: 10px; color: var(--muted); }
.legend { display: grid; gap: 16px; }
.legend > div { display: grid; grid-template-columns: 8px 1fr auto; gap: 9px; align-items: center; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.overdue-dot { background: var(--red); }
.current-dot { background: var(--teal); }
.legend p, .legend strong { margin: 0; font-size: 11px; }
.legend p { font-weight: 700; }
.legend p small { display: block; font-size: 9.5px; font-weight: 500; color: var(--muted); margin-top: 2px; }
.legend strong { white-space: nowrap; }

.bar-list { display: grid; gap: 11px; }
.bar-item { display: grid; grid-template-columns: minmax(80px, 1.15fr) minmax(120px, 2fr) 82px; gap: 11px; align-items: center; }
.bar-label { font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: #edf1f5; border-radius: 999px; height: 7px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), #71a5dc); min-width: 2px; transition: width .3s ease; }
.bar-amount { text-align: right; font-size: 10.5px; font-weight: 750; }
.payable-bars .bar-fill { background: linear-gradient(90deg, #c88520, #e9b45c); }
.empty-state { padding: 25px; color: var(--muted); font-size: 12px; text-align: center; }

.overview-bars { display: grid; gap: 18px; }
.overview-bars button { display: grid; grid-template-columns: 135px 1fr 80px; align-items: center; gap: 12px; border: 0; background: transparent; padding: 1px 0; color: var(--ink); text-align: left; }
.overview-bars button > span { font-size: 11px; font-weight: 700; }
.overview-bars button > div { height: 9px; border-radius: 999px; background: #edf1f5; overflow: hidden; }
.overview-bars button i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), #76a9df); }
.overview-bars button i.payable-bar { background: linear-gradient(90deg, #c88520, #e9b45c); }
.overview-bars button i.sales-bar { background: linear-gradient(90deg, #4b78c7, #769fe3); }
.overview-bars button > strong { text-align: right; font-size: 11px; }
.priority-list { display: grid; gap: 8px; }
.priority-list button { display: grid; grid-template-columns: 32px 1fr 16px; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfd; padding: 10px; color: var(--ink); text-align: left; }
.priority-list button:hover { border-color: #b9cbe0; background: #f5f9fd; }
.priority-list button span strong, .priority-list button span small { display: block; }
.priority-list button span strong { font-size: 10.5px; }
.priority-list button span small { color: var(--muted); margin-top: 3px; font-size: 9px; }
.priority-icon { width: 30px; height: 30px; border-radius: 8px; display: grid !important; place-items: center; font-weight: 850; }
.priority-icon.danger { color: #b93e4c; background: var(--red-soft); }
.priority-icon.warning { color: #946214; background: #fff3dc; }
.priority-icon.good { color: #237967; background: var(--teal-soft); }
.priority-list button > b { color: var(--muted); }
.module-control { display: grid; gap: 5px; min-width: 160px; color: var(--muted); font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 750; }
.module-control select { text-transform: none; letter-spacing: 0; }
.payable-donut { background: conic-gradient(var(--red) 0 25.5%, var(--teal) 25.5% 100%); }

.sales-analysis-grid { display: grid; grid-template-columns: minmax(520px, 1.65fr) minmax(260px, .65fr); gap: 14px; margin-bottom: 14px; }
.seller-chart { display: grid; gap: 12px; min-height: 265px; align-content: center; }
.seller-row { display: grid; grid-template-columns: 86px 1fr 90px 56px; gap: 10px; align-items: center; }
.seller-name { font-size: 10.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seller-track { height: 19px; border-radius: 5px; background: #eef2f6; overflow: hidden; }
.seller-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #315f9d, #6f9fda); transition: width .3s ease; position: relative; }
.seller-fill.leader { background: linear-gradient(90deg, #285b9c, #4f91d9); }
.seller-amount { font-size: 10px; font-weight: 750; text-align: right; }
.seller-goal { font-size: 9px; color: var(--muted); text-align: right; }
.sales-donut { width: 170px; height: 170px; margin: 8px auto 19px; border-radius: 50%; display: grid; place-items: center; position: relative; background: conic-gradient(#3d73ba 0 17.1%, #e5ecf4 17.1% 100%); }
.sales-donut::after { content: ""; position: absolute; inset: 20px; border-radius: 50%; background: white; }
.sales-donut > div { position: relative; z-index: 1; text-align: center; }
.sales-donut strong, .sales-donut span { display: block; }
.sales-donut strong { font-size: 25px; }
.sales-donut span { color: var(--muted); font-size: 10px; }
.sales-insight { padding: 11px 12px; background: #eef5fc; color: #3c5876; border-radius: 9px; font-size: 10.5px; line-height: 1.45; text-align: center; }
.progress-cell { min-width: 150px; }
.progress-wrap { display: flex; align-items: center; gap: 8px; }
.progress-track { flex: 1; height: 6px; border-radius: 999px; background: #e9edf2; overflow: hidden; }
.progress-track i { display: block; height: 100%; border-radius: inherit; background: var(--blue); }
.progress-wrap span { min-width: 35px; font-size: 9px; color: var(--muted); text-align: right; }

.aging-panel { margin-bottom: 14px; }
.aging-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.aging-card { text-align: left; background: #f8fafc; border: 1px solid #e2e8ef; border-radius: 10px; padding: 12px; color: var(--ink); }
.aging-card span, .aging-card strong, .aging-card small { display: block; }
.aging-card span { font-size: 10px; color: var(--muted); }
.aging-card strong { font-size: 14px; margin: 8px 0 3px; }
.aging-card small { font-size: 9.5px; color: var(--muted); }
.aging-card.risk strong { color: var(--red); }

.invoices-panel { padding: 0; overflow: hidden; }
.table-heading { padding: 19px 19px 0; margin-bottom: 14px; }
.table-heading > div > small { display: block; margin-top: 4px; font-size: 10px; color: var(--muted); }
.sort-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; }
.sort-control select { width: auto; padding: 7px 26px 7px 8px; }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th { background: #f8fafc; padding: 10px 12px; text-align: left; color: #69778a; font-size: 9px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
td { padding: 11px 12px; border-top: 1px solid #edf0f4; font-size: 10.5px; white-space: nowrap; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #f8fbfe; }
.invoice-link { color: var(--blue); background: none; border: 0; padding: 0; font-weight: 800; }
.client-cell strong, .client-cell small { display: block; }
.client-cell small { font-size: 9px; color: var(--muted); margin-top: 2px; }
.amount-cell { text-align: right; font-weight: 750; }
.status-badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px; border-radius: 999px; font-weight: 750; font-size: 9px; }
.status-badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; }
.status-badge.overdue { color: #b73f4d; background: var(--red-soft); }
.status-badge.overdue::before { background: var(--red); }
.status-badge.current { color: #1f7d6c; background: var(--teal-soft); }
.status-badge.current::before { background: var(--teal); }
.row-action { border: 0; background: transparent; color: var(--muted); font-weight: 800; }
.table-footer { display: flex; justify-content: space-between; align-items: center; padding: 12px 17px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.table-footer > div { display: flex; align-items: center; gap: 9px; }
.page-button { width: 28px; height: 28px; border: 1px solid #d9e0e8; background: white; border-radius: 7px; color: var(--ink); }
.page-button:disabled { opacity: .4; cursor: default; }

footer { color: #8390a0; display: flex; justify-content: space-between; font-size: 9.5px; padding: 18px 3px 0; }

dialog { width: min(460px, calc(100vw - 30px)); border: 0; border-radius: 16px; padding: 0; box-shadow: 0 30px 80px rgba(13,28,48,.28); color: var(--ink); }
dialog::backdrop { background: rgba(11, 25, 43, .44); backdrop-filter: blur(2px); }
.dialog-header { display: flex; justify-content: space-between; align-items: start; padding: 21px 22px 16px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 5px 0 0; font-size: 21px; }
.dialog-header .icon-button { color: var(--muted); font-size: 25px; }
.invoice-detail { padding: 20px 22px 23px; }
.detail-hero { display: flex; justify-content: space-between; align-items: center; background: #f7f9fc; border: 1px solid var(--line); border-radius: 11px; padding: 14px; margin-bottom: 17px; }
.detail-hero span, .detail-hero strong { display: block; }
.detail-hero span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.detail-hero strong { margin-top: 5px; font-size: 19px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.detail-grid div span, .detail-grid div strong { display: block; }
.detail-grid div span { color: var(--muted); font-size: 9.5px; }
.detail-grid div strong { margin-top: 4px; font-size: 11.5px; }
.next-action { margin-top: 20px; border-left: 3px solid var(--blue); padding: 10px 12px; background: var(--blue-soft); border-radius: 0 8px 8px 0; font-size: 11px; line-height: 1.5; }
.toast { position: fixed; right: 24px; bottom: 24px; transform: translateY(20px); opacity: 0; pointer-events: none; background: #16304f; color: white; border-radius: 9px; padding: 11px 14px; box-shadow: 0 10px 30px rgba(14, 35, 60, .2); font-size: 11px; transition: .22s ease; z-index: 50; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1060px) {
  .module-nav { max-width: 480px; overflow-x: auto; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .analysis-grid { grid-template-columns: 1fr; }
  .sales-analysis-grid { grid-template-columns: 1fr; }
  .aging-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 760px) {
  .topbar { padding: 0 16px; }
  .brand > span:last-child { display: none; }
  .brand-mark { width: 33px; height: 33px; }
  .module-nav { margin: 0 4px; gap: 2px; padding: 3px; }
  .module-tab { padding: 7px 8px; font-size: 0; }
  .module-tab:nth-child(1)::after { content: "Resumen"; font-size: 10px; }
  .module-tab:nth-child(2)::after { content: "CxC"; font-size: 10px; }
  .module-tab:nth-child(3)::after { content: "CxP"; font-size: 10px; }
  .module-tab:nth-child(4)::after { content: "Ventas"; font-size: 10px; }
  #mobileFilters { display: block; }
  .private-pill { display: none; }
  .app-shell { display: block; }
  .filter-panel { position: fixed; z-index: 25; left: 0; top: 68px; width: min(310px, 88vw); transform: translateX(-105%); transition: transform .22s ease; box-shadow: 12px 0 30px rgba(20,36,58,.15); }
  .filter-panel.open { transform: translateX(0); }
  .content { padding: 24px 16px 20px; }
  .page-intro { align-items: start; }
  .intro-actions { display: block; }
  .report-actions { flex-wrap: wrap; }
  .as-of { display: none; }
  .kpi-grid { gap: 10px; }
  .kpi-card { padding: 14px; }
  .kpi-card > strong { font-size: 18px; }
  .status-content { grid-template-columns: 125px 1fr; gap: 12px; }
  .donut { width: 118px; height: 118px; }
  .aging-grid { grid-template-columns: repeat(2, 1fr); }
  .bar-item { grid-template-columns: minmax(70px, 1fr) 1.5fr 72px; }
  .seller-row { grid-template-columns: 72px 1fr 74px; }
  .seller-goal { display: none; }
  .overview-bars button { grid-template-columns: 112px 1fr 70px; }
  footer { display: grid; gap: 5px; }
}

@media (max-width: 500px) {
  .page-intro { display: block; }
  .intro-actions { margin-top: 16px; }
  .report-actions { display: grid; grid-template-columns: 1fr; }
  .report-actions button { width: 100%; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-card > strong { font-size: 22px; }
  .status-content { grid-template-columns: 1fr; justify-items: center; }
  .legend { width: 100%; }
  .aging-grid { grid-template-columns: 1fr 1fr; }
  .sort-control { display: none; }
  .module-control { margin-top: 14px; }
  .overview-bars button { grid-template-columns: 1fr 72px; }
  .overview-bars button > div { grid-column: 1 / -1; grid-row: 2; }
  .model-notice { align-items: start; }
}
