/* Fikr design system — single source of truth. Rules: DESIGN.md */

:root {
  /* ---------- primitives ---------- */
  --brand-50: #EEF8F5;
  --brand-100: #D7EFE7;
  --brand-200: #AEDFD0;
  --brand-300: #7DC8B2;
  --brand-400: #45A98E;
  --brand-500: #1E8C72;
  --brand-600: #0F7560;
  --brand-700: #0B5E4E;
  --brand-800: #094A3E;
  --brand-900: #073B32;

  --n-0: #FFFFFF;
  --n-25: #FAFBFA;
  --n-50: #F4F6F5;
  --n-100: #ECEFEE;
  --n-200: #DCE1DF;
  --n-300: #C2C9C6;
  --n-400: #97A19D;
  --n-500: #67726E;
  --n-600: #525D59;
  --n-700: #3A4441;
  --n-800: #232B28;
  --n-900: #121916;

  --success-50: #E6F4EC; --success-600: #18794E;
  --warning-50: #FDF5E1; --warning-600: #95600A;
  --danger-50: #FDEEEA;  --danger-600: #C23A22;
  --info-50: #EDF1FD;    --info-600: #3B5BDB;

  --rate-1: #B91C1C;
  --rate-2: #C2410C;
  --rate-3: #A16207;
  --rate-4: #15803D;
  --rate-5: #0F7560;

  /* ---------- semantic roles ---------- */
  --bg: var(--n-50);
  --surface: var(--n-0);
  --surface-sunken: var(--n-100);
  --surface-inverse: var(--n-900);
  --text: var(--n-900);
  --text-2: var(--n-600);
  --text-3: var(--n-500);
  --text-inverse: var(--n-0);
  --border: rgba(18, 25, 22, .08);
  --border-strong: rgba(18, 25, 22, .16);
  --accent: var(--brand-600);
  --accent-hover: var(--brand-700);
  --accent-soft: var(--brand-50);
  --accent-soft-2: var(--brand-100);
  --on-accent: var(--n-0);
  --focus-ring: 0 0 0 3px rgba(15, 117, 96, .22);

  /* ---------- typography ---------- */
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-display: clamp(34px, 4.4vw, 52px);
  --fs-h1: 30px;
  --fs-h2: 24px;
  --fs-h3: 18px;
  --fs-title: 15px;
  --fs-body-lg: 17px;
  --fs-patient: 16px;
  --fs-body: 15px;
  --fs-label: 13px;
  --fs-caption: 12px;
  --fs-kpi: 34px;

  /* ---------- spacing (4px grid) ---------- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;
  --sp-20: 80px;

  /* ---------- radius ---------- */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-full: 999px;

  /* ---------- elevation ---------- */
  --sh-1: 0 1px 2px rgba(18, 25, 22, .05), 0 1px 1px rgba(18, 25, 22, .03);
  --sh-2: 0 1px 2px rgba(18, 25, 22, .04), 0 8px 24px -6px rgba(18, 25, 22, .10);
  --sh-3: 0 2px 4px rgba(18, 25, 22, .04), 0 24px 64px -16px rgba(18, 25, 22, .24);
  --sh-accent: 0 1px 0 rgba(255, 255, 255, .16) inset, 0 6px 16px -6px rgba(15, 117, 96, .55);

  /* ---------- motion ---------- */
  --dur-1: 150ms;
  --dur-2: 250ms;
  --dur-3: 400ms;
  --dur-4: 700ms;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);

  /* ---------- sizing / layout ---------- */
  --h-sm: 36px;
  --h-md: 44px;
  --h-lg: 56px;
  --container: 1200px;
  --gutter: var(--sp-8);
  --z-sticky: 10;
  --z-toast: 50;
}
@media (max-width: 1020px) { :root { --gutter: var(--sp-6); } }
@media (max-width: 560px) { :root { --gutter: var(--sp-4); --fs-h1: 26px; --fs-h2: 22px; --fs-kpi: 28px; } }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--fs-body)/1.5 var(--font); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, h4 { margin: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.num { font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; } }

/* ---------- type roles ---------- */
.t-display { font-size: var(--fs-display); line-height: 1.05; font-weight: 800; letter-spacing: -.03em; }
.t-h1 { font-size: var(--fs-h1); line-height: 1.2; font-weight: 700; letter-spacing: -.02em; }
.t-h2 { font-size: var(--fs-h2); line-height: 1.2; font-weight: 700; letter-spacing: -.02em; }
.t-h3 { font-size: var(--fs-h3); line-height: 1.35; font-weight: 600; letter-spacing: -.01em; }
.t-title { font-size: var(--fs-title); line-height: 1.4; font-weight: 600; }
.t-body-lg { font-size: var(--fs-body-lg); line-height: 1.55; }
.t-patient { font-size: var(--fs-patient); line-height: 1.5; }
.t-body { font-size: var(--fs-body); line-height: 1.5; }
.t-label { font-size: var(--fs-label); line-height: 1.4; font-weight: 600; }
.t-caption { font-size: var(--fs-caption); line-height: 1.35; font-weight: 500; }
.t-kpi { font-size: var(--fs-kpi); line-height: 1.1; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.c-2 { color: var(--text-2); }
.c-3 { color: var(--text-3); }
.c-accent { color: var(--accent); }

/* ---------- button ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--h-md); padding: 0 var(--sp-4); border-radius: var(--r-sm);
  font-size: var(--fs-body); font-weight: 600; white-space: nowrap;
  transition-property: transform, background-color, border-color, color, box-shadow, opacity;
  transition-duration: var(--dur-1); transition-timing-function: var(--ease-out);
}
.btn:active:not(:disabled), .btn.is-active { transform: scale(.96); }
.btn:disabled, .btn.is-disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.btn-sm { min-height: var(--h-sm); padding: 0 var(--sp-3); font-size: var(--fs-label); border-radius: var(--r-xs); }
.btn-lg { min-height: var(--h-lg); padding: 0 var(--sp-6); font-size: var(--fs-patient); font-weight: 700; border-radius: var(--r-md); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--sh-accent); }
.btn-primary:hover:not(:disabled), .btn-primary.is-hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong), var(--sh-1); }
.btn-secondary:hover:not(:disabled), .btn-secondary.is-hover { background: var(--n-25); box-shadow: inset 0 0 0 1px var(--n-300), var(--sh-1); }
.btn-ghost { background: var(--surface-sunken); color: var(--text); }
.btn-ghost:hover:not(:disabled), .btn-ghost.is-hover { background: var(--n-200); }
.btn-danger { background: var(--danger-600); color: var(--on-accent); }
.btn-danger:hover:not(:disabled), .btn-danger.is-hover { background: var(--rate-1); }
.btn.is-focus { box-shadow: var(--focus-ring); }
.btn-icon { width: var(--h-md); padding: 0; }

/* ---------- field ---------- */
.field { display: grid; gap: var(--sp-2); }
.field-label { font-size: var(--fs-label); font-weight: 600; color: var(--text-2); }
.field-hint { font-size: var(--fs-caption); color: var(--text-3); }
.field.is-error .field-hint { color: var(--danger-600); }
.input {
  width: 100%; min-height: var(--h-md); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--border-strong); resize: none;
  transition-property: border-color, box-shadow, background-color; transition-duration: var(--dur-1);
}
.input::placeholder { color: var(--text-3); }
.input:hover:not(:disabled), .input.is-hover { border-color: var(--n-300); }
.input:focus, .input.is-focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.field.is-error .input { border-color: var(--danger-600); box-shadow: 0 0 0 3px rgba(194, 58, 34, .14); }
.input:disabled { background: var(--surface-sunken); color: var(--text-3); cursor: not-allowed; }

/* ---------- badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--sp-1); padding: 2px var(--sp-2); border-radius: var(--r-full);
  font-size: var(--fs-caption); font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.badge-neutral { background: var(--surface-sunken); color: var(--text-2); }
.badge-accent { background: var(--accent-soft); color: var(--accent-hover); }
.badge-success { background: var(--success-50); color: var(--success-600); }
.badge-warning { background: var(--warning-50); color: var(--warning-600); }
.badge-danger { background: var(--danger-50); color: var(--danger-600); }
.badge-info { background: var(--info-50); color: var(--info-600); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: var(--r-full); background: currentColor; }

/* ---------- chip (toggle) ---------- */
.chip {
  min-height: 40px; padding: 0 var(--sp-4); border-radius: var(--r-full); border: 1px solid var(--border-strong);
  font-size: var(--fs-body); font-weight: 600; background: var(--surface);
  transition-property: background-color, color, border-color; transition-duration: var(--dur-1);
}
.chip:hover, .chip.is-hover { border-color: var(--n-400); }
.chip[aria-pressed="true"] { background: var(--surface-inverse); color: var(--text-inverse); border-color: var(--surface-inverse); }
.chip.chip-danger[aria-pressed="true"] { background: var(--danger-600); border-color: var(--danger-600); }

/* ---------- option row (radio-like, patient) ---------- */
.opt {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: var(--h-lg); padding: var(--sp-4);
  border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border-strong);
  text-align: left; font-size: var(--fs-patient); font-weight: 600;
  transition-property: transform, border-color, background-color, box-shadow; transition-duration: var(--dur-1); transition-timing-function: var(--ease-out);
}
.opt + .opt { margin-top: var(--sp-2); }
.opt:hover, .opt.is-hover { border-color: var(--brand-300); }
.opt:active { transform: scale(.98); }
.opt[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: var(--focus-ring); }
.opt-dot { width: 22px; height: 22px; border-radius: var(--r-full); border: 2px solid var(--border-strong); flex: none; display: grid; place-items: center;
  transition-property: border-color, background-color; transition-duration: var(--dur-1); }
.opt[aria-pressed="true"] .opt-dot { border-color: var(--accent); background: var(--accent); }
.opt[aria-pressed="true"] .opt-dot::after { content: ""; width: 8px; height: 8px; border-radius: var(--r-full); background: var(--on-accent); }
.opt-meta { margin-left: auto; font-size: var(--fs-caption); color: var(--text-3); font-weight: 500; }

/* ---------- rating face ---------- */
.faces { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--sp-2); }
.face {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-1);
  border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface);
  transition-property: transform, border-color, background-color; transition-duration: var(--dur-1); transition-timing-function: var(--ease-out);
}
.face:hover { border-color: var(--n-400); }
.face:active { transform: scale(.94); }
.face svg { width: 40px; height: 40px; transition: transform var(--dur-2) var(--ease-out); }
.face span { font-size: var(--fs-caption); line-height: 1.25; color: var(--text-3); font-weight: 600; text-align: center; }
.face[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 9%, var(--surface)); }
.face[aria-pressed="true"] svg { transform: scale(1.12); }
.face[aria-pressed="true"] span { color: color-mix(in srgb, var(--c) 80%, var(--n-900)); } /* keeps ≥ 4.5:1 on the tinted fill */

/* ---------- card ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-1); padding: var(--sp-5); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-4); }
@media (max-width: 560px) { .card { padding: var(--sp-4); } }

/* ---------- navigation ---------- */
.seg { position: relative; display: flex; padding: var(--sp-1); background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--r-md); }
.seg-item { position: relative; z-index: 1; min-height: var(--h-sm); padding: 0 var(--sp-4); border-radius: var(--r-sm); font-size: var(--fs-body); font-weight: 600; color: var(--text-2);
  transition: color var(--dur-2) var(--ease-out); }
.seg-item:hover, .seg-item.is-hover { color: var(--text); }
.seg-item[aria-selected="true"] { color: var(--text); }
.seg-pill { position: absolute; top: var(--sp-1); bottom: var(--sp-1); left: var(--sp-1); border-radius: var(--r-sm); background: var(--surface); box-shadow: var(--sh-1), 0 0 0 1px var(--border); }
.seg-static .seg-item[aria-selected="true"] { background: var(--surface); box-shadow: var(--sh-1), 0 0 0 1px var(--border); }

.tabs { display: flex; gap: var(--sp-1); }
.tab { min-height: var(--h-sm); padding: 0 var(--sp-3); border-radius: var(--r-xs); font-size: var(--fs-label); font-weight: 600; color: var(--text-2);
  transition-property: background-color, color; transition-duration: var(--dur-1); }
.tab:hover, .tab.is-hover { color: var(--text); background: var(--n-25); }
.tab[aria-pressed="true"] { background: var(--surface-sunken); color: var(--text); }
.tab:disabled { opacity: .4; cursor: not-allowed; }
.tabs-inverse .tab[aria-pressed="true"] { background: var(--surface-inverse); color: var(--text-inverse); }

.list-item { position: relative; display: block; width: 100%; text-align: left; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border);
  transition: background-color var(--dur-1); }
.list-item:hover, .list-item.is-hover { background: var(--n-25); }
.list-item[aria-current="true"] { background: var(--accent-soft); }
.list-item[aria-current="true"]::before { content: ""; position: absolute; left: 0; top: var(--sp-3); bottom: var(--sp-3); width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }

/* ---------- misc ---------- */
.score { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: var(--r-xs); color: var(--on-accent); font-size: var(--fs-caption); font-weight: 700; flex: none; }
.delta { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 2px var(--sp-2); border-radius: var(--r-full); font-size: var(--fs-caption); font-weight: 600; }
.delta-up { color: var(--success-600); background: var(--success-50); }
.delta-down { color: var(--danger-600); background: var(--danger-50); }
.toast { position: fixed; left: 50%; bottom: var(--sp-6); transform: translate(-50%, var(--sp-5)); opacity: 0; z-index: var(--z-toast); pointer-events: none;
  padding: var(--sp-3) var(--sp-5); border-radius: var(--r-sm); background: var(--surface-inverse); color: var(--text-inverse); font-weight: 600; box-shadow: var(--sh-3);
  transition-property: opacity, transform; transition-duration: var(--dur-2); transition-timing-function: var(--ease-out); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
