/* ==========================================================================
   ACONCHEGO DOS PETS — PWA MOBILE (AGENTS.md v24.0)
   Folha de estilos responsiva carregada em todas as telas do sistema.
   Objetivo: empilhar conteúdo, transformar menus laterais em barras
   inferiores de toque e eliminar qualquer desconfiguração em smartphones
   e tablets, sem afetar o layout executivo em desktop.
   ========================================================================== */

:root {
  --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
  --pwa-teal: #0d9488;
  --pwa-teal-dark: #0f766e;
  --pwa-slate: #334155;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(13, 148, 136, 0.16);
}

/* Evita zoom automático do iOS em campos de formulário. */
@media (max-width: 1023px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* --------------------------------------------------------------------------
   TABLETS E SMARTPHONES — menu lateral vira barra inferior de toque
   -------------------------------------------------------------------------- */
@media (max-width: 1023px) {
  /* Layout legado com sidebar fixa (dashboard executivo) */
  .main-wrapper {
    margin-left: 0 !important;
    padding: 16px 14px calc(96px + var(--pwa-safe-bottom)) !important;
    min-height: 100vh;
  }

  .sidebar {
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: auto !important;
    max-height: 92px;
    flex-direction: row !important;
    border-right: 0 !important;
    border-top: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: 0 -14px 34px -18px rgba(15, 23, 42, 0.55);
    z-index: 1000;
    padding-bottom: var(--pwa-safe-bottom);
  }

  .sidebar-brand,
  .sidebar .menu-category,
  .sidebar .user-profile-bottom {
    display: none !important;
  }

  .sidebar-menu {
    display: flex !important;
    flex-direction: row !important;
    align-items: stretch;
    width: 100%;
    padding: 6px 8px !important;
    gap: 4px;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-menu::-webkit-scrollbar {
    display: none;
  }

  .sidebar .nav-item {
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-width: 76px;
    padding: 8px 10px;
    border-left: 0 !important;
    border-radius: 14px;
    font-size: 9px;
    line-height: 1.15;
    text-align: center;
    white-space: nowrap;
  }

  .sidebar .nav-item i {
    font-size: 1.05rem;
  }

  .sidebar .nav-item img {
    width: 20px;
    height: 20px;
  }

  /* Layout base_painel (aside + main em flex de tela cheia) */
  body.flex.h-screen.overflow-hidden {
    display: block !important;
    height: auto !important;
    min-height: 100vh;
    overflow-y: auto !important;
  }

  body > aside.w-72 {
    position: fixed !important;
    inset: auto 0 0 0 !important;
    width: 100% !important;
    height: auto !important;
    max-height: 92px;
    flex-direction: row !important;
    z-index: 1000;
    padding-bottom: var(--pwa-safe-bottom);
    box-shadow: 0 -14px 34px -18px rgba(15, 23, 42, 0.55);
  }

  body > aside.w-72 > div:first-child,
  body > aside.w-72 > div:last-child {
    display: none !important;
  }

  body > aside.w-72 .flex-1.overflow-y-auto {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 6px 8px !important;
    gap: 4px;
    width: 100%;
    scrollbar-width: none;
  }

  body > aside.w-72 .flex-1.overflow-y-auto::-webkit-scrollbar {
    display: none;
  }

  body > aside.w-72 .flex-1.overflow-y-auto > p {
    display: none !important;
  }

  body > aside.w-72 .flex-1.overflow-y-auto > * + * {
    margin-top: 0 !important;
  }

  body > aside.w-72 a {
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-width: 76px;
    padding: 8px 10px;
    border-radius: 14px;
    font-size: 9px;
    text-align: center;
    white-space: nowrap;
  }

  body > aside.w-72 a i {
    font-size: 1.05rem;
  }

  body > main.flex-1 {
    overflow: visible !important;
    min-height: 100vh;
    padding-bottom: calc(96px + var(--pwa-safe-bottom));
  }

  body > main.flex-1 > header {
    height: auto !important;
    min-height: 64px;
    padding: 12px 16px !important;
    flex-wrap: wrap;
    gap: 10px;
  }

  body > main.flex-1 > div.flex-1.overflow-y-auto {
    overflow: visible !important;
    padding: 16px 14px !important;
  }
}

/* --------------------------------------------------------------------------
   SMARTPHONES — empilhamento vertical e áreas de toque confortáveis
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  header .max-w-7xl {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  header .h-20 {
    height: auto !important;
    min-height: 68px;
    padding-top: 12px;
    padding-bottom: 12px;
    gap: 10px;
    flex-wrap: wrap;
  }

  .max-w-7xl {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  main {
    padding-top: 18px !important;
  }

  /* Cards e blocos nunca extrapolam a largura da tela. */
  .rounded-2xl,
  .rounded-3xl {
    max-width: 100%;
  }

  /* Tabelas largas ganham rolagem horizontal controlada. */
  table {
    display: block;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* Modais ocupam a tela com respiro lateral e rolagem interna. */
  [role="dialog"],
  .modal,
  .modal-content {
    max-width: calc(100vw - 20px) !important;
    max-height: calc(100vh - 32px) !important;
    margin: 10px auto !important;
    overflow-y: auto !important;
  }

  /* Botões de ação primária ficam confortáveis ao toque. */
  button,
  .btn {
    min-height: 42px;
  }

  /* Cabeçalhos de tabela e grids densos podem rolar em vez de quebrar. */
  .overflow-x-auto {
    -webkit-overflow-scrolling: touch;
  }
}

/* --------------------------------------------------------------------------
   BANNER OFFLINE + BOTÃO DE INSTALAÇÃO (injetados pelo _pwa_scripts.html)
   -------------------------------------------------------------------------- */
#pwa-offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2147483000;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f59e0b;
  color: #451a03;
  font-family: Inter, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

#pwa-offline-banner.is-visible {
  display: flex;
}

#pwa-install-btn {
  position: fixed;
  right: 16px;
  bottom: calc(104px + var(--pwa-safe-bottom));
  z-index: 999;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border: 1px solid #0f766e;
  border-radius: 999px;
  background: var(--pwa-teal);
  color: #ffffff;
  font-family: Inter, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 14px 30px -14px rgba(13, 148, 136, 0.9);
  cursor: pointer;
}

#pwa-install-btn.is-visible {
  display: inline-flex;
}

#pwa-install-btn:active {
  transform: scale(0.98);
  background: var(--pwa-teal-dark);
}

@media (min-width: 1024px) {
  #pwa-install-btn {
    bottom: 20px;
  }
}
