/* THE REFERRALS PAGE (2026-10-23, feat/referral-intake). It looks like the main app: DM Sans, the app header with the
   Yarrow logo, cards with the app's radius and shadows, and the app's .btn, .card and .nn-badge patterns. Every colour is
   a token (var(--...)) set by public/appTheme.js from the clinician's saved palette and display mode, so the page follows
   Yarrow, Clinical, Mint and the others, light or dark, exactly as the main app does. No colour is written here. */
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 100 1000; font-display: swap; src: url('/fonts/dm-sans-latin-wght-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 100 1000; font-display: swap; src: url('/fonts/dm-sans-latin-ext-wght-normal.woff2') format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Fraunces'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/fraunces-latin-500-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); }
body { font-family: var(--app-font); font-size: 14px; line-height: 1.6; min-height: 100vh; }
html:not([data-mode]) body { visibility: hidden; }   /* until the palette is applied: no flash of unthemed colours */
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rf-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rf-muted { color: var(--text2); }
.rf-small { font-size: 12px; }

/* ---- the app header (as .app-header in public/index.html) ---- */
.app-header { background-color: var(--bg); background-image: var(--banner-grad); border-bottom: 1px solid var(--border); padding: 0 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; height: var(--app-header-h); position: sticky; top: 0; z-index: 10; }
.header-right { display: flex; align-items: center; gap: 10px; }
.logo { display: flex; align-items: center; gap: 9px; min-width: 0; text-decoration: none; border-radius: 10px; }
.logo:hover { opacity: .85; }
.nn-logo { width: 42px; height: 42px; flex: none; display: block; object-fit: contain; transition: filter .3s ease; }
.brand-name { font-family: 'Fraunces', Georgia, serif; font-weight: 500; font-size: 25px; letter-spacing: -0.5px; color: var(--logo-ink); line-height: 1; }
.rf-page-title { font-size: 15px; font-weight: 600; color: var(--text2); padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--border); white-space: nowrap; }

/* ---- buttons, badges, inputs (the app's own patterns) ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius-sm); font-family: var(--app-font); font-size: 13px; font-weight: 500; cursor: pointer; border: none; transition: all .15s; text-decoration: none; min-height: 36px; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
/* dark mode: dark text on the light accent fill (white on it is about 2:1; this is above 7:1), the same on every page */
:root[data-mode="dark"] .btn-primary { color: var(--bg); }
:root[data-mode="dark"] .btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; min-height: 30px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.nn-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 20px; border: 1px solid var(--border); white-space: nowrap; color: var(--text2); background: var(--surface2); line-height: 1.5; }
.nn-badge.ai { background: color-mix(in srgb, var(--text3) 12%, transparent); color: var(--text2); }
.nn-badge.ok { background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success-ink); border-color: var(--success); }
.nn-badge.accent { background: var(--accent-tint); color: var(--accent); border-color: var(--accent); }
.nn-badge.critical { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); border-color: var(--danger); }
.nn-badge.high { background: color-mix(in srgb, var(--warning) 14%, transparent); color: color-mix(in srgb, var(--warning) 60%, var(--text)); border-color: var(--warning); }
.nn-badge.routine { background: var(--surface2); color: var(--text2); }
label, .rf-label { font-size: 11px; font-weight: 500; color: var(--text2); letter-spacing: .3px; }
input, select, textarea { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: var(--app-font); font-size: 13px; padding: 9px 12px; transition: border-color .15s, box-shadow .15s; outline: none; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }

/* ---- the view tabs ---- */
.rf-tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--surface2); overflow-x: auto; scrollbar-width: thin; }
.rf-tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 11px 12px; font-size: 13px; font-weight: 500; color: var(--text3); cursor: pointer; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.rf-tab:hover { color: var(--text2); }
.rf-tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.rf-count { font-size: 11px; font-weight: 700; border-radius: 10px; padding: 0 7px; background: var(--surface3); color: var(--text2); }
.rf-tab[aria-selected="true"] .rf-count { background: var(--accent); color: white; }
.rf-tab-sep { width: 1px; background: var(--border); margin: 10px 6px; flex: none; }

.rf-msg:not(:empty) { margin: 12px 20px 0; padding: 9px 14px; border-radius: var(--radius-sm); background: var(--accent-tint); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); }
.rf-msg.is-bad { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); border-color: var(--danger); color: var(--danger); font-weight: 600; }

/* ---- layout: the list beside the packet ---- */
.rf-main { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 16px; padding: 16px 20px 32px; align-items: start; }
.rf-main.is-wide { grid-template-columns: minmax(0, 1fr); }
.rf-list { display: flex; flex-direction: column; gap: 10px; position: sticky; top: calc(var(--app-header-h) + 12px); max-height: calc(100vh - var(--app-header-h) - 120px); overflow: auto; padding: 2px; }
.rf-view { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--card-radius); box-shadow: var(--shadow-sm); }
.card-body { padding: 18px 20px; }
.rf-sech { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text3); margin: 0 0 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rf-sech + .rf-sech { margin-top: 14px; }
.card-body > .rf-sech:not(:first-child), .card-body > .rf-items + .rf-sech, .card-body > p + .rf-sech { margin-top: 18px; }
.rf-h2 { font-size: 18px; font-weight: 700; color: var(--text); line-height: 1.3; }
.rf-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 4px; font-size: 13px; color: var(--text2); }

/* a referral in the list */
.rf-item { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--card-radius); padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow-sm); transition: border-color .14s, box-shadow .14s; }
.rf-item:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); box-shadow: var(--shadow-md); }
.rf-item.is-open { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent), var(--shadow-sm); }
.rf-item.has-flag { box-shadow: inset 3px 0 0 var(--danger), var(--shadow-sm); }
.rf-item-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 14px; color: var(--text); }
.rf-item-when { font-weight: 400; font-size: 12px; color: var(--text3); white-space: nowrap; }
.rf-item-reason { font-size: 13px; color: var(--text2); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rf-item-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }

/* quoted source lines */
.rf-quote { margin: 4px 0 0; padding: 4px 10px; border-left: 3px solid var(--accent); background: var(--surface2); font-size: 12px; color: var(--text); white-space: pre-wrap; border-radius: 0 6px 6px 0; }
.rf-quote::before { content: 'Source: '; color: var(--text3); font-weight: 600; }
.rf-ev { margin-top: 2px; }
.rf-ev summary { font-size: 12px; color: var(--text3); cursor: pointer; width: fit-content; }
.rf-ev summary:hover { color: var(--accent); }

.rf-items { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.rf-items > li { padding: 0 0 8px; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.rf-items > li:last-child { border-bottom: none; padding-bottom: 0; }
.rf-empty-line { font-size: 13px; color: var(--text3); }

/* the red flags: first, never colour only (the heading says it) */
.rf-flags { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 6%, var(--surface)); }
.rf-flags .rf-sech { color: var(--danger); }
.rf-flags .rf-quote { border-left-color: var(--danger); }

/* the decision */
.rf-decide { border-color: color-mix(in srgb, var(--accent) 34%, var(--border)); box-shadow: inset 3px 0 0 var(--accent), var(--shadow-sm); }
.rf-seg { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 10px 0 12px; }
.rf-seg-opt { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; transition: border-color .14s, background .14s; }
.rf-seg-opt:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.rf-seg-opt[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-tint); box-shadow: inset 0 0 0 1px var(--accent); }
.rf-seg-opt.is-decline[aria-pressed="true"] { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); box-shadow: inset 0 0 0 1px var(--danger); }
.rf-seg-name { font-weight: 600; font-size: 13px; color: var(--text); }
.rf-seg-sub { font-size: 11px; color: var(--text3); }
.rf-suggested { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.rf-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rf-row.end { justify-content: flex-end; }
.rf-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-bottom: 12px; }
.rf-field { display: flex; flex-direction: column; gap: 4px; }

/* completeness */
.rf-check { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 4px 8px; align-items: start; }
.rf-mark { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; margin-top: 1px; }
.rf-mark.present { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success-ink); }
.rf-mark.missing { background: color-mix(in srgb, var(--warning) 18%, transparent); color: color-mix(in srgb, var(--warning) 60%, var(--text)); }
.rf-mark.not_applicable { background: var(--surface2); color: var(--text3); }
.rf-check-label { font-size: 13px; font-weight: 600; color: var(--text); }
.rf-check-state { font-weight: 400; color: var(--text2); }
.rf-note { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface2); font-size: 13px; color: var(--text2); }
.rf-note.warn { background: color-mix(in srgb, var(--warning) 10%, var(--surface)); color: var(--text); border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--border)); }

/* letters */
.rf-letter { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface); }
.rf-letter + .rf-letter { margin-top: 10px; }
.rf-letter-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.rf-letter-title { font-weight: 600; font-size: 13px; color: var(--text); }
.rf-letter pre { white-space: pre-wrap; font-family: var(--app-font); font-size: 13px; color: var(--text); background: var(--surface2); border-radius: var(--radius-sm); padding: 10px 12px; }

/* criteria and settings */
.rf-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rf-table th { text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text3); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.rf-table td { padding: 8px; border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent); vertical-align: top; color: var(--text); }
.rf-table tr:last-child td { border-bottom: none; }
.rf-terms { color: var(--text2); font-size: 12px; }
.rf-consent { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text); margin: 10px 0; }
.rf-consent input { margin-top: 3px; }
.rf-empty { text-align: center; padding: 40px 24px; }
.rf-empty p + p { margin-top: 6px; }
.rf-hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--text3); word-break: break-all; }
.rf-back { display: none; }

/* ---- phone width: one column, the open referral replaces the list ---- */
@media (max-width: 760px) {
  .app-header { padding: 0 12px; }
  .brand-name { display: none; }
  .rf-page-title { border-left: none; padding-left: 0; margin-left: 0; }
  .rf-tabs { padding: 0 8px; }
  .rf-main { grid-template-columns: minmax(0, 1fr); padding: 12px 12px 28px; }
  .rf-list { position: static; max-height: none; overflow: visible; }
  .rf-main.has-open .rf-list { display: none; }
  .rf-main:not(.has-open) .rf-view { display: none; }
  .rf-main.is-wide .rf-view { display: flex; }
  .rf-back { display: inline-flex; }
  .rf-seg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-body { padding: 14px; }
  .rf-table thead { display: none; }
  .rf-table, .rf-table tbody, .rf-table tr, .rf-table td { display: block; width: 100%; }
  .rf-table tr { padding: 8px 0; border-bottom: 1px solid var(--border); }
  .rf-table td { border: none; padding: 2px 0; }
}
.rf-letter textarea { min-height: 300px; }
