/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base: #0f0f13;
  --bg-sidebar: #16161d;
  --bg-chat: #12121a;
  --bg-input: #1e1e2a;
  --bg-hover: #1e1e2a;
  --bg-active: #252535;
  --bg-card: #1a1a24;
  --bg-modal: #1c1c28;

  --border: #2a2a3a;
  --border-light: #33334a;

  --accent: #6366f1;
  --accent-hover: #5254cc;
  --accent-soft: rgba(99,102,241,0.15);
  --accent2: #8b5cf6;

  --text-primary: #e8e8f0;
  --text-secondary: #9090aa;
  --text-muted: #60607a;

  --online: #22c55e;
  --danger: #ef4444;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;

  --font: 'Vazirmatn', sans-serif;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

/* === AUTH SCREEN === */
.auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-base);
  z-index: 1000;
}

.auth-bg {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
}

.auth-orb {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.25;
  animation: float 8s ease-in-out infinite;
}

.orb1 { width: 400px; height: 400px; background: #6366f1; top: -100px; right: -100px; animation-delay: 0s; }
.orb2 { width: 300px; height: 300px; background: #8b5cf6; bottom: -50px; left: -80px; animation-delay: -3s; }
.orb3 { width: 250px; height: 250px; background: #3b82f6; top: 50%; left: 40%; animation-delay: -6s; }

@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-30px) scale(1.05); }
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  width: 380px;
  position: relative;
  z-index: 1;
  box-shadow: var(--shadow), 0 0 0 1px rgba(99,102,241,0.1);
  animation: slideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 20px; font-weight: 700; color: var(--text-primary);
  margin-bottom: 28px; justify-content: center;
  letter-spacing: -0.5px;
}

.auth-tabs {
  display: flex; gap: 4px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 4px; margin-bottom: 24px;
}

.auth-tab {
  flex: 1; padding: 8px;
  background: none; border: none; border-radius: 6px;
  color: var(--text-secondary); font-family: var(--font);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--accent); color: white;
  box-shadow: 0 2px 8px rgba(99,102,241,0.4);
}

.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.5px; }
.field input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input::placeholder { color: var(--text-muted); }

.form-error {
  color: var(--danger); font-size: 12px; min-height: 16px;
  padding: 0 2px;
}

.btn-primary {
  width: 100%; padding: 11px;
  background: var(--accent);
  border: none; border-radius: var(--radius-sm);
  color: white; font-family: var(--font);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.2s;
  margin-top: 4px;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* === MAIN APP LAYOUT === */
.app {
  display: flex; height: 100vh;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.hidden { display: none !important; }

/* === SIDEBAR === */
.sidebar {
  width: 260px; flex-shrink: 0;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.app-brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--text-primary);
  letter-spacing: -0.3px;
}

.icon-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: var(--radius-sm);
  color: var(--text-secondary); cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-search {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

.sidebar-search input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-family: var(--font);
  font-size: 13px;
}
.sidebar-search input::placeholder { color: var(--text-muted); }

.sidebar-section { padding: 8px 0; }

.section-label {
  padding: 4px 16px 6px;
  font-size: 10px; font-weight: 700;
  color: var(--text-muted); letter-spacing: 1px;
  text-transform: uppercase;
}

.channel-list { display: flex; flex-direction: column; gap: 1px; padding: 0 8px; }

.channel-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.15s;
  position: relative;
}
.channel-item:hover { background: var(--bg-hover); }
.channel-item.active { background: var(--accent-soft); }
.channel-item.active .channel-name { color: var(--accent); font-weight: 600; }

.channel-hash {
  color: var(--text-muted); font-size: 16px; font-weight: 300;
  flex-shrink: 0; width: 18px; text-align: center;
}

.channel-name {
  font-size: 13px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}

.channel-badge {
  background: var(--accent);
  color: white; font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 10px;
  flex-shrink: 0;
}

/* === AVATAR === */
.avatar {
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; flex-shrink: 0;
  font-size: 11px; position: relative;
}
.avatar-sm { width: 30px; height: 30px; font-size: 11px; }
.avatar-md { width: 36px; height: 36px; font-size: 13px; }
.avatar-lg { width: 40px; height: 40px; font-size: 15px; }
.avatar-msg { width: 34px; height: 34px; font-size: 12px; }

.status-indicator {
  position: absolute; bottom: -1px; left: -1px;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--bg-sidebar);
}
.status-indicator.online { background: var(--online); }
.status-indicator.offline { background: var(--text-muted); }

/* === SIDEBAR FOOTER === */
.sidebar-footer {
  margin-top: auto;
  padding: 12px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}

.user-profile-mini { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }

.user-info-mini { min-width: 0; }
.my-name { font-size: 13px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.my-status { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-muted); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--online); }

.logout-btn:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* === CHAT MAIN === */
.chat-main {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg-chat);
  min-width: 0; overflow: hidden;
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  height: 56px; flex-shrink: 0;
  background: var(--bg-chat);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.chat-header-info { display: flex; align-items: center; gap: 12px; }
.chat-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.chat-subtitle { font-size: 12px; color: var(--text-muted); }

.online-pill {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--text-muted);
  background: var(--bg-input); border-radius: 20px;
  padding: 4px 12px;
}

/* === MESSAGES === */
.messages-container {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar { width: 5px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.messages-list {
  display: flex; flex-direction: column;
  padding: 16px 0; min-height: 100%;
  justify-content: flex-end;
}

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 20px; color: var(--text-muted); gap: 12px;
  height: 100%;
}
.empty-icon { font-size: 48px; }
.empty-state p { font-size: 14px; }

/* Message group */
.msg-group {
  display: flex; gap: 10px;
  padding: 4px 20px;
  animation: msgIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-group:hover .msg-actions { opacity: 1; }

.msg-avatar-col { width: 34px; flex-shrink: 0; padding-top: 2px; }
.msg-content-col { flex: 1; min-width: 0; }

.msg-header {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 3px;
}

.msg-author {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
}

.msg-time {
  font-size: 11px; color: var(--text-muted);
}

.msg-bubble {
  display: inline-block;
  background: var(--bg-input);
  padding: 8px 12px;
  border-radius: 4px 12px 12px 12px;
  max-width: 100%;
  word-wrap: break-word;
  font-size: 14px; line-height: 1.5;
  color: var(--text-primary);
  position: relative;
}

.msg-group.own .msg-bubble {
  background: var(--accent-soft);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: 12px 4px 12px 12px;
}

.msg-group.own {
  flex-direction: row-reverse;
}

.msg-group.own .msg-header {
  flex-direction: row-reverse;
}

.msg-group.own .msg-content-col {
  display: flex; flex-direction: column; align-items: flex-end;
}

/* === IMAGES & FILES === */
.msg-image {
  max-width: 320px; max-height: 280px;
  border-radius: 10px; cursor: pointer;
  object-fit: cover;
  transition: opacity 0.2s;
  display: block; margin-top: 4px;
}
.msg-image:hover { opacity: 0.9; }

.msg-file {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px; margin-top: 4px;
  text-decoration: none; color: var(--text-primary);
  max-width: 280px; transition: background 0.15s;
}
.msg-file:hover { background: var(--bg-hover); }
.msg-file-icon { font-size: 24px; }
.msg-file-info { min-width: 0; }
.msg-file-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-file-size { font-size: 11px; color: var(--text-muted); }

/* === REACTIONS === */
.msg-reactions {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 5px;
}

.reaction-chip {
  display: flex; align-items: center; gap: 3px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 13px; cursor: pointer;
  transition: all 0.15s;
}
.reaction-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.reaction-chip.mine { border-color: var(--accent); background: var(--accent-soft); }
.reaction-count { font-size: 11px; color: var(--text-secondary); }

/* === MSG ACTIONS === */
.msg-actions {
  opacity: 0; display: flex; align-items: center; gap: 2px;
  transition: opacity 0.15s;
  margin-top: 4px;
}

.msg-action-btn {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer;
  font-size: 14px; transition: all 0.15s;
  color: var(--text-secondary);
}
.msg-action-btn:hover { background: var(--bg-active); color: var(--text-primary); border-color: var(--border-light); }

/* === DATE SEPARATOR === */
.date-separator {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  color: var(--text-muted); font-size: 11px; font-weight: 600;
}
.date-separator::before, .date-separator::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* === TYPING INDICATOR === */
.typing-indicator {
  padding: 4px 20px 8px;
  font-size: 12px; color: var(--text-muted);
  font-style: italic; min-height: 24px;
  display: flex; align-items: center; gap: 8px;
}

.typing-dots {
  display: flex; gap: 3px; align-items: center;
}

.typing-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* === INPUT AREA === */
.input-area {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.file-preview {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px; margin-bottom: 8px;
}

.file-preview-name { flex: 1; font-size: 13px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-preview-img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.file-preview-remove { width: 24px; height: 24px; border-radius: 50%; background: rgba(239,68,68,0.2); border: none; color: var(--danger); cursor: pointer; font-size: 12px; display: flex; align-items: center; justify-content: center; }

.input-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.attach-btn, .icon-btn { flex-shrink: 0; }

.message-input-wrap { flex: 1; min-width: 0; }

.message-input {
  min-height: 22px; max-height: 140px;
  outline: none; color: var(--text-primary);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  overflow-y: auto; word-wrap: break-word;
}

.message-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted); pointer-events: none;
}

.message-input::-webkit-scrollbar { width: 4px; }
.message-input::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.send-btn {
  width: 34px; height: 34px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); border: none; border-radius: 8px;
  color: white; cursor: pointer;
  transition: all 0.2s;
}
.send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }

/* === EMOJI PICKER === */
.emoji-picker {
  position: fixed; bottom: 80px; right: 20px;
  width: 340px; max-height: 300px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 500; overflow: hidden;
  display: flex; flex-direction: column;
  animation: popIn 0.15s ease;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.emoji-search-wrap { padding: 8px; border-bottom: 1px solid var(--border); }
.emoji-search-wrap input {
  width: 100%; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-primary); font-family: var(--font);
  padding: 6px 10px; outline: none; font-size: 13px;
}
.emoji-search-wrap input:focus { border-color: var(--accent); }

.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 2px; padding: 8px; overflow-y: auto;
}
.emoji-grid::-webkit-scrollbar { width: 4px; }
.emoji-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.emoji-btn-item {
  width: 36px; height: 36px; border-radius: 6px;
  border: none; background: none; cursor: pointer;
  font-size: 20px; display: flex; align-items: center; justify-content: center;
  transition: background 0.1s;
}
.emoji-btn-item:hover { background: var(--bg-hover); }

/* === REACTION PICKER === */
.reaction-picker {
  position: fixed; z-index: 600;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 6px 8px;
  box-shadow: var(--shadow);
  animation: popIn 0.15s ease;
}

.reaction-emojis {
  display: flex; gap: 4px;
}

.reaction-opt {
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: none; cursor: pointer;
  font-size: 20px; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.reaction-opt:hover { background: var(--bg-hover); transform: scale(1.3); }

/* === MODAL === */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 800; animation: fadeIn 0.15s;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 400px;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex; flex-direction: column; gap: 16px;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
}

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 16px; padding: 4px;
  border-radius: 4px; transition: color 0.15s;
}
.modal-close:hover { color: var(--text-primary); }

/* === LOAD MORE === */
.load-more-btn {
  display: block; margin: 8px auto;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text-secondary);
  font-family: var(--font); font-size: 12px;
  padding: 6px 16px; cursor: pointer;
  transition: all 0.15s;
}
.load-more-btn:hover { border-color: var(--accent); color: var(--accent); }

/* === SYSTEM MESSAGES === */
.sys-msg {
  text-align: center; padding: 6px 20px;
  font-size: 12px; color: var(--text-muted);
}

/* === LIGHTBOX === */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; cursor: zoom-out;
  animation: fadeIn 0.15s;
}
.lightbox img {
  max-width: 90vw; max-height: 90vh;
  border-radius: var(--radius); object-fit: contain;
}

/* === RESPONSIVE === */
@media (max-width: 640px) {
  .sidebar { width: 220px; }
}

/* === SCROLLBAR === */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* === TOAST === */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 10px 20px;
  font-size: 13px; color: var(--text-primary);
  box-shadow: var(--shadow); z-index: 9999;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
