/* Kopi — Singapore AI. Warm dark kopi theme. */
:root {
  --bg: #1b1512;
  --bg-sidebar: #14100d;
  --bg-elevated: #241c17;
  --bg-hover: #2c231c;
  --bg-input: #2a211b;
  --border: #3a2e26;
  --text: #f3ece4;
  --text-dim: #b8a898;
  --text-faint: #8a7767;
  --accent: #e08c3f;
  --accent-soft: rgba(224, 140, 63, 0.14);
  --sg-red: #ee2536;
  --green: #4ade80;
  --red: #f87171;
  --radius: 14px;
  --sidebar-w: 272px;
  --font: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  overflow: hidden;
}

#app { display: flex; height: 100vh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.25s ease;
}
#sidebar.hidden { margin-left: calc(-1 * var(--sidebar-w)); }

.brand { display: flex; align-items: center; gap: 10px; padding: 16px 14px 10px; }
.brand-logo { width: 34px; height: 34px; }
.brand-name { font-size: 21px; font-weight: 800; letter-spacing: 0.5px; color: var(--accent); line-height: 1.1; }
.brand-tag { font-size: 9px; font-weight: 700; letter-spacing: 3px; color: var(--text-faint); }
.brand .icon-btn { margin-left: auto; }

.icon-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 16px; cursor: pointer; padding: 6px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.new-chat-btn {
  margin: 8px 14px 12px;
  padding: 11px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: rgba(224, 140, 63, 0.26); }

.conv-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.conv-group { font-size: 10.5px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-faint); padding: 12px 8px 5px; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  color: var(--text-dim); font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover { background: var(--bg-hover); color: var(--text); }
.conv-item.active { background: var(--bg-elevated); color: var(--text); }
.conv-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.conv-item .del { opacity: 0; border: none; background: none; color: var(--text-faint); cursor: pointer; font-size: 13px; }
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: var(--sg-red); }

.sidebar-foot { padding: 12px 14px 16px; border-top: 1px solid var(--border); }
.sandbox-chip {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--text-dim);
  background: var(--bg-elevated); border-radius: 10px; padding: 8px 10px;
}
.sandbox-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.foot-note { font-size: 11px; color: var(--text-faint); text-align: center; margin-top: 10px; }

/* ---------- main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
  background: var(--bg); flex-shrink: 0;
}
.model-wrap { position: relative; }
.model-btn {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  padding: 8px 14px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.model-btn:hover { background: var(--bg-hover); }
.caret { color: var(--text-faint); font-size: 11px; }
.model-menu {
  display: none; position: absolute; top: 46px; left: 0; z-index: 50;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px;
  min-width: 280px; max-height: 340px; overflow-y: auto; padding: 6px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.model-menu.open { display: block; }
.model-item {
  padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 13.5px;
  color: var(--text-dim); display: flex; justify-content: space-between; gap: 10px;
}
.model-item:hover { background: var(--bg-hover); color: var(--text); }
.model-item.active { color: var(--accent); background: var(--accent-soft); }
.model-item .tag { font-size: 10px; color: var(--text-faint); }

.topbar-right { margin-left: auto; }
.badge-sg {
  font-size: 10px; font-weight: 800; letter-spacing: 1.5px;
  color: var(--sg-red); border: 1px solid var(--sg-red);
  padding: 3px 9px; border-radius: 99px;
}

/* ---------- chat scroll ---------- */
#chatScroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }

#welcome {
  max-width: 720px; margin: 0 auto; padding: 9vh 24px 20px;
  text-align: center;
}
.welcome-logo { width: 72px; height: 72px; margin-bottom: 14px; }
#welcome h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; margin-bottom: 8px;
  background: linear-gradient(90deg, var(--accent), #f6c98a); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome-sub { color: var(--text-dim); margin-bottom: 28px; }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-width: 560px; margin: 0 auto; }
.sugg {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-dim);
  padding: 13px 16px; border-radius: var(--radius); font-size: 13.5px; cursor: pointer;
  text-align: left; transition: all 0.15s;
}
.sugg:hover { background: var(--bg-hover); color: var(--text); border-color: var(--accent); }

#messages { max-width: 760px; margin: 0 auto; padding: 12px 24px 24px; }

.msg { display: flex; gap: 12px; margin: 22px 0; }
.msg.user { justify-content: flex-end; }
.msg .bubble {
  max-width: 82%; padding: 12px 17px; border-radius: 18px;
  background: var(--bg-elevated); border: 1px solid var(--border);
}
.msg.user .bubble { background: var(--accent-soft); border-color: transparent; border-bottom-right-radius: 6px; }
.msg.assistant .bubble { background: transparent; border: none; padding: 0 0 0 2px; max-width: 100%; }
.msg .avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
  background: var(--bg-elevated); border: 1px solid var(--border);
}
.msg.assistant .avatar { border-color: var(--accent); }

.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 14px 0 8px; line-height: 1.3; }
.bubble ul, .bubble ol { margin: 8px 0 10px 20px; }
.bubble li { margin: 3px 0; }
.bubble a { color: var(--accent); }
.bubble blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-dim); margin: 10px 0; }
.bubble table { border-collapse: collapse; margin: 10px 0; width: 100%; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 7px 10px; font-size: 13.5px; }
.bubble th { background: var(--bg-elevated); }
.bubble code:not(pre code) {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--bg-elevated); padding: 2px 6px; border-radius: 6px; color: #f6c98a;
}
.bubble img { max-width: 100%; border-radius: 10px; }

/* code block */
.codeblock { margin: 12px 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #12100e; }
.codeblock .code-head {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elevated); padding: 6px 12px; font-size: 11.5px; color: var(--text-faint);
}
.codeblock .code-head .lang { flex: 1; }
.codeblock .code-head button {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 7px; padding: 3px 10px; font-size: 11px; cursor: pointer;
}
.codeblock .code-head button:hover { color: var(--text); border-color: var(--accent); }
.codeblock .code-head button.run { color: var(--green); border-color: rgba(74,222,128,0.4); }
.codeblock .code-head button.run:hover { background: rgba(74,222,128,0.12); }
.codeblock pre { margin: 0; padding: 13px 15px; overflow-x: auto; }
.codeblock pre code { font-family: var(--mono); font-size: 12.8px; line-height: 1.6; background: none; }

/* sandbox output */
.sbx {
  margin: 10px 0 14px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); background: #100d0b;
}
.sbx .sbx-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 13px; font-size: 11.5px; color: var(--text-faint); background: #17120f;
}
.sbx .sbx-head .ok { color: var(--green); }
.sbx .sbx-head .fail { color: var(--red); }
.sbx pre {
  margin: 0; padding: 12px 14px; font-family: var(--mono); font-size: 12.5px;
  white-space: pre-wrap; word-break: break-word; max-height: 380px; overflow-y: auto;
  color: #d9e7d2;
}
.sbx pre.err { color: #f6b3b3; }
.sbx .sbx-img { padding: 10px 14px; }
.sbx .sbx-img img { max-width: 100%; border-radius: 8px; background: #fff; }

.msg-meta { font-size: 11px; color: var(--text-faint); margin-top: 6px; display: flex; gap: 10px; align-items: center; }
.msg-meta button { background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 11px; }
.msg-meta button:hover { color: var(--accent); }

.cursor-blink::after {
  content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- composer ---------- */
#composer { padding: 10px 24px 16px; background: var(--bg); }
.composer-box {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 18px;
  padding: 10px 12px 10px 18px;
  transition: border-color 0.15s;
}
.composer-box:focus-within { border-color: var(--accent); }
#input {
  flex: 1; background: none; border: none; outline: none; resize: none;
  color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55;
  max-height: 200px;
}
#input::placeholder { color: var(--text-faint); }
.send-btn {
  width: 38px; height: 38px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--accent); color: #241400;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { filter: brightness(1.1); }
.send-btn:disabled { opacity: 0.45; cursor: default; }
.composer-note {
  max-width: 760px; margin: 8px auto 0; text-align: center;
  font-size: 11px; color: var(--text-faint);
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  #sidebar { position: fixed; z-index: 100; height: 100vh; margin-left: calc(-1 * var(--sidebar-w)); }
  #sidebar.show { margin-left: 0; box-shadow: 20px 0 60px rgba(0,0,0,0.5); }
  .suggestions { grid-template-columns: 1fr; }
  #welcome h1 { font-size: 27px; }
  #messages { padding: 12px 14px; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- main menu ---------- */
.main-menu { display: flex; gap: 6px; padding: 4px 14px 10px; }
.menu-item {
  flex: 1; padding: 9px 10px; border-radius: 10px; border: 1px solid transparent;
  background: none; color: var(--text-dim); font-size: 13px; font-weight: 600; cursor: pointer;
}
.menu-item:hover { background: var(--bg-hover); color: var(--text); }
.menu-item.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ---------- agents page ---------- */
.page { flex: 1; overflow-y: auto; }
.agents-hero { text-align: center; padding: 6vh 24px 10px; }
.agents-hero h1 {
  font-size: 32px; font-weight: 800; letter-spacing: -0.5px; margin-bottom: 8px;
  background: linear-gradient(90deg, var(--accent), #f6c98a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.bot-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px; max-width: 880px; margin: 18px auto 60px; padding: 0 24px;
}
.bot-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 16px 14px; cursor: pointer; transition: all 0.15s; position: relative;
}
.bot-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.bot-emoji { font-size: 32px; margin-bottom: 8px; }
.bot-name { font-size: 15.5px; font-weight: 700; margin-bottom: 4px; }
.bot-desc { font-size: 12.5px; color: var(--text-dim); min-height: 34px; }
.bot-meta { display: flex; justify-content: space-between; align-items: center; margin: 10px 0 8px; }
.bot-tag { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 99px; }
.bot-model { font-size: 10.5px; color: var(--text-faint); }
.bot-actions { display: flex; gap: 8px; }
.bot-chat {
  flex: 1; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--accent);
  background: none; color: var(--accent); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.bot-chat:hover { background: var(--accent-soft); }
.bot-del {
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: none; color: var(--text-faint); cursor: pointer;
}
.bot-del:hover { color: var(--sg-red); border-color: var(--sg-red); }
.bot-create { border-style: dashed; text-align: center; }
.bot-create .bot-emoji { font-size: 28px; }

/* ---------- model menu groups ---------- */
.model-group {
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--text-faint); padding: 10px 12px 4px;
}

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(10, 7, 5, 0.72); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 20px;
  padding: 30px 28px; width: 100%; max-width: 400px; position: relative;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { transform: translateY(14px); opacity: 0; } }
.modal-close {
  position: absolute; top: 14px; right: 14px; background: none; border: none;
  color: var(--text-faint); font-size: 15px; cursor: pointer;
}
.modal-logo { font-size: 38px; text-align: center; margin-bottom: 6px; }
.modal-card h2 { font-size: 21px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.modal-sub { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.modal-input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-input); color: var(--text);
  font-family: var(--font); font-size: 14px; outline: none;
}
.modal-input:focus { border-color: var(--accent); }
.modal-textarea { min-height: 90px; resize: vertical; }
.modal-error { color: var(--sg-red); font-size: 12.5px; min-height: 18px; margin-bottom: 6px; }
.modal-submit {
  width: 100%; padding: 13px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--accent); color: #241400; font-size: 14.5px; font-weight: 700;
}
.modal-submit:hover { filter: brightness(1.08); }
.modal-switch { text-align: center; margin-top: 14px; font-size: 12.5px; color: var(--text-dim); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12.5px; font-weight: 600; }

/* ---------- onboarding tour ---------- */
.tour {
  position: fixed; inset: 0; background: rgba(10, 7, 5, 0.78); z-index: 250;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(5px);
}
.tour-card {
  background: var(--bg-elevated); border: 1px solid var(--accent); border-radius: 22px;
  padding: 30px 28px; max-width: 620px; width: 100%; animation: modalIn 0.25s ease;
}
.tour-steps { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 22px; }
.tour-step {
  background: var(--bg); border: 1px solid var(--border); border-radius: 14px; padding: 15px;
}
.tour-step span {
  display: inline-flex; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #241400; font-weight: 800; font-size: 12.5px;
  align-items: center; justify-content: center; margin-bottom: 8px;
}
.tour-step b { display: block; font-size: 14px; margin-bottom: 4px; }
.tour-step p { font-size: 12px; color: var(--text-dim); line-height: 1.5; }

@media (max-width: 640px) {
  .tour-steps { grid-template-columns: 1fr; }
  .agents-hero h1 { font-size: 25px; }
}

/* ---------- A-share stock page ---------- */
.stock-wrap { max-width: 900px; margin: 0 auto; padding: 22px 24px 60px; }
.stock-search { position: relative; margin-bottom: 18px; }
.stock-search-input {
  width: 100%; padding: 14px 18px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--bg-input); color: var(--text);
  font-size: 15px; outline: none; font-family: var(--font);
}
.stock-search-input:focus { border-color: var(--accent); }
.stock-results {
  display: none; position: absolute; top: 58px; left: 0; right: 0; z-index: 60;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px;
  overflow: hidden; box-shadow: 0 14px 44px rgba(0,0,0,0.5);
}
.stock-result {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; cursor: pointer; font-size: 14px;
}
.stock-result:hover { background: var(--bg-hover); }
.stock-result-code { color: var(--text-faint); font-size: 12px; font-family: var(--mono); }
.stock-result-empty { padding: 14px 16px; color: var(--text-faint); font-size: 13px; }

.stock-empty { text-align: center; padding: 9vh 20px; }
.stock-empty-icon { font-size: 52px; margin-bottom: 12px; }
.stock-empty h2 {
  font-size: 28px; font-weight: 800; margin-bottom: 8px;
  background: linear-gradient(90deg, var(--accent), #f6c98a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.stock-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.stock-name { font-size: 22px; font-weight: 800; }
.stock-code { font-size: 13px; color: var(--text-faint); font-family: var(--mono); margin-left: 6px; }
.stock-price-row { display: flex; align-items: baseline; gap: 12px; margin-top: 4px; }
.stock-price { font-size: 32px; font-weight: 800; font-family: var(--mono); }
.stock-chg { font-size: 15px; font-weight: 700; font-family: var(--mono); }
.stock-chg.up { color: #e0503f; }
.stock-chg.down { color: #3fae6a; }
.stock-asof { font-size: 11px; color: var(--text-faint); }

.stock-stats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 9px; margin-bottom: 18px;
}
.stock-stat { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 11px; padding: 9px 12px; }
.stock-stat-k { font-size: 10.5px; color: var(--text-faint); margin-bottom: 3px; }
.stock-stat-v { font-size: 14px; font-weight: 700; font-family: var(--mono); }

.stock-chart-box {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px 16px 8px; margin-bottom: 20px;
}
.stock-chart-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--text-dim); margin-bottom: 8px; }
.chart-range { display: flex; gap: 6px; }
.range-btn {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 8px; padding: 3px 11px; font-size: 11px; cursor: pointer;
}
.range-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.stock-chart svg { width: 100%; height: auto; display: block; }

.stock-ai-title { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
.stock-tpl-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tpl-btn {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-dim);
  padding: 8px 16px; border-radius: 99px; font-size: 12.5px; cursor: pointer;
}
.tpl-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.stock-ask { margin-bottom: 14px; }
.stock-analysis {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 20px; min-height: 60px; font-size: 14.5px; line-height: 1.75;
}
.stock-analysis p { margin: 0 0 10px; }
.stock-analysis ul, .stock-analysis ol { margin: 8px 0 10px 20px; }
.stock-analysis h2, .stock-analysis h3 { margin: 14px 0 8px; }
.stock-analysis table { border-collapse: collapse; margin: 10px 0; width: 100%; }
.stock-analysis th, .stock-analysis td { border: 1px solid var(--border); padding: 6px 10px; font-size: 13px; }
.stock-analysis th { background: var(--bg); }
.stock-disclaimer { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--border); font-size: 11px; color: var(--text-faint); }
.analysis-stream { color: var(--text-dim); }

@media (max-width: 640px) {
  .stock-price { font-size: 25px; }
  .stock-head { flex-direction: column; gap: 6px; }
}
