/* PiP prototype v2 — plain-CSS replica of the app's UI system.
   Source of truth: apps/assessment/app/globals.css (@theme, "VicHealth Civic
   Modernist") + packages/ui shadcn components. Values are transcribed, not
   invented — see UIKIT.md for the contract. */

:root {
  --background: hsl(40 20% 98%);
  --foreground: hsl(200 25% 10%);
  --card: hsl(0 0% 100%);
  --primary: hsl(174 100% 27%);
  --primary-fg: hsl(0 0% 100%);
  --secondary: hsl(40 18% 93%);
  --secondary-fg: hsl(200 20% 18%);
  --muted: hsl(40 14% 93%);
  --muted-fg: hsl(200 10% 44%);
  --accent: hsl(40 18% 93%);
  --destructive: hsl(0 72% 51%);
  --border: hsl(40 12% 88%);
  --input: hsl(40 12% 88%);
  --ring: hsl(174 100% 27%);
  --sidebar: hsl(180 30% 12%);
  --sidebar-fg: hsl(40 20% 92%);
  --sidebar-muted: hsl(180 20% 20%);
  --deep-green: #0F3B36;           /* "Learning loop" chip, landing footer */
  /* badge palettes (tailwind v4 approximations used by the app) */
  --green-100: #dcfce7; --green-800: #166534; --green-500: #22c55e; --green-600: #16a34a;
  --amber-50: #fffbeb; --amber-100: #fef3c7; --amber-400: #fbbf24; --amber-500: #f59e0b; --amber-800: #92400e;
  --yellow-100: #fef9c3; --yellow-800: #854d0e;
  --blue-100: #dbeafe; --blue-500: #3b82f6; --blue-700: #1d4ed8;
  --red-400: #f87171; --red-50: #fef2f2;
}

* { box-sizing: border-box; border-color: var(--border); }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Grain overlay, as in globals.css body::before (opacity .018) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 9999; pointer-events: none; opacity: .018;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='256'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='256' height='256' filter='url(%23n)'/%3E%3C/svg%3E");
}

h1, h2, h3 { margin: 0; }
h1 { letter-spacing: -0.025em; font-weight: 700; }
h2 { letter-spacing: -0.02em; font-weight: 600; }
h3 { letter-spacing: -0.01em; font-weight: 600; }
p { margin: 0; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* Staggered entrance like globals.css main > * (reduced-motion safe) */
@media (prefers-reduced-motion: no-preference) {
  @keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
  main > * { animation: slide-up .5s ease-out both; }
  main > *:nth-child(2) { animation-delay: 60ms; } main > *:nth-child(3) { animation-delay: 120ms; }
  main > *:nth-child(4) { animation-delay: 180ms; } main > *:nth-child(5) { animation-delay: 240ms; }
  main > *:nth-child(n+6) { animation-delay: 300ms; }
}

/* ---------- prototype meta bar (NOT part of the app — sits above the chrome) ---------- */
.proto-bar { background: var(--foreground); color: #fff; font-size: 13px; padding: 8px 16px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; position: sticky; top: 0; z-index: 50; min-height: 48px; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.proto-bar .tag { background: rgba(255,255,255,.15); border-radius: 999px; padding: 3px 12px; font-weight: 500; }
.proto-bar .switch-label { text-transform: uppercase; letter-spacing: .06em; font-size: 11px; font-weight: 600; color: rgba(255,255,255,.65); margin-left: auto; }
.proto-bar nav { display: flex; gap: 6px; flex-wrap: wrap; }
.proto-bar a { color: #fff; text-decoration: none; padding: 6px 14px; border-radius: 999px; border: 1px solid rgba(255,255,255,.4); font-weight: 500; transition: background-color .15s; }
.proto-bar a:hover { background: rgba(255,255,255,.15); }
.proto-bar a[aria-current="page"] { background: #fff; color: var(--foreground); font-weight: 600; border-color: #fff; }

/* ---------- org-facing header (Header.tsx replica) ---------- */
.app-header { border-bottom: 1px solid hsl(40 12% 88% / .6); background: rgba(255,255,255,.8); backdrop-filter: blur(4px); position: sticky; top: 48px; z-index: 40; }
.app-header .inner { max-width: 64rem; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 3.5rem; padding: 0 1rem; }
.app-header .left { display: flex; align-items: center; gap: 1.5rem; }
.brand { display: flex; align-items: center; gap: .625rem; text-decoration: none; }
.brand .mark, .brand-mark { width: 1.75rem; height: 1.75rem; border-radius: .375rem; background: var(--primary); color: #fff; font-weight: 700; font-size: .875rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.brand .word { font-weight: 600; letter-spacing: -0.01em; color: var(--foreground); }
.app-header nav { display: flex; align-items: center; gap: 1rem; }
.app-header nav a { font-size: .875rem; text-decoration: none; color: var(--muted-fg); transition: color .15s; }
.app-header nav a:hover { color: var(--foreground); }
.app-header nav a.active { color: var(--foreground); font-weight: 500; }
.app-header .right { display: flex; align-items: center; gap: 1rem; }
.bell { position: relative; padding: .5rem; border-radius: .375rem; text-decoration: none; color: var(--foreground); display: inline-flex; }
.bell:hover { background: var(--muted); }
.bell .count { position: absolute; top: -2px; right: -2px; background: var(--destructive); color: #fff; font-size: 10px; font-weight: 700; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px; display: flex; align-items: center; justify-content: center; }
.signout { font-size: .875rem; color: var(--muted-fg); background: none; border: none; cursor: pointer; font-family: inherit; }
.signout:hover { color: var(--foreground); }

/* ---------- admin shell (AdminSidebar replica) ---------- */
.admin-shell { display: flex; min-height: calc(100vh - 48px); }
.sidebar { width: 16rem; background: var(--sidebar); color: var(--sidebar-fg); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar .brand-block { padding: 1.25rem; border-bottom: 1px solid rgba(255,255,255,.1); display: flex; gap: .625rem; align-items: center; }
.sidebar .brand-block .mark { background: var(--primary); }  /* AdminSidebar: bg-sidebar-accent = hsl(174 100% 27%) = primary */
.sidebar .brand-block .word { color: #fff; font-size: .875rem; font-weight: 600; letter-spacing: -0.01em; }
.sidebar .brand-block .sub { font-size: 11px; color: hsl(40 20% 92% / .6); }
.sidebar nav { padding: .75rem; flex: 1; }
.sidebar .group { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar .group:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.sidebar nav a { display: flex; align-items: center; gap: .75rem; padding: .5rem .75rem; border-radius: .5rem; font-size: .875rem; text-decoration: none; color: hsl(40 20% 92% / .7); transition: all .15s; }
.sidebar nav a:hover { color: #fff; background: var(--sidebar-muted); }
.sidebar nav a.active { background: var(--primary); color: #fff; font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.sidebar .icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-flex; }
.sidebar .icon svg { width: 18px; height: 18px; }
.sidebar .user { padding: .75rem; border-top: 1px solid rgba(255,255,255,.1); display: flex; align-items: center; gap: .625rem; }
.sidebar .user .avatar { width: 2rem; height: 2rem; border-radius: 999px; background: hsl(174 100% 27% / .8); color: #fff; font-size: .75rem; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.sidebar .user .name { font-size: .875rem; color: #fff; font-weight: 500; }
.sidebar .user .email { font-size: 11px; color: hsl(40 20% 92% / .5); }
.sidebar .user .info { flex: 1; min-width: 0; }
.sidebar .user .name, .sidebar .user .email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* AdminSidebar sign-out: p-1.5 rounded-md text-sidebar-foreground/40 hover:text-white hover:bg-sidebar-muted */
.sidebar .user .user-signout { padding: .375rem; border-radius: .375rem; background: none; border: none; cursor: pointer; color: hsl(40 20% 92% / .4); display: inline-flex; flex-shrink: 0; transition: color .15s, background-color .15s; }
.sidebar .user .user-signout:hover { color: #fff; background: var(--sidebar-muted); }
.admin-main { flex: 1; padding: 2rem; overflow-y: auto; min-width: 0; }

/* ---------- page scaffolding ---------- */
.page { padding: 2rem; }
.page .inner-2xl { max-width: 42rem; margin: 0 auto; }
.page .inner-3xl { max-width: 48rem; margin: 0 auto; }
.page .inner-4xl { max-width: 56rem; margin: 0 auto; }
.page .inner-5xl { max-width: 64rem; margin: 0 auto; }
.page-title { font-size: 1.875rem; margin-bottom: .5rem; }         /* org: text-3xl font-bold */
.admin-title { font-size: 1.5rem; margin-bottom: .25rem; }          /* admin: text-2xl font-bold */
.lede { color: var(--muted-fg); margin-bottom: 2rem; }
.lede-sm { font-size: .875rem; color: var(--muted-fg); margin-top: .25rem; }
.back-link { font-size: .875rem; color: var(--muted-fg); text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.section { margin-bottom: 2rem; }
.section-title { font-size: 1.125rem; font-weight: 600; margin-bottom: 1rem; }
/* Section header with right-aligned action (admin "Active Programs" pattern: flex items-center justify-between mb-4) */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.section-head .section-title { margin-bottom: 0; }
.meta-row { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; font-size: .875rem; flex-wrap: wrap; color: var(--muted-fg); }

/* ---------- tabs (EngagementTabs underline pattern) ---------- */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; overflow-x: auto; }
.tab { padding: .5rem 1rem; font-size: .875rem; color: var(--muted-fg); background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -2px; cursor: pointer; font-family: inherit; display: flex; align-items: center; gap: .375rem; white-space: nowrap; }
.tab:hover { color: var(--foreground); }
.tab.active { font-weight: 600; border-bottom-color: var(--primary); color: var(--foreground); }
.tab .attn { background: var(--amber-100); color: var(--amber-800); font-size: .75rem; padding: .125rem .375rem; border-radius: 999px; font-weight: 500; }
[data-tab-panel] { display: none; }
[data-tab-panel].active { display: block; }

/* ---------- step indicator (StepIndicator replica) ---------- */
.steps-row { display: flex; align-items: center; gap: .5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.step-pill { display: flex; align-items: center; gap: .5rem; padding: .375rem .75rem; border-radius: 999px; font-size: .875rem; font-weight: 500; }
.step-pill.active { background: var(--primary); color: #fff; }
.step-pill.complete { background: hsl(174 100% 27% / .1); color: var(--primary); }
.step-pill.pending { background: var(--muted); color: var(--muted-fg); }
.step-join { width: 2rem; height: 1px; background: var(--border); }

/* ---------- buttons (packages/ui Button replica) ---------- */
.btn, .btn-outline, .btn-ghost, .btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; white-space: nowrap;
  border-radius: .375rem; font-size: .875rem; font-weight: 500; font-family: inherit;
  height: 2.5rem; padding: .5rem 1rem; cursor: pointer; text-decoration: none; transition: background-color .15s, color .15s;
  border: none;
}
.btn { background: var(--primary); color: var(--primary-fg); }
.btn:hover { background: hsl(174 100% 27% / .9); }
.btn-outline { border: 1px solid var(--input); background: var(--background); color: var(--foreground); }
.btn-outline:hover { background: var(--accent); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover { background: var(--accent); }
.btn-secondary { background: var(--secondary); color: var(--secondary-fg); }
.btn-sm { height: 2.25rem; padding: 0 .75rem; }
.btn[disabled], .btn-outline[disabled] { opacity: .5; pointer-events: none; }
.link { color: var(--primary); text-decoration: none; font-size: .875rem; }
.link:hover { text-decoration: underline; }

/* ---------- badges (packages/ui Badge replica + status map) ---------- */
.badge { display: inline-flex; align-items: center; border-radius: 999px; border: 1px solid transparent; padding: .125rem .625rem; font-size: .75rem; font-weight: 600; }
.badge.default { background: var(--primary); color: var(--primary-fg); }
.badge.secondary { background: var(--secondary); color: var(--secondary-fg); }
.badge.success { background: var(--green-100); color: var(--green-800); }
.badge.warning { background: var(--yellow-100); color: var(--yellow-800); }
.badge.amber { background: var(--amber-100); color: var(--amber-800); }
.badge.outline { border-color: var(--border); color: var(--foreground); background: transparent; }
.badge.destructive { background: var(--destructive); color: #fff; }
.loop-chip { display: inline-flex; border-radius: 999px; background: var(--deep-green); padding: .125rem .5rem; font-size: 10px; font-weight: 500; color: #fff; }
.link-chip { display: inline-flex; align-items: center; gap: .25rem; border-radius: 999px; background: hsl(174 100% 27% / .1); color: var(--primary); padding: .125rem .625rem; font-size: .75rem; font-weight: 600; text-decoration: none; }

/* ---------- cards (packages/ui Card replica) ---------- */
.card { border-radius: .5rem; border: 1px solid var(--border); background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card-header { display: flex; flex-direction: column; gap: .375rem; padding: 1.5rem; }
.card-title { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.01em; }
.card-desc { font-size: .875rem; color: var(--muted-fg); }
.card-content { padding: 1.5rem; padding-top: 0; }
.card-content.pt { padding-top: 1.5rem; }
.card-footer { display: flex; align-items: center; padding: 1.5rem; padding-top: 0; }
.card.hoverable { transition: border-color .2s, box-shadow .2s; }
.card.hoverable:hover { border-color: hsl(174 100% 27% / .3); box-shadow: 0 4px 6px -1px rgba(0,0,0,.1); }
.metric-card { border-left: 2px solid hsl(174 100% 27% / .2); }
.metric-card .label { font-size: .875rem; font-weight: 500; color: var(--muted-fg); }
.metric-card .value { font-size: 1.5rem; font-weight: 700; margin-top: .25rem; }
.metric-card .sub { font-size: .875rem; color: var(--muted-fg); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.5rem; }
.attention-card { border: 1px solid #fde68a; background: hsl(48 96% 89% / .3); border-radius: .5rem; padding: 1rem 1.25rem; }

/* ---------- tables (packages/ui Table replica) ---------- */
.table-wrap { position: relative; width: 100%; overflow: auto; }
table.app { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.app th { height: 3rem; padding: 0 1rem; text-align: left; vertical-align: middle; font-weight: 500; color: var(--muted-fg); border-bottom: 1px solid var(--border); }
table.app td { padding: 1rem; vertical-align: middle; border-bottom: 1px solid var(--border); }
table.app tbody tr { transition: background-color .15s; }
table.app tbody tr:hover { background: hsl(40 14% 93% / .5); }
table.app tbody tr:last-child td { border-bottom: none; }
table.app .cell-main { font-weight: 500; }
tr.row-attn { background: hsl(48 96% 89% / .3); box-shadow: inset 3px 0 0 var(--amber-400); }

/* ---------- forms (Input/Label/Select/Textarea replicas) ---------- */
.field { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.field > label { font-size: .875rem; font-weight: 500; line-height: 1; }
.field .hint { font-weight: 400; color: var(--muted-fg); }
.input, .select, .textarea {
  width: 100%; border-radius: .375rem; border: 1px solid var(--input); background: var(--background);
  padding: .5rem .75rem; font-size: .875rem; font-family: inherit; color: var(--foreground);
}
.input { height: 2.5rem; display: flex; }
.input::placeholder, .textarea::placeholder { color: var(--muted-fg); }
.select { height: 2.5rem; appearance: none; padding-right: 2.25rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; background-size: 1rem; }
.textarea { min-height: 80px; resize: vertical; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.char-count { font-size: .75rem; color: var(--muted-fg); text-align: right; }
.org-chip { display: inline-flex; align-items: center; gap: .25rem; border-radius: 999px; background: var(--muted); padding: .125rem .5rem; font-size: .75rem; }
.org-chip button { background: none; border: none; cursor: pointer; font-size: .875rem; line-height: 1; padding: 0; color: var(--muted-fg); }

/* ---------- segmented toggle (EngagementForm type toggle) ---------- */
.segmented { display: inline-flex; overflow: hidden; border-radius: .5rem; border: 1px solid var(--border); }
.segmented button { padding: .375rem 1rem; font-size: .875rem; font-weight: 500; background: none; border: none; cursor: pointer; font-family: inherit; color: var(--muted-fg); }
.segmented button.selected { background: var(--primary); color: #fff; }

/* ---------- progress (ProgressBar replica) ---------- */
.progress { width: 100%; background: var(--muted); border-radius: 999px; height: .5rem; overflow: hidden; }
.progress > i { display: block; background: var(--primary); height: 100%; border-radius: 999px; }
.progress.w-24 { width: 6rem; }
.progress.mini { width: 5rem; height: .375rem; }

/* ---------- filter pills (OrganisationsTab pattern) ---------- */
.filter-pills { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-pill { padding: .25rem .75rem; border-radius: 999px; font-size: .75rem; font-weight: 500; background: var(--muted); color: var(--muted-fg); border: none; cursor: pointer; font-family: inherit; }
.filter-pill:hover { background: hsl(40 14% 93% / .8); }
.filter-pill.active { background: var(--foreground); color: var(--background); }
.filter-pill.attn { background: var(--amber-100); color: var(--amber-800); }

/* ---------- entry card (loops EntryCard replica) ---------- */
.entry-card { border-radius: .5rem; border: 1px solid var(--border); background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.05); padding: 1.5rem; }
.entry-card.synthesis { border-color: hsl(174 100% 27% / .4); background: hsl(174 100% 27% / .05); }
.entry-card .entry-meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.entry-card .entry-kind { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-fg); }
.entry-card .entry-date { font-size: .75rem; color: var(--muted-fg); }
.entry-card .entry-prompt { font-size: .875rem; color: var(--muted-fg); font-style: italic; margin-bottom: .5rem; }
.entry-card .entry-body { font-size: .875rem; white-space: pre-wrap; }

/* ---------- dialog (packages/ui Dialog replica) ---------- */
dialog.modal { border: 1px solid var(--border); border-radius: .5rem; padding: 1.5rem; max-width: 32rem; width: calc(100% - 3rem); background: var(--background); box-shadow: 0 10px 30px rgba(0,0,0,.15); }
dialog.modal::backdrop { background: rgba(0,0,0,.8); }
.modal-title { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.01em; margin-bottom: .25rem; }
.modal-desc { font-size: .875rem; color: var(--muted-fg); margin-bottom: 1rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* ---------- due-now strip (asks surface on the record — option B IA) ---------- */
.due-strip { border: 1px solid #fde68a; background: hsl(48 96% 89% / .3); border-radius: .5rem; padding: .65rem 1rem; display: flex; gap: .5rem 1.5rem; flex-wrap: wrap; align-items: center; font-size: .875rem; margin-bottom: 1.5rem; }
.due-strip .label { font-weight: 600; color: var(--amber-800); text-transform: uppercase; font-size: .6875rem; letter-spacing: .06em; }
.due-strip a { color: var(--foreground); text-decoration: none; }
.due-strip a b { font-weight: 600; }
.due-strip a:hover b { text-decoration: underline; }
.due-strip .when { color: var(--muted-fg); }

/* ---------- steps checklist (plan-side, inside activity detail) ---------- */
.steps { list-style: none; padding: 0; margin: .5rem 0 0; font-size: .875rem; }
.steps li { display: flex; gap: .5rem; align-items: baseline; padding: .125rem 0; }
.steps input[type="checkbox"] { accent-color: var(--primary); width: 1rem; height: 1rem; }
.steps li.done label { color: var(--muted-fg); text-decoration: line-through; }

/* ---------- misc ---------- */
.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: var(--muted-fg); }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.dot { width: .375rem; height: .375rem; border-radius: 999px; display: inline-block; }
.dot.high { background: #ef4444; } .dot.medium { background: var(--amber-500); } .dot.low { background: #9ca3af; }
.empty-state { text-align: center; padding: 3rem 0; }
.empty-state .title { margin-top: .5rem; font-size: 1rem; font-weight: 600; }
.empty-state .sub { margin-top: .25rem; font-size: .875rem; color: var(--muted-fg); }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

@media (max-width: 720px) {
  .admin-shell { overflow-x: auto; }      /* keep the sidebar visible; allow horizontal scroll */
  .sidebar { width: 13rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .page, .admin-main { padding: 1rem; }
  .proto-bar { position: static; }        /* wrapped bar heights vary on small screens */
  .app-header { top: 0; }
}
