/* ══════════════════════════════════════════════════════════════
   PROMETHEUS // ARQUITETURA MOBILE
   Não é o desktop encolhido: layout próprio, navegação por toque,
   barra inferior fixa, safe-area do iPhone, zero arrasto lateral.
   Carregado DEPOIS do app.css de propósito (precedência).
   Corte em 820px: pega celular em pé, em paisagem e tablet pequeno.
   ══════════════════════════════════════════════════════════════ */

/* ── trava global de gestos ─────────────────────────────────── */
@media (max-width: 820px) {

  html, body {
    overflow-x: hidden;
    max-width: 100vw;
    /* pan-y: rola só na vertical. Mata o arrasto lateral e a pinça. */
    touch-action: pan-y;
    overscroll-behavior-x: none;
    -webkit-text-size-adjust: 100%;   /* iOS não reescala fonte sozinho */
  }
  body { font-size: 15px; }           /* legível sem zoom */

  /* nada pode vazar da tela */
  #app, #workspace, .desktop, .module, .window-grid,
  .os-window, .detail-card, .data-panel, table, pre {
    max-width: 100%;
  }
  /* conteúdo largo rola DENTRO de si, nunca empurra a página */
  .module table, .module pre, .cam-grid, .module .scroll-x {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  img, video, canvas, iframe, svg { max-width: 100%; height: auto; }

  /* ── cabeçalho compacto e fixo ─────────────────────────────── */
  header {
    position: sticky; top: 0; z-index: 900;
    flex-wrap: wrap; gap: 8px;
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
    background: rgba(0, 0, 0, .94);
    backdrop-filter: blur(8px);
  }
  .brand { flex: 1 1 auto; min-width: 0; }
  .brand b { font-size: 15px; }
  .brand span { font-size: 8.5px; }

  /* faixa de estado: rola na horizontal DENTRO dela mesma */
  .system-strip {
    order: 3; flex: 1 0 100%;
    flex-wrap: nowrap;
    gap: 10px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
    font-size: 10.5px;
  }
  .system-strip::-webkit-scrollbar { display: none; }
  .system-strip > span { white-space: nowrap; flex: 0 0 auto; }

  .header-actions { gap: 6px; }
  .header-actions .icon { padding: 9px 11px; font-size: 10px; min-height: 40px; }

  /* ── área de trabalho ──────────────────────────────────────── */
  .desktop { padding: 16px 14px calc(96px + env(safe-area-inset-bottom, 0px)); }

  .desktop-top { flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
  .desktop-top h1 { font-size: clamp(30px, 11vw, 46px); line-height: 1; }
  .desktop-top p  { font-size: 12px; line-height: 1.55; }
  .core-state { align-self: stretch; justify-content: flex-start; }

  /* UMA coluna. Cartão grande, nada espremido. */
  .window-grid { grid-template-columns: 1fr; gap: 12px; }
  .os-window {
    padding: 16px;
    min-height: 132px;
    border-radius: 2px;
  }
  .os-window h3 { font-size: 16px; margin-top: 10px; }
  .os-window p  { font-size: 12.5px; line-height: 1.5; }
  .win-head span { font-size: 10px; }
  .os-window:active { transform: scale(.985); border-color: var(--ice2); }

  /* o mapa do topo merece altura de verdade */
  .hero-window { grid-column: 1 / -1; }
  .hero-window .mini-map { height: 210px; }

  /* ── módulo aberto: tela cheia ─────────────────────────────── */
  .module { padding: 14px 14px calc(96px + env(safe-area-inset-bottom, 0px)); }
  .back {
    position: sticky; top: calc(env(safe-area-inset-top, 0px) + 58px);
    z-index: 850;
    width: 100%;
    min-height: 46px;                 /* alvo de toque confortável */
    font-size: 12px;
    margin-bottom: 14px;
    background: rgba(0, 0, 0, .92);
    backdrop-filter: blur(6px);
  }
  .module-grid { grid-template-columns: 1fr !important; gap: 12px; }
  .data-panel { padding: 14px; }

  /* formulários: 16px impede o iOS de dar zoom ao focar */
  input, select, textarea { font-size: 16px !important; min-height: 46px; padding: 12px; }
  label { font-size: 10.5px; }
  button { min-height: 46px; }
  .cam-controls, .tabs { flex-wrap: wrap; gap: 8px; }
  .tabs button { flex: 1 1 auto; }

  /* mapas e câmeras com altura utilizável no celular */
  #bigMap, #routeMap, #orbMap, #wifiMap { height: 58vh !important; min-height: 320px; }
  .cam-grid { grid-template-columns: 1fr; }
  .cam-card img, .cam-card.live iframe { height: 200px; }
  .cam-stage { aspect-ratio: 3 / 4; }

  /* chips de cidade: rolam na horizontal, não quebram a tela */
  .city-chips {
    display: flex; flex-wrap: nowrap; gap: 8px;
    overflow-x: auto; scrollbar-width: none; padding-bottom: 4px;
  }
  .city-chips::-webkit-scrollbar { display: none; }
  .city-chip { flex: 0 0 auto; min-height: 40px; }

  /* ── BARRA INFERIOR — navegação nativa do PROMETHEUS ───────── */
  #mobileNav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 950;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: rgba(2, 4, 9, .97);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #mobileNav button {
    border: 0; background: transparent;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 9px 2px; min-height: 58px;
    color: #5f8ba1; font-family: var(--font-b);
    font-size: 8.5px; letter-spacing: .1em;
    -webkit-tap-highlight-color: transparent;
  }
  #mobileNav button i { font-style: normal; font-size: 17px; line-height: 1; }
  #mobileNav button.on { color: var(--ice2); background: linear-gradient(180deg, rgba(0,212,255,.13), transparent); }
  #mobileNav button.on i { filter: drop-shadow(0 0 6px rgba(0,212,255,.6)); }
  #mobileNav button:active { background: rgba(0,212,255,.09); }

  /* toasts sobem acima da barra */
  #toastHost { bottom: calc(74px + env(safe-area-inset-bottom, 0px)) !important; left: 12px; right: 12px; }
  #toastHost > * { max-width: 100%; }

  /* login no celular */
  .login { padding: 20px 16px; }
  .login-card { width: 100%; max-width: 420px; padding: 24px 20px; }
  .login-card h1 { font-size: 30px; }

  /* efeitos pesados atrapalham em tela pequena */
  .scanlines { opacity: .35; }
}

/* ── celular deitado: aproveita a largura, encolhe o vertical ── */
@media (max-width: 900px) and (orientation: landscape) {
  .window-grid { grid-template-columns: 1fr 1fr; }
  .hero-window { grid-column: 1 / -1; }
  .hero-window .mini-map { height: 150px; }
  .desktop-top h1 { font-size: 30px; }
  #bigMap, #routeMap, #orbMap, #wifiMap { height: 74vh !important; min-height: 240px; }
  #mobileNav button { min-height: 48px; font-size: 8px; }
  #mobileNav button i { font-size: 15px; }
  header { position: static; }        /* não roubar altura deitado */
  .back { position: static; }
}

/* ── telas bem estreitas (iPhone SE e afins) ──────────────────── */
@media (max-width: 380px) {
  .desktop { padding-left: 11px; padding-right: 11px; }
  .os-window { padding: 13px; min-height: 118px; }
  #mobileNav button { font-size: 7.5px; }
  .header-actions .icon { padding: 8px 9px; }
}

/* ── desktop: a barra inferior não existe ─────────────────────── */
@media (min-width: 821px) {
  #mobileNav { display: none !important; }
}
