/* ============================================================================
   Ábaco — Cabina de inversión · Dark fintech (OLED)
   Sistema de diseño: ui-ux-pro-max · Inter · densidad dashboard
   ============================================================================ */
:root {
  --bg: #020617;
  --surface: #0B1120;
  --surface-2: #0F172A;
  --surface-3: #161F35;
  --border: #1E293B;
  --border-2: #334155;
  --fg: #F8FAFC;
  --muted: #94A3B8;
  --muted-2: #64748B;
  --accent: #22C55E;
  --accent-ink: #052e16;
  --up: #22C55E;
  --down: #F43F5E;
  --warn: #F59E0B;
  --brand: #38BDF8;
  --radius: 16px;
  --radius-sm: 10px;
  --sp-1: 6px; --sp-2: 10px; --sp-3: 16px; --sp-4: 24px; --sp-5: 36px;
  --shadow: 0 10px 30px -12px rgba(0,0,0,.6);
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: 'Inter', ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 80% -10%, #0b1a2e 0%, var(--bg) 55%);
  color: var(--fg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
h1,h2,h3,h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
button { font-family: inherit; cursor: pointer; }
a, .linklike { color: var(--brand); }
[hidden] { display: none !important; }

/* ---- Brand / logo ---- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -0.02em; }
.brand .logo { width: 26px; height: 26px; color: var(--accent); stroke: currentColor; fill: none; stroke-width: 1.6; }
.brand-lg { font-size: 30px; justify-content: center; }
.brand-lg .logo { width: 40px; height: 40px; }

/* ---- Buttons ---- */
.btn { border: 1px solid var(--border-2); background: var(--surface-2); color: var(--fg); padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; transition: all .16s ease; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.btn:hover { border-color: var(--muted-2); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04160b; }
.btn-primary:hover { background: #16a34a; box-shadow: 0 8px 20px -8px rgba(34,197,94,.6); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--down); border-color: rgba(244,63,94,.4); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--muted); transition: all .16s; }
.icon-btn:hover { color: var(--fg); border-color: var(--border-2); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Login ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-sub { text-align: center; color: var(--muted); margin: -6px 0 8px; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select { background: var(--surface-2); border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 11px 13px; color: var(--fg); font-size: 15px; font-family: inherit; transition: border-color .16s; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.form-error { color: var(--down); font-size: 13px; text-align: center; margin: 0; }
.linklike { background: none; border: none; font-size: 12px; text-align: center; padding: 4px; }

/* ---- Topbar ---- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 14px 20px; padding-top: max(14px, env(safe-area-inset-top)); background: rgba(2,6,23,.82); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border); }
.topbar-capital { margin-left: auto; text-align: right; line-height: 1.15; }
.cap-label { display: block; font-size: 11px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .06em; }
.cap-value { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.topbar-actions { display: flex; gap: 8px; }
.brand#brand-home { cursor: pointer; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; padding: 10px 16px 0; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); position: sticky; top: 68px; z-index: 15; background: var(--bg); }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; background: none; border: none; color: var(--muted); padding: 12px 16px; font-size: 14px; font-weight: 600; border-bottom: 2px solid transparent; transition: color .16s; display: flex; align-items: center; gap: 7px; }
.tab svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); }

/* ---- Layout ---- */
main#view { max-width: 1100px; margin: 0 auto; padding: 24px 20px 96px; padding-bottom: max(96px, calc(env(safe-area-inset-bottom) + 40px)); }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.view-head h1 { font-size: 24px; }
.view-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.grid { display: grid; gap: 14px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 720px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

/* ---- Cards ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card-title { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Stat tile */
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .label { font-size: 12px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .value.sm { font-size: 22px; }
.stat .delta { font-size: 13px; font-weight: 600; }
.up { color: var(--up); } .down { color: var(--down); } .warn { color: var(--warn); }

/* Split bar (cash vs invested) */
.splitbar { height: 10px; border-radius: 6px; overflow: hidden; display: flex; background: var(--surface-3); margin-top: 6px; }
.splitbar > span { display: block; height: 100%; }
.legend { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: middle; }

/* Table */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--muted-2); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .num { text-align: right; }
.asset-chip { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.asset-chip .dot { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--surface-3); color: var(--brand); }

/* Investment option cards */
.opt { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; transition: border-color .16s, transform .16s; }
.opt:hover { border-color: var(--border-2); transform: translateY(-2px); }
.opt-head { display: flex; align-items: center; gap: 12px; }
.opt-ico { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-3); color: var(--accent); flex: none; }
.opt-ico svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.opt h3 { font-size: 16px; }
.opt .desc { color: var(--muted); font-size: 13px; flex: 1; }
.opt .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tag { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.tag.ok { background: rgba(34,197,94,.14); color: var(--up); }
.tag.soon { background: rgba(148,163,184,.14); color: var(--muted); }
.tag.risk { background: rgba(245,158,11,.14); color: var(--warn); }
.tag.live { background: rgba(56,189,248,.14); color: var(--brand); }

/* Running order row */
.run { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.run:last-child { border-bottom: none; }
.run .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 0 rgba(56,189,248,.6); animation: pulse 1.8s infinite; flex: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(56,189,248,0); } 100% { box-shadow: 0 0 0 0 rgba(56,189,248,0); } }

/* Banner */
.banner { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5; align-items: flex-start; }
.banner svg { width: 18px; height: 18px; flex: none; margin-top: 1px; stroke: currentColor; fill: none; stroke-width: 2; }
.banner.info { background: rgba(56,189,248,.08); border: 1px solid rgba(56,189,248,.2); color: #bae6fd; }
.banner.warn { background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.25); color: #fde68a; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,6,23,.7); backdrop-filter: blur(4px); }
.modal-card { position: relative; width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); max-height: 90dvh; overflow-y: auto; animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { font-size: 19px; }
.steps { display: flex; gap: 6px; margin: 14px 0; }
.steps .s { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-3); }
.steps .s.on { background: var(--accent); }
.chooser { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px,1fr)); gap: 8px; }
.chooser button { padding: 12px 6px; border-radius: var(--radius-sm); border: 1px solid var(--border-2); background: var(--surface-2); color: var(--fg); font-weight: 700; font-size: 14px; }
.chooser button.sel { border-color: var(--accent); background: rgba(34,197,94,.1); color: var(--up); }
.amt-row { display: flex; gap: 8px; margin-top: 8px; }
.amt-row button { flex: 1; padding: 9px; border-radius: var(--radius-sm); border: 1px solid var(--border-2); background: var(--surface-2); color: var(--muted); font-weight: 600; }
.amt-row button:hover { color: var(--fg); }
.confirm-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.confirm-row:last-of-type { border-bottom: none; }
.confirm-row .k { color: var(--muted); }
.confirm-row .v { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--surface-3); border: 1px solid var(--border-2); color: var(--fg); padding: 12px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); animation: pop .18s ease; max-width: 90vw; }
.toast.ok { border-color: rgba(34,197,94,.5); }
.toast.err { border-color: rgba(244,63,94,.5); }

/* Skeleton / empty */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: sk 1.3s infinite; border-radius: 8px; height: 16px; }
@keyframes sk { to { background-position: -200% 0; } }
.empty { text-align: center; color: var(--muted); padding: 28px; font-size: 14px; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---- Subnav (submódulos) ---- */
.subnav { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subtab { white-space: nowrap; background: none; border: none; color: var(--muted); padding: 9px 14px; font-size: 13px; font-weight: 600; border-radius: 9px; display: flex; align-items: center; gap: 6px; transition: all .15s; }
.subtab svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }
.subtab:hover { color: var(--fg); }
.subtab.active { background: var(--surface-3); color: var(--fg); }

/* ---- Live badge / dot ---- */
.live-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: pulse 1.8s infinite; }
.live-dot.off { background: var(--muted-2); animation: none; }
.flash { animation: flash .4s ease; }
@keyframes flash { 0% { color: var(--accent); } 100% { color: var(--fg); } }

/* ---- Modal step label ---- */
.mstep { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

/* ---- Consola de debug ---- */
.console { background: #010409; border: 1px solid var(--border); border-radius: 10px; padding: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; max-height: 420px; overflow-y: auto; }
.cline { display: flex; gap: 10px; padding: 4px 6px; border-radius: 6px; align-items: center; white-space: nowrap; }
.cline.bad { background: rgba(244,63,94,.07); }
.cline .ct { color: var(--muted-2); }
.cline .cm { color: var(--brand); font-weight: 700; width: 42px; }
.cline .cp { color: var(--fg); flex: 1; overflow: hidden; text-overflow: ellipsis; }
.cline .cs { font-weight: 700; }
.cline .cs.ok { color: var(--up); } .cline .cs.bad { color: var(--down); }
.cline .cd { color: var(--muted-2); }
.cline .ce { color: var(--down); }
