/* Visor MapBiomas — estilos
 *
 * Sin dependencias externas aparte de MapLibre GL (cargada desde
 * /static/vendor/maplibre-gl.css). Sin CDN: el visor debe funcionar
 * desconectado.
 */

:root {
  --bg-page: #f4f4f2;
  --bg-panel: #ffffff;
  --bg-panel-alt: #fafafa;
  --bg-bar: #1f2937;
  --bg-bar-fg: #f9fafb;
  --bg-bar-fg-muted: #cbd5e1;
  --fg-text: #111827;
  --fg-muted: #4b5563;
  --fg-strong: #0b1320;
  --border: #d1d5db;
  --border-strong: #6b7280;
  --accent: #2563eb;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.05);
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-page);
  color: var(--fg-text);
  font-family: var(--font-stack);
  font-size: 14px;
  line-height: 1.4;
}

body {
  display: grid;
  /* Two explicit columns. ``minmax(0, 1fr)`` keeps the map column from
   * claiming a min-content width that would otherwise push the layout
   * into a horizontal overflow at narrow viewports. Every row sizes
   * to its own content: the map row gets an explicit viewport-
   * derived height (see .map-panel below) so it never collapses
   * regardless of panel size, and the panel grows to fit its own
   * content — the document scrolls past the panel when its content
   * exceeds the viewport. The panel can therefore never steal
   * space from the map by construction. */
  grid-template-columns: 320px minmax(0, 1fr);
  grid-template-rows: auto auto auto auto;
  grid-template-areas:
    "header header"
    "legend map"
    "panel  panel"
    "time   time";
  min-height: 100vh;
}

/* ------- Header ------- */
.viewer-header {
  grid-area: header;
  padding: 12px 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.viewer-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--fg-strong);
}

.viewer-subtitle {
  margin: 0;
  color: var(--fg-muted);
  font-size: 13px;
}

/* ------- Legend ------- */
.legend-panel {
  grid-area: legend;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 14px 14px 18px;
  overflow-y: auto;
  max-height: calc(100vh - 56px - 92px);
}

.legend-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-strong);
}

.legend-help {
  margin: 0 0 10px;
  color: var(--fg-muted);
  font-size: 12px;
}

.legend-groups {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-panel-alt);
}

.legend-group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.legend-group-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.legend-swatch {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.legend-group-name {
  font-weight: 600;
  flex: 1;
  color: var(--fg-strong);
}

.legend-group-code {
  color: var(--fg-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.legend-disclosure {
  width: 14px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 11px;
}

.legend-classes {
  list-style: none;
  margin: 0;
  padding: 4px 10px 10px;
  display: none;
  flex-direction: column;
  gap: 4px;
}

.legend-group.is-open .legend-classes {
  display: flex;
}

.legend-class {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--fg-text);
}

.legend-class-code {
  width: 38px;
  flex-shrink: 0;
  color: var(--fg-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.legend-class-name {
  flex: 1;
}

/* ------- Map + labelling ------- */
.map-panel {
  grid-area: map;
  position: relative;
  background: #dde3eb;
  overflow: hidden;
  /* Deterministic viewport-derived height. The map row no longer
   * competes with the panel via ``1fr`` (see the body grid), so its
   * size is independent of how tall the panel grows. Floor 260px
   * keeps the map usable at very short viewports; ceiling 720px
   * stops the map from pushing the panel offscreen on tall
   * displays. At 1280x800 → 400px (50vh); at 1042x569 → ~284px. */
  height: clamp(260px, 50vh, 720px);
}

.map {
  position: absolute;
  inset: 0;
}

.labelling {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: calc(100% - 24px);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--fg-strong);
}

.labelling-label {
  font-weight: 600;
}

.labelling-note {
  color: var(--fg-muted);
}

/* ------- Clip tool (slice T8c) -------
 *
 * Toolbar pinned to the top-left of the map. The two buttons drive the
 * draw-on-map rectangle tool: the primary button toggles draw mode, the
 * secondary button clears the committed rectangle. A short status line
 * sits below so the reader can see what the endpoint is doing without
 * leaving the map. */
.map-controls {
  position: absolute;
  left: 12px;
  top: 12px;
  max-width: calc(100% - 24px);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow);
  z-index: 1;
  font-size: 12px;
}

.map-tool {
  background: var(--accent);
  color: #ffffff;
  border: 0;
  border-radius: 4px;
  padding: 6px 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.map-tool:focus-visible {
  outline: 2px solid var(--fg-strong);
  outline-offset: 2px;
}

.map-tool[disabled] {
  background: #cbd5e1;
  color: #475569;
  cursor: not-allowed;
}

.map-tool.is-active {
  background: #1d4ed8;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
}

.map-tool-secondary {
  background: var(--bg-panel);
  color: var(--fg-strong);
  border: 1px solid var(--border);
}

.map-tool-secondary.is-active {
  background: var(--bg-panel-alt);
}

.map-tool-help {
  flex-basis: 100%;
  color: var(--fg-muted);
  font-size: 11px;
  line-height: 1.35;
}

.map-tool-status {
  flex-basis: 100%;
  color: var(--fg-text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* ------- Time bar ------- */
.time-bar {
  grid-area: time;
  background: var(--bg-bar);
  color: var(--bg-bar-fg);
  padding: 12px 18px 14px;
  border-top: 1px solid #0f172a;
}

.time-bar-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.time-bar-label {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--bg-bar-fg-muted);
}

.time-bar-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--bg-bar-fg);
}

.time-bar-slider {
  width: 100%;
  margin: 4px 0 4px;
  accent-color: var(--accent);
}

.time-bar-range {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--bg-bar-fg-muted);
  font-variant-numeric: tabular-nums;
}

/* ------- Error states ------- */
.error-banner {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 10px 14px;
  margin: 12px;
  border-radius: 6px;
  font-size: 13px;
}

@media (max-width: 960px) {
  /* Below 960px wide, the legend and the panel would crowd the map in a
   * two-column layout, so we stack everything vertically. The map keeps
   * its viewport-derived height set on .map-panel, so it stays usable
   * regardless of how tall the panel grows; the panel itself has no
   * max-height cap — the document scrolls past it. */
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
      "header"
      "legend"
      "map"
      "panel"
      "time";
  }
  .legend-panel {
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 720px) {
  /* Same stacking as the 960px case. The map's viewport-derived height
   * stays in effect from the base rules, and the panel still has no
   * max-height cap (the document scrolls past it). */
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
      "header"
      "legend"
      "map"
      "panel"
      "time";
  }
  .legend-panel {
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

/* ------- Composition panel (slice T8b) ------- */
.panel-panel {
  grid-area: panel;
  background: var(--bg-panel);
  /* The panel spans the full width of the body, so the old right-border
   * (which separated it from the map column in a 3-column draft) is
   * wrong here. We separate from the map row above with border-top. */
  border-top: 1px solid var(--border);
  padding: 14px 14px 18px;
  /* No max-height and no overflow here: the panel grows with its
   * content and the document scrolls when the panel is taller than
   * the viewport. The map row has its own viewport-derived height
   * (see .map-panel above), so freeing the panel never shrinks the
   * map. The internal flex layout still pushes the D7 labelling
   * toward the bottom of the panel via margin-top: auto on
   * .panel-labelling — without a fixed height, that auto margin
   * collapses once the panel is taller than the sum of its content,
   * which is the intended behaviour (no inner scrollbar to chase). */
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-strong);
}

.panel-help {
  margin: 0 0 4px;
  color: var(--fg-muted);
  font-size: 12px;
}

.panel-chart {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 6px;
}

.panel-chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.panel-chart-title {
  font-size: 13px;
  font-weight: 600;
  fill: var(--fg-strong);
  font-family: var(--font-stack);
}

.panel-chart-subtitle {
  font-size: 11px;
  fill: var(--fg-muted);
  font-family: var(--font-stack);
}

.panel-chart-axis-grid {
  stroke: rgba(15, 23, 42, 0.08);
  stroke-width: 1;
}

.panel-chart-axis-baseline {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.panel-chart-tick {
  font-size: 10px;
  fill: var(--fg-muted);
  font-family: var(--font-stack);
}

.panel-chart-axis-label {
  font-size: 10px;
  fill: var(--fg-muted);
  font-family: var(--font-stack);
}

.panel-chart-cursor {
  stroke: #111827;
  stroke-width: 1.5;
}

.panel-chart-area {
  stroke: rgba(255, 255, 255, 0.6);
  stroke-width: 0.5;
}

.panel-chart-hit {
  cursor: pointer;
}

.panel-legend {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.panel-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--fg-text);
}

.panel-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.panel-legend-label {
  flex: 1;
}

.panel-legend-value {
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

.panel-breakdown-title {
  margin: 12px 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-strong);
}

.panel-breakdown-empty {
  margin: 0;
  font-size: 12px;
  color: var(--fg-muted);
}

.panel-breakdown-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel-bar {
  display: flex;
  align-items: stretch;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-panel-alt);
  padding: 6px 8px;
}

.panel-bar-swatch {
  width: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.panel-bar-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.panel-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
}

.panel-bar-name {
  font-weight: 600;
  color: var(--fg-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-bar-code {
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
  font-size: 11px;
}

.panel-bar-track {
  position: relative;
  height: 6px;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 3px;
  overflow: hidden;
}

.panel-bar-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
}

.panel-bar-footer {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

.panel-bar-area {
  color: var(--fg-text);
}

.panel-bar-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 4px 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-strong);
}

/* The clip result adds an extra summary line under the year total so the
 * reader sees the rectangle's area / valid area / nodata split without
 * doing the arithmetic in their head. */
.panel-bar-window-summary {
  padding: 4px 4px 0;
  font-size: 11px;
  color: var(--fg-muted);
}

.panel-bar-window-label {
  font-variant-numeric: tabular-nums;
}

.panel-bar-total-label {
  color: var(--fg-muted);
  font-weight: 400;
}

.panel-labelling {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
}

.panel-extent-label {
  font-weight: 600;
  color: var(--fg-strong);
}

.panel-boundary-note {
  color: var(--fg-muted);
}
