:root {
  color-scheme: light;
  --navy: #071d34;
  --blue: #064d85;
  --focus: #ffd400;
  --ink: #111820;
  --muted: #4a5662;
  --paper: #ffffff;
  --ground: #edf1f4;
  --line: #111820;
  --danger: #9b111e;
  --success: #0a6b3f;
  --warning: #fff2b8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--ground); font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); }
body { margin: 0; min-width: 300px; line-height: 1.5; }
button, input, textarea, select { font: inherit; }
.skip-link { position: absolute; left: -10000px; top: auto; }
.skip-link:focus { left: 1rem; top: 1rem; z-index: 20; background: var(--focus); color: #000; padding: .75rem; border: 3px solid #000; }

.site-header { min-height: 76px; padding: 12px clamp(16px, 4vw, 48px); color: #fff; background: var(--navy); border-bottom: 6px solid var(--focus); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border: 3px solid #fff; color: var(--focus); font-size: 1.45rem; font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.2rem; letter-spacing: .02em; }
.brand small { color: #d9e8f5; }
.environment { border: 2px solid var(--focus); color: var(--focus); padding: 5px 8px; font-size: .75rem; font-weight: 900; letter-spacing: .12em; }

.shell { width: min(1120px, calc(100% - 32px)); margin: 28px auto 64px; }
.notice { border: 3px solid var(--line); padding: 18px 20px; margin-bottom: 22px; background: var(--paper); }
.notice h1 { margin: 0 0 8px; font-size: clamp(1.5rem, 4vw, 2.25rem); line-height: 1.1; }
.notice p { margin: 7px 0; }
.notice-warning { background: var(--warning); border-left-width: 12px; }
.notice-info { background: #e6f3ff; border-color: var(--blue); border-left-width: 9px; }
.message { border: 3px solid var(--line); background: white; padding: 14px 16px; margin: 0 0 20px; font-weight: 750; }
.message.error { border-color: var(--danger); color: var(--danger); }
.message.success { border-color: var(--success); color: var(--success); }

.auth-grid, .dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; align-items: start; }
.panel { background: var(--paper); border: 3px solid var(--line); box-shadow: 8px 8px 0 #aeb9c4; padding: clamp(20px, 4vw, 34px); }
.panel-secondary { border-color: var(--blue); }
.panel-heading { border-bottom: 3px solid var(--line); margin: -4px 0 24px; padding-bottom: 15px; }
.panel h2 { font-size: 1.5rem; line-height: 1.2; margin: 2px 0 8px; }
.panel p { color: var(--muted); }
.eyebrow { margin: 0; color: var(--blue) !important; font-weight: 900; letter-spacing: .12em; font-size: .75rem; }

.field, form, fieldset, .panel, .dashboard-grid > * { min-width: 0; }
.field { margin: 0 0 18px; }
.field label, .code-form label { display: block; font-weight: 900; color: var(--ink); margin-bottom: 4px; }
.field-help { margin: 0 0 7px !important; font-size: .875rem; color: var(--muted); }
input, textarea, select { width: 100%; max-width: 100%; min-width: 0; border: 3px solid var(--line); border-radius: 0; background: #fff; color: #000; padding: 12px 13px; min-height: 50px; font-family: ui-sans-serif, system-ui, sans-serif; font-weight: 650; }
input[type="file"] { overflow: hidden; }
/* WebKit/iOS miscalculates width:100% for temporal controls with inline padding. */
input[type="date"] { inline-size: 100%; min-inline-size: 0; padding-inline: 0; }
input[type="date"]::-webkit-date-and-time-value { min-width: 0; text-align: left; }
select { overflow-x: hidden; text-overflow: ellipsis; }
input[readonly], textarea[readonly], select:disabled { background: #edf1f4; color: var(--ink); cursor: not-allowed; opacity: 1; }
textarea { min-height: 104px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #687481; opacity: 1; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-weight: 400; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 5px solid var(--focus); outline-offset: 2px; }
input:invalid:not(:placeholder-shown), textarea:invalid:not(:placeholder-shown) { border-color: var(--danger); }
/* Mobile first: fields occupy one row unless there is room for another 350 px column. */
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 350px), 1fr)); gap: 16px; }
#surgery-request-panel .field-row { grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); }
#surgery-request-panel label { min-width: 0; }
#surgery-request-panel input:not([type="checkbox"]), #surgery-request-panel select { width: 100%; min-width: 0; }
#nursing-shifts-panel .field-row { grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); }
#nursing-shifts-panel label { min-width: 0; }
#nursing-shifts-panel input, #nursing-shifts-panel select { width: 100%; min-width: 0; }
.phone-fields { display: grid; grid-template-columns: minmax(170px, .9fr) minmax(160px, 1.1fr); gap: 10px; }
.upload-group { border: 3px solid var(--line); padding: 18px; margin: 0 0 22px; }
.upload-group legend { font-weight: 900; padding: 0 8px; }
.analysis-result { display: block; margin-top: 10px; padding: 12px; border: 2px dashed var(--blue); min-height: 50px; font-weight: 800; }
.analysis-result:empty { display: none; }
.liveness-stage { margin: 16px 0; min-height: 430px; border: 4px solid var(--navy); background: #000; }
.liveness-stage .amplify-button { border-radius: 0; border-width: 3px; font-weight: 800; }
.liveness-stage .amplify-alert { border-radius: 0; }
.liveness-stage video { max-height: 70vh; }
.check-row { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; margin: 20px 0; font-weight: 700; }
.check-row input { width: 24px; height: 24px; min-height: 24px; margin: 2px 0 0; accent-color: var(--blue); }

.button { width: 100%; min-height: 50px; border: 3px solid var(--line); border-radius: 0; padding: 10px 14px; font-weight: 900; cursor: pointer; margin: 5px 0; }
.button:disabled { cursor: not-allowed; }
.button-primary { background: var(--focus); color: #000; }
.button-secondary { background: #e6f3ff; color: var(--navy); border-color: var(--blue); }
.button-dark { background: var(--navy); color: #fff; }
.button-disabled { background: #d9dde1; color: #5a6067; }
.button-quiet { width: auto; background: #fff; color: var(--navy); }
.button[aria-busy="true"] { opacity: .65; }

.action-with-help { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: stretch; }
.action-with-help .action-help-button { width: auto; min-width: 50px; padding-inline: 10px; }
.password-dialog, .action-help-dialog { width: min(100% - 32px, 680px); border: 4px solid var(--line); border-radius: 0; padding: 24px; box-shadow: 10px 10px 0 #071d34; }
.password-dialog::backdrop, .action-help-dialog::backdrop { background: rgb(7 29 52 / 70%); }
.action-help-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - max(24px, 2 * env(safe-area-inset-top), 2 * env(safe-area-inset-bottom)));
  padding: clamp(12px, 4vw, 24px);
  overflow: hidden;
}
.action-help-dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
}
.action-help-dialog > h2 { margin: 0; font-size: clamp(1.15rem, 4vw, 1.5rem); line-height: 1.2; }
#action-help-content {
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  overflow-wrap: anywhere;
  scrollbar-gutter: stable;
  padding-inline-end: 8px;
}
#action-help-content:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
#action-help-content > :first-child { margin-top: 0; }
#action-help-content > :last-child { margin-bottom: 0; }
.action-help-dialog li + li { margin-top: 8px; }
.password-dialog .field-row { margin-bottom: 0; }
.dialog-actions, .dashboard-actions { display: flex; gap: 10px; align-items: center; }
.dialog-actions .button, .dashboard-actions .button { width: auto; }

.dashboard-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 4px solid var(--line); padding-bottom: 18px; margin-bottom: 20px; }
.dashboard-header h1 { margin: 3px 0; }
.dashboard-header p { margin: 0; }
.app-workspace { display: grid; grid-template-columns: minmax(210px, 260px) minmax(0, 1fr); gap: 20px; align-items: start; }
.use-case-menu {
  border: 3px solid var(--line);
  background: var(--paper);
  padding: 8px;
  position: sticky;
  top: 12px;
  min-width: 0;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.use-case-menu:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.menu-module + .menu-module { border-top: 3px solid var(--line); margin-top: 8px; padding-top: 8px; }
.menu-module h2 { color: var(--blue); font-size: .76rem; letter-spacing: .1em; margin: 0 0 4px; text-transform: uppercase; }
.menu-use-case { display: block; width: 100%; border: 2px solid transparent; background: transparent; color: var(--ink); cursor: pointer; font-weight: 800; padding: 5px 10px; text-align: left; overflow-wrap: anywhere; }
.menu-use-case:hover, .menu-use-case.active { background: #e6f3ff; border-color: var(--blue); }
.workspace-main { min-width: 0; }
.use-case-tabs { display: flex; gap: 6px; overflow-x: auto; border-bottom: 3px solid var(--line); min-height: 51px; }
.use-case-tab { display: flex; flex: 0 0 auto; border: 3px solid var(--line); border-bottom: 0; background: #d9dde1; }
.use-case-tab.active { background: var(--paper); box-shadow: inset 0 5px var(--focus); }
.use-case-tab button { border: 0; background: transparent; color: var(--ink); cursor: pointer; font-weight: 900; padding: 12px; }
.use-case-tab .tab-close { border-left: 2px solid var(--line); font-size: 1.25rem; padding-inline: 10px; }
.use-case-panel { padding-top: 20px; }
.use-case-panel > section { margin: 0; }
.selected-permission-summary { border: 3px solid var(--blue); background: #e6f3ff; margin: 0 0 20px; padding: 16px; }
.selected-permission-summary h3 { margin: 0 0 2px; }
.selected-permission-summary p { margin: 0; }
.selected-permission-summary .permission-count { color: var(--ink); font-weight: 900; margin-top: 8px; }
.permission-view-control { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 14px; }
.permission-view-control .button { flex: 0 0 auto; margin: 0; width: auto; }
.permission-choice-list { display: grid; gap: 12px; }
.permission-use-case { min-width: 0; margin: 0; padding: 0; border: 2px solid var(--line); background: var(--paper); }
.permission-use-case legend { margin-inline: 10px; padding-inline: 6px; font-weight: 800; overflow-wrap: anywhere; }
.permission-choice { display: grid; grid-template-columns: 26px 1fr; gap: 10px; align-items: start; border-bottom: 2px solid var(--line); background: var(--paper); padding: 12px; cursor: pointer; }
.permission-choice:last-child { border-bottom: 0; }
.permission-choice:hover, .permission-choice:focus-within { background: #e6f3ff; }
.permission-choice-protected { background: #edf1f4; cursor: not-allowed; }
.permission-choice-protected strong, .permission-choice-protected small { color: #5a6067; }
.permission-choice input { width: 22px; height: 22px; min-height: 22px; margin: 2px 0 0; accent-color: var(--blue); }
.permission-choice strong, .permission-choice small { display: block; }
.permission-choice small { margin-top: 3px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .75rem; overflow-wrap: anywhere; }
.permission-choice-empty { margin: 0; padding: 14px; }
.steps { list-style: none; padding: 0; margin: 0 0 22px; display: grid; grid-template-columns: repeat(4, 1fr); border: 3px solid var(--line); }
.steps li { min-height: 76px; padding: 12px; background: white; border-right: 2px solid var(--line); display: flex; flex-direction: column; }
.steps li:last-child { border-right: 0; }
.steps li.complete { background: #dff6e9; box-shadow: inset 0 -7px var(--success); }
.steps li.pending { background: #fff7cf; box-shadow: inset 0 -7px #d7a800; }
.steps li.rejected { background: #ffe4e7; box-shadow: inset 0 -7px var(--danger); }
.steps span { font-size: .85rem; color: var(--muted); }
.compact-panel { box-shadow: 6px 6px 0 #aeb9c4; }
.identity-panel { grid-column: 1 / -1; }
.code-form { margin-top: 18px; border-top: 2px dashed #77818b; padding-top: 18px; }
.code-form input { letter-spacing: .3em; font-size: 1.25rem; margin-bottom: 10px; }
.verified-block { border: 3px solid var(--success); background: #dff6e9; padding: 14px; font-weight: 850; }
.validator-panel { margin-top: 28px; }
.case-list { display: grid; gap: 18px; margin-top: 18px; }
.case-card { border: 3px solid var(--line); padding: 18px; background: #f8fafb; }
.case-card h3 { margin: 0 0 10px; }
.case-data { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; margin: 0 0 16px; }
.case-data div { border-bottom: 2px solid #aeb9c4; padding: 6px 0; }
.case-data dt { font-size: .75rem; font-weight: 900; letter-spacing: .08em; color: var(--blue); text-transform: uppercase; }
.case-data dd { margin: 3px 0 0; font-weight: 700; overflow-wrap: anywhere; }
.identity-contact-controls { border-top: 3px solid var(--line); margin-top: 18px; padding-top: 16px; }
.identity-contact-controls h4 { margin: 0 0 8px; }
.identity-contact-controls > input, .identity-contact-controls > textarea, .identity-contact-controls > .button { margin-top: 10px; }
.decision-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.decision-actions .button { margin: 0; }
.button-danger { background: #ffe4e7; color: var(--danger); border-color: var(--danger); }
.observation-actions { display: flex; gap: 10px; align-items: center; }
.observation-actions .button { width: auto; }
.observation-view-control { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 10px; align-items: end; border-top: 3px solid var(--line); border-bottom: 3px solid var(--line); margin: 20px 0 14px; padding: 12px 0; }
.observation-view-control .field { margin: 0; }
.observation-view-control .button { width: auto; margin: 0; }
.observation-meta { font-size: .8rem; font-weight: 750; color: var(--muted); }
.observation-card { border-left: 10px solid var(--blue); }
.observation-card[data-type="ratification"] { border-left-color: var(--success); }
.observation-card[data-type="rectification"] { border-left-color: #a05a00; }
.area-filters { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 14px; align-items: end; }
.area-catalog-workspace { display: grid; grid-template-columns: minmax(230px, .75fr) minmax(0, 1.75fr); gap: 20px; align-items: start; }
.area-list { border: 3px solid var(--line); background: var(--paper); }
.area-editor { border: 3px solid var(--line); padding: 18px; min-width: 0; }
.area-record-heading { display: flex; justify-content: space-between; gap: 12px; align-items: start; border-bottom: 3px solid var(--line); margin-bottom: 16px; padding-bottom: 12px; }
.area-record-heading h3 { margin: 3px 0 0; font-size: 1.35rem; }
.area-status { border: 2px solid var(--blue); color: var(--navy); background: #e6f3ff; font-weight: 900; padding: 5px 8px; text-align: center; }
.area-original-name { margin-bottom: 18px; }
.area-category-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 2px solid var(--line); }
.area-category-choice { display: grid; grid-template-columns: 28px 1fr; gap: 8px; border-bottom: 1px solid #aeb9c4; padding: 9px; cursor: pointer; }
.area-category-choice:nth-child(odd) { border-right: 1px solid #aeb9c4; }
.area-category-choice input { width: 22px; height: 22px; min-height: 22px; margin: 1px 0 0; accent-color: var(--blue); }
.area-category-choice strong, .area-category-choice small { display: block; }
.area-category-choice small { color: var(--muted); }
.area-category-choice:has(input:disabled) { background: #edf1f4; cursor: not-allowed; }
.compact-case-list { gap: 8px; }
.assignment-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; border: 2px solid var(--line); background: var(--paper); padding: 10px; }
.assignment-row strong, .assignment-row small { display: block; }
.assignment-row small { color: var(--muted); margin-top: 3px; }
.assignment-row .button { width: auto; margin: 0; }
#bonus-structure-content > .area-editor { margin-top: 18px; }
#bonus-supervision-details .case-card { margin-top: 10px; }
.accounting-catalog-toolbar { display: grid; grid-template-columns: minmax(0, 2fr) minmax(210px, .8fr); gap: 14px; align-items: end; }
#accounting-account-form { margin-top: 18px; }
#accounting-account-form details { border: 2px solid var(--line); padding: 12px; }
#accounting-account-form summary { cursor: pointer; font-weight: 900; }
#accounting-existing-actions { border-top: 3px solid var(--line); margin-top: 22px; padding-top: 16px; }

footer { background: var(--navy); color: #fff; padding: 24px 16px; text-align: center; }
footer p { margin: 0; }

/* Compact layout is selected by available CSS width, never by device or OS. */
@media (max-width: 900px) {
  .auth-grid, .dashboard-grid { grid-template-columns: 1fr; }
  .identity-panel { grid-column: auto; }
  .steps { grid-template-columns: 1fr 1fr; }
  .steps li:nth-child(2) { border-right: 0; }
  .steps li:nth-child(-n+2) { border-bottom: 2px solid var(--line); }
  .dashboard-header { align-items: flex-start; flex-direction: column; }
  .button-quiet { width: 100%; }
  .case-data, .decision-actions, .phone-fields { grid-template-columns: 1fr; }
  .observation-actions { align-items: stretch; flex-direction: column; }
  .observation-actions .button { width: 100%; }
  .dialog-actions, .dashboard-actions { align-items: stretch; flex-direction: column; width: 100%; }
  .dialog-actions .button, .dashboard-actions .button { width: 100%; }
  .observation-view-control { grid-template-columns: 1fr; }
  .observation-view-control .button { width: 100%; }
  .app-workspace { grid-template-columns: minmax(0, 1fr); }
  .use-case-menu {
    position: static;
    display: flex;
    gap: 10px;
    max-height: min(40vh, 16rem);
    max-height: min(40dvh, 16rem);
    overflow: auto;
  }
  .menu-module { flex: 0 0 190px; min-width: 0; }
  .menu-module + .menu-module { border-top: 0; border-left: 3px solid var(--line); margin: 0; padding: 0 0 0 10px; }
  .permission-view-control { align-items: stretch; flex-direction: column; }
  .permission-view-control .button { width: 100%; }
  .area-filters, .area-catalog-workspace, .accounting-catalog-toolbar { grid-template-columns: 1fr; }
  .area-list { max-height: 360px; }
  .assignment-row { grid-template-columns: 1fr; }
  .assignment-row .button { width: 100%; }
}

@media (max-width: 430px) {
  .site-header { align-items: flex-start; }
  .environment { font-size: .65rem; }
  .shell { width: min(100% - 20px, 1120px); margin-top: 16px; }
  .panel { padding: 20px 16px; box-shadow: 5px 5px 0 #aeb9c4; }
  .field-row { gap: 0; }
  .steps { grid-template-columns: 1fr; }
  .steps li { border-right: 0; border-bottom: 2px solid var(--line); }
  .steps li:last-child { border-bottom: 0; }
  .liveness-stage { min-height: 360px; margin-inline: -12px; }
  .area-editor { padding: 14px; }
  .area-record-heading { align-items: stretch; flex-direction: column; }
  .area-category-choices { grid-template-columns: 1fr; }
  .area-category-choice:nth-child(odd) { border-right: 0; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }

.clinical-note-text {
  font: inherit;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
