:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17202a;
  background: #f5f7f8;
  font-synthesis: none;
  --ink: #17202a;
  --muted: #68777a;
  --line: #dfe7e8;
  --brand: #17a6a0;
  --brand-dark: #102a2d;
  --soft: #eef8f7;
  --danger: #a33b43;
  --success: #087b56;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: #f5f7f8; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
.hidden { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef8f7; }
.login-card { width: min(500px, 100%); background: #fff; border: 1px solid #e2e8e8; border-radius: 24px; padding: 42px; box-shadow: 0 24px 70px rgba(17, 49, 54, .10); }
.login-card h1 { margin: 14px 0 12px; font-size: clamp(2rem, 6vw, 3rem); line-height: 1.02; letter-spacing: -.04em; }
.login-card p:not(.eyebrow) { color: #667376; line-height: 1.6; }
.brand-mark { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--brand); color: white; font-weight: 800; font-size: 24px; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; font-size: 18px; }
.eyebrow { margin: 0; color: #158f89; font-size: 11px; letter-spacing: .18em; font-weight: 800; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 18px; background: var(--brand-dark); color: white; display: flex; flex-direction: column; justify-content: space-between; z-index: 5; }
.logo-row { display: flex; align-items: center; gap: 12px; padding: 4px 6px 28px; }
.logo-row strong, .logo-row span { display: block; }
.logo-row span { color: #8eabad; font-size: 12px; margin-top: 2px; }
nav { display: grid; gap: 6px; }
.nav-link, .ghost { border: 0; background: transparent; color: #b9ccce; text-align: left; padding: 12px 14px; border-radius: 10px; }
.nav-link:hover, .nav-link.active { background: #1d3c40; color: #fff; }
.ghost { border: 1px solid #315055; text-align: center; }

main { min-width: 0; padding: 32px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
h1, h2 { margin: 5px 0 0; letter-spacing: -.03em; }
.topbar h1 { font-size: 34px; }
.subtitle { margin: 7px 0 0; color: #738184; }
.date-filter { display: flex; align-items: end; gap: 10px; }
label { display: grid; gap: 7px; color: #586568; font-size: 12px; font-weight: 700; }
input, select { width: 100%; border: 1px solid #dce4e5; background: #fff; color: var(--ink); border-radius: 10px; min-height: 44px; padding: 9px 12px; outline: none; }
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(23, 166, 160, .12); }
.primary, .secondary { border: 0; border-radius: 10px; min-height: 42px; padding: 10px 16px; font-weight: 800; }
.primary { background: var(--brand); color: white; }
.primary:hover { background: #128d88; }
.secondary { background: #e8eeee; color: #244045; }
.secondary:hover { background: #dce5e5; }
.wide { width: 100%; margin-top: 20px; }

.rule-banner { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; padding: 14px 16px; border: 1px solid #cfe5e3; border-radius: 14px; background: #eef8f7; color: #31585b; }
.rule-banner strong { color: #0f716d; white-space: nowrap; }
.rule-banner span { line-height: 1.45; }

.section-title-row { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.section-title-row h2 { font-size: 24px; }
.period-label { color: #758386; font-size: 12px; font-weight: 700; }
.personal-title { margin-top: 28px; }

.summary-grid { display: grid; grid-template-columns: 1.25fr repeat(3, 1fr); gap: 14px; }
.metric, .business-card, .panel, .personal-main-card, .portfolio-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; }
.metric { min-height: 145px; padding: 22px; display: flex; flex-direction: column; justify-content: space-between; }
.metric.featured { background: var(--brand-dark); border-color: var(--brand-dark); color: white; }
.metric span, .business-card span, .personal-main-card span, .portfolio-card span { color: #6b797c; font-size: 13px; }
.metric.featured span, .metric.featured small { color: #a9c2c4; }
.metric strong { font-size: clamp(1.7rem, 3vw, 2.3rem); letter-spacing: -.04em; }
.metric small { color: #8a9597; }
.negative { color: #b83c42 !important; }
.positive { color: var(--success) !important; }

.business-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 14px 0 0; }
.business-card { padding: 20px; }
.business-card header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; }
.business-card h3 { margin: 2px 0 0; }
.business-card .balance { font-size: 26px; font-weight: 850; letter-spacing: -.04em; }
.account-summary { margin: -10px 0 16px; color: #68777a; font-size: 12px; }
.business-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; border-top: 1px solid #edf0f1; padding-top: 16px; }
.business-stats strong, .business-stats small { display: block; }
.business-stats small { margin-bottom: 5px; color: #839092; }

.personal-overview { display: grid; grid-template-columns: minmax(0, 2fr) minmax(240px, .8fr); gap: 14px; margin-bottom: 28px; }
.personal-main-card { padding: 24px; display: grid; grid-template-columns: 1fr 1.5fr; gap: 28px; align-items: center; }
.personal-main-card > div:first-child { border-right: 1px solid #e7eded; padding-right: 26px; }
.personal-main-card > div:first-child strong { display: block; margin: 8px 0 6px; font-size: clamp(2rem, 4vw, 3rem); letter-spacing: -.05em; }
.personal-main-card small { color: #7d8a8c; }
.personal-flow { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.personal-flow div { min-width: 0; }
.personal-flow small, .personal-flow strong { display: block; }
.personal-flow small { margin-bottom: 5px; }
.personal-flow strong { font-size: 20px; }
.portfolio-card { padding: 24px; background: #f7fbfb; display: flex; flex-direction: column; justify-content: center; }
.portfolio-card strong { display: block; margin: 8px 0; font-size: 32px; letter-spacing: -.04em; }
.portfolio-card p { margin: 0; color: #748184; font-size: 13px; line-height: 1.5; }

.panel { padding: 24px; margin-bottom: 22px; scroll-margin-top: 20px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 22px; }
.section-heading > p { max-width: 460px; color: #718083; margin: 0; line-height: 1.5; }
.movement-form { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.full { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
#formMessage, #transferMessage { color: #157b75; font-size: 13px; }
.button-row { display: flex; gap: 10px; }

.transfer-panel { border-color: #cfe4e3; }
.transfer-form { display: grid; grid-template-columns: 1fr 1.2fr 44px 1.2fr 1fr; gap: 16px; align-items: end; }
.swap-button { min-height: 44px; width: 44px; border: 1px solid #d5e2e2; border-radius: 12px; background: #eef5f5; color: #256b68; font-size: 22px; }
.transfer-note { grid-column: 1 / span 3; }
.transfer-actions { grid-column: 4 / -1; }
.transfer-explanation { margin: 18px 0 0; padding: 12px 14px; border-radius: 10px; background: #f2f7f7; color: #526b6e; font-size: 13px; }

.table-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.table-actions select { min-width: 180px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th, td { padding: 14px 12px; text-align: left; border-bottom: 1px solid #edf0f1; font-size: 13px; vertical-align: top; }
th { color: #708083; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
td.amount { font-weight: 850; text-align: right; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 8px; border-radius: 999px; background: #eef3f3; color: #43585b; font-size: 11px; font-weight: 800; }
.linked-account { display: block; margin-top: 5px; color: #638083; font-size: 11px; }
.row-note { display: block; margin-top: 5px; color: #7b888a; line-height: 1.35; max-width: 320px; }
.actions-cell { white-space: nowrap; }
.row-button { border: 0; background: transparent; padding: 4px 6px; font-weight: 800; font-size: 12px; }
.edit-button { color: #167d78; }
.delete-button { color: var(--danger); }
.empty { padding: 34px; text-align: center; color: #748184; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(380px, calc(100vw - 28px)); padding: 14px 17px; border-radius: 12px; background: var(--brand-dark); color: white; box-shadow: 0 12px 35px rgba(0,0,0,.18); z-index: 20; }

@media (max-width: 1180px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .business-grid { grid-template-columns: 1fr; }
  .movement-form { grid-template-columns: repeat(2, 1fr); }
  .transfer-form { grid-template-columns: 1fr 1fr 44px 1fr; }
  .transfer-form > label:nth-of-type(1) { grid-column: 1; }
  .transfer-form > label:nth-of-type(4) { grid-column: 1; }
  .transfer-note { grid-column: 1 / span 2; }
  .transfer-actions { grid-column: 3 / -1; }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; width: 100%; height: auto; padding: 12px 14px; flex-direction: row; align-items: center; }
  .sidebar nav { display: none; }
  .logo-row { padding: 0; }
  .ghost { width: auto; padding: 9px 12px; }
  main { padding: 20px 14px calc(24px + env(safe-area-inset-bottom)); }
  .topbar, .section-heading { align-items: stretch; flex-direction: column; }
  .date-filter { display: grid; grid-template-columns: 1fr 1fr; }
  .date-filter button { grid-column: 1 / -1; }
  .personal-overview { grid-template-columns: 1fr; }
  .personal-main-card { grid-template-columns: 1fr; }
  .personal-main-card > div:first-child { border-right: 0; border-bottom: 1px solid #e7eded; padding: 0 0 22px; }
}

@media (max-width: 680px) {
  .login-card { padding: 30px 24px; }
  .rule-banner { align-items: flex-start; flex-direction: column; gap: 5px; }
  .section-title-row { align-items: flex-start; flex-direction: column; gap: 6px; }
  .summary-grid, .movement-form, .personal-flow { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .button-row { display: grid; grid-template-columns: 1fr; width: 100%; }
  .form-actions button { width: 100%; }
  .transfer-form { grid-template-columns: 1fr 44px 1fr; }
  .transfer-form > label:nth-of-type(1) { grid-column: 1 / -1; }
  .transfer-form > label:nth-of-type(2) { grid-column: 1; }
  .swap-button { grid-column: 2; }
  .transfer-form > label:nth-of-type(3) { grid-column: 3; }
  .transfer-form > label:nth-of-type(4),
  .transfer-form > label:nth-of-type(5),
  .transfer-form > label:nth-of-type(6),
  .transfer-note,
  .transfer-actions { grid-column: 1 / -1; }
  .table-actions { display: grid; grid-template-columns: 1fr; width: 100%; }
  .table-actions select { min-width: 0; }
  .table-wrap { overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; }
  table { min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tr { border: 1px solid #e1e8e9; border-radius: 14px; padding: 10px 14px; background: #fff; }
  td { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid #f0f3f3; }
  td:last-child { border-bottom: 0; }
  td::before { content: attr(data-label); color: #7d898b; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
  td.amount { text-align: left; }
  .actions-cell { white-space: normal; }
  .row-note { max-width: none; }
  .toast { left: 14px; right: 14px; bottom: 14px; }
}

/* V3 · Cuentas por cobrar */
.receivable-metric { border-color: #d9e7e6; background: linear-gradient(180deg, #fff, #f7fbfb); }
.receivable-metric strong { color: #b26712; }
.receivables-panel { border-color: #d6e5e4; }
.receivable-summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.mini-metric { min-height: 112px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fff; display: flex; flex-direction: column; justify-content: space-between; }
.mini-metric span { color: #6b797c; font-size: 12px; font-weight: 700; }
.mini-metric strong { font-size: 28px; letter-spacing: -.04em; }
.featured-light { background: #fff8ec; border-color: #f0d5a8; }
.featured-light strong { color: #a35b0b; }
.receivable-layout { display: grid; grid-template-columns: minmax(290px, .8fr) minmax(0, 1.7fr); gap: 18px; align-items: start; }
.receivable-form, .receivable-list-card { border: 1px solid #e0e8e8; border-radius: 15px; background: #fbfdfd; }
.receivable-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding: 18px; }
.span-2 { grid-column: 1 / -1; }
.form-card-heading, .receivable-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; }
.form-card-heading h3, .receivable-toolbar h3 { margin: 3px 0 0; font-size: 19px; }
.form-card-heading > span { color: #7f8d8f; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.receivable-list-card { min-width: 0; padding: 18px; }
.receivable-toolbar { margin-bottom: 14px; }
.receivable-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.receivable-filters select { min-width: 180px; }
.check-label { display: flex; grid-auto-flow: column; align-items: center; gap: 8px; min-height: 42px; padding: 0 10px; border: 1px solid #dce4e5; border-radius: 10px; background: #fff; white-space: nowrap; }
.check-label input { width: 16px; min-height: 16px; margin: 0; box-shadow: none; }
.receivable-table { min-width: 820px; }
.status-pending { background: #fff1dd; color: #8c4f0a; }
.status-partial { background: #edf4ff; color: #315f9d; }
.status-paid { background: #e7f6ec; color: #297044; }
.pay-button { color: #0f7772; background: #eaf7f6; border-radius: 8px; padding: 7px 10px; }
.locked-label { display: inline-block; max-width: 150px; color: #708083; font-size: 11px; line-height: 1.3; }
.modal-open { overflow: hidden; }
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: rgba(8, 25, 28, .62); backdrop-filter: blur(4px); }
.modal-card { position: relative; width: min(560px, 100%); max-height: calc(100vh - 36px); overflow: auto; padding: 26px; border-radius: 18px; background: #fff; box-shadow: 0 22px 70px rgba(0,0,0,.28); }
.modal-card h2 { margin-bottom: 8px; }
.modal-client { margin: 0 0 20px; color: #637174; }
.modal-close { position: absolute; top: 14px; right: 14px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #eef3f3; color: #40575a; font-size: 24px; line-height: 1; }
.payment-form { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.modal-actions { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-top: 4px; }
#receivableFormMessage, #paymentMessage { color: #157b75; font-size: 13px; }

@media (min-width: 1181px) {
  .summary-grid { grid-template-columns: 1.25fr repeat(4, 1fr); }
}

@media (max-width: 1050px) {
  .receivable-layout { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .receivable-summary-grid, .receivable-form, .payment-form { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .receivable-toolbar { align-items: stretch; flex-direction: column; }
  .receivable-filters { display: grid; grid-template-columns: 1fr; }
  .receivable-filters select { min-width: 0; }
  .receivable-table-wrap { overflow: visible; }
  .receivable-table { min-width: 0; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal-card { width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; padding: 24px 18px calc(24px + env(safe-area-inset-bottom)); }
  .modal-actions { align-items: stretch; flex-direction: column; }
  .modal-actions .button-row { width: 100%; }
}
