:root {
  --primary: #1E3A5F;
  --primary-dark: #132A44;
  --secondary: #2878B5;
  --accent: #D5A94E;
  --background: #F4F7FA;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text-primary: #1E293B;
  --text-secondary: #64748B;
  --success: #198754;
  --warning: #E69A2A;
  --danger: #DC3545;
  --sidebar-width: 280px;
  --sidebar-collapsed: 78px;
  --topbar-height: 64px;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(30, 58, 95, 0.08);
  --shadow-sm: 0 2px 8px rgba(30, 58, 95, 0.06);
  --transition: 0.25s ease;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Cairo', sans-serif;
  background: var(--background);
  color: var(--text-primary);
  margin: 0;
  min-height: 100vh;
  font-size: 0.95rem;
  line-height: 1.6;
}

a { color: var(--secondary); text-decoration: none; }
a:hover { color: var(--primary); }

.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: width var(--transition), transform var(--transition);
  box-shadow: -4px 0 24px rgba(19, 42, 68, 0.25);
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  min-height: var(--topbar-height);
}

.sidebar-brand img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  padding: 2px;
}

.sidebar-brand .brand-text {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-brand .brand-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
}

.sidebar-brand .brand-sub {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.65);
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .sidebar-footer-text { display: none; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.nav-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.45);
  padding: 0.75rem 0.85rem 0.35rem;
  font-weight: 600;
}

.sidebar.collapsed .nav-section-title { text-align: center; font-size: 0; padding: 0.5rem; }
.sidebar.collapsed .nav-section-title::after { content: '•'; font-size: 0.8rem; color: rgba(255,255,255,0.3); }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.7rem 0.85rem;
  color: rgba(255,255,255,0.82);
  border-radius: 10px;
  margin-bottom: 2px;
  transition: var(--transition);
  font-weight: 500;
}

.sidebar-link i { font-size: 1.15rem; width: 22px; text-align: center; flex-shrink: 0; }
.sidebar-link:hover { background: rgba(255,255,255,0.1); color: #fff; }
.sidebar-link.active {
  background: linear-gradient(90deg, var(--secondary), rgba(40,120,181,0.7));
  color: #fff;
  box-shadow: 0 4px 12px rgba(40,120,181,0.35);
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* Main */
.main-content {
  flex: 1;
  margin-right: var(--sidebar-width);
  transition: margin var(--transition);
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar.collapsed ~ .main-content,
body.sidebar-collapsed .main-content { margin-right: var(--sidebar-collapsed); }

body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed); }

.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 1020;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.topbar-right, .topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.btn-icon:hover { background: var(--background); color: var(--primary); border-color: var(--secondary); }

.global-search {
  position: relative;
  width: min(420px, 40vw);
}

.global-search input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 2.5rem 0.55rem 1rem;
  background: var(--background);
  font-family: inherit;
  transition: var(--transition);
}

.global-search input:focus {
  outline: none;
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(40,120,181,0.15);
  background: #fff;
}

.global-search .search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 1050;
}

.search-results.show { display: block; animation: fadeIn 0.2s ease; }

.search-group-title {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--background);
}

.search-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.search-item:hover { background: #f8fafc; }

.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 0.35rem 0.75rem 0.35rem 0.4rem;
  cursor: pointer;
  font-family: inherit;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.page-body { padding: 1.5rem; flex: 1; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 0;
  color: var(--primary-dark);
}

.breadcrumb {
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.breadcrumb li + li::before { content: '/'; margin-left: 0.35rem; color: #cbd5e1; }

/* Cards */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  height: 100%;
  transition: transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}

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

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent-line, var(--secondary));
}

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  margin-bottom: 0.75rem;
}

.stat-card .stat-value {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.2;
}

.stat-card .stat-label {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-top: 0.2rem;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
}

.panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.panel-header h2, .panel-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
}

.panel-body { padding: 1.25rem; }

/* Tables */
.table-modern {
  width: 100%;
  border-collapse: collapse;
}

.table-modern th {
  background: #f8fafc;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-modern td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table-modern tr:hover td { background: #f8fafc; }

.table-responsive-modern {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Badges */
.badge-status {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-status-new { background: #dbeafe; color: #1d4ed8; }
.badge-status-progress { background: #ffedd5; color: #c2410c; }
.badge-status-paused { background: #e2e8f0; color: #475569; }
.badge-status-completed { background: #d1fae5; color: #047857; }
.badge-status-cancelled { background: #fee2e2; color: #b91c1c; }
.badge-status-archived { background: #1e293b; color: #e2e8f0; }

.badge-archived {
  background: #132A44;
  color: #fff;
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-weight: 700;
}

/* Progress */
.progress-modern {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-modern .bar {
  height: 100%;
  background: linear-gradient(90deg, var(--secondary), var(--accent));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
}

.progress-wrap span { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }

/* Buttons */
.btn-primary-custom {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border: none;
  color: #fff;
  border-radius: 10px;
  padding: 0.55rem 1.15rem;
  font-weight: 600;
  font-family: inherit;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary-custom:hover { filter: brightness(1.08); color: #fff; transform: translateY(-1px); }

.btn-accent {
  background: var(--accent);
  border: none;
  color: #132A44;
  border-radius: 10px;
  padding: 0.55rem 1.15rem;
  font-weight: 700;
  font-family: inherit;
}

.btn-outline-custom {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 0.5rem 1rem;
  font-family: inherit;
  font-weight: 600;
}

.btn-outline-custom:hover { border-color: var(--secondary); color: var(--secondary); }

.btn-sm-action {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.btn-sm-action:hover { color: var(--secondary); border-color: var(--secondary); }

/* Forms */
.form-label {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.form-control, .form-select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  font-family: inherit;
  background: #fff;
}

.form-control:focus, .form-select:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(40,120,181,0.15);
}

.required::after { content: ' *'; color: var(--danger); }

.invalid-feedback { display: block; color: var(--danger); font-size: 0.82rem; }

/* Alerts / Toast */
.alert-custom {
  border: none;
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.alert-success-custom { background: #d1fae5; color: #065f46; }
.alert-danger-custom { background: #fee2e2; color: #991b1b; }
.alert-warning-custom { background: #fef3c7; color: #92400e; }
.alert-info-custom { background: #dbeafe; color: #1e40af; }

.toast-container-custom {
  position: fixed;
  top: 80px;
  left: 20px;
  z-index: 1090;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-secondary);
}

.empty-state i { font-size: 3rem; color: #cbd5e1; margin-bottom: 1rem; display: block; }
.empty-state h3 { color: var(--text-primary); font-size: 1.1rem; }

/* Project header */
.project-hero {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 55%, var(--secondary) 100%);
  border-radius: var(--radius);
  color: #fff;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  position: relative;
  overflow: hidden;
}

.project-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0%, transparent 49%, rgba(213,169,78,0.08) 50%, transparent 51%),
    linear-gradient(0deg, transparent 0%, transparent 49%, rgba(255,255,255,0.04) 50%, transparent 51%);
  background-size: 28px 28px;
  pointer-events: none;
}

.project-hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  position: relative;
  z-index: 1;
}

.project-hero .meta-label { font-size: 0.78rem; opacity: 0.75; }
.project-hero .meta-value { font-weight: 700; font-size: 1rem; }

.nav-tabs-custom {
  border-bottom: 1px solid var(--border);
  gap: 0.25rem;
  flex-wrap: wrap;
}

.nav-tabs-custom .nav-link {
  border: none;
  color: var(--text-secondary);
  font-weight: 600;
  border-radius: 10px 10px 0 0;
  padding: 0.75rem 1rem;
}

.nav-tabs-custom .nav-link.active {
  color: var(--primary);
  background: transparent;
  border-bottom: 3px solid var(--accent);
}

/* Login */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(40,120,181,0.18), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(213,169,78,0.15), transparent 45%),
    linear-gradient(160deg, #132A44 0%, #1E3A5F 45%, #2878B5 100%);
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: slideUp 0.45s ease;
}

.auth-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-logo img { max-height: 64px; margin-bottom: 0.75rem; }
.auth-logo h1 { font-size: 1.25rem; color: var(--primary-dark); margin: 0; font-weight: 800; }
.auth-logo p { color: var(--text-secondary); margin: 0.35rem 0 0; font-size: 0.9rem; }

.password-wrap { position: relative; }
.password-wrap .toggle-pass {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
}

.notif-badge {
  position: absolute;
  top: -4px;
  left: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.dropdown-menu {
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.5rem;
}

.dropdown-item { border-radius: 8px; padding: 0.55rem 0.85rem; font-family: inherit; }
.dropdown-item:hover { background: var(--background); }

.skeleton {
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 8px;
  height: 16px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-overlay.show { display: flex; }

.spinner-custom {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border);
  border-top-color: var(--secondary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(19,42,68,0.45);
  z-index: 1035;
}

.sidebar-overlay.show { display: block; }

.action-dropdown .dropdown-toggle::after { display: none; }

.type-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 6px;
}

.permission-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.permission-group-header {
  background: #f8fafc;
  padding: 0.75rem 1rem;
  font-weight: 700;
  color: var(--primary);
}

.permission-group-body {
  padding: 0.75rem 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}

.mobile-card { display: none; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(100%);
    width: min(300px, 85vw);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content, body.sidebar-collapsed .main-content { margin-right: 0 !important; }
  .global-search { width: min(280px, 45vw); }
  .sidebar.collapsed { width: min(300px, 85vw); }
  .sidebar.collapsed .brand-text,
  .sidebar.collapsed .nav-text { display: flex; }
  .sidebar.collapsed .nav-text { display: inline; }
}

@media (max-width: 767.98px) {
  .page-body { padding: 1rem; }
  .global-search { display: none; }
  .global-search.mobile-show {
    display: block;
    position: absolute;
    top: var(--topbar-height);
    right: 0;
    left: 0;
    width: 100%;
    padding: 0.75rem;
    background: #fff;
    border-bottom: 1px solid var(--border);
    z-index: 1015;
  }
  .table-desktop { display: none; }
  .mobile-card { display: block; }
  .stat-card .stat-value { font-size: 1.3rem; }
  .project-hero { padding: 1.15rem; }
}

/* Icon Picker */
.icon-picker-selected {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-picker-preview {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}

.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
}

.icon-picker-item {
  width: 44px;
  height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #fff;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
}

.icon-picker-item:hover {
  border-color: var(--secondary);
  color: var(--secondary);
  transform: translateY(-1px);
}

.icon-picker-item.active {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 10px rgba(40, 120, 181, 0.3);
}

@media print {
  .sidebar, .topbar, .no-print, .btn, .sidebar-overlay { display: none !important; }
  .main-content { margin: 0 !important; }
  .page-body { padding: 0 !important; }
  body { background: #fff; }
}
