:root {
  --bg-color: #f5f7f2;
  --surface: #ffffff;
  --surface-soft: #eef5f0;
  --text-color: #17211c;
  --muted-color: #5c6c63;
  --border-color: #d9e2dc;
  --accent-color: #1b7f5d;
  --accent-strong: #0f5f48;
  --accent-soft: #dff1e9;
  --metric-color: #0f6b7a;
  --metric-soft: #dceff2;
  --warning-color: #9a6417;
  --danger-color: #9b2f32;
  --success-color: #176d43;
  --focus-ring: rgba(15, 107, 122, 0.28);
  --shadow-soft: 0 12px 30px rgba(19, 42, 31, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg-color);
  color: var(--text-color);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

body.filter-open {
  overflow: hidden;
}

a {
  color: var(--accent-strong);
}

a:hover {
  color: var(--metric-color);
}

button,
input,
select,
textarea {
  font: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.site-shell {
  width: min(1520px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  background: color-mix(in srgb, var(--bg-color) 88%, transparent);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-color);
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent-color);
  color: #ffffff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted-color);
  font-size: 0.82rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.btn-primary {
  --bs-btn-bg: var(--accent-color);
  --bs-btn-border-color: var(--accent-color);
  --bs-btn-hover-bg: var(--accent-strong);
  --bs-btn-hover-border-color: var(--accent-strong);
  --bs-btn-focus-shadow-rgb: 15, 107, 122;
}

.btn-outline-secondary {
  --bs-btn-color: var(--text-color);
  --bs-btn-border-color: var(--border-color);
  --bs-btn-hover-bg: var(--surface-soft);
  --bs-btn-hover-color: var(--text-color);
  --bs-btn-hover-border-color: var(--border-color);
}

.hero-dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.88fr);
  gap: 18px;
  align-items: stretch;
  margin: 16px 0 18px;
}

.hero-copy,
.kpi-card,
.filter-panel,
.table-section,
.chart-section,
.method-card,
.faq-section,
.ticker-panel,
.info-strip {
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 310px;
  padding: clamp(22px, 4vw, 44px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--metric-color);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

.hero-copy h1 {
  max-width: 920px;
  margin: 0;
  font-size: clamp(2rem, 4rem, 4rem);
  line-height: 1.02;
}

.hero-subtitle {
  max-width: 790px;
  margin: 18px 0 0;
  color: var(--muted-color);
  font-size: 1.12rem;
}

.hero-method {
  max-width: 820px;
  margin: 18px 0 0;
}

.notice-box {
  max-width: 820px;
  margin-top: 18px;
  padding: 12px 14px;
  border-left: 4px solid var(--warning-color);
  border-radius: 6px;
  background: #fff7e8;
  color: #4d3a17;
  font-weight: 650;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card {
  display: flex;
  min-height: 142px;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
}

.kpi-card-primary {
  border-color: color-mix(in srgb, var(--metric-color) 42%, var(--border-color));
  background: linear-gradient(180deg, var(--metric-soft), var(--surface));
}

.kpi-label {
  color: var(--muted-color);
  font-size: 0.86rem;
  font-weight: 680;
}

.kpi-card strong {
  margin: 8px 0;
  color: var(--text-color);
  font-size: 2rem;
  line-height: 1;
}

.kpi-card-primary strong {
  color: var(--metric-color);
}

.kpi-card-pharmacy strong {
  overflow-wrap: anywhere;
  font-size: 1.35rem;
  line-height: 1.12;
}

.kpi-card small {
  color: var(--muted-color);
}

.ticker-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 52px;
  margin-bottom: 18px;
  padding: 10px 12px;
  overflow: hidden;
}

.ticker-label {
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.ticker-viewport {
  overflow: hidden;
  white-space: nowrap;
}

.ticker-content {
  display: inline-flex;
  gap: 22px;
  align-items: center;
  min-width: 100%;
}

.ticker-content.is-moving {
  animation: ticker-scroll 36s linear infinite;
}

.ticker-entry {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--text-color);
  white-space: nowrap;
  cursor: pointer;
}

.ticker-entry:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.ticker-positive {
  color: var(--danger-color);
}

.ticker-negative {
  color: var(--success-color);
}

@keyframes ticker-scroll {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-50%);
  }
}

.dashboard-layout {
  display: block;
  min-width: 0;
}

.filter-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  border: 0;
  padding: 0;
  background: rgba(14, 24, 18, 0.48);
  opacity: 0;
  cursor: default;
  transition: opacity 0.18s ease;
}

body.filter-open .filter-backdrop {
  opacity: 1;
}

.filter-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1000;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -47%) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

body.filter-open .filter-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.panel-heading,
.section-header,
.chart-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading h2,
.section-header h2,
.method-card h2,
.faq-section h2 {
  margin: 0;
  font-size: 1.25rem;
}

.icon-button,
.info-button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border-color);
  background: var(--surface);
  color: var(--text-color);
  cursor: pointer;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.2rem;
}

.info-button {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--metric-color);
  font-size: 0.75rem;
  font-weight: 800;
}

.info-button:hover,
.icon-button:hover {
  border-color: var(--metric-color);
  background: var(--metric-soft);
}

#btnCloseFilters {
  display: inline-grid;
}

.filter-group {
  margin-top: 18px;
}

.filter-group label,
.filter-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-color);
  font-size: 0.92rem;
  font-weight: 720;
}

.filter-group-strong {
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--metric-color) 40%, var(--border-color));
  border-radius: var(--radius);
  background: var(--metric-soft);
}

.form-control,
.form-select {
  border-color: var(--border-color);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: var(--text-color);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--metric-color);
  box-shadow: 0 0 0 0.22rem var(--focus-ring);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.segmented-control label {
  margin: 0;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: grid;
  min-height: 34px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted-color);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
}

.segmented-control input:checked + span {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(17, 37, 26, 0.1);
}

.range-label {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 6px;
  align-items: center;
}

.range-label output {
  justify-self: end;
  color: var(--muted-color);
  font-size: 0.86rem;
  font-weight: 650;
}

.range-slider {
  margin: 12px 8px 4px;
}

.noUi-target {
  border: 0;
  border-radius: 999px;
  background: #dce5df;
  box-shadow: none;
}

.noUi-horizontal {
  height: 8px;
}

.noUi-connect {
  background: var(--metric-color);
}

.noUi-horizontal .noUi-handle {
  top: -8px;
  right: -11px;
  width: 24px;
  height: 24px;
  border: 2px solid var(--metric-color);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(19, 42, 31, 0.18);
}

.noUi-handle::before,
.noUi-handle::after {
  display: none;
}

.filter-actions {
  margin-top: 20px;
}

.dashboard-main {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.info-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.info-strip > div {
  min-width: 0;
  padding: 14px;
  background: var(--surface);
}

.info-strip strong {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 4px;
  color: var(--metric-color);
}

.info-strip span {
  color: var(--muted-color);
  font-size: 0.9rem;
}

.table-section,
.chart-section,
.faq-section {
  padding: 18px;
  min-width: 0;
}

.table-section {
  overflow: hidden;
}

.table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.result-count {
  color: var(--muted-color);
  font-weight: 700;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 30px;
  margin: 12px 0;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted-color);
  font-size: 0.82rem;
  font-weight: 650;
}

.product-table {
  width: 100%;
  max-width: 100%;
  min-height: 430px;
  min-width: 0;
}

.tabulator {
  max-width: 100%;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-color);
  overflow: hidden;
}

.tabulator .tabulator-tableholder {
  max-width: 100%;
  overflow-x: auto;
}

.tabulator .tabulator-header {
  border-bottom: 1px solid var(--border-color);
  background: var(--surface-soft);
  color: var(--text-color);
  font-weight: 760;
}

.tabulator .tabulator-header .tabulator-col {
  min-height: 42px;
  border-color: var(--border-color);
  background: var(--surface-soft);
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-title {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.18;
}

.tabulator .tabulator-row {
  border-bottom: 1px solid var(--border-color);
  background: var(--surface);
}

.tabulator .tabulator-row:nth-child(even) {
  background: #fbfcfa;
}

.tabulator .tabulator-row:hover {
  background: var(--accent-soft);
}

.tabulator .tabulator-cell {
  border-color: var(--border-color);
  white-space: normal;
}

.product-name-cell {
  display: grid;
  gap: 2px;
}

.product-name-cell strong {
  line-height: 1.25;
}

.product-name-cell span {
  color: var(--muted-color);
  font-size: 0.82rem;
}

.metric-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 108px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--metric-soft);
  color: var(--metric-color);
  font-weight: 830;
}

.metric-cell.is-best {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

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

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
}

.status-badge.available {
  background: #e2f4eb;
  color: var(--success-color);
}

.status-badge.unavailable {
  background: #f7e7e7;
  color: var(--danger-color);
}

.status-badge.unknown {
  background: #eef1f4;
  color: var(--muted-color);
}

.empty-state {
  display: grid;
  gap: 4px;
  place-items: center;
  min-height: 120px;
  padding: 18px;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted-color);
  text-align: center;
}

.empty-state strong {
  color: var(--text-color);
}

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

.chart-card {
  position: relative;
  min-width: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface);
}

.chart-card-wide {
  grid-column: 1 / -1;
}

.chart-card-header {
  padding: 14px 14px 0;
}

.chart-card h3 {
  margin: 0;
  font-size: 1rem;
}

.chart-canvas {
  width: 100%;
  height: 360px;
}

.chart-card-wide .chart-canvas {
  height: 400px;
}

.chart-empty {
  position: absolute;
  inset: 54px 14px 14px;
  min-height: 0;
}

.toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-color);
  font-weight: 650;
}

.method-section {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.method-card {
  padding: 18px;
}

.method-card p:last-child {
  margin-bottom: 0;
}

.faq-section details {
  border-top: 1px solid var(--border-color);
}

.faq-section summary {
  padding: 14px 0;
  cursor: pointer;
  font-weight: 740;
}

.faq-section details p {
  max-width: 850px;
  color: var(--muted-color);
}

.site-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: center;
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted-color);
}

.partner-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.partner-mark img {
  max-height: 42px;
  width: auto;
}

.site-footer > div:last-child {
  text-align: right;
}

.modal-content {
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-color);
}

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

.detail-stat {
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.detail-stat span {
  display: block;
  color: var(--muted-color);
  font-size: 0.8rem;
}

.detail-stat strong {
  display: block;
  margin-top: 4px;
}

.detail-chart-section {
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.detail-chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.detail-chart-header span {
  color: var(--muted-color);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.detail-chart-header h3 {
  margin: 2px 0 0;
  font-size: 1.05rem;
}

.detail-chart-header strong {
  max-width: 42%;
  color: var(--metric-color);
  text-align: right;
}

.detail-chart {
  width: 100%;
  height: 320px;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
}

.detail-table th,
.detail-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

.detail-table th {
  color: var(--muted-color);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.thcdax-popover {
  z-index: 1060;
  max-width: min(360px, calc(100vw - 28px));
  padding: 12px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--text-color);
  color: #ffffff;
  box-shadow: var(--shadow-soft);
  font-size: 0.92rem;
}

.thcdax-popover strong {
  display: block;
  margin-bottom: 4px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  place-items: center;
  background: rgba(245, 247, 242, 0.82);
  backdrop-filter: blur(8px);
}

.loading-overlay.show {
  display: grid;
}

.loading-card {
  display: grid;
  gap: 10px;
  width: min(340px, calc(100% - 32px));
  padding: 22px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  text-align: center;
}

.loading-mark {
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--metric-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.theme-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.theme-choice + .theme-choice {
  margin-top: 8px;
}

.theme-swatch {
  display: inline-flex;
  width: 42px;
  height: 22px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 999px;
}

.theme-swatch span {
  flex: 1;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 1180px) {
  .hero-dashboard {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 780px) {
  .site-shell {
    width: min(100% - 20px, 1520px);
    padding-top: 8px;
  }

  .filter-panel {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    padding: 14px;
  }

  .site-header,
  .section-header,
  .site-footer {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .site-header {
    position: static;
    flex-direction: column;
  }

  .header-actions,
  .table-tools {
    justify-content: stretch;
  }

  .header-actions > *,
  .table-tools > * {
    flex: 1 1 auto;
  }

  .hero-copy {
    min-height: auto;
  }

  .hero-copy h1 {
    font-size: 2rem;
  }

  .kpi-grid,
  .chart-grid,
  .method-section,
  .info-strip,
  .product-detail-grid {
    grid-template-columns: 1fr;
  }

  .chart-card-wide {
    grid-column: auto;
  }

  .chart-canvas,
  .chart-card-wide .chart-canvas {
    height: 330px;
  }

  .ticker-panel {
    grid-template-columns: 1fr;
  }

  .site-footer {
    display: grid;
    text-align: left;
  }

  .site-footer > div:last-child {
    text-align: left;
  }

  .detail-chart-header {
    display: grid;
  }

  .detail-chart-header strong {
    max-width: none;
    text-align: left;
  }

  .detail-chart {
    height: 280px;
  }
}

@media (max-width: 520px) {
  .table-section {
    padding: 10px;
  }

  .tabulator .tabulator-cell,
  .tabulator .tabulator-header .tabulator-col {
    padding-left: 7px;
    padding-right: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
