/* =====================================
   4. MODULES (Panels, Chat, History)
===================================== */
#panels-wrapper {
  position: fixed;
  top: 85px;
  left: 16px;
  right: 16px;
  z-index: 25;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.panel {
  pointer-events: auto;
  background: var(--bg-color, black);
  border: 1px solid var(--theme-color, white);
  color: var(--theme-color, white);
  font-size: 13px;
  will-change: transform;
}

.panel h3 {
  margin: 0;
  padding: 5px 10px;
  border-bottom: 1px solid var(--theme-color, white);
  font-size: 12px;
  text-transform: uppercase;
  background: var(--bg-color, black);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
}
.panel h3:active { cursor: grabbing; }
.panel h3::after { content: "-"; font-size: 10px; opacity: 0.8; margin-left: auto; }
.panel.collapsed:not(.is-wide) h3::after { content: "+"; }
.panel.has-new h3::before { content: "[!] "; animation: blink 1s infinite; color: var(--theme-color, white); }

.panel > *:not(h3) {
  max-height: 400px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, padding 0.35s ease, border-width 0.35s ease;
}
.panel.collapsed:not(.is-wide) > *:not(h3) {
  max-height: 0 !important;
  opacity: 0 !important;
  pointer-events: none;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-width: 0 !important;
}

/* History */
#history-container { width: 250px; }
#history-list { list-style: none; padding: 10px; margin: 0; overflow-y: auto; height: 170px; }
#history-list li { margin-bottom: 8px; opacity: 0.8; white-space: normal; word-wrap: break-word; line-height: 1.2;  overflow-anchor: none; }
#history-list li::before { content: " · "; }

/* Announcements */
#announcement-container { width: 500px; text-align: center; }
#announcement-text { padding: 12px; line-height: 1.5; font-size: 13px; }

/* Right Panels & Chat */
.expand-btn {
  margin-right: 10px;
  font-size: 11px;
  cursor: pointer;
  color: var(--theme-color, white);
  opacity: 0.7;
  transition: all 0.2s ease;
  user-select: none;
}

.expand-btn:hover {
  opacity: 1;
  background: var(--theme-color, white);
  color: var(--bg-color, black);
}

/* --- ANIMATIONS ET LARGEURS --- */
#right-panels { 
  display: flex; 
  flex-direction: column; 
  gap: 15px; 
  width: auto; /* Remplacé ! */
  min-width: 300px; /* Remplacé ! */
  pointer-events: auto; 
  transition: all 0.3s ease;
}

#chat-container, #hearts-container {
  width: 300px;
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#history-container {
  width: 250px;
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#chat-messages, #hearts-messages {
  transition: height 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#chat-container, #hearts-container, #history-container {
  transition: width 0s !important; 
}

/* height reste instantané (évite un jank au redimensionnement/maximize),
   mais on doit réintégrer les transitions du collapse (.panel > *:not(h3))
   sinon ce shorthand les écrase complètement pour ces mêmes éléments. */
#chat-messages, #hearts-messages, #history-list {
  transition: height 0s, max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, padding 0.35s ease, border-width 0.35s ease !important;
}

.panel.is-wide {
  position: fixed !important;
  top: 70px !important;   
  left: 16px !important;
  right: 16px !important;
  bottom: 50px !important;
  
  width: auto !important;
  height: auto !important;
  z-index: 9995 !important; 
  
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
  /* La position/taille bascule instantanément (static -> fixed n'est pas
     interpolable en CSS), ce petit "pop" scale+fade adoucit la transition. */
  animation: panel-maximize 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
/* #panels-wrapper is `position: fixed` with its own z-index (25), which
   creates a stacking context — so a maximized panel's z-index:9995 above
   only outranks its siblings *inside* that context, and is still capped at
   25 against #top-actions (z-index 40). On mobile #top-actions sits right
   on top of the panel's header, trapping the collapse/expand controls
   underneath the SCHEDULE/ARCHIVE/ABOUT row. Same fix as
   #channel-selector.is-open below: bump the wrapper itself, only while a
   panel is actually maximized, just above #top-actions/#channel-selector
   (max 45) but still under the trackbar (9999+) so playback stays usable. */
#panels-wrapper:has(.panel.is-wide) { z-index: 100; }
@keyframes panel-maximize {
  from { opacity: 0.5; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .panel.is-wide { animation: none; }
}
.panel.is-wide > *:not(h3) {
  max-height: none !important;
}

.panel.is-wide #chat-messages,
.panel.is-wide #hearts-messages,
.panel.is-wide #history-list {
  height: 100% !important;
  flex-grow: 1;
  overflow-y: auto;
  max-height: none;
}

/* Date des messages/cœurs : cachée en taille normale pour ne pas encombrer,
   affichée seulement quand le panel est maximisé (utile en remontant l'historique). */
.msg-date { display: none; }
.panel.is-wide .msg-date { display: inline; }

#chat-container.collapsed { height: auto; }
#chat-messages { height: 200px; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 5px; overflow-anchor: none; }
#chat-inputs { display: flex; border-top: 1px solid var(--theme-color, white); }
#chat-inputs input { background: transparent; color: var(--theme-color, white); border: none; padding: 8px; outline: none; }
#chat-username { width: 30%; border-right: 1px solid var(--theme-color, white); }
#chat-input { flex-grow: 1; min-width: 0; }

#hearts-messages { height: 100px; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 5px; border-bottom: 1px solid var(--theme-color, white); color: var(--theme-color, white); z-index: 5; overflow-anchor: none; }
#hearts-messages div { white-space: normal; word-break: break-word; line-height: 1.4; padding-bottom: 4px; }

#chat-send { background: transparent; color: var(--theme-color, white); border: none; border-left: 1px solid var(--theme-color, white); cursor: pointer; font-weight: bold; transition: all 0.2s ease; }
#chat-send { width: 10%; }
#chat-send:hover { background: var(--theme-color, white); color: #000; }

/* Pas d'espace dans beaucoup de kaomojis (ex: (ﾉ≧∀≦)ﾉ‥…━━━★) : sans ça une ligne
   trop longue déborderait du panel au lieu de passer à la ligne. */
#chat-messages div { overflow-wrap: anywhere; }

#chat-kaomoji {
  background: transparent; color: var(--theme-color, white);
  border: none; border-left: 1px solid var(--theme-color, white);
  padding: 0 8px; cursor: pointer; font-weight: bold; white-space: nowrap;
  transition: all 0.2s ease;
}
#chat-kaomoji:hover, #chat-kaomoji.is-active { background: var(--theme-color, white); color: var(--bg-color, black); }

/* Kaomoji picker : rangées de cases à largeur variable (un kaomoji peut faire 3 comme
   30 caractères). flex-grow étire chaque rangée jusqu'aux bords pour garder l'aspect
   d'une grille ; un kaomoji plus large que le panel passe à la ligne dans sa case.
   La hauteur max est sur #kaomoji-grid et pas sur #kaomoji-picker, car les règles
   .panel > *:not(h3) (collapse / maximize) écrasent le max-height des enfants directs. */
#kaomoji-picker { border-top: 1px solid var(--theme-color, white); }
#kaomoji-grid {
  display: flex; flex-wrap: wrap; gap: 4px;
  max-height: 150px; overflow-y: auto; padding: 6px;
  overscroll-behavior: contain;
}
.kaomoji-item {
  flex: 1 1 auto; min-width: 0; max-width: 100%;
  background: transparent; color: var(--theme-color, white);
  border: 1px solid color-mix(in srgb, var(--theme-color, white) 35%, transparent);
  padding: 5px 7px; font-size: 13px; line-height: 1.3; cursor: pointer;
  white-space: pre-wrap; overflow-wrap: anywhere; text-align: center;
}
.kaomoji-item:hover, .kaomoji-item:focus-visible {
  background: var(--theme-color, white); color: var(--bg-color, black);
  border-color: var(--theme-color, white); outline: none;
}
.panel.is-wide #kaomoji-grid { max-height: 30vh; }
/* En mode maximisé le panel est une colonne flex où #chat-messages réclame height: 100% :
   sans ça le picker (overflow: hidden, donc rétrécissable à 0) était écrasé et coupait le
   bas de la grille, qui elle ne défilait pas puisqu'elle se croyait entière. */
.panel.is-wide #kaomoji-picker, .panel.is-wide #chat-inputs { flex-shrink: 0; }

