:root {
  --bg: #120d0e;
  --bg-glow: #2c1e1d;
  --surface: #1d1516;
  --surface-2: #261c1d;
  --border: rgba(255, 255, 255, 0.09);
  --text: #faf6f5;
  --muted: #b8a9a6;
  --cyan: #73d1f9;
  --cyan-dim: rgba(115, 209, 249, 0.14);
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 16px;
  --nav-h: 68px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(110% 60% at 50% 0%, var(--bg-glow) 0%, var(--bg) 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Noto Sans Arabic', 'SF Arabic', 'Geeza Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100dvh;
  overflow-x: hidden;
}

a { color: var(--cyan); text-decoration: none; }
button, input, select, textarea { font-family: inherit; color: var(--text); }

.app-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 14px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom, 0px));
}

/* Top Bar */
.m-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  margin: 0 -14px 12px;
  background: rgba(18, 13, 14, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.m-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.m-brand img {
  height: 30px;
  width: auto;
  border-radius: 6px;
}

.m-brand-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.m-brand-sub {
  font-size: 0.72rem;
  color: var(--muted);
}

.m-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn.cyan {
  border-color: rgba(115, 209, 249, 0.45);
  background: var(--cyan-dim);
  color: var(--cyan);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.green { background: var(--green); box-shadow: 0 0 8px rgba(74, 222, 128, 0.65); }
.status-dot.amber { background: var(--amber); }
.status-dot.red { background: var(--red); box-shadow: 0 0 8px rgba(248, 113, 113, 0.65); }
.status-dot.cyan { background: var(--cyan); }

/* Banners */
.alert-banner {
  display: none;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 12px;
  font-size: 0.84rem;
  line-height: 1.5;
  border: 1px solid var(--border);
}
.alert-banner.visible { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.alert-banner.offline { background: rgba(251, 191, 36, 0.12); border-color: rgba(251, 191, 36, 0.45); color: #fde68a; }
.alert-banner.emergency { background: rgba(248, 113, 113, 0.16); border-color: var(--red); color: #fecaca; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  margin-bottom: 12px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

/* Status & Metrics Grid */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

@media (min-width: 680px) {
  .grid-2.tablet-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.metric-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 12px;
}

.metric-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.metric-value {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 7px;
}

.metric-sub {
  font-size: 0.71rem;
  color: var(--muted);
  margin-top: 4px;
}

.count-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}
.count-chip .num { font-size: 1.25rem; font-weight: 800; color: var(--cyan); }
.count-chip .lbl { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

/* Touch Buttons */
.btn-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.sm { min-height: 38px; padding: 7px 11px; font-size: 0.78rem; border-radius: 10px; }
.btn.primary { background: var(--cyan); color: #0c1215; border-color: var(--cyan); }
.btn.success { background: rgba(74, 222, 128, 0.16); color: var(--green); border-color: rgba(74, 222, 128, 0.45); }
.btn.warn { background: rgba(251, 191, 36, 0.14); color: var(--amber); border-color: rgba(251, 191, 36, 0.45); }
.btn.danger { background: rgba(248, 113, 113, 0.16); color: var(--red); border-color: rgba(248, 113, 113, 0.5); }
.btn.full { width: 100%; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge.ready, .badge.approved, .badge.completed { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.badge.running, .badge.processing, .badge.cyan { background: var(--cyan-dim); color: var(--cyan); }
.badge.warn, .badge.pending_review, .badge.scheduled { background: rgba(251, 191, 36, 0.16); color: var(--amber); }
.badge.failed, .badge.rejected, .badge.expired { background: rgba(248, 113, 113, 0.16); color: var(--red); }
.badge.archived, .badge.stopped, .badge.cancelled { background: rgba(184, 169, 166, 0.15); color: var(--muted); }
.badge.manually_published, .badge.published { background: rgba(115, 209, 249, 0.22); color: var(--cyan); }

/* Progress Bars */
.bar-wrap { margin-bottom: 10px; }
.bar-head { display: flex; justify-content: space-between; font-size: 0.78rem; margin-bottom: 4px; }
.bar-track { height: 7px; background: rgba(255,255,255,0.08); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--cyan); border-radius: 999px; transition: width 0.3s ease; }
.bar-fill.warn { background: var(--amber); }
.bar-fill.danger { background: var(--red); }

/* Inputs */
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: #140f10;
  color: var(--text);
  font-size: 0.9rem;
}
textarea { min-height: 76px; resize: vertical; }

/* Filter Pills & Search */
.filter-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.filter-chip.active {
  background: var(--cyan-dim);
  border-color: var(--cyan);
  color: var(--cyan);
}

/* Carousel & Task List Cards */
.run-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.run-thumb {
  width: 72px;
  height: 90px;
  border-radius: 10px;
  object-fit: cover;
  background: #100b0c;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.run-info { flex: 1; min-width: 0; }
.run-title { font-weight: 700; font-size: 0.94rem; line-height: 1.4; margin-bottom: 5px; }
.run-meta { font-size: 0.74rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* Swipeable Slide Viewer */
.swipe-stage {
  position: relative;
  margin: 0 -4px 10px;
}
.swipe-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  gap: 10px;
  padding: 2px 4px 8px;
  scrollbar-width: none;
}
.swipe-track::-webkit-scrollbar { display: none; }
.swipe-slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0d090a;
  position: relative;
}
.swipe-slide img {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  display: block;
}
.slide-counter {
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  background: rgba(0, 0, 0, 0.72);
  color: var(--cyan);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.thumb-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 10px;
}
.thumb-item {
  width: 56px;
  height: 70px;
  border-radius: 8px;
  object-fit: cover;
  border: 2px solid transparent;
  opacity: 0.65;
  cursor: pointer;
  flex-shrink: 0;
}
.thumb-item.active {
  border-color: var(--cyan);
  opacity: 1;
}

.caption-preview {
  background: #140f10;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px;
  font-size: 0.88rem;
  line-height: 1.75;
  white-space: pre-wrap;
  margin-bottom: 10px;
}

/* Panels */
.view-panel { display: none; }
.view-panel.active { display: block; }

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(20, 14, 15, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav-inner {
  max-width: 860px;
  margin: 0 auto;
  height: var(--nav-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}
.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}
.nav-item .ico { font-size: 1.25rem; line-height: 1; }
.nav-item.active { color: var(--cyan); }
.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 34px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--cyan);
}

/* Auth Screen */
.auth-overlay {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

/* Modal / Confirm Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.72);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}
.modal-backdrop.open { display: flex; }
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
}

/* Toast */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-14px);
  z-index: 120;
  background: #1b1415;
  border: 1px solid var(--cyan);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.84rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 28px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.notif-item {
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  font-size: 0.82rem;
}
.notif-item.unread { border-inline-start: 3px solid var(--cyan); }
.log-row {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  direction: ltr;
  text-align: left;
  word-break: break-word;
}
.log-row.error { color: var(--red); }
.log-row.warn { color: var(--amber); }
