/* claude.ai-inspired look: warm cream, serif headings, terracotta accent */

:root {
  --bg: #faf9f5;
  --bg-sidebar: #f4f1ea;
  --bg-user-msg: #f0eee5;
  --bg-hover: #eae7dd;
  --border: #e5e1d5;
  --border-strong: #d5d0c2;
  --text: #3d3929;
  --text-dim: #8a8570;
  --accent: #c96442;
  --accent-hover: #b55536;
  --serif: "Copernicus", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.6;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; color: inherit; }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.login-box { text-align: center; width: 320px; }
.login-mark { font-size: 42px; color: var(--accent); }
.login-box h1 { font-family: var(--serif); font-weight: 500; font-size: 28px; margin: 12px 0 24px; }
.login-box input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--border-strong);
  border-radius: 10px; background: #fff; font-size: 15px; outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  width: 100%; margin-top: 12px; padding: 11px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 500;
}
.login-box button:hover { background: var(--accent-hover); }
.login-err { color: #b03020; margin-top: 12px; min-height: 20px; font-size: 13px; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; }

.sidebar {
  width: 288px; min-width: 288px; background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-top { padding: 16px 12px 8px; }
.brand {
  font-family: var(--serif); font-size: 19px; padding: 2px 8px 14px;
  display: flex; align-items: baseline; gap: 7px;
}
.brand-mark { color: var(--accent); font-size: 17px; }
.brand-sub { font-family: var(--sans); font-size: 11px; color: var(--text-dim); }

.new-chat {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 12px; border: none; border-radius: 10px;
  background: transparent; color: var(--accent);
  font-size: 14px; font-weight: 600;
}
.new-chat:hover { background: var(--bg-hover); }

.search-wrap {
  display: flex; align-items: center; gap: 7px; margin: 8px 0 4px;
  padding: 7px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: #fffdf9; color: var(--text-dim);
}
.search-wrap:focus-within { border-color: var(--border-strong); }
.search-wrap input {
  border: none; outline: none; background: transparent;
  width: 100%; font-size: 13.5px; color: var(--text);
}

.conv-list { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.conv-group-label {
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 14px 8px 4px;
}
.conv-item {
  display: flex; align-items: center;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; color: var(--text);
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-hover); font-weight: 500; }
.conv-item .conv-title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .conv-del {
  visibility: hidden; border: none; background: none; color: var(--text-dim);
  padding: 2px 4px; border-radius: 5px; font-size: 12px; line-height: 1;
}
.conv-item:hover .conv-del { visibility: visible; }
.conv-item .conv-del:hover { color: #b03020; background: #e7d9ce; }

.search-result { display: block; padding: 8px; border-radius: 8px; cursor: pointer; }
.search-result:hover { background: var(--bg-hover); }
.search-result .sr-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.search-result .sr-snippet { font-size: 12px; color: var(--text-dim); line-height: 1.45; }
.search-result .sr-snippet mark { background: #f3d9a8; color: inherit; border-radius: 2px; padding: 0 1px; }
.search-empty { padding: 16px 8px; color: var(--text-dim); font-size: 13px; }

.sidebar-bottom { padding: 10px 12px; border-top: 1px solid var(--border); }
.ghost-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 12px; border: none; border-radius: 10px;
  background: transparent; color: var(--text); font-size: 13.5px;
}
.ghost-btn:hover { background: var(--bg-hover); }

/* ---------- main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.main.welcome-mode .topbar { position: absolute; top: 0; right: 0; z-index: 5; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; min-height: 52px;
}
.topbar-title {
  font-size: 14px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.model-select {
  border: 1px solid transparent; background: transparent; color: var(--text-dim);
  font-size: 13px; border-radius: 8px; padding: 5px 8px; outline: none; cursor: pointer;
}
.model-select:hover { background: var(--bg-hover); color: var(--text); }

.chat-scroll { flex: 1; overflow-y: auto; position: relative; }
.chat-col { max-width: 46rem; margin: 0 auto; padding: 12px 24px 24px; }

.welcome {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center; pointer-events: none;
}
.welcome-greeting {
  font-family: var(--serif); font-size: 34px; color: var(--text);
  display: flex; align-items: center; gap: 14px; margin-bottom: 15vh;
}
.welcome-mark { color: var(--accent); font-size: 30px; }

/* messages */
.msg { margin: 18px 0; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  background: var(--bg-user-msg); border-radius: 16px;
  padding: 10px 16px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word;
}
.msg-assistant .bubble { padding: 0 2px; }

.msg-assistant .bubble > *:first-child { margin-top: 0; }
.msg-assistant .bubble > *:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  font-family: var(--serif); font-weight: 600; line-height: 1.3;
}
.bubble h1 { font-size: 1.45em; } .bubble h2 { font-size: 1.25em; } .bubble h3 { font-size: 1.1em; }
.bubble p { margin: 0.7em 0; }
.bubble ul, .bubble ol { padding-left: 1.4em; margin: 0.6em 0; }
.bubble li { margin: 0.25em 0; }
.bubble a { color: var(--accent); }
.bubble blockquote {
  margin: 0.8em 0; padding: 2px 14px; border-left: 3px solid var(--border-strong);
  color: var(--text-dim);
}
.bubble code {
  font-family: var(--mono); font-size: 0.86em;
  background: #ece9df; border-radius: 5px; padding: 1.5px 5px;
}
.bubble pre {
  background: #282524; color: #eee8e0; border-radius: 12px;
  padding: 14px 16px; overflow-x: auto; margin: 0.9em 0;
}
.bubble pre code { background: none; padding: 0; color: inherit; font-size: 13px; line-height: 1.55; }
.bubble table { border-collapse: collapse; margin: 0.8em 0; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--border-strong); padding: 6px 12px; font-size: 14px; }
.bubble th { background: var(--bg-user-msg); }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }

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

.msg-error {
  color: #b03020; background: #f7e8e4; border: 1px solid #ecd2ca;
  border-radius: 10px; padding: 10px 14px; font-size: 13.5px; margin: 12px 0;
}

/* tool pills (search / code / output) */
.tool-pill {
  border: 1px solid var(--border); border-radius: 10px;
  background: #f4f1ea; margin: 8px 0; font-size: 13px; overflow: hidden;
}
.tool-pill > summary {
  cursor: pointer; padding: 8px 12px; list-style: none; color: var(--text-dim);
  font-weight: 500; user-select: none;
}
.tool-pill > summary::-webkit-details-marker { display: none; }
.tool-pill > summary:hover { color: var(--text); }
.tool-pill pre {
  margin: 0; padding: 10px 14px; background: #282524; color: #eee8e0;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}
.tool-pill.tool-result pre { background: #201d1c; }
.tool-pill.no-toggle > summary { cursor: default; }
.tool-pill.tool-thinking { background: #efeadf; }
.tool-pill.tool-thinking > summary { color: #8a7a5a; font-style: italic; }

.toggle-row { display: flex; gap: 22px; margin-top: 14px; }
.toggle {
  display: flex !important; align-items: center; gap: 7px; font-weight: 500 !important;
  margin: 0 !important; cursor: pointer;
}
.toggle input { width: auto !important; }

/* image attachments */
.attach-preview {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px;
}
.attach-thumb { position: relative; }
.attach-thumb img {
  height: 60px; width: 60px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border-strong);
}
.attach-thumb button {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px;
  border-radius: 50%; border: none; background: var(--text); color: #fff;
  font-size: 10px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.composer.dragging { border-color: var(--accent); background: #fff8f4; }
.msg-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.msg-images img {
  max-width: 260px; max-height: 260px; border-radius: 12px; border: 1px solid var(--border);
}

/* ---------- composer ---------- */
.composer-wrap { padding: 0 24px 10px; }
.composer {
  max-width: 46rem; margin: 0 auto;
  background: #fff; border: 1px solid var(--border-strong);
  border-radius: 18px; padding: 12px 14px 10px;
  box-shadow: 0 4px 18px rgba(80, 70, 50, 0.06);
}
.composer:focus-within { border-color: #c0bab0; box-shadow: 0 4px 22px rgba(80,70,50,0.1); }
.composer textarea {
  width: 100%; border: none; outline: none; resize: none;
  font-size: 15px; line-height: 1.55; background: transparent;
  max-height: 260px; padding: 2px 4px;
}
.composer-row { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.composer-hint { font-size: 12px; color: var(--accent); min-height: 16px; }
.composer-btns { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  border: none; background: transparent; color: var(--text-dim);
  border-radius: 8px; padding: 7px; display: flex; align-items: center;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.recording { color: #fff; background: #c23b22; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: 0.65; } }

.send-btn {
  border: none; border-radius: 10px; background: var(--accent); color: #fff;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: #d9d3c5; cursor: default; }
.send-btn.stop-mode { background: var(--text); }

.composer-note {
  text-align: center; font-size: 11.5px; color: var(--text-dim);
  padding-top: 8px;
}

/* centered composer on welcome screen */
.main.welcome-mode { justify-content: center; }
.main.welcome-mode .chat-scroll { flex: 0 0 auto; overflow: visible; height: 120px; }
.main.welcome-mode .welcome { position: static; }
.main.welcome-mode .welcome-greeting { margin-bottom: 20px; }
.main.welcome-mode .composer-wrap { padding-bottom: 18vh; }

/* ---------- settings modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(60, 55, 40, 0.35);
  display: flex; align-items: center; justify-content: center; z-index: 40;
}
.modal-card {
  background: var(--bg); border-radius: 16px; padding: 22px 26px;
  width: min(620px, 92vw); max-height: 88vh; overflow-y: auto;
  box-shadow: 0 12px 40px rgba(50, 45, 30, 0.25);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { font-family: var(--serif); font-weight: 500; font-size: 22px; margin: 0; }
.modal-card label {
  display: block; font-size: 13px; font-weight: 600; margin: 16px 0 6px;
}
.modal-card .hint { font-weight: 400; color: var(--text-dim); }
.modal-card textarea, .modal-card input, .modal-card select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong);
  border-radius: 10px; background: #fff; font-size: 14px; outline: none;
}
.modal-card textarea { resize: vertical; line-height: 1.55; }
.modal-card textarea:focus, .modal-card input:focus { border-color: var(--accent); }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-top: 20px; }
.saved-note { color: #3f7d3f; font-size: 13px; }
.primary-btn {
  border: none; border-radius: 10px; background: var(--accent); color: #fff;
  padding: 9px 22px; font-size: 14px; font-weight: 500;
}
.primary-btn:hover { background: var(--accent-hover); }

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d8d2c2; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 720px) {
  .sidebar { display: none; }
}
