/* ============================================================
   Zalo Dashboard — Chat App Style (3-column layout)
   Icon nav | Sidebar conversations | Chat main
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ==================== Design Tokens ==================== */
:root {
  /* Zalo blue palette */
  --zd-blue: #0068ff;
  --zd-blue-hover: #0055d4;
  --zd-blue-soft: rgba(0, 104, 255, 0.08);
  --zd-blue-glow: rgba(0, 104, 255, 0.2);
  /* Surfaces */
  --zd-bg: #0a0e1a;
  --zd-nav-bg: #0d1224;
  --zd-sidebar-bg: #111828;
  --zd-chat-bg: #0f1629;
  --zd-surface: #1a2236;
  --zd-surface-hover: #1e2740;
  --zd-surface-active: #243050;
  /* Borders */
  --zd-border: rgba(148, 163, 184, 0.08);
  --zd-border-strong: rgba(148, 163, 184, 0.15);
  /* Text */
  --zd-text: #e8ecf4;
  --zd-text-secondary: #8b99b0;
  --zd-text-muted: #546178;
  /* Misc */
  --zd-radius: 12px;
  --zd-radius-sm: 8px;
  --zd-transition: 0.15s ease;
  --zd-green: #22c55e;
  --zd-orange: #f59e0b;
  --zd-red: #ef4444;
}

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

/* ==================== Base ==================== */
.zalo-dashboard {
  min-height: 100vh;
  height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--zd-bg);
  color: var(--zd-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: grid;
  grid-template-columns: 64px 340px 1fr;
  grid-template-rows: 1fr;
  overflow: hidden;
}

@media (max-width: 900px) {
  .zalo-dashboard {
    grid-template-columns: 56px 280px 1fr;
  }
}

@media (max-width: 640px) {
  .zalo-dashboard {
    grid-template-columns: 1fr;
  }
  .zd-icon-nav,
  .zd-sidebar {
    display: none;
  }
}

.zd-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.25); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(100, 116, 139, 0.4); }

/* ==================== ICON NAV BAR (column 1) ==================== */
.zd-icon-nav {
  background: var(--zd-nav-bg);
  border-right: 1px solid var(--zd-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 16px;
  gap: 4px;
}

.zd-icon-nav__top,
.zd-icon-nav__bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.zd-icon-nav__avatar {
  margin-bottom: 12px;
}

.zd-nav-avatar-circle {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(145deg, #0d4ab8 0%, var(--zd-blue) 45%, #38a0ff 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: transform var(--zd-transition), box-shadow var(--zd-transition);
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.25),
    0 4px 14px rgba(0, 104, 255, 0.28);
  overflow: hidden;
}

.zd-nav-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  z-index: 1;
}

.zd-nav-avatar-img[hidden] {
  display: none !important;
}

.zd-nav-avatar-letter {
  position: relative;
  z-index: 0;
  line-height: 1;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.zd-nav-avatar-circle--has-photo .zd-nav-avatar-letter {
  display: none;
}

.zd-nav-avatar-circle:hover {
  transform: scale(1.05);
  box-shadow:
    0 0 0 2px rgba(0, 104, 255, 0.35),
    0 6px 18px rgba(0, 104, 255, 0.35);
}

.zd-icon-nav__item {
  width: 44px;
  height: 44px;
  border-radius: var(--zd-radius);
  border: none;
  background: transparent;
  color: var(--zd-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--zd-transition);
  text-decoration: none;
}

.zd-icon-nav__item:hover {
  background: var(--zd-surface);
  color: var(--zd-text-secondary);
}

.zd-icon-nav__item--active {
  background: var(--zd-blue-soft);
  color: var(--zd-blue);
}

.zd-icon-nav__item--active:hover {
  background: rgba(0, 104, 255, 0.12);
  color: var(--zd-blue);
}

.zd-icon-nav__item:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.zd-icon-nav__item-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zd-nav-unread-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
  color: #fff;
  background: var(--zd-red);
  border-radius: 999px;
  box-shadow: 0 0 0 2px var(--zd-nav-bg);
  pointer-events: none;
}

/* ==================== SIDEBAR (column 2) ==================== */
.zd-sidebar {
  background: var(--zd-sidebar-bg);
  border-right: 1px solid var(--zd-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.zd-sidebar-head {
  padding: 10px 12px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--zd-border);
  background: linear-gradient(180deg, rgba(0, 104, 255, 0.04) 0%, transparent 100%);
}

.zd-sidebar-head__toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.zd-sidebar-head__toolbar .zd-sidebar-search-wrap {
  flex: 1 1 0;
  min-width: 0;
}

.zd-sidebar-head__phone-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--zd-border-strong);
  border-radius: var(--zd-radius-sm);
  background: rgba(26, 34, 54, 0.65);
  color: var(--zd-text-secondary);
  cursor: pointer;
  transition: background var(--zd-transition), border-color var(--zd-transition), color var(--zd-transition);
}

.zd-sidebar-head__phone-btn:hover:not(:disabled) {
  background: var(--zd-surface-hover);
  border-color: var(--zd-blue);
  color: var(--zd-blue);
}

.zd-sidebar-head__phone-btn:focus {
  outline: none;
  border-color: var(--zd-blue);
  box-shadow: 0 0 0 2px var(--zd-blue-glow);
}

.zd-sidebar-head__phone-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.zd-sidebar-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.zd-sidebar-search-icon {
  position: absolute;
  left: 12px;
  color: var(--zd-text-muted);
  pointer-events: none;
  opacity: 0.85;
}

.zd-sidebar-search {
  width: 100%;
  padding: 10px 12px 10px 38px;
  border: 1px solid var(--zd-border-strong);
  border-radius: 22px;
  font: inherit;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.8125rem;
  background: rgba(26, 34, 54, 0.85);
  color: var(--zd-text);
  transition: border-color var(--zd-transition), box-shadow var(--zd-transition), background var(--zd-transition);
}

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

.zd-sidebar-search:focus {
  outline: none;
  border-color: var(--zd-blue);
  box-shadow: 0 0 0 3px var(--zd-blue-glow);
}

/* Sidebar status row (first block: connection + account) */
.zd-sidebar-status-bar {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--zd-border);
  background: linear-gradient(180deg, rgba(0, 104, 255, 0.05) 0%, rgba(0, 0, 0, 0.12) 100%);
}

.zd-sidebar-status-bar--onboarding {
  padding: 12px 12px 14px;
  gap: 0;
  background: linear-gradient(
    165deg,
    rgba(59, 130, 246, 0.08) 0%,
    rgba(6, 182, 212, 0.05) 42%,
    rgba(0, 0, 0, 0.12) 100%
  );
}

.zd-sidebar-status-bar--onboarding .zd-header-account-group {
  gap: 0;
}

/* Empty / setup: no accounts or no active row in DB */
.zd-account-setup-hint {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  padding: 14px 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.55);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 8px 24px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.zd-account-setup-hint[hidden] {
  display: none !important;
}

.zd-account-setup-hint__intro {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.zd-account-setup-hint__icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, rgba(59, 130, 246, 0.45), rgba(6, 182, 212, 0.2));
  color: #f0f9ff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.zd-account-setup-hint__copy {
  min-width: 0;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 1px;
}

.zd-account-setup-hint__title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--zd-text);
  letter-spacing: -0.02em;
}

.zd-account-setup-hint__desc {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--zd-text-muted);
}

.zd-account-setup-hint__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.zd-account-setup-hint__login-btn {
  font: inherit;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.8125rem;
  font-weight: 600;
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0d9488);
  box-shadow: 0 2px 12px rgba(37, 99, 235, 0.3);
  transition: filter var(--zd-transition), transform 0.12s ease, box-shadow var(--zd-transition);
}

.zd-account-setup-hint__login-btn:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}

.zd-account-setup-hint__login-btn:active:not(:disabled) {
  transform: scale(0.99);
}

.zd-account-setup-hint__login-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.zd-account-setup-hint__logout-btn {
  font: inherit;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  width: 100%;
  padding: 8px 14px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 10px;
  cursor: pointer;
  color: var(--zd-text-secondary);
  background: transparent;
  transition: background var(--zd-transition), color var(--zd-transition), border-color var(--zd-transition);
}

.zd-account-setup-hint__logout-btn:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.08);
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.35);
}

.zd-account-setup-hint__logout-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.zd-account-setup-hint__logout-btn[hidden] {
  display: none !important;
}

/* Ensure strip is fully removed from layout when onboarding hides it */
.zd-account-strip[hidden] {
  display: none !important;
}

/* ==================== Conversation List ==================== */
.zd-conv-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
}

.zd-conv-item {
  display: flex;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--zd-radius-sm);
  cursor: pointer;
  transition: background var(--zd-transition);
  position: relative;
}

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

.zd-conv-item--active {
  background: var(--zd-surface-active);
}

.zd-conv-item--active:hover {
  background: var(--zd-surface-active);
}

.zd-conv-avatar {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  letter-spacing: -0.02em;
}

.zd-conv-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-weight: 700;
  font-size: 0.95rem;
}

.zd-conv-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.15s ease-out;
}

.zd-conv-avatar-img--show {
  opacity: 1;
}

.zd-conv-body {
  min-width: 0;
  flex: 1;
  padding-top: 2px;
}

.zd-conv-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.zd-conv-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.zd-conv-name {
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--zd-text);
  min-width: 0;
}

.zd-conv-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  background: var(--zd-red);
  border-radius: 999px;
  flex-shrink: 0;
}

.zd-conv-time {
  font-size: 0.6875rem;
  color: var(--zd-text-muted);
  flex-shrink: 0;
}

.zd-conv-preview {
  font-size: 0.8125rem;
  color: var(--zd-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}

.zd-conv-badge {
  font-size: 0.6rem;
  text-transform: uppercase;
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: 0.03em;
}

.zd-conv-badge--friend {
  background: rgba(34, 197, 94, 0.1);
  color: var(--zd-green);
}

.zd-conv-badge--stranger {
  background: rgba(245, 158, 11, 0.1);
  color: var(--zd-orange);
}

/* ==================== Account bar ==================== */
.zd-header-account-group {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}

/* One row: identity (flex) + actions (fixed width) */
.zd-account-strip {
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

.zd-account-strip .zd-account-preview {
  flex: 1 1 0;
  min-width: 0;
}

.zd-account-strip .zd-account-actions {
  flex: 0 0 auto;
  width: auto;
  min-width: min(104px, 100%);
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: 6px;
}

/* Chỉ nút Đăng nhập: trải toàn chiều ngang */
.zd-account-strip--solo .zd-account-actions {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  max-width: none;
}

.zd-account-label {
  font-size: 0.75rem;
  color: var(--zd-text-secondary);
  line-height: 1.35;
  padding: 8px 10px;
  border-radius: var(--zd-radius-sm);
  background: var(--zd-surface);
  border: 1px solid var(--zd-border);
}

.zd-account-label:empty {
  display: none;
}

.zd-account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.zd-account-action-btn {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--zd-radius-sm);
  border: 1px solid var(--zd-border-strong);
  background: var(--zd-surface);
  color: var(--zd-text);
  cursor: pointer;
  text-align: center;
}

.zd-account-action-btn--compact {
  flex: 0 0 auto;
  padding: 6px 10px;
  font-size: 0.6875rem;
  white-space: nowrap;
}

.zd-account-action-btn:hover {
  background: var(--zd-surface-hover);
  border-color: var(--zd-blue);
}

.zd-account-action-btn:focus {
  outline: none;
  border-color: var(--zd-blue);
  box-shadow: 0 0 0 2px var(--zd-blue-glow);
}

.zd-account-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.zd-account-action-btn--danger {
  border-color: rgba(239, 68, 68, 0.45);
  color: #f87171;
}

.zd-account-action-btn--danger:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.65);
}

.zd-account-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border-radius: var(--zd-radius-sm);
  background: var(--zd-surface);
  border: 1px solid var(--zd-border-strong);
  box-shadow: none;
}

.zd-account-preview__avatar-wrap {
  position: relative;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.zd-account-preview__img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--zd-border-strong);
  display: block;
}

.zd-account-preview__img[hidden],
.zd-account-preview__img:not([src]),
.zd-account-preview__img[src=""] {
  display: none !important;
}

.zd-account-preview__initials {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--zd-blue), #0091ff);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
}

.zd-account-preview__initials[hidden] { display: none !important; }

.zd-account-preview__text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.zd-account-preview__name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--zd-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zd-account-preview__uid {
  font-size: 0.6875rem;
  color: var(--zd-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==================== MAIN CHAT (column 3) ==================== */
.zd-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--zd-chat-bg);
  overflow: hidden;
}

/* Chat header */
.zd-chat-header {
  flex-shrink: 0;
  padding: 10px 20px;
  border-bottom: 1px solid var(--zd-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--zd-sidebar-bg);
  min-height: 60px;
}

.zd-chat-header__info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.zd-chat-header__avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
  color: #fff;
  flex-shrink: 0;
  display: none;
  overflow: hidden;
  letter-spacing: -0.02em;
}

.zd-thread-area--active .zd-chat-header__avatar {
  display: block;
}

.zd-chat-header__avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-weight: 700;
  font-size: 0.8125rem;
}

.zd-chat-header__avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.15s ease-out;
}

.zd-chat-header__avatar-img--show {
  opacity: 1;
}

.zd-chat-header__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.zd-chat-header__name {
  font-weight: 700;
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--zd-text);
}

.zd-chat-header__meta {
  font-size: 0.6875rem;
  color: var(--zd-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zd-chat-header__actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.zd-auto-reply-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--zd-text);
  max-width: min(220px, 42vw);
}

.zd-auto-reply-toggle__text {
  line-height: 1.25;
  white-space: normal;
}

.zd-auto-reply-toggle input[type='checkbox'] {
  width: 1.05rem;
  height: 1.05rem;
  flex-shrink: 0;
  accent-color: #22c55e;
  cursor: pointer;
}

/* ==================== Messages ==================== */
.zd-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.zd-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  text-align: center;
}

.zd-empty-state__icon {
  color: var(--zd-text-muted);
  opacity: 0.3;
}

.zd-empty-state__title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--zd-text-secondary);
}

.zd-empty-state__text {
  font-size: 0.875rem;
  color: var(--zd-text-muted);
  max-width: 320px;
  line-height: 1.5;
}

.zd-bubble-row {
  display: flex;
  width: 100%;
}

.zd-bubble-row--them {
  justify-content: flex-start;
}

.zd-bubble-row--me {
  justify-content: flex-end;
}

.zd-bubble-row--pending {
  opacity: 0.72;
}

.zd-bubble-row--pending .zd-bubble-time {
  font-style: italic;
}

.zd-bubble {
  max-width: 65%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
  animation: msg-in 0.2s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.zd-bubble--them {
  background: var(--zd-surface);
  color: var(--zd-text);
  border-bottom-left-radius: 4px;
}

.zd-bubble--me {
  background: var(--zd-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.zd-bubble-text {
  word-break: break-word;
}

.zd-bubble-media {
  margin-bottom: 6px;
  max-width: min(260px, 100%);
}

.zd-bubble-media img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  vertical-align: middle;
}

.zd-bubble-media--placeholder-only {
  max-width: min(260px, 100%);
}

.zd-bubble-photo-placeholder {
  box-sizing: border-box;
  min-height: 88px;
  padding: 16px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--zd-text-secondary);
  background: rgba(15, 22, 41, 0.45);
  border: 1px dashed var(--zd-border-strong);
  border-radius: 12px;
}

.zd-bubble--them .zd-bubble-photo-placeholder {
  background: var(--zd-surface);
  color: var(--zd-text-muted);
}

.zd-bubble--me .zd-bubble-photo-placeholder {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.35);
  color: rgba(255, 255, 255, 0.88);
}

.zd-bubble-time {
  font-size: 0.625rem;
  opacity: 0.55;
  margin-top: 4px;
}

.zd-empty {
  text-align: center;
  color: var(--zd-text-muted);
  padding: 32px 16px;
  font-size: 0.875rem;
}

/* ==================== Composer ==================== */
.zd-composer {
  flex-shrink: 0;
  padding: 10px 20px 14px;
  border-top: 1px solid var(--zd-border);
  background: var(--zd-sidebar-bg);
}

.zd-api-banner {
  font-size: 0.75rem;
  min-height: 0;
  margin: 0;
  padding: 0;
  line-height: 1;
  color: var(--zd-text-secondary);
  transition: all var(--zd-transition);
}

.zd-api-banner:not(:empty) {
  margin-bottom: 8px;
  min-height: 1.2em;
}

.zd-api-banner--error {
  color: var(--zd-orange);
}

.zd-composer__row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
}

.zd-composer__attach-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.zd-composer__attach-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--zd-border-strong);
  background: var(--zd-surface);
  color: var(--zd-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--zd-transition);
}

.zd-composer__attach-btn:hover:not(.zd-composer__attach-btn--disabled) {
  border-color: var(--zd-blue);
  color: var(--zd-blue);
  background: var(--zd-blue-soft);
}

.zd-composer__attach-btn.zd-composer__attach-btn--disabled {
  opacity: 0.35;
  pointer-events: none;
  cursor: not-allowed;
}

.zd-composer__input-wrap {
  flex: 1;
  min-width: 0;
}

.zd-composer__preview[hidden] {
  display: none !important;
}

.zd-composer__preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.zd-composer__preview-card {
  position: relative;
  flex-shrink: 0;
  border-radius: var(--zd-radius-sm);
  overflow: hidden;
  border: 1px solid var(--zd-border-strong);
  background: var(--zd-surface);
  max-width: min(200px, 42vw);
}

.zd-composer__preview-img {
  display: block;
  width: 100%;
  max-height: 120px;
  height: auto;
  object-fit: contain;
  vertical-align: middle;
}

.zd-composer__preview-img[hidden] {
  display: none !important;
}

.zd-composer__preview-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  padding: 12px 40px 12px 14px;
  box-sizing: border-box;
}

.zd-composer__preview-file[hidden] {
  display: none !important;
}

.zd-composer__preview-file-icon {
  flex-shrink: 0;
  color: var(--zd-text-secondary);
  display: flex;
}

.zd-composer__preview-file-title {
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--zd-text);
  word-break: break-all;
}

.zd-composer__preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(15, 22, 41, 0.75);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--zd-transition);
}

.zd-composer__preview-remove:hover {
  background: var(--zd-red);
}

.zd-composer__preview-name {
  font-size: 0.75rem;
  color: var(--zd-text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zd-composer__textarea {
  width: 100%;
  padding: 11px 16px;
  border: 1px solid var(--zd-border-strong);
  border-radius: 22px;
  font: inherit;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.875rem;
  background: var(--zd-surface);
  color: var(--zd-text);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color var(--zd-transition), box-shadow var(--zd-transition);
}

.zd-composer__textarea::placeholder {
  color: var(--zd-text-muted);
}

.zd-composer__textarea:focus {
  outline: none;
  border-color: var(--zd-blue);
  box-shadow: 0 0 0 2px var(--zd-blue-glow);
}

.zd-composer__textarea:disabled {
  opacity: 0.4;
}

.zd-bubble-file-wrap {
  margin-bottom: 6px;
}

.zd-bubble-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  word-break: break-all;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.zd-bubble-file:hover {
  opacity: 0.92;
}

.zd-bubble--me .zd-bubble-file {
  color: #fff;
}

.zd-bubble-file-placeholder {
  font-size: 0.8125rem;
  opacity: 0.85;
  margin-bottom: 6px;
}

.zd-composer__send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--zd-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--zd-transition);
}

.zd-composer__send-btn:hover:not(:disabled) {
  background: var(--zd-blue-hover);
  transform: scale(1.05);
}

.zd-composer__send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ==================== Buttons (generic) ==================== */
.zd-btn {
  font: inherit;
  font-family: 'Inter', system-ui, sans-serif;
  cursor: pointer;
  border: none;
  border-radius: var(--zd-radius-sm);
  padding: 9px 18px;
  font-size: 0.8125rem;
  font-weight: 600;
  transition: all var(--zd-transition);
}

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

.zd-btn--primary:hover:not(:disabled) {
  background: var(--zd-blue-hover);
}

.zd-btn--primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.zd-btn--secondary {
  background: var(--zd-surface);
  color: var(--zd-text);
  border: 1px solid var(--zd-border-strong);
}

.zd-btn--secondary:hover:not(:disabled) {
  background: var(--zd-surface-hover);
}

.zd-btn--secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.zd-btn--danger {
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.zd-btn--danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.28);
  border-color: rgba(239, 68, 68, 0.65);
}

.zd-btn--danger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ==================== Modals ==================== */
.zd-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.zd-modal[hidden] {
  display: none !important;
}

.zd-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.zd-modal--api-secret-locked .zd-modal__close {
  display: none !important;
}

.zd-modal__hint--required {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: var(--zd-radius-sm);
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: var(--zd-text);
  font-size: 0.8125rem;
  line-height: 1.45;
}

.zd-modal__hint--required[hidden] {
  display: none !important;
}

.zd-modal__dialog--narrow {
  max-width: 400px;
}

.zd-logout-confirm-account {
  font-size: 0.8125rem;
  color: var(--zd-text-secondary);
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: var(--zd-radius-sm);
  background: var(--zd-surface);
  border: 1px solid var(--zd-border);
  word-break: break-word;
}

.zd-modal__dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--zd-sidebar-bg);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--zd-border-strong);
  padding: 22px 24px 26px;
  animation: modal-in 0.25s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.zd-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.zd-modal__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--zd-text);
}

.zd-modal__close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--zd-radius-sm);
  background: var(--zd-surface);
  color: var(--zd-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--zd-transition);
}

.zd-modal__close:hover {
  background: var(--zd-surface-hover);
  color: var(--zd-text);
}

.zd-modal__hint {
  margin: 0 0 14px;
  font-size: 0.8125rem;
  color: var(--zd-text-secondary);
  line-height: 1.5;
}

.zd-modal__hint code {
  font-size: 0.8em;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--zd-surface);
  color: #60a5fa;
}

.zd-modal__qr {
  display: flex;
  justify-content: center;
  padding: 10px 0;
}

.zd-qr-img {
  display: inline-block;
  border-radius: 12px;
  background: #fff;
  vertical-align: middle;
}

.zd-modal__status {
  margin: 12px 0 0;
  font-size: 0.8125rem;
  color: var(--zd-text-secondary);
  text-align: center;
  min-height: 1.25em;
}

/* Modal form elements */
.zd-modal-form {
  margin-bottom: 4px;
}

.zd-modal-field {
  margin-bottom: 12px;
}

.zd-modal-field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--zd-text-secondary);
  margin-bottom: 6px;
}

.zd-modal-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--zd-border-strong);
  border-radius: var(--zd-radius-sm);
  font: inherit;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.875rem;
  background: var(--zd-surface);
  color: var(--zd-text);
  transition: border-color var(--zd-transition), box-shadow var(--zd-transition);
}

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

.zd-modal-input:focus {
  outline: none;
  border-color: var(--zd-blue);
  box-shadow: 0 0 0 2px var(--zd-blue-glow);
}

.zd-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.zd-modal-actions--row {
  justify-content: flex-start;
}

.zd-lookup-result {
  font-size: 0.8125rem;
  color: var(--zd-text);
  margin: 8px 0 0;
  padding: 10px 12px;
  background: var(--zd-blue-soft);
  border: 1px solid rgba(0, 104, 255, 0.15);
  border-radius: var(--zd-radius-sm);
}

/* ==================== Legacy compat (JS references) ==================== */
/* These classes exist so the JS doesn't break even though
   we restructured the HTML. They map to existing elements
   or are unused gracefully. */

.zd-thread-area { display: contents; }
.zd-thread-area--active .zd-chat-header { border-bottom-color: var(--zd-border-strong); }

/* sidebar-title & sidebar-lookup-btn removed from HTML but
   the sidebar-head is still present, search is inside it */
.zd-sidebar-title { display: none; }
.zd-sidebar-lookup-btn { display: none; }

/* Old composer classes mapped to new */
.zd-api-panel { display: none; }
.zd-chat-composer { display: none; }
.zd-api-panel-title { display: none; }
.zd-msg-textarea { display: none; }
.zd-api-send-row { display: none; }
.zd-composer-hint-inline { display: none; }

/* button used from old HTML no longer in DOM but keep for safety */
.zd-link-home { display: none; }
