/* منصة البث المباشر - متجاوب مع الموبايل */
:root {
  --bg: #0f0f12;
  --surface: #1a1a1f;
  --surface-hover: #222228;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #2d2d35;
  --radius: 12px;
  --font: 'Segoe UI', 'Tahoma', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  color: var(--primary-hover);
}

/* الهيدر */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-weight: 700;
  font-size: 1.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-ghost {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--border);
}

/* المحتوى الرئيسي */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

/* بطاقات البث في الصفحة الرئيسية */
.lives-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.live-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: border-color 0.2s, transform 0.15s;
}

.live-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.live-card-link {
  display: block;
  color: inherit;
}

.live-card-thumb {
  aspect-ratio: 16/9;
  background: var(--bg);
  position: relative;
}

.live-card-thumb video,
.live-card-thumb .placeholder {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.live-card-thumb .placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: var(--text-muted);
}

.live-badge {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.viewers-badge {
  position: absolute;
  bottom: 0.5rem;
  left: 0.5rem;
  background: rgba(0,0,0,0.7);
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.live-card-body {
  padding: 0.75rem 1rem;
}

.live-card-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.live-card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
}

.live-card-username {
  font-weight: 600;
  font-size: 0.95rem;
}

/* صفحة البث / المشاهدة */
.live-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.live-stage {
  flex: 1;
  background: #000;
  position: relative;
  min-height: 50vh;
}

.broadcast-visible .live-stage {
  height: 50vh;
  min-height: 280px;
}

.live-stage #localVideoWrap,
.live-stage [id="localVideoWrap"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 200px;
}

.live-stage #remoteVideoWrap,
.live-stage [id="remoteVideoWrap"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 200px;
}

.live-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  max-height: 80vh;
  display: block;
  background: #000;
}

.live-stage .placeholder-video {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1rem;
}

.live-stage .placeholder-video.placeholder-connecting {
  flex-direction: column;
  gap: 0.75rem;
}

.live-stage .placeholder-connecting::after {
  content: '';
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: placeholder-spin 0.9s linear infinite;
}

@keyframes placeholder-spin {
  to { transform: rotate(360deg); }
}

.live-info-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.live-info-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.live-info-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
}

.viewers-count {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.viewers-count span {
  color: var(--text);
  font-weight: 600;
}

/* لوحة التحكم للمذيع */
.broadcaster-actions {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* قسم التعليقات */
.comments-section {
  flex: 0 0 340px;
  max-height: 400px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.comments-header {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
}

.comments-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 120px;
}

.comment-item {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.comment-item:last-child {
  border-bottom: none;
}

.comment-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border);
}

.comment-body {
  flex: 1;
  min-width: 0;
}

.comment-user {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--primary);
}

.comment-text {
  font-size: 0.9rem;
  word-break: break-word;
}

.comment-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.comment-form {
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
}

.comment-form input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.comment-form input:focus {
  outline: none;
  border-color: var(--primary);
}

.comment-form input::placeholder {
  color: var(--text-muted);
}

/* تخطيط صفحة المشاهدة: فيديو + تعليقات جنباً إلى جنب على الشاشات الكبيرة */
@media (min-width: 768px) {
  .watch-layout {
    display: flex;
    flex-direction: row;
    min-height: calc(100vh - 56px);
  }

  .watch-layout .live-stage-wrap {
    flex: 1;
    min-width: 0;
  }

  .watch-layout .comments-section {
    max-height: none;
    height: calc(100vh - 56px);
    border-top: none;
    border-left: 1px solid var(--border);
  }
}

/* رسائل الحالة */
.status-msg {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
}

.error-msg {
  color: var(--danger);
}

/* تحسينات للموبايل */
@media (max-width: 767px) {
  .header-inner {
    padding: 0;
  }

  .lives-grid {
    grid-template-columns: 1fr;
  }

  .comment-form {
    padding: 0.5rem;
  }

  .broadcaster-actions .btn {
    flex: 1;
    min-width: 120px;
  }
}

/* safe area للشاشات ذات النتوء */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .header {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .comment-form {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  }
}

/* نماذج التسجيل والدخول والملف الشخصي */
.form-stack { display: flex; flex-direction: column; gap: 1rem; }
.form-stack label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; }
.form-stack input[type="text"],
.form-stack input[type="email"],
.form-stack input[type="password"],
.form-stack input[type="file"],
.form-stack textarea {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.form-stack textarea { min-height: 100px; resize: vertical; }
.profile-card { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; border: 1px solid var(--border); }
.profile-header { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.profile-avatar { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; background: var(--border); }
.profile-stats { display: flex; gap: 1.5rem; margin: 0.75rem 0; }
.profile-bio { color: var(--text-muted); margin-top: 0.5rem; white-space: pre-wrap; }
.btn-follow { min-width: 100px; }
