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

:root {
  --white: #ffffff;
  --gray-50: #f7f7f8;
  --gray-100: #f0f0f2;
  --gray-200: #e4e4e7;
  --gray-300: #d1d1d6;
  --gray-400: #a8a8b3;
  --gray-500: #8b8b96;
  --gray-600: #6b6b76;
  --gray-700: #4a4a53;
  --gray-800: #2c2c33;
  --gray-900: #18181c;
  --accent: #2f6bff;
  --accent-hover: #2559e0;
  --accent-weak: #eaf0ff;
  --accent-text: #ffffff;
  --danger: #d1435b;
  --border: #e7e7ec;
  --border-strong: #d7d7de;

  --fs-12: 12px;
  --fs-14: 14px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-24: 24px;

  --ease: cubic-bezier(.2,.7,.3,1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--gray-50);
  color: var(--gray-900);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: var(--fs-14);
}

body { color-scheme: light; }

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

button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
}
button:active { transform: scale(0.96); }

img { max-width: 100%; display: block; }

svg.lucide { width: 18px; height: 18px; stroke-width: 1.8; flex-shrink: 0; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* -------------------------------------------------- app shell */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
}

.account-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
}

.account-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 5px;
  border-radius: 999px;
  background: var(--white);
  border: 1px solid var(--border);
  font-size: var(--fs-14);
  font-weight: 500;
  white-space: nowrap;
  position: relative;
}
.account-chip:hover { border-color: var(--border-strong); background: var(--gray-50); }

.account-chip.active {
  background: var(--accent-weak);
  border-color: #cddcff;
  color: var(--accent);
}
.account-chip.active:hover { background: #dfe9ff; }

.account-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray-400);
  position: absolute;
  right: 3px;
  bottom: 2px;
  border: 2px solid var(--white);
}

.account-chip.active .dot.online { background: #35c471; }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--white);
  background-size: cover;
  background-position: center;
  background-color: var(--gray-400);
  flex-shrink: 0;
  overflow: hidden;
}

.avatar.lg { width: 44px; height: 44px; font-size: var(--fs-16); }
.avatar.sm { width: 20px; height: 20px; font-size: 10px; }

.avatar.tone-0 { background: linear-gradient(140deg, #7c9bff, #4a6fe8); }
.avatar.tone-1 { background: linear-gradient(140deg, #ff9e7c, #e8664a); }
.avatar.tone-2 { background: linear-gradient(140deg, #6fd6a8, #34a97a); }
.avatar.tone-3 { background: linear-gradient(140deg, #ffc36f, #e89a34); }
.avatar.tone-4 { background: linear-gradient(140deg, #c68fff, #9450e8); }
.avatar.tone-5 { background: linear-gradient(140deg, #6fd1ff, #349ce8); }
.avatar.tone-6 { background: linear-gradient(140deg, #ff8fc1, #e84590); }

.add-account-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--white);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-600);
  flex-shrink: 0;
}
.add-account-btn:hover { background: var(--gray-50); border-color: var(--border-strong); color: var(--gray-900); }

.spacer { flex: 1; }

/* -------------------------------------------------- main layout */

.main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.dialogs-pane {
  width: 340px;
  min-width: 260px;
  max-width: 420px;
  flex-shrink: 0;
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.dialogs-search {
  padding: 12px 16px;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
}
.search-field svg {
  position: absolute;
  left: 11px;
  color: var(--gray-500);
  pointer-events: none;
}

.dialogs-search input {
  width: 100%;
  background: var(--gray-50);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px 9px 34px;
  font-size: var(--fs-14);
  outline: none;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.dialogs-search input:focus { background: var(--white); border-color: var(--accent); }
.dialogs-search input::placeholder { color: var(--gray-500); }

.dialogs-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none;      /* Firefox */
  -ms-overflow-style: none;   /* old Edge */
}
.dialogs-list::-webkit-scrollbar { display: none; } /* Chrome/Safari — scrolling still works */

.dialog-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  position: relative;
  border-bottom: 1px solid var(--gray-50);
  transition: background .12s var(--ease);
}

.dialog-item:hover { background: var(--gray-50); }
.dialog-item.active { background: var(--accent-weak); }
.dialog-item.active:hover { background: var(--accent-weak); }

.dialog-item .meta {
  flex: 1;
  min-width: 0;
}

.dialog-item .avatar { width: 44px; height: 44px; border-radius: 14px; font-size: var(--fs-16); }

.dialog-item .row1 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 4px;
}

.dialog-item .name {
  font-size: var(--fs-14);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-item .time {
  font-size: var(--fs-12);
  color: var(--gray-500);
  flex-shrink: 0;
}

.dialog-item .row2 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.dialog-item .preview {
  font-size: var(--fs-12);
  color: var(--gray-500);
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0; /* let the row actually shrink instead of pushing the badge out */
}
.dialog-item .preview svg { width: 13px; height: 13px; flex-shrink: 0; }
.dialog-item .preview-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.unread-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.empty-hint {
  padding: 24px 16px;
  color: var(--gray-500);
  font-size: var(--fs-14);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.empty-hint svg { color: var(--gray-300); width: 32px; height: 32px; }

/* -------------------------------------------------- skeleton / spinner */

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--gray-200);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  gap: 10px;
  font-size: var(--fs-14);
}

.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 37%, var(--gray-100) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }



.account-chip-sk { width: 120px; height: 32px; border-radius: 999px; }

/* -------------------------------------------------- chat pane */

.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  min-height: 60px;
  flex-shrink: 0;
  cursor: pointer;
}

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

.chat-header .name {
  font-size: var(--fs-14);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
}

.chat-header .status {
  font-size: var(--fs-12);
  color: var(--gray-500);
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-header .status .presence-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--gray-400); flex-shrink: 0;
}
.chat-header .status.online .presence-dot { background: #35c471; }
.chat-header .status.online { color: #2ba362; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-600);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--gray-100); border-color: var(--border); color: var(--gray-900); }

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-row {
  display: flex;
  margin: 4px 0;
  max-width: 100%;
  animation: msg-in .16s var(--ease);
}
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.msg-row.group { gap: 8px; align-items: flex-end; }
.msg-row.group .avatar { width: 36px; height: 36px; border-radius: 14px; font-size: var(--fs-14); margin-bottom: 2px; }
.msg-sender-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 3px;
}
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }

.msg-bubble {
  max-width: 62%;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--white);
  border: 1px solid var(--border);
  position: relative;
  font-size: var(--fs-14);
  line-height: 1.4;
  cursor: default;
}

.msg-row.out .msg-bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.msg-row.out .msg-bubble .msg-time,
.msg-row.out .msg-bubble .reply-quote { color: rgba(255,255,255,0.75); }

.msg-text { white-space: pre-wrap; word-break: break-word; }

.msg-edited-tag {
  font-size: 11px;
  opacity: 0.65;
  margin-left: 6px;
}

.msg-status {
  display: inline-flex;
  align-items: center;
  color: rgba(255,255,255,0.65);
}
.msg-status svg { width: 14px; height: 14px; stroke-width: 2.2; }
.msg-status.read { color: #ffffff; }

.dialog-status { color: var(--gray-400); flex-shrink: 0; }
.dialog-status svg { width: 13px; height: 13px; }
.dialog-status.read { color: var(--accent); }

.msg-time {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 3px;
  text-align: right;
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  align-items: center;
}

.reply-quote {
  border-left: 2px solid var(--accent);
  padding-left: 8px;
  margin-bottom: 6px;
  font-size: var(--fs-12);
  color: var(--gray-600);
  opacity: 0.85;
}

.msg-actions {
  position: absolute;
  top: -14px;
  right: 8px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: none;
  padding: 2px;
  gap: 2px;
}
.msg-row.in .msg-actions { left: 8px; right: auto; }
.msg-bubble:hover .msg-actions { display: flex; }

.msg-actions button {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-600);
}
.msg-actions button svg { width: 14px; height: 14px; }
.msg-actions button:hover { background: var(--gray-100); color: var(--gray-900); }

.reaction-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--gray-100);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.6;
}
.msg-row.out .reaction-chip { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.3); }
.reaction-chip:hover { background: var(--gray-200); }
.msg-row.out .reaction-chip:hover { background: rgba(255,255,255,0.28); }
.reaction-chip.mine { background: var(--accent-weak); border-color: #cddcff; color: var(--accent); }
.msg-row.out .reaction-chip.mine { background: rgba(255,255,255,0.9); color: var(--accent); border-color: transparent; }
.reaction-chip .count { font-weight: 600; }

.reaction-picker {
  position: fixed;
  z-index: 60;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  display: flex;
  gap: 2px;
}
.reaction-picker button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.reaction-picker button:hover { background: var(--gray-100); }

.attachment-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 8px;
  min-width: 180px;
}

.attachment-file .file-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: rgba(0,0,0,0.08);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.attachment-file .file-meta { min-width: 0; }
.attachment-file .file-name { font-size: var(--fs-14); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-file .file-size { font-size: var(--fs-12); opacity: 0.7; }

.attachment-photo img {
  border-radius: 10px;
  max-height: 320px;
  max-width: 100%;
  margin-bottom: 4px;
}

.attachment-audio audio { width: 220px; }

/* -------------------------------------------------- composer */

.composer {
  padding: 12px 20px 18px;
  background: var(--gray-50);
  flex-shrink: 0;
}

.reply-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  padding: 8px 12px;
  font-size: var(--fs-12);
  color: var(--gray-600);
}
.reply-preview .close { margin-left: auto; color: var(--gray-500); display: flex; }
.reply-preview .close:hover { color: var(--gray-900); }

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 6px 8px;
  transition: border-color .15s var(--ease);
}
.composer-box:focus-within { border-color: var(--border-strong); }
.reply-preview + .composer-box { border-radius: 0 0 18px 18px; }

.composer-box textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  max-height: 140px;
  padding: 8px 6px;
  font-size: var(--fs-14);
  line-height: 1.4;
  background: transparent;
}

.composer-box .icon-btn { color: var(--gray-500); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn svg { margin-left: -1px; }
.send-btn.disabled { background: var(--gray-200); color: var(--gray-500); cursor: default; }
.send-btn.disabled:hover { background: var(--gray-200); }

.mic-btn.recording { background: var(--danger); color: var(--white); }
.mic-btn.recording:hover { background: var(--danger); }

.no-chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  font-size: var(--fs-16);
  flex-direction: column;
  gap: 10px;
}
.no-chat-placeholder svg { width: 40px; height: 40px; color: var(--gray-300); }

/* -------------------------------------------------- modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20,20,24,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fade-in .15s var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: modal-in .16s var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

.modal.wide { width: 640px; }

.modal-title {
  font-size: var(--fs-18);
  font-weight: 600;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
}
.modal-close:hover { background: var(--gray-100); color: var(--gray-900); }

.modal-body { position: relative; overflow: auto; }

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0 4px;
}

.qr-box img {
  width: 220px;
  height: 220px;
  border-radius: 12px;
  background: var(--gray-100);
  border: 1px solid var(--border);
}

.qr-hint {
  font-size: var(--fs-14);
  color: var(--gray-600);
  text-align: center;
}

.raw-json {
  background: var(--gray-900);
  color: #d8f0d0;
  border-radius: 10px;
  padding: 14px;
  font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow: auto;
}

.profile-modal .avatar { margin: 0 auto 4px; }
.profile-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.profile-field .label { font-size: var(--fs-12); color: var(--gray-500); }
.profile-field .value { font-size: var(--fs-14); }

.btn {
  padding: 9px 16px;
  border-radius: 10px;
  background: var(--white);
  border: 1px solid var(--border);
  font-size: var(--fs-14);
  font-weight: 500;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:hover { background: var(--gray-50); border-color: var(--border-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: #fbe9ec; border-color: #f6d3d9; color: var(--danger); }
.btn.danger:hover { background: #f6d3d9; }
.btn.block { width: 100%; }

.row-actions { display: flex; gap: 10px; }

.toast-stack {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  align-items: center;
}
.toast {
  background: var(--gray-900);
  color: var(--white);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: var(--fs-14);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in .18s var(--ease);
  box-shadow: none;
}
.toast svg { width: 15px; height: 15px; flex-shrink: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (max-width: 760px) {
  .dialogs-pane { width: 100%; max-width: none; border-right: none; }
  .chat-pane { display: none; }
  .main.chat-open .chat-pane { display: flex; }
  .main.chat-open .dialogs-pane { display: none; }
  .msg-bubble { max-width: 82%; }
}
