/* MERS-CoV Dashboard — visual overhaul layer.
 * Bootstrap/bslib handles base theming; this file adds gradients,
 * custom components (filter bar, status badges, sample progress bars,
 * section headers) and DT/dark-mode overrides that bslib can't reach.
 */
:root {
  --mers-heading-font: "Lexend", var(--bs-body-font-family), sans-serif;
  --mers-topbar-h:    50px;   /* branded header bar height */
  --mers-mainnav-h:   52px;   /* horizontal tab nav height */
}

/* ---- Page background ---- */
body {
  background-color: #f4f5f8;
}
[data-bs-theme="dark"] body {
  background-color: #15171a;
}

/* ---- Branded top bar (replaces bslib page_navbar title bar) ---- */
.mers-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  height: var(--mers-topbar-h, 50px);
  background: linear-gradient(100deg, #981E32 0%, #6e1424 100%);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.22);
}
.mers-brand {
  font-family: var(--mers-heading-font);
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}

/* ---- Horizontal top navigation bar (main tab switcher) ----
 * Sticks below the top bar; the .nav strip scrolls horizontally so all
 * tabs remain accessible on narrow viewports without wrapping. */
.mers-mainnav > .tabbable > ul.nav {
  position: sticky;
  top: var(--mers-topbar-h, 50px);
  z-index: 1015;
  background: #fff;
  border-bottom: 1px solid rgba(0,0,0,.09);
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
  margin: 0 !important;
  padding: 0 1.25rem;
  min-height: var(--mers-mainnav-h, 52px);
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 0.15rem;
  scrollbar-width: none;
}
.mers-mainnav > .tabbable > ul.nav::-webkit-scrollbar { display: none; }

[data-bs-theme="dark"] .mers-mainnav > .tabbable > ul.nav {
  background: #1a1d21;
  border-bottom-color: rgba(255,255,255,.09);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.mers-mainnav > .tabbable > ul.nav .nav-link {
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.45rem 1rem;
  white-space: nowrap;
  color: var(--bs-body-color);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: none;
  transition: background 0.15s, color 0.15s;
}
.mers-mainnav > .tabbable > ul.nav .nav-link:hover {
  background: rgba(152,30,50,.09);
  color: #981e32;
}
.mers-mainnav > .tabbable > ul.nav .nav-link.active {
  background: #981e32;
  color: #fff;
}
[data-bs-theme="dark"] .mers-mainnav > .tabbable > ul.nav .nav-link {
  color: rgba(255,255,255,.8);
}
[data-bs-theme="dark"] .mers-mainnav > .tabbable > ul.nav .nav-link:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}
[data-bs-theme="dark"] .mers-mainnav > .tabbable > ul.nav .nav-link.active {
  background: #981e32;
  color: #fff;
}

/* Tab content area — full width, comfortable padding */
.mers-mainnav > .tabbable > .tab-content {
  padding: 1.25rem 1.5rem;
  min-height: calc(100vh - var(--mers-topbar-h, 50px) - var(--mers-mainnav-h, 52px));
}

/* ---- Sub-tabs (multi-arm tabs within each setting panel) ----
 * Sticky beneath topbar + main nav so the arm switcher stays reachable
 * while scrolling a long panel. */
.mers-subtabs .tabbable > .nav-pills {
  margin-bottom: 1.25rem;
  gap: 0.4rem;
  position: sticky;
  top: calc(var(--mers-topbar-h, 50px) + var(--mers-mainnav-h, 52px));
  z-index: 1010;
  background: #f4f5f8;
  padding: 0.6rem 0;
}
[data-bs-theme="dark"] .mers-subtabs .tabbable > .nav-pills {
  background: #15171a;
}
.mers-subtabs .nav-pills .nav-link {
  border-radius: 999px;
  font-weight: 500;
  padding: 0.45rem 1.1rem;
}
.mers-subtabs .nav-pills .nav-link.active {
  background: var(--bs-primary);
  color: #fff;
}

/* ---- Activity tabs (enrollment records by arm) ---- */
.mers-activity-tabs .nav-pills { gap: 0.35rem; flex-wrap: wrap; }
.mers-activity-tabs .nav-pills .nav-link {
  border-radius: 999px;
  font-weight: 500;
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
}
.mers-activity-tabs .nav-pills .nav-link.active {
  background: var(--bs-primary);
  color: #fff;
}

/* ---- Card polish ---- */
.card {
  background-color: #fff;
  border: 1px solid rgba(0,0,0,.05);
  border-radius: 0.9rem;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
[data-bs-theme="dark"] .card {
  background-color: #1e2125;
  border-color: rgba(255,255,255,.08);
}
.card:not(.border-warning):not(.border-danger):not(.border-info):hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0,0,0,.1);
}
.card-header {
  font-family: var(--mers-heading-font);
  font-weight: 600;
  border-bottom: 1px solid rgba(0,0,0,.06);
  background: transparent;
}

/* ---- Icon badges (card headers) ---- */
.mers-icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.6rem;
  background: rgba(152,30,50,.08);
  color: var(--bs-primary);
  flex-shrink: 0;
}
[data-bs-theme="dark"] .mers-icon-badge {
  background: rgba(255,255,255,.08);
}

/* ---- Arm description banner (sub-arm subtitle) ---- */
.mers-arm-description {
  background: rgba(152,30,50,.04);
  border-left: 3px solid var(--bs-primary);
  border-radius: 0 0.5rem 0.5rem 0;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  color: var(--bs-secondary-color, #6c757d);
  line-height: 1.5;
}
[data-bs-theme="dark"] .mers-arm-description {
  background: rgba(255,255,255,.04);
}

/* ---- Mini chart subtitle (e.g. "Sex distribution" above a donut) ---- */
.mers-chart-subtitle {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--bs-secondary-color, #6c757d);
}

/* ---- Reduce bslib layout_column_wrap bottom gap between sections ---- */
.bslib-gap-spacing {
  row-gap: 0.75rem !important;
}

/* ---- Section divider headers ---- */
.mers-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 1.25rem 0 0.75rem;
  padding-left: 0.5rem;
  border-left: 4px solid var(--bs-primary);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--bs-body-color);
}

/* ---- Status badges (enrollment pace vs target) ---- */
.mers-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.mers-badge-on-track  { background: #d1fae5; color: #065f46; }
.mers-badge-lagging   { background: #fef3c7; color: #92400e; }
.mers-badge-attention { background: #fee2e2; color: #991b1b; }
.mers-badge-complete  { background: #dbeafe; color: #1e40af; }
.mers-badge-neutral   { background: rgba(0,0,0,.06); color: #495057; }
[data-bs-theme="dark"] .mers-badge-on-track  { background: #064e3b; color: #6ee7b7; }
[data-bs-theme="dark"] .mers-badge-lagging   { background: #78350f; color: #fcd34d; }
[data-bs-theme="dark"] .mers-badge-attention { background: #7f1d1d; color: #fca5a5; }
[data-bs-theme="dark"] .mers-badge-complete  { background: #1e3a8a; color: #93c5fd; }

/* ---- Card footer (figure/table caption area) ---- */
.card-footer {
  background: transparent;
  border-top: 1px solid rgba(0,0,0,.05);
  padding: 0.45rem 1rem 0.55rem;
  font-size: 0.78rem;
  color: var(--bs-secondary-color, #6c757d);
}
[data-bs-theme="dark"] .card-footer {
  border-top-color: rgba(255,255,255,.06);
}

/* ---- Value-box gradient tiles ---- */
/* ---- KPI tiles ----
 * These were six fully-saturated gradient blocks with a radial gloss and a
 * lift-on-hover. The problem wasn't taste, it was meaning: every tile got a
 * different colour purely for decoration, which teaches the reader that
 * colour on this page is ornamental — immediately before the charts below
 * start using colour to encode arm, sex and collection status. A KPI strip
 * that shouts also flattens the hierarchy: the numbers are the content, and
 * they were competing with their own backgrounds.
 *
 * Now: a quiet surface tile with the number in text ink, and a 3px accent
 * rail carrying the only colour. The --vb-accent hue still distinguishes
 * tiles, but it's subordinate to the figure. Class names are unchanged so
 * no R module needed touching. */
.vb-gradient {
  --vb-accent: #981e32;
  border: 1px solid rgba(0,0,0,.06);
  border-left: 3px solid var(--vb-accent);
  border-radius: 0.75rem;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
  color: var(--bs-body-color);
  position: relative;
  overflow: hidden;
  min-height: 108px;
}
.vb-gradient:hover {
  box-shadow: 0 4px 14px rgba(0,0,0,.09);
}
[data-bs-theme="dark"] .vb-gradient {
  background: #1e2125;
  border-color: rgba(255,255,255,.09);
  border-left-color: var(--vb-accent);
}

/* Accent hues. Light and dark values are the validated categorical/status
 * steps for each surface — see R/theme.R; keep the two in sync. */
.vb-gradient-primary { --vb-accent: #981e32; }
.vb-gradient-info    { --vb-accent: #2a78d6; }
.vb-gradient-success { --vb-accent: #0ca30c; }
.vb-gradient-neutral { --vb-accent: #8a8a85; }
.vb-gradient-warning { --vb-accent: #fab219; }
.vb-gradient-danger  { --vb-accent: #d03b3b; }
[data-bs-theme="dark"] .vb-gradient-primary { --vb-accent: #c5405a; }
[data-bs-theme="dark"] .vb-gradient-info    { --vb-accent: #2e7bda; }

.vb-gradient .value-box-title {
  font-weight: 500;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--bs-secondary-color, #6c757d);
}
.vb-gradient .value-box-value {
  font-family: var(--mers-heading-font);
  font-weight: 700;
  /* Tabular figures stop the number jittering sideways when a background
   * refresh changes a digit — the count updates in place. */
  font-variant-numeric: tabular-nums;
  font-size: 2.1rem;
  line-height: 1.15;
  color: var(--bs-emphasis-color, #212529);
}
.vb-sub {
  font-size: 0.78rem;
  color: var(--bs-secondary-color, #6c757d);
  font-weight: 500;
}
/* The showcase icon is decoration, not data — keep it recessive and let it
 * carry the tile's accent hue rather than sitting in full-strength ink. */
.vb-gradient .bslib-value-box-showcase,
.vb-gradient .bslib-value-box-showcase .bi,
.vb-gradient .bslib-value-box-showcase .fa,
.vb-gradient .bslib-value-box-showcase svg {
  color: var(--vb-accent);
  opacity: 0.55;
}

/* ---- Data freshness pill (top bar) ----
 * The dashboard now refreshes silently in the background, so this is the
 * only cue that the numbers are live. Colour alone never carries the state
 * — the pill always spells out "Live" / "Delayed" / "Stale" in text. */
.mers-freshness {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  background: rgba(255,255,255,.14);
  color: rgba(255,255,255,.95);
  cursor: default;
}
.mers-freshness-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.mers-freshness-live .mers-freshness-dot {
  background: #5ce65c;
  animation: mers-pulse 2.4s ease-in-out infinite;
}
.mers-freshness-lagging .mers-freshness-dot { background: #fab219; }
.mers-freshness-stale   .mers-freshness-dot { background: #ff8a8a; }
.mers-freshness-stale   { background: rgba(208,59,59,.35); }

@keyframes mers-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}
/* Respect users who've asked the OS for less motion. */
@media (prefers-reduced-motion: reduce) {
  .mers-freshness-live .mers-freshness-dot { animation: none; }
}

/* Hide the freshness label on narrow screens; the dot still reports state
 * and the title attribute still explains it. */
@media (max-width: 640px) {
  .mers-freshness-label { display: none; }
  .mers-freshness { padding: 0.3rem; }
}

.mers-sites-list {
  opacity: 0.85;
  font-size: 0.72rem;
  line-height: 1.3;
  white-space: normal;
}
/* Showcase icon chip. Tinted with the tile's own accent via colour-mix so
 * it stays legible on both surfaces without a second hardcoded palette. */
.vb-gradient .bslib-value-box-showcase {
  font-size: 1.15rem;
  background: color-mix(in srgb, var(--vb-accent) 12%, transparent);
  border-radius: 0.7rem;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Sample progress bars (specimen collection vs target) ---- */
.mers-sample-grid {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.25rem 0;
}
.mers-sample-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.mers-sample-icon {
  width: 2rem;
  text-align: center;
  color: var(--bs-primary);
  flex-shrink: 0;
  font-size: 1.1rem;
}
.mers-sample-body {
  flex: 1;
}
.mers-sample-label {
  font-weight: 600;
  font-size: 0.9rem;
}
.mers-sample-fraction {
  font-size: 0.9rem;
}
.mers-sample-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(0,0,0,.08);
}
.mers-sample-bar .progress-bar {
  border-radius: 999px;
  transition: width 0.5s ease;
}

/* ---- Segmented progress bar (screening/consent funnel) ---- */
.mers-funnel { display: flex; flex-direction: column; gap: 0.75rem; }
.mers-funnel-bar {
  display: flex;
  width: 100%;
  height: 0.85rem;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(0,0,0,.06);
}
.mers-funnel-segment { height: 100%; transition: width 0.4s ease; }
.mers-funnel-pills { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.mers-stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  background: rgba(0,0,0,.045);
}
[data-bs-theme="dark"] .mers-stat-pill { background: rgba(255,255,255,.08); }
.mers-stat-pill .mers-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ---- Circular progress ring (legacy follow-up panel) ---- */
.mers-progress-ring-wrap { display: flex; align-items: center; gap: 1.25rem; }
.mers-progress-ring {
  --mers-pct: 0;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  flex-shrink: 0;
  background: conic-gradient(var(--bs-primary) calc(var(--mers-pct) * 1%), rgba(0,0,0,.08) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.mers-progress-ring::before {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: var(--bs-card-bg, #fff);
}
[data-bs-theme="dark"] .mers-progress-ring::before { background: #1e2125; }
.mers-progress-ring-label {
  position: relative;
  font-family: var(--mers-heading-font);
  font-weight: 700;
  font-size: 1.2rem;
}
.mers-progress-caption { font-size: 0.88rem; color: var(--bs-secondary-color, #6c757d); margin: 0; }

/* ---- Record detail modal (click any table row) ---- */
.mers-record-modal-header {
  margin: -1rem -1rem 0;
  padding: 1rem 1.25rem;
  border-radius: 0.5rem 0.5rem 0 0;
  color: #fff;
}
.modal-body dl.row dt {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--bs-secondary-color, #6c757d);
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
}
.modal-body dl.row dd {
  font-size: 0.92rem;
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(0,0,0,.05);
}
[data-bs-theme="dark"] .modal-body dl.row dd { border-bottom-color: rgba(255,255,255,.06); }
table.dataTable tbody tr { cursor: pointer; }

/* ---- DT table polish ---- */
table.dataTable thead th {
  font-weight: 600;
  border-bottom: 2px solid var(--bs-primary);
}
table.dataTable.hover tbody tr:hover,
table.dataTable.stripe tbody tr.odd {
  background-color: rgba(152,30,50,.035);
}
[data-bs-theme="dark"] table.dataTable thead th {
  background-color: #2b1218;
  color: #fff;
}

/* ---- Progress Report / Admin tab period toggle ---- */
.mers-period-toggle .shiny-options-group {
  display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0;
}
.mers-period-toggle .shiny-options-group label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin: 0;
  padding: 0.35rem 1.1rem;
  border-radius: 999px;
  border: 1.5px solid var(--bs-primary);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--bs-primary);
  background: transparent;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}
.mers-period-toggle .shiny-options-group label:hover {
  background: color-mix(in srgb, var(--bs-primary) 10%, transparent);
}
.mers-period-toggle .shiny-options-group input[type="radio"] { display: none; }
.mers-period-toggle .shiny-options-group label:has(input[type="radio"]:checked) {
  background: var(--bs-primary);
  color: #fff;
  border-color: var(--bs-primary);
}

/* ---- Login screen ---- */
.mers-login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    linear-gradient(160deg, rgba(46,15,22,.72) 0%, rgba(152,30,50,.55) 100%),
    url("img.png") center / cover no-repeat;
}
.mers-login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 0.75rem;
  box-shadow: 0 16px 50px rgba(0,0,0,.35);
  padding: 2rem 2rem 1.75rem;
}
[data-bs-theme="dark"] .mers-login-card {
  background: #1e2126;
}
.mers-login-title {
  font-family: var(--mers-heading-font);
  color: var(--bs-primary);
  font-weight: 700;
  font-size: 1.15rem;
  margin-bottom: 1.5rem;
}
.mers-login-field { margin-bottom: 1.1rem; }
.mers-login-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: #6c757d;
  margin-bottom: 0.35rem;
}
.mers-login-card .form-control {
  border-radius: 0.4rem;
  padding: 0.55rem 0.75rem;
}
.mers-login-btn {
  background: linear-gradient(100deg, var(--bs-primary) 0%, #6e1726 100%);
  border: none;
  color: #fff;
  font-weight: 600;
  padding: 0.6rem 1rem;
  border-radius: 0.4rem;
  margin-top: 0.25rem;
}
.mers-login-btn:hover { filter: brightness(1.08); color: #fff; }
.mers-login-error {
  color: var(--bs-danger);
  font-size: 0.825rem;
  margin: -0.5rem 0 0.85rem;
}

/* ---- Post-login loading overlay ---- */
.mers-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 8, 12, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.mers-loading-overlay.show {
  opacity: 1;
  pointer-events: all;
}
.mers-loading-spinner {
  width: 56px;
  height: 56px;
  border: 5px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: mers-spin .8s linear infinite;
}
@keyframes mers-spin { to { transform: rotate(360deg); } }

/* ---- Slide-deck nav for expanded chart cards ---- */
.mers-deck-nav {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(31, 8, 12, 0.85);
  border-radius: 999px;
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 2100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}
.mers-deck-nav.show {
  opacity: 1;
  pointer-events: all;
  transform: translateX(-50%) translateY(0);
}
.mers-deck-btn {
  background: rgba(255,255,255,.14);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.mers-deck-btn:hover:not(:disabled) { background: rgba(255,255,255,.26); }
.mers-deck-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.mers-deck-btn.mers-deck-close { background: #981E32; }
.mers-deck-btn.mers-deck-close:hover { filter: brightness(1.15); }
.mers-deck-counter {
  color: #fff;
  font-size: 0.8rem;
  min-width: 3.4rem;
  text-align: center;
}
