/* ============================================================================
   VERSÃO MÓVEL (celular/tablet) — TODAS as regras ficam sob html[data-view="mobile"], que é definido por js/device.js.
   Na versão desktop este arquivo não tem efeito nenhum.
   Parte 1: páginas do site (landing, planos, painel, conta, equipamentos, login…).
   ============================================================================ */

html[data-view="mobile"]{ -webkit-text-size-adjust:100%; }
html[data-view="mobile"] body{ -webkit-tap-highlight-color:transparent; }
/* campos com 16px evitam o zoom automático do iPhone ao focar */
html[data-view="mobile"] input, html[data-view="mobile"] select, html[data-view="mobile"] textarea{ font-size:16px; }
/* alvos de toque confortáveis */
html[data-view="mobile"] body.site button, html[data-view="mobile"] a.primary, html[data-view="mobile"] a.ghost{ min-height:40px; }

/* botão "Versão desktop / Versão móvel" */
.view-mode-btn{ white-space:nowrap; }

/* ---------- barra superior do site: logo + hambúrguer; o resto abre num menu ---------- */
html[data-view="mobile"] body.site{ background-attachment:scroll; }
html[data-view="mobile"] .site-topbar{ flex-wrap:wrap; gap:8px 10px; padding:10px 14px; }
html[data-view="mobile"] .site-topbar .brand{ order:0 }
html[data-view="mobile"] .site-topbar .spacer{ order:1 }
html[data-view="mobile"] .site-burger{
  order:2; width:44px; height:40px; padding:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:5px;
}
html[data-view="mobile"] .site-burger span{ display:block; width:20px; height:2px; background:var(--text); border-radius:2px; transition:transform .15s, opacity .15s }
html[data-view="mobile"] .site-topbar.menu-open .site-burger span:nth-child(1){ transform:translateY(7px) rotate(45deg) }
html[data-view="mobile"] .site-topbar.menu-open .site-burger span:nth-child(2){ opacity:0 }
html[data-view="mobile"] .site-topbar.menu-open .site-burger span:nth-child(3){ transform:translateY(-7px) rotate(-45deg) }
/* !important porque alguns blocos (Entrar/Cadastrar, conta) têm display inline que a sessão alterna */
html[data-view="mobile"] .site-topbar:not(.menu-open) > :not(.brand):not(.spacer):not(.site-burger){ display:none !important; }
html[data-view="mobile"] .site-topbar.menu-open > :not(.brand):not(.spacer):not(.site-burger){
  display:flex; order:4; width:100%; box-sizing:border-box; justify-content:center; align-items:center;
}
html[data-view="mobile"] .site-topbar.menu-open > .site-nav{ order:3; flex-direction:column; align-items:stretch; margin:4px 0 0; gap:2px }
html[data-view="mobile"] .site-topbar.menu-open > .site-nav a{ font-size:15px; padding:13px 12px; border-radius:8px; }
html[data-view="mobile"] .site-topbar.menu-open > .acct-topbar-user{ justify-content:flex-start }
html[data-view="mobile"] .site-topbar.menu-open > #topbarLoggedOut, html[data-view="mobile"] .site-topbar.menu-open > #topbarLoggedIn{ flex-direction:column; align-items:stretch; gap:8px !important; }
html[data-view="mobile"] .site-topbar.menu-open > #topbarLoggedIn .acct-topbar-user{ padding:2px 4px }
html[data-view="mobile"] .site-topbar.menu-open > .icon-btn{ width:100%; }

/* ---------- conteúdo ---------- */
html[data-view="mobile"] .site-main{ padding:0 16px; }
html[data-view="mobile"] .page-header{ padding:24px 0 18px; }
html[data-view="mobile"] .page-header h1{ font-size:21px; }
html[data-view="mobile"] .hero-inner{ grid-template-columns:1fr; gap:24px; padding:40px 18px 36px; }
html[data-view="mobile"] .hero-main{ text-align:center; }
html[data-view="mobile"] .hero-main > p{ margin-left:auto; margin-right:auto; font-size:14.5px; }
html[data-view="mobile"] .hero h1{ font-size:32px; }
html[data-view="mobile"] .hero-cta{ justify-content:center; }
html[data-view="mobile"] .hero-cta button, html[data-view="mobile"] .hero-cta a{ flex:1 1 100%; padding:14px 18px; font-size:14px; }
html[data-view="mobile"] .hero-stat{ grid-column:1; text-align:center; }
html[data-view="mobile"] .hero-stat .cap{ margin-left:auto; margin-right:auto; }
html[data-view="mobile"] .tag-strip{ padding:14px 16px; }
html[data-view="mobile"] .site-section{ padding:40px 0; }
html[data-view="mobile"] .site-section h2{ font-size:24px; }
html[data-view="mobile"] .site-section .section-sub{ margin-bottom:26px; }
html[data-view="mobile"] .features-grid{ grid-template-columns:1fr; gap:24px; }
html[data-view="mobile"] .gallery-grid{ grid-template-columns:repeat(2, minmax(0,1fr)); gap:18px 12px; }
html[data-view="mobile"] .plans-grid{ grid-template-columns:1fr; }
html[data-view="mobile"] .plan-card{ padding:18px; }
html[data-view="mobile"] .nav-cards{ grid-template-columns:minmax(0,1fr); gap:12px; margin:22px 0 30px; }
html[data-view="mobile"] .nav-card{ padding:16px; }
html[data-view="mobile"] .recent-item{ flex-wrap:wrap; gap:4px 10px; padding:12px; }
html[data-view="mobile"] .crud-layout{ grid-template-columns:minmax(0,1fr); gap:16px; margin-bottom:32px; }
html[data-view="mobile"] .crud-form{ position:static; padding:16px; }
html[data-view="mobile"] .crud-item{ flex-wrap:wrap; }
html[data-view="mobile"] .crud-item .row-actions{ margin-left:auto; }
html[data-view="mobile"] .crud-item .row-actions button{ min-width:44px; }
html[data-view="mobile"] .crud-form .form-actions{ flex-direction:column; }
html[data-view="mobile"] .auth-card{ max-width:none; padding:20px; }
html[data-view="mobile"] .mp-card-row{ grid-template-columns:1fr; gap:0; }
html[data-view="mobile"] .site-footer{ padding:18px 16px; }

/* diálogos: ocupam a tela quase toda */
html[data-view="mobile"] .modal{ max-width:calc(100vw - 16px); max-height:calc(100dvh - 16px); }
html[data-view="mobile"] .modal-backdrop{ padding:8px; box-sizing:border-box; }

/* o editor embutido (workspace.html) usa a altura visível real, sem a barra de endereço */
html[data-view="mobile"] body.site:has(.workspace-frame){ height:100dvh; }

/* páginas do site: o corpo cresce com o conteúdo (em tela baixa o <main> encolhia e o rodapé sobrepunha o fim da página) */
html[data-view="mobile"] body.site:not(:has(.workspace-frame)){ height:auto; min-height:100dvh; }
html[data-view="mobile"] body.site > main:not(.site-main){ flex:1 0 auto; min-height:auto; }
html[data-view="mobile"] .site-topbar.menu-open > #topbarLoggedOut, html[data-view="mobile"] .site-topbar.menu-open > #topbarLoggedIn{ align-items:stretch !important; }
html[data-view="mobile"] .crud-form input[type="checkbox"], html[data-view="mobile"] .checkbox-row input[type="checkbox"]{ width:22px; height:22px; flex:none; }

/* ============================================================================
   Parte 2: EDITOR (editor.html, dentro de workspace.html ou aberto direto)
   Camadas de baixo pra cima: abas do painel (trilho horizontal), barra de ferramentas, rodapé (camadas/previews).
   O painel de propriedades vira uma folha que sobe por cima da área de desenho.
   ============================================================================ */
html[data-view="mobile"] .app{ height:100vh; height:100dvh; }

/* barra do topo (só quando o editor é aberto direto; embutido, a casca do site cuida disso) */
html[data-view="mobile"] .topbar{ padding:6px 10px; gap:8px; }
html[data-view="mobile"] .topbar .brand-logo{ height:30px; }
html[data-view="mobile"] .topbar-nav{ margin-left:0; }
html[data-view="mobile"] .topbar-nav a.disabled, html[data-view="mobile"] .topbar-nav a.active{ display:none; }
html[data-view="mobile"] .topbar-nav a{ padding:8px 10px; font-size:13px; }
html[data-view="mobile"] #accountBtnLabel{ display:none; }
html[data-view="mobile"] .account-btn{ padding:4px; }
html[data-view="mobile"] .account-dropdown{ position:fixed; top:54px; left:10px; right:10px; width:auto; max-height:calc(100dvh - 70px); overflow:auto; }
html[data-view="mobile"] .account-dropdown .view-mode-btn{ width:100%; justify-content:center; margin-top:8px; min-height:40px; }
html[data-view="mobile"] .account-dropdown #btnLogout{ min-height:40px; }

/* barra de ações: uma fileira que rola na horizontal */
html[data-view="mobile"] .app > header{
  flex-wrap:nowrap; overflow-x:auto; overflow-y:hidden; gap:8px; padding:6px 10px; scrollbar-width:none; -webkit-overflow-scrolling:touch;
}
html[data-view="mobile"] .app > header::-webkit-scrollbar{ display:none; }
html[data-view="mobile"] .app > header > *{ flex:none; }
html[data-view="mobile"] .app > header .spacer{ display:none; }
html[data-view="mobile"] .hgroups{ flex-wrap:nowrap; gap:8px; }
html[data-view="mobile"] .hgrp button.icon-btn{ width:40px; height:40px; }
html[data-view="mobile"] .hgrp .header-num{ height:40px; width:56px; }
html[data-view="mobile"] .hic{ width:22px; height:22px; }
html[data-view="mobile"] button.icon-btn img{ width:22px; height:22px; }
html[data-view="mobile"] #btnMachine{ display:none; }          /* Usinar usa Web Serial: não existe no navegador do celular */
html[data-view="mobile"] .app > header .mode-badge{ position:sticky; left:0; }

/* área central: desenho em cima; barra de ferramentas e abas embaixo */
html[data-view="mobile"] .app > main{ flex-direction:column; position:relative; }
html[data-view="mobile"] .canvas-col{ order:0; position:relative; }
html[data-view="mobile"] .project-name-bar{ height:26px; font-size:11px; }
html[data-view="mobile"] .canvas-wrap{ padding:10px; }

html[data-view="mobile"] .toolbar{
  order:1; width:auto; height:54px; flex:none; flex-direction:row; align-items:center; justify-content:flex-start; gap:4px;
  padding:5px 8px; overflow-x:auto; overflow-y:hidden; border-right:none; border-top:1px solid var(--border); scrollbar-width:none;
}
html[data-view="mobile"] .toolbar::-webkit-scrollbar{ display:none; }
html[data-view="mobile"] .toolbar-group{ flex-direction:row; gap:4px; flex:none; }
html[data-view="mobile"] .tool-btn{ width:44px; height:44px; flex:none; font-size:18px; }
html[data-view="mobile"] .tool-sep{ width:1px; height:28px; margin:0 6px; flex:none; }

/* abas do painel: trilho horizontal; o painel sobe como uma folha por cima do desenho */
html[data-view="mobile"] .sidebar{ order:2; width:auto; flex:none; flex-direction:column; border-left:none; overflow:visible; position:static; }
html[data-view="mobile"] .sidebar-rail{
  width:auto; height:56px; flex-direction:row; padding:0; gap:0; border-left:none; border-top:1px solid var(--border);
}
html[data-view="mobile"] .rail-btn{
  flex:1; min-width:0; padding:6px 2px 4px; border-right:none; border-top:2px solid transparent; font-size:10px; gap:2px;
}
html[data-view="mobile"] .rail-btn .sb-ic{ width:22px; height:22px; }
html[data-view="mobile"] .rail-btn.active{ border-right-color:transparent; border-top-color:var(--accent); }
html[data-view="mobile"] .sidebar.collapsed .rail-btn.active{ border-top-color:transparent; }
html[data-view="mobile"] .rail-hide{ display:none; }
html[data-view="mobile"] .sidebar .sidebar-panels{
  position:absolute; left:0; right:0; bottom:56px; width:auto; max-height:56%; z-index:30;
  background:var(--panel); border-top:1px solid var(--border); border-radius:14px 14px 0 0;
  box-shadow:0 -12px 30px var(--shadow); padding:14px 12px 22px; overscroll-behavior:contain;
}
html[data-view="mobile"] .sb-body.prop-grid{ gap:12px 10px; }
html[data-view="mobile"] .sb-card > summary{ padding:13px 12px; }

/* rodapé: camadas numa fileira e os previews na outra (o zoom sobe para cima do desenho, ver js/mobile-ui.js) */
html[data-view="mobile"] .app > footer{ flex-wrap:wrap; gap:6px; padding:6px 8px; }
html[data-view="mobile"] .tabbar{ flex:1 0 100%; order:0; padding-bottom:2px; }
html[data-view="mobile"] .tabbar-tab{ padding:9px 8px 9px 12px; }
html[data-view="mobile"] .tabbar-actions{ display:flex; }       /* sem hover no toque: ações da camada sempre à vista */
html[data-view="mobile"] .tabbar-add{ padding:9px 12px; }
html[data-view="mobile"] #btnPreview3d, html[data-view="mobile"] #btnPreviewLayer{ order:1; flex:1 1 0; justify-content:center; min-height:40px; padding:6px 8px; font-size:12px; }
html[data-view="mobile"] .app > footer .zoom-controls{ display:none; }
html[data-view="mobile"] .canvas-col .zoom-controls{
  position:absolute; right:10px; bottom:10px; z-index:6; display:flex; gap:2px; padding:3px; background:var(--panel);
  border:1px solid var(--border); border-radius:10px; box-shadow:0 4px 14px var(--shadow);
}
html[data-view="mobile"] .canvas-col .zoom-controls button{ min-height:36px; height:36px; }
html[data-view="mobile"] .canvas-col .zoom-controls button.icon-btn{ width:36px; }
html[data-view="mobile"] .canvas-col .zoom-controls span{ display:flex; align-items:center; width:42px; justify-content:center; }
html[data-view="mobile"] .canvas-col .zoom-controls .app-version, html[data-view="mobile"] .canvas-col .zoom-controls .mouse-coords{ display:none; }
html[data-view="mobile"] .view-btns{ left:10px; bottom:10px; }
html[data-view="mobile"] .view-btns button{ width:38px; height:38px; }

/* janelas (salvar/abrir, máquina, manual, preview…) ocupam a tela */
html[data-view="mobile"] .app ~ .modal-backdrop{ padding:0; align-items:stretch; }
html[data-view="mobile"] .app ~ .modal-backdrop > .modal{ width:100vw; max-width:100vw; height:100dvh; max-height:100dvh; border-radius:0; border:none; }
html[data-view="mobile"] .modal header{ padding-top:12px; padding-bottom:12px; }
html[data-view="mobile"] .modal .modal-footer{ flex-wrap:wrap; }
html[data-view="mobile"] .modal .modal-footer button{ min-height:42px; flex:1 1 auto; justify-content:center; }
html[data-view="mobile"] .help-modal.manual-modal{ height:100dvh; max-height:100dvh; }
html[data-view="mobile"] .preview3d-canvas-wrap{ height:min(60dvh, 420px); }

/* celular deitado: libera altura */
@media (max-height:520px) and (orientation:landscape){
  html[data-view="mobile"] .project-name-bar{ display:none; }
  html[data-view="mobile"] .app > header{ padding:4px 8px; }
  html[data-view="mobile"] .hgrp button.icon-btn{ width:36px; height:36px; }
  html[data-view="mobile"] .toolbar{ height:46px; padding:3px 8px; }
  html[data-view="mobile"] .tool-btn{ width:40px; height:40px; }
  html[data-view="mobile"] .sidebar-rail{ height:46px; }
  html[data-view="mobile"] .rail-btn span{ display:none; }
  html[data-view="mobile"] .sidebar .sidebar-panels{ bottom:46px; max-height:70%; }
  html[data-view="mobile"] .app > footer{ flex-wrap:nowrap; }
  html[data-view="mobile"] .tabbar{ flex:1 1 0; }
  html[data-view="mobile"] #btnPreview3d, html[data-view="mobile"] #btnPreviewLayer{ flex:none; }
}

/* ============================================================================
   Parte 3: TOQUE no desenho (js/mobile-ui.js trata os gestos; aqui só impede o navegador de rolar/dar zoom na página)
   ============================================================================ */
html[data-view="mobile"] .canvas-wrap{ touch-action:none; -webkit-user-select:none; user-select:none; -webkit-touch-callout:none; }
html[data-view="mobile"] canvas{ -webkit-tap-highlight-color:transparent; }
html[data-view="mobile"] .m-keys{
  position:absolute; right:10px; top:34px; z-index:6; display:flex; flex-direction:column; gap:6px;
}
html[data-view="mobile"] .m-keys button{
  width:42px; height:42px; padding:0; justify-content:center; font-size:19px; font-weight:700; border-radius:12px;
  background:var(--panel); opacity:.92; box-shadow:0 4px 14px var(--shadow);
}
html[data-view="mobile"] .m-keys button#mkOk{ color:var(--accent); border-color:var(--accent); }
html[data-view="mobile"] .m-keys button#mkCancel{ color:var(--danger); }
html[data-view="mobile"] .m-keys button.on{ background:var(--accent); color:var(--accent-contrast); border-color:var(--accent); }
