:root {
  --brand: #344E78;
  --bg: #F4F6F9;
  --card: #FFFFFF;
  --ink: #101824;
  --muted: #374151;
  --border: #D1D9E6;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
}

.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;
}

:focus-visible {
  outline: 3px solid #2563EB;
  outline-offset: 2px;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 18px;
}

.impersonation-banner {
  background: #78350F;
  color: #FFFFFF;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-weight: 600;
}

.portal-header {
  background: #FFFFFF;
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}

.portal-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.portal-brand__logo {
  border-radius: 8px;
}

.portal-eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brand);
}

.portal-title {
  margin: 0;
  font-size: 1.35rem;
}

.portal-header__right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.user-badge {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
}

.portal-main {
  padding: 22px 18px 60px;
}

#clinic-workspace {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(16, 24, 36, 0.05);
}

.adapt-panel {
  border: 2px solid #D97706;
  background: #FFFBEB;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title {
  margin: 2px 0 4px;
  font-size: 1.22rem;
}

.sub-title {
  margin: 0 0 8px;
  font-size: 1.02rem;
}

.muted-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.badge-amber {
  background: #78350F;
  color: #FFFFFF;
}

.badge-blue {
  background: #1E3A8A;
  color: #FFFFFF;
}

/* >= 48x48px accessible controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  min-width: 48px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.94rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--brand);
  color: #FFFFFF;
}

.btn-secondary {
  background: #E8EEF6;
  color: #101824;
  border-color: #B8C7DC;
}

.btn-quiet {
  background: #FFFFFF;
  color: #101824;
  border-color: var(--border);
}

.input-control {
  min-height: 48px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #9CA3AF;
  background: #FFFFFF;
  color: #101824;
  font-size: 0.95rem;
}

.launcher-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.search-wrap {
  flex: 1;
  min-width: 240px;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-pill {
  min-height: 48px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #F9FAFB;
  color: #101824;
  font-weight: 600;
  cursor: pointer;
}

.filter-pill.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #FFFFFF;
}

.routines-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.routine-tile {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  background: #FCFDFE;
}

.routine-tile__code {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--brand);
}

.routine-tile__title {
  margin: 4px 0;
  font-size: 1.05rem;
}

.routine-tile__meta {
  font-size: 0.86rem;
  color: var(--muted);
}

.routine-tile__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* AI Adaptation Options */
.adapt-options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 12px;
}

.adapt-opt-card {
  background: #FFFFFF;
  border: 1px solid #D97706;
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.adapt-approved-box {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  background: #ECFDF5;
  border: 1px solid #059669;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

/* ROI KPIs & Table */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-box {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.kpi-box__label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.kpi-box__val {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-weight: 700;
  color: var(--muted);
  background: #F8FAFC;
}

/* Two-Column Admin Forms */
.two-col-admin {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.code-form {
  display: flex;
  gap: 8px;
}

.code-preview {
  background: #101824;
  color: #F8FAFC;
  padding: 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  overflow-x: auto;
}

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.protocol-signoff {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.protocol-status {
  font-size: 0.84rem;
  color: #065F46;
  font-weight: 600;
}

/* Handoff Modal */
.handoff-dialog {
  width: min(94vw, 760px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  background: #FFFFFF;
  color: var(--ink);
}

.handoff-dialog::backdrop {
  background: rgba(16, 24, 36, 0.6);
}

.handoff-dialog__inner {
  padding: 22px;
}

.handoff-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  align-items: start;
}

.qr-panel {
  text-align: center;
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.qr-img {
  display: block;
  margin: 0 auto 10px;
  border-radius: 8px;
}

.qr-caption {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tweaker-box {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.tweaker-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.tweak-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  background: #F9FAFB;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
}

.tweak-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tweak-num {
  width: 64px;
  min-height: 48px;
  padding: 4px 8px;
  border: 1px solid #9CA3AF;
  border-radius: 6px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #101824;
  color: #FFFFFF;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  z-index: 200;
}
