/* ── Design tokens ──────────────────────────────────────────────── */
:root {
  color-scheme: light;

  /* Surfaces — soft mint-white canvas with white cards */
  --canvas:       #f4f7f5;
  --surface:      #ffffff;
  --surface-2:    #f3f6f4;
  --surface-3:    #e6ece8;
  --border:       rgba(15, 42, 32, .09);
  --border-hover: rgba(15, 42, 32, .18);

  /* Text */
  --text:         #13201a;
  --text-soft:    #4d5c55;
  --text-muted:   #8a978f;

  /* Accent — wealth green */
  --accent:       #1f7a4f;
  --accent-2:     #2fa36b;
  --accent-3:     #1b6b45;
  --accent-glow:  rgba(31, 122, 79, .22);
  --accent-wash:  rgba(31, 122, 79, .09);
  --accent-wash2: rgba(31, 122, 79, .04);
  --mint:         #5fd99a;

  /* Semantic */
  --green:        #23945d;
  --green-soft:   #e3f5ea;
  --amber:        #d98a1c;
  --amber-soft:   #fdf1de;
  --blue:         #3b74d6;
  --blue-soft:    #e6eefc;
  --violet:       #7a5ad8;
  --violet-soft:  #efeafc;
  --red:          #df4b3c;
  --red-soft:     #fde8e5;
  --error:        #d0402f;

  /* Sidebar — deep forest green in both themes */
  --side-bg:      #0f2a22;
  --side-bg-2:    #163a2f;
  --side-text:    #e4efe9;
  --side-soft:    #9db5aa;
  --side-border:  rgba(255, 255, 255, .08);

  --shadow-sm:    0 1px 2px rgba(16, 40, 30, .06), 0 1px 3px rgba(16, 40, 30, .05);
  --shadow-md:    0 6px 20px rgba(16, 40, 30, .08), 0 2px 6px rgba(16, 40, 30, .05);
  --shadow-lg:    0 20px 50px rgba(16, 40, 30, .14);

  --radius-sm:    8px;
  --radius-md:    12px;
  --radius-lg:    16px;
  --radius-xl:    22px;

  --sans:         'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --serif:        'Fraunces', Georgia, 'Times New Roman', serif;
  --mono:         'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --sidebar-w:    264px;
  --rail-w:       340px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas:       #0d1613;
  --surface:      #14201b;
  --surface-2:    #1a2923;
  --surface-3:    #24362e;
  --border:       rgba(255, 255, 255, .08);
  --border-hover: rgba(255, 255, 255, .16);
  --text:         #e6efea;
  --text-soft:    #a8b8b0;
  --text-muted:   #6c7d75;
  --accent:       #3fb67b;
  --accent-2:     #5fd99a;
  --accent-3:     #6fdca4;
  --accent-glow:  rgba(95, 217, 154, .22);
  --accent-wash:  rgba(95, 217, 154, .1);
  --accent-wash2: rgba(95, 217, 154, .05);
  --green:        #4cc985;
  --green-soft:   rgba(76, 201, 133, .14);
  --amber:        #f0aa45;
  --amber-soft:   rgba(240, 170, 69, .14);
  --blue:         #77a5f2;
  --blue-soft:    rgba(119, 165, 242, .14);
  --violet:       #a78bf5;
  --violet-soft:  rgba(167, 139, 245, .14);
  --red:          #f2786b;
  --red-soft:     rgba(242, 120, 107, .14);
  --error:        #f2786b;
  --side-bg:      #0a1a15;
  --side-bg-2:    #12291f;
  --shadow-sm:    0 1px 3px rgba(0, 0, 0, .35);
  --shadow-md:    0 6px 20px rgba(0, 0, 0, .35);
  --shadow-lg:    0 20px 50px rgba(0, 0, 0, .5);
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; }
body {
  overflow: hidden;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, textarea, select, input { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; cursor: pointer; }
[hidden] { display: none !important; }
::selection { background: var(--accent-glow); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { border-radius: 99px; background: var(--surface-3); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Shared stroke-icon treatment */
.nav-item svg, .account-gear svg, .icon-button svg, .search-box svg, .feature-icon svg,
.insight-icon svg, .tool-tile svg, .account-avatar svg, .new-chat-button svg, #send-btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Tone helpers for icon tiles */
.tone-green  { --tone: var(--green);  --tone-soft: var(--green-soft); }
.tone-blue   { --tone: var(--blue);   --tone-soft: var(--blue-soft); }
.tone-amber  { --tone: var(--amber);  --tone-soft: var(--amber-soft); }
.tone-violet { --tone: var(--violet); --tone-soft: var(--violet-soft); }
.tone-red    { --tone: var(--red);    --tone-soft: var(--red-soft); }

/* ── App shell ──────────────────────────────────────────────────── */
#app {
  display: grid;
  height: 100%;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--rail-w);
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
#sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px 16px;
  background: linear-gradient(180deg, var(--side-bg) 0%, var(--side-bg-2) 100%);
  color: var(--side-text);
  overflow-y: auto;
}
#sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); }
/* Only the recent chats shrink and scroll, so the profile button stays in view;
   the sidebar itself scrolls only when even the menu does not fit. */
#sidebar > * { flex-shrink: 0; }
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px;
  color: inherit;
  text-decoration: none;
}
.logo-mark {
  display: grid;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, #2fa36b 0%, #1b6b45 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(47, 163, 107, .35);
}
.logo-mark svg { width: 24px; height: 24px; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.25; }
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.logo-sub { color: var(--side-soft); font-size: 12px; }

.new-chat-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #6ee0a5 0%, #3fbf80 100%);
  color: #0c2a1e;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(63, 191, 128, .28);
  transition: transform .15s, box-shadow .15s;
}
.new-chat-button:hover { transform: translateY(-1px); box-shadow: 0 12px 26px rgba(63, 191, 128, .36); }
.new-chat-button:active { transform: translateY(0); }
.new-chat-button svg { width: 16px; height: 16px; stroke-width: 2.2; }

.main-nav { display: grid; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  color: var(--side-text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--side-soft); transition: color .15s; }
.nav-item:hover { background: rgba(255, 255, 255, .05); }
.nav-item:hover svg { color: var(--side-text); }
.nav-item[aria-current="page"] { background: rgba(255, 255, 255, .1); color: #fff; font-weight: 700; }
.nav-item[aria-current="page"] svg { color: var(--mint); }

.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 6px 0;
  border-top: 1px solid var(--side-border);
  color: var(--side-text);
  font-size: 13px;
  font-weight: 600;
}
.see-all { color: var(--side-soft); font-size: 12px; font-weight: 500; text-decoration: none; }
.see-all:hover, .see-all[aria-current="page"] { color: var(--mint); }
#chat-list { flex: 0 1 auto; min-height: 56px; margin: -10px -6px 0; padding: 0 6px; overflow-y: auto; }
#chat-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); }
.chat-row { position: relative; display: flex; align-items: center; margin: 2px 0; }
.chat-select {
  display: grid;
  width: 100%;
  min-width: 0;
  grid-template-columns: 20px minmax(0, 1fr);
  column-gap: 10px;
  align-items: start;
  padding: 9px 34px 9px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--side-text);
  text-align: left;
  transition: background .15s;
}
.chat-select::before {
  content: '';
  grid-row: span 2;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border: 1.6px solid var(--side-soft);
  border-radius: 6px 6px 6px 2px;
  opacity: .8;
}
.chat-select:hover { background: rgba(255, 255, 255, .05); }
.chat-select.active { background: rgba(255, 255, 255, .1); }
.chat-select.active::before { border-color: var(--mint); }
.chat-title { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.chat-meta { color: var(--side-soft); font-size: 11px; }
.chat-delete {
  position: absolute;
  right: 4px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--side-soft);
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}
.chat-row:hover .chat-delete, .chat-delete:focus-visible { opacity: 1; }
.chat-delete:hover { background: rgba(242, 120, 107, .18); color: #ffb3aa; }
.chat-empty { padding: 12px 8px; color: var(--side-soft); font-size: 12px; }
.tools-error { padding: 12px 8px; color: #ffb3aa; font-size: 12px; line-height: 1.6; }

.sidebar-account {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 14px 4px 0;
  border-top: 1px solid var(--side-border);
}
.account-avatar {
  display: grid;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: var(--side-text);
  font-size: 16px;
  font-weight: 700;
}
.account-avatar.is-connected { background: var(--mint); color: #0c2a1e; }
.account-copy { display: flex; min-width: 0; flex: 1; flex-direction: column; line-height: 1.3; }
.account-copy strong { font-size: 14px; font-weight: 600; }
.account-copy small { overflow: hidden; color: var(--side-soft); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.account-gear { display: grid; width: 34px; height: 34px; flex-shrink: 0; place-items: center; border-radius: 10px; color: var(--side-soft); transition: color .15s, background .15s; }
.account-gear svg { width: 20px; height: 20px; }
.account-trigger:hover .account-gear { background: rgba(255, 255, 255, .08); color: var(--side-text); }
#sidebar-scrim { display: none; }

/* ── Main column ─────────────────────────────────────────────────── */
#chat-area {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 28px 8px;
  flex-shrink: 0;
}
.search-box {
  display: flex;
  width: min(560px, 100%);
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.search-box svg { width: 18px; height: 18px; flex-shrink: 0; }
.search-box input {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}
.search-box input::placeholder { color: var(--text-muted); }
.topbar-spacer { flex: 1; }

#status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.status-dot { width: 7px; height: 7px; flex-shrink: 0; border-radius: 50%; background: var(--text-muted); transition: background .3s; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.status-dot.loading { background: var(--amber); animation: pulse-dot 1.2s ease infinite; }
.status-dot.error { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.8); }
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-button:hover { border-color: var(--border); background: var(--surface); color: var(--text); }
.icon-button svg { width: 20px; height: 20px; }
.menu-toggle { display: none; }

#chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 28px 12px;
}

/* ── Hero / empty state ─────────────────────────────────────────── */
#empty-state { display: flex; flex-direction: column; gap: 18px; padding-bottom: 12px; }
.hero {
  position: relative;
  display: grid;
  min-height: 200px;
  grid-template-columns: minmax(0, 1fr) 260px;
  align-items: center;
  overflow: hidden;
  padding: 28px 8px 24px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(ellipse 60% 90% at 100% 0%, var(--green-soft) 0%, transparent 70%),
    linear-gradient(120deg, var(--surface) 40%, var(--surface-2) 100%);
}
.hero-eyebrow {
  display: inline-flex;
  margin-bottom: 10px;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--accent-wash);
  color: var(--accent-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
}
.hero-title {
  color: var(--text);
  font-family: var(--serif);
  font-size: clamp(24px, 2.6vw, 34px);
  font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1.22;
}
.hero-sub { max-width: 520px; margin-top: 10px; color: var(--text-soft); font-size: 14px; }
.hero-art { position: relative; align-self: end; height: 170px; margin: -24px -8px -24px 0; }
.hero-art svg { width: 100%; height: 100%; }
.hill-back { fill: var(--green-soft); }
.hill-front { fill: var(--accent-wash); }
.coins ellipse, .coins rect { fill: #e9b949; stroke: #b9871f; stroke-width: 1.5; }
.stem { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.leaf { fill: var(--accent-2); }
.leaf-soft { fill: var(--green); opacity: .8; }
.hero-tag {
  position: absolute;
  z-index: 1;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.tag-invest  { top: 22px; left: 18px; }
.tag-grow    { top: 76px; left: -6px; }
.tag-achieve { top: 0; right: 24px; }

.feature-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.feature-card {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 14px;
  align-items: center;
  gap: 12px;
  padding: 16px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--tone-soft) 0%, var(--surface) 75%);
  color: var(--text);
  text-align: left;
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.feature-card:hover { transform: translateY(-2px); border-color: var(--tone); box-shadow: var(--shadow-md); }
.feature-card:disabled { cursor: wait; opacity: .6; transform: none; }
.feature-icon {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  background: var(--tone-soft);
  color: var(--tone);
}
.feature-icon svg { width: 20px; height: 20px; }
.feature-copy { display: flex; min-width: 0; flex-direction: column; gap: 2px; line-height: 1.35; }
.feature-copy strong { font-size: 13px; font-weight: 700; }
.feature-copy small { color: var(--text-soft); font-size: 12px; }
.feature-arrow { color: var(--tone); font-size: 14px; }

/* ── Messages ───────────────────────────────────────────────────── */
#messages { display: none; }
#messages.has-messages { display: block; padding-top: 6px; }

.message {
  display: grid;
  width: min(880px, 100%);
  grid-template-columns: 40px minmax(0, 1fr);
  column-gap: 14px;
  margin: 0 auto 22px;
  animation: rise-in .22s ease-out;
}
@keyframes rise-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.message-header { display: contents; }
.message-avatar {
  display: grid;
  width: 40px;
  height: 40px;
  grid-row: span 3;
  place-items: center;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
}
.message-avatar.user { background: var(--surface-3); color: var(--text-soft); }
.message-avatar.assistant { background: var(--accent-wash); color: var(--accent-3); box-shadow: inset 0 0 0 1px var(--accent-glow); }
.message-avatar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.message-meta { display: flex; align-items: baseline; gap: 10px; margin: 2px 0 6px; }
.message-role { color: var(--text); font-size: 13px; font-weight: 600; }
.message-time { color: var(--text-muted); font-size: 11px; }

.message-body {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.75;
  overflow-wrap: anywhere;
}
.message.assistant .message-body {
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 4px 18px 18px 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.message.user .message-body {
  width: fit-content;
  max-width: min(680px, 100%);
  padding: 12px 18px;
  border-radius: 4px 18px 18px 18px;
  background: var(--surface-3);
}
.message-body p { margin: 0; }
.message-body strong { color: var(--text); font-weight: 700; }
.message-body a { color: var(--accent-3); text-decoration: underline; text-underline-offset: 2px; }
.message-body ul, .message-body ol { margin: 8px 0 8px 20px; }
.message-body li + li { margin-top: 4px; }
.message-body hr { margin: 12px 0; border: 0; border-top: 1px solid var(--border); }
.message-body blockquote {
  margin: 12px 0 0;
  padding: 8px 12px;
  border-left: 3px solid var(--amber);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--amber-soft);
  color: var(--text);
}
.message-body code {
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--accent-3);
  font-family: var(--mono);
  font-size: 12px;
}
.message-body h1, .message-body h2, .message-body h3,
.message-body h4, .message-body h5, .message-body h6 {
  margin: 18px 0 8px;
  color: var(--text);
  font-weight: 700;
  line-height: 1.3;
}
.message-body > h1:first-child, .message-body > h2:first-child, .message-body > h3:first-child { margin-top: 0; }
.message-body h1 { font-size: 20px; }
.message-body h2 { font-size: 17px; }
.message-body h3 { font-size: 15px; }
.message-body h4, .message-body h5, .message-body h6 { font-size: 14px; }
.message .chat-trace { grid-column: 2; }

/* ── Input area ─────────────────────────────────────────────────── */
#input-area {
  width: min(936px, calc(100% - 56px));
  margin: 0 auto;
  padding: 8px 0 18px;
  flex-shrink: 0;
}
.follow-ups { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, color .15s, background .15s;
}
.chip:hover { border-color: var(--accent); background: var(--accent-wash2); color: var(--accent-3); }
.chip:disabled { cursor: wait; opacity: .5; }
#input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 10px 10px 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  transition: border-color .15s, box-shadow .15s;
}
#input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash), var(--shadow-md); }
#user-input {
  flex: 1;
  min-height: 44px;
  max-height: 180px;
  padding: 11px 0;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}
#user-input::placeholder { color: var(--text-muted); }
.provider-picker {
  max-width: 190px;
  height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
.provider-picker:hover:not(:disabled) { border-color: var(--border-hover); }
#send-btn {
  display: grid;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px var(--accent-glow);
  transition: transform .15s, background .15s, opacity .15s;
}
:root[data-theme="dark"] #send-btn { color: #0c2a1e; }
#send-btn:hover:not(:disabled) { transform: translateY(-1px); background: var(--accent-3); }
#send-btn:disabled { cursor: not-allowed; opacity: .4; box-shadow: none; }
#send-btn svg { width: 20px; height: 20px; stroke-width: 2.2; }
#input-hint { padding-top: 8px; color: var(--text-muted); font-size: 11px; text-align: center; }
kbd {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 10px;
}

/* ── Right rail ─────────────────────────────────────────────────── */
#right-rail {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding: 16px 20px 20px 4px;
}
.rail-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.rail-head h2 { color: var(--text); font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.pill {
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.is-connected { background: var(--green-soft); color: var(--green); }
.spark-line { fill: none; stroke: var(--accent-2); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.rail-copy { margin: 12px 0 14px; color: var(--text-soft); font-size: 13px; line-height: 1.55; }
.rail-button {
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s;
}
:root[data-theme="dark"] .rail-button { color: #0c2a1e; }
.rail-button:hover { background: var(--accent-3); }
.rail-button:disabled { cursor: wait; opacity: .6; }

.insight-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 11px;
  background: var(--tone-soft);
  color: var(--tone);
}
.insight-icon svg { width: 19px; height: 19px; }

.tool-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tool-tile {
  display: flex;
  min-height: 84px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 8px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--tone-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  transition: border-color .15s, transform .15s;
}
.tool-tile svg { width: 24px; height: 24px; color: var(--tone); }
.tool-tile:hover { transform: translateY(-1px); border-color: var(--tone); }
.tool-tile:disabled { cursor: wait; opacity: .6; transform: none; }

/* Status pills and markers, shared by the answer trace, investigation evidence and Activity. */
.status-pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-soft); font-size: 10.5px; font-weight: 600; line-height: 1.6; white-space: nowrap; }
.status-pill.is-ok { background: var(--accent-wash); color: var(--accent-3); }
.status-pill.is-warning { background: var(--amber-soft); color: var(--amber); }
.status-pill.is-error { background: var(--red-soft); color: var(--red); }
.status-pill.is-running { background: var(--blue-soft); color: var(--blue); }
.status-pill.is-pending, .status-pill.is-muted { background: var(--surface-2); color: var(--text-muted); }
.timeline-marker { display: grid; width: 20px; height: 20px; flex: 0 0 20px; place-items: center; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--text-muted); font-size: 10px; font-weight: 700; }
.is-ok > .timeline-marker { border-color: transparent; background: var(--accent-wash); color: var(--accent-3); }
.is-warning > .timeline-marker { border-color: transparent; background: var(--amber-soft); color: var(--amber); }
.is-error > .timeline-marker { border-color: transparent; background: var(--red-soft); color: var(--red); }
.is-running > .timeline-marker { border-color: var(--blue); color: var(--blue); animation: pulse-dot 1.6s ease-in-out infinite; }
.is-pending > .timeline-marker { border-style: dashed; }

/* The answer's trace: a collapsed timeline of how it was made. */
.chat-trace { margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text-soft); font-size: 11.5px; }
.chat-trace > summary { padding: 9px 12px; cursor: pointer; color: var(--text-soft); font-weight: 600; }
.chat-trace[open] > summary { border-bottom: 1px solid var(--border); color: var(--text); }
.chat-trace .timeline { padding: 4px 12px; }
.timeline { display: grid; margin: 0; padding: 0; list-style: none; }
.timeline-step { position: relative; display: flex; gap: 10px; padding: 10px 0; }
.timeline-step:not(:last-child)::before { position: absolute; top: 32px; bottom: -2px; left: 10px; width: 1px; background: var(--border); content: ""; }
.timeline-body { display: grid; flex: 1; min-width: 0; gap: 3px; }
.timeline-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; color: var(--text); }
.timeline-head strong { overflow-wrap: anywhere; font-size: 12px; }
.timeline-index { color: var(--text-muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.timeline-time { margin-left: auto; color: var(--text-muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.timeline-meta, .timeline-summary, .timeline-evidence, .timeline-note { margin: 0; color: var(--text-soft); font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.timeline-meta code, .timeline-evidence code { font: 10px var(--mono); }
.timeline-summary { color: var(--text); }
.timeline-error { margin: 2px 0 0; padding: 6px 9px; border-radius: var(--radius-sm); background: var(--red-soft); color: var(--text); font-size: 11px; line-height: 1.5; }
.timeline-note { padding: 4px 0 8px 30px; color: var(--text-muted); font-style: italic; }
.timeline-details { margin-top: 4px; }
.timeline-details > summary { width: fit-content; padding: 2px 0; color: var(--text-soft); cursor: pointer; font-size: 10.5px; font-weight: 600; }
.timeline-links { display: flex; gap: 12px; margin-top: 2px; }
.timeline-link { color: var(--accent); font-size: 11px; font-weight: 600; text-decoration: none; }
.timeline-link:hover { text-decoration: underline; }
.trace-detail-label { margin: 8px 0 4px; color: var(--text-muted); font-size: 9px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; }
.trace-code { max-height: 180px; margin: 0; padding: 8px 10px; overflow: auto; border-radius: 7px; background: var(--surface-2); color: var(--text-soft); font: 10px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Investigation evidence card: figures from a saved investigation, under the answer and in Activity. */
.message .evidence-card { grid-column: 2; }
.evidence-card { margin-top: 12px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); font-size: 12.5px; }
.evidence-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; color: var(--text); }
.evidence-head strong { font-size: 13.5px; }
.evidence-head .panel-link { margin-left: auto; }
.evidence-summary { margin: 8px 0; color: var(--text); line-height: 1.55; }
.evidence-error { margin: 8px 0; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--red-soft); color: var(--text); line-height: 1.5; }
.evidence-note { margin: 4px 0 0; color: var(--text-soft); font-size: 11.5px; line-height: 1.5; overflow-wrap: anywhere; }
.evidence-note code, .evidence-card td code { font: 10px var(--mono); }
.evidence-section { margin-top: 8px; border-top: 1px solid var(--border); }
.evidence-section > summary { padding: 9px 0 4px; color: var(--text-soft); cursor: pointer; font-size: 11.5px; font-weight: 600; }
.evidence-section > summary:hover, .evidence-section[open] > summary { color: var(--text); }
.check-list { display: grid; gap: 8px; margin: 4px 0 6px; padding: 0; list-style: none; }
.check-row .timeline-head .status-pill { margin-left: auto; }
.evidence-list { margin: 10px 0 0; color: var(--text-soft); font-size: 11.5px; }
.evidence-list strong { color: var(--text); font-size: 11.5px; }
.evidence-list ul, .evidence-calc { margin: 4px 0 0; padding-left: 18px; line-height: 1.55; }
.evidence-list.is-warning { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--amber-soft); }
.evidence-list.is-warning, .evidence-list.is-warning strong { color: var(--text); }
.evidence-card .markdown-table-wrap { margin: 10px 0 4px; }
.evidence-card .data-table td { white-space: normal; }
.evidence-card .data-table td:not(:first-child) { white-space: nowrap; }
.evidence-card .data-chart { margin: 8px 0 0; padding: 0; border: 0; box-shadow: none; }
.evidence-card .data-chart-title { display: none; }
.chart-missing { margin: 10px 0; padding: 8px 12px; border: 1px dashed var(--border-hover); border-radius: var(--radius-sm); color: var(--text-soft); font-size: 12.5px; }
.evidence-card .chart-heading { justify-content: flex-end; }
.evidence-actions { margin-top: 12px; }

/* ── Tables ─────────────────────────────────────────────────────── */
.markdown-table-wrap {
  max-width: 100%;
  margin: 14px 0 18px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.markdown-table { width: 100%; border-collapse: collapse; font-size: 12px; line-height: 1.6; }
.markdown-table th, .markdown-table td {
  min-width: 110px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.markdown-table th { background: var(--surface-2); color: var(--text); font-weight: 700; font-size: 11px; }
.markdown-table tr:last-child td { border-bottom: 0; }
.markdown-table td:first-child { color: var(--text); font-weight: 600; }
.markdown-table td { color: var(--text-soft); }

/* ── Charts ─────────────────────────────────────────────────────── */
.data-chart {
  margin: 14px 0 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.data-chart-title { margin-bottom: 14px; color: var(--text); font-size: 12px; font-weight: 700; }
.chart-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(100px, 2.5fr) auto;
  align-items: center;
  gap: 10px;
  margin: 9px 0;
}
.chart-label { color: var(--text-soft); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-value { color: var(--text); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart-track { height: 6px; overflow: hidden; border-radius: 99px; background: var(--surface-3); }
.chart-bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: 0 0 8px rgba(124,58,237,.4);
  transition: width .5s ease;
}
.donut-layout { display: flex; flex-wrap: wrap; align-items: center; gap: 24px; }
.donut-ring {
  position: relative;
  width: 140px;
  height: 140px;
  flex-shrink: 0;
  border-radius: 50%;
}
.donut-ring::after {
  position: absolute;
  inset: 28px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  content: '';
}
.donut-legend { display: grid; min-width: min(220px, 100%); gap: 8px; }
.donut-item { display: flex; align-items: center; gap: 8px; color: var(--text-soft); font-size: 10px; }
.donut-swatch { width: 8px; height: 8px; flex-shrink: 0; border-radius: 3px; }
.donut-item strong { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }
.line-chart-scroll { overflow-x: auto; }
.line-chart-svg { display: block; width: 100%; min-width: 520px; height: auto; overflow: visible; }
.line-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 5; }
.line-axis-label { fill: var(--text-soft); font-family: sans-serif; font-size: 10px; }
.line-path { fill: none; stroke: var(--series-color); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.line-point { fill: var(--surface); stroke: var(--series-color); stroke-width: 2.5; cursor: crosshair; vector-effect: non-scaling-stroke; transition: r .15s ease; }
.line-point:hover { r: 6; }
.line-chart-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.line-legend-item { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); color: var(--text); font: inherit; font-size: 11px; cursor: pointer; }
.line-legend-item span { width: 8px; height: 8px; border-radius: 50%; background: var(--series-color); }
.line-legend-item[aria-pressed="false"] { opacity: .45; text-decoration: line-through; }
.chart-hint { margin: 10px 0 0; color: var(--text-muted); font-size: 10px; }
.chart-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.chart-heading .data-chart-title { margin: 0; }
.chart-view-controls { display: inline-flex; gap: 3px; padding: 3px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); }
.chart-view-button { padding: 5px 9px; border: 0; border-radius: 6px; background: transparent; color: var(--text-soft); font: inherit; font-size: 10px; cursor: pointer; }
.chart-view-button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.chart-data-scroll { overflow: auto; }
.chart-data-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.chart-data-table th, .chart-data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; font-variant-numeric: tabular-nums; }
.chart-data-table th:first-child, .chart-data-table td:first-child { text-align: left; }
.chart-data-table th { color: var(--text-soft); font-weight: 600; }
.plotly-chart { width: 100%; min-height: 340px; }
.plotly-chart[hidden], .chart-data-panel[hidden] { display: none !important; }
.plotly-chart-error { display: grid; min-height: 140px; place-items: center; color: var(--text-muted); font-size: 12px; text-align: center; }
.donut-item { width: 100%; padding: 4px 6px; border: 0; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; }
.donut-item:hover { background: var(--surface-2); }
.donut-item.is-muted { opacity: .4; text-decoration: line-through; }

/* ── Code blocks ────────────────────────────────────────────────── */
.code-block, .exec-result, .logs-block {
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.code-block-header, .exec-result-header, .logs-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.lang-badge {
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--accent-wash);
  color: var(--accent-3);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
}
.copy-btn {
  margin-left: auto;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text-soft);
  font-size: 10px;
  transition: color .15s, border-color .15s;
}
.copy-btn:hover { color: var(--text); border-color: var(--border-hover); }
.code-block pre, .exec-result pre, .logs-block pre {
  overflow-x: auto;
  margin: 0;
  padding: 14px;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre;
}
.exec-result-header { color: var(--green); }
.logs-header { color: var(--amber); }
.logs-block pre { color: var(--amber); }

/* ── Typing indicator ───────────────────────────────────────────── */
.typing-indicator { display: flex; align-items: center; gap: 5px; padding: 6px 0; }
.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-3);
  animation: typing-bounce 1.3s ease infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .18s; }
.typing-indicator span:nth-child(3) { animation-delay: .36s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* ── Syntax highlighting ─────────────────────────────────────────── */
.syntax-string  { color: #a5d6ff; }
.syntax-keyword { color: #c084fc; }
.syntax-comment { color: var(--text-muted); font-style: italic; }
.syntax-number  { color: #ffa657; }
.syntax-call    { color: #79c0ff; }
.syntax-property{ color: #7ee787; }
:root[data-theme="light"] .syntax-string  { color: #0550ae; }
:root[data-theme="light"] .syntax-keyword { color: #8250df; }
:root[data-theme="light"] .syntax-comment { color: #6e7781; }
:root[data-theme="light"] .syntax-number  { color: #953800; }
:root[data-theme="light"] .syntax-call    { color: #0366d6; }
:root[data-theme="light"] .syntax-property{ color: #116329; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1280px) {
  :root { --rail-w: 0px; }
  #app { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  #right-rail { display: none; }
}

@media (max-width: 1080px) {
  .feature-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(var(--sidebar-w), 86vw);
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open #sidebar { transform: translateX(0); }
  #sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: block;
    background: rgba(5, 15, 11, .45);
  }
  #sidebar-scrim[hidden] { display: none !important; }
  .menu-toggle { display: grid; }
  .chat-delete { opacity: 1; }
  #topbar { padding: 12px 16px 6px; gap: 8px; }
  #chat-scroll { padding: 6px 16px 10px; }
  #input-area { width: calc(100% - 32px); padding-bottom: 12px; }
  .hero { grid-template-columns: 1fr; padding: 22px 20px; }
  .hero-art { display: none; }
}

@media (max-width: 560px) {
  #status-text { display: none; }
  #status-badge { padding: 8px; }
  .feature-cards { grid-template-columns: 1fr; gap: 10px; }
  .feature-card { padding: 12px; }
  .hero-sub { font-size: 13px; }
  .message { grid-template-columns: 32px minmax(0, 1fr); column-gap: 10px; }
  .message-avatar { width: 32px; height: 32px; }
  .message.assistant .message-body { padding: 12px 14px; }
  #input-wrap { flex-wrap: wrap; padding: 8px 8px 8px 14px; }
  #user-input { flex-basis: 100%; }
  .provider-picker { flex: 1; max-width: none; height: 40px; }
  #send-btn { width: 40px; height: 40px; }
  #input-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Profiles: account trigger, picker, settings dialog ──────────── */
.account-trigger {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  gap: 10px;
  padding: 4px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: inherit;
  text-align: left;
  transition: background .15s;
}
.account-trigger:hover, .account-trigger:focus-visible { background: rgba(255, 255, 255, .07); }

.rail-link {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 6px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.rail-link:hover { text-decoration: underline; }
.rail-link:disabled { cursor: wait; opacity: .6; text-decoration: none; }

body.gate-open #app { visibility: hidden; }
.profile-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  overflow-y: auto;
  place-items: center;
  padding: 24px 16px;
  background: var(--canvas);
}
.gate-card {
  width: min(440px, 100%);
  padding: 32px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.gate-logo { display: inline-grid; margin-bottom: 14px; }
.gate-title { color: var(--text); font-family: var(--serif); font-size: 26px; letter-spacing: -.4px; }
.gate-sub { margin: 8px 0 22px; color: var(--text-soft); font-size: 14px; line-height: 1.55; }
.profile-list { display: grid; gap: 8px; }
.profile-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  transition: border-color .15s, background .15s;
}
.profile-choice:hover, .profile-choice:focus-visible { border-color: var(--accent); background: var(--accent-wash); }
.profile-initial {
  display: grid;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
}
:root[data-theme="dark"] .profile-initial { color: #0c2a1e; }
.gate-link {
  margin-top: 14px;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}
.gate-form { display: grid; gap: 12px; text-align: left; }
.gate-form-title { color: var(--text); font-size: 15px; }
.gate-actions, .dialog-actions { display: flex; gap: 10px; }
.turnstile-slot { min-height: 65px; }
.gate-actions .rail-button, .dialog-actions .rail-button { flex: 1; }
.gate-secondary {
  padding: 10px 14px;
  border: 1px solid var(--border-hover);
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.gate-secondary:hover { background: var(--surface-2); }
.gate-error { margin-top: 14px; color: var(--error); font-size: 13px; }
.gate-note { margin-top: 18px; color: var(--text-muted); font-size: 11.5px; line-height: 1.5; }
.gate-account { margin: -10px 0 18px; color: var(--text-soft); font-size: 13px; overflow-wrap: anywhere; }
.google-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-hover);
  border-radius: 11px;
  background: #fff;
  color: #1f1f1f;
  font-size: 14px;
  font-weight: 600;
}
.google-button:hover { background: #f4f4f4; }
.google-button:disabled { cursor: wait; opacity: .6; }
.google-button svg { width: 18px; height: 18px; flex-shrink: 0; }

.field { display: grid; gap: 5px; color: var(--text-soft); font-size: 12px; font-weight: 600; text-align: left; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
}
.field textarea { resize: vertical; min-height: 60px; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-wash); }

.profile-dialog {
  width: min(520px, calc(100% - 32px));
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.profile-dialog::backdrop { background: rgba(8, 20, 15, .45); }
.profile-dialog form { display: grid; gap: 14px; padding: 22px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2 { font-family: var(--serif); font-size: 21px; letter-spacing: -.3px; }
.dialog-sub { color: var(--text-soft); font-size: 13px; line-height: 1.5; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-wide { grid-column: 1 / -1; }
.dialog-status { min-height: 18px; color: var(--accent); font-size: 12.5px; }
.danger-zone { padding-top: 12px; border-top: 1px solid var(--border); color: var(--text-soft); font-size: 13px; }
.danger-zone summary { color: var(--error); cursor: pointer; font-weight: 600; }
.danger-zone[open] { display: grid; gap: 10px; }
.danger-zone p { line-height: 1.5; }
.danger-button {
  justify-self: start;
  padding: 9px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--error);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.gate-card.is-consent { width: min(560px, 100%); }
.privacy-notice {
  display: grid;
  gap: 12px;
  max-height: min(38vh, 320px);
  overflow-y: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.55;
  text-align: left;
}
.privacy-notice h3 { margin-bottom: 3px; color: var(--text); font-size: 13.5px; }
.privacy-notice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.storage-choice { display: grid; gap: 8px; padding: 0; border: 0; }
.storage-choice legend { margin-bottom: 6px; color: var(--text-soft); font-size: 12px; font-weight: 600; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-wash); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice span { display: grid; gap: 2px; }
.choice strong { color: var(--text); font-size: 13.5px; }
.choice small { color: var(--text-soft); font-size: 12px; }
.consent-check { display: flex; align-items: flex-start; gap: 10px; color: var(--text); font-size: 13px; line-height: 1.45; text-align: left; }
.consent-check input { margin-top: 2px; accent-color: var(--accent); }
.data-zone { padding-top: 12px; border-top: 1px solid var(--border); color: var(--text-soft); font-size: 13px; }
.data-zone > summary { color: var(--text); cursor: pointer; font-weight: 600; }
.data-zone[open] { display: grid; gap: 12px; }
.data-zone .gate-secondary { justify-self: start; }
.data-summary { line-height: 1.5; }
.cas-form { display: grid; gap: 10px; margin-top: 10px; }
.dialog-status.is-error { color: var(--error); }
.cas-form .field input[type="file"] { padding: 7px; font-size: 13px; }
.backup-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.backup-row .data-summary { flex: 1 1 220px; }
.notice-details summary { color: var(--accent); cursor: pointer; font-weight: 600; }
.notice-details[open] summary { margin-bottom: 8px; }
.data-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.recovery-code-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-md);
  background: var(--accent-wash);
}
.recovery-code {
  flex: 1;
  color: var(--text);
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .5px;
  overflow-wrap: anywhere;
  user-select: all;
}
.recovery-note { color: var(--text-soft); font-size: 13px; line-height: 1.5; text-align: left; }
.data-actions .field { flex: 1 1 100%; }

@media (max-width: 560px) {
  .gate-card { padding: 26px 18px; }
  .data-actions { flex-direction: column; align-items: stretch; }
  .field-grid { grid-template-columns: 1fr; }
}

/* ── Pages behind the sidebar ───────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
#page-view { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 28px 28px; }
.page { display: grid; grid-template-columns: minmax(0, 1fr); width: min(1080px, 100%); gap: 18px; margin: 0 auto; }
.page-head, .page-hero { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; }
.page-hero {
  padding: 26px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(ellipse 60% 90% at 100% 0%, var(--green-soft) 0%, transparent 70%),
    linear-gradient(120deg, var(--surface) 40%, var(--surface-2) 100%);
}
.page-title { color: var(--text); font-family: var(--serif); font-size: clamp(22px, 2.4vw, 30px); font-weight: 700; letter-spacing: -.4px; line-height: 1.2; }
.page-sub { max-width: 640px; margin-top: 6px; color: var(--text-soft); font-size: 13.5px; }
.page-cta { width: auto; padding: 10px 18px; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.page-muted { color: var(--text-muted); font-size: 13px; }
.page-loading { padding: 28px; color: var(--text-muted); font-size: 13px; text-align: center; }
.page-error { padding: 12px 14px; border-radius: var(--radius-md); background: var(--red-soft); color: var(--error); font-size: 13px; }
#portfolio-body, #investments-body, #markets-body, #goals-body, #reports-body, #activity-body, #calc-body { display: grid; gap: 18px; }
.page-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.page-stack { display: grid; gap: 18px; }
.page-chips { margin: 0; }
.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.panel-link { color: var(--accent); font-size: 12px; font-weight: 600; text-decoration: none; }
.panel-link:hover { text-decoration: underline; }
.panel .data-chart { margin: 0; padding: 0; border: 0; box-shadow: none; }
.panel .data-chart-title { display: none; }
.panel .chart-heading { justify-content: flex-end; }
.page .feature-card { grid-template-columns: minmax(0, 1fr) 14px; }
.empty-panel { display: grid; justify-items: start; gap: 8px; padding: 26px; }
.empty-panel h2 { color: var(--text); font-size: 17px; }
.empty-panel p { max-width: 560px; color: var(--text-soft); font-size: 13.5px; }
.inline-button { width: auto; margin-top: 6px; padding: 10px 18px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-tile {
  display: grid;
  min-width: 0;
  gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.stat-label { color: var(--text-soft); font-size: 12px; font-weight: 600; }
.stat-value { overflow: hidden; color: var(--text); font-family: var(--serif); font-size: 22px; letter-spacing: -.3px; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--text-muted); font-size: 12px; }
.is-up { color: var(--green) !important; }
.is-down { color: var(--red) !important; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); justify-self: start; }
.seg button { padding: 7px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--text-soft); font-size: 13px; font-weight: 600; transition: background .15s, color .15s; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent-3); box-shadow: var(--shadow-sm); }
.seg-small button { padding: 4px 10px; font-size: 12px; }
.seg-count { margin-left: 2px; color: var(--text-muted); font-weight: 500; font-variant-numeric: tabular-nums; }

/* Activity: saved investigations. */
.activity-panel { display: grid; gap: 14px; }
.activity-list { display: grid; margin: 0; padding: 0; list-style: none; }
.activity-item { display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--border); }
.activity-item:first-child { border-top: 0; }
.activity-body { display: grid; flex: 1; min-width: 0; gap: 4px; }
.activity-title { color: var(--text); font-size: 14px; font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.activity-title:hover { color: var(--accent); }
.activity-outcome { margin: 0; color: var(--text-soft); font-size: 13px; line-height: 1.5; }
.activity-item .timeline-meta { font-size: 12px; color: var(--text-muted); }
.activity-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.small-button { display: inline-block; padding: 6px 12px; font-size: 12px; text-decoration: none; }
.activity-empty { padding: 8px 0; }
.activity-detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.activity-detail-head .activity-actions { margin: 0 0 0 auto; }
.activity-detail-head + .evidence-card { margin-top: 0; padding: 18px 20px; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.activity-skeleton { display: grid; gap: 12px; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.skeleton-row { display: grid; gap: 8px; }
.skeleton-row span { display: block; height: 12px; border-radius: 6px; background: var(--surface-2); animation: skeleton-fade 1.4s ease-in-out infinite; }
.skeleton-row span:first-child { width: 45%; height: 14px; }
.skeleton-row span:last-child { width: 80%; }
@keyframes skeleton-fade { 50% { opacity: .5; } }

.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; white-space: normal; }
.data-table th { color: var(--text-soft); font-size: 12px; font-weight: 600; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--accent-wash2); }
.data-table td small { display: block; color: var(--text-muted); font-size: 11.5px; }
.data-table td.is-up small, .data-table td.is-down small { color: inherit; opacity: .85; }
.data-table.compact th, .data-table.compact td { padding: 8px 6px; }
.holding-name { color: var(--text); font-weight: 600; }
.table-action { padding: 4px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--accent); font-size: 12px; font-weight: 600; }
.table-action:hover { border-color: var(--accent); background: var(--accent-wash2); }
.table-action:disabled { cursor: wait; opacity: .6; }
.table-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.table-search { width: auto; flex: 1; min-width: 180px; box-shadow: none; }
.table-search input { height: 36px; }
.inline-field { display: flex; align-items: center; gap: 8px; }
.inline-field select { width: auto; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; }
.inline-form .rail-button { grid-column: 1 / -1; }
#stock-chart-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.fact-list { display: grid; gap: 10px; }
.fact-list div { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.fact-list dt { color: var(--text-soft); }
.fact-list dd { color: var(--text); font-weight: 600; text-align: right; }
.note-list { display: grid; gap: 6px; padding-left: 18px; color: var(--text-soft); font-size: 13px; }

.shortcut-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.shortcut {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--tone-soft) 0%, var(--surface) 80%);
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s, transform .15s;
}
.shortcut:hover { border-color: var(--tone); transform: translateY(-1px); }
.shortcut strong { font-size: 13px; }
a.tool-tile { text-decoration: none; }
.shortcut small { color: var(--text-soft); font-size: 12px; }

/* Chat rows outside the dark sidebar (Home and All chats). */
.mini-chat-list, #all-chats { display: grid; gap: 2px; }
#page-view .chat-select { color: var(--text); }
#page-view .chat-select::before { border-color: var(--text-muted); }
#page-view .chat-select:hover { background: var(--surface-2); }
#page-view .chat-select.active { background: var(--accent-wash); }
#page-view .chat-select.active::before { border-color: var(--accent); }
#page-view .chat-meta { color: var(--text-muted); }
#page-view .chat-delete { color: var(--text-muted); }
#page-view .chat-delete:hover { background: var(--red-soft); color: var(--error); }
.chat-group { margin: 12px 8px 4px; color: var(--text-muted); font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.chat-group:first-child { margin-top: 0; }

.calc-layout { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 18px; align-items: start; }
.calc-inputs { display: grid; gap: 16px; }
.calc-note { max-width: 720px; font-size: 12px; line-height: 1.5; }
.data-table .total-row td { border-top: 2px solid var(--border-hover); color: var(--text); font-weight: 700; }
.calc-field input[type="range"] { width: 100%; padding: 0; border: 0; accent-color: var(--accent); box-shadow: none; }

.goal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.goal-card { display: grid; gap: 8px; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.goal-card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.goal-card h3 { color: var(--text); font-size: 15px; overflow-wrap: anywhere; }
.goal-target { color: var(--text-soft); font-size: 13px; }
.goal-target strong { color: var(--text); font-family: var(--serif); font-size: 20px; }
.goal-meta, .goal-advice { color: var(--text-soft); font-size: 12.5px; }
.goal-advice { color: var(--text); }
.goal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.progress { height: 8px; overflow: hidden; border-radius: 99px; background: var(--surface-3); }
.progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.pill.is-behind { background: var(--amber-soft); color: var(--amber); }
.goal-form { display: grid; gap: 14px; }

.agent-switch { display: inline-flex; gap: 4px; margin-bottom: 10px; padding: 4px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm); }
.agent-option { padding: 6px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--text-soft); font-size: 12.5px; font-weight: 600; transition: background .15s, color .15s; }
.agent-option:hover { color: var(--text); }
.agent-option[aria-pressed="true"] { background: var(--accent); color: #fff; }
:root[data-theme="dark"] .agent-option[aria-pressed="true"] { color: #0c2a1e; }
.agent-option:disabled { cursor: wait; opacity: .6; }

.connection-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }
.connection-row span { display: grid; line-height: 1.35; }
.connection-row strong { color: var(--text); font-size: 14px; }
.connection-row small { color: var(--text-soft); font-size: 12px; }
.plan-link { flex-shrink: 0; text-decoration: none; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 60;
  max-width: min(480px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--canvas);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  transform: translateX(-50%);
}

@media (max-width: 1080px) {
  .page-columns, .calc-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  #page-view { padding: 6px 16px 20px; }
  .page-hero { padding: 20px; }
}

@media (max-width: 560px) {
  .stat-grid, .stat-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .shortcut-grid { grid-template-columns: minmax(0, 1fr); }
  .stat-tile { padding: 12px 14px; }
  .stat-value { font-size: 18px; }
  .page-head .page-cta, .page-hero .page-cta { width: 100%; }
  #stock-chart-form { grid-template-columns: minmax(0, 1fr); }
  .table-controls .seg { width: 100%; }
}

@media print {
  body { overflow: visible; background: #fff; }
  #app { display: block; height: auto; }
  #sidebar, #topbar, #right-rail, #chat-scroll, #input-area, .page-actions, .page-chips, .table-action, .seg { display: none !important; }
  #page-view { overflow: visible; padding: 0; }
  .panel, .stat-tile { box-shadow: none; break-inside: avoid; }
}

/* ── Right rail cards ───────────────────────────────────────────── */
.rail-head h2 { min-width: 0; }
.rail-more { flex-shrink: 0; color: var(--accent); font-size: 12.5px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.rail-more:hover { text-decoration: underline; }
.rail-copy.rail-error { color: var(--error); }
.rail-figure-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 6px; }
.rail-figure { color: var(--text); font-size: 31px; font-weight: 800; letter-spacing: -.8px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.rail-change { font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.rail-change small { color: var(--text-muted); font-size: 11.5px; font-weight: 500; }
.rail-spark { display: block; width: calc(100% + 18px); height: 104px; margin: 10px -18px 0 0; color: var(--accent-2); }
.rail-spark .spark-line { stroke: currentColor; stroke-width: 2.5; }
.rail-spark .spark-dots, .rail-spark .spark-dot-end { fill: none; stroke: currentColor; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.rail-spark .spark-dots { stroke-width: 6; }
.rail-spark .spark-dot-end { stroke-width: 9; }
.rail-spark.is-down { color: var(--red); }
.rail-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 0; padding-top: 14px; border-top: 1px solid var(--border); }
.rail-metrics div { display: grid; min-width: 0; gap: 2px; padding: 0 2px; text-align: center; }
.rail-metrics div + div { border-left: 1px solid var(--border); }
.rail-metrics dt { color: var(--text-soft); font-size: 12px; white-space: nowrap; }
.rail-metrics dd { overflow: hidden; color: var(--text); font-size: 14.5px; font-weight: 700; letter-spacing: -.2px; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rail-foot { margin-top: 12px; color: var(--text-muted); font-size: 11.5px; line-height: 1.5; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; }
.link-button:hover { text-decoration: underline; }
.link-button:disabled { cursor: wait; opacity: .6; text-decoration: none; }

.rail-list { display: grid; gap: 2px; margin: 0 -8px; list-style: none; }
.rail-row {
  display: flex;
  width: 100%;
  align-items: flex-start;
  gap: 12px;
  padding: 9px 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  transition: background .15s;
}
.rail-row:hover { background: var(--surface-2); }
.rail-row:disabled { cursor: wait; opacity: .6; }
.rail-row .insight-icon { width: 40px; height: 40px; border-radius: 50%; }
.rail-row-body { display: grid; min-width: 0; flex: 1; gap: 2px; }
.rail-row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.rail-row-head strong { display: -webkit-box; min-width: 0; overflow: hidden; color: var(--text); font-size: 13px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
.rail-row small { color: var(--text-muted); font-size: 11.5px; line-height: 1.4; }
.rail-when { flex-shrink: 0; color: var(--text-muted); font-size: 11px; }
.rail-progress { height: 10px; }
.rail-progress span { background: var(--tone); }

.rail-skeleton { display: grid; gap: 10px; }
.rail-skeleton span { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: rail-shimmer 1.2s ease infinite; }
.rail-skeleton span:first-child { width: 60%; height: 26px; }
.rail-skeleton span:last-child { width: 80%; }
@keyframes rail-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

#right-rail .tool-tile { min-height: 84px; padding: 10px 4px; font-size: 11.5px; line-height: 1.3; }
#right-rail .tool-tile svg { width: 22px; height: 22px; }

/* Financial Goals card: big round icon, name and target, percent, then the bar. */
.rail-goals { gap: 6px; }
.rail-goal {
  display: grid;
  width: 100%;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  grid-template-areas: "icon name pct" "icon target pct" "icon bar bar";
  align-items: center;
  column-gap: 14px;
  row-gap: 2px;
  padding: 10px 8px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  transition: background .15s;
}
.rail-goal:hover { background: var(--surface-2); }
.rail-goal-icon { display: grid; width: 52px; height: 52px; grid-area: icon; place-items: center; border-radius: 50%; background: var(--tone-soft); color: var(--tone); }
.rail-goal-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rail-goal-name { grid-area: name; overflow: hidden; color: var(--text); font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.rail-goal-target { grid-area: target; color: var(--text-soft); font-size: 12.5px; }
.rail-goal-pct { grid-area: pct; color: var(--text); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rail-goal .rail-progress { grid-area: bar; margin-top: 8px; }
.rail-add { width: 100%; margin-top: 8px; padding: 9px; border: 1px dashed var(--border-hover); border-radius: 12px; background: transparent; color: var(--accent); font-size: 12.5px; font-weight: 600; }
.rail-add:hover { border-color: var(--accent); background: var(--accent-wash2); }

/* Goal editor dialog and Goals page icons. */
.goal-preview { min-height: 20px; color: var(--text-soft); font-size: 13px; line-height: 1.5; }
.goal-preview.is-behind { color: var(--amber); }
.danger-text { margin-right: auto; color: var(--error); }
.danger-text:hover { border-color: var(--error); background: var(--red-soft); }
.goal-dialog .dialog-actions .rail-button { flex: 0 1 160px; }
.goal-card header { align-items: center; }
.goal-card header h3 { flex: 1; }
.goal-card-icon { width: 40px; height: 40px; border-radius: 50%; }
.goal-card-icon svg { width: 20px; height: 20px; }

.goal-preview.is-loading { color: var(--text-muted); }
.goal-note { font-style: italic; overflow-wrap: anywhere; }
.goal-scenarios { border-top: 1px solid var(--border); padding-top: 6px; font-size: 12.5px; }
.goal-scenarios summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.goal-scenarios .data-table { margin-top: 6px; }
.goal-scenarios .is-up { color: var(--green); }
.goal-scenarios .is-down { color: var(--amber); }
.goal-notes { display: grid; gap: 4px; margin: 8px 0 0; padding-left: 18px; color: var(--text-soft); font-size: 12px; line-height: 1.45; }

/* Saved context on the Goals page. */
.saved-context { margin-top: 18px; }
.saved-context > .page-muted { margin-bottom: 14px; max-width: 720px; }
.context-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; margin-bottom: 14px; }
.context-grid section { display: grid; align-content: start; gap: 8px; }
.context-title { color: var(--text); font-size: 14px; }
.context-title small { margin-left: 6px; color: var(--text-muted); font-size: 11.5px; font-weight: 500; }
.context-facts, .context-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.context-facts li { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.context-facts span { color: var(--text-soft); }
.context-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.context-item p { color: var(--text); font-size: 13px; overflow-wrap: anywhere; }
.context-item small { color: var(--text-muted); font-size: 11.5px; }
.decision-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; align-items: end; }
.decision-form .field-wide, .decision-form .dialog-status { grid-column: 1 / -1; }
.decision-form .dialog-status:empty { display: none; }
.saved-context .danger-text { margin-right: 0; }
.goal-card { min-width: 0; align-content: start; }
.goal-scenarios .table-scroll { overflow-x: auto; }
.goal-scenarios .data-table th { white-space: normal; }
.goal-grid { align-items: start; }

/* Goal planning: alternatives, suitability, assigned holdings and the assign dialog. */
.goal-section { display: grid; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border); }
.goal-section h4 { color: var(--text); font-size: 12.5px; }
.goal-card.is-draft { border-style: dashed; }
.goal-meta.is-warn { color: var(--amber); }
.goal-alts { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; font-size: 12.5px; }
.basis-tag { display: inline-block; margin-right: 4px; padding: 1px 7px; border-radius: 99px; background: var(--surface-3); color: var(--text-soft); font-size: 11px; font-weight: 600; }
.basis-tag.is-certain { background: var(--green-soft); color: var(--green); }
.chip-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip-row-label { min-width: 74px; color: var(--text-muted); font-size: 11.5px; font-weight: 600; }
.goal-section h5 { margin-top: 6px; color: var(--text); font-size: 12px; }
.fund-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.fund-item { display: grid; gap: 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.fund-metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px 12px; margin: 2px 0 0; }
.fund-metrics dt { color: var(--text-muted); font-size: 11px; }
.fund-metrics dd { margin: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.fund-note { display: block; margin-top: 2px; color: var(--text-muted); font-size: 11px; white-space: normal; }
.fund-note.is-warn { color: var(--amber); }
.verdict-chip { display: inline-block; padding: 2px 8px; border: 1px solid var(--border); border-radius: 99px; background: var(--surface-2); color: var(--text-soft); font-size: 11.5px; }
.verdict-chip.is-allowed { border-color: var(--green); color: var(--green); }
.verdict-chip.is-caution { border-color: var(--amber); color: var(--amber); }
.verdict-chip.is-unsuitable { border-color: var(--error); color: var(--error); }
.verdict-chip.is-cannot_assess { color: var(--text-muted); }
.goal-notes ul { margin: 2px 0 4px; padding-left: 16px; }
.goal-when { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 0; padding: 0; border: 0; }
.goal-when legend { padding: 0; margin-bottom: 4px; color: var(--text-soft); font-size: 12.5px; font-weight: 600; }
.goal-when input[type="date"], .goal-when input[type="number"] { flex: 1 1 160px; }
.radio-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.goal-risk-inputs summary { cursor: pointer; color: var(--accent); font-size: 12.5px; font-weight: 600; }
.goal-risk-inputs .field-grid { margin-top: 10px; }
.data-table td.alloc-goals { min-width: 150px; white-space: normal; }

@media (max-width: 600px) {
  .goal-grid, .stat-grid { grid-template-columns: 1fr; }
  .goal-dialog { width: 100%; max-width: 100%; margin: 0; border-radius: 0; }
  .goal-dialog .dialog-actions { flex-wrap: wrap; }
  .goal-dialog .dialog-actions .rail-button { flex: 1 1 100%; }
  .chip-row-label { min-width: 100%; }
}

/* ── Page not found and privacy links ─────────────────────────────── */
.not-found { max-width: 560px; margin: 8vh auto 0; padding: 36px 28px; text-align: center; }
.not-found-code { margin: 0 0 6px; color: var(--accent); font-family: 'Fraunces', serif; font-size: 64px; font-weight: 700; line-height: 1; }
.not-found .page-sub { margin: 10px auto 22px; }
.not-found-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.not-found-actions .page-cta { width: auto; text-decoration: none; }
.gate-legal { margin: 10px 0 0; font-size: 11.5px; }
.gate-legal a, .notice-link a { color: var(--accent); }
.notice-link { margin: 10px 0 0; font-size: 12.5px; }

/* Answer runs in Activity (trace.js renderRunCard) and the link under an answer's trace */
.run-card { display: grid; gap: 12px; }
.run-title { margin: 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.chat-trace-link { display: inline-block; margin-top: 8px; font-size: 12px; }
.activity-panel > h2 { margin: 0; font-size: 15px; }
