/* Modo_Celular — base (tarefa 6.1). Carregado depois de style.css.
   Tudo é escopado em html.mobile (classe aplicada por modo-celular.js).
   Temas: usa as variáveis de style.css (html[data-theme=light|dark]); nada aqui fixa cores.
   Pontos de extensão:
     - 6.2 (mobile.js): gaveta ☰ e janelas em tela cheia usam as variáveis --m-* abaixo;
     - 6.3 (mobile-componentes.css): calendário em lista, tabelas em cartões, alvos de 44 px. */

html.mobile {
  --m-toque: 44px;          /* tamanho mínimo de alvo de toque (6.3) */
  --m-gap: 12px;
  --m-pad: 14px;
  --m-topo: 56px;           /* altura da barra superior */
  --m-gaveta: min(300px, 86vw);
  --m-z-gaveta: 40;
  --m-z-fundo: 39;
  --m-z-janela: 60;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

html.mobile,
html.mobile body {
  max-width: 100%;
  overflow-x: hidden;
}

html.mobile body { min-height: 100vh; min-height: 100dvh; }

html.mobile img,
html.mobile svg,
html.mobile video,
html.mobile canvas { max-width: 100%; }

/* Evita zoom automático do iOS ao focar campos */
html.mobile input,
html.mobile select,
html.mobile textarea { font-size: 16px; max-width: 100%; box-sizing: border-box; }

/* Login sem rolagem horizontal */
html.mobile .login-screen { padding: var(--m-pad); box-sizing: border-box; min-height: 100vh; min-height: 100dvh; }
html.mobile .login-card { width: 100%; max-width: 420px; box-sizing: border-box; padding: 22px var(--m-pad); }

/* Estrutura do aplicativo: uma coluna */
html.mobile .app { grid-template-columns: minmax(0, 1fr); min-height: 100dvh; }
html.mobile .main-wrap { min-width: 0; }
html.mobile .topbar { padding: 0 var(--m-pad); min-height: var(--m-topo); gap: 8px; }
html.mobile .content { padding: 18px var(--m-pad) 40px; min-width: 0; }
/* Barra superior: o bloco de título encolhe (com reticências) para o tema e o ☰ nunca saírem da tela (7.3, 320–360 px) */
html.mobile .topbar > div:first-child { flex: 1 1 0; min-width: 0; overflow: hidden; }
html.mobile .topbar .top-actions { flex: 0 1 auto; min-width: 0; max-width: 100%; }
html.mobile .topbar .top-actions .icon-button { flex: none; }
html.mobile .mobile-only { display: inline-block; }

/* Conteúdo largo rola dentro do próprio bloco, nunca a página */
html.mobile .panel,
html.mobile .card { min-width: 0; }
html.mobile .table-wrap,
html.mobile .table { max-width: 100%; }

/* Formulários em uma coluna */
html.mobile .form-grid { grid-template-columns: minmax(0, 1fr); }

/* Janelas: base respeitando a tela (tela cheia fica na 6.2) */
html.mobile dialog { max-width: 100vw; max-height: 100dvh; box-sizing: border-box; }

/* Áreas seguras (entalhe) */
@supports (padding: max(0px)) {
  html.mobile .topbar { padding-left: max(var(--m-pad), env(safe-area-inset-left)); padding-right: max(var(--m-pad), env(safe-area-inset-right)); }
  html.mobile .content { padding-bottom: max(40px, env(safe-area-inset-bottom)); }
}

/* Ponto de extensão: gaveta (6.2) — estado fechado/aberto controlado por mobile.js */
html.mobile .sidebar { z-index: var(--m-z-gaveta); }

/* ===== Tarefa 6.2 — gaveta ☰ e janelas em tela cheia (Requisito 16.2, 16.4) ===== */

/* Fundo escurecido da gaveta: criado por mobile.js; fora do modo celular nunca aparece */
.m-fundo { display: none; }

/* Gaveta: o estado aberto continua sendo a classe .open do portal.js; mobile.js só sincroniza aria e foco */
html.mobile .sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: var(--m-z-gaveta);
  width: var(--m-gaveta); height: 100vh; height: 100dvh; min-height: 0;
  display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(-105%); visibility: hidden;
  transition: transform .22s ease, visibility 0s linear .22s;
  box-shadow: 10px 0 40px #0004;
}
html.mobile .sidebar.open { transform: none; visibility: visible; transition: transform .22s ease; }
html.mobile .sidebar nav button,
html.mobile .sidebar-foot > button { min-height: var(--m-toque); }
html.mobile .sidebar-foot > button { display: block; width: 100%; text-align: left; }

html.mobile .m-fundo {
  display: block; position: fixed; inset: 0; z-index: var(--m-z-fundo);
  background: rgba(10, 10, 14, .55); opacity: 0; pointer-events: none;
  transition: opacity .22s ease;
}
html.mobile .m-fundo.on { opacity: 1; pointer-events: auto; }
html.mobile.m-gaveta-aberta body { overflow: hidden; }
html.mobile #menu-toggle { min-width: var(--m-toque); min-height: var(--m-toque); }

/* Janelas em tela cheia, com barra superior fixa e X sempre visível */
html.mobile dialog[open] {
  position: fixed; inset: 0; margin: 0; z-index: var(--m-z-janela);
  width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none;
  border: 0; border-radius: 0; box-shadow: none;
  display: flex; flex-direction: column; overflow: hidden;
}
html.mobile dialog[open] > form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; margin: 0; }
html.mobile dialog .dialog-head {
  position: static; flex: 0 0 auto; min-height: var(--m-topo);
  padding: 8px max(var(--m-pad), env(safe-area-inset-right)) 8px max(var(--m-pad), env(safe-area-inset-left));
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel); gap: 10px;
}
html.mobile dialog .dialog-head h2 { font-size: 17px; margin-top: 2px; }
html.mobile dialog .dialog-head .icon-button {
  flex: 0 0 auto; min-width: var(--m-toque); min-height: var(--m-toque);
  font-size: 26px; line-height: 1; display: inline-grid; place-items: center;
  background: var(--soft); color: var(--ink);
}
html.mobile dialog .dialog-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px var(--m-pad); padding-bottom: max(24px, env(safe-area-inset-bottom));
}
html.mobile dialog .dialog-actions { flex-wrap: wrap; }
html.mobile dialog .dialog-actions > button { flex: 1 1 130px; min-height: var(--m-toque); }
