:root {
  color-scheme: light;
  --sidebar-width: 260px;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-850: #171717;
  --gray-900: #111827;
  --gray-950: #0d0d0d;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #fff;
  color: var(--gray-800);
}

button, textarea, a { font: inherit; color: inherit; }

body {
  display: flex;
  overflow: hidden;
}

/* —— Sidebar (Open WebUI) —— */
.sidebar {
  width: var(--sidebar-width);
  flex: none;
  background: var(--gray-50);
  border-right: 1px solid color-mix(in srgb, var(--gray-50) 100%, #000 3%);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 40;
  font-size: 0.8125rem;
  line-height: 1.25rem;
  color: var(--gray-700);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px 4px;
  gap: 4px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 8px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--gray-800);
}

.brand:hover { background: var(--gray-100); }

.gpt-mark {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #fff center / cover no-repeat url("/icon.jpg");
  flex: none;
  display: inline-block;
  overflow: hidden;
}

.gpt-mark.sm { width: 18px; height: 18px; }
.gpt-mark.lg {
  width: 40px;
  height: 40px;
  margin-bottom: 10px;
}

.side-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 6px 8px;
  cursor: pointer;
  text-align: left;
  color: var(--gray-700);
}

.side-link:hover,
.history button:hover,
.icon-btn:hover,
.model-chip:hover,
.chip:hover,
.menu button:hover,
.choice:hover {
  background: var(--gray-100);
}

.side-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px;
}

.side-label {
  margin: 10px 8px 4px;
  color: var(--gray-400);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.history button {
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 12px;
  padding: 7px 8px;
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  color: var(--gray-700);
}

.history button.active {
  background: rgba(0, 0, 0, 0.035);
  font-weight: 500;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  cursor: pointer;
  color: var(--gray-600);
  flex: none;
}

.rail {
  width: 42px;
  flex: none;
  border-right: 0.5px solid var(--gray-50);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  color: var(--gray-700);
}

body.sidebar-collapsed .sidebar { display: none; }
body.sidebar-collapsed .rail { display: flex; }
body:not(.sidebar-collapsed) .rail { display: none; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 30;
}
.scrim[hidden] { display: none; }

/* —— Main —— */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.navbar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex: none;
  padding: 0 8px;
}

.mobile-only { display: none; position: absolute; }
#open-side-mobile { left: 8px; }
#new-chat-mobile { right: 8px; }

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  max-width: min(520px, calc(100% - 96px));
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-800);
}

.model-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.messages {
  flex: 1;
  overflow: auto;
  padding: 12px 0 24px;
}

.shell,
.turn,
.fine {
  width: min(58rem, calc(100% - 16px));
  margin-left: auto;
  margin-right: auto;
}

/* —— Placeholder (empty) —— */
.placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 48px 8px 64px;
  text-align: center;
}

.hello {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 18px;
}

.hello h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--gray-800);
  line-height: 1.2;
}

.hello p {
  margin: 6px 0 0;
  color: var(--gray-500);
  font-size: 0.875rem;
  max-width: 28rem;
}

body:not(.is-empty) .placeholder { display: none; }
body.is-empty .messages,
body.is-empty .dock { display: none; }

.suggestions {
  width: min(42rem, calc(100% - 24px));
  margin: 18px auto 0;
  text-align: left;
}

.sug-label {
  margin: 0 0 8px;
  color: var(--gray-400);
  font-size: 12px;
}

.sug-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.sug-list button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
}

.sug-list strong {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-800);
}

.sug-list span {
  font-size: 12px;
  color: var(--gray-400);
}

/* —— Composer (Open WebUI MessageInput) —— */
.composer {
  width: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.06);
  border-radius: 1.5rem;
  border: 1px solid rgba(243, 244, 246, 0.55);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(8px);
  padding: 2px;
  transition: border-color 0.15s ease;
}

.composer:focus-within,
.composer.over {
  border-color: var(--gray-200);
}

.composer-main {
  padding: 10px 12px 2px;
}

.composer textarea {
  display: block;
  width: 100%;
  border: 0;
  resize: none;
  outline: none;
  background: transparent;
  min-height: 28px;
  max-height: 200px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--gray-800);
}

.composer textarea::placeholder { color: var(--gray-400); }

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 6px 8px;
}

.composer-bar .left {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  flex-wrap: wrap;
}

.chip {
  height: 28px;
  max-width: 220px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--gray-600);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.active {
  color: #0ea5e9;
  background: #f0f9ff;
  border: 1px solid rgba(186, 230, 253, 0.7);
}

.send {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-200);
  color: #fff;
  cursor: default;
  flex: none;
  align-self: center;
}

.send.ready {
  background: #000;
  color: #fff;
  cursor: pointer;
}

.send.ready:hover { background: var(--gray-900); }

.send .stop-mark { display: none; }
.send.stop {
  background: #000;
  color: #fff;
  cursor: pointer;
}
.send.stop .arrow { display: none; }
.send.stop .stop-mark {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: currentColor;
}

.refs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 10px 10px 0;
}
.refs:empty { display: none; }
.refs li { position: relative; }
.refs img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
  border: 1px solid var(--gray-100);
}
.refs button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: var(--gray-900);
  color: #fff;
  cursor: pointer;
  line-height: 18px;
  font-size: 12px;
}

.dock {
  padding: 0 0 12px;
  flex: none;
}

.fine {
  margin: 10px auto 0;
  text-align: center;
  color: var(--gray-400);
  font-size: 12px;
}

/* —— Messages —— */
.turn { margin-bottom: 28px; }

.user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.user p {
  margin: 0;
  max-width: 85%;
  background: var(--gray-50);
  border-radius: 1.25rem;
  padding: 10px 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--gray-800);
}

.assistant-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.assistant-row > .gpt-mark {
  width: 28px;
  height: 28px;
  margin-top: 2px;
}

.assistant {
  margin-top: 0;
  min-width: 0;
  flex: 1;
}

.img-pending {
  display: flex;
  flex-direction: column;
  max-width: min(360px, 100%);
}

.img-pending-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  border-radius: 24px;
  background: #ececec;
  overflow: hidden;
  box-sizing: border-box;
}

.img-pending-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 0;
  flex: none;
  z-index: 1;
}

.img-pending-head .thinking-label {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: #0d0d0d;
  background: linear-gradient(
    90deg,
    rgba(13, 13, 13, 0.42) 0%,
    rgba(13, 13, 13, 0.95) 45%,
    rgba(13, 13, 13, 0.42) 90%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: label-shimmer 2s linear infinite;
}

.img-pending-head .status {
  margin: 0;
  font-size: 12px;
  color: #8e8e8e;
  font-variant-numeric: tabular-nums;
}

.dot-matrix {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--cols, 14), 1fr);
  align-content: center;
  justify-items: center;
  gap: 9px 9px;
  width: 100%;
  min-height: 0;
  padding: 28px 22px 26px;
  box-sizing: border-box;
}

.dot-matrix i {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #0d0d0d;
  opacity: 0.14;
  animation: chatgpt-dot-wave 2.4s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}

@keyframes chatgpt-dot-wave {
  0%, 100% { opacity: 0.12; }
  40% { opacity: 0.18; }
  50% { opacity: 0.78; }
  60% { opacity: 0.22; }
}

@keyframes label-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.shot { position: relative; margin: 0; }
.shot img {
  width: 100%;
  display: block;
  border-radius: 14px;
  background: var(--gray-50);
  cursor: zoom-in;
  border: 1px solid var(--gray-100);
}

.dl {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  opacity: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.shot:hover .dl,
.shot:focus-within .dl { opacity: 1; }

.meta {
  margin: 10px 0 0;
  color: var(--gray-400);
  font-size: 13px;
}

.thinking .status {
  margin: 0;
  color: var(--gray-400);
  font-size: 13px;
}

.err {
  margin: 10px 0 0;
  color: #b42318;
  font-size: 14px;
}

/* —— Menus / lightbox —— */
.menu {
  position: fixed;
  z-index: 50;
  min-width: 280px;
  max-width: min(420px, calc(100vw - 24px));
  max-height: min(420px, calc(100vh - 24px));
  overflow: auto;
  background: #fff;
  border: 1px solid var(--gray-100);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
  padding: 6px;
}
.menu[hidden] { display: none; }

.menu button,
.choice,
.model-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 14px;
  cursor: pointer;
}

.model-option {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  letter-spacing: -0.01em;
}

.model-option[aria-checked="true"] {
  font-weight: 600;
  background: var(--gray-100);
}

.menu button:hover,
.choice:hover,
.model-option:hover,
.sug-list button:hover {
  background: var(--gray-100);
}

.menu button small,
.section,
.check small {
  color: var(--gray-400);
  font-size: 12px;
}

.menu button[aria-checked="true"],
.choice[aria-checked="true"] { font-weight: 600; }

.section { margin: 8px 10px 2px; }

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 6px 4px;
}

.choice {
  width: auto;
  border-radius: 999px;
  padding: 6px 10px;
}

.choice[aria-checked="true"] {
  background: #000;
  color: #fff;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px;
  font-size: 14px;
}
.check input { accent-color: #000; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.88);
  display: grid;
  place-items: center;
  padding: 48px 24px;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 120px);
  border-radius: 12px;
}
.lightbox .light {
  position: absolute;
  top: 16px;
  right: 16px;
  color: #fff;
  font-size: 24px;
}
.download-btn {
  position: absolute;
  bottom: 20px;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
}

@media (max-width: 800px) {
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  }
  body.nav-open .sidebar { transform: none; }
  body.sidebar-collapsed .sidebar { display: flex; }
  body.sidebar-collapsed .rail { display: none; }
  .sug-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .dot-matrix i,
  .img-pending-head .thinking-label { animation: none; }
  .dot-matrix i { opacity: 0.28; }
  .img-pending-head .thinking-label {
    color: #0d0d0d;
    background: none;
    -webkit-background-clip: initial;
    background-clip: initial;
  }
  .sidebar { transition: none; }
}
