/* ---------------- Leaflet Map & Custom Map Elements ---------------- */

  /* Custom Leaflet Controls - Zoom Buttons */
  .leaflet-control-zoom {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
  }

  .leaflet-control-zoom a {
    background-color: rgba(15, 23, 42, 0.92);
    color: #f8fafc;
    border-bottom: 1px solid var(--border-subtle);
    transition: all 0.15s ease;
  }

  .leaflet-control-zoom a:hover {
    background-color: var(--bg-hover);
    color: var(--accent-cyan);
  }

  /* Light Theme Overrides for Zoom Control */
  [data-theme="light"] .leaflet-control-zoom {
    border-color: rgba(0, 0, 0, 0.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  [data-theme="light"] .leaflet-control-zoom a {
    background-color: #ffffff;
    color: #0f172a;
    border-bottom-color: rgba(0, 0, 0, 0.1);
  }

  [data-theme="light"] .leaflet-control-zoom a:hover {
    background-color: #f1f5f9;
    color: #0284c7;
  }

  /* Layer Control */
  .leaflet-control-layers {
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: #f8fafc;
    box-shadow: var(--shadow-lg);
    padding: 10px 14px;
    white-space: nowrap;
    width: auto;
    min-width: max-content;
  }

  .leaflet-control-layers-toggle {
    background-color: rgba(15, 23, 42, 0.88);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
  }

  .leaflet-control-layers label {
    font-size: 13px;
    color: #f8fafc;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
  }

  .leaflet-control-layers label span {
    white-space: nowrap;
  }

  /* Light Theme Overrides for Layer Control */
  [data-theme="light"] .leaflet-control-layers {
    background: rgba(255, 255, 255, 0.96);
    border-color: rgba(0, 0, 0, 0.15);
    color: #0f172a;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  }

  [data-theme="light"] .leaflet-control-layers-toggle {
    background-color: #ffffff;
    border-color: rgba(0, 0, 0, 0.15);
  }

  [data-theme="light"] .leaflet-control-layers label {
    color: #0f172a;
  }

  [data-theme="light"] .leaflet-control-layers-separator {
    border-top-color: rgba(0, 0, 0, 0.12);
  }

  /* Leaflet Map Attribution Bar */
  .leaflet-container .leaflet-control-attribution {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(6px);
    color: #94a3b8;
    border-top-left-radius: 4px;
    border: 1px solid var(--border-subtle);
    border-right: none;
    border-bottom: none;
    font-size: 11px;
    padding: 2px 8px;
  }

  .leaflet-container .leaflet-control-attribution a {
    color: #38bdf8;
    text-decoration: none;
  }

  .leaflet-container .leaflet-control-attribution a:hover {
    text-decoration: underline;
  }

  [data-theme="light"] .leaflet-container .leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.9);
    color: #475569;
    border-color: rgba(0, 0, 0, 0.12);
  }

  [data-theme="light"] .leaflet-container .leaflet-control-attribution a {
    color: #0284c7;
  }

  @media (max-width: 768px) {
    .leaflet-container .leaflet-control-attribution {
      font-size: 9.5px;
      max-width: 65vw;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      padding: 1px 6px;
    }
  }

  /* Compass Rose Widget in Top Right (positioned to the left of Layer Control) */
  .compass-widget {
    position: absolute;
    top: 10px;
    right: 56px;
    width: 44px;
    height: 44px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    z-index: 800;
    transition: all 0.2s ease;
  }

  .compass-widget svg {
    width: 32px;
    height: 32px;
  }

  [data-theme="light"] .compass-widget {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(0, 0, 0, 0.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  /* Popup Customization */
  .leaflet-popup-content-wrapper {
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(14px);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 4px;
  }

  .leaflet-popup-tip {
    background: rgba(15, 23, 42, 0.95);
  }

  .leaflet-popup-content {
    margin: 10px 14px;
    font-size: 13px;
    line-height: 1.4;
  }

  .popup-wreck-title {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
  }

  .popup-wreck-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
  }

  .popup-wreck-btn {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    margin-top: 6px;
    cursor: pointer;
  }

  .popup-wreck-btn:hover {
    background: var(--primary-hover);
  }

  /* Popup Close Button */
  .leaflet-container a.leaflet-popup-close-button {
    color: #94a3b8;
    padding: 3px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.15s ease;
  }

  .leaflet-container a.leaflet-popup-close-button:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.15);
  }

  [data-theme="light"] .leaflet-container a.leaflet-popup-close-button {
    color: #64748b;
  }

  [data-theme="light"] .leaflet-container a.leaflet-popup-close-button:hover {
    color: #0f172a;
    background: rgba(0, 0, 0, 0.08);
  }

  [data-theme="light"] .leaflet-popup-content-wrapper,
  [data-theme="light"] .leaflet-popup-tip {
    background: rgba(255, 255, 255, 0.98);
    color: #0f172a;
    border-color: rgba(0, 0, 0, 0.15);
  }

  [data-theme="light"] .popup-wreck-title {
    color: #0f172a;
  }

  [data-theme="light"] .popup-wreck-meta {
    color: #64748b;
  }

  /* Tooltip Customization (Dark Nautical Default & Light Theme) */
  .leaflet-tooltip,
  .leaflet-tooltip.wreck-map-tooltip {
    background: rgba(15, 23, 42, 0.96) !important;
    backdrop-filter: blur(12px);
    color: #f8fafc !important;
    border: 1px solid var(--border-subtle, #334155) !important;
    border-radius: 8px !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5) !important;
    padding: 10px 14px !important;
    line-height: 1.4 !important;
    font-family: inherit;
  }

  .leaflet-tooltip-top:before {
    border-top-color: rgba(15, 23, 42, 0.96) !important;
  }
  .leaflet-tooltip-bottom:before {
    border-bottom-color: rgba(15, 23, 42, 0.96) !important;
  }
  .leaflet-tooltip-left:before {
    border-left-color: rgba(15, 23, 42, 0.96) !important;
  }
  .leaflet-tooltip-right:before {
    border-right-color: rgba(15, 23, 42, 0.96) !important;
  }

  [data-theme="light"] .leaflet-tooltip,
  [data-theme="light"] .leaflet-tooltip.wreck-map-tooltip {
    background: rgba(255, 255, 255, 0.98) !important;
    color: #0f172a !important;
    border-color: rgba(0, 0, 0, 0.15) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12) !important;
  }

  [data-theme="light"] .leaflet-tooltip-top:before {
    border-top-color: rgba(255, 255, 255, 0.98) !important;
  }
  [data-theme="light"] .leaflet-tooltip-bottom:before {
    border-bottom-color: rgba(255, 255, 255, 0.98) !important;
  }
  [data-theme="light"] .leaflet-tooltip-left:before {
    border-left-color: rgba(255, 255, 255, 0.98) !important;
  }
  [data-theme="light"] .leaflet-tooltip-right:before {
    border-right-color: rgba(255, 255, 255, 0.98) !important;
  }

  /* ==========================================================================
     UNIFIED FLOATING MAP FAB CLUSTER (PHASE 4)
     Consolidates zoom, layers, recenter, and legend controls into a thumb FAB
     ========================================================================== */
  .mobile-map-fab-cluster {
    display: none !important;
  }

  @media (max-width: 768px) {
    /* Consolidate: Hide scattered desktop Leaflet controls on mobile */
    .leaflet-control-zoom {
      display: none !important;
    }

    /* Hide collapsed Leaflet layer toggle button from canvas (managed via FAB) */
    .leaflet-control-layers:not(.leaflet-control-layers-expanded) {
      display: none !important;
    }

    /* When expanded from FAB, present layer picker without width restriction or text wrapping */
    .leaflet-control-layers.leaflet-control-layers-expanded {
      position: absolute;
      top: 10px;
      left: 10px;
      z-index: 1050;
      width: auto !important;
      min-width: max-content !important;
      max-width: calc(100vw - 20px);
      white-space: nowrap !important;
      box-shadow: 0 8px 30px rgba(0, 0, 0, 0.65);
    }

    .leaflet-control-layers.leaflet-control-layers-expanded label,
    .leaflet-control-layers.leaflet-control-layers-expanded label span {
      white-space: nowrap !important;
    }

    /* Hide on-canvas bottom-left legend pills container on mobile (managed via FAB) */
    .legend-pills-container {
      display: none !important;
    }

    .mobile-map-fab-cluster {
      display: flex !important;
      position: absolute;
      bottom: 14px;
      right: 14px;
      z-index: 1045;
      flex-direction: column;
      align-items: flex-end;
      gap: 10px;
      pointer-events: auto;
    }

    .btn-map-fab {
      width: 48px;
      height: 48px;
      border-radius: 50%;
      background: #0284c7;
      color: #ffffff;
      border: 1.5px solid rgba(255, 255, 255, 0.25);
      box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      outline: none;
      transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
      touch-action: manipulation;
    }

    .btn-map-fab:active {
      transform: scale(0.94);
    }

    .mobile-map-fab-cluster.open .btn-map-fab {
      background: #0369a1;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    }

    .mobile-map-fab-cluster.open .fab-icon-normal {
      display: none !important;
    }

    .mobile-map-fab-cluster.open .fab-icon-close {
      display: block !important;
    }

    /* Compact 2-Column Popover Tile Widget */
    .mobile-map-fab-menu {
      width: 215px;
      background: rgba(15, 23, 42, 0.96);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      border: 1px solid rgba(148, 163, 184, 0.25);
      border-radius: 14px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
      padding: 8px;
      opacity: 0;
      transform: translateY(10px) scale(0.96);
      transition: opacity 0.18s cubic-bezier(0.16, 1, 0.3, 1), transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
      pointer-events: none;
      display: flex;
      flex-direction: column;
      gap: 6px;
    }

    .mobile-map-fab-menu.visible {
      opacity: 1;
      transform: translateY(0) scale(1);
      pointer-events: auto;
    }

    /* Top Quick Action Toolbar (Zoom - / Zoom + / Recenter UK) */
    .fab-quick-toolbar {
      display: flex;
      align-items: center;
      gap: 6px;
      padding-bottom: 6px;
      border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    }

    .fab-toolbar-btn {
      flex: 1;
      height: 32px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 4px;
      background: rgba(255, 255, 255, 0.08);
      border: 1px solid rgba(148, 163, 184, 0.22);
      border-radius: 7px;
      color: #f1f5f9;
      font-size: 11.5px;
      font-weight: 600;
      cursor: pointer;
      transition: background 0.15s ease, transform 0.1s ease;
      touch-action: manipulation;
    }

    .fab-toolbar-btn:active {
      background: #0284c7;
      color: #ffffff;
      transform: scale(0.95);
    }

    .fab-recenter-btn {
      flex: 1.25;
    }

    /* 2-Column Action Tiles Grid */
    .fab-actions-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 5px;
    }

    .fab-grid-btn {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: 6px;
      height: 34px;
      padding: 0 8px;
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid rgba(148, 163, 184, 0.18);
      border-radius: 7px;
      font-size: 11.5px;
      font-weight: 600;
      color: #f1f5f9;
      cursor: pointer;
      transition: all 0.15s ease;
      touch-action: manipulation;
      white-space: nowrap;
      box-sizing: border-box;
    }

    .fab-grid-btn:active {
      background: rgba(255, 255, 255, 0.15);
      transform: scale(0.96);
    }

    .fab-grid-btn.active {
      background: rgba(14, 165, 233, 0.25);
      border-color: #38bdf8;
      color: #38bdf8;
    }

    .fab-grid-btn-full {
      grid-column: span 2;
      justify-content: center;
    }

    .fab-grid-btn svg {
      flex-shrink: 0;
      color: #38bdf8;
    }

    /* Light Theme Styling for FAB Cluster */
    [data-theme="light"] .btn-map-fab {
      background: #0284c7;
      border-color: rgba(255, 255, 255, 0.4);
    }

    [data-theme="light"] .mobile-map-fab-menu {
      background: rgba(255, 255, 255, 0.98);
      border-color: #cbd5e1;
      box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    }

    [data-theme="light"] .fab-quick-toolbar {
      border-bottom-color: rgba(0, 0, 0, 0.1);
    }

    [data-theme="light"] .fab-toolbar-btn {
      background: #f1f5f9;
      border-color: #cbd5e1;
      color: #0f172a;
    }

    [data-theme="light"] .fab-toolbar-btn:active {
      background: #e2e8f0;
      color: #0f172a;
    }

    [data-theme="light"] .fab-grid-btn {
      background: #f8fafc;
      border-color: #cbd5e1;
      color: #0f172a;
    }

    [data-theme="light"] .fab-grid-btn:active {
      background: #e2e8f0;
    }

    [data-theme="light"] .fab-grid-btn.active {
      background: rgba(2, 132, 199, 0.15);
      border-color: #0284c7;
      color: #0284c7;
    }

    [data-theme="light"] .fab-grid-btn svg {
      color: #0284c7;
    }
  }
