/* Shared EHR UI — Material 3 Expressive */
.ehr-page {
  min-height: 100dvh;
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-text);
  padding: calc(env(safe-area-inset-top, 0px) + var(--md-sys-space-4)) var(--md-sys-space-4)
    calc(env(safe-area-inset-bottom, 0px) + 96px);
}

.ehr-header {
  max-width: 960px;
  margin: 0 auto var(--md-sys-space-5);
}

.ehr-header h1 {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--md-sys-color-primary);
}

.ehr-header p {
  margin: var(--md-sys-space-2) 0 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.ehr-toolbar {
  display: flex;
  gap: var(--md-sys-space-2);
  flex-wrap: wrap;
  margin-top: var(--md-sys-space-4);
  align-items: center;
}

.ehr-search-wrap {
  flex: 1 1 220px;
  min-width: 180px;
}

.ehr-search-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--md-sys-shape-corner-md);
  background: var(--md-sys-color-surface, #fff);
  color: var(--md-sys-color-text);
}

.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;
}

.ehr-btn {
  border: none;
  border-radius: var(--md-sys-shape-corner-md);
  padding: 12px 18px;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-text);
}

.ehr-btn.primary {
  background: var(--btn-grad);
  color: #fff;
}

.ehr-btn.danger {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.ehr-grid {
  max-width: 960px;
  margin: 0 auto;
  display: grid;
  gap: var(--md-sys-space-4);
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.patient-card {
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-lg);
  padding: var(--md-sys-space-5);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.patient-card:active {
  transform: scale(0.99);
}

.patient-card.select-mode {
  padding-left: calc(var(--md-sys-space-5) + 28px);
}

.patient-card .card-check {
  position: absolute;
  top: var(--md-sys-space-4);
  left: var(--md-sys-space-4);
  width: 22px;
  height: 22px;
  accent-color: var(--md-sys-color-primary);
  display: none;
}

.patient-card.select-mode .card-check {
  display: block;
}

.patient-card h3 {
  margin: 0 0 var(--md-sys-space-2);
  font-size: var(--text-lg);
  font-weight: 800;
}

.patient-card .meta {
  display: grid;
  gap: 4px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.patient-card .meta strong {
  color: var(--md-sys-color-text);
}

.ehr-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--md-sys-space-8) var(--md-sys-space-4);
  color: var(--text-secondary);
  border-radius: var(--md-sys-shape-corner-lg);
  background: var(--md-sys-color-surface-container);
}

.tool-frame {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 520px;
  border: 1px solid var(--border);
  border-radius: var(--md-sys-shape-corner-lg);
  background: var(--md-sys-color-surface);
  box-sizing: border-box;
}

/* Expandable smart FABs — icon-only by default, label inside button */
.fab-stack {
  position: fixed;
  right: calc(var(--md-sys-space-5) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--md-sys-space-6) + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--md-sys-space-3);
}

.fab-stack .smart-fab {
  position: relative;
  right: auto;
  bottom: auto;
}

.smart-fab {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  width: auto;
  height: 56px;
  max-width: 56px;
  padding: 0;
  border: none;
  border-radius: 16px;
  background: var(--btn-grad);
  color: #fff;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  transition: width 0.3s ease, max-width 0.3s ease, padding 0.3s ease, opacity 0.3s ease, border-radius 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
  box-sizing: border-box;
}

.smart-fab .icon {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
}

.smart-fab .fab-text {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  font-size: var(--text-sm);
  font-weight: 700;
  padding-right: 0;
  transition: width 0.3s ease, max-width 0.3s ease, padding 0.3s ease, opacity 0.3s ease, border-radius 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

.smart-fab.expanded {
  max-width: 250px;
  border-radius: 16px;
  padding-right: 16px;
}

.smart-fab.expanded .fab-text {
  max-width: 190px;
  opacity: 1;
  padding-right: 4px;
}

@media (hover: hover) and (pointer: fine) {
  .smart-fab:hover {
    max-width: 250px;
    border-radius: 16px;
    padding-right: 16px;
  }

  .smart-fab:hover .fab-text {
    max-width: 190px;
    opacity: 1;
    padding-right: 4px;
  }
}

/* Standalone page FAB (e.g. patients dashboard) */
.smart-fab--fixed {
  position: fixed;
  right: calc(var(--md-sys-space-5) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--md-sys-space-6) + env(safe-area-inset-bottom, 0px));
  z-index: 40;
}

/* Three-step collapsible action menu (expand → describe → act) */
.action-menu {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--md-sys-space-2);
}

.action-menu--fab {
  position: fixed;
  right: calc(var(--md-sys-space-5) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--md-sys-space-6) + env(safe-area-inset-bottom, 0px));
  z-index: 55;
}

.action-menu--inline {
  align-items: stretch;
  width: 100%;
  max-width: 320px;
}

.action-menu-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  min-height: 56px;
  min-width: 56px;
  padding: 0 16px 0 0;
  border: none;
  border-radius: 16px;
  background: var(--btn-grad);
  color: #fff;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  font-weight: 700;
  transition: width 0.25s ease, padding 0.25s ease, opacity 0.25s ease, border-radius 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.action-menu-trigger-icon {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  line-height: 1;
}

.action-menu-trigger-label {
  white-space: nowrap;
  font-size: var(--text-sm);
}

.action-menu.is-open .action-menu-trigger {
  border-radius: 16px 16px 8px 8px;
}

.action-menu-panel {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: min(320px, calc(100vw - 32px));
  padding: 8px;
  border-radius: 16px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: var(--shadow-lg);
}

.action-menu.is-open .action-menu-panel {
  display: flex;
}

.action-menu--fab .action-menu-panel {
  margin-bottom: 4px;
}

.action-menu-item {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto;
  gap: 2px 10px;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.action-menu-item-icon {
  grid-row: 1 / span 2;
  font-size: 1.2rem;
  text-align: center;
}

.action-menu-item-label {
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.3;
}

.action-menu-item-desc {
  grid-column: 2;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--md-sys-color-on-surface-variant);
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.2s ease;
}

.action-menu-item.is-armed {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
}

.action-menu-item.is-armed .action-menu-item-desc {
  max-height: 80px;
  opacity: 1;
  margin-top: 2px;
}

.action-menu-item.is-armed .action-menu-item-label::after {
  content: " — tap again to confirm";
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--md-sys-color-primary);
}

.action-menu.is-busy .action-menu-item,
.action-menu.is-busy .action-menu-trigger {
  opacity: 0.85;
  pointer-events: none;
}

.page-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
}

/* Patient record */
.record-shell {
  max-width: 980px;
  margin: 0 auto;
  padding-bottom: 100px;
  min-width: 0;
  width: 100%;
}

.common-info-card,
.record-panel {
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-lg);
  padding: var(--md-sys-space-5);
  margin-bottom: var(--md-sys-space-4);
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: clip;
}

.common-info-card h2,
.record-panel h2 {
  margin: 0 0 var(--md-sys-space-4);
  font-size: var(--text-lg);
}

.form-grid {
  display: grid;
  gap: var(--md-sys-space-4);
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.form-grid > div {
  min-width: 0;
  margin-left: 0;
  margin-right: 0;
}

.form-grid label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  box-sizing: border-box;
  display: block;
  width: 100%;
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--md-sys-shape-corner-md);
  background: var(--md-sys-color-surface-container-low);
  color: var(--text);
  font-size: 1rem;
}

.record-tabs {
  display: flex;
  gap: var(--md-sys-space-2);
  margin-bottom: var(--md-sys-space-4);
  flex-wrap: wrap;
}

.record-tab {
  flex: 1;
  min-width: 120px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
  background: var(--md-sys-color-surface-container);
  color: var(--text-secondary);
}

.record-tab.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.history-list {
  display: grid;
  gap: var(--md-sys-space-2);
  margin-bottom: var(--md-sys-space-4);
}

.history-item {
  padding: var(--md-sys-space-3) var(--md-sys-space-4);
  border-radius: var(--md-sys-shape-corner-md);
  background: var(--md-sys-color-surface-container);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.history-item strong {
  color: var(--text);
}

/* Smart save modal */
.smart-save-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--md-sys-space-4);
}

.smart-save-modal[hidden] {
  display: none !important;
}

.smart-save-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.smart-save-card {
  position: relative;
  width: min(100%, 420px);
  max-height: 80vh;
  overflow: auto;
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-xl);
  padding: var(--md-sys-space-6);
  box-shadow: var(--shadow-lg);
}

.smart-save-card h2 {
  margin: 0 0 var(--md-sys-space-2);
  font-size: var(--text-lg);
}

.smart-save-hint {
  margin: 0 0 var(--md-sys-space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.smart-save-list {
  display: grid;
  gap: var(--md-sys-space-2);
  margin-bottom: var(--md-sys-space-4);
}

.smart-save-patient {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--md-sys-shape-corner-md);
  padding: var(--md-sys-space-4);
  background: var(--md-sys-color-surface-container);
  cursor: pointer;
  display: grid;
  gap: 4px;
}

.smart-save-patient strong {
  font-size: var(--text-md);
}

.smart-save-patient span {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.smart-save-new,
.smart-save-cancel {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: var(--md-sys-shape-corner-md);
  font-weight: 700;
  cursor: pointer;
  margin-top: var(--md-sys-space-2);
}

.smart-save-new {
  background: var(--btn-grad);
  color: #fff;
}

.smart-save-cancel {
  background: transparent;
  color: var(--text-secondary);
}

.smart-save-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: var(--md-sys-space-4);
}

/* Scrollable notes & compact signature pads */
.signature-box {
  display: block;
  width: 100%;
  max-width: 300px;
  height: 100px;
  border: 1px solid var(--md-sys-color-outline-variant, #ccc);
  border-radius: 12px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}

.handwriting-scroll,
.clinical-note-scroll {
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--md-sys-color-outline-variant, #ccc);
  border-radius: var(--md-sys-shape-corner-md, 12px);
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

.handwriting-scroll canvas {
  display: block;
  width: 100%;
  height: 480px;
  border: none;
  border-radius: 0;
}

.clinical-note-scroll textarea {
  display: block;
  width: 100%;
  min-height: 480px;
  height: 480px;
  border: none;
  border-radius: 0;
  padding: 12px;
  resize: none;
  box-sizing: border-box;
  font: inherit;
  background: #fff;
  color: inherit;
}

.ehr-sync-status {
  margin: var(--md-sys-space-2) 0 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.ehr-sync-status.is-blocked {
  color: #b3261e;
  font-weight: 600;
}

.ehr-sync-stale-warning {
  margin: var(--md-sys-space-2) 0 0;
  padding: var(--md-sys-space-3);
  border-radius: var(--md-sys-shape-corner-md);
  background: color-mix(in srgb, #b45309 14%, transparent);
  border: 1px solid color-mix(in srgb, #b45309 35%, transparent);
  color: var(--md-sys-color-on-surface);
  font-size: var(--text-sm);
  font-weight: 600;
}

.ehr-dash-sync-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
  background: color-mix(in srgb, var(--md-sys-color-tertiary) 20%, transparent);
  color: var(--md-sys-color-on-surface);
  border: 1px solid color-mix(in srgb, var(--md-sys-color-tertiary) 35%, transparent);
}

.sync-conflict-modal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.sync-conflict-modal[hidden] {
  display: none !important;
}

.sync-conflict-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.sync-conflict-card {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--md-sys-color-surface, #fff);
  color: var(--md-sys-color-text);
  border-radius: var(--md-sys-shape-corner-lg, 16px);
  padding: 20px;
  box-shadow: var(--shadow-lg, 0 8px 32px rgba(0, 0, 0, 0.2));
}

.sync-conflict-intro {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.sync-conflict-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.sync-conflict-panel {
  border: 1px solid var(--border);
  border-radius: var(--md-sys-shape-corner-md);
  padding: 12px;
  background: var(--md-sys-color-surface-container-low, #f7f7f7);
}

.sync-conflict-panel h3 {
  margin: 0 0 8px;
  font-size: var(--text-sm);
}

.sync-conflict-panel dl {
  margin: 0;
  font-size: var(--text-sm);
}

.sync-conflict-panel dt {
  font-weight: 700;
  margin-top: 8px;
}

.sync-conflict-panel dd {
  margin: 2px 0 0;
}

.sync-conflict-keep-both {
  margin-bottom: 16px;
  padding: 12px;
  border-radius: var(--md-sys-shape-corner-md);
  background: var(--md-sys-color-surface-container-highest);
}

.sync-conflict-keep-both label {
  display: block;
  margin-top: 8px;
  font-size: var(--text-sm);
}

.sync-conflict-keep-both input {
  display: block;
  width: 100%;
  margin-top: 4px;
  min-height: 40px;
  padding: 8px 10px;
  box-sizing: border-box;
}

.sync-conflict-note {
  margin: 0 0 8px;
  font-size: var(--text-sm);
}

.sync-conflict-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ehr-dashboard-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--md-sys-space-4) var(--md-sys-space-8);
}

.ehr-dashboard-scroll {
  overflow-x: auto;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-lg);
  background: var(--md-sys-color-surface-container-high);
}

.ehr-dashboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.ehr-dashboard-table th,
.ehr-dashboard-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  vertical-align: top;
  text-align: left;
}

.ehr-dashboard-table th {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: var(--md-sys-color-surface-container);
  position: sticky;
  top: 0;
  z-index: 1;
}

.ehr-dash-id-type {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ehr-dash-id-value {
  font-weight: 700;
  word-break: break-word;
}

.ehr-dash-name-btn {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--md-sys-color-primary);
  cursor: pointer;
  text-align: left;
}

.ehr-section-cell {
  display: block;
  width: 100%;
  min-width: 88px;
  border: 1px dashed var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-sm);
  background: transparent;
  padding: 6px 8px;
  font: inherit;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  cursor: pointer;
  text-align: center;
}

.ehr-section-cell.has-data {
  border-style: solid;
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-text);
  font-weight: 600;
}

.ehr-section-cell.is-empty {
  cursor: default;
  opacity: 0.55;
}

.ehr-section-cell:disabled {
  pointer-events: none;
}

.ehr-view-toggle {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
}

.ehr-selection-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--md-sys-space-3);
  margin-top: var(--md-sys-space-3);
  padding: 10px 12px;
  border-radius: var(--md-sys-shape-corner-md);
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.ehr-selection-count {
  font-weight: 700;
  font-size: var(--text-sm);
}

.ehr-dash-check-col {
  width: 40px;
  text-align: center;
}

.ehr-dash-row-check {
  width: 18px;
  height: 18px;
  accent-color: var(--md-sys-color-primary);
}

.ehr-dash-summary-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-sm);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  font-size: var(--text-sm);
  cursor: pointer;
}

.ehr-dash-summary-btn.is-empty {
  opacity: 0.55;
  cursor: default;
}

.ehr-dash-expand-row td {
  padding: 0 8px 12px 48px;
  background: var(--md-sys-color-surface-container-lowest);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.ehr-dash-section-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ehr-dash-section-link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--md-sys-shape-corner-sm);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-primary);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.ehr-dash-section-link:hover {
  background: var(--md-sys-color-surface-container-high);
}

.ehr-trash-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.patient-action-modal {
  position: fixed;
  inset: 0;
  z-index: 14000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.patient-action-modal[hidden] {
  display: none !important;
}

.patient-action-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.patient-action-card {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--md-sys-color-surface, #fff);
  border-radius: var(--md-sys-shape-corner-lg, 16px);
  padding: 20px;
  box-shadow: var(--shadow-lg, 0 8px 32px rgba(0, 0, 0, 0.2));
}

.patient-action-card--wide {
  width: min(640px, 100%);
}

.patient-action-card h2 {
  margin: 0 0 12px;
  font-size: var(--text-lg);
}

.patient-action-copy {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.patient-action-warning {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--md-sys-shape-corner-md);
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  font-size: var(--text-sm);
}

.patient-action-target {
  margin: 0 0 12px;
  font-size: var(--text-sm);
}

.patient-action-label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  font-weight: 700;
}

.patient-action-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--md-sys-shape-corner-md);
}

.patient-action-list {
  margin: 0 0 16px;
  padding-left: 20px;
  font-size: var(--text-sm);
}

.patient-action-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.patient-unsaved-modal {
  position: fixed;
  inset: 0;
  z-index: 13000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.patient-unsaved-modal[hidden] {
  display: none !important;
}

.patient-unsaved-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.patient-unsaved-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: var(--md-sys-color-surface, #fff);
  border-radius: var(--md-sys-shape-corner-lg, 16px);
  padding: 20px;
  box-shadow: var(--shadow-lg, 0 8px 32px rgba(0, 0, 0, 0.2));
}

.patient-unsaved-intro {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.patient-unsaved-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* The selection bar is only for when patients are ticked: its display:flex must not beat [hidden]. */
.ehr-selection-bar[hidden] {
  display: none;
}

/* Phone: the patient table becomes a single column of tappable cards (no sideways scroll, no clipped cells). */
@media (max-width: 599px) {
  /* Patient record module tabs: one swipeable strip instead of three rows of large pills. */
  .record-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    margin: 0 0 var(--md-sys-space-3);
    padding: 2px 0 6px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }

  .record-tabs::-webkit-scrollbar {
    display: none;
  }

  .record-tab {
    flex: 0 0 auto;
    min-width: 0;
    min-height: 44px;
    padding: 10px 16px;
    white-space: nowrap;
    font-size: var(--text-sm);
    scroll-snap-align: start;
  }

  .ehr-page {
    padding-left: 12px;
    padding-right: 12px;
  }

  .ehr-header {
    margin-bottom: var(--md-sys-space-3);
  }

  html.in-shell .ehr-header > h1,
  html.in-shell .ehr-header > .ehr-header-intro {
    display: none;
  }

  html.in-shell .ehr-header .ehr-sync-status {
    margin-top: 0;
  }

  .ehr-toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .ehr-search-wrap {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .ehr-search-input {
    min-height: 48px;
    border-radius: 999px;
    padding: 12px 18px;
  }

  .ehr-view-toggle {
    flex-wrap: nowrap;
  }

  .ehr-toolbar .ehr-btn {
    min-height: 44px;
  }

  .ehr-dashboard-wrap {
    padding: 0 0 var(--md-sys-space-8);
  }

  .ehr-dashboard-scroll {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .ehr-dashboard-table,
  .ehr-dashboard-table thead,
  .ehr-dashboard-table tbody {
    display: block;
    width: 100%;
  }

  /* Header row shrinks to a "Select all" line (active view) and disappears in Trash. */
  .ehr-dashboard-table thead tr {
    display: flex;
    align-items: center;
    padding: 0 4px 8px;
  }

  .ehr-dashboard-table thead th {
    display: none;
    position: static;
    background: transparent;
    border: 0;
    padding: 0;
  }

  .ehr-dashboard-table thead th.ehr-dash-check-col {
    display: flex;
    align-items: center;
    gap: 10px;
    width: auto;
    text-transform: none;
    letter-spacing: 0;
    font-size: var(--text-sm);
    font-weight: 600;
  }

  .ehr-dashboard-table thead th.ehr-dash-check-col::after {
    content: "Select all";
  }

  .ehr-dashboard-table tbody tr {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    grid-template-areas:
      "check name"
      "check id"
      "sum sum";
    column-gap: 8px;
    row-gap: 4px;
    align-items: center;
    margin: 0 0 10px;
    padding: 14px 14px 12px 10px;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-lg);
    background: var(--md-sys-color-surface-container-high);
  }

  .ehr-dashboard-table tbody td {
    display: block;
    padding: 0;
    border: 0;
    min-width: 0;
  }

  .ehr-dashboard-table tbody td.ehr-dash-check-col {
    grid-area: check;
    width: auto;
    align-self: start;
    padding-top: 2px;
  }

  .ehr-dash-row-check {
    width: 22px;
    height: 22px;
  }

  .ehr-dashboard-table tbody td.ehr-dash-name {
    grid-area: name;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  .ehr-dash-name-btn {
    font-size: var(--text-lg, 1.125rem);
    line-height: 1.25;
    min-height: 32px;
  }

  .ehr-dashboard-table tbody td.ehr-dash-id {
    grid-area: id;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
  }

  .ehr-dash-id-value {
    font-weight: 600;
    font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
    word-break: break-all;
  }

  .ehr-dashboard-table tbody td.ehr-dash-summary {
    grid-area: sum;
    margin-top: 8px;
  }

  .ehr-dash-summary-btn {
    min-height: 40px;
    padding: 8px 12px;
    border-radius: 999px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* "Saved sections" expanded list: sits under its card as part of the same column. */
  .ehr-dashboard-table tbody tr.ehr-dash-expand-row {
    display: block;
    margin-top: -6px;
    padding: 0 0 10px;
    border: 0;
    background: transparent;
  }

  .ehr-dash-expand-row td {
    padding: 0 0 0 44px;
    background: transparent;
    border: 0;
  }

  .ehr-dash-section-link {
    min-height: 44px;
  }

  /* Trash cards: identifier, name, then labelled facts and full-width actions. */
  .ehr-dashboard-table tbody tr.ehr-dash-trash-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "name name"
      "id id"
      "deleted days"
      "actions actions";
    padding-left: 14px;
  }

  .ehr-dash-trash-row .ehr-dash-name {
    font-weight: 700;
    font-size: var(--text-lg, 1.125rem);
  }

  .ehr-dash-trash-row td[data-label] {
    font-size: var(--text-sm);
  }

  .ehr-dash-trash-row td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .ehr-dash-trash-row .ehr-dash-deleted {
    grid-area: deleted;
    margin-top: 6px;
  }

  .ehr-dash-trash-row .ehr-dash-days {
    grid-area: days;
    margin-top: 6px;
  }

  .ehr-dash-trash-row .ehr-trash-actions {
    grid-area: actions;
    margin-top: 10px;
  }

  .ehr-dash-trash-row .ehr-trash-actions .ehr-btn {
    flex: 1 1 0;
    min-height: 44px;
  }
}
