:root {
  /* Material 3 Inspired Palette */
  --bg-color: #f0f4f8;
  /* Slightly cool gray background */
  --surface-main: #ffffff;
  --surface-hover: #f1f5f9;

  --text-main: #1e293b;
  --text-muted: #3d3d3d;

  --primary-color: #3b82f6;
  --primary-bg: #eff6ff;

  --border-color: #e2e8f0;

  /* Layout */
  --header-height: 44px;
  --footer-height: 44px;
  --sidebar-width: 360px;
  /* Slightly wider for better card spacing */

  /* Material Elevations */
  --shadow-1: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-2: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-3: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  /* Stats Box Colors */
  --color-blue-bg: #dbeafe;
  --color-blue-text: #1e40af;
  --color-green-bg: #dcfce7;
  --color-green-text: #166534;
  --color-amber-bg: #fef3c7;
  --color-amber-text: #92400e;
  --color-purple-bg: #f3e8ff;
  --color-purple-text: #6b21a8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-main);
  background-color: var(--bg-color);
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar map"
    "footer footer";
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr var(--footer-height);
  overflow: hidden;
}

/* Header - Elevated */
header {
  grid-area: header;
  background-color: #0F83FA;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 30;
  /* Highest layer */
  box-shadow: var(--shadow-2);
}

.header-title {
  font-size: 1.1rem;
  font-weight: 1000;
  color: #fff;
  letter-spacing: -0.025em;
}

.brand-strong {
  font-weight: 800;
}

.brand-muted {
  color: #f3f3f3;
  font-weight: 400;
}

.header-nav a {
  text-decoration: none;
  color: #fff;
  font-size: 0.875rem;
  font-weight: 1000;
  margin-left: 24px;
  padding: 8px 12px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.header-doc-link {
  font-weight: 700;
}

.header-nav a:hover {
  background-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* Sidebar - Surface */
aside {
  grid-area: sidebar;
  background-color: var(--surface-main);
  /* border-right: 1px solid var(--border-color); optional with shadow */
  box-shadow: 6px 0 10px rgba(69, 69, 69, 0.125);
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 25px;
  z-index: 20;
}

.logo-placeholder {
  width: 100%;
  height: 220px;
  background-color: transparent;
  border: none;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.logo-placeholder:hover {
  transform: scale(1.02);
}

.logo-placeholder img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  margin-left: 4px;
}

.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--primary-color);
  color: #ffffff;
  text-decoration: none;
  font-weight: 600;
  box-shadow: var(--shadow-1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.download-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
}

.sidebar-logos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: center;
}

.sidebar-logos img {
  width: 100%;
  max-height: 80px;
  object-fit: contain;
}

.sidebar-logos .logo-uw {
  max-height: 80px;
}

.sidebar-logos .logo-saswe {
  max-height: 60px;
}


/* Material Inputs */
select.grain-input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  font-size: 0.95rem;
  background-color: #fff;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
}

select.grain-input:hover {
  border-color: var(--text-muted);
}

select.grain-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px var(--primary-bg);
}

/* Material Stats Grid - The "Colored Boxes" */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  /* 2 columns */
  gap: 12px;
}

.stat-box {
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.2s;
}

.stat-box:hover {
  transform: translateY(-2px);
}

/* Color Variants */
.stat-box.blue {
  background-color: var(--color-blue-bg);
  color: var(--color-blue-text);
}

.stat-box.green {
  background-color: var(--color-green-bg);
  color: var(--color-green-text);
}

.stat-box.amber {
  background-color: var(--color-amber-bg);
  color: var(--color-amber-text);
}

.stat-box.purple {
  background-color: var(--color-purple-bg);
  color: var(--color-purple-text);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.8;
  text-transform: uppercase;
}

.stat-value {
  font-family: "Inter", sans-serif;
  /* Not mono, cleaner look */
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-unit {
  font-size: 0.85rem;
  font-weight: 500;
  margin-left: 2px;
  opacity: 0.7;
}

/* Map Area */
#map {
  grid-area: map;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 10;
}


.map-control-card {
  position: absolute;
  top: 16px;
  right: 84px;
  background: var(--surface-main);
  padding: 8px;
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
}

.map-toggle-card {
  top: auto;
  right: auto;
  left: 16px;
  bottom: 16px;
}

.canal-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 500;
  color: #000000;
  cursor: pointer;
}

.canal-toggle-text {
  color: inherit;
  font-size: inherit;
  line-height: 0.75;
}

.canal-switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.canal-switch {
  position: relative;
  width: 40px;
  height: 18px;
  border-radius: 999px;
  background: #cbd5e1;
  box-shadow: inset 0 0 0 1px var(--border-color);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.canal-switch::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: var(--shadow-1);
  transition: transform 0.2s ease;
}

.canal-switch-input:checked + .canal-switch {
  background: var(--primary-color);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.canal-switch-input:checked + .canal-switch::after {
  transform: translateX(20px);
}

.canal-switch-input:focus-visible + .canal-switch {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
}

.map-logo {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 9;
  background: transparent;
  padding: 0;
  box-shadow: none;
  width: 0;
  height: 0;
}

.map-logo img {
  display: block;
  position: absolute;
  width: 90px;
  height: auto;
}

.map-logo .logo-saswe {
  width: 92px;
  right: 2px;
  bottom: 1px;
}

.map-logo .logo-uw {
  width: 80px;
  right: 10px;
  bottom: 90px;
}

.map-control-card > span {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.map-control-card select {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  font-size: 0.875rem;
}

/* Footer */
footer {
  grid-area: footer;
  background-color: var(--surface-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  z-index: 30;
  /* Should be above map */
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  /* Subtle top shadow */
}

.footer-logos {
  display: flex;
  gap: 4px;
  align-items: center;
}


.footer-logo-text {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-muted);
  opacity: 1;
  transition: opacity 0.2s;
}

.footer-logo-text:hover {
  opacity: 1;
}

.footer-logo-sub.footer-logo-text:hover {
  opacity: 0.7;
}

.footer-logo-link {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-main);
  opacity: 1;
  text-decoration: none;
  transition: opacity 0.2s;
}

.footer-logo-link:hover {
  opacity: 1;
}


.footer-logo-uw {
  color: var(--text-main);
  opacity: 1;
}

.footer-logo-sub {
  font-weight: 400;
  color: #1f2937;
}

.footer-strong {
  font-weight: 700;
  color: var(--text-main);
}

.footer-cloudflare-logo {
  height: 26px;
  width: auto;
}

.insights-tab {
  border: #dbd4e3 1px solid;
  background: #f3e8ff;
  color: #6b21a8;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  /* box-shadow: var(--shadow-1); */
}

.insights-tab:hover {
  background: #e9d5ff;
}

.insights-tab--sidebar {
  width: 100%;
  margin-top: -10px;
}

.insights-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 64%;
  background: var(--surface-main);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.15);
  transform: translateY(100%);
  transition: transform 0.25s ease;
  z-index: 12;
  display: flex;
  flex-direction: column;
}

.insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.insights-title {
  font-weight: 600;
  color: var(--text-main);
  font-size: 0.80rem;
}

.insights-tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  flex: 1;
}

.insights-tab-button {
  border: 1px solid #f5e2a1;
  background: var(--color-amber-bg);
  color: var(--color-amber-text);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.insights-tab-button[aria-selected="true"] {
  background: var(--primary-color);
  color: #ffffff;
  border-color: var(--primary-color);
}

.insights-close {
  border: none;
  background: transparent;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
}

.insights-close:hover {
  color: var(--text-main);
}

.insights-body {
  padding: 16px;
  overflow: hidden;
  flex: 1 1 auto;
}

.insights-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  height: 100%;
}

.insights-content[hidden] {
  display: none;
}

.insights-map-card {
  border: 0px solid var(--border-color);
  border-radius: 12px;
  background: #ffffff;
  padding: 10px;
  min-height: 150px;
  max-width: 750px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  position: relative;
}

.insights-map-card--scatter {
  min-height: 260px;
  max-width: 100%;
}

.scatter-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 220px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  font-size: 0.75rem;
  line-height: 1.4;
  box-shadow: var(--shadow-2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.insights-map-card canvas {
  width: 100%;
  height: 100%;
  display: block;
  flex: 1 1 auto;
}

.insights-legend {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: -4px;
}

.insights-legend--vertical {
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 0;
}

.insights-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.insights-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #64748b;
  flex: 0 0 auto;
}

.insights-legend-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.insights-legend-heading {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
}

.insights-legend-size {
  display: grid;
  gap: 8px;
}

.insights-legend-size-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.insights-legend-size-dot {
  display: inline-block;
  border-radius: 50%;
  background: rgba(154, 22, 249, 0.6);
  border: 1px solid rgba(124, 45, 18, 0.35);
}

.insights-legend-size-dot--small {
  width: 6px;
  height: 6px;
}

.insights-legend-size-dot--medium {
  width: 10px;
  height: 10px;
}

.insights-legend-size-dot--large {
  width: 14px;
  height: 14px;
}

.insights-legend-title {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-main);
  text-align: center;
  margin-top: -20px;
}

.insights-legend-bar {
  height: 8px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: linear-gradient(90deg, #fffbe6, #1f8a3b);
}

.insights-side-card {
  border: 1px dashed var(--border-color);
  border-radius: 12px;
  padding: 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.insights-side-title {
  font-weight: 500;
  color: var(--text-main);
}

.insights-bars {
  display: flex;
  flex-direction: column;
  gap: -10px;
}

.insights-bar-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0px;
}

.insights-bar-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.insights-bar-track {
  height: 8px;
  border-radius: 999px;
  background: #f1f5f9;
  overflow: hidden;
}

.insights-bar-fill {
  height: 100%;
  background: #91cd06;
}

.insights-bar-fill--length {
  background: #91cd06;
}

.insights-bar-fill--density {
  background: #d0095c;
}

.insights-bar-value {
  font-size: 0.75rem;
  color: var(--text-main);
}

.insights-placeholder {
  border: 1px dashed var(--border-color);
  border-radius: 12px;
  height: 100%;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

body.insights-open .insights-panel {
  transform: translateY(0);
}

/* Override MapLibre defaults */
.maplibregl-ctrl-group {
  box-shadow: var(--shadow-2) !important;
  border-radius: 12px !important;
  border: none !important;
  margin-top: 16px !important;
  margin-right: 16px !important;
}

.maplibregl-ctrl-bottom-right {
  bottom: auto !important;
  right: 8px !important;
  left: auto !important;
  top: 104px !important;
}

.debug {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: var(--surface-main);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  max-width: 260px;
  z-index: 20;
}
