:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --line: rgba(25, 31, 26, 0.08);
  --line-strong: rgba(25, 31, 26, 0.14);
  --text: #151b17;
  --muted: #66726b;
  --accent: #0f9d74;
  --accent-strong: #0b7a5a;
  --shadow: 0 18px 45px rgba(31, 43, 36, 0.08);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --font-sans: "IBM Plex Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-display: "Space Grotesk", "IBM Plex Sans", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(15, 157, 116, 0.12), transparent 32%),
    radial-gradient(circle at bottom right, rgba(55, 128, 98, 0.08), transparent 28%),
    linear-gradient(180deg, #f8f6f2 0%, var(--bg) 100%);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

code,
pre {
  font-family: "IBM Plex Mono", "Cascadia Code", monospace;
}

.page-shell {
  display: grid;
  grid-template-columns: 332px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  align-items: stretch;
  overflow: hidden;
}

.control-panel,
.chat-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  min-height: 0;
}

.control-panel {
  padding: 24px 20px;
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
}

.panel-head h1,
.chat-header h2 {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-size: 1.8rem;
  line-height: 1.05;
  letter-spacing: -0.05em;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lead,
.helper-text,
.tip-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.95rem;
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.field-hint code {
  background: rgba(0, 0, 0, 0.05);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.72rem;
}

.config-group {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: var(--panel-strong);
}

.config-group h2 {
  margin: 0 0 12px;
  font-size: 0.98rem;
}

.group-title-row,
.header-actions,
.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field span,
.context-label {
  font-size: 0.88rem;
  font-weight: 600;
}

.field input,
.field select,
.field textarea,
.composer-form textarea {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.field input:focus,
.field select:focus,
.composer-form textarea:focus {
  border-color: rgba(15, 157, 116, 0.6);
  box-shadow: 0 0 0 4px rgba(15, 157, 116, 0.12);
}

.preset-wrap,
.grid-fields {
  display: grid;
  gap: 10px;
}

.preset-wrap {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: -2px 0 12px;
}

.single-option-row {
  grid-template-columns: minmax(0, 1fr);
}

.grid-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.preset-button,
.ghost-button,
.text-button,
.primary-button,
.download-link {
  border: none;
  border-radius: 14px;
  transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease;
}

.preset-button,
.ghost-button,
.text-button {
  background: rgba(15, 27, 23, 0.05);
  color: var(--text);
}

.preset-button:hover,
.ghost-button:hover,
.text-button:hover,
.primary-button:hover,
.download-link:hover {
  transform: translateY(-1px);
}

.preset-button {
  padding: 9px 10px;
}

.text-button,
.ghost-button {
  padding: 8px 11px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 16px;
  background: linear-gradient(135deg, var(--accent) 0%, #1f7a5f 100%);
  color: #fff;
  font-weight: 700;
}

.primary-button[disabled] {
  cursor: wait;
  opacity: 0.68;
}

.context-card {
  padding: 12px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(15, 157, 116, 0.08), rgba(15, 157, 116, 0.03));
  border: 1px solid rgba(15, 157, 116, 0.14);
}

.rule-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
}

.doc-card {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.84);
  overflow: hidden;
}

.doc-card summary {
  padding: 12px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.doc-card[open] summary {
  border-bottom: 1px solid var(--line);
}

.url-list {
  margin: 0;
  padding: 12px 18px 14px 32px;
  color: var(--muted);
  line-height: 1.7;
}

.url-list code,
.param-table code,
.api-pre code,
.note-text code {
  word-break: break-all;
}

.table-wrap {
  overflow: auto;
}

.param-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.param-table th,
.param-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.6;
}

.param-table th {
  color: var(--text);
  background: rgba(15, 27, 23, 0.03);
}

.param-table tbody tr:last-child td {
  border-bottom: none;
}

.api-pre {
  margin: 0;
  padding: 14px;
  overflow: auto;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.7;
  background: rgba(15, 27, 23, 0.03);
}

.note-text {
  margin: 0;
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.7;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
  border-radius: 34px;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 248, 245, 0.82);
}

.status-badge {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(15, 157, 116, 0.1);
  color: var(--accent-strong);
  font-size: 0.88rem;
  font-weight: 700;
}

.status-badge[data-state="success"] {
  background: rgba(15, 157, 116, 0.14);
  color: var(--accent-strong);
}

.status-badge[data-state="error"] {
  background: rgba(176, 61, 61, 0.12);
  color: #a63d3d;
}

.status-badge[data-state="loading"] {
  background: rgba(15, 157, 116, 0.16);
  color: var(--accent-strong);
}

.status-badge[data-state="loading"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 15%, rgba(255, 255, 255, 0.48) 50%, transparent 85%);
  transform: translateX(-130%);
  animation: badge-sweep 1.8s ease-in-out infinite;
}

.message-list {
  padding: 18px 22px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  overscroll-behavior: contain;
}

.empty-state {
  margin: clamp(28px, 10vh, 96px) auto 24px;
  padding: 28px;
  max-width: 540px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.84);
  border: 1px dashed var(--line-strong);
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 10px;
  font-size: 1.3rem;
  font-family: var(--font-display);
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.message {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.message.assistant .avatar {
  background: linear-gradient(135deg, rgba(15, 157, 116, 0.95), rgba(10, 104, 77, 0.95));
}

.message.user .avatar {
  background: linear-gradient(135deg, rgba(20, 28, 24, 0.95), rgba(61, 75, 67, 0.9));
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.message-body {
  padding: 14px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
}

.message.user .message-body {
  background: rgba(250, 250, 248, 0.96);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.message-role {
  font-size: 0.95rem;
}

.message-time {
  color: var(--muted);
  font-size: 0.82rem;
}

.message-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.75;
}

.generation-loading {
  margin-top: 14px;
  padding: 14px;
  border-radius: 24px;
  border: 1px solid rgba(15, 157, 116, 0.14);
  background:
    radial-gradient(circle at top left, rgba(15, 157, 116, 0.1), transparent 36%),
    linear-gradient(180deg, rgba(249, 252, 250, 0.98) 0%, rgba(243, 248, 245, 0.96) 100%);
}

.generation-loading-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.generation-loading-label,
.generation-loading-detail {
  margin: 0;
}

.generation-loading-label {
  font-size: 0.96rem;
  font-weight: 700;
}

.generation-loading-detail {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.6;
}

.generation-loading-elapsed {
  flex: none;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(15, 27, 23, 0.06);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}

.generation-loading-visual {
  position: relative;
  margin-top: 14px;
  width: min(100%, 360px);
  aspect-ratio: 1 / 1;
  border-radius: 30px;
  overflow: hidden;
  border: 1px solid rgba(15, 27, 23, 0.06);
  background:
    radial-gradient(circle at 28% 22%, rgba(15, 157, 116, 0.12), transparent 26%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(241, 246, 243, 0.94) 100%);
}

.generation-loading-shimmer,
.generation-loading-orb,
.generation-loading-grid {
  position: absolute;
  inset: 0;
}

.generation-loading-shimmer {
  background: linear-gradient(120deg, transparent 18%, rgba(255, 255, 255, 0.86) 50%, transparent 82%);
  transform: translateX(-120%);
  animation: loading-shimmer 2.4s ease-in-out infinite;
}

.generation-loading-orb {
  inset: auto;
  width: 58%;
  height: 58%;
  top: 22%;
  left: 21%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(15, 157, 116, 0.22) 0%, rgba(15, 157, 116, 0.06) 42%, transparent 74%);
  filter: blur(18px);
  animation: loading-orb 3.2s ease-in-out infinite;
}

.generation-loading-grid {
  inset: 14%;
  background-image: radial-gradient(circle, rgba(89, 98, 92, 0.32) 0 2.4px, transparent 2.6px);
  background-size: 26px 26px;
  mask-image: radial-gradient(circle at center, rgba(0, 0, 0, 1) 0, rgba(0, 0, 0, 0.9) 26%, rgba(0, 0, 0, 0) 74%);
  -webkit-mask-image: radial-gradient(circle at center, rgba(0, 0, 0, 1) 0, rgba(0, 0, 0, 0.9) 26%, rgba(0, 0, 0, 0) 74%);
  animation: loading-grid 4.8s ease-in-out infinite;
}

.generation-loading-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.generation-loading-pill {
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(15, 27, 23, 0.05);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.generation-loading-pill.is-done,
.generation-loading-pill.is-active {
  color: var(--accent-strong);
}

.generation-loading-pill.is-done {
  background: rgba(15, 157, 116, 0.1);
}

.generation-loading-pill.is-active {
  background: rgba(15, 157, 116, 0.16);
  transform: translateY(-1px);
}

.message-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 240px));
  justify-content: flex-start;
  gap: 10px;
  margin-top: 14px;
}

.image-card {
  overflow: hidden;
  border-radius: 18px;
  background: #fff;
  border: 1px solid var(--line);
  width: 100%;
  max-width: 240px;
}

.image-preview-button {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: none;
  display: block;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(15, 157, 116, 0.05), rgba(15, 27, 23, 0.04));
}

.image-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: linear-gradient(180deg, rgba(15, 157, 116, 0.04), rgba(15, 27, 23, 0.03));
}

.image-preview-hint {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(21, 27, 23, 0.72);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.image-preview-button:hover .image-preview-hint,
.image-preview-button:focus-visible .image-preview-hint {
  opacity: 1;
  transform: translateY(0);
}

.image-preview-button:focus-visible {
  outline: 3px solid rgba(15, 157, 116, 0.22);
  outline-offset: -3px;
}

.image-card-footer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px 10px 12px;
}

.image-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 8px 12px;
  background: rgba(15, 157, 116, 0.12);
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

.message-extra {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.7;
}

.composer-panel {
  padding: 14px 22px 20px;
  border-top: 1px solid var(--line);
  background: rgba(248, 248, 245, 0.85);
  box-shadow: 0 -8px 18px rgba(31, 43, 36, 0.04);
}

.prompt-preview {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  overflow: hidden;
}

.prompt-preview summary {
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 700;
  user-select: none;
}

.prompt-preview pre {
  margin: 0;
  padding: 0 14px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  line-height: 1.75;
}

.composer-form textarea {
  width: 100%;
  min-height: 88px;
  max-height: 200px;
  overflow: auto;
  resize: vertical;
}

.composer-actions {
  margin-top: 12px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 24px;
}

.lightbox.is-open {
  display: grid;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 12, 0.74);
  backdrop-filter: blur(8px);
}

.lightbox-dialog {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  padding: 18px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(18, 22, 20, 0.94);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.35);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

.lightbox-close {
  justify-self: end;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
}

.lightbox-image-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
}

.lightbox-image-wrap img {
  max-width: 100%;
  max-height: calc(100vh - 190px);
  display: block;
  object-fit: contain;
  border-radius: 18px;
}

.lightbox-image-wrap img:not([src]),
.lightbox-image-wrap img[src=""] {
  display: none;
}

.lightbox-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.lightbox-label {
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.92rem;
}

body.is-lightbox-open {
  overflow: hidden;
}

.is-loading .message-body {
  position: relative;
}

.is-loading .message-text::after {
  content: " ···";
  animation: dots 1.2s infinite;
}

.primary-button.is-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.34);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes dots {
  0% {
    content: " ·";
  }
  33% {
    content: " ··";
  }
  66% {
    content: " ···";
  }
  100% {
    content: " ·";
  }
}

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

@keyframes badge-sweep {
  100% {
    transform: translateX(130%);
  }
}

@keyframes loading-shimmer {
  100% {
    transform: translateX(120%);
  }
}

@keyframes loading-orb {
  0%,
  100% {
    transform: scale(0.92);
    opacity: 0.65;
  }
  50% {
    transform: scale(1.06);
    opacity: 1;
  }
}

@keyframes loading-grid {
  0%,
  100% {
    transform: scale(0.97) translateY(0);
    opacity: 0.72;
  }
  50% {
    transform: scale(1.03) translateY(-4px);
    opacity: 1;
  }
}

@media (max-width: 1100px) {
  .page-shell {
    grid-template-columns: 304px minmax(0, 1fr);
  }
}

@media (max-width: 960px) {
  body {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    overflow: auto;
  }

  .page-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  .control-panel,
  .chat-panel {
    height: auto;
    min-height: 70vh;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 12px;
    gap: 12px;
  }

  .control-panel,
  .chat-panel {
    border-radius: 24px;
  }

  .control-panel {
    padding: 20px 16px;
    height: auto;
    overflow: visible;
  }

  .chat-header,
  .message-list,
  .composer-panel {
    padding-left: 16px;
    padding-right: 16px;
  }

  .preset-wrap,
  .grid-fields,
  .header-actions {
    grid-template-columns: 1fr;
    display: grid;
  }

  .message {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
  }

  .message-images {
    grid-template-columns: 1fr;
  }

  .image-card {
    max-width: none;
  }

  .generation-loading-top {
    flex-direction: column;
  }

  .generation-loading-elapsed {
    align-self: flex-start;
  }

  .generation-loading-visual {
    width: 100%;
  }

  .lightbox {
    padding: 12px;
  }

  .lightbox-dialog {
    width: min(100vw - 24px, 100%);
    max-height: calc(100vh - 24px);
    padding: 14px;
  }

  .lightbox-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }
}
