* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden; /* Let inner containers handle scrolling */
  background: #C0C0C0;
  font-family: Tahoma, Verdana, sans-serif;
  font-size: 12px;
}

/* 🔑 FULL-VIEWPORT LAYOUT (No more floating window) */
.app-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #D4D0C8;
  margin: 0;
  border: none;
  box-shadow: none;
}

.yahoo-header {
  background: linear-gradient(to right, #000080, #0033CC);
  color: #FFF;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.logo { font-size: 16px; }
.nav span { cursor: pointer; text-decoration: underline; margin: 0 4px; }
.nav span:hover { color: #FFCC00; }

.main-layout {
  flex: 1; /* Fills all space between header & footer */
  display: flex;
  overflow: hidden;
  border-top: 2px groove #FFFFFF;
  border-bottom: 2px groove #FFFFFF;
}

.sidebar-left, .sidebar-right {
  width: 180px;
  background: #E0E0E0;
  padding: 6px;
  overflow-y: auto;
  flex-shrink: 0;
  border-right: 2px inset #808080;
}
.sidebar-right { border-right: none; border-left: 2px inset #808080; }

.panel-title {
  background: #000080;
  color: #FFF;
  padding: 4px 8px;
  font-weight: bold;
  font-size: 11px;
  margin-bottom: 6px;
  border: 1px outset #4040A0;
}

#room-list, #user-list { list-style: none; }
#room-list li, #user-list li {
  padding: 4px 6px;
  margin-bottom: 2px;
  cursor: pointer;
  font-size: 11px;
}
#room-list li:hover { background: #D0D0D0; }
#room-list li.active { background: #000080; color: #FFF; font-weight: bold; }
#user-list li { border-bottom: 1px dotted #A0A0A0; }

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #FFF;
  min-width: 0;
}

.chat-header {
  background: #C0C0C0;
  padding: 5px 10px;
  border-bottom: 1px solid #808080;
  font-size: 11px;
  font-weight: bold;
  flex-shrink: 0;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.5;
  background: #FAFAFA;
}

.msg { margin-bottom: 4px; word-wrap: break-word; }
.msg.system { color: #666; font-style: italic; font-size: 11px; }
.msg .time { color: #555; font-size: 10px; margin-right: 5px; }
.msg .user { color: #0000CC; font-weight: bold; cursor: pointer; }
.msg .user:hover { text-decoration: underline; }

.input-area {
  background: #D4D0C8;
  padding: 6px;
  border-top: 2px groove #FFFFFF;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}
.input-area input {
  flex: 1;
  padding: 6px 8px;
  border: 2px inset #A0A0A0;
  font-family: inherit;
  font-size: 13px;
  background: #FFF;
}
.input-area button {
  padding: 6px 16px;
  background: #D4D0C8;
  border: 2px outset #FFFFFF;
  font-family: inherit;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  flex-shrink: 0;
}
.input-area button:active { border-style: inset; }

.emoticon-picker-wrapper {
  position: relative;
  background: #D4D0C8;
  padding: 4px 8px 6px;
  border-top: 1px solid #C0C0C0;
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}
#emoticon-btn { padding: 4px 10px; background: #D4D0C8; border: 2px outset #FFF; font-size: 16px; cursor: pointer; }
#emoticon-btn:active { border-style: inset; }

.emoticon-dropdown { display: none; position: absolute; bottom: 100%; right: 8px; background: #FFF; border: 2px inset #808080; padding: 8px; z-index: 100; max-width: 280px; box-shadow: 2px 2px 8px rgba(0,0,0,0.3); }
.emoticon-dropdown.show { display: block; }
.emoticon-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; max-height: 180px; overflow-y: auto; }
.emoticon-item { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; cursor: pointer; border: 1px solid transparent; }
.emoticon-item:hover { background: #E0E0E0; border: 1px outset #FFF; }
.emoticon-item img { width: 22px; height: 22px; object-fit: contain; }

.typing-indicator { background: #F0F0F0; padding: 3px 10px; font-size: 10px; color: #555; font-style: italic; border-top: 1px solid #C0C0C0; flex-shrink: 0; }

/* 📺 Video Container */
.video-container {
  background: #D4D0C8;
  border: 2px outset #FFFFFF;
  margin: 0;
  flex: 0 0 auto;
  max-height: 40vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.video-header { background: linear-gradient(to right, #000080, #0033CC); color: #FFF; padding: 4px 8px; display: flex; justify-content: space-between; align-items: center; font-size: 11px; font-weight: bold; }
#song-input { flex: 1; margin: 0 4px; padding: 2px 6px; border: 1px inset #A0A0A0; font-size: 10px; background: #FFF; max-width: 150px; }
#close-video { background: #C0C0C0; border: 1px outset #FFF; width: 18px; height: 16px; font-size: 12px; cursor: pointer; font-weight: bold; }
#close-video:active { border-style: inset; }
#jitsi-frame { flex: 1; width: 100%; min-height: 180px; border: none; background: #000; }
.song-marquee { background: #000; color: #00FF00; font-family: 'Courier New', monospace; font-size: 12px; padding: 4px 0; white-space: nowrap; overflow: hidden; }

.status-bar { background: #C0C0C0; padding: 4px 10px; font-size: 10px; display: flex; justify-content: space-between; align-items: center; border-top: 2px groove #FFF; flex-shrink: 0; gap: 10px; }
#status-text { flex: 1; }
#msg-count { white-space: nowrap; }

/* Auth Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-box { background: #C0C0C0; border: 2px outset #FFFFFF; box-shadow: 6px 6px 0 #808080; width: 300px; }
.modal-title { background: linear-gradient(to right, #000080, #0033CC); color: #FFF; padding: 8px 10px; font-weight: bold; font-size: 13px; }
.modal-content { padding: 16px; }
.modal-content input { width: 100%; padding: 8px; margin-bottom: 10px; border: 2px inset #A0A0A0; font-size: 13px; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions button { flex: 1; padding: 8px; background: #D4D0C8; border: 2px outset #FFF; font-weight: bold; cursor: pointer; }
.error-msg { color: #CC0000; font-size: 11px; margin-top: 8px; text-align: center; min-height: 14px; }

/* Misc */
.live-badge { display: inline-block; width: 8px; height: 8px; background: #FF0000; border-radius: 50%; margin-right: 5px; animation: live-blink 1.2s infinite; }
@keyframes live-blink { 0%,100%{opacity:1} 50%{opacity:0.3} }
.user-context-menu { position: fixed; background: #D4D0C8; border: 2px outset #FFF; box-shadow: 2px 2px 0 #808080; padding: 4px; z-index: 1000; font-size: 11px; min-width: 160px; }
.context-item { padding: 6px 10px; cursor: pointer; }
.context-item:hover { background: #000080; color: #FFF; }
.context-divider { height: 1px; background: #808080; margin: 4px 0; border-top: 1px inset #FFF; }
#logout-link:hover { color: #FFCC00; text-decoration: underline; }
#sound-toggle:hover { color: #FFCC00; text-shadow: 1px 1px 0 #000; }
#youtube-live-btn:hover { color: #FFCC00; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: #E0E0E0; }
::-webkit-scrollbar-thumb { background: #A0A0A0; border: 1px outset #FFF; }
::-webkit-scrollbar-thumb:hover { background: #909090; }

/* 📱 MOBILE FIX (Replaces existing 768px media query) */
@media (max-width: 768px) {
  .main-layout {
    flex-direction: column;
    height: 100dvh; /* Uses dynamic viewport height (accounts for address bar) */
  }
  
  /* Sidebars take less space so chat has room */
  .sidebar-left, .sidebar-right {
    width: 100%;
    max-height: 18vh;
    flex-shrink: 0;
    border: none;
    border-bottom: 2px inset #808080;
    padding: 6px;
  }
  .sidebar-right {
    border-top: 2px inset #808080;
    border-bottom: none;
  }
  #room-list, #user-list { display: flex; flex-wrap: wrap; gap: 4px; }
  #room-list li, #user-list li {
    border: 1px outset #808080; border-radius: 3px; margin: 0; padding: 3px 6px;
  }
  
  /* 🔑 CRITICAL: Chat area flex setup */
  .chat-area {
    flex: 1;
    min-height: 0; /* Allows internal scrolling */
    overflow: hidden;
  }
  
  /* 🔑 CRITICAL: Prevent these from ever shrinking */
  .chat-header,
  .typing-indicator,
  .emoticon-picker-wrapper,
  .input-area,
  .video-container {
    flex-shrink: 0 !important;
  }
  
  /* Messages take ALL remaining space, but scroll instead of pushing UI out */
  .messages-container {
    flex: 1 1 auto;
    min-height: 100px; /* Guaranteed minimum chat height */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
  }
  
  /* Input bar stays visible & touch-friendly */
  .input-area {
    flex-wrap: nowrap !important;
    padding: 8px !important;
    gap: 6px !important;
  }
  .input-area input {
    font-size: 16px; /* Prevents iOS zoom */
    min-height: 44px;
    padding: 0 10px;
  }
  .input-area button {
    width: auto !important;
    padding: 0 16px;
    min-height: 44px;
    flex-shrink: 0;
  }
  
  /* Video container scales properly */
  .video-container { max-height: 30vh; }
  #jitsi-frame { min-height: 140px; }
  
  /* Emoticon grid fits mobile width */
  .emoticon-grid { grid-template-columns: repeat(5, 1fr); gap: 3px; }
  .emoticon-item { width: 30px; height: 30px; }
  .emoticon-item img { width: 20px; height: 20px; }
  
  /* Status bar stays compact */
  .status-bar { padding: 6px 8px; font-size: 9px; flex-wrap: wrap; gap: 4px; }
  
  /* Modal fixes */
  .modal-box { width: 92%; max-width: 320px; }
  .modal-content input { font-size: 15px; min-height: 44px; }
  .modal-actions button { min-height: 44px; }
}

/* 🔽 BOTTOM STATUS BAR - Responsive Fix */
.status-bar, .bottom-bar, footer, [class*="status"], [class*="footer"] {
  display: flex !important;
  align-items: center !important;
  flex-wrap: nowrap !important;       /* ✅ Prevents stacking on mobile */
  padding: 8px 12px !important;
  font-size: 0.95rem !important;
  gap: 12px !important;
  background: #f8fafc !important;
  border-top: 1px solid #e2e8f0 !important;
  width: 100% !important;
  box-sizing: border-box !important;
  max-height: 50px !important;        /* ✅ Prevents video cutoff */
  overflow-x: auto !important;        /* ✅ Horizontal scroll if needed */
  -webkit-overflow-scrolling: touch;
}

/* Keep text & buttons from breaking */
.status-bar span, .status-bar div, .status-bar a, .status-bar button {
  white-space: nowrap !important;     /* ✅ Keeps "Connected as..." on one line */
  flex-shrink: 0 !important;          /* ✅ Prevents squishing */
  font-size: inherit !important;
}

/* 📱 MOBILE-ONLY TWEAKS */
@media (max-width: 768px) {
  .status-bar, .bottom-bar, footer, [class*="status"], [class*="footer"] {
    padding: 6px 10px !important;
    font-size: 0.8rem !important;
    gap: 8px !important;
    max-height: 42px !important;
  }
}

/* 🎨 Retro Format Toolbar */
.format-toolbar {
  background: #D4D0C8;
  padding: 4px 6px;
  display: flex;
  gap: 6px;
  align-items: center;
  border-top: 1px solid #C0C0C0;
  border-bottom: 1px groove #FFF;
}
#msg-font-size {
  padding: 2px 4px;
  border: 2px inset #A0A0A0;
  background: #FFF;
  font-size: 11px;
  cursor: pointer;
}
#msg-color-picker { display: flex; gap: 3px; }
.color-swatch {
  width: 16px; height: 16px;
  border: 1px outset #FFFFFF;
  cursor: pointer;
}
.color-swatch.active { border: 2px inset #000000; }
.color-swatch:hover { transform: scale(1.1); }
