/* =====================================================
   ThemeV2 — Design System Core
   ErpSystem | Arabic RTL | Bootstrap 4 compatible
   ===================================================== */

/* ─────────────────────────────────────────
   1. CSS Custom Properties (Design Tokens)
───────────────────────────────────────────*/
:root {
  --radius: 8px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --border: #e2e8f0;
  --bg: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;

  /* Primary — Deep Blue */
  --v2-primary:        #1d4ed8;
  --v2-primary-dark:   #1e3a8a;
  --v2-primary-light:  #dbeafe;
  --v2-primary-hover:  #1e40af;

  /* Secondary — Teal */
  --v2-secondary:      #0d9488;
  --v2-secondary-dark: #0f766e;
  --v2-secondary-light:#ccfbf1;

  /* Accent — Amber */
  --v2-accent:         #f59e0b;
  --v2-accent-light:   #fef3c7;

  /* State Colors */
  --v2-success:        #16a34a;
  --v2-success-light:  #dcfce7;
  --v2-warning:        #d97706;
  --v2-warning-light:  #fef9c3;
  --v2-danger:         #dc2626;
  --v2-danger-light:   #fee2e2;
  --v2-info:           #0284c7;
  --v2-info-light:     #e0f2fe;

  /* Neutrals */
  --v2-white:          #ffffff;
  --v2-gray-50:        #f8fafc;
  --v2-gray-100:       #f1f5f9;
  --v2-gray-200:       #e2e8f0;
  --v2-gray-300:       #cbd5e1;
  --v2-gray-400:       #94a3b8;
  --v2-gray-500:       #64748b;
  --v2-gray-600:       #475569;
  --v2-gray-700:       #334155;
  --v2-gray-800:       #1e293b;
  --v2-gray-900:       #0f172a;

  /* Sidebar */
  --v2-sidebar-bg:     #0f172a;
  --v2-sidebar-width:  260px;
  --v2-sidebar-collapsed-width: 68px;
  --v2-sidebar-text:   #94a3b8;
  --v2-sidebar-text-active: #ffffff;
  --v2-sidebar-item-hover: rgba(255,255,255,0.07);
  --v2-sidebar-item-active: rgba(29,78,216,0.35);
  --v2-sidebar-border: rgba(255,255,255,0.06);

  /* Topbar */
  --v2-topbar-bg:      #ffffff;
  --v2-topbar-height:  60px;
  --v2-topbar-border:  #e2e8f0;
  --v2-topbar-shadow:  0 1px 4px rgba(0,0,0,0.08);

  /* Page / Content */
  --v2-page-bg:        #f1f5f9;
  --v2-content-bg:     #f1f5f9;

  /* Typography */
  --v2-font-family:    'Cairo', 'Tajawal', 'Segoe UI', sans-serif;
  --v2-font-size-xs:   0.72rem;
  --v2-font-size-sm:   0.82rem;
  --v2-font-size-base: 0.92rem;
  --v2-font-size-md:   1rem;
  --v2-font-size-lg:   1.12rem;
  --v2-font-size-xl:   1.28rem;
  --v2-font-size-2xl:  1.5rem;
  --v2-font-size-3xl:  1.85rem;
  --v2-font-weight-normal: 400;
  --v2-font-weight-medium: 500;
  --v2-font-weight-semibold: 600;
  --v2-font-weight-bold: 700;
  --v2-line-height:    1.6;

  /* Spacing Scale */
  --v2-space-1:  0.25rem;
  --v2-space-2:  0.5rem;
  --v2-space-3:  0.75rem;
  --v2-space-4:  1rem;
  --v2-space-5:  1.25rem;
  --v2-space-6:  1.5rem;
  --v2-space-8:  2rem;
  --v2-space-10: 2.5rem;
  --v2-space-12: 3rem;

  /* Border Radius */
  --v2-radius-sm:  4px;
  --v2-radius-md:  8px;
  --v2-radius-lg:  12px;
  --v2-radius-xl:  16px;
  --v2-radius-2xl: 20px;
  --v2-radius-full: 9999px;

  /* Shadows */
  --v2-shadow-xs:  0 1px 2px rgba(0,0,0,0.05);
  --v2-shadow-sm:  0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);
  --v2-shadow-md:  0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --v2-shadow-lg:  0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.05);
  --v2-shadow-xl:  0 20px 25px rgba(0,0,0,0.10), 0 8px 10px rgba(0,0,0,0.04);
  --v2-shadow-inner: inset 0 2px 4px rgba(0,0,0,0.06);

  /* Transitions */
  --v2-transition-fast:   150ms ease;
  --v2-transition-base:   250ms ease;
  --v2-transition-slow:   350ms ease;

  /* Z-index scale */
  --v2-z-sidebar:  1000;
  --v2-z-topbar:   1010;
  --v2-z-overlay:  1020;
  --v2-z-modal:    1050;
  --v2-z-toast:    1100;
}

/* ─────────────────────────────────────────
   2. Global Reset & Base Styles
───────────────────────────────────────────*/
.v2-app * {
  box-sizing: border-box;
}

.v2-app {
  font-family: var(--v2-font-family);
  font-size: var(--v2-font-size-base);
  color: var(--v2-gray-800);
  background: var(--v2-page-bg);
  direction: rtl;
  text-align: right;
  min-height: 100vh;
}

/* ─────────────────────────────────────────
   3. Layout Skeleton
───────────────────────────────────────────*/

/* Outer shell */
.v2-shell {
  /*display: flex;*/
  min-height: 100vh;
  direction: rtl;
}

/* Sidebar */
.v2-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--v2-sidebar-width);
  background: var(--v2-sidebar-bg);
  z-index: var(--v2-z-sidebar);
  display: flex;
  flex-direction: column;
  transition: width var(--v2-transition-base), transform var(--v2-transition-base);
  overflow: hidden;
  box-shadow: -2px 0 12px rgba(0,0,0,0.25);
}

.v2-sidebar.collapsed {
  width: var(--v2-sidebar-collapsed-width);
}

/* Sidebar brand/logo area */
.v2-sidebar-brand {
  height: var(--v2-topbar-height);
  display: flex;
  align-items: center;
  padding: 0 var(--v2-space-4);
  border-bottom: 1px solid var(--v2-sidebar-border);
  gap: var(--v2-space-3);
  flex-shrink: 0;
}

.v2-sidebar-brand img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: var(--v2-radius-md);
}

.v2-sidebar-brand-text {
  color: var(--v2-white);
  font-size: var(--v2-font-size-md);
  font-weight: var(--v2-font-weight-bold);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--v2-transition-base);
}

.v2-sidebar.collapsed .v2-sidebar-brand-text {
  opacity: 0;
  width: 0;
}

/* Sidebar scroll area */
.v2-sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--v2-space-3) 0;
}

.v2-sidebar-scroll::-webkit-scrollbar {
  width: 3px;
}
.v2-sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.v2-sidebar-scroll::-webkit-scrollbar-thumb { background: var(--v2-gray-700); border-radius: 2px; }

/* Sidebar section label */
.v2-sidebar-label {
  font-size: var(--v2-font-size-xs);
  font-weight: var(--v2-font-weight-semibold);
  color: var(--v2-gray-500);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--v2-space-4) var(--v2-space-5) var(--v2-space-2);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--v2-transition-base);
}

.v2-sidebar.collapsed .v2-sidebar-label {
  opacity: 0;
}

/* Sidebar nav item */
.v2-nav-item {
  display: block;
  margin: 1px var(--v2-space-2);
  border-radius: var(--v2-radius-md);
  transition: background var(--v2-transition-fast);
}

.v2-nav-link {
  display: flex;
  align-items: center;
  gap: var(--v2-space-3);
  padding: var(--v2-space-3) var(--v2-space-4);
  color: var(--v2-sidebar-text);
  text-decoration: none;
  white-space: nowrap;
  border-radius: var(--v2-radius-md);
  transition: color var(--v2-transition-fast), background var(--v2-transition-fast);
  font-size: var(--v2-font-size-sm);
  font-weight: var(--v2-font-weight-medium);
  cursor: pointer;
}

.v2-nav-link:hover {
  background: var(--v2-sidebar-item-hover);
  color: var(--v2-white);
  text-decoration: none;
}

.v2-nav-link.active,
.v2-nav-link.v2-active {
  background: var(--v2-sidebar-item-active);
  color: var(--v2-sidebar-text-active);
}

.v2-nav-icon {
  font-size: 1.05rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  color: inherit;
}

.v2-nav-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--v2-transition-base), width var(--v2-transition-base);
}

.v2-sidebar.collapsed .v2-nav-text,
.v2-sidebar.collapsed .v2-nav-arrow {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* Sidebar submenu arrow */
.v2-nav-arrow {
  font-size: var(--v2-font-size-xs);
  transition: transform var(--v2-transition-fast), opacity var(--v2-transition-base);
  color: var(--v2-gray-500);
}

.v2-nav-item.open > .v2-nav-link .v2-nav-arrow {
  transform: rotate(90deg);
}

/* Sidebar submenu */
.v2-submenu {
  list-style: none;
  padding: var(--v2-space-1) 0 var(--v2-space-2);
  margin: 0;
  overflow: hidden;
  max-height: 0;
  transition: max-height var(--v2-transition-slow);
}

.v2-nav-item.open > .v2-submenu {
  max-height: 600px;
}

.v2-submenu .v2-nav-link {
  padding-right: calc(var(--v2-space-4) + 20px + var(--v2-space-3));
  padding-top: var(--v2-space-2);
  padding-bottom: var(--v2-space-2);
  font-size: var(--v2-font-size-xs);
  border-radius: var(--v2-radius-sm);
  margin: 1px var(--v2-space-1);
}

/* Sidebar divider */
.v2-sidebar-divider {
  height: 1px;
  background: var(--v2-sidebar-border);
  margin: var(--v2-space-3) var(--v2-space-4);
}

/* Sidebar footer */
.v2-sidebar-footer {
  padding: var(--v2-space-4);
  border-top: 1px solid var(--v2-sidebar-border);
  flex-shrink: 0;
}

/* ─────────────────────────────────────────
   4. Topbar
───────────────────────────────────────────*/
.v2-topbar {
  position: fixed;
  top: 0;
  right: var(--v2-sidebar-width);
  left: 0;
  height: var(--v2-topbar-height);
  background: var(--v2-topbar-bg);
  border-bottom: 1px solid var(--v2-topbar-border);
  box-shadow: var(--v2-topbar-shadow);
  z-index: var(--v2-z-topbar);
  display: flex;
  align-items: center;
  padding: 0 var(--v2-space-6);
  gap: var(--v2-space-4);
  transition: right var(--v2-transition-base);
}

.v2-sidebar.collapsed ~ .v2-main-area .v2-topbar {
  right: var(--v2-sidebar-collapsed-width);
}

/* Sidebar toggle button in topbar */
.v2-topbar-toggle {
  background: none;
  border: none;
  color: var(--v2-gray-500);
  cursor: pointer;
  padding: var(--v2-space-2);
  border-radius: var(--v2-radius-md);
  transition: background var(--v2-transition-fast), color var(--v2-transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.v2-topbar-toggle:hover {
  background: var(--v2-gray-100);
  color: var(--v2-gray-800);
}

/* Breadcrumb in topbar */
.v2-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--v2-space-2);
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
}

.v2-breadcrumb-item {
  display: flex;
  align-items: center;
  font-size: var(--v2-font-size-sm);
  color: var(--v2-gray-500);
}

.v2-breadcrumb-item + .v2-breadcrumb-item::before {
  content: "/";
  margin-left: var(--v2-space-2);
  color: var(--v2-gray-300);
}

.v2-breadcrumb-item.active {
  color: var(--v2-gray-800);
  font-weight: var(--v2-font-weight-semibold);
}

/* Topbar actions (right side — becomes left in RTL) */
.v2-topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--v2-space-2);
  margin-right: auto;
}

/* Topbar user info */
.v2-topbar-user {
  display: flex;
  align-items: center;
  gap: var(--v2-space-3);
  padding: var(--v2-space-2) var(--v2-space-3);
  border-radius: var(--v2-radius-lg);
  cursor: pointer;
  transition: background var(--v2-transition-fast);
}

.v2-topbar-user:hover {
  background: var(--v2-gray-100);
}

.v2-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--v2-primary-light);
  color: var(--v2-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--v2-font-size-sm);
  font-weight: var(--v2-font-weight-bold);
  flex-shrink: 0;
}

.v2-user-name {
  font-size: var(--v2-font-size-sm);
  font-weight: var(--v2-font-weight-semibold);
  color: var(--v2-gray-700);
}

.v2-user-role {
  font-size: var(--v2-font-size-xs);
  color: var(--v2-gray-400);
}

/* Topbar icon button */
.v2-topbar-btn {
  position: relative;
  background: none;
  border: none;
  color: var(--v2-gray-500);
  cursor: pointer;
  padding: var(--v2-space-2);
  border-radius: var(--v2-radius-md);
  transition: background var(--v2-transition-fast), color var(--v2-transition-fast);
  font-size: 1rem;
  display: flex;
  align-items: center;
}

.v2-topbar-btn:hover {
  background: var(--v2-gray-100);
  color: var(--v2-primary);
}

.v2-topbar-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  min-width: 16px;
  height: 16px;
  background: var(--v2-danger);
  color: white;
  border-radius: var(--v2-radius-full);
  font-size: 10px;
  font-weight: var(--v2-font-weight-bold);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
}

/* ─────────────────────────────────────────
   5. Main Content Area
───────────────────────────────────────────*/
.v2-main-area {
  margin-right: var(--v2-sidebar-width);
  margin-top: var(--v2-topbar-height);
  min-height: calc(100vh - var(--v2-topbar-height));
  transition: margin-right var(--v2-transition-base);
  display: flex;
  flex-direction: column;
}

.v2-sidebar.collapsed ~ .v2-main-area {
  margin-right: var(--v2-sidebar-collapsed-width);
}

.v2-content {
  flex: 1;
  padding: var(--v2-space-6);
  background: var(--v2-content-bg);
}

/* ─────────────────────────────────────────
   6. Footer
───────────────────────────────────────────*/
.v2-footer {
  background: var(--v2-white);
  border-top: 1px solid var(--v2-gray-200);
  padding: var(--v2-space-4) var(--v2-space-6);
  font-size: var(--v2-font-size-xs);
  color: var(--v2-gray-400);
  text-align: center;
}

/* ─────────────────────────────────────────
   7. Typography
───────────────────────────────────────────*/
.v2-h1 { font-size: var(--v2-font-size-3xl); font-weight: var(--v2-font-weight-bold); color: var(--v2-gray-900); line-height: 1.2; }
.v2-h2 { font-size: var(--v2-font-size-2xl); font-weight: var(--v2-font-weight-bold); color: var(--v2-gray-800); }
.v2-h3 { font-size: var(--v2-font-size-xl);  font-weight: var(--v2-font-weight-semibold); color: var(--v2-gray-800); }
.v2-h4 { font-size: var(--v2-font-size-lg);  font-weight: var(--v2-font-weight-semibold); color: var(--v2-gray-700); }
.v2-h5 { font-size: var(--v2-font-size-md);  font-weight: var(--v2-font-weight-semibold); color: var(--v2-gray-700); }
.v2-h6 { font-size: var(--v2-font-size-sm);  font-weight: var(--v2-font-weight-semibold); color: var(--v2-gray-600); }

.v2-text-muted { color: var(--v2-gray-400); }
.v2-text-sm    { font-size: var(--v2-font-size-sm); }
.v2-text-xs    { font-size: var(--v2-font-size-xs); }

/* ─────────────────────────────────────────
   8. Loading / Preloader States
───────────────────────────────────────────*/
.v2-page-loader {
  position: fixed;
  inset: 0;
  background: var(--v2-gray-900);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--v2-space-4);
}

.v2-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--v2-gray-700);
  border-top-color: var(--v2-primary);
  border-radius: 50%;
  animation: v2-spin 0.7s linear infinite;
}

@keyframes v2-spin {
  to { transform: rotate(360deg); }
}

.v2-busy-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─────────────────────────────────────────
   9. Screen overlay (sidebar mobile)
───────────────────────────────────────────*/
.v2-screen-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: calc(var(--v2-z-sidebar) - 1);
}

@media (max-width: 991px) {
  .v2-screen-overlay.show { display: block; }

  .v2-sidebar {
    transform: translateX(100%);
    width: var(--v2-sidebar-width) !important;
  }
  .v2-sidebar.mobile-open {
    transform: translateX(0);
  }

  .v2-main-area {
    margin-right: 0 !important;
  }

  .v2-topbar {
    right: 0 !important;
  }
}

/* ─────────────────────────────────────────
   10. Utility classes
───────────────────────────────────────────*/
.v2-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v2-flex     { display: flex; }
.v2-flex-center { display: flex; align-items: center; justify-content: center; }
.v2-gap-2    { gap: var(--v2-space-2); }
.v2-gap-3    { gap: var(--v2-space-3); }
.v2-gap-4    { gap: var(--v2-space-4); }
