/*
  LG Chat - Compatibilidade para celulares, tablets, notebooks e desktops.
  Coloque este CSS depois dos outros arquivos CSS no index.html.
*/

:root {
  --app-height: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --mobile-header-height: 64px;
  --message-form-height: 76px;
}

html {
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: var(--app-height);
  overflow-x: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

img,
video,
canvas,
svg {
  max-width: 100%;
  height: auto;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
[role="button"],
a,
input,
textarea,
select {
  -webkit-tap-highlight-color: transparent;
}

input,
textarea,
select {
  font-size: 16px;
}

/* Evita zoom automático no iPhone ao focar em input menor que 16px. */
@supports (-webkit-touch-callout: none) {
  input,
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* Estrutura geral */
.app,
.app-shell,
.chat-app,
.main-layout,
.chat-layout {
  min-height: 100vh;
  min-height: 100dvh;
  min-height: var(--app-height);
  max-width: 100%;
  overflow: hidden;
}

.chat-screen,
.chat-main,
.chat-area {
  min-width: 0;
  max-width: 100%;
}

.sidebar,
.users-panel,
.status-panel,
.chat-info-panel,
.chat-panel {
  min-width: 0;
}

/* Mensagens e mídia */
.messages,
#messages {
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding-bottom: calc(var(--message-form-height) + var(--safe-bottom) + 14px);
}

.message,
.bubble {
  max-width: 100%;
  min-width: 0;
}

.bubble {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-media-image,
.message-media-video,
.message-media-audio,
.media-viewer-image,
.media-viewer-video,
.media-preview-image,
.media-preview-video {
  max-width: min(100%, 720px);
  max-height: 70vh;
  object-fit: contain;
}

.message-file-box,
.media-preview-file-box,
.media-viewer-file-card {
  min-width: 0;
  max-width: 100%;
}

.message-file-info,
.media-preview-file-info,
.media-viewer-file-info,
.chat-item-content,
.chat-last-message {
  min-width: 0;
}

.chat-last-message,
.message-file-info strong,
.message-file-info span,
.media-preview-file-info strong,
.media-preview-file-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Formulário de mensagem */
.message-form,
#messageForm {
  width: 100%;
  max-width: 100%;
  padding-bottom: max(10px, var(--safe-bottom));
}

#messageInput,
.message-input {
  min-width: 0;
  max-width: 100%;
  resize: none;
}

/* Modais */
.modal,
.modal-backdrop,
.media-viewer-modal,
.media-preview-modal,
.audio-recorder-modal,
.forward-message-modal,
.starred-messages-panel,
.chat-search-panel {
  max-width: 100vw;
  max-height: 100dvh;
}

.modal-content,
.media-viewer-content,
.media-preview-content,
.audio-recorder-content {
  width: min(94vw, 720px);
  max-width: calc(100vw - 20px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Menus flutuantes */
.chat-options-menu,
.message-actions-menu,
.attachment-menu {
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 9999;
}

/* Telas pequenas: celular */
@media (max-width: 820px) {
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: var(--app-height);
    overflow: hidden;
  }

  .app,
  .app-shell,
  .chat-app,
  .main-layout,
  .chat-layout {
    height: var(--app-height);
    min-height: var(--app-height);
  }

  .main-layout,
  .chat-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr !important;
  }

  .sidebar {
    width: 100% !important;
    max-width: 100% !important;
    height: var(--app-height) !important;
    min-height: var(--app-height) !important;
    padding-top: var(--safe-top);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
  }

  .chat-main,
  .chat-screen,
  .chat-area {
    width: 100% !important;
    max-width: 100% !important;
    height: var(--app-height) !important;
    min-height: var(--app-height) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    padding-top: var(--safe-top);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
  }

  /*
    Compatibilidade com apps que alternam telas com classes.
    A sidebar aparece quando o body NÃO tem chat aberto.
    O chat aparece quando o body tem .mobile-chat-open.
  */
  body:not(.mobile-chat-open) .chat-main,
  body:not(.mobile-chat-open) .chat-screen,
  body:not(.mobile-chat-open) .chat-area {
    display: none !important;
  }

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

  body.mobile-chat-open .chat-main,
  body.mobile-chat-open .chat-screen,
  body.mobile-chat-open .chat-area {
    display: flex !important;
  }

  .chat-header,
  .conversation-header {
    flex: 0 0 auto;
    min-height: var(--mobile-header-height);
    max-width: 100%;
  }

  .messages,
  #messages {
    flex: 1 1 auto;
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    padding-left: 10px;
    padding-right: 10px;
  }

  .message-form,
  #messageForm {
    flex: 0 0 auto;
    position: sticky;
    bottom: 0;
    z-index: 30;
    background: inherit;
  }

  .chat-info-panel {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: var(--app-height) !important;
    max-width: none !important;
    z-index: 80;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
  }

  .modal-content,
  .media-viewer-content,
  .media-preview-content,
  .audio-recorder-content {
    width: calc(100vw - 16px);
    max-height: calc(var(--app-height) - 16px);
    border-radius: 16px;
  }

  .media-viewer-image,
  .media-viewer-video,
  .media-preview-image,
  .media-preview-video {
    max-height: 58vh;
  }

  .chat-item {
    min-height: 68px;
  }

  .chat-options-button,
  .message-action-button,
  .send-button,
  .media-button,
  .voice-button,
  .back-button {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Tablets */
@media (min-width: 821px) and (max-width: 1180px) {
  .main-layout,
  .chat-layout {
    grid-template-columns: minmax(300px, 36vw) minmax(0, 1fr) !important;
  }

  .sidebar {
    max-width: 420px;
  }

  .chat-info-panel {
    width: min(420px, 42vw);
  }

  .bubble {
    max-width: 78%;
  }
}

/* Desktops e telas grandes */
@media (min-width: 1181px) {
  .bubble {
    max-width: 68%;
  }

  .main-layout,
  .chat-layout {
    max-width: 1920px;
    margin-inline: auto;
  }
}

/* Celulares muito estreitos */
@media (max-width: 380px) {
  .chat-title,
  #chatTitle {
    font-size: 15px;
  }

  .chat-subtitle,
  #chatSubtitle {
    font-size: 12px;
  }

  .bubble {
    font-size: 14px;
  }

  .message-form,
  #messageForm {
    gap: 6px;
  }

  .chat-options-button,
  .message-action-button,
  .send-button,
  .media-button,
  .voice-button {
    min-width: 40px;
    min-height: 40px;
  }
}

/* Paisagem no celular */
@media (max-width: 900px) and (orientation: landscape) {
  .chat-header,
  .conversation-header {
    min-height: 52px;
  }

  .media-viewer-image,
  .media-viewer-video,
  .media-preview-image,
  .media-preview-video {
    max-height: 48vh;
  }

  .modal-content,
  .media-viewer-content,
  .media-preview-content,
  .audio-recorder-content {
    max-height: calc(var(--app-height) - 10px);
  }
}

/* Acessibilidade */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
