@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --bg: #0c0f14;
  --bg-raised: #12161e;
  --bg-card: rgba(20, 25, 35, 0.85);
  --bg-card-hover: rgba(28, 35, 50, 0.92);
  --bg-input: rgba(255, 255, 255, 0.05);
  --bg-input-focus: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(99, 102, 241, 0.35);
  --ink: #f0f2f5;
  --ink-secondary: #94a3b8;
  --ink-muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --accent-glow: rgba(99, 102, 241, 0.25);
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, 0.12);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.12);
  --rose: #f43f5e;
  --rose-soft: rgba(244, 63, 94, 0.12);
  --cyan: #06b6d4;
  --cyan-soft: rgba(6, 182, 212, 0.12);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --radius-pill: 999px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15);
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
  --select-popup-bg: #12161e;
  --select-popup-ink: #f0f2f5;
  --select-popup-muted: #94a3b8;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(99, 102, 241, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 80% 10%, rgba(16, 185, 129, 0.05), transparent),
    radial-gradient(ellipse 50% 50% at 50% 100%, rgba(99, 102, 241, 0.04), transparent);
  z-index: 0;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
select { color-scheme: dark; }

h1, h2, h3, h4 {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  letter-spacing: -0.02em;
  color: var(--ink);
}

p { margin: 0; color: var(--ink-secondary); line-height: 1.6; }

.app-body { position: relative; z-index: 1; }

/* ────── Layout ────── */
.page-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.page-back-row { margin-bottom: 16px; }
.page-back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--ink-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  transition: all var(--transition);
}
.page-back-link:hover {
  color: var(--accent-hover);
  border-color: var(--border-accent);
  background: var(--accent-soft);
}
.page-back-icon {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.9rem;
}

/* ────── Glass Cards ────── */
.glass-card,
.workspace-panel,
.hero-panel,
.sidebar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}
.hero-panel,
.workspace-panel,
.sidebar-card { padding: 28px; }

/* ────── Topbar ────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 15, 20, 0.85);
  backdrop-filter: blur(20px) saturate(1.2);
}

.topbar-left, .topbar-right {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0;
}
.topbar-right { justify-content: flex-end; }

.app-logo {
  display: inline-flex; align-items: center; gap: 12px; min-width: 0;
}
.logo-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.logo-icon {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  filter: drop-shadow(0 10px 22px rgba(15, 23, 42, 0.35));
  flex-shrink: 0;
}
.logo-mark {
  width: 100%;
  height: 100%;
  overflow: visible;
}
.logo-mark-frame,
.logo-mark-sync,
.logo-mark-arrow,
.logo-mark-v {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.logo-mark-frame {
  fill: rgba(15, 23, 42, 0.94);
  stroke: rgba(148, 163, 184, 0.18);
  stroke-width: 1.5;
}
.logo-mark-sync {
  stroke: #8b5cf6;
  stroke-width: 4.2;
}
.logo-mark-arrow {
  stroke: #67e8f9;
  stroke-width: 3.4;
}
.logo-mark-v {
  stroke: #34d399;
  stroke-width: 4.6;
}
.logo-wordmark {
  display: block;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.app-logo small, .identity-chip small {
  display: block; color: var(--ink-muted); font-size: 0.75rem;
}

.identity-chip {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 6px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  min-width: 0; max-width: min(100%, 400px);
}
.identity-chip > div { min-width: 0; }
.identity-chip strong,
.identity-chip small,
.app-logo small,
.logo-wordmark {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-logo:hover .logo-mark-frame {
  fill: rgba(15, 23, 42, 0.98);
  stroke: rgba(103, 232, 249, 0.26);
}
.app-logo:hover .logo-mark-sync {
  stroke: #a78bfa;
}
.app-logo:hover .logo-mark-arrow {
  stroke: #a5f3fc;
}
.app-logo:hover .logo-mark-v {
  stroke: #6ee7b7;
}

.topbar-credit-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(16, 185, 129, 0.24);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(5, 150, 105, 0.24));
  color: #6ee7b7;
  font-size: 0.84rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.14);
}

.user-avatar {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: #fff; font-weight: 700; font-size: 0.8rem;
}

/* ────── Buttons ────── */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 600; font-size: 0.88rem;
  transition: all var(--transition);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.4);
  background: linear-gradient(135deg, var(--accent-hover), #8b5cf6);
}

.btn-outline {
  color: var(--ink-secondary);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-strong);
}
.btn-outline:hover {
  color: var(--ink);
  border-color: var(--border-accent);
  background: var(--accent-soft);
}

.btn-danger {
  color: var(--rose);
  background: var(--rose-soft);
  border-color: rgba(244, 63, 94, 0.2);
}
.btn-danger:hover {
  background: rgba(244, 63, 94, 0.18);
  box-shadow: 0 4px 16px rgba(244, 63, 94, 0.15);
}

.btn-success {
  color: #fff;
  background: linear-gradient(135deg, var(--emerald), #059669);
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.25);
}

.btn-warning {
  color: #000;
  background: linear-gradient(135deg, var(--amber), #d97706);
}

.btn-sm { min-height: 34px; padding: 0 12px; font-size: 0.82rem; }
.btn-lg { min-height: 48px; padding: 0 24px; font-size: 0.95rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.w-full { width: 100%; }

/* ────── Forms ────── */
.form-group {
  display: grid; gap: 6px; margin-bottom: 16px;
}
label {
  color: var(--ink-secondary); font-size: 0.84rem; font-weight: 600;
}
.form-control, .editor-textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--ink);
  outline: none;
  transition: all var(--transition);
}
.form-control:focus, .editor-textarea:focus {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-input-focus);
}
.form-control::placeholder, .editor-textarea::placeholder {
  color: var(--ink-muted);
}
.text-area { min-height: 160px; resize: vertical; }

select.form-control {
  color: var(--ink);
  background-color: var(--bg-input);
  color-scheme: dark;
}

select option,
select optgroup {
  color: var(--select-popup-ink);
  background-color: var(--select-popup-bg);
}

select option[value=""],
select option:disabled {
  color: var(--select-popup-muted);
}

/* ────── Badges ────── */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 26px; padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem; font-weight: 700;
  letter-spacing: 0.02em;
}
.badge-neutral { color: var(--ink-secondary); background: rgba(255, 255, 255, 0.06); }
.badge-success { color: var(--emerald); background: var(--emerald-soft); }
.badge-warning { color: var(--amber); background: var(--amber-soft); }
.badge-danger { color: var(--rose); background: var(--rose-soft); }
.badge-indigo { color: var(--accent-hover); background: var(--accent-soft); }

/* ────── Eyebrow ────── */
.eyebrow {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.12em; font-weight: 700;
  color: var(--accent-hover);
}

/* ────── Hero Panel ────── */
.hero-panel {
  display: flex; justify-content: space-between;
  gap: 24px; align-items: flex-start;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.06), rgba(16, 185, 129, 0.03));
}
.hero-copy { max-width: 680px; }
.hero-copy h1 {
  margin-top: 10px;
  font-size: clamp(1.6rem, 3.5vw, 2.5rem);
  line-height: 1.1;
  background: linear-gradient(135deg, var(--ink), var(--ink-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-copy p { margin-top: 12px; max-width: 600px; font-size: 0.95rem; }

.hero-actions, .stack-actions, .candidate-tags {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.hero-actions { justify-content: flex-end; }

.hero-note {
  min-width: 220px; display: grid; gap: 8px;
}
.hero-note p { margin-top: 6px; }

/* ────── Section Blocks ────── */
.section-block { display: grid; gap: 16px; }
.section-block, .workspace-panel { margin-top: 20px; }

.section-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.section-head h2 { margin-top: 6px; font-size: 1.3rem; }
.workspace-panel h2, .sidebar-card h2, .hero-note p { margin-top: 6px; }

/* ────── Metrics ────── */
.metric-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px;
}
.metric-card {
  padding: 20px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}
.metric-card:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-glow);
}
.metric-card strong {
  display: block; margin-top: 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2rem;
  background: linear-gradient(135deg, var(--accent-hover), var(--emerald));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.metric-label {
  font-size: 0.78rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-muted); font-weight: 700;
}

/* ────── Empty State ────── */
.empty-state {
  padding: 28px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  display: grid; gap: 12px; justify-items: flex-start;
}
.empty-state.compact { padding: 20px; }

/* ────── Checkpoint List ────── */
.checkpoint-list {
  list-style: none; display: grid; gap: 10px; margin: 14px 0 0; padding: 0;
}
.checkpoint-list li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}
.checkpoint-list li:first-child { border-top: none; padding-top: 0; }
.checkpoint-list li span { color: var(--ink-secondary); }
.checkpoint-list li strong { color: var(--ink); }

.muted-copy { color: var(--ink-muted); line-height: 1.7; }

/* ────── Form Messages ────── */
.form-error, .form-success {
  border-radius: 12px; padding: 12px 14px;
  margin-bottom: 14px; font-size: 0.88rem; font-weight: 600;
}
.form-error {
  color: var(--rose); background: var(--rose-soft);
  border: 1px solid rgba(244, 63, 94, 0.18);
}
.form-success {
  color: var(--emerald); background: var(--emerald-soft);
  border: 1px solid rgba(16, 185, 129, 0.18);
}

/* ────── Toasts ────── */
#toast-container {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  display: grid; gap: 8px;
}
.toast {
  min-width: 240px; padding: 12px 16px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow);
  color: var(--ink);
  backdrop-filter: blur(12px);
  animation: toast-in 0.3s ease;
}
.toast.success { border-color: rgba(16, 185, 129, 0.3); }
.toast.error { border-color: rgba(244, 63, 94, 0.3); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ────── Spinners ────── */
.spinner, .spinner-sm {
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner { width: 36px; height: 36px; }
.spinner-sm { width: 16px; height: 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ────── Form Grids ────── */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

@media (max-width: 640px) {
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
}

/* ────── Responsive ────── */
@media (max-width: 960px) {
  .topbar {
    padding: 12px 16px; align-items: flex-start; flex-direction: column;
  }
  .page-shell { width: min(100% - 20px, 1200px); padding-top: 20px; }
  .hero-panel, .section-head { flex-direction: column; }
  .identity-chip { width: 100%; max-width: none; }
}

@media (max-width: 640px) {
  .page-shell { width: min(100% - 16px, 1200px); }
  .hero-panel, .workspace-panel, .sidebar-card { padding: 18px; }
  .btn, .btn-lg { width: 100%; }
  .topbar-right { width: 100%; }
}
