/* =====================================================================
   Celular: o sistema com cara de aplicativo.
   Tudo aqui vale só até 720px; o desktop não muda.
   - topo compacto (menu, logo, avatar) respeitando o notch
   - barra de abas embaixo, com o leitor de plaqueta no centro
   - listas viram cartões (os rótulos vêm do cabeçalho da tabela, ver mobile.js)
   - modais viram folhas que sobem de baixo, com a ação principal sempre à mão
   ===================================================================== */
.tabbar { display: none; }

@media (max-width: 720px) {
  :root { --tabbar: 62px; --gutter: 14px; }
  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: transparent; }
  button, .tab, .pg, .mod, tr[data-id] { touch-action: manipulation; }

  /* ---------- topo ---------- */
  .topbar { gap: 8px; padding-left: 6px; padding-right: 10px; }
  .menu-btn { width: 42px; height: 42px; }
  .menu-btn svg { width: 21px; height: 21px; }
  .brand { gap: 0; }
  .brand img { height: 30px; }
  .brand-sep, .brand-module { display: none; }
  .top-actions { margin-left: auto; gap: 2px; }
  .top-actions [data-soon], .signature, .user-name { display: none !important; }
  .user { padding: 4px; }
  .user-menu { position: fixed; top: calc(var(--top) + env(safe-area-inset-top) + 6px); right: 10px; left: auto; min-width: 0; width: min(300px, calc(100vw - 20px)); }
  .user-menu button { min-height: 46px; }

  /* área útil: notch em cima, barra de abas embaixo */
  .main { padding: calc(var(--top) + env(safe-area-inset-top) + 16px) var(--gutter) calc(var(--tabbar) + env(safe-area-inset-bottom) + 28px); }

  /* ---------- menu lateral vira gaveta por cima de tudo ---------- */
  .side { top: 0; z-index: 60; width: min(86vw, 330px); padding-top: calc(env(safe-area-inset-top) + 18px);
    transform: translateX(-104%); box-shadow: none; }
  body.side-open .side { transform: none; box-shadow: 24px 0 60px -20px rgba(0,0,0,.55); }
  .side-backdrop { inset: 0; z-index: 55; backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
  .side { scrollbar-width: none; }
  .side::-webkit-scrollbar { display: none; }
  .side .pg, .side .mod, .side .short { min-height: 44px; }

  /* ---------- barra de abas ---------- */
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); align-items: stretch; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding: 0 6px env(safe-area-inset-bottom);
    background: linear-gradient(180deg, #0c2a1b 0%, #071b14 100%); border-top: 1px solid rgba(175,140,98,.35);
    box-shadow: 0 -10px 30px -18px rgba(0,0,0,.5); transition: transform .22s cubic-bezier(.22,1,.36,1); }
  .tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0;
    color: rgba(242,241,223,.62); font-size: 10.5px; font-weight: 600; letter-spacing: .02em; }
  .tabbar button svg { width: 22px; height: 22px; stroke-width: 1.7; }
  .tabbar button.on { color: var(--sand); }
  .tabbar button.on svg { stroke-width: 2; }
  .tabbar button:active { opacity: .7; }
  /* leitor de plaqueta: botão de destaque no centro */
  .tabbar .tb-scan .ring { display: grid; place-items: center; width: 54px; height: 54px; margin-top: -24px; border-radius: 50%;
    background: linear-gradient(140deg, #d8bd97, #af8c62); color: #1d1408; border: 4px solid #0b2519;
    box-shadow: 0 10px 22px -8px rgba(0,0,0,.6); }
  .tabbar .tb-scan .ring svg { width: 24px; height: 24px; stroke-width: 2; }
  .tabbar .tb-scan { color: rgba(242,241,223,.85); }
  /* digitando: a barra sai da frente do teclado */
  body.digitando .tabbar { transform: translateY(110%); }

  /* ---------- cabeçalho das páginas ---------- */
  .page-head { padding: 0; gap: 14px; }
  .page-title { gap: 12px; align-items: center; }
  .page-head .title-icon { width: 38px; height: 38px; border-radius: 11px; }
  h1 { font-size: 23px; line-height: 1.15; }
  .page-sub { font-size: 12.5px; }
  .help-dot { display: none; }
  /* ações da página numa faixa que rola de lado, de borda a borda */
  .head-actions { flex: 1 1 100%; display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto; scrollbar-width: none;
    margin: 0 calc(var(--gutter) * -1); padding: 2px var(--gutter) 4px; }
  .head-actions::-webkit-scrollbar { display: none; }
  .head-actions > * { flex: none; }
  .head-actions .btn-primary, .head-actions .btn-ghost { height: 40px; padding: 0 14px; border-radius: 999px; font-size: 13.5px; }
  #scanAtivo { display: none; } /* está na barra de abas */

  .card { border-radius: 14px; }
  .card-head { padding: 14px 16px 8px; flex-wrap: wrap; gap: 4px 12px; }
  .card-head h2 { font-size: 16px; }

  /* ---------- filtros: a busca fica sempre à vista, os demais recolhem ---------- */
  .filters-head { padding: 12px 16px; }
  .filters-body { padding: 0 14px 14px; gap: 10px; }
  .filters.collapsed .filters-body { display: flex; }
  .filters.collapsed .filters-row { display: none; }
  .filters-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .filters-row select { width: 100%; height: 44px; }
  .filters-row > .search-field, .filters-row > input[type=search] { grid-column: 1 / -1; }
  .filters-row button { height: 44px; }
  .search-field { height: 46px; border-radius: 12px; }

  /* ---------- listas: tabela vira cartão ---------- */
  .table-wrap { max-height: none; overflow: visible; }
  .table-wrap table { min-width: 0 !important; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; }
  .table-wrap tbody tr { position: relative; padding: 14px 16px; border-top: 1px solid var(--line-2); }
  .table-wrap tbody tr:first-child { border-top: 0; }
  .table-wrap tbody tr[data-id] { cursor: pointer; }
  .table-wrap tbody tr[data-id]:active { background: #f6f8f6; }
  .table-wrap td { padding: 2px 0 !important; border: 0 !important; text-align: left !important; white-space: normal !important; max-width: none !important; }
  .table-wrap td:first-child { font-weight: 600; }
  .table-wrap td[data-label]:not(:first-child)::before { content: attr(data-label); display: inline-block; min-width: 96px; margin-right: 10px;
    color: var(--ink-3); font-family: var(--sans); font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; vertical-align: baseline; }
  .table-wrap td:empty, .table-wrap td.sem-valor { display: none; }
  .table-wrap td.empty { padding: 26px 8px !important; text-align: center !important; font-weight: 400; }
  .table-wrap td .sub { display: block; }
  /* ações da linha: rodapé do cartão, alinhadas à direita */
  .table-wrap td:has(> .actions) { margin-top: 8px; padding-top: 8px !important; border-top: 1px dashed var(--line) !important; }
  .table-wrap td:has(> .actions)::before { display: none; }
  .table-wrap .actions { justify-content: flex-end; gap: 6px; }
  .table-wrap .act { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; }

  /* cartão do ativo, desenhado à mão:
     [plaqueta]                 [situação]
     Descrição do bem
     marca · modelo
     categoria · localização
     garantia                       valor   */
  #viewAtivos tbody tr[data-id] { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; row-gap: 6px; padding: 15px 16px; }
  #viewAtivos tbody td::before { display: none !important; }
  #viewAtivos tbody td:nth-child(1) { grid-column: 1; grid-row: 1; font-weight: 600; color: var(--green); }
  #viewAtivos tbody td:nth-child(9) { grid-column: 2; grid-row: 1; justify-self: end; align-self: center; }
  #viewAtivos tbody td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; font-size: 15px; font-weight: 600; line-height: 1.35; color: var(--ink); }
  #viewAtivos tbody td:nth-child(2) .sub { font-size: 12.5px; font-weight: 400; }
  #viewAtivos tbody td:nth-child(3) { grid-column: 1 / -1; grid-row: 3; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  #viewAtivos tbody td:nth-child(4) { grid-column: 1 / -1; grid-row: 4; color: var(--ink-2); font-size: 13px; }
  #viewAtivos tbody td:nth-child(7) { grid-column: 1; grid-row: 5; align-self: center; }
  #viewAtivos tbody td:nth-child(7) .sub { display: none; }
  #viewAtivos tbody td:nth-child(8) { grid-column: 2; grid-row: 5; justify-self: end; align-self: center; font-family: var(--mono); font-weight: 700; font-size: 13.5px; }
  #viewAtivos tbody td:nth-child(5), #viewAtivos tbody td:nth-child(6), #viewAtivos tbody td:nth-child(10) { display: none; }
  #viewAtivos tbody td:nth-child(4):has(.dash), #viewAtivos tbody td:nth-child(8):has(.dash) { display: none; }
  #viewAtivos tbody tr[data-id]::after { content: ""; position: absolute; right: 12px; top: 50%; width: 8px; height: 8px; margin-top: -4px;
    border-right: 2px solid var(--ink-4); border-top: 2px solid var(--ink-4); transform: rotate(45deg); opacity: 0; }

  /* ---------- modais: folhas que sobem de baixo ---------- */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-card, .modal-card.sm, .modal-card.xs { width: 100% !important; max-width: 100%; max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
    border-radius: 20px 20px 0 0; animation: folhaSobe .34s cubic-bezier(.22,1,.36,1) both; }
  /* ficha de ativo, OS, evento: ocupam a tela inteira (mini-modais ficam do tamanho do conteúdo) */
  .modal-overlay:not(.mini) > .modal-card:not(.sm):not(.xs) { height: calc(100dvh - env(safe-area-inset-top) - 12px); }
  .modal-card::before { content: ""; flex: none; width: 40px; height: 5px; margin: 8px auto 0; border-radius: 5px; background: #d9ddd9; }
  .modal-card > form, .modal-card > .asset-form { flex: 1; min-height: 0; }
  .form-head { position: relative; flex-wrap: wrap; gap: 10px 12px; padding: 10px 56px 12px 16px !important; }
  .form-head .title-icon { width: 34px; height: 34px; border-radius: 10px; }
  .form-head h2 { font-size: 17px; }
  .form-head .page-sub { font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .form-head .modal-close { position: absolute; top: 6px; right: 8px; width: 40px; height: 40px; border-radius: 50%; background: #f1f3f1; }
  .plate { order: 3; flex: 1 1 100%; display: flex; align-items: center; gap: 8px; text-align: left; padding: 8px 10px; border-radius: 10px; background: #f6f8f6; }
  .plate span { display: inline; font-size: 10px; }
  .plate b, .plate.none b { display: inline; font-size: 15px; line-height: 1.2; }
  .plate b { white-space: nowrap; }
  .plate .plate-link { margin: 0 0 0 auto; height: 34px; white-space: nowrap; flex: none; }
  .form-body { flex: 1; padding: 14px 16px 22px !important; overflow-x: hidden; }
  /* ajuda "?": no toque (não há hover no celular), abre como balão na base da tela */
  .help { width: 20px; height: 20px; font-size: 11px; }
  .help::after, .help::before { display: none; }
  .help.aberto { border-color: var(--green); color: var(--green); }
  .help.aberto::after { display: block; opacity: 1; position: fixed; left: 14px; right: 14px; top: auto; bottom: calc(env(safe-area-inset-bottom) + 22px);
    width: auto; transform: none; z-index: 300; padding: 13px 15px; border-radius: 14px; font-size: 13.5px; font-weight: 500; line-height: 1.5;
    white-space: normal; box-shadow: 0 18px 40px -10px rgba(0,0,0,.5); }
  .modal-tabs { padding: 0 6px; scrollbar-width: none; }
  .modal-tabs::-webkit-scrollbar { display: none; }
  .modal-tabs .tab { height: 44px; padding: 0 12px; }
  fieldset legend { font-size: 14px; }
  /* ação principal grande, em cima; as outras dividem a linha de baixo */
  .modal-actions { flex-wrap: wrap; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)) !important; background: #fff; }
  .modal-actions .spacer { display: none; }
  .modal-actions > button, .modal-actions > a { flex: 1 1 0; min-width: 0; height: 44px; justify-content: center; }
  .modal-actions > .btn-primary { order: -1; flex: 1 1 100%; height: 50px; font-size: 15px; border-radius: 12px; }
  .modal-actions > .hidden { display: none; }
  .asset-form .grid, .modal-card.sm .asset-form .grid, .modal-card.xs .asset-form .grid { grid-template-columns: 1fr !important; gap: 14px; }
  .asset-form .span2, .asset-form .span3 { grid-column: auto !important; }
  .asset-form input, .asset-form select, .asset-form textarea { min-height: 46px; }
  .sel-add .add-inline { width: 46px; height: 46px; }

  /* grupos de filtros em "chips" rolam de lado em vez de empilhar várias linhas */
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-left: -16px; margin-right: -16px; padding: 2px 16px 4px; }
  .chips::-webkit-scrollbar { display: none; }
  .chips > * { flex: none; }

  /* ---------- pequenos ajustes por módulo ---------- */
  .ev-mini { grid-template-columns: repeat(2, 1fr); }
  .ev-funil { grid-template-columns: repeat(2, 1fr); }
  .ev-cards { gap: 12px; }
  .item-head, .item-extra { grid-template-columns: 1fr !important; }
  .item-extra .span2 { grid-column: auto; }
  .cf-lock { margin: 8px auto; padding: 26px 18px; }
  .cf-code { flex-direction: column; align-items: stretch; }
  .cf-digits { width: 100%; height: 54px; font-size: 26px; }
  .cf-code .btn-primary { height: 50px; justify-content: center; }
  .cf-bar { flex-wrap: wrap; }
  .cf-g-acts .btn-ghost { flex: 1; justify-content: center; }
  .qr-scan .btn-ghost { height: 50px; padding: 0 28px; border-radius: 999px; }

  /* avisos acima da barra de abas */
  .toast { bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 14px); max-width: calc(100vw - 28px); text-align: left; }
  .update-bar { bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 14px); }
}

@keyframes folhaSobe { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .modal-card { animation: none !important; } }
