/* ============================================================
   OMEGA LAB - Main Stylesheet
   ============================================================ */
:root {
  --primary: #1565c0;
  --primary-dark: #003c8f;
  --primary-light: #e3f0ff;
  --accent: #00897b;
  --danger: #c62828;
  --warning: #f57c00;
  --success: #2e7d32;
  --info: #0277bd;
  --sidebar-w: 240px;
  --topbar-h: 55px;
  --bg: #f0f4f8;
  --card-bg: #fff;
  --border: #d0d8e4;
  --text: #1a2332;
  --text-muted: #607080;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(21, 101, 192, .10);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ── TOPBAR ─────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: var(--primary-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .5px;
}

.brand i {
  color: #90caf9;
  margin-right: 6px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
}

.branch-badge {
  background: rgba(255, 255, 255, .15);
  padding: 4px 10px;
  border-radius: 20px;
}

.user-info {
  opacity: .9;
}

.btn-logout {
  color: #ffcdd2;
  text-decoration: none;
  font-weight: 600;
}

.btn-logout:hover {
  color: #fff;
}

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--primary-dark);
  overflow-y: auto;
  transition: left .25s ease, transform .25s ease;
  z-index: 900;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) var(--primary-dark);
}

.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-w)));
}

.sidebar nav ul {
  list-style: none;
  padding: 10px 0 60px;
}

.sidebar nav ul li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: #b0bec5;
  text-decoration: none;
  font-size: 13.5px;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}

.sidebar nav ul li a:hover,
.sidebar nav ul li a.active {
  background: rgba(255, 255, 255, .07);
  color: #fff;
  border-left-color: var(--primary-light, #42a5f5);
}

.sidebar nav ul li a i {
  width: 18px;
  text-align: center;
  font-size: 14px;
}

.nav-section {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #546e90;
  text-transform: uppercase;
  padding: 18px 18px 5px;
  margin-top: 4px;
}

/* ── MAIN CONTENT ────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 24px;
  min-height: calc(100vh - var(--topbar-h));
  transition: margin-left .25s ease;
}

.main-content.expanded {
  margin-left: 0;
}

/* ── FOOTER ──────────────────────────────────────────────── */
.app-footer {
  margin-left: var(--sidebar-w);
  padding: 10px 24px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  transition: margin-left .25s ease;
}

/* ── PAGE HEADER ─────────────────────────────────────────── */
.page-header {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-dark);
}

.page-title i {
  margin-right: 8px;
  color: var(--primary);
}

.breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── CARDS ───────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #f5f8ff 0%, #fff 100%);
  border-radius: var(--radius) var(--radius) 0 0;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-dark);
}

.card-body {
  padding: 18px;
}

/* ── STAT CARDS (DASHBOARD) ──────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-card.green {
  border-color: var(--success);
}

.stat-card.orange {
  border-color: var(--warning);
}

.stat-card.red {
  border-color: var(--danger);
}

.stat-card.teal {
  border-color: var(--accent);
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary-dark);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.stat-icon {
  font-size: 32px;
  color: #c7d8f0;
  text-align: right;
}

/* ── TABLES ──────────────────────────────────────────────── */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive table {
  width: auto;
  min-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th {
  background: #f0f4ff;
  color: var(--primary-dark);
  font-weight: 700;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 9px 12px;
  border-bottom: 1px solid #eef0f5;
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: #f6f9ff;
}

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

.badge-success {
  background: #e8f5e9;
  color: #2e7d32;
}

.badge-warning {
  background: #fff3e0;
  color: #e65100;
}

.badge-danger {
  background: #ffebee;
  color: #c62828;
}

.badge-info {
  background: #e1f5fe;
  color: #01579b;
}

.badge-primary {
  background: #e3f2fd;
  color: #1565c0;
}

.badge-gray {
  background: #f5f5f5;
  color: #555;
}

/* ── FORMS ───────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.form-grid.cols-2 {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.form-control {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  width: 100%;
  transition: border-color .2s, box-shadow .2s;
  background: #fff;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21, 101, 192, .12);
  outline: none;
}

.form-control[readonly] {
  background: #f5f7fa;
  color: #555;
}

.form-section {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--primary);
  margin: 18px 0 8px;
  padding-bottom: 5px;
  border-bottom: 2px solid var(--primary-light);
}

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: all .2s;
}

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

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

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  background: #1b5e20;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #7f0000;
}

.btn-warning {
  background: var(--warning);
  color: #fff;
}

.btn-warning:hover {
  background: #e65100;
}

.btn-info {
  background: var(--info);
  color: #fff;
}

.btn-info:hover {
  background: #01579b;
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: #fff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── ALERTS ──────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-success {
  background: #e8f5e9;
  color: #1b5e20;
  border-left: 4px solid var(--success);
}

.alert-danger {
  background: #ffebee;
  color: #7f0000;
  border-left: 4px solid var(--danger);
}

.alert-warning {
  background: #fff3e0;
  color: #bf360c;
  border-left: 4px solid var(--warning);
}

.alert-info {
  background: #e1f5fe;
  color: #01579b;
  border-left: 4px solid var(--info);
}

/* ── SEARCH BAR ──────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-bar .form-control {
  max-width: 320px;
}

/* ── RESULT ENTRY ────────────────────────────────────────── */
.result-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1.5fr 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.result-row:last-child {
  border-bottom: none;
}

.test-name {
  font-weight: 600;
  color: var(--primary-dark);
}

.result-group {
  font-size: 11px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 6px 10px;
  background: #f0f4ff;
  border-radius: 4px;
  margin: 12px 0 4px;
  font-weight: 700;
}

.flag-H {
  color: var(--danger);
  font-weight: 800;
}

.flag-L {
  color: var(--info);
  font-weight: 800;
}

/* ── PRINT STYLES ────────────────────────────────────────── */
@media print {

  .sidebar,
  .topbar,
  .app-footer,
  .no-print,
  .btn-group,
  .search-bar,
  .chat-window,
  .chat-fab,
  .customizer-panel {
    display: none !important;
  }

  .main-content {
    margin: 0 !important;
    padding: 0 !important;
  }

  body {
    background: #fff;
  }

  table {
    border-collapse: collapse;
  }

  td,
  th {
    border: 1px solid #ccc;
  }
}

/* ── CONTENT GRID (mobile-friendly two-column layout) ──── */
.content-grid {
  display: grid;
  gap: 20px;
}

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 768px) {

  .main-content,
  .app-footer {
    margin-left: 0 !important;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .content-grid {
    grid-template-columns: 1fr !important;
  }

  .branch-dropdown {
    min-width: unset;
    width: 90vw;
    right: 5vw;
  }

  .main-content {
    max-width: 100vw;
    overflow-x: hidden;
  }
}

/* ── MISC ────────────────────────────────────────────────── */
.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.mt-1 {
  margin-top: 8px;
}

.mt-2 {
  margin-top: 16px;
}

.mt-3 {
  margin-top: 24px;
}

.mb-1 {
  margin-bottom: 8px;
}

.mb-2 {
  margin-bottom: 16px;
}

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

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

.text-danger {
  color: var(--danger);
}

.text-success {
  color: var(--success);
}

.text-primary {
  color: var(--primary);
}

.fw-bold {
  font-weight: 700;
}

.w-100 {
  width: 100%;
}

/* ── BRANCH SWITCHER ─────────────────────────────────────────────────────── */
.branch-switcher {
  position: relative;
}

.branch-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, .13);
  border: 1.5px solid rgba(255, 255, 255, .25);
  color: #fff;
  border-radius: 22px;
  padding: 5px 13px 5px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s;
  white-space: nowrap;
}

.branch-btn:hover {
  background: rgba(255, 255, 255, .22);
}

.branch-mid {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .5px;
}

.branch-name-short {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.branch-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 30, 80, .22);
  border: 1px solid var(--border);
  min-width: 200px;
  max-width: 260px;
  width: max-content;
  z-index: 3000;
  overflow: hidden;
}

.branch-dropdown-header {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  background: #f5f7fb;
  border-bottom: 1px solid var(--border);
}

.branch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  transition: background .12s;
  border-bottom: 1px solid #f0f2f8;
  white-space: nowrap;
  overflow: hidden;
}

.branch-item .bi-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.branch-item:last-child {
  border-bottom: none;
}

.branch-item:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.branch-item.active {
  background: #e3f2fd;
  color: var(--primary-dark);
  font-weight: 700;
}

.branch-item.active::after {
  content: '\2713';
  margin-left: auto;
  color: var(--primary);
  font-weight: 900;
}

.bi-mid {
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 800;
  min-width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.branch-item.active .bi-mid {
  background: var(--accent);
}

/* Single badge (no switcher) */
.branch-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, .13);
  border: 1.5px solid rgba(255, 255, 255, .2);
  color: #fff;
  border-radius: 22px;
  padding: 5px 12px;
  font-size: 12.5px;
}

/* Sidebar branch info bar */
.sidebar-branch-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .06);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  margin-bottom: 4px;
}

.sidebar-branch-info i {
  color: var(--accent);
  font-size: 16px;
  flex-shrink: 0;
}

/* ── MODAL ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: #fff;
  border-radius: 10px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  transform: scale(.95);
  transition: transform .2s;
}

.modal-overlay.open .modal-box {
  transform: scale(1);
}

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

.modal-header h3 {
  font-size: 16px;
  color: var(--primary-dark);
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Branch filter banner (shown on list pages) */
.branch-filter-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  padding: 9px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  flex-wrap: wrap;
}

.branch-filter-banner .bfb-mid {
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 800;
}
/* ══════════════════════════════════════════════════════════════
   RESPONSIVE FIXES - mobile & tablet
   ══════════════════════════════════════════════════════════════ */

/* ── Sidebar overlay for mobile ─────────────────────────────── */
#sidebarOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 899;
}

/* ── Topbar mobile: see consolidated block below ─────────────── */

/* ── Content-grid: all inline grid-template-columns override ─── */
@media (max-width: 900px) {
  /* All two-panel content-grid layouts stack */
  .content-grid[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  /* Register page two-column layout */
  div[style*="grid-template-columns:1.5fr 1fr"],
  div[style*="grid-template-columns: 1.5fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* Revenue report side-by-side */
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ── Page header: stack title & actions on small screens ──────── */
@media (max-width: 600px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-title {
    font-size: 18px;
  }
  .btn-group {
    width: 100%;
  }
  .btn-group .btn {
    flex: 1;
    justify-content: center;
  }
}

/* ── Tables: all tables get horizontal scroll ───────────────── */
@media (max-width: 768px) {
  /* Wrap any card-body table that isn't already wrapped */
  .card-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table {
    min-width: 500px;
  }
  /* Stat cards: 2 columns on mobile instead of many */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
  /* Search bars: stack on mobile */
  .search-bar {
    flex-direction: column;
  }
  .search-bar .form-control {
    max-width: 100%;
    width: 100%;
  }
  /* Result entry tabs wrap */
  .tabs {
    flex-wrap: wrap;
  }
  /* Patient view info boxes */
  div[style*="display:flex;gap:10px;flex-wrap:wrap;font-size:12px"] {
    flex-direction: column;
  }
  /* Modal: full width on mobile */
  .modal-box {
    max-width: 96vw;
    margin: 0 2vw;
  }
  /* Form grid forced single column */
  .form-grid,
  .form-grid.cols-2,
  div[style*="grid-template-columns:1fr 1fr"].form-grid {
    grid-template-columns: 1fr !important;
  }
  /* Filter forms that use inline flex */
  form[style*="display:flex"] {
    flex-direction: column;
    align-items: stretch !important;
  }
  form[style*="display:flex"] .form-control,
  form[style*="display:flex"] select,
  form[style*="display:flex"] input {
    width: 100%;
    max-width: 100%;
  }
  /* Branch filter banner wrapping */
  .branch-filter-banner {
    gap: 6px;
  }
  .branch-filter-banner .btn {
    margin-left: 0 !important;
    width: 100%;
    justify-content: center;
  }
}

/* ── Small mobile (<480px) ──────────────────────────────────── */
@media (max-width: 480px) {
  .main-content {
    padding: 12px;
  }
  .card-body {
    padding: 12px;
  }
  .card-header {
    padding: 10px 12px;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .stat-value {
    font-size: 22px;
  }
  .result-row {
    grid-template-columns: 1fr !important;
    gap: 4px;
  }
  /* Table font size reduction for very small screens */
  table {
    font-size: 12px;
  }
  th, td {
    padding: 7px 8px;
  }
  .btn {
    padding: 7px 12px;
    font-size: 12px;
  }
}

/* ── Sidebar mobile: slides in as overlay ───────────────────── */
@media (max-width: 768px) {
  .sidebar {
    display: none;
    z-index: 900;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    position: fixed;
  }
  .sidebar.mobile-open {
    display: block !important;
  }
  .main-content,
  .app-footer {
    margin-left: 0 !important;
  }
  .app-footer {
    margin-left: 0 !important;
  }
}

/* ── Tablet (769px – 1024px) ────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --sidebar-w: 200px;
  }
  .main-content {
    padding: 16px;
  }
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
  /* content-grid with fixed px columns: let them shrink */
  .content-grid[style*="340px"],
  .content-grid[style*="360px"],
  .content-grid[style*="400px"],
  .content-grid[style*="420px"] {
    grid-template-columns: 280px 1fr !important;
  }
}

/* ── Topbar: base fixes (all screens) ───────────────────────── */
.topbar {
  overflow: visible; /* allow dropdown to escape */
}

.topbar-right {
  flex-shrink: 1;
  min-width: 0;
  overflow: visible;
  gap: 10px;
}

/* ── Topbar: tablet (≤900px) — tighten spacing ──────────────── */
@media (max-width: 900px) {
  .branch-name-short {
    max-width: 100px;
  }
}

/* ── Topbar: mobile (≤600px) — icon-only compact bar ─────────── */
@media (max-width: 600px) {
  :root { --topbar-h: 50px; }

  .topbar {
    padding: 0 10px;
    height: var(--topbar-h);
  }

  .topbar-left {
    gap: 8px;
  }

  /* Brand: show only icon, hide text */
  .brand {
    font-size: 0; /* hide text */
    gap: 0;
  }
  .brand i,
  .brand img {
    font-size: 20px;
    height: 26px !important;
    margin-right: 0 !important;
  }

  .topbar-right {
    gap: 6px;
  }

  /* Branch switcher button: show MID badge only, hide branch name + chevron */
  .branch-btn {
    padding: 5px 8px;
    gap: 4px;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    justify-content: center;
    overflow: hidden;
  }
  .branch-name-short,
  .branch-btn .fa-chevron-down,
  .branch-btn > span:not(.branch-mid) {
    display: none !important;
  }
  .branch-mid {
    font-size: 10px;
    padding: 0;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Branch dropdown: full-width on mobile */
  .branch-dropdown {
    right: -10px;
    min-width: 220px;
    max-width: 92vw;
  }

  /* User info: icon only */
  .user-info {
    display: flex;
    align-items: center;
    width: 34px;
    height: 34px;
    justify-content: center;
    background: rgba(255,255,255,.13);
    border-radius: 50%;
    overflow: hidden;
  }
  .user-info i {
    font-size: 17px;
    flex-shrink: 0;
  }
  .user-info span,
  .user-info small,
  .user-info br {
    display: none !important;
    width: 0;
    overflow: hidden;
  }

  /* Logout: icon-only circle button */
  .btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,.13);
    border-radius: 50%;
    font-size: 0; /* hides text */
  }
  .btn-logout i {
    font-size: 15px;
  }
  .btn-logout:hover {
    background: rgba(255,100,100,.35);
  }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE CARD OVERFLOW FIXES
   ══════════════════════════════════════════════════════════════ */

/* Prevent the whole page from scrolling horizontally */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

.main-content {
  overflow-x: hidden;
  /* ensure padding doesn't push content out */
  box-sizing: border-box;
  max-width: 100%;
}

/* Cards must never exceed viewport */
.card {
  max-width: 100%;
  box-sizing: border-box;
}

.card-body {
  box-sizing: border-box;
  min-width: 0; /* allow shrinking inside grid/flex */
}

/* All images, iframes, embeds: never overflow their container */
img, iframe, embed, object, video {
  max-width: 100%;
  height: auto;
}

/* ── content-grid: ALL fixed-column inline styles collapse on mobile ── */
@media (max-width: 768px) {
  /* Target the grid wrapper itself */
  .content-grid {
    display: block !important;
  }
  .content-grid > * {
    width: 100% !important;
    min-width: 0 !important;
    margin-bottom: 16px;
  }

  /* register.php two-panel layout */
  div[style*="grid-template-columns:1.5fr"],
  div[style*="grid-template-columns: 1.5fr"] {
    display: block !important;
  }
  div[style*="grid-template-columns:1.5fr"] > div,
  div[style*="grid-template-columns: 1.5fr"] > div {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Select2 container override — must not exceed card width */
  .select2-container {
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box;
  }
  .select2-selection {
    box-sizing: border-box;
  }

  /* Tabs: allow wrapping, reduce padding */
  .tabs {
    flex-wrap: wrap !important;
    border-bottom: none !important;
  }
  .tab-btn {
    flex: 1 1 auto;
    min-width: 0;
    white-space: normal !important;
    word-break: break-word;
    text-align: center;
    border-radius: 6px !important;
    margin: 2px;
    border: 1px solid var(--border) !important;
  }
  .tab-btn.active {
    border-color: var(--primary) !important;
  }

  /* Form grid inside card-body: 1 column */
  .card-body .form-grid {
    grid-template-columns: 1fr !important;
  }
  /* grid-column span: revert so nothing pushes width */
  .card-body [style*="grid-column:1/-1"],
  .card-body [style*="grid-column: 1 / -1"] {
    grid-column: 1 / -1;
  }

  /* Discount row flex in billing card */
  .card-body div[style*="display:flex;gap:4px"] {
    flex-wrap: nowrap; /* keep discount type + value on same line */
  }
  .card-body div[style*="display:flex;gap:4px"] select {
    width: 80px !important;
    flex-shrink: 0;
  }
  .card-body div[style*="display:flex;gap:4px"] input {
    flex: 1;
    min-width: 0;
  }

  /* Patient info flex rows */
  .card-body div[style*="display:flex;gap:30px"] {
    flex-direction: column !important;
    gap: 8px !important;
  }

  /* Page header action buttons: don't force full-width on every btn */
  .page-header .btn-group {
    flex-wrap: wrap;
    gap: 6px;
  }
}

/* ── 480px and below: tighten further ──────────────────── */
@media (max-width: 480px) {
  .card-body {
    padding: 10px !important;
  }
  .card-header {
    padding: 8px 10px !important;
    flex-wrap: wrap;
    gap: 6px;
  }
  /* Selected tests table in register */
  #selectedTestsTable td,
  #selectedTestsTable th {
    padding: 5px 6px;
    font-size: 12px;
  }
  /* Stat cards single col */
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  /* Alert messages: prevent long content overflow */
  .alert {
    word-break: break-word;
    overflow-wrap: break-word;
  }
  .alert a.btn {
    display: inline-block;
    margin-top: 4px;
  }
}

/* ── Register page specific ──────────────────────────────── */
.reg-left-col,
.reg-right-col {
  min-width: 0;
  overflow: hidden;
}

/* Selected tests table: prevent overflow */
#selectedTestsTable {
  table-layout: fixed;
  word-break: break-word;
}
#selectedTestsTable th:nth-child(1),
#selectedTestsTable td:nth-child(1) {
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 768px) {
  .reg-left-col,
  .reg-right-col {
    width: 100%;
    display: block;
  }
}

/* ── Table actions column ────────────────────────────────── */
.actions-col {
  white-space: nowrap;
  width: 1%;  /* shrink to content */
}
@media (max-width: 480px) {
  .actions-col {
    white-space: normal;
  }
  .actions-col .btn {
    margin-bottom: 2px;
  }
}

/* ══════════════════════════════════════════════════════════════
   SWEETALERT2 THEME OVERRIDES
   ══════════════════════════════════════════════════════════════ */

.swal-omega-popup {
  font-family: 'Segoe UI', Arial, sans-serif !important;
  font-size: 14px !important;
  border-radius: 12px !important;
  padding: 24px 20px 20px !important;
}

.swal-omega-popup .swal2-title {
  font-size: 17px !important;
  font-weight: 700 !important;
  color: var(--primary-dark) !important;
}

.swal-omega-popup .swal2-html-container,
.swal-omega-popup .swal2-content {
  font-size: 13.5px !important;
  color: var(--text-muted) !important;
}

.swal-omega-confirm,
.swal-omega-cancel {
  font-size: 13px !important;
  font-weight: 700 !important;
  padding: 8px 20px !important;
  border-radius: 6px !important;
}

/* Loading spinner popup */
.swal2-popup.swal2-loading-spinner {
  width: auto !important;
  padding: 28px 32px !important;
}

/* Toast position tweak */
.swal2-container.swal2-top-end {
  top: 60px !important; /* below topbar */
}

/* ============================================================
   SELECT2 DARK MODE
   ============================================================ */
html.dark .select2-container--default .select2-selection--single {
  background: #1a2a3d;
  border-color: #2a3e56;
}
html.dark .select2-container--default .select2-selection--single .select2-selection__rendered {
  color: #dce4ef;
}
html.dark .select2-container--default .select2-selection--single .select2-selection__arrow {
  color: #7a8da4;
}
html.dark .select2-container--default .select2-selection--multiple {
  background: #1a2a3d;
  border-color: #2a3e56;
}
html.dark .select2-container--default .select2-selection--multiple .select2-selection__choice {
  background: #253348;
  color: #dce4ef;
  border-color: #3a4e68;
}
html.dark .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
  color: #7a8da4;
}
html.dark .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
  color: #ef5350;
}

/* Dropdown */
html.dark .select2-dropdown {
  background: #172030;
  border-color: #2a3e56;
}
html.dark .select2-results__option {
  color: #dce4ef;
}
html.dark .select2-results__option--highlighted,
html.dark .select2-results__option[aria-selected="true"] {
  background: #1a3a5c !important;
  color: #fff !important;
}
html.dark .select2-results__option[aria-selected="true"]:not(.select2-results__option--highlighted) {
  background: #1e2e42 !important;
}
html.dark .select2-search--dropdown .select2-search__field {
  background: #1a2a3d;
  border-color: #2a3e56;
  color: #dce4ef;
}
html.dark .select2-results__message {
  color: #7a8da4;
}
html.dark .select2-container--default.select2-container--open .select2-selection--single,
html.dark .select2-container--default.select2-container--open .select2-selection--multiple {
  border-color: var(--primary);
}
html.dark .select2-container--default .select2-search--dropdown .select2-search__field {
  background: #1a2a3d;
  border-color: #2a3e56;
  color: #dce4ef;
}

/* ============================================================
   MODALS DARK MODE
   ============================================================ */
html.dark .modal-box {
  background: #172030;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}

html.dark .modal-header {
  background: #1a2a3d;
  border-color: #253348;
}

html.dark .modal-header h3 {
  color: #dce4ef;
}

html.dark .modal-close {
  color: #7a8da4;
}

html.dark .modal-footer {
  background: #141e2c;
  border-color: #253348;
}

/* Override inline modal styles (branches.php, expenses.php, etc.) */
html.dark .modal-box,
html.dark .modal-overlay .modal-box {
  background: #172030 !important;
  box-shadow: 0 24px 80px rgba(0,0,0,.6) !important;
}

html.dark .modal-overlay {
  background: rgba(0,0,0,.65) !important;
}

html.dark .modal-footer,
html.dark .modal-overlay .modal-footer {
  background: #141e2c !important;
  border-color: #253348 !important;
}

html.dark .modal-overlay .modal-body {
  background: #172030;
}

html.dark .modal-overlay .modal-body table th {
  background: #1a2a3d;
  color: #dce4ef;
  border-color: #253348;
}

html.dark .modal-overlay .modal-body table td {
  border-color: #1e2e42;
  color: #dce4ef;
}

html.dark .highlight-row td {
  background: rgba(25,101,192,.12) !important;
}

/* ============================================================
   DARK MODE
   ============================================================ */
html.dark {
  --bg: #0f1923;
  --card-bg: #172030;
  --border: #253348;
  --text: #dce4ef;
  --text-muted: #7a8da4;
  --primary-light: #1a2d44;
  --shadow: 0 2px 10px rgba(0,0,0,.35);
  color-scheme: dark;
}

html.dark body {
  background: var(--bg);
  color: var(--text);
}

html.dark .card-header {
  background: linear-gradient(135deg, #1a2a3d 0%, #172030 100%);
}

html.dark .card-title {
  color: var(--text);
}

html.dark .topbar {
  background: #0a1018;
}

html.dark .sidebar {
  background: #0a1018;
}

html.dark .sidebar nav ul li a {
  color: #8899ad;
}

html.dark .sidebar nav ul li a:hover,
html.dark .sidebar nav ul li a.active {
  background: rgba(255,255,255,.05);
}

html.dark .sidebar-branch-info {
  background: rgba(255,255,255,.03);
  border-color: rgba(255,255,255,.05);
}

html.dark th {
  background: #1a2a3d;
  color: var(--text);
  border-color: var(--border);
}

html.dark td {
  border-color: #1e2e42;
}

html.dark tr:nth-child(even) td {
  background: rgba(255,255,255,.015);
}

html.dark .alert-success {
  background: #0d2818;
  border-color: #1b5e20;
  color: #a5d6a7;
}

html.dark .alert-danger {
  background: #2d1215;
  border-color: #b71c1c;
  color: #ef9a9a;
}

html.dark .branch-filter-banner {
  background: var(--primary-light);
  border-color: var(--border);
  color: var(--text);
}

html.dark input[type="text"],
html.dark input[type="email"],
html.dark input[type="password"],
html.dark input[type="number"],
html.dark input[type="date"],
html.dark textarea,
html.dark select {
  background: #1a2a3d;
  border-color: #2a3e56;
  color: var(--text);
  color-scheme: dark;
}

html.dark select option {
  background: #1a2a3d;
  color: var(--text);
}

html.dark select,
html.dark select option,
html.dark select optgroup {
  color-scheme: dark !important;
}

html.dark .branch-dropdown {
  background: #172030;
  border-color: #253348;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}

html.dark .branch-dropdown-header {
  background: #1a2a3d;
  border-color: #253348;
}

html.dark .branch-item {
  color: #dce4ef;
  border-color: #253348;
}

html.dark .branch-item:hover {
  background: rgba(255,255,255,.06);
}

html.dark .branch-item.active {
  background: rgba(25,101,192,.15);
}

html.dark .swal2-popup {
  background: #172030;
  color: #dce4ef;
}

html.dark .swal2-title {
  color: #dce4ef;
}

html.dark .swal2-html-container {
  color: #aab8cc;
}

html.dark .swal2-styled {
  border: 1px solid #2a3e56;
}

html.dark .dropdown-menu,
html.dark .dropdown-content {
  background: #172030;
  border-color: #253348;
}

html.dark input:focus,
html.dark textarea:focus,
html.dark select:focus {
  border-color: var(--primary);
  background: #1a2a3d;
}

html.dark input[type="text"],
html.dark input[type="email"],
html.dark input[type="password"],
html.dark input[type="number"],
html.dark input[type="date"],
html.dark textarea {
  color-scheme: dark;
}

html.dark .form-control::placeholder {
  color: #556677;
}

html.dark .badge-gray {
  background: #2a3340;
  color: #8899aa;
}

html.dark .table-responsive table tbody tr:hover td {
  background: rgba(255,255,255,.05);
}

html.dark .app-footer {
  color: var(--text-muted);
  border-color: var(--border);
}

/* Theme toggle button */
.theme-toggle {
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: background .2s;
}
.theme-toggle:hover {
  background: rgba(255,255,255,.22);
}

/* ── DASHBOARD TABLES ─────────────────────────────────── */
.dash-th {
  background: var(--primary-light) !important;
  border: none !important;
  font-size: 12px;
  padding: 10px 14px;
}
.dash-row-even { background: var(--card-bg); }
.dash-row-odd  { background: color-mix(in srgb, var(--card-bg) 92%, var(--bg)); }
html.dark .dash-row-odd { background: rgba(255,255,255,.025); }

.dash-avatar-m { background: color-mix(in srgb, var(--primary) 15%, transparent); color: var(--primary); }
.dash-avatar-f { background: #fce4ec; color: #c62828; }
html.dark .dash-avatar-f { background: rgba(198,40,40,.2); }

.dash-tests-badge {
  background: var(--primary-light);
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text-muted);
  display: inline-block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dash-action-btn {
  background: var(--warning);
  color: #fff;
  text-decoration: none;
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: opacity .2s;
}
.dash-action-btn:hover { opacity: .85; }

.dash-row-even:hover td,
.dash-row-odd:hover td { background: #eef3ff; }
html.dark .dash-row-even:hover td,
html.dark .dash-row-odd:hover td { background: rgba(255,255,255,.06); }

.dash-icon-box {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* ── Notification Bell ───────────────────────────── */
.notif-wrap { position: relative; }
.notif-bell {
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 18px; position: relative; padding: 6px;
  border-radius: 8px; transition: background .15s;
}
.notif-bell:hover { background: rgba(255,255,255,.12); }
.notif-badge {
  position: absolute; top: 0; right: 0;
  background: #ef4444; color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; line-height: 16px; text-align: center;
  border-radius: 8px; padding: 0 4px; display: none;
}
.notif-panel {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 340px; max-height: 420px; overflow: hidden;
  background: #fff; border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
  z-index: 9999; display: flex; flex-direction: column;
}
html.dark .notif-panel { background: #1e293b; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid #e5e7eb; color: #1f2937;
}
html.dark .notif-header { border-color: rgba(255,255,255,.1); }
.notif-list {
  overflow-y: auto; flex: 1; max-height: 370px;
}
.notif-item {
  display: flex; gap: 10px; padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid #f3f4f6; transition: background .12s;
  text-decoration: none; color: #1f2937;
}
.notif-item:hover { background: #f8f9ff; }
html.dark .notif-item:hover { background: rgba(255,255,255,.06); color: #f3f4f6; }
.notif-item.unread { background: #eff6ff; }
html.dark .notif-item.unread { background: rgba(59,130,246,.1); color: #f3f4f6; }
.notif-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.notif-icon.contact { background: #dbeafe; color: #1d4ed8; }
.notif-icon.visit { background: #dcfce7; color: #16a34a; }
.notif-body { min-width: 0; flex: 1; }
.notif-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #1f2937; }
.notif-msg { font-size: 12px; color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-time { font-size: 11px; color: #9ca3af; margin-top: 3px; }
.notif-empty { text-align: center; padding: 30px; color: #9ca3af; font-size: 13px; }
html.dark .notif-title { color: #f3f4f6; }
html.dark .notif-msg { color: #9ca3af; }
html.dark .notif-time { color: #6b7280; }
html.dark .notif-empty { color: #6b7280; }

/* ============================================================
   THEME CUSTOMIZER PANEL
   ============================================================ */
.customizer-panel {
  position: fixed;
  right: -300px;
  top: 120px;
  width: 290px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-right: none;
  border-top: none;
  z-index: 1050;
  transition: right .25s ease;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 160px);
}
.customizer-panel.open {
  right: 0;
}
.customizer-panel > .customizer-btn {
  position: absolute;
  left: -44px;
  top: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 8px 0 0 8px;
  color: var(--text-muted);
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  transition: color .2s, background .2s;
}
.customizer-panel > .customizer-btn:hover {
  color: var(--primary);
  background: var(--primary-light);
}
.customizer-panel > .customizer-btn i {
  transition: transform .4s ease;
}
.customizer-panel.open > .customizer-btn i {
  transform: rotate(180deg);
}
.customizer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.customizer-header h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.customizer-body {
  padding: 14px;
  overflow-y: auto;
  flex: 1;
}
.customizer-body .desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}
.customizer-swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
.customizer-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all .15s;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.customizer-swatch:hover {
  transform: scale(1.1);
}
.customizer-swatch.active {
  border-color: var(--text);
  transform: scale(1.1);
}
.customizer-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}
.customizer-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.customizer-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.customizer-picker-row input[type="color"] {
  width: 36px; height: 28px;
  border: none; cursor: pointer;
  border-radius: 4px; padding: 0;
}
.customizer-picker-row input[type="text"] {
  width: 76px;
  font-family: monospace;
  font-size: 12px;
  padding: 4px 6px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--text);
}
.customizer-save {
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}
.customizer-save:hover { opacity: .9; }
.customizer-reset {
  width: 100%;
  padding: 6px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  transition: all .15s;
}
.customizer-reset:hover {
  border-color: var(--text-muted);
  color: var(--text);
}
@media (max-width: 768px) {
  .customizer-panel { width: 250px; }
  .hnav { display: none !important; }
  body.topbar-layout .main-content { margin-top: var(--topbar-h); }
}

/* ── Customizer: Toggle Switch ─────────────────────────── */
.cust-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.cust-toggle-row:last-child { border-bottom: none; }
.cust-toggle-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}
.cust-switch {
  position: relative;
  width: 38px;
  height: 20px;
  flex-shrink: 0;
}
.cust-switch input { opacity: 0; width: 0; height: 0; }
.cust-switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: background .25s;
}
.cust-switch .slider::before {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .25s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.cust-switch input:checked + .slider {
  background: var(--primary);
}
.cust-switch input:checked + .slider::before {
  transform: translateX(18px);
}

/* ── Customizer: Option Buttons (Radius / Layout) ──────── */
.cust-options {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.cust-option {
  flex: 1;
  padding: 7px 4px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  line-height: 1.3;
}
.cust-option:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.cust-option.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}
.cust-option i {
  display: block;
  font-size: 16px;
  margin-bottom: 3px;
}

/* ── Customizer: Font Selector ──────────────────────────── */
.cust-font-btn {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.cust-font-btn:hover {
  border-color: var(--primary);
}
.cust-font-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

/* ============================================================
   HORIZONTAL NAV (Topbar Layout)
   ============================================================ */
.hnav {
  display: none;
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  height: 42px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  z-index: 1100;
  overflow: visible;
}
.hnav-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 16px;
  gap: 2px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.hnav-inner::-webkit-scrollbar { display: none; }
.hnav-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  border: none;
  background: none;
  cursor: pointer;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.hnav-link:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.hnav-link.active {
  background: var(--primary);
  color: #fff;
}
.hnav-link i { font-size: 12px; }
.hnav-dropdown {
  position: static;
  flex-shrink: 0;
}
.hnav-menu {
  display: none;
  position: fixed;
  min-width: 200px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 6px;
  z-index: 99999;
}
.hnav-dropdown:hover .hnav-menu {
  /* handled by JS click */
}
.hnav-menu a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  transition: background .12s;
}
.hnav-menu a:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.hnav-menu a i {
  width: 16px;
  text-align: center;
  font-size: 12px;
  opacity: .7;
}
html.dark .hnav {
  background: var(--card-bg);
  border-color: var(--border);
}
html.dark .hnav-menu {
  background: var(--card-bg);
  border-color: var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

/* When topbar layout is active, shift main content down */
body.topbar-layout .hnav {
  display: block;
}
body.topbar-layout .main-content {
  margin-top: calc(var(--topbar-h) + 42px);
}
body.topbar-layout .app-footer {
  margin-top: 0;
}

/* ══════════════════════════════════════════════════════════════
   GROUP CHAT FLOATING WIDGET
   ══════════════════════════════════════════════════════════════ */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.28);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: transform .2s, background .2s;
}
.chat-fab:hover {
  transform: scale(1.08);
  background: var(--primary-dark);
}
.chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid var(--card-bg);
}

.chat-window {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 360px;
  height: 480px;
  max-height: calc(100vh - 140px);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  transition: opacity .2s, transform .2s;
  transform-origin: bottom right;
}
.chat-window.open {
  display: flex;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-header-left i {
  font-size: 18px;
}
.chat-header-title {
  font-size: 14px;
  font-weight: 700;
}
.chat-header-online {
  font-size: 11px;
  opacity: .8;
}
.chat-close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  opacity: .8;
  padding: 2px 6px;
  border-radius: 6px;
  transition: opacity .2s, background .2s;
}
.chat-close-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,.15);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}
.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: chatFadeIn .2s ease;
}
@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-msg.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
}
.chat-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.chat-msg-body {
  background: var(--card-bg);
  padding: 8px 12px;
  border-radius: 12px 12px 12px 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  min-width: 0;
}
.chat-msg.own .chat-msg-body {
  background: var(--primary);
  color: #fff;
  border-radius: 12px 12px 4px 12px;
}
.chat-msg-author {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2px;
}
.chat-msg.own .chat-msg-author {
  color: rgba(255,255,255,.85);
}
.chat-msg-text {
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}
.chat-msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  text-align: right;
}
.chat-msg.own .chat-msg-time {
  color: rgba(255,255,255,.65);
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
}
.chat-empty i {
  font-size: 40px;
  opacity: .3;
}

.chat-input-wrap {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color .2s;
  resize: none;
}
.chat-input:focus {
  border-color: var(--primary);
}
.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background .2s, transform .1s;
}
.chat-send-btn:hover {
  background: var(--primary-dark);
}
.chat-send-btn:active {
  transform: scale(.9);
}
.chat-send-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.chat-typing {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 14px 8px;
  font-style: italic;
  flex-shrink: 0;
}

/* Chat dark mode overrides */
html.dark .chat-window {
  border-color: var(--border);
  box-shadow: 0 8px 40px rgba(0,0,0,.45);
}
html.dark .chat-fab-badge {
  border-color: #172030;
}
html.dark .chat-messages {
  background: #0d1520;
}
html.dark .chat-msg-body {
  background: #1e2a3a;
}
html.dark .chat-msg.own .chat-msg-body {
  background: var(--primary);
}
html.dark .chat-input {
  background: #1a2a3d;
  border-color: #2a3e56;
  color: var(--text);
}

/* Mobile: full-width chat window */
@media (max-width: 480px) {
  .chat-window {
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  .chat-fab {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
}

/* ── Patient name autocomplete ─────────────────────────────── */
.name-suggest {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1000;
  margin-top: 4px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 30, 80, .22);
  max-height: 260px;
  overflow-y: auto;
  display: none;
}
.name-suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.name-suggest-item:last-child { border-bottom: none; }
.name-suggest-item:hover { background: var(--primary-light); }
.name-suggest-item.active {
  background: var(--primary-light);
  border-left: 3px solid var(--primary);
}
.name-suggest-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--primary-dark);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}
.name-suggest-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.name-suggest-meta {
  margin-left: auto;
  text-align: right;
  flex-shrink: 0;
}
.name-suggest-phone { font-size: 11px; color: var(--text-muted); }
.name-suggest-id {
  font-size: 10px;
  color: var(--primary);
  font-weight: 700;
  letter-spacing: .4px;
}
.name-suggest-footer {
  position: sticky;
  bottom: 0;
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
}

