/* ============================================================
   IDHAM ERP — Premium Layout System 2026
   Floating Sidebar · Glass Topbar · RTL Arabic
   ============================================================ */

/* ══════════════════════════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════════════════════════ */
#app {
  display: flex;
  min-height: 100vh;
  width: 100vw;
  overflow-x: hidden;
  background: var(--bg-0);
  direction: rtl;
}

/* ══════════════════════════════════════════════════════════
   FLOATING SIDEBAR — Elevated, Glassy, Premium
   ══════════════════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 266px;
  height: calc(100vh - 24px);
  background: var(--surface-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition:
    width var(--transition-normal),
    transform var(--transition-slow);
  box-shadow:
    var(--shadow-xl),
    inset 0 1px 0 rgba(255,255,255,0.06);
  overflow: hidden;
}

body.theme-light .sidebar {
  background: #ffffff;
  border-color: var(--border);
  box-shadow: var(--shadow-lg);
}

/* Inner glow top edge */
.sidebar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(124,92,255,0.4), transparent);
  pointer-events: none;
}

body.theme-light .sidebar::before {
  background: linear-gradient(90deg, transparent, rgba(91,92,235,0.25), transparent);
}

.sidebar.collapsed {
  width: 76px;
}

/* ── Brand Header ───────────────────────────────────── */
.sidebar-brand {
  height: 68px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 13px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  overflow: hidden;
  background: rgba(124, 92, 255, 0.04);
}

body.theme-light .sidebar-brand {
  background: rgba(79, 70, 229, 0.04);
  border-bottom-color: var(--border);
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary) 0%, #5B5CEB 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 6px 16px var(--primary-glow);
  font-size: 20px;
  transition: all var(--transition-normal);
}

.brand-logo:hover {
  transform: scale(1.05) rotate(-3deg);
  box-shadow: 0 8px 24px var(--primary-glow);
}

.brand-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  transition: opacity var(--transition-fast);
  overflow: hidden;
}

.brand-name {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 15px;
  color: var(--text-0);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--primary);
  letter-spacing: 0.8px;
  opacity: 0.8;
  margin-top: 2px;
}

.sidebar-toggle {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  font-size: 12px;
}

.sidebar-toggle:hover {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
}

/* Collapsed state */
.sidebar.collapsed .brand-text {
  opacity: 0;
  width: 0;
  pointer-events: none;
}

.sidebar.collapsed .sidebar-brand {
  padding: 0 8px;
  justify-content: center;
  flex-direction: column;
  height: 90px;
  gap: 8px;
}

.sidebar.collapsed .brand-logo {
  display: flex !important;
  width: 36px;
  height: 36px;
  font-size: 16px;
  margin: 0 auto;
}

.sidebar.collapsed .sidebar-toggle {
  width: 32px;
  height: 32px;
  margin: 0 auto;
}

/* ── Navigation Scroll Area ─────────────────────────── */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-scroll::-webkit-scrollbar { width: 3px; }
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: rgba(124, 92, 255, 0.2);
  border-radius: 4px;
}
.sidebar-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* ── Nav Item ────────────────────────────────────────── */
.nav-item-single { margin-bottom: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  color: var(--text-2);
  text-decoration: none;
  font-family: var(--font-heading);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  position: relative;
  overflow: hidden;
}

/* Hover state: background blur effect */
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-0);
}

/* Active state: gradient + border-right */
.nav-item.active {
  background: var(--primary-dim);
  color: var(--primary);
  font-weight: 700;
  border-right: 4px solid var(--primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

/* Light mode sidebar: BLACK bold text for maximum readability */
body.theme-light .nav-item {
  color: #1a1a2e;
  font-weight: 700;
}
body.theme-light .nav-item:hover {
  background: rgba(79,70,229,.08);
  color: #0a0a1a;
}
body.theme-light .nav-item.active {
  background: var(--primary-dim);
  color: var(--primary);
  border-right-color: var(--primary);
  font-weight: 800;
}
body.theme-light .brand-name {
  color: #0a0e1a;
  font-weight: 800;
}
body.theme-light .brand-sub {
  color: var(--primary);
  opacity: 0.9;
  font-weight: 600;
}
body.theme-light .sidebar-toggle {
  background: var(--bg-2);
  border-color: var(--border);
  color: #1a1a2e;
}
body.theme-light .sidebar-toggle:hover {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
}
body.theme-light .nav-section-header {
  color: #3d3d5c;
  font-weight: 700;
}
body.theme-light .nav-section-header:hover {
  color: #0a0a1a;
  background: rgba(79,70,229,.06);
}
body.theme-light .nav-section-arrow {
  color: #3d3d5c;
}
body.theme-light .nav-label {
  color: #1a1a2e;
  font-weight: 700;
}
/* No glow filter needed on white background */
body.theme-light .nav-item .nav-icon { filter: none; }
body.theme-light .nav-item:hover .nav-icon,
body.theme-light .nav-item.active .nav-icon { filter: none; }

.nav-icon {
  font-size: 20px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
  filter: none;
}

/* No extra icon filter in light mode - icons are already visible on white */

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
  /* no scale animation for better performance */
}

/* Collapsed state */
.sidebar.collapsed .nav-label { display: none; }
.sidebar.collapsed .nav-item  {
  justify-content: center;
  padding: 13px 0;
  border-radius: var(--radius-md) !important;
  border-right: none !important;
}
.sidebar.collapsed .nav-icon {
  font-size: 22px;
  width: 28px;
}

/* ── Section Groups ──────────────────────────────────── */
.nav-section { margin-bottom: 2px; }

.nav-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  color: var(--text-dim);
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  margin-top: 8px;
}

.nav-section-header:hover {
  color: var(--text-0);
  background: rgba(255,255,255,0.03);
}

.nav-section-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-section-arrow {
  font-size: 10px;
  transition: transform var(--transition-fast);
  color: var(--text-dim);
}

.nav-section.collapsed .nav-section-arrow { transform: rotate(90deg); }

.nav-section-body {
  padding-right: 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 2px;
}

.nav-section.collapsed .nav-section-body { display: none; }

.sidebar.collapsed .nav-section-header .nav-section-label,
.sidebar.collapsed .nav-section-header .nav-section-arrow,
.sidebar.collapsed .nav-section-body { display: none; }

.sidebar.collapsed .nav-section-header .nav-section-icon {
  display: block !important;
  font-size: 24px;
  margin: 0;
}

.sidebar.collapsed .nav-section-header {
  justify-content: center;
  padding: 14px 0;
  margin: 4px 0;
  transition: all var(--transition-fast);
}

/* Collapsed sidebar hover popups */
.sidebar.collapsed .nav-section {
  position: relative;
}

.sidebar.collapsed .nav-section-body {
  display: none;
  position: absolute;
  right: 70px;
  top: 0;
  background: var(--surface-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px;
  min-width: 240px;
  box-shadow: var(--shadow-xl);
  z-index: 1000;
  flex-direction: column;
  gap: 3px;
}

body.theme-light .sidebar.collapsed .nav-section-body {
  background: #ffffff;
  border-color: var(--border);
  box-shadow: var(--shadow-lg);
}

.sidebar.collapsed .nav-section:hover .nav-section-body {
  display: flex !important;
}

.sidebar.collapsed .nav-section:hover .nav-section-body .nav-label {
  display: inline !important;
  font-size: 13px;
  color: var(--text-0);
}

body.theme-light .sidebar.collapsed .nav-section:hover .nav-section-body .nav-label {
  color: var(--text-0);
}

.sidebar.collapsed .nav-section:hover .nav-section-body .nav-item {
  justify-content: flex-start;
  padding: 10px 14px;
  white-space: nowrap;
  border-radius: var(--radius-md);
  border-right: none !important;
}

.sidebar.collapsed .nav-section:hover .nav-section-body .nav-item:hover {
  background: var(--bg-hover);
}

body.theme-light .sidebar.collapsed .nav-section:hover .nav-section-body .nav-item:hover {
  background: rgba(99, 102, 241, 0.08);
}

/* ── Sidebar Footer ──────────────────────────────────── */
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  background: rgba(0,0,0,0.15);
}

body.theme-light .sidebar-footer {
  background: var(--bg-2);
  border-top-color: var(--border);
}

.sidebar.collapsed .user-info,
.sidebar.collapsed .sidebar-footer .btn-ghost { display: none; }

.sidebar.collapsed .sidebar-footer {
  padding: 12px 0;
  justify-content: center;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.user-info { flex: 1; min-width: 0; }
.user-name  { font-family: var(--font-heading); font-size: 13px; font-weight: 700; color: var(--text-0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { font-size: 11px; color: var(--text-dim); margin-top: 1px; }

/* Light mode sidebar footer text = dark */
body.theme-light .user-name { color: var(--text-0); }
body.theme-light .user-role { color: var(--text-muted); }

/* ══════════════════════════════════════════════════════════
   MAIN CONTENT AREA
   ══════════════════════════════════════════════════════════ */
.main-content {
  margin-right: 290px; /* sidebar 266 + 12 margin + 12 gap */
  margin-left: 0;
  width: calc(100vw - 290px);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition:
    margin-right var(--transition-normal),
    width var(--transition-normal);
  background: var(--bg-0);
}

.sidebar.collapsed + .main-content {
  margin-right: 100px; /* 76 + 12 + 12 */
  width: calc(100vw - 100px);
}

/* ══════════════════════════════════════════════════════════
   GLASS TOPBAR — Sticky, Frosted Glass Effect
   ══════════════════════════════════════════════════════════ */
.topbar {
  min-height: 68px;
  padding: 12px 28px;
  background: var(--surface-topbar);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 16px;
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 0;
  z-index: 99;
  transition: background var(--transition-normal);
  box-shadow: 0 1px 0 var(--border-soft), var(--shadow-sm);
}

.topbar::-webkit-scrollbar { display: none; }

body.theme-light .topbar {
  background: rgba(255, 255, 255, 0.85);
  border-color: var(--border);
  box-shadow: 0 1px 0 var(--border), var(--shadow-xs);
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-family: var(--font-heading);
  flex-shrink: 0;
}

.breadcrumb-pill {
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-0);
  font-weight: 600;
  font-size: 13.5px;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.breadcrumb-pill.muted {
  color: var(--text-2);
  font-weight: 400;
  background: transparent;
  border-color: transparent;
}

body.theme-light .breadcrumb-pill {
  background: var(--bg-2);
  border-color: var(--border);
}

.breadcrumb .separator {
  color: var(--text-dim);
  font-size: 12px;
}

/* Topbar Actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ZATCA Badge */
.zatca-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(0, 208, 132, 0.25);
  font-size: 11.5px;
  font-weight: 700;
  font-family: var(--font-heading);
  white-space: nowrap;
  letter-spacing: 0.3px;
}

.zatca-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success-glow);
  /* pulse animation removed for performance */
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 1; }
}

body.theme-light .zatca-badge {
  background: rgba(16, 185, 129, 0.08);
  color: #059669;
  border-color: rgba(5, 150, 105, 0.2);
}

/* Theme Toggle Button */
.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
  transform: rotate(20deg);
}

/* Notification Button */
.notif-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  transition: all var(--transition-fast);
}

.notif-btn:hover {
  background: var(--warning-dim);
  border-color: var(--warning);
  color: var(--warning);
}

.notif-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-0);
  animation: pulse-dot 2s ease infinite;
}

/* Search */
.topbar-search {
  position: relative;
  flex: 0 0 auto;
}

.topbar-search input {
  height: 38px;
  width: 200px;
  padding: 0 14px 0 36px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-1);
  font-size: 13px;
  font-family: var(--font-body);
  outline: none;
  transition: all var(--transition-fast);
}

.topbar-search input:focus {
  width: 260px;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

.topbar-search .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 14px;
  pointer-events: none;
}

/* Portal Dropdowns */
.dropdown-portal {
  position: fixed;
  z-index: 99999;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  display: none;
  flex-direction: column;
  padding: 8px;
  min-width: 190px;
}

.dropdown-portal.open { display: flex; }

@keyframes dropIn {
  from { opacity: 1; }
  to   { opacity: 1; }
}

body.theme-light .dropdown-portal {
  background: var(--bg-1);
  border-color: var(--border);
  box-shadow: var(--shadow-lg);
}

/* ══════════════════════════════════════════════════════════
   FILTER BAR
   ══════════════════════════════════════════════════════════ */
.filterbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 28px;
  background: var(--surface-filter);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
  position: sticky;
  top: 68px;
  z-index: 90;
}

body.theme-light .filterbar {
  background: var(--bg-1);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

.filterbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}

.date-range-group,
.filter-select-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-2);
  font-family: var(--font-heading);
}

.date-range-group input[type="date"],
.filter-select-group select {
  height: 36px;
  padding: 0 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  font-size: 12.5px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color var(--transition-fast);
}

.date-range-group input[type="date"]:focus,
.filter-select-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

/* ══════════════════════════════════════════════════════════
   PAGE CONTENT
   ══════════════════════════════════════════════════════════ */
#page-router-outlet {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.page-content {
  padding: 28px 32px 56px 32px;
  width: 100%;
  box-sizing: border-box;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title {
  font-family: var(--font-heading);
  font-size: 26px;
  font-weight: 700;
  color: var(--text-0);
  margin: 0;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.page-subtitle {
  font-size: 13.5px;
  color: var(--text-2);
  margin-top: 5px;
  line-height: 1.5;
}

/* ══════════════════════════════════════════════════════════
   MOBILE HAMBURGER (Hidden on Desktop)
   ══════════════════════════════════════════════════════════ */
#mobile-menu-btn {
  display: none;
  font-size: 20px;
  color: var(--text-0);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
}

/* ══════════════════════════════════════════════════════════
   SIDEBAR OVERLAY
   ══════════════════════════════════════════════════════════ */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  z-index: 95;
  display: none;
}

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

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — Mobile Only (< 768px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  #mobile-menu-btn { display: flex; }

  .sidebar {
    transform: translateX(110%);
    width: 280px !important;
    top: 0;
    bottom: 0;
    right: 0;
    height: 100vh !important;
    border-radius: 0 !important;
    z-index: 1100 !important;
  }

  .sidebar.mobile-hidden { transform: translateX(110%); }
  .sidebar:not(.mobile-hidden) { transform: translateX(0); }

  .main-content {
    margin-right: 0 !important;
    width: 100vw !important;
  }

  .sidebar.collapsed + .main-content {
    margin-right: 0 !important;
    width: 100vw !important;
  }

  .page-content { padding: 16px; }
  .filterbar { padding: 12px 16px; top: 60px; }
  .topbar { padding: 10px 16px; min-height: 60px; }
  .zatca-badge { display: none; }
  .topbar-search { display: none; }

  .sidebar-overlay { z-index: 1090 !important; }
}

/* ══════════════════════════════════════════════════════════
   PRINT STYLES
   ══════════════════════════════════════════════════════════ */
@media print {
  body, html {
    background: #FFFFFF !important;
    color: #000000 !important;
    font-size: 12px !important;
  }

  .sidebar, .topbar, .filterbar, .no-print,
  .row-actions, .modal-footer, button,
  .modal-tabs, .modal-close, #mobile-menu-btn {
    display: none !important;
  }

  .main-content {
    margin: 0 !important;
    width: 100% !important;
    background: transparent !important;
  }

  .page-content {
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
  }

  .card, .modal {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    position: static !important;
    transform: none !important;
    border-radius: 0 !important;
  }

  .modal-overlay {
    position: static !important;
    background: transparent !important;
    display: block !important;
    padding: 0 !important;
  }

  table { border-collapse: collapse !important; width: 100% !important; color: #000 !important; }
  th, td { border: 1px solid #ccc !important; padding: 6px !important; color: #000 !important; }
  th { background-color: #f5f5f5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
