/* =========================================================
   Maryland Economic Census Explorer
   Styled to match the SDAC building-permits report look.
   ========================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --color-brand: #003370;
  --color-brand-mid: #004494;
  --color-brand-section: #003366;
  --color-text: #222;
  --color-text-muted: #555;
  --color-text-faint: #666;
  --color-bg: #fff;
  --color-bg-alt: #f8f9fa;
  --color-bg-hover: #f0f4ff;
  --color-border: #dee2e6;
  --color-border-light: #e6e9ee;
  --color-border-soft: #eee;
  --color-positive: #1f6f3f;
  --color-negative: #b03030;
  --color-footer-bg: #f9f9f9;
  --focus-ring: 3px solid rgba(0, 68, 148, 0.55);
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  margin: 0 auto;
  max-width: 1400px;
  padding: 20px;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  font-size: 14px;
}

/* ---- Accessibility ---- */

.sr-only,
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-brand-mid);
  color: #fff;
  padding: 10px 16px;
  z-index: 1000;
  text-decoration: none;
  font-weight: 700;
}

.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

/* ---- Header ---- */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  border-bottom: 2px solid var(--color-border-soft);
  padding: 15px 0;
  background: #fff;
}

h1 {
  color: var(--color-brand);
  font-size: 28px;
  margin: 0;
  font-weight: 700;
}

.subtitle {
  font-size: 14px;
  color: var(--color-text-muted);
  margin: 4px 0 0;
  font-weight: 500;
  max-width: 900px;
}

/* ---- Main container ---- */

.container {
  padding: 0 0 2rem;
}

/* ---- Buttons ---- */

.btn {
  background: var(--color-brand-mid);
  color: #fff;
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 13px;
  text-decoration: none;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
  border: 2px solid var(--color-brand-mid);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

.btn:hover {
  background: var(--color-brand);
  border-color: var(--color-brand);
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
  background: #fff;
  color: var(--color-brand-mid);
}

.btn-secondary:hover {
  background: var(--color-brand-mid);
  color: #fff;
}

.caret {
  font-size: 0.7em;
  margin-left: 2px;
}

/* ---- Dashboard header (title + controls) ---- */

.dashboard-header {
  margin: 0 0 12px;
}

.dashboard-header .section-heading {
  margin-bottom: 12px;
}

.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 20px;
  padding: 12px 14px;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group > label,
.control-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--color-brand-section);
}

.select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  min-width: 220px;
  min-height: 36px;
  color: var(--color-text);
  cursor: pointer;
}

.select:disabled {
  background: #f1f1f1;
  color: #888;
  cursor: not-allowed;
}

.control-actions {
  margin-left: auto;
  flex-direction: row;
  align-items: flex-end;
  gap: 10px;
}

/* ---- View tabs ---- */

.view-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  margin: 8px 0 18px;
}

.view-tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 10px 22px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text-muted);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.view-tab:hover {
  color: var(--color-brand);
}

.view-tab.is-active {
  color: var(--color-brand);
  border-bottom-color: var(--color-brand-mid);
}

.view-panel[hidden] {
  display: none;
}

.report-section {
  margin-bottom: 2rem;
}

/* ---- Collapsible About Data ---- */

.about-data-card {
  background: #f7f8fa;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  margin: 18px 0 20px;
  padding: 0;
  overflow: hidden;
}

.about-data-summary {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 16px 18px;
  cursor: pointer;
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
  list-style: none;
}

.about-data-summary::-webkit-details-marker {
  display: none;
}

.about-data-icon {
  font-size: 22px;
  line-height: 1;
  color: var(--color-brand-section);
  transition: transform 0.2s ease;
}

.about-data-card[open] .about-data-icon {
  transform: rotate(90deg);
}

.about-data-content {
  padding: 0 18px 18px;
  font-size: 14px;
  line-height: 1.55;
}

.about-data-content p {
  margin: 0 0 12px;
}

.about-data-content ul {
  margin: 8px 0 14px 22px;
}

.about-data-content li {
  margin: 4px 0;
}

/* ---- Section headings ---- */

.section-heading {
  font-size: 1rem;
  color: var(--color-brand-section);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin: 0 0 6px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--color-brand-section);
}

/* ---- Table area ---- */

.search-input {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  min-width: 240px;
  min-height: 36px;
  background: #fff;
  color: var(--color-text);
}

/* ---- Download dropdown ---- */

.download-dropdown {
  position: relative;
  display: inline-block;
}

.download-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin: 4px 0 0;
  padding: 4px 0;
  list-style: none;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 50;
  min-width: 180px;
}

.download-dropdown.is-open .download-menu {
  display: block;
}

.download-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
}

.download-menu button:hover,
.download-menu button:focus {
  background: var(--color-bg-hover);
}

/* ---- Tables ---- */

.table-wrapper {
  overflow-x: auto;
  overflow-y: visible;
  max-height: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  margin-bottom: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

caption {
  text-align: left;
}

thead th {
  background: var(--color-bg-alt);
  color: var(--color-brand-section);
  font-weight: 700;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 5;
  white-space: nowrap;
}

thead th.numeric-header {
  text-align: left;
}

thead th[data-sort] {
  cursor: pointer;
  user-select: none;
}

thead th[data-sort]:hover {
  background: #eef1f4;
}

.sort-arrows {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-size: 8px;
  line-height: 1;
  margin-left: 6px;
  color: #b0b6bd;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

.sort-arrows .active {
  color: var(--color-brand-mid);
}

th.col-jurisdiction {
  position: sticky;
  left: 0;
  background: var(--color-bg-alt);
  z-index: 7;
  min-width: 80px;
}

td.col-jurisdiction,
td.col-naics {
  position: sticky;
  left: 0;
  background: inherit;
  z-index: 2;
  font-weight: 600;
}

tbody td,
tbody th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

tbody tr:nth-child(even) td,
tbody tr:nth-child(even) th {
  background: var(--color-bg-alt);
}

tbody tr:hover td,
tbody tr:hover th {
  background: var(--color-bg-hover);
}

td.numeric {
  text-align: left;
  white-space: nowrap;
}

.negative-value {
  color: var(--color-negative);
  font-weight: 600;
}

.positive-value {
  color: var(--color-positive);
}

/* ---- Expandable sector rows ---- */

.clickable-row {
  cursor: pointer;
}

.clickable-row .expand-icon {
  display: inline-block;
  width: 12px;
  color: var(--color-brand-mid);
  margin-right: 4px;
}

.subindustry-row td {
  background: #fbfcfd !important;
  font-size: 12.5px;
  color: var(--color-text-muted);
  padding-left: 24px;
}

.subindustry-row .subindustry-naics {
  padding-left: 28px;
  font-weight: 500;
}

/* ---- Footnote tooltip cells ---- */

.footnote-tooltip {
  display: inline-block;
  border-bottom: 1px dotted var(--color-text-muted);
  cursor: help;
  font-weight: 700;
}

/* ---- Chart ---- */

.chart-caption {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.chart-wrapper {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 16px;
  background: #fff;
  overflow: visible;
  position: relative;
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-svg .bar-positive {
  fill: var(--color-brand);
}

.chart-svg .bar-negative {
  fill: var(--color-negative);
}

.chart-svg .bar-label {
  font-size: 11px;
  fill: var(--color-text);
  font-family: 'Segoe UI', Arial, sans-serif;
}

.chart-svg .axis-label {
  font-size: 11px;
  fill: var(--color-text-muted);
  font-family: 'Segoe UI', Arial, sans-serif;
}

.chart-svg .sector-label {
  font-size: 11.5px;
  fill: var(--color-text);
  font-family: 'Segoe UI', Arial, sans-serif;
}

.chart-svg .gridline {
  stroke: var(--color-border-light);
  stroke-width: 1;
}

.chart-svg .zero-line {
  stroke: #444;
  stroke-width: 1.5;
}

.chart-svg .bar-hit {
  fill: transparent;
  cursor: pointer;
}

.chart-tooltip {
  position: absolute;
  background: var(--color-brand-section);
  color: #fff;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 12px;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  z-index: 100;
  max-width: 280px;
  line-height: 1.4;
}

.chart-tooltip[aria-hidden="true"] {
  display: none;
}

.chart-empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--color-text-muted);
  font-style: italic;
}

.unavailable-mark {
  stroke: #777;
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.8;
}

.chart-note {
  margin-top: 8px;
  padding-left: 290px;
  font-size: 12px;
  color: #666;
  font-style: italic;
}

.chart-note-dash {
  display: inline-block;
  width: 14px;
  height: 0;
  border-top: 2px solid #777;
  margin-right: 6px;
  vertical-align: middle;
}

.chart-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.chart-caption {
  margin: 0;
  flex: 1;
}

.chart-toggle {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  flex-shrink: 0;
}

.chart-toggle-btn {
  border: 0;
  background: #fff;
  color: var(--color-text);
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  border-right: 1px solid var(--color-border);
}

.chart-toggle-btn:last-child {
  border-right: 0;
}

.chart-toggle-btn:hover {
  background: #f2f5f8;
}

.chart-toggle-btn.is-active {
  background: var(--color-brand-section);
  color: #fff;
  font-weight: 700;
}

@media (max-width: 700px) {
  .chart-header-row {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ---- About / intro ---- */

.intro-card {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 14px 18px;
  margin: 18px 0;
  box-shadow: none;
}

.intro-card h2 {
  margin: 0 0 14px;
  color: var(--color-text);
  font-size: 20px;
  font-weight: 700;
}

.intro-card p {
  margin: 0 0 8px;
  color: var(--color-text);
  line-height: 1.5;
  font-size: 14px;
}

/* ---- Footer ---- */

.site-footer {
  margin: 12px 0 0;
  padding: 20px;
  background: var(--color-footer-bg);
  border-top: 1px solid #ddd;
  font-size: 13px;
  color: #333;
}

.footer-content p {
  margin: 4px 0;
}

.site-footer h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-brand-section);
  margin: 16px 0 8px;
}

.site-footer h3:first-child {
  margin-top: 0;
}

.footnote-definitions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 4px 16px;
  margin: 0;
}

.footnote-definitions.compact {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.footnote-definitions > div {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 6px;
  padding: 2px 0;
}

.footnote-definitions dt {
  font-weight: 700;
  text-align: center;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1px 0;
  height: fit-content;
}

.footnote-definitions dd {
  margin: 0;
  font-size: 12.5px;
  color: var(--color-text);
}

#symbolsContainer h3:first-child {
  margin-top: 18px;
}

/* ---- Info button + region modal ---- */

.label-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.label-row label {
  margin-bottom: 0;
}

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--color-brand-mid);
  border-radius: 50%;
  background: #fff;
  color: var(--color-brand-mid);
  font-family: 'Georgia', serif;
  font-size: 11px;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  text-transform: none;
}

.info-btn:hover {
  background: var(--color-brand-mid);
  color: #fff;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-panel {
  position: relative;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  width: min(720px, 92vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header .section-heading {
  margin: 0;
  border-bottom: 0;
  padding-bottom: 0;
}

.modal-close {
  background: transparent;
  border: 0;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px 8px;
  border-radius: 4px;
  font-family: inherit;
}

.modal-close:hover {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

.modal-body {
  padding: 16px 18px 20px;
  overflow: auto;
}

.region-map {
  position: relative;
  width: 100%;
  background: #fff;
}

.region-map svg {
  display: block;
  width: 100%;
  height: auto;
}

.region-map .county {
  stroke: #ffffff;
  stroke-width: 0.5;
  cursor: default;
  transition: filter 0.1s ease;
}

.region-map .county:hover {
  filter: brightness(1.15);
  stroke: #111;
  stroke-width: 1;
}

.region-map-tooltip {
  position: absolute;
  background: var(--color-brand-section);
  color: #fff;
  padding: 6px 9px;
  border-radius: 4px;
  font-size: 12px;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
  z-index: 10;
}

.region-map-tooltip[aria-hidden="true"] {
  display: none;
}

.region-legend {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px 12px;
  font-size: 13px;
}

.region-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.region-legend .swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* ---- Reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---- Print ---- */

@media print {
  body { font-size: 11px; max-width: none; padding: 10px; }
  .site-header { border-bottom: 2px solid var(--color-brand-section); }
  .view-tabs,
  .controls-bar,
  .skip-link,
  .download-dropdown { display: none !important; }
  .view-panel[hidden] { display: block !important; }
  .table-wrapper { overflow: visible; max-height: none; border: 1px solid #999; }
  thead th { position: static !important; }
  .site-footer { background: none; border-top: 1px solid #999; }
}
