/* WATranslate Adaptive Mobile UI v4.1
   Desktop behavior remains unchanged.
*/

.mobile-back-button {
  display: none;
}

/* Give modern mobile browsers a stable full-height application viewport. */
@supports (height: 100dvh) {
  .inbox {
    height: 100dvh;
  }
}

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: #0b141a;
  }

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

  #app,
  .inbox {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .inbox {
    position: relative;
    display: block;
    overflow: hidden;
  }

  /* WhatsApp-style mobile navigation:
     chats list is one screen, conversation is another screen. */
  .sidebar,
  .chat {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-width: 0;
    transition: transform .20s ease;
    will-change: transform;
  }

  .sidebar {
    z-index: 10;
    display: flex;
    flex-direction: column;
    border-right: 0;
    transform: translateX(0);
    background: #111b21;
  }

  .chat {
    z-index: 20;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    transform: translateX(100%);
    pointer-events: none;
    background: #0b141a;
  }

  body.mobile-chat-open .sidebar {
    transform: translateX(-22%);
    pointer-events: none;
  }

  body.mobile-chat-open .chat {
    transform: translateX(0);
    pointer-events: auto;
  }

  .sidebar-header,
  .chat-header {
    box-sizing: border-box;
    min-height: calc(56px + env(safe-area-inset-top));
    height: auto;
    padding-top: env(safe-area-inset-top);
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    flex: 0 0 auto;
  }

  .sidebar-header {
    background: #202c33;
  }

  .brand-name {
    font-size: 20px;
  }

  .sidebar-mode-label {
    font-size: 12px;
  }

  #logoutButton {
    min-height: 34px;
    padding: 7px 11px;
  }

  .archive-view-button {
    flex: 0 0 auto;
    min-height: 48px;
    padding-left: max(13px, env(safe-area-inset-left));
    padding-right: max(13px, env(safe-area-inset-right));
  }

  .contact-list {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .contact-row {
    min-height: 72px;
  }

  .contact-row .contact {
    min-height: 72px;
    padding: 10px 46px 10px max(12px, env(safe-area-inset-left));
    gap: 11px;
  }

  .contact-avatar {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }

  .contact-name {
    font-size: 16px;
  }

  .contact-id {
    display: none;
  }

  .contact-last {
    margin-top: 5px;
    font-size: 13px;
  }

  .contact-actions {
    top: 19px;
    right: max(7px, env(safe-area-inset-right));
  }

  .contact-menu-button {
    width: 34px;
    height: 34px;
    font-size: 24px;
  }

  .contact-menu {
    right: 0;
    top: 36px;
    min-width: 165px;
    z-index: 100;
  }

  .contact-menu button {
    min-height: 44px;
    font-size: 14px;
  }

  .chat-header {
    justify-content: flex-start;
    gap: 9px;
    padding-left: max(5px, env(safe-area-inset-left));
    border-bottom: 1px solid rgba(255,255,255,.05);
  }

  .mobile-back-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 44px;
    flex: 0 0 34px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #e9edef;
    font-size: 38px;
    line-height: 1;
    cursor: pointer;
  }

  .chat-header-avatar {
    width: 40px;
    height: 40px;
    font-size: 15px;
  }

  .chat-header-contact {
    min-width: 0;
    flex: 1;
  }

  .chat-header-contact strong {
    font-size: 16px;
  }

  .chat-header-contact span {
    font-size: 11px;
  }

  .messages {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding:
      10px
      max(9px, env(safe-area-inset-right))
      14px
      max(9px, env(safe-area-inset-left));
    scroll-behavior: smooth;
  }

  .message {
    max-width: 88%;
    margin: 5px 0;
    padding: 8px 9px;
    border-radius: 9px;
    font-size: 15px;
    line-height: 1.32;
  }

  .message.in {
    border-top-left-radius: 4px;
  }

  .message.out {
    border-top-right-radius: 4px;
  }

  .message-language,
  .translation-label {
    font-size: 10px;
  }

  .message-meta {
    font-size: 9px;
    margin-top: 4px;
  }

  .message-reply-button {
    min-height: 28px;
    touch-action: manipulation;
  }

  .composer {
    min-height: 0;
    max-height: 48dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding:
      9px
      max(10px, env(safe-area-inset-right))
      calc(9px + env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
    border-top: 1px solid rgba(255,255,255,.08);
    box-shadow: 0 -2px 8px rgba(0,0,0,.12);
  }

  .composer > label:first-child {
    display: none;
  }

  .composer textarea {
    display: block;
    resize: none;
    min-height: 46px;
    max-height: 110px;
    padding: 11px 12px;
    border-radius: 18px;
    font-size: 16px; /* prevents iOS Safari input zoom */
    line-height: 1.3;
  }

  #replyText {
    height: 50px;
  }

  .composer-actions {
    gap: 7px;
    margin-top: 7px;
  }

  .composer-actions button {
    min-height: 40px;
    padding: 9px 14px;
    border-radius: 18px;
    touch-action: manipulation;
  }

  #translateButton {
    width: 100%;
  }

  .preview {
    margin-top: 9px;
    padding-top: 9px;
  }

  .preview label {
    font-size: 11px;
  }

  .preview small {
    font-size: 10px;
  }

  .preview .composer-actions {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .status {
    min-height: 16px;
    margin-top: 5px;
    font-size: 10px;
  }

  .empty {
    padding: 0 20px;
    margin-top: 28px;
  }

  .login-view {
    min-height: 100vh;
    min-height: 100dvh;
    padding:
      calc(16px + env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      calc(16px + env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }

  .login-card {
    width: 100%;
    max-width: 390px;
  }

  .login-card input {
    font-size: 16px;
  }
}

/* Small iPhones (SE/mini-class widths) */
@media (max-width: 390px) {
  .brand-name {
    font-size: 18px;
  }

  .contact-row,
  .contact-row .contact {
    min-height: 66px;
  }

  .contact-avatar {
    width: 42px;
    height: 42px;
    font-size: 16px;
  }

  .contact-name {
    font-size: 15px;
  }

  .contact-last {
    font-size: 12px;
  }

  .message {
    max-width: 92%;
    font-size: 14px;
  }

  .chat-header-avatar {
    width: 36px;
    height: 36px;
  }

  .composer {
    max-height: 52dvh;
  }

  .composer-actions button {
    padding-left: 11px;
    padding-right: 11px;
  }
}

/* Larger phones in landscape: keep the two-pane desktop behavior
   when there is genuinely enough width. */
@media (min-width: 761px) and (max-width: 950px) {
  .inbox {
    grid-template-columns: 280px 1fr;
  }
}
