:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --ink: #0f172a;
  --muted: #5f718b;
  --line: #dbe5f0;
  --line-strong: #c8d6e6;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --accent-soft: #eff6ff;
  --ok: #10b981;
  --warn: #b45309;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

a {
  color: inherit;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  min-height: 42px;
  padding: 10px 12px;
}

textarea {
  line-height: 1.45;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.22);
  outline-offset: 1px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 19px;
  line-height: 1.2;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}

.brand {
  display: block;
  font-size: 26px;
  font-weight: 780;
  text-decoration: none;
}

.eyebrow,
.crumb {
  color: #1d4ed8;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 800;
  text-transform: uppercase;
}

.crumb {
  margin-bottom: 12px;
}

.topnav,
.button-row,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topnav a {
  color: var(--muted);
  font-weight: 720;
  text-decoration: none;
}

.topnav a:hover,
.strong-link:hover {
  color: var(--accent-dark);
}

.doctor-chip,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #1e40af;
  font-size: 13px;
  font-weight: 760;
  padding: 4px 10px;
}

.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 14px;
  font-weight: 760;
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.button.primary:hover {
  background: var(--accent-dark);
}

.button.secondary {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.button.secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.button.compact {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 14px;
}

.button.full {
  width: 100%;
}

.impersonation-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: #fef3c7;
  color: #92400e;
  border-bottom: 1px solid #fde68a;
}

.flash-wrap {
  max-width: 1180px;
  margin: 16px auto 0;
  padding: 0 20px;
}

.flash {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-weight: 680;
}

.flash.notice {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.flash.alert,
.error-box {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.page {
  width: min(1180px, calc(100% - 40px));
  margin: 34px auto 80px;
}

.narrow-page {
  width: min(760px, calc(100% - 40px));
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
}

.page-head p {
  color: var(--muted);
  margin-top: 10px;
  max-width: 720px;
  line-height: 1.45;
}

.auth-page {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel,
.empty-state,
.table-shell,
.workflow-section,
.summary-panel,
.detail-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(460px, 100%);
  padding: 30px;
}

.auth-panel p,
.empty-state p {
  color: var(--muted);
  line-height: 1.45;
  margin-top: 12px;
}

.seed-hint {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.form-stack,
.case-form,
.detail-stack {
  display: grid;
  gap: 18px;
}

.form-stack {
  margin-top: 24px;
}

.form-meta {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.field {
  display: grid;
  gap: 8px;
}

.field.wide {
  grid-column: 1 / -1;
}

.field label {
  font-weight: 760;
}

.workflow-section {
  padding: 22px;
}

.section-intro {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

.section-intro p {
  color: var(--muted);
  margin-top: 7px;
}

.fields-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.radio-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  min-height: 40px;
  padding: 9px 11px;
  font-weight: 650;
}

.radio-option input {
  width: auto;
  min-height: auto;
}

.table-shell {
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.actions {
  width: 1%;
  white-space: nowrap;
}

.strong-link {
  color: var(--ink);
  font-weight: 760;
  text-decoration: none;
}

.muted {
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.35;
}

.empty-state {
  padding: 36px;
  text-align: center;
}

.empty-state .button {
  margin-top: 20px;
}

.split-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 20px;
}

.full-span {
  grid-column: 1 / -1;
}

.detail-section {
  padding: 20px;
}

.detail-row {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}

.detail-label {
  color: var(--muted);
  font-weight: 760;
}

.detail-value {
  line-height: 1.45;
}

.detail-value p {
  margin-bottom: 8px;
}

.summary-panel {
  align-self: start;
  position: sticky;
  top: 96px;
  padding: 18px;
}

.panel-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 12px;
}

pre {
  max-height: 620px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  line-height: 1.45;
  font-size: 13px;
}

.error-box {
  border-radius: var(--radius);
  padding: 14px;
}

.error-box ul {
  margin-bottom: 0;
}

@media (max-width: 860px) {
  .topbar,
  .page-head,
  .impersonation-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .page,
  .narrow-page {
    width: min(100% - 28px, 1180px);
    margin-top: 24px;
  }

  .form-meta,
  .fields-grid,
  .split-page,
  .detail-row {
    grid-template-columns: 1fr;
  }

  .summary-panel {
    position: static;
  }
}
