:root {
  --bg: #fff8f9;
  --panel: #ffffff;
  --side: #fdeef2;
  --text: #2b1d22;
  --muted: #8a7178;
  --line: #f1d9e0;
  --accent: #e8577a;
  --accent-ink: #ffffff;
  --accent-soft: #fde3ea;
  --user-bubble: #e8577a;
  --user-ink: #ffffff;
  --code-bg: #2b1d22;
  --code-ink: #fbe9ee;
  --danger: #c62a4c;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181115; --panel: #211820; --side: #1d151a; --text: #f5e9ed; --muted: #b29ba3;
    --line: #3a2a31; --accent: #ff7a9a; --accent-ink: #21090f; --accent-soft: #3a1f29;
    --user-bubble: #ff7a9a; --user-ink: #21090f; --code-bg: #0f0a0c; --code-ink: #fbe9ee; --danger: #ff6b86;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15.5px/1.65 "IBM Plex Sans Thai", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; font-size: 14px; }

.btn { border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer; background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; padding: 0; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 20px; padding: 6px 8px; border-radius: 8px; line-height: 1; }
.icon-btn:hover { background: var(--accent-soft); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; text-align: center;
  background: var(--panel); padding: 32px 24px; border-radius: 20px; border: 1px solid var(--line); }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: 0 0 8px; }
.login-card input { padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.logo { font-size: 40px; }
.logo.big { font-size: 56px; }

/* layout */
.app { display: flex; height: 100dvh; }
.sidebar { width: 272px; flex-shrink: 0; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px; padding: 14px; }
.side-head { display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 600; font-size: 17px; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; }
.conv { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.conv:hover { background: var(--accent-soft); }
.conv.on { background: var(--panel); box-shadow: 0 0 0 1px var(--line); }
.conv .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.conv .tag { font-size: 11px; }
.conv .act { opacity: 0; font-size: 13px; padding: 2px 5px; }
.conv:hover .act, .conv.on .act { opacity: .7; }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 8px; font-size: 13px; }
.side-foot .row { display: flex; justify-content: space-between; align-items: center; }
.usage .bar { height: 5px; background: var(--line); border-radius: 9px; overflow: hidden; margin-top: 4px; }
.usage .bar i { display: block; height: 100%; background: var(--accent); }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.modes { display: flex; gap: 4px; background: var(--accent-soft); padding: 3px; border-radius: 12px; }
.mode { border: 0; background: none; padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.mode.on { background: var(--panel); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.model { margin-left: auto; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 6px 8px; font-size: 14px; max-width: 150px; }

.chat { flex: 1; overflow-y: auto; }
.empty { max-width: 720px; margin: 8vh auto 0; padding: 0 16px; text-align: center; }
.empty h2 { font-size: 21px; font-weight: 600; }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 20px; text-align: left; }
.quick button { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 12px; cursor: pointer; font-size: 14px; }
.quick button:hover { border-color: var(--accent); }
.quick b { display: block; margin-bottom: 2px; }

.messages { max-width: 780px; margin: 0 auto; padding: 20px 16px 8px; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--user-bubble); color: var(--user-ink); padding: 10px 14px;
  border-radius: var(--radius) var(--radius) 4px var(--radius); max-width: 85%; white-space: pre-wrap; word-break: break-word; }
.msg.assistant .bubble { width: 100%; word-break: break-word; }
.files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.chip { font-size: 12.5px; background: var(--accent-soft); padding: 4px 9px; border-radius: 99px; }
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }
.tools { display: flex; gap: 6px; }
.tools button { font-size: 12.5px; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; cursor: pointer; color: var(--muted); }
.sources { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12.5px; }
.sources a { color: var(--muted); background: var(--accent-soft); padding: 3px 9px; border-radius: 99px; text-decoration: none; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.err { color: var(--danger); font-size: 14px; }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { line-height: 1.3; margin: 1.1em 0 .5em; }
.md h1 { font-size: 1.3em; } .md h2 { font-size: 1.17em; } .md h3 { font-size: 1.05em; }
.md a { color: var(--accent); }
.md code { font-family: "JetBrains Mono", monospace; font-size: .88em; background: var(--accent-soft); padding: .1em .35em; border-radius: 5px; }
.md pre { position: relative; background: var(--code-bg); color: var(--code-ink); padding: 14px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 13px; }
.md pre .copy { position: absolute; top: 6px; right: 6px; font-size: 12px; background: rgba(255,255,255,.12); color: inherit; border: 0; border-radius: 6px; padding: 2px 8px; cursor: pointer; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; margin: .8em 0; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--accent-soft); }
.md blockquote { margin: .8em 0; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--muted); }

/* composer */
.composer { max-width: 780px; width: 100%; margin: 0 auto; padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.att { position: relative; display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 26px 4px 4px; font-size: 13px; max-width: 220px; }
.att img { width: 40px; height: 40px; object-fit: cover; border-radius: 7px; }
.att .ic { width: 40px; height: 40px; display: grid; place-items: center; background: var(--accent-soft); border-radius: 7px; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att button { position: absolute; top: 2px; right: 2px; border: 0; background: none; cursor: pointer; font-size: 13px; color: var(--muted); }
.input-row { display: flex; align-items: flex-end; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 6px; }
.input-row:focus-within { border-color: var(--accent); }
.input-row textarea { flex: 1; border: 0; outline: 0; resize: none; background: none; padding: 7px 4px; max-height: 40vh; }
.attach { align-self: center; }
.send { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); cursor: pointer; font-size: 15px; flex-shrink: 0; }
.send:disabled { opacity: .4; cursor: default; }
.send.stop { background: var(--text); color: var(--bg); }
.hint { text-align: center; font-size: 11.5px; margin: 6px 0 0; }
.drop { position: fixed; inset: 12px; border: 3px dashed var(--accent); border-radius: 20px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  display: grid; place-items: center; font-size: 22px; font-weight: 600; z-index: 50; pointer-events: none; }

.only-mobile { display: none; }
@media (max-width: 820px) {
  .only-mobile { display: inline-block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; width: 84vw; max-width: 300px; }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
  .topbar { padding: 8px 10px; gap: 6px; }
  .mode { padding: 6px 9px; font-size: 13px; }
  .model { max-width: 108px; font-size: 13px; }
  .messages { padding: 14px 12px 8px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .quick { grid-template-columns: 1fr; }
}
