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

:root {
  --bg: #0a0a0a;
  --bg-card: rgba(30,30,30,0.85);
  --bg-input: #1a1a1a;
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --accent-glow: rgba(99,102,241,0.15);
  --purple: #a855f7;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ============ Header ============ */
#header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(15,15,15,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.logo h1 {
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.3px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ============ Buttons ============ */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-xs);
  transition: all 0.2s;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}
.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost {
  background: none;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ghost:hover { color: #fff; border-color: var(--border-hover); }
.btn-ghost-sm {
  background: none;
  color: var(--text-muted);
  border: none;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ghost-sm:hover { color: #f87171; background: rgba(248,113,113,0.08); }
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xs);
  background: rgba(255,255,255,0.08);
  color: #fff;
  text-decoration: none;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
}
.btn-icon:hover { background: rgba(255,255,255,0.15); }

/* ============ Panels ============ */
.panel {
  max-width: 1400px;
  margin: 12px auto;
  padding: 0 24px;
}
.panel-inner {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  animation: slideDown 0.25s ease;
}
.panel-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 16px;
}
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* ============ Status Bar ============ */
.status-bar {
  max-width: 1400px;
  margin: 12px auto;
  padding: 0 24px;
}
.status-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  animation: slideDown 0.25s ease;
}
.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
.status-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
}
.status-detail {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}
.progress-track {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.05);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  border-radius: 2px;
  transition: width 0.5s ease;
  width: 0%;
}

/* ============ Main Layout ============ */
#mainArea {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

/* ============ Gallery ============ */
#gallery {
  columns: 3;
  column-gap: 12px;
  min-height: 200px;
}
.img-card {
  break-inside: avoid;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  cursor: pointer;
  background: rgba(30,30,30,0.6);
  border: 1px solid rgba(255,255,255,0.04);
  transition: transform 0.2s, box-shadow 0.2s;
}
.img-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.img-thumb {
  width: 100%;
  display: block;
  min-height: 120px;
  background: rgba(255,255,255,0.03);
}
.img-error {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.img-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 50%);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 12px;
  opacity: 0;
  transition: opacity 0.2s;
}
.img-card:hover .img-overlay { opacity: 1; }
.img-time {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
}
.img-btns {
  display: flex;
  gap: 6px;
}
.img-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}
.img-btn:hover { background: rgba(255,255,255,0.25); }

.empty-state {
  column-span: all;
  text-align: center;
  padding: 100px 20px;
}
.empty-icon {
  font-size: 56px;
  opacity: 0.25;
  margin-bottom: 16px;
}
.empty-title {
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 500;
}
.empty-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 6px;
}

/* ============ Sidebar ============ */
#sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 80px;
}
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* Mode Tabs */
.mode-tabs {
  display: flex;
  padding: 4px;
  gap: 4px;
}
.tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.tab.active {
  background: var(--accent);
  color: #fff;
}
.tab:not(.active):hover {
  color: #fff;
  background: rgba(255,255,255,0.05);
}

/* Fields */
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
textarea, input[type="text"], input[type="password"], select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  font-size: 13px;
  color: #fff;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea {
  resize: none;
  line-height: 1.6;
}
textarea::placeholder, input::placeholder {
  color: var(--text-muted);
}
select {
  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='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}
select option {
  background: #1a1a1a;
  color: #fff;
}

/* Size & Count Row */
.size-count-row {
  display: flex;
  gap: 12px;
}
.count-btns {
  display: flex;
  gap: 6px;
}
.count-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.count-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.count-btn:not(.active):hover {
  border-color: var(--border-hover);
  color: #fff;
}

/* Generate Button */
.gen-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-dark), #7c3aed);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}
.gen-btn:hover {
  background: linear-gradient(135deg, var(--accent), var(--purple));
  box-shadow: 0 0 30px rgba(99,102,241,0.25);
  transform: translateY(-1px);
}
.gen-btn:active {
  transform: translateY(0);
}
.gen-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
  transform: none;
}
.gen-btn.loading {
  animation: pulseGlow 2s ease-in-out infinite;
}

/* Drop Zone */
.drop-zone {
  border: 2px dashed rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: rgba(99,102,241,0.6);
  background: rgba(99,102,241,0.06);
}
.upload-icon {
  font-size: 28px;
  opacity: 0.35;
  margin-bottom: 8px;
}
.drop-zone p {
  font-size: 12px;
  color: var(--text-muted);
}
.preview-img {
  max-height: 120px;
  border-radius: var(--radius-xs);
  margin-bottom: 8px;
}
.btn-remove {
  background: none;
  border: none;
  color: #f87171;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}
.btn-remove:hover { background: rgba(248,113,113,0.1); }

/* ============ History ============ */
.history-compact { padding: 12px; }
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.history-list {
  max-height: 240px;
  overflow-y: auto;
}
.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 20px 0;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background 0.15s;
}
.history-item:hover {
  background: rgba(255,255,255,0.05);
}
.history-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(255,255,255,0.03);
}
.history-info {
  min-width: 0;
  flex: 1;
}
.history-prompt {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============ Slide Panel ============ */
.slide-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
}
.slide-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}
.slide-panel-content {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 400px;
  max-width: 90vw;
  background: #141414;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  animation: slideLeft 0.3s ease;
}
.slide-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.slide-panel-header h3 {
  font-size: 15px;
  font-weight: 600;
}
.slide-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-full-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.history-full-list .history-item {
  padding: 10px;
}
.history-full-list .history-thumb {
  width: 52px;
  height: 52px;
}

/* ============ Lightbox ============ */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.lightbox-content {
  position: relative;
  max-width: 85vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeInScale 0.25s ease;
}
.lightbox-img {
  max-width: 100%;
  max-height: 75vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  object-fit: contain;
}
.lightbox-info {
  width: 100%;
  max-width: 600px;
  margin-top: 16px;
  text-align: center;
}
.lightbox-prompt {
  font-size: 14px;
  color: rgba(255,255,255,0.8);
  line-height: 1.6;
  word-break: break-word;
  max-height: 80px;
  overflow-y: auto;
}
.lightbox-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}
.lightbox-time {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
}
.lightbox-actions {
  display: flex;
  gap: 8px;
}

/* ============ Animations ============ */
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideLeft {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(99,102,241,0); }
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(99,102,241,0.3); }
  50% { box-shadow: 0 0 25px rgba(99,102,241,0.5); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.shake { animation: shake 0.4s ease; }
.spinner { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Responsive ============ */
@media (max-width: 1100px) {
  #mainArea {
    grid-template-columns: 1fr;
  }
  #sidebar {
    position: static;
    order: -1;
  }
  #gallery {
    columns: 3;
  }
}
@media (max-width: 768px) {
  .header-inner { padding: 12px 16px; }
  .logo h1 { font-size: 15px; }
  #mainArea { padding: 12px 16px; }
  #gallery { columns: 2; column-gap: 8px; }
  .img-card { margin-bottom: 8px; }
  .config-grid { grid-template-columns: 1fr; }
  .size-count-row { flex-direction: column; gap: 10px; }
  .panel, .status-bar { padding: 0 16px; }
  .slide-panel-content { width: 100%; max-width: 100%; }
}
@media (max-width: 480px) {
  #gallery { columns: 2; }
  .empty-state { padding: 60px 16px; }
}
