:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #647084;
  --line: #d8dee8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #138a5a;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(21, 31, 53, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

a {
  color: var(--primary);
  text-decoration: none;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  padding: 0 18px;
  cursor: pointer;
}

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

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.secondary {
  background: #eef2f8;
  color: var(--text);
  border: 1px solid var(--line);
}

.secondary:hover {
  background: #e3e9f3;
}

.ghost,
.ghost-link {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost:hover,
.ghost-link:hover {
  background: #eef2f8;
}

.danger {
  background: var(--danger);
}

.danger:hover {
  background: #8f1f17;
}

.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.88rem;
}

.full {
  width: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  min-height: 66px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 800;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-size: 0.8rem;
}

.nav,
.userbar,
.button-row,
.search-row,
.inline-form,
.sign-meta,
.patient-strip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav a,
.admin-tabs a {
  color: var(--muted);
  font-weight: 700;
  padding: 9px 12px;
  border-radius: 7px;
}

.nav a.active,
.nav a:hover,
.admin-tabs a.active,
.admin-tabs a:hover {
  background: #eef2f8;
  color: var(--text);
}

.userbar {
  color: var(--muted);
}

.shell {
  width: min(1240px, calc(100vw - 32px));
  margin: 24px auto 56px;
}

.login-panel {
  min-height: calc(100vh - 80px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-top: 0;
}

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

.page-head.compact {
  align-items: center;
}

.page-head h1,
.panel h1,
.panel h2,
.panel h3 {
  margin: 0 0 12px;
}

.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.grid-two.wide-left {
  grid-template-columns: minmax(0, 1.5fr) minmax(340px, 0.7fr);
}

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

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c9d2df;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 9px 11px;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 18px 0;
}

legend {
  margin-bottom: 10px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  display: grid;
  place-items: center;
  min-height: 44px;
  cursor: pointer;
  color: var(--muted);
}

.segmented input:checked + label {
  background: var(--primary);
  color: #fff;
}

.treatment-list {
  display: grid;
  gap: 10px;
}

.check-card {
  grid-template-columns: auto 1fr;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
}

.check-card input {
  width: 22px;
  min-height: 22px;
}

.check-card small {
  display: block;
  color: var(--muted);
  font-weight: 400;
}

.muted {
  opacity: 0.65;
}

.results {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.result-row {
  display: grid;
  grid-template-columns: 1.2fr 0.7fr 0.8fr 1fr;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  text-align: left;
  font-weight: 400;
}

.result-row:hover {
  background: #f0f6ff;
}

.result-empty {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.selected-patient {
  display: grid;
  grid-template-columns: 1.2fr 0.7fr 0.8fr 1fr;
  gap: 10px;
  margin-top: 16px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid #b8e0cc;
  background: #eefaf4;
  color: #0f5132;
}

.hidden {
  display: none !important;
}

.sign-shell {
  max-width: 900px;
  margin: 0 auto;
}

.sign-meta {
  justify-content: space-between;
  color: var(--muted);
  margin-bottom: 12px;
}

.consent-document {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.consent-document h1 {
  margin-top: 0;
}

.patient-strip {
  flex-wrap: wrap;
  padding: 10px 0 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.consent-text {
  white-space: pre-wrap;
  margin-top: 18px;
  font-size: 1.06rem;
}

.signature-panel {
  margin-top: 18px;
}

.agreement {
  grid-template-columns: auto 1fr;
  align-items: center;
  font-weight: 800;
}

.agreement input {
  width: 24px;
  min-height: 24px;
}

.signature-canvas {
  width: 100%;
  height: 230px;
  border: 2px dashed #aab5c5;
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

.review-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.pdf-preview {
  width: 100%;
  height: calc(100vh - 180px);
  min-height: 680px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.details {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px 12px;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
}

.hash {
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.8rem;
}

.vertical {
  align-items: stretch;
  flex-direction: column;
  margin-top: 16px;
}

.plain-list {
  padding-left: 20px;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  background: #eef2f8;
  color: #3d4b60;
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 0.82rem;
}

td small {
  color: var(--muted);
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.treatment-admin-list {
  display: grid;
  gap: 10px;
}

.admin-row {
  display: grid;
  grid-template-columns: 60px 110px 1fr 1fr auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tiny {
  min-width: 58px;
}

.mini-check {
  display: inline-flex;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  white-space: nowrap;
}

.mini-check input {
  width: 18px;
  min-height: 18px;
}

.inline-form {
  justify-content: space-between;
  margin-top: 8px;
}

.inline-form input {
  max-width: 180px;
}

.flash {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-weight: 700;
}

.flash.success {
  background: #e9f8f0;
  color: #0f5132;
  border: 1px solid #b8e0cc;
}

.flash.error {
  background: #fff1f0;
  color: #9b1c16;
  border: 1px solid #f4c7c3;
}

.danger-zone {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: 1fr;
    padding: 12px 16px;
  }

  .userbar {
    justify-content: space-between;
  }

  .page-head,
  .grid-two,
  .grid-two.wide-left,
  .review-grid {
    grid-template-columns: 1fr;
  }

  .page-head {
    display: grid;
  }

  .result-row,
  .selected-patient {
    grid-template-columns: 1fr;
  }

  .admin-row {
    grid-template-columns: 1fr;
  }

  .pdf-preview {
    height: 70vh;
    min-height: 460px;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 18px, 1240px);
    margin-top: 12px;
  }

  .panel,
  .consent-document {
    padding: 16px;
  }

  .search-row,
  .button-row {
    flex-direction: column;
    align-items: stretch;
  }
}
