/* ═══════════════════════════════════════════════════════════
   ELINOM CAREPRO — Home Care Management Module
   UK-Compliant CQC-Ready Care Home ERP
   ═══════════════════════════════════════════════════════════ */

/* ── DESIGN TOKENS ─────────────────────────────────────── */
:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-pale: #eef2ff;
  --secondary: #0ea5e9;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --info: #06b6d4;
  --care-teal: #14b8a6;
  --care-rose: #f472b6;
  --care-violet: #8b5cf6;
  --care-amber: #f59e0b;
  --bg: #f1f5f9;
  --bg-card: #fff;
  --bg-header: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow-sm: 0 1px 3px rgb(0,0,0,0.06);
  --shadow: 0 4px 24px rgb(0,0,0,0.08);
  --shadow-lg: 0 12px 48px rgb(0,0,0,0.12);
  --font: 'Inter', -apple-system, blinkmacsystemfont, sans-serif;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── RESET & BASE ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── BRAND GRADIENT ────────────────────────────────────── */
.brand-gradient {
  background: linear-gradient(90deg, #38bdf8, #6366f1, #f472b6, #f59e0b, #38bdf8);
  background-size: 200% 200%;
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
          background-clip: text;
  animation: brandShimmer 4s linear infinite;
}

@keyframes brandShimmer {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

/* ═══════════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════════ */
.cp-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  background: var(--bg-header);
  padding: 0 1.5rem;
  height: 64px;
  gap: 1.5rem;
  flex-wrap: wrap;
  border-bottom: 1px solid rgb(255,255,255,0.06);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 800;
}

.brand-logo i {
  color: var(--care-teal);
  font-size: 1.3rem;
}

.brand-suffix {
  color: rgb(255,255,255,0.7);
  font-weight: 500;
  font-size: 1rem;
}

.facility-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgb(255,255,255,0.07);
  border: 1px solid rgb(255,255,255,0.08);
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  color: rgb(255,255,255,0.65);
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}

.facility-pill:hover {
  background: rgb(255,255,255,0.12);
  color: rgb(255,255,255,0.9);
}
.facility-pill i:first-child { color: var(--care-teal); }

.header-left { position: relative; }
.header-right { position: relative; }

.cp-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  min-width: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 250;
  padding: 0.35rem;
  overflow: hidden;
}
.cp-dropdown.open { display: block; }
.cp-dropdown-right { left: auto; right: 0; }
.cp-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
}
.cp-dropdown-item:hover { background: var(--border-light); }
.cp-dropdown-item.active {
  background: var(--primary-pale);
  color: var(--primary);
  font-weight: 600;
}
.cp-dropdown-item i { width: 1rem; color: var(--text-secondary); }

.kpi-card {
  border: 1px solid var(--border);
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: inherit;
  width: 100%;
}
.kpi-data { flex: 1; min-width: 80px; }
.kpi-icon.residents { background: var(--primary-pale); color: var(--primary); }
.kpi-icon.beds { background: #dbeafe; color: #3b82f6; }
.kpi-icon.meds { background: var(--success-light); color: var(--success); }
.kpi-icon.incidents { background: var(--danger-light); color: var(--danger); }
.kpi-icon.cqc { background: #ccfbf1; color: var(--care-teal); }

.staff-card-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.85rem;
}

.audit-item { cursor: pointer; }
.audit-item:hover { background: var(--border-light); }

.review-item, .med-due-item, .alert-item {
  cursor: pointer;
  transition: var(--transition);
}
.review-item:hover, .med-due-item:hover, .alert-item:hover {
  background: var(--border-light);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 1.6rem;
}

/* ── SHELL + LEFT SIDE NAV ─────────────────────────────── */
.cp-shell {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 64px);
  width: 100%;
}

.cp-sidebar {
  flex: 0 0 260px;
  width: 260px;
  max-width: 260px;
  background: linear-gradient(180deg, #0f172a 0%, #134e4a 55%, #0f766e 100%);
  border-right: 1px solid rgb(255, 255, 255, 0.08);
  position: sticky;
  top: 64px;
  align-self: flex-start;
  height: calc(100vh - 64px);
  overflow: hidden;
  z-index: 90;
}

.cp-side-nav,
.header-nav.cp-side-nav {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.2rem;
  flex: 1;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.85rem 0.7rem 1.25rem;
  scrollbar-width: thin;
  scrollbar-color: rgb(255, 255, 255, 0.25) transparent;
}
.header-nav::-webkit-scrollbar { width: 6px; }
.header-nav::-webkit-scrollbar-thumb {
  background: rgb(255, 255, 255, 0.22);
  border-radius: 999px;
}

.cp-side-nav-label {
  margin: 0.15rem 0.55rem 0.45rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(255, 255, 255, 0.45);
}

.header-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 550;
  color: rgb(255,255,255,0.78);
  text-decoration: none;
  white-space: normal;
  line-height: 1.25;
  overflow-wrap: anywhere;
  word-break: break-word;
  transition: var(--transition);
  position: relative;
  min-height: 44px;
  width: 100%;
}

.header-nav .nav-link i {
  flex: 0 0 1.15rem;
  width: 1.15rem;
  text-align: center;
  font-size: 0.95rem;
}

.header-nav .nav-link span {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  overflow: visible;
  white-space: normal;
}

.header-nav .nav-link:hover {
  color: #fff;
  background: rgb(255,255,255,0.08);
}

.header-nav .nav-link.active {
  color: #fff;
  background: rgb(20, 184, 166, 0.28);
  box-shadow: inset 3px 0 0 #5eead4;
}

.header-nav .nav-link.active::after { display: none; }

.cp-practitioner-dash-actions,
.cp-facility-practitioners-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.cp-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgb(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem 1rem;
}
.cp-search-overlay[hidden] { display: none !important; }
.cp-search-panel {
  width: min(720px, 100%);
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.cp-search-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}
.cp-search-panel-header h3 {
  margin: 0;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.cp-search-panel-body { padding: 1rem; }
#cpSearchInput {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font: inherit;
  margin-bottom: 0.85rem;
}
.cp-search-results { max-height: min(55vh, 420px); overflow: auto; }
.cp-search-hit {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0.7rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.cp-search-hit:hover { background: var(--border-light); }
.cp-search-hit strong { display: block; font-size: 0.9rem; }
.cp-search-hit span { display: block; font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.15rem; }
.cp-search-empty { color: var(--text-muted); padding: 0.75rem 0.35rem; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.cp-dir-table-wrap {
  overflow-x: auto;
  width: 100%;
  max-width: 100%;
  display: block;
}
.cp-dir-table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
}
.cp-dir-table td, .cp-dir-table th { white-space: nowrap; }

/* Practitioner directories — full-width card grid (legible vs wide tables) */
#nursesDirectory,
#nursesDirectory .cp-practitioner-directory-panel,
#nursesDirectory .panel-body {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
#nurseCards.staff-cards.cp-practitioner-cards,
#nurseCards.cp-practitioner-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 100%;
}
.cp-practitioner-card {
  text-align: left;
  cursor: default;
}
.cp-practitioner-card .staff-card-name {
  text-align: center;
}
.cp-practitioner-card .staff-card-role {
  text-align: center;
}
.cp-practitioner-card-details {
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 0.75rem;
  margin: 0.25rem 0 0.85rem;
}
.cp-practitioner-card-details .staff-card-detail {
  font-size: 0.74rem;
  line-height: 1.35;
  padding: 0.35rem 0.45rem;
  border-radius: 8px;
  background: var(--surface-2, #f8fafc);
  min-width: 0;
}
.cp-practitioner-card-details .staff-card-detail span {
  font-size: 0.84rem;
  font-weight: 650;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.cp-practitioner-card .cp-card-email {
  font-size: 0.78rem !important;
}
.cp-practitioner-card .staff-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  margin-top: 0.25rem;
}
@media (max-width: 640px) {
  #nurseCards.cp-practitioner-cards {
    grid-template-columns: 1fr;
  }
  .cp-practitioner-card-details {
    grid-template-columns: 1fr;
  }
}
#dbsBody tr.is-locked input:disabled,
#dbsBody tr.is-locked select:disabled,
#trainingBody tr.is-locked input:disabled,
#trainingBody tr.is-locked select:disabled {
  opacity: 0.72;
  cursor: not-allowed;
  background: var(--surface-2, #f1f5f9);
}
.appt-card .cp-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.65rem;
  align-items: center;
}
.appt-status-rail .inc-status-inline {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
}
.appt-status-rail .appt-status-select {
  min-width: 8.5rem;
}
.cp-dir-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }

/* ── HEADER RIGHT ──────────────────────────────────────── */
.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.action-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgb(255,255,255,0.08);
  background: rgb(255,255,255,0.04);
  color: rgb(255,255,255,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.action-btn:hover {
  background: rgb(255,255,255,0.1);
  color: #fff;
}

.alert-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid #1e293b;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.5rem;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--care-teal), var(--primary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.user-name {
  color: rgb(255,255,255,0.7);
  font-size: 0.82rem;
  font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════════════════════ */
.cp-main {
  padding: 1.5rem;
  max-width: none;
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}

.cp-section {
  display: none;
  animation: fadeUp 0.35s ease;
}
.cp-section.active { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════
   KPI ROW
   ═══════════════════════════════════════════════════════════ */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: var(--transition);
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
}
.kpi-residents .kpi-icon { background: var(--primary-pale); color: var(--primary); }
.kpi-meds .kpi-icon { background: var(--success-light); color: var(--success); }
.kpi-incidents .kpi-icon { background: var(--danger-light); color: var(--danger); }
.kpi-staff .kpi-icon { background: #dbeafe; color: #3b82f6; }
.kpi-cqc .kpi-icon { background: #ccfbf1; color: var(--care-teal); }

.kpi-body { flex: 1; min-width: 80px; }

.kpi-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.kpi-trend {
  width: 100%;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.kpi-trend.positive { color: var(--success); }
.kpi-trend.negative { color: var(--danger); }
.kpi-trend.neutral { color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════
   PANELS & DASH GRID
   ═══════════════════════════════════════════════════════════ */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 1rem;
}

.panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-wide { grid-column: span 2; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}

.panel-head h3 {
  font-size: 0.92rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}
.panel-head h3 i { color: var(--primary); font-size: 0.9rem; }

.panel-action {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  transition: var(--transition);
}
.panel-action:hover { color: var(--primary-light); }

.badge-count {
  background: var(--primary-pale);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 10px;
}

.badge-count.danger {
  background: var(--danger-light);
  color: var(--danger);
}

/* ── TASK LIST (Dashboard) ─────────────────────────────── */
.task-list { padding: 0.5rem 0; max-height: 320px; overflow-y: auto; }

.task-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  transition: var(--transition);
  cursor: pointer;
}
.task-item:hover { background: var(--border-light); }
.task-item:last-child { border-bottom: none; }

.task-check {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 6px;
  flex-shrink: 0;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.task-check.done {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.task-check.done::after { content: '✓'; font-size: 0.7rem; }
.task-body { flex: 1; }

.task-title {
  font-size: 0.85rem;
  font-weight: 500;
}
.task-item.done .task-title { text-decoration: line-through; color: var(--text-muted); }

.task-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.15rem;
}

.task-priority {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
}
.task-priority.high { background: var(--danger-light); color: var(--danger); }
.task-priority.medium { background: var(--warning-light); color: var(--warning); }
.task-priority.low { background: var(--success-light); color: var(--success); }

/* ── ALERT LIST (Dashboard) ────────────────────────────── */
.alert-list { padding: 0.5rem 0; max-height: 320px; overflow-y: auto; }

.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}
.alert-item:last-child { border-bottom: none; }

.alert-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.alert-icon.danger { background: var(--danger-light); color: var(--danger); }
.alert-icon.warning { background: var(--warning-light); color: var(--warning); }
.alert-icon.info { background: #dbeafe; color: #3b82f6; }
.alert-text { flex: 1; }
.alert-text strong { font-size: 0.82rem; display: block; }
.alert-text span { font-size: 0.75rem; color: var(--text-secondary); }

/* ── REVIEW LIST (Dashboard) ──────────────────────────── */
.review-list { padding: 0.5rem 0; max-height: 320px; overflow-y: auto; }

.review-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}
.review-item:last-child { border-bottom: none; }
.review-info { display: flex; align-items: center; gap: 0.6rem; }

.review-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary-pale);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
}
.review-name { font-size: 0.85rem; font-weight: 500; }
.review-date { font-size: 0.72rem; color: var(--text-muted); }

.review-due {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
}
.review-due.overdue { background: var(--danger-light); color: var(--danger); }
.review-due.soon { background: var(--warning-light); color: var(--warning); }
.review-due.ok { background: var(--success-light); color: var(--success); }

/* ── MEDICATION DUE (Dashboard) ───────────────────────── */
.med-due-list { padding: 0.5rem 0; max-height: 320px; overflow-y: auto; }

.med-due-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}
.med-due-item:last-child { border-bottom: none; }

.med-pill-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #fdf4ff;
  color: #a855f7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}
.med-due-body { flex: 1; }
.med-due-name { font-size: 0.82rem; font-weight: 600; }
.med-due-detail { font-size: 0.72rem; color: var(--text-secondary); }

.med-due-time {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
}

/* ── STAFF SHIFT (Dashboard) ──────────────────────────── */
.staff-shift-list {
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.staff-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--bg);
}

.staff-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.staff-chip .dot.day { background: var(--success); }
.staff-chip .dot.night { background: var(--care-violet); }
.staff-chip .dot.float { background: var(--warning); }

/* ── COMPLIANCE SUMMARY (Dashboard) ───────────────────── */
.compliance-summary { padding: 1rem 1.25rem; }

.comp-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-light);
}
.comp-item:last-child { border-bottom: none; }
.comp-label { font-size: 0.82rem; color: var(--text-secondary); }
.comp-value { font-size: 0.82rem; font-weight: 700; }
.comp-value.green { color: var(--success); }
.comp-value.amber { color: var(--warning); }
.comp-value.red { color: var(--danger); }

/* ═══════════════════════════════════════════════════════════
   SECTION TOOLBAR
   ═══════════════════════════════════════════════════════════ */
.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.toolbar-left h2 {
  font-size: 1.25rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.toolbar-left h2 i { color: var(--primary); }

.toolbar-count {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.toolbar-select {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0 0.75rem;
  font-size: 0.82rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-card);
  cursor: pointer;
}
.toolbar-select:focus { outline: none; border-color: var(--primary); }

.search-box {
  display: flex;
  align-items: center;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0 0.75rem;
  gap: 0.5rem;
  background: var(--bg-card);
  transition: var(--transition);
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgb(99,102,241,0.1); }
.search-box i { color: var(--text-muted); font-size: 0.85rem; }

.search-box input {
  border: none;
  outline: none;
  font-size: 0.82rem;
  font-family: var(--font);
  color: var(--text);
  background: transparent;
  width: 160px;
}

/* ── BUTTONS ───────────────────────────────────────────── */
.btn-primary {
  height: 38px;
  padding: 0 1rem;
  border: none;
  border-radius: var(--radius-xs);
  background: var(--primary);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: var(--transition);
}
.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); box-shadow: 0 4px 12px rgb(99,102,241,0.35); }

.btn-outline {
  height: 38px;
  padding: 0 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: var(--transition);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-danger-outline {
  height: 38px;
  padding: 0 1rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: var(--transition);
}
.btn-danger-outline:hover { background: var(--danger); color: #fff; }

.btn-danger {
  height: 38px;
  padding: 0 1rem;
  border: none;
  border-radius: var(--radius-xs);
  background: var(--danger);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: var(--transition);
}
.btn-danger:hover { background: #dc2626; }

.btn-ghost {
  height: 38px;
  padding: 0 1rem;
  border: none;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: var(--transition);
}
.btn-ghost:hover { color: var(--text); background: var(--border-light); }

.btn-sm {
  height: 30px;
  padding: 0 0.65rem;
  font-size: 0.75rem;
  border-radius: 6px;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.pagination-bar .page-info {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin: 0 0.35rem;
}
.risk-history-list {
  margin-top: 0.75rem;
}
.risk-history-list .data-table {
  width: 100%;
  font-size: 0.8rem;
}

/* ═══════════════════════════════════════════════════════════
   RESIDENTS
   ═══════════════════════════════════════════════════════════ */
.residents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.resident-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.resident-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--primary-light);
}

.resident-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}
.resident-card.risk-high::before { background: var(--danger); }
.resident-card.risk-medium::before { background: var(--warning); }
.resident-card.risk-low::before { background: var(--success); }

.res-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.res-avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--care-teal), var(--primary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  flex-shrink: 0;
}
.res-info { flex: 1; }

.res-name {
  font-size: 0.95rem;
  font-weight: 700;
}

.res-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.1rem;
}

.res-status {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  text-transform: uppercase;
}
.res-status.active { background: var(--success-light); color: var(--success); }
.res-status.hospital { background: var(--warning-light); color: var(--warning); }
.res-status.respite { background: #dbeafe; color: #3b82f6; }
.res-status.discharged { background: var(--border-light); color: var(--text-muted); }

.res-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.res-detail {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.res-detail span {
  font-weight: 600;
  color: var(--text);
}

.res-risk-bar {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.risk-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}
.risk-badge.high { background: rgb(239,68,68,0.1); color: var(--danger); }
.risk-badge.medium { background: rgb(245,158,11,0.1); color: var(--warning); }
.risk-badge.low { background: rgb(16,185,129,0.1); color: var(--success); }

.res-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

/* ═══════════════════════════════════════════════════════════
   DAILY NOTES / OBSERVATIONS
   ═══════════════════════════════════════════════════════════ */
.notes-timeline {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.note-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 1rem;
  transition: var(--transition);
}
.note-card:hover { box-shadow: var(--shadow); }

.note-card.escalated {
  border-left: 4px solid var(--danger);
}

.note-time-col {
  flex-shrink: 0;
  width: 70px;
  text-align: center;
}

.note-time {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
}

.note-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.note-cat-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  margin: 0.5rem auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}
.note-cat-icon.general { background: #dbeafe; color: #3b82f6; }
.note-cat-icon.mood { background: #fdf4ff; color: #a855f7; }
.note-cat-icon.behaviour { background: var(--warning-light); color: var(--warning); }
.note-cat-icon.food { background: var(--success-light); color: var(--success); }
.note-cat-icon.personal { background: #ffe4e6; color: #f43f5e; }
.note-cat-icon.activity { background: #ccfbf1; color: var(--care-teal); }
.note-cat-icon.night { background: #eef2ff; color: var(--primary); }
.note-cat-icon.handover { background: var(--border-light); color: var(--text-secondary); }

.note-body { flex: 1; }

.note-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.note-resident {
  font-size: 0.92rem;
  font-weight: 700;
}

.note-category {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: var(--border-light);
  color: var(--text-secondary);
}

.mood-indicator {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
}
.mood-indicator i { font-size: 1.1rem; }
.mood-indicator.happy i { color: var(--success); }
.mood-indicator.content i { color: #3b82f6; }
.mood-indicator.anxious i { color: var(--warning); }
.mood-indicator.low i { color: var(--care-violet); }
.mood-indicator.agitated i { color: var(--danger); }
.mood-indicator.confused i { color: var(--text-muted); }

.note-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.note-footer {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.note-staff {
  font-weight: 600;
  color: var(--text-secondary);
}

.note-flag {
  color: var(--danger);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* ═══════════════════════════════════════════════════════════
   MEDICATION (MAR)
   ═══════════════════════════════════════════════════════════ */
.mar-compliance-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--success-light);
  color: var(--success);
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}

.mar-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.mar-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--border-light);
}
.mar-resident-info { flex: 1; }

.mar-placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mar-date-nav,
.cp-date-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
}
.cp-date-nav .date-label {
  flex: 1 1 auto;
  text-align: center;
  white-space: nowrap;
  min-width: 0;
}
.cp-date-nav-btn {
  flex: 0 0 40px;
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.date-nav-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.date-nav-btn:hover { border-color: var(--primary); color: var(--primary); }

#marDate {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 120px;
  text-align: center;
}

.mar-table-wrap {
  overflow-x: auto;
  scrollbar-width: thin;
}

.mar-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  min-width: 900px;
}

.mar-table th {
  background: var(--bg);
  padding: 0.55rem 0.5rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

.mar-table th:first-child,
.mar-table th:nth-child(2) {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--bg);
}
.mar-table th:nth-child(2) { left: 160px; }

.mar-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border-light);
  text-align: center;
  white-space: nowrap;
}

.mar-table td:first-child,
.mar-table td:nth-child(2) {
  text-align: left;
  font-weight: 500;
  position: sticky;
  left: 0;
  background: var(--bg-card);
  z-index: 1;
}
.mar-table td:nth-child(2) { left: 160px; }
.mar-table td:first-child { font-weight: 600; min-width: 160px; }

.mar-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}
.mar-cell.given { background: var(--success-light); color: var(--success); }
.mar-cell.refused { background: var(--danger-light); color: var(--danger); }
.mar-cell.missed { background: var(--warning-light); color: var(--warning); }
.mar-cell.na { background: var(--border-light); color: var(--text-muted); }
.mar-cell.pending { background: var(--bg); color: var(--text-muted); border: 1px dashed var(--border); }
.mar-cell:hover { transform: scale(1.15); }

/* Missed Doses Panel */
.missed-doses-panel {
  border-top: 1px solid var(--border);
}
.missed-list { padding: 0.5rem 0; max-height: 200px; overflow-y: auto; }

.missed-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.82rem;
}
.missed-item:last-child { border-bottom: none; }

.missed-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--danger-light);
  color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}
.missed-body { flex: 1; }

.missed-reason {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════
   INCIDENTS
   ═══════════════════════════════════════════════════════════ */
.incidents-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.incident-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.incident-card:hover { box-shadow: var(--shadow); }

.incident-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 4px;
}
.incident-card.severity-minor::before { background: var(--success); }
.incident-card.severity-moderate::before { background: var(--warning); }
.incident-card.severity-serious::before { background: #f97316; }
.incident-card.severity-critical::before { background: var(--danger); }

.inc-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.inc-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.inc-type-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  text-transform: uppercase;
}
.inc-type-badge.fall { background: var(--warning-light); color: var(--warning); }
.inc-type-badge.safeguarding { background: var(--danger-light); color: var(--danger); }
.inc-type-badge.accident { background: #fef3c7; color: #d97706; }
.inc-type-badge.medication { background: #fdf4ff; color: #a855f7; }
.inc-type-badge.behavioural { background: #ffe4e6; color: #f43f5e; }

.inc-status {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
}
.inc-status.open { background: var(--danger-light); color: var(--danger); }
.inc-status.investigating { background: var(--warning-light); color: var(--warning); }
.inc-status.escalated { background: #fdf4ff; color: #a855f7; }
.inc-status.closed { background: var(--success-light); color: var(--success); }

.inc-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.inc-meta {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.inc-meta-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.inc-meta-item i { font-size: 0.7rem; }

.inc-escalation {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.esc-step {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--border-light);
  color: var(--text-secondary);
}
.esc-step.done { background: var(--success-light); color: var(--success); }
.esc-step i { font-size: 0.65rem; }

/* ═══════════════════════════════════════════════════════════
   STAFF MANAGEMENT
   ═══════════════════════════════════════════════════════════ */
.sub-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.3rem;
  width: -moz-fit-content;
  width: fit-content;
}

.sub-tab {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition);
}
.sub-tab:hover { background: var(--border-light); }

.sub-tab.active {
  background: var(--primary);
  color: #fff;
}

.staff-panel,
.nurses-panel {
  display: none;
  animation: fadeUp 0.3s ease;
}
.staff-panel.active,
.nurses-panel.active { display: block; }

/* Rota Grid */
.rota-week-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

#rotaWeek {
  font-size: 0.92rem;
  font-weight: 600;
  min-width: 180px;
  text-align: center;
}

.rota-grid {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.rota-row {
  display: grid;
  grid-template-columns: 180px repeat(7, 1fr);
  border-bottom: 1px solid var(--border-light);
}
.rota-row:last-child { border-bottom: none; }

.rota-row.header {
  background: var(--bg);
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.rota-cell {
  padding: 0.65rem 0.5rem;
  font-size: 0.78rem;
  border-right: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
}
.rota-cell:last-child { border-right: none; }

.rota-cell:first-child {
  justify-content: flex-start;
  padding-left: 1rem;
  font-weight: 600;
}

.rota-shift {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}
.rota-shift.early { background: #dbeafe; color: #3b82f6; }
.rota-shift.late { background: #fdf4ff; color: #a855f7; }
.rota-shift.night { background: #1e293b; color: #e2e8f0; }
.rota-shift.off { background: var(--border-light); color: var(--text-muted); }
.rota-shift.annual { background: var(--success-light); color: var(--success); }

.rota-grid-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}
.rota-grid { overflow: visible; border: none; }
.rota-row {
  grid-template-columns: minmax(180px, 1.4fr) repeat(7, minmax(90px, 1fr)) 56px;
  min-width: 980px;
}
.rota-staff-cell { padding: 0.4rem !important; }
.rota-staff-select,
.rota-shift-select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.35rem;
  background: #fff;
}
.rota-shift-select.early { background: #dbeafe; color: #1d4ed8; }
.rota-shift-select.late { background: #f5e8ff; color: #7e22ce; }
.rota-shift-select.night { background: #1e293b; color: #e2e8f0; }
.rota-shift-select.off { background: var(--border-light); color: var(--text-muted); }
.rota-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}
.rota-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
}
.shift-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.25rem;
  margin-top: 0.85rem;
  align-items: center;
}
.shift-legend-edit {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
}
.shift-legend-edit input[type="number"] {
  width: 3.2rem;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.35rem;
}
.shift-legend-edit select {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.cp-staff-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.cp-staff-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  table-layout: auto;
  display: table !important;
}
.cp-staff-table th,
.cp-staff-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.86rem;
  vertical-align: middle;
  text-align: left;
  white-space: nowrap;
}
.cp-staff-table th {
  background: var(--bg);
  font-weight: 700;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 1;
}
.cp-staff-table .toolbar-select,
.cp-staff-table input[type="text"],
.cp-staff-table input[type="date"],
.cp-staff-table input[type="number"] {
  width: 100%;
  min-width: 7rem;
  min-height: 36px;
  font-size: 0.82rem;
}
.cp-table-empty {
  text-align: center !important;
  color: var(--text-muted);
  padding: 1.5rem !important;
  white-space: normal !important;
}
.cp-staff-table-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.65rem;
}
.cp-training-courses-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin-bottom: 0.85rem;
}
.cp-training-courses-add {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: flex-end;
}
.cp-training-courses-add label {
  width: 100%;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.cp-training-courses-add input {
  min-width: 220px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.65rem;
}
.cp-training-courses-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
  align-items: center;
}
.cp-course-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--border-light);
  font-size: 0.74rem;
  font-weight: 600;
}
.cp-duration-cell {
  white-space: normal !important;
  min-width: 16rem;
}
.cp-duration-time {
  margin-top: 0.35rem;
}
.cp-duration-time input[type="number"] {
  width: 3.2rem !important;
  min-width: 3.2rem !important;
}

/* Staff Cards */
.staff-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.staff-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  cursor: pointer;
}
.staff-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.staff-card-actions .book-staff-btn {
  pointer-events: auto;
  position: relative;
  z-index: 2;
  cursor: pointer;
}

.staff-card-avatar {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin: 0 auto 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}
.staff-card-name { font-size: 0.95rem; font-weight: 700; }

.staff-card-role {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.staff-card-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  text-align: left;
}

.staff-card-detail {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.staff-card-detail span {
  font-weight: 600;
  color: var(--text);
  display: block;
}

/* ── CP TABLE (shared) ─────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  scrollbar-width: thin;
}

.cp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.cp-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
}

.cp-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.cp-table tr:hover td { background: var(--border-light); }

.status-pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  display: inline-block;
}
.status-pill.valid { background: var(--success-light); color: var(--success); }
.status-pill.expiring { background: var(--warning-light); color: var(--warning); }
.status-pill.expired { background: var(--danger-light); color: var(--danger); }
.status-pill.overdue { background: var(--danger-light); color: var(--danger); }
.status-pill.enrolled { background: #dbeafe; color: #3b82f6; }
.status-pill.completed { background: var(--success-light); color: var(--success); }

/* ═══════════════════════════════════════════════════════════
   COMPLIANCE / CQC
   ═══════════════════════════════════════════════════════════ */
.cqc-kloe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kloe-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.kloe-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.kloe-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  margin: 0 auto 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}
.kloe-icon.safe { background: #dbeafe; color: #3b82f6; }
.kloe-icon.effective { background: #ccfbf1; color: var(--care-teal); }
.kloe-icon.caring { background: #fce7f3; color: var(--care-rose); }
.kloe-icon.responsive { background: #fef3c7; color: var(--care-amber); }
.kloe-icon.well-led { background: var(--primary-pale); color: var(--primary); }

.kloe-card h4 {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.kloe-rating {
  font-size: 0.85rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
  display: inline-block;
}
.kloe-rating.outstanding { background: var(--success-light); color: var(--success); }
.kloe-rating.good { background: #dbeafe; color: #3b82f6; }
.kloe-rating.requires-improvement { background: var(--warning-light); color: var(--warning); }
.kloe-rating.inadequate { background: var(--danger-light); color: var(--danger); }

.kloe-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.kloe-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 3px;
  transition: width 0.6s ease;
}
.kloe-fill.outstanding { background: linear-gradient(90deg, var(--success), var(--care-teal)); }

.kloe-score {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.compliance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 1rem;
}

/* KPI Tracker */
.kpi-tracker { padding: 0.75rem 1.25rem; }

.kpi-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-light);
}
.kpi-item:last-child { border-bottom: none; }

.kpi-item-label {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.kpi-item-value {
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 50px;
  text-align: right;
}

.kpi-item-bar {
  width: 80px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.kpi-item-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}
.kpi-item-fill.green { background: var(--success); }
.kpi-item-fill.amber { background: var(--warning); }
.kpi-item-fill.red { background: var(--danger); }

/* Audit List */
.audit-list { padding: 0.5rem 0; max-height: 350px; overflow-y: auto; }

.audit-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1.25rem;
  font-size: 0.82rem;
}

.audit-check {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  flex-shrink: 0;
}

.audit-check.done {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.audit-check.done::after { content: '✓'; }

.audit-check.partial {
  background: var(--warning-light);
  border-color: var(--warning);
  color: var(--warning);
}
.audit-check.partial::after { content: '~'; }
.audit-label { flex: 1; font-weight: 500; }
.audit-label.done { color: var(--text-muted); text-decoration: line-through; }

/* ═══════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgb(15, 23, 42, 0.6);
  -webkit-backdrop-filter: blur(4px);
          -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
  animation: modalFadeIn 0.25s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s ease;
}
.modal-box.modal-lg { max-width: 780px; }

@keyframes modalSlideIn {
  from { transform: translateY(20px) scale(0.97); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-top h3 {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.modal-top h3 i { color: var(--primary); }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.modal-close:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.modal-body .form-grid {
  width: 100%;
}
.modal-body .form-group,
.modal-body .form-field {
  min-width: 0;
}
.modal-body .form-group input:not([type="checkbox"]):not([type="radio"]),
.modal-body .form-group select,
.modal-body .form-group textarea,
.modal-body .form-field input:not([type="checkbox"]):not([type="radio"]),
.modal-body .form-field select,
.modal-body .form-field textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* ── MODAL TABS ────────────────────────────────────────── */
.modal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0;
  padding: 0 1.5rem;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

.mtab {
  padding: 0.65rem 1rem;
  border: none;
  background: none;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  white-space: nowrap;
}
.mtab:hover { color: var(--text); }

.mtab.active {
  color: var(--primary);
}

.mtab.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
}

/* Only the active resident-modal tab panel may render */
.mtab-panel,
.mtab-content,
.modal-body > .mtab-panel,
.modal-body > .mtab-content {
  display: none !important;
  animation: fadeUp 0.25s ease;
}
.mtab-panel.active,
.mtab-content.active,
.modal-body > .mtab-panel.active,
.modal-body > .mtab-content.active {
  display: block !important;
}

/* ── FORMS ─────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1rem;
  align-items: start;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.form-field.full-width { grid-column: 1 / -1; }

.form-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-field input,
.form-field select,
.form-field textarea {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0 0.75rem;
  font-size: 0.82rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-card);
  transition: var(--transition);
}

.form-field textarea {
  height: auto;
  padding: 0.6rem 0.75rem;
  resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(99,102,241,0.1);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.form-group.full-width { grid-column: 1 / -1; }
.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0 0.75rem;
  font-size: 0.82rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-card);
  transition: var(--transition);
}
.form-group textarea {
  height: auto;
  padding: 0.6rem 0.75rem;
  resize: vertical;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(99,102,241,0.1);
}

/* Risk Grid (Modal) */
.risk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.75rem;
}

.risk-item {
  background: var(--border-light);
  border-radius: var(--radius-xs);
  padding: 0.9rem;
}

.risk-header {
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.risk-header i { color: var(--primary); }

.risk-item select,
.risk-item textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  font-family: var(--font);
  margin-top: 0.35rem;
}

.risk-item select:focus,
.risk-item textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Care Plan (Modal) */
.care-plan-sections { display: flex; flex-direction: column; gap: 0.75rem; }

.cp-plan-item {
  background: var(--border-light);
  border-radius: var(--radius-xs);
  padding: 0.9rem;
}

.cp-plan-head {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.cp-plan-head i { color: var(--primary); }

.cp-plan-item textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0.5rem 0.65rem;
  font-size: 0.8rem;
  font-family: var(--font);
  resize: vertical;
}

.cp-plan-item textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* NOK Section (Modal) */
.nok-section {
  background: var(--border-light);
  border-radius: var(--radius-xs);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.nok-section h4 {
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.nok-section h4 i { color: var(--primary); }

/* Mood Selector */
.mood-selector {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.mood-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem 0.65rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-card);
  cursor: pointer;
  transition: var(--transition);
  min-width: 64px;
}
.mood-btn i { font-size: 1.2rem; color: var(--text-muted); }
.mood-btn span { font-size: 0.65rem; font-weight: 600; color: var(--text-muted); }
.mood-btn:hover { border-color: var(--primary); }

.mood-btn.selected {
  border-color: var(--primary);
  background: var(--primary-pale);
}
.mood-btn.selected i { color: var(--primary); }
.mood-btn.selected span { color: var(--primary); }

/* Body Map (Incident) */
.body-map-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 120px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.body-map-placeholder:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.body-map-placeholder i { font-size: 2rem; }
.body-map-placeholder span { font-size: 0.82rem; }

/* Medication Round Checks */
.round-checks {
  display: flex;
  gap: 1rem;
}

.round-checks label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  cursor: pointer;
}

/* CD Info Banner */
.cd-info-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--primary-pale);
  border-radius: var(--radius-xs);
  margin-bottom: 1rem;
  font-size: 0.82rem;
  color: var(--primary);
  font-weight: 500;
}
.cd-info-banner i { font-size: 1rem; }

/* ═══════════════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  top: 80px;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 600;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.82rem;
  font-weight: 500;
  border-left: 4px solid var(--primary);
  animation: toastIn 0.3s ease;
  min-width: 280px;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast i { font-size: 1rem; }
.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.warning i { color: var(--warning); }

@keyframes toastIn {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE + MOBILE PARITY
   Desktop and mobile share the same chrome; layout adapts.
   ═══════════════════════════════════════════════════════════ */
.cp-mobile-nav-facility { display: none; }

.cp-nav-toggle {
  display: none;
  margin-left: auto;
  min-width: 44px;
  min-height: 44px;
}

@media (width <= 1200px) {
  .panel-wide { grid-column: span 1; }
  .compliance-grid { grid-template-columns: 1fr; }
}

@media (width <= 1100px) {
  .cp-sidebar {
    flex-basis: 220px;
    width: 220px;
    max-width: 220px;
  }
  .header-nav .nav-link { font-size: 0.82rem; padding: 0.65rem 0.7rem; }
}

@media (width <= 900px) {
  .cp-header {
    padding: 0 0.85rem;
    gap: 0.5rem;
    height: auto;
    min-height: 56px;
  }
  .user-label,
  .user-name { display: none; }
  .facility-pill {
    max-width: 140px;
    padding: 0.3rem 0.55rem;
    font-size: 0.72rem;
  }
  .facility-pill #cpFacilityName {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 6.5rem;
  }
  .cp-persist-dot span { display: none; }

  .cp-main { padding: 1rem; }
  .kpi-row,
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: 1fr; }
  .residents-grid { grid-template-columns: 1fr; }
  .cqc-kloe-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .section-toolbar { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .toolbar-right {
    flex-wrap: wrap;
    width: 100%;
    gap: 0.45rem;
  }
  .toolbar-right .toolbar-select,
  .toolbar-right .search-box,
  .toolbar-right .btn-primary,
  .toolbar-right .btn-outline,
  .toolbar-right .btn-danger {
    flex: 1 1 calc(50% - 0.45rem);
    min-width: 0;
    min-height: 44px;
  }
  .toolbar-right > .cp-date-nav,
  .rota-toolbar.cp-date-nav {
    flex: 1 1 100%;
    width: 100%;
    min-height: 44px;
  }
  .cp-date-nav-btn {
    flex: 0 0 44px !important;
    width: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    min-height: 44px;
    padding: 0 !important;
  }
  .rota-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.45rem;
    width: 100%;
  }
  .toolbar-left h2 {
    font-size: 1.05rem;
    flex-wrap: wrap;
    word-break: break-word;
  }
  .sub-tabs,
  .modal-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    gap: 0.15rem;
    scrollbar-width: none;
  }
  .sub-tabs::-webkit-scrollbar,
  .modal-tabs::-webkit-scrollbar { display: none; }
  .sub-tabs .sub-tab,
  .modal-tabs .mtab {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 40px;
  }
  .risk-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .res-details { grid-template-columns: 1fr; }
  .facilities-grid { grid-template-columns: 1fr; }
  .facility-card .cp-card-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  .facility-card .cp-card-actions .btn-sm {
    flex: 1 1 auto;
    min-height: 40px;
  }
  .capacity-grid,
  .cp-charts-row { grid-template-columns: 1fr; }
}

@media (width <= 768px) {
  .cp-shell { display: block; min-height: 0; }
  /* Own the drawer fully — beat any global [class*="-sidebar"] rules */
  .cp-sidebar,
  aside.cp-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(86vw, 300px) !important;
    min-width: min(86vw, 300px) !important;
    max-width: min(86vw, 300px) !important;
    height: 100dvh !important;
    transform: translateX(-105%) !important;
    transition: transform 0.22s ease, visibility 0s linear 0.22s !important;
    z-index: 320 !important;
    box-shadow: none !important;
    visibility: visible !important;
    opacity: 1 !important;
    overflow: hidden auto !important;
    pointer-events: auto !important;
    background: linear-gradient(180deg, #0f172a 0%, #134e4a 55%, #0f766e 100%) !important;
  }
  .cp-sidebar.is-open,
  .cp-sidebar.open,
  .cp-sidebar.mobile-open,
  aside.cp-sidebar.is-open,
  aside.cp-sidebar.open,
  aside.cp-sidebar.mobile-open,
  body.cp-nav-open .cp-sidebar,
  body.cp-nav-open aside.cp-sidebar {
    transform: translateX(0) !important;
    left: 0 !important;
    box-shadow: 0 16px 40px rgb(0, 0, 0, 0.35) !important;
    visibility: visible !important;
    opacity: 1 !important;
    transition: transform 0.22s ease, visibility 0s linear 0s !important;
  }
  .cp-side-nav,
  .header-nav.cp-side-nav {
    display: flex;
    height: 100%;
    /* Clear sticky two-row header (brand + action chips) */
    padding-top: max(7.25rem, calc(env(safe-area-inset-top, 0px) + 6.75rem));
  }
  .header-nav.is-open { display: flex; }

  .cp-header {
    position: sticky;
    top: 0;
    z-index: 200;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand toggle"
      "actions actions";
    align-items: center;
    column-gap: 0.35rem;
    row-gap: 0.35rem;
    padding: 0.55rem 0.75rem;
  }

  .header-left {
    grid-area: brand;
    min-width: 0;
    gap: 0.45rem;
  }
  .facility-pill { display: none; } /* moved into mobile nav drawer for parity */
  .header-left .cp-dropdown#cpFacilityMenu.open {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    top: auto;
    width: auto;
    min-width: 0;
    max-height: 60vh;
    overflow-y: auto;
    z-index: 400;
  }
  .cp-nav-toggle {
    grid-area: toggle;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 0;
  }
  .header-right {
    grid-area: actions;
    justify-content: flex-end;
    width: 100%;
    gap: 0.3rem;
    padding-top: 0.15rem;
    border-top: 1px solid rgb(255, 255, 255, 0.08);
  }
  body.cp-nav-open { overflow: hidden; }
  body.cp-nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgb(15, 23, 42, 0.45);
    z-index: 300;
    pointer-events: auto;
  }
  body.cp-nav-open .cp-header {
    z-index: 330;
  }
  body.cp-nav-open .cp-nav-toggle {
    z-index: 340;
    position: relative;
  }
  body.cp-nav-open .cp-sidebar {
    z-index: 325 !important;
  }

  .cp-mobile-nav-facility {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.45rem 0.35rem 0.65rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid rgb(255, 255, 255, 0.1);
  }
  .cp-mobile-facility-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 44px;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    border: 1px solid rgb(255, 255, 255, 0.14);
    background: rgb(255, 255, 255, 0.08);
    color: #fff;
    font: inherit;
    font-size: 0.88rem;
    text-align: left;
    cursor: pointer;
  }
  .cp-mobile-facility-btn span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .cp-mobile-facility-actions {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
  }
  .cp-mobile-facility-actions .btn-sm {
    flex: 1 1 calc(33.33% - 0.35rem);
    min-width: 0;
    min-height: 40px;
    padding: 0.4rem 0.35rem;
    font-size: 0.75rem;
    color: #e2e8f0;
    border-color: rgb(255, 255, 255, 0.2);
    background: transparent;
  }

  .header-nav .nav-link {
    width: 100%;
    justify-content: flex-start;
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    font-size: 0.92rem;
    border-radius: 10px;
    color: #f8fafc !important;
  }
  .header-nav .nav-link span {
    display: inline;
    white-space: normal;
    line-height: 1.25;
  }
  .header-nav .nav-link.active::after { display: none; }
  .header-nav .nav-link.active {
    background: rgb(20, 184, 166, 0.22);
    color: #fff !important;
  }
  .cp-side-nav-label {
    color: rgb(255, 255, 255, 0.65);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0.35rem 0.5rem;
  }

  .hdr-btn,
  .user-chip {
    min-width: 44px;
    min-height: 44px;
  }
  .header-right {
    justify-content: space-between;
  }

  .cp-main { padding: 0.85rem; max-width: 100%; overflow-x: hidden; }
  .dash-welcome h1 { font-size: 1.35rem; line-height: 1.25; }
  .dash-welcome p { font-size: 0.85rem; }
  .dash-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }

  .kpi-strip,
  .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
  }
  .kpi-card {
    padding: 0.75rem;
    min-width: 0;
  }
  .kpi-value { font-size: 1.25rem; }
  .kpi-label { font-size: 0.72rem; }

  .panel,
  .panel-body { min-width: 0; }
  .panel-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Toolbars: stack actions full-width on phone */
  .toolbar-right .toolbar-select,
  .toolbar-right .search-box {
    flex: 1 1 100%;
  }
  .toolbar-right .btn-primary,
  .toolbar-right .btn-outline,
  .toolbar-right .btn-danger {
    flex: 1 1 calc(50% - 0.45rem);
  }
  .toolbar-right > .cp-date-nav {
    flex: 1 1 100%;
  }
  .search-box { width: 100%; }
  .search-box input { width: 100%; min-height: 44px; }
  .sub-tabs {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Tables / MAR / compliance: contain overflow inside scroll wraps */
  .mar-table-wrapper,
  .data-table-wrap,
  .table-scroll,
  .rota-grid,
  .cp-patients-table-wrap,
  .cp-staff-table-wrap,
  .cp-dir-table-wrap,
  .panel-body,
  .compliance-grid,
  .audit-list,
  #expiringBody {
    max-width: 100%;
  }
  .cp-patients-table-wrap,
  .cp-staff-table-wrap,
  .cp-dir-table-wrap,
  .mar-table-wrapper,
  .rota-grid,
  .table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  .mar-table-wrapper table,
  .cp-patients-table-wrap table,
  .cp-staff-table-wrap table,
  .cp-dir-table-wrap table,
  .rota-grid table,
  table.data-table {
    width: max-content;
    min-width: 100%;
    max-width: none;
  }
  .mar-container,
  #cp-mar-sheet {
    max-width: 100%;
    overflow: hidden;
  }
  .mar-table {
    font-size: 0.7rem;
    min-width: 640px;
  }
  .mar-table th,
  .mar-table td {
    padding: 0.25rem;
  }
  button.mar-cell {
    min-width: 28px;
    min-height: 28px;
  }

  .rota-row {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .rota-row > * { min-width: 72px; }

  /* Cards / lists */
  .resident-card,
  .incident-card,
  .note-card,
  .staff-card {
    max-width: 100%;
    overflow: hidden;
  }
  .res-actions,
  .cp-card-actions,
  .staff-card-actions,
  .inc-meta {
    flex-wrap: wrap;
    gap: 0.35rem;
  }
  .inc-meta-item {
    max-width: 100%;
    word-break: break-word;
  }
  .inc-status-inline {
    width: 100%;
    justify-content: space-between;
  }
  .inc-status-inline select {
    flex: 1;
    min-height: 40px;
  }

  .rooms-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .cp-section-empty {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
    gap: 0.75rem;
  }
  .cp-section-empty-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
  }
  .cp-section-empty-actions .btn-primary,
  .cp-section-empty-actions .btn-outline {
    flex: 1 1 calc(50% - 0.45rem);
    min-height: 44px;
  }

  /* Modals */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal,
  .modal-box {
    width: 100%;
    max-width: 100vw !important;
    max-height: min(92vh, 100%);
    margin: 0;
    border-radius: 16px 16px 0 0;
  }
  .modal-header,
  .modal-footer {
    padding: 0.85rem 1rem;
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  .modal-footer .btn-primary,
  .modal-footer .btn-outline,
  .modal-footer .btn-danger {
    flex: 1 1 auto;
    min-height: 44px;
  }
  .modal-body {
    padding: 0.85rem 1rem;
    max-height: calc(92vh - 8rem);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .cp-ampm-row {
    width: 100%;
  }
  .cp-ampm-row input,
  .cp-ampm-row select {
    min-height: 44px;
  }
  .mood-selector {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
  }
  .mood-btn {
    min-width: 0;
    min-height: 44px;
    justify-content: center;
  }

  .staff-cards { grid-template-columns: 1fr; }
  .count-badge { white-space: normal; }

  /* Floating AI / chat must not cover primary actions */
  .elinom-copilot-fab,
  .ai-fab,
  [class*="copilot"][class*="fab"],
  #chatWidget,
  #chatToggleBtn {
    bottom: 1rem !important;
    right: 0.75rem !important;
    z-index: 40 !important;
  }
  /* Leave space so FAB does not cover last KPI / card actions */
  .cp-main {
    padding-bottom: 4.5rem;
  }
}

@media (width <= 600px) {
  .brand-suffix { display: none; }
  .cp-persist-dot { display: none; }
  .kpi-strip,
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .kpi-card { padding: 0.7rem; }
  .kpi-value { font-size: 1.2rem; }
  .toolbar-right .btn-primary,
  .toolbar-right .btn-outline:not(.cp-date-nav-btn),
  .toolbar-right .btn-danger {
    flex: 1 1 100%;
  }
  .toolbar-right > .cp-date-nav {
    flex: 1 1 100%;
  }
}

@media (width <= 480px) {
  .cp-main { padding: 0.65rem; }
  /* Keep a compact 2-up KPI mosaic on phones — single column wastes the viewport */
  .kpi-strip,
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-header,
  .panel-body { padding-left: 0.85rem; padding-right: 0.85rem; }
  .rooms-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .appt-card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }
  .appt-status-rail {
    width: 100%;
    align-items: stretch;
  }
  .appt-status-rail .inc-status-inline {
    align-items: stretch;
  }
  .appt-status-rail .appt-status-select {
    width: 100%;
    min-width: 0;
  }
}

/* ═══════════════════════════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════
   MARKUP CLASS ALIASES (carepro.html compatibility)
   ═══════════════════════════════════════════════════════════ */
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}
.panel-header h3 {
  font-size: 0.92rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.panel-header h3 i { color: var(--primary); font-size: 0.9rem; }

.panel-body { padding: 0.75rem 1.25rem 1rem; }

.badge {
  background: var(--primary-pale);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 10px;
}
.badge.danger { background: var(--danger-light); color: var(--danger); }

.hdr-btn {
  width: 36px;
  height: 36px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid rgb(255,255,255,0.08);
  background: rgb(255,255,255,0.04);
  color: rgb(255,255,255,0.6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  flex-shrink: 0;
}
.hdr-btn:hover { background: rgb(255,255,255,0.1); color: #fff; }

.notif-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #1e293b;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.25rem;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.15rem 0.25rem;
  border-radius: 10px;
  font-family: var(--font);
}
.user-chip:hover { background: rgb(255,255,255,0.06); }
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--care-teal), var(--primary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}
.user-label {
  color: rgb(255,255,255,0.7);
  font-size: 0.82rem;
  font-weight: 500;
}

.modal {
  background: #fff;
  background: var(--bg-card, #fff);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s ease;
  opacity: 1;
  isolation: isolate;
}
.modal.modal-lg { max-width: 780px; }
#nurseRegisterModal.open {
  display: flex;
  pointer-events: auto;
}
#nurseRegisterModal .modal {
  background: #fff;
  opacity: 1;
  pointer-events: auto;
  position: relative;
  z-index: 1;
}
#nurseRegisterModal .modal-footer .btn-primary,
#nurseRegisterModal .modal-footer .btn-outline,
#secNurses .btn-primary,
#cpNursesRegisterBtn,
#cpRegisterNurseBtn,
#cpStaffRegisterNurseBtn,
[data-care-action="open-nurse-register"],
[data-care-action="save-nurse"],
[data-care-action="nurse-tab"] {
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  z-index: 1;
}
#secNurses .btn-primary,
#cpNursesRegisterBtn,
#cpRegisterNurseBtn {
  background: linear-gradient(135deg, #0f766e, #0d9488);
  color: #fff;
  border: none;
}
#secNurses .nurses-panel,
#secNurses .cp-nurse-capacity-host,
#secNurses .cp-nurse-capacity-row {
  opacity: 1;
  color: var(--text);
}
.cp-nurse-empty {
  padding: 1rem 0.25rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  min-width: 0;
  flex: 1;
}
.modal-header h3 i { color: var(--primary); }
.modal-header .modal-close {
  margin-left: auto;
  flex-shrink: 0;
  order: 2;
}

.cp-header .notif-panel {
  position: absolute;
  top: 64px;
  right: 1rem;
  width: 360px;
  max-width: calc(100vw - 2rem);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: none;
  overflow: hidden;
}
.cp-header .notif-panel.open { display: block; }
.cp-header .notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.cp-header .notif-panel-header h4 {
  font-size: 0.88rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.cp-header .notif-panel-body { max-height: 320px; overflow-y: auto; }
.cp-header .notif-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: var(--transition);
}
.cp-header .notif-item:hover { background: var(--border-light); }
.cp-header .notif-item.unread { background: var(--primary-pale); }
.cp-header .notif-item-body { flex: 1; min-width: 0; }
.cp-header .notif-item-body strong { display: block; font-size: 0.82rem; }
.cp-header .notif-item-body span { font-size: 0.75rem; color: var(--text-secondary); }
.cp-header .notif-panel-footer {
  text-align: center;
  padding: 0.6rem;
  border-top: 1px solid var(--border);
}
.cp-header .link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

@media (width <= 768px) {
  .cp-header .notif-panel { right: 0.5rem; width: calc(100vw - 1rem); }
}

/* ── Family portal invite ──────────────────────────────── */
.cp-family-portal {
  margin-bottom: 1.25rem;
}
.cp-family-portal-lead {
  margin: 0 0 1rem;
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.45;
  max-width: 52rem;
}
.cp-family-empty {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm, 10px);
  background: var(--bg-subtle, #f8fafc);
}
.cp-family-empty[hidden] { display: none !important; }
.cp-family-empty-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--primary-pale, #ecfeff);
  color: var(--primary);
  flex-shrink: 0;
}
.cp-family-empty strong { display: block; margin-bottom: 0.25rem; }
.cp-family-empty p {
  margin: 0 0 0.75rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* ── Section empty states (MAR / incidents / appointments) ── */
.cp-section-empty {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.1rem 1.2rem;
  margin: 0 0 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm, 10px);
  background: var(--bg-subtle, #f8fafc);
}
.cp-section-empty[hidden] { display: none !important; }
.cp-section-empty-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--primary-pale, #ecfeff);
  color: var(--primary);
  flex-shrink: 0;
}
.cp-section-empty strong { display: block; margin-bottom: 0.25rem; }
.cp-section-empty p {
  margin: 0 0 0.75rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.4;
}
.cp-section-empty-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.empty-state {
  text-align: center;
  padding: 2.5rem 1.25rem;
  color: var(--text-muted);
}
.empty-state i {
  display: block;
  font-size: 1.5rem;
  margin-bottom: 0.6rem;
  opacity: 0.7;
}
.empty-state p { margin: 0; font-size: 0.9rem; }
.cp-mar-inline-empty {
  margin-top: 0.65rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}
.cp-family-form .cp-field-hint {
  font-size: 0.72rem;
  color: var(--text-muted, #64748b);
  line-height: 1.35;
}
.cp-family-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.cp-family-actions .btn-primary,
.cp-family-actions .btn-outline {
  width: auto;
}
.cp-portal-msg {
  min-height: 1.25rem;
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  line-height: 1.4;
}
.cp-portal-msg.is-success {
  color: #0f766e;
  background: #ecfdf5;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
}
.cp-portal-msg.is-error {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
}
.cp-portal-msg .cp-temp-creds {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.45rem;
}
.cp-portal-msg code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  background: rgba(15, 23, 42, 0.06);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}
.cp-portal-accounts {
  margin-top: 1.1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}
.cp-portal-accounts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}
.cp-portal-accounts-head h4 {
  margin: 0;
  font-size: 0.92rem;
}
.cp-portal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}
.cp-portal-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card, #fff);
}
.cp-portal-list .cp-portal-meta {
  min-width: 0;
  flex: 1;
}
.cp-portal-list .cp-portal-meta strong {
  display: block;
  font-size: 0.88rem;
}
.cp-portal-list .cp-portal-meta span {
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.cp-portal-list .cp-portal-empty-row {
  color: var(--text-secondary);
  font-size: 0.85rem;
  border-style: dashed;
  justify-content: center;
}
.btn-sm {
  height: 32px;
  padding: 0 0.7rem;
  font-size: 0.78rem;
}

/* Facilities / beds / AM-PM / card actions */
.facilities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
}
.facility-card {
  border: 1px solid var(--border-light, #e2e8f0);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  background: #fff;
}
.facility-card.active {
  border-color: var(--care-teal, #0f766e);
  box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.2);
}
.facility-card-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.facility-card-meta,
.facility-card-addr {
  font-size: 0.78rem;
  color: var(--text-secondary, #64748b);
}
.room-fac {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted, #94a3b8);
  margin-top: 0.2rem;
}
.inc-status-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-secondary, #64748b);
}
.inc-status-inline select {
  font-size: 0.75rem;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border-light, #e2e8f0);
}
.cp-mar-med-actions {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border-light, #e2e8f0);
}

@media (width <= 720px) {
  .cp-family-empty { flex-direction: column; }
  .cp-family-form .form-grid { grid-template-columns: 1fr; }
}

/* ── Nurse duty & patient attendance ────────────────────── */
.cp-duty-panel { margin-bottom: 1.25rem; }
.cp-duty-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.cp-duty-lead {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  max-width: 42rem;
  line-height: 1.4;
}
.cp-duty-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}
.cp-duty-date-label {
  display: inline-flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}
.cp-duty-date-label input[type="date"] {
  height: 36px;
  padding: 0 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text);
  background: #fff;
}
.cp-duty-day-label {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--text-secondary);
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  background: var(--bg-subtle, #f8fafc);
  border: 1px solid var(--border);
}
.cp-duty-recorder {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 12rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cp-duty-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.cp-duty-table {
  margin: 0;
  min-width: 980px;
}
.cp-duty-table th,
.cp-duty-table td {
  vertical-align: middle;
  padding: 0.45rem 0.5rem;
}
.cp-duty-table select,
.cp-duty-table input[type="text"],
.cp-duty-table input[type="number"],
.cp-duty-table textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font-size: 0.8rem;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
.cp-duty-table textarea {
  min-height: 2.4rem;
  resize: vertical;
}
.cp-duty-time-cell {
  white-space: nowrap;
  min-width: 9.5rem;
  max-width: 11rem;
  vertical-align: middle;
}
.cp-duty-time-cell .cp-ampm-row {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.2rem;
  width: auto;
}
.cp-duty-time-cell input[type="number"] {
  width: 2.6rem;
  min-width: 2.6rem;
  max-width: 2.6rem;
  text-align: center;
  padding: 0.3rem 0.15rem;
}
.cp-duty-time-cell select {
  width: 3.6rem;
  min-width: 3.6rem;
  max-width: 3.6rem;
  padding: 0.3rem 0.15rem;
}
.cp-duration-cell {
  white-space: nowrap;
}
.cp-duration-cell .cp-duration-stack {
  display: inline-flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-start;
}
.cp-duration-cell .cp-ampm-row {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.2rem;
}
.dash-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  padding: 0.35rem 0 0.25rem;
}
.dash-welcome {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 48rem;
}
.dash-welcome h1 {
  margin: 0 0 0.55rem;
  font-size: clamp(1.55rem, 2.2vw, 2rem);
  line-height: 1.25;
  letter-spacing: -0.02em;
  font-weight: 750;
}
.dash-welcome p {
  margin: 0;
  max-width: 40rem;
  font-size: 0.98rem;
  line-height: 1.65;
  color: var(--text-secondary);
}
.dash-date {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.9rem;
  white-space: nowrap;
}
.facility-card.is-unavailable {
  opacity: 0.72;
  border-style: dashed;
}
.note-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.65rem;
}
.cp-duty-actions-col { width: 2.5rem; }
.cp-duty-empty { margin: 0.75rem 0 0; font-size: 0.85rem; }
@media (width <= 768px) {
  .cp-duty-header { flex-direction: column; }
  .cp-duty-toolbar { width: 100%; }
  .cp-duty-toolbar .btn-sm { min-height: 40px; }
}

/* ── Nurse registration ─────────────────────────────────── */
.cp-nurse-panel-lead,
.cp-nurse-modal-lead {
  margin: 0 0 0.85rem;
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.45;
}
.cp-nurse-capacity {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.cp-nurse-capacity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 10px);
  background: var(--bg-subtle, #f8fafc);
}
.cp-nurse-capacity-row.is-full {
  border-color: rgb(220, 38, 38, 0.35);
  background: rgb(254, 242, 242);
}
.cp-nurse-capacity-meta {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.cp-nurse-capacity-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.cp-nurse-capacity-hint.is-full { color: var(--danger, #dc2626); font-weight: 600; }
.form-group-span { grid-column: 1 / -1; }
.req-note { font-weight: 500; color: var(--text-muted); font-size: 0.78rem; }
.cp-upload-preview {
  margin-top: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--bg-subtle, #f8fafc);
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.cp-upload-preview img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.cp-upload-list {
  list-style: none;
  margin: 0.45rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.cp-upload-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.staff-card-avatar-photo {
  padding: 0;
  overflow: hidden;
}
.staff-card-avatar-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
#nurseRegisterModal input[type="file"] {
  width: 100%;
  max-width: 100%;
  font-size: 0.85rem;
}

@media (width <= 768px) {
  .cp-nurse-capacity-row {
    flex-wrap: wrap;
  }
  .cp-nurse-capacity-row .btn-sm {
    flex: 1 1 100%;
    min-height: 44px;
  }
}

/* ── Patients table / LPA / appointments status rail ───── */
.cp-patients-table-wrap {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.cp-patients-table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
}
.cp-patients-table th,
.cp-patients-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
  font-size: 0.82rem;
}
.cp-patients-table th {
  background: var(--bg);
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.cp-patient-actions {
  white-space: nowrap;
}
.cp-lpa-row .cp-lpa-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 500;
  cursor: pointer;
  width: auto;
}
.cp-lpa-check,
#nokPOA1.cp-lpa-check {
  width: 0.95rem !important;
  height: 0.95rem !important;
  max-width: 0.95rem !important;
  min-width: 0.95rem !important;
  margin: 0 !important;
  flex: 0 0 0.95rem !important;
  accent-color: var(--primary);
}

.appt-card-header,
.incident-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.appt-card-main { flex: 1; min-width: 0; }
.appt-status-rail,
.inc-status-rail {
  flex: 0 0 auto;
  margin-left: auto;
  align-self: flex-start;
}
.appt-status-rail .status-pill,
.inc-status-select {
  white-space: nowrap;
}

.header-nav .nav-link-appointments span {
  display: block !important;
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
}
.cp-side-nav.header-nav .nav-link,
.header-nav.cp-side-nav .nav-link {
  flex-shrink: 0;
  padding: 0.7rem 0.85rem;
  font-size: 0.88rem;
  width: 100%;
}

.mar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--border-light);
}
.mar-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.mar-legend-item .mar-cell {
  cursor: default;
  pointer-events: none;
}
.mar-legend-label { color: var(--text); }

.mar-header-bar,
.mar-resident-info {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  padding: 0.85rem 1.15rem;
  min-width: 0;
}
.mar-resident-info strong,
.mar-table td:first-child,
.mar-table td:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 14rem;
}
.mar-table-wrapper,
.mar-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.cp-print-letterhead {
  border-bottom: 2px solid #0f766e;
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
}
.cp-print-letterhead h1 {
  margin: 0;
  font-size: 1.25rem;
  color: #0f766e;
}
.cp-print-letterhead p {
  margin: 0.15rem 0;
  font-size: 0.88rem;
  color: #334155;
}
.cp-print-patient-block {
  margin-bottom: 1rem;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* ═══════════════════════════════════════════════════════════
   PRINT
   ═══════════════════════════════════════════════════════════ */
@media print {
  .cp-header, .section-toolbar, .toast-container { display: none !important; }
  .cp-section { display: block !important; -moz-column-break-inside: avoid; break-inside: avoid; }
  .cp-main { padding: 0; }
  .panel, .resident-card, .note-card, .incident-card { box-shadow: none; border: 1px solid #ccc; }

  /* Default: hide overlays so print is not blank/muddled */
  .modal-overlay { display: none !important; }

  /* Care plan print: show only the care-plan modal content with letterhead */
  body.cp-printing-careplan * { visibility: hidden !important; }
  body.cp-printing-careplan .modal-overlay,
  body.cp-printing-careplan .modal-overlay * { visibility: visible !important; }
  body.cp-printing-careplan .modal-overlay {
    display: block !important;
    position: static !important;
    background: transparent !important;
    inset: auto !important;
  }
  body.cp-printing-careplan .modal-overlay:not(#cpCarePlanModal) { display: none !important; }
  body.cp-printing-careplan #cpCarePlanModal {
    display: block !important;
    position: static !important;
    background: #fff !important;
  }
  body.cp-printing-careplan #cpCarePlanModal .modal {
    box-shadow: none !important;
    border: none !important;
    max-width: none !important;
    width: 100% !important;
  }
  body.cp-printing-careplan #cpCarePlanModal .modal-header,
  body.cp-printing-careplan #cpCarePlanModal .modal-footer,
  body.cp-printing-careplan #cpCarePlanModal .modal-close {
    display: none !important;
  }
  body.cp-printing-careplan #cpCarePlanBody {
    display: block !important;
    padding: 0 !important;
  }
}
