/* Responsive layer (S5): phones 360–430 px (portrait and landscape) and tablets 768–1024 px.
   Loaded after every static stylesheet. Desktop is untouched: each rule below sits inside a media query that does not
   match at 1280 px and wider (the top bar keeps its tabs down to 1181 px). Tokens only (css/tokens.css).

   css/phone.css (loaded after this file) replaces the menu button by a bottom navigation bar on phones (<= 820 px wide or
   <= 500 px tall); the menu mode below stays the navigation of tablets (821-1180 px).

   Breakpoints
     1300  the "lectura en N s" chip no longer fits next to the tabs (was 1250: it overflowed between 1251 and 1293)
     1180  tabs collapse into the menu button                       -> "menu mode"
      820  HUD card becomes a bottom sheet, rail turns horizontal -> "compact portrait" (with min-height 501)
      700  chips shrink, page padding tightens       -> "phone"
     h500  landscape phone: short scene, side controls at 44 px      -> "short" */


.menu-btn { display: none; }

@media (max-width: 1300px) { .topbar .pill.next { display: none; } }

/* ---------- top bar: menu mode (tablets and phones) ---------- */
@media (max-width: 1180px) {
  :root { --view-pad: 18px 22px; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }      /* no font inflation when a phone rotates */
  .page { overscroll-behavior: contain; }
  .topbar { gap: 10px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .menu-btn { display: inline-flex; align-items: center; gap: 8px; flex: none; min-width: 44px; min-height: 44px; padding: 0 14px 0 12px;
    border: 1px solid rgba(255, 255, 255, .35); border-radius: var(--pill); background: none; color: #fff; font-weight: 700; font-size: 14px; white-space: nowrap; }
  .menu-btn:hover, .topbar.menu-open .menu-btn { background: rgba(255, 255, 255, .1); }
  .menu-btn__ico { flex: none; }

  #tabs { display: none; position: absolute; z-index: 31; left: 0; right: 0; top: 100%; padding: 8px 12px 12px;
    background: var(--brand); border-top: 1px solid var(--glass-line); box-shadow: 0 12px 24px rgb(0 0 0 / .4);
    max-height: calc(100dvh - var(--topbar-h)); overflow-y: auto; }
  .topbar.menu-open #tabs { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
  #tabs a { display: flex; align-items: center; min-height: 48px; padding: 0 16px; border-radius: var(--radius-sm); font-size: 15px; }

  .topbar .status { min-width: 0; }
}

/* ---------- top bar: phones ---------- */
@media (max-width: 700px) {
  :root { --view-pad: 14px 12px; }
  .topbar { gap: 8px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .menu-btn__label { display: none; }
  .menu-btn { padding: 0; justify-content: center; width: 44px; }
  .topbar .status { gap: 6px; margin-left: auto; }
  .topbar .pill { padding: 5px 9px; font-size: 12px; }
  .topbar .pill i { display: none; }
  #tabs { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .topbar.menu-open #tabs { grid-template-columns: 1fr 1fr; }
  .page h1 { font-size: 21px; }
}

/* ---------- page contents (every section): reflow, tables scroll inside their card ---------- */
@media (max-width: 1180px) {
  .page .panel, .page .pcard, .page .kc { min-width: 0; }
  .page .panel { overflow-x: auto; }
}
@media (max-width: 700px) {
  /* one scrollable row of pills instead of a stack of rows (body prefix: wins over css/views/charts.css whatever the load order) */
  body .page .subtabs { flex-wrap: nowrap; overflow-x: auto; border-radius: var(--pill); scrollbar-width: none; }
  .subtabs button { flex: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kc b { font-size: 24px; }
  .kc, .page .panel, .page .pcard { padding: 10px 12px; }
  .subtabs button, .page .ack { min-height: 44px; }
}
@media (max-width: 440px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- 3D plant: HUD ---------- */
@media (max-width: 1180px) {
  .pah-hud-cams { left: 84px; transform: none; }
  .pah-hud-cams button { min-height: 44px; padding: 0 14px; }
  .pah-hud-rail { left: max(12px, env(safe-area-inset-left)); width: 60px; }
  .pah-hud-rail__btn { height: 48px; }
  .pah-hud-fly { left: 82px; max-height: calc(100% - 16px); overflow-y: auto; }
  .pah-hud-row { min-height: 44px; }
  .pah-hud-card { max-height: calc(100% - 16px); top: 8px; right: max(8px, env(safe-area-inset-right)); }
  .pah-hud-card__close { min-width: 44px; min-height: 44px; }
  .pah-hud-acts button, .pah-hud-cams select { min-height: 44px; }
}

/* Compact portrait (phones, tablets up to 820 px): rail on top, camera strip under it, unit card as a bottom sheet. */
@media (max-width: 820px) and (min-height: 501px) {
  .pah-hud-tag { left: 84px; top: 14px; }                                  /* beside the rail */
  .pah-hud-rail { left: 8px; top: 8px; transform: none; width: auto; padding: 4px; flex-direction: row; gap: 2px; }
  .pah-hud-rail__btn { width: 48px; }
  .pah-hud-fly { left: 8px; right: 8px; width: auto; top: 130px !important; max-height: min(calc(100% - 140px), 360px); }   /* under the camera strip */
  .pah-hud:has(.pah-hud-card:not([hidden])) .pah-hud-fly { display: none; }       /* the sheet replaces the list; closing it brings the list back */
  .pah-hud-cams { left: 8px; right: 8px; top: 68px; bottom: auto; gap: 2px; padding: 4px; overflow-x: auto; scrollbar-width: none; justify-content: flex-start; }
  .pah-hud-cams button { flex: none; }
  .pah-hud-card { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: min(58%, 480px);
    border-radius: 16px 16px 0 0; padding: 14px max(16px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .pah-hud-card__head { margin-top: -6px; }
  .pah-hud-card__title { font-size: 20px; }
}

/* Short screens (phones in landscape): 44 px controls down the left, camera bar bottom-left, card at the right. */
@media (max-height: 500px) {
  .pah-hud-tag { left: 84px; top: 14px; }
  .pah-hud-rail { top: 8px; transform: none; padding: 4px 0; gap: 0; }
  .pah-hud-rail__btn { height: 44px; }
  .pah-hud-fly { width: min(340px, 50vw); }
  .pah-hud-cams { bottom: 8px; }
  .pah-hud-card { width: min(300px, 42vw); max-height: calc(100% - 76px); }
  .pah-hud-card__model { font-size: 11px; }
}
@media (max-height: 500px) {
  .pah-hud:has(.pah-hud-card:not([hidden])) .pah-hud-fly { display: none; }      /* leave the scene visible beside the card */
}
@media (max-height: 500px) and (max-width: 760px) {
  body:has(.pah-hud-card:not([hidden])) .pah-hud-cams { display: none; }
}

/* 3D labels on small screens: name and state dot only (the card has the readings). */
@media (max-width: 820px), (max-height: 500px) {
  .pah-label { min-width: 0; padding: 2px 6px; margin-top: -4px; }
  .pah-label__row, .pah-label__st, .pah-label__mode { display: none; }
  .pah-label__id { font-size: 11px; max-width: 156px; }
}
