/* ============================================================
   💬 PRIVATE CHAT + SUPPORT - Widget Styles
   public/css/private-chat.css
   ============================================================ */

/* ── Variables ── */
:root {
  --pm-bg: #0f1219;
  --pm-bg-light: #1a1f2e;
  --pm-bg-hover: #232a3d;
  --pm-border: rgba(255, 255, 255, 0.06);
  --pm-text: #e1e5ee;
  --pm-text-muted: #7a8299;
  --pm-accent: #f0b90b;
  --pm-accent-light: rgba(240, 185, 11, 0.15);
  --pm-accent-hover: rgba(240, 185, 11, 0.25);
  --pm-bubble-mine: #1c3a5e;
  --pm-bubble-other: #1e2235;
  --pm-admin-accent: #38bdf8;
  --pm-online: #22c55e;
  --pm-danger: #ef4444;
  --pm-radius: 14px;
  --pm-radius-sm: 8px;
}

/* ============================================================
   📦 PANEL
   ============================================================ */

.pm-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: 380px;
  max-height: 560px;
  height: 560px;
  background: var(--pm-bg);
  border-radius: var(--pm-radius);
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--pm-border);
  z-index: 9999;
  flex-direction: column;
  overflow: hidden;
  display: none;
}

.pm-panel-open {
  display: flex;
  animation: pmSlideIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes pmSlideIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ============================================================
   📌 HEADER
   ============================================================ */

.pm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--pm-bg-light);
  border-bottom: 1px solid var(--pm-border);
  flex-shrink: 0;
}

.pm-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--pm-text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pm-header h3 i {
  color: var(--pm-accent);
}

.pm-header-actions {
  display: flex;
  gap: 6px;
}

.pm-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--pm-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.pm-icon-btn:hover {
  background: var(--pm-bg-hover);
  color: var(--pm-text);
}

.pm-back-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--pm-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.pm-back-btn:hover {
  background: var(--pm-bg-hover);
  color: var(--pm-accent);
}

/* ============================================================
   🗂️ TABS
   ============================================================ */

.pm-tabs {
  display: flex;
  border-bottom: 1px solid var(--pm-border);
  flex-shrink: 0;
}

.pm-tab {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: transparent;
  color: var(--pm-text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
}

.pm-tab:hover {
  color: var(--pm-text);
  background: var(--pm-bg-hover);
}

.pm-tab-active {
  color: var(--pm-accent);
  border-bottom-color: var(--pm-accent);
}

/* ============================================================
   📜 VIEWS
   ============================================================ */

.pm-view {
  display: none;
  flex-direction: column;
  flex: 1;         /* ✅ FIX: remplace height:100% dans un parent flex */
  min-height: 0;   /* ✅ FIX: empêche le flex de déborder */
  overflow: hidden;
}

.pm-view-active {
  display: flex;
}

/* ============================================================
   📋 CONVERSATIONS LIST
   ============================================================ */

.pm-conversations {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--pm-bg-hover) transparent;
}

.pm-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--pm-border);
}

.pm-conv-item:hover {
  background: var(--pm-bg-hover);
}

.pm-conv-unread {
  background: var(--pm-accent-light);
}

.pm-conv-item-avatar {
  position: relative;
  flex-shrink: 0;
}

.pm-conv-item-avatar img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--pm-border);
}

.pm-online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--pm-online);
  border: 2px solid var(--pm-bg);
}

.pm-conv-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pm-conv-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pm-conv-item-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--pm-text);
  display: flex;
  align-items: center;
  gap: 4px;
}

.pm-cert {
  color: var(--pm-accent);
  font-size: 0.7rem;
}

.pm-conv-item-time {
  font-size: 0.72rem;
  color: var(--pm-text-muted);
  flex-shrink: 0;
}

.pm-conv-item-preview {
  font-size: 0.8rem;
  color: var(--pm-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pm-you {
  color: var(--pm-text-muted);
  font-weight: 500;
}

.pm-unread-badge {
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--pm-accent);
  color: #000;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

/* ============================================================
   🔍 SEARCH
   ============================================================ */

.pm-search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--pm-border);
}

.pm-search-box i {
  color: var(--pm-text-muted);
  font-size: 0.85rem;
}

.pm-search-box input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--pm-text);
  font-size: 0.9rem;
  outline: none;
}

.pm-search-box input::placeholder {
  color: var(--pm-text-muted);
}

.pm-search-results {
  flex: 1;
  overflow-y: auto;
}

.pm-search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.pm-search-item:hover {
  background: var(--pm-bg-hover);
}

.pm-search-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.pm-search-name {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--pm-text);
  display: flex;
  align-items: center;
  gap: 5px;
}

.pm-search-hint {
  text-align: center;
  color: var(--pm-text-muted);
  padding: 24px;
  font-size: 0.85rem;
}

/* ============================================================
   💬 CONVERSATION HEADER INFO
   ============================================================ */

.pm-conv-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.pm-conv-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.pm-conv-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--pm-text);
}

.pm-conv-status {
  font-size: 0.72rem;
  color: var(--pm-text-muted);
  display: block;
}

.pm-status-online {
  color: var(--pm-online);
}

.pm-support-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--pm-accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pm-accent);
  font-size: 1rem;
  flex-shrink: 0;
}

/* ============================================================
   💬 MESSAGES
   ============================================================ */

.pm-messages {
  flex: 1;
  min-height: 0; /* ✅ FIX: crucial pour que overflow-y fonctionne dans un flex */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--pm-bg-hover) transparent;
}

.pm-msg {
  display: flex;
  max-width: 82%;
}

.pm-msg-mine {
  align-self: flex-end;
}

.pm-msg-other {
  align-self: flex-start;
}

.pm-msg-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  max-width: 100%;
  word-wrap: break-word;
  position: relative;
}

.pm-msg-mine .pm-msg-bubble {
  background: var(--pm-bubble-mine);
  color: var(--pm-text);
  border-bottom-right-radius: 4px;
}

.pm-msg-other .pm-msg-bubble {
  background: var(--pm-bubble-other);
  color: var(--pm-text);
  border-bottom-left-radius: 4px;
}

.pm-msg-admin .pm-msg-bubble {
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.pm-msg-bubble p {
  margin: 0;
  font-size: 0.87rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.pm-msg-time {
  display: block;
  font-size: 0.65rem;
  color: var(--pm-text-muted);
  margin-top: 3px;
  text-align: right;
}

.pm-read-check {
  color: var(--pm-admin-accent);
  font-size: 0.6rem;
  margin-left: 2px;
}

.pm-admin-label, .pm-sender-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.pm-admin-label {
  color: var(--pm-admin-accent);
}

.pm-sender-label {
  color: var(--pm-accent);
}

/* ── Typing indicator ── */
.pm-typing {
  padding: 4px 16px;
  font-size: 0.75rem;
  color: var(--pm-text-muted);
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.pm-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pm-text-muted);
  animation: pmTypingDot 1.4s infinite;
}

.pm-typing span:nth-child(2) { animation-delay: 0.2s; }
.pm-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pmTypingDot {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1.1); }
}

/* ============================================================
   ✏️ INPUT AREA
   ============================================================ */

.pm-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--pm-border);
  background: var(--pm-bg-light);
  flex-shrink: 0;
}

.pm-input-area input {
  flex: 1;
  border: 1px solid var(--pm-border);
  border-radius: 20px;
  padding: 8px 14px;
  background: var(--pm-bg);
  color: var(--pm-text);
  font-size: 0.87rem;
  outline: none;
  transition: border-color 0.2s;
}

.pm-input-area input:focus {
  border-color: var(--pm-accent);
}

.pm-input-area input::placeholder {
  color: var(--pm-text-muted);
}

.pm-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--pm-accent);
  color: #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all 0.2s;
  flex-shrink: 0;
}

.pm-send-btn:hover {
  background: #d4a00a;
  transform: scale(1.05);
}

/* ============================================================
   📭 EMPTY / LOADING
   ============================================================ */

.pm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  color: var(--pm-text-muted);
  text-align: center;
  gap: 12px;
}

.pm-empty i {
  font-size: 2.2rem;
  opacity: 0.4;
}

.pm-empty p {
  font-size: 0.9rem;
  margin: 0;
}

.pm-start-btn {
  margin-top: 8px;
  padding: 8px 20px;
  border-radius: 20px;
  border: none;
  background: var(--pm-accent);
  color: #000;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}

.pm-start-btn:hover {
  background: #d4a00a;
}

.pm-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--pm-accent);
  font-size: 1.4rem;
}

/* ── Support welcome ── */
.pm-support-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 32px 24px;
  gap: 10px;
}

.pm-support-welcome-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--pm-accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pm-accent);
  font-size: 1.4rem;
}

.pm-support-welcome h4 {
  color: var(--pm-text);
  margin: 0;
  font-size: 1rem;
}

.pm-support-welcome p {
  color: var(--pm-text-muted);
  font-size: 0.82rem;
  margin: 0;
  line-height: 1.4;
}

/* ============================================================
   🛡️ ADMIN
   ============================================================ */

.pm-admin-filters {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--pm-border);
  flex-shrink: 0;
}

.pm-filter {
  padding: 5px 12px;
  border-radius: 14px;
  border: 1px solid var(--pm-border);
  background: transparent;
  color: var(--pm-text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.pm-filter:hover {
  border-color: var(--pm-accent);
  color: var(--pm-text);
}

.pm-filter-active {
  background: var(--pm-accent-light);
  border-color: var(--pm-accent);
  color: var(--pm-accent);
}

.pm-admin-tickets {
  flex: 1;
  overflow-y: auto;
}

.pm-ticket-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--pm-border);
}

.pm-ticket-item:hover {
  background: var(--pm-bg-hover);
}

.pm-close-ticket-btn {
  color: var(--pm-online) !important;
}

.pm-close-ticket-btn:hover {
  color: var(--pm-danger) !important;
}

/* ============================================================
   🍔 CONTEXT MENU
   ============================================================ */

.pm-context-menu {
  position: absolute;
  top: 100%;
  right: 12px;
  background: var(--pm-bg-light);
  border: 1px solid var(--pm-border);
  border-radius: var(--pm-radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 100;
  overflow: hidden;
  min-width: 140px;
}

.pm-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--pm-text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
}

.pm-menu-item:hover {
  background: var(--pm-bg-hover);
}

.pm-menu-danger {
  color: var(--pm-danger);
}

/* ============================================================
   📱 RESPONSIVE
   ============================================================ */

@media (max-width: 480px) {
  .pm-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100dvh;
    max-height: 100vh; /* fallback */
    height: 100dvh;
    height: 100vh; /* fallback */
    height: calc(var(--vh, 1vh) * 100); /* JS override */
    border-radius: 0;
    transform: translateY(100%);
  }

  .pm-panel-open {
    transform: translateY(0);
  }

  .pm-floating-btn {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 768px) and (min-width: 481px) {
  .pm-panel {
    width: 340px;
    max-height: 480px;
    height: 480px;
  }
}

/* ============================================================
   👤 GUEST SUPPORT STYLES
   ============================================================ */

/* Bouton support (visiteurs) */
.pm-floating-btn-support {
  background: linear-gradient(135deg, var(--pm-accent), #e0a800) !important;
}

.pm-floating-btn-support i {
  font-size: 22px;
}

/* Formulaire pseudo guest */
.pm-guest-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
}

.pm-guest-input-group {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.pm-guest-input-group input {
  flex: 1;
  background: var(--pm-bg-light);
  border: 1px solid var(--pm-border);
  border-radius: var(--pm-radius-sm);
  padding: 12px 16px;
  color: var(--pm-text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.pm-guest-input-group input:focus {
  border-color: var(--pm-accent);
}

.pm-guest-input-group input.pm-input-error {
  border-color: var(--pm-danger);
  animation: pmShake 0.3s ease-in-out;
}

@keyframes pmShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.pm-guest-start-btn {
  width: 44px !important;
  min-width: 44px;
  height: 44px;
  border-radius: var(--pm-radius-sm) !important;
}

/* Badge visiteur dans admin */
.pm-guest-badge {
  display: inline-block;
  background: rgba(240, 185, 11, 0.15);
  color: var(--pm-accent);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Avatar guest dans admin */
.pm-guest-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--pm-accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pm-accent);
  font-size: 16px;
}