:root {
  --bg: #09090b;
  --bg-elevated: #141416;
  --bg-hover: #1c1c1f;
  --border: #27272a;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --accent: #e4e4e7;
  --user-bubble: #27272a;
  --assistant-bubble: transparent;
  --reasoning: #3f3f46;
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  overflow: hidden;
}

.shell {
  display: flex;
  height: 100vh;
  width: 100%;
  background: var(--bg);
  overflow: hidden;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.view-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view-panel[hidden] {
  display: none;
}

.view-chat {
  align-items: center;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 900px;
}

.view-settings {
  width: 100%;
}

/* ── Sidebar (nav + chat history) ── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.settings-btn {
  width: 30px;
  height: 30px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.settings-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.sidebar-settings {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.sidebar-settings[hidden] {
  display: none;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  flex: 1;
}

.side-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.side-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.side-nav-item.active {
  background: var(--bg-hover);
  color: var(--text);
}

.side-nav-icon {
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.side-nav-label {
  flex: 1;
  min-width: 0;
}

.sidebar-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.sidebar-chat[hidden] {
  display: none;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar-new {
  padding: 5px 10px;
  font-size: 0.75rem;
  white-space: nowrap;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.history-empty {
  padding: 14px 10px;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 2px;
}

.history-item.active .history-open {
  background: var(--bg-hover);
}

.history-item.running .history-title::after {
  content: " …";
  opacity: 0.65;
}

.history-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.history-open:hover {
  background: var(--bg-hover);
}

.history-title {
  font-size: 0.82rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.history-when {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.history-delete {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s;
}

.history-item:hover .history-delete,
.history-item:focus-within .history-delete {
  opacity: 1;
}

.history-delete:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.menu-btn {
  display: none;
  margin-right: 4px;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.brand-icon {
  font-size: 1.25rem;
  color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  max-width: 200px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn.ghost:hover {
  background: var(--bg-hover);
}

/* ── Chat log ── */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar {
  width: 6px;
}

.chat::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.welcome {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.welcome h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text);
}

.welcome p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.msg {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.msg.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.msg.user .msg-avatar {
  background: var(--user-bubble);
}

.msg-body {
  max-width: 85%;
  min-width: 0;
}

.msg.user .msg-body {
  text-align: right;
}

.msg-content {
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.assistant .msg-content.markdown {
  white-space: normal;
}

.msg.assistant .msg-content.markdown > :first-child {
  margin-top: 0;
}

.msg.assistant .msg-content.markdown > :last-child {
  margin-bottom: 0;
}

.msg.assistant .msg-content.markdown p {
  margin: 0 0 0.75em;
}

.msg.assistant .msg-content.markdown h1,
.msg.assistant .msg-content.markdown h2,
.msg.assistant .msg-content.markdown h3,
.msg.assistant .msg-content.markdown h4 {
  margin: 1.1em 0 0.45em;
  line-height: 1.3;
  font-weight: 600;
}

.msg.assistant .msg-content.markdown h1 { font-size: 1.35rem; }
.msg.assistant .msg-content.markdown h2 { font-size: 1.2rem; }
.msg.assistant .msg-content.markdown h3 { font-size: 1.05rem; }
.msg.assistant .msg-content.markdown h4 { font-size: 0.98rem; color: var(--text-muted); }

.msg.assistant .msg-content.markdown ul,
.msg.assistant .msg-content.markdown ol {
  margin: 0.4em 0 0.85em;
  padding-left: 1.35em;
}

.msg.assistant .msg-content.markdown li {
  margin: 0.25em 0;
}

.msg.assistant .msg-content.markdown li > p {
  margin: 0;
}

.msg.assistant .msg-content.markdown code {
  font-family: Consolas, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.88em;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

.msg.assistant .msg-content.markdown pre {
  margin: 0.75em 0;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
}

.msg.assistant .msg-content.markdown pre code {
  display: block;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 0.84rem;
  line-height: 1.45;
  white-space: pre;
}

.msg.assistant .msg-content.markdown blockquote {
  margin: 0.75em 0;
  padding: 0.35em 0 0.35em 12px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.msg.assistant .msg-content.markdown a {
  color: #93c5fd;
  text-decoration: none;
}

.msg.assistant .msg-content.markdown a:hover {
  text-decoration: underline;
}

.msg.assistant .msg-content.markdown table {
  width: 100%;
  margin: 0.75em 0;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.msg.assistant .msg-content.markdown th,
.msg.assistant .msg-content.markdown td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}

.msg.assistant .msg-content.markdown th {
  background: var(--bg-elevated);
  font-weight: 600;
}

.msg.assistant .msg-content.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

.msg.assistant .msg-content.markdown a.cite-ref {
  color: #93c5fd;
  text-decoration: none;
  font-size: 0.82em;
  vertical-align: super;
  line-height: 0;
  padding: 0 1px;
}

.msg.assistant .msg-content.markdown a.cite-ref:hover {
  text-decoration: underline;
}

.msg.assistant .sources-footer {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.84rem;
}

.msg.assistant .sources-footer-title {
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.msg.assistant .sources-footer-list {
  margin: 0;
  padding-left: 1.25rem;
}

.msg.assistant .sources-footer-list li {
  margin: 0.2em 0;
}

.msg.assistant .sources-footer-list a {
  color: #93c5fd;
  text-decoration: none;
}

.msg.assistant .sources-footer-list a:hover {
  text-decoration: underline;
}

.msg.user .msg-content {
  background: var(--user-bubble);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: inline-block;
  text-align: left;
}

.msg-media {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.msg-media img {
  max-width: 220px;
  max-height: 160px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.media-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.reasoning {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elevated);
}

.reasoning summary {
  padding: 8px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.reasoning-body {
  padding: 0 12px 10px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.msg.assistant {
  align-items: flex-start;
}

.msg.assistant .msg-status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding-top: 5px;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.msg.assistant .msg-status[hidden] {
  display: none !important;
}

.msg.assistant.is-working:not(.has-reply) .msg-body {
  display: none;
}

.msg-status-spinner {
  width: 12px;
  height: 12px;
  margin-top: 3px;
  border: 2px solid var(--border);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: warmup-spin 0.8s linear infinite;
  flex-shrink: 0;
}

.msg.assistant.streaming.has-reply .msg-content:not(:empty)::after {
  content: "▋";
  animation: blink 0.9s step-end infinite;
  margin-left: 2px;
  opacity: 0.7;
}

@keyframes blink {
  50% { opacity: 0; }
}

.error-banner {
  background: #3b1219;
  border: 1px solid #7f1d1d;
  color: #fecaca;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.warmup-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-shrink: 0;
  margin: 0 20px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #1a1a2e;
  border: 1px solid #3f3f5c;
  color: #c4c4d4;
  font-size: 0.82rem;
  animation: warmup-in 0.25s ease;
}

.warmup-banner[hidden] {
  display: none;
}

.warmup-banner.fading {
  animation: warmup-out 0.35s ease forwards;
}

.warmup-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #3f3f5c;
  border-top-color: #c4c4d4;
  border-radius: 50%;
  animation: warmup-spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes warmup-spin {
  to { transform: rotate(360deg); }
}

@keyframes warmup-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes warmup-out {
  to { opacity: 0; transform: translateY(-4px); }
}

/* ── Composer ── */
.composer-wrap {
  flex-shrink: 0;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px 4px 4px;
  font-size: 0.78rem;
}

.attach-chip img {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: cover;
}

.attach-chip button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 1rem;
  line-height: 1;
}

.attach-chip button:hover {
  color: var(--text);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 10px 8px 6px;
}

.composer:focus-within {
  border-color: #52525b;
}

.composer-tools {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.75;
}

.icon-btn:hover {
  background: var(--bg-hover);
  opacity: 1;
}

#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.45;
  resize: none;
  max-height: 160px;
  padding: 6px 4px;
  outline: none;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  opacity: 0.9;
}

.hint {
  margin: 8px 0 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.resource-label {
  font-variant-numeric: tabular-nums;
}

/* ── Settings page (main window) ── */
.settings-page-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.settings-menu-btn {
  display: none;
}

.settings-page-title-wrap {
  flex: 1;
  min-width: 0;
}

.settings-page-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.settings-page-sub {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.settings-page-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 32px;
}

.settings-tab-panel[hidden] {
  display: none;
}

.settings-section-wide {
  max-width: 720px;
}

.model-select-full {
  width: 100%;
  max-width: none;
}

.settings-field-block {
  margin-bottom: 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 24px;
  align-items: start;
  overflow: visible;
  max-width: 1100px;
}

.settings-prompt-col {
  margin-bottom: 0;
}

.settings-side-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.prompt-active {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

.prompt-active-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
}

.prompt-source {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
}

.prompt-updated {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.prompt-preview {
  margin: 0;
  padding: 10px 12px;
  max-height: 220px;
  overflow-y: auto;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 0.74rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
}

.settings-section {
  margin-bottom: 22px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section h3 {
  margin: 0 0 6px;
  font-size: 0.88rem;
  font-weight: 600;
}

.settings-hint {
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.settings-hint code {
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

#systemPromptInput {
  width: 100%;
  resize: vertical;
  min-height: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.45;
  padding: 10px 12px;
}

.settings-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.settings-toggle {
  margin-top: 4px;
}

.knowledge-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.knowledge-empty {
  padding: 14px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.knowledge-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.knowledge-item:last-child {
  border-bottom: none;
}

.knowledge-meta {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.knowledge-delete {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.knowledge-delete:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.settings-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.spell-hint,
.web-search-hint {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

.web-search-hint a {
  color: var(--accent, #6b9fff);
  text-decoration: none;
}

.web-search-hint a:hover {
  text-decoration: underline;
}

.settings-inline {
  margin-top: 10px;
  gap: 12px;
  flex-wrap: wrap;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.settings-field input,
.settings-field select {
  min-width: 100px;
}

.api-key-create {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.api-key-name-input {
  flex: 1;
  min-width: 180px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
}

.api-key-reveal {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--accent, #6b9fff);
  border-radius: 8px;
  background: rgba(107, 159, 255, 0.08);
}

.api-key-reveal-label {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: var(--text);
}

.api-key-reveal-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.api-key-value {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg);
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 0.76rem;
  word-break: break-all;
}

.api-key-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  max-height: 220px;
  overflow-y: auto;
}

.api-key-empty {
  padding: 14px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.api-key-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.api-key-item:last-child {
  border-bottom: none;
}

.api-key-meta {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-top: 2px;
}

.api-key-delete {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.api-key-delete:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.api-usage-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.api-usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.api-usage-table th,
.api-usage-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.api-usage-table th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg-hover);
}

.api-usage-table tr:last-child td {
  border-bottom: none;
}

.api-usage-empty {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

.api-usage-key-name {
  font-weight: 500;
}

.api-usage-key-prefix {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.api-usage-prompt {
  max-width: 360px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.api-usage-hint {
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 900px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .prompt-preview {
    max-height: 160px;
  }

  .settings-page-body {
    padding: 16px;
  }
}

@media (max-width: 860px) {
  .menu-btn,
  .settings-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }

  .shell.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 12px 0 32px rgba(0, 0, 0, 0.35);
  }

  .shell.sidebar-open .main::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 50;
    pointer-events: auto;
  }

  .msg-body {
    max-width: 92%;
  }
}