/* FIDELISCELL V1.0.19 — camada responsiva estável, sem bloqueio de rolagem */
:root{
  --safe-top:env(safe-area-inset-top,0px);
  --safe-right:env(safe-area-inset-right,0px);
  --safe-bottom:env(safe-area-inset-bottom,0px);
  --safe-left:env(safe-area-inset-left,0px);
}
html{
  width:100%;
  min-height:100%;
  overflow-x:hidden;
  overflow-y:auto!important;
  -webkit-text-size-adjust:100%;
  text-size-adjust:100%;
}
body{
  width:100%;
  min-height:100%;
  overflow-x:hidden;
  overflow-y:auto!important;
  position:static;
  overscroll-behavior-y:auto;
  -webkit-overflow-scrolling:touch;
}
body,button,input,select,textarea{font-synthesis:none}
img,svg,video,canvas{max-width:100%;height:auto}
[hidden]{display:none!important}
.app-shell,.content,.page,.card,.hero,.grid,.grid>*,.metric-grid>*,.status-grid>*,.sale-layout>*,.card-head>*{min-width:0}
.content{max-width:100%;overflow:visible}
.page{max-width:1680px;overflow:visible}
.card,.metric,.hero{max-width:100%;overflow-wrap:anywhere}
.table-wrap{width:100%;max-width:100%;overflow-x:auto;overflow-y:visible;-webkit-overflow-scrolling:touch}
.table-wrap table{max-width:none}
input,select,textarea{max-width:100%}
button,.btn,a{touch-action:manipulation}
.sidebar{overflow:hidden}
.sidebar nav{min-height:0;overscroll-behavior:contain}
.sidebar-backdrop{display:none}

/* Desktop/notebook: estrutura fixa, sem aparência de tela de celular. */
@media (min-width:1024px){
  .sidebar{transform:none!important}
  .content{margin-left:255px;width:calc(100% - 255px)}
  .menu-btn,.sidebar-backdrop,.bottom-nav{display:none!important}
  .topbar{padding-left:clamp(20px,2.2vw,36px);padding-right:clamp(20px,2.2vw,36px)}
  .page{padding:clamp(20px,2vw,32px)}
  .metric-grid{grid-template-columns:repeat(4,minmax(0,1fr))}
  .grid.two{grid-template-columns:repeat(2,minmax(0,1fr))}
  .status-grid{grid-template-columns:repeat(3,minmax(0,1fr))}
}

/* Tablets e notebooks estreitos: menu lateral retrátil, conteúdo em duas colunas quando couber. */
@media (min-width:768px) and (max-width:1023px){
  body{padding-bottom:0!important}
  .sidebar{
    width:min(340px,82vw);
    transform:translateX(-105%);
    transition:transform .2s ease;
    box-shadow:14px 0 34px rgba(5,37,50,.18);
  }
  .sidebar.open{transform:translateX(0)}
  .sidebar-backdrop.open{display:block;position:fixed;inset:0;z-index:49;background:rgba(1,24,33,.42)}
  .content{margin-left:0!important;width:100%}
  .menu-btn{display:inline-flex!important;align-items:center;justify-content:center;width:44px;height:44px;padding:0;border-radius:10px}
  .bottom-nav{display:none!important}
  .topbar{height:auto;min-height:72px;padding:10px 18px}
  .page{padding:18px}
  .metric-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
  .grid.two,.status-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
  .sale-layout{grid-template-columns:minmax(0,1fr)!important}
  .cart{position:static!important}
}

/* Celular Android/iPhone e PWA instalado. */
@media (max-width:767px){
  body{
    padding-bottom:calc(68px + var(--safe-bottom))!important;
    font-size:14px;
  }
  .app-shell{min-height:100%;overflow:visible}
  .sidebar{
    width:min(86vw,320px);
    transform:translateX(-105%);
    transition:transform .2s ease;
    padding-top:var(--safe-top);
    box-shadow:14px 0 32px rgba(5,37,50,.2);
  }
  .sidebar.open{transform:translateX(0)}
  .sidebar-backdrop.open{display:block;position:fixed;inset:0;z-index:49;background:rgba(1,24,33,.44)}
  .content{margin-left:0!important;width:100%;min-height:100%;overflow:visible}
  .topbar{
    width:100%;
    height:auto!important;
    min-height:68px;
    padding:calc(8px + var(--safe-top)) max(12px,var(--safe-right)) 8px max(12px,var(--safe-left))!important;
    gap:10px;
  }
  .menu-btn{display:inline-flex!important;align-items:center;justify-content:center;width:44px;min-width:44px;height:44px;padding:0;border-radius:10px}
  .topbar>div:not(.top-actions){flex:1;min-width:0}
  .topbar h1{font-size:clamp(18px,5vw,22px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .topbar p{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .top-actions{margin-left:auto;flex:0 0 auto}
  .top-actions #installPwa{display:none!important}
  .page{width:100%;margin:0;padding:12px max(10px,var(--safe-right)) 18px max(10px,var(--safe-left))!important;overflow:visible}
  .hero{display:grid!important;grid-template-columns:minmax(0,1fr);gap:14px;padding:19px!important;border-radius:17px;align-items:start}
  .hero h2{font-size:clamp(22px,6vw,28px);line-height:1.15;margin:6px 0}
  .hero p{font-size:14px;line-height:1.45}
  .hero .btn{width:100%;margin-top:0!important}
  .metric-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:9px}
  .metric{padding:13px;border-radius:14px;box-shadow:0 6px 18px rgba(5,37,50,.06)}
  .metric span{font-size:12px;line-height:1.25}
  .metric strong{font-size:clamp(17px,5vw,22px);line-height:1.15;margin:7px 0;word-break:break-word}
  .metric small{font-size:11px;line-height:1.3}
  .grid,.grid.two,.grid.two.compact,.status-grid,.sale-layout{grid-template-columns:minmax(0,1fr)!important;gap:12px}
  .card{padding:14px;border-radius:15px;box-shadow:0 6px 18px rgba(5,37,50,.06)}
  .card-head{align-items:flex-start;flex-wrap:wrap;gap:9px}
  .card-head>div{flex:1 1 210px;min-width:0}
  .card-head>.btn,.card-head>button,.card-head>a.btn{flex:1 1 auto;min-width:120px}
  .quick-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:8px}
  .quick-grid a{min-width:0;padding:13px 7px;overflow-wrap:anywhere}
  .sale-layout{display:grid}
  .cart{position:static!important;top:auto!important}
  .product-results{grid-template-columns:minmax(0,1fr)!important;max-height:none!important;overflow:visible!important}
  .product-card{align-items:flex-start;min-width:0}
  .product-card>div{min-width:0}
  .product-card strong{white-space:normal;text-align:right}
  .cart-items{max-height:none!important;overflow:visible!important}
  .cart-row{grid-template-columns:minmax(0,1fr) minmax(74px,.42fr) 40px!important;gap:8px;padding:11px 0}
  .cart-row>div:first-child{grid-column:1/-1}
  .cart-row .qty{grid-column:1}
  .cart-row .price{grid-column:2}
  .cart-row>button{grid-column:3;grid-row:2;height:44px}
  .inline{flex-wrap:wrap}
  .inline>*{flex:1 1 140px}
  .filters{display:grid!important;grid-template-columns:minmax(0,1fr);gap:8px}
  input,select,textarea{font-size:16px!important;min-height:44px}
  textarea{min-height:92px}
  .share-grid{grid-template-columns:minmax(0,1fr)!important}
  .modal-backdrop{place-items:end center!important;padding:0!important}
  .modal{width:100%!important;max-width:none!important;max-height:calc(100dvh - var(--safe-top));border-radius:20px 20px 0 0;padding:16px;padding-bottom:calc(16px + var(--safe-bottom));overflow-y:auto;-webkit-overflow-scrolling:touch}
  .modal-actions{flex-wrap:wrap}
  .modal-actions .btn{flex:1 1 130px}
  .bottom-nav{
    display:grid!important;
    grid-template-columns:repeat(5,minmax(0,1fr))!important;
    position:fixed;
    left:0;right:0;bottom:0;
    height:calc(64px + var(--safe-bottom));
    padding:0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    background:#fff;
    border-top:1px solid var(--line);
    box-shadow:0 -4px 18px rgba(5,37,50,.08);
    z-index:45;
  }
  .bottom-nav a{min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:center;font-size:19px}
  .bottom-nav small{max-width:100%;font-size:10px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .footer{padding:14px 10px!important}
  #toast{left:10px;right:10px;bottom:calc(74px + var(--safe-bottom))}
  .toast{width:100%;max-width:none;margin-left:0}
}

/* Tabelas viram cartões somente em celulares; sem zoom e sem largura infinita. */
@media (max-width:640px){
  .table-wrap{overflow:visible}
  table.mobile-cards,table.mobile-cards tbody{display:block;width:100%;min-width:0!important}
  table.mobile-cards thead{display:none}
  table.mobile-cards tr{display:block;width:100%;margin:0 0 10px;padding:11px;border:1px solid var(--line);border-radius:13px;background:#fff}
  table.mobile-cards tr[hidden]{display:none!important}
  table.mobile-cards td{display:grid;grid-template-columns:minmax(82px,35%) minmax(0,1fr);gap:9px;width:100%;padding:7px 0;border:0;border-bottom:1px dashed #e4ecef;text-align:right;overflow-wrap:anywhere}
  table.mobile-cards td:last-child{border-bottom:0}
  table.mobile-cards td:empty{display:none}
  table.mobile-cards td::before{content:attr(data-label);font-size:10px;font-weight:800;letter-spacing:.4px;text-transform:uppercase;color:var(--muted);text-align:left}
  table.mobile-cards td .btn,table.mobile-cards td button,table.mobile-cards td a.btn{justify-self:end;width:auto;max-width:100%}
}

@media (max-width:360px){
  .metric-grid,.quick-grid{grid-template-columns:minmax(0,1fr)!important}
  .page{padding-left:8px!important;padding-right:8px!important}
  .card,.hero{border-radius:13px}
}

@media (max-width:767px) and (orientation:landscape){
  .topbar{min-height:58px;padding-top:6px!important;padding-bottom:6px!important}
  .sidebar{overflow-y:auto}
  .modal{max-height:100dvh}
}

/* Login V1.0.19: card centralizado de verdade no navegador e no PWA. */
body.login-body{
  width:100%;
  min-height:100vh;
  min-height:100dvh;
  height:auto!important;
  margin:0;
  display:grid!important;
  grid-template-columns:minmax(0,1fr);
  place-items:center!important;
  padding:
    max(24px,var(--safe-top))
    max(16px,var(--safe-right))
    max(24px,var(--safe-bottom))
    max(16px,var(--safe-left))!important;
  overflow-x:hidden!important;
  overflow-y:auto!important;
}
body.login-body>.login-card{
  width:min(430px,100%);
  max-width:430px;
  margin:auto!important;
  align-self:center;
  justify-self:center;
}
@media (max-width:480px){
  body.login-body{
    display:grid!important;
    place-items:center!important;
    padding:
      max(20px,var(--safe-top))
      12px
      max(20px,var(--safe-bottom))!important;
  }
  body.login-body>.login-card{
    width:100%;
    max-width:430px;
    margin:auto!important;
    padding:22px 16px;
    border-radius:20px;
  }
  .login-logo img{height:clamp(82px,24vw,108px)}
  .login-card h1{font-size:28px}
}

/* Guia de instalação para iPhone/iPad e navegadores sem prompt nativo. */
.install-guide-backdrop{position:fixed;inset:0;z-index:300;display:grid;place-items:end center;background:rgba(1,24,33,.5);padding:16px}
.install-guide{width:min(520px,100%);max-height:calc(100dvh - 32px);overflow-y:auto;background:#fff;border-radius:20px;padding:20px;box-shadow:0 20px 60px rgba(0,0,0,.28)}
.install-guide-head{display:flex;align-items:center;justify-content:space-between;gap:12px}
.install-guide-head h2{margin:0;font-size:21px}
.install-guide-close{border:0;background:#edf2f4;border-radius:10px;width:40px;height:40px;font-size:22px}
.install-guide ol{margin:16px 0;padding-left:22px;color:var(--text)}
.install-guide li{margin:10px 0;line-height:1.45}
.install-guide .btn{width:100%}
@media (min-width:768px){.install-guide-backdrop{place-items:center}.install-guide{border-radius:20px}}

@media (prefers-reduced-motion:reduce){*,*::before,*::after{scroll-behavior:auto!important;transition-duration:.01ms!important;animation-duration:.01ms!important;animation-iteration-count:1!important}}

/* A tabela compacta do painel cabe integralmente no desktop, sem cortar colunas. */
@media (min-width:641px){
  body[data-page="dashboard"] .table-wrap table{min-width:0;width:100%;table-layout:fixed}
  body[data-page="dashboard"] .table-wrap th,
  body[data-page="dashboard"] .table-wrap td{overflow-wrap:anywhere}
  body[data-page="dashboard"] .table-wrap th:first-child,
  body[data-page="dashboard"] .table-wrap td:first-child{width:24%}
  body[data-page="dashboard"] .table-wrap th:nth-child(2),
  body[data-page="dashboard"] .table-wrap td:nth-child(2){width:34%}
}

/* Fideliscell V1.0.19 — PWA standalone sem zoom, mantendo rolagem normal. */
html.pwa-standalone,
html.pwa-standalone body{
  touch-action:pan-x pan-y;
  -webkit-text-size-adjust:100%!important;
  text-size-adjust:100%!important;
}
html.pwa-standalone input,
html.pwa-standalone select,
html.pwa-standalone textarea,
html.pwa-standalone button{
  font-size:16px!important;
}
html.pwa-standalone button,
html.pwa-standalone .btn,
html.pwa-standalone a,
html.pwa-standalone input,
html.pwa-standalone select,
html.pwa-standalone textarea{
  touch-action:manipulation;
}
