/* Finanzas personales — sistema visual "fintech limpio" */
:root {
  --bg: #F5F6F8;
  --panel: #FFFFFF;
  --text: #0E1525;
  --text-2: #3B4352;
  --muted: #5E6675;
  --border: #E5E7EB;
  --border-soft: #EEF0F3;
  --border-strong: #D5D9E0;
  --accent: #0B7A5F;
  --accent-hover: #086650;
  --accent-soft: #E7F4EF;
  --accent-ink: #075A46;
  --ink: #0E1525;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --ok: #0B6B53;
  --ok-soft: #E7F4EF;
  --warn: #8A4B08;
  --warn-soft: #FDF3E4;
  --child: #FAFBFC;
  --sel: #EEF6F3;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(14, 21, 37, .04);
  --font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); background: var(--bg); color: var(--text); font-feature-settings: 'tnum' 1, 'cv11' 1; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.hidden { display: none !important; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
.ic { flex: none; vertical-align: -3px; pointer-events: none; }
button svg, a svg { pointer-events: none; }

/* ---------- layout ---------- */
.layout { display: flex; flex-wrap: wrap; min-height: 100vh; }
.sidebar {
  flex: 1 1 248px; max-width: 100%; background: var(--panel); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 18px;
}
@media (min-width: 900px) {
  .sidebar { flex: 0 0 248px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
}
.content { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; }
main { padding: 4px 32px 48px; width: 100%; max-width: 1440px; }
@media (max-width: 640px) { main { padding: 4px 16px 40px; } }

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; }
.brand b { display: block; font-size: 15px; letter-spacing: -0.01em; }
.brand small { display: block; font-size: 12px; color: var(--muted); line-height: 1.2; }

nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 14px 12px 6px; }
.nav-section:first-child { padding-top: 0; }
nav button {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; text-align: left; min-height: 40px;
  padding: 8px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--text-2); font-weight: 500;
}
nav button svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav button:hover { background: #F3F4F6; color: var(--text); }
nav button.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

.side-user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--border-soft); }
.avatar { width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; flex: none; }
.side-user-text { flex: 1; min-width: 0; }
.side-user-text b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-text small { display: block; font-size: 12px; color: var(--muted); }

.topbar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 28px 32px 18px; max-width: 1440px; }
@media (max-width: 640px) { .topbar { padding: 20px 16px 14px; } }
.eyebrow { display: block; font-size: 13px; color: var(--muted); }
.page-head h1 { margin: 2px 0 0; font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.search { display: flex; flex-direction: row; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 12px; height: 44px; width: 340px; max-width: 100%; color: var(--muted); }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { border: 0; outline: 0; flex: 1; min-width: 0; padding: 0; background: transparent; font-size: 14px; color: var(--text); }
kbd { font-family: var(--mono); font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; }

.tab { display: none; }
.tab.active { display: block; }

/* ---------- superficies ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow-x: auto; }
.card h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; letter-spacing: -0.005em; }
.card h3 { font-size: 13px; font-weight: 600; margin: 14px 0 8px; color: var(--text-2); }
.hint { color: var(--muted); margin: 0 0 12px; font-size: 13px; }
.hint.ok { color: var(--ok); }
.hint.warn { color: var(--warn); }
.muted { color: var(--muted); }
.note { font-size: 12px; color: var(--muted); }
.note.orig { font-family: var(--mono); font-size: 11px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.row.between { justify-content: space-between; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.row .grow { flex: 1 1 260px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 + .grid2 { margin-top: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- formularios ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; min-height: 36px; color: var(--text); font-size: 13px; font-weight: 400; cursor: pointer; }
input, select, button, textarea { font: inherit; }
input, select, textarea {
  min-height: 38px; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 9px; background: #fff; color: var(--text); font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox], input[type=radio] { min-height: 0; width: 16px; height: 16px; padding: 0; accent-color: var(--accent); box-shadow: none; }
input[type=color] { padding: 3px; width: 44px; height: 38px; }
input[type=file] { min-height: 0; }
textarea { resize: vertical; }

button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px;
  padding: 0 14px; border-radius: 9px; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }
button.secondary { background: #fff; color: var(--text); border-color: var(--border-strong); }
button.secondary:hover { background: #F7F8FA; }
button.danger { background: #fff; color: var(--danger); border-color: #F3C6C1; }
button.danger:hover { background: var(--danger-soft); }
button.icon { min-height: 32px; padding: 0 8px; background: transparent; border: 1px solid transparent; color: var(--muted); font-weight: 500; }
button.icon:hover { border-color: var(--border); background: #fff; color: var(--text); }
button.block { width: 100%; min-height: 44px; }
button:disabled { opacity: .5; cursor: default; }

.dropzone {
  display: flex; flex-direction: column; position: relative; margin-top: 16px; align-items: center; justify-content: center; text-align: center; gap: 6px;
  min-height: 150px; padding: 22px; border: 1.5px dashed #C9CED6; border-radius: 14px; background: #FAFBFC; cursor: pointer;
  color: var(--text); font-size: 14px;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.dropzone b { font-size: 15px; }
.dropzone .dz-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; }
.dropzone input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

/* ---------- tablas ---------- */
.scroll { overflow: auto; max-height: 440px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: middle; }
th { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: #FAFBFC; position: sticky; top: 0; z-index: 1; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--ok); }
table.raw td { white-space: nowrap; font-size: 12px; }
table.raw tr.header-row td { background: var(--accent-soft); font-weight: 600; }
table.raw tr:hover td { background: #F3F4F6; cursor: pointer; }

table.tx { min-width: 1080px; }
table.tx th:first-child, table.tx td:first-child { padding-left: 18px; }
table.tx th:last-child, table.tx td:last-child { padding-right: 14px; }
table.tx td { padding-top: 10px; padding-bottom: 10px; }
table.tx select { min-height: 32px; padding: 3px 8px; font-size: 13px; max-width: 170px; }
table.tx tr.child td { background: var(--child); }
table.tx tr.child td.desc { padding-left: 34px; color: var(--text-2); }
table.tx tr.child td.desc::before { content: "↳ "; color: var(--muted); }
table.tx tr.pending td:first-child { box-shadow: inset 3px 0 0 #D97706; }
table.tx tr.linkable:hover td { background: var(--accent-soft); cursor: pointer; }
table.tx tr.selected td { background: var(--sel); }
table.tx td:nth-child(2) { white-space: nowrap; color: var(--muted); font-size: 13px; }
td.desc { max-width: 400px; }
td.desc > a { font-weight: 600; }
.more-row td { text-align: center; padding: 14px; }
table.rp-items select { min-height: 32px; padding: 3px 8px; font-size: 13px; max-width: 170px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-soft); }
td.desc a, td a[data-detail] { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted); }
td.desc a:hover, td a[data-detail]:hover { color: var(--accent); border-bottom-color: var(--accent); }
td.desc a.pill { border-bottom: 0; }
.summary-table td:first-child { font-weight: 600; }
.summary-table tr.total td { font-weight: 700; border-top: 2px solid var(--text); }

/* ---------- pills y estados ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; background: #F1F2F5; color: var(--text-2); vertical-align: 1px; }
.pill .ic { width: 13px; height: 13px; vertical-align: 0; }
.pill.pkg { background: #EFEBFF; color: #4C2DB8; text-decoration: none; }
.pill.helpp { background: #E8EEFB; color: #1F4BB8; text-decoration: none; }
.pill.helpp.answered { background: var(--accent-soft); color: var(--accent-ink); }
.pill.dispute { background: #FDECEA; color: #8F1D14; }
.pill.dispute.a_favor { background: var(--ok-soft); color: var(--ok); }
.pill.dispute.en_contra { background: #F1F2F5; color: var(--text-2); }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.status.ok { background: var(--ok-soft); color: var(--ok); }
.status.warn { background: var(--warn-soft); color: var(--warn); }
.status.bad { background: var(--danger-soft); color: var(--danger); }
.status.neutral { background: #F1F2F5; color: var(--text-2); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
mark { background: #FDE68A; color: inherit; padding: 0 1px; border-radius: 2px; }

.stats { display: flex; gap: 6px 22px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); }
.stats b { font-size: 15px; color: var(--text); }
.stats .results { flex-basis: 100%; color: var(--text); }

.banner { position: sticky; top: 8px; z-index: 5; background: var(--warn-soft); border: 1px solid #F5D9A8; border-radius: 14px; padding: 10px 14px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.bulk { background: var(--ink); border-color: var(--ink); color: #fff; }
.banner.bulk #bulk-count { font-weight: 600; margin-right: 4px; }
.banner.bulk select { background: #1A2232; color: #fff; border-color: #2A3345; }
.banner.bulk button.ghost { background: transparent; border-color: transparent; color: #D5D9E0; }
.banner.bulk button.ghost:hover { color: #fff; background: #1A2232; }
.banner.bulk button.light { background: #7EE2C0; border-color: #7EE2C0; color: var(--ink); margin-left: auto; }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow); }
.kpi:first-child { background: var(--ink); border-color: var(--ink); color: #fff; }
.kpi:first-child .kpi-label, .kpi:first-child .note { color: #B8BFCC; }
.kpi:first-child a { color: #7EE2C0; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .note.up { color: var(--danger); }
.kpi .note.down { color: var(--ok); }
.hbars { display: flex; flex-direction: column; gap: 2px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 200px) 1fr minmax(140px, auto); gap: 14px; align-items: center; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.hbar:hover { background: #F5F6F8; }
.hbar-label { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 8px; background: #F1F2F5; border-radius: 999px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 999px; min-width: 2px; }
.hbar-value { font-size: 14px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar-value .muted { font-weight: 400; font-size: 12px; margin-left: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; margin-bottom: 10px; color: var(--text-2); }
.legend i, .chart-tip i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart-wrap { position: relative; }
.month-chart { width: 100%; height: auto; display: block; }
.month-chart .grid { stroke: #E5E7EB; stroke-width: 1; stroke-dasharray: 3 3; }
.month-chart .axis { fill: var(--muted); font-size: 11px; }
.month-chart .seg { stroke: var(--panel); stroke-width: 2; }
.month-chart .hit { fill: transparent; }
.month-chart .col:hover .hit { fill: #F3F4F6; }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; line-height: 1.6; padding: 8px 10px; border-radius: 10px; white-space: nowrap; z-index: 3; box-shadow: 0 8px 24px rgba(14,21,37,.18); }
@media (max-width: 640px) {
  .hbar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label value" "track track"; gap: 4px 10px; padding: 7px 4px; }
  .hbar-label { grid-area: label; } .hbar-value { grid-area: value; } .hbar-track { grid-area: track; }
}

/* ---------- reporte ---------- */
.person { border-left: 4px solid var(--accent); }
.person.unassigned { border-left-color: #D97706; }
.person-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.person-head h2 { margin: 0; }
.person-head .amount { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.breakdowns { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 10px; }
.breakdowns table td { padding: 5px 6px; font-size: 13px; }
.disputes-card { border-left: 4px solid var(--danger); }
tr.dispute-row td { background: #FEF6F5; color: #8F1D14; }
tr.dispute-row td.num { text-decoration: line-through; text-decoration-color: rgba(143, 29, 20, .5); }
tr.dispute-row td:last-child.num { text-decoration: none; }
details summary { cursor: pointer; color: var(--accent); margin-top: 10px; font-weight: 500; }

/* ---------- listas de catálogo ---------- */
.list-item { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border-soft); }
.list-item input[type=text] { flex: 1; }

/* ---------- modal y avisos ---------- */
dialog { border: 0; border-radius: 18px; padding: 22px 24px; width: min(580px, 94vw); box-shadow: 0 24px 60px rgba(14,21,37,.25); color: var(--text); }
dialog::backdrop { background: rgba(14,21,37,.45); }
dialog h2 { margin: 0 0 14px; font-size: 18px; letter-spacing: -0.01em; }
#modal-body { display: flex; flex-direction: column; gap: 12px; max-height: 70vh; overflow-y: auto; }
#modal-body label { font-size: 13px; }
#modal-body h3 { font-size: 13px; margin: 6px 0 0; }
.detail-amount { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
table.detail td { padding: 5px 6px; font-size: 13px; vertical-align: top; }
table.detail td.muted { width: 38%; }
.raw-val { white-space: pre-line; word-break: break-word; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; display: flex; gap: 12px; align-items: center; z-index: 50; max-width: min(520px, calc(100vw - 32px)); box-shadow: 0 10px 30px rgba(14,21,37,.25); }
.toast.error { background: var(--danger); }
.toast button { min-height: 32px; padding: 0 12px; background: #fff; color: var(--ink); border-color: #fff; }

/* ---------- inicio de sesión ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 12px 40px rgba(14,21,37,.06); }
.auth-card .brand { padding: 0; margin-bottom: 6px; }
.auth-card h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.auth-card .hint { margin: -6px 0 0; }
.auth-card input { min-height: 44px; }
.auth-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }

/* ---------- módulos nuevos ---------- */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #F1F2F5; color: var(--text-2); }
.chip.inv { background: #E8EEFB; color: #1F4BB8; }
.chip.rev { background: var(--accent-soft); color: var(--accent-ink); }
.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }
.members { display: flex; flex-direction: column; }
.member { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border-soft); }
.member:last-child { border-bottom: 0; }
.member .avatar { width: 30px; height: 30px; font-size: 12px; border-radius: 8px; }
.member-name { flex: 1; min-width: 0; }
.member-name small { display: block; color: var(--muted); font-size: 12px; }

.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.inv-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; cursor: pointer; text-align: left; color: var(--text); box-shadow: var(--shadow); font-weight: 400; white-space: normal; align-items: stretch; min-height: 0; }
.inv-card:hover { border-color: var(--accent); background: var(--panel); }
.inv-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.inv-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.inv-name { font-size: 15px; font-weight: 600; }
.inv-sub { font-size: 12px; color: var(--muted); }
.inv-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.inv-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.gain { color: var(--ok); font-weight: 600; }
.loss { color: var(--danger); font-weight: 600; }
.spark { width: 100%; height: 36px; display: block; }

.help-list { display: flex; flex-direction: column; gap: 14px; }
.help-item { border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; background: var(--panel); }
.help-item.closed { opacity: .75; }
.help-tx { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 12px 14px; background: #F8F9FA; border-radius: 10px; margin: 10px 0; }
.help-tx b { display: block; }
.help-tx .amt { font-size: 18px; font-weight: 700; white-space: nowrap; }
.thread { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.msg { padding: 8px 12px; border-radius: 10px; background: #F1F2F5; font-size: 13px; max-width: 85%; }
.msg.mine { background: var(--accent-soft); align-self: flex-end; }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.reply { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.reply input { flex: 1 1 220px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.quick button { min-height: 32px; font-size: 13px; font-weight: 500; }
tr.list-item { display: table-row; }
main .card { overflow-x: auto; }

/* ---------- celular y tablet (< 900px) ---------- */
.bottom-nav, .menu-backdrop, .mobile-only { display: none; }
@media (max-width: 899px) {
  /* Menú lateral → panel que se desliza desde la izquierda */
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(300px, 86vw); max-width: none; height: 100%;
    overflow-y: auto; transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(14,21,37,.18);
    padding: max(20px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
  }
  body.menu-open { overflow: hidden; }
  body.menu-open .sidebar { transform: none; }
  .menu-backdrop { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(14,21,37,.4); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.menu-open .menu-backdrop { opacity: 1; pointer-events: auto; }
  nav button { min-height: 44px; }

  /* Barra inferior */
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: rgba(255,255,255,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--border);
    padding: 4px 4px max(4px, env(safe-area-inset-bottom)); gap: 0;
  }
  .bottom-nav button {
    flex-direction: column; justify-content: center; gap: 2px; width: auto; min-height: 54px; padding: 4px 2px; border-radius: 10px;
    font-size: 11px; font-weight: 500; text-align: center; color: var(--muted); background: transparent;
  }
  .bottom-nav button svg { width: 22px; height: 22px; }
  .bottom-nav button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .bottom-nav button.active { background: transparent; color: var(--accent); font-weight: 600; }
  .bottom-nav button:hover { background: transparent; }
  .layout { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .toast { left: 16px; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); max-width: none; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  main { padding: 0 12px 28px; }
  .topbar { padding: max(16px, env(safe-area-inset-top)) 12px 12px; gap: 12px; }
  .page-head h1 { font-size: 24px; }
  .search { width: 100%; height: 46px; }
  .search kbd { display: none; }

  /* iOS no hace zoom al enfocar campos de 16px; áreas táctiles de 44px */
  input, select, textarea { font-size: 16px; min-height: 44px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 0; }
  button { min-height: 44px; }
  button.icon { min-height: 40px; min-width: 40px; }

  .card { padding: 16px; border-radius: 14px; margin-bottom: 12px; }
  .card h2 { font-size: 16px; }
  .section-head h2 { font-size: 17px; }

  /* Filtros: dos por renglón, la búsqueda a todo lo ancho */
  .filters, .row { gap: 10px; }
  .filters > label, .card > .row > label { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .filters select, .row > label > select, .row > label:not(.check) > input { width: 100%; }
  label.check { font-size: 15px; }

  /* Filtros de Movimientos plegados */
  .mobile-only { display: inline-flex; }
  .tx-filters > .row:first-child { flex-wrap: nowrap; align-items: flex-end; }
  .tx-filters > .row:first-child > .grow { flex: 1 1 auto; }
  .tx-filters:not(.open) > .row:first-child > label:not(.grow), .tx-filters:not(.open) .row.between > .row:first-child { display: none; }
  .tx-filters.open > .row:first-child { flex-wrap: wrap; }
  .tx-filters.open #tx-filters-btn { order: -1; flex-basis: 100%; }
  .tx-filters:not(.open) .row.between { border-top: 0; padding-top: 0; }
  .row .grow { flex-basis: 100%; }
  .row.between > .row { width: 100%; }
  .row.between > .row:last-child { flex-wrap: nowrap; }
  .row.between > .row:last-child > button { flex: 1 1 0; min-width: 0; padding: 0 10px; white-space: normal; line-height: 1.2; }

  /* Indicadores: dos columnas; el principal a todo lo ancho */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
  .kpi { padding: 14px; gap: 4px; border-radius: 14px; }
  .kpi:first-child { grid-column: 1 / -1; }
  .kpi-value { font-size: 19px; overflow-wrap: anywhere; }
  .kpi:first-child .kpi-value { font-size: 28px; }
  .kpi-label { font-size: 12px; }

  .month-chart .axis { font-size: 12px; }
  .legend { font-size: 12px; gap: 4px 12px; }

  /* Resumen de inversiones del dashboard: sin columnas secundarias */
  table.inv-dash th:nth-child(5), table.inv-dash td:nth-child(5),
  table.inv-dash th:nth-child(6), table.inv-dash td:nth-child(6) { display: none; }
  .inv-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Movimientos: cada renglón se vuelve una tarjeta */
  .card.flush:has(> table.tx) { overflow: visible; background: transparent; border: 0; box-shadow: none; }
  table.tx { min-width: 0; }
  table.tx thead { display: none; }
  table.tx tbody { display: flex; flex-direction: column; gap: 8px; }
  table.tx tr {
    display: grid; grid-template-columns: 28px 1fr 1fr; column-gap: 8px; row-gap: 6px; align-items: center;
    background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px;
  }
  table.tx td { display: block; padding: 0 !important; border: 0; min-width: 0; }
  table.tx td:empty { display: none; }
  table.tx td:nth-child(1) { grid-column: 1; grid-row: 1 / span 2; align-self: start; padding-top: 2px !important; }
  table.tx td:nth-child(3) { grid-column: 2 / 4; grid-row: 1; max-width: none; }
  table.tx td:nth-child(2) { grid-column: 2; grid-row: 2; }
  table.tx td:nth-child(4) { grid-column: 3; grid-row: 2; font-size: 16px; font-weight: 700; }
  table.tx td:nth-child(5) { grid-column: 2 / 4; grid-row: 3; font-size: 13px; color: var(--muted); }
  table.tx td:nth-child(5)::before { content: "Total con sub-cargos "; }
  table.tx td:nth-child(6) { grid-column: 2 / 4; grid-row: 4; }
  table.tx td:nth-child(7) { grid-column: 2; grid-row: 5; }
  table.tx td:nth-child(8) { grid-column: 3; grid-row: 5; }
  table.tx td:nth-child(9) { grid-column: 1 / 4; grid-row: 6; display: flex; flex-wrap: wrap; gap: 2px; border-top: 1px solid var(--border-soft); padding-top: 6px !important; margin-top: 2px; }
  table.tx select { max-width: none; width: 100%; min-height: 40px; font-size: 16px; }
  table.tx td.desc { font-size: 15px; }
  table.tx tr.child { margin-left: 18px; background: var(--child); }
  table.tx tr.child td.desc { padding-left: 0 !important; }
  table.tx tr.child td:nth-child(7) { grid-column: 2 / 4; grid-row: 5; }
  table.tx tr.child td:nth-child(8) { grid-column: 1 / 4; grid-row: 6; display: flex; flex-wrap: wrap; gap: 2px; border-top: 1px solid var(--border-soft); padding-top: 6px !important; }
  table.tx tr.pending { box-shadow: inset 4px 0 0 #D97706; }
  table.tx tr.pending td:first-child { box-shadow: none; }
  table.tx tr.selected { border-color: var(--accent); }
  table.tx tr.more-row, table.tx tr:has(> td[colspan="9"]) { display: block; text-align: center; }
  table.tx tr.more-row td { display: flex; flex-direction: column; align-items: center; gap: 8px; }

  /* Ventanas: hoja desde abajo */
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; padding: 20px 16px max(16px, env(safe-area-inset-bottom)); }
  #modal-body { max-height: 68vh; }
  dialog .row.end > button { flex: 1 1 0; }

  .banner { border-radius: 12px; }
  .banner.bulk select { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .banner.bulk button.light { margin-left: 0; flex: 1 1 100%; }
  .person-head .amount { font-size: 20px; }
  .help-tx { flex-direction: column; }
  .msg { max-width: 100%; }
  .auth-card { padding: 22px; }
}
