:root {
  --bg: #faf9f6;
  --panel: #ffffff;
  --panel-2: #f5f3ee;
  --border: #e6e2da;
  --text: #2c2a29;
  --text-dim: #736f6a;
  --accent: #d97757;
  --accent-hover: #c46546;
  --accent-dim: rgba(217, 119, 87, 0.25);
  --accent-soft: rgba(217, 119, 87, 0.1);
  --user-bubble: #f3eae2;
  --assistant-bubble: #ffffff;
  --success: #3c8c62;
  --danger: #c94a4a;
  --shadow: 0 2px 8px rgba(44, 42, 41, 0.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #181715;
  --panel: #22201e;
  --panel-2: #181715;
  --border: #33302c;
  --text: #ebe7e0;
  --text-dim: #9e9890;
  --accent: #e08668;
  --accent-hover: #ec977b;
  --accent-dim: rgba(224, 134, 104, 0.3);
  --accent-soft: rgba(224, 134, 104, 0.12);
  --user-bubble: #2e2925;
  --assistant-bubble: #22201e;
  --success: #58b382;
  --danger: #e06c6c;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background-color 0.2s, color 0.2s;
}

.app {
  display: flex;
  height: 100vh;
  width: 100%;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.15s, transform 0.15s, background-color 0.2s;
}

.sidebar.collapsed {
  width: 0;
  border-right: none;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
}

.dm-start-form input[type="text"] {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  min-width: 0;
}
.dm-start-form input[type="text"]:focus { outline: none; border-color: var(--accent); }
.dm-start-form .new-chat-btn { flex: 0 0 auto; padding: 8px 14px; }

.conv-item-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

.new-chat-btn {
  flex: 1;
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.new-chat-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.icon-btn {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.icon-btn:hover { border-color: var(--text-dim); color: var(--text); }

.theme-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12.5px;
  white-space: nowrap;
  transition: all 0.15s;
}
.theme-btn:hover { color: var(--text); border-color: var(--text-dim); }

.sidebar-toggle-mobile { display: none; }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 12px 8px;
  text-align: center;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-dim);
  transition: all 0.15s;
}

.conv-item:hover { background: var(--panel-2); color: var(--text); }

.conv-item.active {
  background: var(--panel-2);
  color: var(--accent);
  border-color: var(--border);
  font-weight: 500;
}

.conv-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conv-item-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s;
}

.conv-item:hover .conv-item-actions,
.conv-item.active .conv-item-actions {
  opacity: 1;
}

.conv-action-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  width: 22px;
  height: 22px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}
.conv-action-btn:hover { background: var(--border); color: var(--text); }
.conv-action-btn.danger:hover { background: var(--danger); color: #ffffff; }

.main {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: none;
  margin: 0;
  padding: 0 clamp(16px, 3vw, 40px);
  width: 100%;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  backdrop-filter: blur(2px);
  border: 1.5px dashed var(--accent);
  border-radius: 14px;
  margin: 8px;
  pointer-events: none;
}

.drop-overlay-inner {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  padding: 10px 20px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 0 10px;
}

.topbar .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color 0.15s;
}
.ghost-btn:hover { border-color: var(--text-dim); }

.model-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 0 14px;
  border-bottom: 1px solid var(--border);
}

.model-btn {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: all 0.15s;
}

.model-btn:hover { color: var(--text); background: var(--panel-2); }

.model-btn.active {
  background: var(--panel);
  border-color: var(--border);
  color: var(--accent);
  box-shadow: var(--shadow);
}

.model-btn .tag {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 1px;
}

.status-line {
  font-size: 12.5px;
  color: var(--text-dim);
  min-height: 18px;
  padding: 6px 2px 0;
}

.status-line.error { color: var(--danger); }
.status-line.searching { color: var(--accent); }

.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 16px 2px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border: 1px solid var(--border);
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
}

.msg.system-note {
  align-self: center;
  color: var(--text-dim);
  font-size: 12.5px;
  background: transparent;
}

.msg .meta {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 6px;
}

.attach-btn,
.search-toggle-btn {
  align-self: flex-end;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 8px;
}

.attach-btn.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.attach-icon,
.search-toggle-icon {
  width: 100%;
  height: 100%;
  padding: 0;
  object-fit: contain;
  display: block;
  opacity: 0.65;
  transition: opacity 0.15s;
}

[data-theme="dark"] .attach-icon,
[data-theme="dark"] .search-toggle-icon,
[data-theme="midnight"] .attach-icon,
[data-theme="midnight"] .search-toggle-icon,
[data-theme="forest"] .attach-icon,
[data-theme="forest"] .search-toggle-icon {
  filter: invert(90%) saturate(0%);
}

.attach-btn:hover .attach-icon,
.search-toggle-btn:hover .search-toggle-icon {
  opacity: 1;
}

.search-toggle-btn[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--accent);
}

.search-toggle-btn[aria-pressed="true"] .search-toggle-icon {
  opacity: 1;
  filter: none;
  background-color: var(--accent);
  -webkit-mask-image: url("/websearch.png");
  mask-image: url("/websearch.png");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.attach-preview {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 2px 8px;
}
.attach-preview:empty { display: none; }

.attach-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.attach-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attach-thumb .remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-thumb .remove-btn:hover { background: var(--danger); color: #ffffff; border-color: var(--danger); }

.msg-images {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.msg-images img {
  max-width: 160px;
  max-height: 160px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  display: block;
}

.msg-thinking {
  margin-bottom: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}

.msg-thinking[hidden] { display: none; }

.msg-thinking summary {
  cursor: pointer;
  padding: 6px 10px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  user-select: none;
}
.msg-thinking summary:hover { color: var(--text); }

.msg-thinking[open] summary {
  border-bottom: 1px dashed var(--border);
}

.msg-thinking-text {
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-wrap: break-word;
  font-style: italic;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 0 18px;
  border-top: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  resize: none;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  max-height: 140px;
  font-family: inherit;
  line-height: 1.45;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }

.composer button[type="submit"] {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  padding: 0 18px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}
.composer button[type="submit"]:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.composer button:disabled { opacity: 0.45; cursor: not-allowed; }

.cursor-blink::after {
  content: "▍";
  animation: blink 1s step-start infinite;
  color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  position: relative;
}

.auth-theme-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.auth-card .title {
  text-align: center;
  margin-bottom: 4px;
}

.auth-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 13.5px;
  margin: 0 0 20px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
}
.auth-form input:focus { outline: none; border-color: var(--accent); }

.auth-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.auth-actions button[type="submit"] {
  flex: 1;
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  padding: 9px 0;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.auth-actions button[type="submit"]:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.auth-actions .ghost-btn {
  flex: 1;
  padding: 9px 0;
  text-align: center;
}

.auth-msg {
  margin-top: 14px;
  font-size: 13px;
  text-align: center;
  color: var(--text-dim);
  min-height: 16px;
}
.auth-msg.error { color: var(--danger); }

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}

@media (max-width: 760px) {
  .sidebar-toggle { display: none; }
  .sidebar-toggle-mobile { display: block; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 20;
    width: 80vw;
    max-width: 300px;
    transform: translateX(-100%);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar.collapsed { width: 80vw; max-width: 300px; }
  .main { padding: 0 12px; }
}

[hidden] { display: none !important; }

.dm-section {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  max-height: 50%;
  min-height: 0;
  border-top: 1px solid var(--border);
}
.dm-section .conv-list { flex: 0 1 auto; min-height: 0; }

.sidebar-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.dm-start-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 8px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.settings-btn {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.settings-btn:hover {
  border-color: var(--text-dim);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-dim);
}

.modal-field input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
}
.modal-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.favicon-preview {
  width: 24px;
  height: 24px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
.modal-actions .new-chat-btn {
  flex: 0 0 auto;
  padding: 8px 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.conv-item.has-unread { color: var(--text); }
.conv-item.has-unread .conv-item-title > span:first-child { font-weight: 600; }
.conv-item.has-unread .conv-item-sub { color: var(--text); opacity: 0.8; }

.icon-btn.has-unread::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}

.app:has(.sidebar.collapsed) .sidebar-toggle-mobile { display: block; }

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(340px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 8px 10px 12px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.clickable { cursor: pointer; }
.toast.clickable:hover { border-color: var(--text-dim); }
.toast.leaving { animation: toast-out 0.18s ease-in forwards; }

.toast-text { flex: 1; min-width: 0; }
.toast-title { font-size: 13px; font-weight: 600; color: var(--text); }
.toast-body {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast-tip {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text);
}

.toast-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  width: 22px;
  height: 22px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  flex-shrink: 0;
}
.toast-close:hover { background: var(--border); color: var(--text); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(16px); }
}

.msg-text.md {
  display: block;
  white-space: normal;
}
.msg-text.md > :first-child { margin-top: 0; }
.msg-text.md > :last-child { margin-bottom: 0; }
.msg-text.md p { margin: 0 0 0.75em; }
.msg-text.md h1, .msg-text.md h2, .msg-text.md h3,
.msg-text.md h4, .msg-text.md h5, .msg-text.md h6 {
  margin: 1em 0 0.4em;
  line-height: 1.3;
  font-weight: 600;
}
.msg-text.md h1 { font-size: 1.35em; }
.msg-text.md h2 { font-size: 1.2em; }
.msg-text.md h3 { font-size: 1.08em; }
.msg-text.md h4, .msg-text.md h5, .msg-text.md h6 { font-size: 1em; }
.msg-text.md ul, .msg-text.md ol { margin: 0 0 0.75em; padding-left: 1.5em; }
.msg-text.md li { margin: 0.2em 0; }
.msg-text.md li > ul, .msg-text.md li > ol { margin: 0.2em 0 0; }
.msg-text.md strong { font-weight: 600; }
.msg-text.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.msg-text.md a:hover { color: var(--accent-hover); }
.msg-text.md hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.msg-text.md blockquote {
  margin: 0 0 0.75em;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--accent-dim);
  color: var(--text-dim);
}
.msg-text.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}
.msg-text.md pre {
  margin: 0 0 0.75em;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre;
}
.msg-text.md pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
}
.msg-text.md .md-table-wrap { overflow-x: auto; margin: 0 0 0.75em; }
.msg-text.md table { border-collapse: collapse; font-size: 0.95em; }
.msg-text.md th, .msg-text.md td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
}
.modal-desc {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-dim);
  line-height: 1.5;
}
.msg-text.md th { background: var(--panel-2); font-weight: 600; }

.msg-text.md .katex-display { margin: 0.6em 0; overflow-x: auto; overflow-y: hidden; }
.msg-text.md .katex { font-size: 1.05em; }

/* ---- Review modal ---- */
.modal-card-wide { max-width: 480px; max-height: 90vh; overflow-y: auto; }
.review-form { gap: 14px; }
.review-text {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
}
.review-text:focus { outline: none; border-color: var(--accent); }
.review-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px 12px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.review-group legend { font-size: 13px; font-weight: 600; color: var(--text); padding: 0 6px; }
.review-error { color: var(--danger); font-size: 13px; }

/* ---- Star rating: hovering/picking star N lights stars 1..N ---- */
.star-row {
  display: flex;
  flex-direction: row-reverse; /* DOM is 5..1 so "~" reaches the lower stars */
  justify-content: flex-end;
  gap: 2px;
}
.star-row input { position: absolute; opacity: 0; pointer-events: none; }
.star-row label {
  font-size: 30px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  color: var(--text-dim);
  opacity: 0.35;
  transition: color 0.1s, opacity 0.1s, transform 0.1s;
}
.star-row:hover label { color: var(--text-dim); opacity: 0.35; }
.star-row label:hover,
.star-row label:hover ~ label,
.star-row:not(:hover) input:checked ~ label {
  color: #f5b301;
  opacity: 1;
}
.star-row label:hover { transform: scale(1.12); }
.star-row input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- Prominent review button ---- */
.review-btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  animation: review-pulse 2.4s ease-in-out infinite;
}
.review-btn:hover { filter: brightness(1.1); }
.review-btn.reviewed {
  animation: none;
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--text);
  font-weight: 500;
}
@keyframes review-pulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent); }
}
@media (prefers-reduced-motion: reduce) { .review-btn { animation: none; } }

/* ---- Right-click menu for DMs ---- */
#dmList .conv-item { -webkit-touch-callout: none; user-select: none; }
.ctx-menu {
  position: fixed;
  z-index: 120;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  box-shadow: var(--shadow);
}
.ctx-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.ctx-menu-item:hover,
.ctx-menu-item:focus-visible { background: var(--panel-2); outline: none; }


/* ---- Extra themes (light = default :root, dark = [data-theme="dark"]) ---- */
[data-theme="ocean"] {
  --bg: #f3f8fb;
  --panel: #ffffff;
  --panel-2: #eaf2f7;
  --border: #d5e3ec;
  --text: #1f2d3a;
  --text-dim: #627889;
  --accent: #2a7fba;
  --accent-hover: #1f6a9e;
  --accent-dim: rgba(42, 127, 186, 0.25);
  --accent-soft: rgba(42, 127, 186, 0.1);
  --user-bubble: #e3f0f8;
  --assistant-bubble: #ffffff;
  --success: #2f8f6b;
  --danger: #c94a4a;
  --shadow: 0 2px 8px rgba(31, 45, 58, 0.06);
}
[data-theme="rose"] {
  --bg: #fdf6f7;
  --panel: #ffffff;
  --panel-2: #faedef;
  --border: #f0d9dd;
  --text: #35272b;
  --text-dim: #85686f;
  --accent: #d6567a;
  --accent-hover: #c0436a;
  --accent-dim: rgba(214, 86, 122, 0.25);
  --accent-soft: rgba(214, 86, 122, 0.1);
  --user-bubble: #fbe6ea;
  --assistant-bubble: #ffffff;
  --success: #3c8c62;
  --danger: #c0392b;
  --shadow: 0 2px 8px rgba(53, 39, 43, 0.06);
}
[data-theme="midnight"] {
  --bg: #0e1420;
  --panel: #151c2b;
  --panel-2: #0e1420;
  --border: #263044;
  --text: #e4e9f2;
  --text-dim: #8f9bb3;
  --accent: #4a8df0;
  --accent-hover: #6aa3f5;
  --accent-dim: rgba(74, 141, 240, 0.3);
  --accent-soft: rgba(74, 141, 240, 0.12);
  --user-bubble: #1b2740;
  --assistant-bubble: #151c2b;
  --success: #4cc38a;
  --danger: #ef6b6b;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
[data-theme="forest"] {
  --bg: #121a15;
  --panel: #1a241d;
  --panel-2: #121a15;
  --border: #2b3a2f;
  --text: #e3ece4;
  --text-dim: #92a396;
  --accent: #3fa563;
  --accent-hover: #55bb79;
  --accent-dim: rgba(63, 165, 99, 0.3);
  --accent-soft: rgba(63, 165, 99, 0.12);
  --user-bubble: #223328;
  --assistant-bubble: #1a241d;
  --success: #58b382;
  --danger: #e06c6c;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ---- Theme picker ---- */
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-option {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 12.5px;
}
.theme-option:hover { border-color: var(--text-dim); }
.theme-option.selected { border-color: var(--accent); }
.theme-swatch {
  height: 46px;
  border-radius: 8px;
  border: 1px solid rgba(128, 128, 128, 0.3);
  display: flex;
}
.theme-swatch-panel { flex: 1; margin: 6px; border-radius: 5px; }
.theme-swatch-accent { width: 45%; height: 6px; margin: 6px; border-radius: 3px; }

/* ---- First-run tutorial ---- */
.tour-block { position: fixed; inset: 0; z-index: 200; }
.tour-block.dim { background: rgba(0, 0, 0, 0.55); }
.tour-spot {
  position: fixed;
  z-index: 201;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55), 0 0 0 3px var(--accent);
  pointer-events: none;
  transition: left 0.25s ease, top 0.25s ease, width 0.25s ease, height 0.25s ease;
}
.tour-card {
  position: fixed;
  z-index: 202;
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.tour-title { margin: 0 0 6px; font-size: 1.05rem; font-weight: 600; }
.tour-text { margin: 0 0 6px; font-size: 13.5px; color: var(--text-dim); line-height: 1.55; }
.tour-list-label { margin-top: 8px; font-size: 12.5px; font-weight: 600; color: var(--text); }
.tour-list { margin: 3px 0 0; padding-left: 18px; font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.tour-footer { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.tour-progress { margin-right: auto; font-size: 12px; color: var(--text-dim); }
.tour-footer .new-chat-btn { flex: 0 0 auto; padding: 8px 16px; }