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

:root {
  --bg-dark: #0a0a0f;
  --bg-card: #12121a;
  --bg-elevated: #1a1a24;
  --bg-hover: #22222e;
  --border-color: #2a2a3a;
  --border-subtle: #1e1e28;
  --text-primary: #f0f0f5;
  --text-secondary: #9090a0;
  --text-muted: #606070;
  --accent: #3c6ffb;
  --accent-hover: #5080ff;
  --accent-glow: rgba(60, 111, 251, 0.25);
  --accent-light: #5ae0ff;
  --gradient: linear-gradient(135deg, #3c6ffb 0%, #5ae0ff 100%);
  --success: #34d399;
  --warning: #fbbf24;
  --error: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font: "Space Grotesk", system-ui, -apple-system, sans-serif;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* Typography */
h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; }

/* Forms */
input, textarea, select, button {
  font-family: inherit;
  font-size: 0.9375rem;
}

input, textarea, select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

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

label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.optional {
  color: var(--text-muted);
  font-weight: 400;
}

/* Buttons */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.primary {
  padding: 0.75rem 1.5rem;
  background: var(--gradient);
  color: white;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.secondary {
  padding: 0.625rem 1.25rem;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.icon-btn {
  padding: 0.5rem;
  background: transparent;
  color: var(--text-secondary);
}

.icon-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.full-width {
  width: 100%;
}

/* Utility */
.hidden {
  display: none !important;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 100px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.ready {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-dot.loading {
  background: var(--warning);
  animation: pulse 1.5s infinite;
}

.status-dot.error {
  background: var(--error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg-hover);
  border-radius: 4px;
  color: var(--text-secondary);
}

/* ========== AUTH PAGE ========== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: 
    radial-gradient(ellipse at 20% 0%, rgba(60, 111, 251, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(90, 224, 255, 0.06) 0%, transparent 50%),
    var(--bg-dark);
}

.auth-container {
  width: 100%;
  max-width: 420px;
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.logo {
  margin-bottom: 1rem;
}

.auth-header h1 {
  margin-bottom: 0.5rem;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-subtitle {
  color: var(--text-secondary);
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.auth-desc {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin-bottom: 1.25rem;
  text-align: center;
}

.auth-error {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid var(--error);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 0.875rem;
  text-align: center;
}

/* API Key Block */
.api-key-block {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.api-key-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.api-key-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-dark);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 0.5rem;
}

.api-key-row code {
  flex: 1;
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 0.8125rem;
  color: var(--accent-light);
  word-break: break-all;
}

.copy-btn {
  padding: 0.375rem;
  background: transparent;
  color: var(--text-secondary);
}

.copy-btn:hover {
  color: var(--accent-light);
  background: var(--bg-hover);
}

.api-key-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.auth-footer {
  margin-top: 1.5rem;
  text-align: center;
}

/* ========== DASHBOARD ========== */
.dashboard {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-name {
  font-size: 1.125rem;
  font-weight: 600;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-tabs {
  display: flex;
  gap: 0.25rem;
}

.nav-tab {
  padding: 0.625rem 1.25rem;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  border-radius: var(--radius-sm);
}

.nav-tab:hover:not(.active) {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.nav-tab.active {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* API Access panel */
.api-access {
  position: relative;
}

.api-access-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: 280px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  z-index: 200;
}

.api-access-header {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.api-access-panel .form-group {
  margin-bottom: 0.75rem;
}

.api-access-panel .api-key-block {
  margin-top: 1rem;
  padding-top: 1rem;
}

/* Sections */
.section {
  flex: 1;
  padding: 2rem;
}

.section-container {
  max-width: 900px;
  margin: 0 auto;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.section-header h2 {
  margin-bottom: 0.25rem;
}

.section-desc {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

/* Generate Form */
.generate-form {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
}

textarea#prompt {
  resize: vertical;
  min-height: 80px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.5rem;
}

.generate-btn {
  min-width: 180px;
}

.status-line {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.status-line.generating {
  color: var(--warning);
}

.status-line.success {
  color: var(--success);
}

.status-line.error {
  color: var(--error);
}

/* Recent Section */
.recent-section {
  margin-top: 2.5rem;
}

.recent-section h3 {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.recent-grid .gallery-item {
  aspect-ratio: 1;
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.gallery-item {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.gallery-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

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

.gallery-item .overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1rem;
}

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

.overlay .prompt-preview {
  font-size: 0.8125rem;
  color: white;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-secondary);
}

.empty-state svg {
  margin-bottom: 1rem;
  opacity: 0.4;
}

.empty-state h3 {
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

/* ========== MODAL ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  max-width: 900px;
  max-height: 90vh;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border-radius: 50%;
  z-index: 10;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.7);
}

#modal-image {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: var(--bg-dark);
}

.modal-info {
  padding: 1.25rem;
  border-top: 1px solid var(--border-color);
}

.modal-prompt {
  font-size: 0.9375rem;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.modal-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
}

.modal-actions a,
.modal-actions button {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  text-decoration: none;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.1);
}

/* Spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Responsive */
@media (max-width: 768px) {
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
  
  .form-row .form-group:last-child {
    grid-column: span 2;
  }
  
  .nav-tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    padding: 0.5rem;
    justify-content: center;
    z-index: 100;
  }
  
  .nav-tab {
    flex: 1;
    flex-direction: column;
    font-size: 0.75rem;
    gap: 0.25rem;
  }
  
  .dashboard-header {
    padding: 0.5rem 1rem;
  }
  
  .section {
    padding: 1.5rem;
    padding-bottom: 5rem;
  }
  
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .form-row {
    grid-template-columns: 1fr;
  }
  
  .form-row .form-group:last-child {
    grid-column: span 1;
  }
  
  .header-left .brand-name {
    display: none;
  }
}

/* Performance Toggle */
.perf-toggle-wrapper {
  display: flex;
  align-items: center;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.toggle-label input {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 100px;
  transition: all 0.3s;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all 0.3s;
}

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

.toggle-label input:checked + .toggle-slider::after {
  transform: translateX(20px);
  background: white;
}

.toggle-label input:disabled + .toggle-slider {
  opacity: 0.5;
}

#perf-label {
  min-width: 100px;
  text-align: right;
}

.toggle-hint {
  color: var(--text-muted);
}
