/* ============================================================
   多模型 AI 图像编辑前端 - 统一样式
   基于原三个前端（Seedream / GPT Image 2 / Nano Banana）合并
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242736;
  --bg-hover: #2a2d3a;
  --border: #2e3144;
  --border-focus: #6366f1;
  --text-primary: #e4e6f0;
  --text-secondary: #9498a8;
  --text-muted: #5c6072;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-lg: 0 25px 60px rgba(0, 0, 0, 0.5);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

/* ===== App Layout ===== */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 440px;
  min-width: 440px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 10;
}

.sidebar-header {
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-subtitle {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
  padding-left: 38px;
}

/* ===== Tab Bar ===== */
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.tab-btn {
  flex: 0 1 auto;
  min-width: 0;
  padding: 9px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color var(--transition), background var(--transition), color var(--transition), box-shadow var(--transition);
}

.tab-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.tab-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Form ===== */
.control-form {
  padding: 18px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.form-label svg {
  flex-shrink: 0;
}

.key-owner {
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.relay-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--warning);
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 12px;
}

/* Textarea */
textarea {
  width: 100%;
  min-height: 140px;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea::placeholder {
  color: var(--text-muted);
}

/* Input / Select */
input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input[type="text"]:focus,
input[type="password"]:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input[type="text"]::placeholder,
input[type="password"]::placeholder {
  color: var(--text-muted);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin-top: 4px;
}

.form-select {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239498a8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-select optgroup {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  font-style: normal;
}

.form-select option {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 8px;
}

/* 并排尺寸选择（Nano Banana 纵横比 + 分辨率） */
.google-size-row {
  display: flex;
  gap: 10px;
}

.google-size-row .form-select {
  flex: 1;
}

/* ===== API Key ===== */
.api-key-wrapper {
  display: flex;
  gap: 0;
}

.api-key-input {
  flex: 1;
  padding: 11px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.api-key-input:focus {
  border-color: var(--border-focus);
  box-shadow: -3px 0 0 0 var(--accent-glow);
}

.toggle-key-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.toggle-key-btn:hover {
  color: var(--text-primary);
}

.key-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.key-save-hint {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
}

.key-save-hint.saved {
  color: var(--success);
  opacity: 1;
}

.copy-key-btn {
  padding: 4px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.copy-key-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ===== Toggle Switch ===== */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-primary);
  border: 2px solid var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: var(--transition);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: #fff;
}

/* ===== Upload Zone ===== */
.upload-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  overflow: hidden;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-zone:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.04);
}

.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

.upload-zone.has-image {
  border-style: solid;
  border-color: var(--border);
  padding: 12px;
  cursor: default;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.upload-hint {
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.6;
}

.upload-zone.has-image .upload-placeholder {
  display: none;
}

.image-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  margin-left: auto;
}

.image-count-badge.hidden {
  display: none;
}

.image-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.image-gallery:empty {
  display: none;
}

.gallery-item {
  position: relative;
  width: calc(50% - 4px);
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: default;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-item-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-secondary);
}

.gallery-item .remove-item-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.75);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  transition: background var(--transition);
}

.gallery-item .remove-item-btn:hover {
  background: var(--danger);
}

.gallery-add-btn {
  width: calc(50% - 4px);
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}

.gallery-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(99, 102, 241, 0.04);
}

/* ===== Provider Panel ===== */
.provider-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-top: 1px dashed var(--border);
  padding-top: 16px;
}

.provider-panel.hidden {
  display: none;
}

/* ===== Buttons ===== */
.generate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  margin-top: auto;
}

.generate-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 25px var(--accent-glow);
}

.generate-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-stop {
  width: 100%;
  padding: 12px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
}

.btn-stop:hover {
  background: #dc2626;
}

/* ===== Status Message ===== */
.status-msg {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}

.status-msg.error {
  display: block;
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.status-msg.success {
  display: block;
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

/* ===== Preview Area ===== */
.preview-area {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 40px;
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 50% 50%, rgba(99, 102, 241, 0.03) 0%, transparent 70%),
    radial-gradient(circle at 20% 80%, rgba(99, 102, 241, 0.02) 0%, transparent 50%);
  overflow: auto;
}

.preview-result {
  width: 100%;
  max-width: 920px;
  animation: fadeIn 0.4s ease;
}

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

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.result-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.download-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.download-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

/* ===== Loading State ===== */
.loading-state {
  text-align: center;
  padding: 60px 20px;
}

.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 20px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-state p {
  color: var(--text-secondary);
  font-size: 15px;
}

.progress-text {
  margin-top: 8px;
  font-size: 13px !important;
  color: var(--text-muted) !important;
}

/* ===== Image Grid ===== */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.image-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  animation: fadeInUp 0.4s ease;
}

.image-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

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

.image-card img {
  width: 100%;
  display: block;
  object-fit: contain;
}

.image-card-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  gap: 8px;
}

.image-card-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-card-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-card {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}

.btn-card:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 15px;
  margin-bottom: 6px;
}

.empty-sub {
  font-size: 13px !important;
  opacity: 0.7;
}

/* ===== Usage Stats ===== */
.usage-stats {
  margin-top: 20px;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.usage-stats strong {
  color: var(--accent);
}

/* ===== Error Panel ===== */
.error-panel {
  margin-top: 16px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  overflow: hidden;
  animation: fadeIn 0.3s ease;
}

.error-panel.hidden {
  display: none;
}

.error-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: rgba(239, 68, 68, 0.12);
  border-bottom: 1px solid rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  font-size: 14px;
  font-weight: 600;
}

.error-detail {
  padding: 14px 16px;
  margin: 0;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
  background: transparent;
}

/* ===== Scrollbar ===== */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.preview-area::-webkit-scrollbar {
  width: 8px;
}

.preview-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ===== Responsive ===== */
@media (max-width: 960px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    max-height: 58vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .preview-area {
    padding: 20px;
  }

  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}
