/* PayFlow — sistema de diseño único. Todas las pantallas usan SOLO estas clases y variables. */
:root {
  /* Color */
  --bg: #EFECE8;            /* fondo de pantalla */
  --surface: #FFFFFF;       /* tarjetas y tablas */
  --surface-2: #FAF6F2;     /* fila zebra, zonas suaves */
  --border: #DDD6CE;
  --text: #231F1B;
  --text-2: #6A625B;
  --primary: #D9500A;
  --primary-hover: #B84208;
  --primary-soft: #FFEDE0;
  --ok: #1F7A4D;      --ok-soft: #E1F3E9;
  --warn: #9A6200;    --warn-soft: #FFF1D6;
  --danger: #B3372E;  --danger-soft: #FBE4E2;
  --neutral-soft: #ECE8E3;
  --info: #3E5C76;    --info-soft: #E6EDF3;
  --neutral: #8C8279;
  /* Tipografía */
  --font: "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-sm: 0.875rem; --fs: 1rem; --fs-lg: 1.125rem; --fs-xl: 1.5rem; --fs-xxl: 1.875rem;
  /* Espacio y forma */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(35,31,27,.06), 0 2px 8px rgba(35,31,27,.05);
  --control-h: 46px;
  --sidebar-w: 224px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
.muted { color: var(--text-2); }
.small { font-size: var(--fs-sm); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- Estructura ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); padding: var(--sp-5) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-5); position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: block; text-align: center; font-size: var(--fs-xl); font-weight: 750; letter-spacing: -.02em; padding: var(--sp-3) var(--sp-4); color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 2px 4px rgba(35,31,27,.12), 0 4px 10px rgba(35,31,27,.08), inset 0 1px 0 #fff; transition: box-shadow .12s, transform .12s; }
.brand:hover { text-decoration: none; box-shadow: 0 3px 6px rgba(35,31,27,.16), 0 6px 14px rgba(35,31,27,.10), inset 0 1px 0 #fff; }
.brand:active { transform: translateY(1px); box-shadow: 0 1px 2px rgba(35,31,27,.14), inset 0 1px 2px rgba(35,31,27,.10); }
.brand-full, .brand-short { color: var(--text); }
.brand-full span, .brand-short span, .login .brand > span { color: var(--primary); }
.brand-short { display: none; font-weight: 800; }
.nav { display: flex; flex-direction: column; gap: var(--sp-1); flex: 1; }
.nav a, .nav button { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--control-h); padding: 0 var(--sp-3); border-radius: var(--radius-sm); color: var(--text-2); font: inherit; font-weight: 550; background: none; border: 0; cursor: pointer; width: 100%; text-align: left; }
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.icon { width: 22px; height: 22px; fill: currentColor; flex-shrink: 0; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: var(--sp-3); }
.sidebar-foot .who { padding: 0 var(--sp-3) var(--sp-2); font-size: var(--fs-sm); color: var(--text-2); }
.main { flex: 1; min-width: 0; padding: var(--sp-5) var(--sp-5) var(--sp-6); }
.container { max-width: 1180px; margin: 0 auto; }
.container.narrow { max-width: 760px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--primary); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--sp-4) var(--sp-5); }
.page-header p { margin: 2px 0 0; color: var(--text-2); }
.actions { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: center; }
.stack > * + * { margin-top: var(--sp-5); }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--sp-5); }
.card.flush { padding: 0; overflow: hidden; }
.card-title { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card.flush .card-title { padding: var(--sp-4) var(--sp-5); margin: 0; border-bottom: 1px solid var(--border); }
.grid { display: grid; gap: var(--sp-4); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: 1fr; } }
.stat .label a { color: inherit; }
.stat .label { color: var(--text-2); font-size: var(--fs-sm); font-weight: 550; }
.stat .value { font-size: var(--fs-xxl); font-weight: 700; letter-spacing: -.02em; margin: var(--sp-1) 0; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--text-2); font-size: var(--fs-sm); }
.stat.danger { border-left: 6px solid var(--danger); }
.stat.warn { border-left: 6px solid #E0A100; }
.stat.neutral { border-left: 6px solid var(--neutral); }
.stat.ok { border-left: 6px solid var(--ok); }

/* ---------- Banner y mensajes ---------- */
.banner { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-radius: var(--radius); margin-bottom: var(--sp-5); font-weight: 550; border: 1px solid transparent; }
.banner.info { background: var(--info-soft); color: var(--info); border-color: #C9D7E3; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: #F2DBA6; }
.banner.danger { background: var(--danger-soft); color: var(--danger); border-color: #F2C4C0; }
.banner.ok { background: var(--ok-soft); color: var(--ok); border-color: #BFE3CE; }
.banner .grow { flex: 1; }
.toast { margin-bottom: var(--sp-4); }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: var(--control-h); padding: 0 var(--sp-5); border-radius: var(--radius-sm); border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s, transform .12s; box-shadow: 0 1px 2px rgba(35,31,27,.18), 0 3px 8px rgba(35,31,27,.12); }
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: 0 2px 4px rgba(35,31,27,.20), 0 6px 14px rgba(35,31,27,.16); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 2px rgba(35,31,27,.20); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #F5B183; outline-offset: 1px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #E7B7B3; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { min-height: 38px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-4) var(--sp-5); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 800px) { .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-weight: 600; font-size: var(--fs-sm); margin-bottom: var(--sp-1); }
.field .req { color: var(--danger); }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: var(--control-h); padding: 0 var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; }
textarea { padding: var(--sp-3); min-height: 90px; resize: vertical; }
input:disabled, input[readonly] { background: var(--surface-2); color: var(--text-2); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.hint { color: var(--text-2); font-size: var(--fs-sm); margin-top: var(--sp-1); }
.error-text { color: var(--danger); font-size: var(--fs-sm); margin-top: var(--sp-1); font-weight: 550; }
.form-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-5); flex-wrap: wrap; }
.filters { display: flex; gap: var(--sp-3); align-items: flex-end; flex-wrap: wrap; margin-bottom: var(--sp-4); }
.filters .field { min-width: 180px; }
.filters .field.grow { flex: 1; }
.check { width: 22px; height: 22px; accent-color: var(--primary); cursor: pointer; }

/* ---------- Selector de archivo ---------- */
.file-picker { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--control-h); padding: 3px var(--sp-3) 3px 3px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.field label.btn { display: inline-flex; margin: 0; font-size: var(--fs-sm); }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.file-input:focus-visible + label { outline: 3px solid #F5B183; outline-offset: 1px; }
.file-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file-name.has-file { color: var(--text); font-weight: 550; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs); }
.table th { text-align: left; font-size: var(--fs-sm); font-weight: 650; color: var(--text-2); background: var(--surface-2); padding: var(--sp-3) var(--sp-2); border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
.table td { padding: var(--sp-3) var(--sp-2); border-bottom: 1px solid #EEE8E1; vertical-align: middle; }
.table tbody tr:nth-child(even) { background: var(--surface-2); }   /* zebra */
.table tbody tr:hover { background: #F1EAE2; }
.table th.num, .table td.num { text-align: right; }
.table th a { color: inherit; }
.table tfoot td { font-weight: 700; background: var(--surface); border-top: 2px solid var(--border); border-bottom: 0; }
.table .row-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; }
.table .col-check { width: 48px; }
.truncate { display: inline-block; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* ---------- Chips ---------- */
.chip { display: inline-flex; align-items: center; padding: 2px var(--sp-3); border-radius: 999px; font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.neutral { background: var(--neutral-soft); color: var(--text-2); }
.chip.info { background: var(--info-soft); color: var(--info); }

/* ---------- Estado vacío ---------- */
.empty { text-align: center; padding: var(--sp-6) var(--sp-5); color: var(--text-2); }
.empty h3 { color: var(--text); margin-bottom: var(--sp-2); }
.empty .btn { margin-top: var(--sp-4); }

/* ---------- Barra de selección (panel de decisión) ---------- */
.selbar { position: sticky; bottom: var(--sp-4); margin-top: var(--sp-4); background: #2A2420; color: #fff; border-radius: var(--radius); padding: var(--sp-4) var(--sp-5); display: flex; gap: var(--sp-5); align-items: center; flex-wrap: wrap; box-shadow: 0 6px 24px rgba(35,31,27,.25); }
.selbar .cell .k { font-size: var(--fs-sm); color: #CDBFB3; }
.selbar .cell .v { font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.selbar .v.good { color: #7EE2A8; }
.selbar .v.bad { color: #FFB4AD; }
.selbar .grow { flex: 1; }
.selbar .btn-secondary { background: transparent; color: #fff; border-color: #6B5E54; }
.selbar .btn { box-shadow: none; }
.selbar .btn-secondary:hover { background: #3D342D; }

/* ---------- Plan semanal ---------- */
.week { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--sp-4); }
.day { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 240px; }
.day.is-today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft), var(--shadow); }
.day-head { padding: var(--sp-4); border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.day-head .name { font-weight: 650; }
.day-head .total { font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.day-body { padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-3); flex: 1; }
.plan-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-3); background: var(--surface); }
.plan-item { min-width: 0; }
.plan-item .row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 2px var(--sp-2); }
.plan-item .p { flex: 1 1 100%; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.plan-item .amt { flex: 1 1 100%; font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.plan-item .meta { white-space: nowrap; }
.plan-item .term { margin-top: var(--sp-2); }
.plan-item select { min-height: 36px; font-size: var(--fs-sm); margin-top: var(--sp-2); }
.plan-item .btn { margin-top: var(--sp-2); }

/* ---------- Pestañas ---------- */
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-1); gap: var(--sp-1); margin-bottom: var(--sp-5); }
.tabs a { padding: var(--sp-2) var(--sp-4); border-radius: 6px; color: var(--text-2); font-weight: 600; min-height: 38px; display: inline-flex; align-items: center; }
.tabs a:hover { text-decoration: none; background: var(--surface-2); }
.tabs a.active { background: var(--primary-soft); color: var(--primary); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-5); }
.login .card { width: 100%; max-width: 400px; }
.login .brand { margin-bottom: var(--sp-5); box-shadow: none; border: 0; background: none; pointer-events: none; }

.log-box { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }

.check-row { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: var(--control-h); font-weight: 600; cursor: pointer; }
.banner strong { font-weight: 750; }
.banner .muted { display: block; font-weight: 400; margin-top: 2px; }

.account-row { display: flex; gap: var(--sp-4); align-items: flex-end; flex-wrap: wrap; }
.account-row:first-of-type { border-top: 0; }
.account-row .filters { margin-bottom: 0; flex: 1 1 520px; }
.account-row.inactive .field input, .account-row.inactive .field select { background: var(--surface-2); }
.account-state { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--control-h); }

/* ---------- Antigüedad de la deuda ---------- */
.aging { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--sp-3); }
@media (max-width: 1100px) { .aging { grid-template-columns: repeat(2, 1fr); } }
.aging-cell { border: 1px solid var(--border); border-top: 5px solid var(--neutral); border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-4); background: var(--surface); }
.aging-cell.current { border-top-color: var(--ok); }
.aging-cell.d30, .aging-cell.d60 { border-top-color: #E0A100; }
.aging-cell.d90, .aging-cell.d90p { border-top-color: var(--danger); }
.aging-cell.empty { background: var(--surface-2); }
.aging-cell .k { color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; }
.aging-cell .v { font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; }
.aging-cell.empty .v { color: var(--text-2); font-weight: 500; }
.aging-cell .s { color: var(--text-2); font-size: var(--fs-sm); }

/* ---------- Orden de pago: firmas ---------- */
.signatures { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-6); margin-top: 72px; }
.signatures div { border-top: 1px solid var(--text); padding-top: var(--sp-2); text-align: center; color: var(--text-2); }

/* ---------- Impresión ---------- */
@media print {
  body { background: #fff; }
  .sidebar, .no-print, .toast, .selbar, .tabs, .filters { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .page-header { box-shadow: none; border: 0; border-bottom: 2px solid var(--text); border-radius: 0; padding: 0 0 var(--sp-3); }
  .table tbody tr:nth-child(even) { background: #F3F3F3 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table th { position: static; }
  .container { max-width: none; }
}
/* Pantallas angostas: el menú lateral se reduce a íconos para dar lugar al contenido */
@media (max-width: 1200px) {
  .sidebar { width: 76px; padding: var(--sp-5) 10px; }
  .brand { padding: var(--sp-3) 0; }
  .brand-full { display: none; }
  .brand-short { display: inline; }
  .nav a, .nav button { justify-content: center; padding: 0; }
  .nav .label, .sidebar-foot .who { display: none; }
  .main { padding: var(--sp-5) var(--sp-4) var(--sp-6); }
}
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; padding: var(--sp-3); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a, .nav button { width: auto; }
  .main { padding: var(--sp-4); }
}

@media (max-width: 1400px) { .col-issue { display: none; } }

/* ---------- Utilidades de espacio (en lugar de estilos en las plantillas) ---------- */
.mt-0 { margin-top: 0; } .m-0 { margin: 0; } .mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); } .mb-5 { margin-bottom: var(--sp-5); }
.card-section { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); }
.hint-pad { padding: var(--sp-3) var(--sp-5); }
.text-xl { font-size: var(--fs-xl); }
.empty-day { text-align: center; padding: var(--sp-5) 0; }
.selbar a { color: #fff; }

/* ---------- Avance del plazo de cuenta corriente ---------- */
.term { min-width: 110px; }
.term .bar { height: 8px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; }
.term .bar span { display: block; height: 100%; border-radius: 999px; background: var(--ok); }
.term.warn .bar span { background: #E0A100; }
.term.danger .bar span { background: var(--danger); }
.term .txt { font-size: var(--fs-sm); color: var(--text-2); margin-top: 2px; white-space: nowrap; }
.term .bar .p0 { width: 0%; }
.term .bar .p10 { width: 10%; }
.term .bar .p20 { width: 20%; }
.term .bar .p30 { width: 30%; }
.term .bar .p40 { width: 40%; }
.term .bar .p50 { width: 50%; }
.term .bar .p60 { width: 60%; }
.term .bar .p70 { width: 70%; }
.term .bar .p80 { width: 80%; }
.term .bar .p90 { width: 90%; }
.term .bar .p100 { width: 100%; }
