/* ============================================================
   Design Tokens
   ============================================================ */
:root {
  --bg:          #f0f2f5;
  --surface:     #ffffff;
  --surface-2:   #f7f9fb;
  --surface-3:   #edf1f6;
  --line:        #dce3ec;
  --line-soft:   #e8eef5;

  --text:        #111827;
  --muted:       #6b7a90;
  --muted-2:     #96a3b4;
  --ink:         #0d1520;

  --accent:      #1a6fc4;
  --accent-2:    #0d8a6a;

  --green:       #0d8a6a;
  --green-bg:    #e8f7f2;
  --red:         #c0392b;
  --red-bg:      #fdf2f1;
  --amber:       #b45309;

  --shadow-sm:   0 1px 3px rgba(17,24,39,.06), 0 1px 2px rgba(17,24,39,.04);
  --shadow:      0 4px 12px rgba(17,24,39,.08);
  --shadow-lg:   0 12px 36px rgba(17,24,39,.13);

  --topbar-h:    58px;
  --r:           8px;
  --ease:        140ms ease;

  --workspace-max:    1680px;
  --workspace-gutter: 20px;
  --workspace-gap:    14px;
  --assistant-w:      320px;
  --composer-w:       320px;
  --fixed-composer-left: max(var(--workspace-gutter), calc((100vw - var(--workspace-max)) / 2 + var(--workspace-gutter) + 1px));
}

/* ============================================================
   Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
button:active { transform: translateY(1px); }
a { color: inherit; }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
.runtime-hidden { display: none !important; }

/* ============================================================
   App Shell
   ============================================================ */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: var(--topbar-h);
}

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  flex: 0 0 auto;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: rgba(255,255,255,.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

/* Brand */
.brand-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: var(--ink);
  display: grid;
  place-items: center;
}

.brand-mark span {
  position: relative;
  width: 14px;
  height: 14px;
  display: block;
}

.brand-mark span::before,
.brand-mark span::after {
  content: "";
  position: absolute;
  left: 0;
  width: 14px;
  height: 2px;
  border-radius: 1px;
  background: #fff;
}
.brand-mark span::before { top: 4px; }
.brand-mark span::after  { top: 9px; opacity: .55; }

.brand-row h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-row p {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
}

/* Switcher */
.switcher {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-3);
}

.switcher button {
  min-width: 76px;
  height: 30px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  transition: all var(--ease);
}

.switcher button.active {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.switcher button:hover:not(.active) {
  color: var(--text);
  background: rgba(255,255,255,.6);
}

/* Status row */
.status-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.status-card {
  height: 32px;
  min-width: 88px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}

.status-card span   { font-size: 10px; font-weight: 600; color: var(--muted); line-height: 1.1; }
.status-card strong {
  font-size: 13px; font-weight: 700; color: var(--ink);
  line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px;
}

.top-action {
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  background: var(--surface);
  white-space: nowrap;
  transition: all var(--ease);
}
.top-action:hover { border-color: #c0cad6; background: var(--surface-2); }

/* Credit coin */
.credit-star {
  display: inline-block;
  position: relative;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  vertical-align: -1px;
  flex-shrink: 0;
}
.credit-star::before {
  content: "";
  position: absolute;
  inset: 2.5px;
  background: #fef3c7;
  clip-path: polygon(50% 0,61% 35%,98% 35%,68% 57%,79% 91%,50% 70%,21% 91%,32% 57%,2% 35%,39% 35%);
}
.credit-balance { display: inline-flex; align-items: center; gap: 4px; }

/* ============================================================
   Main layout: main.workspace.simplified-workspace
   Two columns: studio-panel | assistant-panel
   ============================================================ */
.workspace,
.simplified-workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--assistant-w);
  align-items: start;
  gap: var(--workspace-gap);
  padding: var(--workspace-gutter) var(--workspace-gutter) 24px;
  max-width: var(--workspace-max);
  width: 100%;
  margin: 0 auto;
}

/* ============================================================
   Studio Panel  (section.studio-panel)
   Full-height card: header on top, creation-layout fills rest
   ============================================================ */
.studio-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--topbar-h) - 38px);
}

/* ============================================================
   Creation Layout  (form.creation-layout)
   Three children in a row:
     aside.primary-composer | button.composer-rail | div.canvas-workbench
   ============================================================ */
.creation-layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--composer-w) minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-h) - 38px);
  align-items: stretch;
  margin: 0;
}

/* When JS adds sidebar-collapsed class */
.creation-layout.sidebar-collapsed {
  grid-template-columns: 0 36px minmax(0, 1fr);
}

/* ============================================================
   Primary Composer  (aside.primary-composer)
   Left panel inside creation-layout
   ============================================================ */
.primary-composer {
  grid-column: 1;
  margin: 0;
  border: 0;
  border-radius: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: fixed;
  left: var(--fixed-composer-left);
  top: calc(var(--topbar-h) + var(--workspace-gutter));
  z-index: 45;
  width: var(--composer-w);
  height: calc(100vh - var(--topbar-h) - var(--workspace-gutter) - 24px);
  max-height: calc(100vh - var(--topbar-h) - var(--workspace-gutter) - 24px);
  align-self: start;
}

.creation-layout.sidebar-collapsed .primary-composer {
  width: 0;
  left: var(--fixed-composer-left);
  overflow: hidden;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
}

/* History panel — docked to bottom of primary-composer */
/* Bottom panels row — history + credits side by side */
.bottom-panels {
  flex-shrink: 0;
  border-top: 1px solid var(--line-soft);
  display: flex;
  max-height: 280px;
  min-height: 0;
}

.history-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line-soft);
}

.credits-panel {
  width: 160px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.credits-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #c8d3df transparent;
  padding: 0 8px 4px;
  font-size: 12px;
}

.credits-panel-foot {
  padding: 4px 8px;
  flex-shrink: 0;
}

.credits-panel-body .credits-entry {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 5px 0;
  border-bottom: 1px solid var(--line-soft);
  gap: 4px;
}
.credits-panel-body .credits-entry-left {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.credits-panel-body .credits-entry-right {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
}

.history-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 13px;
  flex-shrink: 0;
}

.history-panel-head span {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.history-panel-head button {
  border: 0;
  padding: 1px 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  background: transparent;
  transition: color var(--ease);
}
.history-panel-head button:hover { color: var(--accent-2); }

.history-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #c8d3df transparent;
  padding: 0 8px 8px;
}

/* 2-column thumb grid inside history panel */
.history-panel-body .gateway-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 0;
}

.history-panel-body .job-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  grid-template-columns: unset;
  column-gap: unset;
  padding: 0;
  border-radius: 6px;
  overflow: hidden;
}

.history-panel-body .job-thumb {
  grid-row: unset;
  width: 100%;
  height: 72px;
  border-radius: 0;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
}

.history-panel-body .job-item strong,
.history-panel-body .job-item span,
.history-panel-body .job-item small {
  padding: 0 6px;
}

.history-panel-body .job-item strong { padding-top: 5px; }
.history-panel-body .job-item small  { padding-bottom: 5px; }

/* composer-scroll wraps everything except prompt-actions */
.composer-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #c8d3df transparent;
}

/* Composer title bar */
.composer-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
}

.composer-title h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.composer-toggle {
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  background: var(--surface);
  transition: all var(--ease);
}
.composer-toggle:hover { border-color: #b0bdd0; color: var(--text); }

/* Prompt entry */
.prompt-entry {
  padding: 0;
  background: transparent;
}

.prompt-entry label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.canvas-composer textarea {
  width: 100%;
  min-height: 96px;
  max-height: 170px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.65;
  resize: none;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}

.canvas-composer textarea::placeholder { color: var(--muted-2); }

.canvas-composer textarea:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(26,111,196,.1);
}

/* Model strip */
.model-strip,
.control-section {
  padding: 10px 13px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
}

.option-stack { display: grid; gap: 6px; }

.model-option {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  background: var(--surface);
  transition: border-color var(--ease), background var(--ease);
}

.model-option:hover { border-color: #b8c5d4; background: var(--surface-2); }

.model-option.active {
  border-color: var(--ink);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.model-option strong {
  display: block;
  font-size: 13px; font-weight: 700; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.model-option small {
  display: block;
  margin-top: 2px;
  font-size: 11px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.single-model .model-option small { white-space: normal; }

.model-option em {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 19px;
  padding: 0 6px;
  border-radius: 4px;
  color: var(--accent-2);
  background: var(--green-bg);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Picture icon */
.picture-icon {
  width: 26px; height: 26px;
  border-radius: 5px;
  background: rgba(26,111,196,.08);
  position: relative;
  flex-shrink: 0;
}
.picture-icon::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1.5px solid var(--accent);
  border-radius: 2px;
}
.picture-icon::after {
  content: "";
  position: absolute;
  width: 9px; height: 5px;
  left: 8px; top: 13px;
  border-left: 1.5px solid var(--accent);
  border-bottom: 1.5px solid var(--accent);
  transform: skew(-22deg);
}

/* Controls (ratio + quality) */
.composer-controls {
  padding: 10px 13px 12px;
  background: var(--surface-2);
  display: grid;
  gap: 10px;
}

.compact-control { display: grid; gap: 6px; }

.control-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Ratio tiles */
.ratio-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.tile {
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
  transition: border-color var(--ease), background var(--ease), color var(--ease);
}

.tile:hover { border-color: #b0bdd0; color: var(--text); background: var(--surface-2); }

.tile.active {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.tile strong { font-size: 11px; font-weight: 700; }

/* Ratio shape indicators */
.ratio {
  display: block;
  border: 2px solid currentColor;
  border-radius: 2px;
  opacity: .65;
}
.tile.active .ratio { opacity: 1; }
.ratio.auto      { width: 17px; height: 17px; border-color: var(--accent-2); }
.ratio.square    { width: 17px; height: 17px; }
.ratio.portrait  { width: 12px; height: 19px; }
.ratio.landscape { width: 21px; height: 13px; }

/* Quality buttons */
.quality-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.quality {
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface);
  transition: border-color var(--ease), background var(--ease), color var(--ease);
}

.quality:hover { border-color: #b0bdd0; color: var(--text); background: var(--surface-2); }

.quality.active {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.quality strong { font-size: 13px; font-weight: 700; }
.quality small  { font-size: 11px; color: inherit; opacity: .7; }

/* Prompt actions bar (bottom of form) */
.prompt-actions {
  padding: 0;
  border-top: 0;
  background: transparent;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.prompt-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  min-width: 0;
  flex: 1;
}

.prompt-meta span {
  font-size: 11px;
  color: var(--muted-2);
  font-weight: 600;
}

.prompt-meta span.warning { color: var(--amber); }

.ghost-action,
.ghost-upload {
  display: inline-flex;
  align-items: center;
  height: 27px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--ease), color var(--ease);
}
.ghost-action:hover,
.ghost-upload:hover { border-color: #b0bdd0; color: var(--text); }
.ghost-upload input { display: none; }

#promptCounter { margin-left: auto; font-size: 11px; color: var(--muted-2); font-weight: 600; }
#promptCounter.warning { color: var(--amber); }

.reference-tray {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.reference-item {
  width: 86px;
  display: grid;
  gap: 4px;
}

.reference-item img {
  width: 86px;
  height: 64px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.reference-item span {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Generate button */
.generate-button {
  width: 160px;
  height: 38px;
  flex: 0 0 160px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 7px;
  color: #fff;
  background: var(--ink);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -.01em;
  box-shadow: 0 2px 8px rgba(13,21,32,.2);
  transition: background var(--ease), box-shadow var(--ease);
}
.generate-button:hover { background: #1c2f46; box-shadow: 0 5px 14px rgba(13,21,32,.24); }

.generate-button.is-loading { position: relative; color: transparent; }
.generate-button.is-loading::after {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.38);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 750ms linear infinite;
}

/* Spark icon */
.spark {
  width: 13px; height: 13px;
  flex-shrink: 0;
  display: inline-block;
  position: relative;
  border-radius: 3px;
  background: rgba(255,255,255,.14);
}
.spark::before {
  content: "";
  position: absolute;
  width: 4px; height: 4px;
  left: 4.5px; top: 4.5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 -4px 0 -1.5px currentColor, 0 4px 0 -1.5px currentColor,
              4px 0 0 -1.5px currentColor, -4px 0 0 -1.5px currentColor;
}

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

/* ============================================================
   Composer Rail  (button.composer-rail)
   Narrow vertical strip shown when sidebar is collapsed
   ============================================================ */
.composer-rail {
  grid-column: 2;
  display: none; /* hidden by default */
  width: 36px;
  height: 100%;
  border: 0;
  border-right: 1px solid var(--line-soft);
  padding: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  writing-mode: vertical-rl;
  letter-spacing: .04em;
  transition: background var(--ease), color var(--ease);
}
.composer-rail:hover { background: var(--surface-3); color: var(--text); }

.creation-layout.sidebar-collapsed .composer-rail {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   Canvas Stage  (div.canvas-stage)
   Right area: grid background + centred empty/result card
   ============================================================ */
.canvas-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 500px;
  background:
    linear-gradient(rgba(17,24,39,.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17,24,39,.028) 1px, transparent 1px),
    var(--surface-2);
  background-size: 36px 36px, 36px 36px, auto;
  overflow: hidden;
}

.canvas-workbench {
  grid-column: 2;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(480px, 1fr) auto;
  background: var(--surface);
}

.creation-layout.sidebar-collapsed .canvas-workbench {
  grid-column: 3;
}

.canvas-composer {
  display: grid;
  gap: 8px;
  padding: 12px 18px 14px;
  border-top: 1px solid var(--line-soft);
  background: rgba(255,255,255,.96);
}

.canvas-stage.has-result {
  background:
    linear-gradient(rgba(17,24,39,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17,24,39,.035) 1px, transparent 1px),
    #eef2f6;
  background-size: 36px 36px, 36px 36px, auto;
}

.stage-result-image {
  position: absolute;
  z-index: 2;
  inset: 28px 42px 42px;
  width: calc(100% - 84px);
  height: calc(100% - 70px);
  object-fit: contain;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.stage-actions {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stage-action {
  height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--ease), background var(--ease);
}

button.stage-action,
button.result-link {
  font-family: inherit;
  cursor: pointer;
}

.stage-action:hover { border-color: #b0bdd0; background: #fff; }

.stage-action.primary {
  border-color: var(--ink);
  color: #fff;
  background: var(--ink);
}

.stage-action.primary:hover { background: #1c2f46; }

/* Empty state */
.empty-state {
  width: min(400px, calc(100% - 32px));
  text-align: center;
}

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

/* Placeholder graphic area */
.empty-preview,
.empty-preview-placeholder {
  min-height: 140px;
  display: grid;
  place-items: center;
  border-bottom: 1px solid var(--line-soft);
  background:
    radial-gradient(circle at 50% 46%, rgba(13,138,106,.09), transparent 42%),
    linear-gradient(rgba(17,24,39,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17,24,39,.03) 1px, transparent 1px),
    var(--surface-2);
  background-size: auto, 22px 22px, 22px 22px, auto;
}

.empty-preview::after,
.empty-preview-placeholder::after { display: none; }

.empty-preview img,
.empty-preview-placeholder img { display: none; }

/* Icon inside placeholder */
.preview-icon {
  width: 44px; height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.preview-icon::before {
  content: "";
  position: absolute;
  width: 6px; height: 6px;
  border-radius: 50%;
  top: 12px; left: 12px;
  background: var(--accent-2);
}
.preview-icon::after {
  content: "";
  position: absolute;
  width: 16px; height: 2px;
  border-radius: 99px;
  right: 10px; bottom: 12px;
  background: var(--accent-2);
  transform: rotate(-26deg);
}

/* Text inside empty card */
.empty-card > span {
  display: inline-flex;
  margin: 14px 18px 0;
  font-size: 11px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.empty-card > h2 {
  margin: 5px 18px 0;
  font-size: 18px; font-weight: 700;
  color: var(--ink);
  letter-spacing: -.02em;
}
.empty-card > p {
  margin: 5px 18px 18px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

/* Result card */
.result-card {
  width: min(860px, 90%);
  position: relative;
  z-index: 3;
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: fadeUp 160ms ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-art {
  aspect-ratio: 4/3;
  min-height: 320px;
  display: grid;
  place-items: center;
  background: #e8edf3;
}
.result-art img {
  width: 100%; height: 100%;
  min-height: 320px;
  display: block;
  object-fit: contain;
  background: #fff;
}

.canvas-stage.has-result {
  place-items: center;
}
.canvas-stage.has-result .empty-state {
  display: none !important;
}
.canvas-stage.has-result .result-card {
  display: none !important;
}

.result-caption {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 13px;
  border-top: 1px solid var(--line-soft);
}
.result-copy { flex: 1; min-width: 0; display: grid; gap: 2px; }
.result-caption strong { font-size: 13px; font-weight: 700; color: var(--ink); }
.result-caption span   { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.result-actions { display: flex; gap: 5px; flex-shrink: 0; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; align-items: center; }

.expiry-notice { width: 100%; margin: 0 0 4px; font-size: 11px; color: #b45309; background: #fffbeb; border: 1px solid #fde68a; border-radius: 4px; padding: 4px 8px; line-height: 1.4; }

.result-link {
  height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px; font-weight: 700;
  text-decoration: none;
  background: var(--surface-2);
  transition: border-color var(--ease), background var(--ease);
}
.result-link:hover { border-color: #b0bdd0; background: #fff; }

.result-link-primary { border-color: var(--ink) !important; color: #fff !important; background: var(--ink) !important; }
.result-link-primary:hover { background: #1c2f46 !important; }

.result-link.is-loading,
.stage-action.is-loading {
  opacity: .72;
  pointer-events: none;
}

/* Result placeholder (queued / loading / error) */
.result-placeholder {
  min-height: 200px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 28px;
  text-align: center;
}
.result-spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(13,138,106,.14);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}
.result-status-badge {
  height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border-radius: 99px;
  font-size: 11px; font-weight: 700;
}
.result-status-badge.queued,
.result-status-badge.running,
.result-status-badge.processing { color: var(--green); background: var(--green-bg); }
.result-status-badge.failed     { color: var(--red);   background: var(--red-bg);   }
.result-status-badge.succeeded  { color: var(--accent); background: rgba(26,111,196,.1); }

.result-placeholder strong { font-size: 17px; font-weight: 700; color: var(--ink); letter-spacing: -.02em; }
.result-placeholder p,
.result-placeholder small { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; max-width: 340px; }
.result-placeholder small { font-size: 12px; }
.result-card[data-status="failed"] .result-caption strong { color: var(--red); }

.gen-progress-wrap {
  width: 220px; max-width: 100%;
  height: 6px;
  background: rgba(13,138,106,.12);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}
.gen-progress-bar {
  height: 100%;
  background: var(--accent-2);
  border-radius: 99px;
  transition: width 1.2s cubic-bezier(.25,.8,.25,1);
  min-width: 6px;
}
.gen-progress-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-2);
  margin-top: 2px;
}

/* ============================================================
   Assistant Panel  (aside.panel.right-panel.assistant-panel)
   Right column — stacked cards
   ============================================================ */
.panel,
.right-panel,
.assistant-panel {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.assistant-panel {
  position: sticky;
  top: calc(var(--topbar-h) + 14px);
  max-height: calc(100vh - var(--topbar-h) - 28px);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #c8d3df transparent;
}

/* Individual cards */
.suggest-card {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 13px;
  flex-shrink: 0;
}

.suggest-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.suggest-card h2 {
  margin: 0;
  font-size: 13px; font-weight: 700;
  color: var(--ink);
}

.account-heading { margin-bottom: 8px; }
.account-heading > div { min-width: 0; }
.account-heading span {
  display: block;
  font-size: 10px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 3px;
}

.suggest-heading button {
  border: 0;
  padding: 1px 0;
  color: var(--accent);
  font-size: 12px; font-weight: 700;
  background: transparent;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color var(--ease);
}
.suggest-heading button:hover { color: var(--accent-2); }

.redeem-note {
  margin: 7px 0 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* Redeem form */
.redeem-form {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 6px;
}

.redeem-form input {
  width: 100%;
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface-2);
  font-size: 13px;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}
.redeem-form input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(26,111,196,.09);
}

.redeem-form button {
  min-height: 34px;
  border: none;
  border-radius: 6px;
  color: #fff;
  background: var(--ink);
  font-size: 13px; font-weight: 700;
  transition: background var(--ease);
}
.redeem-form button:hover { background: #1c2f46; }

/* Suggest / history list items */
.suggest-list,
.gateway-list {
  display: grid;
  gap: 5px;
  margin-top: 9px;
}

.suggest-item,
.gateway-item {
  width: 100%;
  display: block;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px; font-weight: 500;
  line-height: 1.5;
  text-align: left;
  background: var(--surface-2);
  transition: border-color var(--ease), background var(--ease);
}

.suggest-item:hover,
button.gateway-item:hover { border-color: #b0bdd0; background: #fff; color: var(--ink); }

.gateway-item strong { display: block; font-size: 12px; font-weight: 700; color: var(--ink); margin-bottom: 2px; }
.gateway-item span   { display: block; font-size: 11px; color: var(--muted); }
.gateway-item small  { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.4; word-break: break-word; }
.gateway-item.is-active  { border-color: #b0bdd0; box-shadow: var(--shadow-sm); }
.gateway-item.is-pending { border-style: dashed; }

.job-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  column-gap: 9px;
  align-items: center;
}
.job-item:not(:has(.job-thumb)) {
  grid-template-columns: 1fr;
}
.job-thumb {
  grid-row: span 3;
  width: 54px;
  height: 54px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  object-fit: cover;
  background: #fff;
}

.admin-summary {
  margin-top: 7px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

/* Ordering */
.redeem-card  { order: -3; }
.history-card { order: -2; }

/* ============================================================
   Toast
   ============================================================ */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 6px;
  z-index: 50;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  max-width: min(320px, calc(100vw - 32px));
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255,255,255,.97);
  box-shadow: 0 8px 24px rgba(17,24,39,.16);
  font-size: 13px; font-weight: 600;
  backdrop-filter: blur(10px);
  animation: toastIn 140ms ease both;
}

.toast::before {
  content: "";
  width: 6px; height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: var(--accent-2);
}

.toast.error { border-color: rgba(192,57,43,.2); color: var(--red); background: rgba(253,242,241,.97); }
.toast.error::before { background: var(--red); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Auth Dialog
   ============================================================ */
.auth-dialog {
  width: min(380px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.auth-dialog::backdrop {
  background: rgba(17,24,39,.28);
  backdrop-filter: blur(4px);
}

.auth-box {
  display: grid;
  gap: 12px;
  padding: 22px;
}

.auth-box h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.02em; }
.auth-box p  { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.auth-box label {
  display: grid;
  gap: 5px;
  font-size: 11px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.auth-box input {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface-2);
  font-size: 13px;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}
.auth-box input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(26,111,196,.09);
}

.auth-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.auth-actions button {
  height: 36px;
  min-width: 68px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #fff;
  background: var(--ink);
  font-size: 13px; font-weight: 700;
  transition: background var(--ease);
}
.auth-actions button:hover { background: #1c2f46; }

#closeAuth { color: var(--text); background: var(--surface-2); }
#closeAuth:hover { background: var(--surface-3); color: var(--ink); }

/* Loading state */
button.is-loading { position: relative; cursor: wait; }

/* ============================================================
   Responsive
   ============================================================ */

/* 1280px: tighten right column */
@media (max-width: 1280px) {
  :root {
    --workspace-gutter: 16px;
    --workspace-gap: 12px;
    --assistant-w: 295px;
    --composer-w: 290px;
  }

  .workspace,
  .simplified-workspace {
    padding: 12px 16px 20px;
  }
  .creation-layout.sidebar-collapsed { grid-template-columns: 0 36px minmax(0, 1fr); }
}

/* 1060px: hide right panel, single column */
@media (max-width: 1060px) {
  .workspace,
  .simplified-workspace {
    grid-template-columns: 1fr;
  }
  .assistant-panel {
    position: static;
    max-height: none;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    overflow: visible;
  }
}

/* 820px: mobile */
@media (max-width: 820px) {
  :root {
    --topbar-h: 138px;
    --workspace-gutter: 12px;
    --workspace-gap: 10px;
    --composer-w: 100%;
  }

  body { overflow-x: hidden; }

  .app-shell { flex-direction: column; }

  .topbar {
    grid-template-columns: 1fr;
    height: var(--topbar-h);
    padding: 10px 14px;
    gap: 8px;
    overflow-y: auto;
  }

  .switcher { justify-self: stretch; }
  .switcher button { flex: 1; }

  .status-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
  }
  .status-card:first-child { display: none; }

  .workspace,
  .simplified-workspace {
    grid-template-columns: 1fr;
    padding: 10px 12px 20px;
    gap: 10px;
  }

  .studio-panel { min-height: auto; }

  /* stack composer above canvas on mobile */
  .creation-layout {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto;
    min-height: auto;
  }

  .primary-composer {
    width: 100% !important;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    overflow: visible;
    position: static;
    left: auto;
    top: auto;
    height: auto;
    max-height: none;
  }

  .history-panel { max-height: 220px; }

  .history-panel-body .gateway-list { grid-template-columns: repeat(3, 1fr); }

  .creation-layout.sidebar-collapsed .primary-composer {
    width: 100% !important;
  }

  .creation-layout.sidebar-collapsed .advanced-config {
    display: none;
  }

  .composer-rail { display: none !important; }

  .canvas-stage { min-height: 300px; }

  .assistant-panel {
    position: static;
    max-height: none;
    grid-template-columns: 1fr;
    overflow: visible;
  }

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

  .result-caption { flex-direction: column; align-items: flex-start; }
  .result-actions { margin-left: 0; }
  .result-link { width: 100%; }

  .toast-stack { left: 12px; right: 12px; bottom: 12px; }
  .toast { width: 100%; max-width: none; }

  .auth-dialog { width: min(100%, calc(100vw - 24px)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ── 积分明细按钮 ── */
.credit-history-btn {
  background: none; border: 1px solid var(--border, #e2e8f0); border-radius: 6px;
  padding: 2px 8px; font-size: 12px; cursor: pointer; color: var(--muted, #718096);
  margin-left: 4px;
}
.credit-history-btn:hover { background: var(--surface, #f7fafc); }

/* ── 积分明细抽屉 ── */
.credits-drawer { position: fixed; inset: 0; z-index: 1000; display: flex; justify-content: flex-end; }
.credits-drawer.hidden { display: none; }
.credits-drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.credits-drawer-panel {
  position: relative; width: 420px; max-width: 100vw; background: var(--bg, #fff);
  display: flex; flex-direction: column; box-shadow: -4px 0 24px rgba(0,0,0,.12);
}
.credits-drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border, #e2e8f0); font-weight: 600;
}
.credits-drawer-body { flex: 1; overflow-y: auto; padding: 12px 16px; }
.credits-drawer-foot { padding: 12px 16px; border-top: 1px solid var(--border, #e2e8f0); text-align: center; }
.credits-loading { text-align: center; color: var(--muted, #718096); padding: 32px 0; }
.credits-entry {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border-light, #f0f4f8);
}
.credits-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.credits-thumb-placeholder { width: 44px; height: 44px; border-radius: 6px; background: var(--surface, #f7fafc); flex-shrink: 0; }
.credits-entry-mid { flex: 1; min-width: 0; }
.credits-entry-reason { font-size: 13px; font-weight: 500; }
.credits-entry-prompt { font-size: 12px; color: var(--muted, #718096); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.credits-entry-time { font-size: 11px; color: var(--muted, #718096); margin-top: 2px; }
.credits-entry-right { font-size: 15px; flex-shrink: 0; }

/* ── 多图结果网格 ── */
.multi-result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  width: 100%;
}
.multi-result-grid img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 8px; cursor: zoom-in;
}
