:root {
  --bg-0: #0e1621;
  --bg-1: #17212b;
  --bg-2: #202b36;
  --bg-3: #2b3743;
  --bg-hover: #2a3a47;
  --bg-active: #2b5278;
  --border: rgba(255, 255, 255, 0.06);
  --text: #e6edf3;
  --text-dim: #94a3b8;
  --text-faint: #6b7c8c;
  --accent: #2ea5e1;
  --accent-2: #37bbfe;
  --accent-grad: linear-gradient(135deg, #37bbfe, #0d8ddb);
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --danger: #ef4444;
  --shadow-1: 0 8px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: 180ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(1200px 800px at 70% -10%, #1b2a3a 0%, var(--bg-0) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

input,
textarea {
  font: inherit;
  color: inherit;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.16);
}
::-webkit-scrollbar-track {
  background: transparent;
}

.glass {
  background: rgba(23, 33, 43, 0.72);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}

/* ---------- AUTH ---------- */
.auth-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(800px 600px at 20% 20%, #1c3552 0%, transparent 60%),
    radial-gradient(800px 600px at 80% 80%, #143041 0%, transparent 60%), var(--bg-0);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  border-radius: 20px;
  padding: 28px;
  animation: pop 0.35s var(--transition);
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.auth-logo {
  text-align: center;
  margin-bottom: 18px;
}
.auth-logo h1 {
  margin: 10px 0 4px;
  font-size: 22px;
  letter-spacing: 0.2px;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--bg-2);
  border-radius: 12px;
  margin-bottom: 18px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  border-radius: 9px;
  color: var(--text-dim);
  font-weight: 600;
  transition: var(--transition);
}
.auth-tab.active {
  background: var(--accent-grad);
  color: white;
  box-shadow: 0 4px 14px rgba(46, 165, 225, 0.35);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field span {
  font-size: 12px;
  color: var(--text-dim);
  padding-left: 4px;
}
.field input,
.field textarea {
  background: var(--bg-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: var(--transition);
  resize: vertical;
}
.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  background: var(--bg-1);
}

.btn-primary {
  margin-top: 6px;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--accent-grad);
  color: white;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: var(--transition);
  box-shadow: 0 6px 18px rgba(46, 165, 225, 0.35);
}
.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}
.btn-primary:active {
  transform: translateY(0);
}
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.auth-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  animation: shake 0.3s;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.auth-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

[data-show="register"] {
  display: none;
}
.auth-form.register [data-show="register"] {
  display: flex;
}

/* ---------- APP LAYOUT ---------- */
.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

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

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 22, 33, 0.6);
  backdrop-filter: blur(10px);
}

.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--bg-2);
  border-radius: 22px;
  color: var(--text-faint);
  transition: var(--transition);
}
.search-wrap:focus-within {
  background: var(--bg-3);
  color: var(--accent-2);
}
.search-wrap input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  min-width: 0;
}
.search-wrap input::placeholder {
  color: var(--text-faint);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-dim);
  transition: var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.chats-list,
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.chat-row {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
  user-select: none;
}
.chat-row:hover {
  background: var(--bg-hover);
}
.chat-row.active {
  background: var(--bg-active);
}
.chat-row.active .chat-name,
.chat-row.active .chat-preview,
.chat-row.active .chat-time {
  color: white;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: white;
  display: inline-grid;
  place-items: center;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.5px;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  position: relative;
}
.avatar.avatar-xl {
  width: 96px;
  height: 96px;
  font-size: 36px;
}
.avatar[data-online="true"]::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px var(--bg-1);
}

.chat-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
.chat-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.chat-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-time {
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
}
.chat-preview {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-preview .you {
  color: var(--text-faint);
}

.chat-aside {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.unread-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
}
.pin-icon {
  color: var(--text-faint);
  display: grid;
  place-items: center;
}
.chat-row.active .unread-badge {
  background: white;
  color: var(--accent);
}

/* ---------- MAIN ---------- */
.main {
  position: relative;
  background:
    radial-gradient(800px 600px at 80% 10%, rgba(46, 165, 225, 0.07) 0%, transparent 60%),
    var(--bg-0);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
}
.empty-state h2 {
  margin: 12px 0 4px;
  color: var(--text);
}
.empty-state p {
  margin: 0;
  font-size: 14px;
}

.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 22, 33, 0.6);
  backdrop-filter: blur(10px);
  z-index: 2;
}
.chat-meta {
  flex: 1;
  min-width: 0;
}
.chat-title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-subtitle {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--transition);
}
.chat-subtitle.online {
  color: var(--accent-2);
}
.chat-actions {
  display: flex;
  gap: 4px;
}

.msg-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  animation: slideDown 0.2s var(--transition);
}
.msg-search input {
  flex: 1;
  background: var(--bg-2);
  border: 0;
  outline: 0;
  border-radius: 18px;
  padding: 8px 14px;
}
@keyframes slideDown {
  from {
    transform: translateY(-8px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 4% 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.msg {
  max-width: min(640px, 75%);
  padding: 8px 12px 6px;
  border-radius: 14px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  background: var(--bubble-in);
  align-self: flex-start;
  animation: bubble 0.18s ease-out;
  border-top-left-radius: 14px;
  border-bottom-left-radius: 6px;
}
.msg.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-top-right-radius: 14px;
  border-bottom-right-radius: 6px;
  border-bottom-left-radius: 14px;
}
.msg.first-in-group {
  margin-top: 8px;
}
@keyframes bubble {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg-body {
  white-space: pre-wrap;
}
.msg-body.deleted {
  font-style: italic;
  color: var(--text-faint);
}

.msg-meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-faint);
  margin-left: 8px;
  float: right;
  padding-top: 4px;
  user-select: none;
}
.msg.out .msg-meta {
  color: rgba(255, 255, 255, 0.7);
}
.msg-meta .check {
  display: inline-grid;
  place-items: center;
}

.msg-attachment {
  margin: -2px -4px 4px;
  border-radius: 10px;
  overflow: hidden;
  max-width: 360px;
}
.msg-attachment img {
  display: block;
  max-width: 100%;
  max-height: 360px;
  border-radius: 10px;
}
.msg-attachment.file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
}
.msg-attachment.file .file-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-grad);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  flex-shrink: 0;
}
.msg-attachment.file a {
  color: var(--accent-2);
  text-decoration: none;
  word-break: break-all;
}

.date-separator {
  align-self: center;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  margin: 12px 0 6px;
}

.typing-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 18px;
  color: var(--text-dim);
  font-size: 13px;
}
.typing-dots {
  display: inline-flex;
  gap: 3px;
}
.typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.typing-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; transform: translateY(-2px); }
}

.composer {
  display: flex;
  align-items: end;
  gap: 6px;
  padding: 10px 14px 12px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
}
.composer .icon-btn {
  width: 42px;
  height: 42px;
  cursor: pointer;
}
.composer-input-wrap {
  flex: 1;
  background: var(--bg-2);
  border-radius: 18px;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
}
#composer-input {
  background: transparent;
  border: 0;
  outline: 0;
  resize: none;
  padding: 9px 6px;
  max-height: 160px;
  min-height: 24px;
  line-height: 1.4;
}
.composer-preview {
  padding: 8px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 10px;
}
.composer-preview img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
}
.composer-preview .remove {
  margin-left: auto;
  color: var(--danger);
  cursor: pointer;
}

.send-btn {
  width: 46px;
  height: 46px;
  background: var(--accent-grad);
  color: white;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: var(--transition);
  box-shadow: 0 6px 18px rgba(46, 165, 225, 0.35);
}
.send-btn:hover {
  transform: scale(1.05);
}
.send-btn:active {
  transform: scale(0.96);
}

/* Emoji */
.emoji-panel {
  position: absolute;
  bottom: 80px;
  left: 14px;
  width: 320px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-2);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadow-1);
  border: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  z-index: 10;
  animation: pop 0.18s var(--transition);
}
.emoji-panel button {
  font-size: 22px;
  padding: 4px;
  border-radius: 6px;
  transition: background var(--transition);
}
.emoji-panel button:hover {
  background: var(--bg-hover);
}

/* Search results */
.search-results {
  padding: 6px 0;
}
.search-results .section-title {
  padding: 6px 16px;
  color: var(--text-faint);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Profile */
.profile-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
  animation: fade 0.2s;
}
@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.profile-card {
  width: 100%;
  max-width: 420px;
  border-radius: 18px;
  overflow: hidden;
  animation: pop 0.25s var(--transition);
}
.profile-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.profile-header h3 {
  flex: 1;
  margin: 0;
  font-size: 16px;
}
.link-danger {
  color: var(--danger);
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
}
.link-danger:hover {
  background: rgba(239, 68, 68, 0.12);
}
.profile-body {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
}
.avatar-upload {
  align-self: center;
  position: relative;
  cursor: pointer;
}
.avatar-edit {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-grad);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.profile-username {
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

/* Msg context menu */
.msg-menu {
  position: fixed;
  z-index: 100;
  min-width: 160px;
  background: var(--bg-2);
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  padding: 6px;
  animation: pop 0.12s var(--transition);
}
.msg-menu button {
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background var(--transition);
}
.msg-menu button:hover {
  background: var(--bg-hover);
}
.msg-menu button.danger {
  color: var(--danger);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow-1);
  z-index: 200;
  animation: pop 0.2s;
}

.mobile-only {
  display: none;
}

/* Responsive */
@media (max-width: 800px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    width: 100%;
  }
  .app.has-chat .sidebar {
    display: none;
  }
  .app:not(.has-chat) .main {
    display: none;
  }
  .mobile-only {
    display: inline-grid;
  }
  .msg {
    max-width: 85%;
  }
  .emoji-panel {
    left: 8px;
    right: 8px;
    width: auto;
  }
}

/* ===== Additions: groups, reply, reactions, voice, modals ===== */
.primary-btn { background: linear-gradient(135deg,#37bbfe,#0d8ddb); color:#fff; border-radius:50%; }
.primary-btn:hover { filter: brightness(1.1); }

.archived-toggle {
  display:flex; align-items:center; gap:10px; padding:12px 16px;
  border:none; background:transparent; color:var(--text-faint, #95a3b3);
  cursor:pointer; width:100%; text-align:left; border-bottom:1px solid rgba(255,255,255,.04);
}
.archived-toggle:hover { background:rgba(255,255,255,.04); color:#fff; }
.archived-count { margin-left:auto; background:rgba(255,255,255,.08); padding:2px 8px; border-radius:10px; font-size:12px; }

.chat-header-clickable { display:flex; align-items:center; gap:12px; background:none; border:0; color:inherit; padding:0; cursor:pointer; flex:1; min-width:0; }
.chat-header-clickable:hover .chat-title { color:#37bbfe; }
.group-icon { font-size:13px; opacity:.85; margin-right:2px; }
.mute-icon { color:var(--text-faint, #95a3b3); margin-right:4px; }
.unread-badge.muted { background:#5a6878; }
.icon-btn.active { color:#37bbfe; background:rgba(55,187,254,.12); }

/* Sender name colored header in groups */
.msg-sender { font-size:13px; font-weight:600; margin-bottom:2px; }

/* Reply quote inside bubble */
.reply-quote {
  border-left:3px solid #37bbfe; padding:5px 8px; margin-bottom:6px;
  background:rgba(55,187,254,.08); border-radius:6px; cursor:pointer;
}
.reply-quote:hover { background:rgba(55,187,254,.16); }
.reply-quote-name { font-size:12px; font-weight:600; color:#37bbfe; }
.reply-quote-text { font-size:13px; opacity:.85; }

.forwarded-tag { font-size:12px; color:var(--text-faint,#95a3b3); font-style:italic; margin-bottom:4px; }

/* Reply preview above composer */
.reply-preview {
  display:flex; align-items:center; gap:8px; padding:8px 12px; margin:0 12px;
  background:rgba(55,187,254,.08); border-radius:8px; border-left:3px solid #37bbfe;
}
.reply-preview-body { flex:1; min-width:0; }
.reply-preview-name { font-size:12px; font-weight:600; color:#37bbfe; }
.reply-preview-text { font-size:13px; color:var(--text-faint,#95a3b3); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* Reactions row */
.reactions { display:flex; flex-wrap:wrap; gap:4px; margin-top:6px; }
.reaction-pill {
  display:inline-flex; align-items:center; gap:3px; padding:2px 8px;
  background:rgba(255,255,255,.08); border:1px solid transparent; border-radius:12px;
  cursor:pointer; font-size:13px; color:#fff;
}
.reaction-pill:hover { background:rgba(255,255,255,.14); }
.reaction-pill.mine { background:rgba(55,187,254,.22); border-color:#37bbfe; }
.reaction-pill span { font-size:11px; opacity:.85; }

.react-picker {
  position:fixed; z-index:50; display:flex; gap:4px; padding:6px;
  background:rgba(30,40,55,.96); border:1px solid rgba(255,255,255,.08); border-radius:24px;
  box-shadow:0 12px 32px rgba(0,0,0,.4); backdrop-filter:blur(12px);
}
.react-picker button {
  border:0; background:transparent; font-size:22px; padding:4px 6px; cursor:pointer;
  transition:transform .15s;
}
.react-picker button:hover { transform:scale(1.3); }

/* Message highlight when scrolled to via reply */
.msg.flash { animation: msgFlash 1.5s ease-out; }
@keyframes msgFlash { 0% { background-color: rgba(55,187,254,.4); } 100% { background-color: transparent; } }

/* Voice message player */
.msg-voice { display:flex; align-items:center; gap:8px; padding:4px 0; }
.msg-voice audio { height:34px; max-width:240px; }
.voice-dur { font-size:12px; color:var(--text-faint,#95a3b3); }

.voice-btn { color:#37bbfe; }
.voice-btn:hover { background:rgba(55,187,254,.15); }
.recorder-bar {
  display:flex; align-items:center; gap:10px; padding:8px 12px;
  background:rgba(239,68,68,.12); border-radius:10px; color:#fff;
}
.rec-dot { width:10px; height:10px; border-radius:50%; background:#ef4444; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity:.3; } }
.rec-hint { color:var(--text-faint,#95a3b3); font-size:12px; margin-left:auto; }

/* ===== Modals ===== */
.modal-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,.55); z-index:200;
  display:flex; align-items:center; justify-content:center; padding:20px;
}
.modal {
  width:100%; max-width:480px; max-height:85vh; display:flex; flex-direction:column;
  background:rgba(30,40,55,.96); border-radius:14px; border:1px solid rgba(255,255,255,.08);
  backdrop-filter:blur(20px); overflow:hidden;
}
.modal-header { display:flex; align-items:center; justify-content:space-between; padding:14px 18px; border-bottom:1px solid rgba(255,255,255,.06); }
.modal-header h3 { margin:0; font-size:17px; }
.modal-body { padding:16px 18px; overflow:auto; flex:1; }
.modal-footer { display:flex; justify-content:flex-end; gap:8px; padding:12px 18px; border-top:1px solid rgba(255,255,255,.06); }
.btn-secondary {
  background:rgba(255,255,255,.08); color:#fff; border:0; padding:8px 16px; border-radius:8px; cursor:pointer;
}
.btn-secondary:hover { background:rgba(255,255,255,.14); }

.member-chips { display:flex; flex-wrap:wrap; gap:6px; margin:8px 0; min-height:8px; }
.member-chip {
  display:inline-flex; align-items:center; gap:6px; background:rgba(55,187,254,.15);
  border:1px solid rgba(55,187,254,.3); border-radius:16px; padding:3px 10px 3px 3px; font-size:13px;
}
.member-chip .avatar-sm { width:22px; height:22px; font-size:10px; }
.chip-x { cursor:pointer; padding:0 4px; opacity:.7; }
.chip-x:hover { opacity:1; color:#ef4444; }

.ng-results, .fw-list { display:flex; flex-direction:column; gap:2px; }
.ng-result-row, .fw-row {
  display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:8px; cursor:pointer;
}
.ng-result-row:hover, .fw-row:hover { background:rgba(255,255,255,.06); }
.ng-check {
  margin-left:auto; width:24px; height:24px; border-radius:50%;
  background:rgba(255,255,255,.06); display:grid; place-items:center; font-weight:600;
}

/* Group info members */
.member-list { display:flex; flex-direction:column; gap:4px; max-height:340px; overflow:auto; }
.member-row { display:flex; align-items:center; gap:10px; padding:8px 4px; }
.member-row > div:nth-child(2) { flex:1; }
.role-tag { font-size:10px; background:rgba(55,187,254,.2); color:#37bbfe; padding:1px 6px; border-radius:6px; text-transform:uppercase; }

.avatar-sm { width:24px; height:24px; font-size:11px; }

/* Hide msg menu items cleanly */
.msg-menu { z-index:60; }
.msg-menu button span { width:18px; display:inline-block; text-align:center; }

/* Deleted message styling */
.msg.is-deleted { opacity:.7; }
.edited { font-style:italic; opacity:.7; margin-right:4px; }

/* Inline edit */
.msg.editing { background: rgba(55,187,254,.12); }
.msg .edit-input {
  width: 100%; min-width: 220px; min-height: 60px;
  background: rgba(0,0,0,.25); color:#fff; border:1px solid rgba(55,187,254,.4);
  border-radius:8px; padding:6px 8px; font: inherit; resize: vertical;
}
.msg .edit-actions { display:flex; justify-content:flex-end; gap:6px; margin-top:6px; }
.msg .edit-actions button { padding:4px 12px; font-size:12px; }

/* ============ THEME (light) ============ */
:root[data-theme="light"] {
  --bg-0: #f4f6f8;
  --bg-1: #ffffff;
  --bg-2: #f0f3f6;
  --bg-3: #e6ebf0;
  --bg-hover: #eaf1f7;
  --bg-active: #d6e7f5;
  --border: rgba(0,0,0,.08);
  --text: #1a2733;
  --text-dim: #5a6c7d;
  --text-faint: #7d8a98;
  --bubble-in: #ffffff;
  --bubble-out: #cfe9ff;
  --shadow-1: 0 8px 30px rgba(0,0,0,.10);
}
:root[data-theme="light"] body {
  background: radial-gradient(1200px 800px at 70% -10%, #e8f1fb 0%, var(--bg-0) 55%);
}
:root[data-theme="light"] .glass {
  background: rgba(255,255,255,.85);
}
:root[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); }
:root[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.28); }
:root[data-theme="light"] .msg.out { color:#1a2733; }
:root[data-theme="light"] .msg.out a { color:#0d4a82; }

/* ============ DROPDOWN MENUS ============ */
#menu-btn-wrap { position:relative; display:inline-flex; padding:0; }
.attach-wrap { position:relative; display:inline-flex; }
.dropdown-menu {
  position:absolute; top:calc(100% + 8px); right:0;
  background: var(--bg-2); border:1px solid var(--border);
  border-radius:10px; min-width:200px; z-index:80; padding:6px;
  box-shadow: var(--shadow-1);
}
.attach-menu { top:auto; bottom:calc(100% + 8px); left:0; right:auto; }
.dropdown-menu button {
  display:flex; align-items:center; gap:10px; width:100%; padding:8px 10px;
  border-radius:6px; text-align:left; color:var(--text);
}
.dropdown-menu button:hover { background: var(--bg-hover); }

/* ============ FOLDER TABS ============ */
.folder-tabs {
  display:flex; gap:4px; overflow-x:auto; padding:4px 8px;
  border-bottom:1px solid var(--border); background:var(--bg-1);
}
.folder-tab {
  padding:6px 12px; border-radius:8px; color:var(--text-dim); white-space:nowrap;
  font-size:13px; font-weight:500;
}
.folder-tab.active { background:var(--accent); color:#fff; }
.folder-tab:hover:not(.active) { background:var(--bg-hover); }

/* ============ SIDEBAR BOTTOM ============ */
.sidebar-bottom-btn {
  display:flex; align-items:center; gap:8px; padding:10px 14px; color:var(--text-dim);
  border-top:1px solid var(--border); width:100%; text-align:left;
}
.sidebar-bottom-btn:hover { background:var(--bg-hover); color:var(--text); }

/* ============ PINNED BANNER ============ */
.pinned-banner {
  display:flex; align-items:center; gap:10px; padding:8px 14px;
  background:var(--bg-2); border-bottom:1px solid var(--border); cursor:pointer;
}
.pinned-banner:hover { background:var(--bg-hover); }
.pinned-icon { font-size:18px; color:var(--accent); }
.pinned-body { flex:1; min-width:0; }
.pinned-title { font-size:12px; color:var(--accent); font-weight:600; }
.pinned-text { font-size:13px; color:var(--text-dim); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* ============ MULTISELECT BAR ============ */
.multiselect-bar {
  display:flex; align-items:center; gap:10px; padding:8px 14px;
  background:var(--bg-3); border-bottom:1px solid var(--border);
}
.multiselect-bar .danger { color:var(--danger); }
.msg.selected { background: rgba(55,187,254,.15) !important; outline:2px solid var(--accent); }

/* ============ DROP OVERLAY ============ */
.drop-overlay {
  position:absolute; inset:0; background: rgba(13,141,219,.25);
  display:grid; place-items:center; z-index:50; pointer-events:none;
  border:3px dashed var(--accent); border-radius:12px;
}
.drop-overlay-inner { background:var(--bg-2); padding:24px 36px; border-radius:12px; text-align:center; }

/* ============ POLL CARD ============ */
.poll-card { background:rgba(0,0,0,.18); padding:10px; border-radius:10px; margin:6px 0; min-width:240px; }
.msg.out .poll-card { background:rgba(255,255,255,.10); }
.poll-q { font-weight:600; margin-bottom:8px; }
.poll-tag { font-size:10px; padding:1px 6px; border-radius:6px; background:rgba(255,255,255,.12); color:var(--text-dim); margin-left:4px; }
.poll-tag.closed { background:rgba(239,68,68,.2); color:#fecaca; }
.poll-opts { display:flex; flex-direction:column; gap:5px; }
.poll-opt {
  position:relative; display:flex; align-items:center; padding:8px 10px;
  background:rgba(255,255,255,.05); border-radius:8px; overflow:hidden;
  text-align:left; color:var(--text);
}
.poll-opt:hover:not(:disabled) { background:rgba(255,255,255,.10); }
.poll-opt.mine { background:rgba(55,187,254,.15); }
.poll-opt:disabled { cursor:not-allowed; opacity:.85; }
.poll-bar {
  position:absolute; inset:0; right:auto; background:rgba(55,187,254,.18);
  transition: width .3s ease;
}
.poll-opt-text { position:relative; flex:1; z-index:1; }
.poll-opt-pct { position:relative; z-index:1; color:var(--text-dim); font-size:12px; margin-left:8px; }
.poll-meta { display:flex; justify-content:space-between; align-items:center; margin-top:8px; font-size:12px; color:var(--text-dim); }
.poll-close-btn { color:var(--accent); font-size:12px; }
.poll-loading { color:var(--text-faint); font-size:13px; padding:6px; }

/* ============ LOCATION / CONTACT CARDS ============ */
.location-card, .contact-card {
  display:flex; align-items:center; gap:10px; padding:10px;
  background:rgba(0,0,0,.18); border-radius:10px; margin:6px 0;
  text-decoration:none; color:inherit; min-width:220px;
}
.msg.out .location-card, .msg.out .contact-card { background:rgba(255,255,255,.10); }
.location-icon, .contact-icon { font-size:22px; }
.location-label, .contact-name { font-weight:600; }
.location-coords, .contact-phone { font-size:12px; color:var(--text-dim); }

/* ============ STARRED ============ */
.star-badge { margin-right:4px; }
.starred-row { padding:10px; border-radius:8px; cursor:pointer; }
.starred-row:hover { background:var(--bg-hover); }
.starred-meta { font-size:12px; color:var(--text-dim); margin-bottom:4px; }
.starred-body { color:var(--text); }

/* ============ GLOBAL SEARCH ============ */
.search-global { padding:6px 10px; max-height:50%; overflow-y:auto; }
.search-global .section-title { font-size:11px; color:var(--text-faint); text-transform:uppercase; padding:6px 8px; }
.global-msg-row { padding:8px 10px; border-radius:8px; cursor:pointer; }
.global-msg-row:hover { background:var(--bg-hover); }
.global-msg-title { font-weight:600; font-size:13px; color:var(--accent); }
.global-msg-body { font-size:13px; color:var(--text-dim); }
.global-msg-meta { font-size:11px; color:var(--text-faint); margin-top:2px; }
mark { background:rgba(255,235,59,.4); color:inherit; padding:0 2px; border-radius:2px; }

/* ============ PROFILE EXTRAS ============ */
.profile-section-title {
  font-size:11px; color:var(--text-faint); text-transform:uppercase;
  margin-top:20px; padding-bottom:6px; border-bottom:1px solid var(--border);
}
.profile-row-btn {
  display:flex; align-items:center; gap:12px; width:100%; padding:12px;
  border-radius:8px; color:var(--text); margin-top:4px; text-align:left;
}
.profile-row-btn:hover { background:var(--bg-hover); }
.profile-row-btn span { width:22px; text-align:center; }

/* ============ SESSIONS / BLOCKS rows ============ */
.session-row, .block-row {
  display:flex; align-items:center; gap:10px; padding:10px 8px;
  border-bottom:1px solid var(--border);
}
.session-row > div { flex:1; }
.block-row > div { flex:1; }

/* ============ INVITE / GROUP DESC ============ */
#info-extra textarea {
  width:100%; background:var(--bg-3); color:var(--text); border:1px solid var(--border);
  border-radius:8px; padding:8px; font:inherit; resize:vertical;
}
.invite-row { display:flex; gap:6px; align-items:center; margin-top:4px; }
.invite-row input {
  flex:1; padding:8px; background:var(--bg-3); color:var(--text);
  border:1px solid var(--border); border-radius:8px;
}

/* ============ FL LIST ============ */
.fl-list { max-height:240px; overflow:auto; display:flex; flex-direction:column; gap:4px; }
.fl-row { display:flex; align-items:center; gap:8px; padding:6px 8px; border-radius:6px; cursor:pointer; }
.fl-row:hover { background:var(--bg-hover); }
.fl-existing-row { display:flex; justify-content:space-between; align-items:center; padding:6px 8px; }

/* ============ AM rows ============ */
.am-row { display:flex; align-items:center; gap:10px; padding:8px; border-radius:8px; }
.am-row:hover { background:var(--bg-hover); }


/* ============ ÇAĞRI (WebRTC) ============ */
.chat-actions .call-btn { color: var(--accent); }
.call-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.call-box {
  width: min(720px, 96vw); max-height: 92vh;
  background: var(--bg-secondary, #17212b); color: var(--text, #fff);
  border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.call-header { display: flex; align-items: center; gap: 12px; }
.call-peer-avatar { width: 48px; height: 48px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 600; color: #fff;
  background-size: cover; background-position: center;
}
.call-peer-name { font-size: 18px; font-weight: 600; }
.call-status { font-size: 13px; opacity: 0.7; margin-top: 2px; }
.call-video-wrap {
  position: relative; background: #000; border-radius: 10px; overflow: hidden;
  aspect-ratio: 16 / 9; min-height: 220px;
}
.call-video-wrap.voice-only { min-height: 80px; aspect-ratio: auto; height: 80px;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px;
}
.call-video-wrap.voice-only::after { content: '🎙 Sesli arama'; opacity: 0.7; }
#call-remote-video { width: 100%; height: 100%; object-fit: cover; background: #000; }
#call-local-video {
  position: absolute; right: 12px; bottom: 12px; width: 28%; max-width: 200px;
  border: 2px solid #fff; border-radius: 8px; background: #000; object-fit: cover;
}
.call-actions { display: flex; justify-content: center; gap: 18px; }
.call-btn-circle {
  width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
  background: #2c3a47; color: #fff; display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s, background 0.2s;
}
.call-btn-circle:hover { transform: scale(1.06); }
.call-btn-circle.off { background: #555; opacity: 0.6; }
.call-btn-circle.accept { background: #22c55e; }
.call-btn-circle.hangup { background: #ef4444; }
@media (max-width: 600px) {
  .call-box { width: 96vw; padding: 12px; }
  .call-btn-circle { width: 48px; height: 48px; }
}
