/* ============================================================
   Claude Chat — design system
   Register: product (UI serves the work).
   Palette: committed warm clay (Claude terracotta) in OKLCH,
   neutrals tinted toward the same hue (~55deg). No pure #000/#fff.
   ============================================================ */

:root {
  /* Warm-tinted dark neutrals (hue ~55, very low chroma) */
  --bg:        oklch(16% 0.008 55);
  --bg-elev:   oklch(20% 0.009 55);
  --bg-elev-2: oklch(25% 0.010 55);
  --bg-hover:  oklch(28% 0.012 55);
  --border:    oklch(30% 0.012 55);
  --border-strong: oklch(40% 0.014 55);

  --text:      oklch(94% 0.006 55);
  --text-dim:  oklch(68% 0.012 55);
  --text-faint: oklch(54% 0.012 55);

  /* Clay accent */
  --accent:        oklch(64% 0.13 45);
  --accent-hover:  oklch(69% 0.14 45);
  --accent-soft:   oklch(64% 0.13 45 / 0.14);
  --accent-text:   oklch(98% 0.01 55);

  --user-bubble: oklch(26% 0.012 55);
  --code-bg:     oklch(13% 0.008 55);
  --danger:      oklch(64% 0.17 25);
  --warn:        oklch(75% 0.14 75);
  --ok:          oklch(72% 0.15 150);

  --radius:    14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --sidebar-w: 288px;
  --reading: 740px;

  --shadow-1: 0 1px 2px oklch(0% 0 0 / 0.3);
  --shadow-2: 0 8px 30px oklch(0% 0 0 / 0.35);
  --ease: cubic-bezier(0.22, 1, 0.36, 1); /* ease-out-quint-ish */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", "Cascadia Code", Consolas, Monaco, monospace;
}

[data-theme="light"] {
  --bg:        oklch(98.5% 0.006 70);
  --bg-elev:   oklch(96% 0.008 70);
  --bg-elev-2: oklch(93% 0.010 70);
  --bg-hover:  oklch(91% 0.012 70);
  --border:    oklch(88% 0.012 70);
  --border-strong: oklch(80% 0.014 70);

  --text:      oklch(25% 0.012 55);
  --text-dim:  oklch(45% 0.013 55);
  --text-faint: oklch(58% 0.013 55);

  --accent:        oklch(56% 0.14 42);
  --accent-hover:  oklch(50% 0.15 42);
  --accent-soft:   oklch(56% 0.14 42 / 0.12);
  --accent-text:   oklch(99% 0.01 70);

  --user-bubble: oklch(94% 0.012 70);
  --code-bg:     oklch(96% 0.008 70);

  --shadow-1: 0 1px 2px oklch(40% 0.02 55 / 0.10);
  --shadow-2: 0 12px 34px oklch(40% 0.04 55 / 0.14);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
button:focus:not(:focus-visible) { outline: none; }

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.35s var(--ease), transform 0.35s var(--ease);
  margin-left: 0;
}
#sidebar:not(.open) {
  margin-left: calc(-1 * var(--sidebar-w));
}

.sidebar-header {
  display: flex;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 4px 12px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand .spark {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
}

.primary-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 14px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.18s var(--ease), transform 0.12s var(--ease);
  box-shadow: var(--shadow-1);
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn span:first-child { font-size: 17px; line-height: 0; }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.chat-list-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 8px 12px 6px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13.5px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.chat-item::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
  transition: background 0.15s;
}
.chat-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-item.active { background: var(--bg-elev-2); color: var(--text); font-weight: 500; }
.chat-item.active::before { background: var(--accent); }
.chat-item .title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .title-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 13.5px;
  font-family: inherit;
}
.chat-item-actions {
  display: none;
  gap: 2px;
}
.chat-item:hover .chat-item-actions,
.chat-item.active .chat-item-actions { display: flex; }

.mini-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  padding: 3px 5px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.mini-btn:hover { color: var(--text); background: var(--bg); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-hover); }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }

/* ---------- Main ---------- */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: oklch(from var(--bg) l c h / 0.85);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
  z-index: 5;
}

.chat-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: 6px;
}

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  /* Allow the messages area to shrink below its content height so the
     flex-shrink:0 composer (and the chat input) stay on-screen on short /
     landscape viewports instead of being pushed off the bottom. */
  min-height: 0;
  overflow-y: auto;
  padding: 28px 0 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  text-align: center;
  gap: 6px;
  padding: 24px;
}
.empty-logo {
  width: 60px; height: 60px;
  display: grid; place-items: center;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 30px;
  margin-bottom: 14px;
}
.empty-state h2 {
  font-size: 25px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.empty-state p { font-size: 14.5px; max-width: 42ch; line-height: 1.55; }

/* Example prompt chips */
.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
  max-width: 560px;
}
.prompt-chip {
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 15px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.45;
  cursor: pointer;
  max-width: 248px;
  transition: border-color 0.18s var(--ease), background 0.18s var(--ease), transform 0.12s var(--ease);
}
.prompt-chip:hover {
  border-color: var(--accent);
  background: var(--bg-elev-2);
  transform: translateY(-2px);
}
.prompt-chip .chip-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.msg {
  max-width: var(--reading);
  margin: 0 auto 24px;
  padding: 0 24px;
  display: flex;
  gap: 14px;
  animation: fadeIn 0.28s var(--ease);
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user { flex-direction: row-reverse; }

.msg .avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-top: 1px;
}
.msg.user .avatar { background: var(--user-bubble); color: var(--text); }
.msg.assistant .avatar { background: var(--accent); color: var(--accent-text); }

.msg .body {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
  line-height: 1.7;
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg.user .body {
  flex: 0 1 auto;
  margin-left: auto;            /* keep the user bubble pinned to the right */
  background: var(--bg-elev-2);
  padding: 11px 15px;
  border-radius: 16px 16px 4px 16px;
  max-width: 80%;
  line-height: 1.55;
  white-space: pre-wrap;
}


/* Markdown */
.body p { margin: 0 0 12px; }
.body p:last-child { margin-bottom: 0; }
.body ul, .body ol { margin: 0 0 12px; padding-left: 24px; }
.body li { margin-bottom: 5px; }
.body li::marker { color: var(--text-faint); }
.body h1, .body h2, .body h3, .body h4 { margin: 20px 0 10px; line-height: 1.3; letter-spacing: -0.01em; }
.body h1 { font-size: 1.5em; font-weight: 700; }
.body h2 { font-size: 1.28em; font-weight: 700; }
.body h3 { font-size: 1.12em; font-weight: 600; }
.body a { color: var(--accent); text-underline-offset: 2px; }
.body a:hover { text-decoration: underline; }
.body hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.body blockquote {
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 14px;
  color: var(--text-dim);
  margin: 0 0 12px;
}
.body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.body th, .body td { border: 1px solid var(--border); padding: 8px 11px; text-align: left; }
.body th { background: var(--bg-elev); font-weight: 600; }

.body :not(pre) > code {
  background: var(--bg-elev-2);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.86em;
  font-family: var(--mono);
}

/* Code blocks */
.code-wrapper {
  position: relative;
  margin: 0 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-faint);
  text-transform: lowercase;
}
.code-wrapper pre { margin: 0; padding: 15px; overflow-x: auto; }
.code-wrapper pre code {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  background: transparent !important;
  padding: 0 !important;
}
.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-elev-2); }
.copy-btn.copied { color: var(--ok); border-color: var(--ok); }

/* Thinking indicator */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-dim);
}
.thinking .dots span {
  display: inline-block;
  width: 6px; height: 6px;
  margin: 0 1px;
  background: var(--accent);
  border-radius: 50%;
  animation: blink 1.4s infinite both;
}
.thinking .dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ---------- Composer ---------- */
.composer {
  flex-shrink: 0;
  padding: 10px 16px 14px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.composer-settings {
  max-width: var(--reading);
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.model-selector {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 4px 3px 12px;
  transition: border-color 0.15s;
}
.model-selector:hover { border-color: var(--border-strong); }
.model-selector label {
  color: var(--text-faint);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.model-dropdown {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  max-width: 200px;
}
.model-dropdown:focus { outline: none; }
.model-dropdown option { background: var(--bg-elev); color: var(--text); }

/* Thinking toggle as a pill */
.thinking-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 13px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.thinking-toggle:hover { border-color: var(--border-strong); color: var(--text); }
.thinking-toggle:has(input:checked) {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.thinking-toggle input { accent-color: var(--accent); cursor: pointer; }

/* Thinking block */
.thinking-block {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  overflow: hidden;
}
.thinking-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.thinking-summary::-webkit-details-marker { display: none; }
.thinking-summary .chevron { transition: transform 0.2s var(--ease); display: inline-block; }
.thinking-block[open] .thinking-summary .chevron { transform: rotate(90deg); }
.thinking-content {
  padding: 4px 15px 13px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.thinking-block.streaming .thinking-summary .spark { animation: blink 1.4s infinite both; }

/* Context usage */
.context-usage {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-left: auto;
}
.context-bar {
  width: 96px;
  height: 5px;
  background: var(--bg-elev-2);
  border-radius: 999px;
  overflow: hidden;
}
.context-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s var(--ease), background 0.3s;
}
.context-bar-fill.warn { background: var(--warn); }
.context-bar-fill.danger { background: var(--danger); }
.context-text { white-space: nowrap; font-variant-numeric: tabular-nums; }

.composer-inner {
  max-width: var(--reading);
  margin: 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
  box-shadow: var(--shadow-1);
}
.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer-main {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 9px 9px 9px 14px;
}

.composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 11px 14px 0;
}
.composer-attachments:empty { display: none; }

.file-preview {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-dim);
  max-width: 200px;
}
.file-preview-icon { font-size: 16px; }
.file-preview-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-preview-remove {
  background: transparent; border: none; color: var(--text-faint);
  cursor: pointer; padding: 0 4px; font-size: 14px; line-height: 1;
}
.file-preview-remove:hover { color: var(--danger); }

.attach-btn {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 19px;
  cursor: pointer;
  padding: 7px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.attach-btn:hover { color: var(--text); background: var(--bg-hover); }

#input {
  flex: 1;
  resize: none;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  font-family: inherit;
  max-height: 200px;
  overflow-y: auto;
  padding: 8px 0;
}
#input::placeholder { color: var(--text-faint); }

.send-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, opacity 0.15s, transform 0.12s var(--ease);
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.composer-hint {
  max-width: var(--reading);
  margin: 9px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
}
.composer-hint kbd {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--text-dim);
}
.composer-hint .credit {
  display: inline-block;
  margin-top: 3px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.2px;
}

/* Scroll-to-bottom button */
.scroll-bottom-btn {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 15px;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease), color 0.15s;
  z-index: 6;
}
.scroll-bottom-btn.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.scroll-bottom-btn:hover { color: var(--text); border-color: var(--accent); }

/* Error message */
.error-banner {
  max-width: var(--reading);
  margin: 0 auto 16px;
  padding: 12px 16px;
  background: oklch(from var(--danger) l c h / 0.12);
  border: 1px solid oklch(from var(--danger) l c h / 0.5);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 14px;
}

.continuing-hint {
  display: inline-flex;
  align-items: center;
  margin-top: 6px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  font-weight: 500;
}

/* Rate-limit auto-retry countdown */
.rate-limit-wait {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--warn);
  background: oklch(from var(--warn) l c h / 0.12);
  border: 1px solid oklch(from var(--warn) l c h / 0.4);
  border-radius: var(--radius);
}
.rate-limit-wait strong { font-variant-numeric: tabular-nums; }
.rate-limit-wait .rl-spin { animation: blink 1.4s infinite both; }

/* ---------- Sidebar search ---------- */
.sidebar-search {
  padding: 8px 12px 4px;
}
.sidebar-search input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.sidebar-search input:focus { border-color: var(--accent); }
.sidebar-search input::placeholder { color: var(--text-faint); }
.chat-list-empty {
  padding: 18px 14px;
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
}
.chat-item.pinned .title { font-weight: 500; }
.mini-btn.on { color: var(--accent); }

/* ---------- Pill buttons + settings panels ---------- */
.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 13px;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.pill-btn:hover { border-color: var(--border-strong); color: var(--text); }
.pill-btn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.settings-panel {
  max-width: var(--reading);
  margin: 0 auto 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  animation: fadeIn 0.2s var(--ease);
  /* Keep the panel within the viewport and scroll internally when its content
     is taller than the space available (e.g. on short / mobile-landscape
     screens) so options and the chat input below it are never clipped. */
  max-height: 60vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.settings-panel[hidden] { display: none; }
.settings-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.settings-dim { color: var(--text-faint); font-weight: 400; }
.settings-panel textarea,
.settings-panel input[type="text"],
.settings-panel input[type="number"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}
.settings-panel textarea:focus,
.settings-panel input:focus { border-color: var(--accent); }
.settings-row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 18px;
}
.settings-grid label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); display: flex; flex-direction: column; gap: 6px; }
.settings-grid input[type="range"] { accent-color: var(--accent); width: 100%; }
.settings-note { margin-top: 12px; font-size: 11.5px; color: var(--text-faint); }
.primary-btn.slim { flex: 0 0 auto; padding: 8px 16px; font-size: 13px; }

/* ---------- Per-message actions + badges ---------- */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  opacity: 0;
  transition: opacity 0.15s var(--ease);
}
.msg:hover .msg-actions { opacity: 1; }
.msg.user .msg-actions { justify-content: flex-end; }
.msg-act-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.msg-act-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-elev-2); }
.model-badge {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-faint);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  margin-right: auto;
}
.msg.user .model-badge { margin-right: 0; margin-left: auto; }

/* Inline message editor (edit & resend) */
.msg-editor { display: flex; flex-direction: column; gap: 8px; }
.msg-editor textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}
.msg-editor-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* User message attachments rendered in the bubble */
.msg-image {
  max-width: 260px;
  max-height: 260px;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
  margin: 2px 0;
}
.msg-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 3px 0;
}
.msg-text + .msg-text { margin-top: 6px; }

/* Token estimate in the composer hint */
.token-estimate { color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* Drag-and-drop affordance on the composer */
.composer.drag-over .composer-inner {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer.drag-over .composer-inner::after {
  content: "Drop files to attach";
  display: block;
  text-align: center;
  color: var(--accent);
  font-size: 12px;
  padding: 4px 0 8px;
}

/* ---------- Mobile ---------- */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: oklch(0% 0 0 / 0.5);
  backdrop-filter: blur(2px);
  z-index: 19;
}

@media (max-width: 768px) {
  :root { --reading: 100%; }
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 20;
    margin-left: 0 !important;
    transform: translateX(-100%);
    box-shadow: var(--shadow-2);
    /* Clear the notch / status-bar area when the sheet slides in. */
    padding-top: env(safe-area-inset-top);
  }
  #sidebar.open { transform: translateX(0); }
  .backdrop.show { display: block; }
  .msg { padding: 0 14px; }
  .msg.user .body { max-width: 86%; }
  .topbar-actions .ghost-btn { padding: 7px 9px; font-size: 12px; }
  .composer-settings { gap: 6px; }
  .model-dropdown { max-width: 130px; }

  /* Keep the composer above the home indicator / gesture bar. */
  .composer { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }

  /* Touch screens have no hover, so reveal the rename/delete actions for every
     conversation rather than only the active one. */
  .chat-item-actions { display: flex; }

  /* Roomier tap targets (≈44px) for the icon and per-chat mini buttons. */
  .icon-btn { padding: 9px 11px; }
  .mini-btn { padding: 7px 9px; font-size: 15px; }

  /* Touch has no hover — keep per-message actions visible. */
  .msg-actions { opacity: 1; }
  /* Stack the advanced settings grid on narrow screens. */
  .settings-grid { grid-template-columns: 1fr; }
  .msg-image { max-width: 80%; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ── Usage limits modal ─────────────────────────────────────────────── */
.limits-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55); padding: 20px;
}
.limits-overlay.open { display: flex; }
.limits-modal {
  width: 100%; max-width: 620px; max-height: 85vh; overflow: auto;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}
.limits-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-elev);
}
.limits-modal-header h2 { font-size: 18px; font-weight: 600; margin: 0; color: var(--text); }
.limits-body { padding: 20px; }
.limits-loading { color: var(--text-dim); text-align: center; padding: 24px 0; }
.lim-meta {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-bottom: 18px; font-size: 14px; color: var(--text);
}
.lim-dim { color: var(--text-dim); font-size: 12px; }
.lim-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.lim-table th, .lim-table td {
  text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--border);
}
.lim-table th:first-child, .lim-table td:first-child { text-align: left; }
.lim-table th { color: var(--text-dim); font-weight: 500; font-size: 12px; }
.lim-table td { color: var(--text); font-variant-numeric: tabular-nums; }
.lim-model { font-weight: 500; }
.lim-extras { list-style: none; padding: 0; margin: 16px 0 0; font-size: 14px; color: var(--text); }
.lim-extras li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.lim-extras li:last-child { border-bottom: none; }
.lim-note { margin-top: 16px; font-size: 12px; color: var(--text-dim); line-height: 1.5; }

/* ── Usage / credit modal ───────────────────────────────────────────── */
.usage-hero {
  text-align: center;
  padding: 18px 16px 20px;
  margin-bottom: 18px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--bg-hover), transparent);
  border: 1px solid var(--border);
}
.usage-credit {
  font-size: 40px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.usage-credit-label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.usage-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 16px 0 18px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.usage-stats > div { line-height: 1.5; }
.usage-ws {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  word-break: break-all;
}
.usage-limit { margin-top: 14px; }
.usage-limit-bar {
  height: 8px;
  background: var(--bg-elev-2);
  border-radius: 999px;
  overflow: hidden;
}
.usage-limit-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s var(--ease), background 0.3s;
}
.usage-limit-fill.warn { background: var(--warn); }
.usage-limit-fill.danger { background: var(--danger); }
.usage-limit-text { margin-top: 6px; font-size: 12px; color: var(--text-dim); }
.usage-empty { text-align: center; color: var(--text-dim); padding: 16px 0; }

.usage-region {
  margin: 4px 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
}
.usage-region label { display: block; margin-bottom: 8px; font-size: 12px; }
.usage-region select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  max-width: 100%;
}
.usage-region select:focus { outline: none; border-color: var(--accent); }
.usage-region .lim-note { margin-top: 8px; }
.usage-region code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--bg-elev-2);
  padding: 1px 5px;
  border-radius: 5px;
}

@media (max-width: 560px) {
  .usage-stats { grid-template-columns: repeat(2, 1fr); }
  .usage-credit { font-size: 34px; }
}


/* ============================================================
   FOCUS MODE — hide chrome to maximize chat space.
   A floating toggle (top-right) collapses the top bar, the composer
   toolbar buttons, and the footer ("Designed by…"), keeping the chat
   input and messages. Especially useful on mobile landscape.
   ============================================================ */
.focus-toggle {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 50;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: oklch(from var(--bg) l c h / 0.7);
  backdrop-filter: blur(8px);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.focus-toggle:hover { opacity: 1; background: var(--bg-hover); }
.focus-toggle.on { opacity: 0.85; }

/* The fullscreen button sits just left of the focus button. */
#fullscreen-toggle { right: 50px; }

/* Reserve space so the floating buttons don't overlap the top-bar actions. */
#topbar { padding-right: 96px; }

/* When focus mode is on, hide the chrome (NOT the chat input or messages). */
body.focus-mode #topbar { display: none; }
body.focus-mode .composer-settings { display: none; }
body.focus-mode .composer-hint { display: none; }

/* Fullscreen mode hides everything except the messages, the input, and the
   button to exit. Native browser fullscreen is requested alongside this. */
body.fullscreen-mode #topbar,
body.fullscreen-mode .composer-settings,
body.fullscreen-mode .composer-hint,
body.fullscreen-mode #sidebar,
body.fullscreen-mode #backdrop,
body.fullscreen-mode #focus-toggle { display: none; }
body.fullscreen-mode #fullscreen-toggle { right: 8px; }

/* Short viewports (notably mobile landscape): the composer is flex-shrink:0, so
   a tall settings panel would otherwise push the chat input off-screen. Cap the
   panels harder and trim spacing; combined with overflow-y:auto above, the
   options scroll within the panel and the input stays visible. */
@media (max-height: 600px) {
  /* Float the settings panel ABOVE the composer (over the messages) so it no
     longer expands the flex-shrink:0 composer and push the chat input off the
     bottom. The panel scrolls internally; the input stays pinned and visible. */
  .composer {
    position: relative;
    padding-top: 6px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .settings-panel {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(100% + 4px);
    margin: 0 auto;
    max-width: var(--reading);
    max-height: calc(100dvh - 260px);
    padding: 10px 12px;
    box-shadow: var(--shadow-2);
    z-index: 30;
  }
  .settings-grid { gap: 10px 14px; }
  .settings-note { margin-top: 8px; }
}

/* Plan-expiry banner in the Billing modal. */
.usage-expiry {
  margin: 12px 0 4px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  font-size: 13.5px;
  color: var(--text);
}
.usage-expiry.ok { color: var(--text-dim); }
.usage-expiry.warn {
  border-color: oklch(from var(--warn) l c h / 0.5);
  background: oklch(from var(--warn) l c h / 0.12);
}
.usage-expiry.danger {
  border-color: oklch(from var(--danger) l c h / 0.55);
  background: oklch(from var(--danger) l c h / 0.13);
}

/* --- Change-password modal form --- */
.pw-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.pw-field label {
  font-size: 13px;
  color: var(--text-dim);
}
.pw-field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}
.pw-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.pw-message {
  font-size: 13px;
  margin: 2px 0 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.pw-message.ok {
  color: var(--ok);
  border-color: oklch(from var(--ok) l c h / 0.45);
  background: oklch(from var(--ok) l c h / 0.12);
}
.pw-message.err {
  color: var(--danger);
  border-color: oklch(from var(--danger) l c h / 0.5);
  background: oklch(from var(--danger) l c h / 0.12);
}
