/* ══════════════════════════════════════════════════════
   Banana Pro WebUI — Design System
   Style: Apple-like, clean gray-white, minimal, tool-grade
   ══════════════════════════════════════════════════════ */

:root {
  /* Surface */
  --bg:            #f2f2f7;
  --bg-secondary:  #e5e5ea;
  --surface:       #ffffff;
  --surface-raised:#f9f9fb;
  --surface-inset: #f2f2f7;

  /* Borders */
  --border:        #d1d1d6;
  --border-strong: #aeaeb2;
  --border-focus:  #636366;

  /* Text */
  --text-primary:  #1c1c1e;
  --text-secondary:#636366;
  --text-tertiary: #aeaeb2;

  /* Accent — restrained, used only for primary action & selection */
  --accent:        #1c1c1e;
  --accent-hover:  #3a3a3c;
  --accent-soft:   #f2f2f7;
  --accent-select: #e5e5ea;

  /* Semantic */
  --danger:        #ff3b30;
  --danger-soft:   #fff1f0;
  --danger-text:   #c0392b;

  /* Radius scale */
  --r-xs:  4px;
  --r-sm:  6px;
  --r-md:  8px;
  --r-lg:  10px;
  --r-xl:  12px;
  --r-2xl: 16px;

  /* Shadows — extremely subtle */
  --shadow-card:  0 1px 2px rgba(0,0,0,0.04), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-float: 0 4px 16px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-modal: 0 20px 60px rgba(0,0,0,0.14), 0 4px 16px rgba(0,0,0,0.08);

  /* Transitions */
  --t-fast: 0.12s ease;
  --t-base: 0.18s ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: -apple-system, "SF Pro Text", "Helvetica Neue",
               "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; 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); border: 0;
}

/* ══════════════════════════════════════════════════════
   PAGE SHELL — Desktop two-column layout
   ══════════════════════════════════════════════════════ */

.page-shell {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  grid-template-areas: "left right";
  gap: 0;
  max-width: 1440px;
  min-height: calc(100vh - 48px);
  margin: 0 auto;
}

/* ── Top Header — fixed across all breakpoints ── */
.page-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  height: 48px;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Offset body content so fixed header doesn't overlap */
body { padding-top: 48px; }

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.header-pro-badge {
  display: inline-flex;
  align-items: center;
  height: 16px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--text-primary);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.header-chips {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  flex: 1;
  margin-left: 8px;
}

.header-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.header-chip-label {
  color: var(--text-tertiary);
  font-size: 10px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Left control panel ── */
.control-panel {
  grid-area: left;
  height: calc(100vh - 48px);
  position: sticky;
  top: 48px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 12px;
  padding-bottom: 72px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.control-panel::-webkit-scrollbar { width: 4px; }
.control-panel::-webkit-scrollbar-track { background: transparent; }
.control-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Right result panel ── */
.result-panel {
  grid-area: right;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 12px;
  background: var(--bg);
}

/* ══════════════════════════════════════════════════════
   SURFACE CARD — unified card style
   ══════════════════════════════════════════════════════ */

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

/* ══════════════════════════════════════════════════════
   COLLAPSIBLE SECTION (parameter groups)
   ══════════════════════════════════════════════════════ */

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

.param-section + .param-section {
  margin-top: 6px;
}

.param-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast);
}

.param-section-header:hover {
  background: var(--surface-raised);
}

.param-section.is-collapsed .param-section-header {
  /* no change — collapsed state visually same header */
}

.param-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.param-section-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--text-primary);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  flex-shrink: 0;
}

.param-section-chevron {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: transform var(--t-base);
  flex-shrink: 0;
}

.param-section-chevron svg {
  width: 12px;
  height: 12px;
}

.param-section.is-collapsed .param-section-chevron {
  transform: rotate(-90deg);
}

.param-section-body {
  padding: 0 12px 12px;
  display: grid;
  gap: 10px;
}

.param-section.is-collapsed .param-section-body {
  display: none;
}

.param-section-hint { font-size: 11px; color: var(--text-tertiary); margin: -2px 0 0; }
.param-section-hint.is-error { color: var(--danger); }

.platform-handoff {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  margin-bottom: 8px;
}

.platform-handoff-copy {
  min-width: 0;
}

.platform-handoff-copy strong {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
}

.platform-handoff-copy p {
  margin: 0;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.platform-handoff-actions {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ══════════════════════════════════════════════════════
   UPLOAD ZONE
   ══════════════════════════════════════════════════════ */

.upload-zone {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  width: 100%;
  padding: 10px 12px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-inset);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.upload-zone:hover {
  border-color: var(--border-focus);
  background: var(--surface-raised);
}

.upload-zone.is-dragover {
  border-color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-raised) 58%, white);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text-primary) 18%, transparent);
}

.upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  opacity: 0;
  pointer-events: none;
}

.upload-zone-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.upload-zone-label {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Thumb grid */
.thumb-grid {
  display: grid;
  width: 100%;
  min-width: 0;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  align-items: stretch;
}

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

.thumb-grid.single .thumb-card {
  height: clamp(168px, 22vw, 240px);
  min-height: clamp(168px, 22vw, 240px);
  aspect-ratio: auto;
}

.thumb-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
  aspect-ratio: 4/3;
}

.thumb-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.thumb-badge {
  position: absolute;
  left: 4px;
  bottom: 4px;
  max-width: calc(100% - 32px);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: 0;
  font-size: 10px;
  cursor: pointer;
  overflow: hidden;
}

.thumb-badge-token {
  flex: 0 0 auto;
  font-size: 9px;
  letter-spacing: 0.04em;
}

.thumb-badge-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 18px; height: 18px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
}

/* ══════════════════════════════════════════════════════
   FORM CONTROLS
   ══════════════════════════════════════════════════════ */

/* Row: label + control */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.setting-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
}

.setting-label small {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-tertiary);
  margin-top: 1px;
}

/* Chip grid (aspect ratio) */
.chip-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.chip, .segment {
  position: relative;
}

.chip input, .segment input {
  position: absolute;
  opacity: 0;
}

.chip span, .segment span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  text-align: center;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
}

.chip input:checked + span,
.segment input:checked + span {
  border-color: var(--accent);
  background: var(--accent-select);
  color: var(--text-primary);
}

/* Segment grid (size / mode) */
.segment-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

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

.size-segment-grid {
  grid-template-columns: repeat(3, 1fr);
  max-width: 130px;
}

/* Orientation preview */
.ratio-orientation-preview {
  display: flex;
  gap: 4px;
  align-items: center;
}

.orientation-card {
  width: 32px;
  height: 26px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-inset);
  display: grid;
  place-items: center;
  transition: border-color var(--t-fast), background var(--t-fast);
}

.orientation-card.active {
  border-color: var(--accent);
  background: var(--accent-select);
}

.orientation-shape {
  display: block;
  border: 1.5px solid var(--text-tertiary);
  border-radius: 3px;
}

.orientation-shape-landscape { width: 16px; height: 10px; }
.orientation-shape-portrait  { width: 10px; height: 16px; }

/* Toggle switch (iOS-style) */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
}

.toggle-row-text strong {
  display: block;
  font-size: 12px;
  font-weight: 600;
}

.toggle-row-text p {
  margin: 2px 0 0;
  font-size: 10px;
  color: var(--text-tertiary);
}

.switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background var(--t-base);
}

.slider::after {
  content: "";
  position: absolute;
  left: 2px; top: 2px;
  width: 18px; height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: transform var(--t-base);
}

.switch input:checked + .slider { background: #34c759; }
.switch input:checked + .slider::after { transform: translateX(18px); }

/* Textareas & selects */
textarea, .prompt-select, .auth-input, .modal-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color var(--t-fast);
}

textarea:focus, .prompt-select:focus, .auth-input:focus {
  outline: none;
  border-color: var(--border-focus);
}

textarea, .modal-textarea {
  padding: 8px 10px;
  resize: vertical;
  line-height: 1.5;
}

textarea { max-height: 180px; }

.prompt-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.prompt-select {
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.prompt-toolbar .prompt-select { flex: 1 1 160px; }

.prompt-import {
  position: relative;
  overflow: hidden;
}

.prompt-import input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.optimized-prompt-panel {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
  display: grid;
  gap: 8px;
}

.persona-toolbar { display: grid; gap: 4px; }
.persona-summary { font-size: 11px; color: var(--text-tertiary); margin: 0; }
.optimize-button { width: 100%; }

.inline-progress { min-height: 36px; }
.inline-status { margin-top: 0; font-size: 11px; }

/* ══════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════ */

.btn, .primary-button, .ghost-button, .danger-button {
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  min-height: 30px;
  padding: 5px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), opacity var(--t-fast);
}

/* Primary: dark fill */
.primary-button {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: #fff;
}

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

/* Ghost: light bordered */
.ghost-button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-secondary);
}

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

/* Danger: subtle red */
.danger-button {
  background: var(--danger-soft);
  border-color: #ffcdd2;
  color: var(--danger-text);
}

.danger-button:hover { background: #ffe4e1; }

.primary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.form-status {
  margin-top: 4px;
  font-size: 11px;
  min-height: 16px;
  color: var(--text-tertiary);
}

.mobile-submit-bar {
  display: none;
}

/* Submit button — sticky at panel bottom */
#submit-button,
#submit-button-mobile {
  position: fixed;
  left: max(12px, calc((100vw - 1440px) / 2 + 12px));
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(356px, calc(100vw - 24px));
  z-index: 30;
  min-height: 40px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-float);
}

/* ══════════════════════════════════════════════════════
   RESULT PANEL
   ══════════════════════════════════════════════════════ */

.preview-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.result-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px;
}

.meta-pill {
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--text-tertiary);
  border: 1px solid var(--border);
  padding: 2px 7px;
  font-size: 10px;
}

.result-stage {
  flex: 1;
  min-height: 300px;
  overflow: hidden;
  background: var(--surface-inset);
}

.result-stage.empty,
.result-stage.loading {
  display: grid;
  place-items: center;
  padding: 24px;
}

.placeholder { text-align: center; max-width: 280px; }

.placeholder-icon {
  width: 44px; height: 44px;
  margin: 0 auto 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
  font-size: 20px;
}

.placeholder h3 {
  margin: 0 0 5px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.placeholder p { margin: 0; font-size: 12px; color: var(--text-tertiary); }

.result-view { display: block; }

.result-image-shell {
  position: relative;
  background: var(--surface-inset);
}

.image-transfer-actions {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.image-transfer-button {
  min-height: 22px;
  padding: 2px 8px;
  border: 1px solid rgba(148,163,184,0.6);
  border-radius: var(--r-sm);
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(4px);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.image-transfer-button:hover { background: rgba(255,255,255,0.98); }
.image-transfer-button:disabled { opacity: 0.45; cursor: not-allowed; }

.result-image-original { display: block; width: 100%; height: auto; }

/* Result actions bar */
.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.result-actions p {
  font-size: 11px;
  overflow-wrap: anywhere;
  margin: 0;
  color: var(--text-tertiary);
  flex: 1;
  min-width: 0;
}

.result-action-buttons {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0;
}

/* ── Progress ── */
.progress-shell {
  width: min(320px, 90%);
  margin: 0 auto 12px;
}

.progress-track {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  width: 0; height: 100%;
  border-radius: inherit;
  background: var(--text-primary);
  transition: width 0.5s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.progress-label { color: var(--text-primary); font-weight: 600; }

/* ══════════════════════════════════════════════════════
   HISTORY — Gallery grid
   ══════════════════════════════════════════════════════ */

.history-card {
  flex-shrink: 0;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  margin-top: 8px;
  overflow: hidden;
}

.history-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.history-card-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.history-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Gallery grid — responsive 2-6 columns */
.history-gallery {
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 7px;
}

/* Gallery item card */
.history-gallery-item {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-raised);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.history-gallery-item:hover {
  border-color: var(--border-strong);
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

.history-gallery-thumb {
  position: relative;
  aspect-ratio: 4/3;
  background: var(--surface-inset);
  overflow: hidden;
}

.history-gallery-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}

.history-gallery-item:hover .history-gallery-thumb img {
  transform: scale(1.02);
}

/* Transfer buttons overlay on gallery thumb */
.history-gallery-thumb .image-transfer-actions {
  opacity: 0;
  transition: opacity var(--t-fast);
}

.history-gallery-item:hover .image-transfer-actions {
  opacity: 1;
}

.history-gallery-info {
  padding: 6px 8px;
}

.history-gallery-meta {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-gallery-tags {
  font-size: 9px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
}

.history-gallery-actions {
  display: flex;
  gap: 3px;
}

.history-gallery-actions .ghost-button,
.history-gallery-actions .danger-button {
  flex: 1;
  min-height: 22px;
  padding: 2px 4px;
  font-size: 9px;
  border-radius: var(--r-xs);
}

/* Empty state */
.empty-history {
  border: 1.5px dashed var(--border);
  border-radius: var(--r-lg);
  min-height: 80px;
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
  background: var(--surface-inset);
  padding: 16px;
  text-align: center;
  font-size: 12px;
  margin: 10px;
}

/* View all link */
.history-view-all {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-top: 1px solid var(--border);
}

.history-view-all a {
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: var(--r-sm);
  transition: background var(--t-fast);
}

.history-view-all a:hover {
  background: var(--surface-raised);
}

/* Pagination (kept for legacy, hidden in new gallery view) */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
}

.pagination-summary, .pagination-info {
  font-size: 11px;
  color: var(--text-tertiary);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination-controls .ghost-button {
  min-height: 26px;
  padding: 3px 8px;
  font-size: 11px;
}

/* ══════════════════════════════════════════════════════
   MOBILE TAB BAR — native app style
   ══════════════════════════════════════════════════════ */

.mobile-tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  background: rgba(249,249,251,0.94);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid rgba(0,0,0,0.08);
  /* safe area for notched phones */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-tabbar-inner {
  display: flex;
  height: 50px;
}

.mobile-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 4px 4px;
  position: relative;
  transition: color var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.01em;
}

.mobile-tab.is-active {
  color: var(--text-primary);
}

/* Icon container with pill highlight on active */
.mobile-tab-icon-wrap {
  position: relative;
  width: 48px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  transition: background var(--t-fast);
}

.mobile-tab.is-active .mobile-tab-icon-wrap {
  background: var(--accent-select);
}

.mobile-tab-icon {
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Mobile tab panels */
.mobile-panel {
  display: none;
}

/* ══════════════════════════════════════════════════════
   MODALS
   ══════════════════════════════════════════════════════ */

.modal-overlay, .auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.3);
  padding: 16px;
  backdrop-filter: blur(4px);
}

.modal-card, .auth-card {
  width: min(440px, 100%);
  border-radius: var(--r-2xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-modal);
  padding: 16px;
}

.modal-card-wide { width: min(920px, 100%); }

.modal-head, .modal-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.modal-head h2, .auth-card h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.modal-intro, .auth-card p {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.modal-intro.compact { font-size: 11px; }

.auth-input {
  height: 38px;
  padding: 0 10px;
  margin: 6px 0;
}

.modal-two-column {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 12px;
}

.modal-panel {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  padding: 12px;
  min-width: 0;
}

.modal-panel h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }

.modal-field { display: grid; gap: 4px; margin-bottom: 10px; }

.modal-field span { font-size: 11px; color: var(--text-secondary); font-weight: 600; }

.persona-editor-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.modal-input { margin: 0; height: 32px; padding: 0 8px; }

.modal-textarea { min-height: 130px; }

.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-top: 12px;
}

.modal-actions.split { justify-content: space-between; }

.modal-primary { width: auto; min-width: 100px; }

.persona-list {
  margin-top: 8px;
  display: grid;
  gap: 5px;
  max-height: 320px;
  overflow: auto;
}

.persona-item {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}

.persona-item.active {
  border-color: var(--accent);
  background: var(--accent-select);
}

.persona-item strong { display: block; font-size: 12px; margin-bottom: 2px; }
.persona-item span   { display: block; font-size: 11px; color: var(--text-tertiary); }

/* ══════════════════════════════════════════════════════
   HISTORY ALBUM PAGE
   ══════════════════════════════════════════════════════ */

.album-shell {
  max-width: 1440px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 12px;
}

.album-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.album-topbar h1  { margin: 0; font-size: 18px; font-weight: 700; }
.album-topbar p   { margin: 2px 0 0; font-size: 12px; color: var(--text-tertiary); }

.album-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.album-toolbar .primary-button,
.album-toolbar .ghost-button { width: auto; }

.album-selection-status { margin: 0 0 10px; font-size: 11px; color: var(--text-secondary); }

.album-shell .platform-handoff {
  margin-bottom: 10px;
}

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

.album-pagination { margin-top: 12px; }

.album-card {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  position: relative;
}

.album-select-toggle {
  position: absolute;
  top: 8px; left: 8px;
  z-index: 2;
  border-radius: 999px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  padding: 3px 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  cursor: pointer;
}

.album-select-toggle input {
  width: 13px; height: 13px;
  margin: 0;
  accent-color: var(--accent);
}

.album-image {
  width: 100%;
  height: 170px;
  object-fit: cover;
  display: block;
  background: var(--surface-inset);
}

.album-image-wrap { position: relative; }

.album-info { padding: 9px 10px; }

.album-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.album-prompt {
  margin: 5px 0 8px;
  font-size: 12px;
  color: var(--text-primary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.album-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.album-actions .ghost-button,
.album-actions .danger-button {
  min-height: 26px;
  padding: 2px 4px;
  font-size: 10px;
  border-radius: var(--r-xs);
}

/* ══════════════════════════════════════════════════════
   FOCUS RING
   ══════════════════════════════════════════════════════ */

textarea:focus-visible, input:focus-visible, select:focus-visible,
button:focus-visible, .ghost-button:focus-visible,
.danger-button:focus-visible, .primary-button:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 1px;
}

/* ══════════════════════════════════════════════════════
   DIVIDER
   ══════════════════════════════════════════════════════ */

.compact-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

/* ══════════════════════════════════════════════════════
   COMPATIBILITY — classes used in history.html
   ══════════════════════════════════════════════════════ */

.eyebrow {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.brand-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}


/* ══════════════════════════════════════════════════════
   RESPONSIVE — Tablet (768–1100px): two-column, narrower left
   ══════════════════════════════════════════════════════ */

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

  .result-panel { flex-direction: column; }

  #submit-button,
  #submit-button-mobile {
    left: 0;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 300px;
  }
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE — Mobile (<768px): three-tab layout
   ══════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  body { padding-top: 48px; } /* header already fixed globally */

  .page-shell {
    display: block;
    min-height: auto;
    /* room for fixed header + tab bar */
    padding-bottom: calc(50px + env(safe-area-inset-bottom, 0px));
  }

  .page-header {
    padding: 0 12px;
  }

  .header-chips { display: none; }

  /* Show mobile tab bar */
  .mobile-tabbar { display: flex; }

  /* Hide desktop layout elements */
  .control-panel,
  .result-panel { display: none; }

  /* Show mobile panels */
  .mobile-panel { display: block; }

  .mobile-panel-params,
  .mobile-panel-result,
  .mobile-panel-history {
    display: none;
    padding: 10px;
    padding-bottom: calc(50px + env(safe-area-inset-bottom, 0px) + 112px);
    min-height: calc(100vh - 48px - 50px);
  }

  .mobile-panel-params.is-active,
  .mobile-panel-result.is-active,
  .mobile-panel-history.is-active {
    display: block;
  }

  .mobile-panel-params .param-section + .param-section { margin-top: 6px; }

  .platform-handoff {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .platform-handoff-actions {
    justify-content: stretch;
  }

  .platform-handoff-actions .ghost-button,
  .platform-handoff-actions .primary-button {
    flex: 1 1 140px;
  }

  #submit-button {
    display: none;
  }

  .mobile-submit-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(50px + env(safe-area-inset-bottom, 0px));
    z-index: 34;
    display: grid;
    gap: 6px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 94%, white 6%);
    backdrop-filter: blur(12px);
    box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.08);
  }

  .mobile-submit-bar .form-status {
    margin: 0;
    min-height: 16px;
    padding: 0 2px;
    text-align: left;
  }

  #submit-button-mobile {
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
    width: 100%;
    min-height: 46px;
    border-radius: var(--r-md);
    box-shadow: var(--shadow-float);
    font-size: 14px;
  }

  /* Result panel mobile */
  .mobile-panel-result .preview-card {
    min-height: 55vw;
  }

  .result-action-buttons {
    justify-content: stretch;
  }

  .result-action-buttons .ghost-button,
  .result-action-buttons .danger-button {
    flex: 1;
    min-height: 36px;
  }

  /* History mobile — 2 column gallery */
  .mobile-panel-history .history-gallery {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Misc */
  .album-shell { padding: 8px; }
  #aspect-ratio-group { grid-template-columns: repeat(4, 1fr); }
  .thumb-grid { grid-template-columns: repeat(2, 1fr); }
  .prompt-toolbar { flex-direction: column; align-items: stretch; }
  .modal-two-column { grid-template-columns: 1fr; }
  .album-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 420px) {
  .album-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ── 生成到成功为止 ─────────────────────────────── */
.retry-until-success-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.retry-checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary, #555);
  cursor: pointer;
  user-select: none;
}

.retry-checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent, #ff6b35);
  cursor: pointer;
  flex-shrink: 0;
}

.retry-counter {
  font-size: 12px;
  color: var(--text-secondary, #888);
  background: var(--surface-2, #f3f3f3);
  border: 1px solid var(--border, #ddd);
  border-radius: 20px;
  padding: 2px 10px;
  white-space: nowrap;
  animation: retryPulse 1.2s ease-in-out infinite;
}

.retry-counter strong {
  color: var(--accent, #ff6b35);
  font-weight: 700;
}

@keyframes retryPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

.retry-until-success-row--mobile {
  padding: 0 4px 6px;
  justify-content: center;
}
