/* ============================================================
   Cardiff-Model Dashboard — Main CSS  v2.2
   สำนักงานสาธารณสุขจังหวัดชลบุรี
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

/* ---------- RESET & BASE ---------- */
*, *::before, *::after { box-sizing: border-box; }

:root {
  /* Brand palette */
  --c-primary:       #0f3460;
  --c-primary-dk:    #0a2540;
  --c-primary-bg:    rgba(15,52,96,.10);
  --c-sidebar:       #1a1f2e;
  --c-sidebar-hover: rgba(255,255,255,.06);
  --c-sidebar-active:rgba(15,52,96,.35);

  /* Status */
  --c-green:   #10b981;
  --c-amber:   #f59e0b;
  --c-red:     #ef4444;
  --c-blue:    #3b82f6;
  --c-purple:  #8b5cf6;
  --c-teal:    #06b6d4;

  /* Surfaces */
  --c-bg:      #f0f2f5;
  --c-card:    #ffffff;
  --c-border:  #e5e7eb;
  --c-stripe:  #f8fafc;

  /* Text */
  --c-text:    #1f2937;
  --c-light:   #6b7280;
  --c-muted:   #9ca3af;

  /* Layout */
  --sidebar-w: 260px;
  --topbar-h:  56px;
  --radius:    8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow:    0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.10);
}

html, body {
  margin: 0; padding: 0;
  font-family: 'Sarabun', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 16px;
  line-height: 1.65;
}

/* ============================================================
   TOP NAV BAR
   ============================================================ */
.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--c-sidebar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
  gap: 16px;
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  text-decoration: none;
  font-weight: 600;
  flex-shrink: 0;
}
.topnav-brand:hover { color: white; }

.brand-icon { font-size: 22px; line-height: 1; }

.brand-name {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  color: white;
}
.brand-sub {
  font-size: 11px;
  color: #8fa3c0;
  margin: 0;
}

.topnav-center {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.topnav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Nav pills */
.nav-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: var(--radius);
  color: #b0c0d4;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all .2s;
  white-space: nowrap;
}
.nav-pill:hover  { background: rgba(255,255,255,.10); color: white; }
.nav-pill.active { background: var(--c-primary); color: white; }

/* User pill */
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(255,255,255,.09);
  border-radius: 20px;
  color: white;
  font-size: 13px;
}

/* Icon-only button */
.btn-icon {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.18);
  background: transparent;
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: background .2s;
}
.btn-icon:hover { background: rgba(255,255,255,.12); }

/* Small link inside topnav */
.btn-sm-link {
  color: #8fa3c0;
  font-size: 12px;
  text-decoration: none;
  margin-left: 2px;
}
.btn-sm-link:hover { color: white; text-decoration: underline; }

/* Outline nav button */
.btn-outline-nav {
  padding: 7px 14px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: var(--radius);
  color: white;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  transition: all .2s;
  white-space: nowrap;
}
.btn-outline-nav:hover { background: rgba(255,255,255,.10); color: white; text-decoration: none; }

/* Solid primary nav button */
.btn-primary-nav {
  padding: 8px 16px;
  background: var(--c-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all .2s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.btn-primary-nav:hover {
  background: var(--c-primary-dk);
  color: white;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(15,52,96,.35);
  transform: translateY(-1px);
}

/* ============================================================
   ADMIN SIDEBAR
   ============================================================ */
.sidebar-admin {
  position: fixed;
  left: 0; top: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--c-sidebar);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 2px 0 12px rgba(0,0,0,.15);
}

.sidebar-brand {
  padding: 20px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-brand-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--c-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 10px;
  box-shadow: 0 4px 12px rgba(15,52,96,.4);
}
.sidebar-brand-text {
  color: white;
  font-weight: 700;
  font-size: 15px;
  margin: 0;
}
.sidebar-brand-sub {
  color: #7a8fa6;
  font-size: 12px;
  margin: 3px 0 0;
}

.sidebar-section-label {
  padding: 16px 20px 6px;
  color: #4a5568;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.sidebar-nav { flex: 1; padding: 8px 0; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: #8fa3b8;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all .2s;
  margin: 1px 0;
}
.sidebar-nav a:hover {
  background: var(--c-sidebar-hover);
  color: #d0dce8;
  border-left-color: rgba(255,255,255,.15);
}
.sidebar-nav a.active {
  background: var(--c-sidebar-active);
  color: white;
  border-left-color: var(--c-primary);
}
.sidebar-nav a .nav-icon { font-size: 16px; flex-shrink: 0; }

.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,.07);
  margin: 8px 16px;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--c-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.sidebar-username { color: #d0dce8; font-size: 13px; font-weight: 600; }
.sidebar-role     { color: #6b7f93; font-size: 11px; }

/* ============================================================
   MAIN ADMIN WRAPPER
   ============================================================ */
.main-admin {
  margin-left: var(--sidebar-w);
  background: var(--c-bg);
  min-height: 100vh;
}

.admin-topbar {
  background: white;
  padding: 14px 28px;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.admin-title {
  color: var(--c-primary);
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}
.admin-breadcrumb {
  color: var(--c-muted);
  font-size: 12px;
  margin: 2px 0 0;
}
.admin-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--c-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
}
.admin-content { padding: 28px; }

/* ============================================================
   PUBLIC LAYOUT
   ============================================================ */
.layout-public {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.pub-content {
  flex: 1;
  padding-top: calc(var(--topbar-h) + 20px);
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}

.pub-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}
.pub-title {
  color: var(--c-primary);
  font-size: 26px;
  font-weight: 700;
  margin: 0;
}
.pub-subtitle {
  color: var(--c-light);
  font-size: 13px;
  margin: 6px 0 0;
}
.pub-header-actions { display: flex; gap: 10px; align-items: center; }

/* ============================================================
   CRITERIA BAR
   ============================================================ */
.criteria-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 14px 18px;
  background: white;
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--c-primary);
  align-items: center;
}
.criteria-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--c-text);
}
.criteria-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.criteria-date { font-size: 13px; color: var(--c-light); }

.dot-blue   { background: var(--c-primary); }
.dot-green  { background: var(--c-green); }
.dot-purple { background: var(--c-purple); }
.dot-red    { background: var(--c-red); }
.dot-amber  { background: var(--c-amber); }

/* ============================================================
   KPI CARDS
   ============================================================ */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 18px 20px;
  border-left: 4px solid var(--c-primary);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, transform .2s;
  position: relative;
  overflow: hidden;
}
.kpi-card::after {
  content: '';
  position: absolute;
  top: -20px; right: -20px;
  width: 80px; height: 80px;
  border-radius: 50%;
  opacity: .04;
  background: currentColor;
}
.kpi-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.kpi-blue   { border-left-color: var(--c-primary); }
.kpi-green  { border-left-color: var(--c-green); }
.kpi-teal   { border-left-color: var(--c-teal); }
.kpi-red    { border-left-color: var(--c-red); }
.kpi-amber  { border-left-color: var(--c-amber); }
.kpi-purple { border-left-color: var(--c-purple); }

.kpi-icon-wrap {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--c-primary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 12px;
}
.kpi-blue   .kpi-icon-wrap { background: rgba(15,52,96,.10); color: var(--c-primary); }
.kpi-green  .kpi-icon-wrap { background: rgba(16,185,129,.10); color: var(--c-green); }
.kpi-teal   .kpi-icon-wrap { background: rgba(6,182,212,.10); color: var(--c-teal); }
.kpi-red    .kpi-icon-wrap { background: rgba(239,68,68,.10); color: var(--c-red); }
.kpi-amber  .kpi-icon-wrap { background: rgba(245,158,11,.10); color: var(--c-amber); }
.kpi-purple .kpi-icon-wrap { background: rgba(139,92,246,.10); color: var(--c-purple); }

.kpi-label {
  color: var(--c-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.kpi-value {
  color: var(--c-primary);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
}
.kpi-sub { color: var(--c-light); font-size: 12px; }

/* ============================================================
   SECTION CARDS
   ============================================================ */
.section-card {
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.section-title {
  color: var(--c-primary);
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}
.section-subtitle {
  color: var(--c-light);
  font-size: 12px;
  margin: 4px 0 0;
}
.section-action {
  color: var(--c-primary);
  font-size: 13px;
  text-decoration: none;
}
.section-action:hover { text-decoration: underline; }

/* ============================================================
   HOSPITAL STATUS CARDS
   ============================================================ */
.hosp-status-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.hosp-card {
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 18px;
  border-left: 4px solid var(--c-primary);
  box-shadow: var(--shadow-sm);
  transition: all .2s;
}
.hosp-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.hosp-card.pass   { border-left-color: var(--c-green); }
.hosp-card.fail   { border-left-color: var(--c-red); }
.hosp-card.nosend { border-left-color: var(--c-muted); }

.hosp-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 8px;
}
.hosp-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}
.hosp-name {
  color: var(--c-primary);
  font-weight: 700;
  font-size: 14px;
  margin: 0;
  flex: 1;
}
.hosp-district {
  color: var(--c-muted);
  font-size: 11px;
  margin: 4px 0 0;
}

.hosp-stats {
  display: flex;
  justify-content: space-around;
  padding: 10px 0;
  border-top: 1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
  margin: 10px 0;
}
.hosp-stat-item { text-align: center; }
.hosp-stat-val {
  color: var(--c-primary);
  font-weight: 700;
  font-size: 16px;
  display: block;
}
.hosp-stat-lbl {
  color: var(--c-muted);
  font-size: 10px;
  display: block;
  margin-top: 2px;
}

.hosp-rate-bar {
  height: 4px;
  background: var(--c-border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 10px;
}
.hosp-rate-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-green) 0%, #34d399 100%);
  transition: width .4s ease;
}

.hosp-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--c-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 13px;
}

/* ============================================================
   CHARTS
   ============================================================ */
.chart-pane { display: none; }
.chart-pane.active { display: block; }
.chart-wrap { position: relative; height: 280px; }

.view-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--c-border);
}
.view-tab {
  padding: 10px 16px;
  color: var(--c-muted);
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .2s;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
}
.view-tab:hover  { color: var(--c-light); }
.view-tab.active {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
}

/* ============================================================
   CALENDAR
   ============================================================ */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-header {
  text-align: center;
  font-weight: 700;
  color: var(--c-light);
  font-size: 11px;
  padding: 6px 0;
}
.cal-cell {
  aspect-ratio: 1;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  padding: 5px;
  position: relative;
  background: white;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.cal-cell:hover { box-shadow: 0 2px 8px rgba(0,0,0,.10); }
.cal-full-send  { background: #f0fdf4; border-color: #86efac; }
.cal-part-send  { background: #fffbea; border-color: #fcd34d; }
.cal-no-send    { background: #fef2f2; border-color: #fca5a5; }
.cal-weekend    { background: #f8fafc; border-color: #e2e8f0; }
.cal-empty      { background: transparent; border: none; cursor: default; }
.cal-day        { font-weight: 700; font-size: 13px; color: var(--c-primary); }
.cal-mini-bar   { height: 2px; background: var(--c-border); border-radius: 1px; overflow: hidden; }
.cal-mini-bar-fill { height: 100%; background: var(--c-primary); }
.cal-sent       { font-size: 10px; color: var(--c-muted); text-align: center; }
.cal-dot        { width: 6px; height: 6px; border-radius: 50%; display: inline-block; margin: 0 2px; }
.cal-green  { background: var(--c-green); }
.cal-yellow { background: var(--c-amber); }
.cal-red    { background: var(--c-red); }
.cal-gray   { background: var(--c-muted); }
.calendar-legend { display: flex; gap: 16px; margin-top: 14px; flex-wrap: wrap; font-size: 12px; }

/* ============================================================
   FILTER / FORMS
   ============================================================ */
.date-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #f0f0f0;
  border-radius: 20px;
  font-size: 12px;
  color: var(--c-text);
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
}
.date-chip:hover  { background: #e0e0e0; }
.date-chip.active { background: var(--c-primary); color: white; }
.date-chip input[type=date] { border: none; background: none; font-size: 12px; cursor: pointer; padding: 0; }

.filter-form {
  padding: 18px;
  background: var(--c-stripe);
  border-radius: var(--radius);
  margin-bottom: 18px;
  border: 1px solid var(--c-border);
}

.form-group  { margin-bottom: 16px; }
.form-label {
  display: block;
  color: var(--c-text);
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
}
.form-control, .form-select {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .2s, box-shadow .2s;
  color: var(--c-text);
  background: white;
}
.form-control:focus, .form-select:focus {
  border-color: var(--c-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(15,52,96,.12);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: all .2s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--c-primary);
  color: white;
}
.btn-primary:hover {
  background: var(--c-primary-dk);
  color: white;
  box-shadow: 0 4px 12px rgba(15,52,96,.3);
  transform: translateY(-1px);
}

.btn-success { background: var(--c-green); color: white; }
.btn-success:hover { background: #059669; color: white; transform: translateY(-1px); }

.btn-danger  { background: var(--c-red); color: white; }
.btn-danger:hover  { background: #dc2626; color: white; }

.btn-warning { background: var(--c-amber); color: white; }
.btn-warning:hover { background: #d97706; color: white; }

.btn-secondary { background: #6b7280; color: white; }
.btn-secondary:hover { background: #4b5563; color: white; }

.btn-outline-primary {
  background: white;
  color: var(--c-primary);
  border: 1px solid var(--c-primary);
}
.btn-outline-primary:hover { background: var(--c-primary-bg); color: var(--c-primary); }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* Action buttons in tables */
.btn-sm-action {
  padding: 4px 9px;
  border: 1px solid;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  transition: all .2s;
  font-family: inherit;
}
.btn-approve { color: #059669; border-color: #059669; }
.btn-approve:hover { background: #ecfdf5; }
.btn-suspend { color: #d97706; border-color: #d97706; }
.btn-suspend:hover { background: #fffbeb; }
.btn-delete  { color: #dc2626; border-color: #dc2626; }
.btn-delete:hover  { background: #fef2f2; }

/* Filter-row buttons */
.btn-filter {
  background: var(--c-primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.btn-filter:hover { background: var(--c-primary-dk); color: white; }
.btn-filter.reset { background: #6b7280; }
.btn-filter.reset:hover { background: #4b5563; }

.btn-export {
  background: var(--c-green);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.btn-export:hover { background: #059669; color: white; text-decoration: none; }

/* ============================================================
   TABLES
   ============================================================ */
.table-custom {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table-custom thead {
  background: var(--c-stripe);
  border-bottom: 2px solid var(--c-border);
}
.table-custom th {
  padding: 11px 14px;
  color: var(--c-light);
  font-weight: 700;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.table-custom td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}
.table-custom tbody tr:hover { background: var(--c-stripe); }
.table-custom tbody tr:last-child td { border-bottom: none; }

/* Alias classes used in PHP files */
.user-table,
.log-table,
.clinic-table,
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.user-table thead,
.log-table thead,
.clinic-table thead,
.history-table thead {
  background: var(--c-stripe);
  border-bottom: 2px solid var(--c-border);
}
.user-table th,
.log-table th,
.clinic-table th,
.history-table th {
  padding: 11px 14px;
  color: var(--c-light);
  font-weight: 700;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.user-table td,
.log-table td,
.clinic-table td,
.history-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}
.user-table tbody tr:hover,
.log-table tbody tr:hover,
.clinic-table tbody tr:hover,
.history-table tbody tr:hover {
  background: var(--c-stripe);
}

/* ============================================================
   BADGES
   ============================================================ */
.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* Role badges */
.role-badge { display: inline-block; padding: 3px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.role-hospital    { background: #dbeafe; color: #1d4ed8; }
.role-superadmin  { background: #fee2e2; color: #b91c1c; }
.role-province    { background: #fef3c7; color: #b45309; }
.role-viewer      { background: #e5e7eb; color: #374151; }

/* Status badges */
.status-badge { display: inline-block; padding: 3px 9px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.status-active    { background: #d1fae5; color: #065f46; }
.status-pending   { background: #fef3c7; color: #92400e; }
.status-suspended { background: #f3f4f6; color: #6b7280; }

/* Log action badges */
.log-badge { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.log-badge-login   { background: #dbeafe; color: #1e40af; }
.log-badge-logout  { background: #f3f4f6; color: #6b7280; }
.log-badge-upload  { background: #d1fae5; color: #065f46; }
.log-badge-approve { background: #e0e7ff; color: #3730a3; }
.log-badge-delete  { background: #fee2e2; color: #991b1b; }
.log-badge-suspend { background: #fef3c7; color: #92400e; }
.log-badge-register{ background: #fce7f3; color: #9d174d; }

/* Pass/fail */
.status-pass { background: #d1fae5; color: #065f46; display: inline-block; padding: 4px 10px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.status-fail { background: #fee2e2; color: #991b1b; display: inline-block; padding: 4px 10px; border-radius: 10px; font-size: 11px; font-weight: 700; }

/* ============================================================
   FILTER TABS
   ============================================================ */
.filter-tabs {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
  flex-wrap: wrap;
}
.filter-tab {
  padding: 7px 16px;
  border-radius: 20px;
  background: #f0f0f0;
  color: var(--c-light);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.filter-tab:hover  { background: #e0e0e0; color: var(--c-text); }
.filter-tab.active { background: var(--c-primary); color: white; }

/* ============================================================
   UPLOAD ZONE
   ============================================================ */
.upload-zone {
  border: 2px dashed #93c5fd;
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  background: linear-gradient(135deg, rgba(15,52,96,.04) 0%, rgba(59,130,246,.03) 100%);
  cursor: pointer;
  transition: all .2s;
  margin-bottom: 18px;
}
.upload-zone:hover {
  border-color: var(--c-primary);
  background: rgba(15,52,96,.06);
}
.upload-zone.dragover {
  border-color: var(--c-green);
  background: rgba(16,185,129,.06);
}
.upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-text { color: var(--c-text); font-size: 15px; font-weight: 600; margin: 0 0 6px; }
.upload-subtext { color: var(--c-muted); font-size: 13px; margin: 0; }
.file-input { display: none; }

/* Format guide */
.format-guide {
  background: var(--c-stripe);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  font-size: 13px;
}
.format-guide-title { color: var(--c-primary); font-weight: 700; margin-bottom: 10px; }
.format-guide-item  { padding: 5px 0; color: var(--c-light); }
.format-code {
  background: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  color: var(--c-primary);
  border: 1px solid var(--c-border);
}

/* ============================================================
   LOGIN / REGISTER PAGES
   ============================================================ */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0a2540 0%, var(--c-sidebar) 50%, #0f3460 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
}

.auth-container {
  width: 100%;
  max-width: 430px;
}

.auth-card {
  background: white;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.30);
  padding: 40px;
  border-top: 5px solid var(--c-primary);
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-dk) 100%);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  font-size: 28px;
  box-shadow: 0 8px 20px rgba(15,52,96,.35);
}
.auth-title {
  color: var(--c-primary);
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 6px;
}
.auth-subtitle {
  color: var(--c-light);
  font-size: 13px;
  margin: 0;
}

.auth-form .form-group  { margin-bottom: 18px; }
.auth-form .form-label  { color: var(--c-text); font-weight: 600; font-size: 13px; margin-bottom: 7px; display: block; }
.auth-form .form-control {
  border: 1.5px solid #d1d5db;
  border-radius: 7px;
  padding: 10px 13px;
  font-size: 14px;
  width: 100%;
  transition: border-color .2s, box-shadow .2s;
}
.auth-form .form-control:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(15,52,96,.12);
  outline: none;
}

.btn-auth {
  width: 100%;
  padding: 11px 16px;
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-dk) 100%);
  color: white;
  border: none;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
  margin-top: 6px;
}
.btn-auth:hover {
  box-shadow: 0 6px 20px rgba(15,52,96,.35);
  transform: translateY(-1px);
}

.auth-divider {
  text-align: center;
  margin: 20px 0;
  color: var(--c-muted);
  font-size: 12px;
  position: relative;
}
.auth-divider::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  width: 100%; height: 1px;
  background: var(--c-border);
}
.auth-divider span { position: relative; background: white; padding: 0 10px; }

.auth-footer {
  text-align: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--c-border);
  color: var(--c-light);
  font-size: 13px;
}
.auth-footer a { color: var(--c-primary); font-weight: 600; text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

/* Demo box on login page */
.demo-box {
  background: var(--c-stripe);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 18px;
  font-size: 13px;
}
.demo-title {
  color: var(--c-primary);
  font-weight: 700;
  margin-bottom: 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.demo-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--c-border);
}
.demo-item:last-child { border-bottom: none; }
.demo-label { color: var(--c-light); }
.demo-value { color: var(--c-primary); font-weight: 600; font-family: 'Courier New', monospace; font-size: 12px; }

/* Hospital lookup widget */
.hospital-lookup {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--c-stripe);
  border-radius: 6px;
  border: 1px solid var(--c-border);
  font-size: 13px;
}
.hospital-lookup.found    { border-color: #86efac; background: #f0fdf4; }
.hospital-lookup.notfound { border-color: #fca5a5; background: #fef2f2; }
.hospital-name   { color: var(--c-primary); font-weight: 700; }
.hospital-detail { font-size: 12px; color: var(--c-light); margin-top: 3px; }

/* Pending info box */
.pending-info {
  background: #fffbeb;
  border-left: 4px solid var(--c-amber);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  color: #92400e;
  margin-bottom: 14px;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination-custom {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 18px;
  flex-wrap: wrap;
  align-items: center;
}
.pagination-item {
  padding: 7px 11px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  color: var(--c-primary);
  text-decoration: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all .2s;
}
.pagination-item:hover   { background: var(--c-stripe); }
.pagination-item.active  { background: var(--c-primary); color: white; border-color: var(--c-primary); }
.pagination-item.disabled { color: var(--c-muted); cursor: default; }
.pagination-item.disabled:hover { background: white; }

/* ============================================================
   ALERTS / NOTICES
   ============================================================ */
.alert-custom {
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-success-custom { background: #d1fae5; border-left: 4px solid var(--c-green); color: #065f46; }
.alert-error-custom   { background: #fee2e2; border-left: 4px solid var(--c-red);   color: #991b1b; }
.alert-warning-custom { background: #fffbeb; border-left: 4px solid var(--c-amber); color: #92400e; }
.alert-info-custom    { background: #eff6ff; border-left: 4px solid var(--c-blue);  color: #1e40af; }

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-bar-custom {
  height: 6px;
  background: var(--c-border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-green) 0%, #34d399 100%);
  transition: width .4s ease;
}

/* ============================================================
   FOOTER
   ============================================================ */
.pub-footer {
  text-align: center;
  padding: 20px;
  color: var(--c-muted);
  font-size: 12px;
  border-top: 1px solid var(--c-border);
  margin-top: 30px;
  background: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* ============================================================
   TEXT & UTILITY
   ============================================================ */
.text-primary  { color: var(--c-primary) !important; }
.text-green    { color: var(--c-green) !important; }
.text-red      { color: var(--c-red) !important; }
.text-amber    { color: var(--c-amber) !important; }
.text-purple   { color: var(--c-purple) !important; }
.text-muted    { color: var(--c-muted) !important; }
.text-success  { color: var(--c-green) !important; }
.text-danger   { color: var(--c-red) !important; }
.text-warning  { color: var(--c-amber) !important; }

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

.empty-state { text-align: center; padding: 50px 20px; color: var(--c-muted); }
.empty-icon  { font-size: 48px; margin-bottom: 12px; }

.d-flex    { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 6px; }
.gap-2 { gap: 12px; }
.gap-3 { gap: 20px; }

.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
.mb-1 { margin-bottom: 6px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 20px; }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow    { box-shadow: var(--shadow); }
.rounded   { border-radius: var(--radius); }

/* ============================================================
   DARK MODE
   ============================================================ */
body.dark {
  --c-bg:     #111827;
  --c-card:   #1f2937;
  --c-border: #374151;
  --c-stripe: #252f3f;
  --c-text:   #f8fafc;      /* สว่างขึ้น: #f3f4f6 → #f8fafc */
  --c-light:  #cbd5e1;      /* สว่างขึ้น: #9ca3af → #cbd5e1 */
  --c-muted:  #94a3b8;      /* สว่างขึ้น: #6b7280 → #94a3b8 */
  font-size:  15px;         /* ขยาย base font */
}
body.dark .pub-footer,
body.dark .admin-topbar {
  background: #1f2937;
  border-color: #374151;
}
body.dark .pub-title    { color: #93c5fd; }
body.dark .pub-subtitle { color: #94a3b8; }
body.dark .form-label   { color: #cbd5e1; }
body.dark .form-control:disabled,
body.dark .form-control[readonly] { background: #1a2535 !important; color: #94a3b8 !important; border-color: #2d3a4f !important; }
body.dark input[type="date"]      { color-scheme: dark; }
body.dark .section-card { background: #1f2937; }
body.dark .kpi-card     { background: #1f2937; }
body.dark .hosp-card    { background: #1f2937; }
body.dark .topnav       { background: #0d1117; }
body.dark .form-control,
body.dark .form-select  { background: #252f3f; border-color: #374151; color: #f3f4f6; }
body.dark .criteria-bar { background: #1f2937; }
body.dark .section-title { color: #60a5fa; }
body.dark .kpi-value     { color: #60a5fa; }
body.dark .table-custom th,
body.dark .user-table th,
body.dark .log-table th  { background: #252f3f; }
body.dark .table-custom tbody tr:hover,
body.dark .user-table tbody tr:hover,
body.dark .log-table tbody tr:hover { background: #252f3f; }

/* ============================================================
   STAT CARDS (admin overview alias)
   ============================================================ */
.stat-card {
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 20px;
  border-left: 4px solid var(--c-primary);
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.stat-card.pending  { border-left-color: var(--c-amber); }
.stat-card.users    { border-left-color: var(--c-teal); }
.stat-card.hospitals{ border-left-color: var(--c-green); }
.stat-label  { color: var(--c-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; margin-bottom: 8px; }
.stat-value  { color: var(--c-primary); font-size: 32px; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.stat-card.pending   .stat-value { color: var(--c-amber); }
.stat-card.users     .stat-value { color: var(--c-teal); }
.stat-card.hospitals .stat-value { color: var(--c-green); }
.stat-sub    { color: var(--c-muted); font-size: 12px; }
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

/* Log action alias */
.log-action { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.log-action-login  { background: #dbeafe; color: #1e40af; }
.log-action-upload { background: #d1fae5; color: #065f46; }
.log-action-approve{ background: #e0e7ff; color: #3730a3; }

/* Log time */
.log-time { color: var(--c-muted); font-size: 11px; }

/* Recent logs in admin/index.php */
.recent-logs { max-height: 400px; overflow-y: auto; }
.log-item { padding: 11px 0; border-bottom: 1px solid var(--c-border); font-size: 13px; }
.log-item:last-child { border-bottom: none; }

/* Alert pending */
.alert-pending {
  background: #fffbeb;
  border-left: 4px solid var(--c-amber);
  padding: 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.pending-user {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--c-border);
}
.pending-user:last-child { border-bottom: none; }
.pending-info  { flex: 1; }
.pending-name  { color: var(--c-text); font-weight: 600; margin: 0; }
.pending-hosp  { color: var(--c-muted); font-size: 12px; margin: 2px 0 0; }
.pending-actions { display: flex; gap: 6px; }
.btn-approve-lg {
  background: var(--c-green);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s;
  font-family: inherit;
}
.btn-approve-lg:hover { background: #059669; }

/* Section title in admin */
.admin-title-h { color: var(--c-primary); font-size: 20px; font-weight: 700; margin: 0; }
.admin-user-name { color: var(--c-light); font-size: 13px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .topnav { padding: 0 14px; gap: 10px; }
  .pub-content { padding-left: 14px; padding-right: 14px; }
  .topnav-center { display: none !important; }

  .sidebar-admin { width: 0; overflow: hidden; transition: width .3s; }
  .sidebar-admin.open { width: var(--sidebar-w); }
  .main-admin { margin-left: 0; }

  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .hosp-status-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-row { grid-template-columns: 1fr; }

  .admin-content { padding: 16px; }
  .section-card { padding: 16px; }

  .pub-title { font-size: 20px; }
  .section-title { font-size: 14px; }
  .kpi-value { font-size: 24px; }

  .table-custom, .user-table, .log-table { font-size: 11px; }
  .table-custom th, .table-custom td,
  .user-table th, .user-table td,
  .log-table th, .log-table td { padding: 8px 10px; }

  .view-tabs { flex-wrap: nowrap; overflow-x: auto; }
  .cal-grid { gap: 3px; }
  .cal-cell { padding: 3px; font-size: 10px; }

  .auth-card { padding: 28px 22px; }
}

@media (max-width: 480px) {
  .kpi-row { grid-template-columns: 1fr; }
}

/* ============================================================
   CARDIFF MODEL v3 — Enhanced Components
   ============================================================ */

/* ──── CARDIFF HEADER STRIP ──── */
.cardiff-header {
  background: linear-gradient(135deg, #0d1b2a 0%, #0f3460 60%, #16213e 100%);
  color: #fff;
  padding: 0;
  position: relative;
  overflow: hidden;
}
.cardiff-header::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,.03);
  pointer-events: none;
}
.cardiff-header-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 18px 28px;
  flex-wrap: wrap;
}
.cardiff-logo {
  width: 52px; height: 52px;
  border-radius: 12px;
  background: rgba(255,255,255,.12);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}
.cardiff-title-wrap { flex: 1; }
.cardiff-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}
.cardiff-subtitle {
  font-size: 12px;
  color: rgba(255,255,255,.65);
  margin-top: 2px;
}
.cardiff-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.cf-select {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: 'Sarabun', sans-serif;
  cursor: pointer;
}
.cf-select option { color: #000; background: #fff; }
.cf-date {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: 'Sarabun', sans-serif;
  cursor: pointer;
  color-scheme: dark;
}
.cf-btn {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: 'Sarabun', sans-serif;
  transition: background .15s;
  display: flex; align-items: center; gap: 6px;
}
.cf-btn:hover { background: rgba(255,255,255,.25); }
.cf-btn-active { background: rgba(59,130,246,.5) !important; border-color: #3b82f6 !important; }

/* ──── CRITERIA BADGE BAR ──── */
.cf-criteria-bar {
  background: rgba(255,255,255,.06);
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 10px 28px;
  display: flex;
  gap: 24px;
  align-items: center;
  flex-wrap: wrap;
}
.cf-crit {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: rgba(255,255,255,.8);
}
.cf-crit-dot {
  width: 10px; height: 10px; border-radius: 50%;
}
.cf-crit-val { font-weight: 700; color: #fff; }
.cf-date-badge {
  margin-left: auto;
  background: rgba(59,130,246,.3);
  border: 1px solid rgba(59,130,246,.5);
  border-radius: 20px;
  padding: 3px 14px;
  font-size: 12px;
  color: #93c5fd;
  font-weight: 600;
}

/* ──── KPI CARD STRIP (v5 — reference-matched) ──── */

/* ── Section header bar (KPI MOPH / KPI SSJ label) ── */
.cf-kpi-section-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px clamp(16px, 2.5vw, 32px) 0;
  background: transparent;
  flex-wrap: wrap;
}
.cf-kpi-section-bar .kpi-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: clamp(11px, 1vw, 13px);
  font-weight: 800;
  letter-spacing: .5px;
  padding: 6px 18px;
  border-radius: 20px;
  color: #fff;
  white-space: nowrap;
}
.cf-kpi-section-bar .kpi-chip-moph { background: #0f3460; }
.cf-kpi-section-bar .kpi-chip-ssj  { background: linear-gradient(135deg,#10b981,#f59e0b); }
.cf-kpi-section-bar .kpi-criteria  {
  font-size: clamp(11px, 1vw, 13px);
  color: #94a3b8;
  line-height: 1.5;
}

/* Strip wrapper — auto-fit so cards are wider */
.cf-kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(160px, 18vw, 220px), 1fr));
  gap: clamp(10px, 1.4vw, 18px);
  padding: clamp(12px, 1.5vw, 16px) clamp(16px, 2.5vw, 32px) clamp(16px, 2vw, 24px);
  border-bottom: 1px solid var(--c-border);
  background: #f0f4f8;
}

/* ── Base card ── */
.cf-kpi-item {
  padding: clamp(16px, 1.8vw, 22px) clamp(16px, 1.8vw, 22px) clamp(12px, 1.4vw, 18px);
  background: #ffffff;
  border: 1.5px solid #e5eaf0;
  border-radius: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: transform .2s, box-shadow .2s;
  min-height: clamp(140px, 14vw, 180px);
  cursor: default;
}
.cf-kpi-item[onclick] { cursor: pointer; }
.cf-kpi-item[onclick]:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 30px rgba(0,0,0,.11);
}

/* ── Top row: label left + icon badge right ── */
.cf-kpi-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.cf-kpi-labels { flex: 1; min-width: 0; }
.cf-kpi-lbl {
  font-size: clamp(13px, 1.15vw, 15.5px);
  font-weight: 700;
  color: #111827;
  line-height: 1.35;
  word-break: keep-all;
  overflow-wrap: break-word;
}
.cf-kpi-sub {
  font-size: clamp(11.5px, 1vw, 13px);
  color: #94a3b8;
  margin-top: 2px;
  line-height: 1.4;
}

/* ── Icon badge (solid color, top-right) ── */
.cf-kpi-icon {
  width: clamp(42px, 4vw, 52px);
  height: clamp(42px, 4vw, 52px);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(18px, 1.8vw, 24px);
  flex-shrink: 0;
  color: #fff;
}
.cf-kpi-blue   .cf-kpi-icon { background: #4f83f1; }
.cf-kpi-green  .cf-kpi-icon { background: #22c55e; }
.cf-kpi-red    .cf-kpi-icon { background: #ef4444; }
.cf-kpi-amber  .cf-kpi-icon { background: #f97316; }
.cf-kpi-purple .cf-kpi-icon { background: #8b5cf6; }
.cf-kpi-teal   .cf-kpi-icon { background: #06b6d4; }
.cf-kpi-gray   .cf-kpi-icon { background: #94a3b8; }
.cf-kpi-gray { border-color: #cbd5e1; }
.cf-kpi-gray .cf-kpi-val { color: #94a3b8; }

/* ── Big number — ALL dark navy ── */
.cf-kpi-val {
  font-size: clamp(34px, 3.5vw, 52px);
  font-weight: 800;
  line-height: 1;
  color: #111827;
  letter-spacing: -1px;
  margin-top: auto;
  padding-top: 10px;
}

/* ── Footer ── */
.cf-kpi-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  gap: 6px;
  flex-wrap: wrap;
}
.cf-kpi-detail {
  font-size: clamp(11.5px, 1vw, 13px);
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ── Trend badge ── */
.cf-kpi-trend {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: clamp(11px, 0.95vw, 12.5px); font-weight: 700;
  padding: 2px 9px; border-radius: 20px;
}
.trend-up   { background: #dcfce7; color: #16a34a; }
.trend-down { background: #fee2e2; color: #dc2626; }
.trend-flat { background: #f0f4f8; color: #64748b; }

/* ═══════════════════════════════════════════════
   PROGRESS-BAR CARD  (.cf-kpi-bar-card)
   label + % on same line, bar, count
   ═══════════════════════════════════════════════ */
.cf-kpi-bar-card { min-height: clamp(130px, 13vw, 175px); justify-content: center; }

.cf-kpi-bar-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.cf-kpi-bar-card .cf-kpi-lbl { font-size: clamp(14px, 1.3vw, 17px); font-weight: 700; color: #111827; }

/* Percentage number in bar-card */
.cf-kpi-pct-big {
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.5px;
  flex-shrink: 0;
}
.cf-kpi-blue   .cf-kpi-pct-big { color: #4f83f1; }
.cf-kpi-green  .cf-kpi-pct-big { color: #22c55e; }
.cf-kpi-red    .cf-kpi-pct-big { color: #ef4444; }
.cf-kpi-amber  .cf-kpi-pct-big { color: #f97316; }
.cf-kpi-purple .cf-kpi-pct-big { color: #8b5cf6; }
.cf-kpi-teal   .cf-kpi-pct-big { color: #06b6d4; }

.cf-kpi-bar-sub {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
  line-height: 1.3;
}

/* Progress track */
.cf-kpi-bar-wrap {
  height: 10px;
  background: #e9ecef;
  border-radius: 20px;
  overflow: hidden;
  margin: 10px 0 6px;
}
.cf-kpi-bar {
  height: 100%;
  border-radius: 20px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.cf-kpi-blue   .cf-kpi-bar { background: #4f83f1; }
.cf-kpi-green  .cf-kpi-bar { background: #22c55e; }
.cf-kpi-red    .cf-kpi-bar { background: #ef4444; }
.cf-kpi-amber  .cf-kpi-bar { background: #f97316; }
.cf-kpi-purple .cf-kpi-bar { background: #8b5cf6; }
.cf-kpi-teal   .cf-kpi-bar { background: #06b6d4; }

.cf-kpi-bar-count { font-size: 12px; color: #94a3b8; }
.cf-kpi-bar-info-row {
  display: flex; align-items: center;
  justify-content: space-between; gap: 6px;
}

/* ── Label-only chip card (legacy, kept for compat) ── */
.cf-kpi-label-card {
  display: flex !important; flex-direction: column !important;
  align-items: flex-start !important; justify-content: center !important;
  gap: 6px !important; border: none !important; box-shadow: none !important;
  background: transparent !important; min-height: auto !important;
  padding: 0 6px !important; cursor: default !important;
}
.cf-kpi-label-card:hover { transform: none !important; box-shadow: none !important; }

/* ═══════════════════════════════════
   DARK MODE
   ═══════════════════════════════════ */
body.dark .cf-kpi-section-bar .kpi-criteria { color: #94a3b8; }
body.dark .cf-kpi-strip  { background: #0a1120; }
body.dark .cf-kpi-item   { background: #111827; border-color: #1e2d3d; box-shadow: 0 2px 10px rgba(0,0,0,.3); }
body.dark .cf-kpi-item[onclick]:hover { box-shadow: 0 10px 32px rgba(0,0,0,.45); }
body.dark .cf-kpi-lbl    { color: #f1f5f9; }
body.dark .cf-kpi-sub    { color: #94a3b8; }
body.dark .cf-kpi-val    { color: #f1f5f9; }
body.dark .cf-kpi-detail { color: #94a3b8; }
body.dark .cf-kpi-bar-count { color: #94a3b8; }
body.dark .cf-kpi-bar-sub   { color: #94a3b8; }
body.dark .cf-kpi-bar-wrap  { background: #1e2d3d; }
body.dark .trend-up   { background: #052e16; color: #4ade80; }
body.dark .trend-down { background: #450a0a; color: #f87171; }
body.dark .trend-flat { background: #1e293b; color: #94a3b8; }
body.dark .cf-kpi-section-bar { background: transparent; }

/* ──── SECTION WRAPPER ──── */
.cf-section {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.cf-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--c-border);
  gap: 12px;
  flex-wrap: wrap;
}
.cf-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--c-text);
  display: flex; align-items: center; gap: 8px;
}
.cf-section-title i { color: var(--c-primary); font-size: 16px; }
.cf-section-sub { font-size: 11px; color: var(--c-muted); margin-top: 2px; }
.cf-section-body { padding: 20px 24px; }

/* ──── HEATMAP ──── */
.heatmap-wrap { overflow-x: auto; }
.heatmap-table {
  border-collapse: collapse;
  font-size: 11px;
  min-width: 600px;
  width: 100%;
}
.heatmap-table th {
  padding: 5px 4px;
  text-align: center;
  font-weight: 600;
  color: var(--c-light);
  font-size: 10px;
  white-space: nowrap;
}
.heatmap-table td { padding: 2px 2px; }
.hm-hosp-label {
  padding: 5px 12px 5px 4px !important;
  text-align: left !important;
  font-weight: 600;
  white-space: nowrap;
  font-size: 11px;
  color: var(--c-text);
  min-width: 110px;
}
.hm-cell {
  width: 26px; height: 22px;
  border-radius: 3px;
  cursor: default;
  position: relative;
  transition: transform .1s;
}
.hm-cell:hover { transform: scale(1.4); z-index: 10; }
.hm-pass    { background: #10b981; }
.hm-fail    { background: #ef4444; }
.hm-nosend  { background: #e2e8f0; }
.hm-weekend { background: #f8fafc; border: 1px solid #e5e7eb; }
.hm-legend {
  display: flex; gap: 16px; align-items: center;
  flex-wrap: wrap;
  padding: 12px 24px;
  border-top: 1px solid var(--c-border);
  font-size: 11px; color: var(--c-light);
}
.hm-leg-dot {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px; vertical-align: middle; margin-right: 5px;
}

/* ── Heatmap number cells ── */
.hm-num-table th { font-size: 10px; }
.hm-date-label {
  padding: 4px 2px;
  text-align: center;
  font-weight: 600;
  font-size: 10px;
  white-space: nowrap;
  color: var(--c-text);
}
.hm-date-label span { font-size: 8px; font-weight: 400; color: var(--c-muted); }
.hm-date-we { color: #94a3b8 !important; }
.hm-num-cell {
  width: 38px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  transition: transform .12s;
  background: #e2e8f0; /* default nosend */
}
.hm-num-cell:hover { transform: scale(1.3); z-index: 10; }
.hm-num { color: #fff; font-size: 10px; font-weight: 800; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.hm-we-mark, .hm-nosend-mark { color: #cbd5e1; font-size: 11px; }
/* Booking heatmap color states (set by JS recolorHeatmaps) */
.hm-booking-pass { background: #10b981 !important; }
.hm-booking-warn { background: #ef4444 !important; }
.hm-booking-nosend { background: #e2e8f0; }
.hm-booking-we    { background: #f8fafc; border: 1px solid #e5e7eb; }
/* Tele heatmap color states */
.hm-tele-pass { background: #8b5cf6 !important; }
.hm-tele-warn { background: #ef4444 !important; }
.hm-tele-nosend { background: #e2e8f0; }
.hm-tele-we    { background: #f8fafc; border: 1px solid #e5e7eb; }

/* Summary strip */
.hm-summary-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 16px 20px;
  background: var(--c-stripe);
  border-bottom: 1px solid var(--c-border);
}
.hm-sum-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: 12px 14px;
}
.hm-sum-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.hm-sum-val {
  font-size: 18px;
  font-weight: 900;
  color: var(--c-text);
  line-height: 1;
}
.hm-sum-lbl {
  font-size: 11px;
  color: var(--c-muted);
  margin-top: 3px;
}

/* Threshold bar */
.hm-threshold-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  flex-wrap: wrap;
}
.hm-thresh-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.hm-thresh-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.hm-thresh-lbl { font-size: 11px; color: var(--c-text); font-weight: 500; }
.hm-thresh-input {
  width: 65px;
  height: 26px;
  padding: 0 6px;
  border: 1px solid var(--c-border);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  background: var(--c-card);
  color: var(--c-text);
  text-align: center;
}
.hm-thresh-input:focus { outline: none; border-color: #3b82f6; }
.hm-thresh-sep {
  width: 1px;
  height: 18px;
  background: var(--c-border);
  margin: 0 4px;
}
/* Dark mode */
body.dark .hm-sum-card { background: #1e2535; border-color: #2d3a4f; }
body.dark .hm-thresh-input { background: #1e2535; border-color: #2d3a4f; color: #e2e8f0; }
body.dark .hm-booking-nosend, body.dark .hm-tele-nosend { background: #2d3748; }
body.dark .hm-booking-we, body.dark .hm-tele-we { background: #1a2234; border-color: #2d3748; }
body.dark .hm-booking-warn, body.dark .hm-tele-warn { background: #dc2626 !important; } /* darker red for dark mode */
/* Responsive */
@media (max-width: 768px) { .hm-summary-strip { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 480px) { .hm-summary-strip { grid-template-columns: 1fr; } }

/* ──── CIRCULAR PROGRESS (donut ring) ──── */
.ring-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.ring-chart {
  position: relative;
  width: 120px; height: 120px;
}
.ring-chart svg { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #e5e7eb; stroke-width: 10; }
.ring-fg { fill: none; stroke-width: 10; stroke-linecap: round;
           transition: stroke-dashoffset .6s ease; }
.ring-label {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  text-align: center;
  line-height: 1.1;
}
.ring-pct { font-size: 20px; font-weight: 800; }
.ring-sub { font-size: 10px; color: var(--c-muted); }
.ring-title { font-size: 11px; font-weight: 600; color: var(--c-light); text-align: center; }

/* ──── PROGRESS BAR ROW ──── */
.rate-bar-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 2px;
}
.rate-bar-lbl { font-size: 11px; width: 130px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rate-bar-track {
  flex: 1; height: 8px; background: #e5e7eb; border-radius: 10px; overflow: hidden;
}
.rate-bar-fill {
  height: 100%; border-radius: 10px;
  background: linear-gradient(90deg, #10b981, #059669);
  transition: width .4s ease;
}
.rate-bar-fill.warn  { background: linear-gradient(90deg, #f59e0b, #d97706); }
.rate-bar-fill.danger{ background: linear-gradient(90deg, #ef4444, #dc2626); }
.rate-bar-val { font-size: 11px; font-weight: 700; width: 40px; text-align: right; flex-shrink: 0; }

/* ──── HOSPITAL STATUS CARD v2 ──── */
.hosp-status-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  padding: 20px 24px;
}
.hosp-card {
  border-radius: 10px;
  border: 1.5px solid var(--c-border);
  background: var(--c-card);
  padding: 14px;
  transition: transform .15s, box-shadow .15s;
  position: relative;
  overflow: hidden;
}
.hosp-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.hosp-card.pass::before   { background: #10b981; }
.hosp-card.fail::before   { background: #ef4444; }
.hosp-card.nosend::before { background: #9ca3af; }
.hosp-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.hosp-card-top { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.hosp-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 3px; }
.hosp-name { font-size: 12px; font-weight: 700; color: var(--c-text); flex: 1; line-height: 1.35; min-width: 0; word-break: break-word; }
.hosp-district { font-size: 10px; color: var(--c-muted); margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hosp-stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 4px; margin-bottom: 8px; }
.hosp-stat-item { text-align: center; }
.hosp-stat-val { font-size: 14px; font-weight: 800; color: var(--c-text); }
.hosp-stat-lbl { font-size: 9px; color: var(--c-muted); }
.hosp-rate-bar { height: 4px; background: #e5e7eb; border-radius: 4px; overflow: hidden; }
.hosp-rate-bar > div { height: 100%; border-radius: 4px; transition: width .3s; }
.hosp-avatar {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}

/* ──── CHART TABS ──── */
.cf-tabs {
  display: flex; gap: 4px;
  background: var(--c-stripe);
  border-radius: 10px;
  padding: 4px;
}
.cf-tab {
  padding: 5px 14px;
  border-radius: 7px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-family: 'Sarabun', sans-serif;
  color: var(--c-light);
  cursor: pointer;
  transition: all .15s;
  font-weight: 500;
}
.cf-tab.active {
  background: var(--c-card);
  color: var(--c-primary);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.cf-tab:hover:not(.active) { color: var(--c-text); }

/* chart pane show/hide */
.chart-pane { display: none; }
.chart-pane.active { display: block; }
.chart-wrap { height: 260px; position: relative; }
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.chart-row-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }

/* ──── Analytics Cardiff-style grid ──── */
.analytics-chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.analytics-card {
  background: #fff;
  border: 1.5px solid #e5eaf0;
  border-radius: 16px;
  padding: 18px 20px 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.analytics-card-title {
  font-size: 14px; font-weight: 700; color: #111827;
  margin-bottom: 2px;
}
.analytics-card-sub {
  font-size: 11px; color: #94a3b8;
  margin-bottom: 14px;
}
body.dark .analytics-card {
  background: #111827; border-color: #1e2d3d;
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
body.dark .analytics-card-title { color: #f1f5f9; }
body.dark .analytics-card-sub   { color: #64748b; }

/* SSJ Analytics panel (matches overview ssj-crit-panel style) */
.ssj-chart-panel {
  margin: 20px 0 16px;
  background: linear-gradient(135deg, rgba(16,185,129,.06), rgba(59,130,246,.03));
  border: 1px solid rgba(16,185,129,.2);
  border-radius: 12px;
  overflow: hidden;
}
.ssj-chart-panel-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(16,185,129,.15);
}
.ssj-chart-panel-steps {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 10px 16px;
  flex-wrap: wrap;
}
.ssj-chart-panel-steps .ssj-crit-step {
  flex: 1;
  min-width: 160px;
}
.ssj-chart-panel-steps .ssj-step-arrow {
  display: flex;
  align-items: center;
  padding: 0 6px;
  color: var(--c-muted);
}
body.dark .ssj-chart-panel {
  background: linear-gradient(135deg, rgba(16,185,129,.09), rgba(59,130,246,.05));
  border-color: rgba(16,185,129,.25);
}
body.dark .ssj-chart-panel-top {
  border-bottom-color: rgba(16,185,129,.2);
}

/* ──── RANK TABLE ──── */
.rank-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.rank-table thead { background: var(--c-stripe); }
.rank-table th {
  padding: 9px 12px;
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--c-light);
  font-weight: 700;
  white-space: nowrap;
  border-bottom: 2px solid var(--c-border);
}
.rank-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}
.rank-table tbody tr:hover { background: var(--c-stripe); }
.rank-table tbody tr:last-child td { border-bottom: none; }
.tbl-row-clickable { cursor: pointer; transition: background .12s; }
.tbl-row-clickable:hover { background: rgba(59,130,246,.07) !important; }
.tbl-row-clickable:active { background: rgba(59,130,246,.13) !important; }
.rank-num {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800;
  background: var(--c-stripe);
  color: var(--c-light);
}
.rank-num.gold   { background: #fef3c7; color: #b45309; }
.rank-num.silver { background: #f1f5f9; color: #475569; }
.rank-num.bronze { background: #fdf4e7; color: #92400e; }
.rate-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}
.rate-pass   { background: #d1fae5; color: #065f46; }
.rate-warn   { background: #fef3c7; color: #92400e; }
.rate-danger { background: #fee2e2; color: #991b1b; }
.rate-gray   { background: #f1f5f9; color: #64748b; }
.inline-bar {
  display: flex; align-items: center; gap: 6px; min-width: 80px;
}
.inline-bar-track {
  flex: 1; height: 6px; background: #e5e7eb; border-radius: 10px; overflow: hidden;
}
.inline-bar-fill {
  height: 100%; border-radius: 10px;
  transition: width .3s;
}

/* ──── SEND STATUS INDICATOR ──── */
.send-ring {
  width: 50px; height: 50px; position: relative;
  display: inline-flex; align-items: center; justify-content: center;
}
.send-ring-bg { fill: none; stroke: #e5e7eb; stroke-width: 5; }
.send-ring-fg { fill: none; stroke: #10b981; stroke-width: 5; stroke-linecap: round; transition: stroke-dashoffset .5s; }
.send-ring-txt { position: absolute; font-size: 10px; font-weight: 800; color: var(--c-text); }

/* ──── FILTER SECTION ──── */
.cf-filter-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--c-stripe);
  border-bottom: 1px solid var(--c-border);
}
.cf-filter-bar label { font-size: 12px; color: var(--c-light); font-weight: 600; }
.cf-filter-bar select,
.cf-filter-bar input[type=date] {
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid var(--c-border);
  background: var(--c-card);
  font-size: 12px;
  color: var(--c-text);
  font-family: 'Sarabun', sans-serif;
}
.cf-filter-sep { color: var(--c-border); font-size: 16px; margin: 0 2px; }

/* ──── PASS/FAIL CHIP ──── */
.status-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 700;
  white-space: nowrap;
}
.chip-pass   { background: #d1fae5; color: #065f46; }
.chip-fail   { background: #fee2e2; color: #991b1b; }
.chip-nosend { background: #f1f5f9; color: #64748b; }
.chip-tele   { background: #ede9fe; color: #5b21b6; }

/* ──── DONUT SUMMARY ──── */
.donut-row {
  display: flex; gap: 24px; align-items: center;
  flex-wrap: wrap;
}
.donut-legend { display: flex; flex-direction: column; gap: 8px; }
.donut-leg-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
}
.donut-leg-color {
  width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}

/* ──── DARK MODE OVERRIDES ──── */
body.dark .cardiff-header {
  background: linear-gradient(135deg, #070d14 0%, #0d1b34 60%, #0a1328 100%);
}
body.dark .cf-section { background: var(--c-card); }
body.dark .hm-nosend  { background: #2d3748; }
body.dark .hm-weekend { background: #1a2234; border-color: #2d3748; }
body.dark .hosp-card  { background: var(--c-card); border-color: rgba(255,255,255,.08); }
body.dark .rank-table thead { background: rgba(255,255,255,.04); }
body.dark .rank-table tbody tr:hover { background: rgba(255,255,255,.04); }
body.dark .cf-tabs { background: rgba(255,255,255,.06); }
body.dark .cf-tab.active { background: rgba(255,255,255,.1); }
body.dark .cf-filter-bar { background: rgba(255,255,255,.04); }
body.dark .cf-filter-bar select,
body.dark .cf-filter-bar input[type=date] { background: #2d3748; color: #e2e8f0; border-color: #4a5568; }

/* ──── SEND RATE SUMMARY BAR ──── */
.send-summary-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 24px;
  background: linear-gradient(90deg,#ecfdf5,#f0fdf4);
  border-bottom: 1px solid #a7f3d0;
  flex-wrap: wrap;
}
body.dark .send-summary-bar {
  background: rgba(16,185,129,.08);
  border-bottom-color: rgba(16,185,129,.15);
}
.send-pct-big {
  font-size: 32px; font-weight: 900;
  color: #10b981;
  line-height: 1;
}
.send-of { font-size: 13px; color: var(--c-light); }
.send-of strong { color: var(--c-text); }
.send-progress-track {
  flex: 1; height: 12px; background: #a7f3d0; border-radius: 10px; overflow: hidden;
  min-width: 100px;
}
.send-progress-fill {
  height: 100%;
  background: linear-gradient(90deg,#10b981,#059669);
  border-radius: 10px;
  transition: width .5s ease;
}

/* ──── RESPONSIVE ──── */
@media (max-width: 1200px) {
  .cf-kpi-strip { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
@media (max-width: 900px) {
  .cf-kpi-strip { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); padding: 10px 16px 16px; }
  .cf-kpi-section-bar { padding: 10px 16px 0; }
  .cf-kpi-val { font-size: 36px; }
  .chart-row, .chart-row-3 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .cf-kpi-strip { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 8px 12px 14px; }
  .cf-kpi-section-bar { padding: 8px 12px 0; }
  .cf-kpi-val { font-size: 30px; }
  .cardiff-header-inner { padding: 14px 16px; }
  .hosp-status-grid { grid-template-columns: repeat(2,1fr); gap: 10px; padding: 14px; }
}

/* ============================================================
   MAP SECTION — Leaflet Hospital Map
   ============================================================ */

/* Map container */
/* Filter bar above map */
/* ── Cardiff-style Map Control Panel ── */
.map-ctrl-panel {
  padding: 16px 20px 12px;
  background: #fff;
  border-bottom: 1px solid #e5eaf0;
}
.map-ctrl-header {
  display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px;
}
.map-ctrl-title { font-size: 15px; font-weight: 700; color: #111827; }
.map-ctrl-sub   { font-size: 12px; color: #94a3b8; margin-top: 2px; }
.map-ctrl-badge {
  font-size: 11px; font-weight: 700;
  background: #0f3460; color: #fff;
  padding: 4px 14px; border-radius: 20px;
  white-space: nowrap;
}
.map-ctrl-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px;
}
.map-tab-group { display: flex; gap: 4px; }
.map-tab {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 600;
  padding: 6px 14px;
  border: 1.5px solid #e2e8f0; background: #f8fafc; color: #64748b;
  border-radius: 8px; cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.map-tab:hover { border-color: #3b82f6; color: #3b82f6; background: #eff6ff; }
.map-tab.active { background: #f59e0b; border-color: #f59e0b; color: #fff; }
.map-view-btn.active { background: #3b82f6; border-color: #3b82f6; color: #fff; }
.map-view-btn.active[onclick*="'tele'"] { background: #8b5cf6; border-color: #8b5cf6; }
.map-view-btn.active[onclick*="'compare'"] { background: linear-gradient(135deg,#f59e0b,#8b5cf6); border-color: #f59e0b; }
.map-tab-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.map-tab-divider { width: 1px; height: 28px; background: #e2e8f0; margin: 0 4px; flex-shrink: 0; }
.map-ctrl-icon-btn {
  background: #f1f5f9; border: 1.5px solid #e2e8f0; border-radius: 8px;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  color: #64748b; cursor: pointer; flex-shrink: 0; transition: background .15s;
}
.map-ctrl-icon-btn:hover { background: #e2e8f0; }
.map-ctrl-filter-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-top: 10px; border-top: 1px solid #f0f4f8;
}
.map-info-chip { display: flex; align-items: center; gap: 5px; font-size: 12px; color: #64748b; }
.map-info-dot  { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Map legend — KPI SSJ single-row */
.map-legend-title { font-size: 11px; font-weight: 700; color: #64748b; margin-bottom: 6px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.map-legend-basis { font-size: 10px; font-weight: 400; color: #94a3b8; }
.map-legend-chips { display: flex; gap: 5px; }
/* horizontal row variant */
.map-legend-row   { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; }
.map-legend-ssj-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(241,245,249,.8); border: 1px solid rgba(226,232,240,.9);
  border-radius: 20px; padding: 3px 10px 3px 6px;
  white-space: nowrap;
}
.map-legend-ssj-chip .map-info-dot { width: 9px; height: 9px; }
.map-legend-ssj-label { font-size: 11.5px; font-weight: 700; line-height: 1; }
/* legacy stacked chip styles (kept for compat) */
.map-legend-chip-detail { align-items: flex-start !important; gap: 8px !important; background: rgba(241,245,249,.7); border-radius: 8px; padding: 6px 10px; }
.map-legend-chip-detail .map-info-dot { margin-top: 3px; width: 11px; height: 11px; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.map-legend-chip-body { display: flex; flex-direction: column; gap: 1px; }
.map-legend-chip-name { font-size: 12px; font-weight: 700; line-height: 1.2; }
.map-legend-chip-desc { font-size: 10.5px; color: #94a3b8; line-height: 1.2; }
.map-ctrl-clear-btn {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; color: #ef4444;
  padding: 4px 10px; border: 1.5px solid #fecaca; border-radius: 6px;
  white-space: nowrap;
}
.map-ctrl-clear-btn:hover { background: #fef2f2; }

/* Legacy filter bar (kept for fallback) */
.map-filter-bar {
  padding: 12px 18px;
  background: var(--c-bg-card, #1e2d3d);
  border-bottom: 1px solid var(--c-border, rgba(255,255,255,.08));
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.map-filter-label {
  font-size: 12px;
  color: var(--c-muted, #94a3b8);
  white-space: nowrap;
  font-weight: 500;
}
.map-filter-sel {
  padding: 4px 10px;
  background: var(--c-bg-input, #273447);
  border: 1px solid var(--c-border, rgba(255,255,255,.12));
  border-radius: 6px;
  color: var(--c-text, #e2e8f0);
  font-size: 12px;
  font-family: 'Sarabun', sans-serif;
  cursor: pointer;
}
.map-filter-sel:focus { outline: none; border-color: var(--c-accent, #3b82f6); }
.map-filter-btn {
  padding: 4px 12px;
  background: var(--c-accent, #3b82f6);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-family: 'Sarabun', sans-serif;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background .15s;
}
.map-filter-btn:hover { background: #2563eb; }

/* Legend below map */
.map-legend {
  padding: 10px 18px;
  background: var(--c-bg-card, #1e293b);
  border-top: 1px solid var(--c-border, rgba(255,255,255,.08));
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.map-legend-title {
  font-size: 11px;
  color: var(--c-muted, #94a3b8);
  font-weight: 600;
  white-space: nowrap;
}
.map-legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}
.map-leg-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--c-text, #e2e8f0);
  white-space: nowrap;
}
.map-leg-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Custom marker pin */
.map-marker {
  width: 40px;
  height: 40px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 12px rgba(0,0,0,.35);
  border: 2.5px solid rgba(255,255,255,.85);
  transition: transform .18s, box-shadow .18s;
}
.map-marker span {
  transform: rotate(45deg);
  font-size: 14px;
  font-weight: 900;
  color: #fff;
  display: block;
}
.leaflet-marker-icon:hover .map-marker {
  transform: rotate(-45deg) scale(1.18);
  box-shadow: 0 5px 18px rgba(0,0,0,.45);
}
/* Province boundary tooltip */
.leaflet-province-label {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 13px;
  font-weight: 700;
  color: #1d4ed8;
  opacity: 0.8;
}

/* Custom popup */
.leaflet-popup-content-wrapper {
  background: var(--c-bg-card, #1e293b) !important;
  color: var(--c-text, #e2e8f0) !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 30px rgba(0,0,0,.5) !important;
  padding: 0 !important;
  overflow: hidden;
}
.leaflet-popup-tip { background: var(--c-bg-card, #1e293b) !important; }
.leaflet-popup-content { margin: 0 !important; width: 264px !important; }

.map-popup-inner {
  font-family: 'Sarabun', sans-serif;
  font-size: 13px;
}
.map-popup-header {
  padding: 11px 14px 8px;
  background: rgba(0,0,0,.2);
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.map-popup-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--c-text, #f1f5f9);
  line-height: 1.3;
}
.map-popup-meta {
  font-size: 11px;
  color: var(--c-muted, #94a3b8);
  margin-top: 2px;
}
.map-popup-body {
  padding: 10px 14px 12px;
}
.map-popup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  gap: 8px;
  font-size: 12px;
}
.map-popup-key {
  color: var(--c-muted, #94a3b8);
  white-space: nowrap;
  font-size: 11px;
}
.map-popup-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.map-popup-chip.chip-pass   { background: rgba(16,185,129,.2); color: #34d399; }
.map-popup-chip.chip-fail   { background: rgba(239, 68, 68,.2); color: #f87171; }
.map-popup-chip.chip-nosend { background: rgba(148,163,184,.15); color: #94a3b8; }

.map-popup-bar-wrap {
  height: 6px;
  background: rgba(255,255,255,.1);
  border-radius: 3px;
  margin: 6px 0;
  overflow: hidden;
}
.map-popup-bar-fill {
  height: 100%;
  border-radius: 3px;
  opacity: .85;
  transition: width .3s ease;
}

/* ── Hospital data grid below map — 4-column ── */
.map-hosp-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 14px 16px 18px;
  border-top: 1px solid #f1f5f9;
}

/* Card item */
.map-hosp-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: #fff;
  border: 1.5px solid #e5eaf0;
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 1px 5px rgba(15,52,96,.06);
  transition: box-shadow .15s, border-color .15s, transform .15s;
}
.map-hosp-card:hover {
  border-color: #c7d2fe;
  box-shadow: 0 6px 18px rgba(99,102,241,.13);
  transform: translateY(-2px);
}
.map-hosp-card-nodata { opacity: .58; }

/* Rank badge at top */
.map-hosp-card-rank {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  padding: 10px 0 8px;
  border-bottom: 1.5px solid rgba(0,0,0,.05);
  letter-spacing: -0.5px;
}

.map-hosp-card-body {
  flex: 1;
  min-width: 0;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-hosp-card-name {
  font-size: 14px;
  font-weight: 800;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  margin-bottom: 1px;
}
.map-hosp-card-district {
  font-size: 11px;
  color: #64748b;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 3px;
}

/* SSJ status badge inside card */
.map-ssj-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 8px;
  padding: 3px 9px;
  margin-bottom: 8px;
  width: fit-content;
}
.map-ssj-badge-green  { background:#ecfdf5; color:#059669; border:1px solid #a7f3d0; }
.map-ssj-badge-amber  { background:#fffbeb; color:#d97706; border:1px solid #fcd34d; }
.map-ssj-badge-red    { background:#fef2f2; color:#dc2626; border:1px solid #fca5a5; }
.map-ssj-badge-gray   { background:#f8fafc; color:#94a3b8; border:1px solid #e2e8f0; }

/* Progress bars */
.map-hosp-card-bars { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
.map-hosp-bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.map-hosp-bar-lbl {
  font-size: 10.5px;
  font-weight: 600;
  flex-shrink: 0;
  width: 52px;
  display: flex;
  align-items: center;
  gap: 3px;
  color: #475569;
}
.map-hosp-bar-track {
  flex: 1;
  height: 8px;
  background: #f1f5f9;
  border-radius: 6px;
  overflow: hidden;
}
.map-hosp-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width .4s ease;
}
.map-hosp-bar-val {
  font-size: 11px;
  font-weight: 800;
  min-width: 36px;
  text-align: right;
  flex-shrink: 0;
}
.map-hosp-card-nodata-lbl {
  font-size: 12px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
}

/* Dark mode */
body.dark .map-hosp-grid { border-top-color: #1e2d3d; }
body.dark .map-hosp-card { background: #111827; border-color: #1e2d3d; box-shadow: 0 1px 6px rgba(0,0,0,.25); }
body.dark .map-hosp-card:hover { border-color: #3730a3; box-shadow: 0 4px 14px rgba(99,102,241,.2); }
body.dark .map-hosp-card-name { color: #e2e8f0; }
body.dark .map-hosp-bar-track { background: #1e2d3d; }

@media (max-width: 1100px) {
  .map-hosp-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
  .map-hosp-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .map-hosp-grid { grid-template-columns: 1fr; }
}

/* ── (legacy kept for JS compat) ── */
.map-layout-row { display: none; }
.map-layout-left { display: none; }
.map-layout-right { display: none; }
/* ── Map card wrapper (rounded corners, contained) ── */
.map-card-wrap {
  margin: 0 16px 16px;
  border-radius: 14px;
  overflow: hidden;
  border: 1.5px solid #e5eaf0;
  box-shadow: 0 2px 16px rgba(15,52,96,.08);
}
body.dark .map-card-wrap {
  border-color: #1e2d3d;
  box-shadow: 0 2px 16px rgba(0,0,0,.3);
}

#mapContainer {
  width: 100%;
  height: 580px;
}

/* ── Right panel header ── */
.map-rpanel-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 18px 14px;
  border-bottom: 1.5px solid #f1f5f9;
  flex-shrink: 0;
  background: #fff;
}
.map-rpanel-header-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
}
.map-rpanel-header-badge {
  font-size: 12px;
  font-weight: 500;
  color: #64748b;
}

/* ── Right panel tabs (pill style) ── */
.map-rpanel-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 16px 10px;
  background: #fff;
  border-bottom: 1.5px solid #f1f5f9;
  flex-shrink: 0;
}
.map-rpanel-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: #64748b;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  cursor: pointer;
  transition: all .18s ease;
}
.map-rpanel-tab:hover { color: #1d4ed8; border-color: #93c5fd; background: #eff6ff; }
.map-rpanel-tab.active { color: #1e293b; background: #f59e0b; border-color: #f59e0b; font-weight: 700; }

/* ── Right panel pane ── */
.map-rpanel-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.map-rpanel-pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 16px 8px;
  background: #f8fafc;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}
.map-rpanel-stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1.5px solid transparent;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

/* ── Sub-tabs (Top slot / Top tele) ── */
.map-rpanel-subtabs {
  display: flex;
  gap: 8px;
  padding: 8px 12px 7px;
  background: #f8fafc;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}
.map-rpanel-subtab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1.5px solid #e2e8f0;
  background: #fff;
  color: #64748b;
  cursor: pointer;
  transition: all .15s;
}
.map-rpanel-subtab:hover { background: #eff6ff; border-color: #93c5fd; color: #1d4ed8; }
.map-rpanel-subtab.active { background: #eff6ff; border-color: #3b82f6; color: #1d4ed8; font-weight: 700; box-shadow: 0 2px 6px rgba(59,130,246,.15); }

/* ── List ── */
.map-rpanel-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 14px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.map-rpanel-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 16px;
  color: #94a3b8;
  font-size: 13px;
}
.map-rpanel-empty i { font-size: 32px; opacity: .35; }
.map-rpanel-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fff;
  margin-bottom: 6px;
  border: 1.5px solid #f1f5f9;
  transition: box-shadow .15s, border-color .15s, background .15s;
  cursor: default;
}
.map-rpanel-item:hover { box-shadow: 0 3px 12px rgba(15,52,96,.08); border-color: #dbeafe; background: #fafcff; }
.map-rpanel-item-sm { padding: 10px 12px; }

/* rank circle */
.map-rpanel-rank {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #64748b;
  background: #f1f5f9;
  border: 1.5px solid #e2e8f0;
  flex-shrink: 0;
}
.map-rpanel-rank.top1 { background: #fef3c7; border-color: #fbbf24; color: #92400e; }
.map-rpanel-rank.top2 { background: #f1f5f9; border-color: #94a3b8; color: #334155; }
.map-rpanel-rank.top3 { background: #fef3c7; border-color: #d97706; color: #78350f; }

/* item body */
.map-rpanel-item-body { flex: 1; min-width: 0; }
.map-rpanel-name {
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  margin-bottom: 2px;
}
.map-rpanel-sub {
  font-size: 11.5px;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 6px;
}
.map-rpanel-dist {
  font-size: 10.5px;
  color: #94a3b8;
  white-space: nowrap;
  flex-shrink: 0;
  background: #f8fafc;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid #f1f5f9;
  align-self: flex-start;
}

/* bars (keep for backward compat) */
.map-rpanel-item-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.map-rpanel-bars { display: flex; flex-direction: column; gap: 5px; }
.map-rpanel-bar-row { display: flex; align-items: center; gap: 7px; }
.map-rpanel-bar-label { font-size: 11px; width: 18px; text-align: center; flex-shrink: 0; }
.map-rpanel-bar-track {
  flex: 1;
  height: 6px;
  background: #f1f5f9;
  border-radius: 6px;
  overflow: hidden;
}
.map-rpanel-bar-fill { height: 100%; border-radius: 6px; transition: width .4s ease; }
.map-rpanel-bar-val { font-size: 11.5px; font-weight: 700; min-width: 38px; text-align: right; flex-shrink: 0; }

/* Light-mode overrides */
body:not(.dark) #mapContainer { background: #e8eef4; }
body:not(.dark) .map-filter-bar { background: #f8fafc; border-color: #e2e8f0; }
body:not(.dark) .map-filter-sel { background: #fff; border-color: #cbd5e1; color: #334155; }
body:not(.dark) .map-filter-label { color: #64748b; }
body:not(.dark) .map-legend { background: #f8fafc; border-color: #e2e8f0; }
body:not(.dark) .map-leg-item { color: #334155; }
body:not(.dark) .map-legend-title { color: #64748b; }
body:not(.dark) .leaflet-popup-content-wrapper { background: #fff !important; color: #334155 !important; }
body:not(.dark) .leaflet-popup-tip { background: #fff !important; }
body:not(.dark) .map-popup-name { color: #0f172a; }
body:not(.dark) .map-popup-header { background: #f1f5f9; border-color: #e2e8f0; }
body:not(.dark) .map-popup-row { border-color: #f1f5f9; }

/* Responsive */
@media (max-width: 900px) {
  .map-layout-row { flex-direction: column; gap: 10px; }
  .map-layout-left { flex: none; width: 100%; }
  .map-layout-right { flex: none; width: 100%; min-height: 360px; }
  #mapContainer { min-height: 340px; height: 340px; }
}
@media (max-width: 600px) {
  .map-filter-bar { padding: 10px 12px; }
  .leaflet-popup-content { width: 220px !important; }
}

/* ============================================================
   CARDIFF-MODEL LAYOUT v3.0 — Sidebar + Topbar + Main
   ============================================================ */

:root {
  --sb-width:           248px;
  --sb-width-collapsed: 64px;
  --tb-height:          76px;
}

/* ── SIDEBAR ── */
.cw-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sb-width);
  background: var(--c-card);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: width .22s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.cw-sidebar.collapsed { width: var(--sb-width-collapsed); }

/* Brand */
.sb-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}
.sb-logo-icon {
  font-size: 24px;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg,#4f46e5,#7c3aed);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.sb-brand-text { overflow: hidden; white-space: nowrap; }
.sb-brand-name { font-size: 14px; font-weight: 700; color: var(--c-text); line-height: 1.25; }
.sb-brand-sub  { font-size: 11px; color: var(--c-muted); margin-top: 1px; }

/* Collapse button */
.sb-collapse-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% - 20px);
  margin: 8px 10px;
  padding: 9px 12px;
  background: var(--c-stripe);
  border: 1px solid var(--c-border);
  border-radius: 9px;
  cursor: pointer;
  color: var(--c-light);
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.sb-collapse-btn:hover { background: #e9eef4; color: var(--c-text); }
#sbChevron {
  font-size: 14px;
  flex-shrink: 0;
  transition: transform .22s;
}
.cw-sidebar.collapsed #sbChevron { transform: rotate(180deg); }
.sb-collapse-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  overflow: hidden;
  white-space: nowrap;
}
.sb-collapse-text span  { font-size: 12px; font-weight: 600; color: var(--c-text); }
.sb-collapse-text small { font-size: 10px; color: var(--c-muted); }

/* Nav */
.sb-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0;
}
.sb-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin: 2px 10px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--c-light);
  white-space: nowrap;
  overflow: hidden;
  transition: background .15s, color .15s;
}
.sb-item i {
  font-size: 18px;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}
.sb-item:hover { background: #f1f5f9; color: var(--c-text); }
.sb-item.active {
  background: #eef2ff;
  color: #4338ca;
  font-weight: 700;
}
.sb-item-text { overflow: hidden; min-width: 0; }
.sb-item-title { font-size: 14px; font-weight: 500; line-height: 1.3; }
.sb-item.active .sb-item-title { font-weight: 700; }
.sb-item-sub   { font-size: 11px; color: var(--c-muted); margin-top: 1px; }
.sb-item.active .sb-item-sub { color: #818cf8; }

/* ── Sidebar group accordion ── */
.sb-group { margin: 2px 0; }
.sb-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin: 2px 10px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--c-muted);
  white-space: nowrap;
  overflow: hidden;
  transition: background .15s, color .15s;
  user-select: none;
  border: none;
  outline: none;
  width: calc(100% - 20px);
  text-align: left;
  background: transparent;
}
.sb-group-header .sb-item-title {
  font-size: 14px;
  font-weight: 700;
  color: #4338ca;
}
.sb-group-header .sb-item-sub {
  font-size: 11px;
  color: #818cf8;
}
.sb-group-header .sb-group-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}
.sb-group-header:hover { background: #f1f5f9; }
.sb-group-header:hover .sb-item-title { color: #3730a3; }
.sb-group-header.open  { background: transparent; }
.sb-group-header.open .sb-item-title  { color: #4338ca; }
.sb-group-header.open .sb-item-sub    { color: #818cf8; }
.sb-group-chevron {
  margin-left: auto;
  font-size: 12px;
  flex-shrink: 0;
  transition: transform .25s;
}
.sb-group-header.open .sb-group-chevron { transform: rotate(180deg); }
.sb-group-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height .3s ease;
}
.sb-group-body.open { max-height: 600px; }
.sb-group-body .sb-item { padding-left: 26px; }
.sb-group-body .sb-item i { font-size: 16px; }
/* collapsed sidebar: hide group text & sub-items */
.cw-sidebar.collapsed .sb-group-header { justify-content: center; padding: 9px 0; margin: 2px 8px; }
.cw-sidebar.collapsed .sb-group-chevron,
.cw-sidebar.collapsed .sb-group-header .sb-item-text { display: none; }
.cw-sidebar.collapsed .sb-group-body { max-height: 0 !important; }
/* dark mode */
body.dark .sb-group-header .sb-item-title { color: #94a3b8; }
body.dark .sb-group-header.open .sb-item-title { color: #cbd5e1; }
body.dark .sb-group-header:hover { background: rgba(255,255,255,.06); }
body.dark .sb-group-header:hover .sb-item-title { color: #e2e8f0; }

/* Sidebar footer */
.sb-footer {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--c-border);
  flex-shrink: 0;
  overflow: hidden;
}
.sb-footer-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--c-muted);
  margin-bottom: 2px;
}
.sb-footer-date { font-size: 11px; color: var(--c-light); }

/* Collapsed: hide text */
.cw-sidebar.collapsed .sb-brand-text,
.cw-sidebar.collapsed .sb-collapse-text,
.cw-sidebar.collapsed .sb-item-text,
.cw-sidebar.collapsed .sb-footer-label,
.cw-sidebar.collapsed .sb-footer-date { display: none; }
.cw-sidebar.collapsed .sb-item { justify-content: center; padding: 10px 0; margin: 2px 8px; }
.cw-sidebar.collapsed .sb-brand  { justify-content: center; padding: 16px 0; }
.cw-sidebar.collapsed .sb-collapse-btn { justify-content: center; width: calc(100% - 16px); margin: 8px 8px; padding: 9px 0; }
.cw-sidebar.collapsed .sb-footer { padding: 8px 4px; text-align: center; }

/* ── Sidebar Footer: new elements ── */
.sb-footer-row1 {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 7px;
}
/* User row */
.sb-footer-user-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(3,105,161,.07);
  border-radius: 8px;
  padding: 5px 8px;
  margin-bottom: 7px;
  min-width: 0;
}
.sb-footer-user-icon { font-size: 15px; color: #0369a1; flex-shrink: 0; }
.sb-footer-username  { font-size: 12px; font-weight: 600; color: var(--c-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
/* Login button */
.sb-footer-login-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg,#1d4ed8,#0369a1);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 7px;
  transition: opacity .15s;
}
.sb-footer-login-btn:hover { opacity: .88; color: #fff; }
.sb-footer-login-txt { white-space: nowrap; }
/* Icon-only small button */
.sb-ftr-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: rgba(100,116,139,.1);
  color: var(--c-muted);
  font-size: 14px;
  text-decoration: none;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.sb-ftr-icon-btn:hover { background: rgba(3,105,161,.15); color: #0369a1; }
/* Theme row */
.sb-footer-theme-row {
  display: flex;
  gap: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--c-border);
  background: rgba(241,245,249,.6);
}
.sb-theme-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 0;
  border: none;
  border-right: 1px solid var(--c-border);
  background: transparent;
  color: var(--c-muted);
  font-size: 12px;
  cursor: pointer;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.sb-theme-btn:last-child { border-right: none; }
.sb-theme-btn:hover { background: rgba(3,105,161,.08); color: #0369a1; }
.sb-theme-btn.active { background: #1d4ed8; color: #fff; }
.sb-theme-lbl { font-size: 10px; font-weight: 600; }
/* Collapsed: hide text, center icons */
.cw-sidebar.collapsed .sb-footer-row1 { justify-content: center; }
.cw-sidebar.collapsed .sb-footer-row1 > div:first-child { display: none; }
.cw-sidebar.collapsed .sb-footer-user-row { padding: 5px; justify-content: center; }
.cw-sidebar.collapsed .sb-footer-username,
.cw-sidebar.collapsed .sb-ftr-icon-btn[href*="logout"] { display: none; }
.cw-sidebar.collapsed .sb-footer-login-btn { padding: 7px; justify-content: center; }
.cw-sidebar.collapsed .sb-footer-login-txt { display: none; }
.cw-sidebar.collapsed .sb-footer-theme-row { border-radius: 8px; }
.cw-sidebar.collapsed .sb-theme-lbl { display: none; }
.cw-sidebar.collapsed .sb-theme-btn { padding: 7px 0; font-size: 13px; }

/* ── TOPBAR ── */
.cw-topbar {
  position: fixed;
  top: 0;
  left: var(--sb-width);
  right: 0;
  min-height: var(--tb-height);
  height: var(--tb-height);
  background: var(--c-card);
  border-bottom: 2px solid var(--c-border);
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 199;
  transition: left .22s cubic-bezier(.4,0,.2,1);
  /* ไม่มี border-radius — เต็มบรรทัดแบน */
  border-radius: 0;
}
.cw-sidebar.collapsed ~ .cw-topbar { left: var(--sb-width-collapsed); }

/* ── Inner wrapper — layout only, no extra card styling ── */
.tb-header-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0;
  height: 100%;
  overflow: visible;
}

.tb-page-info {
  flex: 0 0 auto;
  padding: 0 16px 0 0;
  border-right: 1px solid var(--c-border);
  margin-right: 14px;
}
.tb-page-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--c-text);
  line-height: 1.2;
  white-space: nowrap;
}
.tb-page-sub {
  font-size: 10px;
  color: var(--c-muted);
  white-space: nowrap;
  margin-top: 2px;
}
.tb-controls {
  /* All visible controls moved to .tb-pinned-right; this div holds only hidden form inputs */
  display: none;
  flex: 0;
}

/* ── Pinned-right zone: ALL visible topbar controls ──────
   Controls zone is hidden; this takes the full remaining
   topbar width. overflow:visible keeps dropdowns unclipped. */
.tb-pinned-right {
  display: flex;
  align-items: center;
  gap: 8px;              /* ช่องไฟระหว่าง group เพิ่มขึ้น */
  flex: 1;
  flex-shrink: 0;
  overflow: visible;
  position: relative;
  flex-wrap: nowrap;
  min-width: 0;
}
.tb-auth-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Theme-button text labels — hidden (icon-only on all sizes) */
.tb-theme-txt { display: none; }

/* ── Mobile sidebar toggle (hamburger) ────────────────────
   Hidden on desktop; shown at ≤768px.                        */
.tb-sb-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--c-text);
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
  margin-right: 6px;
  transition: background .15s;
}
.tb-sb-toggle:hover { background: var(--c-stripe); }
body.dark .tb-sb-toggle { color: #e2e8f0; }

/* ── Mobile sidebar overlay backdrop ─────────────────────
   Covers the page when sidebar drawer is open.               */
.sb-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 310;
}
body.mobile-sidebar-open .sb-overlay { display: block; }
.tb-select {
  height: 30px;
  padding: 0 7px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  background: var(--c-card);
  color: var(--c-text);
  cursor: pointer;
  max-width: 140px;
}
.tb-select:focus { outline: none; border-color: #3b82f6; }
.tb-select-active {
  border-color: #60a5fa !important;
  background: rgba(59,130,246,.12) !important;
  color: #1d4ed8 !important;
  font-weight: 700 !important;
  box-shadow: 0 0 0 2px rgba(59,130,246,.25);
}
body.dark .tb-select-active {
  color: #93c5fd !important;
  background: rgba(59,130,246,.18) !important;
}
.tb-date-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: var(--c-card);
  color: var(--c-light);
  font-size: 12px;
}
/* Date range wrapper — two Thai-year date pickers with separator */
.tb-daterange-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: var(--c-card);
  color: var(--c-text);
  font-size: 11px;
}
/* Thai date picker — transparent native input + Thai-year overlay */
.thai-dp-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 26px;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
.thai-dp-wrap:hover {
  border-color: rgba(59,130,246,.35);
  background: rgba(59,130,246,.08);
}
/* Native date input — full-size, text made invisible, calendar icon remains clickable */
.thai-dp-input {
  width: 88px;
  height: 26px;
  border: none;
  background: transparent;
  outline: none;
  cursor: pointer;
  color: transparent;   /* hide CE year text */
  padding-right: 4px;
  font-size: 11px;
}
/* Calendar picker icon - keep visible and clickable */
.thai-dp-input::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.55;
  margin-left: auto;
  position: relative;
  z-index: 2;
  flex-shrink: 0;
}
/* Hide the editable date text part (webkit) */
.thai-dp-input::-webkit-datetime-edit-fields-wrapper { visibility: hidden; }
/* Thai date overlay — floats over input text area, passes clicks through */
.thai-dp-overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 18px; /* leave room for calendar icon */
  display: flex;
  align-items: center;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--c-text);
  white-space: nowrap;
  pointer-events: none; /* clicks pass through to native input */
  user-select: none;
}
.thai-dp-sep {
  font-size: 10px;
  color: var(--c-muted);
  padding: 0 1px;
  flex-shrink: 0;
  user-select: none;
}
/* Dark mode */
body.dark .thai-dp-overlay { color: #e2e8f0; }
body.dark .thai-dp-input::-webkit-calendar-picker-indicator { filter: invert(1); opacity: .5; }
.tb-date-input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 12px;
  font-family: inherit;
  color: var(--c-text);
  cursor: pointer;
  width: 120px;
}
.tb-theme-group {
  display: flex;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.tb-theme-btn {
  height: 30px;
  width: 30px;
  min-width: 30px;     /* prevent text span from forcing extra width */
  padding: 0;
  border: none;
  border-right: 1px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-light);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;    /* clip any span text that leaks */
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.tb-theme-btn:last-child { border-right: none; }
.tb-theme-btn:hover { background: var(--c-stripe); color: var(--c-text); }
.tb-theme-btn.active {
  background: linear-gradient(135deg,#1d4ed8,#3b82f6);
  color: #fff;
  border-right-color: transparent;
}

.tb-action-btn {
  height: 30px;
  padding: 0 11px;
  border: 1.5px solid var(--c-border);
  border-radius: 8px;
  background: var(--c-card);
  color: var(--c-text);
  font-size: 11.5px;
  font-family: inherit;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, border-color .15s, box-shadow .15s;
  flex-shrink: 0;
  white-space: nowrap;
  cursor: pointer;
}
/* Login CTA — highlighted */
.tb-action-btn.tb-login-btn {
  background: linear-gradient(135deg,#0f3460,#1e4d8c);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(15,52,96,.3);
}
.tb-action-btn.tb-login-btn:hover {
  background: linear-gradient(135deg,#1e4d8c,#2563eb);
  box-shadow: 0 3px 12px rgba(15,52,96,.45);
  color: #fff;
}
/* icon-only variant — square button */
.tb-action-btn.tb-action-icon {
  width: 30px;
  padding: 0;
  justify-content: center;
  font-size: 14px;
}
.tb-action-btn:hover { background: var(--c-stripe); border-color: rgba(99,102,241,.3); }
body.dark .tb-action-btn { background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.1); color: #e2e8f0; }
body.dark .tb-action-btn:hover { background: rgba(255,255,255,.09); }

/* User chip — shows logged-in user name */
.tb-user-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px 0 8px;
  height: 30px;
  background: rgba(99,102,241,.07);
  border: 1.5px solid rgba(99,102,241,.18);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  color: #4338ca;
  flex-shrink: 0;
  white-space: nowrap;
  max-width: 160px;
}
body.dark .tb-user-chip {
  background: rgba(99,102,241,.18);
  border-color: rgba(99,102,241,.35);
  color: #a5b4fc;
}
.tb-user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 90px;
}
.tb-logout-link {
  color: rgba(99,102,241,.5);
  text-decoration: none;
  font-size: 14px;
  border-left: 1px solid rgba(99,102,241,.2);
  padding-left: 6px;
  margin-left: 2px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color .15s;
}
.tb-logout-link:hover { color: #ef4444; }
body.dark .tb-logout-link { border-left-color: rgba(99,102,241,.3); color: rgba(165,180,252,.5); }

/* ── MAIN CONTENT ── */
.cw-main {
  margin-left: var(--sb-width);
  margin-top: var(--tb-height);
  min-height: calc(100vh - var(--tb-height));
  background: var(--c-bg);
  transition: margin-left .22s cubic-bezier(.4,0,.2,1);
  overflow-x: clip;
  display: flex;
  flex-direction: column;
}
.cw-push { flex: 1 0 0; }
.cw-sidebar.collapsed ~ .cw-topbar ~ .cw-main { margin-left: var(--sb-width-collapsed); }

/* ── Criteria info bar (two-row layout) ── */
.cw-criteria-bar {
  display: flex;
  flex-direction: column;
  background: var(--c-card);
  border-bottom: 2px solid var(--c-border);
}
.crit-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 24px;
  font-size: 13px;
  color: var(--c-text);
}
.crit-row + .crit-row {
  border-top: 1px solid var(--c-border);
  background: rgba(16,185,129,.025);
}
.kpi-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 4px 13px;
  border-radius: 20px;
  letter-spacing: .5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.kpi-badge-moph { background: #0f3460; color: #fff; }
.kpi-badge-ssj  { background: linear-gradient(135deg,#10b981,#f59e0b); color: #fff; }
.crit-items {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  flex: 1;
}
.cw-crit-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cw-crit-item > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cw-crit-dot   { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.crit-label    { font-size: 13px; font-weight: 700; color: var(--c-text); line-height: 1.2; }
.crit-formula  { font-size: 11px; color: var(--c-light); line-height: 1.2; }
.crit-divider  { width: 1px; height: 32px; background: var(--c-border); flex-shrink: 0; }
/* Step number badge */
.crit-step-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #e5e7eb;
  color: #6b7280;
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
/* Cascade flow pill */
.crit-cascade {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(59,130,246,.06);
  border: 1px solid rgba(59,130,246,.18);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 11.5px;
  white-space: nowrap;
}
.crit-cascade-lbl  { color: var(--c-text); font-weight: 600; }
.crit-cascade-arr  { color: var(--c-light); font-size: 14px; }
.crit-cascade-pct  { font-weight: 800; font-size: 12px; padding: 1px 6px; border-radius: 4px; }
.crit-cascade-pct.p1 { background: rgba(59,130,246,.15); color: #1d4ed8; }
.crit-cascade-pct.p2 { background: rgba(16,185,129,.15); color: #059669; }
.crit-cascade-pct.p3 { background: rgba(139,92,246,.15); color: #7c3aed; }
/* Date badge */
.cw-date-badge {
  padding: 4px 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #1d4ed8;
  white-space: nowrap;
}
.cw-crit-val { font-weight: 700; color: var(--c-text); }

/* KPI strip inside cw-main */
.cw-main .cf-kpi-strip {
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 14px;
  padding: 12px 24px 20px;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  border-bottom: 1px solid var(--c-border);
}
.cw-main .cf-kpi-section-bar { padding: 12px 24px 0; }

/* ── Hospital Grid Summary KPI Cards ── */
.hg-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.hg-kpi-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hg-kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.hg-kpi-lbl {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hg-kpi-val {
  font-size: 16px;
  font-weight: 900;
  white-space: nowrap;
  flex-shrink: 0;
}
.hg-kpi-bar-track {
  height: 6px;
  background: var(--c-stripe);
  border-radius: 4px;
  overflow: hidden;
}
.hg-kpi-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .4s ease;
  width: 0%;
}
.hg-kpi-sub {
  font-size: 10px;
  color: var(--c-muted);
  font-weight: 500;
}
/* Dark mode */
body.dark .hg-kpi-card { background: #1e2535; border-color: #2d3a4f; }
/* Responsive */
@media (max-width: 900px) { .hg-kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .hg-kpi-grid { grid-template-columns: 1fr; } }

/* ── Hospital Detail Panel KPIs ── */
.hosp-detail-kpi {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 8px 16px;
  min-width: 100px;
}
.hdk-val {
  font-size: 20px;
  font-weight: 900;
  color: var(--c-text);
  line-height: 1;
}
.hdk-lbl {
  font-size: 10px;
  color: var(--c-muted);
  font-weight: 600;
  white-space: nowrap;
}

/* ── KPI SSJ Criteria Panel ── */
.ssj-crit-panel {
  background: linear-gradient(135deg, rgba(16,185,129,.07), rgba(245,158,11,.05));
  border-top: 3px solid #10b981;
  border-bottom: 2px solid rgba(16,185,129,.2);
}
.ssj-crit-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 24px 10px;
  border-bottom: 1px dashed rgba(16,185,129,.3);
}
.ssj-crit-steps {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 14px 24px 16px;
  flex-wrap: wrap;
}
.ssj-crit-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: 12px 16px;
  flex: 1;
  min-width: 180px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.ssj-step-num {
  width: 26px; height: 26px;
  border-radius: 50%;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ssj-step-body { display: flex; flex-direction: column; gap: 2px; }
.ssj-step-title { font-size: 13px; font-weight: 700; color: var(--c-text); }
.ssj-step-formula { font-size: 11px; color: var(--c-muted); margin-top: 2px; }
.ssj-step-threshold { font-size: 15px; font-weight: 900; margin-top: 4px; }
.ssj-step-arrow {
  font-size: 20px;
  color: #d1d5db;
  padding: 0 10px;
  align-self: center;
  flex-shrink: 0;
}
/* Dark mode */
body.dark .ssj-crit-panel { background: linear-gradient(135deg,rgba(16,185,129,.1),rgba(245,158,11,.06)); }
body.dark .ssj-crit-step  { background: #1e2535; border-color: #2d3a4f; }
body.dark .ssj-step-title { color: #e2e8f0; }
body.dark .ssj-step-formula { color: #94a3b8; }
body.dark .ssj-crit-header { border-color: rgba(16,185,129,.25); }
/* Responsive */
@media (max-width: 900px) {
  .ssj-crit-header { padding: 10px 16px 8px; }
  .ssj-crit-steps  { padding: 12px 16px 14px; gap: 8px; }
  .ssj-step-arrow  { display: none; }
  .ssj-crit-step   { flex: 1 1 calc(33% - 8px); }
}
@media (max-width: 600px) {
  .ssj-crit-step   { flex: 1 1 100%; }
  .ssj-crit-header .crit-cascade { display: none; }
}

/* Inner content wrapper */
.cw-content {
  padding: 0 24px 24px;
  width: 100%;
  box-sizing: border-box;
}

/* ── Main section grids (responsive) ── */
#secTopClinic {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  margin-top: 20px;
}
#secHospGrid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  margin-top: 20px;
}
@media (max-width: 1100px) {
  #secTopClinic  { grid-template-columns: 1fr 280px; }
  #secHospGrid   { grid-template-columns: 260px 1fr; }
}
@media (max-width: 900px) {
  #secTopClinic  { grid-template-columns: 1fr; }
  #secHospGrid   { grid-template-columns: 1fr; }
  .cw-content    { padding: 0 16px 20px; }
  .cw-main .cf-kpi-strip { padding: 10px 16px 16px; }
  .cw-main .cf-kpi-section-bar { padding: 10px 16px 0; }
}
@media (max-width: 600px) {
  .cw-content { padding: 0 10px 16px; }
  .hosp-status-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 12px; }
  .crit-row { padding: 8px 12px; font-size: 12px; }
}
@media (max-width: 480px) {
  .cw-content { padding: 0 8px 12px; }
  #secTopClinic, #secHospGrid { gap: 12px; }
  .hosp-status-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 10px; }
}

/* Footer */
.cw-footer {
  text-align: center;
  padding: 16px 24px;
  color: var(--c-muted);
  font-size: 11px;
  border-top: 1px solid var(--c-border);
  margin-top: 8px;
}

/* ── Section show/hide navigation ── */
.sec-hidden { display: none !important; }

/* ══ HOME / DASHBOARD LANDING PAGE ══════════════════════════ */

/* ── Animations ── */
@keyframes homeHeroIn {
  from { opacity:0; transform:translateY(36px) scale(.96); }
  to   { opacity:1; transform:translateY(0)    scale(1);   }
}
@keyframes homeCardIn {
  from { opacity:0; transform:translateY(28px); }
  to   { opacity:1; transform:translateY(0);    }
}
@keyframes homeStatIn {
  from { opacity:0; transform:scale(.75); }
  to   { opacity:1; transform:scale(1);   }
}
@keyframes homeBadgePulse {
  0%,100% { box-shadow:0 0 0 0 rgba(255,255,255,.35); }
  50%     { box-shadow:0 0 0 8px rgba(255,255,255,0);  }
}
@keyframes homeFloat {
  0%,100% { transform:translateY(0);    }
  50%     { transform:translateY(-8px); }
}
@keyframes homeOrb {
  0%,100% { transform:scale(1)   rotate(0deg); }
  50%     { transform:scale(1.1) rotate(10deg); }
}
@keyframes homeStripIn {
  from { opacity:0; transform:translateY(16px); }
  to   { opacity:1; transform:translateY(0); }
}

.home-section {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: clamp(20px, 2.5vw, 36px) clamp(20px, 3vw, 40px) 36px;
  max-width: min(100%, 1240px);
  margin: 0 auto;
  width: 100%;
}

/* ── Hero Pill Card ── */
.home-hero {
  text-align: center;
  margin-bottom: 16px;
  animation: homeHeroIn .75s cubic-bezier(.16,1,.3,1) both;
}
.home-hero-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #4f46e5 0%, #6d28d9 45%, #2563eb 100%);
  border-radius: 28px;
  padding: 36px 40px 32px;
  box-shadow: 0 24px 64px rgba(79,70,229,.28), 0 4px 16px rgba(0,0,0,.1);
}
/* Decorative orbs */
.home-hero-card::before {
  content:'';
  position:absolute; top:-70px; right:-70px;
  width:220px; height:220px; border-radius:50%;
  background:rgba(255,255,255,.09);
  animation: homeOrb 8s ease-in-out infinite;
  pointer-events:none;
}
.home-hero-card::after {
  content:'';
  position:absolute; bottom:-90px; left:-50px;
  width:280px; height:280px; border-radius:50%;
  background:rgba(255,255,255,.06);
  animation: homeOrb 12s ease-in-out infinite reverse;
  pointer-events:none;
}
.home-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 18px;
  border-radius: 99px;
  background: rgba(255,255,255,.18);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 20px;
  border: 1px solid rgba(255,255,255,.3);
  backdrop-filter: blur(8px);
  animation: homeBadgePulse 3s ease-in-out infinite;
  position: relative; z-index:1;
}
.home-hero-title {
  font-size: clamp(30px, 4.5vw, 48px);
  font-weight: 900;
  color: #fff;
  line-height: 1.12;
  margin-bottom: 12px;
  text-shadow: 0 2px 16px rgba(0,0,0,.15);
  position: relative; z-index:1;
  animation: homeFloat 6s ease-in-out infinite;
}
.home-hero-sub {
  font-size: clamp(13px, 1.4vw, 16px);
  color: rgba(255,255,255,.8);
  font-weight: 400;
  position: relative; z-index:1;
}
/* Stats strip inside hero */
.home-hero-stats {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-top: clamp(20px, 3vw, 36px);
  position: relative; z-index:1;
  background: rgba(0,0,0,.15);
  border-radius: 16px;
  padding: clamp(12px, 1.5vw, 18px) 8px;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.12);
}
.home-hero-stat {
  flex: 1;
  text-align: center;
  padding: 0 clamp(12px, 2vw, 24px);
  animation: homeStatIn .6s cubic-bezier(.16,1,.3,1) both;
}
.home-hero-stat + .home-hero-stat {
  border-left: 1px solid rgba(255,255,255,.15);
}
.home-hero-stat-val {
  font-size: clamp(20px, 2.4vw, 32px);
  font-weight: 900;
  color: #fff;
  line-height: 1;
  letter-spacing: -.5px;
}
.home-hero-stat-lbl {
  font-size: clamp(10px, 1vw, 13px);
  color: rgba(255,255,255,.65);
  margin-top: 4px;
  font-weight: 600;
  letter-spacing: .3px;
  white-space: nowrap;
}
.home-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(12px, 1.6vw, 20px);
}
@media (max-width: 1100px) {
  .home-cards { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .home-cards { grid-template-columns: 1fr; }
  .home-section { padding: 18px 16px 24px; }
  .home-hero { margin-bottom: 12px; }
  .home-hero-card { padding: 24px 18px 20px; border-radius: 20px; }
  .home-hero-stats { gap: 0; }
  .home-hero-stat { padding: 0 10px; }
  .hc-title { white-space: normal; }
}
.home-card {
  position: relative;
  border-radius: 20px;
  padding: 0;
  cursor: pointer;
  transition: transform .22s cubic-bezier(.16,1,.3,1), box-shadow .22s;
  border: 1.5px solid transparent;
  overflow: hidden;
  text-decoration: none;
  display: grid;
  grid-template-columns: clamp(64px, 7vw, 88px) 1fr;
  grid-template-rows: auto auto auto;
  animation: homeCardIn .65s cubic-bezier(.16,1,.3,1) both;
}
.home-card:nth-child(1) { animation-delay: .12s; }
.home-card:nth-child(2) { animation-delay: .22s; }
.home-card:nth-child(3) { animation-delay: .32s; }
.home-card:hover {
  transform: translateY(-6px) scale(1.01);
  box-shadow: 0 24px 56px rgba(0,0,0,.14);
  text-decoration: none;
}
.home-card.hc-moph {
  background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 60%, #c7d2fe 100%);
  border-color: #a5b4fc;
}
.home-card.hc-tele {
  background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 60%, #7dd3fc 100%);
  border-color: #38bdf8;
}
.home-card.hc-ssj {
  background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 60%, #a7f3d0 100%);
  border-color: #6ee7b7;
}
.hc-icon-wrap {
  grid-column: 1;
  grid-row: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(24px, 2.8vw, 34px);
  padding: 20px 0;
}
.hc-moph .hc-icon-wrap {
  background: linear-gradient(160deg, #4f46e5, #7c3aed);
  color: #fff;
}
.hc-tele .hc-icon-wrap {
  background: linear-gradient(160deg, #0284c7, #0ea5e9);
  color: #fff;
}
.hc-ssj .hc-icon-wrap {
  background: linear-gradient(160deg, #059669, #0d9488);
  color: #fff;
}
.hc-body {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  padding: clamp(16px, 1.8vw, 22px) clamp(16px, 2vw, 24px) 8px;
}
.hc-title {
  font-size: clamp(16px, 1.5vw, 21px);
  font-weight: 900;
  margin-bottom: 6px;
  line-height: 1.2;
  white-space: nowrap;
}
.hc-moph .hc-title { color: #3730a3; }
.hc-tele .hc-title { color: #075985; }
.hc-ssj  .hc-title { color: #065f46; }
.hc-desc {
  font-size: clamp(12px, 1.1vw, 13.5px);
  line-height: 1.6;
  opacity: .82;
}
.hc-moph .hc-desc { color: #3730a3; }
.hc-tele .hc-desc { color: #075985; }
.hc-ssj  .hc-desc { color: #065f46; }
.hc-footer {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 8px clamp(16px, 2vw, 24px) clamp(14px, 1.6vw, 20px);
  gap: 10px;
}
.hc-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.hc-tag {
  padding: 3px 10px;
  border-radius: 99px;
  font-size: clamp(10.5px, 0.95vw, 12px);
  font-weight: 700;
  white-space: nowrap;
}
.hc-moph .hc-tag { background: rgba(79,70,229,.12);  color: #4338ca; }
.hc-tele .hc-tag { background: rgba(2,132,199,.12);  color: #0369a1; }
.hc-ssj  .hc-tag { background: rgba(5,150,105,.12);  color: #065f46; }
.hc-arrow {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  transition: transform .15s;
}
.hc-moph .hc-arrow { background: #4f46e5; color: #fff; }
.hc-tele .hc-arrow { background: #0284c7; color: #fff; }
.hc-ssj  .hc-arrow { background: #059669; color: #fff; }
.home-card:hover .hc-arrow { transform: translateX(4px); }

/* ════ HOME CARD SHINE (white film glint, top-left → bottom-right) ════ */
@keyframes homeCardShine {
  0%   { transform: translateX(-130%) skewX(-18deg); opacity: 0; }
  5%   { opacity: 1; }
  22%  { transform: translateX(230%) skewX(-18deg); opacity: 0; }
  100% { transform: translateX(230%) skewX(-18deg); opacity: 0; }
}
.home-card { overflow: hidden; }
.home-card::before {
  content: '';
  position: absolute; top: -10%; left: 0;
  width: 45%; height: 120%;
  background: linear-gradient(105deg, transparent 15%, rgba(255,255,255,.42) 50%, transparent 85%);
  animation: homeCardShine 4s ease-in-out infinite;
  pointer-events: none; z-index: 2;
}
.home-card:nth-child(1)::before { animation-delay: .6s; }
.home-card:nth-child(2)::before { animation-delay: 1.1s; }
.home-card:nth-child(3)::before { animation-delay: 1.6s; }
.hc-shine {
  position: absolute; top: -10%; left: 0;
  width: 45%; height: 120%;
  background: linear-gradient(105deg, transparent 15%, rgba(255,255,255,.22) 50%, transparent 85%);
  animation: homeCardShine 4s ease-in-out 0s infinite;
  pointer-events: none; z-index: 2;
}
body.dark .home-card::before {
  background: linear-gradient(105deg, transparent 15%, rgba(255,255,255,.18) 50%, transparent 85%);
}
body.dark .hc-shine {
  background: linear-gradient(105deg, transparent 15%, rgba(255,255,255,.14) 50%, transparent 85%);
}

/* ── Sidebar: Home item (standalone, not in group) ── */
.sb-home-item {
  margin: 4px 6px 8px;
  border-radius: 10px;
}
/* ── Topbar filter hide on home page ── */
.home-active-filters { display: none !important; }
/* ── Dark mode ── */
body.dark .home-card.hc-moph {
  background: linear-gradient(135deg, rgba(79,70,229,.15), rgba(99,102,241,.1));
  border-color: rgba(165,180,252,.3);
}
body.dark .home-card.hc-tele {
  background: linear-gradient(135deg, rgba(2,132,199,.15), rgba(14,165,233,.1));
  border-color: rgba(125,211,252,.3);
}
body.dark .home-card.hc-ssj {
  background: linear-gradient(135deg, rgba(5,150,105,.15), rgba(13,148,136,.1));
  border-color: rgba(110,231,183,.3);
}
body.dark .hc-moph .hc-title,
body.dark .hc-moph .hc-desc { color: #a5b4fc; }
body.dark .hc-tele .hc-title,
body.dark .hc-tele .hc-desc { color: #7dd3fc; }
body.dark .hc-ssj  .hc-title,
body.dark .hc-ssj  .hc-desc { color: #6ee7b7; }
body.dark .home-hero-title { color: var(--c-text-dark, #f1f5f9); }
body.dark .home-hero-badge { background: rgba(79,70,229,.2); border-color: rgba(165,180,252,.3); }

/* ── DARK MODE for new layout ── */
body.dark .cw-sidebar {
  background: #1e2535;
  border-color: #2d3a4f;
}
body.dark .sb-brand-name,
body.dark .sb-item:hover,
body.dark .tb-page-title { color: #e2e8f0; }
body.dark .sb-item.active { background: #1e1b4b; color: #a5b4fc; }
body.dark .sb-item.active .sb-item-sub { color: #818cf8; }
body.dark .sb-collapse-btn { background: #1e2535; border-color: #2d3a4f; }
body.dark .sb-collapse-btn:hover { background: #253047; color: #e2e8f0; }
body.dark .cw-topbar {
  background: #1e2535;
  border-color: #2d3a4f;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
body.dark .tb-page-info {
  border-right-color: #2d3a4f;
}
body.dark .tb-select,
body.dark .tb-date-wrap,
body.dark .tb-daterange-wrap {
  background: #253047;
  border-color: #2d3a4f;
  color: #e2e8f0;
}
body.dark .tb-date-input,
body.dark .tb-action-btn,
body.dark .tb-user-chip {
  background: #253047;
  border-color: #2d3a4f;
  color: #e2e8f0;
}
body.dark .tb-theme-group { border-color: #2d3a4f !important; background: #253047 !important; }
body.dark .tb-theme-btn {
  background: transparent;
  border-color: #2d3a4f;
  color: #94a3b8;
}
body.dark .tb-theme-btn:hover { background: #2d3a4f; color: #e2e8f0; }
body.dark .tb-theme-btn.active { background: #1e1b4b; color: #a5b4fc; }
/* dark criteria-bar — defined below */

/* ── FLOATING NAV BUTTONS (Go to Top / Bottom) ── */
.cw-float-nav {
  position: fixed;
  right: 20px;
  bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1500;
}
.cw-float-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--c-card);
  color: var(--c-text);
  box-shadow: 0 2px 12px rgba(0,0,0,.14);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  opacity: 0.3;
  transition: background .15s, transform .15s, opacity .3s, box-shadow .15s;
}
.cw-float-btn:hover {
  background: #1d4ed8;
  color: #fff;
  transform: scale(1.12);
  box-shadow: 0 4px 18px rgba(29,78,216,.35);
  opacity: 1 !important;
}
body.dark .cw-float-btn {
  background: #253047;
  color: #e2e8f0;
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
}
body.dark .cw-float-btn:hover {
  background: #1d4ed8;
  color: #fff;
}

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  :root { --sb-width: 200px; }
}
@media (max-width: 700px) {
  .cw-sidebar   { width: var(--sb-width-collapsed); }
  .cw-topbar    { left: var(--sb-width-collapsed); }
  .cw-main      { margin-left: var(--sb-width-collapsed); }
  .cw-main .cf-kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .cw-float-nav { right: 12px; bottom: 16px; }
}

/* =========================================================
   HOSPITAL FILTER BANNER
   ========================================================= */
.hosp-filter-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  background: linear-gradient(135deg, #1d4ed8, #0891b2);
  border-bottom: 2px solid rgba(255,255,255,.15);
  flex-wrap: wrap;
}
.hosp-filter-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.6);
  flex-shrink: 0;
}
.hosp-filter-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}
.hosp-filter-label {
  font-size: 10px;
  font-weight: 700;
  color: rgba(255,255,255,.7);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.hosp-filter-name {
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hosp-filter-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.hosp-filter-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.hosp-filter-stat-val {
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  color: #fff !important;
  text-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.hosp-filter-stat-lbl {
  font-size: 9px;
  color: rgba(255,255,255,.85);
  font-weight: 600;
  white-space: nowrap;
}
.hosp-filter-stat {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px;
  padding: 5px 12px;
  align-items: center;
  gap: 2px;
  backdrop-filter: blur(4px);
}
.hosp-filter-clear {
  padding: 6px 14px;
  background: rgba(255,255,255,.15);
  color: #fff;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  transition: background .15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
}
.hosp-filter-clear:hover {
  background: rgba(255,255,255,.28);
  color: #fff;
}

/* =========================================================
   TOP CLINICS ROW
   ========================================================= */
.top-clinic-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  transition: box-shadow .15s, transform .15s;
}
.top-clinic-row:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
  transform: translateY(-1px);
}
.top-clinic-rank {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  color: #fff;
  flex-shrink: 0;
}
.top-clinic-info {
  flex: 1;
  min-width: 0;
}
.top-clinic-count {
  text-align: right;
  flex-shrink: 0;
}

/* dark mode adjustments */
body.dark .top-clinic-row {
  background: var(--c-card);
}
body.dark .hosp-filter-banner {
  background: linear-gradient(135deg, #1e40af, #0e7490);
}

/* ============================================================
   DARK MODE — Main Content (cw-main layout)
   ============================================================ */

/* Body & main area background */
body.dark { background: var(--c-bg); }
body.dark .cw-main { background: var(--c-bg); }
body.dark .cw-content { background: transparent; }
body.dark .cw-footer  { border-color: var(--c-border); color: var(--c-muted); }

/* Sections and cards */
body.dark .cf-section  { background: var(--c-card); box-shadow: 0 2px 8px rgba(0,0,0,.25); }
body.dark .cf-section-head { border-color: var(--c-border); }
body.dark .cf-section-title { color: var(--c-text); }
body.dark .cf-section-sub   { color: var(--c-muted); }

/* Hospital grid cards */
body.dark .hosp-card         { background: var(--c-card) !important; border-color: var(--c-border) !important; }
body.dark .hosp-card:hover   { background: var(--c-stripe) !important; }
body.dark .hosp-name         { color: var(--c-text); }
body.dark .hosp-district     { color: var(--c-muted); }
body.dark .hosp-stat-val     { color: var(--c-text); }
body.dark .hosp-stat-lbl     { color: var(--c-muted); }

/* Rank/summary table */
body.dark .rank-table        { background: var(--c-card); }
body.dark .rank-table thead tr th { background: var(--c-stripe) !important; color: var(--c-text); border-color: var(--c-border); }
body.dark .rank-table tbody tr td { border-color: var(--c-border); color: var(--c-text); }
body.dark .rank-table tbody tr:hover td { background: var(--c-stripe); }
body.dark .table-responsive  { background: var(--c-card); }

/* Form selects */
body.dark .form-select       { background: var(--c-stripe); border-color: var(--c-border); color: var(--c-text); }

/* Chart pane */
body.dark .chart-pane        { background: transparent; }
body.dark .cf-tabs           { background: rgba(255,255,255,.06); }
body.dark .cf-tab            { color: var(--c-muted); }
body.dark .cf-tab.active     { background: rgba(255,255,255,.12); color: var(--c-text); }
body.dark .cf-filter-bar     { background: rgba(255,255,255,.04); }

/* Heatmap */
body.dark .hm-table          { background: transparent; }
body.dark .hm-hosp-label     { color: var(--c-text); background: var(--c-card); border-color: var(--c-border); }
body.dark .hm-date-label     { color: var(--c-muted); }
body.dark .hm-pass           { background: rgba(16,185,129,.45); }
body.dark .hm-fail           { background: rgba(239,68,68,.45); }
body.dark .hm-nosend         { background: #2d3748; }
body.dark .hm-weekend        { background: #1a2234; border-color: #2d3748; }

/* Map */
body.dark .map-filter-bar    { background: var(--c-card); border-color: var(--c-border); }
body.dark .map-filter-select,
body.dark .map-filter-input  { background: var(--c-stripe); border-color: var(--c-border); color: var(--c-text); }
body.dark .map-legend        { background: rgba(30,37,53,.95); border-color: var(--c-border); color: var(--c-text); }
body.dark .map-popup-title   { color: var(--c-text); }
/* Dark mode: map control panel */
body.dark .map-ctrl-panel    { background: #111827; border-color: #1e2d3d; }
body.dark .map-ctrl-title    { color: #f1f5f9; }
body.dark .map-ctrl-sub      { color: #64748b; }
body.dark .map-ctrl-filter-row { border-color: #1e2d3d; }
body.dark .map-info-chip     { color: #94a3b8; }
body.dark .map-legend-ssj-chip { background: rgba(30,45,61,.8); border-color: rgba(51,65,85,.8); }
body.dark .map-legend-title  { color: #94a3b8; }
body.dark .map-legend-chip-detail { background: rgba(30,45,61,.8); }
body.dark .map-legend-chip-desc   { color: #64748b; }
body.dark .map-tab           { background: #1e2d3d; border-color: #2d3a4f; color: #94a3b8; }
body.dark .map-tab:hover     { border-color: #3b82f6; color: #93c5fd; background: #172038; }
body.dark .map-tab.active    { background: #f59e0b; border-color: #f59e0b; color: #fff; }
body.dark .map-tab-divider   { background: #2d3a4f; }
body.dark .map-ctrl-icon-btn { background: #1e2d3d; border-color: #2d3a4f; color: #94a3b8; }
body.dark .map-ctrl-icon-btn:hover { background: #2d3a4f; }
body.dark .map-filter-sel    { background: #1e2d3d; border-color: #2d3a4f; color: #e2e8f0; }
body.dark .map-layout-left    { border-color: #1e2d3d; box-shadow: 0 2px 16px rgba(0,0,0,.3); }
body.dark .map-layout-right   { background: #111827; border-color: #1e2d3d; box-shadow: 0 2px 16px rgba(0,0,0,.3); }
body.dark .map-rpanel-header  { background: #111827; border-color: #1e2d3d; }
body.dark .map-rpanel-header-title { color: #f1f5f9; }
body.dark .map-rpanel-header-badge { color: #94a3b8; }
body.dark .map-rpanel-tabs    { background: #111827; border-color: #1e2d3d; }
body.dark .map-rpanel-tab     { background: #1e2d3d; border-color: #2d3a4f; color: #64748b; }
body.dark .map-rpanel-tab:hover { background: #172038; border-color: #3b82f6; color: #93c5fd; }
body.dark .map-rpanel-tab.active { background: #f59e0b; border-color: #f59e0b; color: #1e293b; }
body.dark .map-rpanel-pane-head { background: #0f1623; border-color: #1e2d3d; }
body.dark .map-rpanel-stat-pill { background: #1e2d3d; box-shadow: none; }
body.dark .map-rpanel-subtabs  { background: #0f1623; border-color: #1e2d3d; }
body.dark .map-rpanel-subtab   { background: #1e2d3d; border-color: #2d3a4f; color: #64748b; }
body.dark .map-rpanel-subtab:hover { background: #172038; border-color: #3b82f6; color: #93c5fd; }
body.dark .map-rpanel-subtab.active { background: #172038; border-color: #3b82f6; color: #93c5fd; }
body.dark .map-rpanel-item    { background: #1a2234; border-color: #1e2d3d; }
body.dark .map-rpanel-item:hover { border-color: #3b82f6; background: #1e2840; }
body.dark .map-rpanel-name    { color: #e2e8f0; }
body.dark .map-rpanel-sub     { color: #64748b; }
body.dark .map-rpanel-rank    { background: #1e2d3d; border-color: #2d3a4f; color: #94a3b8; }
body.dark .map-rpanel-dist    { background: #1e2d3d; border-color: #2d3a4f; color: #64748b; }
body.dark .map-rpanel-bar-track { background: #2d3a4f; }

/* Sidebar group headers */
body.dark .sb-group-header   { color: var(--c-muted); }
body.dark .sb-group-header:hover { background: var(--c-stripe); }
body.dark .sb-item           { color: var(--c-muted); }
body.dark .sb-item:hover     { background: var(--c-stripe); color: var(--c-text); }
body.dark .sb-footer-label,
body.dark .sb-footer-date    { color: var(--c-muted); }
body.dark .sb-footer-user-row { background: rgba(3,105,161,.15); }
body.dark .sb-footer-user-icon { color: #38bdf8; }
body.dark .sb-footer-username  { color: #e2e8f0; }
body.dark .sb-ftr-icon-btn     { background: rgba(255,255,255,.07); color: #94a3b8; }
body.dark .sb-ftr-icon-btn:hover { background: rgba(56,189,248,.18); color: #38bdf8; }
body.dark .sb-footer-theme-row { background: rgba(255,255,255,.05); border-color: #2d3a4f; }
body.dark .sb-theme-btn        { color: #94a3b8; border-right-color: #2d3a4f; }
body.dark .sb-theme-btn:hover  { background: rgba(255,255,255,.08); color: #e2e8f0; }
body.dark .sb-theme-btn.active { background: #1e40af; color: #bfdbfe; }

/* Inline bars and chips */
body.dark .inline-bar-track  { background: rgba(255,255,255,.1); }
body.dark .hosp-rate-bar     { background: rgba(255,255,255,.08); }

/* KPI strip inside main */
body.dark .cw-main .cf-kpi-strip { border-color: var(--c-border); }

/* ============================================================
   CARDIFF MODEL v4.0 — UI Enhancement (2025)
   แก้ขนาดข้อความ · card · progress · graph · badge
   แยก KPI MOPH / KPI SSJ ให้เห็นเด่นชัด
   ============================================================ */

/* ──────────────────────────────────────────────────────────
   BASE TYPOGRAPHY — ปรับขนาดฟอนต์ทั่วโปรเจค
   ────────────────────────────────────────────────────────── */
html, body {
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ──────────────────────────────────────────────────────────
   SIDEBAR v5 — Cardiff-style: white, large text, indigo active
   ────────────────────────────────────────────────────────── */
.cw-sidebar {
  background: #fff;
  border-right: 1px solid #e8ecf0;
  box-shadow: 2px 0 16px rgba(0,0,0,.07);
}
.sb-brand {
  padding: 18px 16px 16px;
  background: #fff;
  border-bottom: 1px solid #e8ecf0;
}
.sb-logo-icon {
  font-size: 22px;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sb-brand-name {
  font-size: 14.5px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -.1px;
}
.sb-brand-sub {
  font-size: 11px;
  color: #9ca3af;
}
.sb-collapse-btn {
  width: calc(100% - 20px);
  margin: 8px 10px;
  padding: 9px 12px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  font-size: 12px;
}
.sb-collapse-btn:hover { background: #eef2ff; color: #4338ca; }
.sb-collapse-text span { font-size: 12.5px; font-weight: 600; color: #374151; }
.sb-collapse-text small { font-size: 10px; color: #9ca3af; }
.sb-item {
  padding: 10px 14px;
  margin: 2px 10px;
  border-radius: 9px;
  color: #4b5563;
}
.sb-item i {
  font-size: 18px;
  color: #6b7280;
}
.sb-item:hover {
  background: #f1f5f9;
  color: #1e293b;
}
.sb-item:hover i { color: #4338ca; }
.sb-item.active {
  background: #eef2ff;
  color: #4338ca;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(67,56,202,.10);
}
.sb-item.active i { color: #4338ca; }
.sb-item-title { font-size: 14px; font-weight: 500; }
.sb-item.active .sb-item-title { font-weight: 700; }
.sb-item-sub   { font-size: 11px; color: #9ca3af; }
.sb-item.active .sb-item-sub { color: #818cf8; }
.sb-footer {
  background: #f8fafc;
  border-top: 1px solid #e8ecf0;
  padding: 10px 14px;
}
.sb-footer-label { font-size: 9px; color: #9ca3af; font-weight: 700; letter-spacing: .06em; }
.sb-footer-date  { font-size: 11px; color: #374151; font-weight: 600; }

/* ──────────────────────────────────────────────────────────
   TOPBAR v5 — pill-style controls, Cardiff reference
   ────────────────────────────────────────────────────────── */
.cw-topbar {
  background: var(--c-card);
  border-bottom: 2px solid var(--c-border);
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  padding: 0 24px;
  gap: 12px;
  border-radius: 0;
}
body.dark .cw-topbar {
  background: var(--c-card);
  border-bottom-color: var(--c-border);
  box-shadow: 0 2px 12px rgba(0,0,0,.28);
}
.tb-page-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--c-text);
  letter-spacing: -.2px;
  line-height: 1.2;
}
body.dark .tb-page-title { color: #e2e8f0; }
.tb-page-sub {
  font-size: 11px;
  color: var(--c-muted);
  margin-top: 3px;
}

/* ─ Hospital select as pill ─ */
.tb-select {
  height: 32px;
  padding: 0 28px 0 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  border-radius: 20px;
  border: 1.5px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-text);
  cursor: pointer;
  max-width: 180px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  flex-shrink: 0;
}
body.dark .tb-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239ca3af'/%3E%3C/svg%3E"); }
.tb-select:focus { outline: none; border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.tb-select-active {
  border-color: #6366f1 !important;
  background-color: #eef2ff !important;
  color: #4338ca !important;
  font-weight: 700 !important;
}
body.dark .tb-select-active { background-color: rgba(99,102,241,.18) !important; color: #a5b4fc !important; }

/* ─ Date picker as pill ─ */
.tb-date-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border: 1.5px solid var(--c-border);
  border-radius: 20px;
  background: var(--c-card);
  color: var(--c-light);
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s;
}
.tb-date-wrap:focus-within { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.tb-date-input {
  border: none;
  outline: none;
  background: transparent;
  color: var(--c-text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  width: 118px;
}

/* ─ Theme group as pill tabs (icon-only) ─ */
.tb-theme-group {
  display: flex;
  border: 1.5px solid var(--c-border);
  border-radius: 20px;
  overflow: hidden;
  background: var(--c-card);
  flex-shrink: 0;
}
body.dark .tb-theme-group { border-color: rgba(255,255,255,.12); background: rgba(255,255,255,.05); }
.tb-theme-btn {
  height: 30px;
  width: 30px;
  min-width: 30px;         /* prevent span text from forcing wider */
  padding: 0;
  border: none;
  border-right: 1px solid var(--c-border);
  background: transparent;
  color: var(--c-muted);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;        /* clip any text content */
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
body.dark .tb-theme-btn { border-right-color: rgba(255,255,255,.08); color: #9ca3af; }
.tb-theme-btn:last-child { border-right: none; }
.tb-theme-btn:hover { background: var(--c-stripe); color: var(--c-text); }
.tb-theme-btn.active {
  background: linear-gradient(135deg,#1d4ed8,#3b82f6);
  color: #fff;
  border-right-color: transparent;
}
body.dark .tb-theme-btn:hover { background: rgba(255,255,255,.08); color: #e2e8f0; }

/* ─ Filter mode button group (ทั้งหมด | รายวัน) ─ */
.tb-filter-group {
  display: flex;
  gap: 2px;
  background: rgba(99,102,241,.07);
  border: 1.5px solid rgba(99,102,241,.16);
  border-radius: 10px;       /* ขอบมนแบบเบา ไม่ใช่ pill */
  padding: 3px;
  flex-shrink: 0;
  box-shadow: inset 0 1px 2px rgba(99,102,241,.06);
}
.tb-filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 30px;
  padding: 0 13px;
  border-radius: 7px;        /* สี่เหลี่ยมแบน ไม่ใช่ pill กลม */
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  color: #6b7280;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  flex-shrink: 0;
  transition: background .18s, color .18s, box-shadow .18s;
}
.tb-filter-btn i { font-size: 12px; }
.tb-filter-btn:hover {
  background: rgba(99,102,241,.14);
  color: #4338ca;
}
.tb-filter-btn.tb-filter-active {
  background: linear-gradient(135deg,#6366f1 0%,#818cf8 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,.35), inset 0 1px 0 rgba(255,255,255,.2);
}
/* Reset button — standalone outside filter group */
.tb-reset-btn {
  background: rgba(239,68,68,.06) !important;
  border: 1.5px solid rgba(239,68,68,.18) !important;
  border-radius: 8px !important;
  color: #ef4444 !important;
  height: 30px !important;
  padding: 0 9px !important;
}
.tb-reset-btn:hover {
  background: rgba(239,68,68,.14) !important;
  color: #dc2626 !important;
  box-shadow: 0 2px 6px rgba(239,68,68,.2) !important;
}
body.dark .tb-filter-group {
  background: rgba(99,102,241,.12);
  border-color: rgba(99,102,241,.28);
  border-radius: 10px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.15);
}
body.dark .tb-filter-btn { color: #9ca3af; }
body.dark .tb-filter-btn:hover { background: rgba(99,102,241,.22); color: #a5b4fc; }
body.dark .tb-filter-btn.tb-filter-active {
  background: linear-gradient(135deg,#6366f1,#4f46e5);
  color: #fff;
}
body.dark .tb-reset-btn {
  background: rgba(239,68,68,.10) !important;
  border-color: rgba(239,68,68,.25) !important;
  color: #f87171 !important;
}
body.dark .tb-reset-btn:hover {
  background: rgba(239,68,68,.2) !important;
  color: #fca5a5 !important;
}

/* ─ Quarter dropdown menu ──────────────────────────────── */
/* ─ Generic animated dropdown (ปีงบ + ไตรมาส) ── */
.tb-dd-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
/* Caret arrow */
.tb-dd-caret {
  font-size: 9px !important;
  margin-left: 3px;
  transition: transform .2s ease;
  opacity: .7;
}
.tb-dd-wrap:has(.tb-dd-open) .tb-dd-caret { transform: rotate(180deg); }

/* Menu — hidden by default via display:none (bulletproof) */
.tb-dd-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 9999;
  flex-direction: column;
  gap: 2px;
  min-width: 210px;
  background: #fff;
  border: 1.5px solid rgba(99,102,241,.2);
  border-radius: 14px;
  box-shadow: 0 12px 36px rgba(0,0,0,.14), 0 2px 8px rgba(99,102,241,.1);
  padding: 7px;
  overflow: hidden;
}
/* Open = display:flex + slide-in animation */
.tb-dd-menu.tb-dd-open {
  display: flex;
  animation: tbDdIn .18s cubic-bezier(.16,1,.3,1) both;
}
@keyframes tbDdIn {
  from { opacity: 0; transform: translateY(-8px) scale(.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1);   }
}

/* Separator between groups */
.tb-dd-sep {
  height: 1px;
  background: rgba(99,102,241,.1);
  margin: 4px 6px;
}

/* Dropdown item */
.tb-dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: none;
  background: transparent;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s, transform .1s;
  text-align: left;
  width: 100%;
  line-height: 1.3;
}
.tb-dd-item:hover {
  background: rgba(99,102,241,.09);
  color: #4338ca;
  transform: translateX(2px);
}
.tb-dd-item.tb-dd-active {
  background: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
  color: #fff;
  font-weight: 700;
  transform: none;
}
.tb-dd-item .tb-dd-label { flex: 1; }
.tb-dd-sub {
  font-size: 11px;
  font-weight: 400;
  opacity: .65;
  white-space: nowrap;
  flex-shrink: 0;
}
.tb-dd-active .tb-dd-sub { opacity: .8; color: rgba(255,255,255,.85); }

/* Dark mode */
body.dark .tb-dd-menu {
  background: #1a1535;
  border-color: rgba(99,102,241,.3);
  box-shadow: 0 12px 36px rgba(0,0,0,.5);
}
body.dark .tb-dd-item { color: #c4b5fd; }
body.dark .tb-dd-item:hover { background: rgba(99,102,241,.18); color: #a5b4fc; }
body.dark .tb-dd-item.tb-dd-active {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
}

/* ─ Topbar responsive breakpoints ──────────────────────── */

/* 1400px: hide date badge — redundant with date range picker */
@media (max-width: 1400px) {
  .tb-date-badge  { display: none; }
}

/* 1350px: hide filter button text — icon-only saves ~100px */
@media (max-width: 1350px) {
  .tb-filter-txt  { display: none; }
  .tb-filter-btn:not(.tb-reset-btn) { padding: 0 9px; }
  .tb-reset-btn   { padding: 0 8px; }
}

/* 1200px: compact hospital select */
@media (max-width: 1200px) {
  .tb-select      { max-width: 150px; }
  .tb-user-name   { max-width: 80px; }
}

/* 1050px: hide subtitle */
@media (max-width: 1050px) {
  .tb-page-sub    { display: none; }
  .tb-select      { max-width: 130px; font-size: 12px; }
  .tb-user-name   { max-width: 70px; }
}

/* 900px: ───── 2-ROW LAYOUT ─────
   Row 1: page title (full width)
   Row 2: .tb-pinned-right takes full width (controls is hidden) */
@media (max-width: 900px) {
  :root { --tb-height: 112px; }
  .cw-topbar {
    height: auto;
    min-height: var(--tb-height);
    padding: 8px 14px;
    align-items: stretch;
    gap: 0;
  }
  .tb-header-card {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    height: auto;
    gap: 0;
    overflow: visible;
  }
  /* Row 1: title spans full width */
  .tb-page-info {
    flex: 0 0 100%;
    border-right: none;
    border-bottom: 1px solid var(--c-border);
    padding: 2px 0 7px;
    margin-right: 0;
    margin-bottom: 7px;
  }
  /* Row 2: pinned-right takes the full remaining row */
  .tb-pinned-right { flex: 1; flex-wrap: nowrap; overflow-x: auto; overflow-y: visible; gap: 4px; }
  .tb-page-title   { font-size: 14px; }
}

/* 768px: mobile — full-width layout + sidebar drawer */
@media (max-width: 768px) {
  :root { --tb-height: 104px; }

  /* Sidebar: off-screen drawer (full sidebar width) */
  .cw-sidebar {
    transform: translateX(-100%);
    z-index: 320;
    width: 260px !important;
    transition: transform .25s cubic-bezier(.4,0,.2,1), width 0s;
  }
  body.mobile-sidebar-open .cw-sidebar { transform: translateX(0); }

  /* Topbar & main: full viewport width */
  .cw-topbar { left: 0 !important; padding: 0 14px; }
  .cw-main   { margin-left: 0 !important; }

  /* Show hamburger */
  .tb-sb-toggle { display: flex; }

  /* 2-row layout inherited from ≤900px but with tighter height */
  .tb-page-info { padding-bottom: 6px; margin-bottom: 6px; }

  /* Hide non-essential labels */
  .tb-filter-txt { display: none; }
  .tb-user-name  { display: none; }
  .tb-date-badge { display: none; }
  .tb-theme-txt  { display: none; }

  /* Tighten the pinned-right zone */
  .tb-pinned-right { gap: 3px; padding-left: 6px; }
}

/* 600px: sidebar is off-screen → topbar has full width → revert to single row */
@media (max-width: 600px) {
  :root { --tb-height: 68px; }
  /* Single-row layout — date range hidden saves enough space */
  .tb-header-card {
    flex-wrap: nowrap;
    flex-direction: row;
    align-items: center;
  }
  .tb-page-info {
    flex: 0 0 auto;
    border-bottom: none;
    border-right: 1px solid var(--c-border);
    padding: 0 10px 0 0;
    margin-right: 8px;
    margin-bottom: 0;
  }
  .tb-daterange-wrap { display: none; }
  .tb-controls    { gap: 4px; }
  .tb-select      { max-width: 110px; height: 28px; font-size: 11px; }
  .tb-filter-btn  { height: 26px; padding: 0 7px; font-size: 11px; }
  .tb-theme-btn   { height: 26px; width: 26px; font-size: 11px; }
  .tb-pinned-right { padding-left: 5px; gap: 3px; }
}

/* 480px: minimal / very small phones */
@media (max-width: 480px) {
  :root { --tb-height: 64px; }
  .tb-page-title  { font-size: 12px; }
  .tb-page-info   { padding: 0 8px 0 0; margin-right: 6px; }
  .tb-select      { max-width: 90px; font-size: 11px; height: 26px; }
  .tb-filter-btn  { height: 24px; padding: 0 6px; font-size: 11px; }
  .tb-theme-btn   { height: 24px; width: 24px; font-size: 11px; }
  .tb-action-btn  { height: 24px; padding: 0 7px; font-size: 11px; }
  .tb-user-chip   { height: 24px; padding: 0 6px; }
  .tb-pinned-right { gap: 2px; }
}

/* ─ Dropdown header label ─ */
.tb-dd-header {
  font-size: 10px;
  font-weight: 700;
  color: #6366f1;
  letter-spacing: .04em;
  padding: 2px 4px 7px;
  display: flex;
  align-items: center;
  gap: 3px;
}
body.dark .tb-dd-header { color: #a5b4fc; }

/* ─ Date picker dropdown ─ */
.tb-date-picker-dd {
  right: 0;
  left: auto;
  min-width: 270px;
}
.tb-dp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.tb-dp-lbl {
  font-size: 10px;
  font-weight: 700;
  color: var(--c-muted);
  margin-bottom: 4px;
}
.tb-dp-apply {
  width: 100%;
  height: 32px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  border: none;
  border-radius: 9px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity .15s;
}
.tb-dp-apply:hover { opacity: .88; }

/* ─ Date badge as clickable button ─ */
.tb-date-badge-btn {
  cursor: pointer;
  border: none;
  background: inherit;
  font-family: inherit;
  padding: inherit;
  display: inherit;
  align-items: inherit;
  gap: inherit;
  height: inherit;
  border-radius: inherit;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}
.tb-date-badge-btn:hover { filter: brightness(.94); }

/* ─ Today date badge ─ */
.tb-date-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  background: #eef2ff;
  border: 1.5px solid #c7d2fe;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  color: #4338ca;
  white-space: nowrap;
  flex-shrink: 0;
}
.tb-date-badge i { font-size: 12px; }
body.dark .tb-date-badge { background: #1e1b4b; border-color: #3730a3; color: #a5b4fc; }

/* ──────────────────────────────────────────────────────────
   KPI SECTION HEADER — แยก MOPH vs SSJ ให้ชัดเจน
   ────────────────────────────────────────────────────────── */

/* ── MOPH Section Header ─ navy gradient ── */
.kpi-section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  padding: 12px 20px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0f3460 0%, #1e4d8c 100%);
  border: none;
  box-shadow: 0 4px 16px rgba(15,52,96,.25);
  position: relative;
  overflow: hidden;
}
.kpi-section-head::before {
  content: '';
  position: absolute;
  right: -20px; top: -20px;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
}
.kpi-section-head .sec-lbl {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #fff !important;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kpi-section-head .sec-lbl i { color: #93c5fd; font-size: 16px; }
.kpi-section-head .sec-period {
  font-size: 11.5px;
  color: rgba(255,255,255,.8) !important;
  background: rgba(255,255,255,.15) !important;
  border: 1px solid rgba(255,255,255,.2) !important;
  border-radius: 20px;
  padding: 3px 12px;
  font-weight: 600;
}

/* ── SSJ Section Header ─ teal gradient ── */
.kpi-section-head.ssj-head {
  background: linear-gradient(135deg, #0891b2 0%, #0e7490 50%, #047857 100%) !important;
  box-shadow: 0 4px 16px rgba(8,145,178,.25) !important;
}
.kpi-section-head.ssj-head .sec-lbl i { color: #a7f3d0; }

/* ──────────────────────────────────────────────────────────
   KPI SUMMARY CARDS (.kpi-sc) — ปรับให้ใหญ่ ชัดเจนขึ้น
   ────────────────────────────────────────────────────────── */
.kpi-cards-r4,
.kpi-cards-r3 {
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-sc {
  background: #fff;
  border: 1.5px solid #e8ecf0;
  border-radius: 14px;
  padding: 20px 20px 16px;
  transition: box-shadow .2s, transform .2s;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
  position: relative;
  overflow: hidden;
}
.kpi-sc::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: #e8ecf0;
  border-radius: 14px 14px 0 0;
}
.kpi-sc:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,.09);
  transform: translateY(-2px);
}
.kpi-sc.sc-pass {
  border-color: #86efac;
  background: linear-gradient(145deg, #f0fdf4 0%, #fff 60%);
}
.kpi-sc.sc-pass::before { background: #10b981; }
.kpi-sc.sc-fail {
  border-color: #fca5a5;
  background: linear-gradient(145deg, #fef2f2 0%, #fff 60%);
}
.kpi-sc.sc-fail::before { background: #ef4444; }

/* KPI value — larger, bolder */
.kpi-sc-val {
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -1.5px;
  margin-bottom: 6px;
  padding-top: 10px;
}
.kpi-sc-lbl {
  font-size: 14px;
  font-weight: 700;
  color: #1f2937;
  line-height: 1.3;
}
.kpi-sc-sub {
  font-size: 11.5px;
  color: #9ca3af;
  margin-top: 5px;
  line-height: 1.4;
}
.kpi-sc-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 20px;
  margin-top: 10px;
}
.kpi-sc-chip.pass {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}
.kpi-sc-chip.fail {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* ──────────────────────────────────────────────────────────
   KPI CARD STRIP (.cf-kpi-item) — แก้ขนาด icon/number
   ────────────────────────────────────────────────────────── */
.cf-kpi-item {
  padding: 20px 20px 16px;
  border-radius: 16px;
  border: 1.5px solid #e8ecf0;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.055);
  min-height: 148px;
  transition: transform .2s, box-shadow .2s;
}
.cf-kpi-item[onclick]:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0,0,0,.12);
}
.cf-kpi-lbl {
  font-size: 13.5px;
  font-weight: 700;
  color: #1f2937;
  line-height: 1.35;
}
.cf-kpi-sub {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 4px;
}
.cf-kpi-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.cf-kpi-val {
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -1.5px;
  color: #111827;
  padding-top: 14px;
  margin-top: auto;
}

/* ── Progress / bar-card ── */
.cf-kpi-bar-card {
  min-height: 112px;
  justify-content: space-between;
}
.cf-kpi-bar-card .cf-kpi-lbl {
  font-size: 13.5px;
  font-weight: 700;
  color: #1f2937;
}
.cf-kpi-pct-big {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -.5px;
}
.cf-kpi-bar-wrap {
  height: 12px;
  border-radius: 20px;
  background: #f0f2f5;
  margin: 10px 0 6px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.06);
}
.cf-kpi-bar {
  height: 100%;
  border-radius: 20px;
  transition: width .7s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.cf-kpi-bar-sub {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
  line-height: 1.4;
}
.cf-kpi-bar-count {
  font-size: 12px;
  font-weight: 700;
  color: #374151;
}

/* Trend badges */
.cf-kpi-trend {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}
.trend-up   { background: #d1fae5; color: #065f46; }
.trend-down { background: #fee2e2; color: #991b1b; }
.trend-flat { background: #f0f4f8; color: #4b5563; }

/* KPI section bar (MOPH/SSJ label chip) */
.cf-kpi-section-bar {
  padding: 14px 24px 0;
}
.cf-kpi-section-bar .kpi-chip {
  font-size: 11.5px;
  font-weight: 800;
  padding: 6px 18px;
  border-radius: 20px;
  letter-spacing: .6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.cf-kpi-section-bar .kpi-chip-moph {
  background: linear-gradient(135deg, #0f3460, #1e4d8c);
}
.cf-kpi-section-bar .kpi-chip-ssj {
  background: linear-gradient(135deg, #0891b2, #10b981);
}
.cf-kpi-section-bar .kpi-criteria {
  font-size: 11.5px;
  color: #6b7280;
  line-height: 1.6;
}

/* KPI strip container */
.cf-kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 14px;
  padding: 14px 24px 22px;
  background: #f8fafc;
  border-bottom: 1px solid #e8ecf0;
}
.cw-main .cf-kpi-strip {
  background: transparent;
  padding: 12px 24px 20px;
}

/* ──────────────────────────────────────────────────────────
   PROGRESS BARS — ทั่วไป
   ────────────────────────────────────────────────────────── */
.progress-bar-custom {
  height: 8px;
  background: #edf2f7;
  border-radius: 10px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(90deg, #10b981, #34d399);
  box-shadow: 0 1px 4px rgba(16,185,129,.3);
  transition: width .5s ease;
}

/* Rate bar rows */
.rate-bar-track {
  height: 10px;
  background: #edf2f7;
  border-radius: 20px;
  overflow: hidden;
}
.rate-bar-fill {
  height: 100%;
  border-radius: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.rate-bar-val {
  font-size: 12px;
  font-weight: 800;
  width: 44px;
}

/* SSJ service bar */
.svc-bar {
  height: 10px;
  border-radius: 10px;
  overflow: hidden;
  background: #edf2f7;
  margin: 7px 0;
}

/* hosp rate bar */
.hosp-rate-bar {
  height: 6px;
  background: #edf2f7;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 10px;
}

/* ──────────────────────────────────────────────────────────
   BADGES & CHIPS — ปรับให้เห็นชัดเจนขึ้น
   ────────────────────────────────────────────────────────── */

/* Status pass/fail */
.status-pass {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
}
.status-fail {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
}

/* Badge pill general */
.badge-pill {
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
}

/* Rate chips */
.rate-pass   { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.rate-warn   { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.rate-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.rate-gray   { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

/* Role badges */
.role-badge  { padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.role-hospital   { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
.role-superadmin { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.role-province   { background: #fef3c7; color: #b45309; border: 1px solid #fde68a; }
.role-viewer     { background: #f1f5f9; color: #374151; border: 1px solid #e2e8f0; }

/* Status user badges */
.status-active    { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.status-pending   { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.status-suspended { background: #f1f5f9; color: #6b7280; border: 1px solid #e2e8f0; }

/* Chart KPI badges */
.chart-kpi-badge {
  font-size: 10.5px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: .6px;
}
.chart-kpi-badge.moph {
  background: rgba(15,52,96,.1);
  color: #0f3460;
  border: 1px solid rgba(15,52,96,.2);
}
.chart-kpi-badge.ssj {
  background: rgba(8,145,178,.1);
  color: #0369a1;
  border: 1px solid rgba(8,145,178,.2);
}

/* Rank numbers */
.rank-num { width: 24px; height: 24px; font-size: 11px; font-weight: 800; border-radius: 6px; }
.rank-num.gold   { background: linear-gradient(135deg, #fef3c7, #fde68a); color: #92400e; }
.rank-num.silver { background: linear-gradient(135deg, #f1f5f9, #e2e8f0); color: #475569; }
.rank-num.bronze { background: linear-gradient(135deg, #fdf4e7, #fde8c4); color: #92400e; }

/* Status chip */
.chip-pass   { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.chip-fail   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.chip-nosend { background: #f1f5f9; color: #4b5563; border: 1px solid #e2e8f0; }

/* ──────────────────────────────────────────────────────────
   SECTION CARDS — ปรับ shadow และ border
   ────────────────────────────────────────────────────────── */
.cf-section {
  border-radius: 14px;
  border: 1px solid #e8ecf0;
  box-shadow: 0 2px 10px rgba(0,0,0,.055);
  margin-bottom: 22px;
}
.cf-section-head {
  padding: 16px 22px;
  border-bottom: 1px solid #e8ecf0;
  background: #fafbfc;
}
.cf-section-title {
  font-size: 14.5px;
  font-weight: 800;
  color: #0f3460;
}
.cf-section-title i { color: #3b82f6; font-size: 17px; }
.cf-section-sub { font-size: 11.5px; color: #9ca3af; margin-top: 2px; }
.cf-section-body { padding: 20px 22px; }

.section-card {
  border-radius: 14px;
  border: 1px solid #e8ecf0;
  box-shadow: 0 2px 10px rgba(0,0,0,.055);
}
.section-title {
  font-size: 15px;
  font-weight: 800;
  color: #0f3460;
}

/* ──────────────────────────────────────────────────────────
   TABLES — ปรับขนาดตัวอักษรและ spacing
   ────────────────────────────────────────────────────────── */
.table-custom,
.user-table,
.log-table,
.clinic-table,
.history-table,
.rank-table,
.kpi-tbl,
.import-table {
  font-size: 13.5px;
}
.table-custom th,
.user-table th,
.log-table th,
.clinic-table thead th,
.history-table th,
.rank-table th,
.kpi-tbl thead th,
.import-table thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6b7280;
  font-weight: 800;
  padding: 10px 14px;
  background: #f8fafc;
}
.table-custom td,
.user-table td,
.log-table td,
.clinic-table tbody td,
.history-table td,
.rank-table td,
.kpi-tbl tbody td,
.import-table tbody td {
  padding: 11px 14px;
  font-size: 13.5px;
}
.rank-table tbody tr:hover { background: #f8faff; }
.table-custom tbody tr:hover,
.user-table tbody tr:hover { background: #f8faff; }

/* ──────────────────────────────────────────────────────────
   HOSPITAL CARDS
   ────────────────────────────────────────────────────────── */
.hosp-card {
  border-radius: 12px;
  border: 1.5px solid #e8ecf0;
  padding: 14px;
}
.hosp-card::before { height: 4px; border-radius: 12px 12px 0 0; }
.hosp-card.pass::before   { background: linear-gradient(90deg, #10b981, #34d399); }
.hosp-card.fail::before   { background: linear-gradient(90deg, #ef4444, #f87171); }
.hosp-card.nosend::before { background: #9ca3af; }
.hosp-name   { font-size: 12.5px; font-weight: 700; }
.hosp-district { font-size: 10.5px; color: #9ca3af; }
.hosp-stat-val { font-size: 15px; font-weight: 800; }
.hosp-stat-lbl { font-size: 9.5px; color: #9ca3af; }

/* ──────────────────────────────────────────────────────────
   CHART CONTAINERS
   ────────────────────────────────────────────────────────── */
.chart-wrap { height: 270px; }
canvas { border-radius: 6px; }

/* Chart filter buttons */
.chart-filter .cf-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 13px;
  border-radius: 7px;
  border: 1.5px solid #e2e8f0;
}
.chart-filter .cf-btn.active {
  background: #0f3460;
  border-color: #0f3460;
  color: #fff;
  box-shadow: 0 2px 8px rgba(15,52,96,.25);
}

/* Tabs */
.cf-tabs { padding: 4px; border-radius: 10px; }
.cf-tab {
  padding: 6px 16px;
  font-size: 12.5px;
  border-radius: 8px;
  font-weight: 600;
}
.cf-tab.active {
  background: #fff;
  color: #0f3460;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

/* View tabs */
.view-tab {
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
}
.view-tab.active { color: #0f3460; border-bottom-color: #0f3460; }

/* ──────────────────────────────────────────────────────────
   KPI MINI CARDS (.kpi-mini)
   ────────────────────────────────────────────────────────── */
.kpi-mini {
  background: #f8fafc;
  border: 1.5px solid #e8ecf0;
  border-radius: 12px;
  padding: 12px 14px;
}
.kpi-mini-val  { font-size: 22px; font-weight: 900; line-height: 1.2; }
.kpi-mini-lbl  { font-size: 10.5px; color: #9ca3af; margin-top: 3px; }
.kpi-mini-sub  { font-size: 12px; color: #4b5563; }

/* ──────────────────────────────────────────────────────────
   FILTER BARS
   ────────────────────────────────────────────────────────── */
.dash-filter-bar {
  background: #fff;
  border: 1px solid #e8ecf0;
  border-radius: 12px;
  padding: 10px 18px;
  box-shadow: 0 1px 6px rgba(0,0,0,.04);
}
.dash-filter-btn {
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 14px;
  border: 1.5px solid #e2e8f0;
}
.dash-filter-btn.active {
  background: #0f3460;
  border-color: #0f3460;
  color: #fff;
  box-shadow: 0 2px 8px rgba(15,52,96,.25);
}
.dash-filter-btn:hover:not(.active) {
  border-color: #93c5fd;
  color: #1d4ed8;
}

/* duplicate removed — defined above */

/* ──────────────────────────────────────────────────────────
   UPLOAD ZONE
   ────────────────────────────────────────────────────────── */
.upload-zone {
  border-radius: 14px;
  border-width: 2px;
}
.upload-text { font-size: 16px; font-weight: 700; }
.upload-subtext { font-size: 13px; }

/* ──────────────────────────────────────────────────────────
   BUTTONS
   ────────────────────────────────────────────────────────── */
.btn {
  font-size: 13.5px;
  font-weight: 700;
  border-radius: 8px;
  padding: 9px 18px;
}
.btn-sm { padding: 5px 13px; font-size: 12px; }
.btn-lg { padding: 12px 26px; font-size: 15px; }
.btn-primary {
  background: linear-gradient(135deg, #0f3460, #1e4d8c);
  box-shadow: 0 2px 10px rgba(15,52,96,.25);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #0a2540, #0f3460);
  box-shadow: 0 6px 18px rgba(15,52,96,.35);
}
.btn-success { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 2px 10px rgba(16,185,129,.2); }
.btn-success:hover { background: linear-gradient(135deg, #059669, #047857); }

/* ──────────────────────────────────────────────────────────
   KPI PERIOD SELECTOR TAB
   ────────────────────────────────────────────────────────── */
.kpi-period-btn {
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 16px;
}
.kpi-period-btn.active {
  color: #0f3460;
  border-bottom-color: #0f3460;
}

/* ──────────────────────────────────────────────────────────
   SYNC STATS GRID
   ────────────────────────────────────────────────────────── */
.sync-stat-box { border-radius: 12px; padding: 12px 14px; }
.sync-stat-val { font-size: 24px; font-weight: 900; }
.sync-stat-lbl { font-size: 11px; }

/* ──────────────────────────────────────────────────────────
   ALERTS
   ────────────────────────────────────────────────────────── */
.alert-custom {
  border-radius: 12px;
  font-size: 13.5px;
}
.alert-success-custom { border-left-width: 5px; }
.alert-error-custom   { border-left-width: 5px; }
.alert-warning-custom { border-left-width: 5px; }
.alert-info-custom    { border-left-width: 5px; }

/* ──────────────────────────────────────────────────────────
   KPI SECTION HEAD + CARDS — extra specificity overrides
   ────────────────────────────────────────────────────────── */

/* Make the colored left-border on kpi-section-head more prominent */
.kpi-section-head { border-left: 5px solid #1e4d8c !important; }
.kpi-section-head.ssj-head { border-left: 5px solid #0891b2 !important; }

/* MOPH card accent top-border */
.kpi-cards-r4 .kpi-sc:not(.sc-pass):not(.sc-fail)::before {
  background: linear-gradient(90deg, #0f3460, #3b82f6);
}
/* SSJ card accent */
.kpi-cards-r3 .kpi-sc:not(.sc-pass):not(.sc-fail)::before {
  background: linear-gradient(90deg, #0891b2, #06b6d4);
}

/* ──────────────────────────────────────────────────────────
   CARDIFF HEADER STRIP
   ────────────────────────────────────────────────────────── */
.cardiff-header {
  background: linear-gradient(135deg, #0d1b2a 0%, #0f3460 55%, #1e3a5f 100%);
}
.cardiff-title  { font-size: 19px; font-weight: 800; }
.cardiff-subtitle { font-size: 12.5px; }

/* ──────────────────────────────────────────────────────────
   FLOATING NAV
   ────────────────────────────────────────────────────────── */
.cw-float-btn {
  width: 42px;
  height: 42px;
  font-size: 16px;
  box-shadow: 0 3px 14px rgba(0,0,0,.16);
}

/* ──────────────────────────────────────────────────────────
   HOSPITAL FILTER BANNER
   ────────────────────────────────────────────────────────── */
.hosp-filter-banner {
  background: linear-gradient(135deg, #1d4ed8, #0284c7);
  box-shadow: 0 4px 16px rgba(29,78,216,.25);
}
.hosp-filter-name   { font-size: 16px; }
.hosp-filter-stat-val { font-size: 22px; }

/* ──────────────────────────────────────────────────────────
   TOP CLINIC ROW
   ────────────────────────────────────────────────────────── */
.top-clinic-row {
  border-radius: 12px;
  border: 1px solid #e8ecf0;
  background: #fff;
}
.top-clinic-row:hover {
  box-shadow: 0 4px 18px rgba(0,0,0,.09);
  background: #fafbff;
}

/* ──────────────────────────────────────────────────────────
   HEATMAP
   ────────────────────────────────────────────────────────── */
.hm-cell { border-radius: 4px; width: 28px; height: 24px; }
.hm-pass    { background: #10b981; }
.hm-fail    { background: #ef4444; }
.hm-nosend  { background: #e2e8f0; }

/* ──────────────────────────────────────────────────────────
   DARK MODE OVERRIDES FOR v4
   ────────────────────────────────────────────────────────── */
body.dark .cw-sidebar { background: #1a2035; border-color: #2d3a4f; }
body.dark .sb-brand   { background: #1a2035; border-color: #2d3a4f; }
body.dark .sb-brand-name { color: #e2e8f0 !important; }
body.dark .sb-brand-sub  { color: #64748b !important; }
body.dark .sb-logo-icon  { background: linear-gradient(135deg, #4f46e5, #7c3aed); }
body.dark .sb-collapse-btn { background: #1e2535; border-color: #2d3a4f; }
body.dark .sb-collapse-btn:hover { background: #1e1b4b; color: #a5b4fc; }
body.dark .sb-collapse-text span { color: #cbd5e1; }
body.dark .sb-item { color: #94a3b8; }
body.dark .sb-item i { color: #64748b; }
body.dark .sb-item:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
body.dark .sb-item:hover i { color: #a5b4fc; }
body.dark .sb-item.active { background: #1e1b4b; color: #a5b4fc; box-shadow: none; }
body.dark .sb-item.active i { color: #a5b4fc; }
body.dark .sb-item.active .sb-item-sub { color: #818cf8; }
body.dark .sb-footer { background: #151d2e; border-color: #2d3a4f; }

body.dark .cw-topbar { background: #1a2035; border-color: #2d3a4f; }
body.dark .tb-page-title { color: #e2e8f0; }

body.dark .kpi-section-head {
  background: linear-gradient(135deg, #0d1f3c, #1a3560) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,.3) !important;
  border-color: #1e4d8c !important;
}
body.dark .kpi-section-head.ssj-head {
  background: linear-gradient(135deg, #053d4a, #075566) !important;
  border-color: #0891b2 !important;
}
body.dark .kpi-section-head .sec-period {
  background: rgba(255,255,255,.1) !important;
  border-color: rgba(255,255,255,.15) !important;
}

body.dark .kpi-sc {
  background: #1e2d42;
  border-color: #2d3a4f;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
body.dark .kpi-sc.sc-pass { background: rgba(16,185,129,.1); border-color: rgba(16,185,129,.3); }
body.dark .kpi-sc.sc-fail { background: rgba(239,68,68,.1);  border-color: rgba(239,68,68,.3); }
body.dark .kpi-sc-lbl { color: #e2e8f0; }
body.dark .kpi-sc-sub { color: #64748b; }
body.dark .kpi-sc-chip.pass { background: rgba(16,185,129,.15); color: #34d399; border-color: rgba(16,185,129,.3); }
body.dark .kpi-sc-chip.fail { background: rgba(239,68,68,.15);  color: #f87171; border-color: rgba(239,68,68,.3); }

body.dark .cf-kpi-item { background: #1e2d42; border-color: #2d3a4f; }
body.dark .cf-kpi-lbl  { color: #e2e8f0; }
body.dark .cf-kpi-sub  { color: #94a3b8; }
body.dark .cf-kpi-val  { color: #f1f5f9; }
body.dark .cf-kpi-bar-wrap { background: #2d3a4f; }

body.dark .cf-section     { background: #1e2d42; border-color: #2d3a4f; }
body.dark .cf-section-head { background: #172130; border-color: #2d3a4f; }
body.dark .cf-section-title { color: #93c5fd; }
body.dark .section-card   { background: #1e2d42; border-color: #2d3a4f; }

body.dark .chart-kpi-badge.moph { background: rgba(147,197,253,.1); color: #93c5fd; border-color: rgba(147,197,253,.2); }
body.dark .chart-kpi-badge.ssj  { background: rgba(103,232,249,.1); color: #67e8f9; border-color: rgba(103,232,249,.2); }

body.dark .dash-filter-bar { background: #1e2d42; border-color: #2d3a4f; }
body.dark .dash-filter-btn { background: #172130; border-color: #2d3a4f; color: #94a3b8; }
body.dark .dash-filter-btn.active { background: #1d4ed8; border-color: #1d4ed8; }
body.dark .dash-filter-btn:hover:not(.active) { border-color: #3b82f6; color: #60a5fa; }

body.dark .kpi-mini { background: #172130; border-color: #2d3a4f; }

body.dark .top-clinic-row { background: #1e2d42; border-color: #2d3a4f; }
body.dark .top-clinic-row:hover { background: #253047; }

body.dark .hosp-filter-banner { background: linear-gradient(135deg, #1e3a8a, #0c6b8a); }

body.dark .status-pass { background: rgba(16,185,129,.12); color: #34d399; border-color: rgba(16,185,129,.25); }
body.dark .status-fail { background: rgba(239,68,68,.12);  color: #f87171; border-color: rgba(239,68,68,.25); }

body.dark .cw-criteria-bar            { background: #172130; border-color: #2d3a4f; }
body.dark .crit-row + .crit-row      { background: rgba(16,185,129,.04); border-color: #2d3a4f; }
body.dark .crit-divider              { background: #2d3a4f; }
body.dark .cw-date-badge             { background: rgba(59,130,246,.15); border-color: rgba(59,130,246,.3); color: #93c5fd; }
body.dark .crit-cascade              { background: rgba(59,130,246,.08); border-color: rgba(59,130,246,.25); }
body.dark .crit-step-num             { background: #253047; color: #94a3b8; }
body.dark .crit-cascade-pct.p1      { background: rgba(59,130,246,.2); color: #93c5fd; }
body.dark .crit-cascade-pct.p2      { background: rgba(16,185,129,.2); color: #34d399; }
body.dark .crit-cascade-pct.p3      { background: rgba(139,92,246,.2); color: #a78bfa; }

body.dark .rank-num.gold   { background: rgba(251,191,36,.15); color: #fbbf24; }
body.dark .rank-num.silver { background: rgba(148,163,184,.12); color: #94a3b8; }
body.dark .rank-num.bronze { background: rgba(234,179,8,.1);   color: #d97706; }

body.dark .cf-tabs { background: rgba(255,255,255,.06); }
body.dark .cf-tab  { color: #94a3b8; }
body.dark .cf-tab.active { background: rgba(255,255,255,.12); color: #93c5fd; }

body.dark .cf-kpi-section-bar .kpi-chip-moph { background: linear-gradient(135deg, #0d1f3c, #1a3560); }
body.dark .cf-kpi-section-bar .kpi-chip-ssj  { background: linear-gradient(135deg, #053d4a, #0891b2); }
body.dark .cf-kpi-section-bar .kpi-criteria  { color: #94a3b8; }
body.dark .cf-kpi-strip { border-color: #2d3a4f; }
body.dark .cw-main .cf-kpi-strip { border-color: #2d3a4f; }

/* ══════════════════════════════════════════════════════════
   DARK MODE — READABILITY ENHANCEMENT
   เพิ่มความสว่างและขนาดตัวอักษรใน dark mode
   ══════════════════════════════════════════════════════════ */

/* ── ฟอนต์ขนาดเพิ่มขึ้น ── */
body.dark .cf-kpi-lbl        { font-size: 13px; font-weight: 700; color: #f1f5f9; }
body.dark .cf-kpi-sub        { font-size: 12px; color: #b0bfd4; }
body.dark .cf-kpi-val        { font-size: inherit; color: #f8fafc; }
body.dark .cf-kpi-detail     { font-size: 12px; color: #b0bfd4; }
body.dark .cf-kpi-bar-count  { font-size: 12px; color: #b0bfd4; }
body.dark .cf-kpi-bar-sub    { font-size: 11px; color: #b0bfd4; }

/* ── KPI Scorecard (kpi-sc) ── */
body.dark .kpi-sc-lbl        { color: #f1f5f9; font-size: 13px; font-weight: 700; }
body.dark .kpi-sc-sub        { color: #b0bfd4; font-size: 12px; }
body.dark .kpi-sc-detail     { color: #b0bfd4; font-size: 12px; }

/* ── Section titles / sub ── */
body.dark .cf-section-title  { color: #93c5fd; font-size: 15px; }
body.dark .cf-section-sub    { color: #b0bfd4; font-size: 12px; }
body.dark .section-title     { color: #93c5fd; font-size: 15px; }

/* ── Criteria bar ── */
body.dark .cf-kpi-section-bar .kpi-criteria { color: #b0bfd4; font-size: 12px; }
body.dark .crit-step-num     { color: #cbd5e1; }
body.dark .kpi-section-head .sec-lbl  { font-size: 14px; }
body.dark .kpi-section-head .sec-period { font-size: 12px; }

/* ── Table text ── */
body.dark .rank-table tbody tr td    { color: #e2e8f0; font-size: 13px; }
body.dark .rank-table thead tr th   { color: #f1f5f9; font-size: 12px; }
body.dark .table-custom td,
body.dark .user-table td,
body.dark .log-table td              { color: #e2e8f0; font-size: 13px; }
body.dark .table-custom th,
body.dark .user-table th,
body.dark .log-table th              { color: #f1f5f9; font-size: 12px; }

/* ── Heatmap ── */
body.dark .hm-hosp-label     { color: #e2e8f0; font-size: 12px; }
body.dark .hm-date-label     { color: #b0bfd4; }
body.dark .hm-sum-lbl        { color: #b0bfd4; font-size: 12px; }
body.dark .hm-sum-val        { color: #f1f5f9; font-size: 18px; }
body.dark .hm-sum-sub        { color: #b0bfd4; font-size: 11px; }
body.dark .hm-legend         { color: #b0bfd4; }

/* ── Analytics ── */
body.dark .analytics-card-title { color: #f1f5f9; font-size: 13px; }
body.dark .analytics-card-sub   { color: #b0bfd4; font-size: 12px; }

/* ── Sidebar / nav ── */
body.dark .sb-brand-sub      { color: #94a3b8 !important; font-size: 12px; }
body.dark .sb-item-lbl       { font-size: 13px; }
body.dark .sb-item-sub       { font-size: 11px; }
body.dark .sb-footer-label   { color: #94a3b8; font-size: 11px; }

/* ── Topbar ── */
body.dark .tb-page-title     { color: #f1f5f9; font-size: 16px; font-weight: 700; }
body.dark .tb-page-sub       { color: #b0bfd4; font-size: 12px; }

/* ── Hosp cards ── */
body.dark .hosp-name         { color: #f1f5f9; font-size: 13px; }
body.dark .hosp-code         { color: #94a3b8; font-size: 11px; }
body.dark .hosp-stat-lbl     { color: #b0bfd4; font-size: 11px; }
body.dark .hosp-stat-val     { color: #f1f5f9; font-size: 13px; }

/* ── SSJ Step labels ── */
body.dark .ssj-step-title    { color: #f1f5f9; font-size: 13px; }
body.dark .ssj-step-sub      { color: #b0bfd4; font-size: 12px; }

/* ── Map panel ── */
body.dark .map-rpanel-subtab { color: #b0bfd4; }
body.dark .map-rpanel-sub    { color: #b0bfd4; font-size: 12px; }
body.dark .map-legend-title  { color: #b0bfd4; font-size: 12px; }
body.dark .map-ctrl-sub      { color: #b0bfd4; font-size: 12px; }

/* ── Modal KPI ── */
body.dark .hm-modal-kpi-lbl  { color: #e2e8f0; font-size: 12px; }
body.dark .hm-modal-kpi-val  { color: #f8fafc; }

/* ── Trend badges ── */
body.dark .trend-flat        { color: #b0bfd4; }

/* ── Form labels ── */
body.dark .form-label        { color: #e2e8f0; font-size: 13px; }
body.dark .pub-subtitle      { color: #b0bfd4; font-size: 13px; }

/* ── Tabs ── */
body.dark .cf-tab            { color: #b0bfd4; font-size: 13px; }
body.dark .cf-tab.active     { color: #93c5fd; }

/* ── Rank table sub text ── */
body.dark .rank-sub          { color: #94a3b8; font-size: 11px; }
body.dark .rank-badge        { font-size: 12px; }

/* ──────────────────────────────────────────────────────────
   RESPONSIVE TWEAKS
   ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .kpi-sc-val     { font-size: 38px; }
  .cf-kpi-val     { font-size: 38px; }
  .kpi-cards-r4,
  .kpi-cards-r3   { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .kpi-sc-val     { font-size: 32px; }
  .cf-kpi-val     { font-size: 32px; }
  .kpi-section-head { padding: 10px 14px; }
  .kpi-section-head .sec-lbl { font-size: 12px; }
  .kpi-cards-r4,
  .kpi-cards-r3   { grid-template-columns: 1fr 1fr; gap: 10px; }
}

/* ──────────────────────────────────────────────────────────
   HEATMAP MODAL — KPI Summary Cards
   ────────────────────────────────────────────────────────── */
/* ── KPI Cards strip ── */
.hm-modal-kpi-wrap {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-bottom: 2px solid #e5eaf0;
  overflow: hidden;
  border-radius: 0;
}
.hm-modal-kpi-section {
  display: flex;
  align-items: stretch;
  padding: 14px 20px;
  gap: 14px;
  border-bottom: 1px solid rgba(0,0,0,.06);
  position: relative;
}
.hm-modal-kpi-section:last-child { border-bottom: none; }

/* MOPH section — blue tint */
.hm-modal-kpi-section-moph {
  background: linear-gradient(135deg, rgba(15,52,96,.055) 0%, rgba(59,130,246,.025) 100%);
  border-left: 4px solid #0f3460;
}
/* SSJ section — emerald tint */
.hm-modal-kpi-section-ssj {
  background: linear-gradient(135deg, rgba(16,185,129,.055) 0%, rgba(245,158,11,.025) 100%);
  border-left: 4px solid #10b981;
}

.hm-modal-kpi-chip {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: #fff;
  border-radius: 8px;
  padding: 10px 5px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.hm-modal-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  flex: 1;
}
.hm-modal-kpi-card {
  background: rgba(255,255,255,.85);
  border: 1.5px solid rgba(0,0,0,.07);
  border-radius: 14px;
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  min-height: 100px;
  box-shadow: 0 1px 5px rgba(0,0,0,.06);
  backdrop-filter: blur(2px);
  transition: box-shadow .15s;
}
.hm-modal-kpi-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.1); }
.hm-modal-kpi-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}
.hm-modal-kpi-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.hm-modal-kpi-lbl {
  font-size: 11px;
  font-weight: 700;
  color: #374151;
  line-height: 1.4;
  word-break: keep-all;
}
.hm-modal-kpi-sub { font-size: 10px; font-weight: 400; color: #94a3b8; }
.hm-modal-kpi-val {
  font-size: 28px;
  font-weight: 800;
  color: #111827;
  letter-spacing: -0.5px;
  margin-top: auto;
  line-height: 1;
  padding-top: 6px;
}
.hm-modal-kpi-extra {
  font-size: 10px;
  color: #94a3b8;
  margin-top: 4px;
  line-height: 1.6;
}

/* ── Clinic table label bar ── */
.hm-modal-table-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px 8px;
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  background: #f8fafc;
  border-bottom: 2px solid #e5eaf0;
}

/* ── Table KPI column tints ── */
.clinic-table .kpi-moph-th {
  background: rgba(15,52,96,.09);
  border-top: 3px solid #0f3460;
  color: #0f3460 !important;
}
.clinic-table .kpi-ssj-th {
  background: rgba(16,185,129,.09);
  border-top: 3px solid #10b981;
  color: #047857 !important;
}
.clinic-table .kpi-ssj-sub-th {
  background: rgba(16,185,129,.05);
  color: #047857 !important;
}
.clinic-table td.kpi-moph-col {
  background: rgba(15,52,96,.03);
}
.clinic-table td.kpi-ssj-col {
  background: rgba(16,185,129,.03);
}
.clinic-table tfoot td.kpi-moph-col {
  background: rgba(15,52,96,.06);
}
.clinic-table tfoot td.kpi-ssj-col {
  background: rgba(16,185,129,.06);
}

/* ── Dark mode overrides ── */
body.dark .hm-modal-kpi-wrap    { border-color: #1e2d45; }
body.dark .hm-modal-kpi-section { border-color: #1e2d45; }
body.dark .hm-modal-kpi-section-moph { background: linear-gradient(135deg,rgba(15,52,96,.18) 0%,rgba(59,130,246,.08) 100%); }
body.dark .hm-modal-kpi-section-ssj  { background: linear-gradient(135deg,rgba(16,185,129,.18) 0%,rgba(245,158,11,.08) 100%); }
body.dark .hm-modal-kpi-card    { background: rgba(17,24,39,.7); border-color: #1e2d45; }
body.dark .hm-modal-kpi-lbl     { color: #e2e8f0; }
body.dark .hm-modal-kpi-val     { color: #f1f5f9; }
body.dark .hm-modal-table-label { background: #0d1526; color: #e2e8f0; border-color: #1e2d45; }
body.dark .clinic-table .kpi-moph-th {
  background: rgba(59,130,246,.18);
  color: #93c5fd !important;
  border-top-color: #60a5fa;
}
body.dark .clinic-table .kpi-ssj-th  {
  background: rgba(16,185,129,.16);
  color: #6ee7b7 !important;
  border-top-color: #34d399;
}
body.dark .clinic-table .kpi-ssj-sub-th {
  background: rgba(16,185,129,.10);
  color: #a7f3d0 !important;
}
body.dark .clinic-table td.kpi-moph-col { background: rgba(15,52,96,.1); }
body.dark .clinic-table td.kpi-ssj-col  { background: rgba(16,185,129,.08); }
body.dark .clinic-table tfoot td.kpi-moph-col { background: rgba(15,52,96,.2); }
body.dark .clinic-table tfoot td.kpi-ssj-col  { background: rgba(16,185,129,.15); }
body.dark .clinic-table thead th {
  color: #dbe7f5 !important;
}
body.dark .clinic-table thead th small,
body.dark .clinic-table thead th .sub-txt {
  color: #9fb3ca !important;
}
body.dark .clinic-table tbody td {
  color: #e5eefb !important;
}
body.dark .clinic-table tfoot td {
  color: #e5eefb !important;
}
body.dark .clinic-table .kpi-num,
body.dark .clinic-table .rate-val {
  color: #f8fafc;
}
body.dark .clinic-table .kpi-muted,
body.dark .clinic-table .sub-txt,
body.dark .text-muted {
  color: #9fb3ca !important;
}
body.dark .hm-modal-kpi-sub {
  color: #9fb3ca;
}
body.dark .modal-title,
body.dark #kpiClinicDetailTitle,
body.dark #mapHospModalLabel {
  color: #f8fafc !important;
}
body.dark .btn-close {
  filter: invert(1) grayscale(100%) brightness(1.4);
}

@media (max-width: 800px) {
  .hm-modal-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .hm-modal-kpi-section { flex-direction: column; }
  .hm-modal-kpi-chip { writing-mode: horizontal-tb; transform: none; padding: 4px 12px; width: fit-content; }
}

/* ══════════════════════════════════════════════════════════════
   GLOBAL FONT SIZE UPGRADE v2.3 — ทั้ง Light & Dark Mode
   เพิ่มขนาดตัวอักษรทั้งโปรเจคให้อ่านง่ายขึ้น
   ══════════════════════════════════════════════════════════════ */

/* ── 1. KPI Big Numbers ── */
.kpi-sc-val,
.cf-kpi-val          { font-size: 52px !important; }
.stat-value          { font-size: 38px !important; }
.ring-pct            { font-size: 22px !important; }
.hg-kpi-val          { font-size: 52px !important; }
.kpi-value           { font-size: 36px !important; }
.hm-modal-kpi-val    { font-size: 28px !important; }
.kpi-mini-val        { font-size: 22px !important; }

/* ── 2. Section / Page Titles ── */
.cf-section-title    { font-size: 16px !important; font-weight: 700 !important; }
.section-title,
.admin-title-h,
.tb-page-title       { font-size: 18px !important; font-weight: 700 !important; }
.pub-title           { font-size: 24px !important; }
.kpi-section-head .sec-lbl { font-size: 15px !important; font-weight: 700 !important; }
.map-ctrl-title      { font-size: 16px !important; }
.analytics-card-title{ font-size: 14px !important; font-weight: 700 !important; }

/* ── 3. Card Labels / Sub / Detail ── */
.cf-kpi-lbl          { font-size: 14px !important; font-weight: 700 !important; }
.cf-kpi-sub,
.cf-kpi-detail,
.cf-kpi-bar-sub,
.cf-kpi-bar-count    { font-size: 13px !important; }
.cf-kpi-bar-lbl      { font-size: 13px !important; font-weight: 700 !important; }
.cf-section-sub      { font-size: 13px !important; }
.kpi-sc-lbl          { font-size: 14px !important; font-weight: 700 !important; }
.kpi-sc-sub,
.kpi-sc-detail       { font-size: 13px !important; }
.kpi-sc-chip         { font-size: 12px !important; }
.stat-label          { font-size: 13px !important; }
.stat-sub            { font-size: 13px !important; }
.kpi-label           { font-size: 14px !important; }
.kpi-sub             { font-size: 13px !important; }
.kpi-mini-lbl        { font-size: 13px !important; }
.analytics-card-sub  { font-size: 13px !important; }
.hm-modal-kpi-lbl    { font-size: 13px !important; }

/* ── 4. Tables ── */
.table-custom,
.user-table,
.log-table,
.rank-table,
.clinic-table        { font-size: 14px !important; }
.table-custom th,
.user-table th,
.log-table th,
.rank-table th,
.clinic-table th     { font-size: 13px !important; font-weight: 700 !important; }
.table-custom td,
.user-table td,
.log-table td,
.rank-table td,
.clinic-table td     { font-size: 14px !important; }
.hm-modal-table-label{ font-size: 13px !important; }

/* ── 5. Heatmap ── */
.hm-hosp-label       { font-size: 13px !important; }
.hm-date-label       { font-size: 12px !important; }
.hm-num              { font-size: 12px !important; }
.hm-num-cell         { font-size: 12px !important; }
.heatmap-table th    { font-size: 12px !important; }
.hm-date-label span  { font-size: 10px !important; }
.hm-sum-lbl          { font-size: 13px !important; }
.hm-sum-val          { font-size: 20px !important; }
.hm-thresh-lbl       { font-size: 13px !important; }
.hm-legend           { font-size: 13px !important; }

/* ── 6. Badges / Chips / Pills ── */
.role-badge,
.status-badge,
.log-badge,
.log-action,
.status-pass,
.status-fail         { font-size: 12px !important; }
.rank-num            { font-size: 12px !important; }
.crit-cascade-pct    { font-size: 13px !important; }
.nav-pill            { font-size: 14px !important; }

/* ── 7. Sidebar ── */
.sb-brand-name       { font-size: 15px !important; }
.sb-brand-sub        { font-size: 12px !important; }
.sb-item-title       { font-size: 14px !important; }
.sb-item-sub         { font-size: 12px !important; }
.sb-footer-label     { font-size: 11px !important; }
.sb-footer-date      { font-size: 13px !important; }
.sb-collapse-text span { font-size: 13px !important; }
.sb-collapse-text small{ font-size: 11px !important; }
.sb-group-label      { font-size: 11px !important; }

/* ── 8. Topbar / Nav / Filters ── */
.brand-name          { font-size: 16px !important; }
.brand-sub           { font-size: 12px !important; }
.tb-date-badge       { font-size: 13px !important; }
.cf-filter-bar label { font-size: 13px !important; }
.cf-filter-bar select,
.cf-filter-bar input { font-size: 14px !important; }
.cf-tab              { font-size: 14px !important; }
.view-tab            { font-size: 14px !important; }

/* ── 9. Hospital Cards ── */
.hosp-name           { font-size: 14px !important; font-weight: 700 !important; }
.hosp-district,
.hosp-code           { font-size: 12px !important; }
.hosp-stat-val       { font-size: 16px !important; font-weight: 800 !important; }
.hosp-stat-lbl       { font-size: 12px !important; }

/* ── 10. Criteria / SSJ Steps ── */
.crit-label          { font-size: 14px !important; }
.crit-formula        { font-size: 12px !important; }
.ssj-step-title      { font-size: 14px !important; }
.ssj-step-formula    { font-size: 12px !important; }
.ssj-step-threshold  { font-size: 16px !important; }
.sec-period          { font-size: 13px !important; }

/* ── 11. Map Panel ── */
.map-ctrl-sub        { font-size: 13px !important; }
.map-legend-title    { font-size: 12px !important; }
.map-legend-chip-name{ font-size: 13px !important; }
.map-legend-chip-desc{ font-size: 12px !important; }
.map-rpanel-subtab   { font-size: 13px !important; }
.map-rpanel-sub      { font-size: 13px !important; }
.map-info-chip       { font-size: 13px !important; }
.map-rpanel-bar-val  { font-size: 13px !important; }
.map-rpanel-bar-label{ font-size: 12px !important; }

/* ── 12. Rate / Ring bars ── */
.rate-bar-lbl        { font-size: 13px !important; }
.rate-bar-val        { font-size: 13px !important; }
.ring-title          { font-size: 13px !important; }
.ring-sub            { font-size: 12px !important; }

/* ── 13. Forms / Inputs / Buttons ── */
.form-control,
.form-select         { font-size: 15px !important; }
.form-label          { font-size: 14px !important; font-weight: 600 !important; }
.btn                 { font-size: 14px !important; }
.btn-sm              { font-size: 13px !important; }
.btn-lg              { font-size: 16px !important; }

/* ── 14. Log / Activity / Admin ── */
.log-item            { font-size: 14px !important; }
.log-time            { font-size: 12px !important; }
.pending-name        { font-size: 14px !important; }
.pending-hosp        { font-size: 13px !important; }
.admin-user-name     { font-size: 13px !important; }
.send-of             { font-size: 14px !important; }

/* ── 15. Responsive Tweaks ── */
@media (max-width: 900px) {
  .kpi-sc-val, .cf-kpi-val, .hg-kpi-val { font-size: 42px !important; }
  .kpi-sc-lbl, .cf-kpi-lbl              { font-size: 13px !important; }
}
@media (max-width: 600px) {
  .kpi-sc-val, .cf-kpi-val, .hg-kpi-val { font-size: 34px !important; }
  .cf-kpi-lbl, .kpi-sc-lbl              { font-size: 13px !important; }
  .table-custom td, .user-table td,
  .log-table td, .rank-table td          { font-size: 13px !important; }
  .hosp-name                             { font-size: 13px !important; }
}

/* ══════════════════════════════════════════════════════════════
   QUARTERLY CARDS (ไตรมาส) — Light & Dark Mode
   ══════════════════════════════════════════════════════════════ */

/* ── Header ── */
.q-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--c-text);
  line-height: 1.2;
}
.q-months {
  font-size: 12px;
  color: var(--c-light);
  margin-top: 2px;
}
.q-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  border: 1.5px solid;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ── Step boxes (Slot / จอง / Tele) ── */
.q-step-box {
  flex: 1;
  text-align: center;
  background: rgba(255,255,255,.75);
  border-radius: 8px;
  padding: 7px 4px;
  border: 1px solid;
}
.q-step-lbl {
  font-size: 12px;
  color: #475569;
  font-weight: 700;
  margin-bottom: 2px;
}
.q-step-val {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.2;
}
.q-step-thr {
  font-size: 11px;
  color: #64748b;
  margin-top: 2px;
  font-weight: 600;
}

/* ── Bottom counts ── */
.q-count {
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.q-count-book { color: #2563eb; }
.q-count-tele { color: #7c3aed; }
.q-hosp-tag {
  font-size: 12px;
  color: var(--c-light);
  background: var(--c-stripe);
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--c-border);
}

/* ── Responsive breakpoints ── */
@media (max-width: 1400px) {
  .hosp-status-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 1100px) {
  .hosp-status-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 800px) {
  .hosp-status-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 14px; }
}
@media (max-width: 480px) {
  .hosp-status-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 10px; }
}

/* ── DARK MODE overrides ── */
body.dark .q-title    { color: #f1f5f9; }
body.dark .q-months   { color: #94a3b8; }
body.dark .q-step-box {
  background: rgba(30, 41, 59, 0.85);
  border-color: rgba(148,163,184,.2);
}
body.dark .q-step-lbl { color: #cbd5e1; }
body.dark .q-step-thr { color: #94a3b8; }
body.dark .q-count-book { color: #60a5fa; }
body.dark .q-count-tele { color: #a78bfa; }
body.dark .q-hosp-tag {
  color: #94a3b8;
  background: rgba(30,41,59,.6);
  border-color: rgba(148,163,184,.2);
}

/* ============================================================
   DASHBOARD DESIGN SYSTEM OVERRIDE
   Professional typography, cards, progress, graph, badge
   ============================================================ */
:root {
  color-scheme: light;
  --ui-font-display: clamp(1.65rem, 1.1rem + 1.25vw, 2.45rem);
  --ui-font-h1: clamp(1.35rem, 1.05rem + 0.8vw, 1.95rem);
  --ui-font-h2: clamp(1.12rem, 0.95rem + 0.45vw, 1.45rem);
  --ui-font-h3: 1.05rem;
  --ui-font-body: 0.96rem;
  --ui-font-small: 0.84rem;
  --ui-font-micro: 0.76rem;
  --ui-radius-lg: 20px;
  --ui-radius-md: 16px;
  --ui-radius-sm: 12px;
  --ui-shadow-card: 0 14px 36px rgba(15, 23, 42, 0.08);
  --ui-shadow-hover: 0 22px 48px rgba(15, 23, 42, 0.14);
  --ui-border-soft: rgba(148, 163, 184, 0.22);
  --ui-panel-bg: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(248,250,252,0.98) 100%);
  --ui-muted-bg: rgba(148, 163, 184, 0.08);
  --tbl-kpi-moph-bg: rgba(15,52,96,.12);
  --tbl-kpi-moph-text: #0f3460;
  --tbl-kpi-moph-border: #0f3460;
  --tbl-kpi-moph-sub-bg: rgba(15,52,96,.06);
  --tbl-kpi-moph-sub-text: #0f3460;
  --tbl-kpi-ssj-bg: rgba(16,185,129,.10);
  --tbl-kpi-ssj-text: #047857;
  --tbl-kpi-ssj-border: #10b981;
  --tbl-kpi-ssj-sub-bg: rgba(16,185,129,.06);
  --tbl-kpi-ssj-sub-text: #047857;
}

body {
  font-size: var(--ui-font-body);
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(circle at top left, rgba(59,130,246,.10), transparent 26%),
    radial-gradient(circle at top right, rgba(16,185,129,.08), transparent 22%),
    var(--c-bg);
}

.tb-page-title,
.page-title,
.section-title,
.cf-section-title,
.sc3-title,
.kpi-section-head .sec-lbl {
  font-size: var(--ui-font-h1) !important;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 800;
}

.tb-page-sub,
.cf-section-sub,
.sc3-subtitle,
.kpi-section-head .sec-period,
.analytics-card-sub {
  font-size: 0.92rem !important;
  line-height: 1.55;
}

/* topbar ไม่มี border-radius — เต็มบรรทัดแบน */
.cf-section,
.section-card,
.section-card-v3,
.analytics-card,
.hosp-card,
.map-layout-left,
.map-layout-right,
.map-rpanel-item,
.ssj-chart-panel,
.chart-panel,
.stat-card-v3,
.cf-kpi-item {
  border-radius: var(--ui-radius-lg) !important;
}
.cw-topbar {
  border-radius: 0 !important;
}

.cf-section,
.section-card,
.section-card-v3,
.analytics-card,
.hosp-card,
.map-layout-left,
.map-layout-right,
.map-rpanel-item,
.ssj-chart-panel,
.chart-panel,
.stat-card-v3,
.cf-kpi-item {
  border: 1px solid var(--ui-border-soft) !important;
  box-shadow: var(--ui-shadow-card) !important;
  background: var(--ui-panel-bg);
  backdrop-filter: blur(10px);
}

.cf-kpi-item[onclick]:hover,
.section-card:hover,
.section-card-v3:hover,
.stat-card-v3:hover,
.hosp-card:hover,
.map-rpanel-item:hover {
  box-shadow: var(--ui-shadow-hover) !important;
  transform: translateY(-4px);
}

.cf-kpi-item {
  min-height: 164px;
  padding: 22px 22px 18px;
}

.cf-kpi-lbl,
.sc-label,
.analytics-card-title,
.hosp-stat-lbl,
.map-rpanel-header-title {
  font-size: 0.96rem !important;
  font-weight: 800;
  line-height: 1.35;
}

.cf-kpi-sub,
.sc-sub,
.cf-kpi-detail,
.cf-kpi-bar-sub,
.map-rpanel-sub,
.hosp-district,
.hosp-code {
  font-size: 0.84rem !important;
  line-height: 1.45;
}

.cf-kpi-val {
  font-size: clamp(2.5rem, 2rem + 1.2vw, 3.4rem) !important;
  letter-spacing: -0.04em;
}

.sc-value {
  font-size: clamp(2rem, 1.65rem + 0.8vw, 2.8rem) !important;
  letter-spacing: -0.03em;
}

.cf-kpi-icon,
.sc-icon-wrap {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  font-size: 26px;
}

.cf-kpi-bar-wrap,
.progress-bar-custom,
.rate-bar-track,
.svc-bar,
.send-progress-track {
  height: 12px !important;
  border-radius: 999px !important;
  background: linear-gradient(180deg, rgba(226,232,240,.95), rgba(241,245,249,.95)) !important;
  overflow: hidden;
}

.cf-kpi-bar,
.progress-fill,
.rate-bar-fill,
.send-progress-fill {
  border-radius: 999px !important;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.18);
}

.badge,
.badge-pill,
.kpi-badge,
.cw-date-badge,
.tb-date-badge,
.role-badge,
.status-badge,
.log-badge,
.cf-kpi-trend,
.map-ssj-badge,
.q-badge,
.kpi-sc-chip {
  border-radius: 999px !important;
  font-size: 0.78rem !important;
  font-weight: 800 !important;
  letter-spacing: 0.01em;
  padding: 0.38rem 0.78rem !important;
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
}

/* ── Filter group: ขอบมนแบบสี่เหลี่ยมเบา (ไม่ใช่ pill) ── */
.tb-filter-group,
.tb-select,
.tb-daterange-wrap,
.tb-user-chip,
.tb-action-btn,
.tb-action-icon {
  border-radius: 8px !important;
}
/* icon-only action/theme buttons: square + centered */
.tb-action-btn.tb-action-icon {
  width: 32px !important;
  padding: 0 !important;
  justify-content: center;
  font-size: 14px;
}

.chart-wrap,
.ring-chart,
.analytics-chart-grid canvas,
canvas {
  border-radius: 18px;
}

.chart-wrap {
  min-height: 300px;
}

.cf-kpi-strip {
  gap: 18px;
  padding: 18px 24px 24px;
}

.tb-filter-btn,
.cf-tab,
.map-tab,
.map-rpanel-tab,
.map-rpanel-subtab {
  font-size: 0.86rem !important;
  font-weight: 700;
  border-radius: 6px !important;  /* ปุ่มกรอง: แบนแบบสี่เหลี่ยมเบา */
}
/* theme buttons — icon + text label */
.tb-theme-group {
  height: 34px;
  border-radius: 8px !important;
  overflow: visible !important;
  border: 1.5px solid #d1d5db !important;
  background: #fff !important;
}
.tb-theme-btn {
  width: auto !important;
  height: 34px !important;
  padding: 0 13px !important;
  gap: 5px !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  white-space: nowrap;
  justify-content: flex-start !important;
  border-radius: 6px !important;
}
.tb-theme-btn:first-child { border-radius: 6px 0 0 6px !important; }
.tb-theme-btn:last-child  { border-radius: 0 6px 6px 0 !important; border-right: none !important; }

body.dark {
  color-scheme: dark;
  --ui-border-soft: rgba(71, 85, 105, 0.58);
  --ui-shadow-card: 0 18px 38px rgba(2, 6, 23, 0.38);
  --ui-shadow-hover: 0 24px 52px rgba(2, 6, 23, 0.52);
  --ui-panel-bg: linear-gradient(180deg, rgba(23,33,48,0.96) 0%, rgba(17,24,39,0.98) 100%);
  --ui-muted-bg: rgba(51, 65, 85, 0.42);
  --tbl-kpi-moph-bg: rgba(59,130,246,.14);
  --tbl-kpi-moph-text: #93c5fd;
  --tbl-kpi-moph-border: #60a5fa;
  --tbl-kpi-moph-sub-bg: rgba(59,130,246,.08);
  --tbl-kpi-moph-sub-text: #dbeafe;
  --tbl-kpi-ssj-bg: rgba(16,185,129,.14);
  --tbl-kpi-ssj-text: #6ee7b7;
  --tbl-kpi-ssj-border: #34d399;
  --tbl-kpi-ssj-sub-bg: rgba(16,185,129,.08);
  --tbl-kpi-ssj-sub-text: #d1fae5;
  background:
    radial-gradient(circle at top left, rgba(59,130,246,.18), transparent 26%),
    radial-gradient(circle at top right, rgba(16,185,129,.08), transparent 22%),
    var(--c-bg);
}

body.dark .cf-section,
body.dark .section-card,
body.dark .section-card-v3,
body.dark .analytics-card,
body.dark .hosp-card,
body.dark .map-layout-left,
body.dark .map-layout-right,
body.dark .map-rpanel-item,
body.dark .ssj-chart-panel,
body.dark .chart-panel,
body.dark .stat-card-v3,
body.dark .cf-kpi-item,
body.dark .cw-topbar {
  background: var(--ui-panel-bg) !important;
  border-color: var(--ui-border-soft) !important;
  box-shadow: var(--ui-shadow-card) !important;
}

body.dark .cf-kpi-bar-wrap,
body.dark .progress-bar-custom,
body.dark .rate-bar-track,
body.dark .svc-bar,
body.dark .send-progress-track {
  background: linear-gradient(180deg, rgba(30,41,59,.95), rgba(15,23,42,.92)) !important;
}

body.dark .tb-date-badge,
body.dark .cw-date-badge,
body.dark .badge-pill,
body.dark .role-badge,
body.dark .status-badge,
body.dark .log-badge,
body.dark .cf-kpi-trend,
body.dark .map-ssj-badge,
body.dark .q-badge,
body.dark .kpi-sc-chip {
  border: 1px solid rgba(71, 85, 105, 0.55);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03);
}

@media (max-width: 992px) {
  .tb-page-title,
  .page-title,
  .section-title,
  .cf-section-title,
  .sc3-title,
  .kpi-section-head .sec-lbl {
    font-size: clamp(1.2rem, 1rem + 0.6vw, 1.5rem) !important;
  }

  .cf-kpi-item {
    min-height: 148px;
    padding: 18px;
  }

  .cf-kpi-val {
    font-size: clamp(2.1rem, 1.7rem + 1vw, 2.7rem) !important;
  }

  .chart-wrap {
    min-height: 260px;
  }
}

/* ============================================================
   HOSPITAL DETAIL TABLE + CLINIC MODAL
   ============================================================ */
.hd-table-wrap {
  overflow: auto;
  border: 1px solid var(--ui-border-soft);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,250,252,.98));
  box-shadow: 0 12px 28px rgba(15,23,42,.06);
}

.hd-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1040px;
}

.hd-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%);
  color: #40566f;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .02em;
  text-transform: uppercase;
  padding: 14px 14px;
  border-bottom: 1px solid rgba(148,163,184,.25);
  white-space: nowrap;
}

.hd-table tbody td,
.hd-table tfoot td {
  padding: 14px 14px;
  border-bottom: 1px solid rgba(226,232,240,.85);
  vertical-align: middle;
}

.hd-table tbody tr {
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}

.hd-table tbody tr:hover {
  background: linear-gradient(90deg, rgba(59,130,246,.05), rgba(16,185,129,.04));
}

.hd-table tbody tr.is-clickable {
  cursor: pointer;
}

.hd-table tbody tr.is-clickable:hover td:first-child {
  box-shadow: inset 3px 0 0 #3b82f6;
}

.hd-clinic-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.hd-clinic-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--c-text);
  line-height: 1.35;
}

.hd-clinic-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--c-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hd-index-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(59,130,246,.1);
  color: #2563eb;
  font-size: 12px;
  font-weight: 800;
}

.hd-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
}

.hd-pill-opd {
  background: rgba(59,130,246,.10);
  color: #2563eb;
  border-color: rgba(59,130,246,.18);
}

.hd-pill-other {
  background: rgba(148,163,184,.12);
  color: #64748b;
  border-color: rgba(148,163,184,.2);
}

.hd-pill-online {
  background: rgba(16,185,129,.12);
  color: #059669;
  border-color: rgba(16,185,129,.18);
}

.hd-pill-offline {
  background: rgba(148,163,184,.12);
  color: #64748b;
  border-color: rgba(148,163,184,.2);
}

.hd-num {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -.02em;
  color: var(--c-text);
}

.hd-num-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--c-muted);
}

.hd-rate {
  min-width: 110px;
}

.hd-rate-value {
  font-size: 15px;
  font-weight: 900;
}

.hd-rate-track {
  margin-top: 6px;
  height: 8px;
  border-radius: 999px;
  background: rgba(226,232,240,.95);
  overflow: hidden;
}

.hd-rate-fill {
  height: 100%;
  border-radius: 999px;
}

.hd-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #2563eb;
  font-size: 12px;
  font-weight: 800;
}

.hd-table tfoot td {
  background: rgba(248,250,252,.92);
  font-weight: 700;
}

.clinic-row-modal .modal-dialog {
  max-width: min(92vw, 980px);
}

.clinic-row-modal .modal-content {
  border-radius: 22px;
  overflow: hidden;
}

.clinic-row-hero {
  padding: 22px 24px 18px;
  border-bottom: 1px solid rgba(148,163,184,.18);
  background: linear-gradient(135deg, rgba(59,130,246,.10), rgba(16,185,129,.08));
}

.clinic-row-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.2;
  color: var(--c-text);
}

.clinic-row-sub {
  margin-top: 8px;
  color: var(--c-muted);
  font-size: 13px;
}

.clinic-row-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  padding: 20px 24px 8px;
}

.clinic-row-card {
  border: 1px solid rgba(148,163,184,.18);
  border-radius: 16px;
  padding: 16px 16px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,250,252,.96));
}

.clinic-row-card-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--c-muted);
}

.clinic-row-card-value {
  margin-top: 10px;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  color: var(--c-text);
}

.clinic-row-card-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--c-muted);
}

.clinic-row-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 10px 24px 24px;
}

.clinic-row-meta-box {
  border: 1px solid rgba(148,163,184,.18);
  border-radius: 16px;
  padding: 16px 18px;
  background: rgba(248,250,252,.86);
}

.clinic-row-meta-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.clinic-row-meta-value {
  margin-top: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--c-text);
  line-height: 1.45;
}

body.dark .hd-table-wrap {
  background: linear-gradient(180deg, rgba(20,29,44,.98), rgba(16,23,36,.98));
  border-color: rgba(71,85,105,.48);
  box-shadow: 0 18px 40px rgba(2,6,23,.34);
}

body.dark .hd-table thead th {
  background: linear-gradient(180deg, #172131 0%, #131c2b 100%);
  color: #c8d6e5;
  border-bottom-color: rgba(71,85,105,.48);
}

body.dark .hd-table tbody td,
body.dark .hd-table tfoot td {
  border-bottom-color: rgba(51,65,85,.72);
  color: #e5eefb;
}

body.dark .hd-table tbody tr:hover {
  background: linear-gradient(90deg, rgba(59,130,246,.12), rgba(16,185,129,.08));
}

body.dark .hd-clinic-name,
body.dark .hd-num,
body.dark .clinic-row-title,
body.dark .clinic-row-card-value,
body.dark .clinic-row-meta-value {
  color: #f8fafc;
}

body.dark .hd-clinic-meta,
body.dark .hd-num-sub,
body.dark .clinic-row-sub,
body.dark .clinic-row-card-label,
body.dark .clinic-row-card-sub,
body.dark .clinic-row-meta-label {
  color: #9fb3ca;
}

body.dark .hd-rate-track {
  background: rgba(51,65,85,.9);
}

body.dark .hd-table tfoot td {
  background: rgba(19,28,43,.9);
}

body.dark .hd-pill-opd {
  background: rgba(59,130,246,.16);
  color: #93c5fd;
  border-color: rgba(59,130,246,.28);
}

body.dark .hd-pill-other,
body.dark .hd-pill-offline {
  background: rgba(71,85,105,.26);
  color: #c8d6e5;
  border-color: rgba(100,116,139,.28);
}

body.dark .hd-pill-online {
  background: rgba(16,185,129,.18);
  color: #6ee7b7;
  border-color: rgba(16,185,129,.28);
}

body.dark .hd-index-badge {
  background: rgba(59,130,246,.18);
  color: #93c5fd;
}

body.dark .hd-action {
  color: #93c5fd;
}

body.dark .clinic-row-hero {
  background: linear-gradient(135deg, rgba(59,130,246,.16), rgba(16,185,129,.10));
  border-bottom-color: rgba(71,85,105,.5);
}

body.dark .clinic-row-card,
body.dark .clinic-row-meta-box {
  background: linear-gradient(180deg, rgba(20,29,44,.98), rgba(16,23,36,.96));
  border-color: rgba(71,85,105,.42);
}

@media (max-width: 900px) {
  .clinic-row-grid,
  .clinic-row-meta {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .clinic-row-grid,
  .clinic-row-meta {
    grid-template-columns: 1fr;
  }
}

/* ═══════════════════════════════════════════════════════════════
   Hospital Data Tabs (mp-htab-bar)
   ═══════════════════════════════════════════════════════════════ */
.mp-htab-bar {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.mp-htab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.mp-htab:hover {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0369a1;
}
.mp-htab.active {
  background: #0369a1;
  border-color: #0369a1;
  color: #fff;
}
.mp-htab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(0,0,0,.12);
  color: inherit;
  line-height: 1;
}
.mp-htab.active .mp-htab-count {
  background: rgba(255,255,255,.25);
}
body.dark .mp-htab {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}
body.dark .mp-htab:hover {
  background: #1e3a5f;
  border-color: #38bdf8;
  color: #38bdf8;
}
body.dark .mp-htab.active {
  background: #0369a1;
  border-color: #0369a1;
  color: #fff;
}

/* ═══════════════════════════════════════════════════════════════
   Hospital Card Pagination
   ═══════════════════════════════════════════════════════════════ */
.mp-pager-wrap {
  padding: 10px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid #e2e8f0;
}
.mp-pager {
  display: flex;
  align-items: center;
  gap: 3px;
}
.mp-pg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.mp-pg-btn:hover {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0369a1;
}
.mp-pg-btn.active {
  background: #0369a1;
  border-color: #0369a1;
  color: #fff;
  font-weight: 700;
}
.mp-pg-btn:disabled,
.mp-pg-btn[disabled] {
  opacity: .4;
  cursor: not-allowed;
}
.mp-pg-dots {
  color: #94a3b8;
  font-size: 12px;
  padding: 0 2px;
  user-select: none;
}
.mp-pg-info {
  font-size: 11px;
  color: #94a3b8;
  margin-left: 8px;
  white-space: nowrap;
}
body.dark .mp-pager-wrap {
  border-top-color: rgba(71,85,105,.4);
}
body.dark .mp-pg-btn {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}
body.dark .mp-pg-btn:hover {
  background: #1e3a5f;
  border-color: #38bdf8;
  color: #38bdf8;
}
body.dark .mp-pg-btn.active {
  background: #0369a1;
  border-color: #0369a1;
  color: #fff;
}

/* ═══════════════════════════════════════════════════════════════
   Hospital Search Autocomplete
   ═══════════════════════════════════════════════════════════════ */
.mp-search-wrap input#mpSearchInput {
  width: 200px;
  padding: 5px 10px 5px 30px;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  font-size: 12px;
  background: #f8fafc;
  color: #1e293b;
  outline: none;
  transition: border-color .15s, box-shadow .15s, width .2s;
}
.mp-search-wrap input#mpSearchInput:focus {
  border-color: #0369a1;
  box-shadow: 0 0 0 2px rgba(3,105,161,.15);
  width: 240px;
  background: #fff;
}
#mpSearchDrop {
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 260px;
  max-height: 240px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 9999;
}
.mp-drop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 12px;
  color: #1e293b;
  cursor: pointer;
  transition: background .1s;
}
.mp-drop-item:hover {
  background: #f0f9ff;
  color: #0369a1;
}
.mp-drop-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mp-drop-item-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 600;
  flex-shrink: 0;
}
.mp-drop-item-tag.pao {
  background: rgba(13,148,136,.12);
  color: #0d9488;
}
.mp-drop-no-result {
  padding: 10px 14px;
  font-size: 12px;
  color: #94a3b8;
  text-align: center;
}
body.dark .mp-search-wrap input#mpSearchInput {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}
body.dark .mp-search-wrap input#mpSearchInput:focus {
  background: #0f172a;
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56,189,248,.15);
}
body.dark #mpSearchDrop {
  background: #1e293b;
  border-color: #334155;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
body.dark .mp-drop-item {
  color: #e2e8f0;
}
body.dark .mp-drop-item:hover {
  background: #1e3a5f;
  color: #38bdf8;
}

/* ═══════════════════════════════════════════════════════════════
   Search highlight animation
   ═══════════════════════════════════════════════════════════════ */
@keyframes mp-hl-pulse {
  0%   { box-shadow: none; }
  20%  { box-shadow: 0 0 0 3px rgba(3,105,161,.55), 0 0 12px rgba(3,105,161,.25); }
  60%  { box-shadow: 0 0 0 3px rgba(3,105,161,.30); }
  100% { box-shadow: none; }
}
.mp-card-hl {
  animation: mp-hl-pulse 1.8s ease forwards;
}

/* ═══════════════════════════════════════════════════════════════
   รพ.สต. teal badge
   ═══════════════════════════════════════════════════════════════ */
.map-ssj-badge-teal {
  background: rgba(13,148,136,.12);
  color: #0d9488;
  border: 1px solid rgba(13,148,136,.25);
}
body.dark .map-ssj-badge-teal {
  background: rgba(13,148,136,.18);
  color: #2dd4bf;
  border-color: rgba(13,148,136,.3);
}

/* ═══════════════════════════════════════════════════════════════
   Overview Dashboard Tabs (ov-dash-tab / ov-sub-tab)
   ═══════════════════════════════════════════════════════════════ */
.ov-dash-tabbar {
  display: flex;
  gap: 0;
  padding: 0 16px;
  background: linear-gradient(to bottom, #eff6ff, #f0f7ff);
  border-bottom: 2px solid #bfdbfe;
  margin-top: 0;
}
.ov-dash-tab {
  padding: 10px 22px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: #64748b;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s, background .15s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  line-height: 1;
}
.ov-dash-tab.active {
  color: #1e40af;
  border-bottom-color: #1d4ed8;
  background: rgba(255,255,255,.6);
}
.ov-dash-tab:hover:not(.active) {
  color: #374151;
  background: rgba(0,0,0,.03);
}

/* Booking sub-tabs */
.ov-sub-tabbar {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1.5px solid #e2e8f0;
}
.ov-sub-tab {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1.5px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, border-color .15s, color .15s;
}
.ov-sub-tab.active {
  background: #0369a1;
  border-color: #0369a1;
  color: #fff;
}
.ov-sub-tab:hover:not(.active) {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0369a1;
}
.ov-sub-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(0,0,0,.12);
}

/* Hidden class for tab system (higher specificity than sec-hidden) */
.ov-hidden { display: none !important; }

/* Dark mode */
body.dark .ov-dash-tabbar {
  background: linear-gradient(to bottom, #0f172a, #1e293b);
  border-bottom-color: #1e40af;
}
body.dark .ov-dash-tab { color: #94a3b8; }
body.dark .ov-dash-tab.active { color: #93c5fd; border-bottom-color: #3b82f6; background: rgba(255,255,255,.04); }
body.dark .ov-sub-tabbar { background: #1e293b; border-bottom-color: #334155; }
body.dark .ov-sub-tab { background: #0f172a; border-color: #334155; color: #94a3b8; }
body.dark .ov-sub-tab.active { background: #0369a1; border-color: #0369a1; color: #fff; }
body.dark .ov-sub-tab:hover:not(.active) { background: #1e3a5f; border-color: #2563eb; color: #93c5fd; }

/* ═══════════════════════════════════════════════════════════════
   Data Type Toggle (booking / tele) in topbar
   ═══════════════════════════════════════════════════════════════ */
.tb-dtype-toggle {
  display: flex;
  align-items: center;
  background: rgba(0,0,0,.07);
  border-radius: 22px;
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.06);
}
.tb-dtype-btn {
  padding: 5px 13px;
  border: none;
  border-radius: 19px;
  background: transparent;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
  line-height: 1;
}
.tb-dtype-btn.active {
  background: #fff;
  color: #1e40af;
  box-shadow: 0 1px 4px rgba(0,0,0,.14);
}
.tb-dtype-btn.active i { color: #1d4ed8; }

/* ── Hospital type dropdown dot ── */
.tb-ht-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 7px;
  flex-shrink: 0;
  vertical-align: middle;
}

/* Hospital type checkbox dropdown */
.tb-type-menu { min-width: 175px; padding-bottom: 6px; }
.tb-chk-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 12px;
  color: #374151;
  cursor: pointer;
  user-select: none;
  transition: background .1s, color .1s;
}
.tb-chk-item:hover { background: #f0f9ff; color: #0369a1; }
.tb-chk-item input[type=checkbox] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: #0369a1;
  flex-shrink: 0;
}
.tb-dd-sub-inline { font-size: 10px; color: #94a3b8; margin-left: 2px; }
.tb-dd-divider-line { height: 1px; background: #e2e8f0; margin: 3px 0; }

/* Dark mode */
body.dark .tb-dtype-toggle { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.06); }
body.dark .tb-dtype-btn { color: #94a3b8; }
body.dark .tb-dtype-btn.active { background: #1e3a5f; color: #93c5fd; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
body.dark .tb-dtype-btn.active i { color: #60a5fa; }
body.dark .tb-chk-item { color: #e2e8f0; }
body.dark .tb-chk-item:hover { background: #1e3a5f; color: #93c5fd; }
body.dark .tb-dd-divider-line { background: #334155; }
body.dark .tb-dd-sub-inline { color: #64748b; }

/* ══════════════════════════════════════════════════════════
   Home Card — วิธีคำนวณเกณฑ์ Button
   ══════════════════════════════════════════════════════════ */
.hc-calc-btn {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 0;
  padding: 10px 16px;
  border: none;
  border-top: 1px solid rgba(0,0,0,.07);
  border-radius: 0 0 18px 18px;
  font-size: clamp(12px, 1.05vw, 13.5px);
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, opacity .15s;
  letter-spacing: .02em;
}
.hc-calc-btn:hover { transform: translateY(-1px); opacity: .92; }
.hc-calc-btn:active { transform: translateY(0); }

/* per-KPI colours */
.hc-calc-moph {
  background: linear-gradient(135deg, #eef2ff, #c7d2fe);
  color: #4338ca;
  box-shadow: 0 2px 8px rgba(99,102,241,.18);
}
.hc-calc-moph:hover { box-shadow: 0 4px 14px rgba(99,102,241,.28); }

.hc-calc-tele {
  background: linear-gradient(135deg, #e0f2fe, #bae6fd);
  color: #0369a1;
  box-shadow: 0 2px 8px rgba(2,132,199,.18);
}
.hc-calc-tele:hover { box-shadow: 0 4px 14px rgba(2,132,199,.28); }

.hc-calc-ssj {
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  color: #065f46;
  box-shadow: 0 2px 8px rgba(5,150,105,.18);
}
.hc-calc-ssj:hover { box-shadow: 0 4px 14px rgba(5,150,105,.28); }

/* ══════════════════════════════════════════════════════════
   KPI Criteria Modal
   ══════════════════════════════════════════════════════════ */
.cw-kpi-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9900;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}
.cw-kpi-modal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}
.cw-kpi-modal-box {
  position: relative;
  background: #fff;
  border-radius: 20px;
  width: min(92vw, 720px);
  max-width: min(92vw, 720px);
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(15,23,42,.22), 0 4px 16px rgba(15,23,42,.10);
  transform: scale(.94) translateY(12px);
  transition: transform .25s cubic-bezier(.34,1.44,.64,1);
}
.cw-kpi-modal-overlay.visible .cw-kpi-modal-box {
  transform: scale(1) translateY(0);
}
.cw-kpi-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 10;
  background: rgba(255,255,255,.75);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  color: #64748b;
  transition: background .15s, color .15s, transform .15s;
}
.cw-kpi-modal-close:hover { background: #fff; color: #1e293b; transform: rotate(90deg); }

/* ── Tabs ── */
.cw-kpi-modal-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 14px 0;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.cw-kpi-tab {
  flex: 1;
  padding: 10px 10px;
  border: none;
  border-radius: 8px 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: #64748b;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.cw-kpi-tab:hover { background: #e2e8f0; color: #334155; }
.cw-kpi-tab-moph.active { background: #eef2ff; color: #4338ca; border-bottom: 2px solid #6366f1; }
.cw-kpi-tab-tele.active { background: #e0f2fe; color: #0369a1; border-bottom: 2px solid #0284c7; }
.cw-kpi-tab-ssj.active  { background: #d1fae5; color: #065f46; border-bottom: 2px solid #059669; }

/* ── Panel ── */
.cw-kpi-panel {
  overflow-y: auto;
  flex: 1;
}
@keyframes cwPanelIn {
  from { opacity:0; transform: translateX(10px); }
  to   { opacity:1; transform: translateX(0); }
}
.cw-panel-in { animation: cwPanelIn .2s ease forwards; }

/* ── Modal Header ── */
.cw-kpi-modal-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px 28px 20px;
  position: relative;
  overflow: hidden;
}
.cw-kpi-header-moph { background: linear-gradient(135deg, #eef2ff 0%, #c7d2fe 100%); }
.cw-kpi-header-tele { background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%); }
.cw-kpi-header-ssj  { background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%); }
.cw-kpi-header-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  color: #fff;
}
.cw-kpi-header-moph .cw-kpi-header-icon { background: linear-gradient(135deg, #6366f1, #4338ca); box-shadow: 0 6px 18px rgba(99,102,241,.35); }
.cw-kpi-header-tele .cw-kpi-header-icon { background: linear-gradient(135deg, #0284c7, #0ea5e9); box-shadow: 0 6px 18px rgba(2,132,199,.35); }
.cw-kpi-header-ssj  .cw-kpi-header-icon { background: linear-gradient(135deg, #059669, #10b981); box-shadow: 0 6px 18px rgba(5,150,105,.35); }
.cw-kpi-header-title {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
}
.cw-kpi-header-sub {
  font-size: 13px;
  color: #475569;
  margin-top: 3px;
}

/* ── Body ── */
.cw-kpi-modal-body {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Step ── */
.cw-kpi-step {
  display: flex;
  gap: 16px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 18px 20px;
  opacity: 0;
  transform: translateY(8px);
  transition: none;
}
@keyframes cwStepIn {
  from { opacity:0; transform: translateY(10px); }
  to   { opacity:1; transform: translateY(0); }
}
.cw-step-appear { animation: cwStepIn .28s ease forwards; }
.cw-kpi-step-num {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  flex-shrink: 0;
  color: #fff;
  margin-top: 1px;
}
.cw-step-moph { background: linear-gradient(135deg, #6366f1, #4338ca); }
.cw-step-tele { background: linear-gradient(135deg, #0284c7, #0ea5e9); }
.cw-step-ssj  { background: linear-gradient(135deg, #059669, #10b981); }

.cw-kpi-step-content { flex: 1; min-width: 0; }
.cw-kpi-step-title {
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 5px;
}
.cw-kpi-step-desc {
  font-size: 13px;
  color: #64748b;
  line-height: 1.5;
  margin-bottom: 12px;
}

/* ── Formula ── */
.cw-kpi-formula {
  border-radius: 12px;
  padding: 12px 16px;
  font-family: 'Roboto Mono', monospace, sans-serif;
}
.cw-formula-moph { background: rgba(99,102,241,.08); border: 1px solid rgba(99,102,241,.2); }
.cw-formula-tele { background: rgba(2,132,199,.08);  border: 1px solid rgba(2,132,199,.2);  }
.cw-formula-ssj  { background: rgba(5,150,105,.08);  border: 1px solid rgba(5,150,105,.2);  }

.cw-formula-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.cw-formula-row-simple { gap: 12px; }
.cw-formula-label {
  font-size: 13px;
  font-weight: 700;
  color: #475569;
  white-space: nowrap;
}
.cw-formula-eq {
  font-size: 15px;
  font-weight: 700;
  color: #94a3b8;
}
.cw-formula-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.cw-formula-num, .cw-formula-den {
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  line-height: 1.35;
  white-space: nowrap;
}
.cw-formula-num {
  border-bottom: 2px solid #94a3b8;
  padding-bottom: 2px;
}
.cw-formula-text {
  font-size: 13px;
  color: #334155;
}
.cw-formula-result {
  font-size: 15px;
  font-weight: 800;
  padding: 3px 11px;
  border-radius: 20px;
  margin-left: 4px;
  white-space: nowrap;
}
.cw-result-moph { background: rgba(99,102,241,.15); color: #4338ca; }
.cw-result-tele { background: rgba(2,132,199,.15);  color: #0369a1; }
.cw-result-ssj  { background: rgba(5,150,105,.15);  color: #065f46; }

.cw-formula-badge-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.cw-formula-badge {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}
.cw-badge-his   { background: rgba(5,150,105,.15); color: #065f46; border: 1px solid rgba(5,150,105,.3); }
.cw-badge-nohis { background: rgba(245,158,11,.12); color: #92400e; border: 1px solid rgba(245,158,11,.3); }

/* ── Funnel arrow ── */
.cw-kpi-funnel-arrow {
  text-align: center;
  font-size: 18px;
  color: #cbd5e1;
  margin: -4px 0;
  animation: cwArrowBounce 1.6s ease-in-out infinite;
}
@keyframes cwArrowBounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(4px); }
}

/* ── Note ── */
.cw-kpi-note {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: 10px;
  margin-top: 2px;
}
.cw-note-moph { background: rgba(99,102,241,.07); color: #4338ca; }
.cw-note-tele { background: rgba(2,132,199,.07);  color: #0369a1; }
.cw-note-ssj  { background: rgba(5,150,105,.07);  color: #065f46; }

/* ── Icon animations ── */
@keyframes cwBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  40%       { transform: translateY(-6px) scale(1.08); }
  60%       { transform: translateY(-3px) scale(1.04); }
}
.cw-bounce { animation: cwBounce 2.2s ease-in-out infinite; }

@keyframes cwPulseRing {
  0%   { box-shadow: 0 0 0 0 rgba(2,132,199,.55); }
  70%  { box-shadow: 0 0 0 10px rgba(2,132,199,0); }
  100% { box-shadow: 0 0 0 0 rgba(2,132,199,0); }
}
.cw-pulse-ring { animation: cwPulseRing 2s ease-out infinite; }

@keyframes cwSpinSlow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.cw-spin-slow { animation: cwSpinSlow 6s linear infinite; }

/* ── Dark mode ── */
body.dark .cw-kpi-modal-box { background: #1e293b; }
body.dark .cw-kpi-modal-tabs { background: #0f172a; border-color: #334155; }
body.dark .cw-kpi-tab { color: #94a3b8; }
body.dark .cw-kpi-tab:hover { background: #1e3a5f; color: #e2e8f0; }
body.dark .cw-kpi-tab-moph.active { background: #1e1b4b; color: #a5b4fc; border-color: #818cf8; }
body.dark .cw-kpi-tab-tele.active { background: #0c2240; color: #7dd3fc; border-color: #38bdf8; }
body.dark .cw-kpi-tab-ssj.active  { background: #064e3b; color: #6ee7b7; border-color: #34d399; }
body.dark .cw-kpi-header-title { color: #f1f5f9; }
body.dark .cw-kpi-header-sub { color: #94a3b8; }
body.dark .cw-kpi-header-moph { background: linear-gradient(135deg, #1e1b4b, #312e81); }
body.dark .cw-kpi-header-tele { background: linear-gradient(135deg, #0c2240, #164e63); }
body.dark .cw-kpi-header-ssj  { background: linear-gradient(135deg, #064e3b, #065f46); }
body.dark .cw-kpi-step { background: #0f172a; border-color: #334155; }
body.dark .cw-kpi-step-title { color: #f1f5f9; }
body.dark .cw-kpi-step-desc { color: #94a3b8; }
body.dark .cw-formula-moph { background: rgba(99,102,241,.12); border-color: rgba(99,102,241,.25); }
body.dark .cw-formula-tele { background: rgba(2,132,199,.12);  border-color: rgba(2,132,199,.25);  }
body.dark .cw-formula-ssj  { background: rgba(5,150,105,.12);  border-color: rgba(5,150,105,.25);  }
body.dark .cw-formula-label { color: #94a3b8; }
body.dark .cw-formula-num, body.dark .cw-formula-den { color: #e2e8f0; }
body.dark .cw-formula-text { color: #e2e8f0; }
body.dark .cw-formula-eq { color: #475569; }
body.dark .cw-result-moph { background: rgba(99,102,241,.2); color: #a5b4fc; }
body.dark .cw-result-tele { background: rgba(2,132,199,.2);  color: #7dd3fc; }
body.dark .cw-result-ssj  { background: rgba(5,150,105,.2);  color: #6ee7b7; }
body.dark .cw-note-moph { background: rgba(99,102,241,.12); color: #a5b4fc; }
body.dark .cw-note-tele { background: rgba(2,132,199,.12);  color: #7dd3fc; }
body.dark .cw-note-ssj  { background: rgba(5,150,105,.12);  color: #6ee7b7; }
body.dark .cw-kpi-modal-close { background: rgba(15,23,42,.75); border-color: #334155; color: #94a3b8; }
body.dark .cw-kpi-modal-close:hover { background: #334155; color: #f1f5f9; }
body.dark .cw-kpi-funnel-arrow { color: #334155; }
body.dark .cw-formula-num { border-color: #475569; }
body.dark .hc-calc-moph { background: linear-gradient(135deg, #1e1b4b, #312e81); color: #a5b4fc; }
body.dark .hc-calc-tele { background: linear-gradient(135deg, #0c2240, #164e63); color: #7dd3fc; }
body.dark .hc-calc-ssj  { background: linear-gradient(135deg, #064e3b, #065f46); color: #6ee7b7; }
