:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1c1a17;
  --muted: #6b675e;
  --line: #e3ded4;
  --line-strong: #cfc9bd;
  --accent: #6366F1;
  --accent-ink: #4F46E5;
  --ok: #2f7d46;
  --warn: #b0562a;
  --err: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 17px; display: inline-flex; align-items: center; gap: 8px; }
.brand-word { display: inline-flex; flex-direction: column; line-height: 1; }
.brand-sub {
  font-size: 8.5px; font-weight: 600; letter-spacing: 3px;
  color: var(--muted); margin-top: 3px;
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-email { color: var(--muted); font-size: 14px; }

/* Layout */
.app { max-width: 820px; margin: 0 auto; padding: 28px 20px 60px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow);
  margin-bottom: 18px;
}
h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 20px; }

/* Forms */
label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
input, textarea, select {
  width: 100%; padding: 11px 12px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; color: var(--ink);
}
input[type="checkbox"] { width: auto; margin: 0; }
.agree {
  display: flex; align-items: flex-start; gap: 10px; margin-top: 18px;
  font-weight: 400; font-size: 14px; color: var(--ink); cursor: pointer;
}
.agree input { margin-top: 3px; flex: none; }
.site-footer {
  max-width: 820px; margin: 0 auto; padding: 20px; text-align: center;
  color: var(--muted); font-size: 13px; border-top: 1px solid var(--line);
}
.site-footer a { color: var(--muted); margin: 0 8px; }
textarea { min-height: 120px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 11px 18px; font-size: 15px; font-weight: 600; font-family: inherit;
  border: 1px solid transparent; border-radius: 9px; cursor: pointer; transition: .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: #f0ece3; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.btn-block { width: 100%; }

/* Segmented choice (scope, language) */
.choices { display: flex; gap: 10px; margin-top: 6px; }
.choice {
  flex: 1; padding: 16px; border: 1.5px solid var(--line-strong); border-radius: 10px;
  cursor: pointer; text-align: center; background: #fff; transition: .15s;
}
.choice:hover { border-color: var(--accent); }
.choice.active { border-color: var(--accent); background: #EEF0FF; box-shadow: inset 0 0 0 1px var(--accent); }
.choice .c-title { font-weight: 700; }
.choice .c-desc { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

/* Stepper */
.stepper { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; font-size: 12.5px; }
.step { color: var(--muted); padding: 4px 10px; border-radius: 20px; background: #efeae0; white-space: nowrap; }
.step.done { color: var(--ok); }
.step.current { background: var(--accent); color: #fff; }

/* Price breakdown */
.price-total { font-size: 34px; font-weight: 800; color: var(--accent-ink); }
.price-total small { font-size: 16px; font-weight: 600; color: var(--muted); }
.breakdown { list-style: none; padding: 0; margin: 16px 0; border-top: 1px solid var(--line); }
.breakdown li { display: flex; justify-content: space-between; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.breakdown .k { color: var(--muted); }
.breakdown .v { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Code / preview */
pre.code {
  background: #1e1c19; color: #eee; padding: 16px; border-radius: 10px;
  overflow: auto; font-family: ui-monospace, monospace; font-size: 13px; max-height: 360px;
}
.md {
  background: #fbfaf7; border: 1px solid var(--line); border-radius: 10px; padding: 18px;
  white-space: pre-wrap; font-size: 15px; max-height: 420px; overflow: auto;
}

/* Data summary + plan */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 14px; }
.kv .k { color: var(--muted); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.ok { background: #e3f2e7; color: var(--ok); }
.pill.warn { background: #fbeee2; color: var(--warn); }
.pill.err { background: #fbe4e2; color: var(--err); }
.tag { display:inline-block; background:#efeae0; color:var(--muted); border-radius:6px; padding:2px 8px; font-size:12px; margin:2px 4px 2px 0; }

/* Runs list */
.run-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px;
  cursor: pointer; background: #fff; transition: .15s;
}
.run-item:hover { border-color: var(--accent); }
.run-meta { font-size: 13px; color: var(--muted); }

/* Spinner */
.spinner { width: 18px; height: 18px; border: 2.5px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.spinner-lg { width: 34px; height: 34px; border: 3px solid var(--accent); border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; z-index: 100; box-shadow: var(--shadow); max-width: 90%;
}
.toast.err { background: var(--err); }

.link { color: var(--accent); cursor: pointer; text-decoration: underline; background: none; border: none; font: inherit; padding: 0; }

/* Floating WhatsApp "Chat with us" button */
.wa-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  display: inline-flex; align-items: center; gap: 8px;
  background: #25D366; color: #fff; text-decoration: none;
  padding: 12px 18px; border-radius: 999px; font-weight: 650; font-size: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,.22); transition: transform .15s, box-shadow .15s;
}
.wa-fab:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.28); }
.wa-fab svg { display: block; }
@media (max-width: 520px) { .wa-fab span { display: none; } .wa-fab { padding: 14px; } }
.muted-note { font-size: 13px; color: var(--muted); margin-top: 12px; }

/* ============================================================
   iOS-style polish: translucent bar, safe areas, tap feedback,
   dark mode. Progressive — older browsers keep the base styles.
   ============================================================ */

/* Softer, larger rounding + tactile press feedback */
.card { border-radius: 16px; }
.btn { border-radius: 12px; transition: transform .12s ease, background .15s ease; }
.btn:active { transform: scale(0.97); }
.run-item:active, .choice:active { transform: scale(0.99); }

/* Translucent, blurred sticky top bar (falls back to solid) */
.topbar {
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-left: calc(24px + env(safe-area-inset-left));
  padding-right: calc(24px + env(safe-area-inset-right));
}

/* Content respects the notch / home indicator + smooth momentum scroll */
.app { padding-bottom: calc(60px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }

/* Toast: fixed dark chip so it stays readable in light AND dark mode */
.toast { background: #1f232b; }

/* Phone refinements: bigger tap targets, no iOS zoom-on-focus (16px inputs) */
@media (max-width: 640px) {
  .app { padding: 18px 16px calc(40px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  .card { padding: 20px; border-radius: 18px; }
  .btn { padding: 14px 18px; font-size: 16px; }
  input, textarea, select { font-size: 16px; padding: 13px 14px; }
  .wa-fab { bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* Dark mode (auto — follows the phone/OS setting) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --ink: #f2f3f5;
    --muted: #9aa0ab;
    --line: #262a33;
    --line-strong: #333a47;
    --accent: #7c83ff;
    --accent-ink: #6366f1;
  }
  input, textarea, select, .run-item, .choice { background: #171a21; }
  .btn-ghost:hover { background: #20242d; }
  .choice.active { background: #20233a; }
  .step { background: #20242d; }
  .md { background: #14171d; }
  pre.code { background: #0c0d10; }
  .tag { background: #20242d; }
  .site-footer a { color: var(--muted); }
}

/* --- Analyst assistant panel --- */
.asst-card { margin-top: 16px; }
.asst-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.asst-remaining { color: var(--muted); font-size: 13px; }
.asst-log {
  max-height: 320px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 4px; margin-bottom: 12px;
}
.asst-msg { display: flex; }
.asst-user { justify-content: flex-end; }
.asst-assistant { justify-content: flex-start; }
.asst-bubble {
  max-width: 82%; padding: 9px 13px; border-radius: 14px;
  font-size: 14.5px; line-height: 1.5; white-space: pre-wrap;
  border: 1px solid var(--line);
}
.asst-user .asst-bubble { background: var(--accent); color: #fff; border-color: var(--accent); }
.asst-assistant .asst-bubble { background: var(--bg); color: var(--ink); }
.asst-input { display: flex; gap: 8px; align-items: flex-end; }
.asst-input textarea {
  flex: 1; resize: vertical; min-height: 42px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit;
}
.asst-input .btn { white-space: nowrap; }
