:root {
  /* MOH dashboard palette */
  --bg:           #0E1015;
  --bg-deep:      #07080a;
  --card:         #15181E;
  --card-border:  #507E71;
  --panel:        rgba(15, 22, 18, 0.96);

  --text:    #f4f7f5;
  --muted:   #8aa19a;

  --green-saudi:  #008755;
  --green-band:   #318669;
  --green-deep:   #052e1c;
  --accent-soft:  #F0B323;
  --accent-pale:  #D8D382;
  --teal:         #14B8A6;
  --teal-bright:  #00C0BB;
  --red:          #C8102E;

  --status-complete:   #16a34a;
  --status-partial:    #F0B323;
  --status-deficient:  #f97316;
  --status-incomplete: #dc2626;
  --status-unknown:    #6b7280;

  --topbar-h:    104px;
  --side-w:      400px;       /* widened in v7 for reason labels */
  --strip-w:     56px;

  --radius:      10px;
  --shadow:      0 12px 32px -8px rgba(0, 0, 0, 0.55);

  --pattern:     url("assets/pattern.png");
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-columns: 1fr var(--strip-w);
  grid-template-areas:
    "topbar topbar"
    "map    rstrip";
}
body[data-panel-open="true"] {
  grid-template-columns: 1fr var(--side-w) var(--strip-w);
  grid-template-areas:
    "topbar topbar topbar"
    "map    panel  rstrip";
}
body[data-panel-open="false"] #panel { display: none; }

/* ============================================================
   TOPBAR — single band matching Frame 1171275504.svg
   ============================================================ */
.topbar {
  grid-area: topbar;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 0 18px;
  background: var(--green-band);
  border-bottom: 2px solid var(--green-saudi);
  color: #fff;
  position: relative;
  z-index: 1000;
  gap: 16px;
  overflow: hidden;
}

.topbar-side {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
}
.topbar-side--start { justify-content: flex-start; }
.topbar-side--end   { justify-content: flex-end; }

.brand-logo {
  display: block;
  height: 64px;
  width: auto;
  object-fit: contain;
  opacity: 0.95;
}
.brand-logo--midani   { height: 56px; }
.brand-logo--building { height: 64px; }
.brand-logo--moh      { height: 70px; }

.brand-text {
  text-align: end;
  min-width: 0;
  margin-inline-end: 6px;
}
.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-soft);
  letter-spacing: 0.01em;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.brand-sub {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 2px;
}

.topbar-centre {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.filterbar {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-wrap: wrap;
  justify-content: center;
}

/* Pill-style dropdowns — yellow border + chevron, matches the SVG dropdowns. */
.pill-select {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 4px 10px;
  min-width: 124px;
  background: rgba(0, 0, 0, 0.32);
  border: 1.5px solid var(--accent-soft);
  border-radius: 10px;
  cursor: pointer;
}
.pill-label {
  font-size: 0.7rem;
  color: var(--accent-soft);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.pill-select select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  color: #fff;
  font: inherit;
  font-size: 0.88rem;
  padding: 0;
  padding-inline-end: 18px;     /* room for chevron */
  cursor: pointer;
  outline: none;
}
.pill-select::after {
  content: "▾";
  position: absolute;
  inset-inline-start: 10px;     /* in RTL this puts the chevron at the visual-left of the pill */
  bottom: 10px;
  color: var(--accent-soft);
  font-size: 0.85rem;
  pointer-events: none;
}
.pill-select select option {
  background: var(--card);
  color: var(--text);
}

/* Audio toggle keeps a slightly different visual so it doesn't read as another filter pill. */
.audio-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
  border: 1.5px solid rgba(255, 255, 255, 0.30);
  color: #fff;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  align-self: center;
}
.audio-toggle:hover { background: rgba(0, 0, 0, 0.5); }
body[data-audio-enabled="true"] .audio-toggle {
  background: var(--accent-soft);
  color: #1a1500;
  border-color: var(--accent-soft);
}

/* ============================================================
   PATTERN STRIP
   ============================================================ */
.pattern-strip {
  grid-area: rstrip;
  background-color: var(--bg-deep);
  background-image: var(--pattern);
  background-size: 56px 72px;
  background-repeat: repeat;
  border-inline-start: 1px solid rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.55);
}

/* ============================================================
   MAP + PINS
   ============================================================ */
#map {
  grid-area: map;
  background: #0d1310;
}

.pin-wrap { background: transparent; border: 0; }
.pin-wrap .pin-svg { position: relative; z-index: 2; }

/* Heat-radius rings — gradient color + size based on pressure tier.
   The radial-gradient inside each ring gives the smooth "heatmap" feel
   without needing a CSS animation for the color stops themselves.
   Only the "high" tier (pressure ≥ 2) actually pulses. */
.pulse-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
  animation: none;
}

/* No submissions yet → no ring. */
.pressure-unknown .pulse-ring { display: none; }

/* < 0.5 patients/employee — calm. Dark green, smallest. Static. */
.pressure-low .pulse-ring {
  inset: -18px;
  background: radial-gradient(circle,
    rgba(22, 101, 52, 0.65) 0%,
    rgba(22, 101, 52, 0.35) 45%,
    rgba(22, 101, 52, 0) 75%);
}

/* 0.5 – < 2 — moderate. Yellow center → orange edge → fades into red.
   Larger than low so the radius itself signals rising pressure. Static. */
.pressure-mid .pulse-ring {
  inset: -38px;
  background: radial-gradient(circle,
    rgba(250, 204, 21, 0.65) 0%,    /* yellow core */
    rgba(249, 115, 22, 0.45) 40%,   /* orange */
    rgba(220, 38, 38, 0.18) 70%,    /* red, low alpha */
    rgba(220, 38, 38, 0) 100%);
}

/* ≥ 2 — critical. Bright red, largest, pulsing. */
.pressure-high .pulse-ring {
  inset: -62px;
  background: radial-gradient(circle,
    rgba(220, 38, 38, 0.92) 0%,
    rgba(220, 38, 38, 0.50) 35%,
    rgba(220, 38, 38, 0) 75%);
  /* User requested: no pulsing animation on red tier. Keep the static glow. */
  animation: none;
}

@keyframes heat-pulse {
  0%, 100% { transform: scale(1);    opacity: 0.95; }
  50%      { transform: scale(1.35); opacity: 0.25; }
}

.pin-wrap .ping-flash {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid #22d3ee;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.4) 0%, rgba(34, 211, 238, 0) 70%);
  pointer-events: none;
  opacity: 0;
  z-index: 3;
}
.pin-wrap.pinged .ping-flash { animation: ping-flash 1.2s ease-out; }
@keyframes ping-flash {
  0%   { transform: scale(0.6); opacity: 0; }
  20%  { transform: scale(1.0); opacity: 0.9; }
  100% { transform: scale(2.4); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .pulse-ring, .pin-wrap.pinged .ping-flash { animation: none; }
  .pulse-ring { opacity: 0.5; }
}

.pin-wrap.selected .pin-svg {
  filter: drop-shadow(0 0 6px var(--accent-soft));
  transform: translateY(-2px);
}

/* ============================================================
   DASHBOARD PANEL
   ============================================================ */
.panel {
  grid-area: panel;
  background: var(--card);
  border-inline-start: 1px solid var(--card-border);
  border-inline-end: 1px solid var(--card-border);
  padding: 14px 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  font-size: 0.92rem;
  scrollbar-width: thin;
  scrollbar-color: var(--card-border) transparent;
}
.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 4px; }

.panel-head {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--card-border);
}
.panel-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-soft);
}
.panel-sub { font-size: 0.78rem; color: var(--muted); }
.back-btn {
  align-self: flex-start;
  background: rgba(0, 0, 0, 0.32);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.30);
  border-radius: 8px;
  padding: 4px 10px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.back-btn[hidden] { display: none; }
.back-btn:hover { background: rgba(0, 0, 0, 0.5); }

.status-badge {
  align-self: flex-start;
  margin-top: 4px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  background: var(--status-unknown);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.panel-section { display: flex; flex-direction: column; gap: 8px; }
.panel-section-title {
  font-size: 0.82rem;
  color: var(--accent-pale);
  margin: 0;
  font-weight: 600;
}

.chart-host {
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 80px;
}

/* 24h hourly bar chart for توزيع الحالات */
.hour-chart {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  grid-auto-rows: 64px;
  gap: 3px;
  align-items: end;
  padding: 10px;
}
.hour-bar {
  position: relative;
  height: 100%;
  display: flex;
  align-items: end;
}
.hour-bar > span {
  display: block;
  width: 100%;
  background: var(--status-unknown);
  border-radius: 2px 2px 0 0;
  transition: height 0.25s ease;
}
.hour-bar[title]:hover > span { filter: brightness(1.2); }
.hour-bar.bar-complete   > span { background: var(--status-complete); }
.hour-bar.bar-partial    > span { background: var(--status-partial); }
.hour-bar.bar-deficient  > span { background: var(--status-deficient); }
.hour-bar.bar-incomplete > span { background: var(--status-incomplete); }
.hour-bar.bar-empty      > span { background: rgba(255, 255, 255, 0.06); }

.hour-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.72rem;
  color: var(--muted);
  padding-inline-start: 4px;
}
.hl-item { display: inline-flex; align-items: center; gap: 4px; }
.hl-item i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* Operations pressure — coloured badge instead of two number cards */
.pressure-badge {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  padding: 18px 14px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--card-border);
  color: #fff;
  font-weight: 700;
}
.pressure-text {
  font-size: 1.5rem;
  letter-spacing: 0.02em;
}
.pressure-meta {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
}
.pressure-badge.pressure-low {
  background: linear-gradient(135deg, rgba(22, 163, 74, 0.18), rgba(20, 184, 166, 0.10));
  border-color: var(--status-complete);
  color: var(--status-complete);
}
.pressure-badge.pressure-mid {
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.20), rgba(240, 179, 35, 0.12));
  border-color: var(--status-deficient);
  color: var(--status-deficient);
}
.pressure-badge.pressure-high {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.28), rgba(220, 38, 38, 0.12));
  border-color: var(--status-incomplete);
  color: #fca5a5;
}
.pressure-badge.pressure-unknown {
  color: var(--muted);
}
.pressure-badge .pressure-meta {
  color: inherit;
  opacity: 0.85;
}

/* الأسباب — wider label column, wrap long reasons */
.bar-row {
  display: grid;
  grid-template-columns: 1fr 90px 28px;   /* label takes the rest; track 90px; value tiny */
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}
.bar-row + .bar-row { margin-top: 5px; }
.bar-row .bar-label {
  color: var(--text);
  text-align: end;
  white-space: normal;       /* wrap long reasons */
  line-height: 1.25;
  word-break: break-word;
}
.bar-row .bar-track {
  height: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  position: relative;
}
.bar-row .bar-fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  border-radius: 4px;
  background: var(--accent-soft);
}
.bar-row .bar-value {
  font-variant-numeric: tabular-nums;
  color: var(--accent-pale);
  text-align: start;
  font-weight: 700;
}

/* ============================================================
   SYNC BUTTON — sits at the end of the filter row
   ============================================================ */
.sync-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.32);
  border: 1.5px solid var(--accent-soft);
  color: var(--accent-soft);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  align-self: center;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.sync-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  color: #1a1500;
}
.sync-btn:disabled { cursor: progress; opacity: 0.85; }
.sync-btn.busy   { background: var(--accent-soft); color: #1a1500; }
.sync-btn.ok     { background: var(--status-complete); color: #fff; border-color: var(--status-complete); }
.sync-btn.failed { background: var(--status-incomplete); color: #fff; border-color: var(--status-incomplete); }
.sync-btn .sync-icon { display: block; width: 16px; height: 16px; }
.sync-btn.busy .sync-icon { animation: sync-spin 1s linear infinite; }
@keyframes sync-spin {
  from { transform: rotate(0); }
  to   { transform: rotate(360deg); }
}

/* ============================================================
   THRESHOLDS — hidden gear + popover (bottom-left of the map)
   ============================================================ */
/* User requested: move to bottom-right visually (was bottom-left), keep visible.
   In RTL, inset-inline-start = visual right. Removed the low-opacity hidden style. */
.thresholds-btn {
  position: fixed;
  bottom: 14px;
  inset-inline-start: 14px;
  z-index: 1001;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(15, 22, 18, 0.92);
  color: var(--accent-soft);
  border: 1px solid var(--card-border);
  cursor: pointer;
  opacity: 1;
  transition: transform 0.2s, background 0.2s;
  display: grid;
  place-items: center;
  padding: 0;
  box-shadow: 0 6px 16px -4px rgba(0, 0, 0, 0.45);
}
.thresholds-btn:hover { background: rgba(49, 134, 105, 0.9); transform: scale(1.08); }

.thresholds-popover {
  position: fixed;
  bottom: 60px;
  inset-inline-start: 14px;
  z-index: 1002;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 280px;
  max-width: 320px;
  box-shadow: 0 16px 36px -12px rgba(0, 0, 0, 0.6);
  color: var(--text);
}
.thresholds-popover[hidden] { display: none; }

.th-pop-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid var(--card-border);
}
.th-pop-head h4 { margin: 0; color: var(--accent-soft); font-size: 0.95rem; }
.th-close {
  background: transparent; color: var(--muted); border: 0;
  font-size: 1.4rem; cursor: pointer; padding: 0 6px;
  line-height: 1;
}
.th-close:hover { color: var(--text); }

.th-row { margin-top: 12px; }
.th-row .th-label {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 0.78rem; color: var(--muted);
}
.th-row .th-label .th-val {
  font-variant-numeric: tabular-nums;
  color: var(--accent-soft); font-weight: 700; font-size: 0.95rem;
}
.th-row input[type="range"] {
  width: 100%; margin-top: 6px;
  accent-color: var(--accent-soft);
}

.th-reset {
  margin-top: 14px; width: 100%;
  padding: 6px 10px; background: rgba(0,0,0,0.32);
  color: var(--text); border: 1px solid var(--card-border);
  border-radius: 8px; font: inherit; font-size: 0.82rem;
  cursor: pointer;
}
.th-reset:hover { background: rgba(0,0,0,0.5); }

/* ============================================================
   LEAFLET CONTROLS
   ============================================================ */
.leaflet-control-layers {
  background: var(--card) !important;
  color: var(--text);
  border: 1px solid var(--card-border) !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow);
}
.leaflet-control-layers-expanded { padding: 10px 12px; }
.leaflet-control-layers label { font-size: 0.88rem; }
.leaflet-control-attribution { display: none !important; }
.leaflet-control-zoom a {
  background: var(--card) !important;
  color: var(--text) !important;
  border-color: var(--card-border) !important;
}

/* ============================================================
   MOBILE (last-pass)
   ============================================================ */
@media (max-width: 768px) {
  :root { --topbar-h: 168px; --side-w: 100vw; }
  body,
  body[data-panel-open="true"] {
    grid-template-rows: var(--topbar-h) auto 1fr;
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "map";
  }
  .topbar { grid-template-columns: auto 1fr auto; gap: 8px; padding: 0 10px; }
  .topbar-side { padding: 4px 0; gap: 6px; }
  .brand-logo { height: 34px; }
  .brand-logo--midani { height: 32px; }
  .brand-logo--moh    { height: 38px; }
  .brand-logo--building { height: 34px; }
  .brand-title { font-size: 0.95rem; }
  .brand-sub { font-size: 0.65rem; }
  .filterbar { gap: 6px; }
  .pill-select { min-width: 96px; padding: 3px 8px; }
  .pill-label { font-size: 0.62rem; }
  .pill-select select { font-size: 0.78rem; }
  .pattern-strip { display: none; }
  .panel {
    position: fixed;
    inset-block-start: var(--topbar-h);
    inset-block-end: 0;
    inset-inline-start: 0;
    inset-inline-end: 0;
    z-index: 1100;
  }
  body[data-pin-selected="false"] #panel { display: none; }
}
