:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-card: #1c1f27;
  --border: #2a2e38;
  --text: #e8e9ec;
  --text-muted: #9aa0ac;
  --accent: #6d5bff;
  --accent-hover: #5a49e6;
  --danger: #e5484d;
  --success: #3dd68c;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Tahoma', 'Segoe UI', system-ui, -apple-system, sans-serif;
  direction: rtl;
  text-align: right;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s ease;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.danger {
  background: var(--danger);
}

input, select {
  font-family: inherit;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  width: 100%;
}

input:focus, select:focus, button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ============ صفحات تسجيل الدخول ============ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 30% 20%, #1a1f2e 0%, var(--bg) 60%);
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  font-size: 22px;
  margin: 0 0 6px;
  text-align: center;
}

.auth-card p.subtitle {
  color: var(--text-muted);
  text-align: center;
  margin: 0 0 26px;
  font-size: 14px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.form-error {
  background: rgba(229, 72, 77, 0.12);
  border: 1px solid rgba(229, 72, 77, 0.4);
  color: #ff8f92;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
  margin-bottom: 16px;
  display: none;
}

.form-error.show {
  display: block;
}

.auth-card button[type="submit"] {
  width: 100%;
  padding: 12px;
  font-size: 15.5px;
  margin-top: 6px;
}

/* ============ تخطيط عام للتطبيق ============ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header .brand {
  font-weight: bold;
  font-size: 17px;
}

.app-header .brand span {
  color: var(--accent);
}

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

.header-actions .user-tag {
  color: var(--text-muted);
  font-size: 13.5px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 22px;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 17px;
}

.card h2 small {
  color: var(--text-muted);
  font-weight: normal;
  font-size: 13px;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  background: rgba(61, 214, 140, 0.12);
  color: var(--success);
  border: 1px solid rgba(61, 214, 140, 0.3);
}

.status-badge.off {
  background: rgba(154, 160, 172, 0.12);
  color: var(--text-muted);
  border-color: var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
}

th, td {
  text-align: right;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show {
  opacity: 1;
}

.toast.error {
  border-color: rgba(229, 72, 77, 0.5);
  color: #ff8f92;
}

.toast.success {
  border-color: rgba(61, 214, 140, 0.5);
  color: var(--success);
}

.pill-btn {
  padding: 5px 12px;
  font-size: 13px;
  border-radius: 999px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 10px;
  font-size: 14.5px;
}

/* ============ واجهة القنوات (العميل) ============ */
.channels-toolbar {
  position: sticky;
  top: 61px;
  z-index: 15;
  background: var(--bg);
  padding: 14px 24px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.channels-toolbar input[type="search"] {
  flex: 1;
  min-width: 200px;
}

.channels-toolbar select {
  min-width: 160px;
  width: auto;
}

.channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  padding: 20px 24px 40px;
}

.channel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

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

.channel-card .logo-wrap {
  width: 100%;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.channel-card img {
  max-width: 100%;
  max-height: 64px;
  object-fit: contain;
  border-radius: 6px;
}

.channel-card .no-logo {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text-muted);
  margin: 0 auto;
}

.channel-card .name {
  font-size: 13.5px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.channel-card .group {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* مشغل الفيديو */
.player-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.player-overlay.hidden {
  display: none;
}

.player-box {
  width: 100%;
  max-width: 1000px;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

.player-box video {
  width: 100%;
  max-height: 78vh;
  display: block;
  background: #000;
}

.player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #111;
}

.player-header .title {
  font-size: 15px;
}

.player-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
}

.player-close:hover {
  color: var(--text);
  background: transparent;
}

.player-error {
  padding: 30px 20px;
  text-align: center;
  color: #ff8f92;
  display: none;
}

.player-error.show {
  display: block;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 20px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 380px;
}

.modal-box h3 {
  margin: 0 0 16px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 640px) {
  .container { padding: 16px; }
  .channels-toolbar { padding: 12px 16px; }
  .channels-grid { padding: 16px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .auth-card { padding: 28px 22px; }
}
