/* CSS Reset & Variables */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: rgba(30, 41, 59, 0.7);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --success: #10b981;
  --danger: #ef4444;
  --border-color: rgba(255, 255, 255, 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* Sidebar */
.sidebar {
  width: 340px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.brand {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
}

.logo-icon {
  font-size: 28px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 9999px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  font-weight: 600;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

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

.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.field-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Form Elements */
select, input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: var(--bg-primary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-2 label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: block;
}

/* Preset Chips */
.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.chip:hover {
  background: rgba(99, 102, 241, 0.2);
  color: var(--text-main);
}

.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Sliders */
.slider-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.value-display {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 4px rgba(0,0,0,0.4);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
}

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 2px 4px;
}

.text-btn:hover {
  text-decoration: underline;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
}

.secondary-btn {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-color: var(--danger);
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px;
  gap: 20px;
}

/* Prompt Header */
.prompt-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prompt-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.prompt-label {
  font-size: 0.78rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.prompt-icon.positive { color: var(--success); }
.prompt-icon.negative { color: var(--danger); }

textarea#positive-prompt {
  resize: vertical;
  min-height: 52px;
  font-size: 0.92rem;
  line-height: 1.4;
}

.prompt-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 6px;
}

.prompt-samples {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sample-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sample-btn {
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: 0.2s;
}

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

.primary-btn {
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45);
}

.primary-btn:active {
  transform: translateY(0);
}

/* Preview Section */
.preview-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.canvas-wrapper {
  position: relative;
  width: 512px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas#render-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.canvas-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
  background: radial-gradient(circle at center, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.95) 100%);
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.canvas-placeholder h3 {
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.canvas-placeholder p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Progress Overlay */
.progress-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.progress-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 70%;
  gap: 8px;
}

.progress-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: var(--accent-gradient);
  transition: width 0.15s ease-out;
}

.progress-step-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Canvas Toolbar */
.canvas-toolbar {
  width: 512px;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  font-size: 0.78rem;
}

.meta-info {
  color: var(--text-muted);
}

.toolbar-buttons {
  display: flex;
  gap: 8px;
}

.tool-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  cursor: pointer;
  transition: 0.2s;
}

.tool-btn:hover {
  background: rgba(255,255,255,0.1);
}

.tool-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
}

.tool-btn.primary:hover {
  background: var(--accent-hover);
}

/* Gallery Section */
.gallery-section {
  margin-top: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
}

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

.gallery-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.gallery-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.gallery-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-color);
  cursor: pointer;
  background: #000;
  transition: transform 0.2s, box-shadow 0.2s;
}

.gallery-item:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

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

.gallery-item .item-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.gallery-item:hover .item-overlay {
  opacity: 1;
}

.item-action-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.7rem;
  cursor: pointer;
}

.item-action-btn:hover {
  background: var(--accent);
}

.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 30px;
}

/* Responsive */
@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
    height: auto;
  }
  .sidebar {
    width: 100%;
    height: auto;
  }
  .main-content {
    overflow-y: visible;
  }
}
