@import url("./correcoes-visuais/layout-tela-cheia.css");
@import url("./correcoes-visuais/painel-informacoes.css");
@import url("./correcoes-visuais/grade-conversa.css");
@import url("./correcoes-visuais/formulario-mensagem.css");

/*
  LG Chat - FIX FINAL RESPONSIVO
  Este arquivo precisa ficar por último no index.html.
*/

:root {
  --app-height: 100dvh;
}

.chat-page.hidden {
  display: none !important;
}

/* Evita que tela de login/cadastro seja travada pelo CSS do chat. */
body:not(.chat-active) {
  position: static !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

/* Tablet, celular e navegador estreito */
@media (max-width: 1100px) {
  html {
    width: 100% !important;
    min-height: 100% !important;
    overflow-x: hidden !important;
  }

  body.chat-active {
    width: 100% !important;
    height: var(--app-height) !important;
    min-height: var(--app-height) !important;
    overflow: hidden !important;
    position: fixed !important;
    inset: 0 !important;
  }

  body.chat-active .app-shell {
    width: 100vw !important;
    height: var(--app-height) !important;
    min-height: var(--app-height) !important;
    overflow: hidden !important;
  }

  body.chat-active .chat-page {
    width: 100vw !important;
    height: var(--app-height) !important;
    min-height: var(--app-height) !important;
    display: grid !important;
    grid-template-columns: 100vw !important;
    grid-template-rows: minmax(0, 1fr) !important;
    grid-template-areas: "sidebar" !important;
    transform: none !important;
    overflow: hidden !important;
  }

  body.chat-active:not(.mobile-chat-open) #sidebarRoot {
    grid-area: sidebar !important;
    display: block !important;
    width: 100vw !important;
    height: var(--app-height) !important;
    min-width: 0 !important;
    max-width: 100vw !important;
    overflow: hidden !important;
  }

  body.chat-active:not(.mobile-chat-open) #chatMainRoot {
    display: none !important;
  }

  body.chat-active.mobile-chat-open .chat-page {
    grid-template-areas: "chat" !important;
  }

  body.chat-active.mobile-chat-open #sidebarRoot {
    display: none !important;
  }

  body.chat-active.mobile-chat-open #chatMainRoot {
    grid-area: chat !important;
    display: block !important;
    width: 100vw !important;
    height: var(--app-height) !important;
    min-width: 0 !important;
    max-width: 100vw !important;
    overflow: hidden !important;
  }

  body.chat-active .sidebar {
    width: 100vw !important;
    height: var(--app-height) !important;
    max-width: 100vw !important;
    max-height: var(--app-height) !important;
    overflow: hidden !important;
  }

  body.chat-active .chat-main {
    width: 100vw !important;
    height: var(--app-height) !important;
    max-width: 100vw !important;
    max-height: var(--app-height) !important;
    min-width: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows:
      auto
      auto
      auto
      auto
      minmax(0, 1fr)
      auto
      auto
      auto
      auto !important;
    grid-template-areas:
      "header"
      "search"
      "starred"
      "block"
      "messages"
      "typing"
      "reply"
      "editing"
      "form" !important;
  }

  body.chat-active .chat-header {
    grid-area: header !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }

  body.chat-active #chatSearchPanel {
    grid-area: search !important;
  }

  body.chat-active #starredMessagesPanel {
    grid-area: starred !important;
  }

  body.chat-active #chatBlockNotice {
    grid-area: block !important;
  }

  body.chat-active #messages {
    grid-area: messages !important;
    min-width: 0 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
  }

  body.chat-active #typingText {
    grid-area: typing !important;
  }

  body.chat-active #replyBar {
    grid-area: reply !important;
  }

  body.chat-active #editingBar {
    grid-area: editing !important;
  }

  body.chat-active #messageForm,
  body.chat-active .message-form {
    grid-area: form !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    display: grid !important;
    grid-template-columns: 42px minmax(0, 1fr) 42px 64px !important;
    gap: 8px !important;
    align-items: center !important;
    padding: 8px 9px max(8px, env(safe-area-inset-bottom)) !important;
    margin: 0 !important;
    overflow: visible !important;
    position: relative !important;
    bottom: auto !important;
    z-index: 20 !important;
  }

  body.chat-active #messageInput {
    width: 100% !important;
    min-width: 0 !important;
    height: 42px !important;
    font-size: 16px !important;
  }

  body.chat-active .media-button,
  body.chat-active .voice-button {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    padding: 0 !important;
  }

  body.chat-active #sendMessageButton {
    width: 64px !important;
    min-width: 64px !important;
    height: 42px !important;
    padding-inline: 8px !important;
    font-size: 13px !important;
  }

  body.chat-active .chat-header-profile {
    min-width: 0 !important;
  }

  body.chat-active #chatTitle,
  body.chat-active #chatSubtitle {
    max-width: 100% !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  body.chat-active .chat-header-actions,
  body.chat-active .header-actions {
    flex-shrink: 0 !important;
  }

  body.chat-active .chat-item,
  body.chat-active .chat-item-content,
  body.chat-active .chat-last-message {
    min-width: 0 !important;
  }

  body.chat-active .chat-last-message {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  body.chat-active .info-panel {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: var(--app-height) !important;
    max-height: var(--app-height) !important;
    z-index: 100 !important;
  }

  body.chat-active .modal-content,
  body.chat-active .media-viewer-content,
  body.chat-active .media-preview-content,
  body.chat-active .audio-recorder-content {
    max-width: calc(100vw - 16px) !important;
    max-height: calc(var(--app-height) - 16px) !important;
    overflow: auto !important;
  }

  body.chat-active .call-panel {
    padding: 10px !important;
  }

  body.chat-active .call-card {
    width: 100% !important;
    height: calc(var(--app-height) - 20px) !important;
    max-height: calc(var(--app-height) - 20px) !important;
  }
}

@media (max-width: 430px) {
  body.chat-active #messageForm,
  body.chat-active .message-form {
    grid-template-columns: 40px minmax(0, 1fr) 40px 56px !important;
    gap: 6px !important;
  }

  body.chat-active .media-button,
  body.chat-active .voice-button {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
  }

  body.chat-active #sendMessageButton {
    width: 56px !important;
    min-width: 56px !important;
    font-size: 12px !important;
    padding-inline: 6px !important;
  }
}


/* ===== FIX: ações do cabeçalho no celular/tablet =====
   Mantém chamada, busca, favoritas e atualizar visíveis em telas pequenas. */

.refresh-mobile-label {
  display: none;
}

.remote-call-audio {
  display: none !important;
}

@media (max-width: 1100px) {
  body.chat-active .chat-header {
    padding: 7px 8px !important;
    gap: 6px !important;
    min-height: 60px !important;
  }

  body.chat-active .back-button {
    display: inline-grid !important;
    place-items: center !important;
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    flex: 0 0 40px !important;
  }

  body.chat-active .chat-header-profile {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    gap: 8px !important;
    padding: 4px 5px !important;
  }

  body.chat-active .chat-header-avatar {
    width: 38px !important;
    height: 38px !important;
    flex: 0 0 38px !important;
  }

  body.chat-active .chat-title-box {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  body.chat-active .chat-header h2 {
    font-size: 15px !important;
  }

  body.chat-active .chat-header p {
    font-size: 11.5px !important;
  }

  body.chat-active .header-actions {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    flex: 0 0 auto !important;
    max-width: min(54vw, 236px) !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 2px !important;
  }

  body.chat-active .header-actions::-webkit-scrollbar {
    display: none !important;
  }

  body.chat-active .header-actions .ghost-button,
  body.chat-active .header-actions .call-header-button,
  body.chat-active .header-actions .chat-search-toggle,
  body.chat-active .header-actions .starred-toggle,
  body.chat-active #refreshChatsButton {
    display: inline-grid !important;
    place-items: center !important;
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 !important;
    border-radius: 999px !important;
    font-size: 16px !important;
    flex: 0 0 38px !important;
  }

  body.chat-active #refreshChatsButton .refresh-full-label {
    display: none !important;
  }

  body.chat-active #refreshChatsButton .refresh-mobile-label {
    display: inline !important;
    font-size: 20px !important;
    line-height: 1 !important;
  }

  body.chat-active .header-actions button:disabled {
    opacity: 0.45 !important;
  }

  body.chat-active .chat-search-box {
    grid-template-columns: 1fr auto !important;
    gap: 8px !important;
  }

  body.chat-active .chat-search-icon {
    display: none !important;
  }

  body.chat-active #messageSearchType {
    grid-column: 1 / -1 !important;
  }

  body.chat-active .chat-search-small-button {
    grid-column: 1 / 2 !important;
  }

  body.chat-active .chat-search-close {
    grid-column: 2 / 3 !important;
  }

  body.chat-active .chat-search-status,
  body.chat-active .chat-search-results {
    padding-left: 0 !important;
  }

  body.chat-active .starred-messages-panel,
  body.chat-active .chat-search-panel {
    max-height: calc(var(--app-height) - 115px) !important;
    overflow: auto !important;
  }

  body.chat-active .app-tools-panel {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  body.chat-active #installAppButton,
  body.chat-active #toggleSoundButton,
  body.chat-active #enableNotificationsButton {
    min-height: 40px !important;
  }
}

@media (max-width: 390px) {
  body.chat-active .header-actions {
    max-width: min(50vw, 190px) !important;
  }

  body.chat-active .header-actions .ghost-button,
  body.chat-active .header-actions .call-header-button,
  body.chat-active .header-actions .chat-search-toggle,
  body.chat-active .header-actions .starred-toggle,
  body.chat-active #refreshChatsButton {
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    flex-basis: 36px !important;
    font-size: 15px !important;
  }
}
