/* ─────────────────────────────────────────────────────────────
   Chat — a quiet client for OpenAI-compatible endpoints.
   Design reference: Claude.ai's typographic calm, Linear's density,
   Open WebUI's structure with the chrome removed.
   ───────────────────────────────────────────────────────────── */

@font-face {
  font-family: "Inter";
  src: url("../fonts/InterVariable.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg:        #0e1013;
  --panel:     #14171c;
  --panel-2:   #1a1e24;
  --panel-3:   #20252d;
  --line:      #242a33;
  --line-soft: #1c212a;
  --text:      #e7e9ec;
  --text-dim:  #b9bfc7;
  --muted:     #8f97a2;
  --accent:    #d99a4e;
  --accent-ink:#1a1206;
  --accent-10: rgba(217, 154, 78, .10);
  --accent-20: rgba(217, 154, 78, .20);
  --danger:    #d2605a;
  --radius:    14px;
  --shadow:    0 12px 32px rgba(0,0,0,.38);
  --side-w:    264px;
  --maxw:      760px;
}

:root[data-theme="light"] {
  --bg:        #fbfaf8;
  --panel:     #f4f2ee;
  --panel-2:   #ece9e3;
  --panel-3:   #e3dfd8;
  --line:      #d6d0c6;
  --line-soft: #e4dfd7;
  --text:      #1b1d20;
  --text-dim:  #3d4147;
  --muted:     #6b7076;
  --accent:    #a76a1f;
  --accent-ink:#fff8ee;
  --accent-10: rgba(167, 106, 31, .10);
  --accent-20: rgba(167, 106, 31, .18);
  --shadow:    0 12px 32px rgba(60,50,35,.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
body { overflow: hidden; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
::selection { background: var(--accent-20); }

/* ── shell ───────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; height: 100dvh; }

/* ── sidebar ─────────────────────────────────────────────── */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
  padding: 14px 10px 10px;
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 12px; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 3px var(--accent-10);
}
.brand-name { font-weight: 600; letter-spacing: -.01em; font-size: 15px; }

.icon-btn {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  color: var(--muted); transition: background .14s, color .14s;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }

.side-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid transparent;
  border-radius: 10px; padding: 0 10px; height: 34px; margin: 0 2px 10px;
  color: var(--muted); transition: border-color .15s;
}
.side-search:focus-within { border-color: var(--line); }
.side-search input {
  flex: 1; min-width: 0; background: none; border: 0; outline: 0;
  font-size: 13.5px; color: var(--text);
}
.side-search input::placeholder { color: var(--muted); }

.chat-list { flex: 1; overflow-y: auto; min-height: 0; padding: 2px; }
.chat-group { font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); padding: 14px 8px 6px; font-weight: 550; }
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 9px; border-radius: 9px; margin-bottom: 1px;
  font-size: 13.5px; color: var(--text-dim);
  cursor: pointer; transition: background .12s, color .12s;
}
.chat-item:hover { background: var(--panel-2); color: var(--text); }
.chat-item.active { background: var(--panel-3); color: var(--text); }
.chat-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .row-more {
  opacity: 0; width: 22px; height: 22px; border: 0; border-radius: 6px; background: none;
  color: var(--muted); display: grid; place-items: center; cursor: pointer; flex: none;
}
.chat-item:hover .row-more { opacity: 1; }
.chat-item .row-more:hover { color: var(--text); background: var(--panel); }

.side-foot { border-top: 1px solid var(--line-soft); padding-top: 8px; margin-top: 6px; }
.side-action {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 9px; border-radius: 9px; font-size: 13.5px; color: var(--muted);
  transition: background .12s, color .12s;
}
.side-action:hover { background: var(--panel-2); color: var(--text); }
.model-chip-side {
  font-size: 11.5px; color: var(--muted); padding: 4px 9px 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── main ────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 10px max(14px, calc((100% - var(--maxw)) / 2 + 26px)) 10px;
  border-bottom: 1px solid var(--line-soft);
  position: relative; z-index: 5;
}
.only-mobile { display: none; }
.topbar-right { margin-left: auto; }

.model-picker {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 9px;
  font-size: 13.5px; font-weight: 500; color: var(--text-dim);
  transition: background .14s, color .14s;
}
.model-picker:hover { background: var(--panel-2); color: var(--text); }
.model-picker svg { color: var(--muted); }

.model-menu {
  position: absolute; top: calc(100% - 2px); left: max(14px, calc((100% - var(--maxw)) / 2 + 26px));
  min-width: 260px; max-height: 320px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 5px; box-shadow: var(--shadow); z-index: 20;
}
.model-opt {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border-radius: 8px; font-size: 13.5px; color: var(--text-dim);
}
.model-opt:hover { background: var(--panel-2); color: var(--text); }
.model-opt.sel { color: var(--text); background: var(--accent-10); }
.model-empty { padding: 10px; font-size: 13px; color: var(--muted); }

/* ── thread ──────────────────────────────────────────────── */
.scroll { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
.thread { max-width: var(--maxw); margin: 0 auto; padding: 26px 26px 12px; }

.empty { text-align: center; padding: 16vh 0 0; }
.empty h1 { font-size: 27px; font-weight: 550; letter-spacing: -.02em; margin: 0 0 10px; }
.empty-sub { color: var(--muted); font-size: 14px; margin: 0 auto; max-width: 34ch; }
.empty-cta { margin-top: 18px; }

.msg { margin-bottom: 26px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--panel-2); border: 1px solid var(--line-soft);
  border-radius: 16px 16px 5px 16px;
  padding: 10px 15px; max-width: 78%; white-space: pre-wrap; word-break: break-word;
}
.msg.assistant .body { font-size: 15.2px; line-height: 1.72; }
.msg.assistant .body > *:first-child { margin-top: 0; }
.msg.assistant .body > *:last-child { margin-bottom: 0; }

.msg-actions { display: flex; gap: 4px; margin-top: 8px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  font-size: 11.5px; color: var(--muted); padding: 3px 8px; border-radius: 7px;
}
.msg-actions button:hover { background: var(--panel-2); color: var(--text-dim); }

/* markdown */
.body p { margin: 0 0 14px; }
.body h1, .body h2, .body h3, .body h4 { margin: 26px 0 12px; line-height: 1.28; font-weight: 600; letter-spacing: -.02em; }
.body h1 { font-size: 23px; } .body h2 { font-size: 19.5px; } .body h3 { font-size: 17px; }
.body ul, .body ol { margin: 0 0 14px; padding-left: 22px; }
.body li { margin: 4px 0; }
.body a { color: var(--accent); text-decoration: underline; text-decoration-color: var(--accent-20); text-underline-offset: 2px; }
.body a:hover { text-decoration-color: var(--accent); }
.body blockquote {
  margin: 0 0 14px; padding: 2px 0 2px 14px;
  border-left: 2px solid var(--line); color: var(--text-dim);
}
.body hr { border: 0; border-top: 1px solid var(--line-soft); margin: 22px 0; }
.body table {
  border-collapse: separate; border-spacing: 0;
  width: auto; max-width: 100%; margin: 0 0 16px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.body th, .body td {
  padding: 7px 13px; text-align: left;
  border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft);
}
.body th:last-child, .body td:last-child { border-right: 0; }
.body tr:last-child td { border-bottom: 0; }
.body th { background: var(--panel-2); font-weight: 550; }
.body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .885em; background: var(--panel-2);
  padding: .12em .38em; border-radius: 5px;
}
.body pre {
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: 11px; padding: 13px 15px; overflow-x: auto;
  margin: 0 0 14px; position: relative;
}
.body pre code { background: none; padding: 0; font-size: 12.9px; line-height: 1.62; }
.code-copy {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 7px; padding: 3px 8px;
  opacity: 0; transition: opacity .14s, color .14s;
}
.body pre:hover .code-copy { opacity: 1; }
.code-copy:hover { color: var(--text); }

.caret {
  display: inline-block; width: 7px; height: 15px; margin-left: 2px;
  background: var(--accent); border-radius: 1px; vertical-align: -2px;
  animation: blink 1.05s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.thinking { display: flex; gap: 4px; padding: 4px 0; }
.thinking i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: pulse 1.3s ease-in-out infinite;
}
.thinking i:nth-child(2) { animation-delay: .18s; }
.thinking i:nth-child(3) { animation-delay: .36s; }
@keyframes pulse { 0%,100% { opacity: .25; } 50% { opacity: 1; } }

.err { color: var(--danger); font-size: 13.5px; padding: 2px 0 0; }

/* ── composer ────────────────────────────────────────────── */
.composer-wrap { padding: 6px 26px calc(14px + env(safe-area-inset-bottom)); }
.composer {
  max-width: calc(var(--maxw) - 52px); margin: 0 auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 9px 9px 9px 14px;
  display: flex; align-items: flex-end; gap: 8px;
  transition: border-color .16s, box-shadow .16s;
  box-shadow: 0 2px 10px rgba(0,0,0,.10);
}
.composer:focus-within { border-color: var(--accent-20); box-shadow: 0 0 0 3px var(--accent-10); }
.composer textarea {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: none; resize: none;
  font-size: 16px; line-height: 1.5; max-height: 40vh; min-height: 22px;
  display: block; padding: 4px 2px;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-actions { display: flex; align-items: center; gap: 6px; padding-bottom: 1px; }
.spacer { flex: 1; }
.pill {
  font-size: 11.5px; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line-soft); border-radius: 8px; padding: 3px 9px;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: color .14s, border-color .14s;
}
.pill:hover { color: var(--text-dim); border-color: var(--line); }
.send-btn, .stop-btn {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--panel-3); color: var(--muted);
  transition: background .14s, color .14s, transform .1s;
}
.send-btn:not(:disabled) { background: var(--accent); color: var(--accent-ink); }
.send-btn:not(:disabled):hover { transform: translateY(-1px); }
.send-btn:disabled { cursor: default; opacity: 1; background: var(--panel-3); color: var(--muted); }
.stop-btn { background: var(--panel-3); color: var(--text-dim); }
.stop-btn:hover { color: var(--danger); }
.composer-note {
  max-width: calc(var(--maxw) - 52px); margin: 7px auto 0; text-align: center;
  font-size: 11.5px; color: var(--muted); min-height: 15px;
}

/* ── settings sheet ──────────────────────────────────────── */
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(430px, 100vw);
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); z-index: 60;
  display: flex; flex-direction: column;
  animation: slidein .18s ease-out;
}
@keyframes slidein { from { transform: translateX(18px); opacity: .6; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
}
.sheet-head h2 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.sheet-body { flex: 1; overflow-y: auto; padding: 6px 16px 26px; }
.sheet-body section { padding: 16px 0; border-bottom: 1px solid var(--line-soft); }
.sheet-body section:last-child { border-bottom: 0; }
.sheet-body h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 0 0 12px; font-weight: 600;
}
.field { display: block; margin-bottom: 13px; }
.field > span { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 5px; }
.field > span em { color: var(--muted); font-style: normal; font-size: 11.5px; }
.field input[type="url"], .field input[type="password"],
.field input[type="text"], .field textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 11px; font-size: 13.5px; outline: 0;
  transition: border-color .15s;
}
.field input:focus, .field textarea:focus { border-color: var(--accent-20); }
.field textarea { resize: vertical; line-height: 1.5; }
.field.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field.row > span { margin: 0; }
.field input[type="range"] { flex: 1; accent-color: var(--accent); }
.field output { font-size: 12.5px; color: var(--muted); width: 28px; text-align: right; }
.field input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.ghost-btn {
  font-size: 12.5px; color: var(--text-dim); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px;
  transition: color .14s, border-color .14s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--line); }
.ghost-btn.danger { color: var(--danger); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 8px 0 0; }
.hint.ok { color: #6aa86a; }
.hint.bad { color: var(--danger); }

/* ── mobile ──────────────────────────────────────────────── */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: 82vw; max-width: var(--side-w);
    z-index: 55; transform: translateX(-102%);
    transition: transform .2s ease-out; box-shadow: var(--shadow);
    padding-top: calc(14px + env(safe-area-inset-top));
  }
  .sidebar.open { transform: none; }
  .only-mobile { display: grid; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; }
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 10px 8px; }
  .thread { padding: 16px 16px 6px; }
  .composer-wrap { padding: 4px 12px calc(8px + env(safe-area-inset-bottom)); }
  .composer { max-width: none; border-radius: 16px; padding: 8px 8px 8px 12px; }
  .composer textarea { padding: 2px 2px; }
  .pill { display: none; }              /* the header picker is the one control */
  .empty { padding-top: 18vh; }
  .empty h1 { font-size: 23px; }
  .empty-sub { max-width: 30ch; }
  .msg.user .bubble { max-width: 88%; }
  .model-menu { left: 8px; right: 8px; min-width: 0; }
  .msg-actions { opacity: 1; }
  .chat-item .row-more { opacity: 1; }
  .send-btn, .stop-btn { width: 38px; height: 38px; }
  .ghost-btn { min-height: 40px; }
  .icon-btn { width: 34px; height: 34px; }
  .composer-note { max-width: none; }
}

/* ── sync status ─────────────────────────────────────────── */
.sync-row {
  display: flex; align-items: center; gap: 7px;
  padding: 3px 10px 7px; font-size: 11.5px; color: var(--muted);
}
.sync-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); flex: none; }
.sync-dot.on { background: #6aa86a; }
.sync-dot.off { background: #b07a3f; }
.sync-dot.busy { background: var(--accent); animation: sync-pulse 1.2s ease-in-out infinite; }
@keyframes sync-pulse { 50% { opacity: .3; } }

/* ── context menu ────────────────────────────────────────── */
.row-menu {
  position: fixed; z-index: 80; min-width: 194px; padding: 5px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
}
.menu-item {
  display: block; width: 100%; text-align: left; padding: 8px 10px;
  border: 0; border-radius: 8px; background: none; cursor: pointer;
  color: var(--text-dim); font-size: 13.5px;
}
.menu-item:hover { background: var(--panel-2); color: var(--text); }
.menu-item.danger { color: var(--danger); }

/* ── prompt flyout ───────────────────────────────────────── */
.flyout {
  position: fixed; z-index: 80; padding: 5px; max-height: 300px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
}
.flyout-row {
  display: flex; flex-direction: column; gap: 2px; width: 100%;
  text-align: left; padding: 8px 10px; border: 0; border-radius: 8px;
  background: none; cursor: pointer;
}
.flyout-row.sel, .flyout-row:hover { background: var(--panel-2); }
.flyout-title { font-size: 13.5px; color: var(--text); }
.flyout-preview {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.flyout-empty { padding: 10px; font-size: 12.5px; color: var(--muted); }

/* ── editing a message ───────────────────────────────────── */
.edit-box { width: 100%; }
.edit-box textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 15px; line-height: 1.55;
  color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; resize: vertical; outline: none;
}
.edit-box textarea:focus { border-color: var(--accent-20); box-shadow: 0 0 0 3px var(--accent-10); }
.edit-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.msg.user .msg-actions { justify-content: flex-end; }

/* ── small controls ──────────────────────────────────────── */
.ghost-btn.sm { padding: 5px 10px; font-size: 12.5px; }
.ghost-btn.primary { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.link-btn {
  background: none; border: 0; padding: 4px 0; cursor: pointer;
  color: var(--muted); font-size: 12.5px;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line);
}
.link-btn:hover { color: var(--text); text-decoration-color: var(--muted); }
.prompt-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.prompt-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 10px; border: 1px solid var(--line-soft); border-radius: 9px; font-size: 13px;
}
.prompt-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── attachments ─────────────────────────────────────────── */
.ghost-icon {
  width: 30px; height: 30px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer;
}
.ghost-icon:hover { color: var(--text); background: var(--panel-2); }
.ghost-icon.mic-on { color: var(--accent); background: var(--accent-10); animation: sync-pulse 1.4s ease-in-out infinite; }
.attach-strip { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 0 8px; }
.attach-thumb { position: relative; width: 62px; height: 62px; border-radius: 9px; overflow: hidden; border: 1px solid var(--line); }
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-thumb button {
  position: absolute; top: 2px; right: 2px; width: 17px; height: 17px; padding: 0;
  border: 0; border-radius: 50%; background: rgba(0,0,0,.62); color: #fff;
  font-size: 11px; line-height: 17px; text-align: center; cursor: pointer;
}
.msg-imgs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 7px; }
.msg-imgs img { max-width: 190px; max-height: 190px; border-radius: 9px; border: 1px solid var(--line-soft); display: block; }

/* ── metering ────────────────────────────────────────────── */
.side-foot-foot { display: flex; align-items: center; justify-content: space-between; padding-right: 10px; }
.meter-row { padding: 0 10px 6px; }
.meter { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.drag-over .composer { border-color: var(--accent-20); box-shadow: 0 0 0 3px var(--accent-10); }
