/* ==========================================================================
   PUBLIC CHAT — PREMIUM ULTRA-DARK & LIGHT MATTE THEME
   ========================================================================== */

:root, [data-theme="dark"] {
  --bg-dark: #07080a;
  --panel-bg: rgba(15, 17, 23, 0.85);
  --panel-border: rgba(255, 255, 255, 0.08);
  --matte-box: rgba(11, 13, 19, 0.92);
  --glass-blur: blur(24px);

  --accent-cyan: #00f2fe;
  --accent-purple: #4facfe;
  --emerald: #10b981;
  --danger: #ef4444;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --input-bg: rgba(0, 0, 0, 0.45);
  --input-border: rgba(255, 255, 255, 0.12);

  --msg-bubble-other: rgba(255, 255, 255, 0.04);
  --msg-bubble-mine: linear-gradient(135deg, rgba(0, 242, 254, 0.18), rgba(79, 172, 254, 0.18));
  --msg-border-mine: rgba(0, 242, 254, 0.35);

  --radius-capsule: 50px;
  --radius-card: 22px;
  
  --neu-shadow: 0 16px 40px rgba(0, 0, 0, 0.65);
  --glow-cyan: 0 0 20px rgba(0, 242, 254, 0.35);
  --particle-color: rgba(0, 242, 254, 0.4);
}

[data-theme="light"] {
  --bg-dark: #f1f5f9;
  --panel-bg: rgba(255, 255, 255, 0.88);
  --panel-border: rgba(0, 0, 0, 0.08);
  --matte-box: rgba(255, 255, 255, 0.95);

  --accent-cyan: #0284c7;
  --accent-purple: #2563eb;
  --emerald: #059669;

  --text-main: #0f172a;
  --text-muted: #64748b;

  --input-bg: rgba(241, 245, 249, 0.95);
  --input-border: rgba(203, 213, 225, 0.8);

  --msg-bubble-other: rgba(241, 245, 249, 0.95);
  --msg-bubble-mine: linear-gradient(135deg, rgba(2, 132, 199, 0.12), rgba(37, 99, 235, 0.15));
  --msg-border-mine: rgba(2, 132, 199, 0.3);

  --neu-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
  --glow-cyan: 0 0 15px rgba(2, 132, 199, 0.25);
  --particle-color: rgba(2, 132, 199, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', sans-serif;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 0.3s ease, color 0.3s ease;
}

#particles-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  pointer-events: none;
  z-index: 0;
}

.glass-card {
  background: var(--panel-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--panel-border);
  box-shadow: var(--neu-shadow);
  border-radius: var(--radius-card);
  transition: all 0.3s ease;
}

.matte-box { background: var(--matte-box); }

/* GRADIENTS */
.gradient-cyan-purple { background: linear-gradient(135deg, #00f2fe, #4facfe); }
.gradient-emerald-mint { background: linear-gradient(135deg, #10b981, #059669); }
.gradient-sunset-glow { background: linear-gradient(135deg, #ff7e5f, #feb47b); }
.gradient-neon-violet { background: linear-gradient(135deg, #a855f7, #ec4899); }
.gradient-solar-flare { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.gradient-ocean-deep   { background: linear-gradient(135deg, #0284c7, #2563eb); }

/* BUTTONS */
.capsule-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--input-border);
  padding: 8px 18px;
  border-radius: var(--radius-capsule);
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.capsule-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.capsule-btn.primary-glow {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  color: #fff;
  border: none;
  font-weight: 800;
  box-shadow: var(--glow-cyan);
}

.capsule-btn.primary-glow:hover {
  filter: brightness(1.12);
  transform: translateY(-2px);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
}

.action-attach-btn {
  font-size: 1.2rem;
  color: var(--accent-cyan);
}

.hidden { display: none !important; }

/* TOASTS */
.toast-container {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 260px;
  padding: 12px 20px;
  border-radius: var(--radius-capsule);
  font-weight: 700;
  font-size: 0.84rem;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--neu-shadow);
  color: var(--text-main);
  animation: slideIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.mention-alert {
  border: 1px solid var(--accent-cyan);
  box-shadow: var(--glow-cyan);
  background: var(--matte-box);
}

@keyframes slideIn {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.toast.info { border-left: 4px solid var(--accent-cyan); }
.toast.success { border-left: 4px solid var(--emerald); }
.toast.error { border-left: 4px solid var(--danger); }

/* MAIN LAYOUT */
.app-layout {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
  z-index: 10;
  position: relative;
}

/* HEADER */
.app-header {
  height: 64px;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--radius-capsule);
  flex-shrink: 0;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-capsule {
  display: flex;
  align-items: center;
  gap: 10px;
}

.glowing-icon {
  font-size: 1.4rem;
  color: var(--accent-cyan);
  filter: drop-shadow(0 0 8px var(--accent-cyan));
}

.logo-capsule h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.online-pill {
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 4px 12px;
  border-radius: var(--radius-capsule);
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.profile-trigger-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.profile-trigger-btn:hover { transform: scale(1.1); }

.header-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  box-shadow: var(--neu-shadow);
}

.username-control-capsule {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-capsule);
  padding: 4px 6px 4px 14px;
  gap: 8px;
  transition: all 0.2s ease;
}

.username-control-capsule.locked {
  border-color: var(--accent-cyan);
  background: rgba(0, 242, 254, 0.05);
}

.input-icon { color: var(--text-muted); font-size: 0.85rem; }

.username-control-capsule input {
  border: none; background: transparent; outline: none;
  color: var(--text-main); font-weight: 700; font-size: 0.88rem; width: 130px;
}

.username-control-capsule input:disabled { color: var(--accent-cyan); cursor: default; }

/* CHAT VIEWPORT */
.chat-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

/* MESSAGE CARDS */
.message-card {
  display: flex;
  gap: 12px;
  max-width: 80%;
  position: relative;
  animation: smoothSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.message-card.deleting {
  opacity: 0;
  transform: scale(0.9) translateY(-8px);
}

@keyframes smoothSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-card.mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 38px; height: 38px;
  border-radius: 50%; color: #fff; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  cursor: pointer;
  transition: transform 0.2s ease;
}

.msg-avatar:hover { transform: scale(1.1); }

.msg-bubble-wrapper {
  display: flex;
  flex-direction: column;
  position: relative;
}

.msg-bubble {
  padding: 10px 16px;
  border-radius: 20px;
  background: var(--msg-bubble-other);
  border: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.message-card.mine .msg-bubble {
  background: var(--msg-bubble-mine);
  border-color: var(--msg-border-mine);
}

.message-card.mentioned-me .msg-bubble {
  border: 1px dashed var(--accent-cyan);
  box-shadow: var(--glow-cyan);
}

.msg-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.msg-author {
  font-weight: 800;
  font-size: 0.84rem;
  color: var(--accent-cyan);
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.msg-author:hover { opacity: 0.8; text-decoration: underline; }

.msg-time { font-size: 0.68rem; color: var(--text-muted); }
.msg-text { font-size: 0.92rem; line-height: 1.45; word-break: break-word; user-select: text; }

/* HOVER ACTIONS */
.msg-actions-bar {
  position: absolute;
  top: -12px; right: 12px;
  background: var(--matte-box);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-capsule);
  padding: 2px 6px;
  display: flex; gap: 4px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform: translateY(4px);
  box-shadow: var(--neu-shadow);
  z-index: 10;
}

.message-card.mine .msg-actions-bar { left: 12px; right: auto; }

.message-card:hover .msg-actions-bar {
  opacity: 1; pointer-events: auto; transform: translateY(0);
}

.msg-action-btn {
  background: transparent; border: none; color: var(--text-muted);
  padding: 4px 6px; font-size: 0.78rem; cursor: pointer; border-radius: 50%;
  transition: color 0.15s ease;
}

.msg-action-btn:hover { color: var(--accent-cyan); }
.msg-action-btn.delete-btn:hover { color: var(--danger); }

/* LINKS & IMAGES */
.chat-link {
  color: var(--accent-cyan); font-weight: 700;
  text-decoration: underline; text-underline-offset: 3px;
}

.chat-msg-img {
  max-width: 100%; max-height: 280px; border-radius: 14px;
  object-fit: cover; cursor: pointer; margin-top: 4px;
  border: 1px solid var(--panel-border); transition: transform 0.2s ease;
}

.chat-msg-img:hover { transform: scale(1.01); box-shadow: var(--glow-cyan); }

/* LINK HOVER PREVIEW */
.link-preview-popover {
  position: fixed; z-index: 1000; width: 280px;
  background: var(--matte-box); border: 1px solid var(--panel-border);
  border-radius: 16px; box-shadow: var(--neu-shadow); overflow: hidden;
  backdrop-filter: var(--glass-blur); pointer-events: none;
  animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.preview-img-container { width: 100%; height: 120px; background: rgba(0,0,0,0.2); overflow: hidden; }
.preview-img-container img { width: 100%; height: 100%; object-fit: cover; }
.preview-content { padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.preview-domain { font-size: 0.68rem; font-weight: 800; color: var(--accent-cyan); text-transform: uppercase; }
.preview-title { font-size: 0.85rem; font-weight: 800; color: var(--text-main); line-height: 1.2; }
.preview-desc { font-size: 0.75rem; color: var(--text-muted); line-height: 1.3; max-height: 40px; overflow: hidden; }

/* INSTAGRAM / FB STYLE PROFILE VIEW MODAL */
.profile-card-view {
  text-align: center;
  padding: 0 0 24px 0 !important;
  overflow: hidden;
  position: relative;
}

.modal-close-btn {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 20;
  background: rgba(0,0,0,0.4) !important;
  color: #fff !important;
}

.profile-banner-header {
  height: 100px;
  background: linear-gradient(135deg, rgba(0, 242, 254, 0.25), rgba(79, 172, 254, 0.25));
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.profile-avatar-large {
  width: 76px; height: 76px;
  border-radius: 50%;
  font-size: 2.2rem;
  display: flex; align-items: center; justify-content: center;
  border: 4px solid var(--matte-box);
  box-shadow: var(--neu-shadow);
  transform: translateY(38px);
}

.profile-details-body {
  padding: 48px 24px 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.profile-username-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
}

.badge-pill {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: var(--radius-capsule);
  background: rgba(0, 242, 254, 0.12);
  border: 1px solid rgba(0, 242, 254, 0.3);
  color: var(--accent-cyan);
}

.status-indicator-box {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.profile-bio-text {
  font-size: 0.88rem;
  color: var(--text-main);
  font-style: italic;
  margin-top: 6px;
  max-width: 280px;
  line-height: 1.4;
}

/* @ MENTION TAG */
.mention-tag {
  background: rgba(0, 242, 254, 0.15);
  color: var(--accent-cyan);
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(0, 242, 254, 0.3);
  cursor: pointer;
}

.mention-tag:hover { text-decoration: underline; }

/* TYPING INDICATOR */
.typing-bar { padding: 6px 20px; font-size: 0.75rem; color: var(--text-muted); font-style: italic; }

/* MENTION POPUP */
.mention-popup {
  position: absolute; bottom: 64px; left: 16px; right: 16px; max-width: 320px;
  background: var(--matte-box); border: 1px solid var(--panel-border);
  border-radius: 16px; box-shadow: var(--neu-shadow); display: flex; flex-direction: column;
  overflow: hidden; z-index: 100; backdrop-filter: var(--glass-blur);
}

.mention-item {
  padding: 10px 14px; display: flex; align-items: center; gap: 10px;
  cursor: pointer; transition: background 0.15s ease;
}

.mention-item:hover, .mention-item.selected { background: rgba(0, 242, 254, 0.12); }

.mention-item .mention-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 0.8rem;
}

.mention-item .mention-name { font-size: 0.85rem; font-weight: 700; color: var(--text-main); }

/* CHAT INPUT BAR */
.chat-input-bar {
  padding: 12px 16px; display: flex; gap: 10px; align-items: center;
  border-top: 1px solid var(--panel-border); background: rgba(0, 0, 0, 0.15);
}

.chat-input-bar input {
  flex: 1; padding: 12px 20px; border: 1px solid var(--input-border);
  background: var(--input-bg); border-radius: var(--radius-capsule); outline: none;
  color: var(--text-main); font-size: 0.9rem;
}

.chat-input-bar input:focus { border-color: var(--accent-cyan); box-shadow: var(--glow-cyan); }

/* MODALS */
.custom-modal {
  position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(10px);
  z-index: 999; display: flex; align-items: center; justify-content: center;
}

.modal-card { width: 90%; max-width: 380px; padding: 24px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.input-label { font-size: 0.78rem; font-weight: 800; color: var(--text-muted); display: block; margin-bottom: 8px; }

.input-group { position: relative; width: 100%; }
.input-group input {
  width: 100%; padding: 10px 16px 10px 40px;
  border: 1px solid var(--input-border); background: var(--input-bg);
  border-radius: var(--radius-capsule); outline: none; color: var(--text-main); font-size: 0.88rem;
}

.input-group .input-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); }

.custom-select {
  width: 100%; padding: 10px 16px;
  border: 1px solid var(--input-border); background: var(--input-bg);
  border-radius: var(--radius-capsule); outline: none; color: var(--text-main); font-size: 0.88rem;
  cursor: pointer;
}

.avatar-preview-box { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 14px; }
.avatar-preview-box .msg-avatar { width: 60px; height: 60px; font-size: 1.8rem; }
.preview-name { font-weight: 800; font-size: 1rem; color: var(--text-main); }

.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; max-height: 110px; overflow-y: auto; }
.emoji-option {
  font-size: 1.3rem; background: rgba(255,255,255,0.05); border: 1px solid var(--panel-border);
  border-radius: 10px; padding: 6px; cursor: pointer; text-align: center; transition: all 0.15s ease;
}
.emoji-option:hover, .emoji-option.active { background: rgba(0, 242, 254, 0.15); border-color: var(--accent-cyan); transform: scale(1.1); }

.gradient-presets-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.gradient-option { height: 32px; border-radius: 10px; border: 2px solid transparent; cursor: pointer; transition: all 0.15s ease; }
.gradient-option[data-bg="cyan-purple"] { background: linear-gradient(135deg, #00f2fe, #4facfe); }
.gradient-option[data-bg="emerald-mint"] { background: linear-gradient(135deg, #10b981, #059669); }
.gradient-option[data-bg="sunset-glow"] { background: linear-gradient(135deg, #ff7e5f, #feb47b); }
.gradient-option[data-bg="neon-violet"] { background: linear-gradient(135deg, #a855f7, #ec4899); }
.gradient-option[data-bg="solar-flare"] { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.gradient-option[data-bg="ocean-deep"]   { background: linear-gradient(135deg, #0284c7, #2563eb); }
.gradient-option:hover, .gradient-option.active { border-color: #fff; transform: scale(1.1); }

.text-cyan { color: var(--accent-cyan); }
.text-emerald { color: var(--emerald); }
.btn-block { width: 100%; }
.margin-top-xs { margin-top: 8px; }
.margin-top-sm { margin-top: 12px; }
.margin-top-md { margin-top: 18px; }
.margin-bottom-xs { margin-bottom: 8px; }

@media (max-width: 600px) {
  .app-header { flex-direction: column; height: auto; gap: 10px; border-radius: var(--radius-card); }
}