/* Responsive Styles for Mobile Devices */

/* Tablet (768px - 1023px) */
@media (max-width: 1023px) {
  :root {
    --sidebar-width: 320px;
  }
  
  .new-chat-btn {
    left: 260px;
  }
}

/* Mobile (< 768px) */
@media (max-width: 767px) {
  :root {
    --sidebar-width: 100vw;
    --header-height: 56px;
  }
  
  /* Auth Screen */
  .auth-screen {
    padding: 16px;
    background: var(--bg-primary);
  }
  
  .auth-container {
    box-shadow: none;
    border-radius: 0;
    max-width: 100%;
  }
  
  .auth-header {
    padding: 30px 20px 16px;
  }
  
  .auth-logo {
    width: 64px;
    height: 64px;
  }
  
  .auth-logo svg {
    width: 32px;
    height: 32px;
  }
  
  .auth-header h1 {
    font-size: 20px;
  }
  
  .auth-form {
    padding: 20px;
  }
  
  /* Messenger Layout */
  .messenger {
    position: relative;
  }
  
  /* Sidebar - Full screen on mobile */
  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100;
    transform: translateX(0);
  }
  
  .sidebar.hidden-mobile {
    transform: translateX(-100%);
  }
  
  .sidebar-header {
    padding: 0 12px;
  }
  
  .search-container {
    padding: 8px;
  }
  
  .chat-item {
    padding: 10px 12px;
  }
  
  .chat-item-avatar img,
  .chat-item-avatar-placeholder {
    width: 48px;
    height: 48px;
  }
  
  /* Chat Area */
  .chat-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 101;
    transform: translateX(100%);
    transition: transform var(--transition-normal);
  }
  
  .chat-area.active {
    transform: translateX(0);
  }
  
  .chat-header {
    padding: 0 12px;
  }
  
  .chat-header-avatar img,
  .chat-header-avatar-placeholder {
    width: 38px;
    height: 38px;
  }
  
  .chat-header-name {
    font-size: 15px;
  }
  
  .chat-header-status {
    font-size: 12px;
  }
  
  /* Back button on mobile */
  .back-btn {
    display: flex !important;
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-full);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    margin-right: 4px;
    transition: all var(--transition-fast);
  }
  
  .back-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }
  
  /* Messages */
  .messages-container {
    padding: 12px;
  }
  
  .message {
    max-width: 85%;
    padding: 8px 10px;
  }
  
  .message-content {
    font-size: 14px;
  }
  
  /* Input */
  .chat-input-container {
    padding: 8px 12px;
  }
  
  .chat-input-wrapper {
    gap: 8px;
  }
  
  .chat-input textarea {
    min-height: 40px;
    padding: 10px 14px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .chat-input-btn {
    width: 36px;
    height: 36px;
  }
  
  .send-btn {
    width: 40px;
    height: 40px;
  }
  
  /* New chat button */
  .new-chat-btn {
    left: auto;
    right: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
  }
  
  /* Modals */
  .modal {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
  }
  
  .modal-header {
    padding: 16px;
  }
  
  .modal-body {
    padding: 16px;
    max-height: calc(100vh - 120px);
  }
  
  /* No chat selected - hide on mobile when sidebar is visible */
  .no-chat-selected {
    display: none;
  }
}

/* Small Mobile (< 375px) */
@media (max-width: 374px) {
  .chat-item-avatar img,
  .chat-item-avatar-placeholder {
    width: 44px;
    height: 44px;
  }
  
  .chat-item-name {
    font-size: 14px;
  }
  
  .chat-item-message {
    font-size: 13px;
  }
  
  .message {
    max-width: 90%;
  }
}

/* Landscape Mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .auth-header {
    padding: 16px 20px 12px;
  }
  
  .auth-logo {
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
  }
  
  .auth-logo svg {
    width: 24px;
    height: 24px;
  }
  
  .auth-form {
    padding: 16px 20px;
  }
  
  .form-group {
    margin-bottom: 12px;
  }
  
  .chat-input-container {
    padding: 6px 12px;
  }
  
  .chat-header {
    height: 50px;
  }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
  .chat-item:hover,
  .search-result-item:hover,
  .contact-item:hover {
    background: transparent;
  }
  
  .chat-item:active,
  .search-result-item:active,
  .contact-item:active {
    background: var(--bg-hover);
  }
  
  /* Increase touch targets */
  .chat-input-btn,
  .chat-header-btn,
  .menu-btn {
    min-width: 44px;
    min-height: 44px;
  }
  
  .auth-tab {
    padding: 12px;
  }
  
  .btn {
    padding: 16px 24px;
    min-height: 48px;
  }
}

/* Safe Area for Notch Phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .sidebar-header,
  .chat-header {
    padding-top: max(0px, env(safe-area-inset-top));
  }
  
  .chat-input-container {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  
  .modal {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Dark mode optimization for OLED */
@media (prefers-color-scheme: dark) {
  [data-theme="dark"] .sidebar,
  [data-theme="dark"] .chat-header,
  [data-theme="dark"] .chat-input-container {
    background: #000000;
  }
  
  [data-theme="dark"] .sidebar-header,
  [data-theme="dark"] .search-container {
    background: #0a0a0a;
  }
}

/* Print styles - hide UI elements */
@media print {
  .sidebar,
  .chat-input-container,
  .chat-header-actions,
  .new-chat-btn {
    display: none !important;
  }
  
  .chat-area {
    width: 100% !important;
  }
  
  .message {
    break-inside: avoid;
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
    --text-primary: #000000;
    --accent-primary: #0066cc;
  }
  
  [data-theme="dark"] {
    --border-color: #ffffff;
    --text-primary: #ffffff;
    --accent-primary: #66b3ff;
  }
  
  .message {
    border: 1px solid var(--border-color);
  }
}
