:root {
  --bg: #0f1115; --card: #1a1d24; --line: #272b34; --text: #f2f4f8; --muted: #8a92a3;
  --pos: #34c778; --neg: #ff6b6b; --accent: #4c8dff; --warn: #f5b942;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f4f6fa; --card: #ffffff; --line: #e1e5ec; --text: #14171d; --muted: #6a7384; --pos: #1a9a55; --neg: #d94a4a; --accent: #2b6be0; --warn: #b9801a; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
main { padding: calc(16px + env(safe-area-inset-top)) 16px calc(88px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
h1 { font-size: 28px; margin: 0; }
h2 { font-size: 15px; color: var(--muted); font-weight: 600; margin: 22px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
h3 { margin: 0 0 4px; }
.muted { color: var(--muted); font-size: 14px; }
.pos { color: var(--pos); font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--neg); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dim { opacity: .55; }
.error { color: var(--neg); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin-bottom: 12px; }
.hero .big { font-size: 38px; font-weight: 700; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .card { margin: 0; font-size: 20px; font-weight: 600; }
.alert { display: block; background: color-mix(in srgb, var(--warn) 16%, var(--card)); color: var(--text); border: 1px solid var(--warn); border-radius: 12px; padding: 10px 14px; margin: 12px 0 0; text-decoration: none; font-size: 14px; }
ul { list-style: none; margin: 0; padding: 0; }
.tx { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.tx-main { min-width: 0; }
.tx-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day { padding: 14px 0 4px; color: var(--muted); font-size: 13px; text-transform: capitalize; }
.filters { display: grid; gap: 8px; margin-bottom: 8px; }
input, select { width: 100%; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 16px; }
.btn { display: block; width: 100%; background: var(--accent); color: #fff; border: 0; border-radius: 12px; padding: 13px; font-size: 16px; font-weight: 600; margin-top: 12px; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.login { display: grid; gap: 10px; align-content: center; min-height: 80vh; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.badge.ok { background: color-mix(in srgb, var(--pos) 20%, transparent); color: var(--pos); }
.badge.bad { background: color-mix(in srgb, var(--neg) 20%, transparent); color: var(--neg); }
.badge.na { background: var(--line); color: var(--muted); }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.bar { height: 10px; border-radius: 6px; background: var(--accent); }
.barrow { margin: 10px 0; }
.seg { display: flex; gap: 6px; margin-bottom: 8px; }
.seg button { flex: 1; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px; font-size: 14px; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
svg text { fill: var(--muted); font-size: 11px; }
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
#tabs[hidden] { display: none; }
#tabs a { flex: 1; text-align: center; color: var(--muted); text-decoration: none; font-size: 10px; padding: 4px 0; }
#tabs a span { display: block; font-size: 20px; line-height: 1.1; }
#tabs a.on { color: var(--accent); }
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; z-index: 10; }
.sheet { background: var(--card); width: 100%; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 80vh; overflow: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: 15px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: 12px; z-index: 20; font-size: 14px; }
#toast[hidden] { display: none; }

/* Contenedores de disposicion (movil: una columna) */
.stats, .cards, .cols { display: grid; gap: 12px; }
.stats .card, .cards .card { margin: 0; }

/* Tablet y PC: menu lateral y contenido a mas ancho */
@media (min-width: 900px) {
  body { font-size: 15px; }
  body.auth { padding-left: 220px; }
  #tabs { top: 0; bottom: 0; right: auto; width: 220px; flex-direction: column; justify-content: flex-start; gap: 4px; padding: 28px 12px; border-top: 0; border-right: 1px solid var(--line); background: var(--card); backdrop-filter: none; }
  #tabs a { display: flex; align-items: center; gap: 12px; text-align: left; font-size: 15px; padding: 10px 14px; border-radius: 10px; }
  #tabs a span { display: inline; width: 22px; text-align: center; font-size: 18px; }
  #tabs a:hover { background: var(--line); }
  #tabs a.on { background: color-mix(in srgb, var(--accent) 16%, transparent); }
  main { max-width: 1040px; padding: 32px 40px 48px; }
  main.login { max-width: 380px; }
  h1 { font-size: 32px; }
  .stats { grid-template-columns: 1fr 1.4fr; gap: 16px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
  .cols { grid-template-columns: 1fr 1fr; gap: 28px; align-items: start; }
  .filters { grid-template-columns: 2fr 1fr 1fr; }
  .tx { padding: 12px 8px; border-radius: 8px; }
  .tx:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
  .btn { max-width: 360px; }
  .sheet-bg { align-items: center; justify-content: center; }
  .sheet { max-width: 480px; border-radius: 20px; padding-bottom: 18px; }
  #toast { left: auto; right: 24px; bottom: 24px; max-width: 360px; }
}

/* Tablet vertical */
@media (min-width: 600px) and (max-width: 899px) {
  main { max-width: 760px; }
  .cards { grid-template-columns: 1fr 1fr; }
}

/* Pagos recurrentes */
.av { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: #fff; font-weight: 700; flex: none; }
.av.sm { width: 22px; height: 22px; font-size: 11px; }
.av.paid { opacity: .4; }
.sub { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.sub:last-child { border-bottom: 0; }
.sub-main { flex: 1; min-width: 0; }
.sub-r { display: grid; gap: 2px; justify-items: end; text-align: right; font-variant-numeric: tabular-nums; }
.badge.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.monthbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; text-transform: capitalize; }
.nav { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px; width: 44px; height: 38px; font-size: 22px; line-height: 1; }
.sums { margin-bottom: 12px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal.head { margin-bottom: 6px; text-align: center; color: var(--muted); font-size: 12px; }
.cell { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; min-height: 56px; padding: 4px 2px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; }
.cell.empty { background: transparent; border: 0; }
.cell.today { border-color: var(--accent); }
.cell.today .dn { color: var(--accent); font-weight: 700; }
.marks { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; }
.tiny { font-size: 10px; }
.more { display: block; text-align: center; color: var(--accent); text-decoration: none; margin: 8px 0 0; font-size: 14px; }
@media (min-width: 900px) {
  .cell { min-height: 64px; }
  .cols.pagos-cols { grid-template-columns: 1.1fr 1fr; }
}

/* Logos de las empresas */
.av { position: relative; overflow: hidden; }
.av img.lg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 18%; box-sizing: border-box; }
.av.sm img.lg { padding: 14%; }
.mk.paid { opacity: .4; }
.sub[data-key] { cursor: pointer; }
.sheet input { margin-top: 10px; }

/* Importacion y hojas */
.sheet select { margin-top: 10px; }
.sheet .card { margin-top: 10px; margin-bottom: 0; }
.sheet .row { padding: 4px 0; min-width: 0; }
.sheet .tx-desc { max-width: 68%; }

/* Conexion bancaria */
input[type=checkbox] { width: 20px; height: 20px; padding: 0; accent-color: var(--accent); flex: none; }
.bankrow { padding: 10px 0; border-top: 1px solid var(--line); }

/* Auditoria */
.kpi { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cut { padding: 12px 0; border-top: 1px solid var(--line); }
.cut:first-child { border-top: 0; padding-top: 0; }
.cut .muted { margin: 4px 0; }
.linkcard { display: block; text-decoration: none; color: inherit; }
ul.plain { margin: 0; padding-left: 18px; list-style: disc; }
#runAudit { margin-bottom: 12px; }

.linkbtn { background: none; border: 0; color: var(--accent); font-size: 15px; padding: 0 4px; cursor: pointer; }

/* Seguridad */
pre.codes { background: var(--bg); border: 1px solid var(--line); padding: 12px; border-radius: 10px; font-size: 18px; line-height: 1.9; letter-spacing: .04em; user-select: all; white-space: normal; margin: 10px 0; }

/* Escritorio: menu lateral ordenado y mas ancho util */
@media (min-width: 900px) {
  #tabs a { flex: none; }
  #tabs::before { content: 'Finanzas hogar'; display: block; padding: 4px 14px 22px; font-weight: 700; font-size: 17px; }
}
@media (min-width: 1200px) {
  main { max-width: 1200px; }
}

/* Ficha del dia de pagos */
.cell.has { cursor: pointer; box-shadow: inset 0 0 0 1px var(--line); border-radius: 8px; }
.sheet { max-height: 88vh; overflow-y: auto; }
.cap { text-transform: capitalize; }
.dpago { padding: 12px 0; border-top: 1px solid var(--line); margin-top: 10px; }
.dpago .row { padding: 3px 0; align-items: center; }
.dp-n { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dgrid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin-top: 8px; }
.dgrid span:nth-child(even) { text-align: right; }
.dh { margin-top: 8px; }
/* Prevision */
.fline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.fdot { fill: var(--card); stroke: var(--neg); stroke-width: 2; }
/* Presupuestos */
.pbar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.pfill { height: 100%; background: var(--pos); border-radius: 4px; }
.pfill.cerca { background: var(--warn, #e0a030); }
.pfill.pasado { background: var(--neg); }
.prow { padding: 8px 0; cursor: pointer; }
.prow + .prow { border-top: 1px solid var(--line); }
/* Por revisar */
.revname { font-size: 22px; font-weight: 700; margin: 6px 0; word-break: break-word; }
.revchips { margin: 8px 0 14px; }
.revraw { font-size: 13px; color: var(--muted); word-break: break-word; margin: 6px 0; }
.revdet { margin: 8px 0; }
.revdet summary { cursor: pointer; color: var(--accent); margin-bottom: 6px; }
.revmov { padding: 6px 0 0; }
.chip.sug { border-color: var(--accent); }
.revchips .chip { padding: 10px 14px; }
/* Modo privado */
.cols[hidden] { display: none; }
.privcard .btn { width: auto; margin: 0; padding: 8px 16px; }
.privcard .row { align-items: center; margin-bottom: 6px; }
/* Graficos de velas */
.velas { display: block; touch-action: pan-y; user-select: none; }
.vgrid { stroke: var(--line); stroke-width: 1; }
.vtxt { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.vup { stroke: var(--pos); fill: var(--pos); }
.vdown { stroke: var(--neg); fill: var(--neg); }
.vvol { opacity: 0.35; stroke: none; }
.vlast { stroke: var(--muted); stroke-dasharray: 3 3; }
.vtag { fill: var(--card); stroke: var(--line); }
.vtagtxt { fill: var(--text); font-size: 11px; font-variant-numeric: tabular-nums; }
.vcruz { stroke: var(--muted); stroke-width: 1; }
.velainfo { min-height: 38px; font-size: 13px; line-height: 1.4; margin-bottom: 4px; }
/* Cripto */
.cryrow { padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.cryrow .row { padding: 2px 0; }
/* Chat de la auditoria */
.chatlog { max-height: 460px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.chatlog:empty { display: none; }
.bubble { padding: 10px 13px; border-radius: 16px; max-width: 92%; line-height: 1.45; font-size: 15px; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.err { border-color: var(--neg); }
.chips[hidden] { display: none; }
.chatform { display: flex; gap: 8px; margin-top: 8px; }
.chatform input { flex: 1; min-width: 0; }
.chatform .btn { width: auto; margin-top: 0; padding: 0 20px; }
