/* ==========================================================================
   NeuroSteam Academy Manager — Unified Design System & Styles
   Cairo Typography, RTL First, Responsive Admin Layout, Print Stylesheets
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #f8fafc;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --info: #06b6d4;
  --info-light: #ecfeff;
  
  --border-color: #e2e8f0;
  --border-radius-sm: 6px;
  --border-radius-md: 10px;
  --border-radius-lg: 16px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  --font-family: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --sidebar-width: 270px;
  --header-height: 70px;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  direction: rtl;
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- Layout & Shell ---------------- */
#app-layout {
  display: flex;
  width: 100vw;
  min-height: 100vh;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 100;
  transition: transform 0.3s ease;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-brand {
  padding: 20px;
  border-bottom: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  border-radius: var(--border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  color: #fff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 11px;
  color: #94a3b8;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 10px;
  list-style: none;
}

.nav-category {
  font-size: 11px;
  text-transform: uppercase;
  color: #64748b;
  padding: 12px 14px 4px 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--border-radius-sm);
  color: #cbd5e1;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-item:hover {
  background-color: var(--bg-sidebar-hover);
  color: #ffffff;
  transform: translateX(-3px);
}

.nav-item.active {
  background-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

/* Main Content Area */
#main-wrapper {
  flex: 1;
  margin-right: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* Header */
#top-header {
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.global-search {
  position: relative;
  width: 340px;
}

.global-search input {
  width: 100%;
  padding: 9px 38px 9px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  font-family: inherit;
  font-size: 13px;
  background-color: #f1f5f9;
  transition: all 0.2s;
}

.global-search input:focus {
  outline: none;
  border-color: var(--primary);
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 15px;
}

.role-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: #f8fafc;
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--border-radius-md);
  font-size: 13px;
  color: var(--text-main);
}

.role-select {
  border: none;
  background: transparent;
  font-family: inherit;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  outline: none;
}

/* Main Viewport */
#viewport {
  flex: 1;
  padding: 28px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ---------------- Component Cards & KPI ---------------- */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.view-title-group h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
}

.view-title-group p {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 3px;
}

.view-actions {
  display: flex;
  gap: 10px;
}

/* KPI Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.kpi-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}

.kpi-card.success::after { background: var(--success); }
.kpi-card.warning::after { background: var(--warning); }
.kpi-card.danger::after { background: var(--danger); }

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-icon-wrap {
  width: 50px;
  height: 50px;
  border-radius: var(--border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background-color: var(--primary-light);
  color: var(--primary);
}

.kpi-card.success .kpi-icon-wrap { background-color: var(--success-light); color: var(--success); }
.kpi-card.warning .kpi-icon-wrap { background-color: var(--warning-light); color: var(--warning); }
.kpi-card.danger .kpi-icon-wrap { background-color: var(--danger-light); color: var(--danger); }

.kpi-content {
  flex: 1;
}

.kpi-title {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
  margin-top: 4px;
}

.kpi-hint {
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
}

/* Standard Box / Surface */
.card-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.box-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---------------- Buttons & Inputs ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background-color: #f1f5f9;
  color: #334155;
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background-color: #e2e8f0;
}

.btn-success {
  background-color: var(--success);
  color: #fff;
}
.btn-success:hover {
  background-color: #059669;
}

.btn-danger {
  background-color: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background-color: #dc2626;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ---------------- Tables ---------------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 14px;
}

.data-table th {
  background-color: #f8fafc;
  color: #475569;
  font-weight: 700;
  padding: 12px 14px;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tr:hover {
  background-color: #f8fafc;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-neutral { background: #f1f5f9; color: #475569; }

/* ---------------- Form Elements ---------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.form-control {
  padding: 9px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-family: inherit;
  font-size: 14px;
  background-color: #ffffff;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ---------------- Modals ---------------- */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal-container {
  background-color: #ffffff;
  border-radius: var(--border-radius-md);
  max-width: 750px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalSlide 0.25s ease;
}

@keyframes modalSlide {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-body {
  padding: 22px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background-color: #f8fafc;
}

/* ---------------- Toast Notifications ---------------- */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 300px;
  padding: 12px 18px;
  border-radius: var(--border-radius-sm);
  background-color: #0f172a;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastFade 0.3s ease;
}

.toast.success { background-color: #059669; }
.toast.error { background-color: #dc2626; }
.toast.warning { background-color: #d97706; }

@keyframes toastFade {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Mobile Bottom Navigation & Touch Controls */
#sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.7);
  z-index: 999;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 0.3s ease;
}

#sidebar-overlay.active {
  display: block;
}

.sidebar-toggle-btn {
  display: none;
  background: #1e293b;
  border: 1px solid #334155;
  color: #f8fafc;
  font-size: 20px;
  width: 42px;
  height: 42px;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  touch-action: manipulation;
}

.sidebar-toggle-btn:hover, .sidebar-toggle-btn:active {
  background: #334155;
  color: #38bdf8;
}

#mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  z-index: 100;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
  text-decoration: none;
  gap: 3px;
  cursor: pointer;
  min-width: 48px;
  min-height: 48px;
  touch-action: manipulation;
  user-select: none;
  transition: color var(--transition-fast);
}

.mobile-nav-item span:first-child {
  font-size: 18px;
}

.mobile-nav-item.active {
  color: var(--primary);
  font-weight: 700;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .sidebar-toggle-btn {
    display: inline-flex;
  }
  #sidebar {
    transform: translateX(100%);
    z-index: 1000;
    box-shadow: -6px 0 25px rgba(0, 0, 0, 0.6);
  }
  #sidebar.open {
    transform: translateX(0);
  }
  #main-wrapper {
    margin-right: 0;
    padding-bottom: 74px;
  }
  #mobile-nav {
    display: flex;
  }
  .global-search {
    width: 180px;
  }
  /* Mobile touch target minimums */
  .btn {
    min-height: 42px;
    padding: 10px 16px;
  }
  .form-control {
    min-height: 42px;
    font-size: 15px;
  }
}

/* ---------------- Print Stylesheet ---------------- */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  #sidebar, #top-header, #mobile-nav, .view-actions, .btn, #toast-container, .modal-footer, .no-print {
    display: none !important;
  }
  #main-wrapper {
    margin: 0 !important;
    padding: 0 !important;
  }
  #viewport {
    padding: 0 !important;
    max-width: 100% !important;
  }
  .print-card {
    border: none !important;
    box-shadow: none !important;
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 !important;
  }
}
