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

:root {
  --bg: #f5f6f2;
  --card: #ffffff;
  --well: #eff0ea;
  --border: #dde1da;
  --border-dashed: #cbd0c6;
  --border-strong: #cbd0c6;
  --text: #161616;
  --muted: #6b7280;
  --text-faint: #9ca3af;
  --primary: #163064;
  --primary-fg: #ffffff;
  --accent: #163064;
  --accent-subtle: #e7ecf5;
  --secondary: #eff0ea;
  --secondary-fg: #161616;
  --gold: #c9a438;
  --gold-subtle: #f8f1dc;
  --gold-ink: #8a6f17;
  --danger: #dc2626;
  --success: #10b981;
  --warning: #d97706;
  --risk-low: #16a34a;
  --risk-mid: #d97706;
  --risk-high: #dc2626;
  --soft-blue: #dce7ff;
  --lvl-1: #86efac; --lvl-1-ink: #15803d;
  --lvl-2: #16a34a; --lvl-2-ink: #15803d;
  --lvl-3: #d97706; --lvl-3-ink: #b45309;
  --lvl-4: #dc2626; --lvl-4-ink: #b91c1c;
  --lvl-5: #991b1b; --lvl-5-ink: #991b1b;
  --shadow-soft: 0 1px 2px rgba(22,48,100,.04), 0 10px 30px rgba(22,48,100,.06);
  --shadow-md: 0 20px 56px rgba(22,48,100,.14);
  --radius: 12px;
  --radius-xl: 20px;
  --radius-2xl: 28px;
  --radius-hero: 36px;
  --radius-pill: 999px;
  --chart-grid: #dde1da;
  --font-sans: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'Roboto Mono', ui-monospace, 'SF Mono', monospace;
  font-family: var(--font-sans);
}

[data-theme="dark"] {
  --bg: #14171f;
  --card: #1b1f2a;
  --well: #20252f;
  --border: #2a2f3d;
  --border-dashed: #3a4152;
  --border-strong: #3a4152;
  --text: #f5f6f2;
  --muted: #9aa1ae;
  --text-faint: #767d8b;
  --primary: #4a6fb5;
  --primary-fg: #ffffff;
  --accent: #4a6fb5;
  --accent-subtle: #22304a;
  --secondary: #20252f;
  --secondary-fg: #f5f6f2;
  --gold: #c9a438;
  --gold-subtle: #2e2a1c;
  --gold-ink: #e0bf58;
  --danger: #f87171;
  --success: #34d399;
  --warning: #f59e0b;
  --risk-low: #16a34a;
  --risk-mid: #d97706;
  --risk-high: #dc2626;
  --lvl-1: #4ade80; --lvl-1-ink: #4ade80;
  --lvl-2: #16a34a; --lvl-2-ink: #22c55e;
  --lvl-3: #d97706; --lvl-3-ink: #f59e0b;
  --lvl-4: #dc2626; --lvl-4-ink: #f87171;
  --lvl-5: #7f1d1d; --lvl-5-ink: #fca5a5;
  --shadow-soft: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  --shadow-md: 0 20px 56px rgba(0,0,0,.5);
  --chart-grid: #2a2f3d;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Typography */
.font-display { font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.text-muted { color: var(--muted); }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.mono { font-family: var(--font-mono); }

/* 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; }
.items-start { align-items: flex-start; }
.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 32px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: var(--card);
  position: sticky; top: 0; z-index: 40;
}
.site-logo { display: flex; align-items: baseline; gap: 9px; margin-right: auto; text-decoration: none; }
.site-logo-mark { font-weight: 700; font-size: 20px; letter-spacing: -0.02em; color: var(--text); }
.site-logo-tag { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.14em; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: var(--radius-pill); font-size: 14.5px;
  font-weight: 500; line-height: 1.2; cursor: pointer; border: 1px solid transparent;
  background: transparent; color: var(--text);
  transition: background .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease;
  text-decoration: none; white-space: nowrap; font-family: var(--font-sans);
}
.btn svg { display: block; }
.btn-primary { background: var(--accent); color: var(--primary-fg); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); opacity: 1; text-decoration: none; }
.btn-primary:active { transform: none; filter: brightness(.94); }
.btn-outline { background: var(--card); color: var(--text); border-color: var(--border-strong); }
.btn-outline:hover { background: var(--well); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--muted); border: none; }
.btn-ghost:hover { background: var(--accent-subtle); color: var(--accent); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; text-decoration: none; }
.btn-gold { background: var(--gold); color: #161616; font-weight: 500; }
.btn-gold:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); text-decoration: none; }
.btn-lg { padding: 15px 28px; font-size: 16px; height: auto; }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-icon { padding: 8px; }
.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: transform .18s ease, box-shadow .18s ease; text-decoration: none; color: inherit; display: block; }
.card-hover:hover { box-shadow: var(--shadow-soft); transform: translateY(-2px); text-decoration: none; }
.card-dashed { border: 1px dashed var(--border-dashed); background: transparent; }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-xl); }
.plans-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(300px,1fr)); gap: 1.5rem; align-items: stretch; }
.forms-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(300px,1fr)); gap: 26px; }
.hero-grid { display: grid; grid-template-columns: minmax(0,1.08fr) minmax(0,.92fr); gap: 3rem; align-items: end; }
.hero-code-chip { position: absolute; right: -14px; bottom: -52px; width: 220px; }
.signin-grid { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.panel-hover { transition: transform .18s ease, box-shadow .18s ease; }
.panel-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-soft); }

/* Inputs */
.input, .textarea, .select {
  width: 100%; min-height: 44px; padding: 10px 14px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); font-size: 15px; background: var(--card);
  color: var(--text); outline: none; transition: border-color 0.15s, box-shadow 0.15s; font-family: var(--font-sans);
}
.input:hover, .textarea:hover, .select:hover { border-color: var(--text-faint); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle);
}
.input-lg { height: 3.2rem; font-size: 1.1rem; }
.input-mono { font-family: var(--font-mono); 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='%236b7280' stroke-width='1.5'%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: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 500; }
.badge-secondary { background: var(--accent-subtle); color: var(--accent); }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 4px 12px; border-radius: var(--radius-pill); white-space: nowrap; }
.tag-accent { background: var(--accent-subtle); color: var(--accent); }
.tag-gold { background: var(--gold-subtle); color: var(--gold-ink); }
.tag-outline { border: 1px solid var(--border-strong); color: var(--muted); }

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

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

/* Icon buttons (theme toggle etc.) */
.icon-circle-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  background: transparent; border: 1px solid var(--border); border-radius: 50%;
  color: var(--muted); cursor: pointer; padding: 0;
}
.icon-circle-btn:hover { background: var(--well); }

/* 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(--well); padding: 1.5rem 1.25rem; }
.answer-sidebar-item { width: 100%; text-align: left; border-radius: var(--radius); padding: 0.6rem 0.75rem; font-size: 0.875rem; display: flex; align-items: flex-start; gap: 0.6rem; cursor: pointer; background: none; border: none; color: var(--muted); transition: background 0.15s, color 0.15s; font-family: var(--font-sans); }
.answer-sidebar-item.active { background: var(--accent-subtle); color: var(--accent); }
.answer-sidebar-item.active .circle-border { border-color: var(--accent); color: var(--accent); }
.answer-sidebar-item:hover:not(.active) { background: rgba(22,48,100,0.06); }

/* 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(--accent); 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: var(--danger); }
@keyframes slide-in { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: translateY(0); } }

/* Choice option */
.choice-option { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 0.85rem 1.1rem; cursor: pointer; transition: border-color 0.15s, background 0.15s; text-align: left; background: var(--card); color: var(--text); width: 100%; font-size: 0.95rem; font-family: var(--font-sans); }
.choice-option:hover { background: var(--well); }
.choice-option.selected { border-color: var(--accent); background: var(--accent-subtle); color: var(--accent); font-weight: 500; }
.choice-option .choice-mark { width: 18px; height: 18px; flex: none; border-radius: 50%; border: 1.5px solid var(--border-strong); }
.choice-option.selected .choice-mark { border-color: var(--accent); background: var(--accent); position: relative; }
.choice-option.selected .choice-mark::after { content: ''; position: absolute; left: 5px; top: 2px; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }

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

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

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.tscroll { overflow-x: auto; }
.table th { text-align: left; font-size: 11.5px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 12px 10px; border-bottom: 1px solid var(--border-strong); }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--border); }
.table tbody tr:nth-child(even) { background: var(--well); }

/* Risk level chip (NOM-035) */
.risk-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 500; }
.risk-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.risk-badge[data-level="nulo"], .risk-badge[data-level="bajo"] { background: color-mix(in srgb, var(--lvl-2) 16%, transparent); color: var(--lvl-2-ink); }
.risk-badge[data-level="medio"] { background: color-mix(in srgb, var(--lvl-3) 16%, transparent); color: var(--lvl-3-ink); }
.risk-badge[data-level="alto"] { background: color-mix(in srgb, var(--lvl-4) 16%, transparent); color: var(--lvl-4-ink); }
.risk-badge[data-level="muy_alto"] { background: color-mix(in srgb, var(--lvl-5) 16%, transparent); color: var(--lvl-5-ink); }

/* Dialogs (share / rename / delete) */
.dialog-backdrop { position: fixed; inset: 0; display: grid; place-items: center; padding: 1rem; background: rgba(20,23,31,.55); z-index: 200; }
.dialog { width: min(480px,100%); display: flex; flex-direction: column; gap: 1rem; padding: 2rem; border-radius: var(--radius-2xl); background: var(--card); box-shadow: var(--shadow-md); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

/* Icon (svg) helper */
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* Entrance animation (landing hero) */
@keyframes fp-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.rise { animation: fp-rise .5s cubic-bezier(.22,.8,.3,1) both; }

/* 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; }
  .hero-grid { grid-template-columns: 1fr; gap: 2.5rem; }
  .hero-code-chip { position: static; width: auto; margin-top: 1rem; }
  .signin-grid { grid-template-columns: 1fr; min-height: auto; }
}
