/* NC EVI Dashboard - Static Site Styles */
/* Adapted from Shiny custom.css */

:root {
  --evi-navy:       #1B2A4A;
  --evi-dark-blue:  #2D5F8A;
  --evi-blue:       #4472C4;
  --evi-light-blue: #5B9BD5;
  --evi-sky-blue:   #8FB8DE;
  --evi-pale-blue:  #D6E6F5;
  --evi-warm:       #D4762C;
  --evi-warm-light: #F4C089;
  --evi-warm-pale:  #FDE8D0;
  --evi-text:       #212529;
  --evi-text-muted: #666666; /* darkened from #6C757D for WCAG AA contrast (~5:1 on white) */
  --evi-bg:         #F8F9FA;
  --evi-border:     #DEE2E6;
}

/* --- Skip link (visually hidden until focused) --- */
.evi-skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--evi-navy);
  color: #ffffff;
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.95rem;
  z-index: 9999;
  text-decoration: none;
  border-radius: 0 0 4px 0;
}
.evi-skip-link:focus {
  top: 0;
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

/* --- Typography --- */
body {
  font-family: 'Century Gothic', 'Futura', 'Inter', 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--evi-bg);
  color: var(--evi-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
}

.min-width-0 { min-width: 0; }

/* --- Page title (below standard header) --- */
.evi-page-title {
  color: #115072;
  font-weight: bold;
}

.evi-page-title span {
  color: #217991;
  font-size: 75%;
  display: block;
  font-family: 'Century Gothic', 'Futura', sans-serif;
}

.evi-page-title span::before {
  content: "❱❱ ";
  color: #d9534f;
}

/* --- Content width wrapper (side margins on medium+ screens) --- */
.evi-content-wrap {
  max-width: 1300px;
  margin-left: auto;
  margin-right: auto;
}

/* --- App navigation tab strip --- */
/* --- Tab bar (simple flex, no Bootstrap navbar machinery) --- */
.evi-tab-bar {
  display: flex;
  align-items: center;
  background-color: #115072;
  border-radius: 6px;
  padding: 0;
}

.evi-tab-links {
  display: flex;
  flex-wrap: nowrap;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;       /* Firefox */
}
.evi-tab-links::-webkit-scrollbar { display: none; } /* Chrome/Safari */

.evi-tab-link {
  color: rgba(255, 255, 255, 0.72);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.6rem 1.1rem;
  border-bottom: 3px solid transparent;
  transition: color 0.15s, border-bottom-color 0.15s;
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;  /* eliminates 300ms tap delay on mobile */
}

.evi-tab-link:hover {
  color: #ffffff;
  border-bottom-color: rgba(255, 255, 255, 0.35);
}

.evi-tab-link.active {
  color: #ffffff;
  border-bottom-color: var(--evi-warm);
}

.evi-tab-link:focus         { outline: none; }
.evi-tab-link:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.85); outline-offset: -2px; }


/* --- Tab Content --- */
.tab-content { padding: 20px 0; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* --- Value Boxes --- */
.evi-value-box {
  background: #FFFFFF;
  border-radius: 6px;
  padding: 14px 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  height: 100%;
}

.evi-value-box-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--evi-navy);
  line-height: 1.2;
}

.evi-value-box-subtitle {
  font-size: 0.78rem;
  color: var(--evi-text-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.evi-stat-item {
  border-top: 3px solid;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 8px 0;
}

.evi-stat-divider {
  width: 1px;
  align-self: center;
  height: 60%;
  background: var(--evi-border);
  flex-shrink: 0;
}

/* --- Links inside cards --- */
.evi-card a {
  color: var(--evi-blue);
  text-decoration: underline;
}
.evi-card a:hover {
  color: var(--evi-dark-blue);
}

/* --- Cards --- */
.evi-card {
  background: #FFFFFF;
  border-radius: 8px;
  border: 1px solid var(--evi-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 20px;
  margin-bottom: 16px;
}

h2.evi-card-header, h3.evi-card-header,
h2.evi-card-header-inline, h3.evi-card-header-inline {
  /* Reset browser heading defaults so visual appearance is unchanged */
  margin-top: 0;
  line-height: inherit;
}

.evi-card-header {
  font-size: 1rem;
  font-weight: 600;
  color: var(--evi-navy);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--evi-pale-blue);
}

.evi-card-header-inline {
  /* Used for headings rendered inline with sibling elements (e.g. bubble chart title) */
  display: inline;
  font-size: 1rem;
  font-weight: 600;
  color: var(--evi-navy);
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.evi-card-header.evi-card-header-sm { font-size: 0.85rem; }

/* --- Ranking Panels --- */
.evi-ranking-panel {
  background: #FFFFFF;
  border-radius: 8px;
  border: 1px solid var(--evi-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 16px;
  margin-bottom: 12px;
}

h2.evi-ranking-title { margin-top: 0; line-height: inherit; }

.evi-ranking-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--evi-navy);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.evi-ranking-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid #F0F0F0;
  font-size: 0.85rem;
}

.evi-ranking-item:last-child { border-bottom: none; }

.evi-ranking-name { font-weight: 500; color: var(--evi-text); }

.evi-ranking-score {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 2px 8px;
  border-radius: 4px;
}

.evi-ranking-score.above { color: var(--evi-dark-blue); background-color: var(--evi-pale-blue); }
.evi-ranking-score.below { color: #8B4513; background-color: var(--evi-warm-pale); }

/* --- Comparison Cards (Area at a Glance) --- */
.evi-comparison-card {
  background: var(--evi-dark-blue);
  border-radius: 8px;
  border: 1px solid var(--evi-dark-blue);
  padding: 16px;
  text-align: center;
}

.evi-comparison-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #ffffff;
  margin-bottom: 10px;
}

.evi-comparison-values {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.evi-comparison-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #FFFFFF;
  display: block;
}

.evi-comparison-tag {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.evi-comparison-divider {
  width: 1px;
  height: 40px;
  background-color: rgba(255, 255, 255, 0.35);
}

/* --- Narrative --- */
.evi-narrative {
  background: var(--evi-pale-blue);
  border-left: 4px solid var(--evi-blue);
  border-radius: 0 6px 6px 0;
  padding: 16px 20px;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--evi-navy);
  margin-bottom: 16px;
}

/* --- YOY Badge --- */
.evi-yoy-badge {
  font-size: 0.95rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  background: #F8F9FA;
}

/* --- Score (large) --- */
.evi-score-large {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
}

.evi-score-label {
  font-size: 0.8rem;
  color: var(--evi-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Sidebar layout --- */
.evi-sidebar {
  width: 280px;
  flex-shrink: 0;
}

.evi-sidebar-content {
  background: #FFFFFF;
  border-radius: 8px;
  border: 1px solid var(--evi-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 16px;
  position: sticky;
  top: 16px;
}

.evi-sidebar-content label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--evi-navy);
  margin-bottom: 4px;
}

h3.evi-sidebar-heading { margin-top: 0; line-height: inherit; }

.evi-sidebar-heading {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--evi-navy);
  margin-bottom: 6px;
}

#compare-metric-radios { font-size: 0.85rem; }

.evi-sidebar-content select,
.evi-sidebar-content input[type="range"] {
  width: 100%;
}

.evi-sidebar-content .form-control,
.evi-sidebar-content .form-select {
  font-size: 0.88rem;
  border-color: var(--evi-border);
  border-radius: 6px;
}

.evi-sidebar-content .form-control:focus,
.evi-sidebar-content .form-select:focus {
  border-color: var(--evi-blue);
  box-shadow: 0 0 0 0.2rem rgba(68, 114, 196, 0.25);
}

/* --- Map container --- */
.evi-map-container {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--evi-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

#overview-map {
  height: 540px;
  width: 100%;
  border-radius: 8px;
}

/* Smooth fill transitions on Leaflet polygons */
.leaflet-interactive {
  transition: fill 0.4s ease, fill-opacity 0.4s ease;
}

.leaflet-container {
  font-family: 'Inter', 'Lato', sans-serif;
}

.leaflet-popup-content {
  font-family: 'Inter', 'Lato', sans-serif;
  font-size: 0.88rem;
  line-height: 1.5;
  min-width: 180px;
}

.leaflet-popup-content strong { color: var(--evi-navy); }

/* Leaflet legend */
.evi-map-legend {
  background: white;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--evi-border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  font-size: 0.78rem;
  line-height: 1.4;
}

.evi-map-legend-title {
  font-weight: 700;
  color: var(--evi-navy);
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.evi-legend-gradient-bar {
  width: 130px;
  height: 12px;
  /* gradient injected by JS from MAP_COLORS constant */
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.1);
}

.evi-legend-gradient-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: #555;
  margin-top: 3px;
  width: 130px;
}

/* --- Year Slider --- */
.evi-year-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.evi-year-display {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--evi-navy);
  min-width: 60px;
  text-align: center;
}

.evi-play-btn {
  font-size: 0.8rem;
  padding: 3px 12px;
  border-radius: 20px;
  border: 1px solid var(--evi-blue);
  background: white;
  color: var(--evi-blue);
  cursor: pointer;
  transition: all 0.15s;
}

.evi-play-btn:hover {
  background: var(--evi-blue);
  color: white;
}

input[type="range"] {
  accent-color: var(--evi-blue);
  width: 100%;
}

.evi-year-ticks {
  position: relative;
  width: 100%;
  padding: 0 7px;   /* ~thumb-radius offset to align with track ends */
  height: 1em;
  margin-top: 2px;
}

.evi-year-ticks span {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.62rem;
  color: #767676;
  white-space: nowrap;
}

/* --- Profile sidebar score display --- */
.evi-profile-score {
  text-align: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--evi-border);
  margin-bottom: 10px;
}

.evi-profile-rank {
  font-size: 0.82rem;
  color: var(--evi-text-muted);
  text-align: center;
  margin-top: 4px;
}

/* --- Data Tables --- */
.dataTables_wrapper {
  font-size: 0.88rem;
}

table.dataTable thead th {
  background-color: var(--evi-navy) !important;
  color: #FFFFFF !important;
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  /* Freeze header within its scrollable wrapper */
  position: sticky;
  top: 0;
  z-index: 2;
}

table.dataTable tbody tr:hover {
  background-color: var(--evi-pale-blue) !important;
}

/* --- DataTables download buttons --- */
/* The dt-buttons wrapper can override Bootstrap's outline btn styles */
.dt-buttons { margin-bottom: 8px; }

.dt-buttons .btn,
.dt-buttons .btn.btn-outline-secondary {
  background-color: #FFFFFF !important;
  color: var(--evi-navy) !important;
  border: 1px solid var(--evi-border) !important;
  font-size: 0.78rem;
  padding: 4px 12px;
  border-radius: 4px;
  font-weight: 500;
}

.dt-buttons .btn:hover,
.dt-buttons .btn.btn-outline-secondary:hover {
  background-color: var(--evi-pale-blue) !important;
  color: var(--evi-navy) !important;
  border-color: var(--evi-blue) !important;
}

/* --- Intro / orientation banner --- */
.evi-intro-banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  background: linear-gradient(135deg, #EBF4FB, var(--evi-pale-blue));
  border: 1px solid var(--evi-sky-blue);
  border-left: 4px solid var(--evi-blue);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--evi-navy);
}

.evi-intro-text { flex: 1; }

.evi-dismiss-btn {
  background: none;
  border: none;
  color: var(--evi-text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0 0 12px;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.evi-dismiss-btn:hover { opacity: 1; }

.evi-above-label { color: #1e7e34; font-weight: 600; }
.evi-below-label { color: #646464; font-weight: 600; }

/* --- Dynamic insight bar --- */
.evi-insight-bar {
  background: #FFFFFF;
  border: 1px solid var(--evi-border);
  border-radius: 6px;
  padding: 9px 16px;
  margin-bottom: 14px;
  font-size: 0.83rem;
  color: var(--evi-text-muted);
  line-height: 1.6;
  display: block;
}

/* --- Performance badge (above / below avg) --- */
.evi-perf-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.evi-badge-above {
  background: var(--evi-pale-blue);
  color: var(--evi-dark-blue);
  border: 1px solid var(--evi-sky-blue);
}

.evi-badge-below {
  background: var(--evi-warm-pale);
  color: #8B4513;
  border: 1px solid var(--evi-warm-light);
}

/* --- Chart captions --- */
.evi-chart-caption {
  font-size: 0.72rem;
  color: var(--evi-text-muted);
  text-align: right;
  padding: 4px 8px 0;
  font-style: italic;
}

/* --- Reset button (Compare Areas sidebar) --- */
.evi-reset-btn {
  margin-top: 6px;
  width: 100%;
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--evi-border);
  background: white;
  color: var(--evi-text-muted);
  cursor: pointer;
}

/* Inline variant — auto width for use inside filter bars */
.evi-reset-btn-inline {
  width: auto;
  margin-top: 0;
  white-space: nowrap;
  align-self: flex-end;
}

/* --- Filter bars (Rankings & Trends) --- */
.evi-filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding: 12px 20px;
}

.evi-filter-bar-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 130px;
}

.evi-filter-bar-label .evi-sidebar-heading {
  margin-bottom: 0;
}

.evi-filter-bar-sub {
  font-size: 0.74rem;
  color: var(--evi-text-muted);
  font-style: italic;
}

.evi-filter-bar-select {
  width: auto;
  min-width: 160px;
}

/* --- Section container (visually groups a linked filter + chart + table) --- */
.evi-section-container {
  background: var(--evi-pale-blue);
  border: 1px solid var(--evi-border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 1rem;
}

.evi-section-container-filter {
  background: transparent;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

/* --- Zone buttons --- */
.evi-zone-btn {
  margin: 2px;
  font-size: 0.78rem;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--evi-blue);
  background: white;
  color: var(--evi-blue);
  cursor: pointer;
  transition: all 0.15s;
}

.evi-zone-btn:hover {
  background: var(--evi-blue);
  color: white;
}

/* --- Tom Select overrides --- */
.ts-wrapper .ts-control {
  border-color: var(--evi-border) !important;
  border-radius: 6px !important;
  font-size: 0.88rem;
}

.ts-wrapper.focus .ts-control {
  border-color: var(--evi-blue) !important;
  box-shadow: 0 0 0 0.2rem rgba(68, 114, 196, 0.25) !important;
}

.ts-wrapper .ts-control .item {
  background-color: var(--evi-pale-blue) !important;
  color: var(--evi-navy) !important;
  border: 1px solid var(--evi-sky-blue) !important;
  border-radius: 4px !important;
  padding: 1px 6px !important;
  font-size: 0.82rem;
}

/* --- About modal --- */

/* --- Highlight row --- */
tr.evi-highlighted td {
  font-weight: bold !important;
  background-color: #C8E0F4 !important;
}

/* --- Loading overlay --- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27, 42, 74, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: white;
  font-size: 1rem;
  gap: 16px;
}

.evi-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Section navigation (Rankings & Trends jump buttons) --- */
.evi-section-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0 10px;
  border-bottom: 1px solid var(--evi-border);
}

.evi-section-nav-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--evi-text-muted);
  margin-right: 4px;
  white-space: nowrap;
}

.evi-section-nav-btn {
  font-size: 0.8rem;
  padding: 4px 14px;
  border-radius: 20px;
  border: 1px solid var(--evi-border);
  background: #fff;
  color: var(--evi-navy);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.evi-section-nav-btn:hover {
  background: var(--evi-navy);
  color: #fff;
  border-color: var(--evi-navy);
}

/* --- Responsive --- */
@media (max-width: 992px) {
  .evi-sidebar { width: 220px; }
}

@media (max-width: 768px) {
  .evi-sidebar       { width: 100%; }
  .evi-score-large   { font-size: 2rem; }
  .evi-narrative     { font-size: 0.85rem; padding: 12px 14px; }
  #overview-map      { height: 380px; }
  .evi-comparison-values { flex-direction: column; gap: 6px; }
  .evi-comparison-divider { width: 40px; height: 1px; }
}

@media (max-width: 768px) {
  /* Show only even years on medium-small screens */
  .evi-year-ticks span:not(.evi-tick-even):not(.evi-tick-major) { display: none; }
}

@media (max-width: 480px) {
  /* Show only key years (multiples of 5 + endpoints) on small screens */
  .evi-year-ticks span:not(.evi-tick-major) { display: none; }
}

@media (max-width: 576px) {
  .evi-tab-link { font-size: 0.8rem; padding: 0.5rem 0.7rem; }

  /* Compact gradient legend on mobile */
  .evi-map-legend { padding: 5px 8px; font-size: 0.68rem; }
  .evi-map-legend-title { font-size: 0.72rem; margin-bottom: 2px; }
  .evi-legend-gradient-bar { width: 110px; height: 10px; }
  .evi-legend-gradient-labels { width: 110px; }
}
