:root {
  --bg: #0e1217;
  --surface: #161c24;
  --surface-2: #1d2530;
  --line: #2a3441;
  --text: #e8edf3;
  --muted: #93a1b3;
  --accent: #d4a72c;
  --up: #2fb5a0;
  --down: #f0715c;
  --warn: #f2b632;
  --warn-bg: #3a2f0f;
  --info: #5aa9f0;
  --ok: #3fbf7f;
  --bad: #ff6b6b;
  --focus: #8ab4ff;
  --radius: 12px;
  --gutter: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eef0f3; --line: #d9dde3;
    --text: #151a21; --muted: #5b6676; --accent: #9a7410; --up: #12806f; --down: #c6412c;
    --warn: #8a5a00; --warn-bg: #fff2cf; --info: #1a62b3; --ok: #1b7f4b; --bad: #b3261e; --focus: #1a62b3;
  }
}
:root[data-theme="light"] {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eef0f3; --line: #d9dde3;
  --text: #151a21; --muted: #5b6676; --accent: #9a7410; --up: #12806f; --down: #c6412c;
  --warn: #8a5a00; --warn-bg: #fff2cf; --info: #1a62b3; --ok: #1b7f4b; --bad: #b3261e; --focus: #1a62b3;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font);
  min-height: 100vh; overflow-x: hidden;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 8px; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
a { color: var(--info); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.error { color: var(--bad); min-height: 1.2em; }

/* ---------- layout: sidebar + main (drawer on phones, fixed on desktop) ---------- */
.shell { display: block; min-height: 100vh; min-height: 100dvh; }
.side {
  position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(86vw, 320px); transform: translateX(-102%); visibility: hidden;
  transition: transform .2s ease, visibility 0s linear .2s; display: flex; flex-direction: column; gap: 10px; padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface); border-right: 1px solid var(--line);
}
.shell.open .side { transform: none; visibility: visible; transition: transform .2s ease; }
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .55); }
.scrim[hidden] { display: none; }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 4px; }
.mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #17130a; font-weight: 800; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg, .newchat svg, .navlink svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.newchat { display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; text-decoration: none; min-height: 44px; }
.newchat svg { width: 20px; height: 20px; }
.side-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 6px 0; }
.convlist { flex: 1; min-height: 80px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; overscroll-behavior: contain; }
.convrow { position: relative; display: flex; align-items: center; border-radius: 8px; }
.convrow:hover, .convrow:focus-within { background: var(--surface-2); }
.convitem { flex: 1; min-width: 0; display: block; padding: 10px 40px 10px 10px; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 8px; min-height: 40px; }
.convitem[aria-current="page"] { background: var(--surface-2); font-weight: 600; }
.convdel { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; opacity: .75; }
.convdel:hover, .convdel:focus-visible { color: var(--bad); background: var(--bg); opacity: 1; }
.pad { padding: 8px 6px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 8px; }
.navlink { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 8px 10px; color: var(--text); text-decoration: none; font-size: 15px; border-radius: 8px; }
.navlink:hover { background: var(--surface-2); }
.navlink[aria-current="page"] { background: var(--surface-2); color: var(--accent); font-weight: 600; }
.side-note { margin: 0; padding: 0 8px; color: var(--muted); font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.top {
  display: flex; align-items: center; gap: 8px 12px; padding: 8px var(--gutter); position: sticky; top: 0; z-index: 10;
  background: var(--bg); border-bottom: 1px solid var(--line); min-height: 56px;
}
.top h1 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
.pills { display: flex; flex-wrap: nowrap; gap: 6px; align-items: center; overflow-x: auto; max-width: 62%; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
#view { flex: 1; padding: var(--gutter); width: 100%; max-width: 1100px; outline: none; min-width: 0; }
#view > * + * { margin-top: 14px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tab { padding: 10px 14px; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; min-height: 44px; display: flex; align-items: center; }
.tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.only-desktop { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 280px 1fr; }
  .side { position: sticky; top: 0; height: 100vh; height: 100dvh; width: auto; transform: none; visibility: visible; transition: none; }
  .scrim { display: none !important; }
  .only-mobile { display: none !important; }
  .only-desktop { display: initial; }
  .top { padding: 10px 24px; }
  #view { padding: 20px 24px; }
  .pills { max-width: none; flex-wrap: wrap; overflow: visible; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
  .grid-2 > *, .grid-3 > * { margin-top: 0 !important; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card > h2 + * { margin-top: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  font-weight: 600; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.badge.sample { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
.badge.imported { color: var(--info); border-color: var(--info); background: transparent; }
.badge.delayed { color: var(--warn); border-color: var(--warn); background: transparent; }
.badge.live { color: var(--ok); border-color: var(--ok); background: transparent; }
.badge.off { color: var(--muted); }
.badge.closed { color: var(--info); border-color: var(--info); background: transparent; border-style: dashed; }
.badge.ok { color: var(--ok); border-color: var(--ok); background: transparent; }
.badge.bad { color: var(--bad); border-color: var(--bad); background: transparent; }
.badge.practice { color: var(--muted); border-style: dashed; }

.banner {
  border-radius: var(--radius); padding: 10px 12px; font-size: 14px; border: 1px solid var(--line); background: var(--surface);
}
.banner.sample {
  border-color: var(--warn); color: var(--text);
  background: repeating-linear-gradient(-45deg, var(--warn-bg), var(--warn-bg) 10px, var(--surface) 10px, var(--surface) 20px);
}
.banner.sample strong { color: var(--warn); }
.banner.info { border-color: var(--info); }
.banner.off { border-style: dashed; }
.banner.warn { border-color: var(--bad); }

.btn {
  font: inherit; min-height: 44px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #17130a; font-weight: 600; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 88px; resize: vertical; }
input:disabled, textarea:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; }
.field { margin-bottom: 10px; }
.fields-2 { display: block; }
@media (min-width: 640px) { .fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; } }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(5, 1fr); } }
.tile { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tiles.sample .tile { outline: 1px dashed var(--warn); }

.chart-wrap { width: 100%; overflow: hidden; touch-action: pan-y; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.readout { min-height: 22px; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); margin-top: 6px; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.c-up { stroke: var(--up); fill: none; stroke-width: 1.5; }
.c-down { stroke: var(--down); fill: var(--down); stroke-width: 1.5; }
.c-wick-up { stroke: var(--up); stroke-width: 1.2; }
.c-wick-down { stroke: var(--down); stroke-width: 1.2; }
.c-last { stroke: var(--accent); stroke-dasharray: 4 3; stroke-width: 1; }
.c-lasttag { fill: var(--accent); }
.c-lasttext { fill: #17130a; font-size: 11px; font-weight: 700; }
.c-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.c-wm { fill: var(--warn); opacity: 0.16; font-size: 44px; font-weight: 800; letter-spacing: 6px; font-family: var(--font); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.entry.practice { background: repeating-linear-gradient(-45deg, transparent, transparent 14px, var(--surface-2) 14px, var(--surface-2) 15px); }
.entry .rationale { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 6px; }
.hash { font-family: var(--mono); font-size: 11px; color: var(--muted); }

.chat-log { min-height: 160px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 90%; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.bubble.system { align-self: center; max-width: 100%; border: 1px dashed var(--line); background: transparent; color: var(--muted); font-size: 14px; }

.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; padding: 16px; }
.overlay[hidden] { display: none; }
.login { width: min(420px, 100%); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); background: var(--surface-2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 10px; z-index: 40; max-width: 92vw; }

@media (prefers-reduced-motion: no-preference) { .btn { transition: background-color 0.12s; } }
.c-wm.c-wm-sm { font-size: 28px; letter-spacing: 3px; }

/* ---------- live spot, research, assistant ---------- */
.bigprice { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; line-height: 1.1; }
.tiny { font-size: 11px; }
.stance { font-size: 22px; font-weight: 700; }
.stance-bullish_lean { color: var(--up); }
.stance-bearish_lean { color: var(--down); }
.stance-neutral, .stance-insufficient { color: var(--muted); }
.bullets { margin: 6px 0 0; padding-left: 20px; }
.bullets li { margin: 4px 0; overflow-wrap: anywhere; }
.evidence { list-style: none; margin: 0; padding: 0; }
.evidence li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.evidence li:first-child { border-top: 0; }
.dir { font-size: 18px; text-align: center; line-height: 1.3; }
.dir-up { color: var(--up); } .dir-down { color: var(--down); } .dir-flat { color: var(--muted); }
.tablewrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.field.inline { margin: 0; min-width: 130px; }
details.card > summary { cursor: pointer; font-weight: 600; }
pre.mono { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 0; }

/* ---------- chat ---------- */
body.chatmode #view { max-width: none; padding: 0; display: flex; flex-direction: column; }
body.chatmode #view > * + * { margin-top: 0; }
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; max-width: 860px; margin: 0 auto; }
.thread { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 16px var(--gutter) 8px; overflow-y: auto; min-height: 0; }
.hero { margin: auto; text-align: center; padding: 24px var(--gutter); max-width: 560px; }
.hero h2 { font-size: 24px; margin-bottom: 6px; }
.hero .chips { justify-content: center; margin-top: 16px; }
.bubble { max-width: 100%; }
.bubble.user { align-self: flex-end; max-width: 86%; background: var(--accent); color: #17130a; padding: 10px 14px; border-radius: 18px 18px 4px 18px; }
.bubble.assistant { align-self: stretch; padding: 2px 0 2px 12px; border-left: 3px solid var(--line); }
.bubble.assistant.model { border-left-color: var(--info); }
.bubble.assistant.rule { border-left-color: var(--ok); }
.bubble.assistant.error { border-left-color: var(--bad); }
.bubble.system { align-self: center; color: var(--muted); font-size: 14px; }
.bubble .msgtext { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .meta { margin-top: 6px; }
.bubble.user .muted { color: #3a3012; }
.bubble a { color: var(--info); }
.bubble.user a { color: #17130a; }
.composer {
  position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 78%, transparent); padding: 8px var(--gutter) calc(10px + env(safe-area-inset-bottom));
}
.composer .box { display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 6px 6px 6px 14px; }
.composer .box:focus-within { border-color: var(--focus); }
.composer textarea { flex: 1; min-height: 40px; max-height: 160px; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; padding: 9px 0; }
.composer .send { min-width: 64px; min-height: 40px; border-radius: 14px; }
.composer .hint { margin: 4px 6px 0; font-size: 12px; color: var(--muted); }
.chips { gap: 6px; }
.chip { min-height: 38px; padding: 4px 12px; border-radius: 999px; font-size: 13px; }
.setting { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 10px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.setting .what { flex: 1 1 260px; min-width: 0; }
.tag-planned { color: var(--muted); border-style: dashed; }
.msgtext.md { white-space: normal; }
.md > * + * { margin-top: 8px; }
.md p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.md .mdh { font-weight: 700; }
.md ul, .md ol { margin: 0; padding-left: 22px; }
.md li { margin: 3px 0; overflow-wrap: anywhere; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md pre.mono { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 0; }
.md pre.mono code { background: transparent; padding: 0; }
.md .tablewrap { max-width: 100%; }
