/* ═══════════════════════════════════════════════════════════
   FLOW ALÁFIA — theme-mobile.css  v3
   ═══════════════════════════════════════════════════════════ */

/* ════════════════════════════════════════════════
   TABLET (769–1024px): sidebar estreita hover-expand
   ════════════════════════════════════════════════ */
@media (max-width: 1024px) and (min-width: 769px) {
  aside, aside#aside {
    width: 64px !important;
    min-width: 64px !important;
    overflow: hidden !important;
    transition: width .22s ease !important;
    flex-shrink: 0 !important;
  }
  aside:hover, aside#aside:hover {
    width: 240px !important;
    z-index: 200;
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .logo-area { padding: .75rem .5rem !important; align-items: center !important; }
  .logo-name, .logo-sub, .logo-by { opacity:0; transition:opacity .15s; white-space:nowrap; }
  aside:hover .logo-name, aside:hover .logo-sub, aside:hover .logo-by,
  aside#aside:hover .logo-name, aside#aside:hover .logo-sub, aside#aside:hover .logo-by { opacity:1; }
  aside nav a span, aside#aside nav a span { opacity:0; transition:opacity .15s; white-space:nowrap; overflow:hidden; }
  aside:hover nav a span, aside#aside:hover nav a span { opacity:1; }
  .nav-sec { font-size:0 !important; }
  aside:hover .nav-sec, aside#aside:hover .nav-sec { font-size:.58rem !important; }
  .nav-foot { padding:.75rem .5rem !important; }
  .nav-info, .btn-sair, .nav-terreiro { opacity:0; transition:opacity .15s; }
  aside:hover .nav-info, aside:hover .btn-sair, aside:hover .nav-terreiro,
  aside#aside:hover .nav-info, aside#aside:hover .btn-sair, aside#aside:hover .nav-terreiro { opacity:1; }
  .kpi-grid { grid-template-columns: repeat(3,1fr) !important; }
  .dash-grid { grid-template-columns: 1fr 1fr !important; }
}

/* ════════════════════════════════════════════════
   MOBILE (até 768px)
   ════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Reset crítico: desfaz o layout flex horizontal ── */
  html { height: 100%; }

  body {
    flex-direction: column !important;
    height: 100dvh !important;
    height: 100vh !important; /* fallback */
    overflow: hidden !important;
    position: relative !important;
  }

  /* ── ASIDE → DRAWER ── */
  aside, aside#aside {
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    width: 80vw !important;
    max-width: 300px !important;
    min-width: unset !important;
    height: 100dvh !important;
    height: 100vh !important;
    z-index: 1000 !important;
    transform: translateX(-105%) !important;
    transition: transform .28s cubic-bezier(.4,0,.2,1) !important;
    box-shadow: none !important;
    overflow-y: auto !important;
    flex-shrink: 0 !important;
  }

  aside.fa-open, aside#aside.fa-open {
    transform: translateX(0) !important;
    box-shadow: 8px 0 32px rgba(0,0,0,.55) !important;
  }

  /* ── OVERLAY ── */
  #fa-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 999;
    -webkit-tap-highlight-color: transparent;
  }
  #fa-overlay.fa-open { display: block; }

  /* ── WRAP: ocupa 100% sem o aside ── */
  .wrap {
    flex: 1 !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    height: 100% !important;
  }

  /* ── TOPBAR / HEADER ── */
  .topbar, header {
    padding: .7rem 1rem !important;
    gap: 10px;
    flex-shrink: 0 !important;
    position: relative;
    z-index: 10;
  }

  /* Botão hamburguer */
  #fa-menu-btn {
    background: none;
    border: none;
    color: var(--txt2);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 6px;
    -webkit-tap-highlight-color: transparent;
    min-width: 36px;
    min-height: 36px;
  }
  #fa-menu-btn:active { color: var(--gold); background: var(--bg3); }

  /* Esconde info do usuário no topbar (fica só avatar) */
  .top-info { display: none !important; }
  .top-avatar { width: 32px !important; height: 32px !important; }
  .topbar-left h1, header h2 { font-size: 1rem !important; }
  .topbar-left p, .topbar-sub { font-size: .65rem !important; }

  /* ── MAIN ── */
  main {
    flex: 1 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 1rem !important;
    padding-bottom: 72px !important;
    min-height: 0 !important;
  }

  /* ── BOTTOM NAV ── */
  #fa-bottom-nav {
    position: fixed !important;
    bottom: 0 !important; left: 0 !important; right: 0 !important;
    height: 60px !important;
    background: var(--bg2) !important;
    border-top: 1px solid var(--brd) !important;
    display: flex !important;
    align-items: stretch !important;
    z-index: 900 !important;
    padding-bottom: env(safe-area-inset-bottom, 0) !important;
  }

  #fa-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--txt3);
    text-decoration: none;
    font-size: .58rem;
    font-weight: 600;
    letter-spacing: .3px;
    text-transform: uppercase;
    border-top: 2px solid transparent;
    transition: color .12s;
    -webkit-tap-highlight-color: transparent;
    padding: .35rem .2rem;
  }
  #fa-bottom-nav a svg { flex-shrink: 0; opacity: .7; }
  #fa-bottom-nav a.on { color: var(--gold) !important; border-top-color: var(--gold) !important; }
  #fa-bottom-nav a.on svg { opacity: 1; }
  #fa-bottom-nav a:active { background: var(--bg3); }

  /* ── GRIDS ── */
  .kpi-grid { grid-template-columns: repeat(2,1fr) !important; gap: .625rem !important; }
  .kpi { padding: .875rem !important; }
  .kpi-val { font-size: 1.2rem !important; }

  .dash-grid, .dash-grid2 { grid-template-columns: 1fr !important; gap: .75rem !important; }

  /* ── CALENDÁRIO: empilha cal-side + evt-side ── */
  main.cal-main, .cal-main {
    display: block !important;
    overflow-y: auto !important;
  }

  /* força o main do calendario a ser block */
  body > .wrap > main {
    display: block !important;
    overflow-y: auto !important;
  }

  .cal-side {
    width: 100% !important;
    overflow-y: visible !important;
    padding: .75rem !important;
  }

  .evt-side {
    width: 100% !important;
    min-width: unset !important;
    border-left: none !important;
    border-top: 1px solid var(--brd) !important;
    max-height: none !important;
    overflow-y: visible !important;
  }

  /* ── TABELAS ── */
  .card table, main table, table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    white-space: nowrap !important;
    max-width: 100% !important;
  }

  /* ── FILTROS / ABAS ── */
  .filtros, .tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    white-space: nowrap !important;
    gap: .35rem !important;
    scrollbar-width: none !important;
    flex-wrap: nowrap !important;
    padding-bottom: .25rem !important;
  }
  .filtros::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
  .fb, .tab { flex-shrink: 0 !important; font-size: .72rem !important; }

  /* ── CARDS ── */
  .card { padding: .875rem !important; }

  /* ── BOTÕES TOUCH ── */
  .btn, button:not(#fa-menu-btn):not(#btn-theme):not(.btn-sair):not(.cal-nav-btn):not(.fb):not(.stab) {
    min-height: 40px !important;
  }

  /* ── FORMULÁRIOS ── */
  .form-grid, .form-row { grid-template-columns: 1fr !important; }

  /* ── MODAL ── */
  .modal-box, .modal-content, .modal {
    width: calc(100vw - 2rem) !important;
    max-width: none !important;
    max-height: 85dvh !important;
    overflow-y: auto !important;
    margin: 1rem auto !important;
  }

  /* ── COLUNAS OPCIONAIS ── */
  .col-hide-mobile { display: none !important; }

  /* ── GRIDS DE CARDS (estoque, orixas etc) ── */
  .pessoa-grid, .items-grid, .estoque-grid, .produto-grid,
  .obrig-card-grid, .animais-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── TEMA: esconde label, mantém ícone ── */
  #btn-theme .theme-label { display: none !important; }
  #btn-theme { padding: 5px 8px !important; }

}

/* ── Fix específico: main com display:flex inline (calendário, etc) ── */
@media (max-width: 768px) {
  /* Override qualquer main com display flex para ser block */
  main {
    display: block !important;
  }
  /* Mas preserva o scroll */
  main {
    overflow-y: auto !important;
  }
}
