:root {
  --ink: #173133;
  --muted: #647779;
  --faint: #91a0a1;
  --line: #dce7e6;
  --surface: #ffffff;
  --canvas: #f4f8f7;
  --teal: #0e7c7b;
  --teal-dark: #095f5e;
  --teal-soft: #e2f3f1;
  --blue-soft: #eaf2ff;
  --blue: #356ca9;
  --amber: #a86913;
  --amber-soft: #fff3dc;
  --red: #b84646;
  --red-soft: #fff0ef;
  --green: #32765a;
  --green-soft: #eaf6ef;
  --shadow: 0 16px 42px rgba(28, 66, 67, .08);
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
.hidden { display: none !important; }
.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; }
.eyebrow { margin: 0 0 5px; color: var(--teal); font-size: 11px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.muted { color: var(--muted); font-size: 13px; }

.access-gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 15%, #fff 0, var(--canvas) 58%); }
.gate-card { width: min(460px, 100%); padding: 40px; text-align: center; background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.gate-card .brand-mark { margin: 0 auto 18px; }
.gate-card h1 { margin: 0 0 10px; font: 600 28px/1.2 Georgia, serif; }
.gate-card p:not(.eyebrow) { margin: 0 0 22px; color: var(--muted); line-height: 1.55; }

.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: white; background: linear-gradient(145deg, #13918f, var(--teal-dark)); font: 700 19px Georgia, serif; box-shadow: 0 7px 18px rgba(14,124,123,.22); }
.shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 16px; background: var(--surface); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; margin: 0 7px 30px; color: var(--ink); text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font: 600 19px Georgia, serif; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 11px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 11px; padding: 10px 12px; color: var(--muted); text-align: left; text-decoration: none; border: 0; border-radius: 10px; background: transparent; cursor: pointer; }
.nav-item span { width: 20px; color: var(--faint); text-align: center; }
.nav-item:hover { color: var(--ink); background: #f2f7f6; }
.nav-item.active { color: var(--teal-dark); background: var(--teal-soft); font-weight: 700; }
.nav-item.active span { color: var(--teal); }
.sidebar-spacer { flex: 1; }
.scope-card { margin: 12px 5px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: #f9fbfb; }
.scope-card span, .scope-card strong, .scope-card small { display: block; }
.scope-card span { margin-bottom: 5px; color: var(--faint); font-size: 10px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.scope-card strong { font-size: 13px; }
.scope-card small { margin-top: 3px; color: var(--muted); }
.back-link { margin: 0 8px; color: var(--muted); font-size: 12px; text-decoration: none; }
.back-link:hover { color: var(--teal); }

.workspace { min-width: 0; }
.topbar { height: 84px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px clamp(22px, 4vw, 56px); background: rgba(255,255,255,.84); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.topbar h1 { margin: 0; font: 600 23px Georgia, serif; }
.session-block { display: flex; align-items: center; gap: 10px; text-align: right; }
.session-block strong, .session-block small { display: block; }
.session-block strong { font-size: 13px; }
.session-block small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; color: var(--teal-dark); background: var(--teal-soft); font-size: 12px; font-weight: 800; }
main { width: min(1380px, 100%); margin: 0 auto; padding: 32px clamp(22px, 4vw, 56px) 60px; }

.hero-card { display: flex; align-items: center; justify-content: space-between; gap: 34px; padding: 28px 30px; color: white; border-radius: 18px; background: linear-gradient(118deg, #123d40, #126b6b 70%, #168582); box-shadow: 0 18px 38px rgba(12,75,75,.17); }
.hero-card h2 { margin: 0 0 8px; font: 600 clamp(24px,3vw,34px)/1.15 Georgia, serif; }
.hero-card p:not(.eyebrow) { max-width: 700px; margin: 0; color: #d5e9e7; line-height: 1.55; }
.hero-card .eyebrow { color: #8ee0da; }
.hero-status { flex: 0 0 auto; padding: 10px 14px; color: #d8f5ee; border: 1px solid rgba(203,244,238,.35); border-radius: 999px; background: rgba(255,255,255,.08); font-size: 12px; font-weight: 700; white-space: nowrap; }
.metrics { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 14px; margin: 18px 0; }
.metric { padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(28,66,67,.035); }
.metric span, .metric small { display: block; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 7px 0 2px; font: 600 30px Georgia, serif; }
.metric small { color: var(--faint); font-size: 10px; }
.overview-grid { display: grid; grid-template-columns: 1.3fr .7fr; gap: 18px; }
.operations-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; margin-top: 18px; }
.contingency-admin-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:18px; margin-top:18px; }
.reconciliation-form { display:grid; gap:11px; margin-bottom:16px; padding-bottom:16px; border-bottom:1px solid var(--line); }
.reconciliation-actions { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.incident-action { margin-left:8px; padding:4px 7px; color:var(--teal-dark); border:1px solid var(--line); border-radius:7px; background:white; cursor:pointer; }
.incidents-panel { margin-top: 18px; }
.incidents-metrics { grid-template-columns: repeat(2, minmax(0,220px)); margin: 14px 0; }
.incidents-filters { display:flex; flex-wrap:wrap; align-items:end; gap:12px; margin-bottom:14px; padding-bottom:14px; border-bottom:1px solid var(--line); }
.incidents-filters label { display:flex; flex-direction:column; gap:4px; font-size:11px; color:var(--muted); }
.incidents-filters select { padding:7px 9px; border:1px solid var(--line); border-radius:7px; background:var(--surface); color:var(--ink); }
.incident-row { flex-direction:column; align-items:stretch; gap:8px; }
.incident-badges { display:flex; gap:6px; margin-top:6px; flex-wrap:wrap; }
.incident-actions { display:flex; flex-wrap:wrap; gap:0; }
.incident-timeline { margin-top:8px; padding:10px 12px; border-radius:8px; background:var(--canvas); display:grid; gap:6px; }
.incident-timeline-line { margin:0; font-size:11.5px; color:var(--muted); }
.operations-metrics { grid-template-columns: repeat(6, minmax(0,1fr)); }
.ops-list { display: grid; gap: 8px; }
.ops-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid #edf2f1; }
.ops-row:last-child { border-bottom: 0; }
.ops-row div { min-width: 0; }
.ops-row strong, .ops-row small { display: block; }
.ops-row strong { font-size: 12px; }
.ops-row small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.ops-row > span { color: var(--ink); font: 600 16px Georgia, serif; white-space: nowrap; }
#operations-warning { margin: 12px 0 0; }

.semaphore { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; padding: 18px 22px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.semaphore-signal { display: flex; align-items: center; gap: 10px; }
.semaphore-signal strong { font: 700 22px Georgia, serif; }
.signal-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); flex: none; }
.signal-dot.good { background: var(--green); }
.signal-dot.warn { background: var(--amber); }
.signal-dot.danger { background: var(--red); }
.semaphore.good { border-color: var(--green-soft); }
.semaphore.warn { border-color: var(--amber-soft); }
.semaphore.danger { border-color: var(--red-soft); }
.semaphore-causes ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; }
.semaphore-causes .empty { margin: 0; color: var(--muted); font-size: 12.5px; }
#cockpit-shift { margin: 10px 0 0; }
.cockpit-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; margin-top: 16px; }
.cockpit-card { display: flex; flex-direction: column; gap: 10px; padding: 18px; }
.cockpit-card-detail { margin: 0; font-size: 12.5px; }
.cockpit-card .row-action { align-self: flex-start; text-decoration: none; font-size: 11px; }
@media (max-width: 980px) { .cockpit-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 680px) { .cockpit-grid { grid-template-columns: 1fr; } }
.panel, .table-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 26px rgba(28,66,67,.04); }
.panel { padding: 22px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel h2, .section-intro h2 { margin: 0; font: 600 22px/1.25 Georgia, serif; }
.pending-list { display: grid; gap: 9px; }
.pending-item { display: flex; align-items: center; gap: 12px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 11px; }
.pending-item .signal { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 4px var(--amber-soft); }
.pending-item.ok .signal { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.pending-item div { flex: 1; }
.pending-item strong, .pending-item small { display: block; }
.pending-item strong { font-size: 13px; }
.pending-item small { margin-top: 2px; color: var(--muted); }
.pending-item button { color: var(--teal); border: 0; background: none; cursor: pointer; }
.permission-summary { display: flex; flex-wrap: wrap; gap: 7px; }
.permission-chip { padding: 6px 9px; color: var(--teal-dark); border-radius: 8px; background: var(--teal-soft); font-size: 11px; font-weight: 650; }
.role-governance-grid { display:grid; grid-template-columns:minmax(0,1.15fr) minmax(300px,.85fr); gap:18px; }
.role-scope-warning { margin-bottom:18px; }
.governance-list { display:grid; gap:9px; }
.governance-card { display:flex; align-items:flex-start; justify-content:space-between; gap:14px; padding:13px; border:1px solid var(--line); border-radius:11px; background:#fbfdfd; }
.governance-card-copy { min-width:0; }
.governance-card-copy strong,.governance-card-copy small { display:block; }
.governance-card-copy small { margin-top:4px; color:var(--muted); line-height:1.4; }
.governance-card .role-chips { margin-top:8px; }
.access-events-panel { margin-top:18px; }
.permission-picker { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; max-height:310px; overflow:auto; }
.permission-option { display:flex; align-items:flex-start; gap:8px; padding:11px; border:1px solid var(--line); border-radius:10px; background:#fbfdfd; cursor:pointer; }
.permission-option input { width:auto; margin-top:3px; accent-color:var(--teal); }
.permission-option strong,.permission-option small { display:block; }
.permission-option small { margin-top:2px; color:var(--muted); font-weight:400; line-height:1.35; }
.risk-copy { color:var(--amber); font-weight:700; }
.empty { padding: 28px; color: var(--muted); text-align: center; }

.section-intro { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.section-intro p:not(.eyebrow) { max-width: 720px; margin: 7px 0 0; color: var(--muted); line-height: 1.5; }
.section-actions { display: flex; align-items: center; gap: 10px; }
.search-field input { width: min(300px, 72vw); padding: 10px 13px; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); outline: none; }
.filter-field select { min-width: 170px; padding: 10px 32px 10px 11px; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.search-field input:focus, .filter-field select:focus, label input:focus, label textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
.table-card { overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 18px; color: var(--faint); text-align: left; background: #f9fbfb; border-bottom: 1px solid var(--line); font-size: 10px; letter-spacing: .07em; text-transform: uppercase; }
td { padding: 14px 18px; border-bottom: 1px solid #edf2f1; font-size: 13px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfdfd; }
.physician-cell, .person-cell { display: flex; align-items: center; gap: 10px; }
.physician-cell .avatar, .person-cell .avatar { width: 34px; height: 34px; }
.physician-cell strong, .physician-cell small, .person-cell strong, .person-cell small { display: block; }
.physician-cell small, .person-cell small { margin-top: 2px; color: var(--muted); }
.role-chips { display: flex; flex-wrap: wrap; gap: 5px; min-width: 170px; }
.role-chip { padding: 4px 7px; color: #405c5e; border: 1px solid var(--line); border-radius: 7px; background: #f8fbfa; font-size: 10px; font-weight: 700; }
.scope-copy { min-width: 125px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.date-copy { color: var(--muted); white-space: nowrap; font-size: 11px; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 750; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good { color: var(--green); background: var(--green-soft); }
.badge.warn { color: var(--amber); background: var(--amber-soft); }
.badge.neutral { color: var(--muted); background: #eef3f2; }
.badge.danger { color: var(--red); background: var(--red-soft); }
.row-action { padding: 7px 10px; color: var(--teal-dark); border: 1px solid #bedbd8; border-radius: 8px; background: white; cursor: pointer; }
.row-action:hover { background: var(--teal-soft); }

.identity-grid { display: grid; grid-template-columns: .8fr 1.2fr; gap: 18px; }
.identity-status-card { display: flex; align-items: center; gap: 16px; }
.identity-icon { display: grid; place-items: center; width: 48px; height: 48px; flex: 0 0 auto; color: var(--amber); border-radius: 50%; background: var(--amber-soft); font: 700 22px Georgia, serif; }
.identity-icon.good { color: var(--green); background: var(--green-soft); }
.identity-status-card h3 { margin: 3px 0; font: 600 20px Georgia, serif; }
.identity-status-card p { margin: 0; color: var(--muted); line-height: 1.45; }
.form-stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--ink); font-size: 12px; font-weight: 700; }
label input, label textarea { width: 100%; padding: 10px 12px; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; background: white; outline: none; resize: vertical; }
.privacy-note { margin: -2px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 8px 14px; border: 1px solid transparent; border-radius: 9px; text-decoration: none; cursor: pointer; font-weight: 700; }
.button.primary { color: white; background: var(--teal); }
.button.primary:hover { background: var(--teal-dark); }
.button.ghost { color: var(--muted); border-color: var(--line); background: white; }
.button.danger { color: white; background: var(--red); }
.button:disabled { opacity: .58; cursor: wait; }

dialog { width: min(560px, calc(100vw - 28px)); padding: 0; border: 0; border-radius: 17px; box-shadow: 0 28px 80px rgba(17,49,51,.24); }
dialog.wide-dialog { width: min(820px, calc(100vw - 28px)); }
dialog::backdrop { background: rgba(14,39,41,.46); backdrop-filter: blur(2px); }
.dialog-card { display: grid; gap: 17px; padding: 24px; }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; }
.dialog-heading h2 { margin: 0; font: 600 24px Georgia, serif; }
.dialog-heading p:not(.eyebrow) { margin: 4px 0 0; color: var(--muted); }
.icon-button { width: 34px; height: 34px; color: var(--muted); border: 1px solid var(--line); border-radius: 50%; background: white; cursor: pointer; font-size: 21px; }
.warning-box { display: grid; gap: 3px; padding: 11px 12px; color: #795018; border: 1px solid #f0d29d; border-radius: 10px; background: var(--amber-soft); font-size: 11px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; }
.form-error { margin: -4px 0 0; color: var(--red); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.role-fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.role-fieldset legend { margin-bottom: 9px; font-size: 12px; font-weight: 800; }
.role-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-height: 320px; overflow-y: auto; padding: 1px; }
.role-option { padding: 11px; border: 1px solid var(--line); border-radius: 11px; background: #fbfdfd; }
.role-option.disabled { opacity: .56; }
.role-main { display: flex; align-items: start; gap: 8px; cursor: pointer; }
.role-main input { margin-top: 2px; accent-color: var(--teal); }
.role-main strong, .role-main small { display: block; }
.role-main small { margin-top: 2px; color: var(--muted); font-weight: 400; line-height: 1.35; }
.role-scope { display: grid; grid-template-columns: 1fr; gap: 5px; margin: 9px 0 0 23px; }
.role-scope select { width: 100%; padding: 7px 8px; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; background: white; }
.scope-check { display: flex; grid-template-columns: none; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; font-weight: 550; }
.scope-check input { width: auto; accent-color: var(--teal); }
.permission-preview { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: #f9fbfb; }
.permission-preview > strong { font-size: 11px; }
.professional-fields { padding: 12px; border: 1px solid #bcdedb; border-radius: 11px; background: var(--teal-soft); }
.specialty-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 14px 0 8px; font-size: 12px; }
.specialty-list { display: grid; gap: 8px; }
.specialty-row { display: grid; grid-template-columns: minmax(180px,2fr) minmax(110px,1fr) auto auto; align-items: end; gap: 8px; padding: 9px; border: 1px solid #c9dedc; border-radius: 9px; background: white; }
.specialty-main { display: flex; align-items: center; gap: 5px; min-height: 39px; font-size: 11px; color: var(--muted); }
.specialty-main input { width: auto; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: min(410px, calc(100vw - 48px)); padding: 12px 15px; color: white; border-radius: 11px; background: #153f41; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .18s ease; }
.toast.visible { opacity: 1; transform: none; }
.toast.error { background: #833c3c; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 82px minmax(0,1fr); }
  .sidebar { padding-inline: 10px; }
  .brand { margin-inline: auto; }
  .brand > span:last-child, .nav-item:not(.active)::after, .nav-item { font-size: 0; }
  .nav-item { justify-content: center; padding: 11px; }
  .nav-item span { width: auto; font-size: 18px; }
  .scope-card, .back-link { display: none; }
  .metrics { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .overview-grid { grid-template-columns: 1fr; }
  .operations-grid { grid-template-columns: 1fr; }
  .role-governance-grid { grid-template-columns:1fr; }
  .contingency-admin-grid { grid-template-columns: 1fr; }
  .operations-metrics { grid-template-columns: repeat(3, minmax(0,1fr)); }
}

@media (max-width: 700px) {
  .shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; display: flex; flex-direction: row; align-items: center; gap: 8px; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand { margin: 0 auto 0 0; }
  .brand > span:last-child { display: none; }
  .sidebar nav { display: flex; }
  .sidebar-spacer, .scope-card, .back-link { display: none; }
  .nav-item, .nav-item.active { width: auto; font-size: 0; }
  .topbar { height: auto; padding: 13px 18px; }
  .session-block > div:not(.avatar) { display: none; }
  main { padding: 22px 14px 44px; }
  .hero-card { display: block; padding: 22px; }
  .hero-status { display: inline-block; margin-top: 18px; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric { padding: 14px; }
  .section-intro { display: block; }
  .section-actions { align-items: stretch; margin-top: 15px; }
  .search-field input { width: 100%; margin-top: 15px; }
  .section-actions .search-field input { margin-top: 0; }
  .table-card { overflow-x: auto; }
  table { min-width: 720px; }
  .identity-grid { grid-template-columns: 1fr; }
  .role-picker, .permission-picker, .form-grid, .form-grid.three, .specialty-row { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .section-actions { display: grid; }
}
#media-share-dialog { width: min(850px, 90vw); max-height: 85vh; overflow: auto; border: 1px solid var(--line, #dbe7e5); border-radius: 18px; padding: 24px; }
#media-share-url { width: 100%; }
#media-share-form select, #media-filters select { min-height: 38px; border: 1px solid #dbe7e5; border-radius: 8px; padding: 6px; }
#view-media > .panel { margin-top: 16px; }
.media-finding-note { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; width: 100%; }
.media-finding-note input { flex: 1; min-width: 180px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); }
#media-findings .ops-row { flex-wrap: wrap; overflow-wrap: anywhere; }
