@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d0d;
  --bg2: #161616;
  --bg3: #1e1e1e;
  --bg4: #252525;
  --border: #2a2a2a;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-glow: rgba(59,130,246,0.15);
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #64748b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html { direction: rtl; }

body {
  font-family: 'Vazirmatn', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ======= صفحه احراز هویت ======= */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 0%, rgba(59,130,246,0.08) 0%, transparent 70%);
}

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-logo p {
  color: var(--text2);
  margin-top: 6px;
  font-size: 0.9rem;
}

.tab-btns {
  display: flex;
  background: var(--bg3);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 28px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-family: inherit;
  font-size: 0.95rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.88rem;
  color: var(--text2);
  margin-bottom: 8px;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s;
  outline: none;
  direction: ltr;
  text-align: right;
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }

.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { filter: brightness(1.1); }

.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { filter: brightness(1.1); }

.btn-ghost {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg4); }

.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 16px;
  display: none;
}

/* ======= داشبورد ======= */
.dashboard-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-text {
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
}

.dashboard-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.page-subtitle {
  color: var(--text2);
  margin-bottom: 32px;
}

.create-room-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 32px;
}

.create-room-card h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
  color: var(--text2);
  font-weight: 500;
}

.create-room-form {
  display: flex;
  gap: 12px;
}

.create-room-form input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}

.create-room-form input:focus {
  border-color: var(--primary);
}

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.room-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s, transform 0.2s;
}

.room-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.room-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.room-card-name {
  font-size: 1.05rem;
  font-weight: 600;
}

.room-badge {
  background: var(--primary-glow);
  color: var(--primary);
  border: 1px solid rgba(59,130,246,0.3);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}

.room-card-meta {
  color: var(--text2);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.room-card-actions {
  display: flex;
  gap: 8px;
}

.room-card-actions .btn {
  flex: 1;
  padding: 9px 12px;
  font-size: 0.85rem;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 { font-size: 1.2rem; margin-bottom: 8px; color: var(--text); }

/* ======= اتاق ======= */
.room-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.room-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 50;
}

.room-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.room-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.room-subtitle {
  color: var(--text2);
  font-size: 0.83rem;
}

.participant-badge {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
}

.room-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.video-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
  gap: 16px;
}

.section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  content: '';
  width: 3px;
  height: 16px;
  border-radius: 2px;
  background: var(--primary);
}

.speakers-section .section-title::before { background: var(--primary); }
.listeners-section .section-title::before { background: var(--green); }

.videos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.video-tile {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16/9;
  position: relative;
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.video-tile.local video { transform: scaleX(-1); }

.video-tile-info {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  padding: 8px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.video-tile-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #fff;
}

.media-icons {
  display: flex;
  gap: 4px;
}

.media-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
}

.media-icon.off { background: var(--red); }
.media-icon.on { background: rgba(255,255,255,0.15); }

.video-tile.no-video .video-avatar {
  display: flex;
}

.video-avatar {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
}

.video-avatar .avatar { width: 56px; height: 56px; font-size: 1.4rem; }

/* شنوندگان */
.listeners-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.listener-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 90px;
  position: relative;
  transition: border-color 0.2s;
}

.listener-tile.hand-raised {
  border-color: var(--yellow);
}

.hand-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  background: var(--yellow);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  box-shadow: 0 2px 8px rgba(245,158,11,0.4);
  animation: bounce 0.6s infinite alternate;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-4px); }
}

.listener-name {
  font-size: 0.78rem;
  color: var(--text2);
  text-align: center;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* پنل شرکت‌کنندگان */
.participants-panel {
  width: 280px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.panel-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 8px 4px;
  margin-bottom: 4px;
}

.participant-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  position: relative;
}

.participant-item:hover { background: var(--bg3); }

.participant-item .avatar { width: 32px; height: 32px; font-size: 0.8rem; flex-shrink: 0; }

.participant-item-name {
  flex: 1;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.participant-tags {
  display: flex;
  gap: 4px;
}

.tag-owner {
  background: rgba(139,92,246,0.2);
  color: #a78bfa;
  border: 1px solid rgba(139,92,246,0.3);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
}

.tag-hand {
  background: rgba(245,158,11,0.2);
  color: #fbbf24;
  border: 1px solid rgba(245,158,11,0.3);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
}

.participant-actions {
  display: none;
  gap: 4px;
}

.participant-item:hover .participant-actions { display: flex; }

.action-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  transition: all 0.15s;
}

.action-btn.promote { background: rgba(34,197,94,0.15); color: var(--green); }
.action-btn.promote:hover { background: var(--green); color: #fff; }
.action-btn.demote { background: rgba(245,158,11,0.15); color: var(--yellow); }
.action-btn.demote:hover { background: var(--yellow); color: #fff; }
.action-btn.kick { background: rgba(239,68,68,0.15); color: var(--red); }
.action-btn.kick:hover { background: var(--red); color: #fff; }

/* کنترل‌ها */
.room-controls {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-shrink: 0;
}

.ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.2s;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
}

.ctrl-btn:hover { background: var(--bg4); transform: scale(1.05); }
.ctrl-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.ctrl-btn.off { background: var(--red); color: #fff; border-color: var(--red); }
.ctrl-btn.hand-on { background: var(--yellow); color: #fff; border-color: var(--yellow); }

.leave-btn {
  padding: 12px 24px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 26px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 600;
  font-size: 0.9rem;
}

.leave-btn:hover {
  background: var(--red);
  opacity: 0.9;
  transform: scale(1.05);
}

/* Responsive */
@media (max-width: 768px) {
  body { font-size: 14px; }
  .auth-card { width: 90%; }
  .container { padding: 12px; }
  .grid { grid-template-columns: 1fr; }
  .room-page { flex-direction: column; }
  .room-controls { flex-wrap: wrap; }
}
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
}

.leave-btn:hover { background: #dc2626; transform: scale(1.03); }

.end-room-btn {
  padding: 12px 24px;
  background: rgba(239,68,68,0.15);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 26px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
}

.end-room-btn:hover { background: var(--red); color: #fff; }

/* توست نوتیفیکیشن */
.toasts {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  min-width: 300px;
}

.toast {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.toast.success { border-color: rgba(34,197,94,0.4); }
.toast.error { border-color: rgba(239,68,68,0.4); }
.toast.info { border-color: rgba(59,130,246,0.4); }
.toast.warn { border-color: rgba(245,158,11,0.4); }

@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-10px); }
}

/* اسکرول‌بار */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* رسپانسیو */
@media (max-width: 768px) {
  .participants-panel { display: none; }
  .videos-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .room-controls { gap: 8px; }
  .ctrl-btn { width: 44px; height: 44px; font-size: 0.95rem; }
  .leave-btn, .end-room-btn { padding: 10px 16px; font-size: 0.85rem; }
  .create-room-form { flex-direction: column; }
  .rooms-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .auth-card { padding: 24px 20px; }
  .dashboard-main { padding: 20px 16px; }
  .room-header { padding: 10px 14px; }
}

/* لودینگ */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text2);
  padding: 40px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
