/* ── Zalo Chat Dashboard — Style ─────────────────────── */

:root {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-chat: #ffffff;
  --bg-hover: #f8fafc;
  --bg-active: #e2e8f0;
  --accent: #0068FF;
  --accent-hover: #005CE6;
  --accent-glow: rgba(0, 104, 255, 0.2);
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bubble-in: #f1f5f9;
  --bubble-out: #3b82f6;
  --border: #e2e8f0;
  --border-light: #f8fafc;
  --radius: 12px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1);
  --transition: all 0.2s ease-in-out;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}



/* ── App Container ──────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  position: relative;
  z-index: 10;
  background: var(--bg-primary);
  box-shadow: 0 0 24px rgba(0,0,0,0.05);
}

/* ── Status Bar ─────────────────────────────────────── */
#status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.status-left .logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  color: var(--accent);
}

.logo-text {
  font-weight: 700;
  font-size: 18px;
  color: #0f172a;
}

.status-center {
  display: flex;
  align-items: center;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  border-radius: 20px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  transition: var(--transition);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
  animation: pulse-green 2s infinite;
}

.status-dot.disconnected {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.status-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-value {
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Main Container ─────────────────────────────────── */
.main-container {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
  gap: 16px;
}

/* ── Sidebar ────────────────────────────────────────── */
#sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  position: relative;
  z-index: 5;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  transition: var(--transition);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.search-icon {
  font-size: 14px;
  opacity: 0.6;
}

.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
}

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

/* Tabs */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg-hover);
}

/* Content */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.list-loading {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Contact/Group items */
.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 1px solid var(--border);
}

.contact-item:hover {
  background: var(--bg-hover);
}

.contact-item.active {
  background: var(--bg-active);
  border-left: 3px solid var(--accent);
}

.contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  color: #fff;
}

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

.contact-name {
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-id {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-badge {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
  display: none;
}

.contact-item.has-new .contact-badge {
  display: block;
  animation: pulse-green 1.5s infinite;
}

/* Sidebar toggle (mobile) */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  z-index: 100;
  box-shadow: var(--shadow);
}

/* ── Chat Area ──────────────────────────────────────── */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-chat);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* Empty state */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.chat-empty h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.chat-empty p {
  color: var(--text-secondary);
  font-size: 14px;
}

.empty-hint {
  margin-top: 8px;
  font-size: 13px !important;
  color: var(--text-muted) !important;
}

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: transparent;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-target-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
}

.chat-target-name {
  font-weight: 600;
  font-size: 15px;
}

.chat-target-id {
  font-size: 12px;
  color: var(--text-muted);
}

.chat-target-details {
  display: flex;
  flex-direction: column;
}

.chat-actions {
  display: flex;
  gap: 8px;
}

/* Messages container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  position: relative;
  scroll-behavior: smooth;
}

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

/* Message bubble */
.message-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
  animation: fadeInUp 0.25s ease;
  word-wrap: break-word;
  word-break: break-word;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-bubble.incoming {
  background: var(--bubble-in);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.message-bubble.outgoing {
  background: var(--bubble-out);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.message-bubble.outgoing .message-sender {
  color: rgba(255,255,255,0.8);
}

.message-text {
  white-space: pre-wrap;
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.message-bubble.outgoing .message-time {
  color: rgba(255,255,255,0.6);
}

.message-media {
  margin-top: 6px;
  font-size: 12px;
  color: var(--accent);
}

.message-media a {
  color: inherit;
  text-decoration: underline;
}

/* Date separator */
.date-separator {
  text-align: center;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 12px;
  position: relative;
}

.date-separator::before,
.date-separator::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 60px);
  height: 1px;
  background: var(--border);
}

.date-separator::before { left: 0; }
.date-separator::after { right: 0; }

/* New messages indicator */
.new-messages-indicator {
  position: sticky;
  bottom: 8px;
  align-self: center;
  padding: 6px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 5;
  animation: fadeInUp 0.3s ease;
  text-align: center;
  margin: 0 auto;
  display: block;
  width: fit-content;
}

/* ── Input Bar ──────────────────────────────────────── */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

.input-wrapper textarea {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  transition: var(--transition);
}

.input-wrapper textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

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

.btn-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

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

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

/* ── Buttons ────────────────────────────────────────── */
.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-icon:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}

.input-attach {
  width: 42px;
  height: 42px;
}

.btn {
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
}

/* ── Modal ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 90%;
  max-width: 480px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
  backdrop-filter: var(--glass-blur);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ── Toast ──────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 60px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  animation: slideInRight 0.3s ease;
  box-shadow: var(--shadow);
  max-width: 360px;
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast-success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--success);
}

.toast-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger);
}

.toast-info {
  background: rgba(0, 104, 255, 0.15);
  border: 1px solid rgba(0, 104, 255, 0.3);
  color: #60a5fa;
}

/* ── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.25);
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: -280px;
    top: 52px;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow);
  }

  #sidebar.open {
    left: 0;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .message-bubble {
    max-width: 85%;
  }

  .status-right .stat-label {
    display: none;
  }
}

@media (max-width: 480px) {
  #status-bar {
    padding: 0 12px;
    height: 48px;
  }

  .logo-text {
    font-size: 14px;
  }

  .stat-item {
    font-size: 12px;
  }
}

/* ── Login Screen ─────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 13, 0.6);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  width: 90%;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(24px) saturate(150%);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5);
  animation: scaleIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.login-logo {
  font-size: 48px;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 12px var(--accent-glow));
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.login-qr-container {
  margin: 20px 0;
}

.login-qr-img {
  width: 220px;
  height: 220px;
  border-radius: var(--radius);
  border: 2px solid var(--border-light);
  background: #fff;
  padding: 8px;
  margin-bottom: 12px;
}

.login-qr-hint {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

.login-url-container {
  margin: 16px 0;
}

.login-url-container a {
  display: inline-block;
  text-decoration: none;
}

.login-status {
  min-height: 24px;
  font-size: 13px;
  color: var(--warning);
  margin: 12px 0;
}

.login-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.btn-login {
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius);
}

.btn-login:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-cancel-login {
  padding: 10px 20px;
}

.login-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn-logout {
  color: var(--danger) !important;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.1) !important;
}

/* Sync button */
#btn-sync {
  transition: var(--transition);
}

#btn-sync.syncing {
  animation: spin 1s linear infinite;
  color: var(--accent) !important;
}

#btn-sync.done {
  color: var(--success) !important;
}

/* Chat item in sidebar */
.chat-item-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.contact-item .contact-type {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── User Profile Sticky (Sidebar Bottom) ──────────────── */
.user-profile-sticky {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex !important;
  align-items: center;
  gap: 12px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.02);
  z-index: 10;
}
.user-profile-sticky.hidden {
  display: none !important;
}

.user-avatar-wrap {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-active);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.user-avatar-wrap i {
  color: var(--text-muted);
  width: 20px;
  height: 20px;
}

.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

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

.user-id {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
