/* NPN Mobile Map Layout v1 */

:root {
  --npn-mobile-bg: rgba(5, 9, 5, .96);
  --npn-mobile-border: rgba(125, 211, 252, .30);
  --npn-mobile-text: #ecfdf5;
  --npn-mobile-muted: rgba(236,253,245,.62);
  --npn-mobile-accent: rgba(132,255,132,.86);
  --npn-safe-top: env(safe-area-inset-top, 0px);
  --npn-safe-bottom: env(safe-area-inset-bottom, 0px);
}

.npn-mobile-bottom-nav {
  display: none !important;
}

.npn-mobile-tools-sheet {
  display: none;
}

/* These classes are added by JS. Desktop remains untouched unless screen is small. */
body.npn-mobile-device,
body.npn-mobile-width {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* Generic mobile/tablet layout */
@media (max-width: 900px), (pointer: coarse) and (max-width: 1180px) {
  html,
  body {
    height: 100%;
    overflow: hidden !important;
  }

  body {
    background: #020602 !important;
  }

  .topbar,
  header.topbar,
  body > header,
  .app-header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 15000 !important;
    min-height: calc(74px + var(--npn-safe-top)) !important;
    padding-top: var(--npn-safe-top) !important;
    background: rgba(3, 8, 3, .98) !important;
    border-bottom: 1px solid rgba(125,211,252,.20) !important;
  }

  .topbar .brand,
  header .brand,
  .brand {
    min-width: 0 !important;
  }

  .topbar h1,
  header h1 {
    font-size: 18px !important;
    line-height: 1.1 !important;
    margin: 0 !important;
    max-width: calc(100vw - 90px) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .topbar .subtitle,
  header .subtitle {
    font-size: 11px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: calc(100vw - 90px) !important;
  }

  .topbar .actions,
  nav.actions,
  .actions {
    position: fixed !important;
    top: calc(74px + var(--npn-safe-top)) !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 14999 !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 7px !important;
    padding: 7px 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    background: rgba(3, 8, 3, .96) !important;
    border-bottom: 1px solid rgba(125,211,252,.16) !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }

  .topbar .actions::-webkit-scrollbar,
  nav.actions::-webkit-scrollbar,
  .actions::-webkit-scrollbar {
    display: none !important;
  }

  .topbar .actions button,
  nav.actions button,
  .actions button,
  .topbar .actions a,
  nav.actions a,
  .actions a {
    flex: 0 0 auto !important;
    min-height: 42px !important;
    padding: 10px 12px !important;
    font-size: 13px !important;
    white-space: nowrap !important;
  }

  /* Hide right side on mobile */
  .right-panel,
  .right-sidebar,
  aside:has(.priority-nodes),
  aside:has(#priorityNodes),
  .priority-nodes,
  #priorityNodes {
    display: none !important;
  }

  /* Turn left filters into drawer */
  .sidebar,
  .left-sidebar,
  aside.filters,
  #filters,
  .filters-panel {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: var(--npn-safe-bottom) !important;
    top: auto !important;
    width: auto !important;
    max-width: none !important;
    max-height: 62vh !important;
    z-index: 16000 !important;
    overflow: auto !important;
    transform: translateY(calc(100% + 76px)) !important;
    transition: transform .22s ease !important;
    background: rgba(4, 10, 4, .98) !important;
    border-top: 1px solid rgba(125,211,252,.30) !important;
    box-shadow: 0 -18px 48px rgba(0,0,0,.45) !important;
    -webkit-overflow-scrolling: touch !important;
  }

  body.npn-mobile-filters-open .sidebar,
  body.npn-mobile-filters-open .left-sidebar,
  body.npn-mobile-filters-open aside.filters,
  body.npn-mobile-filters-open #filters,
  body.npn-mobile-filters-open .filters-panel {
    transform: translateY(0) !important;
  }

  .sidebar input,
  .sidebar select,
  .sidebar button,
  .left-sidebar input,
  .left-sidebar select,
  .left-sidebar button,
  aside.filters input,
  aside.filters select,
  aside.filters button {
    min-height: 44px !important;
    font-size: 16px !important; /* prevents iOS zoom on focus */
  }

  /* Map takes the screen */
  main,
  .app,
  .layout,
  .content,
  .map-layout,
  .page,
  .map-page {
    height: 100vh !important;
    width: 100vw !important;
    overflow: hidden !important;
    display: block !important;
  }

  #map,
  .leaflet-container {
    position: fixed !important;
    top: calc(124px + var(--npn-safe-top)) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: var(--npn-safe-bottom) !important;
    width: 100vw !important;
    height: auto !important;
    min-height: 0 !important;
    z-index: 1 !important;
  }

  .leaflet-left {
    left: 8px !important;
  }

  .leaflet-top {
    top: calc(132px + var(--npn-safe-top)) !important;
  }

  .leaflet-bottom {
    bottom: calc(12px + var(--npn-safe-bottom)) !important;
  }

  .leaflet-control-zoom a {
    width: 42px !important;
    height: 42px !important;
    line-height: 42px !important;
    font-size: 25px !important;
  }

  .leaflet-control-attribution {
    display: none !important;
  }

  /* Custom panels become mobile sheets. */
  .npn-map-layer-control,
  .npn-solar-control,
  .npn-solar-forecast-control,
  .npn-range-control,
  .npn-rf-control,
  #npn-rf-command-center,
  #npn-node-solar-forecast,
  #npn-home-spacewx-badge,
  #npn-hamclock-panel {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    bottom: calc(12px + var(--npn-safe-bottom)) !important;
    top: auto !important;
    width: auto !important;
    max-width: none !important;
    max-height: 58vh !important;
    overflow: auto !important;
    z-index: 16500 !important;
    font-size: 14px !important;
    -webkit-overflow-scrolling: touch !important;
  }

  #npn-rf-command-center,
  #npn-node-solar-forecast,
  #npn-home-spacewx-badge {
    width: auto !important;
    transform: none !important;
  }

  #npn-rf-command-center .npn-rf-shell,
  #npn-node-solar-forecast .npn-node-solar-shell,
  #npn-home-spacewx-badge .npn-home-spacewx-card {
    max-height: inherit !important;
  }

  /* Desktop toolbox blocks the map on touch screens. Mobile uses Tools sheet instead. */
  #npn-panel-dock.npn-panel-dock {
    display: none !important;
  }

  .npn-mobile-tools-sheet {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(10px + var(--npn-safe-bottom));
    z-index: 16502;
    display: grid;
    gap: 10px;
    max-height: min(58vh, 420px);
    padding: 10px;
    overflow: auto;
    border: 1px solid var(--npn-mobile-border);
    background: var(--npn-mobile-bg);
    color: var(--npn-mobile-text);
    box-shadow: 0 -18px 48px rgba(0,0,0,.48);
    transform: translateY(calc(100% + 24px));
    transition: transform .22s ease;
    -webkit-overflow-scrolling: touch;
  }

  body.npn-mobile-tools-open .npn-mobile-tools-sheet {
    transform: translateY(0);
  }

  .npn-mobile-tools-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(125,211,252,.18);
  }

  .npn-mobile-tools-title {
    display: grid;
    gap: 2px;
    min-width: 0;
  }

  .npn-mobile-tools-title b {
    font-size: 13px;
    letter-spacing: .12em;
    text-transform: uppercase;
  }

  .npn-mobile-tools-title span {
    color: var(--npn-mobile-muted);
    font-size: 11px;
  }

  .npn-mobile-tools-close {
    flex: 0 0 auto;
    min-height: 34px;
    border: 1px solid var(--npn-mobile-border);
    background: rgba(15,24,15,.94);
    color: var(--npn-mobile-text);
    padding: 0 10px;
    font-weight: 950;
    text-transform: uppercase;
  }

  .npn-mobile-tools-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .npn-mobile-tool-btn {
    min-width: 0;
    min-height: 46px;
    border: 1px solid rgba(125,211,252,.28);
    border-left: 3px solid var(--npn-mobile-accent);
    background: rgba(15, 31, 20, .84);
    color: var(--npn-mobile-text);
    padding: 8px 9px;
    text-align: left;
    font-weight: 950;
    text-transform: uppercase;
    letter-spacing: .04em;
  }

  .npn-mobile-tool-btn span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .npn-mobile-tools-empty {
    border: 1px dashed rgba(125,211,252,.22);
    color: var(--npn-mobile-muted);
    padding: 12px;
    font-size: 12px;
    line-height: 1.35;
  }

  .npn-panel-collapsed {
    max-height: 42px !important;
  }

  .npn-mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 15500;
    background: rgba(0,0,0,.32);
    display: none;
  }

  body.npn-mobile-filters-open .npn-mobile-backdrop,
  body.npn-mobile-panel-open .npn-mobile-backdrop,
  body.npn-mobile-tools-open .npn-mobile-backdrop {
    display: block;
  }

  .npn-mobile-toast {
    position: fixed;
    left: 50%;
    bottom: calc(18px + var(--npn-safe-bottom));
    transform: translateX(-50%);
    z-index: 18000;
    background: rgba(5, 9, 5, .96);
    border: 1px solid rgba(125,211,252,.38);
    color: var(--npn-mobile-text);
    padding: 9px 12px;
    font-size: 12px;
    font-weight: 900;
    box-shadow: 0 16px 40px rgba(0,0,0,.40);
    display: none;
  }

  .npn-mobile-toast.show {
    display: block;
  }

  body.npn-ios .topbar .actions button,
  body.npn-ios nav.actions button,
  body.npn-ios .actions button {
    min-height: 44px !important;
  }
}

/* Smaller phones */
@media (max-width: 430px) {
  .topbar h1,
  header h1 {
    font-size: 16px !important;
  }

  .topbar .subtitle,
  header .subtitle {
    font-size: 10px !important;
  }

  .topbar .actions button,
  nav.actions button,
  .actions button {
    font-size: 12px !important;
    min-height: 40px !important;
    padding: 9px 10px !important;
  }

  #map,
  .leaflet-container {
    top: calc(120px + var(--npn-safe-top)) !important;
  }

  .leaflet-top {
    top: calc(128px + var(--npn-safe-top)) !important;
  }

  .npn-mobile-tools-grid {
    grid-template-columns: 1fr;
  }

}

/* Landscape phone */
@media (max-height: 520px) and (orientation: landscape) {
  .topbar,
  header.topbar,
  body > header,
  .app-header {
    min-height: calc(50px + var(--npn-safe-top)) !important;
  }

  .topbar .actions,
  nav.actions,
  .actions {
    top: calc(50px + var(--npn-safe-top)) !important;
    padding: 5px 8px !important;
  }

  .topbar h1,
  header h1 {
    font-size: 15px !important;
  }

  #map,
  .leaflet-container {
    top: calc(96px + var(--npn-safe-top)) !important;
  }

  .leaflet-top {
    top: calc(104px + var(--npn-safe-top)) !important;
  }

  .sidebar,
  .left-sidebar,
  aside.filters,
  #filters,
  .filters-panel {
    max-height: 72vh !important;
  }

  .npn-map-layer-control,
  .npn-solar-control,
  .npn-solar-forecast-control,
  .npn-range-control,
  .npn-rf-control {
    max-height: 68vh !important;
  }
}
