:root {
  --bg-app: #18191a;
  --bg-panel: #1f2023;
  --bg-hover: #2d2f34;
  --bg-active: rgba(0, 132, 255, 0.16);
  --bg-input: #3a3b3c;
  --bg-bubble-other: #303030;
  --theme-color: #0084ff;
  --text-main: #e4e6eb;
  --text-muted: #b0b3b8;
  --text-faint: #7b7e84;
  --border: rgba(255, 255, 255, 0.08);
  --online: #31a24c;
  --danger: #f02849;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg-app); color: var(--text-main); overflow: hidden; }

/* ---- AUTH SCREEN ---- */
.auth-screen {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(circle at center, #20242c 0%, #141517 100%);
}
.auth-card {
  width: 100%; max-width: 400px; padding: 34px 30px; border-radius: 20px;
  background: var(--bg-panel); border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.auth-logo { text-align: center; margin-bottom: 24px; }
.messenger-logo-circle {
  width: 60px; height: 60px; border-radius: 50%; margin: 0 auto 12px;
  background: linear-gradient(135deg, #00c6ff 0%, #0078ff 50%, #a033ff 100%);
  display: flex; align-items: center; justify-content: center; font-size: 1.9rem; color: #fff;
}
.auth-logo h1 { font-size: 1.6rem; font-weight: 800; }
.auth-logo p { font-size: 0.86rem; color: var(--text-muted); margin-top: 4px; }

.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: var(--bg-app); border-radius: 10px; margin-bottom: 20px; }
.auth-tab { padding: 8px; border: none; border-radius: 8px; background: transparent; color: var(--text-muted); font-weight: 600; cursor: pointer; }
.auth-tab.active { background: var(--bg-hover); color: #fff; }

.input-group { margin-bottom: 14px; }
.input-group label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.input-group input {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-app); color: #fff; font-size: 0.92rem; outline: none;
}
.input-group input:focus { border-color: var(--theme-color); }
.auth-error { color: #ff6b81; font-size: 0.82rem; min-height: 18px; margin-bottom: 10px; text-align: center; }

.btn-messenger {
  width: 100%; padding: 11px 18px; border: none; border-radius: 10px; background: var(--theme-color);
  color: #fff; font-weight: 700; font-size: 0.94rem; cursor: pointer; transition: 0.15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-messenger:hover { filter: brightness(1.1); }
.btn-messenger.small { width: auto; padding: 10px 20px; font-size: 0.88rem; }

/* ---- 3-COLUMN MESSENGER SHELL ---- */
.messenger-shell { display: flex; height: 100vh; width: 100vw; background: var(--bg-app); }

/* 1. Icon Rail */
.icon-rail {
  width: 60px; flex-shrink: 0; background: var(--bg-app); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 14px 0;
}
.rail-top, .rail-bottom { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.rail-btn {
  width: 42px; height: 42px; border-radius: 12px; border: none; background: transparent;
  color: var(--text-muted); font-size: 1.15rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.15s;
}
.rail-btn:hover { background: var(--bg-hover); color: #fff; }
.rail-btn.active { background: var(--bg-hover); color: #fff; }
.rail-btn.danger:hover { color: var(--danger); }
.rail-me-avatar {
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 0.9rem; margin-top: 4px;
}

/* 2. Chats / People Sidebar */
.chats-sidebar {
  width: 320px; flex-shrink: 0; background: var(--bg-panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-top {
  padding: 16px 16px 10px; display: flex; align-items: center; justify-content: space-between;
}
.sidebar-top h2 { font-size: 1.45rem; font-weight: 800; letter-spacing: -0.02em; }
.sidebar-top-actions { display: flex; gap: 8px; }

.circle-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--bg-input);
  color: var(--text-main); font-size: 0.92rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.15s;
}
.circle-btn:hover { background: #4e4f50; }

.sidebar-search {
  margin: 4px 14px 12px; padding: 0 14px; height: 38px; border-radius: 20px; background: var(--bg-input);
  display: flex; align-items: center; gap: 8px;
}
.sidebar-search i { color: var(--text-muted); font-size: 0.85rem; }
.sidebar-search input { flex: 1; background: none; border: none; color: var(--text-main); font-size: 0.9rem; outline: none; }
.sidebar-search input::placeholder { color: var(--text-muted); }

.sidebar-list { flex: 1; overflow-y: auto; padding: 0 8px 14px; }
.sidebar-list::-webkit-scrollbar { width: 6px; }
.sidebar-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 10px; }

.chat-row {
  display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; cursor: pointer; transition: 0.12s;
  width: 100%; border: none; background: transparent; text-align: left; color: inherit;
}
.chat-row:hover { background: var(--bg-hover); }
.chat-row.active { background: var(--bg-active); }

.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar-circle {
  border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff;
}
.avatar-circle.sm { width: 28px; height: 28px; font-size: 0.72rem; }
.avatar-circle.md { width: 40px; height: 40px; font-size: 1rem; }
.avatar-circle.lg { width: 48px; height: 48px; font-size: 1.15rem; }
.avatar-circle.xl { width: 76px; height: 76px; font-size: 1.8rem; }

.active-dot {
  position: absolute; bottom: 1px; right: 1px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--online); border: 2px solid var(--bg-panel);
}

.chat-row-meta { flex: 1; min-width: 0; }
.chat-row-name { font-size: 0.94rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row-sub {
  font-size: 0.8rem; color: var(--text-muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-row.unread .chat-row-name, .chat-row.unread .chat-row-sub { color: #fff; font-weight: 700; }
.unread-blue-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--theme-color); flex-shrink: 0; }

.people-section-label {
  padding: 10px 10px 6px; font-size: 0.75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase;
}
.person-action-btn {
  padding: 6px 12px; border-radius: 8px; border: none; background: var(--theme-color); color: #fff;
  font-size: 0.78rem; font-weight: 600; cursor: pointer; flex-shrink: 0;
}
.person-action-btn.added { background: var(--bg-input); color: var(--text-main); }

/* 3. Center Chat Stage */
.chat-stage { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-panel); }
.empty-chat-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 32px; gap: 12px;
}
.empty-icon { font-size: 3.5rem; color: var(--theme-color); opacity: 0.9; }
.empty-chat-state p { color: var(--text-muted); font-size: 0.92rem; max-width: 360px; }

.active-chat-view { display: flex; flex-direction: column; height: 100%; }

.stage-header {
  height: 62px; padding: 0 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.stage-header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.stage-name { font-size: 0.98rem; font-weight: 700; }
.stage-sub { font-size: 0.76rem; color: var(--text-muted); }
.stage-header-right { display: flex; align-items: center; gap: 6px; }
.header-icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; background: transparent;
  color: var(--theme-color); font-size: 1.08rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.header-icon-btn:hover { background: var(--bg-hover); }
.header-icon-btn.info-toggle.active { background: rgba(0, 132, 255, 0.14); }
.mobile-back-btn { display: none; }

/* Messages Area */
.messages-scroll {
  flex: 1; overflow-y: auto; padding: 18px 18px 10px; display: flex; flex-direction: column; gap: 6px;
}
.messages-scroll::-webkit-scrollbar { width: 6px; }
.messages-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 10px; }

.bubble-row { display: flex; align-items: flex-end; gap: 8px; max-width: 72%; position: relative; }
.bubble-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble-row.theirs { align-self: flex-start; }

.bubble-content-wrap { display: flex; flex-direction: column; }
.bubble-row.mine .bubble-content-wrap { align-items: flex-end; }
.bubble-sender-label { font-size: 0.72rem; color: var(--text-muted); margin: 0 0 3px 10px; }

.bubble {
  padding: 9px 14px; border-radius: 18px; font-size: 0.93rem; line-height: 1.42;
  word-break: break-word; white-space: pre-wrap; position: relative;
}
.bubble-row.theirs .bubble { background: var(--bg-bubble-other); color: var(--text-main); border-bottom-left-radius: 4px; }
.bubble-row.mine .bubble { background: var(--theme-color); color: #fff; border-bottom-right-radius: 4px; }

.bubble-reply {
  font-size: 0.76rem; color: var(--text-muted); background: rgba(255,255,255,0.06);
  padding: 5px 10px; border-radius: 10px; margin-bottom: 3px; max-width: 280px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.bubble-img { max-width: 260px; max-height: 240px; border-radius: 14px; margin-top: 4px; cursor: pointer; display: block; }
.bubble-file {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px;
  background: rgba(255,255,255,0.1); color: #fff; text-decoration: none; font-size: 0.84rem; margin-top: 4px;
}

.bubble-reactions { display: flex; gap: 4px; margin-top: 3px; }
.react-chip {
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: 100px;
  padding: 2px 7px; font-size: 0.74rem; color: var(--text-main); cursor: pointer;
}

.bubble-actions {
  display: none; align-items: center; gap: 2px; align-self: center;
}
.bubble-row:hover .bubble-actions { display: flex; }
.b-act-btn {
  width: 26px; height: 26px; border-radius: 50%; border: none; background: transparent;
  color: var(--text-muted); font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.b-act-btn:hover { background: var(--bg-hover); color: #fff; }

.typing-indicator { height: 20px; padding: 0 20px; font-size: 0.75rem; color: var(--text-muted); font-style: italic; }

/* Bottom Composer */
.composer-previews { padding: 6px 16px 0; display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--border); }
.preview-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 10px;
  background: var(--bg-hover); font-size: 0.78rem; color: var(--text-main);
}
.preview-pill button { background: none; border: none; color: var(--text-muted); cursor: pointer; }

.messenger-composer {
  padding: 10px 14px; display: flex; align-items: center; gap: 8px;
}
.composer-icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; background: transparent;
  color: var(--theme-color); font-size: 1.15rem; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.composer-icon-btn:hover { background: var(--bg-hover); }
.composer-icon-btn.inside { width: 30px; height: 30px; font-size: 1.05rem; }

.composer-pill {
  flex: 1; height: 38px; border-radius: 20px; background: var(--bg-input); padding: 0 6px 0 14px;
  display: flex; align-items: center; gap: 6px;
}
.composer-pill input { flex: 1; background: none; border: none; color: var(--text-main); font-size: 0.93rem; outline: none; }
.composer-pill input::placeholder { color: var(--text-muted); }

.emoji-wrap { position: relative; }
.emoji-popover {
  position: absolute; bottom: 44px; right: 0; width: 228px; padding: 8px; border-radius: 14px;
  background: #242526; border: 1px solid var(--border); box-shadow: 0 12px 32px rgba(0,0,0,0.6);
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; z-index: 40;
}
.emoji-opt { padding: 5px; font-size: 1.1rem; background: none; border: none; border-radius: 8px; cursor: pointer; }
.emoji-opt:hover { background: var(--bg-hover); }

/* 4. Right Info Sidebar */
.info-sidebar {
  width: 280px; flex-shrink: 0; background: var(--bg-panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 20px 14px;
}
.info-profile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; margin-bottom: 18px; }
.info-profile h3 { font-size: 1.05rem; font-weight: 700; }
.info-profile span { font-size: 0.78rem; color: var(--text-muted); }

.info-quick-actions { display: flex; justify-content: center; gap: 18px; margin-bottom: 16px; }
.info-action-item { display: flex; flex-direction: column; align-items: center; gap: 5px; background: none; border: none; color: var(--text-muted); font-size: 0.75rem; cursor: pointer; }
.in-chat-search { margin-bottom: 14px; }
.in-chat-search input {
  width: 100%; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-input); color: #fff; font-size: 0.84rem; outline: none;
}

.info-section { margin-bottom: 6px; }
.info-acc-btn {
  width: 100%; padding: 10px; border: none; border-radius: 8px; background: transparent; color: var(--text-main);
  font-weight: 600; font-size: 0.88rem; display: flex; align-items: center; justify-content: space-between; cursor: pointer;
}
.info-acc-btn:hover { background: var(--bg-hover); }
.info-acc-body { display: none; padding: 8px 10px; }
.info-section.open .info-acc-body { display: block; }
.theme-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 8px; }
.theme-dots { display: flex; gap: 10px; }
.theme-dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.2); cursor: pointer; }
.info-media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.info-media-grid img { width: 100%; height: 68px; object-fit: cover; border-radius: 8px; cursor: pointer; }

/* ---- MODALS ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  width: 100%; max-width: 420px; background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.7);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.modal-search { margin: 0 0 12px 0; }
.modal-user-list { max-height: 290px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.modal-user-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,0.03);
}
.modal-user-item .u-info { flex: 1; min-width: 0; }
.modal-user-item .u-name { font-size: 0.9rem; font-weight: 600; }
.modal-user-item .u-handle { font-size: 0.76rem; color: var(--text-muted); }

.lightbox {
  position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 90vh; border-radius: 12px; }

@media (max-width: 960px) {
  .info-sidebar { display: none !important; }
}
@media (max-width: 720px) {
  .chats-sidebar { width: 100%; flex: 1; }
  .chat-stage { display: none; width: 100%; }
  .messenger-shell.mobile-chat-open .chats-sidebar { display: none; }
  .messenger-shell.mobile-chat-open .chat-stage { display: flex; }
  .mobile-back-btn { display: flex; }
}
