:root {
  color-scheme: light;
  --ink: #16324e;
  --muted: #52667a;
  --teal: #0d756e;
  --tint: #e5f4f0;
  --bg: #f3f6f9;
  --line: #dbe5ec;
  --white: #fff;
  --radius: 18px;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100dvh; }
a { color: var(--teal); }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.8rem, 4vw, 2.4rem); line-height: 1.12; letter-spacing: -.042em; }
h2 { font-size: 1.18rem; line-height: 1.25; letter-spacing: -.022em; }
.sub { margin-top: .6rem; color: var(--muted); font-size: .95rem; }
.shell { width: min(100% - 36px, 1080px); margin-inline: auto; }

.topbar { background: #fff; border-bottom: 1px solid var(--line); }
.topbar-inner {
  min-height: 68px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 24px; padding: calc(10px + env(safe-area-inset-top)) 0 10px;
}
.brand { display: inline-flex; align-items: center; }
.brand img { display: block; width: 145px; height: auto; }
nav { display: flex; align-items: center; gap: clamp(.65rem, 2.3vw, 1.35rem); flex-wrap: wrap; }
nav a, .text-button { color: var(--muted); font: inherit; font-size: .85rem; font-weight: 650; text-decoration: none; }
nav a:hover, .text-button:hover { color: var(--teal); text-decoration: underline; }
.text-button { cursor: pointer; background: none; border: 0; padding: 8px 0; }
nav form, .account-bar form { margin: 0; }
nav:empty { display: none; }

.gate { margin-inline: auto; width: min(100%, 440px); padding-block: clamp(28px, 7vh, 78px) 40px; }
.gate-identity {
  display: flex; justify-content: center; margin-bottom: 28px;
}
.gate-identity .brand-logo { display: block; width: min(100%, 310px); height: auto; }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: clamp(19px, 4vw, 32px); box-shadow: 0 4px 20px #16324e08; }
.gate-card h1 { font-size: clamp(1.65rem, 5vw, 2rem); }
.flow { display: grid; gap: 16px; margin-top: 21px; }
label { display: block; margin-bottom: 5px; font-size: .89rem; font-weight: 700; }
input:not([type=hidden]), select {
  background: #fbfdff; border: 1px solid #cbd9e4; border-radius: 10px; width: 100%;
  min-height: 45px; color: var(--ink); padding: 9px 12px; font: inherit;
}
input:focus-visible, :is(button,a,select):focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.password-row { position: relative; }
.password-row input:not([type=hidden]) { padding-right: 5.25rem; }
.reveal { position: absolute; inset: 1px 3px 1px auto; border: 0; background: transparent; color: var(--teal); font: inherit; font-size: .78rem; font-weight: 700; cursor: pointer; padding: 0 9px; border-radius: 8px; }
.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 8px 14px;
  color: var(--ink); font: inherit; font-size: .9rem; font-weight: 700; text-decoration: none; cursor: pointer;
}
.button:hover { border-color: var(--teal); color: var(--teal); }
.primary { background: var(--teal); border-color: var(--teal); color: white; }
.primary:hover { background: #095f59; color: white; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.button.small { min-height: 36px; font-size: .78rem; }
.button.danger { color: #9e2a26; border-color: #efd9d8; background: #fff9f8; }
.help { margin-top: 6px; color: var(--muted); font-size: .8rem; }
.gate-card > .help { margin-top: 18px; }
.gate-card > a.button { margin-top: 18px; }
.feedback { border: 1px solid #f0d6d3; background: #fff5f3; color: #8f332b; margin-top: 15px; padding: 9px 12px; border-radius: 9px; font-size: .88rem; }
.feedback.success { border-color: #c6e5dd; background: #edf8f5; color: #17564e; }

.workspace main { padding-block: 32px 56px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 14px 24px; margin-bottom: 24px; }
.admin-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.workspace main > .feedback { margin: 0 0 18px; }
.section-head { display: flex; align-items: center; gap: 10px; }
.section-head > span { font-size: .83rem; color: var(--muted); }
.user-list { padding: 0; margin: 14px 0 0; list-style: none; }
.user-row {
  display: grid; align-items: center; grid-template-columns: auto minmax(0,1fr) auto auto;
  gap: 10px; padding: 12px 0; border-top: 1px solid var(--line);
}
.avatar { display: grid; place-content: center; width: 37px; height: 37px; border-radius: 12px; background: var(--tint); color: var(--teal); font-weight: 800; }
.user-name { display: grid; min-width: 0; overflow-wrap: anywhere; }
.user-name strong { font-size: .93rem; }
.user-name span { color: var(--muted); font-size: .79rem; }
.badge { display: inline-flex; color: var(--muted); background: var(--bg); padding: 4px 8px; border-radius: 99px; font-size: .72rem; font-weight: 700; line-height: 1.2; }
.badge.enabled { color: #17564e; background: var(--tint); }
.back { display: inline-block; font-size: .85rem; text-decoration: none; font-weight: 700; margin-bottom: 18px; }
.access form { margin-top: 17px; }
.patient-row, .visit-entry { padding: 14px 0; border-top: 1px solid var(--line); }
.patient-row, .visit-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.patient-row form { margin: 0; }
.visit-entry pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: .92rem; background: var(--bg); border-radius: 9px; padding: 12px; margin: 10px 0 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 790px) {
  .admin-layout { grid-template-columns: 1fr; gap: 14px; }
}
@media (max-width: 440px) {
  .shell { width: calc(100% - 28px); }
  .user-row { grid-template-columns: auto minmax(0,1fr) auto; }
  .user-row .badge { grid-column: 2; grid-row: 2; justify-self: start; }
  .user-row .button { grid-column: 3; grid-row: 1 / span 2; }
  .workspace main { padding-top: 24px; }
}
