/* Dark-first, like every trading terminal this sits next to. The light palette is a full redefinition rather than a filter, so
   neither theme is an afterthought. */

:root {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --bg-input: #1c2128;
  --border: #272e38;
  --border-strong: #3a434f;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-faint: #6b7480;
  --accent: #f5b942;
  --accent-dim: #b7791f;
  --accent-soft: rgba(245, 185, 66, .12);
  --long: #22c55e;
  --short: #ef4444;
  --user-bubble: #1f6feb;
  --user-text: #ffffff;
  --tool: #a78bfa;
  --tool-soft: rgba(167, 139, 250, .10);
  --warn: #f0b429;
  --warn-soft: rgba(240, 180, 41, .10);
  --danger: #f85149;
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --bg-raised: #ffffff;
    --bg-input: #ffffff;
    --border: #d9dee4;
    --border-strong: #c2c9d1;
    --text: #1f2328;
    --text-dim: #5b6572;
    --text-faint: #848d97;
    --accent: #b7791f;
    --accent-dim: #b7791f;
    --accent-soft: rgba(183, 121, 31, .10);
    --long: #15803d;
    --short: #b91c1c;
    --user-bubble: #0969da;
    --tool: #6d4aff;
    --tool-soft: rgba(109, 74, 255, .07);
    --warn: #9a6700;
    --warn-soft: rgba(154, 103, 0, .08);
    --danger: #cf222e;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 920px;
  margin: 0 auto;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent-dim);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
}

.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; }
.brand-text p {
  margin: 0; font-size: 11.5px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background .13s, border-color .13s, opacity .13s;
}

.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
  padding: 5px 11px;
}
.ghost:hover { background: var(--bg-raised); color: var(--text); }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  margin-inline-start: 4px;
}
.dot.ok { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dot.bad { background: var(--danger); box-shadow: 0 0 0 3px rgba(248, 81, 73, .12); }

/* -------------------------------------------------------------- messages */

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 22px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.messages::-webkit-scrollbar { width: 9px; }
.messages::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 5px;
  border: 2px solid var(--bg);
}

.welcome { margin: auto 0; text-align: center; padding: 20px 0 30px; }
.welcome h2 { font-size: 21px; font-weight: 600; margin: 0 0 10px; }
.welcome-note {
  color: var(--text-dim); font-size: 13.5px; margin: 0 auto 24px;
  max-width: 480px; line-height: 1.85;
}
.welcome-note strong { color: var(--warn); font-weight: 600; }

.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 9px;
  text-align: start;
}
.suggestion {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 11px 14px;
  text-align: start;
  font-size: 13.5px;
  line-height: 1.6;
  border-radius: var(--radius-sm);
}
.suggestion:hover {
  border-color: var(--accent-dim);
  color: var(--text);
  background: var(--accent-soft);
}

.msg { display: flex; flex-direction: column; gap: 8px; }
.msg.user { align-items: flex-start; }

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-end-start-radius: 4px;
}

.msg.bot .bubble {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-end-end-radius: 4px;
  max-width: 100%;
  width: 100%;
}

.bubble strong { font-weight: 600; }
.bubble ul { margin: 8px 0; padding-inline-start: 20px; }
.bubble li { margin: 3px 0; }
.bubble code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--bg-input);
  padding: 1px 5px;
  border-radius: 4px;
  direction: ltr;
  display: inline-block;
}
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ tool cards */

.tool {
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--tool);
  border-radius: var(--radius-sm);
  background: var(--tool-soft);
  overflow: hidden;
  font-size: 13px;
}

.tool summary {
  cursor: pointer;
  padding: 8px 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  list-style: none;
  user-select: none;
}
.tool summary::-webkit-details-marker { display: none; }

.tool-name {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--tool);
  direction: ltr;
  font-weight: 500;
}
.tool-state { color: var(--text-faint); font-size: 11.5px; margin-inline-start: auto; }
.tool-state.ok { color: var(--accent); }
.tool-state.bad { color: var(--danger); }

.tool pre {
  margin: 0;
  padding: 10px 13px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  direction: ltr;
  text-align: left;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 320px;
  color: var(--text-dim);
}

/* The spinner only exists while a tool is in flight. */
.spin {
  width: 11px; height: 11px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--tool);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------- proposed action */

.proposal {
  border: 1px solid var(--warn);
  background: var(--warn-soft);
  border-radius: var(--radius-sm);
  padding: 12px 15px;
  font-size: 13.5px;
}
.proposal h4 {
  margin: 0 0 7px;
  font-size: 13px;
  color: var(--warn);
  display: flex;
  align-items: center;
  gap: 7px;
}
.proposal pre {
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  direction: ltr;
  text-align: left;
  overflow-x: auto;
  background: var(--bg);
  padding: 9px 11px;
  border-radius: 6px;
  max-height: 260px;
  white-space: pre-wrap;
  word-break: break-all;
}

.meta {
  font-size: 11.5px;
  color: var(--text-faint);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.error-box {
  border: 1px solid var(--danger);
  background: rgba(248, 81, 73, .08);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
}

.typing { display: inline-block; width: 7px; height: 15px; background: var(--accent); vertical-align: -2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* -------------------------------------------------------------- composer */

.composer-wrap {
  padding: 10px 18px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.banner {
  margin-bottom: 9px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  color: var(--warn);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 8px 7px 7px;
}
.composer:focus-within { border-color: var(--accent-dim); }

.composer textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.7;
  padding: 4px 7px;
  max-height: 170px;
}
.composer textarea::placeholder { color: var(--text-faint); }

#send {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--accent-dim);
  color: #fff;
  border-radius: 10px;
  flex-shrink: 0;
}
#send:disabled { opacity: .4; cursor: not-allowed; }
#send svg { transform: scaleX(-1); }

.stop {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 7px 13px;
  flex-shrink: 0;
}

.hint {
  margin: 7px 2px 0;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------------------------------------------------------------- dialog */

dialog {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  padding: 0;
  max-width: 540px;
  width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }

.dialog-body { padding: 20px 22px; }
.dialog-body h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.dialog-body p { margin: 0 0 14px; font-size: 13px; color: var(--text-dim); line-height: 1.8; }

.dialog-body input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 9px 12px;
  direction: ltr;
  outline: none;
}
.dialog-body input:focus { border-color: var(--accent-dim); }

.dialog-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; }
#key-save, #tools-close.primary {
  background: var(--accent-dim); color: #fff; padding: 7px 18px;
}

.tools-list { max-height: 420px; overflow-y: auto; font-size: 13px; }
.tool-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.tool-row:last-child { border-bottom: none; }
.tool-row code {
  font-family: var(--mono); font-size: 11.5px; color: var(--accent);
  direction: ltr; flex-shrink: 0;
}
.tool-row span { color: var(--text-dim); font-size: 12.5px; }
.tool-row.write code { color: var(--warn); }

@media (max-width: 600px) {
  .topbar { padding: 10px 13px; }
  .messages { padding: 16px 13px 6px; }
  .composer-wrap { padding: 8px 13px 12px; }
  .brand-text h1 { font-size: 14px; }
  #btn-tools, #btn-clear { display: none; }
  .bubble { max-width: 92%; }
}


/* ----------------------------------------------------------- trading bits */

.proposal.blocked { border-color: var(--danger); }
.proposal.blocked h4 { color: var(--danger); }
.proposal .risk-ok { color: var(--long); font-size: 12.5px; }
.proposal .risk-bad { color: var(--danger); font-size: 12.5px; }
.side-long { color: var(--long); font-weight: 600; }
.side-short { color: var(--short); font-weight: 600; }
.ticker-strip {
  display: flex; gap: 14px; overflow-x: auto; padding: 6px 18px;
  border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-dim);
  font-variant-numeric: tabular-nums; scrollbar-width: none;
}
.ticker-strip::-webkit-scrollbar { display: none; }
.ticker-strip span { white-space: nowrap; }
.ticker-strip .up { color: var(--long); }
.ticker-strip .down { color: var(--short); }

.who { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; direction: ltr; }
.login-error { color: var(--danger); font-size: 12.5px; margin-top: 8px; }
.dialog-body input + input { margin-top: 8px; }
