/* Demo-only phone layout. Linked only by the Northline demo build.
   Wider than 820px: this file does nothing, so the desktop demo matches production.
   2.0 chrome: pages live in the left rail; the top bar has brand, Network|Systems,
   rail toggle, attention, Action list, Settings. On a phone the domain toggle sits on
   its own row so it never clashes with the brand or the icon cluster. */

.demo-nav-btn {
  display: none;
}

@media (max-width: 820px) {
  .appbar {
    position: sticky;
    top: 0;
    z-index: 40;
  }
  .appbar .wrap {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    row-gap: 8px;
    min-height: 54px;
    padding: 6px 12px !important;
    max-width: none;
    width: 100%;
    box-sizing: border-box;
  }
  /* Row 1: brand · menu · attention · Action list · Settings */
  .appbar .brand {
    order: 1;
    width: auto !important;
    flex: 1 1 auto;
    min-width: 0;
    font-size: 15px;
    margin-right: 0;
    overflow: hidden;
  }
  .appbar .brand .nm {
    display: flex !important;
    min-width: 0;
    overflow: hidden;
  }
  .appbar .brand .nm,
  .appbar .brand .nm > :first-child {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  .appbar .brand .nm small,
  .appbar .brand small {
    display: none !important;
  }
  .appbar #railbtn {
    order: 2;
  }
  .appbar .bar-right {
    order: 3;
    flex: none;
    flex-wrap: nowrap;
    gap: 6px;
    margin-left: 0;
    white-space: nowrap;
  }
  /* Row 2: Network | Systems — full width, equal hit targets */
  .appbar .domain {
    order: 4;
    flex: 1 1 100%;
    width: 100%;
    display: flex;
    border-radius: 10px;
    box-sizing: border-box;
  }
  .appbar .domain button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 40px;
    padding: 8px 10px;
    font-size: 14px;
    box-sizing: border-box;
  }
  /* Very narrow phones: logo mark only so brand + icons stay on one row */
  @media (max-width: 380px) {
    .appbar .brand .nm {
      display: none !important;
    }
    .appbar .brand {
      flex: 0 0 auto;
    }
    .appbar .bar-right {
      gap: 4px;
    }
    .appbar #railbtn,
    .appbar .iconbtn.bell,
    .appbar .settings > summary,
    .appbar .health .st {
      width: 40px;
      height: 40px;
      min-width: 40px;
      min-height: 40px;
    }
  }
  .appbar .bar-gap {
    display: none;
  }
  .appbar .barq,
  .appbar .collected {
    display: none !important;
  }

  /* Compact attention pill: icon + count */
  .appbar .health .txt {
    display: none !important;
  }
  .appbar .health .st {
    padding: 7px 10px !important;
    gap: 0 !important;
    min-width: 42px;
    min-height: 42px;
    box-sizing: border-box;
    justify-content: center;
    border-radius: 10px !important;
  }
  .appbar .health .st[data-count]:not([data-count=""])::after {
    content: attr(data-count);
    font-size: 14px;
    font-weight: 700;
    margin-left: 6px;
  }

  /* Matching 42×42 hit targets for menu, Action list, Settings */
  .appbar #railbtn,
  .appbar .iconbtn.bell,
  .appbar .settings > summary {
    width: 42px;
    height: 42px;
    border: 1px solid color-mix(in srgb, var(--bar-ink, #fff) 28%, transparent);
    border-radius: 10px;
    flex: none;
    box-sizing: border-box;
  }
  .appbar #railbtn[aria-expanded="true"],
  body.demo-nav-open .appbar #railbtn {
    background: color-mix(in srgb, var(--bar-ink, #fff) 14%, transparent);
    color: var(--bar-ink, #fff);
  }
  .appbar .iconbtn.bell {
    display: inline-grid;
    place-items: center;
  }

  /* Settings summary: icon only, keep in the bar */
  .appbar .settings {
    display: block !important;
    position: static;
  }
  .appbar .settings > summary {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    font-size: 0 !important;
    gap: 0 !important;
  }
  .appbar .settings > summary .gear {
    font-size: 18px !important;
    line-height: 1;
  }

  /* Settings opens as a phone sheet under the bar (top set in JS from the bar bottom) */
  .appbar .settings .list,
  .appbar .settings .list.right {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    top: 110px; /* fallback; demo-mobile.js sets the real bar bottom + 8px */
    bottom: max(10px, env(safe-area-inset-bottom, 0px)) !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 14px 14px 20px !important;
    border-radius: 14px !important;
    box-shadow: 0 18px 48px rgba(0, 0, 0, .45) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    z-index: 60;
    background: var(--card) !important;
    color: var(--ink) !important;
    white-space: normal !important;
    box-sizing: border-box;
  }
  .appbar .settings .pal-grid {
    grid-template-columns: 1fr !important;
  }
  .appbar .settings .pal {
    white-space: normal;
  }
  .appbar .settings .seg2,
  .appbar .settings .seg3,
  .appbar .settings .seg4 {
    margin-bottom: 14px;
  }
  .appbar .settings .seg2 button,
  .appbar .settings .seg3 button,
  .appbar .settings .seg4 button {
    min-height: 44px;
    color: var(--muted) !important;
    background: var(--card) !important;
  }
  .appbar .settings .seg2 button[aria-pressed="true"],
  .appbar .settings .seg3 button[aria-pressed="true"],
  .appbar .settings .seg4 button[aria-pressed="true"] {
    background: var(--cur-bg) !important;
    color: var(--cur-ink) !important;
  }
  .appbar .settings .mi,
  .appbar .settings .list a.mi {
    min-height: 44px;
    display: flex;
    align-items: center;
    white-space: normal;
  }
  .appbar .settings .pal-note {
    white-space: normal;
  }

  /* Left rail: off-canvas drawer */
  .shell {
    position: relative;
  }
  .rail {
    position: fixed !important;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 300px) !important;
    max-width: 300px;
    z-index: 55;
    transform: translateX(-105%);
    transition: transform .18s ease;
    box-shadow: none;
    /* Clear the two-row phone app bar (brand row + Network|Systems) */
    padding-top: max(110px, env(safe-area-inset-top, 0px) + 100px);
    background: var(--card) !important;
  }
  body.demo-nav-open .rail {
    transform: translateX(0);
    box-shadow: 12px 0 32px rgba(0, 0, 0, .35);
  }
  body.demo-nav-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 50;
  }
  html[data-rail="thin"] .rail {
    width: min(86vw, 300px) !important;
  }
  html[data-rail="thin"] .rail-h .lbl,
  html[data-rail="thin"] .rail-h .chev,
  html[data-rail="thin"] .rail-h .badge,
  html[data-rail="thin"] .rail-h .newn,
  html[data-rail="thin"] .rail-sec.open .rail-group {
    display: revert;
  }
  html[data-rail="thin"] .rail-h {
    justify-content: flex-start;
    padding: 10px 14px;
  }
  html[data-rail="thin"] .appbar .brand {
    width: auto !important;
  }
  html[data-rail="thin"] .appbar .brand .nm {
    display: flex !important;
  }

  .shell-main {
    width: 100%;
    min-width: 0;
  }

  /* Page chrome */
  .wrap,
  .shell-main main.wrap {
    padding-left: 14px;
    padding-right: 14px;
    box-sizing: border-box;
  }
  .demobanner {
    font-size: 12.5px !important;
    padding: 8px 14px !important;
    line-height: 1.35;
    white-space: normal;
  }
  .crumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 0;
    line-height: 1.45;
    overflow-wrap: anywhere;
  }
  .titlerow {
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
  }
  .titlerow h1,
  main.wrap > h1 {
    font-size: 24px;
    line-height: 1.2;
    overflow-wrap: anywhere;
    min-width: 0;
  }
  /* Sign-in chip (when present) matches the other bar controls */
  .appbar .signin,
  .appbar a.signin {
    flex: none;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Collector health banner: stack link + dismiss under the message */
  .hbanner {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 10px;
  }
  .hbanner > span {
    flex: 1 1 100%;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .hbanner a {
    margin-left: 0 !important;
  }
  .hbanner .hbx {
    margin-left: auto;
  }

  /* Site page tabs: swipe sideways instead of crushing labels */
  .sitetabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    scrollbar-width: none;
  }
  .sitetabs::-webkit-scrollbar {
    display: none;
  }
  .sitetabs [role="tab"],
  .sitetabs button {
    flex: none;
    white-space: nowrap;
    min-height: 40px;
  }

  /* Home */
  .hero {
    gap: 14px;
    align-items: flex-start;
  }
  .hero .ring {
    width: 88px;
    height: 88px;
  }
  .hero h1 {
    font-size: 22px;
  }
  .hchips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .hchip {
    min-height: 40px;
    justify-content: center;
    box-sizing: border-box;
  }
  .home {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  /* Services: one column so numbers and labels stay readable */
  .svcstrip {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }
  .svcstrip .svc {
    padding: 14px 16px;
  }
  .svcstrip .svc b {
    font-size: 26px;
    line-height: 1.15;
  }
  .svcstrip .svc b.svct {
    font-size: 18px;
    line-height: 1.35;
  }
  .svcstrip .svc span {
    font-size: 14px;
  }

  .secstrip {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .secl {
    padding: 14px 16px;
  }
  .secl b {
    font-size: 28px;
  }
  /* Keep the WAN glance at its drawn size and pan sideways. Shrinking the
     viewBox into the phone width made city names unreadably small. Do not
     cap the height: the ground row sits low in the SVG and a short frame
     would hide the cities. */
  .hmap,
  .panel .hmap,
  .home > .panel .hmap {
    max-height: none;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    display: block;
    align-items: stretch;
  }
  .hmap svg,
  .panel .hmap svg,
  .home > .panel .hmap svg {
    width: auto;
    max-width: none;
    max-height: none;
    /* Fallback before demo-mobile.js sets the viewBox width; wide enough for
       the Northline ground row so labels stay near their 14px design size. */
    min-width: 1100px;
    height: auto;
  }
  .hmleg {
    gap: 8px 14px;
  }

  /* Site cards: one column so INTERNET / SWITCHES / APS / TUN stay readable */
  .sgrid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }
  .sitecard {
    padding: 16px 16px 14px 22px;
  }
  .sc-m {
    gap: 10px;
  }
  .scm b {
    font-size: 18px;
  }

  /* Search and filters */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .search {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
  }
  .fchip {
    min-height: 40px;
  }

  /* Maps and wide content */
  .diagram,
  .mapframe,
  .ommap,
  .tblwrap,
  .pathsvg,
  .wide,
  table.nets,
  table.fw,
  table.paths {
    max-width: 100%;
  }
  .diagram,
  .mapframe,
  .ommap,
  .tblwrap,
  .pathsvg {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Inventory / Systems folds: keep summaries tappable */
  .invtype > summary,
  .invsite > summary,
  details > summary {
    min-height: 44px;
  }

  /* Attention lists */
  .att > li {
    grid-template-columns: 22px 1fr;
  }
  .att .what,
  .att .det {
    grid-column: 2;
  }
  table.sites .opt {
    display: none;
  }
  .devhit {
    grid-template-columns: 22px 1fr;
  }
  .devhit > *:nth-child(n + 3) {
    grid-column: 2;
  }

  .dpanel {
    width: min(100vw - 16px, 420px);
    max-width: calc(100vw - 16px);
  }

  .nrow small {
    font-size: 13px;
    line-height: 1.45;
  }
}
