:root {
  --bg: #101418;
  --bg-2: #171c22;
  --bg-3: #1f262e;
  --border: #2b333d;
  --text: #e8edf2;
  --text-dim: #9aa7b4;
  --accent: #e8563f;
  --accent-2: #ff7a5c;
  --ok: #3fbf7f;
  --warn: #e8b23f;
  --danger: #e05252;
  --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Noto Naskh Arabic", "Noto Sans Arabic", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
}

#app { display: flex; height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 210px; min-width: 210px;
  background: var(--bg-2);
  border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand-icon { font-size: 26px; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--text-dim); }
nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  text-align: start; background: none; border: none; color: var(--text-dim);
  padding: 10px 12px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.nav-btn:hover { background: var(--bg-3); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; font-size: 11px; color: var(--text-dim); padding: 8px; }
.backup-indicator {
  margin-top: auto; font-size: 12px; color: var(--warn);
  display: flex; align-items: center; gap: 8px; padding: 8px;
}
.backup-indicator.hidden { display: none; }
.backup-indicator + .sidebar-foot { margin-top: 6px; }

/* ---------- Main ---------- */
#main { flex: 1; overflow-y: auto; padding: 26px 30px 110px; }
.view.hidden { display: none; }

h1 { font-size: 21px; margin-bottom: 4px; }
h2 { font-size: 16px; margin: 22px 0 10px; }
.subtitle { color: var(--text-dim); margin-bottom: 20px; font-size: 13px; }

/* ---------- Cards / stats ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.card .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.card .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.card .hint { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.card.ok .value { color: var(--ok); }
.card.warn .value { color: var(--warn); }
.card.accent .value { color: var(--accent-2); }

.panel {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-top: 14px;
}
.panel h3 { font-size: 13px; margin-bottom: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }

.bar-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 13px; }
.bar-row .bar-label { width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { flex: 1; height: 8px; background: var(--bg-3); border-radius: 4px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.bar-row .bar-val { width: 90px; text-align: end; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }
.search-input { width: 280px; }

.btn {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--text-dim); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.icon-btn {
  background: none; border: none; color: var(--text); font-size: 15px; cursor: pointer;
  padding: 6px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg-3); }

.filters-panel {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px;
}
.filters-panel.hidden { display: none; }
.field label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.field input, .field select { width: 100%; }
.filters-actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { background: var(--bg-2); color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; position: sticky; top: 0; }
tbody tr:hover { background: var(--bg-2); cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; color: var(--text-dim); }

.tag { display: inline-block; background: var(--bg-3); border: 1px solid var(--border); border-radius: 20px; padding: 1px 9px; font-size: 11px; margin: 1px 0; margin-inline-end: 2px; color: var(--text-dim); }
.badge { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.badge.draft { background: #3a4250; color: #b9c4d0; }
.badge.scheduled { background: #274a63; color: #7fc0ef; }
.badge.aired { background: #1f4634; color: #64d99f; }
.badge.archived { background: #4a4030; color: #d9b664; }
.badge.auto { background: #274a63; color: #7fc0ef; }
.badge.manual { background: #3a4250; color: #b9c4d0; }

.empty { text-align: center; color: var(--text-dim); padding: 46px 20px; font-size: 13px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px;
  width: 640px; max-width: 92vw; max-height: 86vh; overflow-y: auto; padding: 22px 24px;
}
.modal h2 { margin: 0 0 16px; }
.modal .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal .form-grid .full { grid-column: 1 / -1; }
.modal textarea { width: 100%; min-height: 70px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.rec-list { margin-top: 8px; }
.rec-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--bg-3);
}
.rec-item .rec-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-item .rec-meta { color: var(--text-dim); font-size: 12px; white-space: nowrap; }

/* ---------- Player ---------- */
.player {
  position: fixed; inset-inline-start: 210px; inset-inline-end: 0; bottom: 0; height: 64px;
  background: var(--bg-2); border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 18px; z-index: 50;
}
.player.hidden { display: none; }
.player-info { min-width: 180px; max-width: 260px; }
#player-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-times { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
#player-seek { flex: 1; accent-color: var(--accent); }
#player-volume { width: 90px; accent-color: var(--accent); }

/* ---------- Toasts ---------- */
#toasts { position: fixed; inset-inline-end: 18px; bottom: 80px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-3); border: 1px solid var(--border); border-inline-start: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; font-size: 13px; max-width: 340px;
  animation: slideIn .18s ease;
}
.toast.ok { border-inline-start-color: var(--ok); }
.toast.error { border-inline-start-color: var(--danger); }
@keyframes slideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--warn);
  border-radius: 50%; display: inline-block; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--text-dim); }
.row-actions { display: flex; gap: 4px; }
.back-link { color: var(--accent-2); cursor: pointer; font-size: 13px; margin-bottom: 12px; display: inline-block; background: none; border: none; }
.settings-grid { display: grid; gap: 14px; max-width: 620px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.settings-row .desc { font-size: 12px; color: var(--text-dim); margin-top: 3px; max-width: 380px; }

/* ---------- File rows & viewer ---------- */
.file-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.viewer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.78);
  display: flex; align-items: center; justify-content: center; z-index: 150;
}
.viewer {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px;
  width: 1040px; max-width: 94vw; height: 88vh; display: flex; flex-direction: column; overflow: hidden;
}
.viewer-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.viewer-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar a.btn { text-decoration: none; }
.viewer-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #000; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-none { color: var(--text-dim); padding: 40px; text-align: center; max-width: 480px; line-height: 1.6; }

/* ---------- Language / RTL ---------- */
.lang-row { margin-top: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.lang-row label { font-size: 11px; color: var(--text-dim); }
.lang-row select { width: 100%; }
.backup-indicator + .lang-row { margin-top: 6px; }
.lang-row + .sidebar-foot { margin-top: 4px; }
[dir="rtl"] body, [dir="rtl"] { font-size: 14.5px; }
[dir="rtl"] input[type="number"], [dir="rtl"] input[type="date"], [dir="rtl"] .num, [dir="rtl"] code, [dir="rtl"] .rec-meta, [dir="rtl"] .player-times { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] td.num, [dir="rtl"] .bar-val { text-align: end; }
[dir="rtl"] .rec-name, [dir="rtl"] .viewer-title { direction: ltr; unicode-bidi: isolate; text-align: start; }

/* ---------- Login & users ---------- */
[hidden] { display: none !important; }
.login-backdrop { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 300; }
.login-box { width: 380px; max-width: 92vw; background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; padding: 26px 28px; }
.login-box .brand { padding: 0 0 18px; }
.login-box .field { margin-bottom: 12px; }
.login-box .field input, .login-box .field select { width: 100%; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 10px; }
.login-actions { display: flex; justify-content: flex-end; }
.user-row { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px; border-top: 1px solid var(--border); }
.user-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 11px; color: var(--text-dim); }
.user-row + .lang-row, .backup-indicator + .user-row { margin-top: 6px; }
.users-table td, .users-table th { padding: 8px 10px; }
.users-table select, .users-table input { padding: 5px 8px; font-size: 12px; }
.users-add { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
