/* mobile-touch.css — shared mobile-touch adaptations for interactive maps.
 *
 * Loaded AFTER map.css / langmap.css / trade-portal.css / gdp's map.css so
 * shared positional rules win the cascade (per spec T-SC-3).
 *
 * All rules gated by `(max-width: 767px) and (pointer: coarse)` to avoid
 * catching desktop users who resize narrow with a fine pointer.
 *
 * Spec: modules/maps/specs/mobile_touch_maps/
 */

/* Defaults: mobile-only affordances hidden on desktop. Inside the media
   query below, they are un-hidden. Media-query rule wins via source order
   when it matches. */
.map-search-icon,
.map-search-overlay {
  display: none;
}

@media (max-width: 767px) and (pointer: coarse) {

  /* ── UC-1 — Map SVG fills column width ─────────────────────────── */

  .map-canvas,
  .map-canvas svg,
  .lm-svg {
    width: 100% !important;
    max-width: 100% !important;
  }

  .map-canvas { height: auto; min-height: 280px; }

  body.trade-map-body,
  body.gdp-map-body,
  body.langmap-body {
    overflow-x: hidden;
  }

  /* ── UC-2 — 48×48 minimum touch target ─────────────────────────── */

  .map-control-bar button,
  .map-control-bar .map-step-btn,
  .map-control-bar .map-play-btn,
  .map-control-bar .map-reset-btn,
  .trade-portal-tabs [role="tab"],
  .lm-control-bar button,
  .lm-zoom-toggle button,
  .lm-endangered-toggle,
  .map-projection-toggle-host button,
  .map-search-icon,
  .map-utility-icon {
    min-width: 48px !important;
    min-height: 48px !important;
    box-sizing: border-box;
  }

  /* UC-2 — short-label swap. Elements that carry data-short-label get
     their text label hidden, and the short label rendered via ::before. */
  [data-short-label] {
    position: relative;
    font-size: 0 !important;
    letter-spacing: 0;
  }
  [data-short-label]::before {
    content: attr(data-short-label);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
  }

  /* ── UC-3 — Dropdown for continent / view strips ──────────────── */

  body[data-region="unified"] .lm-view-selector { display: none !important; }
  body[data-region="unified"] .lm-view-selector-select { display: inline-block !important; }

  /* .map-region-select is a Tier-1 hidden GDP feature — leave hidden on mobile
     for v1; surface only when Tier 3 lands with actual options. */
  .map-region-select { display: none !important; }

  /* Trade portal: hide inline search bar; overlay opener takes over. */
  .trade-map-body .map-search-wrap { display: none; }
  .trade-map-body .map-search-overlay .map-search-wrap { display: block !important; }

  /* Endangered-toggle compact on mobile */
  .lm-endangered-toggle {
    padding: 0 !important;
    width: 48px;
    height: 48px;
    font-size: 0;
  }
  .lm-endangered-toggle::before {
    content: "⚠";
    font-size: 1.3rem;
    color: var(--color-fg, #111);
  }
  .lm-filter-count { display: none; }

  /* Language-map speed / projection-toggle-host keep sensible sizing */
  .lm-speed-badge { display: none !important; }

  /* ── UC-4 — Year slider: thumb-sized, inline play ──────────────── */

  .map-slider-container,
  .map-slider-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    flex-wrap: nowrap;
  }

  .map-slider,
  input[type="range"].map-slider,
  input[type="range"].lm-timeline-range {
    flex: 1 1 auto;
    min-width: 0;
    height: 48px;
    background: transparent;
  }

  .map-slider::-webkit-slider-thumb,
  input[type="range"].map-slider::-webkit-slider-thumb,
  input[type="range"].lm-timeline-range::-webkit-slider-thumb {
    width: 48px;
    height: 48px;
  }
  .map-slider::-moz-range-thumb,
  input[type="range"].map-slider::-moz-range-thumb,
  input[type="range"].lm-timeline-range::-moz-range-thumb {
    width: 48px;
    height: 48px;
  }

  .map-play-btn,
  .map-step-btn,
  .map-reset-btn {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    padding: 0;
  }
  .map-play-btn svg,
  .map-step-btn svg,
  .map-reset-btn svg {
    width: 18px;
    height: 18px;
  }

  /* Ensure the slider area isn't pushed off by a flexbox wrap of label strings */
  .map-speed-badge { display: none !important; }

  /* ── UC-5 — Horizontal legend ──────────────────────────────────── */

  .map-legend,
  .map-legend-bar,
  .lm-legend {
    position: static !important;
    max-width: 100% !important;
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 12px;
    padding: 8px 12px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .map-legend > *,
  .lm-legend > * {
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  /* Legend data-gaps disclosure inside horizontal strip */
  .lm-legend-gaps {
    flex-shrink: 0;
  }
  .lm-legend-gaps[hidden] { display: none !important; }

  /* ── UC-6 — Utility chrome icons ───────────────────────────────── */

  .map-utility-icon,
  .about-panel-trigger {
    width: 44px;
    height: 44px;
    padding: 0;
  }
  .map-utility-icon .label,
  .map-utility-icon-label {
    display: none;
  }

  /* ── UC-7 — Bottom sheet (shared rule for all three detail panels) */

  .map-detail-panel,
  .lm-detail-panel,
  .map-side-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-height: 60vh;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--color-border, #e2e8f0);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.25s ease-out;
    z-index: 600;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .map-detail-panel.open,
  .lm-detail-panel.is-open,
  .map-side-panel.open,
  .map-side-panel.is-open {
    transform: translateY(0);
  }

  /* ── UC-8 — Narrative below map, not beside it ────────────────── */

  .map-era-surface {
    position: static !important;
    width: 100% !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    margin-top: 12px;
  }

  .map-comparison-card.comparison-card--inline {
    position: static !important;
    width: 100% !important;
    left: auto;
    right: auto;
    top: auto;
    margin-top: 12px;
    order: 10;
  }

  /* ── Search overlay (shared, used by T-TR-2, T-GD-4, T-LM-2) ──── */

  .map-search-overlay {
    position: fixed;
    inset: 0;
    z-index: 700;
    background: var(--color-bg, #fff);
    display: none;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
  }
  .map-search-overlay.map-search-overlay--open {
    display: flex;
  }
  .map-search-overlay .map-search-overlay-close {
    align-self: flex-end;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-fg, #111);
  }
  .map-search-overlay .map-search-wrap,
  .map-search-overlay .lm-search-wrap {
    display: block !important;
    width: 100%;
    position: static;
  }
  .map-search-overlay input[type="text"] {
    width: 100%;
    min-height: 44px;
    font-size: 1rem;
    padding: 10px 12px;
    box-sizing: border-box;
  }

  /* Search-icon button — hidden on desktop, visible only when a host
     page mounts one in a map control area. */
  .map-search-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: 8px;
    cursor: pointer;
    padding: 0;
    color: var(--color-fg, #111);
  }
  .map-search-icon svg { width: 22px; height: 22px; }

  /* ── Language-map specific overrides ──────────────────────────── */

  .lm-search-wrap { display: none; }  /* inline wrap hidden; overlay takes over */
  body[data-region="unified"] .lm-search-wrap { display: none; }

  .lm-zoom-toggle {
    display: inline-flex;
    gap: 4px;
  }
  .lm-zoom-toggle button {
    padding: 0 !important;
  }
}

/* (Default hiding for .map-search-icon / .map-search-overlay is at the top
   of this file, before the media-query rule that un-hides them on mobile.) */
