/*
 * Assessment Builder — design prototype. Shared tokens + component kit.
 * Layout concept: the Anaya dashboard shell (left nav, top bar) around one working surface per screen.
 * Tokens mirror apps/web/app/globals.css (bare HSL triplets, magenta primary 322 100% 36%).
 */
:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --surface: 240 5% 98.4%;          /* page ground behind cards */
  --card: 0 0% 100%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 42%;
  --border: 240 5.9% 90%;
  --border-strong: 240 5.9% 82%;
  --primary: 322 100% 36%;
  --primary-foreground: 0 0% 98%;
  --primary-soft: 322 60% 97%;
  --primary-soft-foreground: 322 100% 30%;
  --secondary: 190 67% 31%;
  --secondary-soft: 190 50% 95%;
  --ai: 262 70% 50%;                /* one AI colour across builder and fill */
  --ai-soft: 262 80% 97%;
  --ai-border: 262 60% 85%;
  --success: 152 60% 32%;
  --success-soft: 150 55% 95%;
  --warning: 32 95% 38%;
  --warning-soft: 40 95% 94%;
  --danger: 0 72% 46%;
  --danger-soft: 0 85% 96%;
  --ring: 322 100% 36%;
  --shadow: 240 10% 10%;
  --radius: 0.5rem;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: 240 10% 5.5%;
    --foreground: 0 0% 96%;
    --surface: 240 8% 8%;
    --card: 240 8% 10%;
    --muted: 240 5% 15%;
    --muted-foreground: 240 5% 66%;
    --border: 240 5% 19%;
    --border-strong: 240 5% 28%;
    --primary: 322 85% 62%;
    --primary-foreground: 240 10% 6%;
    --primary-soft: 322 40% 16%;
    --primary-soft-foreground: 322 90% 78%;
    --secondary: 190 60% 55%;
    --secondary-soft: 190 40% 14%;
    --ai: 262 85% 74%;
    --ai-soft: 262 35% 16%;
    --ai-border: 262 35% 34%;
    --success: 152 55% 55%;
    --success-soft: 152 35% 13%;
    --warning: 38 90% 60%;
    --warning-soft: 38 45% 13%;
    --danger: 0 80% 66%;
    --danger-soft: 0 45% 15%;
    --ring: 322 85% 62%;
    --shadow: 0 0% 0%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --background: 240 10% 5.5%;
  --foreground: 0 0% 96%;
  --surface: 240 8% 8%;
  --card: 240 8% 10%;
  --muted: 240 5% 15%;
  --muted-foreground: 240 5% 66%;
  --border: 240 5% 19%;
  --border-strong: 240 5% 28%;
  --primary: 322 85% 62%;
  --primary-foreground: 240 10% 6%;
  --primary-soft: 322 40% 16%;
  --primary-soft-foreground: 322 90% 78%;
  --secondary: 190 60% 55%;
  --secondary-soft: 190 40% 14%;
  --ai: 262 85% 74%;
  --ai-soft: 262 35% 16%;
  --ai-border: 262 35% 34%;
  --success: 152 55% 55%;
  --success-soft: 152 35% 13%;
  --warning: 38 90% 60%;
  --warning-soft: 38 45% 13%;
  --danger: 0 80% 66%;
  --danger-soft: 0 45% 15%;
  --ring: 322 85% 62%;
  --shadow: 0 0% 0%;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  background: hsl(var(--surface));
  color: hsl(var(--foreground));
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; border-radius: 4px; }
.tabular { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: hsl(var(--muted-foreground)); }
.mono { font-family: var(--font-mono); font-size: 12px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }

/* ── App shell ─────────────────────────────────────────── */
#app { height: 100%; }
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); height: 100%; }
.shell.nav-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.nav {
  background: hsl(var(--card));
  border-right: 1px solid hsl(var(--border));
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
.nav-brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; font-weight: 650; }
.nav-logo { width: 28px; height: 28px; border-radius: 8px; background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.nav-group { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: hsl(var(--muted-foreground)); padding: 8px 8px 4px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; border: 0; background: none;
  text-align: left; color: hsl(var(--foreground) / 0.85); font-size: 13.5px; width: 100%;
}
.nav-item:hover { background: hsl(var(--muted)); }
.nav-item[aria-current="page"] { background: hsl(var(--primary-soft)); color: hsl(var(--primary-soft-foreground)); font-weight: 600; }
.nav-item .badge { margin-left: auto; }
.nav-foot { margin-top: auto; padding: 12px; border-top: 1px solid hsl(var(--border)); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px; min-height: 56px;
  background: hsl(var(--card)); border-bottom: 1px solid hsl(var(--border)); flex-wrap: wrap;
}
.crumbs { display: flex; align-items: center; gap: 6px; color: hsl(var(--muted-foreground)); font-size: 13px; min-width: 0; flex-wrap: wrap; }
.crumbs b { color: hsl(var(--foreground)); font-weight: 600; }
.topbar-spacer { flex: 1; }
.proto-ribbon {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em;
  color: hsl(var(--warning)); background: hsl(var(--warning-soft)); border: 1px solid hsl(var(--warning) / 0.35);
  padding: 3px 8px; border-radius: 999px;
}
/* position: relative contains absolutely positioned descendants (e.g. .sr-only live regions);
   without it they resolve against the page and stretch the document past the viewport. */
.content { flex: 1; min-height: 0; overflow: auto; position: relative; }
.page { padding: 24px; max-width: 1240px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -0.01em; text-wrap: balance; }
.page-head p { margin: 0; color: hsl(var(--muted-foreground)); max-width: 68ch; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* Screen switcher (prototype only) */
.tourbar {
  display: flex; gap: 4px; padding: 6px 12px; overflow-x: auto; background: hsl(var(--muted)); border-bottom: 1px solid hsl(var(--border));
  scrollbar-width: thin;
}
.tourbar button {
  white-space: nowrap; border: 1px solid transparent; background: none; padding: 5px 10px; border-radius: 999px; font-size: 12.5px;
  color: hsl(var(--muted-foreground)); display: inline-flex; gap: 6px; align-items: center;
}
.tourbar button:hover { color: hsl(var(--foreground)); }
.tourbar button[aria-current="step"] { background: hsl(var(--card)); border-color: hsl(var(--border)); color: hsl(var(--foreground)); font-weight: 600; }
.tourbar .num { font-variant-numeric: tabular-nums; color: hsl(var(--muted-foreground)); font-size: 11px; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: calc(var(--radius) - 1px); border: 1px solid hsl(var(--border-strong)); background: hsl(var(--card));
  font-weight: 550; font-size: 13.5px; white-space: nowrap; transition: background 120ms, border-color 120ms, box-shadow 120ms;
}
.btn:hover { background: hsl(var(--muted)); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: hsl(var(--primary)); border-color: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { background: hsl(var(--primary) / 0.9); }
.btn-ai { background: hsl(var(--ai-soft)); border-color: hsl(var(--ai-border)); color: hsl(var(--ai)); }
.btn-ai:hover { background: hsl(var(--ai-soft)); border-color: hsl(var(--ai)); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: hsl(var(--muted)); }
.btn-danger { color: hsl(var(--danger)); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 44px; padding: 0 18px; font-size: 14.5px; }
.icon-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 6px; border: 1px solid transparent;
  background: transparent; color: hsl(var(--muted-foreground)); flex: none;
}
.icon-btn:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }
.icon-btn[aria-pressed="true"] { background: hsl(var(--primary-soft)); color: hsl(var(--primary-soft-foreground)); }
.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 20px; height: 20px; }
.kbd { font-family: var(--font-mono); font-size: 11px; padding: 1px 5px; border: 1px solid hsl(var(--border-strong)); border-bottom-width: 2px; border-radius: 4px; color: hsl(var(--muted-foreground)); background: hsl(var(--card)); }

/* ── Badges, chips, status ─────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); white-space: nowrap; border: 1px solid transparent;
}
.badge .icon { width: 12px; height: 12px; }
.badge-primary { background: hsl(var(--primary-soft)); color: hsl(var(--primary-soft-foreground)); }
.badge-ai { background: hsl(var(--ai-soft)); color: hsl(var(--ai)); border-color: hsl(var(--ai-border)); }
.badge-success { background: hsl(var(--success-soft)); color: hsl(var(--success)); }
.badge-warning { background: hsl(var(--warning-soft)); color: hsl(var(--warning)); }
.badge-danger { background: hsl(var(--danger-soft)); color: hsl(var(--danger)); }
.badge-teal { background: hsl(var(--secondary-soft)); color: hsl(var(--secondary)); }
.badge-outline { background: transparent; border-color: hsl(var(--border-strong)); color: hsl(var(--foreground) / 0.8); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; flex: none; }

/* Segmented answer chips — 44px targets for tablet use (WCAG 2.5.8) */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  min-height: 44px; padding: 8px 14px; border-radius: 8px; border: 1px solid hsl(var(--border-strong)); background: hsl(var(--card));
  font-size: 13.5px; font-weight: 500; text-align: left; line-height: 1.25;
}
.seg button:hover { border-color: hsl(var(--primary) / 0.6); }
.seg button[aria-pressed="true"] { background: hsl(var(--primary)); border-color: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.seg button.quiet { border-style: dashed; color: hsl(var(--muted-foreground)); }
.seg button.quiet[aria-pressed="true"] { background: hsl(var(--muted)); color: hsl(var(--foreground)); border-style: solid; border-color: hsl(var(--border-strong)); }
.seg.compact button { min-height: 36px; padding: 6px 10px; font-size: 12.5px; }

/* ── Cards, panels ─────────────────────────────────────── */
.card { background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) + 4px); }
.card-pad { padding: 16px; }
.panel-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: hsl(var(--muted-foreground)); font-weight: 650; margin: 0 0 8px; }
.divider { height: 1px; background: hsl(var(--border)); margin: 12px 0; border: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* Inputs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field .label { font-size: 12.5px; font-weight: 600; }
.field .hint { font-size: 12px; color: hsl(var(--muted-foreground)); }
.input, .textarea, .select {
  width: 100%; border: 1px solid hsl(var(--border-strong)); background: hsl(var(--card)); border-radius: calc(var(--radius) - 1px);
  padding: 8px 10px; min-height: 36px; font-size: 13.5px;
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus { outline: 2px solid hsl(var(--ring) / 0.5); outline-offset: 0; border-color: hsl(var(--ring)); }
.switch { position: relative; width: 36px; height: 20px; border-radius: 999px; border: 0; background: hsl(var(--border-strong)); flex: none; padding: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: hsl(var(--card)); transition: transform 140ms; box-shadow: 0 1px 2px hsl(var(--shadow) / 0.25); }
.switch[aria-checked="true"] { background: hsl(var(--primary)); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid hsl(var(--border)); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 12px; font-size: 13px; font-weight: 550; color: hsl(var(--muted-foreground)); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs button[aria-selected="true"] { color: hsl(var(--foreground)); border-bottom-color: hsl(var(--primary)); }

/* ── Overlays ──────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: hsl(var(--shadow) / 0.45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade 140ms ease-out; }
.dialog {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: 14px; width: min(760px, 100%); max-height: calc(100% - 32px);
  display: flex; flex-direction: column; box-shadow: 0 24px 60px -12px hsl(var(--shadow) / 0.35); animation: pop 160ms ease-out;
}
.dialog.wide { width: min(1080px, 100%); }
.dialog-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-head p { margin: 4px 0 0; color: hsl(var(--muted-foreground)); font-size: 13px; }
.dialog-body { padding: 4px 20px 16px; overflow: auto; min-height: 0; }
.dialog-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid hsl(var(--border)); flex-wrap: wrap; align-items: center; }
.sheet { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: hsl(var(--card)); border-left: 1px solid hsl(var(--border)); z-index: 50; display: flex; flex-direction: column; box-shadow: -20px 0 50px -20px hsl(var(--shadow) / 0.35); animation: slide 180ms ease-out; }
.popover { position: absolute; z-index: 40; background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: 10px; box-shadow: 0 12px 32px -8px hsl(var(--shadow) / 0.3); padding: 6px; min-width: 220px; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px; border: 0; background: none; width: 100%; text-align: left; font-size: 13px; }
.menu-item:hover, .menu-item[data-active="true"] { background: hsl(var(--muted)); }
.menu-item .kbd { margin-left: auto; }
.menu-sep { height: 1px; background: hsl(var(--border)); margin: 4px 2px; }
.toast-stack { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; align-items: center; pointer-events: none; width: min(560px, calc(100% - 32px)); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: hsl(var(--foreground)); color: hsl(var(--background)); padding: 10px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 10px 30px -10px hsl(var(--shadow) / 0.5); animation: pop 160ms ease-out; }
.toast .btn { height: 26px; padding: 0 8px; font-size: 12px; background: transparent; border-color: hsl(var(--background) / 0.35); color: hsl(var(--background)); }

/* AI surface */
.ai-card { border: 1px solid hsl(var(--ai-border)); background: hsl(var(--ai-soft)); border-radius: 12px; padding: 14px; }
.ai-mark { display: inline-flex; align-items: center; gap: 4px; color: hsl(var(--ai)); font-weight: 600; font-size: 12px; }
.shimmer { background: linear-gradient(90deg, hsl(var(--muted)) 0%, hsl(var(--border)) 50%, hsl(var(--muted)) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: 6px; }

/* Empty state */
.empty { text-align: center; padding: 40px 16px; color: hsl(var(--muted-foreground)); }
.empty .icon { width: 28px; height: 28px; margin-bottom: 8px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes arrive { 0% { background: hsl(var(--ai-soft)); box-shadow: 0 0 0 2px hsl(var(--ai-border)); } 100% { background: hsl(var(--card)); box-shadow: none; } }

/* ── Responsive shell ──────────────────────────────────── */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 45; transform: translateX(-100%); transition: transform 180ms; }
  .shell.nav-open .nav { transform: none; box-shadow: 20px 0 50px -20px hsl(var(--shadow) / 0.4); }
  .page { padding: 16px; }
  .topbar { padding: 8px 16px; }
}
@media (min-width: 901px) { .nav-toggle { display: none; } }
