/* ─── Reset & Base ─────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #007AFF;
  --primary-light: #4DA3FF;
  --primary-dim: #CCE4FF;
  --primary-dark: #0055CC;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --surface2: #F9FAFC;
  --bubble-in: #FFFFFF;
  --bubble-out: #007AFF;
  --bubble-in-text: #111827;
  --bubble-out-text: #FFFFFF;
  --text: #111827;
  --text-sub: #4B5563;
  --text-muted: #9CA3AF;
  --border: #E5E7EB;
  --shadow: rgba(0, 0, 0, 0.05);
  --shadow-card: rgba(0, 0, 0, 0.04);
  --online: #10B981;
  --offline: #9CA3AF;
  --unread: #EF4444;
  --radius: 18px;
  --radius-sm: 12px;
  --header-h: 64px;
  --input-h: 72px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html,
body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* ─── Layout ────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  overflow: hidden;
  position: relative;
}

/* ─── Header ────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  min-height: var(--header-h);
  background: rgba(25, 25, 28, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  border-bottom: 0.5px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.header-back {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s;
  flex-shrink: 0;
}

.header-back:hover {
  background: rgba(255, 255, 255, 0.3);
}

.header-back svg {
  width: 20px;
  height: 20px;
}

.header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
}

.header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-name {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.header-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
  margin-top: 2px;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.3);
}

.header-status .dot.offline {
  background: rgba(255, 255, 255, 0.4);
  box-shadow: none;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.header-btn svg {
  width: 18px;
  height: 18px;
}

/* ─── Messages Area ──────────────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(0, 122, 255, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(0, 85, 204, 0.05) 0%, transparent 60%),
    var(--bg);
}

.messages-area::-webkit-scrollbar {
  width: 4px;
}

.messages-area::-webkit-scrollbar-track {
  background: transparent;
}

.messages-area::-webkit-scrollbar-thumb {
  background: var(--primary-dim);
  border-radius: 4px;
}

/* ─── Date Separator ────────────────────────────────────────── */
.date-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 8px;
  color: var(--text-muted);
  font-size: 11px;
}

.date-sep::before,
.date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.date-sep span {
  background: var(--bg);
  padding: 0 8px;
  border-radius: 10px;
}

/* ─── Message Row ────────────────────────────────────────────── */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: msg-in 0.25s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg-row.outgoing {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msg-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 72%;
}

.msg-row.outgoing .msg-group {
  align-items: flex-end;
}

.msg-sender-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 2px;
  padding: 0 4px;
}

.bubble {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  word-wrap: break-word;
  position: relative;
  max-width: 100%;
}

.msg-row.incoming .bubble {
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 6px var(--shadow-card);
}

.msg-row.outgoing .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 122, 255, 0.3);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  padding: 0 4px;
}

.msg-row.outgoing .msg-meta {
  justify-content: flex-end;
}

.msg-time {
  font-size: 10.5px;
  color: var(--text-muted);
}

.msg-row.outgoing .msg-time {
  color: rgba(255, 255, 255, 0.6);
}

.msg-tick {
  display: flex;
  align-items: center;
  color: var(--text-muted);
}

.msg-tick.read {
  color: var(--primary);
}

.msg-tick svg {
  width: 14px;
  height: 14px;
}

/* ─── Typing Indicator ───────────────────────────────────────── */
.typing-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msg-in 0.2s ease both;
}

.typing-bubble {
  background: var(--bubble-in);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  box-shadow: 0 1px 6px var(--shadow-card);
  display: flex;
  align-items: center;
  gap: 5px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }

  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ─── Empty State ────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 24px;
  text-align: center;
  gap: 12px;
  pointer-events: none;
}

.empty-state .icon {
  font-size: 52px;
  line-height: 1;
  color: var(--primary);
  opacity: 0.8;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.empty-state p {
  font-size: 14px;
  color: var(--text-sub);
  max-width: 260px;
  line-height: 1.5;
}

/* ─── Input Bar ──────────────────────────────────────────────── */
.input-bar {
  min-height: var(--input-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.03);
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

.attach-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  font-size: 22px;
}

.attach-btn:hover {
  color: var(--primary);
  background: var(--border);
}

.input-wrap {
  flex: 1;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.msg-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  padding: 10px 14px;
  resize: none;
  max-height: 120px;
  min-height: 44px;
  color: var(--text);
}

.msg-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 10px rgba(0, 122, 255, 0.35);
  font-size: 20px;
}

.send-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.send-btn:active {
  transform: scale(0.93);
}

.send-btn:disabled {
  background: var(--text-muted);
  box-shadow: none;
  cursor: default;
  transform: none;
}

/* ─── File Attachment Preview ────────────────────────────────── */
.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
}

.msg-file-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.msg-file-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.msg-file-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.msg-file-size {
  font-size: 11px;
  opacity: 0.8;
}

.msg-image {
  max-width: 240px;
  border-radius: 12px;
  display: block;
  cursor: pointer;
}

/* ─── Sound Toggle ───────────────────────────────────────────── */
.sound-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-sub);
  flex-shrink: 0;
  transition: all 0.15s;
}

.sound-btn:hover {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
}

.sound-btn.muted {
  color: var(--text-muted);
}

.sound-btn svg {
  width: 18px;
  height: 18px;
}



/* ─── Toast Notification ─────────────────────────────────────── */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px) scale(0.95);
  background: rgba(30, 30, 30, 0.85);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 12px 24px;
  border-radius: 100px;
  z-index: 9999;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.1);
  pointer-events: none;
  white-space: nowrap;
  letter-spacing: -0.2px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* ─── Admin Layout ───────────────────────────────────────────── */
.admin-app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 2px 0 12px rgba(0, 40, 120, 0.06);
}

.sidebar-header {
  height: var(--header-h);
  background: rgba(25, 25, 28, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 0.5px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  color: #fff;
}

.sidebar-header .logo {
  font-size: 22px;
  color: var(--primary-light);
}

.sidebar-header .title {
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  flex: 1;
}

.sidebar-header .badge-total {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 10px;
}

.sidebar-search {
  padding: 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.search-input-wrap {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 8px;
}

.search-input-wrap:focus-within {
  border-color: var(--primary);
}

.search-input-wrap svg {
  color: var(--text-muted);
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

.search-inp {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  padding: 9px 0;
  color: var(--text);
  font-family: var(--font);
}

.search-inp::placeholder {
  color: var(--text-muted);
}

.sidebar-tabs {
  display: flex;
  padding: 8px 12px;
  gap: 6px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 7px 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  transition: all 0.15s;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.conv-list::-webkit-scrollbar {
  width: 4px;
}

.conv-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.conv-item:hover {
  background: var(--surface2);
}

.conv-item.active {
  background: var(--primary-dim);
}

.conv-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.conv-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  border: 2px solid var(--primary-dim);
}

.conv-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--online);
  border: 2px solid var(--surface);
}

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

.conv-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-preview {
  font-size: 13px;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conv-preview.unread-preview {
  color: var(--text);
  font-weight: 500;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.conv-time {
  font-size: 11px;
  color: var(--text-muted);
}

.conv-badge {
  background: var(--unread);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.conv-closed-badge {
  background: var(--text-muted);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 8px;
}

/* ─── Admin Chat Panel ───────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.no-conv-selected {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 14px;
  text-align: center;
  padding: 40px;
  color: var(--text-sub);
}

.no-conv-selected .big-icon {
  font-size: 56px;
  animation: float 3s ease-in-out infinite;
}

.no-conv-selected h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.no-conv-selected p {
  font-size: 14px;
  max-width: 240px;
  line-height: 1.5;
}

/* Admin header with close button */
.admin-chat-header {
  height: var(--header-h);
  background: rgba(25, 25, 28, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  color: #fff;
  border-bottom: 0.5px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.close-conv-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 20px;
  padding: 6px 12px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-left: auto;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.close-conv-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.close-conv-btn svg {
  width: 14px;
  height: 14px;
}

/* ─── Responsive – Mobile ────────────────────────────────────── */
@media (max-width: 640px) {
  .admin-app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    position: absolute;
    z-index: 20;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar.hidden {
    transform: translateX(-100%);
  }

  .chat-panel {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    position: absolute;
    z-index: 10;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .chat-panel.hidden {
    transform: translateX(100%);
  }

  .msg-group {
    max-width: 82%;
  }

  .bubble {
    font-size: 15px;
  }

  .header-back {
    display: flex;
  }
}

@media (min-width: 641px) {
  .header-back.mobile-only {
    display: none;
  }
}

/* ─── Animations ─────────────────────────────────────────────── */
.fade-in {
  animation: fadeIn 0.3s ease both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.slide-up {
  animation: slideUp 0.35s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ─── Status Pill ────────────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-sub);
  margin: 6px auto;
  box-shadow: 0 1px 4px var(--shadow-card);
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online);
}

.status-pill .dot.offline {
  background: var(--offline);
}