/* Intake uses the existing navigation rail. It never reserves a row above the inbox or reader. */
#khcIntake, #khcIntakeDialog {
  --intake-green: #16745c; --intake-ready-line: #bedbd0; --intake-ready-soft: #eaf6f0;
  --intake-violet: #6553ad; --intake-help-line: #d8cfed; --intake-help-soft: #f3f0fa;
  --intake-text: #203f50; --intake-muted: #5c7180; --intake-cord: #8e9899;
  color: var(--intake-text);
}
[data-theme="dark"] #khcIntake, [data-theme="dark"] #khcIntakeDialog {
  --intake-green: #238568; --intake-ready-line: #375f51; --intake-ready-soft: #19372e;
  --intake-violet: #b2a1ef; --intake-help-line: #51496b; --intake-help-soft: #2c2741;
  --intake-text: #e5edf4; --intake-muted: #aec0ce; --intake-cord: #a5b4b8;
}
#khcIntake { overflow: hidden; margin: 0 0 12px; padding: 0 0 10px; border-bottom: 1px solid var(--line); min-width: 0; }
#khcIntake[hidden], #khcIntake [hidden], .intake-entry[hidden] { display: none !important; }
#khcIntake button, #khcIntakeDialog button { font: inherit; cursor: pointer; }
#khcIntake button:focus-visible, #khcIntake summary:focus-visible, .intake-entry:focus-visible, #khcIntakeDialog button:focus-visible { outline: 3px solid var(--accent, #2468a3); outline-offset: 2px; }
#khcIntake button:disabled { cursor: default; opacity: .42; }
.intake-tray-head { display: flex; align-items: center; gap: 3px; }
#khcIntakeToggle { display: flex; align-items: center; flex: 1; min-width: 0; gap: 7px; min-height: 34px; padding: 4px 3px; background: none; border: 0; color: var(--intake-text); text-align: left; font-weight: 700 !important; font-size: 13px !important; }
.intake-title-mark { display: grid; place-items: center; flex: none; width: 21px; height: 21px; border-radius: 7px; background: var(--intake-ready-soft); color: var(--intake-green); }
.intake-chevron { margin-left: auto; color: var(--intake-muted); font-size: 16px; }
#khcIntakePopout { display: grid; place-items: center; width: 28px; height: 30px; border: 0; border-radius: 6px; background: none; color: var(--intake-muted); font-size: 19px !important; }
#khcIntakePopout:hover { background: var(--surface-2); }
.intake-counts { display: flex; flex-wrap: wrap; gap: 5px; padding: 2px 3px 0; }
#khcIntake .intake-count { padding: 3px 7px; border: 1px solid transparent; border-radius: 6px; font-size: 11px; font-weight: 650; line-height: 1.3; white-space: nowrap; }
.intake-ready-count { color: var(--intake-green); background: var(--intake-ready-soft); }
.intake-help-count { color: var(--intake-violet); background: var(--intake-help-soft); }
#khcIntake .intake-count[aria-pressed="true"] { border-color: currentColor; }
#khcIntakePanel { padding: 0 0 1px; }
.intake-rope-viewport { position: relative; padding: 42px 9px 14px; overflow: visible; isolation: isolate; }
.intake-rope { position: absolute; top: 0; left: 0; width: 100%; height: 42px; overflow: visible; pointer-events: none; }
.intake-rope circle { fill: var(--surface); stroke: #9ba8ac; stroke-width: 1.2; }
.intake-rope path { fill: none; stroke: var(--intake-cord); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.intake-rope .intake-rope-shadow { stroke: #183b471b; stroke-width: 4; }
.intake-rope .intake-rope-highlight { stroke: #e0e6e4; stroke-width: .65; }
#khcReady, #khcIntakeHelp { display: block; min-width: 0; }
#khcIntake .khc-ready-card, #khcIntake .intake-help-card { position: relative; padding: 0; border: 0; background: none; min-width: 0; width: 100%; overflow-wrap: anywhere; }
.intake-hanging-card { position: relative; transform-origin: 50% -17px; }
/* Small steel wire handle and a graphite binder jaw, rather than a wooden peg. */
.intake-pin { position: absolute; z-index: 4; left: calc(50% - 11px); top: -25px; width: 22px; height: 29px; filter: drop-shadow(0 1px 1px #233c4a30); pointer-events: none; }
.intake-pin::before { content: ''; position: absolute; left: 6px; top: 0; width: 10px; height: 20px; box-sizing: border-box; border: 2px solid #a5b2bc; border-left-color: #d5dfe4; border-right-color: #7b909e; border-radius: 5px 5px 3px 3px; box-shadow: inset 0 0 0 .5px #ecf1f3; }
.intake-pin::after { content: ''; position: absolute; left: 2px; top: 17px; width: 18px; height: 10px; background: linear-gradient(#6e8797 0 1px, #304b5c 2px, #233d4d); clip-path: polygon(12% 0,88% 0,100% 100%,0 100%); border-radius: 2px; transform-origin: 20% 0; }
#khcIntake .intake-chart-sheet, #khcIntake .intake-help-sheet { position: relative; width: 100%; border: 1px solid var(--intake-ready-line); border-top: 3px solid var(--intake-green); border-radius: 7px; background: var(--surface); box-shadow: 0 4px 8px #24445513, 0 1px 2px #24445513; }
#khcIntake .intake-chart-sheet { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: start; gap: 10px 7px; padding: 13px 10px 10px; min-height: 150px; }
.intake-avatar { display: grid; place-items: center; position: relative; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--intake-green); color: white; font-size: 10px; font-weight: 700; }
.khc-ready-info, .intake-help-identity > div { min-width: 0; }
.khc-ready-name, .intake-help-name { margin: 0; color: var(--intake-text); font-size: 13px; line-height: 1.3; font-weight: 700; }
.khc-ready-when, .khc-ready-sub, .intake-help-meta { margin: 4px 0 0; color: var(--intake-muted); font-size: 11px; line-height: 1.4; }
.intake-time { color: var(--intake-text); font-weight: 700; font-variant-numeric: tabular-nums; }
.khc-ready-sub { display: flex; flex-wrap: wrap; gap: 3px 6px; }
.intake-patient-type { font-size: 10px; font-weight: 600; padding: 1px 4px; border-radius: 3px; background: var(--intake-ready-soft); color: var(--intake-text); }
#khcIntake .intake-chart-sheet > button { grid-column: 1 / -1; align-self: end; width: 100%; min-height: 36px; padding: 7px; border: 0; border-radius: 5px; background: var(--intake-green); color: white; font-size: 12px; font-weight: 650; }
#khcIntake .intake-chart-sheet > button:hover:not(:disabled) { background: color-mix(in srgb, var(--intake-green) 88%, black); }
.khc-ready-error { margin: 6px 0 0; color: var(--danger); font-size: 11px; }
#khcIntake .intake-help-sheet { padding: 11px 9px 9px; border-color: var(--intake-help-line); border-top-color: var(--intake-violet); background: color-mix(in srgb, var(--intake-help-soft) 35%, var(--surface)); }
.intake-help-identity { display: flex; align-items: center; gap: 7px; }
.intake-help-card .intake-avatar { background: var(--intake-violet); }
.intake-help-meta, .intake-help-body { font-size: 11px; }
.intake-progress-label { display: flex; justify-content: space-between; gap: 8px; margin: 8px 0 3px; color: var(--intake-muted); font-size: 10px; }
.intake-progress-label b { color: var(--intake-text); }
.intake-progress { height: 4px; background: var(--intake-help-line); border-radius: 8px; overflow: hidden; }
.intake-progress > span { display: block; height: 100%; background: var(--intake-violet); border-radius: inherit; }
.intake-help-prompt { margin: 6px 0; font-size: 11px; line-height: 1.4; color: var(--intake-text); }
.intake-help-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; }
#khcIntake .intake-help-actions .btn { min-height: 32px; padding: 5px 6px; border-radius: 5px; border: 1px solid var(--intake-help-line); background: var(--surface); color: var(--intake-text); font-size: 10px; }
#khcIntake .intake-help-actions [data-draft-act]:first-child { background: var(--intake-violet); color: white; border-color: transparent; }
#khcIntake .intake-help-actions [data-later] { margin-left: auto; background: none; border: 0; color: var(--intake-muted); }
.intake-help-details { margin-top: 6px; color: var(--intake-muted); font-size: 10px; line-height: 1.4; }
.intake-help-details summary { cursor: pointer; padding: 3px 0; }
.intake-help-details p { margin: 5px 0; }
[data-theme="dark"] #khcIntake .intake-help-actions [data-draft-act]:first-child, [data-theme="dark"] .intake-help-card .intake-avatar { color: #211737; }
.intake-tray-controls { display: flex; align-items: center; justify-content: center; gap: 7px; }
#khcIntake .intake-tray-controls button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--intake-text); font-size: 19px; line-height: 1; }
#khcIntakePosition { color: var(--intake-muted); font-size: 11px; min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
#khcIntake #khcIntakeMotion { margin-left: 3px; font-size: 12px; color: var(--intake-muted); }
.intake-announcement, .intake-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@keyframes intake-wind { 0%,100% { transform: rotate(-1.7deg); } 45% { transform: rotate(1.7deg); } 75% { transform: rotate(-.35deg); } }
@media (prefers-reduced-motion: no-preference) {
  .intake-hanging-card { animation: intake-wind 6.4s ease-in-out -1.1s infinite; }
  .khc-ready-card:nth-child(2n) .intake-hanging-card { animation-duration: 7.1s; animation-delay: -3.7s; animation-direction: reverse; }
  .intake-help-card .intake-hanging-card { animation-duration: 6.9s; animation-delay: -4.2s; animation-direction: reverse; }
}
#khcIntake.intake-wind-paused .intake-hanging-card,
#khcIntake article:hover .intake-hanging-card, #khcIntake article:focus-within .intake-hanging-card,
#khcIntake .intake-help-card:hover .intake-hanging-card, #khcIntake .intake-help-card:focus-within .intake-hanging-card { animation-play-state: paused; }
#khcIntake .is-filing .intake-hanging-card { animation: none; }
#khcIntake .is-filing .intake-pin::after { transform: rotate(-16deg) translateY(-2px); transition: transform .1s ease; }
.intake-flight-scene { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.intake-flight-card { transform-origin: 50% 5%; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .intake-hanging-card { animation: none !important; transform: none !important; } }
/* Small access points when the navigation rail is unavailable. No extra workspace row. */
.intake-entry { display: none; align-items: center; gap: 5px; flex: none; min-height: 34px; padding: 5px 8px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 11px; cursor: pointer; }
.intake-entry b { display: grid; place-items: center; min-width: 19px; height: 19px; padding: 0 4px; border-radius: 6px; background: #d9f2e6; color: #185c45; font-size: 11px; }
.app:has(.body.left-rail-min) #khcIntakeEntry, .app:has(.ap-inbox-layout) #khcIntakeEntry { display: inline-flex; }
.app:has(.ap-inbox-layout) #tabs > #khcIntake { display: none; }
.detail.expanded #khcIntakeReaderEntry { display: inline-flex; }
@media (max-width: 1100px) { .detail.open #khcIntakeReaderEntry { display: inline-flex; } }
@media (max-width: 760px) { #khcIntakeEntry { display: inline-flex; } }
@media (max-width: 600px) {
  #khcIntakeReaderEntry { flex-direction: column; gap: 0; min-width: 34px; min-height: 38px; padding: 2px 4px; }
  #khcIntakeReaderEntry .intake-entry-label { font-size: 8px; line-height: 1.1; }
  #khcIntakeReaderEntry b { height: 16px; min-width: 16px; font-size: 10px; }
  #khcIntakeEntry { padding: 4px; gap: 3px; font-size: 10px; }
}
/* The larger view opens only on request; the browser provides focus isolation. */
#khcIntakeDialog { width: min(350px, calc(100vw - 28px)); max-height: min(640px, calc(100dvh - 32px)); padding: 15px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: 0 20px 80px #122d3f40; overflow: auto; }
#khcIntakeDialog::backdrop { background: #142b3d40; }
.intake-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.intake-dialog-head h2 { margin: 0; font-size: 17px; color: var(--intake-text); }
#khcIntakeClose { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 8px; background: var(--surface-2); color: var(--intake-text); font-size: 24px !important; }
#khcIntake.intake-in-dialog { margin: 0; padding: 0; border: 0; }
.intake-in-dialog .intake-tray-head { display: none; }
.intake-in-dialog .intake-counts { margin-top: 8px; }
.intake-in-dialog .intake-chart-sheet { min-height: 170px !important; padding: 16px !important; }
.intake-in-dialog .intake-help-sheet { padding: 15px !important; }
.intake-in-dialog .khc-ready-name, .intake-in-dialog .intake-help-name { font-size: 16px; }
.intake-in-dialog .intake-help-prompt, .intake-in-dialog .intake-help-meta, .intake-in-dialog .intake-help-body { font-size: 12px; }
.intake-dialog-note { margin: 13px 0 0; color: var(--intake-muted); font-size: 11px; text-align: center; }
@media (max-width: 600px) { #khcIntakeDialog { width: calc(100vw - 20px); margin: auto auto 10px; max-height: calc(100dvh - 24px); } }

/* A facility is a simultaneous waiting-room board, never a patient carousel. */
.intake-facility { margin: 0 3px 5px; color: var(--intake-muted); font-size: 11px; }
.intake-rope-viewport { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 25px 8px; padding: 27px 4px 9px; }
.intake-rope-viewport > section, #khcReady, #khcIntakeHelp { display: contents; }
#khcIntake .khc-ready-card::before, #khcIntake .intake-help-card::before {
  content: ''; position: absolute; top: -20px; left: -4px; right: -4px; height: 21px; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 21' preserveAspectRatio='none'%3E%3Cpath d='M0 5 Q80 13 160 5' fill='none' stroke='%23213d4918' stroke-width='3.5'/%3E%3Cpath d='M0 4 Q80 12 160 4' fill='none' stroke='%2396a1a3' stroke-width='2'/%3E%3Cpath d='M0 3.5 Q80 11.5 160 3.5' fill='none' stroke='%23dfe6e5' stroke-width='.6'/%3E%3C/svg%3E") center / 100% 21px no-repeat;
}
.intake-hanging-card { transform-origin: 50% -12px; }
.intake-pin { top: -20px; left: calc(50% - 9px); width: 18px; height: 24px; }
.intake-pin::before { left: 5px; width: 8px; height: 16px; border-width: 1.5px; border-radius: 4px; }
.intake-pin::after { left: 2px; top: 14px; width: 14px; height: 8px; }
#khcIntake .intake-chart-sheet { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 7px 7px; min-height: 104px; }
#khcIntake .intake-chart-sheet .intake-avatar, #khcIntake .intake-help-sheet .intake-avatar { display: none; }
#khcIntake .khc-ready-name, #khcIntake .intake-help-name { font-size: 13px; line-height: 1.3; }
#khcIntake .khc-ready-when, #khcIntake .intake-help-meta { font-size: 11px; margin-top: 4px; }
#khcIntake .intake-dob, #khcIntake .intake-appointment { display: flex; flex-wrap: wrap; column-gap: 4px; margin: 3px 0 0; color: var(--intake-text); font-size: 11px; line-height: 1.4; font-variant-numeric: tabular-nums; }
#khcIntake .intake-field-label { color: var(--intake-muted); font-size: 10px; font-weight: 500; }
#khcIntake .intake-dob > span:last-child { font-weight: 650; }
#khcIntake .khc-ready-when .intake-time, #khcIntake .intake-help-meta .intake-time { font-size: 11px; }
#khcIntake .khc-ready-sub { display: none; }
#khcIntake .intake-chart-sheet > button { min-height: 30px; padding: 5px 2px; font-size: 11px; margin-top: auto; }
#khcIntake .intake-help-sheet { min-height: 104px; padding: 10px 7px 7px; }
#khcIntake .intake-help-prompt, #khcIntake .intake-help-actions, #khcIntake .intake-help-details, #khcIntake .intake-progress-label { display: none; }
#khcIntake .intake-progress { margin: 7px 0; }
#khcIntake .intake-help-open { width: 100%; min-height: 30px; padding: 5px 2px; font-size: 11px; border: 0; border-radius: 5px; background: var(--intake-violet); color: #fff; }
[data-theme="dark"] #khcIntake .intake-help-open { color: #211737; }
.intake-tray-controls { justify-content: space-between; padding: 1px 4px 0; }
.intake-tray-controls > span { font-size: 10px; color: var(--intake-muted); }
@media (min-width: 1101px) {
  .app.intake-board-open { --intake-rail-w: clamp(320px, 28vw, 420px); --intake-reader-w: min(var(--reader-w), calc(100vw - var(--intake-rail-w) - 360px)); }
  .app.intake-board-open .body:not(.left-rail-min):not(:has(.ap-inbox-layout)) { --rail-w: var(--intake-rail-w); }
  .app.intake-board-open:has(.body:not(.left-rail-min)):not(:has(.ap-inbox-layout)) .detail:not(.expanded) { width: var(--intake-reader-w); }
  .app.intake-board-open:has(.detail.open:not(.expanded)):has(.body:not(.left-rail-min)):not(:has(.ap-inbox-layout)) .body { margin-right: var(--intake-reader-w); }
  .app.intake-board-open:has(.body:not(.left-rail-min)):not(:has(.ap-inbox-layout)) .reader-w-resize { right: var(--intake-reader-w); }
}
@media (min-width: 1360px) { .intake-rope-viewport { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
#khcIntakeDialog { width: min(740px, calc(100vw - 28px)); }
.intake-in-dialog .intake-rope-viewport { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#khcIntake.intake-in-dialog .intake-chart-sheet { min-height: 112px !important; padding: 12px !important; }
#khcIntake.intake-in-dialog .khc-ready-name, #khcIntake.intake-in-dialog .intake-help-name { font-size: 14px; }
#khcIntake.intake-in-dialog .intake-help-card { grid-column: 1 / -1; }
#khcIntake.intake-in-dialog .intake-help-prompt, #khcIntake.intake-in-dialog .intake-help-details { display: block; }
#khcIntake.intake-in-dialog .intake-help-actions, #khcIntake.intake-in-dialog .intake-progress-label { display: flex; }
#khcIntake.intake-in-dialog .intake-help-open { display: none; }
#khcIntake.intake-in-dialog .intake-help-meta { font-size: 11px; }
#khcIntake.intake-in-dialog .intake-help-actions .btn { min-height: 36px; font-size: 12px; padding: 6px 10px; }
@media (max-width: 600px) { .intake-in-dialog .intake-rope-viewport { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Keep a compact, truthful status visible when the facility has no eligible intake cards. */
.intake-feed-status { margin: 7px 3px 3px; padding: 10px 11px; border-radius: 9px; background: var(--intake-ready-soft); color: var(--intake-text); font-size: 12px; line-height: 1.45; }
#khcIntake.has-feed-error .intake-feed-status { background: var(--surface-2); border: 1px solid var(--line); }
#khcIntake.is-empty #khcIntakeToggle { opacity: 1; cursor: default; }
#khcIntake.is-empty .intake-chevron, #khcIntake.is-empty #khcIntakePopout, #khcIntake.is-empty .intake-counts { display: none; }

/* Appointment-driven emphasis grows in the grid, so cards never overlap their neighbours. */
#khcIntake { --intake-late-ink: #8b480d; --intake-late-line: #dca15b; --intake-late-soft: #fff2da; }
[data-theme="dark"] #khcIntake { --intake-late-ink: #ffd69b; --intake-late-line: #a57b45; --intake-late-soft: #3c2d1a; }
.intake-urgency { display: flex; flex-direction: column; gap: 4px; margin: 9px 3px 2px; padding: 10px 11px; border-left: 3px solid var(--intake-late-line); border-radius: 0 7px 7px 0; background: var(--intake-late-soft); color: var(--intake-late-ink); font-size: 12px; line-height: 1.4; }
.intake-urgency strong { font-weight: 750; }
.intake-urgency span { font-size: 11px; overflow-wrap: anywhere; }
#khcIntake.intake-escalating #khcIntakeToggle { cursor: default; }
#khcIntake.intake-escalating .intake-chevron { visibility: hidden; }
#khcIntake .intake-is-late .intake-chart-sheet, #khcIntake .intake-is-late .intake-help-sheet { border-color: var(--intake-late-line); border-top-color: var(--intake-late-ink); padding: calc(10px + var(--intake-late-progress, 0) * 8px) calc(7px + var(--intake-late-progress, 0) * 5px); }
#khcIntake .intake-is-late .intake-hanging-card { animation-duration: var(--intake-wind-duration, 6.4s); }
#khcIntake .intake-late-label { margin: 5px 0 3px; color: var(--intake-late-ink); font-size: 11px; line-height: 1.4; font-weight: 700; font-variant-numeric: tabular-nums; }
#khcIntake .intake-late-primary .intake-chart-sheet, #khcIntake .intake-late-primary .intake-help-sheet { min-height: calc(132px + var(--intake-late-progress, 0) * 70px); }
#khcIntake .intake-late-primary .khc-ready-name, #khcIntake .intake-late-primary .intake-help-name { font-size: calc(13px + var(--intake-late-progress, 0) * 9px); }
#khcIntake[data-late-stage="growing"] .intake-late-primary { grid-column: span 2; }
#khcIntake[data-late-stage="wide"] .intake-late-primary { grid-column: 1 / -1; }
@keyframes intake-wind { 0%,100% { transform: rotate(calc(-1 * var(--intake-wind-angle, 1.7deg))); } 45% { transform: rotate(var(--intake-wind-angle, 1.7deg)); } 75% { transform: rotate(-.35deg); } }
@media (min-width: 1101px) {
  .app.intake-board-open { --intake-rail-w: clamp(320px, calc(28vw + var(--intake-escalation-progress, 0) * 13vw), 590px); }
}
/* At thirty minutes cards float over the working inbox; the transparent gaps pass clicks through. */
#khcIntake.intake-overlay:not(.intake-in-dialog) { position: fixed; z-index: 48; top: var(--intake-overlay-top, 90px); left: var(--intake-overlay-left, 280px); width: var(--intake-overlay-width, calc(100vw - 292px)); display: block !important; margin: 0; padding: 0 22px 14px; border: 0; border-radius: 0; background: transparent; box-shadow: none; overflow: visible; pointer-events: none; }
#khcIntake.intake-overlay[hidden] { display: none !important; }
#khcIntake.intake-overlay { --intake-late-ink: #9e3034; --intake-late-line: #cc7775; --intake-late-soft: #fff0ec; }
[data-theme="dark"] #khcIntake.intake-overlay { --intake-late-ink: #ffb8ad; --intake-late-line: #a9615d; --intake-late-soft: #422623; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-tray-head { display: inline-flex; padding: 3px 7px; gap: 8px; border: 1px solid var(--intake-late-line); border-radius: 8px; background: var(--surface); box-shadow: 0 3px 10px #17384b20; pointer-events: auto; }
#khcIntake.intake-overlay:not(.intake-in-dialog) #khcIntakeToggle { flex: none; font-size: 15px !important; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-facility { display: inline-block; margin: 0 8px; padding: 4px 7px; border-radius: 5px; background: var(--surface); }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-counts { display: inline-flex; vertical-align: middle; padding: 0; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-count { pointer-events: auto; box-shadow: 0 2px 7px #17384b15; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-urgency { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; clip-path: inset(50%); }
#khcIntake.intake-overlay:not(.intake-in-dialog) #khcIntakePanel { display: block; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-rope-viewport { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-auto-flow: row dense; gap: 34px; padding: 31px 8px 14px; overflow: visible; align-items: start; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary { grid-column: span 2; grid-row: span 2; margin: 0; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-hanging-card { pointer-events: auto; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-hanging-card { --intake-wind-angle: 4deg; animation-duration: 3.4s; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-chart-sheet,
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-help-sheet { min-height: 270px; padding: 22px 20px 18px; box-shadow: 0 7px 18px #17384b2b; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .khc-ready-name,
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-help-name { font-size: clamp(22px, 2vw, 29px); line-height: 1.2; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-dob,
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-appointment { font-size: 16px; margin-top: 9px; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-field-label,
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-time { font-size: 14px; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-late-label { margin-top: 16px; font-size: 15px; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-chart-sheet > button,
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-help-open { min-height: 42px; margin-top: 13px; padding: 10px; font-size: 14px; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-tray-controls { position: absolute; top: 2px; right: 22px; padding: 3px 5px 3px 9px; gap: 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 2px 7px #17384b15; pointer-events: auto; }
#khcIntake.intake-overlay:not(.intake-in-dialog) .intake-tray-controls > span { font-size: 11px; }
#khcIntake.intake-overlay:not(.intake-in-dialog) #khcIntakeMotion { min-width: 32px; min-height: 32px; }
@media (max-width: 1279px), (max-height: 760px) {
  #khcIntake.intake-overlay:not(.intake-in-dialog) { width: min(420px, var(--intake-overlay-width, calc(100vw - 24px))); padding: 0 20px 12px; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-tray-controls { position: static; display: inline-flex; margin-top: 5px; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-rope-viewport { display: block; padding: 30px 10px 10px; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) article:not(.intake-late-primary) { display: none; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-chart-sheet,
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-help-sheet { min-height: 210px; padding: 18px; }
}
@media (max-width: 760px) {
  #khcIntake.intake-overlay:not(.intake-in-dialog) { width: min(310px, var(--intake-overlay-width, calc(100vw - 16px))); padding: 0 14px 8px; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-facility { display: none; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-counts { margin-top: 5px; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-chart-sheet,
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-help-sheet { min-height: 185px; padding: 14px; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .khc-ready-name,
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-help-name { font-size: 22px; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-dob,
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-appointment { font-size: 14px; margin-top: 5px; }
}
@media (prefers-reduced-motion: reduce) { #khcIntake .intake-hanging-card { animation: none !important; transform: none !important; } }

/* The explanation is requested only after an explicit Taken back action. */
#khcLateReasonDialog { width: min(490px, calc(100vw - 28px)); max-height: calc(100dvh - 32px); margin: auto; padding: 25px; overflow: auto; color: var(--text, #203f50); background: var(--surface, #fff); border: 1px solid var(--line, #cbd5df); border-radius: 15px; box-shadow: 0 18px 70px #132e4845; }
#khcLateReasonDialog::backdrop { background: #132e4860; }
.intake-late-form { display: flex; flex-direction: column; gap: 13px; margin: 0; }
.intake-late-heading { display: flex; align-items: flex-start; gap: 12px; }
.intake-late-heading h2 { margin: 0 0 5px; font-size: 20px; line-height: 1.25; }
.intake-late-heading p { margin: 0; color: var(--muted, #5c7180); font-size: 13px; line-height: 1.45; }
.intake-late-mark { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border: 1px solid #e0b275; border-radius: 50%; background: #fff2db; color: #844a14; font-size: 20px; font-weight: 750; }
.intake-late-patient { display: flex; flex-direction: column; gap: 5px; padding: 12px 14px; border: 1px solid var(--line, #cbd5df); border-radius: 8px; background: var(--surface-2, #f4f7fa); overflow-wrap: anywhere; }
.intake-late-patient strong { font-size: 16px; line-height: 1.3; }
.intake-late-patient span { color: var(--muted, #5c7180); font-size: 12px; line-height: 1.45; font-variant-numeric: tabular-nums; }
.intake-late-form > label { font-size: 13px; font-weight: 700; margin-bottom: -7px; }
#khcLateReason { box-sizing: border-box; width: 100%; min-height: 126px; padding: 11px 12px; resize: vertical; border: 1px solid var(--line, #b8c6d1); border-radius: 8px; background: var(--surface, #fff); color: var(--text, #203f50); font: inherit; font-size: 14px; line-height: 1.5; }
#khcLateReason:focus-visible, #khcLateReasonDialog button:focus-visible { outline: 3px solid var(--accent, #2468a3); outline-offset: 3px; }
.intake-late-hint { margin: -5px 0 0; color: var(--muted, #5c7180); font-size: 12px; line-height: 1.5; }
.intake-late-error { margin: 0; color: var(--danger, #ae3038); font-size: 13px; line-height: 1.45; }
.intake-late-error:empty { display: none; }
.intake-late-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; margin-top: 3px; }
#khcLateReasonDialog button { min-height: 40px; padding: 9px 13px; border: 1px solid var(--line, #b8c6d1); border-radius: 7px; background: var(--surface, #fff); color: var(--text, #203f50); font: inherit; font-size: 13px; font-weight: 650; cursor: pointer; }
#khcLateReasonDialog [data-save] { border-color: transparent; background: var(--brand, #185d79); color: #fff; }
#khcLateReasonDialog button:disabled { opacity: .5; cursor: default; }
[data-theme="dark"] .intake-late-mark { background: #3c2d1a; color: #ffd69b; border-color: #a57b45; }
@media (max-width: 600px) { #khcLateReasonDialog { padding: 20px 17px; } #khcLateReason { font-size: 16px; } .intake-late-actions { flex-wrap: wrap; } .intake-late-actions [data-save] { flex: 1; } }
/* Reserve space for the larger swing instead of allowing neighbouring cards to collide. */
#khcIntake.intake-escalating:not(.intake-overlay) .intake-rope-viewport { column-gap: 20px; padding-left: 14px; padding-right: 14px; }
#khcIntake.intake-escalating .intake-late-primary { order: -1; }

/* Secondary late cards stay compact; their labels remain visible beside the dominant card. */
#khcIntake.intake-overlay:not(.intake-in-dialog) article:not(.intake-late-primary) .intake-chart-sheet,
#khcIntake.intake-overlay:not(.intake-in-dialog) article:not(.intake-late-primary) .intake-help-sheet { padding: 10px 7px 7px; }
#khcIntake.intake-overlay:not(.intake-in-dialog) article:not(.intake-late-primary) .intake-late-label { font-size: 10px; margin: 5px 0 0; }
@media (max-height: 760px) {
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-chart-sheet,
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-help-sheet { min-height: 170px; padding: 14px; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .khc-ready-name,
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-help-name { font-size: 22px; }
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-dob,
  #khcIntake.intake-overlay:not(.intake-in-dialog) .intake-late-primary .intake-appointment { font-size: 14px; margin-top: 5px; }
}

/* Schedule links are explicit and separate from completing or rooming an intake. */
#khcIntake .intake-match-row { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 4px; margin-top: 5px; }
#khcIntake .intake-match-status { color: var(--intake-muted); font-size: 9px; line-height: 1.3; white-space: nowrap; }
#khcIntake .intake-match-status[hidden] { display: none; }
#khcIntake .intake-match-status.needs-review { color: #a24b17; font-weight: 700; }
#khcIntake .intake-match-button { min-height: 24px; padding: 3px 4px; border: 1px solid var(--intake-line, var(--line)); border-radius: 5px; background: var(--surface); color: var(--intake-text); font: inherit; font-size: 9px; font-weight: 650; line-height: 1.3; cursor: pointer; }
#khcIntake .intake-match-button:hover { border-color: var(--brand, #185d79); }
#khcIntake .intake-match-button:focus-visible { outline: 3px solid var(--accent, #2468a3); outline-offset: 2px; }
#khcIntake .intake-late-primary .intake-match-row, #khcIntake.intake-in-dialog .intake-match-row { gap: 4px 7px; margin-top: 8px; }
#khcIntake .intake-late-primary .intake-match-button, #khcIntake.intake-in-dialog .intake-match-button { min-height: 30px; padding: 5px 7px; font-size: 11px; }
#khcIntake .intake-late-primary .intake-match-status, #khcIntake.intake-in-dialog .intake-match-status { font-size: 11px; }
[data-theme="dark"] #khcIntake .intake-match-status.needs-review { color: #f4be81; }
/* Compact cards already say Change match / Rematch schedule on the action itself.
   Keep the full status on the prominent card and in the expanded patient board. */
#khcIntake.intake-overlay:not(.intake-in-dialog) article:not(.intake-late-primary) .intake-match-status { display: none; }

#khcIntakeMatchDialog { box-sizing: border-box; width: min(620px, calc(100vw - 28px)); max-height: calc(100dvh - 32px); margin: auto; padding: 24px; overflow: auto; color: var(--text, #203f50); background: var(--surface, #fff); border: 1px solid var(--line, #cbd5df); border-radius: 15px; box-shadow: 0 18px 70px #132e4845; }
#khcIntakeMatchDialog::backdrop { background: #132e4860; }
.intake-match-form { display: flex; flex-direction: column; gap: 15px; margin: 0; }
.intake-match-heading h2 { margin: 0 0 7px; font-size: 22px; line-height: 1.25; }
.intake-match-heading p { margin: 4px 0 0; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.intake-match-context { color: var(--muted, #5c7180); }
.intake-match-entered { font-weight: 650; }
.intake-match-explanation { margin: 0; color: var(--muted, #5c7180); font-size: 13px; line-height: 1.5; }
.intake-match-candidates { min-width: 0; padding: 0; margin: 0; border: 0; }
.intake-match-candidates legend { padding: 0; margin-bottom: 8px; font-size: 13px; font-weight: 700; }
.intake-match-list { display: flex; flex-direction: column; gap: 7px; }
.intake-match-list > p { margin: 0; font-size: 13px; line-height: 1.5; }
.intake-match-candidate { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; padding: 11px 12px; border: 1px solid var(--line, #cbd5df); border-radius: 8px; cursor: pointer; }
.intake-match-candidate:has(input:checked) { border-color: var(--brand, #185d79); background: var(--surface-2, #f4f7fa); box-shadow: inset 3px 0 var(--brand, #185d79); }
.intake-match-candidate input { flex: none; width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--brand, #185d79); }
.intake-match-candidate > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.intake-match-candidate strong { font-size: 14px; line-height: 1.4; }
.intake-match-suggested { display: inline-block; margin-left: 8px; color: var(--muted, #5c7180); font-size: 11px; }
.intake-match-meta, .intake-match-reasons { display: block; margin-top: 4px; color: var(--muted, #5c7180); font-size: 12px; line-height: 1.45; }
.intake-match-reasons { font-size: 11px; }
.intake-match-preview { padding: 14px; border: 1px solid var(--line, #cbd5df); border-radius: 9px; background: var(--surface-2, #f4f7fa); overflow-wrap: anywhere; }
.intake-match-preview[hidden] { display: none; }
.intake-match-preview h3 { margin: 0 0 9px; font-size: 12px; font-weight: 700; color: var(--muted, #5c7180); }
.intake-match-preview > strong { font-size: 16px; }
.intake-match-preview p { margin: 5px 0 0; font-size: 13px; line-height: 1.45; }
.intake-match-preview > p > span { display: inline-block; min-width: 90px; color: var(--muted, #5c7180); }
.intake-match-preview .intake-match-review-note { margin-top: 10px; color: var(--muted, #5c7180); font-size: 12px; }
.intake-match-warning { margin-top: 12px; padding: 10px 12px; border: 1px solid #d8ad71; border-radius: 6px; background: #fff3df; color: #784311; }
.intake-match-warning p { margin: 0; font-size: 13px; font-weight: 650; }
.intake-match-warning p + p { margin-top: 7px; }
.intake-match-loading { color: var(--muted, #5c7180); }
.intake-match-error { margin: 0; color: var(--danger, #ae3038); font-size: 13px; line-height: 1.5; }
.intake-match-error:empty { display: none; }
.intake-match-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding-top: 2px; }
#khcIntakeMatchDialog button { min-height: 40px; padding: 9px 13px; border: 1px solid var(--line, #b8c6d1); border-radius: 7px; background: var(--surface, #fff); color: var(--text, #203f50); font: inherit; font-size: 13px; font-weight: 650; cursor: pointer; }
#khcIntakeMatchDialog [data-link] { background: var(--brand, #185d79); color: #fff; border-color: transparent; }
#khcIntakeMatchDialog button:disabled { opacity: .5; cursor: default; }
#khcIntakeMatchDialog :is(button,input):focus-visible { outline: 3px solid var(--accent, #2468a3); outline-offset: 3px; }
[data-theme="dark"] .intake-match-warning { background: #3c2d1a; color: #ffd69b; border-color: #a57b45; }
@media (max-width: 600px) { #khcIntakeMatchDialog { padding: 20px 16px; } .intake-match-heading h2 { font-size: 20px; } .intake-match-candidate { padding: 11px 9px; } .intake-match-suggested { display: block; margin: 3px 0 0; } .intake-match-actions [data-link] { flex: 1; } }
