* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-sidebar: #0d0d1a;
  --accent: #7c3aed;
  --accent-light: #a78bfa;
  --accent-glow: rgba(124, 58, 237, 0.35);
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  --text-primary: #ffffff;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #475569;
  --sidebar-width: 260px;
}

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  direction: rtl;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ==============================================================================
   Layout & Container
   ============================================================================== */
.app-container {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  position: relative;
  overflow-x: hidden;
}

/* ==============================================================================
   Sidebar (Desktop & Mobile Drawer)
   ============================================================================== */
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--bg-sidebar), var(--bg-secondary));
  border-left: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 1000;
  overflow-y: auto;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-logo {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-logo h1 {
  font-size: 1.35rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #fff, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-close-btn {
  display: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.sidebar-close-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--error);
  border-color: var(--error);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  border-right: 3px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  user-select: none;
}

.nav-item:hover {
  background: rgba(124, 58, 237, 0.12);
  color: var(--text-primary);
  transform: translateX(-4px);
}

.nav-item.active {
  background: rgba(124, 58, 237, 0.2);
  color: #fff;
  border-right-color: var(--accent);
  box-shadow: inset 4px 0 12px rgba(124, 58, 237, 0.15);
}

.nav-item span {
  font-size: 1.25rem;
  flex-shrink: 0;
}

/* ==============================================================================
   Main Content
   ============================================================================== */
.main-content {
  flex: 1;
  margin-right: var(--sidebar-width);
  padding: 24px;
  min-height: 100vh;
  width: calc(100% - var(--sidebar-width));
  max-width: calc(100% - var(--sidebar-width));
  transition: all 0.3s ease;
}

/* ==============================================================================
   Header
   ============================================================================== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 16px 24px;
  background: linear-gradient(135deg, var(--bg-card), var(--bg-secondary));
  border-radius: 16px;
  border: 1px solid var(--border);
  gap: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(124, 58, 237, 0.15);
  border: 1px solid var(--border-light);
  color: var(--accent-light);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 1.4rem;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.mobile-menu-btn:hover {
  background: var(--accent);
  color: #fff;
  transform: scale(1.05);
}

.header-title h2 {
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-title p {
  color: var(--text-secondary);
  font-size: 0.82rem;
  margin-top: 2px;
}

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

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.online { background: rgba(16, 185, 129, 0.15); color: var(--success); border: 1px solid var(--success); }
.status-badge.offline { background: rgba(239, 68, 68, 0.15); color: var(--error); border: 1px solid var(--error); }
.status-badge.warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); border: 1px solid var(--warning); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.offline { background: var(--error); box-shadow: 0 0 8px var(--error); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* ==============================================================================
   Grids & Responsive Layouts
   ============================================================================== */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }

.config-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

/* ==============================================================================
   Cards & Stats
   ============================================================================== */
.card {
  background: linear-gradient(145deg, var(--bg-card), var(--bg-secondary));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  transition: all 0.2s ease;
  max-width: 100%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.card:hover {
  border-color: var(--border-light);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

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

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-card {
  text-align: center;
  padding: 18px 14px;
}

.stat-icon {
  font-size: 2rem;
  margin-bottom: 8px;
  opacity: 0.9;
}

.stat-value {
  font-size: clamp(1.6rem, 3.5vw, 2.3rem);
  font-weight: 800;
  background: linear-gradient(135deg, #ffffff, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 6px;
  font-weight: 600;
}

/* ==============================================================================
   Tables (Full Mobile Scrolling & Responsiveness)
   ============================================================================== */
.table-container,
.table-responsive {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  border-radius: 12px;
  margin-top: 8px;
  margin-bottom: 8px;
}

table {
  width: 100%;
  min-width: 580px;
  border-collapse: collapse;
  text-align: right;
}

th, td {
  padding: 12px 14px;
}

th {
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

td {
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

/* ==============================================================================
   Tabs Bar (Momentum Scroll for Mobile)
   ============================================================================== */
.tabs-bar,
.tabs-container {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
  padding-bottom: 10px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}

.tabs-bar::-webkit-scrollbar,
.tabs-container::-webkit-scrollbar {
  height: 4px;
}

.tabs-bar::-webkit-scrollbar-thumb,
.tabs-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.tabs-bar button,
.tabs-container button {
  white-space: nowrap;
  flex-shrink: 0;
}

/* ==============================================================================
   Buttons & Actions
   ============================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  white-space: nowrap;
  touch-action: manipulation;
  min-height: 40px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-success { background: linear-gradient(135deg, #10b981, #059669); color: white; }
.btn-warning { background: linear-gradient(135deg, #f59e0b, #d97706); color: white; }
.btn-error { background: linear-gradient(135deg, #ef4444, #dc2626); color: white; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #6d28d9); color: white; box-shadow: 0 4px 14px var(--accent-glow); }
.btn-secondary { background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-info { background: linear-gradient(135deg, #3b82f6, #2563eb); color: white; }

.btn-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ==============================================================================
   Form Elements
   ============================================================================== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Toggle Switch */
.toggle-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.toggle-group:last-child { border-bottom: none; }

.toggle-label {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}

.toggle-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.toggle {
  position: relative;
  width: 52px;
  height: 28px;
  background: var(--bg-primary);
  border-radius: 14px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.3s;
  flex-shrink: 0;
}

.toggle.active {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  top: 2px;
  right: 2px;
  transition: all 0.3s;
}

.toggle.active::after {
  right: 26px;
}

/* Slider */
.slider-group {
  margin-bottom: 20px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.slider-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.slider-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-light);
}

.slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-primary);
  -webkit-appearance: none;
  appearance: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Logs */
.logs-container {
  max-height: 380px;
  overflow-y: auto;
  background: #11141a;
  border-radius: 10px;
  padding: 16px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.82rem;
  line-height: 1.8;
  border: 1px solid var(--border);
}

.log-entry {
  display: flex;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(51, 65, 85, 0.4);
  word-break: break-word;
}

.log-time { color: var(--text-muted); flex-shrink: 0; font-size: 0.8rem; }
.log-level { font-weight: 700; width: 60px; flex-shrink: 0; }
.log-level.info { color: var(--info); }
.log-level.warning { color: var(--warning); }
.log-level.error { color: var(--error); }
.log-level.success { color: var(--success); }
.log-message { color: var(--text-primary); flex: 1; }

/* Progress */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Section Title */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ==============================================================================
   RESPONSIVE BREAKPOINTS (Mobile & Tablet First)
   ============================================================================== */

/* Screen <= 1200px */
@media (max-width: 1200px) {
  .grid-5 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Screen <= 1024px (Mobile & Tablet Mode for Sidebar) */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(100%);
    width: 280px;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.7);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: inline-flex;
  }

  .main-content {
    margin-right: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    padding: 16px 14px !important;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Screen <= 768px */
@media (max-width: 768px) {
  .header {
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 16px;
  }

  .header-title h2 {
    font-size: 1.2rem;
  }

  .grid-5, .grid-4, .grid-3, .grid-2 {
    grid-template-columns: 1fr;
  }

  .config-grid {
    grid-template-columns: 1fr;
  }

  .hide-mobile {
    display: none !important;
  }

  th, td {
    padding: 10px 10px;
    font-size: 0.83rem;
  }

  .btn {
    padding: 8px 14px;
    font-size: 0.85rem;
  }

  /* Modals */
  .modal-dialog,
  [style*="position: fixed"][style*="inset: 0"] .card,
  [style*="position: fixed"][style*="top: 0"] .card {
    width: 95% !important;
    max-width: 95% !important;
    max-height: 90vh !important;
    padding: 16px !important;
  }
}

/* Screen <= 540px */
@media (max-width: 540px) {
  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .header-right {
    justify-content: flex-start;
    width: 100%;
  }

  .header-status {
    width: 100%;
    justify-content: space-between;
  }

  .btn-group .btn {
    flex: 1 1 calc(50% - 6px);
  }

  .card {
    padding: 14px 12px;
    border-radius: 12px;
  }

  .stat-card {
    padding: 14px 10px;
  }

  .stat-icon {
    font-size: 1.6rem;
  }

  .stat-value {
    font-size: 1.6rem;
  }
}

/* Animations for Toasts and Modals */
@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

