:root {
  --bg: #ffffff;
  --ink: #202124;
  --muted: #8c8f94;
  --line: #e7e7e8;
  --panel: #f5f5f5;
  --soft: #fafafa;
  --accent: #191a1d;
  --orange: #f25a1d;
  --shadow: 0 14px 40px rgba(22, 24, 29, 0.08);
  --radius-xl: 24px;
  --radius-md: 14px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  overflow-x: hidden;
}

button,
textarea,
select {
  font: inherit;
}

.layout-shell {
  min-height: 100vh;
  display: block;
  padding-left: 276px;
  background: var(--bg);
}

.history-sidebar {
  width: 276px;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-right: 1px solid #ededee;
  background: #f7f7f8;
  padding: 18px 12px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 4px 8px;
}

.sidebar-header strong,
.sidebar-header small {
  display: block;
}

.sidebar-header strong {
  color: #202124;
  font-size: 16px;
  font-weight: 700;
}

.sidebar-header small {
  margin-top: 3px;
  color: #8b8e94;
  font-size: 12px;
}

.sidebar-new-button,
.clear-history-button,
.history-item,
.sidebar-backdrop,
.sidebar-toggle,
.confirm-secondary,
.confirm-danger {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.sidebar-new-button {
  min-height: 32px;
  border-radius: 999px;
  color: #fff;
  background: #191a1d;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
}

.clear-history-button {
  min-height: 34px;
  margin-top: auto;
  border-radius: 8px;
  color: #9a9da3;
  background: transparent;
  font-size: 12px;
  font-weight: 560;
}

.clear-history-button:not(:disabled):hover {
  color: #b4483b;
  background: rgba(216, 70, 52, 0.07);
}

.clear-history-button:disabled {
  color: #b4b6ba;
  cursor: not-allowed;
}

.history-list {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  padding: 2px 0 8px;
}

.history-empty {
  padding: 14px 10px;
  color: #9a9da3;
  font-size: 13px;
}

.history-item {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  color: #2a2c31;
  background: transparent;
  padding: 8px;
  text-align: left;
}

.history-item:hover,
.history-item.active {
  background: #fff;
}

.history-item.active {
  box-shadow: inset 0 0 0 1px #e4e4e6;
}

.history-status {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
}

.history-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #d8dadd;
  border-top-color: #2d3137;
  border-radius: 50%;
  animation: spin 760ms linear infinite;
}

.history-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.12);
}

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

.history-thumb {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: #ececef;
  overflow: hidden;
}

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

.history-copy {
  min-width: 0;
}

.history-copy strong,
.history-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-copy strong {
  color: #25262a;
  font-size: 13px;
  font-weight: 650;
}

.history-copy small {
  margin-top: 4px;
  color: #92959b;
  font-size: 12px;
}

.sidebar-backdrop,
.sidebar-toggle {
  display: none;
}

.app-shell {
  min-height: 100vh;
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 34px 32px 22px;
}

.app-shell:not(.has-chat) {
  align-content: center;
  grid-template-rows: auto auto;
  gap: 44px;
  justify-items: center;
}

.hero {
  align-self: end;
  padding-bottom: 0;
  text-align: center;
  transition: opacity 160ms ease, transform 160ms ease;
}

.hero h1 {
  margin: 0;
  color: #202124;
  font-size: clamp(28px, 3.2vw, 42px);
  font-weight: 430;
  letter-spacing: 0;
}

.thread {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 16px 0 250px;
  display: none;
}

.app-shell.has-chat {
  grid-template-rows: 1fr auto;
  padding-top: 18px;
}

.app-shell.has-chat .hero {
  display: none;
}

.app-shell.has-chat .thread {
  display: block;
}

.composer-wrap {
  width: min(1040px, 100%);
  min-width: 0;
  max-width: 100%;
  margin: 0 auto;
  position: sticky;
  bottom: 22px;
  z-index: 20;
}

.app-shell:not(.has-chat) .composer-wrap {
  position: static;
}

.composer {
  width: 100%;
  min-width: 0;
  min-height: 126px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  padding: 14px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.composer:focus-within {
  border-color: #d8d8da;
  box-shadow: 0 18px 48px rgba(22, 24, 29, 0.11);
}

.composer.dragging {
  border-color: #191a1d;
  box-shadow: 0 18px 50px rgba(22, 24, 29, 0.15);
}

.reference-strip {
  display: none;
  gap: 10px;
  align-items: center;
  overflow-x: auto;
  padding: 0 0 10px;
}

.reference-strip.has-items {
  display: flex;
}

.reference-card {
  width: 96px;
  aspect-ratio: 1 / 1;
  position: relative;
  flex: 0 0 auto;
  border: 1px solid #dedfe1;
  border-radius: 14px;
  overflow: hidden;
  background: #f3f4f5;
}

.reference-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}

.reference-index {
  position: absolute;
  left: 7px;
  bottom: 7px;
  min-width: 30px;
  padding: 4px 7px;
  border-radius: 999px;
  color: #fff;
  background: rgba(20, 21, 24, 0.84);
  font-size: 11px;
  font-weight: 720;
  line-height: 1;
  text-align: center;
}

.reference-order-controls {
  position: absolute;
  left: 7px;
  top: 7px;
  display: flex;
  gap: 4px;
}

.reference-order-button {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(20, 21, 24, 0.78);
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.reference-order-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.remove-ref {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: #1f2024;
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.remove-ref svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
}

.prompt-input {
  width: 100%;
  min-height: 58px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 8px 6px 6px;
  color: #25262a;
  background: transparent;
  font-size: 18px;
  line-height: 1.42;
}

.prompt-input::placeholder {
  color: #c8c9cc;
  font-weight: 560;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 42px;
  min-width: 0;
}

.left-actions,
.right-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.left-actions {
  min-width: 0;
  flex: 1 1 auto;
}

.right-actions {
  flex: 0 0 auto;
}

.inline-controls {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.inline-controls::-webkit-scrollbar {
  display: none;
}

.inline-control {
  flex: 0 0 auto;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  border: 1px solid #e7e7e8;
  border-radius: 999px;
  color: #6f737a;
  background: #fff;
  padding: 0 8px 0 10px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.inline-control span {
  color: #8b8e94;
  font-weight: 560;
}

.inline-control select {
  max-width: 76px;
  border: 0;
  outline: 0;
  color: #2b2d32;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
}

.inline-control .aspect-select {
  max-width: 86px;
}

.inline-control:focus-within {
  border-color: #d5d6d8;
  box-shadow: 0 0 0 3px rgba(25, 26, 29, 0.06);
}

.icon-button,
.send-button,
.model-button {
  border: 0;
  background: none;
  cursor: pointer;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: #94969b;
  display: grid;
  place-items: center;
}

.icon-button:hover {
  background: #f2f2f3;
  color: #696c72;
}

.api-key-button {
  position: relative;
}

.api-key-button.configured {
  color: #1d6b3a;
  background: #edf8f1;
}

.api-key-button.configured::after {
  content: "";
  width: 8px;
  height: 8px;
  position: absolute;
  right: 7px;
  top: 7px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #2fa35a;
}

.icon-button svg,
.send-button svg,
.model-button svg {
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button svg {
  width: 23px;
  height: 23px;
}

.send-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff;
  background: var(--accent);
  display: grid;
  place-items: center;
  transition: transform 140ms ease, background 140ms ease;
}

.send-button:disabled {
  cursor: not-allowed;
  background: #b8bac0;
}

.send-button:not(:disabled):hover {
  transform: translateY(-1px);
  background: #090a0c;
}

.send-button svg {
  width: 25px;
  height: 25px;
}

.model-menu {
  position: relative;
}

.model-button {
  height: 38px;
  border-radius: 999px;
  color: #303137;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 8px 0 10px;
  font-size: 15px;
  background: transparent;
}

.model-button:hover {
  background: #f3f3f4;
}

.model-button svg {
  width: 17px;
  height: 17px;
  color: #8a8d92;
}

.spark-dot {
  width: 11px;
  height: 11px;
  border: 3px solid #e7e7ea;
  border-top-color: #b7b9bf;
  border-radius: 50%;
  display: inline-block;
}

.spark-dot.solid {
  border: 0;
  background: #191a1d;
}

.model-popover {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: 280px;
  border: 1px solid #e2e3e5;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.14);
  padding: 10px;
  display: none;
}

.model-menu.open .model-popover {
  display: block;
}

.selected-model {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  background: #f7f7f8;
}

.selected-model strong,
.selected-model small {
  display: block;
}

.selected-model small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.checkmark {
  color: #191a1d;
  font-weight: 700;
}

.message {
  margin: 24px 0;
  display: flex;
  width: 100%;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
}

.message-inner {
  max-width: min(680px, 72vw);
}

.assistant .message-inner {
  width: min(760px, 72vw);
  max-width: min(760px, 72vw);
}

.user .message-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-thumbs {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 12px;
  max-width: 360px;
  flex-wrap: wrap;
}

.message-thumb {
  width: 96px;
  height: 96px;
  position: relative;
  display: block;
}

.message-thumb img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border: 1px solid #dedfe1;
  border-radius: 14px;
  background: #f3f4f5;
  cursor: zoom-in;
}

.message-thumb span {
  position: absolute;
  left: 7px;
  top: 7px;
  min-width: 30px;
  padding: 4px 7px;
  border-radius: 999px;
  color: #fff;
  background: rgba(20, 21, 24, 0.84);
  font-size: 11px;
  font-weight: 720;
  line-height: 1;
  text-align: center;
}

.bubble {
  border-radius: 18px;
  padding: 12px 16px;
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.user .bubble {
  background: #f3f3f4;
  color: #242529;
  font-weight: 650;
}

.assistant .bubble {
  padding: 0;
  background: transparent;
}

.assistant-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8a8d92;
  font-size: 16px;
  font-weight: 620;
  margin-bottom: 12px;
}

.assistant-meta svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.assistant-body {
  border-top: 1px solid #e6e6e7;
  padding-top: 18px;
}

.assistant-body p {
  margin: 0 0 16px;
  font-size: 17px;
  line-height: 1.55;
  font-weight: 540;
}

.output-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(124px, 160px));
  gap: 12px;
  width: min(760px, 100%);
  align-items: start;
}

.output-card {
  margin: 0;
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid #e3e3e4;
  background: #f5f5f6;
}

.output-card-pending,
.output-card-error {
  aspect-ratio: 1 / 1;
}

.output-card-error {
  display: grid;
  place-items: center;
  padding: 12px;
  color: #9a4238;
  background: #fff4f2;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.output-card img {
  width: 100%;
  height: auto;
  display: block;
  cursor: zoom-in;
}

.download-link {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 50%;
  background: rgba(20, 21, 24, 0.82);
  text-decoration: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.continue-link {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 54px);
  min-height: 30px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(20, 21, 24, 0.84);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 650;
  line-height: 30px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 140ms ease, transform 140ms ease, background 140ms ease;
}

.continue-link:hover {
  background: #111216;
}

.download-link svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.output-card:hover .download-link,
.output-card:hover .continue-link,
.continue-link:focus-visible,
.download-link:focus-visible {
  opacity: 1;
  transform: translateY(0);
}

.pending-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(124px, 1fr));
  gap: 12px;
  max-width: 520px;
}

.skeleton {
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  background: linear-gradient(110deg, #eeeeef 8%, #f7f7f8 18%, #eeeeef 33%);
  background-size: 200% 100%;
  animation: shimmer 1.25s linear infinite;
}

@keyframes shimmer {
  to {
    background-position-x: -200%;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  padding: 12px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(22, 23, 26, 0.92);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(12, 12, 14, 0.78);
  display: none;
  place-items: center;
  padding: 28px;
  z-index: 80;
}

.lightbox.open {
  display: grid;
}

.lightbox img {
  max-width: min(96vw, 1300px);
  max-height: 92vh;
  border-radius: 18px;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.32);
}

.lightbox-close {
  position: fixed;
  top: 24px;
  right: 26px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(14, 15, 18, 0.42);
}

.confirm-modal.open {
  display: grid;
}

.confirm-card {
  width: min(420px, 100%);
  border-radius: 18px;
  border: 1px solid #e5e5e7;
  background: #fff;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.22);
  padding: 22px;
}

.confirm-card h2 {
  margin: 0 0 10px;
  color: #202124;
  font-size: 20px;
  font-weight: 720;
  letter-spacing: 0;
}

.confirm-card p {
  margin: 0;
  color: #5f6369;
  font-size: 14px;
  line-height: 1.65;
}

.api-key-card {
  width: min(500px, 100%);
}

.api-key-field {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.api-key-field span {
  color: #34363b;
  font-size: 13px;
  font-weight: 680;
}

.api-key-field input {
  width: 100%;
  height: 44px;
  border: 1px solid #dfe0e3;
  border-radius: 10px;
  outline: 0;
  padding: 0 12px;
  color: #222328;
  background: #fff;
  font-size: 15px;
}

.api-key-field input:focus {
  border-color: #bfc2c8;
  box-shadow: 0 0 0 3px rgba(25, 26, 29, 0.07);
}

.api-key-status {
  min-height: 18px;
  margin-top: 10px;
  color: #777b82;
  font-size: 12px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  flex-wrap: wrap;
}

.confirm-secondary,
.confirm-danger {
  min-height: 38px;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 650;
}

.confirm-secondary {
  color: #34363b;
  background: #f2f2f3;
}

.confirm-danger {
  color: #fff;
  background: #d84634;
}

.confirm-danger.primary-save {
  background: #191a1d;
}

.confirm-secondary:disabled,
.confirm-danger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .layout-shell {
    display: block;
    padding-left: 0;
  }

  .history-sidebar {
    width: min(312px, 86vw);
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: auto;
    transform: translateX(-104%);
    transition: transform 180ms ease;
  }

  body.sidebar-open .history-sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: block;
    background: rgba(14, 15, 18, 0.28);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-toggle {
    width: 38px;
    height: 38px;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 22;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #555960;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 8px 24px rgba(22, 24, 29, 0.1);
  }

  .sidebar-toggle svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2.2;
    fill: none;
    stroke-linecap: round;
  }

  .app-shell {
    padding-top: 58px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 58px 12px 14px;
  }

  .app-shell:not(.has-chat) {
    gap: 28px;
  }

  .hero {
    padding-bottom: 0;
  }

  .hero h1 {
    font-size: 28px;
  }

  .composer-wrap {
    width: calc(100vw - 24px);
    bottom: 16px;
  }

  .composer {
    min-height: 118px;
    border-radius: 20px;
    padding: 10px;
  }

  .prompt-input {
    font-size: 16px;
    min-height: 58px;
  }

  .model-button {
    max-width: 168px;
    font-size: 14px;
    gap: 6px;
  }

  .composer-actions {
    align-items: flex-end;
    flex-wrap: wrap;
  }

  .left-actions {
    flex: 1 1 100%;
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .right-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .inline-controls {
    order: 3;
    flex-basis: 100%;
    gap: 6px;
  }

  .inline-control {
    min-height: 32px;
    padding: 0 8px;
    font-size: 12px;
  }

  .inline-control select {
    max-width: 70px;
  }

  .inline-control .aspect-select {
    max-width: 82px;
  }

  .send-button {
    width: 42px;
    height: 42px;
  }

  .reference-card,
  .message-thumb,
  .message-thumbs img {
    width: 84px;
    height: 84px;
  }

  .reference-index,
  .message-thumb span {
    font-size: 10px;
    padding: 3px 6px;
  }

  .continue-link,
  .download-link {
    opacity: 1;
    transform: none;
  }

  .message-inner {
    max-width: 92vw;
  }

  .assistant .message-inner {
    width: 92vw;
    max-width: 92vw;
  }

  .bubble {
    font-size: 15px;
    padding: 11px 14px;
  }

  .assistant-meta {
    font-size: 15px;
  }

  .assistant-body p {
    font-size: 16px;
  }

  .pending-grid {
    grid-template-columns: repeat(2, minmax(112px, 1fr));
  }
}
