:root {
  --bg: #0c0d10;
  --surface: #14161b;
  --surface-2: #1c1f26;
  --surface-3: #232731;
  --border: #23262e;
  --border-strong: #2d313b;
  --primary: #5b8cff;
  --primary-hover: #7099ff;
  --primary-soft: rgba(91, 140, 255, 0.12);
  --accent: #7c5cff;
  --text: #eef0f4;
  --text-secondary: #b6bac4;
  --text-muted: #7a8091;
  --success: #3ddc84;
  --danger: #ff5e5b;
  --warning: #ffb547;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 22px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  letter-spacing: -0.008em;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2e38; border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #383d4b; }

.bg-gradient {
  background:
    radial-gradient(circle at 20% 20%, rgba(91, 140, 255, 0.18) 0%, transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(124, 92, 255, 0.15) 0%, transparent 45%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Icons */
.icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }

/* ── Login ────────────────────────────────────────────────────────── */
.login-container { width: 100%; padding: 24px; }
.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  max-width: 400px;
  margin: 0 auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-card h1 { margin: 0 0 6px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.login-card .subtitle { color: var(--text-muted); margin: 0 0 28px; font-size: 14px; }
.login-card label {
  display: block;
  margin: 14px 0 6px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.login-card input[type=text], .login-card input[type=password] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
.login-card input:focus {
  border-color: var(--primary);
  background: var(--surface);
}
.login-card button {
  width: 100%;
  margin-top: 24px;
  padding: 13px;
  background: linear-gradient(135deg, #5b8cff 0%, #7c5cff 100%);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.08s;
  letter-spacing: -0.01em;
  font-family: inherit;
}
.login-card button:hover { opacity: 0.9; }
.login-card button:active { transform: scale(0.99); }
.error {
  background: rgba(255, 94, 91, 0.12);
  color: #ff8b89;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid rgba(255, 94, 91, 0.25);
}

/* ── Topbar ───────────────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  min-height: 58px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { flex-shrink: 0; margin-right: auto; }
.topbar .user-info { flex-wrap: wrap; justify-content: flex-end; min-width: 0; row-gap: 4px; }
.topbar .btn-link { white-space: nowrap; }
.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand .logo {
  width: 26px;
  height: 26px;
  color: #3ddc84;
  filter: drop-shadow(0 2px 6px rgba(61, 220, 132, 0.35));
}
.user-info { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-info .user-name { font-weight: 600; color: var(--text); }
.user-info .user-role { color: var(--text-muted); font-size: 12px; margin-left: 4px; }
.btn-link {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-link:hover { background: var(--surface-2); color: var(--text); }
.btn-link .icon { width: 14px; height: 14px; }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.status-dot.on { background: var(--success); box-shadow: 0 0 8px rgba(61, 220, 132, 0.6); }
.status-dot.off { background: var(--danger); box-shadow: 0 0 8px rgba(255, 94, 91, 0.6); }

/* ── Layout ───────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100vh - 58px);
  height: calc(100dvh - 58px);
  min-height: 0;
}
.chat-list {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
}
.chat-list-header {
  padding: 18px 20px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 5;
}
.chat-list-header span {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--text);
}
.chat-list-header button {
  background: var(--surface-2);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-list-header button:hover { background: var(--surface-3); color: var(--text); }

/* Chat item */
.chat-item {
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.12s;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  position: relative;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--primary-soft); }
.chat-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.chat-item .avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  flex-shrink: 0;
  position: relative;
  overflow: visible;
}
.ava-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.chat-item .body { min-width: 0; }
.chat-item .top-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.chat-item .name-text {
  font-weight: 600;
  font-size: 14.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.chat-item .preview {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.chat-item .preview-thumb {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.chat-item .preview-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.chat-item .right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.chat-item .time {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.chat-item .badge {
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 2px 6px rgba(91, 140, 255, 0.4);
}
.chat-item .status {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.chat-item .status.unassigned { background: rgba(255, 181, 71, 0.15); color: #ffc66b; }
.chat-item .status.assigned { background: rgba(91, 140, 255, 0.15); color: #8aabff; }
.chat-item .status.transferred { background: rgba(191, 90, 242, 0.15); color: #d4a5ff; }

/* Platform badge on avatar */
.platform-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
  box-sizing: content-box;
}
.platform-badge.telegram { background: #229ED9; }
.platform-badge.whatsapp { background: #25D366; }
.platform-badge.max { background: #7B5BF0; }
.platform-badge svg { width: 10px; height: 10px; color: white; }

/* ── Chat area ────────────────────────────────────────────────────── */
.chat-area {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-height: 0;
  overflow: hidden;
}
#chat-view { min-height: 0; }

.placeholder {
  margin: auto;
  color: var(--text-muted);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.placeholder .icon-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.15), rgba(124, 92, 255, 0.15));
  border: 1px solid var(--border);
  color: var(--primary);
}
.placeholder .icon-circle svg { width: 32px; height: 32px; }

.chat-header {
  background: var(--surface);
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  min-height: 64px;
}
#chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  min-width: 0;
  flex: 1;
}
#chat-title .header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  position: relative;
}
#chat-title .title-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
#chat-title .title-main {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
#chat-title .title-sub {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  background: var(--bg);
}
.msg {
  max-width: 65%;
  width: fit-content;
  min-width: 0;
  padding: 5px 9px 5px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.3;
  word-wrap: break-word;
  white-space: normal;
  position: relative;
  letter-spacing: -0.005em;
}
.msg .msg-text {
  white-space: pre-wrap;
  word-wrap: break-word;
}
/* Inline time at bottom-right */
.msg .meta {
  float: right;
  font-size: 10px;
  opacity: 0.6;
  margin-left: 8px;
  margin-top: 3px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}
.msg.out .meta { opacity: 0.75; }
.msg::after { content: ""; clear: both; display: table; }
.msg.in {
  background: var(--surface-2);
  align-self: flex-start;
  color: var(--text);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--border);
}
.msg.out {
  background: linear-gradient(135deg, #5b8cff 0%, #7c5cff 100%);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 14px rgba(91, 140, 255, 0.3);
}
/* (inline meta defined above) */
.msg.out .meta { text-align: right; }
.msg.in .meta { color: var(--text-muted); opacity: 1; }

/* Composer */
.composer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  font-family: inherit;
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  line-height: 1.35;
  max-height: 120px;
  background: var(--surface-2);
  color: var(--text);
}
.composer textarea::placeholder { color: var(--text-muted); }
.composer textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
}
.composer button#send-btn {
  padding: 0;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #5b8cff 0%, #7c5cff 100%);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.08s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(91, 140, 255, 0.4);
}
.composer button#send-btn:hover { opacity: 0.92; }
.composer button#send-btn:active { transform: scale(0.95); }
.composer button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--surface-2);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, color 0.15s;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.attach-btn:hover { background: var(--surface-3); color: var(--text); }
.attach-btn.recording { background: var(--primary, #6c8aff); color: white; }
.voice-cancel-btn { color: var(--danger) !important; }
.voice-cancel-btn:hover { background: rgba(255, 94, 91, 0.15) !important; }
.voice-rec-time {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 600;
}
.voice-rec-time::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.4s infinite;
}

/* Deleted message bubble — muted, italic, no media/reactions/actions */
.msg.deleted {
  background: var(--surface-2, #2a2c34) !important;
  color: var(--text-muted, #8a8e9b) !important;
  font-style: italic;
  box-shadow: none !important;
  border: 1px dashed var(--border, #3a3d48) !important;
}
.msg.deleted .msg-text.deleted-text {
  display: inline-flex;
  align-items: center;
  font-style: italic;
  opacity: 0.85;
}
.msg.deleted .meta { color: var(--text-muted); opacity: 0.6; }
.msg.deleted .msg-actions { display: none !important; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 94, 91, 0.6); }
  50% { box-shadow: 0 0 0 10px rgba(255, 94, 91, 0); }
}

/* Buttons */
.btn {
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  color: var(--text);
  font-family: inherit;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: linear-gradient(135deg, #5b8cff 0%, #7c5cff 100%); color: white; border-color: transparent; }
.btn.primary:hover { opacity: 0.9; }
.btn.danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn.warn { background: var(--warning); color: white; border-color: var(--warning); }
.btn.transfer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}
.btn.transfer:hover { background: var(--surface-3); color: var(--text); }
.btn.transfer .icon { color: var(--text-muted); }

.select-inline {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}

#chat-actions { display: flex; gap: 8px; align-items: center; }

/* ── Modal ────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 92%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.modal-card h3 { margin: 0 0 6px; font-size: 19px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.modal-card .subtitle { font-size: 13px; color: var(--text-muted); margin: 0 0 18px; }
.modal-card input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  background: var(--surface-2);
  color: var(--text);
}
.modal-card input::placeholder { color: var(--text-muted); }
.modal-card input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.platform-picker { display: flex; gap: 8px; margin-bottom: 14px; }
.platform-picker label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  user-select: none;
  transition: all 0.15s;
  background: var(--surface-2);
  color: var(--text);
}
.platform-picker input { display: none; }
.platform-picker label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* ── Media in messages ───────────────────────────────────────────── */
.msg audio.msg-audio {
  width: 100%;
  max-width: 280px;
  display: block;
  margin-bottom: 4px;
  filter: invert(0.88) hue-rotate(180deg);
}
.msg.out audio.msg-audio { filter: none; }

/* Custom voice player */
.voice-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 6px 10px 6px 6px;
  margin-bottom: 4px;
  --played: 0%;
}
.voice-msg .voice-play {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.voice-msg .voice-play:hover { background: rgba(255, 255, 255, 0.28); }
.voice-msg .voice-play:active { transform: scale(0.94); }
.msg.in .voice-msg .voice-play {
  background: var(--primary, #6c8aff);
}
.msg.in .voice-msg .voice-play:hover {
  background: var(--primary-hover, #557af0);
}
.voice-msg .voice-wave {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 28px;
  cursor: pointer;
  position: relative;
}
.voice-msg .voice-wave span {
  flex: 1;
  background: rgba(255, 255, 255, 0.38);
  border-radius: 2px;
  min-height: 4px;
}
.voice-msg .voice-wave span.played {
  background: #fff;
}
.msg.in .voice-msg .voice-wave span {
  background: rgba(150, 160, 200, 0.55);
}
.msg.in .voice-msg .voice-wave span.played {
  background: var(--primary, #6c8aff);
}
.voice-msg .voice-dur {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
  min-width: 30px;
  text-align: right;
}
.voice-msg.voice-err .voice-dur { color: #f88; }
.voice-msg .voice-speed {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: inherit;
  font: 600 11px/1 inherit;
  padding: 4px 7px;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
  transition: opacity 0.15s, background 0.15s;
}
.voice-msg .voice-speed:hover { opacity: 1; }
.voice-msg .voice-speed.active {
  opacity: 1;
  background: rgba(255, 255, 255, 0.32);
}
.msg.in .voice-msg .voice-speed {
  background: rgba(120, 130, 200, 0.2);
}
.msg.in .voice-msg .voice-speed.active {
  background: var(--primary, #6c8aff);
  color: #fff;
}
.msg img.msg-img {
  max-width: 240px;
  max-height: 280px;
  width: auto;
  height: auto;
  border-radius: 10px;
  display: block;
  cursor: zoom-in;
  margin-bottom: 4px;
  object-fit: cover;
}
/* When bubble contains an image, keep it tight around the image */
.msg:has(> img.msg-img) {
  max-width: 260px;
  padding: 3px;
}
.msg:has(> img.msg-img) img.msg-img {
  width: 100%;
  max-width: 100%;
  max-height: 320px;
  margin-bottom: 0;
  border-radius: 11px;
}
.msg:has(> img.msg-img) .msg-text {
  padding: 4px 7px 2px;
  display: block;
}
.msg:has(> img.msg-img) .meta {
  padding: 0 7px 4px;
}
/* Album grid */
.msg.album { max-width: 320px; padding: 3px; }
.album-grid { display: grid; gap: 2px; border-radius: 11px; overflow: hidden; }
.album-grid.album-2 { grid-template-columns: 1fr 1fr; }
.album-grid.album-3 { grid-template-columns: 1fr 1fr; }
.album-grid.album-3 .album-img:first-child { grid-column: 1 / -1; }
.album-grid.album-4plus { grid-template-columns: 1fr 1fr; }
.album-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  aspect-ratio: 1 / 1;
  cursor: zoom-in;
  display: block;
  max-height: 160px;
}
.msg.album .msg-text { display: block; padding: 4px 7px 2px; }
.msg.album .meta { padding: 0 7px 4px; }
/* Stickers: no bubble, no padding, transparent */
.msg.sticker {
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  padding: 0 !important;
  max-width: 150px;
}
.msg.sticker .msg-img {
  max-width: 150px;
  max-height: 150px;
  background: transparent;
  cursor: default;
}
.msg.sticker .meta {
  padding: 0 4px;
}
.img-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: zoom-out;
}
.img-viewer img {
  max-width: 95vw;
  max-height: 95vh;
  border-radius: var(--radius-sm);
}

#attach-preview {
  padding: 10px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
#attach-preview img {
  max-height: 60px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
#attach-preview .cancel {
  background: var(--surface-2);
  border: none;
  cursor: pointer;
  color: var(--danger);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#attach-preview .cancel:hover { background: var(--surface-3); }

/* ── Reply / React ───────────────────────────────────────────────── */
.reply-quote {
  border-left: 3px solid var(--primary);
  padding: 6px 10px;
  margin-bottom: 6px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  max-height: 60px;
  overflow: hidden;
}
.msg.out .reply-quote {
  background: rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.92);
  border-left-color: rgba(255,255,255,0.7);
}

.reply-preview {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
}
.reply-preview .cancel {
  background: var(--surface-2);
  border: none;
  color: var(--danger);
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.reply-preview .cancel:hover { background: var(--surface-3); }

.react-row {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.react-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  font-size: 13px;
}
.msg.out .react-chip {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.3);
}
.tick {
  display: inline-block;
  margin-left: 4px;
  font-size: 11px;
  opacity: 0.7;
  letter-spacing: -2px;
}
.tick.read { color: #4fc3ff; opacity: 1; }
.msg.out .tick { color: rgba(255,255,255,0.75); }
.msg.out .tick.read { color: #9ddfff; opacity: 1; }

/* Message action menu */
.msg-actions {
  position: absolute;
  top: -14px;
  left: 0;
  right: auto;
  display: none;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 3px 5px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}
.msg.out .msg-actions { left: auto; right: 0; }
.msg:hover .msg-actions { display: flex; }
.msg-actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  color: var(--text-secondary);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.msg-actions button:hover { background: var(--surface-2); color: var(--text); }
.msg-actions .icon { width: 15px; height: 15px; }

.react-picker {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 6px 8px;
  display: flex;
  gap: 2px;
  box-shadow: var(--shadow-lg);
  z-index: 150;
}
.react-picker button {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 50%;
  transition: transform 0.1s, background 0.15s;
}
.react-picker button:hover { background: var(--surface-2); transform: scale(1.15); }

/* Toast notification (top) */
.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  max-width: 92%;
  pointer-events: none;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast.warn { color: #ff8b89; border-color: rgba(255, 94, 91, 0.4); background: #1b1113; }
.toast .icon { width: 16px; height: 16px; flex-shrink: 0; }

/* Mobile back */
.mobile-back {
  display: none;
  background: var(--surface-2);
  border: none;
  width: 36px;
  height: 36px;
  padding: 0;
  cursor: pointer;
  color: var(--text);
  border-radius: 50%;
  align-items: center;
  justify-content: center;
}

/* ── Mobile ───────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  .topbar { padding: 0 12px; height: 54px; }
  .brand { font-size: 14px; }
  .user-info { font-size: 12px; gap: 6px; }
  .btn-link { padding: 5px 8px; font-size: 12px; }

  .layout {
    grid-template-columns: 1fr;
    height: calc(100vh - 54px);
    height: calc(100dvh - 54px);
  }

  .chat-list { display: block; border-right: none; }
  .chat-area { display: none; }

  body.chat-open .chat-list { display: none; }
  body.chat-open .chat-area { display: flex; }

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

  .chat-header { padding: 10px 14px; min-height: 56px; }
  #chat-title .title-main { font-size: 14px; }
  #chat-title .header-avatar { width: 34px; height: 34px; font-size: 12px; }
  #chat-actions .btn,
  #chat-actions .select-inline { font-size: 12px; padding: 6px 10px; }

  .messages { padding: 10px; gap: 3px; }
  .msg { max-width: min(fit-content, 75%); font-size: 13.5px; padding: 5px 9px 3px; border-radius: 12px; }
  .msg img.msg-img { max-width: 160px; max-height: 160px; border-radius: 8px; }
  .msg.sticker { background: transparent !important; box-shadow: none !important; border: none !important; padding: 0 !important; max-width: 130px; }
  .msg.sticker img.msg-img { max-width: 130px; max-height: 130px; background: transparent; }
  .msg .meta { font-size: 9.5px; }

  .composer { padding: 10px 12px; gap: 6px; }
  .composer textarea { font-size: 15px; padding: 9px 14px; }

  .chat-list-header { padding: 14px 16px 10px; }
  .chat-list-header span { font-size: 17px; }
  .chat-item { padding: 12px 14px; }
  .chat-item .avatar { width: 44px; height: 44px; font-size: 15px; }
  .chat-item .name-text { font-size: 15px; }

  .modal-card { padding: 22px; max-width: 92%; }

  /* on mobile: hide actions by default, show only when message is tapped */
  .msg-actions { display: none; top: -14px; }
  .msg.selected .msg-actions { display: flex; }
}
