/* Camada visual mobile/app (escopo seguro) */
body.mobile-app {
  --app-header-h: 60px;
  --app-bottom-h: 72px;
}

body.mobile-app .mobile-app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5000;
  height: var(--app-header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

body.mobile-app .mobile-app-header .title {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.mobile-app .mobile-app-header .action-btn {
  min-height: 40px;
  min-width: 40px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body.mobile-app.mobile-authenticated .header {
  display: none;
}

body.mobile-app.mobile-authenticated .main-content,
body.mobile-app.mobile-authenticated .chat-wrap {
  padding-top: calc(var(--app-header-h) + 10px) !important;
  padding-bottom: calc(var(--app-bottom-h) + 10px) !important;
}

body.mobile-app .mobile-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5000;
  height: var(--app-bottom-h);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  background: rgba(15, 23, 42, 0.98);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

body.mobile-app .mobile-bottom-nav a {
  color: #cbd5e1;
  text-decoration: none;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 10px;
}

body.mobile-app .mobile-bottom-nav a.active {
  color: #fff;
  background: rgba(30, 112, 130, 0.45);
}

body.mobile-app .mobile-bottom-nav .icon {
  font-size: 16px;
  line-height: 1;
}

body.mobile-app .logout-btn,
body.mobile-app .btn,
body.mobile-app button,
body.mobile-app input[type="submit"],
body.mobile-app input[type="button"] {
  min-height: 44px;
}

body.mobile-app .nav-menu-icon,
body.mobile-app .logout-btn-icon,
body.mobile-app .admin-menu-icon img {
  width: 20px !important;
  height: 20px !important;
}

body.mobile-app.login-mobile {
  justify-content: center;
}

body.mobile-app.login-mobile .login-container {
  margin: 12px !important;
  width: calc(100% - 24px);
  max-width: 420px;
  padding: 22px 16px !important;
  border-radius: 14px;
}

body.mobile-app.login-mobile .title {
  font-size: 24px;
}

body.mobile-app.login-mobile .form-group {
  margin-bottom: 16px;
}

body.mobile-app.login-mobile .form-group input {
  font-size: 16px;
}

body.mobile-app.mobile-authenticated .destaques-grid,
body.mobile-app.mobile-authenticated .noticias-ia-grid,
body.mobile-app.mobile-authenticated .stats-grid {
  grid-template-columns: 1fr !important;
}

/* Ajustes internos adicionais para experiencia app */
body.mobile-app.mobile-authenticated {
  overflow-x: hidden;
}

body.mobile-app.mobile-authenticated .main-content,
body.mobile-app.mobile-authenticated .container,
body.mobile-app.mobile-authenticated .content,
body.mobile-app.mobile-authenticated .page-content,
body.mobile-app.mobile-authenticated .chat-wrap {
  width: 100% !important;
  max-width: 100% !important;
  padding-left: 12px !important;
  padding-right: 12px !important;
}

body.mobile-app.mobile-authenticated .stats-grid,
body.mobile-app.mobile-authenticated .termos-grid,
body.mobile-app.mobile-authenticated .usuarios-grid,
body.mobile-app.mobile-authenticated .cards-grid,
body.mobile-app.mobile-authenticated .profile-grid {
  grid-template-columns: 1fr !important;
}

body.mobile-app.mobile-authenticated .btn,
body.mobile-app.mobile-authenticated .logout-btn,
body.mobile-app.mobile-authenticated .admin-menu-toggle,
body.mobile-app.mobile-authenticated .btn-assinar,
body.mobile-app.mobile-authenticated .btn-secondary,
body.mobile-app.mobile-authenticated .btn-danger {
  min-height: 44px !important;
  padding: 10px 14px !important;
  font-size: 14px !important;
}

body.mobile-app.mobile-authenticated input,
body.mobile-app.mobile-authenticated textarea,
body.mobile-app.mobile-authenticated select {
  font-size: 16px !important;
  width: 100% !important;
}

body.mobile-app.mobile-authenticated .form-group,
body.mobile-app.mobile-authenticated .termo-acoes,
body.mobile-app.mobile-authenticated .actions,
body.mobile-app.mobile-authenticated .filters {
  gap: 10px !important;
}

body.mobile-app.mobile-authenticated .table-responsive,
body.mobile-app.mobile-authenticated table {
  width: 100% !important;
}

/* Card mobile gerado pelo JS para tabelas */
body.mobile-app .mobile-table-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

body.mobile-app .mobile-table-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

body.mobile-app .mobile-table-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  margin-bottom: 6px;
  align-items: start;
}

body.mobile-app .mobile-table-row:last-child {
  margin-bottom: 0;
}

body.mobile-app .mobile-table-key {
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

body.mobile-app .mobile-table-val {
  color: #0f172a;
  font-size: 13px;
  word-break: break-word;
}

@media (max-width: 390px) {
  body.mobile-app .mobile-table-row {
    grid-template-columns: 1fr;
  }
}

/* Fluidez visual app */
body.mobile-app * {
  -webkit-tap-highlight-color: transparent;
}

body.mobile-app a,
body.mobile-app button,
body.mobile-app .btn {
  transition: transform 0.12s ease, opacity 0.15s ease, background-color 0.2s ease;
}

body.mobile-app a.tap-active,
body.mobile-app button.tap-active,
body.mobile-app .btn.tap-active {
  transform: scale(0.98);
  opacity: 0.92;
}

body.mobile-app .mobile-app-header .action-btn.open {
  transform: rotate(90deg);
}

body.mobile-app .mobile-page-loader {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  background: rgba(2, 6, 23, 0.38);
  backdrop-filter: blur(2px);
}

body.mobile-app .mobile-page-loader.show {
  display: flex;
}

body.mobile-app .mobile-page-loader .spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255,255,255,0.4);
  border-top-color: #f59e0b;
  border-radius: 50%;
  animation: appSpin 0.8s linear infinite;
}

body.mobile-app .mobile-page-loader .text {
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
}

body.mobile-app .mobile-offline-bar {
  position: fixed;
  top: calc(var(--app-header-h) + 2px);
  left: 8px;
  right: 8px;
  z-index: 6000;
  display: none;
  padding: 9px 10px;
  border-radius: 10px;
  background: #b91c1c;
  color: #fff;
  font-size: 12px;
  text-align: center;
}

body.mobile-app .mobile-offline-bar.show {
  display: block;
}

@keyframes appSpin {
  to {
    transform: rotate(360deg);
  }
}

/* Chat no app: comportamento estilo mensageiro */
@media (max-width: 768px) {
  body.mobile-app.mobile-chat-page .chat-shell {
    display: block !important;
    min-height: calc(100vh - var(--app-header-h) - var(--app-bottom-h) - 20px);
  }

  body.mobile-app.mobile-chat-page .chat-sidebar,
  body.mobile-app.mobile-chat-page .chat-main {
    min-height: calc(100vh - var(--app-header-h) - var(--app-bottom-h) - 24px);
    border-radius: 14px;
  }

  body.mobile-app.mobile-chat-page:not(.chat-open) .chat-main {
    display: none !important;
  }

  body.mobile-app.mobile-chat-page.chat-open .chat-sidebar {
    display: none !important;
  }

  body.mobile-app.mobile-chat-page .mobile-chat-back {
    margin-right: 8px;
    font-size: 12px !important;
    min-height: 36px !important;
    padding: 6px 10px !important;
  }

  body.mobile-app.mobile-chat-page:not(.chat-open) .mobile-chat-back {
    display: none !important;
  }

  body.mobile-app.mobile-chat-page .chat-main-head {
    position: sticky;
    top: 0;
    z-index: 3;
  }

  body.mobile-app.mobile-chat-page .composer {
    position: sticky;
    bottom: 0;
    z-index: 3;
    background: #fff;
  }
}

/* Sheet de menu "Mais" */
body.mobile-app .mobile-more-sheet {
  position: fixed;
  inset: 0;
  z-index: 8000;
  display: none;
}

body.mobile-app .mobile-more-sheet.open {
  display: block;
}

body.mobile-app .mobile-more-overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.45);
}

body.mobile-app .mobile-more-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 68vh;
  background: #0f172a;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

body.mobile-app .mobile-more-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  font-weight: 700;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

body.mobile-app .mobile-more-head .close {
  background: rgba(255,255,255,0.15);
  border: 0;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

body.mobile-app .mobile-more-list {
  padding: 8px;
  overflow-y: auto;
  max-height: calc(68vh - 52px);
}

body.mobile-app .mobile-more-list a {
  display: block;
  color: #e2e8f0;
  text-decoration: none;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  font-size: 14px;
}

/* Remove espaço fantasma da lista de conversas */
@media (max-width: 768px) {
  body.mobile-app.mobile-chat-page:not(.chat-open) .chat-sidebar {
    min-height: auto !important;
    height: auto !important;
  }

  body.mobile-app.mobile-chat-page:not(.chat-open) #conversationList {
    flex: 0 0 auto !important;
    max-height: 58vh !important;
    height: auto !important;
  }

  body.mobile-app.mobile-chat-page:not(.chat-open) .chat-sidebar {
    overflow: hidden;
  }
}
