/* ============================================================
   Casa CFO — Sistema de diseño
   Minimalista, elegante, mobile-first. Light + Dark.
   ============================================================ */

:root {
  /* Paleta — light */
  --bg:        #f6f7f5;
  --bg-grad:   radial-gradient(120% 60% at 50% 0%, #ffffff 0%, #f6f7f5 60%);
  --surface:   #ffffff;
  --surface-2: #fbfbfa;
  --ink:       #14181c;
  --ink-soft:  #3b4248;
  --muted:     #8a9197;
  --hairline:  #ecece8;
  --hairline-2:#f1f1ee;

  --accent:    #0e7c66;
  --accent-ink:#0a5a4a;
  --accent-bg: #e6f3ef;
  --gold:      #b0863c;

  --pos:       #14935f;
  --pos-bg:    #e7f4ec;
  --neg:       #cf463b;
  --neg-bg:    #fbeae8;
  --warn:      #c2841b;
  --warn-bg:   #fbf1de;

  --shadow:    0 1px 2px rgba(20,24,28,.04), 0 8px 24px rgba(20,24,28,.05);
  --shadow-lg: 0 8px 40px rgba(20,24,28,.16);

  --r-sm: 12px;
  --r:    18px;
  --r-lg: 24px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0b0d0f;
    --bg-grad:   radial-gradient(120% 60% at 50% 0%, #15181b 0%, #0b0d0f 60%);
    --surface:   #15181b;
    --surface-2: #1a1e22;
    --ink:       #f1f3f2;
    --ink-soft:  #c4c9cc;
    --muted:     #7d858b;
    --hairline:  #262b2f;
    --hairline-2:#20242800;

    --accent:    #1fb592;
    --accent-ink:#7fe0c9;
    --accent-bg: #11352c;
    --gold:      #d2a861;

    --pos:       #2bb578;
    --pos-bg:    #123127;
    --neg:       #e26458;
    --neg-bg:    #3a1f1c;
    --warn:      #e0a93f;
    --warn-bg:   #352c16;

    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    --shadow-lg: 0 10px 50px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
::selection { background: var(--accent-bg); }

.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- App shell ---------- */
#app { min-height: 100dvh; }
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg-grad);
  position: relative;
}
.screen {
  padding: calc(var(--safe-top) + 14px) 18px calc(var(--nav-h) + var(--safe-bot) + 28px);
  animation: rise .32s cubic-bezier(.2,.7,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Header ---------- */
.hdr { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.hdr .eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.hdr h1 { font-size: 26px; font-weight: 700; margin: 2px 0 0; letter-spacing: -0.02em; }
.hdr .sub { font-size: 13px; color: var(--muted); margin-top: 3px; }

.iconbtn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--hairline); background: var(--surface);
  display: grid; place-items: center; color: var(--ink-soft);
  box-shadow: var(--shadow);
}
.iconbtn:active { transform: scale(.94); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.card.pad { padding: 18px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Hero net worth ---------- */
.hero {
  background: linear-gradient(150deg, var(--accent) 0%, var(--accent-ink) 100%);
  color: #fff; border: none; border-radius: var(--r-lg);
  padding: 22px; position: relative; overflow: hidden;
  box-shadow: 0 12px 30px -8px color-mix(in srgb, var(--accent) 55%, transparent);
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -50px;
  width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255,255,255,.10);
}
.hero .label { font-size: 12.5px; font-weight: 600; letter-spacing: .04em; opacity: .85; text-transform: uppercase; }
.hero .value { font-size: 38px; font-weight: 750; margin: 4px 0 2px; letter-spacing: -0.02em; }
.hero .delta { font-size: 13px; opacity: .9; display: inline-flex; align-items: center; gap: 5px; }
.hero .split { display: flex; gap: 22px; margin-top: 18px; }
.hero .split .k { font-size: 11.5px; opacity: .8; text-transform: uppercase; letter-spacing: .04em; }
.hero .split .v { font-size: 16px; font-weight: 650; margin-top: 2px; }

/* ---------- KPI tiles ---------- */
.kpi { padding: 15px 16px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--hairline); box-shadow: var(--shadow); }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 7px; letter-spacing: -0.02em; }
.kpi .hint { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.kpi .ic { color: var(--accent); display: grid; place-items: center; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- Pills / chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--hairline); color: var(--ink-soft);
}
.chip.pos { background: var(--pos-bg); color: var(--pos); border-color: transparent; }
.chip.neg { background: var(--neg-bg); color: var(--neg); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.accent { background: var(--accent-bg); color: var(--accent-ink); border-color: transparent; }

/* ---------- Section title ---------- */
.section-t { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 4px 12px; }
.section-t h2 { font-size: 15px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.section-t .more { font-size: 13px; color: var(--accent); font-weight: 600; background: none; border: none; padding: 0; }

/* ---------- List rows ---------- */
.list { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.li { display: flex; align-items: center; gap: 13px; padding: 13px 15px; border-bottom: 1px solid var(--hairline-2); background: none; width: 100%; text-align: left; border-left: none; border-right: none; border-top: none; color: inherit; }
.li:last-child { border-bottom: none; }
.li:active { background: var(--surface-2); }
.li .ava { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 18px; flex: none; background: var(--surface-2); border: 1px solid var(--hairline); }
.li .t { font-size: 14.5px; font-weight: 600; }
.li .s { font-size: 12px; color: var(--muted); margin-top: 1px; }
.li .amt { font-size: 14.5px; font-weight: 700; white-space: nowrap; }

/* ---------- Progress ---------- */
.bar { height: 9px; border-radius: 999px; background: var(--hairline); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .5s cubic-bezier(.2,.7,.2,1); }
.bar.pos > i { background: var(--pos); }
.bar.warn > i { background: var(--warn); }
.bar.neg > i { background: var(--neg); }

/* ---------- Alerts ---------- */
.alert { display: flex; gap: 12px; padding: 13px 15px; border-radius: var(--r); align-items: flex-start; }
.alert .ic { flex: none; margin-top: 1px; }
.alert .msg { font-size: 13.5px; line-height: 1.45; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.neg  { background: var(--neg-bg);  color: var(--neg); }
.alert.pos  { background: var(--pos-bg);  color: var(--pos); }
.alert.warn .msg, .alert.neg .msg, .alert.pos .msg { color: var(--ink); }

/* ---------- Segmented control ---------- */
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--hairline); padding: 4px; border-radius: 13px; gap: 4px; }
.seg button { flex: 1; border: none; background: none; padding: 8px 6px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: calc(var(--nav-h) + var(--safe-bot));
  padding-bottom: var(--safe-bot);
  max-width: 480px; margin: 0 auto;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(18px);
  -webkit-backdrop-filter: saturate(1.4) blur(18px);
  border-top: 1px solid var(--hairline);
  display: grid; grid-template-columns: repeat(6, 1fr); align-items: center;
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 9.5px; font-weight: 600;
  padding: 6px 0;
}
.nav a.on { color: var(--accent); }
.nav a .ic { display: grid; place-items: center; }
.nav-badge {
  position: absolute; top: -6px; right: -9px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 9.5px; font-weight: 800; display: grid; place-items: center;
  border: 2px solid var(--surface); box-sizing: content-box;
}
.nav .fab-slot { position: relative; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-bot) + 16px); z-index: 60;
  width: 56px; height: 56px; border-radius: 18px;
  background: var(--accent); color: #fff; border: none;
  display: grid; place-items: center;
  box-shadow: 0 10px 24px -6px color-mix(in srgb, var(--accent) 70%, transparent);
}
.fab:active { transform: scale(.93); }
@media (min-width: 481px) { .fab, .nav { right: max(18px, calc(50% - 240px + 18px)); } }

/* Botón flotante de Arkad (siempre accesible, abajo-izquierda) */
.arkad-fab {
  position: fixed; left: 18px; bottom: calc(var(--nav-h) + var(--safe-bot) + 16px); z-index: 60;
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(150deg, #b0863c, #7a5a22); color: #fff; border: none;
  font-size: 26px; line-height: 1; display: grid; place-items: center;
  box-shadow: 0 10px 24px -6px color-mix(in srgb, var(--gold) 70%, transparent);
}
.arkad-fab:active { transform: scale(.93); }
@media (min-width: 481px) { .arkad-fab { left: max(18px, calc(50% - 240px + 18px)); } }

/* ---------- Sheet (bottom modal) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(8,10,12,.42); z-index: 100; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101;
  max-width: 480px; margin: 0 auto;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 8px 18px calc(20px + var(--safe-bot));
  box-shadow: var(--shadow-lg);
  animation: slideup .32s cubic-bezier(.2,.8,.2,1);
  max-height: 92dvh; overflow-y: auto;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 999px; background: var(--hairline); margin: 6px auto 14px; }
.sheet h3 { font-size: 19px; font-weight: 700; margin: 0 0 16px; letter-spacing: -0.02em; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }
.input, .select {
  width: 100%; padding: 13px 14px; border-radius: 13px;
  border: 1px solid var(--hairline); background: var(--surface-2); color: var(--ink);
  font-size: 16px; outline: none; transition: border-color .15s, background .15s;
}
.input:focus, .select:focus { border-color: var(--accent); background: var(--surface); }
.input.big { font-size: 30px; font-weight: 700; padding: 10px 14px; letter-spacing: -0.02em; }
.amount-row { display: flex; gap: 10px; }
.amount-row .select { width: 104px; flex: none; }

.choicegrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 11px 4px;
  border-radius: 13px; border: 1px solid var(--hairline); background: var(--surface-2);
  font-size: 10.5px; font-weight: 600; color: var(--ink-soft); text-align: center; line-height: 1.15;
}
.choice .e { font-size: 20px; }
.choice.on { border-color: var(--accent); background: var(--accent-bg); color: var(--accent-ink); }

.btn {
  width: 100%; padding: 15px; border-radius: 15px; border: none;
  background: var(--accent); color: #fff; font-size: 15.5px; font-weight: 700;
  margin-top: 6px;
}
.btn:active { transform: scale(.99); filter: brightness(.97); }
.btn.ghost { background: var(--surface-2); color: var(--ink); border: 1px solid var(--hairline); }
.btn.danger { background: var(--neg-bg); color: var(--neg); }

.seg.type { margin-bottom: 18px; }
.seg.type button.on.income { color: var(--pos); }
.seg.type button.on.expense { color: var(--neg); }

/* ---------- Toggle row + switch ---------- */
.toggle-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: var(--surface-2); border: 1px solid var(--hairline);
  border-radius: 13px; padding: 12px 14px; margin-bottom: 14px; text-align: left; color: inherit;
}
.toggle-row .t { font-size: 14px; font-weight: 600; }
.toggle-row .s { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.switch { width: 46px; height: 28px; border-radius: 999px; background: var(--hairline); flex: none; position: relative; transition: background .2s; }
.switch > i { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch.on { background: var(--accent); }
.switch.on > i { transform: translateX(18px); }

/* ---------- Sliders (área táctil amplia + thumb propio) ---------- */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 36px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: var(--hairline); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 1px 5px rgba(0,0,0,.28);
  margin-top: -10px;
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--hairline); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--accent); }
input[type="range"]::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  border: 3px solid var(--surface); box-shadow: 0 1px 5px rgba(0,0,0,.28);
}

/* ---------- Camino (timeline de niveles) ---------- */
.camino-row { display: flex; gap: 14px; position: relative; padding-bottom: 20px; }
.camino-row::before { content: ""; position: absolute; left: 17px; top: 36px; bottom: -4px; width: 2px; background: var(--hairline); }
.camino-row:last-child::before { display: none; }
.camino-row.done::before { background: var(--accent); }
.camino-node { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 800; font-size: 15px; border: 2px solid var(--hairline); background: var(--surface); color: var(--muted); z-index: 1; }
.camino-row.done .camino-node { background: var(--accent); border-color: var(--accent); color: #fff; }
.camino-row.current .camino-node { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.camino-body { flex: 1; min-width: 0; }
.camino-name { font-weight: 700; font-size: 15.5px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.camino-row.locked .camino-name { color: var(--muted); }
.camino-desc { font-size: 13px; color: var(--ink-soft); margin-top: 3px; line-height: 1.45; }
.camino-row.locked .camino-desc { color: var(--muted); }
.camino-principle { font-size: 12px; color: var(--muted); font-style: italic; margin-top: 6px; line-height: 1.4; }
.camino-next { background: var(--surface-2); border: 1px solid var(--hairline); border-radius: 14px; padding: 13px; margin-top: 12px; }

/* ---------- Onboarding ---------- */
.onb-step { display: flex; align-items: center; gap: 11px; width: 100%; background: none; border: none; padding: 9px 2px; text-align: left; color: var(--ink); font-size: 14px; }
.onb-step + .onb-step { border-top: 1px solid var(--hairline-2); }
.onb-check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--hairline); display: grid; place-items: center; color: transparent; flex: none; font-size: 13px; font-weight: 800; }
.onb-check.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Selector de idioma (welcome) ---------- */
.seg-lang { font-size: 12px; font-weight: 700; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--hairline); background: var(--surface); color: var(--muted); letter-spacing: .02em; }
.seg-lang.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Chat Arkad (indicador "escribiendo") ---------- */
.typing { display: inline-flex; gap: 4px; background: var(--surface-2); padding: 13px 14px; border-radius: 4px 16px 16px 16px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .5; animation: typing-bounce 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 38px 20px; }
.empty .e { font-size: 34px; opacity: .5; }
.empty p { font-size: 13.5px; margin: 10px 0 0; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.right { text-align: right; }
.divider { height: 1px; background: var(--hairline); margin: 14px 0; }
.spacer { height: 8px; }
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.legend { display: flex; flex-direction: column; gap: 9px; flex: 1; }
.legend .lr { display: flex; align-items: center; gap: 9px; font-size: 12.5px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .lv { margin-left: auto; font-weight: 650; }
