:root {
  --bg: #0d0f14;
  --panel: #12151c;
  --panel-hi: #171b24;
  --border: #1e2230;
  --text: #e5e7eb;
  --muted: #8b93a7;
  --user: #2b3340;
  --assistant: #141821;
  --accent: #c0392b;
  --accent-hi: #e74c3c;
  --green: #16a34a;
  --gold: #eab308;
  --blue: #3b82f6;
  --mono: "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body.chat {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 100vh;
  overflow: hidden;
}
body.chat.share { grid-template-columns: 1fr; }

/* ---------- Sidebar ---------- */
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.logo {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  color: #000;
  font-weight: 800;
  display: grid; place-items: center;
  font-size: 18px;
}
.brand .name { font-weight: 700; letter-spacing: 0.5px; }
.new-chat {
  margin: 16px;
  padding: 10px 14px;
  background: var(--panel-hi);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.new-chat:hover { background: #1b2030; }
.session-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.session-list a {
  display: block;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-list a:hover { background: var(--panel-hi); }
.session-list a.active { background: #1e2430; }
.session-list a .cost {
  float: right;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}
.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.sidebar-foot a { color: var(--muted); text-decoration: none; }
.small { font-size: 11px; }
.muted { color: var(--muted); }

/* ---------- Main ---------- */
#main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.title { font-weight: 600; letter-spacing: 0.2px; }
.pills { display: flex; gap: 8px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
}
.pill.cost #session-cost { color: var(--green); }
.pill.share {
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
}
.pill.share:hover { color: var(--text); }

/* ---------- Messages ---------- */
.messages {
  overflow-y: auto;
  padding: 28px 0;
  scroll-behavior: smooth;
}
.msg {
  max-width: 760px;
  margin: 0 auto 18px;
  padding: 0 24px;
}
.msg .bubble {
  padding: 14px 18px;
  border-radius: 10px;
  line-height: 1.6;
  word-wrap: break-word;
}
.msg.user .bubble {
  background: var(--user);
  margin-left: 18%;
  white-space: pre-wrap; /* user input stays literal */
}
.msg.assistant .bubble {
  background: var(--assistant);
  border: 1px solid var(--border);
  margin-right: 10%;
}

/* ---------- Markdown rendering ---------- */
.msg.assistant .bubble > *:first-child { margin-top: 0; }
.msg.assistant .bubble > *:last-child { margin-bottom: 0; }
.msg.assistant .bubble p {
  margin: 0 0 10px;
}
.msg.assistant .bubble strong {
  color: #fff;
  font-weight: 700;
}
.msg.assistant .bubble em { color: var(--gold); font-style: italic; }
.msg.assistant .bubble h1,
.msg.assistant .bubble h2,
.msg.assistant .bubble h3,
.msg.assistant .bubble h4 {
  margin: 18px 0 8px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}
.msg.assistant .bubble h1 { font-size: 1.35em; }
.msg.assistant .bubble h2 { font-size: 1.2em; }
.msg.assistant .bubble h3 { font-size: 1.08em; color: var(--gold); }
.msg.assistant .bubble h4 { font-size: 1em; color: var(--gold); }
.msg.assistant .bubble ul,
.msg.assistant .bubble ol {
  margin: 6px 0 12px;
  padding-left: 24px;
}
.msg.assistant .bubble li { margin: 4px 0; }
.msg.assistant .bubble li > p { margin: 0; }
.msg.assistant .bubble ul li::marker { color: var(--accent); }
.msg.assistant .bubble ol li::marker { color: var(--gold); }
.msg.assistant .bubble a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg.assistant .bubble blockquote {
  margin: 8px 0;
  padding: 4px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.msg.assistant .bubble hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
.msg.assistant .bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
  width: 100%;
}
.msg.assistant .bubble th,
.msg.assistant .bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.msg.assistant .bubble th {
  background: #0b0e14;
  color: var(--gold);
  font-weight: 600;
}
.msg.assistant .bubble code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: #0a0c12;
  color: #f0db4f;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.msg.assistant .bubble pre {
  background: #0a0c12;
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
}
.msg.assistant .bubble pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text);
  font-size: inherit;
}
.msg .meta {
  margin: 6px 10% 0 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.msg .meta .chip {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #0b0e14;
  border: 1px solid var(--border);
  color: var(--muted);
}
.msg .meta .chip.profile { color: var(--gold); }
.msg .meta .chip.model { color: var(--blue); }
.msg .meta .chip.cost { color: var(--green); }

.msg .bubble pre {
  background: #0a0c12;
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
}
.msg .bubble code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: #0a0c12;
  padding: 1px 4px;
  border-radius: 3px;
}

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

/* ---------- Composer ---------- */
.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.composer textarea {
  resize: none;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 14.5px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 200px;
  line-height: 1.4;
}
.composer textarea:focus { outline: 1px solid var(--accent); }
.send {
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.send:disabled { opacity: 0.5; cursor: wait; }
.send:hover:not(:disabled) { background: var(--accent-hi); }

/* ---------- Share page ---------- */
#main.full { grid-template-columns: 1fr; }
.share-banner {
  max-width: 760px;
  margin: 0 auto 24px;
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
}
.share-banner a { color: var(--gold); }
