:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: #172033;
  background: #f4f7fb;

  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8faff;
  --surface-hover: #eef4ff;
  --line: #dfe5ee;
  --line-soft: #e9edf3;
  --text: #172033;
  --muted: #68758a;
  --muted-2: #929dad;
  --blue: #4f8df7;
  --blue-strong: #2e75ee;
  --blue-soft: #edf4ff;
  --green: #24b878;
  --danger: #d94b5b;
  --radius: 15px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
}

html,
body { overflow: hidden; }

body {
  background: radial-gradient(circle at 65% 0%, #fff 0, var(--bg) 42%);
}

button,
textarea,
input { font: inherit; }

button { color: inherit; }

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(46, 117, 238, .22);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 22px 14px 14px;
  border-right: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, .94);
  box-shadow: 8px 0 26px rgba(46, 67, 97, .03);
  backdrop-filter: blur(16px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 9px 24px;
}

.brand-mark,
.welcome-logo {
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #6ba7ff, #2e75ee);
  box-shadow: 0 10px 30px rgba(49, 112, 233, .2);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

.brand-mark svg,
.welcome-logo svg {
  width: 25px;
  height: 25px;
  fill: currentColor;
  stroke: none;
}

.brand-mark .spark,
.welcome-logo .spark { fill: #dceaff; }

.brand strong,
.brand span { display: block; }

.brand strong {
  color: var(--text);
  font-size: 17px;
  letter-spacing: .1px;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #b8cff4;
  border-radius: 11px;
  color: #245cae;
  background: linear-gradient(180deg, #f5f9ff, #edf4ff);
  cursor: pointer;
  font-size: 15px;
  transition: .2s ease;
}

.new-chat:hover {
  border-color: #78a6e9;
  background: var(--surface-hover);
  transform: translateY(-1px);
}

.new-chat svg { width: 17px; }

.new-chat kbd {
  margin-left: auto;
  padding: 2px 5px;
  border: 1px solid #d8e0ed;
  border-radius: 5px;
  color: var(--muted);
  background: var(--surface);
  font-family: inherit;
  font-size: 11px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 25px 8px 9px;
  color: var(--muted-2);
  font-size: 12px;
  letter-spacing: .8px;
  text-transform: uppercase;
}

.history-header button,
.top-actions button,
.mobile-menu {
  padding: 5px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.history-header button:hover,
.top-actions button:hover,
.mobile-menu:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.history-header svg { width: 15px; height: 15px; }

.history-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.history-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 9px;
  color: #596579;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
}

.history-item:hover,
.history-item.active { color: var(--text); background: var(--surface-hover); }

.history-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  width: 2px;
  height: 18px;
  border-radius: 2px;
  background: var(--blue);
}

.history-item svg { width: 15px; height: 15px; flex: 0 0 auto; }
.history-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty-history {
  padding: 18px 5px;
  color: var(--muted-2);
  font-size: 13px;
  text-align: center;
}

.main-panel {
  display: grid;
  grid-template-rows: 66px minmax(0, 1fr) min-content;
  min-width: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(14px);
  z-index: 5;
}

.model-info { display: flex; align-items: center; gap: 10px; }

.model-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid #d6e2f5;
  border-radius: 9px;
  color: #367ce8;
  background: #f1f6ff;
}

.model-icon svg { width: 17px; }
.model-info strong,
.model-info span { display: block; }
.model-info strong { font-size: 14px; }
.model-info div > span { margin-top: 3px; color: var(--muted); font-size: 11px; }

.model-info i {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(36, 184, 120, .45);
}

.model-info i.offline {
  background: #e8a33d;
  box-shadow: 0 0 8px rgba(232, 163, 61, .45);
}

.top-actions { display: flex; gap: 5px; }
.top-actions svg { width: 17px; height: 17px; }
.mobile-menu { display: none; }

.chat-scroll {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  scrollbar-gutter: auto;
  scrollbar-color: #aeb8c6 #eef1f5;
}

.welcome {
  width: min(710px, calc(100% - 40px));
  min-height: 100%;
  margin: 0 auto;
  padding: clamp(60px, 11vh, 112px) 0 45px;
  text-align: center;
}

.welcome-logo {
  width: 54px;
  height: 54px;
  margin: 0 auto 23px;
  border-radius: 17px;
}

.welcome-logo svg { width: 38px; height: 38px; }
.welcome h1 { margin: 0 0 10px; font-size: clamp(26px, calc(3vw + 2px), 34px); letter-spacing: -.8px; }
.welcome > p { width: min(520px, 100%); margin: 0 auto; color: var(--muted); font-size: 15px; line-height: 1.8; }

.suggestions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 42px;
}

.suggestions button {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  min-width: 0;
  min-height: 84px;
  padding: 15px 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, .9);
  cursor: pointer;
  text-align: left;
  transition: .2s ease;
}

.suggestions button:hover {
  border-color: #adc6e9;
  background: #f8fbff;
  box-shadow: 0 8px 24px rgba(31, 64, 105, .08);
  transform: translateY(-2px);
}

.suggestion-icon { display: grid; place-items: center; flex: 0 0 auto; width: 29px; height: 29px; border-radius: 8px; }
.suggestion-icon svg { width: 15px; }
.suggestion-icon.blue { color: #357be4; background: #edf4ff; }
.suggestion-icon.purple { color: #8254d6; background: #f3edff; }
.suggestion-icon.green { color: #168b63; background: #eaf9f2; }
.suggestions strong,
.suggestions small { display: block; }
.suggestions strong { margin-top: 1px; font-size: 13px; white-space: nowrap; }
.suggestions small { margin-top: 7px; color: var(--muted); font-size: 11px; white-space: nowrap; }

.messages { width: min(820px, calc(100% - 44px)); margin: 0 auto; padding: 32px 0 40px; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 13px; margin-bottom: 27px; animation: messageIn .25s ease; }

@keyframes messageIn { from { opacity: 0; transform: translateY(5px); } }

.avatar { display: grid; place-items: center; width: 32px; height: 32px; margin-top: 1px; border-radius: 9px; }
.message.user .avatar { color: #4b5565; background: #e8edf4; }
.message.assistant .avatar { color: #fff; background: linear-gradient(145deg, #4d90ff, #2769df); }
.avatar svg { width: 17px; height: 17px; }
.message-content { min-width: 0; color: #252a33; font-size: 15px; line-height: 1.78; }
.message-meta { display: flex; align-items: center; justify-content: space-between; height: 24px; margin-bottom: 5px; }
.message-meta strong { color: var(--text); font-size: 13px; }
.message-meta time { color: var(--muted-2); font-size: 11px; }
.message-text { overflow-wrap: anywhere; }
.message-text p { margin: 0 0 10px; }
.message-text p:last-child { margin-bottom: 0; }
.message-text pre { position: relative; overflow: auto; margin: 12px 0; padding: 16px; border: 1px solid #d8dee8; border-radius: 10px; color: #20242c; background: #f3f5f8; line-height: 1.55; }
.message-text code { font-family: Consolas, "Cascadia Code", monospace; font-size: 14px; }
.message-text :not(pre) > code { padding: 2px 5px; border-radius: 4px; color: #1f64c5; background: #edf4ff; }
.message-images { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.message-images img { max-width: 260px; max-height: 230px; border: 1px solid var(--line); border-radius: 10px; object-fit: cover; cursor: zoom-in; }
.message-images img:not([src]) { min-width: 160px; min-height: 120px; background: #eef2f7; }
.message-images.missing { color: var(--muted); font-size: 12.5px; }
.message-images.missing::after { content: "图片已失效（本地缓存被清理）"; }

.thinking { margin: 3px 0 14px; padding: 3px 0 3px 12px; border-left: 2px solid #bdc9d9; color: var(--muted); }
.thinking summary { cursor: pointer; color: #64748b; font-size: 13px; user-select: none; }
.thinking div { margin-top: 8px; color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.error-message { padding: 10px 12px; border: 1px solid #f0c2c8; border-radius: 9px; color: var(--danger); background: #fff3f4; }

.composer-area {
  position: relative;
  min-height: 0;
  padding: 12px max(22px, calc((100% - 820px) / 2)) 15px;
  background: linear-gradient(180deg, rgba(244, 247, 251, 0), var(--bg) 20%);
  z-index: 6;
}

.composer {
  border: 1px solid #d4dae4;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 12px 35px rgba(31, 45, 64, .1);
  transition: .2s;
}

.composer:focus-within { border-color: #78a6e9; box-shadow: 0 0 0 3px rgba(58, 104, 178, .08), 0 12px 35px rgba(31, 45, 64, .1); }
.composer textarea { display: block; width: 100%; max-height: 170px; padding: 15px 16px 8px; border: 0; outline: 0; resize: none; color: var(--text); background: transparent; font-size: 15px; line-height: 1.55; }
.composer textarea::placeholder { color: #8995a7; }
.composer-bottom { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 8px 11px; }
.composer-tools { display: flex; align-items: center; gap: 4px; }
.composer-tools button { display: flex; align-items: center; gap: 5px; padding: 6px 7px; border: 0; border-radius: 7px; color: var(--muted); background: none; cursor: pointer; font-size: 12px; }
.composer-tools button:hover { color: var(--text); background: #eef2f7; }
.composer-tools button.active { color: #2e75ee; background: #edf4ff; }
.composer-tools svg { width: 15px; height: 15px; }
.effort-control { display: flex; align-items: center; gap: 5px; padding: 0 2px; color: var(--muted); font-size: 12px; }
.effort-control select { padding: 5px 6px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: var(--surface); cursor: pointer; font-size: 12px; }
.effort-control select:hover { color: var(--text); border-color: #adc6e9; }
.effort-control.inactive { opacity: .45; pointer-events: none; }
.divider { width: 1px; height: 14px; margin: 0 4px; background: #d9dee6; }
.send-button { display: grid; place-items: center; width: 31px; height: 31px; border: 0; border-radius: 9px; color: #fff; background: var(--blue-strong); cursor: pointer; box-shadow: 0 4px 14px rgba(46, 117, 238, .25); transition: .2s; }
.send-button:hover { background: #4789f4; transform: translateY(-1px); }
.send-button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.send-button svg { width: 16px; height: 16px; fill: currentColor; stroke-width: 1.5; }
.send-button .icon-stop { display: none; }
.send-button.sending .icon-send { display: none; }
.send-button.sending .icon-stop { display: block; }
.disclaimer { margin: 8px 0 0; color: #7e8999; font-size: 10px; text-align: center; }

.image-preview-list { display: flex; gap: 8px; overflow-x: auto; width: 100%; }
.image-preview-list:not(:empty) { padding: 0 0 8px; }
.image-preview { position: relative; flex: 0 0 auto; width: 64px; height: 64px; }
.image-preview img { width: 100%; height: 100%; border: 1px solid #cbd3df; border-radius: 9px; object-fit: cover; }
.image-preview img { cursor: zoom-in; }
.image-preview button { position: absolute; top: -6px; right: -6px; display: grid; place-items: center; width: 19px; height: 19px; padding: 0; border: 1px solid #cbd3df; border-radius: 50%; background: #fff; cursor: pointer; }
.image-preview button svg { width: 10px; height: 10px; }

.image-preview.uploading img { opacity: .45; }
.image-preview.failed img { border-color: #eab6bd; opacity: .6; }

.preview-state {
  position: absolute;
  left: 50%;
  top: 50%;
  padding: 2px 6px;
  border-radius: 6px;
  color: #fff;
  background: rgba(28, 40, 58, .72);
  font-size: 10.5px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.config-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  padding: 9px 11px;
  border: 1px solid #f2d9a8;
  border-radius: 10px;
  color: #8a5b12;
  background: #fffaef;
  font-size: 12.5px;
  line-height: 1.5;
}

.config-warning svg { flex: 0 0 auto; width: 15px; height: 15px; }
.config-warning span { flex: 1; }
.config-warning button {
  flex: 0 0 auto;
  padding: 4px 9px;
  border: 1px solid #e3c48c;
  border-radius: 7px;
  color: #8a5b12;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}

.config-warning button:hover { background: #fff4dd; }

.overlay { display: none; position: fixed; inset: 0; z-index: 30; background: rgba(26, 38, 57, .28); backdrop-filter: blur(2px); }
.overlay.visible { display: block; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 26px;
  background: rgba(13, 19, 29, .84);
  backdrop-filter: blur(4px);
}

.lightbox img {
  max-width: 92vw;
  max-height: 86vh;
  border-radius: 10px;
  box-shadow: 0 26px 60px rgba(0, 0, 0, .45);
  cursor: zoom-in;
}

.lightbox img.actual {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, .12);
  cursor: pointer;
}

.lightbox-close:hover { background: rgba(255, 255, 255, .24); }
.lightbox-close svg { width: 17px; height: 17px; }

.lightbox-hint {
  position: fixed;
  bottom: 16px;
  left: 50%;
  color: #dfe8f6;
  font-size: 12.5px;
  opacity: .78;
  pointer-events: none;
  transform: translateX(-50%);
}

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 100; max-width: min(440px, calc(100% - 30px)); padding: 10px 15px; border: 1px solid #d2d9e4; border-radius: 9px; color: #252a33; background: #fff; box-shadow: 0 12px 35px rgba(31, 45, 64, .18); font-size: 13px; opacity: 0; pointer-events: none; transform: translate(-50%, 20px); transition: .25s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #eef1f5; }
::-webkit-scrollbar-thumb { min-height: 44px; border: 2px solid #eef1f5; border-radius: 10px; background: #aeb8c6; }
::-webkit-scrollbar-thumb:hover { background: #8d99aa; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 258px; transform: translateX(-102%); transition: transform .25s ease; box-shadow: 18px 0 45px rgba(31, 45, 64, .18); }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: block; margin-right: 8px; }
  .topbar { justify-content: flex-start; padding: 0 14px; }
  .top-actions { margin-left: auto; }
  .suggestions { grid-template-columns: 1fr; margin-top: 28px; }
  .suggestions button { min-height: 66px; }
  .welcome { padding-top: 45px; }
  .messages { width: calc(100% - 28px); }
  .composer-area { padding-right: 14px; padding-left: 14px; }
  .composer-tools button span { display: none; }
  .effort-label { display: none; }
}
