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

:root {
  --bg:        #0f1117;
  --bg2:       #161b27;
  --bg3:       #1e2535;
  --border:    #2a3045;
  --border2:   #3a4460;
  --text:      #e2e8f0;
  --text2:     #94a3b8;
  --text3:     #64748b;
  --primary:   #6366f1;
  --primary-h: #4f52d6;
  --green:     #22c55e;
  --red:       #ef4444;
  --purple:    #a855f7;
  --yellow:    #eab308;
  --radius:    10px;
  --radius-lg: 16px;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
  --sidebar-w: 300px;
  --navbar-h:  60px;
}

html { font-size: 15px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =============================================
   NAVBAR
   ============================================= */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--navbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}
.navbar-brand:hover { text-decoration: none; }
.brand-icon { font-size: 1.3rem; }

.navbar-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.nav-user { color: var(--text2); font-size: .9rem; }

.nav-breadcrumb {
  color: var(--text2);
  font-size: .875rem;
}
.nav-breadcrumb a { color: var(--text2); }
.nav-breadcrumb a:hover { color: var(--text); }

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, opacity .15s;
  padding: 8px 16px;
  text-decoration: none;
  line-height: 1;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-h); }

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border2);
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); }

.btn-sm { padding: 5px 12px; font-size: .8rem; }

.btn-full { width: 100%; }

.btn-icon {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  cursor: pointer;
  padding: 7px 10px;
  font-size: .9rem;
  transition: background .15s;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--border); }

.btn-generate {
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 32px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .2s, transform .1s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn-generate:hover { opacity: .9; }
.btn-generate:active { transform: scale(.98); }
.btn-generate:disabled { opacity: .5; cursor: not-allowed; }

/* =============================================
   FORMS
   ============================================= */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
textarea,
.param-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, .param-input:focus {
  border-color: var(--primary);
}
input::placeholder, textarea::placeholder { color: var(--text3); }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.form-group label { font-weight: 600; font-size: .875rem; color: var(--text2); }

/* =============================================
   ALERTS
   ============================================= */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
}
.alert-error {
  background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .3);
  color: #fca5a5;
}
.alert-success {
  background: rgba(34, 197, 94, .12);
  border: 1px solid rgba(34, 197, 94, .3);
  color: #86efac;
}

/* =============================================
   BADGES
   ============================================= */
.badge {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 20px;
}
.badge-purple { background: rgba(168,85,247,.2); color: #c084fc; }
.badge-green  { background: rgba(34,197,94,.2);  color: #86efac; }
.badge-blue   { background: rgba(99,102,241,.2); color: #a5b4fc; }

/* =============================================
   AUTH PAGES
   ============================================= */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 60% 20%, rgba(99,102,241,.12) 0%, transparent 60%),
              var(--bg);
}

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

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow);
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 20px;
  text-decoration: none;
}
.brand-icon-lg { font-size: 1.6rem; }
.brand-name { font-size: 1.2rem; }

.auth-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.auth-header p { color: var(--text2); font-size: .9rem; }

.auth-form { margin-top: 4px; }

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: .875rem;
  color: var(--text2);
}

/* =============================================
   HOME PAGE
   ============================================= */
.home-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px;
}

.home-header {
  margin-bottom: 40px;
}
.home-header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.home-header p { color: var(--text2); font-size: 1.05rem; }

.gradient-text {
  background: linear-gradient(135deg, var(--primary), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.tool-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  color: var(--text);
  text-decoration: none;
  transition: border-color .2s, transform .15s, box-shadow .2s;
  cursor: pointer;
}
.tool-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(99,102,241,.15);
  text-decoration: none;
  color: var(--text);
}

.tool-card-placeholder {
  opacity: .4;
  cursor: default;
}
.tool-card-placeholder:hover {
  border-color: var(--border);
  transform: none;
  box-shadow: none;
}

.tool-card-icon {
  font-size: 2rem;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
  border-radius: 12px;
}

.tool-card-body { flex: 1; min-width: 0; }

.tool-card-title {
  font-weight: 700;
  font-size: .95rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.tool-card-desc {
  color: var(--text2);
  font-size: .825rem;
  line-height: 1.5;
}

.tool-card-arrow {
  color: var(--text3);
  font-size: 1.1rem;
  flex-shrink: 0;
}
.tool-card:hover .tool-card-arrow { color: var(--primary); }

/* =============================================
   TOOL PAGE LAYOUT
   ============================================= */
.tool-page { display: flex; flex-direction: column; }

.tool-layout {
  display: flex;
  height: calc(100vh - var(--navbar-h));
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.tool-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.sidebar-icon { font-size: 1.6rem; }
.sidebar-header h2 { font-size: 1rem; font-weight: 700; margin: 0; }
.sidebar-sub { font-size: .75rem; color: var(--text3); }

.sidebar-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: none; }

.param-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 8px;
}
.param-required { color: var(--red); margin-left: 2px; }
.param-optional { color: var(--text3); font-weight: 400; text-transform: none; letter-spacing: 0; }
.param-hint { font-size: .75rem; color: var(--text3); margin-top: 6px; }
.param-hint-inline { font-size: .78rem; color: var(--text3); font-weight: 400; text-transform: none; letter-spacing: 0; }

.api-key-row {
  display: flex;
  gap: 6px;
}
.api-key-row input { min-width: 0; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  color: var(--text2);
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] { accent-color: var(--primary); cursor: pointer; }

/* Ratio grid */
.ratio-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.ratio-btn {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text2);
  font-family: inherit;
  font-size: .75rem;
  font-weight: 600;
  padding: 6px 4px;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.ratio-btn:hover { border-color: var(--primary); color: var(--text); }
.ratio-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Quality grid */
.quality-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.quality-option {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.quality-option:hover { border-color: var(--primary); }
.quality-option.active { border-color: var(--primary); background: rgba(99,102,241,.1); }
.quality-name { display: block; font-weight: 700; font-size: .9rem; }
.quality-res { display: block; font-size: .72rem; color: var(--text2); margin-top: 2px; }

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.toggle-switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 20px;
  transition: .2s;
  cursor: pointer;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background: var(--text3);
  border-radius: 50%;
  transition: .2s;
}
.toggle-switch input:checked + .toggle-slider { background: rgba(99,102,241,.3); border-color: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); background: var(--primary); }
.toggle-label { font-size: .875rem; font-weight: 500; }

.sidebar-credits {
  margin-top: auto;
  padding-top: 12px;
  font-size: .78rem;
  color: var(--text3);
  text-align: center;
}

/* ===== MAIN AREA ===== */
.tool-main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Prompt */
.prompt-section { position: relative; }

.prompt-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  padding: 14px 16px;
  resize: vertical;
  min-height: 110px;
  outline: none;
  transition: border-color .15s;
  line-height: 1.6;
}
.prompt-input:focus { border-color: var(--primary); }
.prompt-counter {
  text-align: right;
  font-size: .75rem;
  color: var(--text3);
  margin-top: 4px;
}

/* Upload / Drop zone */
.upload-section {}

.drop-zone {
  background: var(--bg2);
  border: 2px dashed var(--border2);
  border-radius: var(--radius-lg);
  min-height: 160px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  overflow: hidden;
  position: relative;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(99,102,241,.04);
}

.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px;
  gap: 8px;
  text-align: center;
  color: var(--text2);
}
.drop-zone-content.hidden { display: none; }
.drop-icon { font-size: 2.5rem; }
.drop-zone-content p { font-size: .9rem; line-height: 1.6; }
.link { color: var(--primary); }

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

.preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg3);
  border: 1px solid var(--border);
}
.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,.7);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: .75rem;
  width: 22px;
  height: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  line-height: 1;
}
.preview-remove:hover { background: var(--red); }

.preview-add {
  aspect-ratio: 1;
  border: 2px dashed var(--border2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--text3);
  cursor: pointer;
  transition: all .15s;
  background: transparent;
}
.preview-add:hover { border-color: var(--primary); color: var(--primary); }

/* Generate section */
.generate-section { display: flex; flex-direction: column; gap: 12px; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result */
.result-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.result-header h3 { font-size: 1rem; font-weight: 700; }
.result-meta { font-size: .78rem; color: var(--text3); }

.progress-wrap { margin-bottom: 16px; }
.progress-bar {
  height: 6px;
  background: var(--bg3);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--purple));
  border-radius: 10px;
  transition: width .4s ease;
  width: 0%;
}
.progress-status { font-size: .82rem; color: var(--text2); }

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

.result-image-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg3);
  border: 1px solid var(--border);
}
.result-image-wrap img {
  width: 100%;
  display: block;
}
.result-image-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0,0,0,.7));
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity .2s;
}
.result-image-wrap:hover .result-image-actions { opacity: 1; }

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }

  .tool-layout { flex-direction: column; height: auto; overflow: visible; }
  .tool-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .tool-main { padding: 20px 16px; }

  .ratio-grid { grid-template-columns: repeat(4, 1fr); }
  .navbar { padding: 0 16px; }
  .nav-breadcrumb { display: none; }

  .home-container { padding: 32px 16px; }
  .home-header h1 { font-size: 1.5rem; }
}
