/* ════════════════════════════════════════════
   TANIDIK Mesajlar Premium
   WhatsApp / Telegram inspired · noir + gold
   ════════════════════════════════════════════ */

/* ── Page base ─────────────────────────────── */
.msg-body {
  background: #050505;
  overflow: hidden;
}

.msg-page {
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
  padding: 0 !important;
  max-width: 100% !important;
}

/* ── Two-panel layout ──────────────────────── */
.msg-layout {
  display: flex;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Reset dashboard-section styles */
.msg-inbox.messages-inbox.dashboard-section,
.msg-chat.conversation-panel.dashboard-section {
  border-radius: 0 !important;
  border: none !important;
  padding: 0 !important;
  background: transparent !important;
}

/* ── INBOX PANEL ───────────────────────────── */
.msg-inbox {
  width: 100%;
  flex-shrink: 0;
  background: #08080c;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

/* ── Inbox topbar ──────────────────────────── */
.msg-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(0.9rem + env(safe-area-inset-top, 0px)) 1rem 0.7rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  background: rgba(5, 5, 8, 0.96);
  backdrop-filter: blur(20px);
  position: relative;
}

/* Gold top line */
.msg-topbar::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1.5px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(201,162,39,0.5) 30%,
    rgba(245,208,96,0.85) 50%,
    rgba(201,162,39,0.5) 70%,
    transparent 100%
  );
}

.msg-topbar-title {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  margin: 0;
}

.msg-topbar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(201, 162, 39, 0.08);
  border: 1px solid rgba(201, 162, 39, 0.22);
  color: #c9a227;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  padding: 0;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.msg-topbar-btn:hover {
  background: rgba(201, 162, 39, 0.16);
}

/* ── Search bar ────────────────────────────── */
.msg-search-wrap {
  position: relative;
  padding: 0.55rem 0.75rem;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.msg-search-ico {
  position: absolute;
  left: 1.35rem;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
}

.msg-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.6rem 0.75rem 0.6rem 2.4rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-size: 0.85rem;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}

.msg-search-input::placeholder { color: rgba(255,255,255,0.28); }

.msg-search-input:focus {
  outline: none;
  border-color: rgba(201, 162, 39, 0.35);
  background: rgba(255, 255, 255, 0.07);
}

/* ── User search panel (new message) ──────── */
.msg-user-search {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

.msg-user-search-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
}

.msg-user-search-inner svg { color: rgba(255,255,255,0.3); flex-shrink: 0; }

.msg-user-search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 0.85rem;
  font-family: inherit;
  padding: 0.6rem 0;
  outline: none;
}

.msg-user-search-input::placeholder { color: rgba(255,255,255,0.28); }

.msg-user-results { display: flex; flex-direction: column; gap: 2px; }

/* ── Refresh button (hidden, JS only) ─────── */
.msg-refresh-btn {
  display: none !important;
}

/* ── Thread list ───────────────────────────── */
.msg-threads {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 100px; /* bottom nav space */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

.msg-threads::-webkit-scrollbar { width: 3px; }
.msg-threads::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* JS renders .message-thread as <a> links */
.message-thread {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  padding: 10px 14px !important;
  text-decoration: none !important;
  border-bottom: 1px solid rgba(255,255,255,0.04) !important;
  transition: background 0.12s !important;
  cursor: pointer !important;
  position: relative !important;
  -webkit-tap-highlight-color: transparent !important;
}

.message-thread:hover,
.message-thread.active {
  background: rgba(255, 255, 255, 0.045) !important;
}

.message-thread.active::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, #c9a227, #f5d060);
  border-radius: 0 2px 2px 0;
}

/* Avatar */
.message-thread-avatar {
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  border-radius: 50% !important;
  background: linear-gradient(135deg, #1a1000, #2a1e00) !important;
  border: 1.5px solid rgba(201, 162, 39, 0.22) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 0.9rem !important;
  font-weight: 700 !important;
  color: #c9a227 !important;
  flex-shrink: 0 !important;
}

.message-thread-avatar--ai {
  background: linear-gradient(135deg, #0d0018, #180030) !important;
  border-color: rgba(140, 80, 255, 0.35) !important;
  color: #a060ff !important;
  font-size: 1.1rem !important;
}

/* Thread content */
.message-thread-body {
  flex: 1 !important;
  min-width: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 3px !important;
}

.message-thread-top {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 6px !important;
}

.message-thread-title {
  font-size: 0.88rem !important;
  font-weight: 600 !important;
  color: rgba(255, 255, 255, 0.9) !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  flex: 1 !important;
  min-width: 0 !important;
}

.message-thread-time {
  font-size: 0.68rem !important;
  color: rgba(255, 255, 255, 0.32) !important;
  white-space: nowrap !important;
  flex-shrink: 0 !important;
}

.message-thread-preview {
  font-size: 0.78rem !important;
  color: rgba(255, 255, 255, 0.38) !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  line-height: 1.35 !important;
  margin: 0 !important;
}

/* Unread badge */
.message-thread.unread .message-thread-title {
  color: #fff !important;
}

.message-thread.unread .message-thread-preview {
  color: rgba(255, 255, 255, 0.62) !important;
  font-weight: 500 !important;
}

.message-nav-unread-badge,
.message-thread .bnav-badge {
  min-width: 18px !important;
  height: 18px !important;
  border-radius: 999px !important;
  background: linear-gradient(135deg, #f8d36b, #c99422) !important;
  color: #0a0700 !important;
  font-size: 9px !important;
  font-weight: 800 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 4px !important;
}

/* ── CHAT PANEL ────────────────────────────── */
.msg-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #050505;
  height: 100%;
  overflow: hidden;
  position: absolute;
  inset: 0;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 10;
}

/* ── Chat header ───────────────────────────── */
.msg-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 0.75rem 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(5, 5, 8, 0.96);
  backdrop-filter: blur(20px);
  flex-shrink: 0;
  position: relative;
}

.msg-chat-header::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1.5px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(201,162,39,0.4) 30%,
    rgba(245,208,96,0.7) 50%,
    rgba(201,162,39,0.4) 70%,
    transparent 100%
  );
}

.msg-back-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.msg-back-btn:hover { background: rgba(255,255,255,0.1); }

/* Context header (JS renders user info here) */
.msg-chat-info {
  flex: 1;
  min-width: 0;
  padding: 0;
}

.msg-chat-info strong,
.conversation-context-header strong {
  display: block;
  font-size: 0.9rem !important;
  font-weight: 700 !important;
  color: rgba(255, 255, 255, 0.92) !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

.msg-chat-info span,
.msg-chat-info p,
.conversation-context-header span {
  font-size: 0.72rem !important;
  color: rgba(255, 255, 255, 0.38) !important;
}

.msg-chat-opts {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: color 0.15s;
}

.msg-chat-opts:hover { color: rgba(255,255,255,0.75); }

/* ── Empty state ───────────────────────────── */
.msg-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 2rem;
  text-align: center;
  gap: 0.75rem;
}

.msg-empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(201, 162, 39, 0.06);
  border: 1px solid rgba(201, 162, 39, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.msg-empty-title {
  font-size: 1rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
  margin: 0;
}

.msg-empty-sub {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.32);
  line-height: 1.55;
  margin: 0;
  max-width: 240px;
}

/* ── Messages area ─────────────────────────── */
.msg-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

.msg-messages::-webkit-scrollbar { width: 3px; }
.msg-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* Message bubble rows */
.message-bubble-with-avatar {
  display: flex !important;
  align-items: flex-end !important;
  gap: 8px !important;
  max-width: 100% !important;
  margin-bottom: 2px !important;
}

.message-bubble-with-avatar.message-bubble-row--own {
  flex-direction: row-reverse !important;
}

.message-bubble-avatar {
  width: 28px !important;
  height: 28px !important;
  min-width: 28px !important;
  border-radius: 50% !important;
  background: linear-gradient(135deg, #1a1000, #2a1e00) !important;
  border: 1px solid rgba(201,162,39,0.2) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 0.7rem !important;
  font-weight: 700 !important;
  color: #c9a227 !important;
  flex-shrink: 0 !important;
  align-self: flex-end !important;
  margin-bottom: 2px !important;
}

/* Bubbles */
.message-bubble {
  max-width: 72% !important;
  padding: 8px 12px !important;
  border-radius: 18px !important;
  position: relative !important;
  word-break: break-word !important;
  line-height: 1.45 !important;
}

/* Their bubble — dark glass, left side */
.message-bubble.message-bubble-content:not(.message-bubble--own) {
  background: rgba(255, 255, 255, 0.07) !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-bottom-left-radius: 4px !important;
  color: rgba(255, 255, 255, 0.88) !important;
}

/* Own bubble — gold gradient, right side */
.message-bubble.message-bubble--own {
  background: linear-gradient(135deg, #9a7010 0%, #c9a227 40%, #f0c84a 100%) !important;
  border: none !important;
  border-bottom-right-radius: 4px !important;
  color: #0a0700 !important;
}

.message-bubble.message-bubble--grouped {
  border-radius: 12px !important;
}

.message-bubble p {
  margin: 0 !important;
  font-size: 0.88rem !important;
}

.message-sender-label {
  display: block !important;
  font-size: 0.68rem !important;
  font-weight: 700 !important;
  color: rgba(201, 162, 39, 0.7) !important;
  margin-bottom: 3px !important;
  text-transform: uppercase !important;
  letter-spacing: 0.05em !important;
}

.message-bubble--own .message-sender-label {
  color: rgba(0, 0, 0, 0.45) !important;
}

.message-meta {
  display: block !important;
  font-size: 0.62rem !important;
  color: rgba(255, 255, 255, 0.3) !important;
  margin-top: 4px !important;
  text-align: right !important;
}

.message-bubble--own .message-meta {
  color: rgba(0, 0, 0, 0.38) !important;
}

/* Actions (copy button) */
.message-actions {
  margin-top: 5px !important;
}

.message-action-btn {
  font-size: 0.65rem !important;
  color: rgba(255, 255, 255, 0.28) !important;
  background: transparent !important;
  border: none !important;
  cursor: pointer !important;
  padding: 0 !important;
  font-family: inherit !important;
  transition: color 0.15s !important;
}

.message-action-btn:hover { color: rgba(255,255,255,0.55) !important; }

.message-bubble--own .message-action-btn {
  color: rgba(0,0,0,0.28) !important;
}

/* ── Typing indicator ──────────────────────── */
.msg-typing {
  padding: 0 16px 6px;
  font-size: 0.75rem;
  color: rgba(201, 162, 39, 0.55);
  min-height: 20px;
  flex-shrink: 0;
}

/* ── AI Quick prompts ──────────────────────── */
.msg-ai-prompts {
  padding: 0.5rem 0.75rem 0.4rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.msg-ai-label {
  display: block;
  font-size: 0.65rem;
  color: rgba(201, 162, 39, 0.55);
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 0.45rem;
}

.msg-ai-chips {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.msg-ai-chips::-webkit-scrollbar { display: none; }

.msg-ai-chip {
  border: 1px solid rgba(201, 162, 39, 0.22) !important;
  background: rgba(201, 162, 39, 0.06) !important;
  color: rgba(255, 255, 255, 0.65) !important;
  border-radius: 999px !important;
  padding: 0.3rem 0.75rem !important;
  font-size: 0.75rem !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  font-family: inherit !important;
  transition: background 0.15s, border-color 0.15s !important;
  flex-shrink: 0 !important;
}

.msg-ai-chip:hover {
  background: rgba(201, 162, 39, 0.14) !important;
  border-color: rgba(201, 162, 39, 0.4) !important;
  color: #f5d060 !important;
}

/* ── Compose bar ───────────────────────────── */
.msg-compose {
  padding: 0.55rem 0.75rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(5, 5, 8, 0.96);
  backdrop-filter: blur(20px);
  flex-shrink: 0;
}

.msg-compose-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 24px;
  padding: 6px 6px 6px 10px;
  transition: border-color 0.18s;
}

.msg-compose-row:focus-within {
  border-color: rgba(201, 162, 39, 0.35);
}

/* Attach button */
.msg-attach-btn {
  width: 30px;
  height: 30px;
  min-width: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.35);
  cursor: pointer;
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 2px;
}

.msg-attach-btn:hover { color: rgba(201,162,39,0.7); }

/* Textarea */
.msg-textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 0.88rem;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.4;
  padding: 4px 0;
  max-height: 120px;
  overflow-y: auto;
  scrollbar-width: none;
  min-height: 22px;
}

.msg-textarea::-webkit-scrollbar { display: none; }
.msg-textarea::placeholder { color: rgba(255,255,255,0.28); }

/* Send button */
.msg-send-btn {
  width: 34px !important;
  height: 34px !important;
  min-width: 34px !important;
  border-radius: 50% !important;
  background: linear-gradient(135deg, #b8911f, #f0c84a) !important;
  border: none !important;
  color: #0a0700 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  padding: 0 !important;
  flex-shrink: 0 !important;
  align-self: flex-end !important;
  transition: opacity 0.15s, transform 0.1s !important;
  box-shadow: 0 2px 10px rgba(201, 162, 39, 0.35) !important;
}

.msg-send-btn:hover { opacity: 0.88 !important; }
.msg-send-btn:active { transform: scale(0.92) !important; }

/* ── Mobile: chat-active toggle ────────────── */
@media (max-width: 768px) {
  .msg-layout.chat-active .msg-inbox {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .msg-layout.chat-active .msg-chat {
    transform: translateX(0) !important;
  }
}

/* ── Desktop: side-by-side ─────────────────── */
@media (min-width: 769px) {
  .msg-inbox {
    width: 320px;
    flex-shrink: 0;
  }

  .msg-chat {
    position: static !important;
    transform: none !important;
    flex: 1;
  }

  .msg-back-btn {
    display: none;
  }
}

/* ── AI concierge bubble (existing class) ──── */
.ai-concierge-loading-bubble {
  background: rgba(140, 80, 255, 0.1) !important;
  border: 1px solid rgba(140, 80, 255, 0.2) !important;
  border-radius: 18px !important;
}

/* Attachment thumbnail */
.message-attachment-img {
  max-width: 200px !important;
  max-height: 200px !important;
  border-radius: 10px !important;
  margin-top: 6px !important;
  display: block !important;
  object-fit: cover !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
}

/* Mobile stabilization: keep chat/input usable above the app chrome. */
@media (max-width: 768px) {
  .msg-body {
    width: 100%;
    min-width: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .msg-page,
  .msg-layout {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 100svh !important;
    height: 100dvh !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  .msg-layout {
    display: flex !important;
  }

  .msg-inbox,
  .msg-chat {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .msg-inbox {
    height: 100% !important;
  }

  .msg-threads {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px));
  }

  .message-thread,
  .message-thread-body,
  .message-thread-top,
  .message-thread-title,
  .message-thread-preview,
  .message-thread-meta {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .msg-chat {
    position: fixed !important;
    inset: 0 !important;
    height: 100svh !important;
    height: 100dvh !important;
    z-index: 900 !important;
    transform: translateX(100%) !important;
  }

  .msg-layout.chat-active .msg-chat {
    transform: translateX(0) !important;
  }

  .msg-chat-header,
  .msg-chat-info {
    min-width: 0;
  }

  .msg-messages {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .message-bubble-with-avatar {
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .message-bubble {
    max-width: min(82vw, 320px) !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  .msg-ai-prompts {
    flex-shrink: 0;
    max-height: 96px;
    overflow: hidden;
  }

  .msg-compose {
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    padding-bottom: calc(0.55rem + env(safe-area-inset-bottom, 0px));
  }

  .msg-compose-row {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .msg-textarea {
    min-width: 0;
    font-size: 16px;
  }

  .msg-send-btn,
  .msg-attach-btn {
    flex-shrink: 0;
  }
}
