/* GoonWall v5 - Mobile Responsive Styles */

/* Android navigation bar and viewport fixes */
@supports (height: 100dvh) {
  body {
    height: 100dvh !important;
  }
}

/* Fallback for browsers that don't support dvh */
@supports not (height: 100dvh) {
  body {
    height: calc(100vh - env(safe-area-inset-bottom)) !important;
  }
}

/* Mobile breakpoints */
@media screen and (max-width: 768px) {
  
  /* --- Body & Layout Overrides --- */
  body {
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height */
    overflow: hidden;
    /* Ensure proper handling of Android navigation bar */
    min-height: -webkit-fill-available;
  }
  
  /* Additional Android navigation bar fix */
  html {
    height: -webkit-fill-available;
  }

  .main-container {
    flex-direction: column;
    padding: 5px;
    gap: 5px;
    height: 100%;
    overflow: hidden;
  }

  /* --- Video Section (Top) --- */
  .video-section {
    flex: 1;
    order: 1;
    min-height: 0; /* Allow flex shrinking */
  }

  .video-wall {
    grid-template-columns: 1fr; /* Single column on mobile */
    gap: 5px;
    padding: 5px;
    height: 100%;
    overflow-y: auto;
  }

  .video-player {
    aspect-ratio: 16/9; /* Maintain video aspect ratio */
    min-height: 200px;
  }

  /* --- Video Controls Mobile Optimization --- */
  .video-player button {
    opacity: 1; /* Always visible on mobile */
    font-size: 14px;
    padding: 10px 15px;
  }

  .mute-button {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .vote-skip-button {
    padding: 8px 12px;
    font-size: 11px;
  }

  /* --- Side Panel (Bottom) --- */
  .side-panel {
    flex: 0 0 45vh; /* Fixed height - 45% of viewport */
    order: 2;
    min-width: unset;
    max-width: unset;
    width: 100%;
    min-height: 280px; /* Ensure minimum height for chat and scrolling */
    max-height: 45vh; /* Prevent overflow */
    display: flex;
    flex-direction: column;
  }

  /* --- Tab Container Mobile --- */
  .tab-container {
    height: 100%;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .tab-header {
    flex-shrink: 0;
  }

  .tab-button {
    padding: 12px 8px;
    font-size: 11px;
    letter-spacing: 0.3px;
  }

  .tab-button.settings-tab {
    flex: 0 1 50px;
    font-size: 14px;
  }

  .tab-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
  }

  .tab-panel {
    position: static; /* Override absolute positioning */
    padding: 10px;
    gap: 10px;
    height: 100%; /* Full height of container */
    flex-direction: column;
    display: none; /* Hide inactive tabs */
    overflow: hidden; /* Prevent panel overflow */
  }
  
  .tab-panel.active {
    display: flex; /* Only active tabs are flex */
  }

  /* --- Chat Mobile Optimization --- */
  #chat-tab.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }

  #chat-messages {
    flex: 1;
    min-height: 0;
    gap: 6px;
    padding: 6px;
    font-size: 13px;
    overflow-y: auto;
  }

  .chat-message {
    padding: 6px 8px;
    border-radius: 6px;
  }

  .chat-message .username {
    font-size: 12px;
  }

  .chat-message .text {
    font-size: 13px;
    line-height: 1.3;
  }

  /* Role badges mobile */
  .role-badge {
    font-size: 9px;
    padding: 1px 4px;
  }

  /* Delete button mobile */
  .delete-btn {
    opacity: 1; /* Always visible on mobile */
    font-size: 14px;
    padding: 4px 8px;
  }

  /* GIF containers mobile */
  .gif-container img, 
  .gif-container video {
    max-height: 150px;
  }

  #chat-form {
    gap: 6px;
    margin-top: 6px;
    flex-shrink: 0; /* Never shrink the input form */
    background-color: var(--surface-color);
    padding: 8px 0;
    border-top: 1px solid var(--border-color);
  }

  #chat-input {
    padding: 10px;
    font-size: 14px;
    border-radius: 6px;
  }

  #chat-form button {
    padding: 10px 16px;
    font-size: 11px;
    border-radius: 6px;
  }

  /* --- Users Tab Mobile --- */
  .users-stats {
    gap: 8px;
    margin-bottom: 10px;
    flex-shrink: 0; /* Prevent stats from shrinking */
  }

  .stat-item {
    padding: 12px;
    border-radius: 6px;
  }

  .stat-item span {
    font-size: 24px;
  }

  .stat-item label {
    font-size: 10px;
  }

  #users-list {
    padding: 6px;
    border-radius: 6px;
    flex: 1; /* Take remaining space */
    min-height: 0; /* Allow flex shrinking */
    overflow-y: auto; /* Enable scrolling */
  }

  .user-item {
    padding: 8px 10px;
    border-radius: 6px;
    margin-bottom: 3px;
  }

  .user-name {
    font-size: 13px;
  }

  .user-role {
    font-size: 9px;
    padding: 1px 4px;
  }

  /* --- Settings Tab Mobile --- */
  #users-tab.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
  }
  
  #settings-tab.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
  }
  
  .settings-content {
    gap: 15px;
    padding: 6px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  .premium-section {
    gap: 12px;
  }

  .premium-button {
    padding: 15px;
    font-size: 14px;
    border-radius: 8px;
  }

  .premium-info {
    font-size: 12px;
    padding: 10px;
    border-radius: 6px;
  }

  .discord-link {
    padding: 12px 20px;
    font-size: 14px;
    gap: 10px;
  }

  .discord-icon {
    width: 20px;
    height: 20px;
  }

  .premium-perks {
    border-radius: 6px;
  }

  .perks-header {
    padding: 10px 12px;
  }

  .perks-content {
    padding: 12px;
  }

  .perk-item {
    padding: 6px 0;
    padding-left: 18px;
  }

  #qr-code-container {
    padding: 12px;
    border-radius: 8px;
    min-height: 120px;
  }

  /* --- Scrollbar Mobile Optimization --- */
  #chat-messages::-webkit-scrollbar,
  #users-list::-webkit-scrollbar,
  .settings-content::-webkit-scrollbar,
  .tab-panel::-webkit-scrollbar,
  .video-wall::-webkit-scrollbar {
    width: 4px;
  }

  #chat-messages::-webkit-scrollbar-thumb,
  #users-list::-webkit-scrollbar-thumb,
  .settings-content::-webkit-scrollbar-thumb,
  .tab-panel::-webkit-scrollbar-thumb,
  .video-wall::-webkit-scrollbar-thumb {
    border-radius: 2px;
  }
}

/* Smaller mobile devices */
@media screen and (max-width: 480px) {
  
  /* Android navigation bar handling for small devices */
  body {
    height: 100vh;
    height: 100dvh;
    min-height: -webkit-fill-available;
  }
  
  html {
    height: -webkit-fill-available;
  }
  
  .main-container {
    padding: 3px;
    gap: 3px;
  }

  .video-wall {
    padding: 3px;
    gap: 3px;
  }

  .video-player {
    min-height: 180px;
  }

  .side-panel {
    flex: 0 0 50vh; /* Larger on small screens for better chat visibility */
    min-height: 300px; /* Ensure minimum height for chat */
    max-height: 50vh; /* Prevent overflow */
    display: flex;
    flex-direction: column;
  }

  .tab-button {
    padding: 10px 6px;
    font-size: 10px;
  }

  .tab-button.settings-tab {
    flex: 0 1 45px;
    font-size: 12px;
  }

  .tab-panel {
    position: static; /* Override absolute positioning */
    padding: 8px;
    gap: 8px;
    height: 100%; /* Full height of container */
    flex-direction: column;
    display: none; /* Hide inactive tabs */
    overflow: hidden; /* Prevent panel overflow */
  }
  
  .tab-panel.active {
    display: flex; /* Only active tabs are flex */
  }

  #chat-messages {
    padding: 5px;
    gap: 5px;
  }

  .chat-message {
    padding: 5px 6px;
  }

  .chat-message .username {
    font-size: 11px;
  }

  .chat-message .text {
    font-size: 12px;
  }

  #chat-input {
    padding: 8px;
    font-size: 13px;
  }

  #chat-form button {
    padding: 8px 12px;
    font-size: 10px;
  }

  .gif-container img, 
  .gif-container video {
    max-height: 120px;
  }

  .stat-item {
    padding: 10px;
  }

  .stat-item span {
    font-size: 20px;
  }
  
  /* Specific tab layout for small mobile */
  #users-tab.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
  }
  
  #settings-tab.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
  }
  
  .settings-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  .premium-button {
    padding: 12px;
    font-size: 13px;
  }

  .premium-info {
    font-size: 11px;
    padding: 8px;
  }

  .discord-link {
    padding: 10px 16px;
    font-size: 13px;
    gap: 8px;
  }

  .discord-icon {
    width: 18px;
    height: 18px;
  }
}

/* Landscape mobile orientation */
@media screen and (max-width: 768px) and (orientation: landscape) {
  
  .side-panel {
    flex: 0 0 40vh; /* Smaller sidebar in landscape but still usable */
    min-height: 220px; /* Ensure minimum height for chat */
  }

  .video-player {
    min-height: 150px;
  }

  .tab-button {
    padding: 8px 6px;
  }

  .tab-panel {
    position: static; /* Override absolute positioning */
    padding: 8px;
    height: auto; /* Let flex handle height */
    flex-direction: column;
    display: none; /* Hide inactive tabs */
  }
  
  .tab-panel.active {
    display: flex; /* Only active tabs are flex */
  }

  #chat-messages {
    font-size: 12px;
  }

  .gif-container img, 
  .gif-container video {
    max-height: 100px;
  }
}
