/* =========================================================
   1. GLOBAL STYLES, WINDOW ANCHORS & RESETS
   ========================================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100vh !important;
  max-height: 100vh !important;
  width: 100vw !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important; 
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #0b0c10;
  color: #e5e7eb;
  display: flex !important;
  flex-direction: column !important;
}

/* =========================================================
   2. LANDING / LOGIN SCREEN OVERLAY 
   ========================================================= */
#auth-modal {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: url('background.jpg') no-repeat center center fixed;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 5vh;
  z-index: 99999;
}

.modal-content {
  background: rgba(18, 18, 24, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 24px 28px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.85);
  width: 90%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-content h3 {
  font-size: 18px;
  font-weight: 700;
  color: #f3f4f6;
}

.modal-content input {
  background: #1f222e;
  border: 1px solid #374151;
  color: #fff;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

.modal-content input:focus {
  border-color: #a855f7;
}

/* =========================================================
   3. HEADER & MAIN PAGE FLEX CONTAINER 
   ========================================================= */
header {
  height: 45px;
  padding: 10px 18px;
  background-color: #12141c;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

header h2 {
  font-size: 18px;
  font-weight: 700;
  color: #f3f4f6;
  line-height: 25px;
}

#main-container {
  display: flex !important;
  flex-direction: row !important;
  flex: 1 !important;
  height: calc(100vh - 45px) !important;
  width: 100vw !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

/* Video Wrapper (Elastic Flex Layout) */
#video-wrapper {
  flex: 1 1 auto !important;
  background-color: #000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  min-width: 0;
  height: 100% !important;
  overflow: hidden;
  transition: width 0.2s ease-in-out;
}

#videoElement {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #000;
}

/* =========================================================
   4. CHAT SIDEBAR & MESSAGES CONTAINER
   ========================================================= */
#chat-panel {
  width: 340px !important;
  max-width: 340px !important;
  min-width: 340px !important;
  background-color: #0f1117;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  flex-shrink: 0 !important;
  position: relative !important; /* Establishes coordinate workspace containment */
}

.chat-header {
  padding: 10px 14px;
  background-color: #161822;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 600;
  font-size: 13px;
  color: #e5e7eb;
  flex-shrink: 0;
}

#chat-messages {
  flex: 1 1 0% !important;
  min-height: 0 !important;
  padding: 12px 14px;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.chat-entry {
  font-size: 13px;
  line-height: 1.45;
  width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-entry .time {
  font-size: 11px;
  color: #6b7280;
  margin-right: 6px;
}

.chat-entry .author {
  margin-right: 6px;
  font-weight: 700;
}

.chat-entry .text {
  color: #e5e7eb;
}

.chat-entry a.chat-link {
  color: #60a5fa !important;
  text-decoration: underline !important;
}

.system-entry {
  font-size: 11px;
  color: #9ca3af;
  font-style: italic;
}

.chat-entry .chat-media {
  display: block;
  max-width: 100%;
  max-height: 200px;
  border-radius: 6px;
  margin-top: 6px;
  object-fit: cover;
}

/* =========================================================
   5. PREVIEWS & GIPHY SEARCH MODAL
   ========================================================= */
.chat-link-preview {
  display: flex;
  flex-direction: column;
  background: #181a20;
  border-left: 3px solid #a855f7;
  border-radius: 6px;
  overflow: hidden;
  margin-top: 6px;
  width: 100%;
}

.chat-link-preview .preview-img {
  width: 100%;
  max-height: 140px;
  object-fit: cover;
}

.chat-link-preview .preview-content {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-link-preview .preview-title {
  font-size: 12px;
  font-weight: bold;
  color: #60a5fa;
}

#giphy-modal {
  position: absolute !important; 
  bottom: 80px !important;   
  left: 14px !important;     
  right: 14px !important;
  width: auto !important;     
  background: #181920;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 99999 !important;
  max-height: 280px;
  box-sizing: border-box;
}

#giphy-search-input {
  width: 100%;
  background: #252836;
  border: 1px solid #3b3f54;
  color: #fff;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

#giphy-results {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 6px;
  overflow-y: auto;
  max-height: 220px;
}

#giphy-results img {
  width: 100%;
  height: 85px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
}

/* =========================================================
   6. CHAT FOOTER ACTIONS DOCK
   ========================================================= */
.chat-footer {
  margin-top: auto !important;  
  flex-shrink: 0 !important;    
  padding: 14px 14px 20px 14px;  
  background-color: #12141c;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.name-row,
.msg-row {
  display: flex;
  gap: 6px;
  align-items: center;
  width: 100%;
}

.name-row input,
.msg-row input {
  flex: 1;
  background: #1c1f2b;
  border: 1px solid #323749;
  color: #fff;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.name-row input:focus,
.msg-row input:focus {
  border-color: #a855f7;
}

.btn {
  background: #9333ea;
  color: #fff;
  border: none;
  padding: 9px 15px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.gif-btn {
  background: #374151;
  color: #f3f4f6;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 9px 12px;
  border-radius: 6px;
  font-weight: bold;
  font-size: 11px;
  cursor: pointer;
}

/* =========================================================
   7. SEAMLESS POPOUT STYLING SPECIFICS & MOBILE VIEWPORTS
   ========================================================= */
body.popout-window {
  display: flex !important;
  justify-content: center !important;
  align-items: stretch !important;
  height: 100vh !important;
  width: 100vw !important;
  background-color: #0b0c10 !important;
}

body.popout-window #main-container {
  height: 100vh !important;
  width: 100vw !important;
}

body.popout-window #video-wrapper {
  display: none !important; 
}

body.popout-window #chat-panel {
  position: relative !important; 
  width: 100vw !important;
  max-width: 100vw !important;
  min-width: 100vw !important;
  height: 100vh !important;
  border-left: none !important;
  inset: unset !important;
}

@media (max-width: 768px) {
  #main-container {
    flex-direction: column !important;
  }
  #video-wrapper {
    width: 100% !important;
    height: 38vh !important;
  }
  #chat-panel {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 100% !important;
    height: calc(62vh - 45px) !important;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    position: relative !important;
  }
  #giphy-modal {
    bottom: 100px !important;
  }
}
/* Explicit structural rules to prevent document rendering hangs */
body.popout-window #main-container {
  height: 100vh !important;
  width: 100vw !important;
}

body.popout-window #chat-panel {
  display: flex !important;
  position: relative !important;
  width: 100vw !important;
  max-width: 100vw !important;
  min-width: 100vw !important;
  height: 100vh !important;
  border-left: none !important;
  inset: unset !important;
}

/* Direct layout structure overrides when popout mode triggers state classes */
body.hide-sidebar-layout #chat-panel {
  display: none !important;
}

body.hide-sidebar-layout #video-wrapper {
  width: 100% !important;
  flex: 1 1 auto !important;
}

/* Force the panel layout state selector to override the default ID layout definitions */
body.hide-sidebar-layout #chat-panel,
body #chat-panel[style*="display: none"] {
  display: none !important;
}

body.hide-sidebar-layout #video-wrapper,
body #chat-panel[style*="display: none"] ~ #video-wrapper {
  width: 100% !important;
  flex: 1 1 auto !important;
}

/* Force structural elimination of the chat panel over any other flex declarations */
body #chat-panel[style*="none"] {
  display: none !important;
}

/* Force video player box framework to span full viewport context when chat panel disappears */
body #chat-panel[style*="none"] ~ #video-wrapper,
body #chat-panel[style*="none"] + #video-wrapper {
  width: 100% !important;
  flex: 1 1 auto !important;
}

/* =========================================================
   8. POPOUT WINDOW ELEMENT RECONSTRUCTION OVERRIDES
   ========================================================= */
body.popout-window {
  display: flex !important;
  flex-direction: column !important;
  height: 100vh !important;
  width: 100vw !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
}

body.popout-window #chat-panel {
  display: flex !important;
  flex-direction: column !important;
  height: 100vh !important;
  width: 100vw !important;
  max-width: 100vw !important;
  min-width: 100vw !important;
  border-left: none !important;
  position: relative !important;
}

body.popout-window #chat-messages {
  flex: 1 1 auto !important; /* Forces messages container to expand to maximum height */
  height: calc(100vh - 150px) !important; /* Failsafe height bounds fallback */
  overflow-y: auto !important;
}

body.popout-window .chat-footer {
  margin-top: auto !important;
  padding-bottom: 20px !important;
}

/* =========================================================
   8. POPOUT WINDOW ELEMENT RECONSTRUCTION OVERRIDES
   ========================================================= */
body.popout-window,
body[style*="chat.html"],
html:has(iframe[src*="chat.html"]) body {
  display: flex !important;
  flex-direction: column !important;
  height: 100vh !important;
  width: 100vw !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* Force the panel to fill the entire popup window viewport */
body.popout-window #chat-panel,
body[style*="chat.html"] #chat-panel,
window-sidebar #chat-panel,
html #chat-panel:only-child {
  display: flex !important;
  flex-direction: column !important;
  height: 100vh !important;
  width: 100vw !important;
  max-width: 100vw !important;
  min-width: 100vw !important;
  border-left: none !important;
  position: fixed !important;
  inset: 0 !important;
}

/* Force messages area to grow and take up all available vertical space */
body.popout-window #chat-messages,
html #chat-panel:only-child #chat-messages {
  flex: 1 1 auto !important;
  display: flex !important;
  flex-direction: column !important;
  height: calc(100vh - 140px) !important; /* Forces the text view to expand above footer */
  overflow-y: auto !important;
}

/* Push the controls container tightly against the bottom edge */
body.popout-window .chat-footer,
html #chat-panel:only-child .chat-footer {
  margin-top: auto !important;
  padding-bottom: 24px !important;
}

/* Unclamps the panel width boundaries inside the popout standalone canvas view context */
body.popout-window #chat-panel {
  max-width: 100vw !important;
  width: 100vw !important;
  height: 100vh !important;
}
