/* TOP OPS 360 — Mobile-first optimization layer */
:root{
  --mobile-header-h:68px;
  --mobile-bottom-h:70px;
}
html{-webkit-text-size-adjust:100%;text-size-adjust:100%;scroll-behavior:smooth}
button,.btn,.nav button,summary{-webkit-tap-highlight-color:transparent;touch-action:manipulation}
.mobile-menu-btn,.mobile-sidebar-close,.mobile-overlay,.mobile-bottom-nav{display:none}

@media (max-width:768px){
  body{overflow-x:hidden;background:#f3f5f7}
  body.mobile-nav-open{overflow:hidden}

  /* App shell */
  .app{display:block!important;min-height:100dvh}
  .main,main{
    padding:
      calc(var(--mobile-header-h) + 12px + env(safe-area-inset-top))
      10px
      calc(var(--mobile-bottom-h) + 18px + env(safe-area-inset-bottom))!important;
    width:100%;
    min-width:0;
  }

  /* Drawer lateral */
  aside{
    display:block!important;
    position:fixed!important;
    left:0!important;top:0!important;bottom:0!important;
    width:min(86vw,340px)!important;
    height:100dvh!important;
    z-index:1100!important;
    transform:translateX(-105%);
    transition:transform .22s ease;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    padding:calc(12px + env(safe-area-inset-top)) 12px calc(24px + env(safe-area-inset-bottom))!important;
    box-shadow:18px 0 46px rgba(3,12,18,.28)!important;
  }
  aside.mobile-open{transform:translateX(0)}
  .mobile-overlay{
    display:block;
    position:fixed;inset:0;z-index:1090;
    background:rgba(4,14,20,.52);
    backdrop-filter:blur(2px);
    opacity:0;pointer-events:none;
    transition:opacity .2s ease;
  }
  body.mobile-nav-open .mobile-overlay{opacity:1;pointer-events:auto}

  .brand{display:flex!important;align-items:center;justify-content:space-between;padding:4px 4px 13px!important;margin-bottom:8px!important}
  .brand .logo span:last-child{display:inline!important;font-size:18px}
  .brand small{display:block!important;margin:5px 0 0 48px!important}
  .mobile-sidebar-close{
    display:grid;place-items:center;
    position:absolute;right:12px;top:calc(12px + env(safe-area-inset-top));
    width:42px;height:42px;border:0;border-radius:11px;
    background:rgba(255,255,255,.08);color:white;font-size:24px;z-index:2
  }

  .nav{display:block!important}
  .nav-section{display:block!important;margin:8px 0 10px!important}
  .nav-section summary{
    display:flex!important;
    min-height:42px;align-items:center;
    padding:9px 10px!important;
    font-size:10px!important;
    color:#8ba2af!important
  }
  .nav button{
    display:flex!important;width:100%!important;
    min-height:48px!important;
    padding:11px 12px!important;
    justify-content:flex-start!important;
    font-size:14px!important;border-radius:11px!important
  }
  .nav button span:last-child{display:inline!important}
  .nav .ico{width:26px!important;font-size:17px}

  /* Cabeçalho mobile */
  .topbar{
    position:fixed!important;
    left:0;right:0;top:0!important;
    z-index:1000!important;
    min-height:calc(var(--mobile-header-h) + env(safe-area-inset-top));
    margin:0!important;border-radius:0!important;
    padding:calc(9px + env(safe-area-inset-top)) 10px 9px!important;
    display:grid!important;
    grid-template-columns:46px minmax(0,1fr) auto!important;
    align-items:center!important;gap:8px!important;
    background:rgba(255,255,255,.94)!important;
    backdrop-filter:blur(16px)!important;
    border-width:0 0 1px!important;
  }
  .mobile-menu-btn{
    display:grid;place-items:center;
    width:44px;height:44px;border:1px solid #dce4e9;border-radius:12px;
    background:#fff;color:#173746;font-size:22px;font-weight:900
  }
  .topbar>div:first-of-type{min-width:0}
  .topbar h1,#pageTitle{
    font-size:18px!important;line-height:1.15!important;
    white-space:nowrap;overflow:hidden;text-overflow:ellipsis
  }
  .topbar .subtitle,#pageSubtitle{display:none!important}
  .right-actions{display:flex!important;align-items:center!important;gap:6px!important;width:auto!important;flex-wrap:nowrap!important}
  .right-actions>.btn:not(.icon-btn){display:none!important}
  .right-actions .icon-btn{display:grid!important;place-items:center;width:42px;height:42px;padding:0!important}
  .user-strip{padding:0!important;border:0!important;background:transparent!important;gap:0!important}
  .user-strip .user-meta,.user-strip>.btn{display:none!important}
  .user-strip .avatar,.avatar{width:40px!important;height:40px!important;font-size:13px!important}

  /* KPIs e conteúdo */
  .grid{gap:9px!important}
  .cards{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:9px!important}
  .card{padding:12px!important;border-radius:13px!important;min-width:0}
  .card .label{font-size:10px!important;line-height:1.25}
  .card .value{font-size:20px!important;margin:5px 0 2px!important;overflow-wrap:anywhere}
  .card .hint{font-size:9.5px!important;line-height:1.25}
  .two,.three,.asset-grid,.report-grid,.access-grid,.mini-grid,.detail-grid,.asset-detail{
    grid-template-columns:1fr!important
  }
  .panel{padding:12px!important;margin-top:10px!important;border-radius:13px!important}
  .panel h3{font-size:15px!important;margin-bottom:10px!important}
  .event-card{padding:12px!important}
  .statline{padding:9px 0!important;font-size:12px}

  /* Barras de ferramentas touch-friendly */
  .toolbar{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;align-items:stretch!important
  }
  .toolbar .search,.toolbar input.search,.toolbar select{
    grid-column:1/-1!important;
    min-width:0!important;max-width:none!important
  }
  .toolbar .btn{width:100%!important;min-height:46px!important;padding:10px!important}
  .btn{min-height:44px;padding:10px 12px;border-radius:10px}
  .btn.small{min-height:38px;padding:8px 10px;font-size:11px}

  /* Formulários */
  .form-grid{grid-template-columns:1fr!important;gap:12px!important}
  .full{grid-column:auto!important}
  label{font-size:12px!important;margin-bottom:6px!important}
  input,select,textarea{
    min-height:48px!important;
    padding:12px!important;
    border-radius:10px!important;
    font-size:16px!important
  }
  textarea{min-height:110px!important}
  .actions{
    position:sticky;bottom:0;
    background:linear-gradient(180deg,rgba(255,255,255,.78),#fff 24%);
    margin:12px -14px -14px!important;padding:16px 14px calc(14px + env(safe-area-inset-bottom))!important;
    display:grid!important;grid-template-columns:1fr 1fr!important;z-index:2
  }
  .actions .btn{width:100%;min-height:48px}

  /* Modal vira folha fullscreen */
  .modal{padding:0!important;align-items:stretch!important}
  .modal-box{
    width:100%!important;max-width:none!important;
    height:100dvh!important;max-height:none!important;
    border-radius:0!important;padding:calc(14px + env(safe-area-inset-top)) 14px 14px!important
  }
  .modal-head{
    position:sticky;top:calc(-14px - env(safe-area-inset-top));
    z-index:4;background:#fff;
    margin:-14px -14px 14px!important;
    padding:calc(12px + env(safe-area-inset-top)) 14px 10px!important;
    border-bottom:1px solid #edf0f2
  }
  .modal-head h2{font-size:18px!important}

  /* Tabelas no telemóvel */
  .table-wrap{
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
    margin-left:-12px;margin-right:-12px;
    padding:0 12px 5px;
    scroll-snap-type:x proximity
  }
  table{font-size:11.5px!important;min-width:720px!important}
  th,td{padding:9px 8px!important}
  th{position:sticky;top:0;z-index:1}
  table th:first-child,table td:first-child{
    position:sticky;left:0;
    background:#fff;z-index:2;
    box-shadow:5px 0 8px rgba(16,24,40,.035)
  }
  table th:first-child{background:#f8fafb;z-index:3}

  /* Alertas */
  .alert-row{grid-template-columns:1fr!important;padding:12px!important}
  .alert-actions{display:grid!important;grid-template-columns:1fr 1fr!important}
  .alert-actions .btn{width:100%}

  /* Login */
  .auth-screen{display:block!important;min-height:100dvh!important}
  .auth-panel{
    min-height:100dvh!important;padding:
      calc(18px + env(safe-area-inset-top))
      14px
      calc(18px + env(safe-area-inset-bottom))!important;
    display:flex!important;align-items:center!important
  }
  .auth-card{width:100%!important;max-width:460px!important;margin:auto!important;padding:20px!important;border-radius:18px!important}
  .auth-card h1{font-size:25px!important}
  .auth-card p{font-size:13px;line-height:1.5}
  .auth-field{margin-bottom:13px}
  .auth-card .btn[type="submit"]{width:100%;min-height:50px;font-size:15px}
  .login-note{font-size:11px!important;line-height:1.5!important}

  /* Bottom navigation */
  .mobile-bottom-nav{
    display:grid;
    grid-template-columns:repeat(5,1fr);
    position:fixed;left:0;right:0;bottom:0;z-index:1050;
    height:calc(var(--mobile-bottom-h) + env(safe-area-inset-bottom));
    padding:6px 4px env(safe-area-inset-bottom);
    background:rgba(255,255,255,.96);
    border-top:1px solid #dfe6eb;
    box-shadow:0 -6px 20px rgba(16,24,40,.08);
    backdrop-filter:blur(14px)
  }
  .mobile-bottom-nav button{
    border:0;background:transparent;color:#667085;
    min-width:0;padding:3px 2px;border-radius:10px;
    display:flex;flex-direction:column;align-items:center;justify-content:center;
    gap:2px;font-size:9px;font-weight:700
  }
  .mobile-bottom-nav button .mi{font-size:20px;line-height:1}
  .mobile-bottom-nav button.active{color:var(--green);background:#edf6f2}

  /* Banner local menos intrusivo */
  #standaloneModeBanner{
    bottom:calc(var(--mobile-bottom-h) + 10px + env(safe-area-inset-bottom))!important;
    left:10px!important;right:10px!important;
    max-width:none!important;font-size:9.5px!important;
    padding:7px 9px!important;opacity:.92
  }
}

@media (max-width:380px){
  .cards{grid-template-columns:1fr!important}
  .toolbar{grid-template-columns:1fr!important}
  .toolbar>*{grid-column:1!important}
  .actions{grid-template-columns:1fr!important}
}

.pwa-install-btn{margin:12px 6px 4px;width:calc(100% - 12px);border:1px solid rgba(184,137,61,.35);background:rgba(184,137,61,.12);color:#f1d9a7;padding:11px 12px;border-radius:10px;font-weight:800;cursor:pointer;text-align:left}.pwa-install-btn:hover{background:rgba(184,137,61,.2)}
@media(max-width:900px){.pwa-install-btn{min-height:46px}}

/* advanced-v42 */
.code-preview{display:flex;gap:10px;align-items:center;flex-wrap:wrap}.code-preview img{max-width:150px;max-height:90px;background:#fff;border:1px solid #dfe5e9;border-radius:8px;padding:5px}.gps-pill{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:11px}.ai-issue{border-left:4px solid #b54708;background:#fff8eb;padding:11px 12px;border-radius:9px;margin:8px 0}.ai-issue.high{border-color:#b42318;background:#fff0ee}.ai-strength{display:inline-block;background:#e7f7ef;color:#05603a;padding:5px 8px;border-radius:99px;margin:3px;font-size:11px}.score-ring{font-size:30px;font-weight:900}.scanner-video{width:100%;max-height:55vh;background:#111;border-radius:12px}
