:root {
  color-scheme: light;
  --navy: #1a2a3a;
  --navy-deep: #142433;
  --navy-soft: #1c3348;
  --canvas: #e8eef4;
  --surface: #ffffff;
  --surface-soft: #f0f4f8;
  --ink: #1a2a3a;
  --muted: #5a6f84;
  --subtle: #6a7f94;
  --line: #c8d4e2;
  --green: #2f5f8a;
  --green-bright: #4a7ba8;
  --clinical: #1e4566;
  --clinical-soft: #d5dee8;
  --billing: #5a6f84;
  --billing-soft: #dce5ee;
  --support: #2f5f8a;
  --support-soft: #dce5ee;
  --shadow: 0 12px 38px rgba(26, 42, 58, 0.08);
  --radius: 16px;
  --display: "IBM Plex Sans", "Source Sans 3", ui-sans-serif, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-family: "Source Sans 3", "IBM Plex Sans", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
h1, h2, h3 { font-family: var(--display); }

html { min-width: 320px; background: var(--canvas); scroll-behavior: smooth; }

body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--ink); background: var(--canvas); }

button, input, select, textarea { font: inherit; }

button:focus-visible, a:focus-visible { outline: 3px solid #2f5f8a; outline-offset: 3px; }

.app-shell { min-height: 100vh; }

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 32px;
  border-bottom: 1px solid #c8d4e2;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--navy);
  box-shadow: 0 7px 18px rgba(26, 42, 58, 0.18);
}

.brand-mark i { position: relative; width: 22px; height: 22px; display: block; }
.brand-mark i::before, .brand-mark i::after { content: ""; position: absolute; border-radius: 2px; background: white; }
.brand-mark i::before { width: 22px; height: 7px; top: 7px; left: 0; }
.brand-mark i::after { width: 7px; height: 22px; top: 0; left: 7px; }

.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-size: 16px; letter-spacing: -0.02em; }
.brand-copy small { color: var(--muted); font-size: 12px; }

.environment-labels { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }

.notice {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 700;
}

.notice-synthetic { border-color: #8ab4d4; color: #1e4566; background: #d5dee8; }
.notice i { width: 7px; height: 7px; border-radius: 50%; background: var(--green-bright); box-shadow: 0 0 0 3px rgba(47, 95, 138, 0.16); }

.workspace { max-width: 1500px; min-height: calc(100vh - 78px); display: grid; grid-template-columns: 320px minmax(0, 1fr); margin: 0 auto; }

.control-rail {
  min-width: 0;
  padding: 38px 28px 28px;
  color: #fff;
  background:
    radial-gradient(circle at -10% 22%, rgba(47, 95, 138, 0.22), transparent 34%),
    linear-gradient(168deg, var(--navy) 0%, var(--navy-deep) 100%);
}

.rail-heading { display: flex; gap: 13px; align-items: flex-start; }
.rail-step { width: 28px; height: 28px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 8px; color: var(--green); background: #d5dee8; font: 800 11px/1 var(--mono); }
.control-rail .rail-step { color: #8ab4d4; background: rgba(255, 255, 255, 0.09); }
.eyebrow { margin: 0 0 6px; color: var(--green); font: 800 11px/1.2 var(--mono); letter-spacing: 0.12em; }
.control-rail .eyebrow { color: #8ab4d4; }
.rail-heading h1 { margin: 0; font-size: 20px; line-height: 1.25; letter-spacing: -0.025em; }
.rail-intro { margin: 20px 0 26px; color: #b8c4d0; font-size: 14px; line-height: 1.6; }

.role-tabs { display: grid; gap: 10px; }

.role-tab {
  width: 100%;
  min-height: 70px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 12px;
  padding: 12px 13px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 12px;
  color: #e8eef4;
  text-align: left;
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.role-tab:hover { border-color: rgba(255, 255, 255, 0.26); background: rgba(255, 255, 255, 0.07); transform: translateY(-1px); }
.role-tab.is-active { border-color: rgba(47, 95, 138, 0.52); color: #fff; background: rgba(47, 95, 138, 0.2); box-shadow: inset 3px 0 0 #2f5f8a; }
.role-tab > span:nth-child(2) { min-width: 0; display: grid; gap: 4px; }
.role-tab strong { font-size: 14px; }
.role-tab small { color: #b8c4d0; font-size: 12px; }
.role-tab.is-active small { color: #b8c4d0; }
.tab-check { opacity: 0; color: #2f5f8a; font-style: normal; font-weight: 900; }
.role-tab.is-active .tab-check { opacity: 1; }

.role-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; }
.role-icon svg { width: 21px; height: 21px; fill: currentColor; }
.clinical-icon { color: #8ab4d4; background: rgba(47, 95, 138, 0.22); }
.billing-icon { color: #6a9cc4; background: rgba(47, 95, 138, 0.18); }
.support-icon { color: #9ec5e0; background: rgba(138, 180, 212, 0.14); }

.policy-note { margin-top: 24px; padding: 17px; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 12px; background: rgba(11, 21, 32, 0.45); }
.policy-heading-row { display: flex; align-items: center; gap: 9px; }
.policy-heading-row svg { width: 18px; height: 18px; fill: #2f5f8a; }
.policy-note h2 { margin: 0; font-size: 13px; }
.policy-note p { margin: 10px 0 0; color: #b8c4d0; font-size: 12px; line-height: 1.55; }
.keyboard-hint { margin: 18px 0 0; color: #8fa0b0; font-size: 12px; text-align: center; }
kbd { min-width: 21px; display: inline-grid; place-items: center; padding: 3px 5px; border: 1px solid rgba(255,255,255,.14); border-radius: 5px; color: #e8eef4; background: rgba(255,255,255,.06); font: inherit; }

.main-stage { min-width: 0; padding: 35px clamp(24px, 4vw, 58px) 50px; }

.stage-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.stage-heading h2 { margin: 0; font-size: clamp(25px, 3vw, 35px); line-height: 1.1; letter-spacing: -0.045em; }
.patient-anchor { flex: 0 0 auto; display: grid; gap: 4px; padding-left: 18px; border-left: 1px solid var(--line); }
.patient-anchor span { color: var(--muted); font-size: 12px; }
.patient-anchor strong { font: 800 13px/1.2 var(--mono); }

.query-card {
  display: grid;
  grid-template-columns: minmax(180px, 0.85fr) minmax(320px, 1.55fr) auto;
  align-items: center;
  gap: 20px;
  padding: 15px 18px;
  border: 1px solid #c8d4e2;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.query-label { display: flex; align-items: center; gap: 12px; }
.query-label h3 { margin: 0; font-size: 14px; }
.query-card pre { margin: 0; padding: 12px 15px; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; color: #e8eef4; background: var(--navy-deep); font: 12px/1.55 var(--mono); }
.query-card pre span { color: #8ab4d4; font-weight: 800; }
.query-parameter { display: grid; gap: 5px; }
.query-parameter span { color: var(--muted); font-size: 11px; }
.query-parameter strong { font: 800 12px/1.2 var(--mono); }

.identity-strip {
  display: grid;
  grid-template-columns: minmax(160px, 1.15fr) minmax(120px, 1fr) auto minmax(135px, 1fr) auto minmax(145px, 1fr);
  align-items: center;
  gap: 14px;
  margin: 14px 0;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f0f4f8;
}

.identity-title { display: flex; align-items: center; gap: 11px; }
.identity-title div, .identity-fact { min-width: 0; display: grid; gap: 4px; }
.identity-strip small { color: var(--muted); font-size: 11px; }
.identity-strip strong { overflow: hidden; font: 800 12px/1.3 var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.identity-arrow { color: #8fa0b0; }
.identity-fact.outcome strong { color: var(--green); }

.record-card { overflow: hidden; border: 1px solid #c8d4e2; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.record-card.is-updating .record-content { opacity: 0.35; transform: translateY(4px); }

.record-header { min-height: 92px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.record-header h3 { margin: 0; font-size: 18px; letter-spacing: -0.02em; }
.record-header p:not(.eyebrow) { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.column-count { flex: 0 0 auto; display: flex; align-items: baseline; gap: 8px; padding: 10px 13px; border-radius: 10px; color: var(--clinical); background: var(--clinical-soft); }
.column-count strong { font-size: 22px; }
.column-count span { font-size: 12px; font-weight: 700; }

.record-content { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr); transition: opacity 130ms ease, transform 130ms ease; }
.field-view { min-width: 0; padding: 20px 22px 24px; }
.field-view-heading, .json-heading { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 15px; color: var(--muted); font-size: 12px; font-weight: 800; }
.boundary-badge { display: inline-flex; align-items: center; gap: 6px; color: var(--green); }
.boundary-badge i { width: 6px; height: 6px; border-radius: 50%; background: var(--green-bright); box-shadow: 0 0 0 3px rgba(47, 95, 138, 0.16); }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; border-top: 1px solid var(--line); }
.field-pair { min-width: 0; padding: 13px 11px 13px 0; border-bottom: 1px solid var(--line); }
.field-pair:nth-child(odd) { padding-right: 18px; }
.field-pair:nth-child(even) { padding-left: 18px; border-left: 1px solid var(--line); }
.field-pair dt { margin: 0 0 5px; color: var(--muted); font: 11px/1.2 var(--mono); }
.field-pair dd { margin: 0; overflow-wrap: anywhere; font-size: 13px; font-weight: 700; line-height: 1.35; }
.field-pair.is-common dd::after { content: "Common"; display: inline-block; margin-left: 7px; padding: 2px 5px; border-radius: 4px; color: #5a6f84; background: #243548; font-size: 9px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; vertical-align: 2px; }

.json-view { min-width: 0; padding: 20px 0 0; border-left: 1px solid var(--line); background: var(--navy-deep); }
.json-heading { margin: 0; padding: 0 18px 15px; color: #8fa0b0; }
.json-view pre { max-height: 390px; margin: 0; padding: 0 18px 22px; overflow: auto; color: #e8eef4; font: 12px/1.65 var(--mono); white-space: pre-wrap; }
.json-key { color: #8ab4d4; }
.json-string { color: #b8c4d0; }
.json-number { color: #9ec5e0; }

.record-footer { min-height: 57px; display: flex; align-items: center; gap: 11px; padding: 11px 20px; border-top: 1px solid #c8d4e2; background: #f0f4f8; }
.record-footer svg { width: 22px; height: 22px; flex: 0 0 auto; fill: var(--green); }
.record-footer p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.record-footer strong { color: var(--ink); }

body[data-role="billing"] .column-count { color: var(--billing); background: var(--billing-soft); }
body[data-role="billing"] .query-card pre { border-left-color: var(--billing); }
body[data-role="billing"] .outcome strong { color: var(--billing); }
body[data-role="support"] .column-count { color: var(--support); background: var(--support-soft); }
body[data-role="support"] .query-card pre { border-left-color: var(--support); }
body[data-role="support"] .outcome strong { color: var(--support); }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 285px minmax(0, 1fr); }
  .control-rail { padding: 30px 22px; }
  .main-stage { padding: 30px 25px 42px; }
  .query-card { grid-template-columns: 1fr 1.55fr; }
  .query-parameter { grid-column: 1 / -1; display: flex; justify-content: space-between; padding-top: 4px; }
  .identity-strip { grid-template-columns: minmax(165px, 1.2fr) repeat(2, minmax(125px, 1fr)); }
  .identity-arrow { display: none; }
  .record-content { grid-template-columns: 1fr; }
  .json-view { border-top: 1px solid var(--line); border-left: 0; }
  .json-view pre { max-height: 280px; }
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; padding: 13px 18px; }
  .workspace { display: block; }
  .control-rail { padding: 24px 20px; }
  .rail-intro { margin: 14px 0 18px; }
  .role-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .role-tab { min-height: 112px; grid-template-columns: 1fr; justify-items: center; gap: 7px; text-align: center; }
  .tab-check { display: none; }
  .role-tab.is-active { box-shadow: inset 0 -3px 0 #2f5f8a; }
  .policy-note { margin-top: 18px; }
  .keyboard-hint { display: none; }
  .identity-strip { grid-template-columns: 1fr 1fr; }
  .identity-title { grid-column: 1 / -1; }
  .identity-arrow { display: none; }
}

@media (max-width: 620px) {
  .topbar { display: grid; gap: 12px; }
  .environment-labels { justify-content: flex-start; }
  .notice { min-height: 27px; font-size: 11px; }
  .control-rail { padding: 22px 16px; }
  .role-tab { min-height: 102px; padding: 10px 7px; }
  .role-tab small { display: none; }
  .role-tab strong { font-size: 12px; }
  .main-stage { padding: 25px 14px 36px; }
  .stage-heading { align-items: flex-start; }
  .patient-anchor { display: none; }
  .stage-heading h2 { font-size: 27px; }
  .query-card { grid-template-columns: 1fr; padding: 15px; }
  .query-parameter { grid-column: auto; }
  .identity-strip { padding: 13px; }
  .record-header { align-items: flex-start; padding: 17px; }
  .record-header p:not(.eyebrow) { max-width: 230px; }
  .column-count { display: grid; justify-items: center; gap: 0; }
  .column-count span { max-width: 55px; text-align: center; }
  .field-view { padding: 17px; }
  .field-grid { grid-template-columns: 1fr; }
  .field-pair:nth-child(odd), .field-pair:nth-child(even) { padding: 12px 0; border-left: 0; }
  .record-footer { align-items: flex-start; }
}

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

html[data-theme="dark"] {
  color-scheme: dark;
  --navy: #101c2a;
  --navy-deep: #0b1520;
  --navy-soft: #15263a;
  --canvas: #0b1520;
  --surface: #122033;
  --surface-soft: #15263a;
  --ink: #e8eef4;
  --muted: #8fa0b0;
  --subtle: #6a7f94;
  --line: #243548;
  --green: #8ab4d4;
  --green-bright: #9ec5e0;
  --clinical: #8ab4d4;
  --clinical-soft: #1c3348;
  --billing: #8ab4d4;
  --billing-soft: #1c3348;
  --support: #8ab4d4;
  --support-soft: #1c3348;
  --shadow: 0 12px 38px rgba(0, 0, 0, 0.35);
}

html[data-theme="dark"] .topbar {
  border-bottom-color: var(--line);
  background: rgba(16, 28, 42, 0.94);
}

html[data-theme="dark"] .record-footer {
  border-top-color: var(--line);
  background: var(--surface-soft);
}

html[data-theme="dark"] .notice-synthetic {
  border-color: #3d5166;
  color: #9ec5e0;
  background: #1c3348;
}

html[data-theme="dark"] .rail-step {
  background: #243548;
}

html[data-theme="dark"] .identity-strip {
  background: var(--surface-soft);
}

