:root {
  color-scheme: dark;
  --bg: #101311;
  --surface: #171b18;
  --surface-raised: #1d231f;
  --surface-hover: #252c27;
  --text: #f1f4f1;
  --muted: #9aa49c;
  --subtle: #69746c;
  --line: #2b332d;
  --accent: #a7e2bc;
  --accent-strong: #76c998;
  --accent-ink: #102218;
  --danger: #ff8e89;
  --shadow: 0 18px 60px rgb(0 0 0 / 42%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-raised: #f0f3f0;
  --surface-hover: #e9eeea;
  --text: #1c2620;
  --muted: #66736a;
  --subtle: #89948c;
  --line: #dfe6e0;
  --accent: #267c4b;
  --accent-strong: #1e7041;
  --accent-ink: #ffffff;
  --danger: #b83f3a;
  --shadow: 0 18px 60px rgb(28 44 33 / 18%);
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
.sr-only, .sr-only-file {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.app-shell {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
}
.topbar {
  position: relative;
  z-index: 2;
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}
.icon-button:hover { background: var(--surface-hover); color: var(--text); }
.icon-button svg { width: 21px; height: 21px; }
.topbar-selects { display: flex; align-items: center; gap: 5px; min-width: 0; }
.topbar select {
  max-width: min(42vw, 220px);
  height: 36px;
  padding: 0 27px 0 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  appearance: none;
  color: var(--text);
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa49c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  font-size: 13px;
  cursor: pointer;
}
#effort-select { max-width: 76px; }
.topbar-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.chat-messages {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 28px 20px 32px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(440px, calc(100% - 36px));
  transform: translate(-50%, -58%);
  text-align: center;
}
.empty-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 22px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--surface);
  color: var(--accent);
}
.empty-mark svg { width: 39px; height: 39px; }
.empty-state h1 { margin: 0; font-size: 22px; line-height: 1.35; font-weight: 600; }
.empty-state p { margin: 9px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.composer {
  flex: 0 0 auto;
  padding: 0 20px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent 0, var(--bg) 20px);
}
.attachment-preview {
  display: flex;
  gap: 10px;
  max-width: 780px;
  margin: 0 auto 10px;
  overflow-x: auto;
}
.attachment-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  max-width: 210px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}
.attachment-item img, .attachment-thumb {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 8px;
  object-fit: cover;
}
.attachment-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  width: min(780px, 100%);
  min-height: 58px;
  margin: 0 auto;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 8px 26px rgb(0 0 0 / 10%);
}
.composer-tools { display: flex; align-items: center; gap: 0; padding-bottom: 1px; }
.composer-icon { width: 38px; height: 38px; flex-basis: 38px; }
.composer-icon svg { width: 20px; height: 20px; }
#prompt-input {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  max-height: 180px;
  min-height: 40px;
  padding: 10px 5px 8px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 22px;
}
#prompt-input::placeholder { color: var(--subtle); opacity: 1; }
#prompt-input:focus-visible { outline: 0; }
.send-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 0;
  border-radius: 13px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: background-color 140ms ease, transform 140ms ease;
}
.send-button:hover { background: var(--accent-strong); }
.send-button:active { transform: scale(.96); }
.send-button svg { width: 20px; height: 20px; }
.send-button .stop-icon { display: none; }
.send-button.is-stop .send-icon { display: none; }
.send-button.is-stop .stop-icon { display: block; }
.composer-caption {
  width: min(780px, 100%);
  margin: 8px auto 0;
  color: var(--subtle);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
}
.drawer-backdrop, .modal-backdrop, .lightbox {
  position: fixed;
  z-index: 20;
  inset: 0;
  background: rgb(0 0 0 / 58%);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}
.drawer {
  position: fixed;
  z-index: 21;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  width: min(320px, calc(100vw - 48px));
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  border-right: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  transition: transform 220ms ease;
}
.drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 0 2px 8px 10px; }
.drawer-title { font-size: 16px; font-weight: 600; }
.drawer-new-chat, .setting-action {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.drawer-new-chat:hover, .setting-action:hover { background: var(--surface-hover); }
.drawer-new-chat svg { width: 19px; height: 19px; color: var(--accent); }
.session-list { flex: 1; min-height: 0; overflow-y: auto; margin-top: 14px; }
.session-item {
  display: flex;
  align-items: center;
  min-height: 42px;
  margin: 2px 0;
  padding: 0 11px;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
}
.session-item:hover, .session-item.active { background: var(--surface-hover); color: var(--text); }
.session-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.modal-backdrop {
  z-index: 30;
  display: grid;
  place-items: center;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.settings-panel {
  width: min(520px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  padding: 0 18px 0 22px;
  border-bottom: 1px solid var(--line);
}
.settings-header h2 { margin: 0; font-size: 17px; font-weight: 600; }
.settings-content { overflow-y: auto; padding: 4px 22px 22px; }
.settings-section { padding: 16px 0; border-bottom: 1px solid var(--line); }
.settings-section h3 { margin: 0 0 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.setting-action { justify-content: space-between; min-height: 42px; border: 0; padding: 0 8px; font-size: 14px; }
.setting-action-note { color: var(--muted); font-size: 12px; }
.setting-action svg { width: 18px; height: 18px; color: var(--muted); }
.inline-control { display: flex; gap: 8px; margin-top: 10px; }
input[type="text"], input[type="url"], input[type="password"], .settings-textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.inline-control input { height: 40px; padding: 0 11px; }
input::placeholder, .settings-textarea::placeholder { color: var(--subtle); opacity: 1; }
.secondary-button, .primary-button, .danger-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease;
}
.secondary-button:hover { background: var(--surface-hover); }
.primary-button { border-color: transparent; background: var(--accent); color: var(--accent-ink); }
.primary-button:hover { background: var(--accent-strong); }
.danger-button { border-color: color-mix(in srgb, var(--danger) 32%, transparent); color: var(--danger); background: transparent; }
.danger-button:hover { background: color-mix(in srgb, var(--danger) 9%, transparent); }
.settings-textarea { display: block; min-height: 94px; padding: 10px 11px; resize: vertical; line-height: 1.55; }
.advanced-settings { padding: 15px 0; border-bottom: 1px solid var(--line); }
.advanced-settings summary { color: var(--muted); font-size: 13px; cursor: pointer; }
.advanced-fields { display: grid; gap: 8px; padding-top: 14px; }
.advanced-fields label { margin-top: 4px; color: var(--muted); font-size: 12px; }
.advanced-fields input { height: 40px; padding: 0 11px; }
.settings-buttons { display: grid; gap: 9px; padding-top: 18px; }
.settings-buttons > button { width: 100%; }
.logout-button { border-color: transparent; background: transparent; color: var(--muted); }
.form-error { min-height: 18px; margin: 8px 0 0; color: var(--danger); font-size: 13px; }
.auth-overlay {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.auth-panel { width: min(360px, 100%); text-align: center; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 24px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--surface);
  color: var(--accent);
}
.brand-mark svg { width: 35px; height: 35px; }
.auth-panel h1 { margin: 0; font-size: 23px; font-weight: 600; }
.auth-subtitle { margin: 8px 0 25px; color: var(--muted); font-size: 14px; }
.auth-panel input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}
.auth-panel > .primary-button { width: 100%; margin-top: 12px; min-height: 46px; font-size: 14px; }
.auth-panel .form-error { text-align: left; }
.lightbox {
  z-index: 40;
  display: grid;
  place-items: center;
  padding: calc(60px + env(safe-area-inset-top)) 20px calc(30px + env(safe-area-inset-bottom));
}
.lightbox img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.lightbox-close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px; color: #fff; }
.message { width: min(780px, 100%); margin: 0 auto 24px; }
.message-user { display: flex; justify-content: flex-end; }
.message-bubble {
  max-width: min(82%, 620px);
  padding: 11px 15px;
  border-radius: 17px;
  background: var(--surface-raised);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.message-user .message-bubble { border-bottom-right-radius: 5px; background: color-mix(in srgb, var(--accent) 17%, var(--surface)); }
.message-assistant { font-size: 15px; line-height: 1.75; overflow-wrap: anywhere; }
.message-assistant p { margin: 0 0 12px; }
.message-assistant p:last-child { margin-bottom: 0; }
.message-assistant pre {
  overflow: auto;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0b0e0c;
  color: #e5eee7;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="light"] .message-assistant pre { background: #202823; color: #eef5ef; }
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 0 10px 0 13px;
  border-bottom: 1px solid rgb(255 255 255 / 11%);
  color: #aab9ad;
  font: 11px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.code-header button {
  padding: 5px 8px;
  border: 0;
  border-radius: 7px;
  background: rgb(255 255 255 / 8%);
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.message-assistant pre code { display: block; padding: 12px 14px; white-space: pre; }
.thinking-box {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}
.thinking-box summary { padding: 10px 13px; cursor: pointer; color: var(--muted); }
.thinking-content { padding: 0 13px 12px; line-height: 1.65; white-space: pre-wrap; }
.chat-image { display: block; max-width: min(100%, 420px); max-height: 420px; border-radius: 12px; object-fit: contain; cursor: zoom-in; }
@media (max-width: 560px) {
  .topbar { flex-basis: 54px; gap: 5px; padding-right: 10px; padding-left: 10px; }
  .topbar-selects { gap: 2px; }
  .topbar select { max-width: 43vw; padding-left: 8px; font-size: 12px; }
  #effort-select { max-width: 62px; }
  .topbar-icon { width: 36px; height: 38px; flex-basis: 36px; }
  .chat-messages { padding: 20px 14px 24px; }
  .composer { padding-right: 12px; padding-left: 12px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .composer-box { gap: 2px; border-radius: 16px; }
  .composer-tools { gap: 0; }
  .composer-icon { width: 34px; flex-basis: 34px; }
  .send-button { width: 38px; height: 38px; flex-basis: 38px; }
  .composer-caption { font-size: 10px; }
  .settings-content { padding-right: 17px; padding-left: 17px; }
  .message-bubble { max-width: 90%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

/* Extra styles for actions, markdown elements, and toast */
.attachment-remove {
  margin-left: 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
}
.attachment-remove:hover { color: var(--danger); }
.session-item { justify-content: space-between; gap: 6px; }
.session-delete {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--subtle);
  font-size: 16px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.session-delete:hover { color: var(--danger); background: rgb(255 100 100 / 12%); }
.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg-file-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}
.msg-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.msg-action-btn {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.msg-action-btn:hover { background: var(--surface-hover); color: var(--text); }
.message-assistant h1, .message-assistant h2, .message-assistant h3, .message-assistant h4 {
  margin: 14px 0 8px;
  line-height: 1.35;
}
.message-assistant h1 { font-size: 19px; }
.message-assistant h2 { font-size: 17px; }
.message-assistant h3 { font-size: 15.5px; }
.message-assistant ul, .message-assistant ol { margin: 8px 0 12px; padding-left: 22px; }
.message-assistant li { margin: 4px 0; }
.message-assistant blockquote {
  margin: 10px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  color: var(--muted);
  border-radius: 0 8px 8px 0;
}
.message-assistant code:not(pre code) {
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--surface-raised);
  font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.message-assistant a { color: var(--accent); text-decoration: underline; }
.message-assistant hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  padding: 9px 16px;
  border-radius: 12px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}
.toast.show { opacity: 1; }
