/* ============================================================================
   HỘP THƯ HỖ TRỢ & GIAO DỊCH 2 CỘT (TinNhan.html) — THEME B: SANG SÁNG NĂNG ĐỘNG
   Palette: Frosted White Glass (rgba(255,255,255,0.92)) + Electric Blue -> Cyan (#2563EB -> #06B6D4)
   ============================================================================ */

:root {
  --tn-glass: rgba(255, 255, 255, 0.92);
  --tn-glass-soft: rgba(248, 250, 252, 0.88);
  --tn-border: #e2e8f0;
  --tn-text: #0f172a;
  --tn-muted: #64748b;
  --tn-primary: #2563eb;
  --tn-cyan: #06b6d4;
  --tn-gradient: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
}

/* ==================== OUTER WRAPPER & 2-COLUMN SHELL ==================== */
.tn-outer-wrap {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 20px 24px;
}

.tn-shell {
  width: 100%;
  height: calc(100dvh - 110px);
  min-height: 560px;
  background: var(--tn-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--tn-border);
  border-radius: 20px;
  box-shadow: 0 18px 46px -18px rgba(15, 23, 42, 0.14), 0 4px 14px rgba(37, 99, 235, 0.05);
  display: grid;
  grid-template-columns: minmax(300px, 32%) minmax(0, 1fr);
  overflow: hidden;
}

/* ==================== LEFT SIDEBAR (CONVERSATIONS) ==================== */
.tn-sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  border-right: 1px solid var(--tn-border);
  background: rgba(255, 255, 255, 0.62);
}

.tn-sidebar-top {
  padding: 18px 16px 14px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  flex-direction: column;
  gap: 11px;
  flex-shrink: 0;
}

.tn-sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tn-sidebar-title {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 55%, #0891b2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tn-total-unread {
  min-width: 24px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--tn-gradient);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px -3px rgba(37, 99, 235, 0.45);
}

.tn-admin-mode-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 11px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.10), rgba(6, 182, 212, 0.13));
  border: 1px solid rgba(37, 99, 235, 0.22);
  font-size: 12px;
  font-weight: 800;
  color: #1d4ed8;
}

.tn-admin-mode-sub {
  font-size: 11px;
  font-weight: 600;
  color: #0369a1;
}

.tn-search-wrap {
  position: relative;
  width: 100%;
}

.tn-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: #94a3b8;
  pointer-events: none;
}

.tn-search-input {
  width: 100%;
  padding: 9px 13px 9px 36px;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: var(--tn-text);
  font-size: 13.5px;
  outline: none;
  box-sizing: border-box;
  transition: all 0.16s ease;
}

.tn-search-input:focus {
  background: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.tn-filter-pills {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tn-filter-pill {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #475569;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

.tn-filter-pill:hover {
  border-color: #93c5fd;
  color: #1d4ed8;
}

.tn-filter-pill.active {
  background: var(--tn-gradient);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 6px 14px -5px rgba(37, 99, 235, 0.45);
}

.tn-pill-dot {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #ffffff;
  font-size: 10.5px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tn-filter-pill.active .tn-pill-dot {
  background: rgba(255, 255, 255, 0.28);
}

/* Conversation List Scroll Container */
.tn-convo-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tn-convo-list::-webkit-scrollbar,
.tn-messages-scroll::-webkit-scrollbar {
  width: 6px;
}

.tn-convo-list::-webkit-scrollbar-thumb,
.tn-messages-scroll::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.4);
  border-radius: 999px;
}

.tn-list-loading,
.tn-list-empty {
  text-align: center;
  padding: 28px 14px;
  color: var(--tn-muted);
  font-size: 13px;
  font-weight: 600;
}

.tn-list-section-label {
  padding: 6px 8px 2px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
}

/* Conversation Item */
.tn-convo-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: all 0.16s ease;
  position: relative;
}

.tn-convo-item:hover {
  background: rgba(239, 246, 255, 0.72);
}

.tn-convo-item.is-pinned-support {
  background: linear-gradient(135deg, rgba(239, 246, 255, 0.92), rgba(236, 254, 255, 0.88));
  border-color: rgba(59, 130, 246, 0.28);
  box-shadow: 0 6px 16px -10px rgba(37, 99, 235, 0.22);
}

.tn-convo-item.active {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.13), rgba(6, 182, 212, 0.11));
  border-color: rgba(37, 99, 235, 0.42);
}

.tn-convo-item.has-unread {
  background: rgba(239, 246, 255, 0.9);
}

.tn-convo-avatar-wrap {
  position: relative;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
}

.tn-convo-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #e2e8f0;
  background: #f1f5f9;
  display: block;
}

.tn-convo-item.is-pinned-support .tn-convo-avatar {
  border-color: #38bdf8;
}

.tn-online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #ffffff;
}

.tn-convo-body {
  flex: 1;
  min-width: 0;
}

.tn-convo-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.tn-convo-name-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  flex: 1;
}

.tn-convo-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--tn-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tn-cskh-pill {
  flex-shrink: 0;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--tn-gradient);
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.tn-convo-time {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
}

.tn-convo-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 3px;
}

.tn-convo-preview {
  font-size: 12.5px;
  color: var(--tn-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.tn-convo-item.has-unread .tn-convo-preview {
  color: #0f172a;
  font-weight: 700;
}

.tn-unread-badge {
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #2563eb;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ==================== RIGHT PANE (CHAT AREA) ==================== */
.tn-chat-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  min-width: 0;
  background: rgba(255, 255, 255, 0.45);
  position: relative;
}

.tn-welcome-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.tn-welcome-card {
  max-width: 420px;
  text-align: center;
  padding: 32px 26px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #e2e8f0;
  box-shadow: 0 12px 32px -14px rgba(15, 23, 42, 0.08);
}

.tn-welcome-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(6, 182, 212, 0.16));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
}

.tn-welcome-card h2 {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 850;
  color: var(--tn-text);
}

.tn-welcome-card p {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--tn-muted);
  line-height: 1.55;
}

.tn-btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 12px;
  border: none;
  background: var(--tn-gradient);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 20px -6px rgba(37, 99, 235, 0.48);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.tn-btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px -6px rgba(37, 99, 235, 0.56);
}

/* Active Chat Flex Column */
.tn-active-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* Chat Header */
.tn-chat-header {
  padding: 13px 18px;
  border-bottom: 1px solid var(--tn-border);
  background: rgba(255, 255, 255, 0.88);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.tn-mobile-back-btn {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #334155;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.tn-mobile-back-btn svg {
  width: 19px;
  height: 19px;
}

.tn-chat-partner {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  flex: 1;
}

.tn-partner-avatar-wrap {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}

.tn-partner-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #dbeafe;
  display: block;
}

.tn-partner-meta {
  min-width: 0;
  flex: 1;
}

.tn-partner-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tn-partner-name {
  margin: 0;
  font-size: 15.5px;
  font-weight: 850;
  color: var(--tn-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tn-role-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.tn-role-badge.is-admin {
  background: var(--tn-gradient);
  color: #ffffff;
  box-shadow: 0 3px 8px -3px rgba(37, 99, 235, 0.45);
}

.tn-role-badge.is-customer {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.tn-partner-status {
  margin-top: 2px;
  font-size: 12px;
  color: var(--tn-muted);
  font-weight: 500;
}

.tn-partner-status.is-online {
  color: #059669;
  font-weight: 700;
}

/* Messages Scroll Viewport */
.tn-messages-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tn-load-older-wrap {
  text-align: center;
  margin-bottom: 6px;
}

.tn-btn-older {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.tn-btn-older:hover {
  border-color: #2563eb;
  color: #2563eb;
}

.tn-messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tn-chat-empty-intro {
  margin: auto 0;
  text-align: center;
  padding: 28px 18px;
  color: var(--tn-muted);
  font-size: 13.5px;
}

.tn-chat-empty-intro strong {
  display: block;
  font-size: 15.5px;
  color: var(--tn-text);
  margin-bottom: 4px;
}

/* Message Row & Bubbles */
.tn-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 78%;
}

.tn-msg-row.is-me {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.tn-msg-row.is-them {
  align-self: flex-start;
}

.tn-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #e2e8f0;
  flex-shrink: 0;
  margin-bottom: 18px;
}

.tn-msg-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.tn-msg-row.is-me .tn-msg-col {
  align-items: flex-end;
}

.tn-msg-row.is-them .tn-msg-col {
  align-items: flex-start;
}

.tn-bubble {
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}

/* Sent: Blue -> Cyan Gradient */
.tn-msg-row.is-me .tn-bubble {
  background: var(--tn-gradient);
  color: #ffffff;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 6px 16px -8px rgba(37, 99, 235, 0.55);
}

/* Received: Clean Light Slate */
.tn-msg-row.is-them .tn-bubble {
  background: #f1f5f9;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-radius: 18px 18px 18px 4px;
}

.tn-bubble.is-recalled {
  background: #f8fafc !important;
  color: #94a3b8 !important;
  border: 1px dashed #cbd5e1 !important;
  font-style: italic;
  box-shadow: none !important;
}

.tn-bubble.is-image-only {
  padding: 4px;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.tn-msg-image {
  display: block;
  max-width: min(320px, 68vw);
  max-height: 300px;
  border-radius: 13px;
  object-fit: cover;
  cursor: zoom-in;
  border: 1px solid rgba(226, 232, 240, 0.9);
}

.tn-msg-text-with-img {
  margin-top: 8px;
}

.tn-msg-time {
  font-size: 11px;
  color: #94a3b8;
  padding: 0 4px;
}

/* Typing indicator */
.tn-typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  align-self: flex-start;
}

.tn-typing-dots {
  display: inline-flex;
  gap: 3px;
}

.tn-typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2563eb;
  animation: tnBounce 1.1s infinite ease-in-out;
}

.tn-typing-dots i:nth-child(2) { animation-delay: 0.16s; }
.tn-typing-dots i:nth-child(3) { animation-delay: 0.32s; }

@keyframes tnBounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.45; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* Quick Prompts (1-Tap Starter Chips) */
.tn-quick-prompts {
  padding: 10px 16px;
  border-top: 1px solid #f1f5f9;
  background: rgba(248, 250, 252, 0.92);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.tn-quick-label {
  font-size: 12px;
  font-weight: 800;
  color: #64748b;
}

.tn-quick-chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

.tn-quick-chip:hover {
  background: var(--tn-gradient);
  color: #ffffff;
  border-color: transparent;
}

/* Image Preview Bar */
.tn-image-preview-bar {
  padding: 10px 16px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.tn-preview-thumb-wrap {
  position: relative;
  width: 58px;
  height: 58px;
  flex-shrink: 0;
}

.tn-preview-thumb-wrap img {
  width: 58px;
  height: 58px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid #cbd5e1;
}

.tn-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: #ef4444;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.tn-preview-note {
  font-size: 12.5px;
  color: #475569;
  font-weight: 600;
}

/* Composer Footer */
.tn-composer {
  padding: 12px 16px;
  border-top: 1px solid var(--tn-border);
  background: rgba(255, 255, 255, 0.94);
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.tn-attach-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #475569;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.16s ease;
}

.tn-attach-btn svg {
  width: 20px;
  height: 20px;
}

.tn-attach-btn:hover {
  border-color: #2563eb;
  color: #2563eb;
  background: #eff6ff;
}

.tn-message-input {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  padding: 10px 15px;
  border-radius: 14px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: var(--tn-text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.45;
  resize: none;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.tn-message-input:focus {
  background: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.tn-send-btn {
  height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  border: none;
  background: var(--tn-gradient);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 8px 18px -6px rgba(37, 99, 235, 0.48);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.tn-send-btn svg {
  width: 16px;
  height: 16px;
}

.tn-send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.tn-send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Lightbox */
.tn-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(6px);
  z-index: 11500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}

.tn-lightbox img {
  max-width: min(960px, 95vw);
  max-height: 88vh;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
  object-fit: contain;
}

/* ==================== MOBILE 2-SCREEN FLOW (<= 768px) ==================== */
@media (max-width: 768px) {
  .tn-outer-wrap {
    padding: 0 0 96px;
  }

  .tn-shell {
    height: calc(100dvh - 156px);
    min-height: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    grid-template-columns: 1fr;
  }

  .tn-sidebar {
    border-right: none;
  }

  /* Default mobile view: show conversation list, hide chat pane */
  .tn-shell:not(.is-chat-open) .tn-chat-pane {
    display: none;
  }

  /* Active mobile chat view: hide list, show chat pane with Back button */
  .tn-shell.is-chat-open .tn-sidebar {
    display: none;
  }

  .tn-shell.is-chat-open .tn-chat-pane {
    display: flex;
  }

  .tn-mobile-back-btn {
    display: inline-flex;
  }

  .tn-msg-row {
    max-width: 88%;
  }

  .tn-composer {
    padding: 10px 12px;
  }

  .tn-send-btn span {
    display: none;
  }

  .tn-send-btn {
    width: 42px;
    padding: 0;
  }
}


/* ===== UNIFIED SVG ICON ALIGNMENT (js/dq-icons.js) ===== */
.tn-welcome-icon {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  color: #2563eb;
}

.tn-role-badge,
.tn-quick-chip,
.tn-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tn-btn-primary {
  justify-content: center;
}

.tn-chat-empty-intro strong {
  justify-content: center;
}
