/* ============================================================
   AI Trading Bot — light blue / white minimal theme
   (styled after rallyio: Inter, #2F80FF accent, pill buttons,
    soft blue shadows, rounded cards)
   ============================================================ */
:root {
  --blue-50:  #F3F8FF;
  --blue-100: #E5F0FF;
  --blue-200: #C9E0FF;
  --blue-300: #A9CDFF;
  --blue-500: #2F80FF;
  --blue-600: #1E6BF0;
  --ink:      #0E1B2E;
  --muted:    #5B6B82;
  --line:     #E6EEF9;
  --white:    #FFFFFF;
  --green:    #1A9E55;
  --green-bg: #E6F8EE;
  --amber:    #B45309;
  --amber-bg: #FEF3C7;
  --red:      #DC2626;
  --red-bg:   #FEE2E2;
  --shadow-sm: 0 4px 14px rgba(20, 70, 150, .06);
  --shadow:    0 16px 40px rgba(20, 70, 150, .10);
  --radius:    18px;
  --radius-lg: 26px;
  --maxw:      1120px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 480px at 50% -120px, var(--blue-100), transparent 70%),
    linear-gradient(180deg, var(--blue-50), #fff 40%);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.15; letter-spacing: -0.02em; }
h2 { font-size: 1.4rem; font-weight: 800; }
a { color: inherit; text-decoration: none; }
code { background: var(--blue-50); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }
.fine { font-size: .85rem; color: var(--muted); margin-top: 10px; }
.lead { color: var(--muted); margin: 8px 0 18px; }
.spacer { flex: 1; }
.row-between { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }

/* ---------- Brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; }
.brand__dot {
  width: 18px; height: 18px; border-radius: 6px;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-300));
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.7);
}
.brand__name { font-size: 1.2rem; letter-spacing: -0.03em; }
.brand__name span { color: var(--blue-500); }

/* ---------- Eyebrow ---------- */
.eyebrow {
  display: inline-block;
  font-size: .8rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--blue-600);
  background: var(--blue-100);
  padding: 6px 12px; border-radius: 999px;
  margin-bottom: 10px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-weight: 600; font-size: .98rem;
  padding: 13px 22px; border-radius: 999px;
  border: 1.5px solid transparent; cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
  white-space: nowrap;
}
.btn--sm { padding: 9px 16px; font-size: .9rem; }
.btn--block { width: 100%; }
.btn--primary { background: var(--blue-500); color: #fff; box-shadow: 0 8px 20px rgba(47,128,255,.28); }
.btn--primary:hover { background: var(--blue-600); transform: translateY(-2px); box-shadow: 0 12px 26px rgba(47,128,255,.34); }
.btn--ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn--ghost:hover { border-color: var(--blue-300); transform: translateY(-2px); }
.btn--danger { color: var(--red); }
.btn--danger:hover { border-color: var(--red); }
.btn:disabled { background: var(--blue-50); color: var(--muted); border-color: var(--line); cursor: not-allowed; box-shadow: none; transform: none; }

/* ---------- Nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,.78);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.nav__inner { display: flex; align-items: center; justify-content: space-between; height: 68px; gap: 18px; }
.nav__cta { display: flex; align-items: center; gap: 14px; }

/* ---------- Top-bar status dropdown (brokers / AI / markets) ---------- */
.nav__status { position: relative; display: flex; align-items: center; min-width: 0; }
.status-btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; font-size: .82rem; font-weight: 700; color: var(--ink);
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  background: #fff; border: 1.5px solid var(--line);
  transition: border-color .15s ease, box-shadow .2s ease;
}
.status-btn:hover, .status-btn[aria-expanded="true"] { border-color: var(--blue-300); box-shadow: var(--shadow-sm); }
.status-btn__dot { flex: none; width: 8px; height: 8px; border-radius: 999px; background: var(--muted); transition: width .15s ease, height .15s ease; }
.status-btn__dot--ok   { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.status-btn__dot--warn { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-bg); }
/* Health-red: enlarged and gently pulsing so a problem reads at a glance. */
.status-btn__dot--bad  {
  background: var(--red); width: 13px; height: 13px;
  box-shadow: 0 0 0 4px var(--red-bg);
  animation: statusDotPulse 1.6s ease-in-out infinite;
}
@keyframes statusDotPulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--red-bg); }
  50%      { box-shadow: 0 0 0 7px var(--red-bg); }
}
@media (prefers-reduced-motion: reduce) { .status-btn__dot--bad { animation: none; } }
.status-btn__chev { color: var(--muted); font-size: .68rem; transition: transform .15s ease; }
.status-btn[aria-expanded="true"] .status-btn__chev { transform: rotate(180deg); }

.status-menu {
  position: absolute; top: calc(100% + 10px); right: 0;
  width: min(340px, calc(100vw - 32px)); z-index: 60;
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 8px; text-align: left;
}
.status-menu[hidden] { display: none; }
.status-menu__group {
  font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 10px 12px 4px;
}
.status-menu__group:not(:first-child) { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; }
.status-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; }
.status-row__dot { flex: none; width: 8px; height: 8px; border-radius: 999px; }
.status-row__dot--ok   { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.status-row__dot--warn { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-bg); }
.status-row__dot--bad  { background: var(--red);   box-shadow: 0 0 0 3px var(--red-bg); }
.status-row__dot--muted { background: var(--blue-200); }
.status-row__label { font-size: .9rem; font-weight: 600; min-width: 0; }
.status-row__sub { display: block; font-size: .78rem; font-weight: 500; color: var(--muted); }
.status-row__action {
  margin-left: auto; flex: none;
  font-size: .8rem; font-weight: 700; color: var(--blue-600);
  background: var(--blue-50); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; cursor: pointer; font-family: inherit; white-space: nowrap;
  transition: border-color .15s ease, background .15s ease;
}
.status-row__action:hover { border-color: var(--blue-300); background: var(--blue-100); }
.status-row__action--quiet { color: var(--muted); background: transparent; border-color: transparent; }
.status-row__action--quiet:hover { color: var(--red); background: var(--red-bg); border-color: transparent; }
.status-row__state { margin-left: auto; flex: none; font-size: .8rem; font-weight: 700; }
.status-row__state--ok { color: var(--green); }
.status-row__state--bad { color: var(--red); }
.status-row__state--muted { color: var(--muted); }

@media (max-width: 860px) {
  .nav__greeting, .app-user__avatar { display: none; }  /* make room in the bar */
}
.nav__greeting { color: var(--muted); font-weight: 600; font-size: .95rem; white-space: nowrap; }
.app-user { display: flex; align-items: center; gap: 10px; }
.app-user__avatar { width: 30px; height: 30px; border-radius: 999px; border: 1.5px solid var(--line); }

/* ---------- App layout ---------- */
.app { padding: 34px 0 80px; }
.app__inner { display: grid; gap: 22px; }
/* Grid items default to min-width:auto and won't shrink below their content's
   intrinsic width — a long log line or option would then blow the whole layout
   past the container cap. Let every item shrink so inner overflow:auto works. */
.app__inner > *, .view > * { min-width: 0; }
.app-card {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 30px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.stat {
  background: var(--blue-50); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 16px;
}
.stat .k { display: block; color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { display: block; font-weight: 700; margin-top: 4px; }

/* ---------- Pills & tags ---------- */
.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.pill--live { background: var(--green-bg); color: var(--green); }
.pill--warn { background: var(--amber-bg); color: var(--amber); }
.pill--muted { background: var(--blue-50); color: var(--muted); border: 1px solid var(--line); }
.pill--blue { background: var(--blue-100); color: var(--blue-600); }
.pill--red { background: var(--red-bg); color: var(--red); }
h2 .pill { vertical-align: middle; margin-left: 6px; }
.tag {
  display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--blue-600); background: var(--blue-100); padding: 4px 9px; border-radius: 999px;
}

/* ---------- Bots (list rows) ---------- */
/* Agents are laid out as full-width rows: a status accent on the left edge,
   name + strategy in the middle, scannable metric columns and a mini budget
   sparkline on the right. */
.bots { display: flex; flex-direction: column; gap: 12px; }
.bot-row {
  position: relative; display: flex; align-items: center; gap: 24px;
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 24px 18px 26px;
  box-shadow: var(--shadow-sm); overflow: hidden;
  transition: transform .18s ease, box-shadow .25s ease, border-color .2s ease;
}
.bot-row:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--blue-300); }
.bot-row:focus-visible { outline: 2px solid var(--blue-300); outline-offset: 2px; }
/* Colored bar pinned to the left edge = the agent's run state at a glance. */
.bot-row__accent { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--blue-200); }
.bot-row__accent--run  { background: linear-gradient(180deg, #34c77b, var(--green)); }
.bot-row__accent--stop { background: var(--blue-200); }
.bot-row__accent--warn { background: var(--amber); }
.bot-row__accent--err  { background: var(--red); }

.bot-row__main { flex: 1 1 auto; min-width: 0; }
.bot-row__title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bot-row__title h3 { font-size: 1.08rem; margin: 0; }
.bot-row__prompt {
  color: var(--muted); font-size: .9rem; margin: 5px 0 0;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.bot-row__sub { margin-top: 7px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.bot-row__metrics { display: flex; gap: 30px; flex: none; }
.bot-metric { text-align: right; min-width: 76px; }
.bot-metric__k { display: block; font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.bot-metric__v { display: block; font-weight: 700; font-size: .96rem; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.bot-row__end { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; width: 128px; }
.bot-row__end .spark { margin: 0; width: 128px; height: 34px; }
.bot-row__chev { color: var(--blue-600); font-weight: 700; font-size: .84rem; white-space: nowrap; }
.bot-row:hover .bot-row__chev { text-decoration: underline; }

/* Stack the row on narrow screens: name/strategy on top, metrics below. */
@media (max-width: 820px) {
  .bot-row { flex-wrap: wrap; gap: 14px 20px; padding: 18px 20px; }
  .bot-row__main { flex: 1 1 100%; }
  .bot-metric { text-align: left; }
  .bot-row__end { flex-direction: row; align-items: center; margin-left: auto; width: auto; gap: 14px; }
}

/* Empty state: shown when the user has no agents yet. */
.bots-empty {
  text-align: center; padding: 44px 24px;
  border: 1.5px dashed var(--blue-200); border-radius: var(--radius);
  background: var(--blue-50);
}
.bots-empty__icon {
  font-size: 2rem; line-height: 1;
  width: 64px; height: 64px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow-sm);
}
.bots-empty h3 { font-size: 1.15rem; }
.bots-empty .fine { max-width: 42ch; margin: 8px auto 18px; }

.card {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .25s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--blue-300); }
.bot h3 { font-size: 1.1rem; }
.bot__prompt {
  color: var(--muted); font-size: .92rem; margin: 4px 0 10px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.bot__tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.bot__meta { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.bot__actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.bot__summary { margin-top: 10px; }
.bot__summary summary { cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--blue-600); }
.bot__summary pre {
  white-space: pre-wrap; word-wrap: break-word; font-size: .82rem;
  background: var(--blue-50); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin-top: 8px; max-height: 320px; overflow: auto;
}

/* ---------- Logs ---------- */
.logbox {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem; line-height: 1.5; color: #33445c;
  white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--blue-50); border: 1.5px dashed var(--blue-200);
  border-radius: 14px; padding: 16px;
  height: 260px; overflow: auto;
}

/* ---------- Alerts ---------- */
.alert { padding: 10px 14px; border-radius: 12px; margin: 10px 0; font-size: .9rem; font-weight: 500; }
.alert--error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(220,38,38,.2); }
.alert--ok { background: var(--green-bg); color: var(--green); border: 1px solid rgba(26,158,85,.25); }
.alert[hidden] { display: none; }

/* Dismissible per-bot error */
.bot__error { position: relative; padding-right: 34px; }
.bot__error-time { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; opacity: .7; margin-bottom: 4px; }
.bot__error-x {
  position: absolute; top: 6px; right: 8px; width: 22px; height: 22px;
  border: none; background: transparent; color: var(--red);
  font-size: 1.1rem; line-height: 1; cursor: pointer; border-radius: 6px; opacity: .7;
}
.bot__error-x:hover { opacity: 1; background: rgba(220,38,38,.12); }

/* ---------- Transactions table ---------- */
.tx-scroll { margin-top: 8px; max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.tx-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.tx-table thead th {
  position: sticky; top: 0; z-index: 1; text-align: left; font-weight: 700;
  background: var(--blue-50); color: var(--muted); padding: 8px 10px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tx-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tx-table tbody tr:last-child td, .tx-table tr:last-child td { border-bottom: none; }
.tx-at { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.tx-tool { white-space: nowrap; font-weight: 600; }
.tx-detail { word-break: break-word; }
.tx-detail code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .74rem; }
.tx-json {
  margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .72rem;
  line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow: auto; color: var(--ink);
}
.tx-more { margin-top: 8px; }
.tx-status .pill { font-size: .66rem; padding: 3px 8px; white-space: nowrap; }

/* Outcome tints: green = the order went through, red = it didn't. */
.tx-table tr.tx-row--ok td { background: #F3FBF6; }
.tx-table tr.tx-row--bad td { background: #FDF5F5; }

/* Filter toolbar: one horizontal bar above the table. The controls must
   override the global form-field rules (display:block; width:100%) or each
   filter lands on its own line. */
.tx-filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin: 4px 0 10px; padding: 10px 12px;
  background: var(--blue-50); border: 1px solid var(--line); border-radius: 12px;
}
.tx-filters select, .tx-filters input {
  display: inline-block; width: auto; margin-top: 0;
  font: inherit; font-size: .82rem; font-weight: 500; color: var(--ink);
  padding: 7px 12px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff;
}
.tx-filters select { cursor: pointer; }
.tx-filters select:hover { border-color: var(--blue-300); }
.tx-filters input { flex: 1; min-width: 170px; border-radius: 999px; }
.tx-count { margin-left: auto; margin-top: 0; white-space: nowrap; font-weight: 600; }
.tx-count a { color: var(--blue-600); font-weight: 700; }

/* ---------- Master / detail views ---------- */
.view { display: grid; gap: 22px; }
.view[hidden] { display: none; }   /* explicit display above beats the UA [hidden] rule */
/* Detail pages get a wider canvas so the two-column layout has room. */
body.wide-mode .container { max-width: 1440px; }

/* List: whole row is a button that opens the bot's page */
.bot-item { cursor: pointer; }
.bot-item__err { color: var(--red); font-weight: 700; }

/* Per-bot portfolio & P&L (color-coded) */
.pnl-pos { color: var(--green); font-weight: 700; }
.pnl-neg { color: var(--red); font-weight: 700; }
.pnl-zero { color: var(--muted); }
.bot-item__pf { margin-top: 8px; font-size: .9rem; }
.spark { display: block; max-width: 100%; margin-top: 6px; }
.spark-wrap { margin-top: 10px; }
.spark-wrap .fine { margin-top: 2px; }

/* Detail page: the overview card plus one card per section (Transactions,
   Run history, Activity), spaced like the home-page sections. */
#botDetail { display: grid; gap: 22px; }
#botDetail > * { min-width: 0; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sec-head .eyebrow { margin-bottom: 6px; }
.sec-head h2 { margin: 0; }
.detail-topbar { display: flex; justify-content: flex-start; margin-bottom: 6px; }
.detail-back { margin-bottom: 2px; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.detail-title h2 { margin-bottom: 6px; }
.detail-title > div { display: flex; gap: 6px; flex-wrap: wrap; }
.detail-prompt { font-size: 1rem; color: var(--ink); display: block; -webkit-line-clamp: unset; overflow: visible; white-space: pre-wrap; }
.detail-prompt.clamped { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.prompt-more {
  background: none; border: none; padding: 0; cursor: pointer;
  font: inherit; font-size: .88rem; font-weight: 600; color: var(--blue-600);
}
.detail-h {
  font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 22px 0 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.detail-h:first-child { margin-top: 0; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 28px; margin-top: 8px; }
.detail-col { min-width: 0; }
.kv-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.kv-table td { padding: 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.kv-table tr:last-child td { border-bottom: none; }
.kv-table td:first-child { color: var(--muted); width: 42%; }
.kv-table td:last-child { font-weight: 600; }
.summary-pre {
  white-space: pre-wrap; word-wrap: break-word; font-size: .84rem;
  background: var(--blue-50); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin-top: 4px; max-height: 360px; overflow: auto;
}
/* On the detail page let the transactions table breathe. */
.detail-card .tx-scroll { max-height: 420px; }

/* ---------- Run history (per-run summaries, click-to-read) ---------- */
.run-reload { margin-bottom: 8px; }
.run-list { display: grid; gap: 6px; }
.run-item { border: 1px solid var(--line); border-radius: 10px; background: var(--blue-50); }
.run-sum {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; cursor: pointer; list-style: none; font-size: .84rem;
}
.run-sum::-webkit-details-marker { display: none; }
.run-sum::before { content: '▸'; color: var(--muted); transition: transform .15s; }
.run-item[open] .run-sum::before { transform: rotate(90deg); }
.run-at { font-weight: 600; font-variant-numeric: tabular-nums; margin-right: auto; }
.run-meta { text-transform: none; letter-spacing: 0; }
.run-item .summary-pre { margin: 0 12px 12px; }

/* Full AI session logs on the bot detail page: each run expands into the
   complete conversation replay (timeline styles come from admin.css). */
.sess-detail > .run-sum { flex-wrap: wrap; }
.sess-detail .run-nums { color: var(--muted); font-variant-numeric: tabular-nums; }
.sess-body { padding: 6px 14px 14px; }
.sess-body > .info-grid { margin: 10px 0 12px; }
.sess-body > .prompt-card {
  margin: 8px 0; padding: 10px 14px; background: #fff;
  border: 1px solid var(--line); border-radius: 10px;
}
.sess-body > .timeline { margin-top: 16px; }

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}

/* ---------- Landing (public home page) ---------- */
.nav__link { font-weight: 600; font-size: .92rem; color: var(--muted); }
.nav__link:hover { color: var(--ink); }

.hero { padding: 72px 0 30px; }
.hero__grid {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: 48px; align-items: center;
}
.hero__copy h1 { font-size: clamp(2.3rem, 5vw, 3.4rem); font-weight: 800; margin: 6px 0 4px; }
.lead--lg { font-size: 1.08rem; max-width: 46ch; }
.hero__actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; }

/* Illustrative bot card in the hero */
.hero__visual { min-width: 0; }
.demo-bot { box-shadow: var(--shadow); transform: rotate(.6deg); }
.demo-bot:hover { transform: rotate(0) translateY(-3px); }
.demo-bot__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.demo-bot__head .pnl-pos { font-size: 1.05rem; }
.demo-bot__prompt { color: var(--muted); font-size: .92rem; margin: 10px 0 14px; }
.demo-bot__budget-bar {
  height: 8px; border-radius: 999px; background: var(--blue-100); overflow: hidden;
}
.demo-bot__budget-bar span { display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--blue-500), var(--blue-300)); }
.demo-bot__budget .fine { margin-top: 6px; }
.demo-bot__log {
  margin-top: 14px; padding: 12px 14px; display: grid; gap: 6px;
  font-size: .8rem; color: #33445c;
  background: var(--blue-50); border: 1.5px dashed var(--blue-200); border-radius: 12px;
}
.demo-bot__log b { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; margin-right: 4px; }

.section { padding: 64px 0; }
.section--tint { background: linear-gradient(180deg, transparent, var(--blue-50) 18%, var(--blue-50) 82%, transparent); }
.section__head { max-width: 640px; margin-bottom: 34px; }
.section__title { font-size: clamp(1.5rem, 3vw, 2rem); }
.section__head .lead { margin-bottom: 0; }

.feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.feature h3 { font-size: 1.02rem; margin: 12px 0 6px; }
.feature p { color: var(--muted); font-size: .92rem; }
.feature__icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 14px;
  color: var(--blue-600);
  background: linear-gradient(135deg, var(--blue-100), #fff);
  border: 1px solid var(--line);
  transition: transform .2s ease, box-shadow .2s ease, color .2s ease;
}
.feature:hover .feature__icon { transform: translateY(-3px); box-shadow: var(--shadow-sm); color: var(--blue-500); }
.feature__icon svg { width: 21px; height: 21px; }

.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.step { position: relative; }
.step h3 { font-size: 1rem; margin: 12px 0 6px; }
.step p { color: var(--muted); font-size: .9rem; }
.step__num {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 999px; font-weight: 800; font-size: .95rem;
  color: #fff; background: var(--blue-500); box-shadow: 0 6px 16px rgba(47,128,255,.3);
}
/* Dashed connector between numbered steps — the steps are a real sequence. */
@media (min-width: 901px) {
  .step:not(:last-child)::after {
    content: ""; position: absolute; top: 16px; left: 46px; right: -18px;
    border-top: 2px dashed var(--blue-200);
  }
}

.modes { display: flex; gap: 24px; align-items: stretch; margin-top: 30px; }
.modes__item { flex: 1; min-width: 0; }
.modes__item p { color: var(--muted); font-size: .92rem; margin-top: 8px; }
.modes__divider { width: 1px; background: var(--line); }

.safety-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 40px; }
.safety { padding: 16px 0; border-top: 1px solid var(--line); }
.safety h3 { font-size: 1rem; margin-bottom: 6px; }
.safety p { color: var(--muted); font-size: .92rem; }

.section--cta { padding-top: 10px; }
/* The final CTA is the one bold, saturated moment on an otherwise airy page. */
.cta-card {
  text-align: center; padding: 54px 34px; border: none; overflow: hidden; position: relative;
  background: linear-gradient(135deg, var(--blue-600), var(--blue-500) 55%, #4d93ff);
  color: #fff; box-shadow: 0 26px 64px rgba(47,128,255,.36);
}
.cta-card::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(620px 220px at 50% -60%, rgba(255,255,255,.28), transparent 70%);
}
.cta-card > * { position: relative; }
.cta-card h2 { font-size: clamp(1.5rem, 3vw, 2rem); color: #fff; }
.cta-card .lead { max-width: 46ch; margin: 10px auto 6px; color: rgba(255,255,255,.9); }
.cta-card .fine { color: rgba(255,255,255,.78); }
.cta-card .btn { margin-top: 4px; }
.cta-card .btn--primary { background: #fff; color: var(--blue-600); box-shadow: 0 12px 26px rgba(6,22,55,.22); }
.cta-card .btn--primary:hover { background: #fff; color: #1657c9; transform: translateY(-2px); box-shadow: 0 16px 34px rgba(6,22,55,.3); }

.footer { border-top: 1px solid var(--line); padding: 30px 0 46px; background: #fff; }
.footer__inner { display: grid; gap: 14px; }
.footer__legal { max-width: 76ch; }

@media (max-width: 900px) {
  .hero { padding-top: 48px; }
  .hero__grid { grid-template-columns: 1fr; gap: 30px; }
  .feature-grid { grid-template-columns: 1fr 1fr; }
  .steps { grid-template-columns: 1fr 1fr; }
  .modes { flex-direction: column; gap: 16px; }
  .modes__divider { width: auto; height: 1px; }
  .safety-grid { grid-template-columns: 1fr; }
  .nav__link { display: none; }
}
@media (max-width: 640px) {
  .feature-grid, .steps { grid-template-columns: 1fr; }
}

/* ---------- Auth ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-wrap { display: flex; flex-direction: column; align-items: center; gap: 26px; padding: 40px 20px; }
.auth-card { width: min(430px, 92vw); text-align: center; padding: 34px 32px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.85rem; font-weight: 800; letter-spacing: -0.02em; text-wrap: balance; }
.auth-features {
  list-style: none; text-align: left;
  margin: 6px 0 20px; padding: 16px; gap: 14px;
  display: flex; flex-direction: column;
  background: var(--blue-50); border: 1px solid var(--line); border-radius: 16px;
}
.auth-features li { display: flex; align-items: flex-start; gap: 12px; }
.auth-features__icon {
  flex: none; width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--blue-600);
  background: linear-gradient(135deg, var(--blue-100), #fff);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.auth-features__icon svg { width: 17px; height: 17px; }
.auth-features li b { display: block; font-size: .92rem; }
.auth-features li span:not(.auth-features__icon) { display: block; color: var(--muted); font-size: .85rem; margin-top: 1px; }
.auth-form { text-align: left; margin-top: 6px; }
.auth-form label, .modal label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0; color: var(--ink); }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font-family: inherit; font-size: .95rem; color: var(--ink);
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 14px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue-300); box-shadow: 0 0 0 4px var(--blue-100); }
/* Strategy prompt: compact by default, grows into a notepad while editing */
#f_prompt {
  height: 110px; resize: vertical; line-height: 1.55;
  transition: height .25s ease, border-color .15s ease, box-shadow .15s ease;
}
#f_prompt:focus { height: min(55vh, 520px); }
.gsi-wrap { display: flex; justify-content: center; margin: 14px 0 4px; }
.divider {
  display: flex; align-items: center; gap: 12px; color: var(--muted);
  font-size: .8rem; margin: 16px 0 4px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(14,27,46,.35); backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; overflow-y: auto;
}
/* display:flex above would otherwise override the hidden attribute */
.modal[hidden] { display: none; }
.modal__card { width: min(680px, 96vw); box-shadow: var(--shadow); }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.lbl { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 6px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.check {
  display: flex; align-items: center; gap: 10px;
  font-weight: 500 !important; font-size: .9rem;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  cursor: pointer; margin: 0 !important;
  transition: border-color .15s ease;
}
.check:hover { border-color: var(--blue-300); }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--blue-500); }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Connect (connector) modal ---------- */
.connect-steps { margin: 8px 0 14px 18px; color: var(--muted); font-size: .92rem; }
.connect-steps li { margin: 4px 0; }
.cmd-row { display: flex; gap: 10px; align-items: stretch; margin: 6px 0 4px; }
.cmd {
  flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem; background: var(--blue-50); border: 1.5px dashed var(--blue-200);
  border-radius: 12px; padding: 12px 14px; overflow-x: auto; white-space: nowrap;
  display: flex; align-items: center;
}

/* ============================================================
   Settings page — structured sections, status chips, toggles
   ============================================================ */
.settings-wrap { width: 100%; max-width: 780px; margin: 0 auto; padding: 0 24px; }
.settings-head { margin: 30px 0 22px; }
.settings-head h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; margin: 2px 0 0; }
.settings-head .lead { margin: 6px 0 0; }

/* Each settings block is an app-card; give consecutive ones breathing room. */
.set-card { margin-top: 18px; }
.set-card > .fine:first-of-type { margin-top: 4px; }
.set-card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 4px;
}
.set-card__head h2 { margin: 2px 0 0; }
.set-card__head .eyebrow { margin-bottom: 8px; }

/* Connection status chip: a colored dot + word, tinted by state. */
.conn-status {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  font-size: .82rem; font-weight: 700; white-space: nowrap;
  padding: 7px 14px; border-radius: 999px;
  background: var(--blue-50); border: 1px solid var(--line); color: var(--muted);
}
.conn-status__dot { width: 8px; height: 8px; border-radius: 999px; background: var(--muted); flex: none; }
.conn-status.is-ok    { color: var(--green); background: var(--green-bg); border-color: transparent; }
.conn-status.is-ok    .conn-status__dot { background: var(--green); }
.conn-status.is-bad   { color: var(--red);   background: var(--red-bg);   border-color: transparent; }
.conn-status.is-bad   .conn-status__dot { background: var(--red); }
.conn-status.is-muted .conn-status__dot { background: var(--blue-200); }

/* Row of action buttons under a section body. */
.set-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.set-actions:empty { display: none; }

/* Label/description on the left, control on the right; hairline between rows. */
.set-list { margin-top: 10px; }
.set-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 0; border-top: 1px solid var(--line); flex-wrap: wrap;
}
.set-row:first-child { border-top: none; }
.set-row__info { min-width: 200px; flex: 1 1 260px; }
.set-row__info strong { font-weight: 700; font-size: .95rem; }
.set-row__info .fine { margin-top: 3px; }
.set-row__control { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Inline, pill-shaped select (overrides the block/full-width form default). */
.set-select {
  display: inline-block; width: auto; margin-top: 0; cursor: pointer;
  font-weight: 600; font-size: .9rem; padding: 9px 16px; border-radius: 999px;
}
.set-select:hover { border-color: var(--blue-300); }
/* Key input: fixed, comfortable width, aligned with the buttons beside it. */
.set-input { width: auto; min-width: 260px; margin-top: 0; }
@media (max-width: 560px) { .set-input { min-width: 0; flex: 1 1 100%; } }

/* Toggle switch — replaces the raw checkbox on preferences. */
.switch { position: relative; display: inline-flex; align-items: center; flex: none; }
.switch input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 0; opacity: 0; cursor: pointer;
}
.switch__track {
  width: 46px; height: 27px; border-radius: 999px;
  background: var(--blue-100); border: 1px solid var(--line);
  transition: background .18s ease, border-color .18s ease;
}
.switch__track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 999px; background: #fff;
  box-shadow: 0 2px 6px rgba(20,70,150,.28); transition: transform .18s ease;
}
.switch input:checked + .switch__track { background: var(--blue-500); border-color: var(--blue-500); }
.switch input:checked + .switch__track::after { transform: translateX(19px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 4px var(--blue-100); }
.switch__state { min-width: 26px; font-weight: 600; }

/* Security facts list. */
.sec-list { margin: 10px 0 0; padding-left: 20px; line-height: 1.75; }
.sec-list li { margin: 4px 0; }

/* Collapsible "how to get your API key" help under the Zerodha card. */
.zd-help { margin: 12px 0 4px; }
.zd-help > summary { cursor: pointer; font-weight: 600; color: var(--blue-600, #2f6fd6); }
.zd-help ol { margin: 10px 0 6px; padding-left: 20px; line-height: 1.7; }
.zd-help li { margin: 5px 0; }
.zd-help a { color: var(--blue-600, #2f6fd6); }
.zd-help code {
  display: inline-block; margin-top: 4px; padding: 3px 8px;
  background: var(--blue-50, #eef4ff); border: 1px solid var(--line);
  border-radius: 6px; font-size: .82rem; word-break: break-all;
}

/* ---------- Notes for the bot (temporary owner tips with expiry) ---------- */
.notes-head { margin-top: 18px; }
.notes-head .detail-h { margin: 0; }
.note-item {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; margin: 8px 0;
}
.note-text { white-space: pre-wrap; word-break: break-word; font-size: .92rem; }
.note-foot {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-top: 8px; flex-wrap: wrap;
}
.note-actions a { margin-left: 12px; font-size: .85rem; font-weight: 600; }
.note-actions .note-del { color: var(--red); }
.note--expired { opacity: .65; background: var(--blue-50); }
.note--expired .note-text { text-decoration: line-through; text-decoration-color: var(--muted); }

/* ============ Loading / processing feedback ============ */
/* Deployments are intentionally small, so requests can be slow. These give
   instant "working…" feedback on every user action. */

/* Thin bar pinned to the top of the page while a user request is in flight.
   Driven only by user-initiated calls — background polling never shows it. */
.route-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 2000;
  overflow: hidden; opacity: 0; transition: opacity .25s ease; pointer-events: none;
}
.route-progress.is-active { opacity: 1; }
.route-progress::before {
  content: ""; position: absolute; top: 0; left: 0; height: 100%; width: 40%;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg, var(--blue-300), var(--blue-500));
  animation: route-slide 1.1s ease-in-out infinite;
}
@keyframes route-slide {
  0%   { left: -40%; width: 40%; }
  50%  { left: 35%;  width: 45%; }
  100% { left: 100%; width: 35%; }
}

/* Shimmering placeholder boxes for panels that are still fetching content. */
.skeleton {
  display: block; border-radius: 10px;
  background: linear-gradient(100deg, var(--blue-50) 30%, var(--blue-100) 50%, var(--blue-50) 70%);
  background-size: 200% 100%; animation: skeleton-shimmer 1.3s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-stack { padding: 4px 0; }
.skeleton--line { height: 12px; margin: 10px 0; }
.skeleton--line.is-short { width: 55%; }
.skeleton--row  { height: 46px; margin: 8px 0; border-radius: 12px; }

/* Inline spinner shown inside a button while its action runs. */
.btn-spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px;
  vertical-align: -2px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: btn-spin .6s linear infinite; opacity: .75;
}
.btn.is-busy { cursor: progress; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
