/* Stock agent dashboard: the ONE stylesheet (served at /app.css).
   The CSP is default-src 'self'; script-src 'self': the only script is /assets/chat.js (the chat widget);
   no inline style attributes or <style> blocks, no web fonts or CDNs. Every visual rule lives here. Flat design: hairline borders, no gradients,
   no shadows. Colours are tokens (light + dark via prefers-color-scheme), contrast WCAG AA: text (hover
   states included) 4.5:1; the focus ring, field borders and the stop → target bar's zones 3:1 against the
   card. Body content is 16px+; 13–14px only for metadata (timestamps, stat labels, chart labels, footer). */

:root {
  color-scheme: light dark;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16191f;
  --text-2: #555d6b;
  --line: #e1e4e9;
  --field: #ffffff;
  --field-line: #868e9b;
  --link: #1f4fd1;
  --focus: #1f4fd1;
  --btn: #1f4fd1;
  --btn-hover: #1a43b3;
  --btn-text: #ffffff;
  --mark: #1f4fd1;
  --mark-fg: #ffffff;
  --accent-tint: #e9effc;
  --accent-line: #c9d7f6;
  --accent-text: #1a43b3;
  --ok: #12733a;
  --ok-tint: #e7f4eb;
  --ok-line: #b9dfc6;
  --ok-zone: #3f9a63;
  --bad: #b42318;
  --bad-tint: #fdeceb;
  --bad-line: #f3c4bf;
  --bad-zone: #de5f55;
  --warn: #8f5400;
  --warn-tint: #fdf2e1;
  --warn-line: #f0d6a8;

  --radius: 8px;
  --radius-card: 12px;
  --page: 1040px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #16191e;
    --surface-2: #1e2229;
    --text: #e8eaee;
    --text-2: #a3aab6;
    --line: #2b3038;
    --field: #0e1013;
    --field-line: #6f7887;
    --link: #8fb0ff;
    --focus: #8fb0ff;
    --btn: #3b68e3;
    --btn-hover: #2f5bd6;
    --btn-text: #ffffff;
    --mark: #3b68e3;
    --mark-fg: #ffffff;
    --accent-tint: #1b2846;
    --accent-line: #2c3f6b;
    --accent-text: #b4caff;
    --ok: #5fd08b;
    --ok-tint: #11291b;
    --ok-line: #1f4a31;
    --ok-zone: #3a8f5c;
    --bad: #ff8f85;
    --bad-tint: #341719;
    --bad-line: #5c2a2c;
    --bad-zone: #c4574f;
    --warn: #f2bb57;
    --warn-tint: #2f2411;
    --warn-line: #574217;
  }
}

/* ---------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 16px/1.5 var(--font);
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 650; }
p { margin: 0 0 12px; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
b, strong { font-weight: 650; }
code { font-family: var(--mono); font-size: 0.9em; overflow-wrap: anywhere; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--text-2); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- top bar */

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: var(--page); margin: 0 auto; padding: 8px 16px; min-height: 60px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px;
  color: var(--text); text-decoration: none; font-size: 17px; font-weight: 700; letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
/* the app mark: three rising bars on a rounded square (pure CSS, no image) */
.brand-mark {
  width: 30px; height: 30px; flex: none; border-radius: var(--radius); background: var(--mark);
  display: inline-flex; align-items: flex-end; justify-content: center; gap: 3px; padding: 7px 7px 8px;
}
.brand-mark i { display: block; width: 4px; border-radius: 1px; background: var(--mark-fg); }
.brand-mark i:nth-child(1) { height: 6px; }
.brand-mark i:nth-child(2) { height: 10px; }
.brand-mark i:nth-child(3) { height: 15px; }

.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.nav form { margin: 0; display: flex; }
.nav a, .nav .nav-button {
  display: inline-flex; align-items: center; min-height: 40px; padding: 8px 12px;
  border: 0; border-radius: var(--radius); background: none;
  color: var(--text-2); font: inherit; font-size: 15px; font-weight: 550; text-decoration: none;
  cursor: pointer;
}
.nav a:hover, .nav .nav-button:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-tint); color: var(--accent-text); font-weight: 650; }
.nav .nav-button { text-decoration: underline; text-decoration-color: transparent; }

/* ---------------------------------------------------------------- layout */

main { flex: 1; width: 100%; max-width: var(--page); margin: 0 auto; padding: 24px 16px 32px; }
main.narrow { max-width: calc(420px + 32px); padding-top: 32px; }
main.chat-page { max-width: calc(760px + 32px); }
.site-footer {
  width: 100%; max-width: var(--page); margin: 0 auto; padding: 16px 16px 24px;
  color: var(--text-2); font-size: 13px;
}
.site-footer p { margin: 0; border-top: 1px solid var(--line); padding-top: 16px; }

.page-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: 4px 16px; margin-bottom: 16px;
}
.page-head p { margin: 0; color: var(--text-2); font-size: 14px; }
.lede { color: var(--text-2); margin: 4px 0 16px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card);
  padding: 20px; margin-bottom: 16px; min-width: 0;
}
.card-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: 4px 12px; margin-bottom: 12px;
}
.card-head .count { color: var(--text-2); font-size: 14px; }
.card > :last-child { margin-bottom: 0; }

/* callouts (errors, warnings, notices) */
.callout {
  border: 1px solid; border-radius: var(--radius); padding: 10px 12px; margin: 0 0 16px;
  font-size: 16px; overflow-wrap: anywhere;
}
.callout-bad { color: var(--bad); background: var(--bad-tint); border-color: var(--bad-line); }
.callout-warn { color: var(--warn); background: var(--warn-tint); border-color: var(--warn-line); }
.callout-ok { color: var(--ok); background: var(--ok-tint); border-color: var(--ok-line); }

/* ---------------------------------------------------------------- buttons and forms */

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: var(--btn); color: var(--btn-text);
  font: inherit; font-size: 16px; font-weight: 600; line-height: 1.2; text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--btn-hover); text-decoration: none; }
button.secondary, .button.secondary {
  background: var(--surface); color: var(--text); border-color: var(--field-line);
}
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); }
button.link {
  min-height: 0; padding: 0; border: 0; background: none; color: var(--link);
  font-weight: 500; text-decoration: underline; text-underline-offset: 2px;
}
button.link:hover { background: none; text-decoration-thickness: 2px; }
.block, .actions-full .button { width: 100%; }
.actions-full { margin: 0 0 16px; }

form { margin: 0; }
.field { display: block; margin: 0 0 16px; }
.field-label { display: block; margin-bottom: 6px; font-size: 16px; font-weight: 600; }
.hint { display: block; margin-top: 6px; color: var(--text-2); font-size: 16px; font-weight: 400; }
input[type="text"], input[type="password"], input:not([type]), textarea {
  display: block; width: 100%; min-height: 48px; margin: 0; padding: 10px 12px;
  border: 1px solid var(--field-line); border-radius: var(--radius);
  background: var(--field); color: var(--text);
  font: inherit; font-size: 17px; line-height: 1.4;
}
input:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
textarea { resize: vertical; min-height: 96px; }
/* PIN / one-time codes: large, spaced, tabular digits */
input.code, input.secret {
  min-height: 56px; font-family: var(--mono); font-size: 24px; letter-spacing: 0.3em;
  text-align: center; font-variant-numeric: tabular-nums;
}
/* the Angel One MPIN: a text field shown as dots (not a password field, so browsers do not offer to save it) */
input.secret { -webkit-text-security: disc; text-security: disc; }
.form-actions { margin-top: 20px; }

/* ---------------------------------------------------------------- auth pages (login, setup, Angel One, messages) */

.auth-card { padding: 24px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card .sub { color: var(--text-2); margin: 0 0 20px; }
.auth-card form { margin-top: 4px; }
.auth-card .section { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 20px; }
.notes { margin: 16px 0 0; padding: 0; list-style: none; color: var(--text-2); font-size: 16px; }
.notes li { margin-bottom: 8px; }
.notes li:last-child { margin-bottom: 0; }
.back { display: inline-block; margin-top: 16px; font-size: 15px; }
ol.steps { margin: 0 0 12px; padding-left: 22px; }
ol.steps li { margin-bottom: 8px; padding-left: 2px; }
/* the 2FA QR code (inline SVG, black on white so every phone camera reads it, also in dark mode) */
.qr {
  background: #fff; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius);
  width: 100%; max-width: 280px; margin: 8px auto 16px;
}
.qr svg { display: block; width: 100%; height: auto; }
p.key code {
  display: block; padding: 10px 12px; border-radius: var(--radius); background: var(--surface-2);
  font-size: 16px; letter-spacing: 0.08em; word-break: break-all; text-align: center;
}

/* ---------------------------------------------------------------- dashboard */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card);
}
.stat-label { color: var(--text-2); font-size: 13px; font-weight: 600; letter-spacing: 0.02em; }
.stat-value {
  display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 650; line-height: 1.3;
  overflow-wrap: anywhere; font-variant-numeric: tabular-nums;
}
.stat-detail { color: var(--text-2); font-size: 14px; overflow-wrap: anywhere; }
.stat-detail.bad { color: var(--bad); }
.stat .button { align-self: flex-start; margin-top: 6px; min-height: 40px; padding: 8px 14px; font-size: 15px; }
.dot { width: 10px; height: 10px; flex: none; border-radius: 50%; background: currentColor; }
.health {
  display: flex; flex-wrap: wrap; gap: 4px 16px; margin: -4px 0 16px; padding: 0; list-style: none;
  color: var(--text-2); font-size: 14px;
}
.health .bad { font-weight: 600; }

.positions { margin: 0; padding: 0; list-style: none; }
.pos { padding: 16px 0; border-top: 1px solid var(--line); }
.pos:first-child { padding-top: 4px; border-top: 0; }
.pos:last-child { padding-bottom: 0; }
.pos-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px;
}
.pos-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; }
.pos-sym { font-size: 18px; font-weight: 700; letter-spacing: 0.01em; overflow-wrap: anywhere; }
.pos-qty { color: var(--text-2); font-size: 15px; font-variant-numeric: tabular-nums; }
.pos-price {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px;
  font-variant-numeric: tabular-nums;
}
.pos-ltp { font-size: 18px; font-weight: 650; }
.chg { font-size: 15px; font-weight: 650; }
.up { color: var(--ok); }
.down { color: var(--bad); }
.flat { color: var(--text-2); }
.tag {
  display: inline-block; padding: 1px 8px; border: 1px solid; border-radius: 999px;
  font-size: 13px; font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.tag-warn { color: var(--warn); background: var(--warn-tint); border-color: var(--warn-line); }
.tag-bad { color: var(--bad); background: var(--bad-tint); border-color: var(--bad-line); }
.tag-ok { color: var(--ok); background: var(--ok-tint); border-color: var(--ok-line); }

/* the stop → target bar (inline SVG: positions are SVG attributes, colours come from here) */
.range { display: block; width: 100%; height: 24px; margin: 14px 0 8px; overflow: visible; }
.range-loss { fill: var(--bad-zone); }
.range-gain { fill: var(--ok-zone); }
.range-none { fill: var(--field-line); }
.range-be { stroke: var(--text); stroke-width: 2px; }
.range-dot { stroke: var(--surface); stroke-width: 3px; }
.range-dot.up { fill: var(--ok); }
.range-dot.down { fill: var(--bad); }
.range-dot.flat { fill: var(--text); }
.range-dot.stale { fill: var(--surface); stroke: var(--text-2); stroke-width: 2px; stroke-dasharray: 3 2; }
.range-labels {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px;
  color: var(--text-2); font-size: 14px; font-variant-numeric: tabular-nums;
}
.range-labels > span { min-width: 0; }
.range-labels .lbl-be { text-align: center; }
.range-labels .lbl-target { grid-column: 3; text-align: right; }
.lbl-name { color: var(--text); font-weight: 600; }
.pos-meta { margin: 8px 0 0; color: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; }

.empty { padding: 8px 0 4px; }
.empty-title { font-size: 17px; font-weight: 650; margin-bottom: 4px; }
.example {
  display: inline-block; padding: 2px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface-2); color: var(--text); font-weight: 600;
}
.empty-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 16px; }

.alerts { margin: 0; padding: 0; list-style: none; }
.alerts li { padding: 12px 0; border-top: 1px solid var(--line); }
.alerts li:first-child { padding-top: 0; border-top: 0; }
.alerts li:last-child { padding-bottom: 0; }
.alert-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 14px; }
.alert-title { color: var(--text); font-weight: 650; }
.alert-text { margin: 6px 0 0; font-size: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.lvl {
  display: inline-block; padding: 0 8px; border: 1px solid currentColor; border-radius: 999px;
  font-size: 12px; font-weight: 700; line-height: 1.6;
}
.lvl-p1 { color: var(--bad); }
.lvl-p2 { color: var(--warn); }
.lvl-p3 { color: var(--text-2); }
.page-foot { color: var(--text-2); font-size: 13px; }

/* ---------------------------------------------------------------- AI chat */

.spend { color: var(--text-2); font-size: 14px; margin: 0 0 16px; font-variant-numeric: tabular-nums; }
.thread { display: flex; flex-direction: column; gap: 12px; margin: 0 0 16px; padding: 0; list-style: none; }
.msg { display: flex; min-width: 0; }
.msg-user { justify-content: flex-end; }
.msg-assistant { justify-content: flex-start; }
.msg-system { justify-content: center; }
.bubble {
  max-width: min(88%, 640px); min-width: 0; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card);
}
.msg-user .bubble { background: var(--accent-tint); border-color: var(--accent-line); border-bottom-right-radius: 4px; }
.msg-assistant .bubble { border-bottom-left-radius: 4px; }
.msg-system .bubble { max-width: 100%; background: var(--warn-tint); border-color: var(--warn-line); }
.msg-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 2px; color: var(--text-2); font-size: 13px; }
.msg-meta .who { color: var(--text); font-weight: 650; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.note { margin: 8px 0 0; color: var(--warn); font-size: 16px; overflow-wrap: anywhere; }
.proposal {
  margin-top: 10px; padding: 12px; min-width: 0;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.proposal-label {
  margin: 0 0 4px; color: var(--text-2); font-size: 12px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.proposal-summary { margin: 0 0 6px; font-weight: 600; overflow-wrap: anywhere; }
.proposal-state { margin: 0; color: var(--text-2); font-size: 16px; overflow-wrap: anywhere; }
.proposal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.empty-chat { padding: 20px; text-align: center; color: var(--text-2); }
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card);
}
.composer textarea { flex: 1; min-width: 0; min-height: 48px; }
.composer button { flex: none; }
.chat-tools {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  margin-top: 8px; color: var(--text-2); font-size: 14px;
}
.chat-tools button.link { font-size: 14px; }

/* ---------------------------------------------------------------- AI chat widget (base.html + /assets/chat.js)
   A floating bubble at the bottom right of every logged-in page (except /chat) that opens a small chat
   window; on phones the window is a full-width bottom sheet. Messages reuse the /chat page's .msg, .bubble
   and .proposal rules. Hidden until the script runs (the `hidden` attribute). On wide screens the window's
   top stays below the 60px top bar (Logout stays reachable). */

[hidden] { display: none !important; }
.site-footer.has-chatw { padding-bottom: 96px; }

.chatw-bubble {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  width: 56px; height: 56px; min-height: 0; padding: 0; border-radius: 50%;
}
.chatw-icon { width: 26px; height: 26px; fill: currentColor; }
.chatw.is-open .chatw-bubble { background: var(--btn-hover); }

.chatw-panel {
  position: fixed; right: 20px; bottom: 88px; z-index: 60;
  display: flex; flex-direction: column;
  width: 400px; max-width: calc(100vw - 32px);
  height: min(620px, max(320px, calc(100vh - 160px))); height: min(620px, max(320px, calc(100dvh - 160px)));
  background: var(--surface); border: 1px solid var(--field-line); border-radius: var(--radius-card);
  overflow: hidden;
}
.chatw-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--line);
}
.chatw-head-actions { display: flex; align-items: center; gap: 2px; }
.chatw-tool {
  display: inline-flex; align-items: center; min-height: 40px; padding: 8px 10px;
  border: 0; border-radius: var(--radius); background: none;
  color: var(--link); font: inherit; font-size: 14px; font-weight: 550; text-decoration: none;
}
.chatw-tool:hover { background: var(--surface-2); color: var(--link); text-decoration: none; }
.chatw-close {
  width: 40px; height: 40px; min-height: 0; padding: 0;
  border: 0; background: none; color: var(--text-2);
}
.chatw-close:hover { background: var(--surface-2); color: var(--text); }
.chatw-close svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
}
.chatw-spend {
  margin: 0; padding: 6px 16px; border-bottom: 1px solid var(--line);
  color: var(--text-2); font-size: 14px; font-variant-numeric: tabular-nums;
}
.chatw-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 12px; background: var(--bg);
}
.chatw-body > .callout { margin: 0; }
.chatw-empty { margin: 8px 4px; color: var(--text-2); font-size: 16px; text-align: center; }
.chatw-thread { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.chatw .bubble { max-width: 90%; padding: 8px 12px; }
.chatw .msg-system .bubble { max-width: 100%; }
.chatw .proposal-actions button { min-height: 40px; padding: 8px 14px; }
.chatw-typing {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card);
  border-bottom-left-radius: 4px; color: var(--text-2); font-size: 14px;
}
.chatw-dots { display: inline-flex; gap: 3px; }
.chatw-dots i {
  display: block; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: chatw-blink 1.2s infinite ease-in-out;
}
.chatw-dots i:nth-child(2) { animation-delay: 0.2s; }
.chatw-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatw-blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .chatw-dots i { animation: none; opacity: 0.6; }
}
.chatw-error {
  margin: 0; padding: 8px 16px; border-top: 1px solid var(--warn-line);
  background: var(--warn-tint); color: var(--warn); font-size: 16px; overflow-wrap: anywhere;
}
.chatw-composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 4px;
  border-top: 1px solid var(--line); background: var(--surface);
}
/* grows with its text up to max-height (Firefox has no field-sizing: chat.js sets the height there) */
.chatw-composer textarea {
  flex: 1; min-width: 0; min-height: 44px; max-height: 160px; padding: 10px 12px;
  font-size: 16px; resize: none; field-sizing: content;
}
.chatw-send { flex: none; min-height: 44px; padding: 10px 16px; }
.chatw button:disabled { opacity: 0.6; cursor: progress; }
.chatw-hint { margin: 0; padding: 2px 12px 10px; background: var(--surface); color: var(--text-2); font-size: 13px; }
/* touch screens: no Shift+Enter on a phone keyboard, so no new-line hint */
.chatw-hint-touch { display: none; }
@media (pointer: coarse) {
  .chatw-hint-keys { display: none; }
  .chatw-hint-touch { display: inline; }
}

@media (max-width: 599px) {
  .chatw-bubble { right: 16px; bottom: 16px; }
  .chatw.is-open .chatw-bubble { display: none; }
  .chatw-panel {
    left: 0; right: 0; bottom: 0; width: 100%; max-width: none;
    height: 85vh; height: 85dvh;
    border-width: 1px 0 0; border-radius: var(--radius-card) var(--radius-card) 0 0;
  }
}

/* ---------------------------------------------------------------- manual forms (settings, add / stop / remove a stock) */

.optional { margin-left: 6px; color: var(--text-2); font-size: 14px; font-weight: 400; }
.form-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; margin-bottom: 4px;
}
.form-grid .field { min-width: 0; }
.form-grid .hint { font-size: 14px; }
button.danger { background: var(--bad); color: var(--btn-text); }
button.danger:hover { background: var(--bad); filter: brightness(0.92); }
button.danger-outline { color: var(--bad); border-color: var(--bad-line); }
button.danger-outline:hover { background: var(--bad-tint); }
.section-form { margin-top: 12px; }
.pos-actions { margin-top: 10px; }
.pos-actions summary {
  display: inline-flex; align-items: center; min-height: 40px; padding: 6px 0;
  color: var(--link); font-size: 15px; font-weight: 600; cursor: pointer;
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 2px;
}
.pos-actions summary:hover { text-decoration-color: currentColor; }
.pos-actions[open] summary { color: var(--text); }
.pos-actions-body {
  display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 16px;
  margin-top: 8px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2);
}
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 12px; flex: 1 1 320px; }
.inline-form .field { flex: 1 1 200px; margin: 0; }
.inline-form .hint { font-size: 14px; }
.inline-form button { margin-top: 30px; }
.remove-form { flex: none; margin-top: 30px; }
.confirm-lines { margin: 8px 0 16px; padding-left: 20px; }
.confirm-lines li { margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.confirm-note { margin: 16px 0 0; font-size: 14px; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 879px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 599px) {
  .topbar-inner { padding: 8px 16px 6px; }
  .nav { width: calc(100% + 16px); margin: 0 -8px; justify-content: space-between; }
  .nav a, .nav .nav-button { padding: 8px; }
  main { padding: 16px 16px 24px; }
  main.narrow { padding-top: 16px; }
  h1 { font-size: 22px; }
  .card { padding: 16px; }
  .auth-card { padding: 20px 16px; }
  .range-labels { gap: 8px; font-size: 13px; }
  .range-labels .lbl-name, .range-labels .lbl-price, .range-labels .lbl-pct { display: block; }
  .bubble { max-width: 92%; }
  .composer { flex-direction: column; align-items: stretch; }
  .composer button { width: 100%; }
}
@media (max-width: 479px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .inline-form button, .remove-form, .remove-form button, .confirm-actions > * { width: 100%; }
  .inline-form button, .remove-form { margin-top: 0; }
}
/* six nav links (Settings and Paper added 2026-10-19) still fit one row from a 360px phone up, and the
   top bar is one 60px row from 640px up (measured in Chromium with system-ui, as the five links were) */
@media (max-width: 599px) {
  .nav { gap: 0; }
  .nav a, .nav .nav-button { padding: 8px clamp(3px, 1vw, 8px); font-size: clamp(13px, 3.6vw, 15px); }
}
@media (min-width: 600px) and (max-width: 699px) {
  .nav a, .nav .nav-button { padding: 8px; }
}

/* ---------------------------------------------------------------- PAPER pages (/paper, /paper/watchlist) */

.table-wrap { overflow-x: auto; margin: 0 0 12px; -webkit-overflow-scrolling: touch; }
.ptable { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.ptable th, .ptable td { padding: 8px 10px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
.ptable thead th { border-top: 0; color: var(--text-2); font-size: 13px; font-weight: 600; }
.ptable tbody th { font-weight: 700; }
.symlist { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.symlist li {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2);
}
.symlist .sym { font-weight: 650; }
.symlist form { display: flex; }
.symlist button.link { min-height: 32px; padding: 4px 6px; font-size: 15px; }
input[type="file"] { display: block; max-width: 100%; font-size: 16px; }

/* ---------------------------------------------------------------- "Stock add karo" by name (/stocks/find, /stocks/pick; 2026-10-20) */

.find-form { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 12px; }
.find-form .field { flex: 1 1 280px; margin: 0; }
.find-form .hint { font-size: 14px; }
.find-form button { margin-top: 30px; }
.find-or { margin: 16px 0 8px; font-size: 15px; }
.find-count { margin: 16px 0 8px; font-size: 15px; }
.find-list { margin: 0; padding: 0; list-style: none; }
.find-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.find-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; min-width: 0; overflow-wrap: anywhere; }
.find-pick { flex: none; }
.find-note { font-size: 14px; }
.find-back { margin: 16px 0 0; font-size: 15px; }
.find-pick button { min-height: 44px; }
@media (max-width: 479px) {
  .find-form button { width: 100%; margin-top: 0; }
}
.universe-line { font-weight: 600; }
.auto-list summary { min-height: 40px; padding: 6px 0; color: var(--link); font-size: 15px; font-weight: 600; cursor: pointer; }

/* ---------------------------------------------------------------- Stock check (/check, Gates v0 2026-10-19) */

.gtable td { white-space: normal; min-width: 7rem; }
.gtable td:nth-child(3) { min-width: 16rem; }
.gate-details { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); font-size: 14px; }
.gate-bad { color: var(--bad); font-weight: 650; }
.gate-warn { color: var(--warn); font-weight: 650; }
.gate-ok { color: var(--ok); font-weight: 650; }
.gate-muted { color: var(--text-2); font-weight: 650; }
@media (max-width: 599px) {
  .gtable, .gtable tbody { display: block; width: 100%; }
  .gtable thead { display: none; }
  .gtable tr { display: block; padding: 10px 0; border-top: 1px solid var(--line); }
  .gtable th, .gtable td { display: block; min-width: 0; padding: 2px 0; border-top: 0; white-space: normal; overflow-wrap: anywhere; }
  .gtable td:nth-child(3) { min-width: 0; }
}
