/**
 * Emarat Enterprise UI — Bootstrap 5.3 design system
 * Premium corporate dashboard theme (light / dark / RTL ready)
 */

:root {
  --ep-primary: #0F4C81;
  --ep-primary-hover: #0c3d66;
  --ep-primary-soft: rgba(15, 76, 129, 0.1);
  --ep-secondary: #2563EB;
  --ep-accent: #22C55E;
  --ep-danger: #DC2626;
  --ep-warning: #F59E0B;
  --ep-info: #0EA5E9;

  --ep-bg: #F8FAFC;
  --ep-surface: #FFFFFF;
  --ep-surface-elevated: #FFFFFF;
  --ep-border: #E2E8F0;
  --ep-border-light: #F1F5F9;
  --ep-text: #0F172A;
  --ep-text-muted: #64748B;
  --ep-text-soft: #94A3B8;

  --ep-sidebar-width: 280px;
  --ep-sidebar-collapsed: 76px;
  --ep-topbar-height: 64px;
  --ep-radius: 12px;
  --ep-radius-sm: 8px;
  --ep-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --ep-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  --ep-shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.1);
  --ep-transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --ep-font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --ep-bg: #0B1220;
  --ep-surface: #111827;
  --ep-surface-elevated: #1E293B;
  --ep-border: #334155;
  --ep-border-light: #1E293B;
  --ep-text: #F1F5F9;
  --ep-text-muted: #94A3B8;
  --ep-text-soft: #64748B;
  --ep-primary-soft: rgba(37, 99, 235, 0.15);
  --ep-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

/* ─── Base ─── */
html { scroll-behavior: smooth; }

body.enterprise-body {
  font-family: var(--ep-font);
  background: var(--ep-bg);
  color: var(--ep-text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; transition: color var(--ep-transition); }

/* ─── App shell ─── */
.enterprise-app {
  display: flex;
  min-height: 100vh;
}

.enterprise-sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: var(--ep-sidebar-width);
  background: var(--ep-surface);
  border-inline-end: 1px solid var(--ep-border);
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: width var(--ep-transition), transform var(--ep-transition);
  overflow: hidden;
}

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

.enterprise-sidebar-brand {
  height: var(--ep-topbar-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--ep-border-light);
  flex-shrink: 0;
}

.enterprise-sidebar-brand img {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.enterprise-sidebar-brand span {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ep-primary);
  white-space: nowrap;
}

.enterprise-sidebar.is-collapsed .brand-text,
.enterprise-sidebar.is-collapsed .nav-label,
.enterprise-sidebar.is-collapsed .nav-heading,
.enterprise-sidebar.is-collapsed .nav-chevron,
.enterprise-sidebar.is-collapsed .nav-content {
  display: none !important;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px 24px;
}

.sidebar-scroll::-webkit-scrollbar { width: 5px; }
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--ep-border);
  border-radius: 99px;
}

/* Sidebar navigation */
.enterprise-nav { list-style: none; margin: 0; padding: 0; }

.enterprise-nav .nav-heading {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ep-text-soft);
  padding: 16px 12px 6px;
  margin: 0;
}

.enterprise-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--ep-radius-sm);
  color: var(--ep-text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  background: transparent;
  width: 100%;
  text-align: start;
  transition: all var(--ep-transition);
}

.enterprise-nav .nav-link i.nav-icon {
  font-size: 1.15rem;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  color: var(--ep-text-soft);
}

.enterprise-nav .nav-link:hover {
  background: var(--ep-primary-soft);
  color: var(--ep-primary);
}

.enterprise-nav .nav-link:hover i { color: var(--ep-primary); }

.enterprise-nav .nav-link.active,
.enterprise-nav .nav-content a.active {
  background: var(--ep-primary-soft);
  color: var(--ep-primary);
  font-weight: 600;
}

.enterprise-nav .nav-link.active i,
.enterprise-nav .nav-content a.active i { color: var(--ep-primary); }

.enterprise-nav .nav-chevron {
  margin-inline-start: auto;
  font-size: 0.75rem;
  transition: transform var(--ep-transition);
}

.enterprise-nav .nav-link[aria-expanded="true"] .nav-chevron {
  transform: rotate(180deg);
}

.enterprise-nav .nav-content {
  list-style: none;
  margin: 4px 0 8px;
  padding: 0 0 0 34px;
}

.enterprise-nav .nav-content a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 0.8125rem;
  color: var(--ep-text-muted);
  border-radius: var(--ep-radius-sm);
}

.enterprise-nav .nav-content a:hover { color: var(--ep-primary); background: var(--ep-primary-soft); }
.enterprise-nav .nav-content a i { font-size: 0.35rem; }

/* Main column */
.enterprise-main {
  flex: 1;
  margin-inline-start: var(--ep-sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-inline-start var(--ep-transition);
}

.enterprise-sidebar.is-collapsed ~ .enterprise-main,
body.sidebar-collapsed .enterprise-main {
  margin-inline-start: var(--ep-sidebar-collapsed);
}

/* Topbar */
.enterprise-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  height: var(--ep-topbar-height);
  background: var(--ep-surface);
  border-bottom: 1px solid var(--ep-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  box-shadow: var(--ep-shadow-sm);
}

.topbar-toggle {
  border: none;
  background: var(--ep-bg);
  color: var(--ep-text);
  width: 40px;
  height: 40px;
  border-radius: var(--ep-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--ep-transition);
}

.topbar-toggle:hover { background: var(--ep-primary-soft); color: var(--ep-primary); }

.topbar-search {
  flex: 1;
  max-width: 420px;
  position: relative;
}

.topbar-search-wrap {
  flex: 1;
  max-width: 420px;
  position: relative;
  min-width: 0;
}

.topbar-search-wrap .topbar-search {
  max-width: none;
}

.topbar-search input {
  width: 100%;
  border: 1px solid var(--ep-border);
  background: var(--ep-bg);
  border-radius: 99px;
  padding: 8px 16px 8px 40px;
  font-size: 0.875rem;
  color: var(--ep-text);
}

.topbar-search input:focus {
  outline: none;
  border-color: var(--ep-secondary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.topbar-search i {
  position: absolute;
  inset-inline-start: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ep-text-soft);
}

/* Global nav search results */
.nav-search-results {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline: 0;
  background: var(--ep-surface);
  border: 1px solid var(--ep-border);
  border-radius: var(--ep-radius);
  box-shadow: var(--ep-shadow-lg);
  max-height: 360px;
  overflow-y: auto;
  z-index: 1100;
  padding: 6px;
}

.nav-search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--ep-radius-sm);
  text-decoration: none;
  color: var(--ep-text);
  transition: background 0.12s;
}

.nav-search-item:hover,
.nav-search-item.active {
  background: var(--ep-primary-soft);
  color: var(--ep-primary);
}

.nav-search-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--ep-bg-subtle, #f1f5f9);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--ep-primary);
}

.nav-search-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-search-item-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.nav-search-item-title mark {
  background: rgba(37, 99, 235, 0.2);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

.nav-search-item-meta {
  font-size: 11px;
  color: var(--ep-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.nav-search-item-go {
  color: var(--ep-text-soft);
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.12s;
}

.nav-search-item:hover .nav-search-item-go,
.nav-search-item.active .nav-search-item-go {
  opacity: 1;
}

.nav-search-empty {
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--ep-text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-inline-start: auto;
}

.topbar-btn {
  position: relative;
  border: none;
  background: transparent;
  color: var(--ep-text-muted);
  width: 40px;
  height: 40px;
  border-radius: var(--ep-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--ep-transition);
}

.topbar-btn:hover {
  background: var(--ep-primary-soft);
  color: var(--ep-primary);
}

.topbar-btn .badge-dot {
  position: absolute;
  top: 8px;
  inset-inline-end: 8px;
  width: 8px;
  height: 8px;
  background: var(--ep-danger);
  border-radius: 50%;
  border: 2px solid var(--ep-surface);
}

.topbar-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 4px;
  border-radius: 99px;
  border: 1px solid var(--ep-border);
  background: var(--ep-bg);
  cursor: pointer;
  margin-inline-start: 8px;
}

.topbar-profile img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.topbar-profile .name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ep-text);
  line-height: 1.2;
}

.topbar-profile .role {
  font-size: 0.6875rem;
  color: var(--ep-text-muted);
}

/* Content */
.enterprise-content {
  flex: 1;
  padding: 24px;
}

.enterprise-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--ep-border);
  font-size: 0.8125rem;
  color: var(--ep-text-muted);
  background: var(--ep-surface);
}

/* Page header */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ep-text);
  margin: 0 0 4px;
}

.page-header .subtitle {
  color: var(--ep-text-muted);
  font-size: 0.875rem;
  margin: 0;
}

.breadcrumb-enterprise {
  --bs-breadcrumb-divider: "›";
  font-size: 0.8125rem;
  margin-bottom: 8px;
}

.breadcrumb-enterprise .breadcrumb-item a { color: var(--ep-text-muted); }
.breadcrumb-enterprise .breadcrumb-item.active { color: var(--ep-text); }

/* Cards & KPI widgets */
.ep-card {
  background: var(--ep-surface);
  border: 1px solid var(--ep-border);
  border-radius: var(--ep-radius);
  box-shadow: var(--ep-shadow-sm);
  transition: box-shadow var(--ep-transition), transform var(--ep-transition);
}

.ep-card:hover { box-shadow: var(--ep-shadow); }

.ep-card-body { padding: 20px; }

.kpi-card {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--ep-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.kpi-icon.primary { background: rgba(15, 76, 129, 0.12); color: var(--ep-primary); }
.kpi-icon.secondary { background: rgba(37, 99, 235, 0.12); color: var(--ep-secondary); }
.kpi-icon.accent { background: rgba(34, 197, 94, 0.12); color: var(--ep-accent); }
.kpi-icon.warning { background: rgba(245, 158, 11, 0.12); color: var(--ep-warning); }
.kpi-icon.danger { background: rgba(220, 38, 38, 0.12); color: var(--ep-danger); }

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--ep-text);
}

.kpi-label {
  font-size: 0.8125rem;
  color: var(--ep-text-muted);
  margin-bottom: 4px;
}

.kpi-trend {
  font-size: 0.75rem;
  font-weight: 600;
}

.kpi-trend.up { color: var(--ep-accent); }
.kpi-trend.down { color: var(--ep-danger); }

/* Filter bar */
.filter-bar {
  background: var(--ep-surface);
  border: 1px solid var(--ep-border);
  border-radius: var(--ep-radius);
  padding: 16px;
  margin-bottom: 20px;
}

/* Tables */
.ep-table-wrap {
  background: var(--ep-surface);
  border: 1px solid var(--ep-border);
  border-radius: var(--ep-radius);
  overflow: hidden;
}

.ep-table {
  margin: 0;
  font-size: 0.875rem;
}

.ep-table thead th {
  background: var(--ep-bg);
  color: var(--ep-text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--ep-border);
  padding: 12px 16px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.ep-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--ep-border-light);
  vertical-align: middle;
}

.ep-table tbody tr:hover { background: var(--ep-primary-soft); }
.ep-table tbody tr:last-child td { border-bottom: none; }

/* Badges */
.badge-ep {
  font-weight: 600;
  font-size: 0.6875rem;
  padding: 4px 10px;
  border-radius: 99px;
}

.badge-ep-success { background: rgba(34, 197, 94, 0.15); color: #15803d; }
.badge-ep-warning { background: rgba(245, 158, 11, 0.15); color: #b45309; }
.badge-ep-danger { background: rgba(220, 38, 38, 0.15); color: #b91c1c; }
.badge-ep-primary { background: var(--ep-primary-soft); color: var(--ep-primary); }

[data-theme="dark"] .badge-ep-success { color: #86efac; }
[data-theme="dark"] .badge-ep-warning { color: #fcd34d; }
[data-theme="dark"] .badge-ep-danger { color: #fca5a5; }

/* Forms */
.form-floating > .form-control,
.form-floating > .form-select {
  border-radius: var(--ep-radius-sm);
  border-color: var(--ep-border);
}

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

.btn-ep-primary {
  background: var(--ep-primary);
  border-color: var(--ep-primary);
  color: #fff;
  border-radius: var(--ep-radius-sm);
  font-weight: 600;
  padding: 8px 18px;
}

.btn-ep-primary:hover {
  background: var(--ep-primary-hover);
  border-color: var(--ep-primary-hover);
  color: #fff;
}

.btn-ep-secondary {
  background: var(--ep-secondary);
  border-color: var(--ep-secondary);
  color: #fff;
  border-radius: var(--ep-radius-sm);
  font-weight: 600;
}

/* Sub-nav (Employee mgmt etc.) */
.emp-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  padding: 12px;
  background: var(--ep-surface);
  border: 1px solid var(--ep-border);
  border-radius: var(--ep-radius);
}

.emp-subnav a {
  padding: 8px 14px;
  border-radius: var(--ep-radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ep-text-muted);
  border: 1px solid transparent;
}

.emp-subnav a:hover,
.emp-subnav a.active {
  color: var(--ep-primary);
  background: var(--ep-primary-soft);
  border-color: rgba(15, 76, 129, 0.15);
}

/* Legacy NiceAdmin compatibility inside enterprise shell */
.enterprise-content .card {
  border-radius: var(--ep-radius);
  border-color: var(--ep-border);
  box-shadow: var(--ep-shadow-sm);
}

.enterprise-content .table-emp th {
  background: var(--ep-primary) !important;
}

.enterprise-content .filter-card,
.enterprise-content .kpi-card {
  background: var(--ep-surface);
  border: 1px solid var(--ep-border);
  border-radius: var(--ep-radius);
}

/* Auth layout */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--ep-primary) 0%, #1e3a5f 50%, var(--ep-secondary) 100%);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--ep-surface);
  border-radius: var(--ep-radius);
  box-shadow: var(--ep-shadow-lg);
  padding: 40px 36px;
}

/* Empty / error states */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--ep-text-muted);
}

.empty-state i { font-size: 3rem; opacity: 0.4; margin-bottom: 16px; }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--ep-border-light) 25%, var(--ep-border) 50%, var(--ep-border-light) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.2s ease-in-out infinite;
  border-radius: var(--ep-radius-sm);
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Sidebar overlay (mobile) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1035;
}

/* Responsive */
@media (max-width: 1199px) {
  .enterprise-sidebar {
    transform: translateX(calc(-1 * var(--ep-sidebar-width)));
  }

  [dir="rtl"] .enterprise-sidebar {
    transform: translateX(var(--ep-sidebar-width));
  }

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

  .enterprise-main {
    margin-inline-start: 0 !important;
  }

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

  .topbar-search-wrap { display: none; }
  .topbar-search { display: none; }
  .topbar-profile .profile-text { display: none; }
}

/* RTL */
[dir="rtl"] .enterprise-nav .nav-content { padding: 0 34px 0 0; }
[dir="rtl"] .enterprise-nav .nav-chevron { transform: scaleX(-1); }
[dir="rtl"] .enterprise-nav .nav-link[aria-expanded="true"] .nav-chevron {
  transform: scaleX(-1) rotate(180deg);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible (a11y) */
:focus-visible {
  outline: 2px solid var(--ep-secondary);
  outline-offset: 2px;
}

/* Form patterns */
.ep-pills .nav-link {
  border-radius: 999px;
  color: var(--ep-text-muted);
  font-size: 13px;
  padding: 6px 14px;
}

.ep-pills .nav-link.active {
  background: var(--ep-primary);
  color: #fff;
}

.ep-check-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--ep-border);
  border-radius: var(--ep-radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin: 0;
}

.ep-check-card input { accent-color: var(--ep-primary); }

.ep-check-card:has(input:checked) {
  border-color: var(--ep-primary);
  background: var(--ep-primary-soft);
}

.ep-check-card span {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.ep-stepper {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.ep-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ep-text-muted);
}

.ep-step span {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ep-border-light);
  font-weight: 600;
  font-size: 12px;
}

.ep-step.active {
  color: var(--ep-primary);
  font-weight: 600;
}

.ep-step.active span {
  background: var(--ep-primary);
  color: #fff;
}

.ep-progress {
  height: 6px;
  background: var(--ep-border-light);
  border-radius: 999px;
}

.ep-progress .progress-bar {
  background: var(--ep-primary);
  border-radius: 999px;
}

.kpi-trend.down { color: var(--ep-danger); }

.chart-placeholder { font-size: 13px; }
