/* ═══════════════════════════════════════════════════════════════
   ELCARO v3 — component kit ("Autopilot" language)
   Rules: every control is a pill · every surface is a hairline card
   radius 22 · emphasis by weight, not color or caps · color = money
   ═══════════════════════════════════════════════════════════════ */

* { margin:0; padding:0; box-sizing:border-box; }
html { -webkit-text-size-adjust:100%; }

html, body { overscroll-behavior: none; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 44px 44px;
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:active { transform: scale(.97); }
input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; }
[hidden] { display: none !important; }

/* ── APP SHELL ──────────────────────────────────────────────── */
#app { max-width: 560px; margin: 0 auto; padding: 0 var(--pad-screen); }

/* header */
#hdr {
  display: flex; align-items: center; gap: 9px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 2px 4px;
}
#hdr .mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
  font-size: 15px; font-weight: 900;
}
#hdr .word { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
#hdr .spacer { flex: 1; }

/* theme toggle — pill */
#theme-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 7px 13px;
  font-size: 12px; font-weight: 700; color: var(--ink-2);
  transition: border-color .2s, color .2s;
}
#theme-toggle:hover { border-color: var(--line-2); color: var(--ink); }
#theme-toggle .dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink); position: relative; overflow: hidden;
}
#theme-toggle .dot::after { content:''; position:absolute; inset:0 50% 0 0; background:var(--bg); }

/* screen container */
.screen { animation: screen-in .34s cubic-bezier(.2,.7,.2,1) both; }
@keyframes screen-in { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }
@media (prefers-reduced-motion: reduce) { .screen { animation:none; } }

/* large title */
.title { font-size: var(--fs-title); font-weight: 700; letter-spacing: -.02em; padding: 10px 2px 2px; }
.title-sub { font-size: var(--fs-sub); color: var(--ink-2); padding: 0 2px 12px; }

/* back row (sub-screens) */
.backrow { display: flex; align-items: center; padding: 10px 2px 2px; min-height: 40px; }
.backrow .back { display:flex; align-items:center; gap:6px; font-size:14px; font-weight:700; color:var(--ink-2); padding:6px 10px 6px 2px; }
.backrow .back:hover { color: var(--ink); }
.backrow .br-title { flex:1; text-align:center; font-size:16px; font-weight:700; margin-right:52px; }

/* ── CONTROLS ───────────────────────────────────────────────── */

/* chip — outlined pill; .on = filled */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 8px 16px;
  font-size: 14px; font-weight: 500; color: var(--ink);
  background: transparent;
  transition: border-color .15s, background .15s, color .15s;
}
.chip:hover { border-color: var(--line-2); }
.chip.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 700; }
.chip.ghost { color: var(--ink-3); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 0 6px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--pad-screen)); padding-left: var(--pad-screen); padding-right: var(--pad-screen); }
.chips.scroll::-webkit-scrollbar { display: none; }

/* segmented control — track + filled thumb */
.seg {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--fill); border-radius: var(--r-pill);
  margin: 4px 0 12px;
}
.seg button {
  padding: 6px 14px; border-radius: var(--r-pill);
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  transition: background .15s, color .15s;
}
.seg button.on { background: var(--accent); color: var(--on-accent); font-weight: 700; }

/* primary CTA — full-width black pill */
.cta {
  display: block; width: 100%;
  background: var(--accent); color: var(--on-accent);
  border-radius: var(--r-pill); padding: 15px;
  font-size: 15px; font-weight: 700; text-align: center;
  margin: 12px 0 2px;
}
.cta.quiet { background: transparent; color: var(--ink); border: 1px solid var(--line-2); }
.cta[disabled] { opacity: .35; pointer-events: none; }

/* tint badge (confidence, status) */
.tint { display:inline-flex; align-items:center; border-radius:var(--r-pill); padding:5px 12px; font-size:12px; font-weight:700; }
.tint.g { color: var(--green); background: var(--green-tint); }
.tint.r { color: var(--red);   background: var(--red-tint); }
.tint.n { color: var(--ink-2); background: var(--fill); }

/* ── SURFACES ───────────────────────────────────────────────── */

.card { border: 1px solid var(--line); border-radius: var(--r-card); background: var(--bg); overflow: hidden; }
.card + .card { margin-top: 12px; }
.card.pad { padding: 16px; }

/* section label row */
.slabel { display: flex; justify-content: space-between; align-items: center; padding: 14px 2px 8px; }
.slabel h3 { font-size: var(--fs-h3); font-weight: 700; letter-spacing: -.01em; }
.slabel .aux { font-size: 12px; color: var(--ink-3); font-weight: 500; }

/* list row */
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); min-height: 52px; }
.row:last-child { border-bottom: none; }
.row.tap:hover { background: var(--fill); }
.row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.row .dot.g { background: var(--green); } .row .dot.r { background: var(--red); } .row .dot.n { background: var(--ink-4); }
.row .body { flex: 1; min-width: 0; }
.row .t { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.row .t.md { font-weight: 500; }
.row .s { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.row .end { text-align: right; flex: none; }
.row .end .t { font-size: 14px; }
.row .end .t.dim { font-weight: 500; color: var(--ink-2); }
.row .chev { color: var(--ink-4); flex: none; }

/* money colors — numbers only */
.up { color: var(--green); font-weight: 700; }
.dn { color: var(--red);   font-weight: 700; }

/* hero numeral — one per screen */
.hero { text-align: center; padding: 18px 0 4px; }
.hero .cur { font-size: 28px; font-weight: 400; color: var(--ink-2); vertical-align: 24px; margin-right: 2px; }
.hero .n { font-size: var(--fs-hero); font-weight: 400; letter-spacing: -.035em; line-height: 1.02; }
.hero .u { font-size: 13px; color: var(--ink-2); margin-top: 7px; }

/* stat block (radar / big value + context) */
.stat { display: flex; align-items: center; gap: 16px; padding: 14px 16px; }
.stat .big { font-size: 50px; font-weight: 400; letter-spacing: -.03em; line-height: 1; }
.stat .body { flex: 1; min-width: 0; }
.stat .t { font-size: 15px; font-weight: 700; }
.stat .s { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }
.stat .end { margin-left: auto; text-align: right; flex: none; }
.stat .end .p { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.stat .end .d { font-size: 13px; margin-top: 2px; }

/* split card (floor / ceiling) */
.split { display: flex; border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; }
.split > div { flex: 1; padding: 14px 16px; text-align: center; }
.split > div + div { border-left: 1px solid var(--line); }
.split .l { font-size: var(--fs-micro); font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.split .v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; }
.split .d { font-size: 12.5px; font-weight: 700; margin-top: 3px; }

/* probability cards */
.probs { display: flex; gap: 12px; }
.prob { flex: 1; border: 1px solid var(--line); border-radius: var(--r-card); padding: 14px 16px; }
.prob .pc { font-size: 36px; font-weight: 400; letter-spacing: -.03em; color: var(--green); }
.prob .s { font-size: 12px; color: var(--ink-2); margin-top: 4px; line-height: 1.4; }
.prob .rng { font-size: 15px; font-weight: 700; margin-top: 12px; }

/* KV grid (greeks etc.) */
.kv { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: none; }
.kv .k { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.kv .v { font-size: 14px; font-weight: 700; }

/* micro label */
.micro { font-size: var(--fs-micro); font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }

/* tool tile grid (launcher) */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  border: 1px solid var(--line); border-radius: var(--r-card);
  padding: 16px; text-align: left; background: var(--bg);
  display: flex; flex-direction: column; gap: 10px; min-height: 104px;
  transition: border-color .15s, background .15s;
}
.tile:hover { border-color: var(--line-2); background: var(--fill); }
.tile .ic { width: 26px; height: 26px; color: var(--ink); }
.tile .tt { font-size: 15px; font-weight: 700; letter-spacing: -.01em; margin-top: auto; }
.tile .ts { font-size: 12px; color: var(--ink-2); }

/* skeleton shimmer */
.skel { border-radius: 8px; background: var(--fill); position: relative; overflow: hidden; min-height: 14px; }
.skel::after { content:''; position:absolute; inset:0; transform:translateX(-100%); background:linear-gradient(90deg,transparent,rgba(127,127,127,.12),transparent); animation:skel 1.2s infinite; }
@keyframes skel { to { transform:translateX(100%); } }

/* empty / error state */
.empty { text-align: center; padding: 36px 20px; color: var(--ink-2); font-size: 14px; }
.empty b { display: block; color: var(--ink); font-size: 16px; font-weight: 700; margin-bottom: 6px; }

/* ── BOTTOM NAV ─────────────────────────────────────────────── */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding: 8px 0 calc(6px + env(safe-area-inset-bottom, 0px));
}
#nav .inner { max-width: 560px; margin: 0 auto; display: flex; }
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3); padding: 4px 0;
  transition: color .15s;
}
#nav a.on { color: var(--ink); }
#nav a svg { width: 21px; height: 21px; }

/* numeric keypad (calc) */
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px 0 4px; }
.pad button {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 14px 0; font-size: 20px; font-weight: 500;
}
.pad button:hover { border-color: var(--line-2); }
.pad button.soft { background: transparent; color: var(--ink-2); }

/* input pill */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: var(--fs-micro); font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.field input, .field select {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--bg-2); padding: 12px 14px;
  font-size: 16px; font-weight: 700; width: 100%;
  outline: none; transition: border-color .15s;
}
.field input:focus, .field select:focus { border-color: var(--line-2); }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields2 > .field { min-width: 0; }
.field input { min-width: 0; }
.field .seg { flex-wrap: wrap; }
.field.wide { grid-column: 1 / -1; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom,0px)); transform: translateX(-50%) translateY(8px);
  background: var(--accent); color: var(--on-accent);
  border-radius: var(--r-pill); padding: 11px 20px;
  font-size: 14px; font-weight: 700; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 99; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
