:root {
  --bg: #0a0f1a;
  --bg-elev: #111827;
  --bg-card: #162033;
  --bg-hover: #1e293b;
  --border: #24324a;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.16);
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
a { color: #818cf8; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text);
  background: transparent;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); text-decoration: none; }
.btn-chatgpt { background: #10a37f; color: #fff; }
.btn-chatgpt:hover:not(:disabled) { background: #0d8a6a; text-decoration: none; }
.btn-secondary { background: var(--bg-hover); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #27354c; text-decoration: none; }
.btn-ghost { border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.btn-danger-ghost { color: #fca5a5; border-color: rgba(239, 68, 68, 0.32); }
.btn-danger-ghost:hover:not(:disabled) { background: rgba(239, 68, 68, 0.14); }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* Auth Screen */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #182341 0%, var(--bg) 62%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}
.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #a5b4fc;
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-sub { margin: 0 0 20px; color: var(--text-muted); font-size: 13.5px; }
.auth-footer { margin-top: 18px; text-align: center; color: var(--text-muted); }

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 12px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.divider span { padding: 0 10px; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.auth-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.auth-tab.active { background: var(--bg-hover); color: #fff; }

/* Form Controls */
.form-stack { display: flex; flex-direction: column; gap: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: #cbd5e1; }
input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* App Shell */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 276px;
  min-width: 256px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-top {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #10a37f);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #fff;
}
.brand-title { font-weight: 700; font-size: 14.5px; }
.brand-meta { font-size: 11.5px; color: var(--text-muted); }
.sidebar-section-label {
  padding: 12px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.session-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--accent-soft); border-color: rgba(99, 102, 241, 0.4); }
.session-item-title {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

.sidebar-bottom {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}
.status-dot.connected { background: var(--success); box-shadow: 0 0 8px rgba(16, 185, 129, 0.6); }
.status-dot.warn { background: var(--warn); }

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Main area */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar h2 { margin: 0; font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions, .composer-actions, .row-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-muted);
}

.banner-warn {
  background: rgba(245, 158, 11, 0.14);
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde68a;
  padding: 10px 22px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.workspace-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel h3 { margin: 0 0 3px; font-size: 15.5px; }
.muted { margin: 0; color: var(--text-muted); font-size: 12.5px; }

/* Dropzone */
.dropzone {
  border: 2px dashed #334155;
  border-radius: var(--radius);
  padding: 26px 20px;
  text-align: center;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.55);
  transition: all 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}
.dropzone-icon { font-size: 30px; margin-bottom: 6px; }
.dropzone-title { font-weight: 600; font-size: 14.5px; }
.dropzone-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

/* Guided Creative Brief Studio */
.brief-studio {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(11, 16, 28, 0.55);
  padding: 14px 16px;
}
.brief-studio-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brief-title { font-weight: 700; font-size: 14px; }
.brief-body {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brief-two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.brief-row { display: flex; flex-direction: column; gap: 7px; }
.brief-label { font-size: 12.5px; font-weight: 600; color: #cbd5e1; }
.pill-group { display: flex; flex-wrap: wrap; gap: 6px; }
.choice-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: #cbd5e1;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.14s;
}
.choice-pill:hover { border-color: var(--accent); color: #fff; }
.choice-pill.active {
  background: rgba(99, 102, 241, 0.24);
  border-color: var(--accent);
  color: #e0e7ff;
  font-weight: 600;
}

/* Draft Queue */
.draft-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.draft-card {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 14px;
  align-items: start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px;
}
.draft-thumb {
  width: 150px;
  height: 90px;
  border-radius: 7px;
  background: #000;
  object-fit: cover;
}
.draft-meta { font-weight: 600; font-size: 13.5px; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.draft-size { font-size: 11.5px; color: var(--text-muted); font-weight: 400; }
.draft-prompt-input { resize: vertical; min-height: 48px; font-size: 13px; }
.draft-actions { display: flex; flex-direction: column; gap: 6px; }

.draft-images-box {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px dashed #334155;
  background: rgba(10, 15, 26, 0.55);
}
.draft-images-box.dragover { border-color: var(--accent); background: rgba(99, 102, 241, 0.12); }
.draft-images-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.draft-images-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.draft-thumbs-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.prod-thumb-wrap {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}
.prod-thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prod-thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.prod-thumb-remove:hover { background: var(--danger); }

/* Job Results */
.jobs-list { display: flex; flex-direction: column; gap: 14px; }
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}
.job-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 15px;
}
.job-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.job-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.job-filename { font-weight: 700; font-size: 13.5px; }
.job-time { font-size: 11.5px; color: var(--text-muted); }
.job-img-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: #7dd3fc;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-queued { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }
.badge-processing { background: rgba(99, 102, 241, 0.22); color: #a5b4fc; }
.badge-completed { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.badge-failed { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

.job-brief-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.brief-tag {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.14);
  color: #c7d2fe;
}
.job-extra-note {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding: 7px 10px;
  background: rgba(10, 15, 26, 0.55);
  border-radius: 7px;
}
.job-stage { font-size: 13px; color: #a5b4fc; display: flex; align-items: center; gap: 8px; }
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(165, 180, 252, 0.3);
  border-top-color: #818cf8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.prompt-output-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  line-height: 1.65;
  color: #e2e8f0;
  max-height: 360px;
  overflow-y: auto;
}
.job-error-box {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.job-feedback-bar {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.feedback-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
}
.feedback-btn:hover { border-color: var(--accent); color: #fff; }
.feedback-btn.active-up { background: rgba(16, 185, 129, 0.2); border-color: var(--success); color: #6ee7b7; }
.feedback-btn.active-down { background: rgba(239, 68, 68, 0.18); border-color: var(--danger); color: #fca5a5; }

.refine-drawer {
  margin-top: 10px;
  padding: 12px;
  border-radius: 9px;
  background: rgba(10, 15, 26, 0.65);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1000;
}
.modal-card {
  width: 100%;
  max-width: 470px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.connect-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px;
}
.connect-box-title { font-weight: 700; font-size: 13.5px; margin-bottom: 4px; }
.connect-summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}
.connect-summary:hover { color: var(--text); }

/* Toast */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #1e293b;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  max-width: 340px;
}
.toast.success { border-color: rgba(16, 185, 129, 0.55); }
.toast.error { border-color: rgba(239, 68, 68, 0.6); color: #fecaca; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .draft-card { grid-template-columns: 1fr; }
  .draft-thumb { width: 100%; height: 150px; }
}
