:root {
  --color-primary: #008e91;
  --color-primary-dark: #006e73;
  --color-yellow: #ffea00;
  --color-text: #223033;
  --color-muted: #647274;
  --color-border: #d8e5e4;
  --color-panel: #fbfefe;
  --color-soft: #f1fbfc;
  --color-danger: #d92d20;
  --color-warning: #f79009;
  --color-success: #16a34a;
  font-family: 'Montserrat', 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--color-text);
  background:
    linear-gradient(135deg, rgba(223, 244, 251, 0.95), rgba(255, 247, 143, 0.72)),
    #f7fbfb;
}

.auth-pending::before {
  content: attr(data-auth-message);
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(247, 251, 251, 0.92);
  color: var(--color-primary-dark);
  font-weight: 700;
}

.dashboard-page {
  padding: 36px;
}

.dashboard-shell {
  width: min(1344px, 100%);
  margin: 0 auto;
  padding: 36px 44px 44px;
  border: 1px solid var(--color-border);
  border-radius: 34px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 28px 80px -54px rgba(0, 0, 0, 0.32);
}

.dashboard-hero,
.hero-actions,
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.kicker {
  margin: 0 0 8px;
  color: var(--color-primary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1rem;
}

.hero-actions {
  display: grid;
  justify-items: end;
  gap: 16px;
}

.hero-top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 18px;
}

.hero-filter-stack {
  display: grid;
  justify-items: start;
  gap: 10px;
}

.filter-select,
.range-filter button,
.pharmacy-type-filter button,
.top-risk-filter button,
.map-trend-filter button,
.ghost-btn,
.ghost-link {
  min-height: 40px;
  border: 1px solid #bcd4d3;
  border-radius: 999px;
  background: #fff;
  color: var(--color-text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
}

.filter-select {
  padding: 0 18px;
}

.range-filter,
.pharmacy-type-filter,
.top-limit-filter,
.top-risk-filter,
.map-trend-filter {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid #d9e5e4;
  border-radius: 999px;
  background: #f6fbfb;
}

.range-filter button,
.pharmacy-type-filter button,
.top-limit-filter button,
.top-risk-filter button,
.map-trend-filter button {
  min-height: 32px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.range-filter button.is-active,
.pharmacy-type-filter button.is-active,
.top-limit-filter button.is-active,
.top-risk-filter button.is-active,
.map-trend-filter button.is-active {
  border-radius: 999px;
  background: var(--color-yellow);
  color: #4e4300;
  box-shadow: inset 0 0 0 1px rgba(196, 164, 0, 0.16);
}

.range-filter button:focus-visible,
.pharmacy-type-filter button:focus-visible,
.top-limit-filter button:focus-visible,
.top-risk-filter button:focus-visible,
.map-trend-filter button:focus-visible {
  outline: 2px solid rgba(0, 142, 145, 0.34);
  outline-offset: 2px;
}

.pharmacy-type-filter-group {
  display: grid;
  justify-items: start;
  gap: 6px;
}

.pharmacy-type-filter-group > span {
  color: var(--color-muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pharmacy-type-filter {
  flex-wrap: wrap;
  justify-content: flex-start;
  max-width: 720px;
}

.pharmacy-type-filter button {
  min-height: 30px;
  padding: 0 12px;
  white-space: nowrap;
}

.ghost-btn,
.ghost-link {
  display: inline-grid;
  place-items: center;
  padding: 0 18px;
  background: #eaf8f8;
  color: var(--color-primary-dark);
  cursor: pointer;
}

.ghost-link[hidden],
#admin-link[hidden] {
  display: none !important;
}

.page-status {
  min-height: 22px;
  margin: 18px 0 8px;
  color: var(--color-danger);
  font-weight: 700;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 22px;
}

.kpi-card,
.panel,
.pin-detail {
  border: 1px solid var(--color-border);
  border-radius: 24px;
  background: var(--color-panel);
}

.kpi-card {
  display: grid;
  min-height: 128px;
  padding: 20px;
  gap: 10px;
  align-content: start;
}

.kpi-card p {
  color: var(--color-muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.kpi-card > strong {
  display: block;
  font-size: 2.3rem;
  line-height: 1;
}

.average-kpi {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.average-kpi span:first-child {
  color: var(--color-primary);
  font-size: 0.74em;
  font-weight: 900;
}

.is-warning-value {
  color: var(--color-danger);
}

.is-success-value {
  color: var(--color-success);
}

.trend-pill,
.muted-pill {
  display: inline-flex;
  align-items: center;
  justify-self: end;
  gap: 7px;
  padding: 0;
  background: transparent;
  color: var(--color-muted);
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
}

.trend-value {
  padding: 5px 9px;
  border-radius: 999px;
  background: #edf8f4;
  font-size: 1rem;
  line-height: 1.05;
  color: var(--color-success);
}

.trend-pill.is-negative {
  background: transparent;
}

.trend-pill.is-negative strong {
  background: #fff6e8;
  color: var(--color-danger);
}

.trend-pill.is-neutral {
  color: var(--color-muted);
}

.kpi-inline-meta {
  display: inline-flex;
  flex-wrap: wrap;
  justify-self: end;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.kpi-inline-meta .trend-pill,
.kpi-inline-meta .muted-pill {
  justify-self: auto;
}

.muted-pill {
  padding: 5px 10px;
  border-radius: 999px;
  background: #f5f8f8;
  color: var(--color-muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.42fr) minmax(560px, 0.58fr);
  gap: 20px;
  margin-top: 22px;
}

.panel {
  padding: 24px;
}

.stock-distribution {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.stock-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 74px;
  align-items: center;
  gap: 12px;
}

.stock-track,
.stock-progress {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef5f5;
}

.stock-progress {
  width: 100%;
  border: 0;
  appearance: none;
}

.stock-progress::-webkit-progress-bar {
  border-radius: 999px;
  background: #eef5f5;
}

.stock-progress::-webkit-progress-value {
  border-radius: 999px;
}

.stock-progress::-moz-progress-bar {
  border-radius: 999px;
}

.stock-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  min-width: 4px;
}

.stock-row span,
.top-product-meta,
.map-summary,
.empty-detail {
  color: var(--color-muted);
  font-size: 0.82rem;
}

.stock-row strong,
.top-product-title {
  font-size: 0.9rem;
}

.top-products {
  margin-top: 32px;
}

.top-products-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.top-products-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.top-risk-filter {
  background: #fff;
}

.top-risk-filter span {
  align-self: center;
  color: var(--color-muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.top-risk-filter button {
  min-width: 84px;
  padding: 0 10px;
  color: var(--color-muted);
}

.top-risk-filter button.is-active {
  background: #fff3bf;
  color: #6f5200;
}

.top-limit-filter {
  flex: 0 0 auto;
}

.top-limit-filter button {
  min-width: 34px;
  padding: 0 10px;
}

.top-products-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  max-height: 392px;
  overflow-y: auto;
  padding-right: 4px;
}

.top-product {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid #eadf9a;
  border-radius: 18px;
  background: #fffdf4;
}

.rank {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: #fff3bf;
  color: #8a6400;
  font-weight: 800;
}

.risk-pill {
  padding: 7px 10px;
  border-radius: 999px;
  background: #fff1f0;
  color: var(--color-danger);
  font-size: 0.78rem;
  font-weight: 800;
}

.map-panel {
  min-width: 0;
}

.map-panel-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.map-trend-filter {
  background: #fff;
}

.map-trend-filter button {
  min-width: 68px;
  padding: 0 12px;
  color: var(--color-muted);
}

.map-trend-filter button[data-trend-filter="growth"].is-active {
  background: #edf8f4;
  color: var(--color-success);
  box-shadow: inset 0 0 0 1px rgba(22, 163, 74, 0.18);
}

.map-trend-filter button[data-trend-filter="reduce"].is-active {
  background: #fff1f0;
  color: var(--color-danger);
  box-shadow: inset 0 0 0 1px rgba(217, 45, 32, 0.16);
}

.map-layout {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 18px;
}

.coverage-map {
  min-height: clamp(520px, 52vh, 680px);
  overflow: hidden;
  border: 1px solid #c7dddd;
  border-radius: 24px;
  background: var(--color-soft);
}

.map-loading {
  display: grid;
  min-height: 540px;
  place-items: center;
  padding: 28px;
  color: var(--color-muted);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.pin-detail {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.pharmacy-marker {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 900;
  box-shadow: 0 10px 20px -12px rgba(0, 0, 0, 0.5);
}

.pharmacy-marker.is-high-flow {
  background: var(--color-yellow);
  color: #4e4300;
}

.pharmacy-marker.is-product-up {
  border-color: var(--color-success);
}

.pharmacy-marker.is-product-down {
  border-color: var(--color-danger);
}

.pharmacy-marker.is-product-flat,
.pharmacy-marker.is-product-none {
  border-color: #fff;
}

.pharmacy-marker-group {
  display: inline-grid;
  min-width: 82px;
  height: 32px;
  place-items: center;
  padding: 0 14px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 14px 28px -16px rgba(0, 0, 0, 0.58);
}

.detail-title {
  font-size: 1.28rem;
  font-weight: 800;
}

.detail-address {
  margin-top: 6px;
  color: var(--color-muted);
  font-size: 0.86rem;
}

.detail-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.detail-chip {
  padding: 7px 11px;
  border-radius: 999px;
  background: #eaf8f8;
  color: var(--color-primary-dark);
  font-size: 0.74rem;
  font-weight: 800;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.detail-metric {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 6px;
  min-width: 0;
  min-height: 98px;
  padding: 0 8px 9px;
  border: 1.5px solid #bddddd;
  border-bottom: 4px solid rgba(0, 142, 145, 0.7);
  border-radius: 0;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdfd 100%);
  text-align: center;
  box-shadow: 0 10px 20px -20px rgba(0, 77, 80, 0.55);
}

.detail-metric.is-featured {
  background: linear-gradient(180deg, #ffffff 0%, #f8fcfc 100%);
}

.detail-metric-icon {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  margin-top: -16px;
  border: 3px solid #d7f2f1;
  border-radius: 999px;
  background: #63c7c5;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
  box-shadow: 0 10px 18px -14px rgba(0, 142, 145, 0.9);
}

.detail-metric-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.detail-metric-label {
  color: var(--color-muted);
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1.15;
  order: 3;
}

.detail-metric-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 5px;
  min-width: 0;
  color: var(--color-text);
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
  order: 2;
  white-space: nowrap;
}

.detail-metric-value.is-date {
  max-width: 74px;
  font-size: 0.75rem;
  line-height: 1.15;
  white-space: normal;
}

.detail-metric-value.is-product-value {
  flex-direction: column;
  gap: 5px;
  line-height: 1;
  white-space: normal;
}

.detail-primary-value {
  color: var(--color-text);
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
}

.detail-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 6px;
  border-radius: 999px;
  background: #edf8f4;
  color: var(--color-success);
  font-size: 0.62rem;
  font-weight: 900;
  line-height: 1;
}

.detail-trend span {
  order: initial;
}

.detail-trend-arrow {
  font-size: 0.72rem;
  line-height: 1;
}

.detail-trend-down {
  background: #fff6e8;
  color: var(--color-danger);
}

.detail-trend-flat {
  background: #f0f5f5;
  color: var(--color-muted);
}

.stock-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  min-width: 0;
}

.stock-fill-out_of_stock,
.detail-stock-fill-out_of_stock,
.stock-progress-out_of_stock::-webkit-progress-value {
  background: rgba(217, 45, 32, 0.28);
}

.stock-fill-low_stock,
.detail-stock-fill-low_stock,
.stock-progress-low_stock::-webkit-progress-value {
  background: rgba(247, 144, 9, 0.28);
}

.stock-fill-medium_stock,
.detail-stock-fill-medium_stock,
.stock-progress-medium_stock::-webkit-progress-value {
  background: rgba(74, 222, 128, 0.28);
}

.stock-fill-high_stock,
.detail-stock-fill-high_stock,
.stock-progress-high_stock::-webkit-progress-value {
  background: rgba(22, 163, 74, 0.3);
}

.stock-progress-out_of_stock::-moz-progress-bar {
  background: rgba(217, 45, 32, 0.28);
}

.stock-progress-low_stock::-moz-progress-bar {
  background: rgba(247, 144, 9, 0.28);
}

.stock-progress-medium_stock::-moz-progress-bar {
  background: rgba(74, 222, 128, 0.28);
}

.stock-progress-high_stock::-moz-progress-bar {
  background: rgba(22, 163, 74, 0.3);
}

.falcon-map-popup .leaflet-popup-content-wrapper {
  border: 1px solid var(--color-border);
  border-radius: 22px;
  box-shadow: 0 22px 54px -34px rgba(0, 0, 0, 0.48);
}

.falcon-map-popup .leaflet-popup-content {
  width: 360px !important;
  margin: 16px;
  font-family: 'Montserrat', 'Segoe UI', sans-serif;
}

.map-popup-detail .detail-title {
  font-size: 1.12rem;
}

.map-popup-detail .detail-grid {
  margin-top: 14px;
}

.map-group-nav {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.map-group-nav span {
  color: var(--color-text);
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
}

.map-group-nav-btn {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #d8e8e8;
  border-radius: 999px;
  background: #fff;
  color: var(--color-primary-dark);
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 10px 22px -18px rgba(0, 0, 0, 0.5);
}

.map-group-nav-btn:hover,
.map-group-nav-btn:focus-visible {
  border-color: var(--color-primary);
  background: #effafa;
  outline: none;
}

.detail-products {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid #e2eeee;
  border-radius: 12px;
  background: #fbfdfd;
}

.detail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--color-muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.detail-section-head strong {
  display: inline-grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  background: #fff7cf;
  color: var(--color-text);
}

.detail-products ol {
  display: grid;
  gap: 4px;
  max-height: 112px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  scrollbar-width: thin;
}

.detail-products li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-height: 24px;
  font-size: 0.72rem;
}

.detail-product-rank {
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 999px;
  background: #fff7cf;
  font-weight: 900;
}

.detail-product-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-products li strong {
  color: var(--color-danger);
  font-size: 0.72rem;
}

.detail-empty {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

@media (max-width: 520px) {
  .falcon-map-popup .leaflet-popup-content {
    width: min(82vw, 340px) !important;
  }

  .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1100px) {
  .kpi-grid,
  .dashboard-grid,
  .map-layout {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    justify-items: start;
  }

  .hero-top-actions {
    justify-content: flex-start;
  }

  .hero-filter-stack,
  .pharmacy-type-filter-group {
    justify-items: start;
  }

  .pharmacy-type-filter {
    justify-content: flex-start;
  }
}
