@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800;900&display=swap');

:root {
  /* Project-Wide Font: Tajawal */
  --font-sans: 'Tajawal', Tahoma, sans-serif;
  
  /* Cyber Emerald Theme Palette */
  --bg-main: #f0f4f8;
  --bg-mesh: radial-gradient(at 0% 0%, rgba(13, 148, 136, 0.08) 0px, transparent 50%),
              radial-gradient(at 100% 0%, rgba(99, 102, 241, 0.06) 0px, transparent 50%);
  --panel-bg: rgba(255, 255, 255, 0.95);
  --panel-border: #cbd5e1;
  --card-bg: #ffffff;
  --card-border: #cbd5e1;
  
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-inverse: #ffffff;
  
  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-light: rgba(13, 148, 136, 0.08);
  --primary-glow: rgba(13, 148, 136, 0.2);
  
  --accent: #6366f1;
  --accent-light: rgba(99, 102, 241, 0.08);
  
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #ffffff;
  --sidebar-active: #ffffff;
  --sidebar-active-bg: #0d9488;
  
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.15);
  
  --radius-sm: 3px;
  --radius-md: 4px;
  --radius-lg: 6px;
  --radius-full: 9999px;
}

[data-theme="dark"] {
  --bg-main: #0b0f19;
  --bg-mesh: radial-gradient(at 0% 0%, rgba(13, 148, 136, 0.15) 0px, transparent 40%),
              radial-gradient(at 100% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 40%);
  --panel-bg: rgba(15, 23, 42, 0.95);
  --panel-border: #334155;
  --card-bg: #1e293b;
  --card-border: #334155;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --sidebar-bg: #090d16;
  --input-bg: #0f172a;
  --input-border: #334155;
  
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  background-image: var(--bg-mesh);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  font-size: 0.94rem;
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
}

/* Base Layout Container */
.app-layout {
  display: flex;
  min-height: 100vh;
  direction: rtl;
}

/* Compact Sidebar Styling */
.app-sidebar {
  width: 230px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 100;
  transition: transform 0.2s ease;
  box-shadow: 4px 0 15px rgba(0, 0, 0, 0.2);
  text-align: right;
}

.sidebar-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-icon-box {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #0d9488 0%, #4f46e5 100%);
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: 1.3rem;
  font-weight: 800;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.1rem;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.2;
}

.brand-text span {
  font-size: 0.72rem;
  color: #94a3b8;
  font-weight: 400;
  display: block;
}

.sidebar-nav {
  padding: 10px 8px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #64748b;
  padding: 10px 10px 4px;
  font-weight: 800;
  text-align: right;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.95rem;
  transition: all 0.15s ease;
  text-align: right;
}

.nav-link svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.2;
  flex-shrink: 0;
}

.nav-link:hover {
  color: var(--sidebar-hover);
  background: rgba(255, 255, 255, 0.08);
}

.nav-link.active {
  color: var(--sidebar-active);
  background: var(--sidebar-active-bg);
  font-weight: 800;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #6366f1 0%, #0d9488 100%);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.9rem;
}

.user-info .user-name {
  color: white;
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.2;
}

.user-info .user-role {
  color: #94a3b8;
  font-size: 0.75rem;
}

/* Main Content Area */
.app-main {
  flex: 1;
  margin-right: 230px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-right 0.2s ease;
  text-align: right;
}

.app-header {
  height: 56px;
  padding: 0 20px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.header-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-toggle {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 4px;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.2px;
  text-align: right;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cmd-palette-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cmd-palette-btn svg {
  width: 17px;
  height: 17px;
}

.cmd-palette-btn:hover {
  border-color: var(--primary);
  color: var(--text-main);
}

.cmd-kbd {
  background: var(--bg-main);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-size: 0.75rem;
  font-family: monospace;
}

.theme-toggle-btn {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
}

.theme-toggle-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.logout-btn svg {
  width: 16px;
  height: 16px;
}

.logout-btn:hover {
  background: var(--danger);
  color: white;
}

/* Ergonomic Content Body */
.content-body {
  padding: 16px 20px;
  flex: 1;
  max-width: 1200px;
  width: 100%;
}

/* Card System */
.glass-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  text-align: right;
}

.glass-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--panel-border);
}

.glass-card-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: right;
}

.glass-card-title svg {
  color: var(--primary);
  width: 22px;
  height: 22px;
  stroke-width: 2.2;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stats-grid-wide {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stats-grid-wide .stat-card {
  padding: 14px 16px;
}

.stats-grid-wide .stat-label {
  font-size: 0.88rem;
}

@media (max-width: 760px) {
  .stats-grid-wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .stats-grid-wide {
    grid-template-columns: minmax(0, 1fr);
  }
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  text-align: right;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--primary);
}

.stat-card.danger::after { background: var(--danger); }
.stat-card.success::after { background: var(--success); }

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
  gap: 4px;
}

.stat-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-icon {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.stat-icon svg {
  width: 15px;
  height: 15px;
  stroke-width: 2.2;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  letter-spacing: -0.3px;
  text-align: right;
}

.stat-desc {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Button System */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  text-align: right;
  width: fit-content;
}

.btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

.btn:disabled,
.logout-btn:disabled,
a.btn[aria-busy="true"] {
  cursor: wait;
  opacity: 0.72;
  pointer-events: none;
}

.button-spinner {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
  animation: button-spin 0.7s linear infinite;
}

@keyframes button-spin {
  to { transform: rotate(360deg); }
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--card-bg);
  border-color: var(--card-border);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-full {
  width: auto;
  max-width: 280px;
  min-width: 160px;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

/* Compact Toolbar Strips */
.toolbar-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Form Controls & Controlled Max Widths */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 320px));
  gap: 14px;
  margin-bottom: 14px;
  text-align: right;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: right;
  max-width: 360px;
  width: 100%;
}

.form-group.full {
  grid-column: 1 / -1;
  max-width: 680px;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  text-align: right;
}

.form-control, input[type="text"], input[type="number"], input[type="password"], input[type="file"], select, textarea {
  width: 100%;
  max-width: 360px;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  color: var(--text-main);
  outline: none;
  direction: rtl;
  text-align: right;
  transition: border-color 0.15s ease;
}

.form-control:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.search-box {
  position: relative;
  min-width: 220px;
  max-width: 320px;
}

.search-box input {
  padding-right: 34px;
  text-align: right;
  max-width: 100%;
}

.search-box svg {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 18px;
  height: 18px;
}

/* Balanced Table Layout */
.table-responsive {
  width: 100%;
  max-height: 65vh;
  overflow: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  direction: rtl;
}

.table-responsive.table-compact {
  max-height: 205px;
}

.table-compact .modern-table th {
  padding: 6px 12px;
  font-size: 0.88rem;
}

.table-compact .modern-table td {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.modern-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: right;
  direction: rtl;
  font-size: 0.9rem;
}

.modern-table thead {
  position: sticky;
  top: 0;
  z-index: 5;
}

.modern-table th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--card-bg);
  box-shadow: 0 2px 0 var(--panel-border);
  color: var(--text-main);
  font-weight: 800;
  font-size: 0.94rem;
  padding: 10px 14px;
  border-bottom: 2px solid var(--panel-border);
  white-space: nowrap;
  text-align: right;
}

.modern-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--panel-border);
  color: var(--text-main);
  text-align: right;
  transition: background 0.1s ease;
}

.modern-table tbody tr:hover {
  background: var(--primary-light);
}

/* Pulsing Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.2;
}

.badge-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  animation: pulseDot 1.5s infinite;
}

@keyframes pulseDot {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-success .badge-pulse { background: var(--success); }

.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-warning .badge-pulse { background: var(--warning); }

.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-danger .badge-pulse { background: var(--danger); }

.badge-info { background: var(--accent-light); color: var(--accent); }

/* Command Palette Backdrop */
.cmd-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  direction: rtl;
}

.cmd-modal-backdrop.open {
  display: flex;
}

.cmd-modal {
  width: min(560px, calc(100% - 24px));
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  text-align: right;
}

.cmd-input-wrap {
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.cmd-input-wrap input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 1rem;
  width: 100%;
  max-width: 100%;
  color: var(--text-main);
  text-align: right;
  direction: rtl;
}

.cmd-results {
  max-height: 340px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cmd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 700;
  transition: background 0.1s ease;
  text-align: right;
}

.cmd-item:hover, .cmd-item.selected {
  background: var(--primary-light);
  color: var(--primary);
}

/* Toast Notification System */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  direction: rtl;
}

.toast {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.88rem;
  animation: slideUp 0.2s ease;
  min-width: 260px;
  text-align: right;
}

.toast.success { border-right: 4px solid var(--success); }
.toast.error { border-right: 4px solid var(--danger); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Login Page Styling */
.login-wrapper {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  direction: rtl;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-brand .brand-icon-box {
  margin: 0 auto 14px;
  width: 54px;
  height: 54px;
  font-size: 1.6rem;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-main);
}

.login-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Media Queries & Responsiveness */
@media (max-width: 992px) {
  .app-sidebar {
    transform: translateX(100%);
  }
  
  .app-sidebar.open {
    transform: translateX(0);
  }
  
  .app-main {
    margin-right: 0;
  }
  
  .mobile-toggle {
    display: block;
  }
}
