/* ====================================================================
   VFJah Messenger — feuille de style rétro
   MSN Messenger 6/7 (chrome bleu, dégradés, biseaux) croisé avec
   l'esthétique Skyblog/IRC années 2000 (couleurs vives, glitter, blink).
   Responsive : desktop = fenêtres flottantes ; mobile = plein écran.
   ==================================================================== */

:root {
  --msn-blue: #2a6fc9;
  --msn-blue-2: #4d9de0;
  --msn-grad: linear-gradient(180deg, #5aa9f0 0%, #2a6fc9 45%, #1d5bb0 100%);
  --bevel-light: #ffffff;
  --bevel-dark: #7a9cc6;
  --panel: #eaf2fb;
  --panel-2: #d6e6f8;
  --ink: #11335c;
  --sky-pink: #ff5fa2;
  --sky-green: #7ed957;
  --sky-yellow: #ffe14d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: #1a3a6b;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* fond ciel étoilé Skyblog */
.sky-bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(2px 2px at 20% 30%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 70% 60%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 40% 80%, #ffe14d 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 85% 25%, #ff5fa2 50%, transparent 51%),
    linear-gradient(160deg, #16356a 0%, #0d2147 60%, #1d1040 100%);
  background-size: 300px 300px, 250px 250px, 200px 200px, 350px 350px, cover;
  animation: drift 60s linear infinite;
}
@keyframes drift { to { background-position: 300px 0, -250px 200px, 200px -200px, -350px 100px, 0 0; } }

@keyframes blinkk { 50% { opacity: .25; } }
.blink { animation: blinkk 1.1s steps(2) infinite; }

/* ---------------- Chrome de fenêtre MSN ---------------- */
.msn-window {
  background: var(--panel);
  border: 2px solid var(--msn-blue);
  border-radius: 8px 8px 6px 6px;
  box-shadow: 0 6px 22px rgba(0,0,0,.45), inset 0 0 0 1px var(--bevel-light);
  overflow: hidden;
}

.title-bar {
  display: flex; align-items: center; gap: 6px;
  background: var(--msn-grad);
  color: #fff;
  padding: 4px 8px;
  font-weight: bold;
  text-shadow: 0 1px 1px rgba(0,0,0,.4);
  cursor: default;
  user-select: none;
}
.title-bar-icon { font-size: 14px; }
.title-bar-text { flex: 1; letter-spacing: .3px; }
.title-bar-controls { display: flex; gap: 4px; }
.title-bar-controls > span {
  width: 18px; height: 16px; line-height: 14px; text-align: center;
  background: rgba(255,255,255,.25);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 3px; cursor: pointer; font-size: 11px;
}
.title-bar-controls > span:hover { background: rgba(255,255,255,.5); }

/* ---------------- Écran de connexion ---------------- */
.login-window {
  width: 340px; margin: 6vh auto 0;
}
.login-body { padding: 18px 22px 24px; background: var(--panel); }
.login-logo { text-align: center; margin-bottom: 14px; }
.butterfly { font-size: 46px; filter: drop-shadow(0 0 6px var(--msn-blue-2)); animation: flap 3s ease-in-out infinite; }
@keyframes flap { 50% { transform: rotate(-8deg) translateY(-4px); } }
.login-logo h1 { margin: 4px 0 0; font-size: 26px; color: var(--msn-blue); }
.login-logo h1 span { color: var(--sky-pink); }
.tagline { color: #6b4aa0; font-size: 11px; margin: 4px 0 0; }

form label { display: block; margin: 10px 0 2px; font-weight: bold; }
form input, form select, .personal-msg, #search-contacts {
  width: 100%; padding: 6px 8px; font-family: inherit; font-size: 13px;
  border: 1px solid var(--bevel-dark); border-radius: 4px;
  background: #fff; box-shadow: inset 1px 1px 2px rgba(0,0,0,.12);
}
.status-pick { margin-top: 10px; }

.big-btn {
  width: 100%; margin-top: 16px; padding: 9px;
  font-weight: bold; font-size: 14px; color: #fff; cursor: pointer;
  background: var(--msn-grad);
  border: 1px solid #1d5bb0; border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}
.big-btn:hover { filter: brightness(1.08); }
.big-btn:active { transform: translateY(1px); }
.link-btn { width: 100%; margin-top: 8px; background: none; border: 0; color: var(--msn-blue); cursor: pointer; text-decoration: underline; }
.register-lead { text-align: center; color: #6b4aa0; font-size: 12px; margin: 0 0 10px; line-height: 1.4; }
.avatar-register { margin-bottom: 12px; }
.register-avatar-preview {
  width: 72px; height: 72px; margin: 0 auto 10px; font-size: 42px; line-height: 72px;
  text-align: center; border-radius: 10px;
  background: linear-gradient(180deg, #fff 0%, #e8eef8 100%);
  border: 2px solid var(--bevel-dark); box-shadow: inset 0 1px 0 #fff;
}
.avatar-picker {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
  max-height: 140px; overflow-y: auto; padding: 4px;
  background: rgba(255,255,255,.6); border-radius: 6px; border: 1px solid var(--bevel-dark);
}
.avatar-pick {
  font-size: 22px; line-height: 1; padding: 6px 0; cursor: pointer;
  border: 2px solid transparent; border-radius: 6px; background: #fff;
}
.avatar-pick:hover { border-color: var(--msn-blue-2); background: #f0f6ff; }
.avatar-pick.selected { border-color: var(--sky-pink); background: #fff8e0; box-shadow: 0 0 0 1px var(--sky-pink); }
.error { color: #c0203a; font-weight: bold; text-align: center; margin-top: 10px; }

/* ---------------- Application ---------------- */
#app { display: flex; gap: 14px; padding: 14px; align-items: flex-start; flex-wrap: wrap; position: relative; min-height: calc(100vh - 28px); min-height: calc(100dvh - 28px); }

.mobile-nav { display: none !important; }

.contact-window { width: 300px; flex: 0 0 auto; position: relative; }
.contact-window.floating { position: absolute; flex: none; max-height: none; display: flex; flex-direction: column; }
.contact-window.floating .contacts-scroll { flex: 1; max-height: none; min-height: 0; overflow-y: auto; }
.contact-window .resize-grip { position: absolute; right: 2px; bottom: 2px; }

.me-card {
  display: flex; gap: 10px; align-items: center;
  padding: 10px; background: var(--panel-2);
  border-bottom: 1px solid var(--bevel-dark);
}
.me-avatar { cursor: pointer; }
.me-avatar:hover { filter: brightness(1.08); box-shadow: 0 0 0 2px var(--sky-yellow); }

.avatar-menu {
  position: fixed; z-index: 60; min-width: 200px;
  background: #fff; border: 2px solid var(--msn-blue); border-radius: 8px;
  padding: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.avatar-menu p { margin: 0 0 8px; font-weight: bold; color: var(--msn-blue); font-size: 12px; }
.avatar-emojis { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.avatar-emo-btn { font-size: 22px; padding: 4px; cursor: pointer; border: 1px solid var(--bevel-dark); border-radius: 6px; background: var(--panel); }
.avatar-emo-btn:hover { background: var(--sky-yellow); }
#avatar-photo-btn, #avatar-menu-close {
  font-size: 12px; padding: 4px 8px; margin-right: 6px; cursor: pointer;
  border: 1px solid var(--bevel-dark); border-radius: 5px; background: var(--panel-2);
}

.add-contact-dialog {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  background: rgba(13, 33, 71, 0.55);
}
.add-contact-dialog[hidden] { display: none !important; }
.add-contact-dialog .msn-window { width: min(360px, 94vw); max-height: 80vh; display: flex; flex-direction: column; }
.add-contact-body { padding: 10px; background: var(--panel); display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.add-contact-list { flex: 1; min-height: 180px; max-height: 42vh; overflow-y: auto; background: #fff; border: 1px solid var(--bevel-dark); border-radius: 4px; }
.add-contact-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--panel-2);
}
.add-contact-row:hover { background: var(--sky-yellow); }
.add-contact-row .c-handle { font-size: 10px; color: var(--msn-blue); }
.add-contact-manual { display: flex; gap: 6px; }
.add-contact-manual input { flex: 1; padding: 6px; border: 1px solid var(--bevel-dark); border-radius: 4px; }
.add-contact-manual button { padding: 6px 12px; cursor: pointer; font-weight: bold; background: var(--msn-grad); color: #fff; border: 1px solid #1d5bb0; border-radius: 5px; }
.add-contact-hint { margin: 0; font-size: 11px; color: #8a6fb0; }
.add-contact-empty { padding: 16px; text-align: center; color: #8a6fb0; font-style: italic; }

.me-avatar, .peer-avatar {
  width: 42px; height: 42px; min-width: 42px; display: grid; place-items: center;
  font-size: 24px; background: #fff; border: 2px solid var(--msn-blue);
  border-radius: 6px; box-shadow: 0 0 0 2px #fff, 0 2px 5px rgba(0,0,0,.25);
}
.me-info { flex: 1; min-width: 0; }
.me-name-row { display: flex; gap: 6px; align-items: center; }
.me-name { font-weight: bold; font-size: 14px; color: var(--msn-blue); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-select, .status-pick select { padding: 4px; border-radius: 4px; border: 1px solid var(--bevel-dark); background: #fff; }
.status-select { font-size: 11px; max-width: 110px; }
.personal-msg { margin-top: 5px; font-style: italic; color: #6b4aa0; }

.mob-only { display: none !important; }
.room-only { display: none; }
.chat-window.is-room .room-only { display: inline-block; }
.chat-window.is-room .dm-only { display: none !important; }
.chat-window.is-room .peer-avatar { font-size: 18px; }
.room-members { margin-left: auto; font-size: 11px; color: #8a6fb0; white-space: nowrap; }

.toolbar { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--bevel-dark); flex-wrap: wrap; align-items: center; }
.room-topic-input {
  flex: 1; min-width: 72px; max-width: 110px; padding: 5px 6px; font-size: 12px;
  border: 1px solid var(--bevel-dark); border-radius: 4px; background: #fff;
}
#search-contacts { flex: 1; min-width: 80px; }

.group-head-rooms { background: linear-gradient(90deg, #5a7fc9, var(--msn-blue-2)); }

.room-row.contact-style {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; cursor: pointer;
  border-bottom: 1px solid var(--panel-2);
}
.room-row.contact-style:hover { background: var(--sky-yellow); }
.room-row .room-icon {
  font-weight: bold; color: var(--msn-blue); font-size: 16px; background: var(--panel-2);
}
.room-row.joined .room-hash::after { content: " ✓"; color: var(--sky-green); font-size: 10px; }
.room-row.browse { opacity: .88; }
.room-row.browse .room-hash { color: #6b4aa0; }
.room-preview {
  display: block; font-size: 11px; font-style: italic; color: #6b4aa0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px;
}
.room-row .room-action {
  flex-shrink: 0; padding: 2px 6px; font-size: 14px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--bevel-dark); border-radius: 4px;
}
.room-row .room-action:hover { background: var(--sky-yellow); }

.toolbar button {
  white-space: nowrap; padding: 5px 8px; cursor: pointer;
  background: linear-gradient(#fff, var(--panel-2));
  border: 1px solid var(--bevel-dark); border-radius: 5px; font-weight: bold; color: var(--ink);
}
.toolbar button:hover { background: var(--sky-yellow); }
#search-contacts { flex: 1; }

.contacts-scroll { max-height: 50vh; overflow-y: auto; padding: 4px 0; background: #fff; }

.group-head {
  padding: 4px 10px; font-weight: bold; color: #fff;
  background: linear-gradient(90deg, var(--sky-pink), var(--msn-blue-2));
  cursor: pointer; margin-top: 2px;
}
.group-head::before { content: "▼ "; font-size: 9px; }
.group-head.collapsed::before { content: "► "; }

.contact-row {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px; cursor: pointer;
}
.contact-row:hover { background: var(--sky-yellow); }
.contact-row .dot { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 4px currentColor; }
.dot.online { background: var(--sky-green); color: var(--sky-green); }
.dot.away, .dot.brb, .dot.lunch { background: var(--sky-yellow); color: var(--sky-yellow); }
.dot.busy, .dot.phone { background: #ff4d4d; color: #ff4d4d; }
.dot.invisible, .dot.offline { background: #b8b8b8; color: #b8b8b8; }
.contact-row .c-avatar { font-size: 18px; }
.contact-row .c-name { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.contact-row .c-display { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-row .c-handle { font-size: 10px; color: var(--msn-blue); background: transparent; padding: 0; }
.contact-row.offline { opacity: .55; }
.contact-row .c-personal { font-size: 11px; font-style: italic; color: #8a6fb0; }

.bridges-bar {
  display: flex; gap: 6px; padding: 6px 10px; flex-wrap: wrap;
  background: var(--panel-2); border-top: 1px solid var(--bevel-dark); min-height: 26px;
}
.bridge-pill {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: bold;
  background: #fff; border: 1px solid var(--bevel-dark);
}
.bridge-pill.on { background: var(--sky-green); color: #0a3d0a; }
.bridge-pill.off { opacity: .6; }

/* ---------------- Fenêtres de chat ---------------- */
#chats { position: relative; flex: 1; min-width: 280px; min-height: 70vh; }
.chat-window { width: 360px; display: flex; flex-direction: column; max-height: 78vh; position: relative; }
.chat-window.floating { position: absolute; max-height: none; box-shadow: 0 8px 28px rgba(0,0,0,.5); }
.chat-window.floating .messages { flex: 1; min-height: 120px; }
.resize-grip {
  position: absolute; right: 2px; bottom: 2px; width: 14px; height: 14px;
  cursor: nwse-resize; opacity: .7;
  background: linear-gradient(135deg, transparent 45%, var(--msn-blue) 46%);
}

.chat-peer {
  display: flex; gap: 8px; align-items: center; padding: 8px 10px;
  background: var(--panel-2); border-bottom: 1px solid var(--bevel-dark);
}
.peer-meta { display: flex; flex-direction: column; min-width: 0; }
.peer-name { color: var(--msn-blue); }
.peer-personal { font-size: 11px; color: #8a6fb0; }

.messages {
  flex: 1; min-height: 200px; overflow-y: auto; padding: 8px 10px;
  background:
    repeating-linear-gradient(0deg, #ffffff, #ffffff 22px, #f3f8ff 22px, #f3f8ff 23px);
}
.msg { margin: 6px 0; line-height: 1.4; }
.msg-body { white-space: pre-line; }
.msg .who { font-weight: bold; }
.msg.me .who { color: var(--sky-pink); }
.msg.them .who { color: var(--msn-blue); }
.msg .time { color: #9aa7b8; font-size: 10px; margin-left: 4px; }
.msg-img { max-width: min(280px, 100%); border-radius: 6px; border: 1px solid var(--bevel-dark); vertical-align: middle; }
.chat-link { font-weight: bold; text-decoration: underline; cursor: pointer; }
.chat-link-user { color: #6b4aa0; }
.chat-link-user.who { cursor: pointer; }
.chat-link-user.who:hover { color: var(--sky-pink); }
.chat-link-room { color: var(--msn-blue); }
.chat-link-room:hover { color: var(--sky-pink); background: rgba(255,225,77,.35); border-radius: 3px; }
.chat-link-url { color: #0d6b3a; word-break: break-all; }
.chat-link-url:hover { color: #094d2a; background: rgba(144,238,180,.35); border-radius: 3px; }
.foot-quick-bar {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px;
  background: linear-gradient(180deg, #e8f5e9 0%, #dceee0 100%);
  border-top: 1px solid var(--bevel-dark); border-bottom: 1px solid var(--bevel-dark);
}
.foot-cmd-btn {
  flex: 1 1 auto; min-width: 72px; padding: 4px 6px; font-size: 11px; font-family: inherit;
  cursor: pointer; border: 1px solid #2e7d4a; border-radius: 5px;
  background: linear-gradient(180deg, #fff 0%, #c8e6c9 100%);
  color: #1b5e20; font-weight: bold;
}
.foot-cmd-btn:hover { filter: brightness(1.05); background: #fff; }
.foot-cmd-btn:active { transform: translateY(1px); }
.chat-link:hover { text-decoration: underline; }
.msg.system { text-align: center; color: #8a6fb0; font-style: italic; font-size: 11px; }
.msg.nudge {
  text-align: center; font-weight: bold; color: #c0203a;
  background: #ffe9ef; border: 1px dashed var(--sky-pink); border-radius: 6px; padding: 4px;
}
.msg.bridge .who::after { content: " 🌐"; }
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-6px, 3px); } 40% { transform: translate(6px, -3px); }
  60% { transform: translate(-5px, -2px); } 80% { transform: translate(5px, 2px); }
}
.shaking { animation: shake .5s ease-in-out 2; }

.typing-line { padding: 2px 10px; font-size: 11px; font-style: italic; color: #8a6fb0; }

.emote-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px 8px; background: var(--panel-2); border-top: 1px solid var(--bevel-dark); }
.emote-bar button { font-size: 16px; background: #fff; border: 1px solid var(--bevel-dark); border-radius: 4px; cursor: pointer; padding: 1px 4px; }
.emote-bar button:hover { background: var(--sky-yellow); }

.composer { display: flex; gap: 6px; padding: 8px; background: var(--panel); align-items: center; }
.file-btn { padding: 4px 8px; cursor: pointer; border: 1px solid var(--bevel-dark); border-radius: 4px; background: #fff; }
.pending-requests { padding: 8px; background: var(--sky-yellow); font-size: 12px; }
.pending-row { margin: 4px 0; }
.pending-row button { margin-left: 6px; padding: 2px 8px; cursor: pointer; }
.msg-input { flex: 1; resize: none; padding: 6px; border: 1px solid var(--bevel-dark); border-radius: 5px; font-family: inherit; font-size: 13px; }
.send-btn { padding: 0 14px; font-weight: bold; color: #fff; background: var(--msn-grad); border: 1px solid #1d5bb0; border-radius: 6px; cursor: pointer; }
.send-btn:hover { filter: brightness(1.08); }

/* ---------------- Toasts "X vient de se connecter" ---------------- */
#toasts { position: fixed; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  width: 220px; padding: 8px 10px; color: #fff; font-size: 12px;
  background: var(--msn-grad); border: 1px solid #1d5bb0; border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,.4); animation: slidein .3s ease;
}
.toast b { color: var(--sky-yellow); }
@keyframes slidein { from { transform: translateX(120%); } }

/* ---------------- Mobile : navigation single-pane ---------------- */
@media (max-width: 760px) {
  #app { flex-direction: column; padding: 0; gap: 0; min-height: 100dvh; }
  .mob-only { display: inline-block !important; }
  .contact-window, .chat-window { width: 100vw; border-radius: 0; max-height: none; border-left: 0; border-right: 0; }
  .login-window { width: 100vw; margin: 0; min-height: 100dvh; border-radius: 0; }
  #chats { width: 100%; min-height: 0; flex: 1; }
  .chat-window { min-height: 100dvh; display: none; }
  .chat-window.mobile-active { display: flex; }
  .contact-window { display: none; flex: 1; min-height: 100dvh; }
  .contact-window.mobile-active { display: flex; flex-direction: column; }
  .contact-window.floating, .chat-window.floating { position: relative; left: auto !important; top: auto !important; width: 100vw !important; height: auto !important; }
  .contacts-scroll { max-height: none; flex: 1; }
  .room-topic-input { max-width: none; flex: 1; }
  .toolbar button, .send-btn, .emote-bar button { min-height: 40px; min-width: 40px; font-size: 14px; }
  .msg-input { font-size: 16px; min-height: 44px; }
  .contact-row, .room-row { padding: 10px 12px; }
  .room-preview { max-width: 70vw; }
  .title-bar { padding: 8px 10px; }
  .title-bar-controls > span { width: 32px; height: 28px; line-height: 26px; font-size: 14px; }
  #toasts { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { width: auto; max-width: 100%; }
  .resize-grip { display: none; }
}
