/* ======================== Friends Page ======================== */
.friends-page {
  position: fixed; inset: 0; z-index: 999;
  background: #0f172a;
  color: #e2e8f0;
  display: flex; flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.friends-close {
  position: fixed; top: 12px; right: 16px; z-index: 10000;
  background: rgba(30,41,59,0.9); color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.15); width: 36px; height: 36px; border-radius: 50%;
  font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.friends-close:hover { background: rgba(30,41,59,1); border-color: rgba(255,255,255,0.3); }

.friends-layout {
  display: flex; height: 100%; overflow: hidden;
}

/* Ensure friendsPage and its fixed children hide */
#friendsPage.hidden,
#friendsPage.hidden .friends-close { display: none !important; }

/* Mobile: sidebar full-width, chat overlays when open */
@media (max-width: 767px) {
  .friends-layout.showing-chat .friends-sidebar { display: none; }
  .friends-layout:not(.showing-chat) .friends-chat { display: none !important; }
  .friends-layout.showing-chat .friends-chat { display: flex !important; }
}

/* ======================== Sidebar (Friend List) ======================== */
.friends-sidebar {
  width: 100%; max-width: 100%;
  display: flex; flex-direction: column;
  background: #1e293b;
  border-right: 1px solid rgba(255,255,255,0.08);
}
@media (min-width: 768px) {
  .friends-sidebar { width: 280px; max-width: 280px; flex-shrink: 0; }
}

.friends-sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 52px 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
@media (min-width: 768px) {
  .friends-sidebar-header { padding-right: 16px; }
}
.friends-sidebar-header h3 { margin: 0; font-size: 17px; font-weight: 600; color: #e2e8f0; }
.friends-sidebar-header .icon-btn { background: none; border: none; color: #94a3b8; font-size: 22px; cursor: pointer; width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.friends-sidebar-header .icon-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

.friends-search { margin: 8px 12px; padding: 8px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.05); color: #fff; font-size: 13px; outline: none; }
.friends-search:focus { border-color: #6366F1; }
.friends-search::placeholder { color: #64748b; }

.friends-list { flex: 1; overflow-y: auto; }

/* Friend item */
.friend-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer; transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.friend-item:hover, .friend-item.active { background: rgba(99, 102, 241, 0.12); }

.friend-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: #6366F1; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0; overflow: hidden;
}
.friend-avatar img { width: 100%; height: 100%; object-fit: cover; }

.friend-info { flex: 1; min-width: 0; }
.friend-name { font-size: 14px; font-weight: 500; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend-last-msg { font-size: 12px; color: #94a3b8; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.friend-meta { text-align: right; flex-shrink: 0; }
.friend-time { font-size: 11px; color: #64748b; }
.friend-badge {
  display: inline-block; min-width: 18px; height: 18px; line-height: 18px;
  background: #EF4444; color: #fff; border-radius: 9px; font-size: 10px; font-weight: 600;
  text-align: center; padding: 0 5px; margin-top: 4px;
}
.friend-badge:empty { display: none; }

/* Add friend button row */
.friends-add-row { padding: 8px 14px; border-top: 1px solid rgba(255,255,255,0.06); }
.friends-add-btn {
  width: 100%; padding: 8px; border: 1px dashed rgba(255,255,255,0.2);
  background: none; color: #94a3b8; border-radius: 8px;
  font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.friends-add-btn:hover { border-color: #6366F1; color: #6366F1; }

/* Requests badge */
.friends-requests-badge {
  display: inline-block; background: #F59E0B; color: #000; border-radius: 9px;
  font-size: 10px; font-weight: 700; padding: 0 6px; height: 18px; line-height: 18px;
}

/* ======================== Chat Window ======================== */
.friends-chat {
  flex: 1; display: flex; flex-direction: column;
  background: #0f172a;
  position: relative; overflow: hidden;
}
@media (max-width: 767px) {
  .friends-chat { position: fixed; inset: 0; z-index: 1001; }
}

.friends-chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid rgba(255,255,255,0.06);
  background: #1e293b;
}
.friends-back-btn { display: none; background: none; border: none; color: #94a3b8; font-size: 20px; cursor: pointer; padding: 0; }
@media (max-width: 767px) { .friends-back-btn { display: block; } }
.friends-chat-name { flex: 1; font-size: 15px; font-weight: 600; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friends-chat-header .icon-btn { background: none; border: none; color: #94a3b8; font-size: 18px; cursor: pointer; width: 34px; height: 34px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.friends-chat-header .icon-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* Messages area */
.friends-messages {
  flex: 1; overflow-y: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}

/* Load more */
.friends-load-more {
  text-align: center; padding: 6px;
}
.friends-load-more button {
  background: none; border: none; color: #6366F1; font-size: 12px; cursor: pointer;
}

/* Message bubble */
.msg-row { display: flex; gap: 8px; max-width: 75%; align-items: flex-end; }
.msg-row.me { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.other { align-self: flex-start; }

.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  background: #6366F1; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px;
}
.msg-row.me .msg-avatar { background: #22C55E; }

.msg-bubble {
  padding: 8px 12px; border-radius: 12px; font-size: 14px; line-height: 1.5;
  word-break: break-word; position: relative;
}
.msg-row.me .msg-bubble { background: #6366F1; color: #fff; border-bottom-right-radius: 4px; }
.msg-row.other .msg-bubble { background: #334155; color: #e2e8f0; border-bottom-left-radius: 4px; }

.msg-time { font-size: 10px; color: #64748b; margin-top: 2px; }
.msg-row.me .msg-time { text-align: right; color: rgba(255,255,255,0.5); }

.msg-status { font-size: 10px; margin-left: 4px; }
.msg-status.read { color: #34D399; }
.msg-status.delivered { color: #94a3b8; }

/* Emoji message */
.msg-emoji .msg-bubble { font-size: 40px; background: transparent !important; padding: 4px; line-height: 1.2; }

/* Voice message */
.msg-voice .msg-bubble { display: flex; align-items: center; gap: 8px; min-width: 100px; cursor: pointer; }
.msg-voice-play { width: 28px; height: 28px; border-radius: 50%; border: none; background: rgba(255,255,255,0.2); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }
.msg-row.me .msg-voice-play { background: rgba(255,255,255,0.3); }
.msg-voice-wave { flex: 1; height: 24px; display: flex; align-items: center; gap: 2px; }
.msg-voice-wave span { width: 2px; background: currentColor; border-radius: 1px; }
.msg-voice-dur { font-size: 12px; opacity: 0.7; }

/* Image message */
.msg-img-bubble { padding: 4px !important; background: transparent !important; }
.msg-img-bubble img { display: block; }

/* Product card */
.msg-product .msg-bubble { padding: 0; overflow: hidden; max-width: 240px; background: #1e293b !important; border: 1px solid rgba(255,255,255,0.1); }
.msg-product-img { width: 100%; height: 140px; object-fit: cover; display: block; background: #0f172a; cursor: pointer; border-radius: 8px 8px 0 0; }
.msg-product-img:hover { opacity: 0.9; }
.msg-product-info { padding: 8px 10px; }
.msg-product-name { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.msg-product-price { font-size: 14px; font-weight: 700; color: #F59E0B; }

/* Video call message */
.msg-vcall .msg-bubble { font-size: 13px; opacity: 0.8; }

/* Date separator */
.msg-date-sep { text-align: center; font-size: 11px; color: #64748b; padding: 6px 0; }

/* ======================== Input Bar ======================== */
.friends-input-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-top: 1px solid rgba(255,255,255,0.06);
  background: #1e293b;
}
.friends-input-bar .icon-btn {
  background: none; border: none; color: #94a3b8; font-size: 18px;
  cursor: pointer; width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.friends-input-bar .icon-btn:hover, .friends-input-bar .icon-btn.active { background: rgba(255,255,255,0.1); color: #fff; }

.friends-msg-input {
  flex: 1; min-width: 0; height: 36px;
  padding: 0 14px; border-radius: 18px; border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06); color: #e2e8f0; font-size: 14px; line-height: 36px;
  outline: none; font-family: inherit; resize: none;
}
.friends-msg-input:focus { border-color: #6366F1; }
.friends-msg-input::placeholder { color: #64748b; }

.friends-send-btn {
  background: #6366F1; color: #fff; border: none; border-radius: 18px;
  padding: 0 16px; height: 36px; font-size: 13px; font-weight: 600;
  cursor: pointer; flex-shrink: 0; white-space: nowrap;
}
.friends-send-btn:hover { opacity: 0.85; }
.friends-send-btn:active { opacity: 0.7; }
.send-btn:disabled { opacity: 0.4; cursor: default; }

/* Voice recording button */
.voice-recording { background: #EF4444 !important; animation: pulse-rec 1s infinite; }
@keyframes pulse-rec { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* Emoji picker — fixed to viewport so it stays visible when iOS keyboard is open */
.friends-emoji-picker {
  position: fixed; bottom: 56px; left: 12px; right: 12px;
  max-height: 260px; overflow-y: auto;
  background: #1e293b; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px; padding: 0;
  z-index: 10000; /* above everything including #friendsChat (1001) */
}
.emoji-picker-close {
  position: sticky; top: 0; z-index: 2;
  text-align: right; padding: 6px 10px; font-size: 18px; color: #94a3b8;
  cursor: pointer; background: #1e293b; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.emoji-picker-close:hover { color: #fff; }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 8px;
}
.emoji-grid button {
  background: none; border: none; font-size: 24px; cursor: pointer;
  padding: 8px 4px; border-radius: 8px; text-align: center;
  -webkit-tap-highlight-color: transparent; user-select: none;
  touch-action: manipulation;
}
.emoji-grid button:hover, .emoji-grid button:active { background: rgba(255,255,255,0.15); }

@media (max-width: 767px) {
  .emoji-grid { grid-template-columns: repeat(6, 1fr); }
  .emoji-grid button { font-size: 26px; padding: 10px 4px; }
}

/* ======================== Video Call Overlay ======================== */
.call-overlay {
  position: fixed; inset: 0; z-index: 2000; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.call-video { width: 100%; height: 100%; object-fit: cover; }
.call-remote-video { width: 100%; height: 100%; object-fit: cover; }
.call-local-video {
  position: absolute; top: 16px; right: 16px; width: 120px; height: 160px;
  border-radius: 12px; object-fit: cover; border: 2px solid rgba(255,255,255,0.3);
}
.call-controls {
  position: absolute; bottom: 40px; display: flex; gap: 16px;
}
.call-btn {
  width: 56px; height: 56px; border-radius: 50%; border: none;
  font-size: 22px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.call-btn-end { background: #EF4444; color: #fff; }
.call-btn-accept { background: #22C55E; color: #fff; }
.call-btn-mute { background: rgba(255,255,255,0.2); color: #fff; }

/* Incoming call toast */
.call-incoming-toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 3000; background: #1e293b; border-radius: 16px; padding: 16px 20px;
  display: flex; align-items: center; gap: 14px; box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.call-incoming-toast .call-info { color: #fff; }
.call-incoming-toast .call-info .call-label { font-size: 11px; color: #94a3b8; }
.call-incoming-toast .call-info .call-name { font-size: 15px; font-weight: 600; margin-top: 2px; }
.call-incoming-actions { display: flex; gap: 8px; }
.call-incoming-actions button { padding: 8px 16px; border-radius: 20px; border: none; font-size: 13px; cursor: pointer; font-weight: 600; }
.call-btn-reject { background: #EF4444; color: #fff; }
.call-btn-accept-sm { background: #22C55E; color: #fff; }

/* ======================== Nav Badge ======================== */
.nav-badge {
  position: absolute; top: 4px; right: 8px;
  min-width: 18px; height: 18px; line-height: 18px;
  background: #EF4444; color: #fff; border-radius: 9px;
  font-size: 10px; font-weight: 700; text-align: center; padding: 0 5px;
}
.nav-badge:empty { display: none; }
.nav-item { position: relative; }

/* ======================== Modal ======================== */
#friendsPage .modal { position: fixed; inset: 0; z-index: 1500; display: flex; align-items: center; justify-content: center; }
#friendsPage .modal.hidden { display: none; }
#friendsPage .modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
#friendsPage .modal-content {
  position: relative; background: #1e293b; border-radius: 16px;
  padding: 20px; max-width: 380px; width: 90%; max-height: 80vh; overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}
#friendsPage .modal-close { position: absolute; top: 12px; right: 14px; background: none; border: none; color: #94a3b8; font-size: 22px; cursor: pointer; }
#friendsPage .modal-content h2 { margin: 0 0 8px; font-size: 17px; color: #e2e8f0; }
#friendsPage .modal-desc { font-size: 13px; color: #94a3b8; margin: 0 0 16px; }

#friendsPage .input-group { margin-bottom: 14px; }
#friendsPage .input-group label { display: block; font-size: 12px; color: #94a3b8; margin-bottom: 4px; }
#friendsPage .phone-input-wrap { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; padding: 0 10px; }
#friendsPage .phone-prefix { color: #94a3b8; font-size: 13px; }
#friendsPage .phone-input-wrap input { flex: 1; padding: 8px 0; background: none; border: none; color: #fff; font-size: 15px; outline: none; }

#friendsPage .primary-btn {
  width: 100%; padding: 10px; background: #6366F1; color: #fff; border: none;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
#friendsPage .primary-btn:hover { opacity: 0.9; }
#friendsPage .primary-btn:disabled { opacity: 0.4; cursor: default; }

/* Friend request item */
#friendsPage .request-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
#friendsPage .request-item .friend-avatar { width: 40px; height: 40px; font-size: 15px; }
#friendsPage .request-item .friend-info { flex: 1; }
#friendsPage .request-actions { display: flex; gap: 6px; }
#friendsPage .request-actions button { padding: 6px 12px; border-radius: 6px; border: none; font-size: 12px; cursor: pointer; font-weight: 500; }
#friendsPage .btn-accept { background: #6366F1; color: #fff; }
#friendsPage .btn-reject { background: rgba(255,255,255,0.1); color: #94a3b8; }

/* Product picker */
#friendsPage .product-pick-item {
  display: flex; gap: 10px; padding: 10px; border-radius: 8px; cursor: pointer;
  align-items: center; border: 1px solid rgba(255,255,255,0.05); margin-bottom: 6px;
}
#friendsPage .product-pick-item:hover { background: rgba(255,255,255,0.05); }
#friendsPage .product-pick-img { width: 50px; height: 50px; border-radius: 6px; object-fit: cover; background: #0f172a; }
#friendsPage .product-pick-name { font-size: 13px; font-weight: 500; color: #e2e8f0; }
#friendsPage .product-pick-price { font-size: 13px; color: #F59E0B; font-weight: 600; }

/* Typing indicator */
#friendsPage .typing-indicator {
  font-size: 12px; color: #64748b; padding: 4px 14px; font-style: italic;
}
#friendsPage .typing-indicator:empty { display: none; }

/* Empty state */
#friendsPage .friends-empty { text-align: center; padding: 40px 20px; color: #64748b; font-size: 13px; }

/* Supply contact items */
#friendsPage .supply-contact-item .friend-avatar { background: #F59E0B; }
