/* ==================================================================
   IROTECHLAB MESSANGER — theme v15 (desktop empty state fixed)
================================================================== */

:root {
  --primary: #E63946;
  --primary-dark: #C42E3B;
  --accent: #F77F00;
  --success: #22C55E;
  --danger: #EF4444;
  --border: rgba(255,255,255,0.08);
  --muted: #8A8A90;
  --muted-2: #5A5A60;
}

html.dark {
  --bg: #0E0E10;
  --panel: #1A1A1D;
  --elev: #242428;
  --text: #F2F2F4;
  --bubble-theirs-bg: #242428;
  --bubble-theirs-text: #E9E9EC;
  --tick-color: rgba(255,255,255,0.85);
  --tick-read: #4FC3F7;
}
html.dark body { background: var(--bg); color: var(--text); }

html:not(.dark) {
  --border: rgba(0,0,0,0.08);
  --muted: #6A6A70;
  --muted-2: #9A9AA0;
  --bg: #F2F2F5;
  --panel: #FFFFFF;
  --elev: #FFFFFF;
  --text: #111114;
  --bubble-theirs-bg: #FFFFFF;
  --bubble-theirs-text: #111114;
  --tick-color: #4A4A50;
  --tick-read: #2196F3;
}
html:not(.dark) body { background: var(--bg); color: var(--text); }

* { -webkit-tap-highlight-color: transparent; }
html, body { font-family: 'Inter', ui-sans-serif, system-ui, sans-serif; }

.gradient-bg {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(230,57,70,0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 20%, rgba(247,127,0,0.05), transparent 60%),
    linear-gradient(135deg, var(--bg) 0%, var(--bg) 100%);
}

.glass {
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}
html.dark .glass { background: rgba(20,20,23,0.85); }

.screen { position: relative; }

/* ================================================================
   BRAND LOGO
================================================================ */
.brand-logo {
  width: 40px; height: 40px;
  flex-shrink: 0;
  color: var(--text);
  display: block;
  object-fit: contain;
}
.brand-logo.sm { width: 28px; height: 28px; }
.brand-logo.lg { width: 48px; height: 48px; }
.brand-logo.xl { width: 64px; height: 64px; }

.brand-logo.glow {
  filter: drop-shadow(0 0 10px rgba(230,57,70,0.35));
}
.brand-logo.watermark {
  opacity: 0.10;
  filter: none;
}

html:not(.dark) .brand-logo {
  filter: invert(1) brightness(0.15);
}
html:not(.dark) .brand-logo.glow {
  filter: invert(1) brightness(0.15) drop-shadow(0 0 10px rgba(230,57,70,0.35));
}
html:not(.dark) .brand-logo.watermark {
  filter: invert(1) brightness(0.15);
  opacity: 0.10;
}

/* AVATAR IMAGE */
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* ================================================================
   TOP BUTTONS
================================================================ */
.top-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: transparent; border: 0; cursor: pointer;
  color: var(--muted); transition: .15s;
}
.top-btn:hover { background: rgba(128,128,128,0.12); color: var(--text); }

.shadow-glow { box-shadow: 0 8px 30px -10px rgba(230,57,70,0.65); }

/* ================================================================
   INPUTS
================================================================ */
input, textarea, select {
  background-color: transparent !important;
  color: inherit !important;
  -webkit-text-fill-color: inherit;
  caret-color: var(--primary);
}
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--elev) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  transition: background-color 9999s ease-in-out 0s;
  caret-color: var(--primary);
}

.input-wrap {
  display: flex; align-items: center; gap: 10px;
  background: rgba(128,128,128,0.08);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 14px;
  transition: .2s;
}
.input-wrap:focus-within {
  border-color: rgba(230,57,70,0.6);
  background: rgba(230,57,70,0.05);
  box-shadow: 0 0 0 3px rgba(230,57,70,0.10);
}
.input-wrap i { color: var(--muted); font-size: 14px; flex-shrink: 0; }
.input-wrap input {
  flex: 1; background: transparent !important; border: 0; outline: 0;
  padding: 12px 0; color: inherit; font-size: 14px; min-width: 0;
  box-shadow: none !important;
}
.input-wrap input::placeholder { color: var(--muted-2); }

.bio-input {
  width: 100%;
  background: rgba(128,128,128,0.08) !important;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  color: inherit;
  outline: none;
  resize: vertical;
  min-height: 68px;
  transition: .2s;
}
.bio-input:focus {
  border-color: rgba(230,57,70,0.6);
  background: rgba(230,57,70,0.05) !important;
  box-shadow: 0 0 0 3px rgba(230,57,70,0.10);
}
.bio-input::placeholder { color: var(--muted-2); }

/* ================================================================
   BUTTONS
================================================================ */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; border: 0; cursor: pointer;
  transition: transform .15s, box-shadow .2s, opacity .2s;
  box-shadow: 0 10px 25px -10px rgba(230,57,70,0.7);
}
.btn-primary:hover { transform: translateY(-1px);
  box-shadow: 0 14px 30px -10px rgba(230,57,70,0.85); }
.btn-primary:disabled { opacity: .6; cursor: wait; }

.btn-ghost {
  background: rgba(128,128,128,0.12);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: .15s;
}
.btn-ghost:hover { background: rgba(128,128,128,0.2); }

.btn-ghost-red {
  background: rgba(230,57,70,0.10);
  color: var(--primary);
  border: 1px solid rgba(230,57,70,0.30);
  cursor: pointer;
  transition: .15s;
}
.btn-ghost-red:hover { background: rgba(230,57,70,0.18); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; transition: .2s;
}
.icon-btn:hover { background: rgba(128,128,128,0.12); color: var(--text); }

/* ================================================================
   LOADING SPINNER
================================================================ */
.btn-loading {
  pointer-events: none;
  opacity: 0.85;
  position: relative;
}
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
.spinner.dark {
  border-color: rgba(0,0,0,0.25);
  border-top-color: var(--primary);
}
@keyframes spin { to { transform: rotate(360deg); } }
.top-btn .spinner {
  width: 14px; height: 14px;
  border-width: 2px;
  border-color: rgba(230,57,70,0.35);
  border-top-color: var(--primary);
}
.settings-select.btn-loading { opacity: 0.7; }

/* ================================================================
   COMPOSER
================================================================ */
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px 6px;
}
.composer-btn {
  width: 40px; height: 40px;
  flex-shrink: 0;
  border-radius: 12px;
  display: grid; place-items: center;
  padding: 0; line-height: 1;
}
.icon-btn.composer-btn {
  background: rgba(128,128,128,0.08);
  border: 1px solid var(--border);
  color: var(--muted);
}
.icon-btn.composer-btn:hover {
  background: rgba(128,128,128,0.14);
  color: var(--text);
}
.send-btn.composer-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; border: 0;
  box-shadow: 0 8px 22px -8px rgba(230,57,70,0.7);
  transition: transform .15s, box-shadow .2s;
}
.send-btn.composer-btn:hover { transform: translateY(-1px); }

#msg-input {
  flex: 1; min-width: 0;
  background: rgba(128,128,128,0.10) !important;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14.5px;
  line-height: 20px;
  padding: 10px 16px;
  border-radius: 22px;
  resize: none; outline: none;
  max-height: 128px;
  min-height: 40px;
  height: 40px;
  transition: border-color .15s, background .15s;
}
#msg-input:focus {
  border-color: rgba(230,57,70,0.55);
  background: rgba(230,57,70,0.06) !important;
  box-shadow: 0 0 0 3px rgba(230,57,70,0.10);
}

/* ================================================================
   CHAT MESSAGES + EMPTY STATE
================================================================ */
#messages {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}
/* spacer pushes real messages to bottom when there are few */
#messages::before {
  content: '';
  flex: 1 0 auto;
}

/* when the empty state is active */
#messages.has-empty {
  justify-content: center;
}
#messages.has-empty::before {
  display: none;
}

#chat-empty {
  display: none;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
#messages.has-empty #chat-empty {
  display: flex;
}

/* ================================================================
   CHAT BUBBLES
================================================================ */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  width: 100%;
  animation: msgIn .18s ease-out;
  position: relative;
}
.msg-row.mine   { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

.bubble-wrap {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 4px;
  max-width: 82%;
  position: relative;
}
@media (min-width: 640px) { .bubble-wrap { max-width: 68%; } }

.bubble-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  max-width: 100%;
  order: 1;
}
.msg-row.mine .bubble-col { align-items: flex-end; }
.msg-row.mine   .bubble-col { align-items: flex-end; }
.msg-row.theirs .bubble-col { align-items: flex-start; }

.msg-row.mine   .bubble-menu-btn { order: 0; }
.msg-row.theirs .bubble-menu-btn { order: 2; }

.bubble {
  padding: 6px 10px 5px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.32;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  width: fit-content;
  max-width: 100%;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  cursor: pointer;
  transition: background .15s;
}
.bubble .bubble-text { display: block; white-space: pre-wrap; word-break: break-word; }

.bubble.mine {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-bottom-right-radius: 3px;
}
.bubble.theirs {
  background: var(--bubble-theirs-bg);
  border: 1px solid var(--border);
  color: var(--bubble-theirs-text);
  border-bottom-left-radius: 3px;
}

.msg-meta {
  font-size: 10px;
  color: rgba(255,255,255,0.7);
  margin-top: 1px;
  align-self: flex-end;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.bubble.mine .msg-meta { color: rgba(255,255,255,0.8); }
.bubble.theirs .msg-meta { color: var(--muted); }
.msg-meta .edited { font-style: italic; opacity: .85; }

.tick { display: inline-flex; align-items: center; line-height: 1; font-size: 10px; margin-left: 1px; }
.tick i { font-size: 10px; }
.tick[data-state="read"] i { color: var(--tick-read); }
.tick[data-state="delivered"] i { color: rgba(255,255,255,0.9); }
.tick[data-state="sent"] i { color: rgba(255,255,255,0.7); }

.bubble-menu-btn {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--elev);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer; font-size: 12px;
  align-self: flex-end;
  margin-bottom: 4px;
  flex-shrink: 0;
  animation: msgIn .15s;
}
.bubble-menu-btn:hover { color: var(--text); }

/* ================================================================
   DROPDOWN + POPOVER
================================================================ */
.msg-dropdown {
  position: fixed;
  z-index: 70;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  min-width: 150px;
  box-shadow: 0 14px 40px -10px rgba(0,0,0,0.35);
  animation: popIn .14s ease-out;
}
html.dark .msg-dropdown { background: #1E1E22; }
.msg-dropdown button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 12px;
  background: transparent; border: 0; cursor: pointer;
  border-radius: 10px;
  color: var(--text); font-size: 13.5px; text-align: left;
  transition: background .12s;
}
.msg-dropdown button i { width: 16px; text-align: center; color: var(--muted); }
.msg-dropdown button:hover { background: rgba(230,57,70,0.12); color: var(--primary); }
.msg-dropdown button:hover i { color: var(--primary); }

.reaction-pop {
  position: fixed;
  z-index: 71;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px -8px rgba(0,0,0,0.35);
  animation: popIn .14s ease-out;
}
html.dark .reaction-pop { background: #1E1E22; }
.reaction-pop button {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: transparent; border: 0; cursor: pointer;
  font-size: 19px; line-height: 1;
  transition: transform .12s, background .12s;
  padding: 0;
}
.reaction-pop button:hover { background: rgba(230,57,70,0.15); transform: scale(1.2); }

/* ================================================================
   INLINE EDIT
================================================================ */
.edit-wrap {
  display: flex; flex-direction: column; gap: 6px;
  width: 100%;
}
.edit-wrap textarea {
  width: 100%;
  background: rgba(0,0,0,0.06) !important;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  color: inherit; font-size: 14px; line-height: 1.35;
  resize: vertical; min-height: 40px;
  outline: none;
}
.edit-actions { display: flex; gap: 6px; justify-content: flex-end; }
.edit-actions button {
  padding: 4px 12px; border-radius: 8px; border: 0; cursor: pointer;
  font-size: 12px; font-weight: 600;
}
.edit-actions .save { background: #fff; color: var(--primary); }
.edit-actions .cancel { background: rgba(255,255,255,0.2); color: #fff; }

/* ================================================================
   REACTIONS
================================================================ */
.reactions-row {
  display: flex; flex-wrap: wrap; gap: 3px;
  padding: 0 1px; margin-top: 2px;
}
.reaction-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 6px; height: 19px; font-size: 11px; line-height: 1;
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
  transition: background .15s, transform .1s;
}
.reaction-chip:hover { transform: scale(1.06); }
.reaction-chip.active {
  background: rgba(230,57,70,0.20);
  border-color: rgba(230,57,70,0.55);
  color: var(--primary);
}
html.dark .reaction-chip.active { background: rgba(230,57,70,0.30); }
.reaction-chip .emoji { font-size: 11px; line-height: 1; }
.reaction-chip .count { font-size: 10px; font-weight: 600; line-height: 1; }

/* ================================================================
   EMOJI PICKER
================================================================ */
.emoji-picker {
  position: absolute;
  bottom: 64px; left: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(340px, calc(100vw - 24px));
  box-shadow: 0 20px 40px -10px rgba(0,0,0,0.45);
  z-index: 40;
  overflow: hidden;
  animation: msgIn .15s ease-out;
}
html.dark .emoji-picker { background: #1A1A1D; }
.emoji-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 4px 6px;
  gap: 2px;
  overflow-x: auto;
}
.emoji-tabs button {
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 8px;
  border: 0; background: transparent; cursor: pointer;
  font-size: 18px; line-height: 1;
  transition: background .12s;
}
.emoji-tabs button.active { background: rgba(230,57,70,0.15); }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  max-height: 260px;
  overflow-y: auto;
}
.emoji-grid button {
  width: 34px; height: 34px; border-radius: 8px;
  background: transparent; border: 0; cursor: pointer;
  font-size: 20px; line-height: 1; transition: .15s;
  display: grid; place-items: center;
}
.emoji-grid button:hover { background: rgba(230,57,70,0.20); transform: scale(1.15); }

/* ================================================================
   CONVERSATIONS LIST
================================================================ */
.conv-item {
  display: flex; gap: 12px; align-items: center;
  padding: 10px 14px; cursor: pointer;
  transition: background .15s; position: relative;
}
.conv-item:hover { background: rgba(128,128,128,0.08); }
.conv-item.active { background: rgba(230,57,70,0.10); }
.conv-item .avatar-wrap { position: relative; flex-shrink: 0; }
.conv-item .avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
  overflow: hidden;
}
.conv-item .presence-dot {
  position: absolute;
  bottom: 0; right: 0;
  width: 12px; height: 12px; border-radius: 50%;
  background: #22C55E;
  border: 2px solid var(--bg);
  display: none;
}
.conv-item.online .presence-dot { display: block; }

.conv-item .meta { flex: 1; min-width: 0; }
.conv-item .name {
  font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .preview {
  font-size: 12px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-item .unread {
  background: var(--primary); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px;
  display: grid; place-items: center; flex-shrink: 0;
}

/* ================================================================
   SEARCH
================================================================ */
.search-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; cursor: pointer; transition: background .15s;
}
.search-item:hover { background: rgba(230,57,70,0.10); }
.search-item .avatar-wrap { position: relative; flex-shrink: 0; }
.search-item .avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: grid; place-items: center;
  font-weight: 600; font-size: 14px; color: #fff;
  overflow: hidden;
}
.search-item .presence-dot {
  position: absolute; bottom: 0; right: 0;
  width: 11px; height: 11px; border-radius: 50%;
  background: #22C55E;
  border: 2px solid var(--bg);
  display: none;
}
.search-item.online .presence-dot { display: block; }
.search-item .u { font-size: 14px; font-weight: 600; }
.search-item .n { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ================================================================
   MODALS
================================================================ */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
}
.modal-card {
  width: 100%; max-width: 420px;
  border-radius: 24px;
  border: 1px solid var(--border);
  padding: 22px;
  animation: popIn .18s ease-out;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.lbl {
  font-size: 11px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
}
.settings-select {
  width: 100%;
  background: rgba(128,128,128,0.08) !important;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  color: inherit;
  cursor: pointer;
  outline: none;
}
.settings-select:focus { border-color: rgba(230,57,70,0.6); }

.modal-card-tall {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.modal-card-tall .modal-head {
  padding: 18px 22px 14px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-card-tall .modal-body {
  padding: 18px 22px 22px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

#profile-save-btn { color: var(--primary); }
#profile-save-btn:hover { background: rgba(230,57,70,0.12); color: var(--primary); }

.reaction-slots {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.reaction-slot {
  aspect-ratio: 1;
  border-radius: 12px;
  background: rgba(128,128,128,0.10);
  border: 1px dashed var(--border);
  display: grid; place-items: center;
  font-size: 22px; line-height: 1;
  cursor: pointer;
  transition: .15s;
}
.reaction-slot:hover { background: rgba(230,57,70,0.10); border-color: rgba(230,57,70,0.4); }
.reaction-slot.empty { color: var(--muted-2); font-size: 18px; }

.menu-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 12px 14px;
  background: transparent; border: 0; cursor: pointer;
  border-radius: 12px; color: var(--text);
  font-size: 14px; font-weight: 500; text-align: left;
  transition: .15s;
}
.menu-item i { width: 18px; text-align: center; color: var(--muted); }
.menu-item:hover { background: rgba(230,57,70,0.12); }
.menu-item:hover i { color: var(--primary); }

/* ================================================================
   MISC
================================================================ */
.typing-dots { display: inline-flex; gap: 3px; margin-right: 4px; vertical-align: middle; }
.typing-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; animation: bounce 1s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30%           { transform: translateY(-4px); opacity: 1; }
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.9) translateY(4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.25); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(230,57,70,0.5); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px; border-radius: 18px;
  font-size: 13px; z-index: 100;
  box-shadow: 0 12px 30px -10px rgba(0,0,0,0.4);
  animation: msgIn .2s ease-out;
}
.toast.error { border-color: rgba(239,68,68,0.5); }
.toast.success { border-color: rgba(34,197,94,0.5); }

#drawer.open { transform: translateX(0); }
/* Red rounded-square brand badge (empty state) */
.empty-logo-wrap {
  display: inline-grid;
  place-items: center;
  width: 96px;
  height: 96px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 26px;
  box-shadow: 0 12px 40px -10px rgba(230,57,70,0.55);
  margin: 0 auto 20px;
}
.empty-logo-wrap .brand-logo {
  width: 64px;
  height: 64px;
  filter: none !important;
  opacity: 1 !important;
}

/* ================================================================
   BOOT OVERLAY
================================================================ */
.boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  background: var(--bg);
  transition: opacity .18s ease-out, visibility .18s ease-out;
}
.boot-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.boot-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
}

.boot-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(230,57,70,0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-top: 4px;
}

.boot-status {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.02em;
  min-height: 18px;
}

/* error variant */
.boot-status.error {
  color: #EF4444;
}
.boot-retry {
  margin-top: 16px;
  padding: 8px 20px;
  border-radius: 12px;
  border: 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 8px 22px -8px rgba(230,57,70,0.7);
  display: none;
}
.boot-overlay.has-error .boot-retry { display: inline-block; }
.boot-overlay.has-error .boot-spinner { display: none; }

/* ================================================================
   GROUPS / CHANNELS
================================================================ */
.thread-avatar { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); }
.thread-avatar i { font-size: 20px; color: #fff; }

.msg-author {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  padding: 0 4px 2px;
  letter-spacing: 0.02em;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  transition: background .15s;
}
.member-row:hover { background: rgba(128,128,128,0.08); }
.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}
.role-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(230,57,70,0.15);
  color: var(--primary);
  border: 1px solid rgba(230,57,70,0.3);
}

/* Group message author row (avatar + name above bubble) */
.msg-author-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px 3px;
}
.msg-author-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: grid;
  place-items: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}
.msg-author-avatar .avatar-img { width: 100%; height: 100%; }

.msg-author {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ================================================================
   GC dropdown + search tabs + thread helpers
================================================================ */
.gc-wrap { position: relative; display: inline-block; }
.gc-dropdown {
  position: absolute;
  top: 46px;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  min-width: 180px;
  box-shadow: 0 14px 40px -10px rgba(0,0,0,0.35);
  z-index: 80;
  animation: popIn .14s ease-out;
}
html.dark .gc-dropdown { background: #1E1E22; }
.gc-dropdown button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px;
  background: transparent; border: 0; cursor: pointer;
  border-radius: 10px;
  color: var(--text); font-size: 13.5px; text-align: left;
  transition: background .12s;
}
.gc-dropdown button i { width: 16px; text-align: center; color: var(--muted); }
.gc-dropdown button:hover { background: rgba(230,57,70,0.12); color: var(--primary); }
.gc-dropdown button:hover i { color: var(--primary); }

.search-tabs {
  display: flex; gap: 6px;
  margin-bottom: 8px;
}
.stab {
  flex: 1;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(128,128,128,0.08);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px; font-weight: 600;
  cursor: pointer; transition: .15s;
}
.stab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-color: transparent;
}
.stab:hover:not(.active) { background: rgba(128,128,128,0.14); color: var(--text); }

/* Thread icon overlay in sidebar avatar */
.thread-avatar { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); }
.thread-avatar i { font-size: 20px; color: #fff; }

/* Role badge */
.role-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(230,57,70,0.15);
  color: var(--primary);
  border: 1px solid rgba(230,57,70,0.3);
}

/* Author row above incoming group messages */
.msg-author-row {
  display: flex; align-items: center; gap: 6px;
  padding: 0 4px 3px;
}
.msg-author-avatar {
  width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: grid; place-items: center;
  font-size: 9px; font-weight: 700; color: #fff;
  overflow: hidden; flex-shrink: 0;
}
.msg-author-avatar .avatar-img { width: 100%; height: 100%; }
.msg-author {
  font-size: 11px; color: var(--primary);
  font-weight: 600; letter-spacing: 0.02em;
}

/* Channel notice when composer hidden */
.channel-notice {
  text-align: center;
  padding: 12px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(128,128,128,0.06);
  border-top: 1px solid var(--border);
  border-radius: 0;
}

/* Member action buttons in thread info */
.mem-act {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: rgba(128,128,128,0.12);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  transition: .15s;
  font-size: 11px;
}
.mem-act:hover { background: rgba(230,57,70,0.15); color: var(--primary); border-color: rgba(230,57,70,0.4); }
.mem-act.danger:hover { background: rgba(239,68,68,0.15); color: #EF4444; border-color: rgba(239,68,68,0.4); }

/* Grouped consecutive messages (same author) */
.msg-row.grouped .bubble.theirs { border-top-left-radius: 6px; }
.msg-row.theirs.grouped + .msg-row.theirs { margin-top: -1px; }
.msg-row.mine + .msg-row.mine.grouped { margin-top: -1px; }

/* ================================================================
   OAUTH LOGIN BUTTON + DIVIDER
================================================================ */
.or-divider {
  position: relative;
  text-align: center;
  margin: 20px 0 16px;
}
.or-divider::before {
  content: '';
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: 1px;
  background: var(--border);
}
.or-divider span {
  position: relative;
  display: inline-block;
  padding: 0 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.iro-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 18px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: transform .15s, box-shadow .2s, background .2s;
  border: 0;
}
.iro-btn-brand {
  color: #fff;
  background: linear-gradient(135deg, #E63946, #C42E3B);
  box-shadow: 0 8px 24px -8px rgba(230,57,70,0.55);
}
.iro-btn-brand:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px -8px rgba(230,57,70,0.7);
}
.iro-btn-brand:active { transform: translateY(0); }
.iro-btn .iro-btn-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
html:not(.dark) .or-divider span { background: #fff; }

/* ================================================================
   IMAGE MESSAGES — grid inside bubbles
================================================================ */
.bubble.has-image {
  padding: 5px;
  max-width: 300px;
}
.bubble.has-image .bubble-text {
  padding: 4px 8px 0;
  margin-bottom: 2px;
}
.bubble.has-image .msg-meta {
  padding-right: 6px;
}

.bubble-images {
  display: grid;
  gap: 3px;
  border-radius: 10px;
  overflow: hidden;
  max-width: 100%;
}
.bubble-images.count-1 {
  grid-template-columns: 1fr;
}
.bubble-images.count-1 .bubble-image-cell {
  aspect-ratio: 1 / 1;
  max-height: 260px;
}
.bubble-images.count-2 {
  grid-template-columns: 1fr 1fr;
}
.bubble-images.count-2 .bubble-image-cell {
  aspect-ratio: 1 / 1;
}
.bubble-images.count-3 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1.2fr 1fr;
}
.bubble-images.count-3 .bubble-image-cell:first-child {
  grid-column: 1 / 3;
  aspect-ratio: 16 / 9;
}
.bubble-images.count-3 .bubble-image-cell:nth-child(2),
.bubble-images.count-3 .bubble-image-cell:nth-child(3) {
  aspect-ratio: 1 / 1;
}

.bubble-image-cell {
  overflow: hidden;
  background: rgba(0,0,0,0.15);
  cursor: pointer;
  position: relative;
}
/* a small ⋯ chip we add on image bubbles so the menu is always reachable */
.bubble-image-more {
  position: absolute;
  top: 4px; right: 4px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: 0;
  font-size: 12px;
  line-height: 1;
  display: grid; place-items: center;
  cursor: pointer;
  z-index: 2;
  opacity: 0.9;
  transition: background .15s, transform .15s;
}
.bubble-image-more:hover { background: rgba(230,57,70,0.85); transform: scale(1.05); }
.bubble-image-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .15s;
}
.bubble-image-cell:hover img { transform: scale(1.03); }

/* ================================================================
   IMAGE PREVIEW MODAL
================================================================ */
.image-preview-card {
  max-width: 480px !important;
}
.preview-grid {
  display: grid;
  gap: 6px;
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 12px;
}
.preview-grid.empty { display: none; }
.preview-grid.count-1 {
  grid-template-columns: 1fr;
}
.preview-grid.count-1 .preview-cell { aspect-ratio: 1 / 1; max-height: 300px; }
.preview-grid.count-2 {
  grid-template-columns: 1fr 1fr;
}
.preview-grid.count-2 .preview-cell { aspect-ratio: 1 / 1; }
.preview-grid.count-3 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1.2fr 1fr;
}
.preview-grid.count-3 .preview-cell:first-child {
  grid-column: 1 / 3;
  aspect-ratio: 16 / 9;
}
.preview-grid.count-3 .preview-cell:nth-child(2),
.preview-grid.count-3 .preview-cell:nth-child(3) {
  aspect-ratio: 1 / 1;
}

.preview-cell {
  position: relative;
  overflow: hidden;
  background: rgba(0,0,0,0.15);
}
.preview-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.preview-cell-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 12px;
  transition: background .15s, transform .15s;
}
.preview-cell-remove:hover {
  background: #EF4444;
  transform: scale(1.1);
}

.preview-caption-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
#preview-caption {
  flex: 1;
  background: rgba(128,128,128,0.10) !important;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  line-height: 20px;
  transition: border-color .15s, background .15s;
}
#preview-caption:focus {
  border-color: rgba(230,57,70,0.55);
  background: rgba(230,57,70,0.06) !important;
}

/* ================================================================
   FULLSCREEN IMAGE VIEWER
================================================================ */
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.94);
  display: grid;
  place-items: center;
  animation: viewerIn .15s ease-out;
}
@keyframes viewerIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.viewer-img {
  max-width: 94vw;
  max-height: 88vh;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, transform .15s;
  z-index: 2;
}
.viewer-close:hover { background: rgba(230,57,70,0.85); transform: scale(1.05); }

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, transform .15s;
  z-index: 2;
}
.viewer-nav:hover { background: rgba(255,255,255,0.2); transform: translateY(-50%) scale(1.05); }
.viewer-prev { left: 16px; }
.viewer-next { right: 16px; }

.viewer-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  background: rgba(0,0,0,0.6);
  padding: 6px 14px;
  border-radius: 999px;
  z-index: 2;
}

@media (max-width: 640px) {
  .bubble.has-image { max-width: 260px; }
  .image-preview-card { max-width: calc(100vw - 24px) !important; }
  .viewer-nav { width: 40px; height: 40px; font-size: 16px; }
  .viewer-close { width: 40px; height: 40px; font-size: 16px; }
}

/* ================================================================
   PEER PROFILE — attach image button
================================================================ */
.peer-attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(128,128,128,0.10);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .15s, border-color .15s;
}
.peer-attach-btn i { font-size: 13px; color: var(--muted); }
.peer-attach-btn:hover {
  background: rgba(230,57,70,0.12);
  border-color: rgba(230,57,70,0.4);
}
.peer-attach-btn:hover i { color: var(--primary); }
.peer-attach-btn:active { transform: scale(0.98); }

/* paperclip hide transition */
#attach-btn { transition: opacity .15s, transform .15s; }
#attach-btn.hidden { display: none !important; }

/* ================================================================
   REPLY — composer strip + quote block
================================================================ */
.reply-strip { padding: 6px 10px 0; }
.reply-strip-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: rgba(128,128,128,0.10);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
}
.reply-strip-thumb {
  width: 36px; height: 36px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  display: none;
  background: rgba(0,0,0,0.25);
}
.reply-strip-thumb.has { display: block; }
.reply-strip-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.reply-strip-body { flex: 1; min-width: 0; }
.reply-strip-author {
  font-size: 11px; font-weight: 700;
  color: var(--primary); line-height: 1.1;
}
.reply-strip-text {
  font-size: 12px; color: var(--muted); line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reply-strip-cancel {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: transparent; border: 0;
  color: var(--muted); cursor: pointer;
  flex-shrink: 0;
}
.reply-strip-cancel:hover { background: rgba(230,57,70,0.15); color: var(--primary); }

/* Quote block rendered inside a bubble */
.quote-block {
  display: flex;
  gap: 6px;
  align-items: center;
  align-self: stretch;
  flex: 0 0 auto;
  padding: 4px 7px;
  margin: 0 0 4px;
  border-left: 3px solid rgba(255,255,255,0.55);
  background: rgba(0,0,0,0.15);
  border-radius: 6px;
  max-width: 100%;
  min-height: 0;
  cursor: pointer;
  transition: background .15s;
}
.bubble.theirs .quote-block {
  border-left-color: rgba(230,57,70,0.7);
  background: rgba(128,128,128,0.12);
}
.quote-block:hover { background: rgba(0,0,0,0.28); }
.bubble.theirs .quote-block:hover { background: rgba(128,128,128,0.20); }

.quote-thumb {
  width: 32px; height: 32px;
  border-radius: 5px;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(0,0,0,0.30);
}
.quote-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.quote-body {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}
.quote-author {
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: 1px;
  color: rgba(255,255,255,0.95);
}
.bubble.theirs .quote-author { color: var(--primary); }
.quote-text {
  font-size: 11.5px;
  line-height: 1.3;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.quote-text.deleted { font-style: italic; opacity: 0.55; }

.bubble.has-image .quote-block { margin: 0 0 4px; }

@keyframes msgFlash {
  0%, 100% { background: transparent; }
  25%, 75% { background: rgba(230,57,70,0.22); }
}
.msg-row.flash { animation: msgFlash 1.2s ease-out; border-radius: 8px; }
