:root {
  --panel-bg: #ffffff;
  --app-bg: #eae6df;
  --sidebar-bg: #ffffff;
  --header-bg: #f0f2f5;
  --text-primary: #111b21;
  --text-secondary: #667781;
  --border: #e9edef;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --accent: #00a884;
  --accent-dark: #008069;
  --hover: #f5f6f6;
  --active: #e9edef;
  --danger: #e35145;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cg fill='none' stroke='rgba(0,0,0,0.05)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='16' y='18' width='38' height='26' rx='7'/%3E%3Cpath d='M26 44v9l10-9'/%3E%3Crect x='150' y='14' width='40' height='26' rx='3'/%3E%3Cpath d='M150 16l20 16 20-16'/%3E%3Ccircle cx='36' cy='118' r='6'/%3E%3Cpath d='M42 118V96l14-4v18'/%3E%3Crect x='96' y='92' width='34' height='24' rx='4'/%3E%3Ccircle cx='113' cy='104' r='7'/%3E%3Crect x='104' y='86' width='12' height='6' rx='2'/%3E%3Cpolygon points='200,90 204,100 215,101 207,108 209,119 200,113 191,119 193,108 185,101 196,100'/%3E%3Cpath d='M40 165c-7-7-16-3-16 4 0 7 9 13 16 19 7-6 16-12 16-19 0-7-9-11-16-4z'/%3E%3Cpath d='M185 155c11 2 18 11 18 22-11 0-20-7-22-18-1-3 1-5 4-4z'/%3E%3Cpath d='M186 158l12 14'/%3E%3Cpath d='M110 155l32-12-11 32-7-15z'/%3E%3Cpath d='M131 155l-7 20'/%3E%3Ccircle cx='60' cy='205' r='14'/%3E%3Cpath d='M60 196v9l7 4'/%3E%3Cpath d='M170 195h22v16a8 8 0 0 1-8 8h-6a8 8 0 0 1-8-8z'/%3E%3Cpath d='M192 199h5a6 6 0 0 1 0 12h-5'/%3E%3C/g%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --panel-bg: #111b21;
    --app-bg: #0b141a;
    --sidebar-bg: #111b21;
    --header-bg: #1d2528;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --border: #222d34;
    --bubble-in: #242626;
    --bubble-out: #144d37;
    --hover: #202c33;
    --active: #2a3942;
    --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
    --chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cg fill='none' stroke='rgba(255,255,255,0.045)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='16' y='18' width='38' height='26' rx='7'/%3E%3Cpath d='M26 44v9l10-9'/%3E%3Crect x='150' y='14' width='40' height='26' rx='3'/%3E%3Cpath d='M150 16l20 16 20-16'/%3E%3Ccircle cx='36' cy='118' r='6'/%3E%3Cpath d='M42 118V96l14-4v18'/%3E%3Crect x='96' y='92' width='34' height='24' rx='4'/%3E%3Ccircle cx='113' cy='104' r='7'/%3E%3Crect x='104' y='86' width='12' height='6' rx='2'/%3E%3Cpolygon points='200,90 204,100 215,101 207,108 209,119 200,113 191,119 193,108 185,101 196,100'/%3E%3Cpath d='M40 165c-7-7-16-3-16 4 0 7 9 13 16 19 7-6 16-12 16-19 0-7-9-11-16-4z'/%3E%3Cpath d='M185 155c11 2 18 11 18 22-11 0-20-7-22-18-1-3 1-5 4-4z'/%3E%3Cpath d='M186 158l12 14'/%3E%3Cpath d='M110 155l32-12-11 32-7-15z'/%3E%3Cpath d='M131 155l-7 20'/%3E%3Ccircle cx='60' cy='205' r='14'/%3E%3Cpath d='M60 196v9l7 4'/%3E%3Cpath d='M170 195h22v16a8 8 0 0 1-8 8h-6a8 8 0 0 1-8-8z'/%3E%3Cpath d='M192 199h5a6 6 0 0 1 0 12h-5'/%3E%3C/g%3E%3C/svg%3E");
  }
}

:root[data-theme="dark"] {
  --panel-bg: #111b21;
  --app-bg: #0b141a;
  --sidebar-bg: #111b21;
  --header-bg: #1d2528;
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --border: #222d34;
  --bubble-in: #242626;
  --bubble-out: #144d37;
  --hover: #202c33;
  --active: #2a3942;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cg fill='none' stroke='rgba(255,255,255,0.045)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='16' y='18' width='38' height='26' rx='7'/%3E%3Cpath d='M26 44v9l10-9'/%3E%3Crect x='150' y='14' width='40' height='26' rx='3'/%3E%3Cpath d='M150 16l20 16 20-16'/%3E%3Ccircle cx='36' cy='118' r='6'/%3E%3Cpath d='M42 118V96l14-4v18'/%3E%3Crect x='96' y='92' width='34' height='24' rx='4'/%3E%3Ccircle cx='113' cy='104' r='7'/%3E%3Crect x='104' y='86' width='12' height='6' rx='2'/%3E%3Cpolygon points='200,90 204,100 215,101 207,108 209,119 200,113 191,119 193,108 185,101 196,100'/%3E%3Cpath d='M40 165c-7-7-16-3-16 4 0 7 9 13 16 19 7-6 16-12 16-19 0-7-9-11-16-4z'/%3E%3Cpath d='M185 155c11 2 18 11 18 22-11 0-20-7-22-18-1-3 1-5 4-4z'/%3E%3Cpath d='M186 158l12 14'/%3E%3Cpath d='M110 155l32-12-11 32-7-15z'/%3E%3Cpath d='M131 155l-7 20'/%3E%3Ccircle cx='60' cy='205' r='14'/%3E%3Cpath d='M60 196v9l7 4'/%3E%3Cpath d='M170 195h22v16a8 8 0 0 1-8 8h-6a8 8 0 0 1-8-8z'/%3E%3Cpath d='M192 199h5a6 6 0 0 1 0 12h-5'/%3E%3C/g%3E%3C/svg%3E");
}

:root[data-theme="light"] {
  --panel-bg: #ffffff;
  --app-bg: #eae6df;
  --sidebar-bg: #ffffff;
  --header-bg: #f0f2f5;
  --text-primary: #111b21;
  --text-secondary: #667781;
  --border: #e9edef;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --hover: #f5f6f6;
  --active: #e9edef;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cg fill='none' stroke='rgba(0,0,0,0.05)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='16' y='18' width='38' height='26' rx='7'/%3E%3Cpath d='M26 44v9l10-9'/%3E%3Crect x='150' y='14' width='40' height='26' rx='3'/%3E%3Cpath d='M150 16l20 16 20-16'/%3E%3Ccircle cx='36' cy='118' r='6'/%3E%3Cpath d='M42 118V96l14-4v18'/%3E%3Crect x='96' y='92' width='34' height='24' rx='4'/%3E%3Ccircle cx='113' cy='104' r='7'/%3E%3Crect x='104' y='86' width='12' height='6' rx='2'/%3E%3Cpolygon points='200,90 204,100 215,101 207,108 209,119 200,113 191,119 193,108 185,101 196,100'/%3E%3Cpath d='M40 165c-7-7-16-3-16 4 0 7 9 13 16 19 7-6 16-12 16-19 0-7-9-11-16-4z'/%3E%3Cpath d='M185 155c11 2 18 11 18 22-11 0-20-7-22-18-1-3 1-5 4-4z'/%3E%3Cpath d='M186 158l12 14'/%3E%3Cpath d='M110 155l32-12-11 32-7-15z'/%3E%3Cpath d='M131 155l-7 20'/%3E%3Ccircle cx='60' cy='205' r='14'/%3E%3Cpath d='M60 196v9l7 4'/%3E%3Cpath d='M170 195h22v16a8 8 0 0 1-8 8h-6a8 8 0 0 1-8-8z'/%3E%3Cpath d='M192 199h5a6 6 0 0 1 0 12h-5'/%3E%3C/g%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

/* Author rules that set `display` on a class normally beat the UA default
   `[hidden]{display:none}` regardless of specificity, since origin wins
   before specificity in the cascade. Restore it explicitly so toggling the
   `hidden` attribute from JS always works, even on elements styled with
   display:flex/grid elsewhere in this file. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "Roboto Variable", Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--app-bg);
  color: var(--text-primary);
}

button, input, textarea { font-family: inherit; }

.icon-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0.4rem;
  border-radius: 50%;
  line-height: 1;
}
.icon-btn:hover { background: var(--hover); }

/* ---------- Login ---------- */
.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--app-bg);
}
.login-card {
  background: var(--panel-bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  width: min(90vw, 340px);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  text-align: center;
}
.login-logo { color: var(--accent); display: flex; justify-content: center; }
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-subtitle { margin: 0 0 0.5rem; color: var(--text-secondary); font-size: 0.9rem; }
.login-card label {
  text-align: left;
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.login-card input {
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--app-bg);
  color: var(--text-primary);
  font-size: 0.95rem;
}
.login-card button {
  margin-top: 0.4rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.7rem;
  font-size: 1rem;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-dark); }
.login-error { color: var(--danger); font-size: 0.85rem; margin: 0; }

/* ---------- App layout ---------- */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  position: relative;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.sidebar-header {
  height: 60px;
  flex: none;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
}
.me {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  min-width: 0;
  background: none;
  border: none;
  padding: 0.3rem 0.4rem 0.3rem 0.1rem;
  margin-left: -0.1rem;
  border-radius: 999px;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
  max-width: 60%;
}
.me:hover { background: var(--hover); }
.me span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-actions { display: flex; gap: 0.2rem; align-items: center; }

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667781, #8696a0);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex: none;
  overflow: hidden;
  font-size: 0.95rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-me { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); }

/* info-avatar is a <button> (so it can open the lightbox) but still needs to
   look exactly like the plain-div avatars elsewhere. */
button.info-avatar {
  border: none;
  padding: 0;
  font-family: inherit;
  cursor: default;
}
button.info-avatar[title], button.info-avatar { cursor: pointer; }

.connection-banner {
  background: #fef6e0;
  color: #6b4e00;
  padding: 0.7rem 1rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
:root[data-theme="dark"] .connection-banner { background: #3a2f0d; color: #f5d67e; }
@media (prefers-color-scheme: dark) {
  .connection-banner { background: #3a2f0d; color: #f5d67e; }
  :root[data-theme="light"] .connection-banner { background: #fef6e0; color: #6b4e00; }
}
.connection-banner img { max-width: 160px; margin-top: 0.5rem; border-radius: 8px; background: #fff; padding: 6px; }
.connection-banner .link-btn {
  background: none; border: 1px solid currentColor; border-radius: 6px;
  padding: 0.3rem 0.8rem; margin-top: 0.5rem; cursor: pointer; color: inherit;
}

/* ---------- Chat list filter tabs ---------- */
.chat-filter-tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem 0.7rem;
  flex: none;
  overflow-x: auto;
}
.chat-filter-tab {
  flex: none;
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--hover);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
}
.chat-filter-tab:hover { background: var(--active); }
.chat-filter-tab.active { background: var(--accent); color: #fff; }

/* ---------- Sidebar menu (⋮) ---------- */
.menu-wrap { position: relative; }
.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 180px;
  padding: 0.35rem;
  z-index: 10;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.menu-item:hover { background: var(--hover); }

.search-box { padding: 0.46rem 0.75rem; }
.search-box input {
  width: 100%;
  padding: 0.44rem 0.9rem;
  border-radius: 8px;
  border: none;
  background: var(--header-bg);
  color: var(--text-primary);
  font-size: 0.9375rem;
  outline: none;
}

.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.empty-list { text-align: center; color: var(--text-secondary); padding: 2rem 1rem; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.chat-item-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 0.15rem; }
.chat-item-top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.chat-item-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-time { font-size: 0.72rem; color: var(--text-secondary); flex: none; }
.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.chat-item-preview { color: var(--text-secondary); font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.unread .chat-item-name { font-weight: 700; }
.chat-item.unread .chat-item-preview { color: var(--text-primary); font-weight: 500; }
.unread-badge {
  background: var(--accent); color: #fff; font-size: 0.72rem; font-weight: 600;
  border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center; flex: none;
}

/* Per-item ⋮ quick-actions, revealed on hover/focus so the row stays clean
   otherwise (same idea as the reaction button on message bubbles). */
.chat-item-menu-wrap { position: relative; flex: none; opacity: 0; transition: opacity 0.1s ease; }
.chat-item:hover .chat-item-menu-wrap,
.chat-item-menu-wrap:has(.chat-item-popover:not([hidden])),
.chat-item-menu-wrap:focus-within {
  opacity: 1;
}
.chat-item-menu-btn { font-size: 1.1rem; padding: 0.3rem 0.45rem; }
.chat-item-popover {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 190px;
  padding: 0.35rem;
  z-index: 6;
}
.popover-action {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.85rem;
  white-space: nowrap;
}
.popover-action:hover { background: var(--hover); }
.popover-action-danger { color: var(--danger); }

/* ---------- Generic context menu (chat-list right-click) ---------- */
.context-menu {
  position: fixed;
  z-index: 70;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 200px;
  padding: 0.35rem;
}
.context-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.88rem;
}
.context-menu-item:hover { background: var(--hover); }
.context-menu-item.danger { color: var(--danger); }

/* ---------- Chat area ---------- */
.chat-area {
  position: relative;
  background-color: var(--app-bg);
  background-image: var(--chat-pattern);
  background-repeat: repeat;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: 0.3rem;
}
.empty-state h2 { margin: 0.5rem 0 0; color: var(--text-primary); font-weight: 300; }

.chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

.chat-header {
  height: 60px;
  flex: none;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.back-btn { display: none; }
.chat-header-info { display: flex; flex-direction: column; min-width: 0; }
.chat-header-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-status { font-size: 0.78rem; color: var(--text-secondary); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 5%;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.load-failure {
  margin: auto;
  text-align: center;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem;
}
.load-failure .link-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 1rem;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}
.load-failure .link-btn:hover { background: var(--hover); }

.older-spinner {
  align-self: center;
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.3rem 0.8rem;
  margin: 0.4rem 0;
}

.date-sep {
  align-self: center;
  background: var(--header-bg);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.25rem 0.7rem;
  border-radius: 8px;
  margin: 0.6rem 0;
}

.bubble {
  max-width: min(65%, 480px);
  padding: 0.4rem 0.6rem 0.32rem;
  border-radius: 7.5px;
  box-shadow: var(--shadow);
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.3;
  font-size: 0.9375rem;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 0; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 0; }
.bubble.pending { opacity: 0.6; }
.bubble.failed { outline: 1px solid var(--danger); }
.bubble.failed .meta { color: var(--danger); }

/* ---------- Multi-select ---------- */
.select-bar {
  height: 60px;
  flex: none;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
}
.select-bar-count { flex: 1; font-weight: 500; }
.select-bar-actions { display: flex; gap: 0.2rem; }
.select-bar-actions button:disabled { opacity: 0.35; cursor: default; }
.select-bar-actions button:disabled:hover { background: none; }

.bubble-select-check {
  position: absolute;
  left: -2rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  cursor: pointer;
}
.bubble.select-mode .bubble-select-check { display: block; }
.bubble-select-check input { width: 18px; height: 18px; cursor: pointer; }
.bubble.select-mode { cursor: pointer; }
.bubble.selected { outline: 2px solid var(--accent); }
@media (max-width: 780px) {
  .bubble-select-check { left: -1.6rem; }
}
.bubble-sender { font-size: 0.8rem; font-weight: 600; margin-bottom: 0.15rem; }
.bubble-text { white-space: pre-wrap; }
.bubble-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(0, 0, 0, 0.08);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  font-size: 0.9em;
}
:root[data-theme="dark"] .bubble-text code { background: rgba(255, 255, 255, 0.1); }
@media (prefers-color-scheme: dark) {
  .bubble-text code { background: rgba(255, 255, 255, 0.1); }
  :root[data-theme="light"] .bubble-text code { background: rgba(0, 0, 0, 0.08); }
}
.bubble .meta {
  display: block;
  font-size: 0.68rem;
  color: var(--text-secondary);
  text-align: right;
  margin-top: 0.15rem;
  user-select: none;
}
.bubble .ack { margin-left: 0.25rem; }
.bubble .ack.read { color: #53bdeb; }

/* ---------- Quoted reply preview ---------- */
.quote-preview {
  border-left: 3px solid var(--accent);
  background: rgba(0, 0, 0, 0.06);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
:root[data-theme="dark"] .quote-preview { background: rgba(255, 255, 255, 0.07); }
@media (prefers-color-scheme: dark) {
  .quote-preview { background: rgba(255, 255, 255, 0.07); }
  :root[data-theme="light"] .quote-preview { background: rgba(0, 0, 0, 0.06); }
}

.reply-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  background: var(--header-bg);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  font-size: 0.85rem;
}
.reply-bar-body { min-width: 0; overflow: hidden; }
.reply-bar-label { display: block; color: var(--accent); font-weight: 600; font-size: 0.75rem; }
#reply-bar-text { display: block; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Media in bubbles ---------- */
.media-wrap { position: relative; margin: -0.1rem -0.15rem 0.3rem; }
.bubble .media-wrap:first-child { margin-top: -0.1rem; }
.media-wrap:has(.meta-overlay) { margin-bottom: -0.1rem; }
.media-image, .media-video {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--hover);
}
.media-image { cursor: zoom-in; }
/* Stickers are small transparent WebP/PNG images, not photos — they were
   sharing .media-image's 320px cap and cover-crop, making a tiny sticker take
   up as much bubble space as a full photo. */
.media-wrap-sticker { margin: 0; }
.media-sticker {
  display: block;
  width: 130px;
  height: 130px;
  object-fit: contain;
  background: none;
}
/* WhatsApp overlays the time/ack pill on the media itself when there's no
   caption, instead of a separate line — saves space and reads as one unit. */
.meta.meta-overlay {
  position: absolute;
  right: 0.4rem;
  bottom: 0.35rem;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-top: 0;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  padding: 0.1rem 0.4rem;
  border-radius: 8px;
}
.meta.meta-overlay .ack.read { color: #53bdeb; }
.voice-player {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: min(260px, 65vw);
  padding: 0.2rem 0.1rem;
}
.voice-play-btn {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 0 2px;
}
.voice-play-btn:hover { background: var(--accent-dark); }
.voice-track { flex: 1; position: relative; height: 18px; display: flex; align-items: center; cursor: pointer; }
.voice-track::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 2px;
  background: rgba(134, 150, 160, 0.4);
}
.voice-track-fill {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  width: 0%;
  pointer-events: none;
}
.voice-track-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.voice-time { flex: none; font-size: 0.7rem; color: var(--text-secondary); min-width: 30px; }
.voice-player audio { display: none; }
.media-doc {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: 6px;
  background: var(--hover);
  color: inherit;
  text-decoration: none;
}
.media-doc-icon { font-size: 1.4rem; }
.media-doc-label { font-size: 0.85rem; word-break: break-all; }

/* ---------- Message actions (right-click / hover chevron menu) ---------- */
/* Matches official WhatsApp Web: just a react icon + chevron show on hover,
   not a row of icons — both open the same dropdown, which is also what
   right-clicking anywhere on the bubble opens. */
.msg-actions {
  position: absolute;
  top: 0.1rem;
  right: -1.7rem;
  display: flex;
  align-items: center;
  gap: 0.05rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.bubble:hover .msg-actions, .msg-actions:has(.msg-dropdown:not([hidden])), .msg-actions:focus-within {
  opacity: 1;
}
.msg-action-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg-action-icon:hover { background: rgba(134, 150, 160, 0.2); }
.msg-action-chevron { font-size: 0.7rem; }
.msg-dropdown {
  position: absolute;
  top: 1.6rem;
  right: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 190px;
  padding: 0.35rem;
  z-index: 6;
}
.bubble.out .msg-dropdown { right: 0; }
.bubble.in .msg-dropdown { left: 0; right: auto; }
.msg-dropdown-emojis {
  display: flex;
  justify-content: space-between;
  padding: 0.1rem 0.1rem 0.4rem;
  margin-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
.react-option {
  background: none;
  border: none;
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0.15rem;
  border-radius: 50%;
}
.react-option:hover { background: var(--hover); }
.msg-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.85rem;
  white-space: nowrap;
}
.msg-dropdown-item:hover { background: var(--hover); }
.msg-dropdown-item-danger { color: var(--danger); }
.reaction-badge {
  position: absolute;
  bottom: -0.5rem;
  right: 0.4rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 0.05rem 0.3rem;
  box-shadow: var(--shadow);
}

/* ---------- Info panel ---------- */
.info-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 100%);
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  z-index: 5;
  display: flex;
  flex-direction: column;
}
.info-panel-header {
  height: 60px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0 1rem;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.info-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1.2rem;
  text-align: center;
  overflow-y: auto;
}
.info-avatar { width: 96px; height: 96px; font-size: 2rem; margin-bottom: 1rem; }
.info-panel-body h2 { margin: 0 0 0.3rem; font-size: 1.2rem; }
.info-id { margin: 0; color: var(--text-secondary); }
.info-type { margin: 0.6rem 0 0; font-size: 0.8rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }

.info-action-btn {
  margin-top: 1.4rem;
  width: 100%;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-primary);
}
.info-action-btn:hover { background: var(--active); }
.info-action-btn-danger { color: var(--danger); }

.info-participants { width: 100%; margin-top: 1.4rem; text-align: left; }
.info-participants h3 { font-size: 0.78rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 0.5rem; }
.info-participants ul { list-style: none; margin: 0; padding: 0; }
.info-participant {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.info-participant:last-child { border-bottom: none; }
/* ---------- Profile panel (reuses .info-panel base) ---------- */
.profile-settings { width: 100%; margin-top: 1.6rem; text-align: left; }
.profile-settings h3 {
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 0.5rem;
}
.profile-settings-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  padding: 0.8rem 0.2rem;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}
.profile-settings-row:hover { background: var(--hover); }
.profile-settings-icon { font-size: 1.1rem; flex: none; }
.profile-settings-label { flex: 1; }
.profile-settings-value { color: var(--text-secondary); font-size: 0.85rem; }
.profile-settings-row-danger { color: var(--danger); }

.info-participant-admin {
  font-size: 0.68rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------- Lightbox (avatar/photo zoom) ---------- */
.lightbox-overlay { background: rgba(0, 0, 0, 0.75); cursor: zoom-out; }
.lightbox-image {
  max-width: min(90vw, 480px);
  max-height: 85vh;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

/* ---------- PDF viewer ---------- */
.pdf-viewer-overlay { background: rgba(0, 0, 0, 0.6); }
.pdf-viewer {
  background: var(--panel-bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  width: min(94vw, 900px);
  height: min(92vh, 1100px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pdf-viewer-header {
  flex: none;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0 1rem;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}
.pdf-viewer-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}
.pdf-viewer-actions { display: flex; gap: 0.2rem; flex: none; }
.pdf-viewer-frame { flex: 1; border: none; background: #fff; }

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: rgba(0, 168, 132, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop-overlay-box {
  background: var(--panel-bg);
  border: 2px dashed var(--accent);
  border-radius: 12px;
  padding: 2rem 3rem;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--accent-dark);
  box-shadow: var(--shadow);
}

.composer {
  position: relative;
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: var(--header-bg);
}
.quick-reply-popup {
  position: absolute;
  bottom: 100%;
  left: 1rem;
  right: 1rem;
  margin-bottom: 0.4rem;
  max-height: 260px;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.3rem;
}
.quick-reply-popup-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
}
.quick-reply-popup-item.active, .quick-reply-popup-item:hover { background: var(--hover); }
.quick-reply-popup-shortcut { color: var(--accent); font-size: 0.85rem; }
.quick-reply-popup-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* ---------- Quick replies modal ---------- */
.quick-reply-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.3rem;
  border-bottom: 1px solid var(--border);
}
.quick-reply-row:last-child { border-bottom: none; }
.quick-reply-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.1rem; }
.quick-reply-shortcut { color: var(--accent); font-size: 0.85rem; }
.quick-reply-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quick-reply-new-row { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.5rem 0; }
.quick-reply-shortcut-input { width: 100%; }
.quick-reply-text-input {
  width: 100%;
  resize: vertical;
  min-height: 50px;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--header-bg);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 0.6rem 1rem;
  border-radius: 20px;
  border: none;
  background: var(--panel-bg);
  color: var(--text-primary);
  outline: none;
  font-size: 0.95rem;
}
.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  flex: none;
  cursor: pointer;
  font-size: 1.1rem;
}
.send-btn:disabled { opacity: 0.5; cursor: default; }
.send-btn:not(:disabled):hover { background: var(--accent-dark); }
.composer-attach, .composer-mic { flex: none; font-size: 1.3rem; }
.composer-mic.recording { background: var(--danger); color: #fff; }

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: #111b21;
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 50;
  box-shadow: var(--shadow);
}

/* ---------- Modals (forward / new chat / new group) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 1rem;
}
.modal {
  background: var(--panel-bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  width: min(92vw, 380px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 0.9rem;
  gap: 0.7rem;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-search, .modal-input {
  width: 100%;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--header-bg);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}
.modal-form { display: flex; flex-direction: column; gap: 0.6rem; }
.modal-hint { margin: 0; font-size: 0.8rem; color: var(--text-secondary); }
.modal-hint-error { color: var(--danger); }
.modal-submit-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.65rem;
  font-size: 0.92rem;
  cursor: pointer;
}
.modal-submit-btn:hover { background: var(--accent-dark); }
.modal-submit-btn:disabled { opacity: 0.6; cursor: default; }
.modal-chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.modal-chat-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.3rem;
  cursor: pointer;
  border-radius: 8px;
}
.modal-chat-item:hover { background: var(--hover); }
.modal-chat-item-selectable input[type="checkbox"] { flex: none; width: 18px; height: 18px; }
.modal-empty { text-align: center; color: var(--text-secondary); padding: 1rem; font-size: 0.85rem; }

/* ---------- Labels (WhatsApp Business) ---------- */
.label-list { max-height: 260px; }
.label-swatch { flex: none; width: 14px; height: 14px; border-radius: 4px; }
.label-new-row { display: flex; gap: 0.5rem; padding: 0.4rem 0; }
.label-new-row .modal-input { flex: 1; }
.label-new-btn { flex: none; width: auto; padding: 0.5rem 0.9rem; font-size: 0.85rem; white-space: nowrap; }

/* ---------- Image editor ---------- */
.image-editor-overlay { background: rgba(0, 0, 0, 0.75); }
.image-editor {
  background: #111b21;
  color: #e9edef;
  border-radius: 10px;
  box-shadow: var(--shadow);
  width: min(94vw, 720px);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.image-editor-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.6rem 0.8rem;
  background: #1d2528;
}
.ie-toolbar-spacer { flex: 1; }
.ie-tool-btn {
  background: none;
  border: none;
  color: #e9edef;
  font-size: 1.05rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
}
.ie-tool-btn:hover { background: rgba(255, 255, 255, 0.08); }
.ie-tool-btn.active { background: var(--accent); color: #fff; }
.ie-color-input {
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 50%;
  overflow: hidden;
  background: none;
  cursor: pointer;
}
.image-editor-toolbar .icon-btn { color: #e9edef; }
.image-editor-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b141a;
  padding: 0.8rem;
  overflow: auto;
}
.ie-canvas {
  max-width: 100%;
  max-height: 70vh;
  display: block;
  touch-action: none;
  border-radius: 4px;
}
.ie-text-input {
  position: absolute;
  transform: translate(-2px, -50%);
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.6);
  outline: none;
  font: 600 20px sans-serif;
  padding: 2px 4px;
  min-width: 40px;
  max-width: min(80vw, 400px);
}
.ie-crop-box {
  position: absolute;
  border: 2px dashed #fff;
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
}
.ie-crop-actions {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0 0.8rem 0.6rem;
}
.ie-crop-actions .link-btn {
  background: none;
  border: none;
  color: #e9edef;
  cursor: pointer;
  padding: 0.5rem 0.8rem;
}
.ie-crop-actions .modal-submit-btn { width: auto; padding: 0.5rem 1.2rem; }
.image-editor-footer {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.8rem;
  background: #1d2528;
}
.ie-caption-input {
  flex: 1;
  padding: 0.6rem 1rem;
  border-radius: 20px;
  border: none;
  background: #2a3942;
  color: #e9edef;
  outline: none;
  font-size: 0.95rem;
}

/* ---------- Responsive (mobile) ---------- */
@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: absolute; inset: 0; z-index: 2; }
  .chat-area { position: absolute; inset: 0; z-index: 1; transform: translateX(100%); transition: transform 0.2s ease; }
  .chat-area.open { transform: translateX(0); z-index: 3; }
  .back-btn { display: inline-flex; }
  .bubble { max-width: 85%; }
  .info-panel { width: 100%; z-index: 6; }
  .chat-item-menu-wrap { opacity: 1; }
}
