:root {
  --paper: #f6f3ee;        /* warm cream canvas (Claude) */
  --paper-2: #efeadf;      /* user bubble */
  --panel: #efebe3;        /* sidebar */
  --line: #e3ded3;         /* hairlines */
  --line-2: #d5cfc1;
  --ink: #2c2a26;
  --ink-2: #5f5b52;
  --ink-3: #928d80;
  --accent: #c96442;       /* Claude coral-terracotta */
  --accent-soft: #f3d9cd;
  --ok: #5c8a58;
  --bad: #b1524a;
  --serif: 'Source Serif 4','Cambria','Georgia',serif;
  --sans: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif;
  --mono: ui-monospace,'SF Mono',Menlo,Consolas,monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 15.5px; line-height: 1.62;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }

#app { display: flex; height: 100dvh; overflow: hidden; }

/* ---------------- sidebar ---------------- */
#sidebar {
  width: 272px; flex: none; background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 10px 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 650; }
.brand-mark { color: var(--accent); font-size: 19px; line-height: 1; }
.brand-mark.small { font-size: 15px; color: var(--accent); }
.brand-name { font-family: var(--serif); font-weight: 600; letter-spacing: .2px; }
#btn-close-menu { display: none; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2);
}
.icon-btn:hover { background: rgba(0,0,0,.05); }
.side-action {
  margin: 4px 12px 10px; padding: 8px 12px; align-self: flex-start;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line-2); border-radius: 10px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-2);
}
.side-action:hover { background: rgba(0,0,0,.04); }
.sa-ic { font-size: 14px; color: var(--accent); }
#session-list { flex: 1; overflow-y: auto; padding: 2px 12px 12px; }
.s-group { font-size: 11.5px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); margin: 12px 6px 4px; }
.session-item {
  position: relative; display: flex; align-items: center;
  padding: 7px 10px; border-radius: 9px; font-size: 14px;
  white-space: nowrap; overflow: hidden;
}
.session-item:hover { background: rgba(0,0,0,.05); }
.session-item.active { background: rgba(0,0,0,.07); font-weight: 600; }
.s-title { overflow: hidden; text-overflow: ellipsis; }
.s-del { margin-left: auto; flex: none; padding: 2px 6px; border-radius: 6px; font-size: 12px; color: var(--ink-3); opacity: 0; }
.session-item:hover .s-del { opacity: 1; }
.s-del:hover { background: rgba(0,0,0,.08); color: var(--bad); }
.side-foot { border-top: 1px solid var(--line); }
.side-foot-row {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; text-align: left;
}
.side-foot-row:hover { background: rgba(0,0,0,.04); }
.av {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}
.sfr-main { display: flex; flex-direction: column; min-width: 0; }
.sfr-title { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sfr-sub { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
#scrim { display: none; }

/* ---------------- main ---------------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#topbar {
  display: flex; align-items: center; gap: 8px;
  height: 52px; padding: 0 18px; flex: none;
}
#btn-menu { display: none; }
#topbar-center { display: flex; align-items: center; gap: 8px; margin: 0 auto -26px; pointer-events: none; }
#topbar-title { font-family: var(--serif); font-weight: 600; font-size: 15px; }
.conn-flag { font-size: 12px; color: var(--bad); }

#chat-scroll { flex: 1; overflow-y: auto; scroll-behavior: auto; }
#messages { max-width: 780px; margin: 0 auto; padding: 8px 18px 24px; }
#welcome {
  max-width: 780px; margin: 0 auto; width: 100%;
  padding: 8vh 18px 0; text-align: center;
}
#welcome.hidden { display: none; }
.w-kicker { color: var(--accent); font-size: 26px; }
#greeting { font-family: var(--serif); font-weight: 590; font-size: clamp(26px, 4.4vw, 38px); margin: 10px 0 26px; }
#greeting .mark { color: var(--accent); }
#chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  border: 1px solid var(--line-2); border-radius: 999px;
  padding: 7px 15px; font-size: 13.5px; color: var(--ink-2);
  background: var(--panel);
}
.chip:hover { border-color: var(--accent); color: var(--ink); background: #fff; }

/* messages — Claude style: words on the left, user answers right in a soft pill */
.msg { margin: 0 0 22px; animation: rise .22s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.msg.user .bubble {
  margin-left: auto; display: inline-block;
  background: var(--paper-2); border-radius: 16px;
  padding: 9px 16px; max-width: 100%;
  white-space: pre-wrap; word-break: break-word; text-align: left;
}
.msg.assistant .body { min-width: 0; }
.md { overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 13px; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 620; line-height: 1.3; margin: 20px 0 10px; }
.md ul, .md ol { margin: 0 0 13px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md blockquote { margin: 0 0 13px; padding: 2px 0 2px 14px; border-left: 3px solid var(--line-2); color: var(--ink-2); }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.md table { border-collapse: collapse; margin: 0 0 14px; width: 100%; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line-2); padding: 6px 10px; text-align: left; }
.md code {
  font-family: var(--mono); font-size: 13px;
  background: rgba(0,0,0,.06); border-radius: 5px; padding: 1.5px 5px;
}
.cb { margin: 0 0 14px; border: 1px solid var(--line-2); border-radius: 10px; background: #fff; overflow: hidden; }
.cb-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; background: var(--panel);
  font-size: 12px; color: var(--ink-3);
}
.cb-copy { font-size: 12px; color: var(--accent); padding: 2px 8px; border-radius: 6px; }
.cb-copy:hover { background: var(--accent-soft); }
.cb code { display: block; padding: 12px 14px; background: none; overflow-x: auto; font-size: 13px; line-height: 1.55; }
.tools-row {
  display: inline-flex; gap: 6px; align-items: center;
  font-size: 13px; color: var(--ink-3);
  border-bottom: 1px solid var(--line);
  padding: 0 0 10px; margin-bottom: 14px;
}
.caret {
  display: inline-block; width: 8px; height: 15px; margin-left: 2px;
  background: var(--ink-2); vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.think {
  display: flex; align-items: center; gap: 5px;
  margin: 2px 0 10px; color: var(--ink-3); font-size: 13.5px;
}
.think span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); opacity: .3;
  display: inline-block;
  animation: thinkp 1.2s infinite ease-in-out;
}
.think span:nth-child(2) { animation-delay: .18s; }
.think span:nth-child(3) { animation-delay: .36s; }
.think i { font-style: italic; margin-left: 4px; }
@keyframes thinkp {
  0%, 80%, 100% { transform: scale(.7); opacity: .3; }
  40% { transform: scale(1); opacity: .9; }
}
.msg.streaming .md p:last-child { margin-bottom: 0; }

/* ---------------- composer ---------------- */
#composer-wrap { display: flex; flex-direction: column; flex-shrink: 0; }
#composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: #fff; border: 1px solid var(--line-2); border-radius: 20px;
  padding: 9px 10px 9px 17px;
  box-shadow: 0 3px 14px rgba(70, 50, 20, .07);
}
#composer:focus-within { border-color: var(--ink-3); }
#input {
  flex: 1; border: 0; outline: none; resize: none; background: transparent;
  font: inherit; line-height: 1.5; color: var(--ink);
  min-height: 24px; max-height: 160px;
}
#input::placeholder { color: var(--ink-3); }
#input:disabled { opacity: .55; }
.send {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.send:hover { background: #111; }
.send:disabled, .send[disabled] { opacity: .45; cursor: default; }
.ic-stop { display: none; width: 12px; height: 12px; border-radius: 3px; background: #fff; }
.send.stop .ic-up { display: none; }
.send.stop .ic-stop { display: block; }
.disclaimer { margin: 8px auto 0; padding: 0 16px 10px; text-align: center; font-size: 12px; color: var(--ink-3); }

/* ---------------- toast ---------------- */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(16px);
  background: var(--ink); color: #fff; font-size: 13.5px;
  padding: 9px 18px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 50; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

::selection { background: var(--accent-soft); }

/* ---------------- phone ---------------- */
@media (max-width: 900px) {
  #sidebar {
    position: absolute; z-index: 30; top: 0; bottom: 0; left: 0;
    width: min(320px, 85vw);
    transform: translateX(-102%); transition: transform .25s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.12);
  }
  #app.sidebar-open #sidebar { transform: none; }
  #scrim {
    display: block; position: absolute; inset: 0; z-index: 20;
    background: rgba(40, 30, 20, .3); opacity: 0; pointer-events: none;
    transition: opacity .25s;
  }
  #app.sidebar-open #scrim { opacity: 1; pointer-events: auto; }
  #btn-menu { display: inline-flex; }
  #btn-close-menu { display: inline-flex; }
  #messages { padding: 4px 14px 16px; }
  #welcome { padding-top: 4vh; }
  #topbar-center { margin: 0; }
  #composer { margin: 0 10px; }
  .msg.user .bubble { max-width: 88%; }
}
