/**
 * MapLibre GL Time Slider — bottom-docked timeline styles.
 *
 * Colors are driven by CSS custom properties. The light palette is the default;
 * the dark palette applies automatically via `@media (prefers-color-scheme:
 * dark)`. An explicit `theme: 'light' | 'dark'` adds a `.ts-theme-light` /
 * `.ts-theme-dark` class on the dock root that redeclares the variables, so it
 * overrides the media query.
 */

/* Light palette (default) */
.maplibregl-time-slider-dock,
.maplibregl-time-slider-dock.ts-theme-light {
  --ts-bg: #ffffff;
  --ts-shadow: rgba(0, 0, 0, 0.18);
  --ts-fg: #333333;
  --ts-fg-strong: #1f2a37;
  --ts-fg-muted: #5a5a5a;
  --ts-fg-subtle: #999999;
  --ts-border: #e0e0e0;
  --ts-tick: #707070;
  --ts-marker: #4a90d9;
  --ts-display-bg: #f5f5f5;
  --ts-btn-bg: #efefef;
  --ts-btn-border: #cccccc;
  --ts-btn-hover-bg: #e2e2e2;
  --ts-btn-hover-border: #bbbbbb;
  --ts-input-bg: #ffffff;
  --ts-input-border: #d8d8d8;
  --ts-accent: #4a90d9;
  --ts-accent-hover: #3a7bc8;
  --ts-accent-ring: rgba(74, 144, 217, 0.25);
  --ts-danger: #c0392b;
}

/* Dark palette (follows the system preference) */
@media (prefers-color-scheme: dark) {
  .maplibregl-time-slider-dock {
    --ts-bg: #1f1f1f;
    --ts-shadow: rgba(0, 0, 0, 0.6);
    --ts-fg: #e6e6e6;
    --ts-fg-strong: #f4f4f4;
    --ts-fg-muted: #b0b0b0;
    --ts-fg-subtle: #888888;
    --ts-border: #3a3a3a;
    --ts-tick: #8f8f8f;
    --ts-marker: #5a9fe0;
    --ts-display-bg: #2c2c2c;
    --ts-btn-bg: #353535;
    --ts-btn-border: #555555;
    --ts-btn-hover-bg: #454545;
    --ts-btn-hover-border: #666666;
    --ts-input-bg: #2c2c2c;
    --ts-input-border: #555555;
    --ts-accent: #5a9fe0;
    --ts-accent-hover: #4a90d9;
    --ts-accent-ring: rgba(90, 159, 224, 0.35);
    --ts-danger: #f08a80;
  }
}

/* Explicit dark override (wins over the media query) */
.maplibregl-time-slider-dock.ts-theme-dark {
  --ts-bg: #1f1f1f;
  --ts-shadow: rgba(0, 0, 0, 0.6);
  --ts-fg: #e6e6e6;
  --ts-fg-strong: #f4f4f4;
  --ts-fg-muted: #b0b0b0;
  --ts-fg-subtle: #888888;
  --ts-border: #3a3a3a;
  --ts-tick: #555555;
  --ts-marker: #5a9fe0;
  --ts-display-bg: #2c2c2c;
  --ts-btn-bg: #353535;
  --ts-btn-border: #555555;
  --ts-btn-hover-bg: #454545;
  --ts-btn-hover-border: #666666;
  --ts-input-bg: #2c2c2c;
  --ts-input-border: #555555;
  --ts-accent: #5a9fe0;
  --ts-accent-hover: #4a90d9;
  --ts-accent-ring: rgba(90, 159, 224, 0.35);
  --ts-danger: #f08a80;
}

/* Corner toggle button (clock icon) that collapses/expands the dock. The
 * selector is scoped under the toggle container so it outranks MapLibre's own
 * `.maplibregl-ctrl-group button { display: block }` rule (which would otherwise
 * win on specificity and push the clock icon to the top-left corner). */
.maplibregl-time-slider-toggle .maplibregl-time-slider-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 29px;
  height: 29px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  color: #333;
}

.maplibregl-time-slider-toggle .maplibregl-time-slider-toggle-btn svg {
  width: 20px;
  height: 20px;
}

/* Reserve-space layout wrapper: a flex column holding the map then the dock.
 * (The control also sets these inline; declared here so the .ts-docked flex
 * sizing works even if inline styles are stripped.) */
.maplibregl-time-slider-layout {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
  max-width: 100%;
  /* Never exceed the dynamic viewport. On mobile the wrapper height can resolve
   * to the large viewport (URL bar excluded) when the map fills the screen via
   * `height: 100%` or a pixel value, which pushes the docked control rows below
   * the visible (small) viewport. Capping here keeps the dock on-screen for
   * every sizing path; the flexible map child absorbs the difference.
   * `100vh` is the fallback where `dvh` is unsupported. */
  max-height: 100vh;
  max-height: 100dvh;
}

/* Dock shell. Overlay by default (fallback); reserve-space layout adds
 * `.ts-docked` to place it in normal flow below the map. */
.maplibregl-time-slider-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: stretch;
  height: 66px;
  background: var(--ts-bg);
  color: var(--ts-fg);
  border-top: 1px solid var(--ts-border);
  box-shadow: 0 -1px 6px var(--ts-shadow);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 12px;
  box-sizing: border-box;
}

.maplibregl-time-slider-dock *,
.maplibregl-time-slider-dock *::before,
.maplibregl-time-slider-dock *::after {
  box-sizing: border-box;
}

/* Reserve-space: the dock sits in normal flow below the map (not overlaid). */
.maplibregl-time-slider-dock.ts-docked {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  flex: 0 0 auto;
  width: 100%;
}

/* Collapsed: the dock is hidden; only the corner toggle remains. */
.maplibregl-time-slider-dock.ts-collapsed {
  display: none;
}

/* Generic dock inputs (range excluded — it has its own look) */
.maplibregl-time-slider-dock input:not([type='range']),
.maplibregl-time-slider-dock textarea,
.maplibregl-time-slider-dock select {
  color: var(--ts-fg);
  background: var(--ts-input-bg);
  border: 1px solid var(--ts-input-border);
  border-radius: 3px;
  padding: 4px 6px;
  font-size: 12px;
  outline: none;
}

.maplibregl-time-slider-dock input:not([type='range']):focus,
.maplibregl-time-slider-dock textarea:focus,
.maplibregl-time-slider-dock select:focus {
  border-color: var(--ts-accent);
  box-shadow: 0 0 0 2px var(--ts-accent-ring);
}

/* Shared button */
.maplibregl-time-slider-dock .time-slider-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  color: var(--ts-fg);
  background: var(--ts-btn-bg);
  border: 1px solid var(--ts-btn-border);
  border-radius: 4px;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.maplibregl-time-slider-dock .time-slider-btn:hover {
  background: var(--ts-btn-hover-bg);
  border-color: var(--ts-btn-hover-border);
}

.maplibregl-time-slider-dock .time-slider-btn.ts-active {
  background: var(--ts-accent);
  border-color: var(--ts-accent-hover);
  color: #fff;
}

/* ----- Left cluster: date + transport ----- */
.ts-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-right: 1px solid var(--ts-border);
}

.ts-playback {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ts-playback .time-slider-btn {
  width: 28px;
  height: 24px;
  padding: 0;
  font-size: 12px;
}

.ts-speed {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 4px;
  font-size: 11px;
  color: var(--ts-fg-muted);
}

.ts-speed-input {
  width: 58px;
  text-align: center;
}

/* ----- Center: scrubbable axis ----- */
.ts-axis {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: stretch;
  padding: 8px 10px 4px;
}

.ts-axis-track {
  position: relative;
  flex: 1 1 auto;
  cursor: pointer;
}

.ts-axis-track::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 20px;
  height: 1px;
  background: var(--ts-border);
}

.ts-ticks {
  position: absolute;
  inset: 0;
}

.ts-tick {
  position: absolute;
  bottom: 20px;
  width: 1px;
  height: 14px;
  background: var(--ts-tick);
  transform: translateX(-0.5px);
}

.ts-tick-major {
  width: 2px;
  height: 20px;
  background: var(--ts-fg-strong);
  transform: translateX(-1px);
}

.ts-tick-label {
  position: absolute;
  /* Anchor to the tick's baseline edge (constant) so the label sits below the
   * ticks regardless of tick height, instead of being overlapped by tall ticks. */
  bottom: -17px;
  left: 0;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--ts-fg-muted);
  white-space: nowrap;
}

.ts-marker {
  position: absolute;
  top: 0;
  bottom: 18px;
  width: 2px;
  background: var(--ts-marker);
  transform: translateX(-1px);
  pointer-events: none;
  z-index: 2;
}

/* Downward triangle at the top of the marker (the pointer). */
.ts-marker-knob {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid var(--ts-marker);
}

/* Current-date label, rendered beneath the pointer and riding with it. */
.ts-marker-label {
  position: absolute;
  top: 9px;
  left: 0;
  transform: translateX(-50%);
  padding: 1px 6px;
  background: var(--ts-marker);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1.4;
  white-space: nowrap;
  border-radius: 3px;
  pointer-events: none;
}

/* "No data for this date" badge, riding beneath the date label on the marker.
 * Hidden until the current date's source reports it has no data. A warm red
 * reads on both the light and dark map backgrounds the dock floats over. */
.ts-no-data {
  position: absolute;
  top: 30px;
  left: 0;
  transform: translateX(-50%);
  padding: 1px 6px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1.4;
  white-space: nowrap;
  border-radius: 3px;
  pointer-events: none;
  display: none;
}

.ts-no-data.ts-visible {
  display: block;
}

/* ----- Right cluster: pills + add-data ----- */
.ts-right {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-left: 1px solid var(--ts-border);
}

.ts-pills {
  display: flex;
  gap: 3px;
}

.ts-pill {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--ts-btn-border);
  background: var(--ts-btn-bg);
  color: var(--ts-fg);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.ts-pill:hover {
  background: var(--ts-btn-hover-bg);
  border-color: var(--ts-btn-hover-border);
}

.ts-pill.ts-active {
  background: var(--ts-accent);
  border-color: var(--ts-accent-hover);
  color: #fff;
}

.ts-add-data {
  white-space: nowrap;
}

/* Hide-timeline button. */
.ts-collapse-btn {
  width: 28px;
  height: 24px;
  padding: 0;
  font-size: 11px;
}

/* ----- Layers popover ----- */
/* Static so the popover anchors to .ts-right (full dock height) and floats
 * clearly above the whole dock rather than the small button. */
.ts-layers {
  position: static;
}

.ts-popover {
  position: absolute;
  right: 12px;
  bottom: calc(100% + 8px);
  width: 300px;
  min-width: 240px;
  max-width: 640px;
  display: none;
  background: var(--ts-bg);
  border: 1px solid var(--ts-border);
  border-radius: 6px;
  box-shadow: 0 2px 14px var(--ts-shadow);
  z-index: 5;
}

.ts-layers.ts-open .ts-popover {
  display: block;
}

/* Scrollable content area, kept separate from the popover so the resize grip
 * (a direct child of the popover) does not scroll away with the content. */
.ts-popover-scroll {
  max-height: 60vh;
  overflow-y: auto;
  padding: 10px;
}

/* Drag handle for resizing the popover width. Sits on the free-to-grow edge. */
.ts-resize-grip {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  cursor: ew-resize;
  z-index: 6;
  touch-action: none;
}

.ts-resize-grip.ts-grip-left {
  left: -2px;
}

.ts-resize-grip.ts-grip-right {
  right: -2px;
}

/* Subtle visual affordance: a vertical accent line that brightens on hover. */
.ts-resize-grip::before {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 3px;
  width: 3px;
  height: 32px;
  border-radius: 3px;
  background: var(--ts-border);
  transition: background 0.15s ease;
}

.ts-resize-grip:hover::before {
  background: var(--ts-accent);
}

/* Drag handle for resizing the popover height. Sits on the top edge (the
 * popover is anchored at its bottom and grows upward), inset from the corners so
 * the width grips keep those edges. */
.ts-resize-grip-v {
  position: absolute;
  top: -2px;
  left: 12px;
  right: 12px;
  height: 10px;
  cursor: ns-resize;
  z-index: 6;
  touch-action: none;
}

/* Subtle visual affordance: a horizontal accent line that brightens on hover. */
.ts-resize-grip-v::before {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 3px;
  height: 3px;
  width: 32px;
  border-radius: 3px;
  background: var(--ts-border);
  transition: background 0.15s ease;
}

.ts-resize-grip-v:hover::before {
  background: var(--ts-accent);
}

/* While dragging, suppress text selection and force the resize cursor. */
body.ts-resizing {
  cursor: ew-resize;
  user-select: none;
}

body.ts-resizing-v {
  cursor: ns-resize;
  user-select: none;
}

.ts-layer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.ts-layer-empty {
  padding: 10px;
  text-align: center;
  font-size: 12px;
  color: var(--ts-fg-subtle);
}

.ts-layer-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--ts-border);
  border-radius: 4px;
}

.ts-layer-head {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ts-layer-visible {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.ts-layer-visible input {
  accent-color: var(--ts-accent);
  cursor: pointer;
  margin: 0;
}

.ts-layer-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--ts-fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}

.ts-layer-remove {
  border: none;
  background: transparent;
  color: var(--ts-fg-subtle);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.ts-layer-remove:hover {
  color: var(--ts-fg);
}

.ts-opacity {
  width: 100%;
  accent-color: var(--ts-accent);
  cursor: pointer;
}

.ts-cog-controls {
  display: flex;
  gap: 4px;
}

.ts-cog-controls input {
  min-width: 0;
  flex: 1 1 0;
}

/* Keep the colormap dropdown from dominating the row; let it share space with
 * the rescale/nodata inputs (a touch wider so its labels stay readable). */
.ts-cog-controls .ts-cmap {
  min-width: 0;
  flex: 2 1 0;
}

/* ----- Settings ----- */
.ts-settings-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--ts-border);
}

/* Checkbox rows lay the box and label side by side (the compound selector wins
 * over the `.ts-field` column default regardless of source order). */
.ts-field.ts-field-check {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}

.ts-field.ts-field-check input {
  flex: 0 0 auto;
  accent-color: var(--ts-accent);
  cursor: pointer;
}

/* Inline group of granularity checkboxes (H/D/M/Y). */
.ts-check-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ts-check-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--ts-fg-muted);
  cursor: pointer;
}

.ts-check-group input {
  accent-color: var(--ts-accent);
  cursor: pointer;
}

/* ----- Layers ----- */
.ts-layers-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--ts-border);
}

/* "Layers" section heading above the layer list. */
.ts-layers-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--ts-fg);
  margin-bottom: 6px;
}

/* ----- Add-data form ----- */
.ts-add-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--ts-border);
}

.ts-form-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--ts-fg);
}

.ts-form-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ts-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: var(--ts-fg-muted);
}

/* The explicit-dates list wraps across a few lines: a long series is far easier
 * to scan (and edit) than the same text scrolling sideways in a one-line input. */
.ts-field textarea.ts-dates {
  resize: vertical;
  min-height: 34px;
  line-height: 1.4;
  white-space: pre-wrap;
}

/* Result of a pasted date-list URL: how many dates it yielded, or why it failed.
 * Hidden until there is something to say, so the field stays compact. */
.ts-dates-status {
  display: none;
  margin-top: 3px;
  font-size: 10px;
  line-height: 1.3;
  color: var(--ts-fg-muted);
  overflow-wrap: anywhere;
}

.ts-dates-status.ts-visible {
  display: block;
}

.ts-dates-status.ts-error {
  color: var(--ts-danger);
}

.ts-add-submit {
  align-self: flex-start;
}

/* ----- Responsive ----- */
@media (max-width: 640px) {
  .maplibregl-time-slider-dock {
    height: auto;
    flex-wrap: wrap;
    align-items: center;
    row-gap: 2px;
    padding-bottom: 4px;
  }

  /* Axis gets its own full-width row on top. Its children are absolutely
   * positioned, so it needs an explicit min-height (room for the marker label,
   * ticks, and tick labels) or the row collapses and the slider is cut off. */
  .ts-axis {
    order: -1;
    flex: 1 1 100%;
    min-height: 56px;
    padding: 8px 12px 4px;
  }

  .ts-left {
    flex: 1 1 auto;
    border-right: none;
    padding: 2px 8px;
  }

  .ts-right {
    flex: 0 1 auto;
    flex-wrap: wrap;
    border-left: none;
    padding: 2px 8px;
  }

  /* Anchor the popover to the full-width dock (not the narrow, left-aligned
   * right cluster) so it spans the screen instead of overflowing off-screen. */
  .ts-right {
    position: static;
  }

  .ts-popover {
    left: 8px;
    right: 8px;
    width: auto;
    min-width: 0;
    max-width: none;
  }

  .ts-popover-scroll {
    max-height: 66vh;
  }

  /* The full-width mobile popover spans the screen, so width resizing does not
   * apply; hide the grip to avoid an unusable handle. */
  .ts-resize-grip {
    display: none;
  }
}
/*$vite$:1*/