/* ════════════════════════════════════════════════════════════════════════
   Phase 8 — Polish global (messagerie, controls flottants, animations)
   Loaded AFTER style/gamified/grimoire so all overrides take precedence.
   ════════════════════════════════════════════════════════════════════════ */

/* ── 1. Lucide icon polish (.lic) ─────────────────────────────────────── */
.lic, [data-lucide].lic {
  display: inline-block;
  width: 1em; height: 1em;
  vertical-align: -0.18em;
  stroke-width: 1.7;
  color: currentColor;
  flex-shrink: 0;
}
.lic svg, [data-lucide].lic > svg {
  width: 100%; height: 100%;
  stroke: currentColor;
  stroke-width: 1.7;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
button .lic, a .lic { margin-right: 0.4em; }
.btn-grim .lic, .btn-primary .lic, .btn-secondary .lic { color: var(--gold-glow, #c9a84c); }
h1 .lic, h2 .lic, h3 .lic { color: var(--gold-glow, #c9a84c); margin-right: 0.45em; }

/* ── 2. Floating controls bottom-left (theme/audio/particles/ambient) ── */
.floating-controls,
#floating-controls,
.fixed-controls {
  position: fixed;
  bottom: 18px;
  left: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 90;
}
.floating-controls button,
#floating-controls button,
.fixed-controls button,
.theme-toggle-btn,
.particles-toggle-btn,
.audio-toggle-btn,
.ambient-toggle-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(160deg, rgba(20,14,11,0.8), rgba(8,6,8,0.85));
  border: 1px solid rgba(201,168,76,0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--gold-glow, #c9a84c);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  box-shadow:
    0 4px 14px rgba(0,0,0,0.55),
    inset 0 1px 0 rgba(255,255,255,0.08);
  transition: transform 0.2s cubic-bezier(.2,.8,.2,1), box-shadow 0.25s, background 0.2s;
  position: relative;
}
.floating-controls button:hover,
#floating-controls button:hover,
.fixed-controls button:hover {
  transform: scale(1.08) translateY(-2px);
  background: linear-gradient(160deg, rgba(40,28,18,0.9), rgba(20,12,16,0.92));
  box-shadow:
    0 6px 22px rgba(0,0,0,0.6),
    0 0 22px rgba(201,168,76,0.45),
    inset 0 1px 0 rgba(255,255,255,0.12);
  color: #f0d77a;
}

/* ── 3. Messagerie — popup redesign ──────────────────────────────────── */
#msg-btn {
  position: fixed;
  bottom: 18px;
  right: 92px;  /* leave room for chatbot bubble at right:18px */
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(160deg, #6b2840 0%, #2a1018 100%);
  border: 2px solid var(--gold-glow, #c9a84c);
  display: flex;
  align-items: center; justify-content: center;
  color: #f0d77a;
  cursor: pointer;
  font-size: 1.3rem;
  z-index: 95;
  box-shadow:
    0 6px 22px rgba(0,0,0,0.65),
    0 0 24px rgba(107,40,64,0.45);
  transition: transform 0.25s, box-shadow 0.3s;
}
#msg-btn:hover {
  transform: scale(1.08);
  box-shadow:
    0 8px 28px rgba(0,0,0,0.75),
    0 0 32px rgba(201,168,76,0.65);
}
#msg-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: #c92e2e;
  color: #fff;
  border-radius: 12px;
  min-width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0 5px;
  font-family: 'Cinzel', serif;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.2);
}

#msg-popup {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: min(820px, calc(100vw - 40px));
  height: min(640px, calc(100vh - 120px));
  background:
    linear-gradient(180deg, rgba(15, 9, 11, 0.96) 0%, rgba(8, 5, 8, 0.96) 100%),
    url("/static/images/grimoire/messages_owl.jpg") center/cover no-repeat;
  background-blend-mode: multiply, normal;
  border: 1.5px solid var(--gold-glow, #c9a84c);
  border-radius: 12px;
  z-index: 200;
  display: flex !important;
  overflow: hidden;
  box-shadow:
    0 30px 80px rgba(0,0,0,0.85),
    0 0 60px rgba(201,168,76,0.25),
    inset 0 0 0 1px rgba(240,215,122,0.15);
}
#msg-popup[style*="display:none"],
#msg-popup[style*="display: none"] {
  display: none !important;
}

#msg-close {
  position: absolute;
  top: 10px; right: 14px;
  width: 32px; height: 32px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(201,168,76,0.4);
  color: var(--gold-glow, #c9a84c);
  border-radius: 50%;
  cursor: pointer;
  z-index: 5;
  font-family: 'Cinzel', serif;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
#msg-close:hover {
  background: rgba(201,168,76,0.2);
  color: #fff;
  transform: rotate(90deg);
}

#msg-friends-col {
  width: 80px;
  min-width: 80px;
  max-width: 80px;
  border-right: 1px solid rgba(201,168,76,0.25);
  display: flex; flex-direction: column;
  background: rgba(10, 6, 9, 0.65);
  overflow: hidden;
}
#msg-friends-header {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(201,168,76,0.2);
  background: linear-gradient(180deg, rgba(0,0,0,0.55), transparent);
  letter-spacing: 2px;
}
#msg-friends-col #msg-friends-header span { display: none; }
#msg-friends-col .msg-friend-info { display: none; }
#msg-friends-col .msg-friend-item { justify-content: center; padding: 0.5rem !important; }
#msg-friends-col .msg-unread-badge { position: absolute; top: 2px; right: 2px; }
#msg-friends-col .msg-friend-item { position: relative; }
#msg-friends-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0;
}
#msg-friends-list .friend-item,
#msg-friends-list > div[onclick] {
  display: flex !important;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 1rem !important;
  cursor: pointer;
  border-bottom: 1px solid rgba(201,168,76,0.08);
  transition: all 0.18s;
  background: transparent;
}
#msg-friends-list .friend-item:hover,
#msg-friends-list > div[onclick]:hover,
#msg-friends-list .friend-item.active {
  background: rgba(201,168,76,0.12);
  border-left: 3px solid var(--gold-glow, #c9a84c);
  padding-left: calc(1rem - 3px) !important;
}

#msg-conv-col {
  flex: 1;
  display: flex; flex-direction: column;
  min-width: 0;
}
#msg-conv-header {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(201,168,76,0.2);
  background: linear-gradient(180deg, rgba(0,0,0,0.55), transparent);
  font-family: 'Cinzel', serif;
  letter-spacing: 1px;
}
#msg-conv-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* Modern speech bubbles */
#msg-conv-messages > div {
  max-width: 75%;
  padding: 0.6rem 0.95rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.4;
  font-family: 'Raleway', sans-serif;
  position: relative;
  word-wrap: break-word;
  animation: msg-pop-in 0.25s cubic-bezier(.2,.85,.3,1.05);
}
@keyframes msg-pop-in {
  from { opacity: 0; transform: translateY(6px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Outgoing (mine) — gold tint, right-aligned */
#msg-conv-messages > div.msg-mine,
#msg-conv-messages > div[data-mine="1"] {
  align-self: flex-end;
  background: linear-gradient(160deg, rgba(201,168,76,0.25), rgba(140,110,40,0.18));
  border: 1px solid rgba(201,168,76,0.35);
  color: #f5e8c8;
  border-bottom-right-radius: 4px;
}
/* Incoming — glass dark, left-aligned */
#msg-conv-messages > div.msg-them,
#msg-conv-messages > div[data-mine="0"] {
  align-self: flex-start;
  background: linear-gradient(160deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid rgba(255,255,255,0.1);
  color: #e8e0d0;
  border-bottom-left-radius: 4px;
}

#msg-conv-input-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(201,168,76,0.2);
  display: flex; gap: 0.5rem;
  background: rgba(0,0,0,0.4);
}
#msg-input {
  flex: 1;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(201,168,76,0.25);
  color: #e8e0d0;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-family: 'Raleway', sans-serif;
  font-size: 0.9rem;
  resize: none;
  transition: border-color 0.2s;
}
#msg-input:focus {
  outline: none;
  border-color: var(--gold-glow, #c9a84c);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.18);
}
#msg-conv-input-area button {
  background: linear-gradient(160deg, #c9a84c 0%, #8a6f2c 100%);
  border: none;
  color: #1a1410;
  width: 44px; height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}
#msg-conv-input-area button:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 18px rgba(201,168,76,0.5);
}

/* Empty / unselected state */
#msg-conv-messages:empty::before {
  content: "Aucun parchemin ouvert. Sélectionnez un ami pour commencer.";
  display: block;
  text-align: center;
  color: rgba(201,168,76,0.55);
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  margin: 4rem auto 0;
  font-size: 1.05rem;
  max-width: 280px;
}

@media (max-width: 700px) {
  #msg-popup {
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    bottom: 80px;
    right: 8px;
  }
  #msg-friends-col { width: 110px; }
  #msg-friends-list .friend-item { padding: 0.5rem 0.5rem !important; font-size: 0.78rem; }
  #msg-btn { right: 80px; bottom: 14px; width: 50px; height: 50px; }
}

/* ── 4. Chatbot widget polish ──────────────────────────────────────── */
#chat-toggle {
  background: linear-gradient(160deg, #432064 0%, #1a0a30 100%) !important;
  border: 2px solid var(--gold-glow, #c9a84c) !important;
  width: 56px !important; height: 56px !important;
  box-shadow:
    0 6px 22px rgba(0,0,0,0.65),
    0 0 24px rgba(67, 32, 100, 0.4) !important;
}
#chat-toggle:hover {
  box-shadow:
    0 8px 28px rgba(0,0,0,0.75),
    0 0 32px rgba(201,168,76,0.65) !important;
}

/* ── 5. Page transition (fade-in on load) ────────────────────────────── */
main, .page-container {
  animation: page-fade-in 0.4s cubic-bezier(.2,.85,.3,1);
}
@keyframes page-fade-in {
  from { opacity: 0; transform: translateY(8px) scale(0.995); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── 6. Reduced motion respect ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
