/* ============================================================
   متغیرها (تم دارک پیش‌فرض)
   ============================================================ */
:root {
  --bg: #0f0f13;
  --bg-soft: #17171e;
  --card: #1e1e28;
  --border: #2a2a38;
  --text: #e8e8f0;
  --muted: #9a9ab0;
  --primary: #7c3aed;
  --primary-soft: #8b5cf6;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg: #f4f4f8;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --border: #e2e2ea;
  --text: #1a1a2e;
  --muted: #6b6b80;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* ============================================================
   ریست پایه
   ============================================================ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html, body { height: 100%; }
body {
  font-family: Vazirmatn, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
  overflow-x: hidden;
  line-height: 1.6;
}
a { color: var(--primary-soft); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ============================================================
   صفحه ورود/ثبت‌نام
   ============================================================ */
.auth-shell {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  min-height: 100vh;
}

.auth-brand {
  position: relative;
  padding: 3rem;
  background: linear-gradient(135deg, #1a1a2e 0%, #2d1b4e 100%);
  color: #fff;
  overflow: hidden;
}
.brand-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
  pointer-events: none;
}
.brand-glow--1 {
  width: 420px; height: 420px;
  background: #7c3aed;
  top: -120px; right: -120px;
}
.brand-glow--2 {
  width: 320px; height: 320px;
  background: #3b82f6;
  bottom: -100px; left: -100px;
}

.brand-inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  min-height: 400px;
}
.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 2.5rem;
}
.brand-logo__mark { font-size: 2rem; }
.brand-title {
  font-size: 2.6rem;
  line-height: 1.35;
  margin-bottom: 1rem;
  font-weight: 800;
}
.grad {
  background: linear-gradient(90deg, #a78bfa, #60a5fa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub {
  color: rgba(255, 255, 255, 0.72);
  margin-bottom: 2.5rem;
  line-height: 1.8;
  font-size: 1rem;
}
.brand-features {
  list-style: none;
  display: grid;
  gap: 1.3rem;
}
.brand-features li {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.feat-icon {
  font-size: 1.6rem;
  width: 48px; height: 48px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  flex-shrink: 0;
}
.brand-features strong { display: block; margin-bottom: 0.2rem; }
.brand-features small {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.82rem;
}
.brand-foot {
  position: absolute;
  bottom: 1.5rem;
  right: 3rem;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.5);
  z-index: 2;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  position: relative;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.tabs {
  position: relative;
  display: flex;
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 1.6rem;
  border: 1px solid var(--border);
}
.tab {
  flex: 1;
  padding: 0.65rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 999px;
  z-index: 2;
  transition: color 0.3s;
}
.tab.is-active { color: #fff; }
.tab-indicator {
  position: absolute;
  top: 4px; bottom: 4px;
  right: 4px;
  width: calc(50% - 4px);
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  border-radius: 999px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}
.tab-indicator[data-pos="1"] { transform: translateX(-100%); }

.form-pane { display: none; }
.form-pane.is-active {
  display: block;
  animation: fadeIn 0.35s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.pane-head { margin-bottom: 1.3rem; }
.pane-head h2 { font-size: 1.35rem; margin-bottom: 0.35rem; }
.pane-head p { color: var(--muted); font-size: 0.88rem; }

.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-weight: 500;
}
.req { color: var(--danger); }
.optional { color: var(--muted); font-size: 0.75rem; font-weight: 400; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-icon {
  position: absolute;
  right: 0.85rem;
  opacity: 0.55;
  pointer-events: none;
  font-size: 1rem;
}
.input-wrap input {
  width: 100%;
  padding: 0.85rem 2.7rem 0.85rem 2.7rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.input-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.18);
}
.input-wrap input::placeholder { color: var(--muted); opacity: 0.6; }

.eye-btn {
  position: absolute;
  left: 0.55rem;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.55;
  font-size: 1.05rem;
  padding: 0.3rem;
  border-radius: 6px;
  transition: opacity 0.2s, background 0.2s;
}
.eye-btn:hover { opacity: 1; background: var(--border); }

.field-error {
  color: var(--danger);
  font-size: 0.78rem;
  margin-top: 0.35rem;
  min-height: 1em;
  line-height: 1.4;
}
.field-hint { color: var(--muted); font-size: 0.75rem; margin-top: 0.35rem; }
.field-status {
  position: absolute;
  left: 0.85rem;
  font-size: 1rem;
  pointer-events: none;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}
.field.has-error input {
  border-color: var(--danger);
  animation: shake 0.4s;
}

.strength {
  display: flex;
  gap: 4px;
  margin-top: 0.5rem;
}
.strength__bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  transition: background 0.3s;
}
.strength[data-level="1"] .strength__bar:nth-child(-n+1) { background: var(--danger); }
.strength[data-level="2"] .strength__bar:nth-child(-n+2) { background: var(--warning); }
.strength[data-level="3"] .strength__bar:nth-child(-n+3) { background: #3b82f6; }
.strength[data-level="4"] .strength__bar { background: var(--success); }
.strength-label {
  font-size: 0.75rem;
  margin-top: 0.3rem;
  color: var(--muted);
  min-height: 1em;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.checkbox input {
  accent-color: var(--primary);
  width: 16px; height: 16px;
  cursor: pointer;
}
.checkbox--terms { margin-bottom: 1rem; }

.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.8rem 1.3rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.2s, background 0.2s, box-shadow 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  position: relative;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn--primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  color: #fff;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
}
.btn--primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.5);
}
.btn--ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn--ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--muted);
}
.btn--block { width: 100%; }
.btn--sm { padding: 0.45rem 0.9rem; font-size: 0.82rem; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: none;
}
.btn.loading .spinner { display: inline-block; }
.btn.loading .btn-label { opacity: 0.75; }
@keyframes spin { to { transform: rotate(360deg); } }

.switch-hint {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 1.2rem;
}
.link-btn {
  background: none;
  border: none;
  color: var(--primary-soft);
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }

.theme-fab {
  position: absolute;
  top: 1.2rem;
  left: 1.2rem;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  font-size: 1.15rem;
  display: grid;
  place-items: center;
  transition: transform 0.2s, border-color 0.2s;
  z-index: 10;
}
.theme-fab:hover {
  transform: scale(1.08);
  border-color: var(--primary);
}

/* ============================================================
   Toast
   ============================================================ */
.toast-container {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 0.5rem;
  z-index: 9999;
  pointer-events: none;
  max-width: 90vw;
}
.toast {
  padding: 0.75rem 1.3rem;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  animation: slideDown 0.3s;
  pointer-events: auto;
  min-width: 200px;
  text-align: center;
}
.toast--success {
  border-color: var(--success);
  color: var(--success);
}
.toast--error {
  border-color: var(--danger);
  color: var(--danger);
}
.toast--info {
  border-color: var(--primary);
  color: var(--primary-soft);
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: none; }
}

/* ============================================================
   صفحه چت
   ============================================================ */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 1rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 5;
}
.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.brand-mini {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1.05rem;
  font-weight: 700;
}
.icon-btn {
  background: none;
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--text);
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  transition: background 0.2s;
}
.icon-btn:hover { background: var(--border); }
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem 0.25rem 0.25rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
}

.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============================================================
   سایدبار
   ============================================================ */
.sidebar {
  width: 250px;
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  transition: transform 0.3s;
  flex-shrink: 0;
}
.sidebar-section { margin-bottom: 1.6rem; }
.sidebar-section h3 {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.user-list {
  list-style: none;
  display: grid;
  gap: 0.35rem;
}
.user-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  transition: background 0.2s;
}
.user-list li:hover { background: var(--border); }
.user-list li.online::before {
  content: '';
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--success);
  flex-shrink: 0;
}

/* ============================================================
   ناحیه چت
   ============================================================ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  scroll-behavior: smooth;
}
.message {
  max-width: 72%;
  padding: 0.6rem 1rem;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 0.92rem;
  line-height: 1.55;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: fadeIn 0.25s;
  align-self: flex-start;
}
.message.mine {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  color: #fff;
  border-color: transparent;
}
.message .msg-head {
  display: flex;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}
.message .msg-body { white-space: pre-wrap; }
.message .msg-time {
  font-size: 0.68rem;
  opacity: 0.55;
  margin-top: 0.35rem;
  display: block;
  text-align: left;
  direction: ltr;
}
.message.mine .msg-time { color: rgba(255, 255, 255, 0.8); }

.typing-indicator {
  padding: 0 1.2rem 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.3rem;
  font-style: italic;
}

.scroll-bottom {
  position: absolute;
  bottom: 85px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8rem;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
  font-family: inherit;
}
.scroll-bottom:hover { transform: translateX(-50%) scale(1.05); }

.message-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: center;
}
.message-form input[type="text"] {
  flex: 1;
  padding: 0.75rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  transition: border-color 0.2s;
  min-width: 0;
}
.message-form input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}

/* ============================================================
   Modal
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(4px);
}
.modal[hidden] { display: none; }
.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem;
  width: min(440px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  display: grid;
  gap: 0.55rem;
  box-shadow: var(--shadow);
  animation: fadeIn 0.3s;
}
.modal-content h3 {
  margin-bottom: 0.5rem;
  font-size: 1.15rem;
}
.modal-content label {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.3rem;
}
.modal-content input,
.modal-content textarea {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  width: 100%;
  transition: border-color 0.2s;
}
.modal-content input:focus,
.modal-content textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
}
.modal-actions .btn { flex: 1; }

/* ============================================================
   حالت خالی
   ============================================================ */
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  font-size: 0.92rem;
}
.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 0.8rem;
  opacity: 0.5;
}

/* ============================================================
   اتاق‌ها و گروه‌ها
   ============================================================ */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}
.section-head h3 {
  margin: 0;
}
.mini-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  transition: all 0.15s;
}
.mini-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.mini-btn.danger:hover {
  background: var(--danger);
  border-color: var(--danger);
}

.room-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s;
  white-space: nowrap;
  overflow: hidden;
}
.room-item:hover { background: var(--border); }
.room-item.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  color: #fff;
}
.room-item.active small { color: rgba(255, 255, 255, 0.8); }
.room-item small {
  font-size: 0.72rem;
  color: var(--muted);
  margin-right: auto;
}
.public-group-item .mini-btn {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
}

.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.room-header-info {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.room-header-icon {
  font-size: 1.5rem;
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  background: var(--bg);
  border-radius: 10px;
}
.room-header-info strong {
  display: block;
  font-size: 0.95rem;
}
.room-header-info small {
  color: var(--muted);
  font-size: 0.75rem;
}
.room-header-actions {
  display: flex;
  gap: 0.3rem;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  font-size: 0.85rem;
  transition: background 0.15s;
}
.member-row:hover { background: var(--bg-soft); }
.avatar-sm {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar-sm img { width: 100%; height: 100%; object-fit: cover; }
.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
}
.badge--purple { background: rgba(124, 58, 237, 0.15); color: var(--primary-soft); }
.badge--yellow { background: rgba(245, 158, 11, 0.15); color: var(--warning); }

/* ============================================================
   ریسپانسیو
   ============================================================ */
@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-panel { padding: 1.2rem; }
  .auth-card { padding: 1.5rem; }
  .brand-title { font-size: 2rem; }
}

@media (max-width: 720px) {
  .sidebar {
    position: absolute;
    top: 0; bottom: 0; right: 0;
    z-index: 50;
    transform: translateX(100%);
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: none; }
  .message { max-width: 85%; }
  .chat-header { padding: 0.5rem 0.7rem; }
  .user-chip span:last-child { display: none; }
  .brand-mini strong { display: none; }
}

@media (max-width: 480px) {
  .auth-card { padding: 1.2rem; }
  .brand-title { font-size: 1.7rem; }
  .tab { font-size: 0.9rem; padding: 0.55rem; }
  .message-form { padding: 0.6rem 0.7rem; gap: 0.35rem; }
}