:root {
  color-scheme: light;
  /* Warm, single-accent farm theme built on the Morro do Peão brand red. */
  --primary: #7c0303;
  --primary-dark: #5a0202;
  --primary-soft: #f6ebe7;
  --canvas: #ffffff;
  --surface-dark: #1c1512;
  --bg: #f4efe6;
  --surface: #ffffff;
  --surface-2: #efe8db;
  --line: #e4dccc;
  --hairline-strong: #4a3f38;
  --text: #211b16;
  --body: #4a4138;
  --muted: #8c8073;
  /* Accent alias: everything that used the old blue now reads as brand red. */
  --blue: var(--primary);
  --radius: 8px;
  --radius-lg: 14px;
  /* Soft warm elevation for content cards; sharp chrome shadow for sticky bars. */
  --shadow: none;
  --shadow-soft: 0 6px 22px rgba(46, 30, 20, 0.08);
  --shadow-chrome: 0 8px 24px rgba(46, 30, 20, 0.16);
  /* Data-visualization palette (legend ramp, material dots) stays quantitative. */
  --teal: #2a9d8f;
  --amber: #f4a261;
  --red: #e76f51;
  --violet: #7b61ff;
}

/* Local Leaflet fallback. Keeps the map usable if the CDN stylesheet is blocked. */
.leaflet-container {
  position: relative;
  overflow: hidden;
  background: #dfe6ed;
  outline: 0;
  touch-action: pan-x pan-y;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-container img,
.leaflet-container svg,
.leaflet-container canvas {
  max-width: none !important;
  max-height: none !important;
}

.leaflet-container img.leaflet-image-layer,
.leaflet-container .leaflet-tile {
  max-width: none !important;
  max-height: none !important;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-map-pane {
  z-index: auto;
}

.leaflet-zoom-animated {
  transform-origin: 0 0;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control {
  float: left;
  clear: both;
  margin: 10px;
}

.leaflet-right .leaflet-control {
  float: right;
}

.leaflet-control-zoom a {
  display: block;
  width: 30px;
  height: 30px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  color: #1f2d3a;
  text-align: center;
  text-decoration: none;
  font-size: 20px;
  font-weight: 800;
  line-height: 30px;
}

.leaflet-control-zoom a:last-child {
  border-bottom: 0;
}

.leaflet-control-layers {
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(17, 29, 43, 0.14);
}

.leaflet-control-layers-toggle {
  display: block;
  width: 34px;
  height: 34px;
  background:
    linear-gradient(#ffffff, #ffffff),
    #ffffff;
}

.leaflet-control-layers-toggle::before {
  display: block;
  color: #1f2d3a;
  content: "▦";
  text-align: center;
  font-size: 21px;
  line-height: 34px;
}

.leaflet-control-layers-list {
  display: none;
  min-width: 128px;
  padding: 8px 10px;
  color: #1f2d3a;
  font-size: 13px;
}

.leaflet-control-layers-expanded .leaflet-control-layers-list {
  display: block;
}

.leaflet-control-layers-expanded .leaflet-control-layers-toggle {
  display: none;
}

.leaflet-control-layers label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  min-height: 26px;
}

.leaflet-control-layers input {
  width: 14px;
  height: 14px;
  min-height: 14px;
  padding: 0;
}

.leaflet-popup {
  position: absolute;
  text-align: center;
  margin-bottom: 20px;
}

.leaflet-popup-content-wrapper {
  padding: 1px;
  text-align: left;
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(17, 29, 43, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 20px;
  min-height: 72px;
  padding: 14px 24px;
  background: var(--surface-dark);
  color: #ffffff;
  border-bottom: 1px solid var(--hairline-strong);
}

/* Section nav lives inside the single header (no separate top bar). */
.topbar .topbar-nav {
  margin-left: 0;
}

@media (max-width: 1080px) {
  .topbar .topbar-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  object-fit: contain;
  /* Logo art is dark red on white; sit it on a white tile so it reads on black. */
  padding: 4px;
  background: #ffffff;
  border-radius: var(--radius);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  line-height: 1.3;
}

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

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
}

.icon-button {
  width: 38px;
  height: 38px;
  color: #f8fbff;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.12);
}

.icon-button:hover,
.icon-button.is-active {
  background: rgba(255, 255, 255, 0.18);
}

.icon-button svg,
.text-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.dataset-picker {
  display: block;
  min-width: 0;
}

.dataset-picker select {
  width: auto;
  min-width: 180px;
  max-width: 280px;
  min-height: 38px;
  padding: 0 12px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
}

.dataset-picker select:focus {
  border-color: #ffffff;
  box-shadow: none;
}

/* button-primary: the universal red CTA (design.md). */
.button-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  background: var(--primary);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.button-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.button-primary svg {
  width: 17px;
  height: 17px;
  stroke-width: 2;
}

.button-primary:disabled,
.icon-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.filter-panel,
.event-panel,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.filter-panel,
.event-panel {
  padding: 14px;
}

.filter-panel {
  display: grid;
  gap: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.section-title h2,
.panel h2 {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
}

.text-button {
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  color: #21313f;
  border-color: var(--line);
  background: var(--surface-2);
  font-size: 13px;
}

.text-button:hover {
  background: #e4ebf2;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.checkbox-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
  min-height: 34px;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: var(--blue);
}

.checkbox-row span {
  color: #273747;
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  border-width: 2px;
  box-shadow: none;
}

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--body);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.event-panel {
  min-height: 280px;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.event-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-right: 2px;
  overflow: auto;
}

.event-item {
  display: grid;
  gap: 7px;
  width: 100%;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.event-item:hover,
.event-item.is-selected {
  border-color: var(--primary);
  background: #fbf2f2;
}

.event-item.is-selected {
  box-shadow: inset 3px 0 0 var(--primary);
}

.event-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
}

.event-title span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.event-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.event-meta strong {
  display: block;
  color: var(--text);
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 16px;
  overflow: auto;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(18px, 2vw, 28px);
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.map-panel {
  position: relative;
  min-height: 520px;
  height: min(64vh, 720px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #dfe6ed;
  box-shadow: var(--shadow-soft);
}

.view-tabs {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.view-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 13px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #314250;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.view-tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.view-tab.is-active {
  background: var(--text);
  color: #ffffff;
}

.view-tab svg {
  width: 17px;
  height: 17px;
}

#map {
  width: 100%;
  height: 100%;
}

.map-status {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 500;
  max-width: min(420px, calc(100% - 28px));
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  color: #263542;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(17, 29, 43, 0.12);
}

.map-mode {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 500;
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(17, 29, 43, 0.12);
}

.basemap-mode {
  top: 68px;
}

.mode-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 86px;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #314250;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.mode-button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.mode-button.is-active {
  background: var(--text);
  color: #ffffff;
}

.mode-button svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.2;
}

.primary-mode-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-mode-button:hover,
.primary-mode-button.is-active {
  background: var(--primary-dark);
  color: #ffffff;
}

.animation-controls {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 520;
  display: grid;
  gap: 10px;
  max-width: 760px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 24px rgba(17, 29, 43, 0.14);
}

.animation-controls.is-hidden {
  display: none;
}

.animation-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.speed-control span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.speed-control select {
  width: 92px;
  min-height: 34px;
}

.animation-slider {
  width: 100%;
  min-height: 20px;
  padding: 0;
  accent-color: var(--primary);
}

.animation-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  color: #263542;
  font-size: 12px;
  font-weight: 800;
}

.map-status.is-hidden {
  display: none;
}

.legend {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 500;
  min-width: 190px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  color: #263542;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(17, 29, 43, 0.12);
}

.legend-title {
  margin-bottom: 8px;
  font-weight: 800;
}

.legend-ramp {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), #f4d35e, var(--red));
}

.legend-values {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1.15fr) repeat(3, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.panel {
  min-width: 0;
  padding: 14px;
}

.selected-panel {
  min-height: 260px;
}

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

.detail-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.detail-list dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 750;
}

.chart-panel {
  height: 260px;
}

.chart-panel canvas {
  width: 100% !important;
  height: 210px !important;
  margin-top: 10px;
}

.quality-panel {
  margin-top: 14px;
}

.quality-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.quality-item {
  min-width: 0;
  padding: 10px;
  border: 1px solid #f1cf9f;
  border-radius: var(--radius);
  background: #fff8ed;
  color: #4f3923;
  font-size: 13px;
  line-height: 1.35;
}

.quality-item strong {
  display: block;
  margin-bottom: 4px;
  color: #2b2118;
}

.empty-state {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
}

.leaflet-popup-content {
  min-width: 180px;
  margin: 12px;
  font: 13px/1.4 Inter, ui-sans-serif, system-ui, sans-serif;
}

.popup-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 10px;
}

.popup-grid dt {
  color: #5f6d7a;
  font-weight: 700;
}

.popup-grid dd {
  margin: 0;
  font-weight: 700;
}

/* --- Signature corner square (design.md) --- */
.corner-square {
  position: absolute;
  top: 0;
  left: 0;
  width: 12px;
  height: 12px;
  background: var(--primary);
}

/* Mark metric cards with a clean brand accent bar at the top. */
.metric {
  position: relative;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--primary);
}

/* --- Import modal + drop zone --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.55);
}

.modal.is-hidden {
  display: none;
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  padding: 32px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-chrome);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.modal-head .icon-button {
  color: var(--text);
  background: transparent;
  border-color: transparent;
}

.modal-head .icon-button:hover {
  background: var(--surface-2);
}

.modal-lede {
  margin: 0 0 20px;
  color: var(--body);
  font-size: 15px;
  line-height: 1.5;
}

.dropzone {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 36px 20px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--primary);
  outline: none;
}

.dropzone.is-dragover {
  border-color: var(--primary);
  background: #fbf2f2;
}

.dropzone svg {
  width: 34px;
  height: 34px;
  color: var(--primary);
  stroke-width: 1.75;
}

.dropzone p {
  margin: 0;
  font-size: 14px;
}

.dropzone p strong {
  color: var(--text);
}

.dropzone-hint {
  color: var(--muted);
  font-size: 13px;
}

.import-status {
  margin: 16px 0 0;
  min-height: 20px;
  font-size: 14px;
  font-weight: 700;
}

.import-status[data-kind="error"] {
  color: var(--primary);
}

.import-status[data-kind="ok"] {
  color: #3f8500;
}

.import-status[data-kind="loading"] {
  color: var(--muted);
}

@media (max-width: 1180px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

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

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 900;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .event-panel {
    max-height: 360px;
  }

  .metrics,
  .detail-grid,
  .quality-list {
    grid-template-columns: 1fr;
  }

  .map-panel {
    min-height: 420px;
    height: 58vh;
  }

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

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
    justify-content: flex-end;
  }

  .date-row,
  .detail-list,
  .event-meta {
    grid-template-columns: 1fr;
  }

  .workspace,
  .sidebar {
    padding: 12px;
  }

  .legend {
    left: 14px;
    right: auto;
    bottom: 58px;
  }

  .animation-head {
    align-items: stretch;
    flex-direction: column;
  }

  .speed-control {
    justify-content: space-between;
    margin-left: 0;
  }

  .animation-stats {
    grid-template-columns: 1fr;
  }
}
