/* =========================================================
   Universal Responsive Design: Mobile, Tablet & Desktop
   Adapts to:
   - Mobile: 320px - 767px (iPhone, Android)
   - Tablet: 768px - 1024px (iPad, Android Tablets)
   - Laptop / Desktop: 1025px+ (MacBook, PC, 4K displays)
   ========================================================= */

/* Mobile Back Button (Hidden by default on Desktop) */
.mobile-back-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--palette-accent-blue, #007aff);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  margin-right: 6px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: opacity 0.15s ease;
}

.mobile-back-btn:active {
  opacity: 0.55;
  background: transparent;
}

.mobile-back-text {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.2px;
  color: var(--palette-accent-blue, #007aff);
  margin-left: 2px;
}

/* =========================================================
   Mobile Optimization (< 768px)
   ========================================================= */
@media screen and (max-width: 767px) {
  /* Main Container Layout */
  .main-wrapper {
    position: relative;
    width: 100vw;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    overflow: hidden;
  }

  /* Full screen Sidebar when viewing list */
  .sidebar {
    width: 100vw !important;
    min-width: 100vw !important;
    max-width: 100vw !important;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 20;
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.32s ease, filter 0.32s ease;
  }

  /* Full screen Chat Stage */
  .chat-stage {
    width: 100vw !important;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    transform: translateX(100%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  }

  /* When a chat is active on mobile, slide in chat stage & slide out sidebar with Telegram iOS parallax */
  .main-wrapper.in-chat .sidebar {
    transform: translateX(-28%);
    opacity: 0.92;
    filter: brightness(0.95);
    pointer-events: none;
  }

  .main-wrapper.in-chat .chat-stage {
    transform: translateX(0);
    z-index: 30;
    box-shadow: -8px 0 25px rgba(0, 0, 0, 0.35);
  }

  /* Show mobile back button in chat header */
  .mobile-back-btn {
    display: flex !important;
  }

  /* Adjust chat header on small screens */
  .chat-header {
    padding: 10px 14px;
  }

  .chat-header-title {
    font-size: 15px;
    max-width: 130px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-header-actions .btn-call span {
    display: none; /* Icon only on mobile */
  }

  .chat-header-actions .btn-call {
    padding: 8px;
    border-radius: 50%;
  }

  /* Message bubbles on mobile */
  .msg-row {
    max-width: 92% !important;
  }

  .msg-bubble {
    padding: 10px 13px;
    font-size: 14px;
  }

  .msg-bubble img.msg-image {
    max-width: 240px;
    max-height: 240px;
  }

  .file-bubble-card {
    max-width: 260px;
  }

  /* Touch-friendly input footer */
  .chat-footer {
    padding: 8px 12px 14px;
  }

  .input-row textarea {
    font-size: 16px; /* Prevents iOS auto-zoom on inputs */
  }

  /* Modals on mobile */
  .modal-card {
    width: 94vw !important;
    max-width: 94vw !important;
    padding: 20px 16px !important;
    border-radius: 16px;
  }

  /* Active Call Overlay on mobile */
  .call-control-bar {
    padding: 0 16px;
    height: 76px;
  }

  .local-pip-container {
    width: 110px;
    height: 160px;
    bottom: 90px;
    right: 14px;
  }

  /* Emoji Popover on mobile */
  .emoji-popover {
    left: 10px !important;
    right: 10px !important;
    max-width: calc(100vw - 20px) !important;
    bottom: 70px !important;
  }
}

/* =========================================================
   Tablet Optimization (768px - 1024px)
   ========================================================= */
@media screen and (min-width: 768px) and (max-width: 1024px) {
  .sidebar {
    width: 320px;
    min-width: 300px;
  }

  .chat-header-title {
    font-size: 15px;
  }

  .msg-row {
    max-width: 85%;
  }

  .local-pip-container {
    width: 160px;
    height: 110px;
  }
}

/* =========================================================
   Desktop & Wide Screens (1025px+)
   ========================================================= */
@media screen and (min-width: 1025px) {
  .sidebar {
    width: 380px;
  }

  .msg-row {
    max-width: 75%;
  }

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

  /* Smooth scrollbars */
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
  }
}
