/* ═══════════════════════════════════════════════════════════
   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;
}

/* ── HEADER NAV ────────────────────────────────────────── */
.header-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.header-nav::-webkit-scrollbar { display: none; }

.header-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-xs);
  font-size: 0.82rem;
  font-weight: 500;
  color: rgb(255,255,255,0.5);
  text-decoration: none;
  white-space: nowrap;
  transition: var(--transition);
  position: relative;
}

.header-nav .nav-link:hover {
  color: rgb(255,255,255,0.85);
  background: rgb(255,255,255,0.06);
}

.header-nav .nav-link.active {
  color: #fff;
  background: rgb(99, 102, 241, 0.35);
}

.header-nav .nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  border-radius: 3px;
  background: var(--primary-light);
}

/* ── 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: 1600px;
  margin: 0 auto;
}

.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 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.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 {
  display: none;
  animation: fadeUp 0.3s ease;
}
.staff-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); }

/* 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,
.modal-body .form-group select,
.modal-body .form-group textarea,
.modal-body .form-field input,
.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,
.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
   ═══════════════════════════════════════════════════════════ */
@media (width <= 1200px) {
  .panel-wide { grid-column: span 1; }
  .compliance-grid { grid-template-columns: 1fr; }
}

@media (width <= 900px) {
  .cp-header {
    padding: 0 1rem;
    gap: 0.75rem;
  }
  .facility-pill { display: none; }
  .user-name { display: none; }
  .header-nav .nav-link span { display: none; }

  .cp-main { padding: 1rem; }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .dash-grid { grid-template-columns: 1fr; }
  .residents-grid { grid-template-columns: 1fr; }
  .cqc-kloe-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .section-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { flex-wrap: wrap; }
  .sub-tabs { overflow-x: auto; width: 100%; }
  .risk-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .res-details { grid-template-columns: 1fr; }
}

.cp-nav-toggle {
  display: none;
  margin-left: auto;
}

@media (width <= 768px) {
  .cp-header {
    position: relative;
    flex-wrap: wrap;
  }

  .cp-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .header-nav {
    display: none;
    order: 4;
    flex: 1 1 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    overflow: visible;
    max-height: none;
    padding: 0.35rem 0 0.5rem;
    border-top: 1px solid rgb(255, 255, 255, 0.08);
  }

  .header-nav.is-open {
    display: flex;
  }

  .header-nav .nav-link {
    width: 100%;
    justify-content: flex-start;
  }

  .header-nav .nav-link span {
    display: inline;
  }

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

@media (width <= 600px) {
  .cp-header { height: auto; min-height: 56px; }
  .brand-suffix { display: none; }

  .header-nav .nav-link {
    padding: 0.4rem 0.5rem;
    font-size: 0.9rem;
  }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .kpi-card { padding: 0.9rem; }
  .kpi-value { font-size: 1.3rem; }
  .modal-body { padding: 1rem; }
  .mood-selector { gap: 0.35rem; }
  .mood-btn { min-width: 52px; padding: 0.35rem 0.5rem; }
  .mar-table { font-size: 0.72rem; }
  .staff-cards { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════
   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); }

/* ═══════════════════════════════════════════════════════════
   MOBILE OVERRIDES — CarePro-specific
   ═══════════════════════════════════════════════════════════ */
@media (width <= 768px) {
  .rota-row {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .rota-row > * {
    min-width: 80px;
  }
}

@media (width <= 480px) {
  .cp-main { padding: 0.75rem; }
  .kpi-row { grid-template-columns: 1fr; }
  .kpi-card { padding: 0.75rem; }
  .panel { padding: 0.75rem; }
  .cp-header { padding: 0 0.5rem; gap: 0.4rem; }
}

/* ═══════════════════════════════════════════════════════════
   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: 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.modal-lg { max-width: 780px; }

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

/* ═══════════════════════════════════════════════════════════
   PRINT
   ═══════════════════════════════════════════════════════════ */
@media print {
  .cp-header, .section-toolbar, .modal-overlay, .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; }
}
