/* The Nightmap app shell (design overhaul, Phase 2): the one navigation, five places, the same everywhere.
   A bottom bar up to 1023px, a rail on the left from 1024px. Built by js/nm-shell.js. Reads css/nm-tokens.css only (npm run lint:ui).
   While it is on the page <html> has class ui-shell-on, and --ui-shell-bottom / --ui-shell-left say how much room it takes
   (the sheet and the toast in css/nm-kit.css sit clear of it by reading those). */
@layer ui.shell {
  /* Same values before js/nm-shell.js adds ui-shell-on, so the map controls do not jump when it arrives (layout shift) */
  html.ui2, html.ui-shell-on { --ui-shell-bottom: calc(var(--ui-bar-h) + var(--ui-safe-bottom)); --ui-shell-left: 0px; --ui-toast-lift: var(--ui-bar-h); }

  .ui-shell {
    position: fixed; z-index: var(--ui-z-bar); left: 0; right: 0; bottom: 0;
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
    height: calc(var(--ui-bar-h) + var(--ui-safe-bottom)); padding: 0 var(--ui-space-1) var(--ui-safe-bottom);
    background: var(--ui-glass); -webkit-backdrop-filter: blur(var(--ui-glass-blur)) saturate(1.2); backdrop-filter: blur(var(--ui-glass-blur)) saturate(1.2); border-top: 1px solid var(--ui-line);
    user-select: none; -webkit-user-select: none;
  }
  .ui-shell__item {
    appearance: none; display: grid; justify-items: center; align-content: center; gap: 4px; min-width: 0; margin: 0; padding: 0;
    border: 0; background: transparent; color: var(--ui-muted); text-decoration: none; cursor: pointer; position: relative;
    font: 500 10px/1 var(--ui-font-sans); letter-spacing: 0.01em;
    transition: color var(--ui-dur-control) var(--ui-ease);
    -webkit-tap-highlight-color: transparent;
  }
  .ui-shell.has-new-map { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .ui-shell__new span { text-align: center; }
  .ui-shell__item[data-place="orbitcam"] .ui-icon { color: var(--ui-orbitcam); }
  .ui-shell__item:hover { color: var(--ui-text); }
  .ui-shell__item[aria-current="page"], .ui-shell__item.is-on { color: var(--ui-accent); }
  .ui-shell__item:focus-visible { outline-offset: -4px; }
  .ui-shell__item .ui-count { position: absolute; top: 8px; left: 50%; margin-left: 6px; }

  /* What a page keeps of its own controls sits in this cluster, clear of the bar: on the map, search and home on phones */
  /* a photograph opened from a panel must sit above the sheet (the old lightboxes and the 360 viewer are 1000, the sheet 1200) */
  html.ui2 .imageLightbox, html.ui2 #panoLightbox, html.ui2 [class^="lightbox_"], html.ui2 [class^="large_"] { z-index: var(--ui-z-dialog); }

  .ui-mapbtns { position: fixed; z-index: var(--ui-z-bar); left: var(--ui-space-3); top: calc(var(--ui-space-3) + var(--ui-safe-top)); display: grid; gap: var(--ui-space-2); }
  .ui-mapbtns .ui-btn { background: var(--ui-surface-1); border-color: var(--ui-line-strong); box-shadow: var(--ui-shadow-sheet); }
  .ui-mapbtns .ui-btn:hover, .ui-mapbtns .ui-btn:active { background: var(--ui-surface-3); }

  /* the dock of quick layer toggles (js/nm-dock-ui.js, kit version): chips on a card-coloured ground so they read over the map */
  .nm-dock--ui { gap: var(--ui-space-2); align-items: flex-end; }
  .nm-dock--ui .ui-chip { background: var(--ui-surface-1); border-color: var(--ui-line-strong); box-shadow: var(--ui-shadow-sheet); color: var(--ui-text); }
  .nm-dock--ui .ui-chip:hover { background: var(--ui-surface-3); }
  .nm-dock--ui .ui-chip.is-on, .nm-dock--ui .ui-chip[aria-pressed="true"] { background: var(--ui-surface-1); border-color: var(--ui-accent); color: var(--ui-accent); }
  .nm-dock--ui .nm-dock-item, .nm-dock--ui .nm-dock-more { flex-direction: row; width: auto; height: auto; min-height: var(--ui-control-h-small); padding: 0 var(--ui-space-3); border-radius: var(--ui-radius-pill); gap: var(--ui-space-2); font: 500 var(--ui-size-small) / 1 var(--ui-font-sans); }
  .nm-dock--ui .nm-dock-label { font: inherit; color: inherit; text-shadow: none; position: static; order: 0; }
  .nm-dock--ui .nm-dock-item[hidden] { display: none; }

  /* search box and results (built inline by _initDbSearchControl): kit shape and type */
  html.ui2 .nm-search input { border-radius: var(--ui-radius-control); border-color: var(--ui-line-strong); background: var(--ui-surface-1); color: var(--ui-text); min-height: var(--ui-control-h); font-family: var(--ui-font-sans); }
  html.ui2 .nm-search ul { border-radius: var(--ui-radius-card); background: var(--ui-surface-1); border-color: var(--ui-line-strong); box-shadow: var(--ui-shadow-sheet); padding: 0; }
  html.ui2 .nm-search li { min-height: var(--ui-target); padding: var(--ui-space-2) var(--ui-space-3); border-radius: 0; border-top: 1px solid var(--ui-line); }
  html.ui2 .nm-search li:first-child { border-top: 0; }
  html.ui2 .nm-search li:hover { background: var(--ui-surface-3); }
  html.ui2 .nm-search .nm-type { font: 500 var(--ui-size-label) / var(--ui-lh-label) var(--ui-font-mono); letter-spacing: var(--ui-track-label); color: var(--ui-muted); }

  /* the Layers sheet (js/nm-layers.js) */
  .nm-layers { display: grid; gap: var(--ui-space-3); }
  .nm-layers .ui-label { margin-top: var(--ui-space-3); }
  .nm-layers .ui-label:first-child { margin-top: 0; }
  .nm-layers__list { display: grid; }
  .nm-layers .ui-switch a { color: inherit; text-decoration-color: var(--ui-muted); }

  /* a page shown in the kit sheet (js/nm-page-panel.js): the iframe fills the sheet */
  .ui-sheet__body:has(> .nm-page-host) { padding: 0; overflow: hidden; display: flex; }
  .nm-page-host { flex: 1; min-height: 0; display: flex; }
  .nm-page-kitframe { flex: 1; width: 100%; border: 0; background: var(--ui-surface-1); }

  /* the All tools list (js/nm-tools-panel.js): rows with a small photo */
  .nmt-kit { display: grid; gap: var(--ui-space-2); }
  .nmt-kit .ui-group { margin: var(--ui-space-3) 0 0; } .nmt-kit .ui-group:first-child { margin-top: 0; }
  .nmt-kit .ui-group[hidden], .nmt-kit .ui-list[hidden] { display: none; }
  .ui-row--photo { align-items: center; gap: var(--ui-space-3); }
  .ui-row__thumb { flex: none; width: 56px; height: 56px; border-radius: var(--ui-radius-control); object-fit: cover; background: var(--ui-surface-2); }
  .ui-row--photo .ui-row__main > small { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .nmt-kit__pad { display: grid; gap: var(--ui-space-2); padding: 0 var(--ui-gutter); }

  /* a signed-in header at the top of the You sheet */
  .ui-you { display: flex; align-items: center; gap: var(--ui-space-3); padding: var(--ui-space-2) 0 var(--ui-space-4); }
  .ui-you__face { flex: none; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--ui-surface-3); color: var(--ui-text); font: 700 24px/1 var(--ui-font-serif); overflow: hidden; }
  .ui-you__face img { width: 100%; height: 100%; object-fit: cover; }
  .ui-you__who { min-width: 0; display: grid; gap: 2px; }
  .ui-you__who .ui-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  @media (min-width: 1024px) {
    html.ui2, html.ui-shell-on { --ui-shell-bottom: 0px; --ui-shell-left: var(--ui-rail-w); --ui-toast-lift: 0px; }
    .ui-shell {
      right: auto; top: 0; width: var(--ui-rail-w); height: auto; padding: calc(var(--ui-space-3) + var(--ui-safe-top)) 0 var(--ui-space-3);
      grid-template-columns: none; grid-auto-rows: 60px; align-content: start; border-top: 0; border-right: 1px solid var(--ui-line);
    }
    .ui-shell.has-new-map { grid-template-columns: none; }
    .ui-shell__item { font-size: 11px; }
    .ui-shell__item { margin: 2px var(--ui-space-1); border-radius: var(--ui-radius-control); }
    .ui-shell__item[aria-current="page"], .ui-shell__item.is-on { background: var(--ui-action); color: var(--ui-on-action); }
    .ui-shell__item[aria-current="page"]:hover, .ui-shell__item.is-on:hover { color: var(--ui-on-action); }
    .ui-shell__item .ui-count { top: 6px; }
    .ui-mapbtns { display: none; }

    /* class ui-shell-top on <html>: the five places are a pill of tools top left instead of the rail (the 3D map, profile settings) */
    html.ui-shell-top, html.ui2.ui-shell-top { --ui-shell-left: 0px; }
    html.ui-shell-top .ui-shell { top: calc(var(--ui-safe-top) + var(--ui-space-3)); left: var(--ui-space-3); right: auto; bottom: auto; width: auto; height: auto; display: flex; gap: 2px; padding: var(--ui-space-1);
      border: 1px solid var(--ui-line); border-radius: var(--ui-radius-pill); box-shadow: var(--ui-shadow-sheet); }
    html.ui-shell-top .ui-shell__item { display: flex; align-items: center; gap: var(--ui-space-2); margin: 0; height: 36px; padding: 0 var(--ui-space-3); border-radius: var(--ui-radius-pill); color: var(--ui-text); font: 600 14px/1 var(--ui-font-sans); }
    html.ui-shell-top .ui-shell__item:hover:not([aria-current="page"], .is-on) { background: var(--ui-surface-3); }
    html.ui-shell-top .ui-shell__item .ui-icon { width: 18px; height: 18px; }
  }
}

/* ---- The map page while it still has its old controls (only under ?ui=2) ----
   The old CSS marks many of these !important. Among !important rules the EARLIEST layer wins, so these live in the `force` layer, which is
   listed before `legacy`. Each rule here goes when the Map pass replaces the control it adjusts. */
@layer force {
  /* replaced by the shell: the account cluster (You), and the Tools, Planetarium and Shop buttons of the old tools bar (Plan, Sky, Shop) */
  html.ui2 .nm-acct,
  html.ui2 .nm-toolbar-btn--tools, html.ui2 .nm-toolbar-btn--planetarium, html.ui2 .nm-toolbar-btn--shop, html.ui2 .nm-toolbar-btn--transits { display: none !important; }
  /* the invitation to take a tour goes (brand sheet: voice). The tours themselves stay under You. */
  html.ui2 .nm-wt-nudge { display: none !important; }

  @media (max-width: 1023px) {
    /* phones and tablets: the old bottom tools bar gives way to the shell; search and home move to .ui-mapbtns; Layers stays on the dock's More */
    html.ui2 .nm-toolbar { display: none !important; }
    html.ui2 .leaflet-bottom { bottom: var(--ui-shell-bottom) !important; }
    html.ui2 .nm-dock { bottom: calc(var(--ui-shell-bottom) + var(--ui-space-4)) !important; }
  }
  @media (min-width: 1024px) {
    html.ui2 .leaflet-left { left: var(--ui-shell-left) !important; }
    html.ui2 .nm-wt-nudge, html.ui2 #nm-debug-clear { margin-left: var(--ui-shell-left) !important; }
  }

  /* a pin panel adopted into the sheet (js/nm-pinsheet.js): the invisible Leaflet popup is never seen, and the old popup content rules must not cap its height inside the sheet */
  html.ui2 .nm-pinhost .leaflet-popup-content { max-height: none !important; overflow: visible !important; width: auto !important; margin: 0 !important; }
}

/* Map controls are built a few seconds after the page starts and settle into place as the script runs: hidden until the map has drawn so they do not count as layout shift */
@layer force {
  html.ui2:not(.nm-map-settled) .leaflet-control-container { visibility: hidden; }
}

/* The logo's bottom margin is set by body.nm-dock-phone, which js/nm-dock-ui.js adds late; same value from the start so the controls do not move (layout shift) */
@layer force {
  @media (max-width: 1023px) {
    html.ui2 .leaflet-bottom.leaflet-right .leaflet-control:has(#nm-logo-ctl) { margin-bottom: 4px !important; }
  }
}
