/* ── Formly Design System ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fafaf9;
  --card: #ffffff;
  --border: #e5e5e2;
  --border-dashed: #d0cfcb;
  --text: #18181b;
  --muted: #71717a;
  --primary: #18181b;
  --primary-fg: #fafaf9;
  --secondary: #f4f4f5;
  --secondary-fg: #3f3f46;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --shadow-soft: 0 2px 8px 0 rgba(0,0,0,0.07);
  --radius: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.25rem;
  --chart-grid: #e5e5e2;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  --bg: #111113;
  --card: #1c1c1f;
  --border: #2e2e32;
  --border-dashed: #3f3f46;
  --text: #fafaf9;
  --muted: #a1a1aa;
  --primary: #fafaf9;
  --primary-fg: #18181b;
  --secondary: #27272a;
  --secondary-fg: #d4d4d8;
  --danger: #f87171;
  --success: #34d399;
  --warning: #fbbf24;
  --shadow-soft: 0 2px 8px 0 rgba(0,0,0,0.5);
  --chart-grid: #2e2e32;
}

body { background: var(--bg); color: var(--text); min-height: 100vh; }

/* Typography */
.font-display { font-weight: 600; letter-spacing: -0.03em; }
.text-muted { color: var(--muted); }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.mono { font-family: 'SF Mono', 'Fira Code', monospace; }

/* Layout */
.container { max-width: 64rem; margin: 0 auto; padding: 0 1.5rem; }
.container-sm { max-width: 48rem; margin: 0 auto; padding: 0 1.5rem; }
.container-xs { max-width: 28rem; margin: 0 auto; padding: 0 1.5rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.place-center { display: grid; place-items: center; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.min-h-screen { min-height: 100vh; }
.text-center { text-align: center; }
.flex-wrap { flex-wrap: wrap; }

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}
.site-logo { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.03em; text-decoration: none; color: var(--text); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border-radius: var(--radius); font-size: 0.875rem;
  font-weight: 500; cursor: pointer; border: none; transition: all 0.15s;
  text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { opacity: 0.88; }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--secondary); }
.btn-ghost { background: transparent; color: var(--muted); border: none; }
.btn-ghost:hover { background: var(--secondary); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.88; }
.btn-lg { padding: 0.625rem 1.5rem; font-size: 1rem; height: 2.75rem; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-icon { padding: 0.5rem; }
.btn-w-full { width: 100%; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-xl); padding: 1.25rem; color: var(--text);
}
.card-2xl { border-radius: var(--radius-2xl); padding: 2rem; }
.card-hover { transition: box-shadow 0.15s, transform 0.15s; text-decoration: none; color: inherit; display: block; }
.card-hover:hover { box-shadow: var(--shadow-soft); transform: translateY(-1px); }
.card-dashed { border: 1px dashed var(--border-dashed); background: transparent; }

/* Inputs */
.input, .textarea, .select {
  width: 100%; padding: 0.55rem 0.75rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 0.9rem; background: var(--card);
  color: var(--text); outline: none; transition: border-color 0.15s; font-family: inherit;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--primary); }
.input-lg { height: 3rem; font-size: 1.1rem; }
.input-mono { font-family: 'SF Mono', 'Fira Code', monospace; letter-spacing: 0.2em; text-align: center; font-size: 1.2rem; }
.textarea { resize: vertical; min-height: 7rem; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2.5rem; }

/* Badges / Kickers */
.kicker { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.2em; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.7rem; font-weight: 500; }
.badge-secondary { background: var(--secondary); color: var(--secondary-fg); }

/* Progress */
.progress-bar { height: 4px; border-radius: 999px; background: var(--secondary); overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); transition: width 0.3s; }

/* Circle icon */
.circle-icon { width: 3rem; height: 3rem; border-radius: 50%; display: grid; place-items: center; }
.circle-sm { width: 1.5rem; height: 1.5rem; border-radius: 50%; display: grid; place-items: center; font-size: 0.7rem; }
.circle-icon-primary { background: var(--primary); color: var(--primary-fg); }
.circle-border { border: 1px solid var(--border); background: var(--card); }

/* Stepper */
.stepper { display: flex; align-items: center; gap: 0.75rem; }
.stepper-line { width: 2rem; height: 1px; background: var(--border); }

/* Sidebar layout for answering */
.answer-layout { display: grid; grid-template-columns: 260px 1fr; flex: 1; }
.answer-sidebar { border-right: 1px solid var(--border); background: var(--secondary); padding: 1.25rem; }
.answer-sidebar-item { width: 100%; text-align: left; border-radius: 0.5rem; padding: 0.5rem 0.75rem; font-size: 0.875rem; display: flex; align-items: flex-start; gap: 0.5rem; cursor: pointer; background: none; border: none; color: var(--muted); transition: background 0.1s; }
.answer-sidebar-item.active { background: var(--card); color: var(--text); box-shadow: var(--shadow-soft); }
.answer-sidebar-item:hover:not(.active) { background: rgba(128,128,128,0.12); }

/* Toast */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: var(--primary); color: var(--primary-fg); padding: 0.75rem 1.25rem; border-radius: var(--radius); font-size: 0.875rem; box-shadow: var(--shadow-soft); animation: slide-in 0.2s ease; }
.toast.error { background: #ef4444; }
@keyframes slide-in { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: translateY(0); } }

/* Choice option */
.choice-option { border: 1px solid var(--border); border-radius: 0.5rem; padding: 0.75rem 1rem; cursor: pointer; transition: all 0.1s; text-align: left; background: var(--card); color: var(--text); width: 100%; font-size: 0.9rem; }
.choice-option:hover { background: var(--secondary); }
.choice-option.selected { border-color: var(--primary); background: rgba(127,127,127,0.08); }

/* Path card (home page) */
.path-card { border: 1px solid var(--border); border-radius: var(--radius-2xl); padding: 2rem; background: var(--card); transition: box-shadow 0.15s, transform 0.15s; text-decoration: none; color: inherit; display: block; }
.path-card:hover { box-shadow: var(--shadow-soft); transform: translateY(-1px); }

/* Form builder question card */
.question-card { border: 1px solid var(--border); border-radius: var(--radius-xl); padding: 1.25rem; background: var(--card); }

/* Spacing helpers */
.mt-0\.5 { margin-top: 0.125rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }
.mt-10 { margin-top: 2.5rem; }
.mt-12 { margin-top: 3rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 1.25rem; }
.pt-6 { padding-top: 1.5rem; }
.py-6 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.py-12 { padding-top: 3rem; padding-bottom: 3rem; }
.py-20 { padding-top: 5rem; padding-bottom: 5rem; }
.px-6 { padding: 0 1.5rem; }
.p-5 { padding: 1.25rem; }
.p-8 { padding: 2rem; }
.p-10 { padding: 2.5rem; }
.p-12 { padding: 3rem; }
.space-y > * + * { margin-top: 0.75rem; }
.space-y-4 > * + * { margin-top: 1rem; }

/* Misc */
.border-t { border-top: 1px solid var(--border); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none; }
.italic { font-style: italic; }
.pre-wrap { white-space: pre-wrap; }
hr { border: none; border-top: 1px solid var(--border); }

@media (max-width: 768px) {
  .answer-layout { grid-template-columns: 1fr; }
  .answer-sidebar { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  h1.big { font-size: 2.5rem !important; }
}
