/* Trade Scout: "calm & trustworthy". Deep navy and warm paper, one teal accent, Inter.
   Two themes: paper (light) and navy (dark). The page follows the computer's setting unless the
   header toggle picks one (stored in this browser). Colour names (--card, --accent, --good...) are
   also read by the chart and the scripts, so keep them. */

@font-face {
  font-family: "Inter";
  src: url("/static/inter-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --navy: #0F1B2D;
  --bg: #F7F5F0;          /* paper */
  --card: #FFFFFF;
  --raised: #FBFAF6;
  --line: #E5E1D8;
  --fg: #13233A;
  --muted: #5E6B7C;
  --accent: #0E8F84;      /* teal, deepened for contrast on paper */
  --accent-ink: #FFFFFF;
  --accent-soft: #0E8F8414;
  --good: #1E9A5E;
  --bad: #D2453D;
  --warn: #B7791F;
  --band: #0E8F841F;
  --tip-bg: #0F1B2D;
  --tip-fg: #F3F6FA;
  --head-bg: #0F1B2D;
  --head-fg: #EAF0F7;
  --head-muted: #9FB0C6;
  --shadow: 0 1px 2px #0F1B2D0F, 0 6px 22px #0F1B2D0B;
  --radius: 14px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0F1B2D;          /* navy */
  --card: #15243A;
  --raised: #1A2C46;
  --line: #24385A;
  --fg: #EAF0F7;
  --muted: #93A3BA;
  --accent: #1FB5A8;
  --accent-ink: #0F1B2D;
  --accent-soft: #1FB5A81C;
  --good: #2BB673;
  --bad: #E5534B;
  --warn: #E8B04B;
  --band: #1FB5A828;
  --tip-bg: #EAF0F7;
  --tip-fg: #0F1B2D;
  --head-bg: #0B1524;
  --head-fg: #EAF0F7;
  --head-muted: #8FA1B9;
  --shadow: 0 1px 2px #00000040, 0 10px 30px #00000035;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0F1B2D; --card: #15243A; --raised: #1A2C46; --line: #24385A; --fg: #EAF0F7; --muted: #93A3BA;
    --accent: #1FB5A8; --accent-ink: #0F1B2D; --accent-soft: #1FB5A81C; --good: #2BB673; --bad: #E5534B;
    --warn: #E8B04B; --band: #1FB5A828; --tip-bg: #EAF0F7; --tip-fg: #0F1B2D; --head-bg: #0B1524;
    --head-fg: #EAF0F7; --head-muted: #8FA1B9; --shadow: 0 1px 2px #00000040, 0 10px 30px #00000035;
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.6 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss03";
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
main { max-width: 1180px; margin: 0 auto; padding: 26px 22px 64px; }
h1 { font-size: 28px; line-height: 1.2; font-weight: 700; letter-spacing: -0.02em; margin: 4px 0 6px; }
h2 { font-size: 18px; font-weight: 650; letter-spacing: -0.01em; margin: 34px 0 12px; }
h3 { font-size: 15.5px; font-weight: 650; margin: 24px 0 8px; }
h4, h5 { font-size: 14px; font-weight: 650; margin: 18px 0 6px; }
.sub { color: var(--muted); margin: 0 0 8px; font-size: 14px; }
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.num, td.num, th.num, .tile > b { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- header */
header { position: sticky; top: 0; z-index: 10; background: var(--head-bg); color: var(--head-fg); box-shadow: 0 1px 0 #ffffff10; }
nav { max-width: 1180px; margin: 0 auto; padding: 0 22px; height: 58px; display: flex; gap: 4px; align-items: center; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--head-fg); font-weight: 700; font-size: 16.5px;
  letter-spacing: -0.01em; margin-right: 18px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; flex: none; }
nav a.link { color: var(--head-muted); padding: 7px 11px; border-radius: 9px; font-size: 14px; font-weight: 500; }
nav a.link:hover { color: var(--head-fg); background: #ffffff10; text-decoration: none; }
nav a.link.on { color: var(--head-fg); background: #1FB5A824; box-shadow: inset 0 -2px 0 #1FB5A8; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
nav .pill { background: #ffffff10; border-color: #ffffff22; color: var(--head-muted); }
#theme-toggle { background: transparent; border: 1px solid #ffffff22; color: var(--head-fg); padding: 5px 9px; border-radius: 9px; font-size: 14px; line-height: 1; }
#theme-toggle:hover { border-color: #1FB5A8; }
@media (max-width: 860px) { nav { height: auto; flex-wrap: wrap; padding: 8px 14px; } .brand { margin-right: 6px; } }

/* ---------------------------------------------------------------- surfaces */
.banner { padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); border-left: 4px solid var(--accent);
  background: var(--card); margin: 12px 0; box-shadow: var(--shadow); }
.banner.good { border-left-color: var(--good); color: var(--fg); }
.banner.bad { border-left-color: var(--bad); color: var(--fg); }
.banner.warn { border-left-color: var(--warn); color: var(--fg); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile > b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; }
.tile > span { color: var(--muted); font-size: 12.5px; line-height: 1.45; display: block; margin-top: 2px; }
.empty { color: var(--muted); padding: 16px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.doc { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 24px 18px; box-shadow: var(--shadow); }
.doc table { font-size: 14px; } .doc hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
pre { white-space: pre-wrap; background: var(--raised); border: 1px solid var(--line); padding: 10px 12px; border-radius: 10px; font-size: 13px; }
code { background: var(--raised); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; font-size: 0.92em; }
pre code { background: none; border: 0; padding: 0; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 13px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--raised); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover td { background: var(--accent-soft); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
table.kv th { width: 190px; text-transform: none; letter-spacing: 0; font-size: 13px; background: var(--raised); }

/* ---------------------------------------------------------------- pills and status */
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--line); color: var(--muted); background: var(--raised); white-space: nowrap; }
.pill.s-waiting { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.pill.s-open { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.pill.s-closed { color: var(--muted); }
.pill.s-cancelled { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: color-mix(in srgb, var(--bad) 9%, transparent); }
.pill.d-long { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.pill.d-short { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

/* The stop-to-target bar */
.where { position: relative; height: 8px; min-width: 130px; border-radius: 5px;
  background: linear-gradient(90deg, var(--bad) 0, color-mix(in srgb, var(--bad) 35%, var(--line)) 22%, var(--line) 45%,
    color-mix(in srgb, var(--good) 35%, var(--line)) 78%, var(--good) 100%); }
.where i { position: absolute; top: -5px; width: 4px; height: 18px; background: var(--fg); border-radius: 3px; box-shadow: 0 0 0 2px var(--card); }
.where em { position: absolute; top: -1px; height: 10px; background: var(--band); border: 1px solid var(--accent); border-radius: 4px; }

/* ---------------------------------------------------------------- buttons */
.btns { display: flex; gap: 10px; flex-wrap: wrap; }
button, .btn { font: inherit; font-size: 14px; font-weight: 550; border: 1px solid var(--line); background: var(--card); color: var(--fg);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; transition: border-color .15s, background .15s; }
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
button:focus-visible, .btn:focus-visible, a:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }
.job { font-size: 12.5px; color: var(--muted); margin-top: 8px; white-space: pre-wrap; }

/* ---------------------------------------------------------------- chart */
#chart { height: 470px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden; box-shadow: var(--shadow); }
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.legend span::before { content: ""; display: inline-block; width: 16px; height: 3px; border-radius: 2px; margin-right: 7px; vertical-align: middle; background: var(--c); }

footer { max-width: 1180px; margin: 0 auto; padding: 0 22px 34px; color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- glossary bubbles */
.term { border-bottom: 1px dotted color-mix(in srgb, var(--muted) 70%, transparent); cursor: help; }
.term:focus { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.ib { display: inline-block; width: 15px; height: 15px; margin-left: 3px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  font: 700 10px/15px "Inter", system-ui, sans-serif; text-align: center; vertical-align: super; text-transform: none; letter-spacing: 0; font-style: normal; }
#tip { position: absolute; z-index: 50; display: none; background: var(--tip-bg); color: var(--tip-fg); padding: 10px 13px; border-radius: 11px;
  font-size: 13px; line-height: 1.55; box-shadow: 0 12px 34px #0F1B2D40; max-width: 340px; text-transform: none; letter-spacing: 0; font-weight: 400; }

/* ---------------------------------------------------------------- the Ask panel */
/* With the panel open, the page is centred in the space to its left (not on the whole screen), and uses
   all of that space up to a comfortable reading width. */
body.chat-open { --free: calc(100vw - 390px); --page: min(1440px, var(--free)); }
body.chat-open main, body.chat-open footer, body.chat-open nav {
  max-width: var(--page); margin-left: max(0px, calc((var(--free) - var(--page)) / 2)); margin-right: 390px; }
body.chat-open main { padding-left: 28px; padding-right: 28px; }
#chat { position: fixed; top: 0; right: 0; bottom: 0; width: 390px; z-index: 20; background: var(--card); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; box-shadow: -8px 0 30px #0F1B2D14; }
body.chat-closed #chat { display: none; } body.chat-open #chat-toggle { display: none; }
#chat-toggle { position: fixed; right: 20px; bottom: 20px; z-index: 20; border-radius: 26px; padding: 11px 18px; font-weight: 650;
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: 0 8px 24px #0F1B2D33; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 58px; background: var(--head-bg); color: var(--head-fg); }
.chat-head b { margin-right: auto; display: flex; align-items: center; gap: 8px; font-size: 15px; }
.chat-head b svg { width: 22px; height: 22px; }
.chat-head select, .chat-head button { font-size: 13px; padding: 5px 9px; background: #ffffff12; color: var(--head-fg); border: 1px solid #ffffff26; border-radius: 8px; }
.chat-head select option { color: #13233A; }
.chat-bar { display: flex; gap: 6px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--card); }
.chat-bar select { flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 6px 8px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
.chat-bar button { font-size: 13px; padding: 6px 10px; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; background: var(--bg); }
.msg { padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.55; max-width: 94%; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); white-space: pre-wrap; border-bottom-right-radius: 5px; }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; box-shadow: var(--shadow); }
.msg.ai p { margin: 0 0 8px; } .msg.ai p:last-child { margin: 0; } .msg.ai ul, .msg.ai ol { margin: 4px 0 8px; padding-left: 20px; }
.msg.ai h2, .msg.ai h3, .msg.ai h4 { font-size: 14px; margin: 8px 0 4px; } .msg.ai .table-wrap { font-size: 12px; box-shadow: none; }
.msg.pending { white-space: pre-wrap; color: var(--muted); } .msg.error { color: var(--bad); }
.chat-status { font-size: 12px; color: var(--muted); padding: 6px 14px 2px; min-height: 22px; background: var(--card); }
#chat form { display: flex; gap: 8px; padding: 10px 14px; background: var(--card); }
#chat textarea { flex: 1; resize: none; height: 62px; font: inherit; font-size: 14px; padding: 9px 11px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
.chat-foot { font-size: 11px; color: var(--muted); padding: 0 14px 12px; background: var(--card); }
@media (max-width: 1000px) {
  body.chat-open main, body.chat-open footer, body.chat-open nav { max-width: 1180px; margin-left: auto; margin-right: auto; }
  #chat { width: 100%; }
}

/* ---------------------------------------------------------------- chart toolbar (candle length, range) */
.chart-tools { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; }
.chart-tools .seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; box-shadow: var(--shadow); }
.chart-tools button { border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.chart-tools button:hover { color: var(--fg); background: var(--accent-soft); }
.chart-tools button.on { background: var(--accent); color: var(--accent-ink); }

/* ---------------------------------------------------------------- watchlist */
.add-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 14px 0 6px; }
.add-form input, details.edit input { font: inherit; font-size: 14px; padding: 8px 11px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); }
.add-form input[name=ticker] { width: 170px; text-transform: uppercase; }
.add-form input[name=note] { flex: 1; min-width: 220px; }
details.edit summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }
details.edit[open] { min-width: 300px; }
details.edit form { display: grid; gap: 10px; margin-top: 10px; }
details.edit fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 10px; display: grid; gap: 6px; }
details.edit legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
details.edit label { display: grid; gap: 3px; font-size: 12.5px; color: var(--muted); }
details.edit input { width: 100%; padding: 6px 9px; }

/* Sign-in (only on the server, where the app is reachable from the internet) */
.sign-out { margin: 0; }
.sign-out button { background: transparent; border: 1px solid #ffffff22; color: var(--head-fg); padding: 5px 9px; border-radius: 9px; font-size: 13px; }
.sign-out button:hover { border-color: #1FB5A8; }
main.login { max-width: 360px; margin: 12vh auto; }
main.login form { display: flex; flex-direction: column; gap: 10px; }
main.login input[type=password] { font: inherit; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: inherit; }
.login-error { color: var(--bad); }
