/* ═══════════════════════════════════════════════════════
   VISIGEN — AI Image Generator
   mahdi.dev  |  Brand: #29ff03 / #0a0a0f
═══════════════════════════════════════════════════════ */

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

:root {
  --accent:        #29ff03;
  --accent-dim:    rgba(41, 255, 3, 0.12);
  --accent-glow:   rgba(41, 255, 3, 0.25);
  --bg:            #0a0a0f;
  --surface:       #111118;
  --surface-2:     #17171f;
  --surface-3:     #1e1e28;
  --border:        #1e1e2e;
  --border-light:  #2a2a3a;
  --text:          #f0f0f0;
  --text-muted:    #666680;
  --text-dim:      #888898;
  --danger:        #ff4455;
  --danger-dim:    rgba(255, 68, 85, 0.12);
  --sidebar-w:     340px;
  --radius-sm:     6px;
  --radius:        10px;
  --radius-lg:     16px;
  --radius-xl:     22px;
  --font-brand:    'Bebas Neue', sans-serif;
  --font-mono:     'Space Mono', monospace;
  --font-ui:       'Outfit', sans-serif;
  --transition:    0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Layout ── */
body { display: flex; height: 100vh; overflow: hidden; }

/* ════════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  flex-shrink: 0;
  transition: transform var(--transition);
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 24px 0;
  gap: 0;
}

/* ── Brand ── */
.brand {
  padding: 26px 24px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-logo {
  font-family: var(--font-brand);
  font-size: 28px;
  letter-spacing: 3px;
  color: var(--accent);
  line-height: 1;
}

.brand-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border-light);
}

.brand-sub {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Panels ── */
.panel {
  padding: 20px 24px 4px;
  border-bottom: 1px solid var(--border);
}

.panel-header {
  margin-bottom: 16px;
}

.panel-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--accent);
  text-transform: uppercase;
}

/* ── Fields ── */
.field-group {
  margin-bottom: 16px;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.get-key-link {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.5px;
  opacity: 0.8;
  transition: opacity var(--transition);
}
.get-key-link:hover { opacity: 1; }

.optional-tag {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

/* Inputs */
.text-input,
.textarea-input,
.select-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  appearance: none;
}
.text-input { padding: 10px 38px 10px 12px; }
.textarea-input { padding: 10px 12px; resize: vertical; line-height: 1.5; }
.textarea-sm { min-height: 64px; }
.select-input { padding: 10px 32px 10px 12px; cursor: pointer; }

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

.text-input::placeholder,
.textarea-input::placeholder { color: var(--text-muted); font-size: 13px; }

/* Key input wrapper */
.key-input-wrap { position: relative; }
.eye-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  transition: color var(--transition);
  display: flex;
  align-items: center;
}
.eye-btn:hover { color: var(--accent); }
.eye-btn svg { width: 16px; height: 16px; }

.field-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

/* Select wrapper */
.select-wrap { position: relative; }
.select-arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  stroke: var(--text-muted);
  pointer-events: none;
}

/* ── Style Chips ── */
.style-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
  padding: 5px 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Size Grid ── */
.size-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.size-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  padding: 10px 4px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
}
.size-btn:hover { border-color: var(--accent); color: var(--accent); }
.size-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.size-icon {
  display: block;
  background: currentColor;
  opacity: 0.4;
  border-radius: 1px;
}
.size-square   { width: 16px; height: 16px; }
.size-portrait { width: 12px; height: 16px; }
.size-landscape { width: 20px; height: 14px; }
.size-wide     { width: 24px; height: 13px; }

/* ── Sliders ── */
.range-input {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border-light);
  outline: none;
  cursor: pointer;
}
.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  cursor: pointer;
  transition: box-shadow var(--transition);
}
.range-input::-webkit-slider-thumb:hover {
  box-shadow: 0 0 12px var(--accent-glow);
}

.slider-val {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(41,255,3,0.2);
}

/* ── Generate Button ── */
.generate-area {
  padding: 20px 24px 8px;
  margin-top: auto;
  flex-shrink: 0;
}

.generate-btn {
  position: relative;
  width: 100%;
  background: var(--accent);
  color: #0a0a0f;
  font-family: var(--font-brand);
  font-size: 22px;
  letter-spacing: 3px;
  border: none;
  border-radius: var(--radius);
  padding: 14px 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  transition: transform 0.1s, box-shadow var(--transition);
}

.generate-btn:hover {
  box-shadow: 0 0 28px var(--accent-glow), 0 0 60px rgba(41,255,3,0.1);
  transform: translateY(-1px);
}
.generate-btn:active { transform: translateY(0); }
.generate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.generate-btn-shortcut {
  font-family: var(--font-mono);
  font-size: 10px;
  opacity: 0.6;
  letter-spacing: 1px;
}

.btn-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255,255,255,0.18) 50%, transparent 60%);
  background-size: 200% 100%;
  background-position: 200% 0;
  transition: background-position 0.7s;
}
.generate-btn:hover .btn-shimmer {
  background-position: -200% 0;
}

/* ════════════════════════════════════════════
   WORKSPACE
════════════════════════════════════════════ */
.workspace {
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: 28px;
  gap: 24px;
}

/* Mobile header */
.mobile-header {
  display: none;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.menu-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px;
  cursor: pointer;
  display: flex;
}
.menu-btn svg { width: 18px; height: 18px; }

.mobile-brand {
  font-family: var(--font-brand);
  font-size: 22px;
  letter-spacing: 3px;
  color: var(--accent);
}

/* ── Canvas Area ── */
.canvas-area { display: flex; flex-direction: column; gap: 16px; }

.canvas-card {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: calc(100vh - 220px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
  height: 100%;
}

.empty-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  opacity: 0.06;
  position: absolute;
  inset: 0;
}
.empty-cell {
  background: linear-gradient(135deg, var(--accent), transparent);
}

.empty-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  position: relative;
}
.empty-text svg {
  width: 44px;
  height: 44px;
  stroke: var(--text-muted);
  opacity: 0.5;
}
.empty-text h2 {
  font-family: var(--font-brand);
  font-size: 28px;
  letter-spacing: 2px;
  color: var(--text);
  opacity: 0.5;
}
.empty-text p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Loading State ── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: 100%;
  height: 100%;
}

.loading-ring {
  position: relative;
  width: 60px;
  height: 60px;
}

.ring-segment {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  animation: spin 1.1s linear infinite;
}
.ring-segment:nth-child(2) {
  inset: 8px;
  border-top-color: rgba(41, 255, 3, 0.5);
  animation-duration: 0.85s;
  animation-direction: reverse;
}
.ring-segment:nth-child(3) {
  inset: 16px;
  border-top-color: rgba(41, 255, 3, 0.25);
  animation-duration: 1.4s;
}

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

.loading-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 1px;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

.loading-bar-wrap {
  width: 180px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.loading-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ── Error State ── */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 32px;
}
.error-state svg {
  width: 44px;
  height: 44px;
  stroke: var(--danger);
  opacity: 0.8;
}
.error-state h2 {
  font-family: var(--font-brand);
  font-size: 24px;
  letter-spacing: 2px;
  color: var(--danger);
}
.error-state p {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 340px;
  line-height: 1.6;
}

.retry-btn {
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 20px;
  cursor: pointer;
  margin-top: 4px;
  transition: all var(--transition);
}
.retry-btn:hover { background: rgba(255,68,85,0.2); }

/* ── Result State ── */
.result-state {
  width: 100%;
  height: 100%;
  position: relative;
}

.generated-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.image-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--transition);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
}
.result-state:hover .image-overlay { opacity: 1; }

.overlay-actions {
  display: flex;
  gap: 10px;
}

.overlay-btn {
  background: rgba(10, 10, 15, 0.85);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(8px);
  transition: all var(--transition);
}
.overlay-btn svg { width: 15px; height: 15px; }
.overlay-btn:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Prompt Recap ── */
.prompt-recap {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.recap-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}

.recap-text {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ── History Section ── */
.history-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
  transition: color var(--transition);
}
.clear-btn:hover { color: var(--danger); }

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

.history-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.history-item:hover {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  transform: scale(1.02);
}
.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.history-item-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.history-item:hover .history-item-overlay { opacity: 1; }
.history-item-overlay svg {
  width: 22px;
  height: 22px;
  stroke: var(--text);
}

/* ════════════════════════════════════════════
   LIGHTBOX
════════════════════════════════════════════ */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 10, 0.96);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  backdrop-filter: blur(12px);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.lightbox-close {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  z-index: 10000;
}
.lightbox-close:hover { border-color: var(--accent); color: var(--accent); }
.lightbox-close svg { width: 18px; height: 18px; }

.lightbox-img {
  max-width: 90vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 20px 80px rgba(0,0,0,0.8);
}

.lightbox-caption {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 600px;
  text-align: center;
  line-height: 1.5;
  padding: 0 20px;
}

/* ════════════════════════════════════════════
   TOAST
════════════════════════════════════════════ */
.toast-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10000;
  pointer-events: none;
}

.toast {
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-ui);
  padding: 10px 16px;
  min-width: 220px;
  max-width: 340px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: toastIn 0.25s ease;
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.success { border-left: 3px solid var(--accent); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid #4488ff; }

.toast-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.toast.success .toast-dot { background: var(--accent); }
.toast.error   .toast-dot { background: var(--danger); }
.toast.info    .toast-dot { background: #4488ff; }

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

/* ════════════════════════════════════════════
   MOBILE OVERLAY
════════════════════════════════════════════ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
  backdrop-filter: blur(2px);
}

/* ════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════ */
@media (max-width: 768px) {
  body { overflow: auto; }
  html, body { height: auto; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    z-index: 100;
    height: 100%;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 40px rgba(0,0,0,0.6);
  }

  .sidebar-overlay.visible { display: block; }

  .workspace {
    height: auto;
    min-height: 100vh;
    padding: 16px;
    overflow: visible;
  }

  .mobile-header { display: flex; }

  .canvas-card {
    aspect-ratio: auto;
    height: 60vw;
    min-height: 260px;
    max-height: none;
  }

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

@media (min-width: 1400px) {
  .canvas-card {
    max-height: calc(100vh - 180px);
  }
}
