:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-soft: #f4f4f5;
  --surface-strong: #ececf1;
  --surface-raised: #ffffff;
  --text: #202123;
  --muted: #6b7280;
  --muted-strong: #4b5563;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #10a37f;
  --accent-dark: #0e8065;
  --accent-soft: #e7f8f2;
  --accent-warm: #8b5cf6;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --success: #027a48;
  --success-soft: #dcfae6;
  --warning: #a15c07;
  --warning-soft: #fff3d6;
  --shadow: 0 10px 26px rgba(32, 33, 35, 0.07);
  --shadow-soft: 0 4px 14px rgba(32, 33, 35, 0.05);
  --focus: 0 0 0 4px rgba(16, 163, 127, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100%;
  overflow-x: hidden;
  min-height: 100vh;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: var(--bg);
}

body.chat-page {
  height: 100dvh;
  overflow: hidden;
}

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

button,
label {
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

button,
a,
input,
textarea,
select {
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease;
}

.app-shell {
  min-height: 100dvh;
  padding: 28px;
}

.chat-app-shell {
  display: flex;
  height: 100dvh;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  padding: env(safe-area-inset-top) 0 0;
  background: var(--surface);
}

.page-shell {
  min-height: 100dvh;
  padding: calc(28px + env(safe-area-inset-top)) 28px calc(28px + env(safe-area-inset-bottom));
}

.auth-shell {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
}

.auth-card {
  display: grid;
  width: min(100%, 420px);
  gap: 18px;
  padding: 32px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
}

.auth-card::before {
  display: block;
  width: 72px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-warm));
  content: "";
}

.auth-card h1,
.auth-card p {
  margin: 0;
}

.auth-brand,
.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(16, 163, 127, 0.24);
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(16, 163, 127, 0.95), rgba(139, 92, 246, 0.9)),
    var(--accent);
  box-shadow: 0 8px 18px rgba(16, 163, 127, 0.16);
}

.auth-note,
.auth-link {
  color: var(--muted);
  line-height: 1.5;
}

.auth-link a,
.topbar a {
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(100%, 1480px);
  min-height: 52px;
  margin: 0 auto 10px;
  padding: 6px 10px;
  color: var(--muted-strong);
  font-size: 14px;
  font-weight: 700;
}

.chat-app-shell .topbar {
  flex: 0 0 auto;
  overflow: hidden;
  width: 100%;
  min-height: 52px;
  margin: 0;
  border-width: 0 0 1px;
  border-radius: 0;
  background: var(--surface);
  box-shadow: none;
  backdrop-filter: none;
}

.chat-app-shell .topbar > span:not(.topbar-spacer),
.chat-app-shell .topbar a {
  flex: 0 0 auto;
}

.chat-app-shell [data-user-email] {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-brand {
  margin-right: 4px;
  color: var(--text) !important;
}

.topbar a {
  border-radius: 8px;
  padding: 10px 12px;
}

.topbar .ghost-button {
  min-height: 38px;
}

.topbar a:hover {
  background: var(--surface-soft);
}

.topbar a[aria-current="page"] {
  color: var(--text);
  background: var(--surface-strong);
}

.topbar-spacer {
  flex: 1;
}

.content-panel {
  width: min(100%, 1480px);
  max-width: none;
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 450px) minmax(0, 1fr);
  gap: 20px;
  max-width: 1320px;
  min-height: calc(100dvh - 56px);
  margin: 0 auto;
}

.chat-workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 0;
  width: 100%;
  min-height: 0;
  flex: 1;
  margin: 0 auto;
  border-top: 0;
}

.chat-sidebar {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 14px;
  background: var(--surface-soft);
  box-shadow: none;
  backdrop-filter: none;
}

.sidebar-head,
.chat-header,
.header-actions,
.composer-input-row,
.composer-options,
.admin-layout {
  display: flex;
  gap: 12px;
}

.sidebar-head,
.chat-header {
  align-items: flex-start;
  justify-content: space-between;
}

.sidebar-head {
  margin-bottom: 14px;
}

.compact-button {
  min-height: 40px;
  padding: 0 14px;
}

.chat-sidebar .compact-button {
  min-width: 76px;
}

.session-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  align-content: start;
  padding-right: 2px;
  scrollbar-width: thin;
}

.session-item {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 64px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.session-item:hover {
  border-color: var(--line-strong);
  background: var(--surface);
}

.session-item strong,
.session-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.session-item.active {
  border-color: var(--line);
  background: var(--surface);
  box-shadow: none;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  padding: 0;
  background: var(--surface);
  box-shadow: none;
  backdrop-filter: none;
}

.chat-header {
  flex: 0 0 auto;
}

.chat-header {
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.92);
}

.header-actions {
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.danger-button {
  color: var(--danger);
}

.chat-messages {
  display: flex;
  flex: 1 1 auto;
  overflow: auto;
  width: 100%;
  min-height: 0;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: var(--surface);
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.chat-empty {
  display: grid;
  min-height: 100%;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.chat-main > .message {
  flex: 0 0 auto;
  width: min(100% - 40px, 860px);
  margin: 12px auto 0;
}

.chat-empty strong {
  color: var(--text);
  font-size: 22px;
}

.chat-empty span {
  max-width: 480px;
  line-height: 1.6;
}

.compact-empty {
  min-height: 180px;
  padding: 16px;
}

.chat-message {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  width: min(100%, 860px);
  max-width: none;
  margin: 0 auto;
  padding: 22px 24px;
}

.user-message {
  align-self: stretch;
  grid-template-columns: minmax(0, 1fr) 38px;
  background: var(--surface);
}

.assistant-message {
  background: var(--surface);
}

.user-message .message-avatar {
  grid-column: 2;
  grid-row: 1;
}

.user-message .message-bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  max-width: min(680px, 100%);
  border-radius: 18px;
  padding: 12px 14px;
  background: var(--surface-soft);
}

.message-avatar {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 900;
}

.message-bubble {
  display: grid;
  gap: 10px;
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.message-text {
  line-height: 1.65;
  white-space: normal;
  overflow-wrap: anywhere;
}

.message-bubble time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.generation-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.generation-meta span,
.status-pill {
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 800;
}

.generation-meta.success span:first-child,
.status-pill.success {
  color: var(--success);
  background: var(--success-soft);
}

.generation-meta.failed span:first-child,
.generation-meta.blocked span:first-child,
.status-pill.failed,
.status-pill.blocked {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-pill.pending {
  color: var(--warning);
  background: var(--warning-soft);
}

.message-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.generation-loading-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.generation-loading-card {
  position: relative;
  overflow: hidden;
  min-height: 180px;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 28% 24%, rgba(16, 163, 127, 0.26), transparent 28%),
    radial-gradient(circle at 70% 62%, rgba(139, 92, 246, 0.2), transparent 30%),
    linear-gradient(135deg, #f7f7f8, #ececf1);
  filter: saturate(1.08);
  box-shadow: var(--shadow-soft);
}

.generation-loading-blur {
  position: absolute;
  inset: 18%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.48);
  filter: blur(24px);
  animation: softPulse 1.8s ease-in-out infinite;
}

.generation-loading-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    transparent 0%,
    rgba(255, 255, 255, 0.2) 34%,
    rgba(255, 255, 255, 0.72) 48%,
    rgba(255, 255, 255, 0.2) 62%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: shimmer 1.45s ease-in-out infinite;
}

.chat-image-card {
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.chat-image-card a:first-child,
.image-preview-button {
  display: grid;
  width: 100%;
  min-height: 180px;
  aspect-ratio: 1 / 1;
  place-items: center;
  border: 0;
  padding: 0;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.03) 25%, transparent 25%),
    #0f172a;
  cursor: zoom-in;
  font: inherit;
}

.chat-image-card img,
.image-preview-button img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
}

.image-preview-button:hover img {
  opacity: 0.94;
}

.chat-composer {
  display: grid;
  flex: 0 0 auto;
  min-width: 0;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 14px 20px calc(18px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
}

.composer-options {
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  width: min(100%, 860px);
  margin: 0 auto;
}

.upload-preview {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: min(100%, 860px);
  min-width: 0;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  background: var(--surface-soft);
}

.upload-preview img {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  background: #0f172a;
}

.upload-preview strong,
.upload-preview span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-preview strong {
  color: var(--text);
  font-size: 13px;
}

.upload-preview span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ratio-strip {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
  gap: 8px;
  scrollbar-width: thin;
}

.ratio-chip {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--muted);
  background: var(--surface);
  font-weight: 800;
}

.ratio-chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.ratio-chip.active {
  border-color: rgba(16, 163, 127, 0.42);
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.mini-field {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mini-field input {
  width: 72px;
  min-height: 38px;
}

.toggle-field,
.table-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.toggle-field input,
.table-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.composer-input-row {
  align-items: flex-end;
  width: min(100%, 860px);
  min-width: 0;
  margin: 0 auto;
}

.attach-button {
  display: inline-grid;
  flex: 0 0 auto;
  width: 44px;
  height: 58px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted-strong);
  background: var(--surface);
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(32, 33, 35, 0.05);
}

.attach-button:hover {
  border-color: var(--line-strong);
  color: var(--text);
  background: var(--surface-soft);
}

.attach-button input {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.attach-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.composer-input-row textarea {
  min-height: 58px;
  max-height: 180px;
  border-radius: 14px;
  background: var(--surface-raised);
  box-shadow: 0 6px 18px rgba(32, 33, 35, 0.08);
}

.send-button {
  min-width: 72px;
  min-height: 58px;
  border-radius: 14px;
}

.sr-only {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.controls-panel {
  align-self: start;
  padding: 24px;
}

.results-panel {
  display: flex;
  min-height: 620px;
  flex-direction: column;
  padding: 24px;
}

.brand-row,
.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 24px;
  line-height: 1.2;
}

.result-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-badge {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: var(--surface);
  white-space: nowrap;
}

.status-badge.ready {
  border-color: rgba(2, 122, 72, 0.24);
  color: var(--success);
  background: var(--success-soft);
}

.status-badge.warn {
  border-color: rgba(161, 92, 7, 0.28);
  color: var(--warning);
  background: var(--warning-soft);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 22px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.tab-button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.tab-button.active {
  color: var(--accent-dark);
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(23, 32, 24, 0.1);
}

.form-stack {
  display: grid;
  gap: 18px;
}

.field,
.upload-group {
  display: grid;
  gap: 8px;
}

.field span,
.field-label,
.ratio-field legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

textarea,
input[type="number"],
input[type="email"],
input[type="password"],
input[type="text"],
input[type="search"],
input[type="datetime-local"] {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  outline: none;
}

textarea,
input[type="number"],
input[type="email"],
input[type="password"],
input[type="text"],
input[type="search"],
input[type="datetime-local"] {
  padding: 12px 13px;
}

.moderation-form input,
.moderation-form select {
  min-height: 44px;
}

textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.55;
}

textarea:focus,
input:focus,
.tab-button:focus-visible,
.ratio-button:focus-visible,
.ratio-chip:focus-visible,
.image-preview-button:focus-visible,
.icon-action-button:focus-visible,
.attach-button:focus-within,
.upload-box:focus-within,
.primary-button:focus-visible,
.ghost-button:focus-visible,
.download-button:focus-visible,
select:focus {
  border-color: rgba(16, 163, 127, 0.72);
  box-shadow: var(--focus);
  outline: none;
}

.upload-box {
  display: grid;
  min-height: 92px;
  place-items: center;
  gap: 4px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 18px;
  color: var(--muted);
  background: var(--surface-soft);
  text-align: center;
  cursor: pointer;
}

.upload-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.upload-title {
  color: var(--text);
  font-weight: 800;
}

.upload-meta {
  font-size: 12px;
}

.source-preview {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f172a;
}

.source-preview img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
}

.source-preview span {
  padding: 9px 11px;
  color: #eaf1e7;
  font-size: 12px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.35);
}

.ratio-field {
  display: grid;
  gap: 10px;
  margin: 0;
  border: 0;
  padding: 0;
}

.ratio-field legend {
  padding: 0;
}

.ratio-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.ratio-button {
  display: grid;
  min-height: 58px;
  align-content: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  color: var(--text);
  background: var(--surface);
}

.ratio-button span {
  font-size: 13px;
  font-weight: 800;
}

.ratio-button small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ratio-button.active {
  border-color: rgba(16, 163, 127, 0.48);
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.field-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 14px;
  align-items: end;
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.code-row .ghost-button {
  min-height: 44px;
  white-space: nowrap;
}

.primary-button,
.ghost-button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: var(--radius);
  font-weight: 800;
}

.primary-button {
  border: 0;
  color: white;
  background: var(--accent);
  box-shadow: none;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.ghost-button {
  border: 1px solid var(--line);
  padding: 0 14px;
  color: var(--muted-strong);
  background: var(--surface);
}

.ghost-button:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.message {
  margin-bottom: 16px;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-weight: 700;
  line-height: 1.45;
}

.message.error {
  color: var(--danger);
  background: var(--danger-soft);
}

.message.success {
  color: var(--success);
  background: var(--success-soft);
}

.loading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.loading strong {
  color: var(--text);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--surface-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  flex: 1;
}

.gallery.empty {
  display: grid;
  min-height: 360px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(241, 245, 249, 0.7);
}

.empty-state {
  display: grid;
  gap: 8px;
  max-width: 280px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
}

.image-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.image-frame {
  display: grid;
  min-height: 260px;
  margin: 0;
  place-items: center;
  background: #111814;
}

.image-frame img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 540px;
  object-fit: contain;
}

.image-actions {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.revised-prompt {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.download-button {
  border: 1px solid var(--line);
  min-height: 34px;
  padding: 0 10px;
  color: var(--accent-dark);
  text-decoration: none;
  background: var(--accent-soft);
}

.download-button:hover {
  border-color: rgba(16, 163, 127, 0.35);
  background: #dff7ef;
}

.hidden {
  display: none !important;
}

.modal-open {
  overflow: hidden;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.image-modal-panel {
  position: relative;
  display: grid;
  max-width: min(1100px, 94vw);
  max-height: min(860px, 92dvh);
  place-items: center;
}

.image-modal-panel img {
  display: block;
  max-width: 100%;
  max-height: 92dvh;
  border-radius: var(--radius);
  object-fit: contain;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.4);
}

.redeem-panel {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(420px, 92vw);
  gap: 16px;
  padding: 22px;
}

.redeem-panel textarea {
  min-height: auto;
}

.image-modal-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  display: flex;
  gap: 8px;
}

.icon-action-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  color: #ffffff;
  background: rgba(0, 0, 0, 0.58);
  text-decoration: none;
  backdrop-filter: blur(10px);
}

.icon-action-button:hover {
  background: rgba(0, 0, 0, 0.78);
}

.icon-action-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.history-list {
  display: grid;
  gap: 14px;
}

.history-item {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.history-item p {
  margin: 0;
  color: var(--text);
  line-height: 1.55;
}

.history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.history-head strong,
.history-head span {
  display: block;
}

.history-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-top: 4px;
}

.ratio-pill {
  border-radius: 999px;
  padding: 6px 9px;
  color: var(--accent-dark) !important;
  background: var(--accent-soft);
  white-space: nowrap;
}

.history-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.history-thumb {
  display: grid;
  overflow: hidden;
  width: 100%;
  min-height: 140px;
  aspect-ratio: 1 / 1;
  place-items: center;
  border: 0;
  padding: 0;
  border-radius: var(--radius);
  background: #0f172a;
  cursor: zoom-in;
  font: inherit;
}

.history-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(241, 245, 249, 0.92)),
    var(--surface-soft);
  box-shadow: var(--shadow-soft);
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.stat-card strong {
  color: var(--text);
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.admin-section {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.admin-section h2 {
  font-size: 20px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.search-input {
  max-width: 260px;
}

.providers-list {
  display: grid;
  gap: 8px;
}

.provider-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  background: var(--surface);
}

.ok-text {
  color: var(--accent-dark);
  font-weight: 800;
}

.error-text {
  color: var(--danger);
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  background: var(--surface-soft);
}

tbody tr:hover {
  background: #f8fbff;
}

.inline-credit-form {
  display: grid;
  grid-template-columns: 100px minmax(140px, 1fr) 72px;
  gap: 8px;
}

.inline-credit-form input,
.inline-credit-form button {
  min-height: 38px;
}

.inline-credit-form button {
  border: 0;
  border-radius: var(--radius);
  color: white;
  background: var(--accent);
  font-weight: 800;
}

.inline-credit-form button:hover {
  background: var(--accent-dark);
}

.admin-layout {
  align-items: flex-start;
  width: min(100%, 1480px);
  margin: 0 auto;
  gap: 18px;
}

.admin-nav {
  position: sticky;
  top: 18px;
  display: grid;
  flex: 0 0 252px;
  gap: 8px;
  padding: 18px;
}

.admin-nav h1 {
  margin-bottom: 8px;
  font-size: 24px;
}

.admin-nav-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-weight: 900;
}

.admin-nav-button:hover,
.admin-nav-button.active {
  border-color: rgba(16, 163, 127, 0.28);
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.admin-nav-button.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.admin-content {
  flex: 1;
  min-width: 0;
}

.admin-view {
  display: none;
}

.admin-view.active {
  display: grid;
  gap: 14px;
}

.moderation-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  padding: 12px;
  background: var(--surface-soft);
}

.compact-field {
  gap: 6px;
}

.compact-field span {
  font-size: 12px;
}

.generated-codes {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface-soft);
}

.generated-codes strong {
  color: var(--text);
}

.generated-codes span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.generated-codes textarea {
  min-height: 130px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  resize: vertical;
}

select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
}

.word-input {
  min-width: 120px;
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
}

.prompt-cell {
  max-width: 380px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

td small {
  display: block;
  max-width: 260px;
  overflow: hidden;
  margin-top: 5px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inline-loading {
  margin-bottom: 0;
}

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

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

@keyframes softPulse {
  0%,
  100% {
    opacity: 0.42;
    transform: scale(0.92);
  }

  50% {
    opacity: 0.78;
    transform: scale(1.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

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

  .chat-app-shell {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: env(safe-area-inset-top) 0 0;
  }

  .page-shell {
    padding: 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .controls-panel,
  .results-panel {
    padding: 18px;
  }

  .results-panel {
    min-height: 440px;
  }

  .chat-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    flex: none;
    min-height: 0;
    flex: 1;
  }

  .chat-sidebar {
    display: grid;
    max-height: 142px;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-head {
    align-items: center;
    margin-bottom: 8px;
  }

  .sidebar-head h1 {
    font-size: 18px;
  }

  .session-list {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    padding: 0 2px 4px;
    scroll-snap-type: x proximity;
  }

  .session-item {
    flex: 0 0 min(240px, 74vw);
    min-height: 58px;
    scroll-snap-align: start;
  }

  .chat-main {
    min-height: 0;
  }

  .admin-layout {
    flex-direction: column;
  }

  .admin-nav {
    position: static;
    display: flex;
    overflow-x: auto;
    width: 100%;
    flex: none;
    gap: 8px;
    padding: 10px;
  }

  .admin-nav h1,
  .admin-nav .eyebrow {
    display: none;
  }

  .admin-nav-button {
    flex: 0 0 auto;
    min-height: 42px;
    white-space: nowrap;
  }

  .moderation-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body.chat-page {
    height: 100dvh;
    overflow: hidden;
  }

  body:not(.chat-page) {
    min-height: 100dvh;
  }

  .auth-shell {
    align-items: start;
    place-items: start stretch;
    padding: calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  }

  .auth-card {
    width: 100%;
    gap: 16px;
    border-radius: 12px;
    padding: 22px 18px;
  }

  .auth-card h1 {
    font-size: 24px;
  }

  .auth-note,
  .auth-link {
    font-size: 14px;
  }

  .brand-row,
  .results-header,
  .chat-header,
  .section-head,
  .provider-row,
  .history-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: stretch;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    padding: 8px;
  }

  .topbar a,
  .topbar .ghost-button {
    min-height: 44px;
    padding: 0 10px;
  }

  .topbar-brand {
    flex: 1 1 100%;
    min-height: 44px;
  }

  .page-shell .topbar [data-user-email] {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-app-shell .topbar {
    gap: 4px;
    min-height: auto;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px 8px;
    scrollbar-width: thin;
  }

  .chat-app-shell .topbar a,
  .chat-app-shell .topbar .ghost-button {
    min-height: 36px;
    padding: 0 8px;
    font-size: 13px;
  }

  .chat-app-shell .topbar-brand {
    flex: 0 0 auto;
  }

  .topbar-spacer {
    display: none;
  }

  .chat-app-shell .topbar-spacer {
    display: block;
    min-width: 8px;
  }

  .chat-app-shell [data-user-email] {
    display: none;
  }

  .chat-app-shell .topbar > span:not(.topbar-spacer):not([data-user-email]) {
    flex: 0 0 auto;
    min-height: 36px;
    align-content: center;
    padding: 0 6px;
    font-size: 13px;
    white-space: nowrap;
  }

  h1 {
    font-size: 25px;
  }

  h2 {
    font-size: 20px;
  }

  .content-panel {
    width: 100%;
    padding: 16px;
  }

  .page-shell {
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(14px + env(safe-area-inset-bottom));
  }

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

  .field-row {
    grid-template-columns: 1fr;
  }

  .code-row {
    grid-template-columns: 1fr;
  }

  .code-row .ghost-button {
    width: 100%;
  }

  .chat-workspace {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .chat-sidebar {
    max-height: 82px;
    padding: 6px 8px;
  }

  .sidebar-head {
    gap: 6px;
    margin-bottom: 6px;
  }

  .sidebar-head .eyebrow {
    display: none;
  }

  .sidebar-head h1 {
    font-size: 14px;
  }

  .chat-sidebar .compact-button {
    min-width: 58px;
    min-height: 32px;
    padding: 0 8px;
    font-size: 12px;
  }

  .session-item {
    flex-basis: min(170px, 62vw);
    min-height: 38px;
    padding: 7px 9px;
  }

  .session-item strong {
    font-size: 13px;
  }

  .session-item span {
    display: none;
  }

  .chat-header {
    gap: 6px;
    padding: 8px 10px;
  }

  .chat-header h2 {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-header .eyebrow,
  #sessionMeta {
    display: none;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    gap: 6px;
  }

  .header-actions .ghost-button {
    min-height: 34px;
    padding: 0 8px;
    font-size: 12px;
  }

  .chat-main > .message {
    width: calc(100% - 20px);
    margin-top: 8px;
    margin-bottom: 8px;
    padding: 10px 12px;
    font-size: 14px;
  }

  .chat-message,
  .user-message {
    grid-template-columns: 1fr;
    max-width: 100%;
    padding: 10px 10px;
  }

  .message-text {
    font-size: 14px;
    line-height: 1.52;
  }

  .message-avatar {
    display: none;
  }

  .user-message .message-bubble {
    grid-column: auto;
    justify-self: stretch;
    max-width: 100%;
  }

  .composer-options,
  .composer-input-row {
    width: 100%;
  }

  .composer-options {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
  }

  .composer-input-row {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 50px;
    gap: 6px;
    align-items: end;
  }

  .attach-button {
    width: 40px;
    height: 44px;
  }

  .chat-composer {
    gap: 6px;
    border-top-color: var(--line-strong);
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  }

  .composer-input-row textarea {
    min-height: 44px;
    max-height: 104px;
    padding: 10px 11px;
    font-size: 14px;
  }

  .send-button {
    min-width: 50px;
    min-height: 44px;
    padding: 0 8px;
    font-size: 13px;
  }

  .upload-preview {
    grid-template-columns: 44px minmax(0, 1fr);
    width: 100%;
  }

  .upload-preview img {
    width: 44px;
    height: 44px;
  }

  .upload-preview .ghost-button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .ratio-strip {
    flex-wrap: nowrap;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .ratio-chip {
    flex: 0 0 auto;
    min-height: 32px;
    padding: 0 9px;
    font-size: 12px;
  }

  .mini-field {
    gap: 5px;
    white-space: nowrap;
  }

  .mini-field input {
    width: 50px;
    min-height: 32px;
    padding: 6px 8px;
    font-size: 13px;
  }

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

  .generation-loading-grid {
    grid-template-columns: 1fr;
  }

  .generation-loading-card,
  .chat-image-card a:first-child,
  .image-preview-button {
    min-height: 150px;
  }

  .image-modal {
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  }

  .image-modal-actions {
    top: 8px;
    right: 8px;
  }

  .send-button {
    min-height: 44px;
  }

  .image-modal-panel {
    max-width: 100%;
    max-height: 88dvh;
  }

  .image-modal-panel img {
    max-height: 86dvh;
  }

  .redeem-panel {
    width: 100%;
    max-height: calc(100dvh - 32px);
    overflow: auto;
    padding: 18px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-card strong {
    font-size: 24px;
  }

  .moderation-form {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .gallery {
    grid-template-columns: 1fr;
  }

  .inline-credit-form {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    margin-inline: -4px;
    border-radius: 8px;
  }

  .table-wrap::before {
    display: block;
    padding: 8px 10px;
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 12px;
    font-weight: 800;
    content: "可左右滑动查看完整表格";
  }

  table {
    min-width: 700px;
  }

  th,
  td {
    padding: 10px;
  }

  .search-input {
    max-width: none;
  }

  .provider-row {
    gap: 8px;
  }

  .provider-row strong,
  .provider-row span {
    overflow-wrap: anywhere;
  }

  .history-item {
    padding: 14px;
  }

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

  .history-thumb {
    min-height: 120px;
  }
}

@media (max-width: 390px) {
  .chat-app-shell .topbar {
    padding: 5px 6px;
  }

  .chat-app-shell .topbar a,
  .chat-app-shell .topbar .ghost-button {
    min-height: 34px;
    padding: 0 7px;
  }

  .brand-mark {
    width: 22px;
    height: 22px;
  }

  .chat-sidebar {
    max-height: 76px;
  }

  .session-item {
    flex-basis: min(156px, 60vw);
  }

  .chat-header {
    padding: 8px 10px;
  }

  .header-actions {
    gap: 6px;
  }

  .composer-input-row {
    grid-template-columns: 38px minmax(0, 1fr) 48px;
    gap: 6px;
  }

  .attach-button,
  .send-button,
  .composer-input-row textarea {
    min-height: 42px;
  }

  .attach-button {
    width: 38px;
    height: 42px;
  }

  .send-button {
    min-width: 48px;
    padding: 0 8px;
  }

  .ratio-chip {
    padding: 0 9px;
  }

  .mini-field span {
    display: none;
  }

  .mini-field input {
    width: 48px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

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

  .auth-card {
    padding: 20px 16px;
  }
}
