:root {
  --bg: #080d1a;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #273449;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Arabic", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.app-shell, .layout-body, .main-content, .panel-section { max-width: 100%; min-width: 0; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
.ltr-val { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }

/* Focus accessibility */
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .dropzone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: radial-gradient(circle at top, #172554 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.brand-header { display: flex; gap: 0.9rem; align-items: center; margin-bottom: 1.1rem; }
.brand-logo {
  width: 46px; height: 46px; border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  display: grid; place-items: center; font-weight: 800; font-size: 1.35rem; color: #fff;
  flex-shrink: 0;
}
.brand-header h1 { margin: 0; font-size: 1.25rem; }
.brand-header p { margin: 0.15rem 0 0; }
.lang-switch-row { display: flex; justify-content: flex-end; margin-bottom: 0.85rem; }

/* Shell */
.topbar {
  height: 60px;
  background: rgba(17, 24, 39, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 35;
  gap: 0.5rem;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.55rem; flex-wrap: nowrap; min-width: 0; }
.brand-inline { display: flex; align-items: center; gap: 0.5rem; font-size: 0.98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.brand-dot.live { background: var(--success); box-shadow: 0 0 10px var(--success); }
.icon-btn {
  display: none;
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.35rem 0.65rem; font-size: 1.1rem; cursor: pointer;
}

.notice-strip {
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.3);
  color: #fde68a;
  text-align: center;
  font-size: 0.82rem;
  padding: 0.42rem 0.85rem;
}

.layout-body { display: flex; min-height: calc(100vh - 94px); }

.sidebar {
  width: 256px;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex-shrink: 0;
}
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 38;
}
.nav-list { display: flex; flex-direction: column; gap: 0.35rem; }
.nav-item {
  width: 100%;
  text-align: start;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.72rem 0.9rem;
  border-radius: 10px;
  font-size: 0.93rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(59, 130, 246, 0.5);
  color: #fff;
  font-weight: 600;
}
.sidebar-footer { margin-top: 1.25rem; padding-top: 0.9rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.65rem; }
.health-mini { font-size: 0.78rem; color: var(--muted); display: flex; justify-content: space-between; gap: 0.4rem; }

.main-content {
  flex: 1;
  padding: 1.35rem;
  max-width: 1600px;
  width: 100%;
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.section-head h2 { margin: 0; font-size: 1.35rem; font-weight: 700; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  margin-bottom: 1rem;
  min-width: 0;
}
.card h3 { margin: 0 0 0.85rem; font-size: 1.02rem; font-weight: 600; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.stat-label { font-size: 0.78rem; color: var(--muted); }
.stat-value { font-size: 1.28rem; font-weight: 700; }
.stat-sub { font-size: 0.76rem; color: var(--muted); }

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

/* Forms & Buttons */
.form-stack { display: flex; flex-direction: column; gap: 0.85rem; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
  align-items: end;
}
label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); min-width: 0; }
label.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  padding: 0.4rem 0;
  cursor: pointer;
}
input[type="text"], input[type="password"], input[type="number"], input[type="search"],
input[type="datetime-local"], input[type="date"], input[type="file"], select, textarea {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.91rem;
}
select { text-overflow: ellipsis; }
textarea { resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.6rem 1rem; border-radius: 8px; border: 1px solid transparent;
  font-size: 0.88rem; font-weight: 600; cursor: pointer; text-decoration: none;
  color: #fff; background: var(--surface-2); transition: opacity 0.15s, background 0.15s;
}
.btn:disabled { opacity: 0.42; cursor: not-allowed; }
.btn-sm { padding: 0.38rem 0.72rem; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #052e16; }
.btn-warning { background: var(--warning); color: #1c1917; }
.btn-danger { background: var(--danger); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: rgba(255,255,255,0.07); color: var(--text); }
.btn-group { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; }

.control-btn-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}
.estop-zone { margin-top: 0.5rem; }

/* Progress Bar */
.progress-track {
  width: 100%; height: 8px; border-radius: 999px; background: var(--bg);
  border: 1px solid var(--border); overflow: hidden; margin: 0.4rem 0;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.35s ease;
}

/* HLS Video Player */
.hls-player-wrap {
  background: #020617;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
}
.hls-video {
  width: 100%;
  max-height: 280px;
  background: #000;
  border-radius: 8px;
  display: block;
}

/* Dropzone & Prep Guide */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  text-align: center;
  background: rgba(59, 130, 246, 0.04);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragover { border-color: var(--primary); background: rgba(59, 130, 246, 0.12); }
.dropzone p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.prep-guide { margin-top: 0.9rem; border-top: 1px solid var(--border); padding-top: 0.7rem; }
.prep-guide summary { cursor: pointer; font-size: 0.86rem; color: var(--accent); font-weight: 600; }
.code-block {
  background: #020617; border: 1px solid var(--border); border-radius: 8px;
  padding: 0.75rem; font-size: 0.78rem; overflow-x: auto; color: #cbd5e1;
}

/* Badges & Alerts */
.badge {
  display: inline-block;
  padding: 0.2rem 0.58rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-streaming { background: rgba(16, 185, 129, 0.18); color: #34d399; border: 1px solid #10b981; }
.badge-stopped { background: rgba(148, 163, 184, 0.16); color: #cbd5e1; border: 1px solid #64748b; }
.badge-reconnecting { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border: 1px solid #f59e0b; }
.badge-danger { background: rgba(239, 68, 68, 0.18); color: #f87171; border: 1px solid #ef4444; }
.badge-info { background: rgba(6, 182, 212, 0.16); color: #22d3ee; border: 1px solid #06b6d4; }

.pill-banner { margin-top: 0.85rem; padding: 0.65rem 0.85rem; border-radius: 8px; font-size: 0.84rem; }
.warn-banner { background: rgba(245, 158, 11, 0.12); border: 1px solid rgba(245, 158, 11, 0.35); color: #fde68a; margin-bottom: 0.85rem; }
.alert-box { padding: 0.75rem 0.9rem; border-radius: 8px; font-size: 0.87rem; margin-bottom: 0.85rem; }
.alert-danger { background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.45); color: #fecaca; }
.policy-note {
  background: rgba(59, 130, 246, 0.12); border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: 8px; padding: 0.75rem; font-size: 0.82rem; color: #bfdbfe;
}

/* Media, Playlists & Calendar */
.media-preview-box { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.thumb-img {
  width: 140px; height: 96px; object-fit: cover; border-radius: 8px;
  background: #020617; border: 1px solid var(--border); flex-shrink: 0;
}
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.85rem;
  margin-top: 0.9rem;
}
.video-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.video-card img { width: 100%; height: 140px; object-fit: cover; background: #020617; cursor: pointer; }
.video-card-body { padding: 0.8rem; display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.filter-bar { display: flex; gap: 0.65rem; flex-wrap: wrap; align-items: center; }
.filter-bar input { flex: 1; min-width: 180px; }
.filter-bar select { width: auto; min-width: 155px; }

.list-stack { display: flex; flex-direction: column; gap: 0.55rem; }
.list-row {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.7rem 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.draggable-row { cursor: grab; }
.draggable-row.dragging { opacity: 0.5; border-color: var(--primary); }
.quota-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.65rem 0.85rem; margin-bottom: 0.85rem; font-size: 0.85rem;
}

.weekday-picker { grid-column: 1 / -1; }
.weekday-grid { display: flex; gap: 0.45rem; flex-wrap: wrap; margin-top: 0.35rem; }
.chip-check {
  flex-direction: row; align-items: center; gap: 0.3rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.35rem 0.6rem; color: var(--text); cursor: pointer;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.45rem; }
.cal-cell {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem; min-height: 82px; font-size: 0.78rem;
}
.cal-pill {
  background: rgba(59, 130, 246, 0.22); border-inline-start: 3px solid var(--primary);
  padding: 0.2rem 0.35rem; border-radius: 4px; margin-top: 0.25rem; font-size: 0.74rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Charts */
.chart-box svg { width: 100%; height: 165px; display: block; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
th, td { padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--border); text-align: start; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: rgba(255,255,255,0.02); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.72);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 70;
}
.modal-card {
  width: 100%; max-width: 600px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 1.25rem;
  max-height: 90vh; overflow-y: auto;
}

.toast {
  position: fixed; bottom: 1rem; inset-inline-end: 1rem;
  background: #1e293b; border: 1px solid var(--primary); color: #fff;
  padding: 0.75rem 1rem; border-radius: 10px; z-index: 80;
  max-width: 360px; box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}

/* Responsive Breakpoints (375, 390, 768, 1024, 1440, 1920) */
@media (max-width: 1024px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .icon-btn { display: inline-flex; }
  #top-scope-badge { display: none; }
  .sidebar {
    position: fixed; top: 60px; bottom: 0; inset-inline-start: 0; z-index: 40;
    transform: translateX(-110%); transition: transform 0.2s ease;
    box-shadow: 12px 0 32px rgba(0,0,0,0.55);
  }
  [dir="rtl"] .sidebar { transform: translateX(110%); }
  .sidebar.open { transform: translateX(0) !important; }
  .main-content { padding: 0.9rem; }
  .control-btn-grid { grid-template-columns: 1fr; }
  .cal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) {
  .topbar { padding: 0 0.5rem; gap: 0.35rem; }
  .topbar-right { gap: 0.3rem; }
  .brand-inline strong { font-size: 0.82rem; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  .btn-sm { padding: 0.32rem 0.5rem; font-size: 0.74rem; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
