/* ============================================
   Next Future ERP - Web Design System
   SAP ByDesign Inspired | RTL-First | Arabic
   ============================================ */

/* ── Google Fonts ──────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800&family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Custom Properties ─────────────────── */
:root {
  /* ─ Brand Colors (Admina Theme Standards) ─ */
  --primary: #2563EB;
  --primary-dark: #1D4ED8;
  --primary-light: #EFF6FF;
  --primary-gradient: linear-gradient(135deg, #2563EB, #1D4ED8);
  --primary-gradient-hover: linear-gradient(135deg, #1D4ED8, #1E40AF);

  /* ─ Semantic Colors ─ */
  --success: #16A34A;
  --success-light: #DCFCE7;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --danger: #DC2626;
  --danger-light: #FEE2E2;
  --info: #06B6D4;
  --info-light: #CFFAFE;

  /* ─ Neutral Colors ─ */
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --text-inverse: #FFFFFF;

  --bg-body: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #F1F5F9;
  --bg-sidebar: #0F172A;
  --bg-sidebar-hover: #1E293B;
  --bg-sidebar-active: rgba(37, 99, 235, 0.2);

  --border-color: #E2E8F0;
  --border-focus: #2563EB;
  --border-radius-sm: 6px;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
  --border-radius-xl: 20px;
  --border-radius-full: 9999px;

  /* ─ Shadows ─ */
  --shadow-xs: 0 1px 3px rgba(0,0,0,0.03);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);

  /* ─ Spacing ─ */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 72px;
  --topnav-height: 60px;

  /* ─ Typography ─ */
  --font-family: 'Cairo', 'Inter', 'Segoe UI', sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.8125rem;
  --font-size-base: 0.875rem;
  --font-size-md: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;

  /* ─ Transitions ─ */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ─────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--primary-dark); }

img { max-width: 100%; height: auto; }

/* ── Scrollbar ─────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* ── Global Page Header & Title Formatting (Admina Theme Standards) ─ */
.page-header {
    margin-bottom: 1.25rem !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 1rem !important;
    background: #FFFFFF !important;
    padding: 1rem 1.25rem !important;
    border: 1px solid #E2E8F0 !important;
    border-radius: 16px !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02) !important;
}

.page-header h1, 
.page-title, 
h1.page-title,
.md-content-title,
.pv-toolbar__title h1 {
    font-size: 1.2rem !important;
    font-weight: 700 !important;
    color: #0F172A !important;
    margin: 0 !important;
    line-height: 1.3 !important;
    letter-spacing: normal !important;
}

.page-header p, 
.page-subtitle, 
.pv-toolbar__subtitle,
.md-content-subtitle {
    font-size: 0.8rem !important;
    color: #64748B !important;
    margin: 0.2rem 0 0 0 !important;
    font-weight: 500 !important;
}

/* ── Document Card Section Titles (بيانات الفاتورة، سطور الفاتورة، إلخ) ── */
.pv-card__title h1, .pv-card__title h2, .pv-card__title h3,
.pv-card__head h1, .pv-card__head h2, .pv-card__head h3,
.pv-card h1, .pv-card h2, .pv-card h3,
.pv-wrap h1, .pv-wrap h2, .pv-wrap h3 {
    font-size: 1.05rem !important;
    font-weight: 700 !important;
    color: #0F172A !important;
    margin: 0 !important;
    line-height: 1.3 !important;
}

/* ── Sidebar Light Theme (القائمة المضيئة النهارية) ─────────────── */
html.sidebar-light .twin-sidebar,
body.sidebar-light .twin-sidebar {
    background: #FFFFFF !important;
    border-left: 1px solid #E2E8F0 !important;
    box-shadow: -2px 0 12px rgba(0,0,0,0.03) !important;
}

html.sidebar-light .twin-rail,
body.sidebar-light .twin-rail {
    background: #FFFFFF !important;
    border-left: 1px solid #F1F5F9 !important;
}

html.sidebar-light .twin-panel,
body.sidebar-light .twin-panel {
    background: #F8FAFC !important;
    border-left: 1px solid #E2E8F0 !important;
}

html.sidebar-light .twin-panel__head,
body.sidebar-light .twin-panel__head {
    border-bottom: 1px solid #E2E8F0 !important;
}

.twin-panel__logo {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    font-size: 1.2rem !important;
    font-weight: 700 !important;
    text-decoration: none !important;
}

html.sidebar-light .twin-panel__logo,
body.sidebar-light .twin-panel__logo {
    color: #0F172A !important;
}

html.sidebar-light .twin-menu-title,
body.sidebar-light .twin-menu-title {
    color: #94A3B8 !important;
}

html.sidebar-light .twin-menu a,
body.sidebar-light .twin-menu a {
    color: #334155 !important;
}

html.sidebar-light .twin-menu a:hover,
body.sidebar-light .twin-menu a:hover {
    color: var(--primary, #2563EB) !important;
    background: #EFF6FF !important;
}

html.sidebar-light .twin-menu li.active > a,
body.sidebar-light .twin-menu li.active > a {
    color: #FFFFFF !important;
    background: var(--primary, #2563EB) !important;
}

html.sidebar-light .rail-icon,
body.sidebar-light .rail-icon {
    color: #64748B !important;
}

html.sidebar-light .rail-icon:hover,
body.sidebar-light .rail-icon:hover {
    color: var(--primary, #2563EB) !important;
    background: #EFF6FF !important;
}

html.sidebar-light .rail-icon.active,
body.sidebar-light .rail-icon.active {
    color: #FFFFFF !important;
    background: var(--primary, #2563EB) !important;
}

/* ── Global Preloader Loading Overlay (شاشة التحميل المودرن) ─────────────── */
.global-preloader {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    visibility: hidden;
}

body[data-theme="dark"] .global-preloader,
html[data-theme="dark"] .global-preloader {
    background: rgba(7, 13, 25, 0.9);
}

.global-preloader.show {
    opacity: 1 !important;
    pointer-events: all !important;
    visibility: visible !important;
}

.preloader-spinner-wrap {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto;
}

.preloader-spinner {
    position: absolute;
    inset: 0;
    border: 3.5px solid rgba(37, 99, 235, 0.15);
    border-top-color: var(--primary, #2563EB);
    border-right-color: var(--primary, #2563EB);
    border-radius: 50%;
    animation: preloader-spin 0.85s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
}

.preloader-logo {
    position: absolute;
    inset: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #FFFFFF;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 6px;
}

body[data-theme="dark"] .preloader-logo,
html[data-theme="dark"] .preloader-logo {
    background: #0F172A !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.preloader-logo img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    animation: logo-pulse 1.4s ease-in-out infinite alternate;
}

@keyframes preloader-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes logo-pulse {
    0% { transform: scale(0.9); opacity: 0.85; }
    100% { transform: scale(1.08); opacity: 1; }
}

/* ── Mobile Navbar & Header Responsiveness ──────────────────────── */
.navbar-header {
    padding: 0.75rem 1.25rem;
    background: #FFFFFF;
    border-bottom: 1px solid #E2E8F0;
    position: sticky;
    top: 0;
    z-index: 1010;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

body[data-theme="dark"] .navbar-header {
    background: #0F172A !important;
    border-bottom: 1px solid #1E293B !important;
}

@media (max-width: 1199.98px) {
    .navbar-header {
        padding: 0.6rem 1rem !important;
        overflow: visible !important;
    }
}

@media (max-width: 575.98px) {
    .navbar-header {
        padding: 0.5rem 0.75rem !important;
    }
}

/* ── Fix Mobile Sidebar Toggle Button Positioning ──────────────────────── */
.twin-mobile-toggle {
    position: static !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    inset: auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    border-radius: 10px !important;
    background: #2563EB !important;
    color: #FFFFFF !important;
    border: none !important;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25) !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 10 !important;
}

/* ── Full Dark Mode (الوضع الليلي الكلي الشامل) ──────────────────── */
body[data-theme="dark"],
html[data-theme="dark"] {
    --bg-body: #070D19;
    --bg-surface: #0F172A;
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --border-color: #1E293B;
}

body[data-theme="dark"],
body[data-theme="dark"] body,
body[data-theme="dark"] .dashboard-main,
body[data-theme="dark"] .dashboard-main-body,
body[data-theme="dark"] .dashboard-container,
body[data-theme="dark"] .page-content,
body[data-theme="dark"] .d-footer,
body[data-theme="dark"] main {
    background-color: #070D19 !important;
    color: #F8FAFC !important;
}

body[data-theme="dark"] .bg-base,
body[data-theme="dark"] .card,
body[data-theme="dark"] .md-content,
body[data-theme="dark"] .pv-card,
body[data-theme="dark"] .pv-toolbar,
body[data-theme="dark"] .page-header,
body[data-theme="dark"] .navbar-header,
body[data-theme="dark"] .md-table-wrapper,
body[data-theme="dark"] .bg-white,
body[data-theme="dark"] .offcanvas,
body[data-theme="dark"] .modal-content,
body[data-theme="dark"] .dropdown-menu {
    background-color: #0F172A !important;
    border-color: #1E293B !important;
    color: #F8FAFC !important;
}

body[data-theme="dark"] .text-main,
body[data-theme="dark"] h1,
body[data-theme="dark"] h2,
body[data-theme="dark"] h3,
body[data-theme="dark"] h4,
body[data-theme="dark"] h5,
body[data-theme="dark"] h6,
body[data-theme="dark"] .fw-bold {
    color: #F8FAFC !important;
}

body[data-theme="dark"] .text-neutral-700,
body[data-theme="dark"] .text-secondary-light,
body[data-theme="dark"] .text-muted {
    color: #94A3B8 !important;
}

body[data-theme="dark"] .border,
body[data-theme="dark"] .border-bottom,
body[data-theme="dark"] .border-top,
body[data-theme="dark"] .border-neutral-200 {
    border-color: #1E293B !important;
}

body[data-theme="dark"] .table {
    color: #E2E8F0 !important;
}

body[data-theme="dark"] .table th {
    background-color: #162032 !important;
    color: #CBD5E1 !important;
    border-color: #1E293B !important;
}

body[data-theme="dark"] .table td {
    background-color: #0F172A !important;
    border-color: #1E293B !important;
    color: #E2E8F0 !important;
}

body[data-theme="dark"] .table-hover tbody tr:hover td {
    background-color: #1E293B !important;
}

body[data-theme="dark"] .form-control,
body[data-theme="dark"] .form-select {
    background-color: #162032 !important;
    border-color: #1E293B !important;
    color: #F8FAFC !important;
}

body[data-theme="dark"] .apexcharts-canvas text {
    fill: #94A3B8 !important;
}

body[data-theme="dark"] .apexcharts-tooltip {
    background: #0F172A !important;
    border-color: #1E293B !important;
    color: #FFFFFF !important;
}

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  /* تدرج ليلي–زُرقي متناسق مع شعار الشركة (--primary / الأزرق المعلوماتي) */
  background: linear-gradient(
    155deg,
    #050d18 0%,
    #0a1f35 38%,
    #0c2744 52%,
    #082038 78%,
    #040a12 100%
  );
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  top: -45%;
  right: -25%;
  width: 85%;
  height: 190%;
  background: radial-gradient(
    ellipse at 60% 25%,
    rgba(10, 110, 209, 0.28) 0%,
    rgba(59, 130, 246, 0.08) 45%,
    transparent 68%
  );
  pointer-events: none;
}

.login-page::after {
  content: '';
  position: absolute;
  bottom: -35%;
  left: -25%;
  width: 70%;
  height: 130%;
  background: radial-gradient(
    ellipse at 30% 70%,
    rgba(56, 189, 248, 0.12) 0%,
    rgba(10, 110, 209, 0.06) 42%,
    transparent 65%
  );
  pointer-events: none;
}

/* ─ Login Left: Branding ─ */
.login-branding {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3rem;
  position: relative;
  z-index: 1;
}

.login-branding__picture {
  display: block;
  margin: 0 auto 2rem;
  max-width: min(220px, 42vw);
}

.login-branding__logo {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(140px, 28vh);
  margin: 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 28px rgba(10, 110, 209, 0.35))
    drop-shadow(0 0 20px rgba(56, 189, 248, 0.15));
  animation: float 6s ease-in-out infinite;
}

/* شعار فوق بطاقة الدخول — يظهر فقط على الشاشات الصغيرة */
.login-mobile-brand {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.login-mobile-brand__picture {
  display: block;
  max-width: min(240px, 72vw);
}

.login-mobile-brand__logo {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(120px, 24vh);
  margin: 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 6px 20px rgba(10, 110, 209, 0.35));
}

.login-mobile-brand__title {
  margin: 0.75rem 0 0;
  font-size: 1.125rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.login-mobile-brand__accent {
  color: #7ec8ff;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.login-branding__title {
  font-size: var(--font-size-3xl);
  font-weight: 800;
  color: white;
  margin-bottom: 0.5rem;
  letter-spacing: -0.5px;
}

.login-branding__accent {
  color: #7ec8ff;
  font-weight: 800;
}

.login-branding__subtitle {
  font-size: var(--font-size-md);
  color: #9ec5e8;
  text-align: center;
  max-width: 400px;
  line-height: 1.8;
}

.login-branding__features {
  margin-top: 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-feature {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #c5dff5;
  font-size: var(--font-size-sm);
}

.login-feature__icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(10, 110, 209, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #93c5fd;
  flex-shrink: 0;
}

/* ─ Login Right: Form ─ */
.login-form-section {
  width: 480px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  position: relative;
  z-index: 1;
  gap: 0;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border-radius: var(--border-radius-xl);
  padding: 2.5rem;
  box-shadow:
    var(--shadow-xl),
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 48px rgba(10, 110, 209, 0.12);
  animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-card__header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-card__title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.login-card__desc {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* ─ Form Elements ─ */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.form-input-wrapper {
  position: relative;
}

.form-input-wrapper__icon {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  transition: color var(--transition-fast);
  width: 18px;
  height: 18px;
}

.form-input {
  width: 100%;
  height: 44px;
  padding: 0 14px 0 14px;
  padding-right: 42px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--border-radius-md);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-surface);
  transition: all var(--transition-fast);
  outline: none;
}

.form-input:hover {
  border-color: #CBD5E1;
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(10, 110, 209, 0.1);
}

.form-input:focus + .form-input-wrapper__icon {
  color: var(--primary);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.password-toggle {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color var(--transition-fast);
}
.password-toggle:hover { color: var(--text-secondary); }

/* ─ Buttons ─ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 1.5rem;
  height: 44px;
  border: none;
  border-radius: var(--border-radius-md);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: var(--primary-gradient);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background: var(--primary-gradient-hover);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.3);
}

.btn-block { width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border-color);
}
.btn-ghost:hover {
  background: var(--bg-surface-hover);
  border-color: #CBD5E1;
}

.btn .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: none;
}
.btn.loading .spinner { display: block; }
.btn.loading .btn-text { opacity: 0.6; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─ Login checkbox ─ */
.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-check label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  cursor: pointer;
}

/* ─ Alert Messages ─ */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-sm);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.alert-danger {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #FECACA;
}

.alert-success {
  background: var(--success-light);
  color: #065F46;
  border: 1px solid #A7F3D0;
}

/* ============================================
   MAIN APP LAYOUT
   ============================================ */
.app-layout {
  display: flex;
  min-height: 100vh;
  direction: rtl;
}

/* ─ Sidebar ─ */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0;
  right: 0;
  background: var(--bg-sidebar);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-slow);
  overflow: hidden;
}

.app-layout--collapsed .sidebar {
  transform: translateX(100%);
}

.sidebar__header {
  height: var(--topnav-height);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.sidebar__logo {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

/* Close button — hidden on desktop, visible on mobile */
.sidebar__close {
  display: none;
  margin-right: auto;  /* push to far left in RTL */
  background: none;
  border: none;
  color: #94A3B8;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 8px;
  line-height: 0;
  transition: background 0.2s, color 0.2s;
}
.sidebar__close:hover {
  background: rgba(255,255,255,0.08);
  color: #E2E8F0;
}

.sidebar__brand {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: white;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar__brand span {
  color: #3B82F6;
}

/* ─ Sidebar Navigation ─ */
.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

.sidebar__nav::-webkit-scrollbar { width: 3px; }
.sidebar__nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.nav-section {
  margin-bottom: 0.5rem;
}

.nav-section__title {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.75rem 0.75rem 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--border-radius-md);
  color: #94A3B8;
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  position: relative;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: #E2E8F0;
}

.nav-item.active {
  background: var(--bg-sidebar-active);
  color: #3B82F6;
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  right: -0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: #3B82F6;
  border-radius: 0 3px 3px 0;
}

.nav-item__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active .nav-item__icon {
  opacity: 1;
}

.nav-item__badge {
  margin-right: auto;
  margin-left: 0;
  padding: 2px 8px;
  border-radius: var(--border-radius-full);
  font-size: 11px;
  font-weight: 700;
  background: rgba(59,130,246,0.15);
  color: #3B82F6;
}

/* ─ Sidebar expandable items ─ */
.nav-group__toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--border-radius-md);
  color: #94A3B8;
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  width: 100%;
  border: none;
  background: none;
  text-align: right;
  white-space: nowrap;
}

.nav-group__toggle:hover {
  background: var(--bg-sidebar-hover);
  color: #E2E8F0;
}

.nav-group__arrow {
  margin-right: auto;
  margin-left: 0;
  width: 16px;
  height: 16px;
  transition: transform var(--transition-fast);
  opacity: 0.4;
}

.nav-group.open .nav-group__arrow {
  transform: rotate(90deg);
}

.nav-group__children {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition-slow);
  padding-right: 1rem;
}

.nav-group.open .nav-group__children {
  max-height: 600px;
}

.nav-group__children .nav-item {
  padding: 0.5rem 0.75rem;
  font-size: var(--font-size-xs);
}

/* ─ Sidebar Footer ─ */
.sidebar__footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar__avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--border-radius-full);
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: var(--font-size-sm);
  flex-shrink: 0;
}

.sidebar__user-info {
  overflow: hidden;
}

.sidebar__user-name {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: #E2E8F0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__user-role {
  font-size: var(--font-size-xs);
  color: #64748B;
}

/* ─ TopNav ─ */
.topnav {
  height: 60px;
  background: white;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
  z-index: 900;
  flex-wrap: wrap;
}

.topnav__right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topnav__breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #64748B;
  font-size: var(--font-size-sm);
  margin-inline-start: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topnav__left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topnav__icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--border-radius-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  position: relative;
}

.topnav__icon-btn:hover {
  background: var(--bg-body);
  color: var(--text-primary);
}

.topnav__icon-btn .badge-dot {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}

.topnav__search {
  position: relative;
  width: 280px;
}

.topnav__search input {
  width: 100%;
  height: 38px;
  padding: 0 14px 0 38px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--border-radius-full);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  background: var(--bg-body);
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition-fast);
}

.topnav__search input:focus {
  border-color: var(--border-focus);
  background: var(--bg-surface);
  box-shadow: 0 0 0 3px rgba(10, 110, 209, 0.08);
  width: 340px;
}

.topnav__search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

.topnav__user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-right: 1px solid var(--border-color);
  padding-right: 0.75rem;
  margin-right: 0.5rem;
}
.topnav__user-text {
  text-align: right;
  display: flex;
  flex-direction: column;
}
.topnav__user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}
.topnav__user-company {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.2;
}
.topnav__user-avatar {
  width: 36px;
  height: 36px;
  background: #2563EB;
  color: #FFFFFF;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1.1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.topnav__add-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 6px;
  position: relative;
}

/* ─ TopNav Dropdown ─ */
.topnav__dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  width: 240px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.topnav__dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.topnav__dropdown-header {
  padding: 0.75rem 1rem;
  background: #F8FAFC;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.topnav__dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.2s;
}

.topnav__dropdown-item:hover {
  background: var(--bg-body);
  color: var(--primary);
}

.topnav__dropdown-item svg {
  color: var(--text-muted);
  transition: color 0.2s;
}

.topnav__dropdown-item:hover svg {
  color: var(--primary);
}

/* ─ Main Content Area ─ */
.main-wrapper {
  margin-right: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  transition: margin-right var(--transition-slow);
  overflow-x: hidden;
  max-width: 100%;
}

.app-layout--collapsed .main-wrapper {
  margin-right: 0;
}

.main-content {
  padding: 1.5rem;
  max-width: 1400px;
}

/* ─ Page Header ─ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.page-header__title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--text-primary);
}

.page-header__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* رأس نماذج المستندات: العنوان + شريط الحالة (حبوب) في سطر واحد */
.page-header--doc {
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-header--doc .page-header__lead {
  flex: 1;
  min-width: min(100%, 200px);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.page-header--doc .page-header__title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

.page-header--doc .page-header__title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.2;
}

.page-header--doc .page-header__subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.page-header--doc .page-header__doc-status {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.65rem;
}

.page-header--doc .page-header__doc-status-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .page-header--doc .page-header__title {
    font-size: 1.2rem;
  }
  .page-header--doc .page-header__title-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }
  .page-header--doc .page-header__doc-status {
    width: 100%;
  }
}

/* ============================================
   DASHBOARD CARDS
   ============================================ */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-surface);
  border-radius: var(--border-radius-lg);
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
  border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) 0;
}

.stat-card--blue::after { background: var(--primary-gradient); }
.stat-card--green::after { background: linear-gradient(135deg, #10B981, #059669); }
.stat-card--amber::after { background: linear-gradient(135deg, #F59E0B, #D97706); }
.stat-card--red::after { background: linear-gradient(135deg, #EF4444, #DC2626); }

.stat-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.stat-card__icon {
  width: 44px;
  height: 44px;
  border-radius: var(--border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-card--blue .stat-card__icon { background: var(--primary-light); color: var(--primary); }
.stat-card--green .stat-card__icon { background: var(--success-light); color: var(--success); }
.stat-card--amber .stat-card__icon { background: var(--warning-light); color: var(--warning); }
.stat-card--red .stat-card__icon { background: var(--danger-light); color: var(--danger); }

.stat-card__trend {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: var(--font-size-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--border-radius-full);
}

.stat-card__trend--up { background: var(--success-light); color: var(--success); }
.stat-card__trend--down { background: var(--danger-light); color: var(--danger); }

.stat-card__value {
  font-size: var(--font-size-2xl);
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
  direction: ltr;
  text-align: right;
}

.stat-card__label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* ─ Content Cards ─ */
.card {
  background: var(--bg-surface);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.card__title {
  font-size: var(--font-size-base);
  font-weight: 700;
  color: var(--text-primary);
}

.card__body {
  padding: 1.25rem;
}

/* ─ Recent Activity List ─ */
.activity-list {
  list-style: none;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border-color);
}

.activity-item:last-child { border-bottom: none; }

.activity-item__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.activity-item__dot--blue { background: var(--primary); }
.activity-item__dot--green { background: var(--success); }
.activity-item__dot--amber { background: var(--warning); }

.activity-item__content { flex: 1; }

.activity-item__text {
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  margin-bottom: 0.125rem;
}

.activity-item__time {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* ─ Quick Actions Grid ─ */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.25rem 0.75rem;
  border-radius: var(--border-radius-md);
  border: 1.5px solid var(--border-color);
  background: var(--bg-surface);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  color: var(--text-primary);
}

.quick-action:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.quick-action__icon {
  width: 24px;
  height: 24px;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}

.quick-action:hover .quick-action__icon {
  color: var(--primary);
}

.quick-action__label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-align: center;
}

/* ─ Dashboard secondary grid ─ */
.dashboard-content-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
}

/* ============================================
   BRANCH SELECTION (Stage 2 - Two-Stage Login)
   ============================================ */
.branch-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
}

.branch-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--bg-surface);
  position: relative;
}

.branch-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.branch-item--selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(10, 110, 209, 0.1);
}

.branch-item input[type="radio"] {
  display: none;
}

.branch-item__info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.branch-item__name {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
}

.branch-item__badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--border-radius-full);
  background: var(--success-light);
  color: var(--success);
}

.branch-item__check {
  color: var(--primary);
  opacity: 0;
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
}

.branch-item--selected .branch-item__check {
  opacity: 1;
}

/* Stage transition animation */
#stage1, #stage2 {
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   UTILITIES
   ============================================ */
.text-muted { color: var(--text-muted) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-primary { color: var(--primary) !important; }
.fw-600 { font-weight: 600 !important; }
.fw-700 { font-weight: 700 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mt-1 { margin-top: 0.5rem !important; }
.hidden { display: none !important; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
  .login-branding { display: none; }
  .login-form-section { width: 100%; }
  .login-mobile-brand {
    display: flex;
    width: 100%;
    max-width: 400px;
    padding-top: 0.5rem;
  }
  .dashboard-content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  /* Sidebar: fully hidden off-screen on mobile */
  .sidebar {
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px !important;
    height: 100vh;
    z-index: 1050;
    transition: right 0.3s ease;
    transform: none !important;
    display: flex;
    flex-direction: column;
  }
  .sidebar.open {
    right: 0;
  }
  /* Show close button on mobile */
  .sidebar__close {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  /* Scrollable nav on mobile */
  .sidebar__nav {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Overlay behind sidebar when open */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1040;
    backdrop-filter: blur(2px);
  }
  .sidebar-overlay.active { display: block; }

  /* Main wrapper takes full width */
  .main-wrapper {
    margin-right: 0 !important;
    width: 100%;
    overflow-x: hidden;
  }
  /* TopNav: hide search & user name on mobile */
  .topnav__search { display: none; }
  .topnav__user-info { display: none !important; }
  .topnav__add-text { display: none; }
  .topnav__add-btn { padding: 0.35rem; }
  .topnav {
    padding: 0.5rem 0.75rem;
    position: sticky;
    top: 0;
    z-index: 900;
    flex-wrap: nowrap;
    min-height: var(--topnav-height);
    height: auto;
    gap: 0.5rem;
  }
  .topnav__add-btn { 
    padding: 0; 
    width: 32px; 
    height: 32px; 
    justify-content: center; 
  }
  .breadcrumb-desktop-only {
    display: none;
  }
  .topnav__right {
    flex-wrap: nowrap;
    min-width: 0;
    flex: 1; /* Take up available space to center breadcrumb */
  }
  .topnav__breadcrumb {
    flex: 1;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
  }
  .topnav__breadcrumb-current {
    font-weight: 700;
    color: var(--text-primary);
  }
  .topnav__left {
    gap: 0.5rem;
  }
  /* main content padding */
  .main-content {
    padding: 0.75rem;
  }
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .login-card {
    padding: 1.5rem;
  }
  .login-form-section {
    padding: 1rem;
  }
  .topnav__breadcrumb {
    display: none; /* Hide breadcrumbs on very small screens to save space */
  }
  .search-input {
    width: 150px; /* Shrink global search */
  }
  .topnav {
    padding: 0 0.5rem;
  }
  .sidebar {
    width: 260px; /* Ensure sidebar doesn't exceed screen */
  }
}

/* ─ App Layout No Sidebar (Home Dashboard) ─ */
.app-layout--no-sidebar .sidebar { display: none !important; }
.app-layout--no-sidebar .main-wrapper { margin-right: 0 !important; width: 100%; }

/* ══════════════════════════════════════════════════════════════════
   GLOBAL PICKER DIALOGS OVERHAUL (اختيار المورد، العميل، الصنف، الحساب)
   ══════════════════════════════════════════════════════════════════ */

/* Overlay Backdrop */
.ip-overlay, .ap-overlay,
#supplierPickerOverlay, #customerPickerOverlay, #itemPickerOverlay,
#accountPickerOverlay, #analyticAccountPickerOverlay {
    background: rgba(15, 23, 42, 0.65) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
}

/* Modal Dialog Box */
.ip-dialog, .ap-dialog {
    background: #FFFFFF !important;
    border-radius: 20px !important;
    border: 1px solid #E2E8F0 !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;
    overflow: hidden !important;
}

body[data-theme="dark"] .ip-dialog,
body[data-theme="dark"] .ap-dialog,
html[data-theme="dark"] .ip-dialog,
html[data-theme="dark"] .ap-dialog {
    background: #0F172A !important;
    border-color: #1E293B !important;
    color: #F8FAFC !important;
}

/* Modal Header - Modern Primary Blue Gradient */
.ip-header, .ap-header {
    background: linear-gradient(135deg, var(--primary, #2563EB) 0%, #1D4ED8 100%) !important;
    color: #FFFFFF !important;
    padding: 1rem 1.4rem !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.ip-header__icon, .ap-header__icon {
    width: 38px !important;
    height: 38px !important;
    border-radius: 10px !important;
    background: rgba(255, 255, 255, 0.2) !important;
    backdrop-filter: blur(4px) !important;
    color: #FFFFFF !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.ip-header__title, .ap-header__title,
h2.ip-header__title, h2.ap-header__title {
    font-size: 1.1rem !important; /* ~18px compact title */
    font-weight: 700 !important;
    color: #FFFFFF !important;
    margin: 0 !important;
    line-height: 1.3 !important;
    letter-spacing: normal !important;
}

.ip-header__subtitle, .ap-header__subtitle {
    font-size: 0.78rem !important;
    color: rgba(255, 255, 255, 0.85) !important;
    margin-top: 0.15rem !important;
}

.ip-header__close, .ap-header__close {
    width: 34px !important;
    height: 34px !important;
    border-radius: 8px !important;
    background: rgba(255, 255, 255, 0.2) !important;
    color: #FFFFFF !important;
    border: none !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.ip-header__close:hover, .ap-header__close:hover {
    background: rgba(255, 255, 255, 0.35) !important;
    transform: scale(1.05) !important;
}

/* Modal Search Bar */
.ip-search, .ap-search {
    padding: 0.85rem 1.4rem !important;
    background: #F8FAFC !important;
    border-bottom: 1px solid #E2E8F0 !important;
}

body[data-theme="dark"] .ip-search,
body[data-theme="dark"] .ap-search {
    background: #162032 !important;
    border-color: #1E293B !important;
}

.ip-search__input, .ap-search input,
.ip-search input, #spSearchInput, #cpSearchInput, #ipSearchInput {
    border: 1px solid #CBD5E1 !important;
    border-radius: 10px !important;
    padding: 0.6rem 2.4rem 0.6rem 0.9rem !important;
    font-size: 0.9rem !important;
    background: #FFFFFF !important;
    color: #0F172A !important;
    transition: all 0.2s ease !important;
}

body[data-theme="dark"] .ip-search__input,
body[data-theme="dark"] .ap-search input,
body[data-theme="dark"] .ip-search input,
body[data-theme="dark"] #spSearchInput,
body[data-theme="dark"] #cpSearchInput,
body[data-theme="dark"] #ipSearchInput {
    background: #0F172A !important;
    border-color: #334155 !important;
    color: #F8FAFC !important;
}

.ip-search__input:focus, .ap-search input:focus {
    border-color: var(--primary, #2563EB) !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15) !important;
}

/* Modal Table Results */
.ip-table thead th, .ap-table thead th {
    background: #F1F5F9 !important;
    color: #475569 !important;
    font-weight: 700 !important;
    font-size: 0.8rem !important;
    padding: 0.65rem 0.85rem !important;
    border-bottom: 1px solid #E2E8F0 !important;
}

body[data-theme="dark"] .ip-table thead th,
body[data-theme="dark"] .ap-table thead th {
    background: #162032 !important;
    color: #CBD5E1 !important;
    border-color: #1E293B !important;
}

.ip-table tbody td, .ap-table tbody td {
    padding: 0.6rem 0.85rem !important;
    border-bottom: 1px solid #F1F5F9 !important;
    color: #334155 !important;
    font-size: 0.85rem !important;
}

body[data-theme="dark"] .ip-table tbody td,
body[data-theme="dark"] .ap-table tbody td {
    border-color: #1E293B !important;
    color: #E2E8F0 !important;
}

.ip-table tbody tr:hover, .ap-table tbody tr:hover {
    background: #EFF6FF !important;
}

body[data-theme="dark"] .ip-table tbody tr:hover,
body[data-theme="dark"] .ap-table tbody tr:hover {
    background: #1E293B !important;
}

.ip-table tbody tr.ip-active-row, .ip-table tbody tr.selected,
.ap-table tbody tr.ap-active-row, .ap-table tbody tr.selected {
    background: #DBEAFE !important;
}

body[data-theme="dark"] .ip-table tbody tr.ip-active-row,
body[data-theme="dark"] .ip-table tbody tr.selected,
body[data-theme="dark"] .ap-table tbody tr.ap-active-row,
body[data-theme="dark"] .ap-table tbody tr.selected {
    background: #1E3A8A !important;
}

.ip-table tbody tr.ip-active-row td, .ip-table tbody tr.selected td,
.ap-table tbody tr.ip-active-row td, .ap-table tbody tr.selected td {
    color: #1E40AF !important;
    font-weight: 700 !important;
}

body[data-theme="dark"] .ip-table tbody tr.ip-active-row td,
body[data-theme="dark"] .ip-table tbody tr.selected td,
body[data-theme="dark"] .ap-table tbody tr.ip-active-row td,
body[data-theme="dark"] .ap-table tbody tr.selected td {
    color: #93C5FD !important;
}

/* Modal Footer Buttons & Status */
.ip-footer, .ap-footer {
    padding: 0.85rem 1.4rem !important;
    background: #F8FAFC !important;
    border-top: 1px solid #E2E8F0 !important;
}

body[data-theme="dark"] .ip-footer,
body[data-theme="dark"] .ap-footer {
    background: #162032 !important;
    border-color: #1E293B !important;
}

.ip-btn, .ap-btn {
    border-radius: 8px !important;
    font-size: 0.85rem !important;
    padding: 0.45rem 1.1rem !important;
    font-weight: 600 !important;
}

.ip-btn-confirm, .ap-btn-confirm,
button[id*="BtnConfirm"], button[id*="Confirm"] {
    background: var(--primary, #2563EB) !important;
    border-color: var(--primary, #2563EB) !important;
    color: #FFFFFF !important;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25) !important;
}

.ip-btn-cancel, .ap-btn-cancel,
button[id*="BtnCancel"], button[id*="Cancel"] {
    background: #FFFFFF !important;
    border: 1px solid #CBD5E1 !important;
    color: #475569 !important;
}

body[data-theme="dark"] .ip-btn-cancel,
body[data-theme="dark"] .ap-btn-cancel,
body[data-theme="dark"] button[id*="BtnCancel"],
body[data-theme="dark"] button[id*="Cancel"] {
    background: #1E293B !important;
    border-color: #334155 !important;
    color: #CBD5E1 !important;
}

.ip-status__count, .ap-status__count {
    font-weight: 700 !important;
    color: var(--primary, #2563EB) !important;
}
