/**
 * Shared layout for RBAC dashboard (sidebar, topbar, cards, tables)
 */
:root {
  --bg-main: #F7F3ED;
  --bg-card: #FFFFFF;
  --bg-card-light: #FAF7F2;
  --text-dark: #1F1F1F;
  --text-light: #6B6B6B;
  --text-muted: #9CA3AF;
  --primary: #1A73E8;
  --primary-dark: #1558b0;
  --danger: #E74C3C;
  --success: #27AE60;
  --warning: #F39C12;
  --admin-color: #8B5CF6;
  --border: #E5E7EB;
  --radius: 14px;
  --shadow: 0 4px 25px rgba(0,0,0,0.06);
  --font-main: "Tajawal", sans-serif;
  --sidebar-width: 260px;
}

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

/* Design tokens: spacing (use multiples of 4px) */
:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
}

body {
  font-family: var(--font-main);
  background: var(--bg-main);
  color: var(--text-dark);
  direction: rtl;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body.has-app-header {
  padding-top: 0;
}

body:not(.layout-with-sidebar) {
  display: block;
}

/* ——— Unified App Header (logo + name + logout) ——— */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 1100;
  flex-shrink: 0;
}

.app-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.app-header-brand-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
}
.app-header-brand { display: inline-flex; align-items: center; gap: var(--space-3); }

.app-header-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--text-dark);
  font-weight: 700;
  font-size: 18px;
  transition: opacity 0.2s;
}

.app-header-brand:hover {
  opacity: 0.9;
}

.app-header-logo {
  width: 40px;
  height: 40px;
  display: block;
  border-radius: 10px;
}

.app-header-name {
  white-space: nowrap;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-header-logout {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  border: none;
  background: rgba(231, 76, 60, 0.1);
  color: var(--danger);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.app-header-logout:hover {
  background: rgba(231, 76, 60, 0.2);
}

/* Loading and error states for data fetch */
.loading-state {
  color: var(--text-muted);
  margin: 0;
  padding: var(--space-4);
}
.error-state {
  color: var(--danger);
  margin: 0;
  padding: var(--space-4);
}

/* Dashboard hero: large logo + welcome */
.dashboard-hero {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  margin-bottom: var(--space-6);
}
.dashboard-hero-logo {
  display: block;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius);
  object-fit: contain;
  box-shadow: var(--shadow);
}
.dashboard-hero-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 var(--space-2);
  color: var(--text-dark);
}
.dashboard-hero-sub {
  color: var(--text-light);
  margin: 0;
  font-size: 1rem;
}

.dashboard-quick-actions .quick-action-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-card-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s, border-color 0.2s;
}
.dashboard-quick-actions .quick-action-link:hover {
  background: rgba(26, 115, 232, 0.08);
  border-color: var(--primary);
}

/* Profile dropdown in topbar */
.profile-dropdown-wrap { position: relative; }
.profile-dropdown-btn {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  font-weight: 700; font-size: 1rem;
}
.profile-dropdown-btn:hover { opacity: 0.9; }
.profile-dropdown-menu {
  position: absolute; top: 100%; right: 0; margin-top: 8px;
  min-width: 180px; background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: var(--space-2); z-index: 1100; display: none;
}
.profile-dropdown-menu.visible { display: block; }
.profile-dropdown-menu a, .profile-dropdown-menu button {
  display: block; width: 100%; padding: 10px 12px; text-align: right;
  border: none; background: none; cursor: pointer; color: var(--text-dark);
  font-family: var(--font-main); font-size: 14px; text-decoration: none;
  border-radius: 8px;
}
.profile-dropdown-menu a:hover, .profile-dropdown-menu button:hover { background: var(--bg-card-light); }

@media (max-width: 640px) {
  .app-header-inner { padding: var(--space-3) var(--space-4); }
  .app-header-name { font-size: 16px; }
}

.layout-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.layout-with-sidebar .layout-body {
  flex-direction: row;
}

/* Sidebar: fixed width, no overlap with content */
.app-sidebar {
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -2px 0 10px rgba(0,0,0,0.05);
  height: 100vh;
  position: fixed;
  width: var(--sidebar-width);
  right: 0;
  top: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.sidebar-logo-img {
  width: 36px;
  height: 36px;
  display: block;
  margin: 0 auto 10px;
  border-radius: 10px;
  object-fit: contain;
}

.sidebar-logo {
  width: 44px;
  height: 44px;
  margin: 0 auto 10px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.sidebar-brand-text { display: flex; flex-direction: column; gap: 6px; }
.sidebar-app-name { font-size: 15px; font-weight: 700; color: var(--text-dark); }
.sidebar-role-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(26,115,232,0.1);
  color: var(--primary);
}

.sidebar-nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.sidebar-nav ul { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li { margin: 2px 10px; border-radius: 10px; }
.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  color: var(--text-light);
  text-decoration: none;
  font-size: 15px;
  transition: all 0.2s;
  border-radius: 10px;
}
.sidebar-nav li a:hover { background: rgba(26,115,232,0.08); color: var(--primary); }
.sidebar-nav li.active a {
  background: rgba(26,115,232,0.1);
  color: var(--primary);
  font-weight: 600;
  border-right: 3px solid var(--primary);
}
.sidebar-nav li a i { width: 20px; text-align: center; font-size: 16px; }

.sidebar-footer { padding: 15px 18px; border-top: 1px solid var(--border); }
.logout-btn {
  width: 100%;
  padding: 12px;
  background: rgba(231,76,60,0.08);
  color: var(--danger);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.25s;
}
.logout-btn:hover { background: rgba(231,76,60,0.15); }

/* Main: margin clears fixed sidebar; only when sidebar present */
body.layout-with-sidebar .main-content {
  margin-right: var(--sidebar-width);
}
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 15px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.topbar-title { font-size: 20px; font-weight: 700; color: var(--text-dark); }
.topbar-title span { color: var(--primary); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-profile-wrap { position: relative; }
.topbar-profile-wrap .profile-dropdown-menu { right: 0; left: auto; top: 100%; margin-top: 8px; min-width: 200px; }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}
.avatar:hover { opacity: 0.9; }

/* Role badges (production) */
.role-badge.role-super-admin { background: #dc2626; color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.role-admin { background: #7c3aed; color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.role-supervisor { background: #1d4ed8; color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.role-user { background: #6b7280; color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.role-employee { background: #6b7280; color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.user { background: #6b7280; color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.employee { background: #6b7280; color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.supervisor { background: #1d4ed8; color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.admin { background: #7c3aed; color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.status-active { color: var(--success); font-weight: 600; }
.status-inactive { color: var(--text-muted); }
.btn-sm.btn-edit-user { padding: 6px 10px; background: rgba(26,115,232,0.1); color: var(--primary); border: 1px solid rgba(26,115,232,0.3); border-radius: 8px; cursor: pointer; }
.btn-sm.btn-edit-user:hover { background: rgba(26,115,232,0.2); }

.page-body { padding: 28px 32px; flex: 1; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-3px); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}
.stat-card.purple::before { background: linear-gradient(90deg, #8B5CF6, #6D28D9); }
.stat-card.blue::before { background: linear-gradient(90deg, #1A73E8, #0d5bb8); }
.stat-card.green::before { background: linear-gradient(90deg, #27AE60, #1e8449); }
.stat-card.orange::before { background: linear-gradient(90deg, #F39C12, #d68910); }
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 14px;
}
.stat-card.purple .stat-icon { background: rgba(139,92,246,0.1); color: #8B5CF6; }
.stat-card.blue .stat-icon { background: rgba(26,115,232,0.1); color: #1A73E8; }
.stat-card.green .stat-icon { background: rgba(39,174,96,0.1); color: #27AE60; }
.stat-card.orange .stat-icon { background: rgba(243,156,18,0.1); color: #F39C12; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-dark); margin-bottom: 4px; }
.stat-label { font-size: 14px; color: var(--text-light); }

/* Card */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}
.card-header {
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 16px; font-weight: 700; color: var(--text-dark); }
.card-body { padding: 20px 22px; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: right;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-card-light);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-card-light); }

/* Buttons */
.btn-sm {
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: rgba(231,76,60,0.1); color: var(--danger); }
.btn-danger:hover { background: rgba(231,76,60,0.2); }
.btn-edit { background: rgba(243,156,18,0.1); color: var(--warning); }
.btn-edit:hover { background: rgba(243,156,18,0.2); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  padding: 14px 20px;
  border-radius: 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 9999;
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.ok { background: var(--success); }
.toast.err { background: var(--danger); }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Dashboard quick actions (single layout authority) */
.dashboard-quick-actions {
  display: none;
  margin-top: var(--space-6);
  padding: var(--space-5);
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.dashboard-quick-actions h3 {
  margin-bottom: var(--space-4);
  font-size: 16px;
  color: var(--text-dark);
}
.dashboard-quick-actions .quick-actions-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Section panels (admin dashboard in-page tabs) */
.section-panel { display: none; }
.section-panel.active { display: block; }
.section-tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}
.section-tabs button {
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-light);
}
.section-tabs button:hover { background: var(--bg-card-light); }
.section-tabs button.active {
  background: rgba(26,115,232,0.1);
  color: var(--primary);
  border-color: var(--primary);
}

/* Admin dashboard: overview grid, notifications, users table */
.overview-quick-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-top: var(--space-5);
}
.overview-quick-stats .stat-card { margin-bottom: 0; }
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); margin-top: var(--space-5); }
.charts-row .card { padding: var(--space-4); }
.chart-container { position: relative; height: 260px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); margin-bottom: var(--space-6); }
.full-col { margin-bottom: var(--space-6); }

.notif-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-light);
  position: relative;
}
.notif-btn:hover { border-color: var(--admin-color); color: var(--admin-color); }
.notif-dot { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; background: var(--danger); border-radius: 50%; display: none; }
.notif-dot.has-unread { display: block; }
.notif-badge { position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; padding: 0 5px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.notif-dropdown {
  position: absolute; top: 100%; right: 0; margin-top: 8px; width: 360px; max-height: 400px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  z-index: 1100; display: none; flex-direction: column;
}
.notif-dropdown.show { display: flex; }
.notif-dropdown-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.notif-dropdown-body { overflow-y: auto; flex: 1; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; cursor: pointer; }
.notif-item:hover { background: var(--bg-card-light); }
.notif-item.unread { background: rgba(139,92,246,0.06); }
.notif-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 14px; }

.users-table { width: 100%; border-collapse: collapse; }
.users-table th { text-align: right; padding: 12px 16px; font-size: 13px; font-weight: 600; color: var(--text-muted); background: var(--bg-card-light); border-bottom: 1px solid var(--border); }
.users-table td { padding: 14px 16px; font-size: 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: var(--bg-card-light); }
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar-sm { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; color: #fff; }

.role-tag { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.role-tag.admin { background: rgba(139,92,246,0.1); color: #8B5CF6; }
.role-tag.supervisor { background: rgba(26,115,232,0.1); color: #1A73E8; }
.role-tag.user { background: rgba(39,174,96,0.1); color: #27AE60; }

.status-badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.status-badge.active { background: rgba(39,174,96,0.1); color: #27AE60; }
.status-badge.inactive { background: rgba(231,76,60,0.1); color: #E74C3C; }
.btn-purple { background: rgba(139,92,246,0.1); color: var(--admin-color); }
.btn-purple:hover { background: rgba(139,92,246,0.2); }

.search-input { padding: 8px 14px; border: 1px solid var(--border); border-radius: 10px; font-family: var(--font-main); font-size: 14px; outline: none; width: 220px; }
.search-input:focus { border-color: var(--admin-color); }

.role-select { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--border); font-family: var(--font-main); font-size: 13px; background: #fff; cursor: pointer; }
.role-select:focus { border-color: var(--admin-color); }

.activity-list { display: flex; flex-direction: column; gap: 14px; }
.activity-item { display: flex; align-items: flex-start; gap: 12px; }
.activity-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.activity-text { flex: 1; }
.activity-text strong { font-size: 14px; font-weight: 600; }
.activity-text p { font-size: 13px; color: var(--text-light); margin-top: 2px; }
.activity-time { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.sys-stats { display: flex; flex-direction: column; gap: 16px; }
.sys-stat-item { display: flex; flex-direction: column; gap: 6px; }
.sys-stat-label { display: flex; justify-content: space-between; font-size: 14px; }
.sys-stat-label span:last-child { font-weight: 700; }
.progress-bar { height: 8px; background: var(--bg-card-light); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 1s ease; }

.loading-row td { text-align: center; padding: 40px; color: var(--text-muted); }

.stat-change { font-size: 12px; margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

.card-header .card-title { font-size: 16px; font-weight: 700; color: var(--text-dark); }

@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .overview-quick-stats { grid-template-columns: 1fr; }
  .charts-row { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .app-sidebar { display: none; }
  .main-content { margin-right: 0; }
  .stats-grid { grid-template-columns: 1fr; }
}
