/* ═══════════════════════════════════════════════════════
   LIGHT THEME  (Default)
   ═══════════════════════════════════════════════════════ */
:root {
  --sidebar-width: 230px;

  /* Sidebar */
  --sidebar-bg:           #e5e7eb;
  --sidebar-text:         #4b5563;
  --sidebar-brand-border: #d1d5db;
  --sidebar-hover-bg:     #d1d5db;
  --sidebar-hover-text:   #111827;
  --sidebar-active-bg:    rgba(37,99,235,.1);
  --sidebar-active-text:  #2563eb;
  --sidebar-active-bar:   #2563eb;
  --sidebar-group-text:   #9ca3af;
  --sidebar-icon:         #3b82f6;

  /* Layout */
  --body-bg:      #f1f5f9;
  --topbar-bg:    #ffffff;
  --topbar-border:#e2e8f0;
  --card-bg:      #ffffff;
  --card-border:  #e2e8f0;

  /* Brand */
  --primary:      #2563eb;
  --primary-rgb:  37,99,235;
  --primary-light:#eff6ff;
  --primary-text: #ffffff;

  /* Text */
  --text-main:    #1e293b;
  --text-muted:   #64748b;

  /* Login screen — يشتقّ تلقائياً من ألوان الثيم الحالي */
  --login-grad:         linear-gradient(150deg, var(--primary) 0%, color-mix(in srgb, var(--primary) 60%, #000) 100%);
  --login-field-bg:     #f8fafc;
  --login-field-border: #e2e8f0;
}

/* قيم حقول الدخول للثيمات الداكنة */
[data-theme="dark"]     { --login-field-bg: #111827; --login-field-border: #374151; }
[data-theme="midnight"] { --login-field-bg: #060c18; --login-field-border: #172236; }

/* ═══════════════════════════════════════════════════════
   MIDNIGHT THEME  (Deep Navy + Gold)
   ═══════════════════════════════════════════════════════ */
[data-theme="midnight"] {
  /* Sidebar */
  --sidebar-bg:           #050c1a;
  --sidebar-text:         #5b7a9d;
  --sidebar-brand-border: #0c1d34;
  --sidebar-hover-bg:     #0a1729;
  --sidebar-hover-text:   #b8c9df;
  --sidebar-active-bg:    rgba(245,158,11,.14);
  --sidebar-active-text:  #fbbf24;
  --sidebar-active-bar:   #f59e0b;
  --sidebar-group-text:   #3a5270;
  --sidebar-icon:         #f59e0b;

  /* Layout */
  --body-bg:      #080f1e;
  --topbar-bg:    #0e1829;
  --topbar-border:#172236;
  --card-bg:      #0e1829;
  --card-border:  #172236;

  /* Brand */
  --primary:      #f59e0b;
  --primary-rgb:  245,158,11;
  --primary-light:#1c1506;
  --primary-text: #0a0a0a;

  /* Text */
  --text-main:    #dce4f0;
  --text-muted:   #5b7089;
}

/* ── Override Bootstrap CSS variables for midnight ── */
[data-theme="midnight"] {
  --bs-body-color:             #dce4f0;
  --bs-body-color-rgb:         220, 228, 240;
  --bs-body-bg:                #080f1e;
  --bs-body-bg-rgb:            8, 15, 30;
  --bs-secondary-color:        #5b7089;
  --bs-secondary-color-rgb:    91, 112, 137;
  --bs-emphasis-color:         #f0f4fa;
  --bs-emphasis-color-rgb:     240, 244, 250;
  --bs-border-color:           #172236;
  --bs-border-color-translucent: rgba(255,255,255,.07);
  --bs-card-bg:                #0e1829;
  --bs-card-cap-bg:            rgba(255,255,255,.03);
  --bs-card-cap-color:         #dce4f0;
  --bs-card-border-color:      #172236;
  --bs-card-color:             #dce4f0;
  --bs-table-color:            #c8d4e6;
  --bs-table-bg:               transparent;
  --bs-table-border-color:     #172236;
  --bs-table-striped-color:    #c8d4e6;
  --bs-table-striped-bg:       rgba(255,255,255,.02);
  --bs-table-hover-color:      #dce4f0;
  --bs-table-hover-bg:         rgba(245,158,11,.06);
  --bs-dropdown-bg:            #0e1829;
  --bs-dropdown-border-color:  #172236;
  --bs-dropdown-link-color:    #dce4f0;
  --bs-dropdown-link-hover-bg: #172236;
  --bs-dropdown-divider-bg:    #172236;
  --bs-list-group-bg:          #0e1829;
  --bs-list-group-border-color:#172236;
  --bs-list-group-color:       #dce4f0;
  --bs-nav-tabs-border-color:  #172236;
  --bs-nav-link-color:         #5b7089;
  color-scheme: dark;
}

/* ── Midnight mode component-level fixes ── */
[data-theme="midnight"] .card { color: #dce4f0; }
[data-theme="midnight"] .card-header { color: #dce4f0; }
[data-theme="midnight"] .card-footer {
  background-color: rgba(255,255,255,.03);
  border-color: #172236;
}
[data-theme="midnight"] .form-control,
[data-theme="midnight"] .form-select,
[data-theme="midnight"] .form-check-input:not(:checked) {
  background-color: #060c18;
  border-color: #172236;
  color: #dce4f0;
}
[data-theme="midnight"] .form-control::placeholder { color: #3a5270; }
[data-theme="midnight"] .form-control:focus,
[data-theme="midnight"] .form-select:focus {
  background-color: #060c18;
  border-color: var(--primary);
  color: #dce4f0;
  box-shadow: 0 0 0 .2rem rgba(245,158,11,.2);
}
[data-theme="midnight"] .input-group-text {
  background-color: #060c18;
  border-color: #172236;
  color: #8baac4;
}
[data-theme="midnight"] .table { color: #c8d4e6; }
[data-theme="midnight"] .table td,
[data-theme="midnight"] .table th { border-color: #172236; color: #c8d4e6; }
[data-theme="midnight"] .table-light,
[data-theme="midnight"] thead.table-light th,
[data-theme="midnight"] thead.table-dark th,
[data-theme="midnight"] .table > thead > tr > th {
  background-color: #060c18 !important;
  color: #dce4f0 !important;
  border-color: #172236 !important;
}
[data-theme="midnight"] .table-hover > tbody > tr:hover > td { background-color: rgba(245,158,11,.06); }
[data-theme="midnight"] .badge.text-dark,
[data-theme="midnight"] .badge.text-bg-warning,
[data-theme="midnight"] .badge.text-bg-info,
[data-theme="midnight"] .badge.text-bg-light { color: #080f1e !important; }
[data-theme="midnight"] .modal-content { background-color: #0e1829; color: #dce4f0; border: 1px solid #172236; }
[data-theme="midnight"] .modal-header, [data-theme="midnight"] .modal-footer { border-color: #172236; }
[data-theme="midnight"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
[data-theme="midnight"] .alert-danger  { background-color: #200808; border-color: #7f1d1d; color: #fca5a5; }
[data-theme="midnight"] .alert-success { background-color: #071a0e; border-color: #166534; color: #86efac; }
[data-theme="midnight"] .alert-warning { background-color: #1c1003; border-color: #92400e; color: #fde68a; }
[data-theme="midnight"] .alert-info    { background-color: #04111e; border-color: #0e4272; color: #67e8f9; }
[data-theme="midnight"] .text-muted    { color: #5b7089 !important; }
[data-theme="midnight"] .text-dark     { color: #dce4f0 !important; }
[data-theme="midnight"] .bg-light      { background-color: #0e1829 !important; }
[data-theme="midnight"] .bg-white      { background-color: #0e1829 !important; }
[data-theme="midnight"] hr             { border-color: #172236; }
[data-theme="midnight"] .border,
[data-theme="midnight"] .border-bottom,
[data-theme="midnight"] .border-top,
[data-theme="midnight"] .border-start,
[data-theme="midnight"] .border-end    { border-color: #172236 !important; }
[data-theme="midnight"] .list-group-item { background-color: #0e1829; color: #dce4f0; border-color: #172236; }
[data-theme="midnight"] .nav-tabs .nav-link { color: #5b7089; border-color: #172236; }
[data-theme="midnight"] .nav-tabs .nav-link.active { background-color: #0e1829; border-color: #172236 #172236 #0e1829; color: #dce4f0; }
[data-theme="midnight"] .progress { background-color: #172236; }
[data-theme="midnight"] code { background: #1c1506; color: #fbbf24; }
[data-theme="midnight"] .fw-bold { color: inherit; }

/* ═══════════════════════════════════════════════════════
   DARK THEME
   ═══════════════════════════════════════════════════════ */
[data-theme="dark"] {
  --sidebar-bg:           #0f0f0f;
  --sidebar-text:         #9ca3af;
  --sidebar-brand-border: #1f1f1f;
  --sidebar-hover-bg:     #1a1a2e;
  --sidebar-hover-text:   #e2e8f0;
  --sidebar-active-bg:    rgba(99,102,241,.18);
  --sidebar-active-text:  #a5b4fc;
  --sidebar-active-bar:   #6366f1;
  --sidebar-group-text:   #4b5563;
  --sidebar-icon:         #818cf8;
  --body-bg:      #111827;
  --topbar-bg:    #1f2937;
  --topbar-border:#374151;
  --card-bg:      #1f2937;
  --card-border:  #374151;
  --primary:      #6366f1;
  --primary-rgb:  99,102,241;
  --primary-light:#1e1b4b;
  --primary-text: #ffffff;
  --text-main:    #f1f5f9;
  --text-muted:   #9ca3af;
}

/* ── Override Bootstrap CSS variables for dark mode ── */
[data-theme="dark"] {
  /* Body */
  --bs-body-color:             #f1f5f9;
  --bs-body-color-rgb:         241, 245, 249;
  --bs-body-bg:                #111827;
  --bs-body-bg-rgb:            17, 24, 39;
  --bs-secondary-color:        #9ca3af;
  --bs-secondary-color-rgb:    156, 163, 175;
  --bs-emphasis-color:         #f8fafc;
  --bs-emphasis-color-rgb:     248, 250, 252;
  /* Borders */
  --bs-border-color:           #374151;
  --bs-border-color-translucent: rgba(255,255,255,.1);
  /* Cards */
  --bs-card-bg:                #1f2937;
  --bs-card-cap-bg:            rgba(255,255,255,.04);
  --bs-card-cap-color:         #f1f5f9;
  --bs-card-border-color:      #374151;
  --bs-card-color:             #f1f5f9;
  /* Tables */
  --bs-table-color:            #e5e7eb;
  --bs-table-bg:               transparent;
  --bs-table-border-color:     #374151;
  --bs-table-striped-color:    #e5e7eb;
  --bs-table-striped-bg:       rgba(255,255,255,.03);
  --bs-table-hover-color:      #f1f5f9;
  --bs-table-hover-bg:         rgba(255,255,255,.07);
  /* Dropdowns */
  --bs-dropdown-bg:            #1f2937;
  --bs-dropdown-border-color:  #374151;
  --bs-dropdown-link-color:    #f1f5f9;
  --bs-dropdown-link-hover-bg: #374151;
  --bs-dropdown-divider-bg:    #374151;
  /* List groups */
  --bs-list-group-bg:          #1f2937;
  --bs-list-group-border-color:#374151;
  --bs-list-group-color:       #f1f5f9;
  /* Nav */
  --bs-nav-tabs-border-color:  #374151;
  --bs-nav-link-color:         #9ca3af;
  /* Misc */
  color-scheme: dark;
}

/* ── Dark mode component-level fixes ── */

/* Cards */
[data-theme="dark"] .card { color: #f1f5f9; }
[data-theme="dark"] .card-header { color: #f1f5f9; }
[data-theme="dark"] .card-footer {
  background-color: rgba(255,255,255,.04);
  border-color: #374151;
}

/* Form controls */
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-check-input:not(:checked) {
  background-color: #111827;
  border-color: #374151;
  color: #f1f5f9;
}
[data-theme="dark"] .form-control::placeholder { color: #6b7280; }
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
  background-color: #111827;
  border-color: var(--primary);
  color: #f1f5f9;
  box-shadow: 0 0 0 .2rem rgba(99,102,241,.25);
}
[data-theme="dark"] .input-group-text {
  background-color: #111827;
  border-color: #374151;
  color: #cbd5e1;
}

/* Tables */
/* Light theme — override all table headers to gray */
thead.table-light > tr > th,
thead.table-dark  > tr > th {
  background-color: #d1d5db !important;
  color: #1f2937 !important;
  border-color: #c3c8d0 !important;
}
[data-theme="dark"] .table { color: #e5e7eb; }
[data-theme="dark"] .table td,
[data-theme="dark"] .table th { border-color: #374151; color: #e5e7eb; }
[data-theme="dark"] .table-light,
[data-theme="dark"] thead.table-light th,
[data-theme="dark"] thead.table-dark th,
[data-theme="dark"] .table > thead > tr > th {
  background-color: #111827 !important;
  color: #e5e7eb !important;
  border-color: #374151 !important;
}
[data-theme="dark"] .table-hover > tbody > tr:hover > td { background-color: rgba(255,255,255,.07); }

/* Badges — fix text-dark badges */
[data-theme="dark"] .badge.text-dark,
[data-theme="dark"] .badge.text-bg-warning,
[data-theme="dark"] .badge.text-bg-info,
[data-theme="dark"] .badge.text-bg-light { color: #111827 !important; }

/* Modals */
[data-theme="dark"] .modal-content { background-color: #1f2937; color: #f1f5f9; border: 1px solid #374151; }
[data-theme="dark"] .modal-header, [data-theme="dark"] .modal-footer { border-color: #374151; }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* Alerts */
[data-theme="dark"] .alert-danger  { background-color: #3f0a0a; border-color: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .alert-success { background-color: #052e16; border-color: #166534; color: #86efac; }
[data-theme="dark"] .alert-warning { background-color: #261900; border-color: #854d0e; color: #fde68a; }
[data-theme="dark"] .alert-info    { background-color: #0c2340; border-color: #0e4272; color: #67e8f9; }

/* Misc */
[data-theme="dark"] .text-muted    { color: #9ca3af !important; }
[data-theme="dark"] .text-dark     { color: #f1f5f9 !important; }
[data-theme="dark"] .bg-light      { background-color: #1f2937 !important; }
[data-theme="dark"] .bg-white      { background-color: #1f2937 !important; }
[data-theme="dark"] hr             { border-color: #374151; }
[data-theme="dark"] .border,
[data-theme="dark"] .border-bottom,
[data-theme="dark"] .border-top,
[data-theme="dark"] .border-start,
[data-theme="dark"] .border-end    { border-color: #374151 !important; }
[data-theme="dark"] .list-group-item { background-color: #1f2937; color: #f1f5f9; border-color: #374151; }
[data-theme="dark"] .nav-tabs .nav-link { color: #9ca3af; border-color: #374151; }
[data-theme="dark"] .nav-tabs .nav-link.active { background-color: #1f2937; border-color: #374151 #374151 #1f2937; color: #f1f5f9; }
[data-theme="dark"] .progress { background-color: #374151; }
[data-theme="dark"] code { background: #1e1b4b; color: #a5b4fc; }
[data-theme="dark"] .fw-bold { color: inherit; }

/* ═══════════════════════════════════════════════════════
   PINK THEME  (Rose Blossom)
   ═══════════════════════════════════════════════════════ */
[data-theme="pink"] {
  /* Sidebar */
  --sidebar-bg:           #fce4ec;
  --sidebar-text:         #880e4f;
  --sidebar-brand-border: #f8bbd0;
  --sidebar-hover-bg:     #f8bbd0;
  --sidebar-hover-text:   #560027;
  --sidebar-active-bg:    rgba(233,30,99,.12);
  --sidebar-active-text:  #c2185b;
  --sidebar-active-bar:   #e91e63;
  --sidebar-group-text:   #f48fb1;
  --sidebar-icon:         #e91e63;

  /* Layout */
  --body-bg:      #fdf0f5;
  --topbar-bg:    #ffffff;
  --topbar-border:#f8bbd0;
  --card-bg:      #ffffff;
  --card-border:  #f8bbd0;

  /* Brand */
  --primary:      #e91e63;
  --primary-rgb:  233,30,99;
  --primary-light:#fce4ec;
  --primary-text: #ffffff;

  /* Text */
  --text-main:    #3b0a22;
  --text-muted:   #9e617b;
}

/* ── Override Bootstrap CSS variables for pink theme ── */
[data-theme="pink"] {
  --bs-body-color:             #3b0a22;
  --bs-body-color-rgb:         59, 10, 34;
  --bs-body-bg:                #fdf0f5;
  --bs-body-bg-rgb:            253, 240, 245;
  --bs-secondary-color:        #9e617b;
  --bs-secondary-color-rgb:    158, 97, 123;
  --bs-emphasis-color:         #3b0a22;
  --bs-emphasis-color-rgb:     59, 10, 34;
  --bs-border-color:           #f8bbd0;
  --bs-border-color-translucent: rgba(233,30,99,.15);
  --bs-card-bg:                #ffffff;
  --bs-card-cap-bg:            rgba(233,30,99,.04);
  --bs-card-cap-color:         #3b0a22;
  --bs-card-border-color:      #f8bbd0;
  --bs-card-color:             #3b0a22;
  --bs-table-color:            #3b0a22;
  --bs-table-bg:               transparent;
  --bs-table-border-color:     #f8bbd0;
  --bs-table-striped-color:    #3b0a22;
  --bs-table-striped-bg:       rgba(233,30,99,.03);
  --bs-table-hover-color:      #3b0a22;
  --bs-table-hover-bg:         rgba(233,30,99,.06);
  --bs-dropdown-bg:            #ffffff;
  --bs-dropdown-border-color:  #f8bbd0;
  --bs-dropdown-link-color:    #3b0a22;
  --bs-dropdown-link-hover-bg: #fce4ec;
  --bs-dropdown-divider-bg:    #f8bbd0;
  --bs-list-group-bg:          #ffffff;
  --bs-list-group-border-color:#f8bbd0;
  --bs-list-group-color:       #3b0a22;
  --bs-nav-tabs-border-color:  #f8bbd0;
  --bs-nav-link-color:         #c2185b;
  color-scheme: light;
}

/* ── Pink theme component-level fixes ── */
[data-theme="pink"] .card { color: #3b0a22; }
[data-theme="pink"] .card-header { color: #3b0a22; background-color: rgba(233,30,99,.04); }
[data-theme="pink"] .card-footer { background-color: rgba(233,30,99,.03); border-color: #f8bbd0; }
[data-theme="pink"] .form-control,
[data-theme="pink"] .form-select,
[data-theme="pink"] .form-check-input:not(:checked) {
  background-color: #fff;
  border-color: #f48fb1;
  color: #3b0a22;
}
[data-theme="pink"] .form-control::placeholder { color: #c2849a; }
[data-theme="pink"] .form-control:focus,
[data-theme="pink"] .form-select:focus {
  background-color: #fff;
  border-color: var(--primary);
  color: #3b0a22;
  box-shadow: 0 0 0 .2rem rgba(233,30,99,.2);
}
[data-theme="pink"] .input-group-text {
  background-color: #fce4ec;
  border-color: #f48fb1;
  color: #880e4f;
}
[data-theme="pink"] .table { color: #3b0a22; }
[data-theme="pink"] .table td,
[data-theme="pink"] .table th { border-color: #f8bbd0; color: #3b0a22; }
[data-theme="pink"] .table-light,
[data-theme="pink"] thead.table-light th,
[data-theme="pink"] thead.table-dark th,
[data-theme="pink"] .table > thead > tr > th {
  background-color: #fce4ec !important;
  color: #880e4f !important;
  border-color: #f8bbd0 !important;
}
[data-theme="pink"] .table-hover > tbody > tr:hover > td { background-color: rgba(233,30,99,.06); }
[data-theme="pink"] .modal-content { background-color: #ffffff; color: #3b0a22; border: 1px solid #f8bbd0; }
[data-theme="pink"] .modal-header,
[data-theme="pink"] .modal-footer { border-color: #f8bbd0; background-color: #fce4ec; }
[data-theme="pink"] .alert-danger  { background-color: #fce4ec; border-color: #e91e63; color: #880e4f; }
[data-theme="pink"] .alert-success { background-color: #e8f5e9; border-color: #43a047; color: #1b5e20; }
[data-theme="pink"] .alert-warning { background-color: #fff8e1; border-color: #f9a825; color: #6d4c00; }
[data-theme="pink"] .alert-info    { background-color: #e3f2fd; border-color: #1e88e5; color: #0d47a1; }
[data-theme="pink"] .text-muted    { color: #9e617b !important; }
[data-theme="pink"] .text-dark     { color: #3b0a22 !important; }
[data-theme="pink"] .bg-light      { background-color: #fce4ec !important; }
[data-theme="pink"] .bg-white      { background-color: #ffffff !important; }
[data-theme="pink"] hr             { border-color: #f8bbd0; }
[data-theme="pink"] .border,
[data-theme="pink"] .border-bottom,
[data-theme="pink"] .border-top,
[data-theme="pink"] .border-start,
[data-theme="pink"] .border-end    { border-color: #f8bbd0 !important; }
[data-theme="pink"] .list-group-item { background-color: #fff; color: #3b0a22; border-color: #f8bbd0; }
[data-theme="pink"] .nav-tabs .nav-link { color: #c2185b; border-color: #f8bbd0; }
[data-theme="pink"] .nav-tabs .nav-link.active { background-color: #fff; border-color: #f8bbd0 #f8bbd0 #fff; color: #e91e63; }
[data-theme="pink"] .progress { background-color: #fce4ec; }
[data-theme="pink"] code { background: #fce4ec; color: #c2185b; }
[data-theme="pink"] .fw-bold { color: inherit; }
[data-theme="pink"] .btn-close { filter: none; }

/* ═══════════════════════════════════════════════════════
   DEEP TEAL THEME  (Teal + Amber)
   ═══════════════════════════════════════════════════════ */
[data-theme="teal"] {
  /* Sidebar */
  --sidebar-bg:           linear-gradient(180deg, #15464a 0%, #10393c 100%);
  --sidebar-text:         #bcd6d6;
  --sidebar-brand-border: rgba(255,255,255,.08);
  --sidebar-hover-bg:     rgba(255,255,255,.06);
  --sidebar-hover-text:   #ffffff;
  --sidebar-active-bg:    rgba(255,255,255,.10);
  --sidebar-active-text:  #ffffff;
  --sidebar-active-bar:   #f0a93b;
  --sidebar-group-text:   #7fa4a5;
  --sidebar-icon:         #f0a93b;

  /* Layout */
  --body-bg:      #f3f7f6;
  --topbar-bg:    #ffffff;
  --topbar-border:#e0eae8;
  --card-bg:      #ffffff;
  --card-border:  #e0eae8;

  /* Brand */
  --primary:      #0f7d6f;
  --primary-rgb:  15,125,111;
  --primary-light:#e3f3f0;
  --primary-text: #ffffff;

  /* Text */
  --text-main:    #1e3230;
  --text-muted:   #6f8483;
}

/* ── Override Bootstrap CSS variables for deep teal ── */
[data-theme="teal"] {
  --bs-body-color:             #1e3230;
  --bs-body-color-rgb:         30, 50, 48;
  --bs-body-bg:                #f3f7f6;
  --bs-body-bg-rgb:            243, 247, 246;
  --bs-secondary-color:        #6f8483;
  --bs-secondary-color-rgb:    111, 132, 131;
  --bs-emphasis-color:         #1e3230;
  --bs-emphasis-color-rgb:     30, 50, 48;
  --bs-border-color:           #e0eae8;
  --bs-border-color-translucent: rgba(15,125,111,.15);
  --bs-card-bg:                #ffffff;
  --bs-card-cap-bg:            rgba(15,125,111,.04);
  --bs-card-cap-color:         #1e3230;
  --bs-card-border-color:      #e0eae8;
  --bs-card-color:             #1e3230;
  --bs-table-color:            #1e3230;
  --bs-table-bg:               transparent;
  --bs-table-border-color:     #e0eae8;
  --bs-table-striped-color:    #1e3230;
  --bs-table-striped-bg:       rgba(15,125,111,.03);
  --bs-table-hover-color:      #1e3230;
  --bs-table-hover-bg:         #f4faf8;
  --bs-dropdown-bg:            #ffffff;
  --bs-dropdown-border-color:  #e0eae8;
  --bs-dropdown-link-color:    #1e3230;
  --bs-dropdown-link-hover-bg: #e3f3f0;
  --bs-dropdown-divider-bg:    #e0eae8;
  --bs-list-group-bg:          #ffffff;
  --bs-list-group-border-color:#e0eae8;
  --bs-list-group-color:       #1e3230;
  --bs-nav-tabs-border-color:  #e0eae8;
  --bs-nav-link-color:         #0f7d6f;
  color-scheme: light;
}

/* ── Deep teal theme component-level fixes ── */
[data-theme="teal"] .card { color: #1e3230; }
[data-theme="teal"] .card-header { color: #1e3230; background-color: rgba(15,125,111,.04); }
[data-theme="teal"] .card-footer { background-color: rgba(15,125,111,.03); border-color: #e0eae8; }
[data-theme="teal"] .form-control,
[data-theme="teal"] .form-select,
[data-theme="teal"] .form-check-input:not(:checked) {
  background-color: #fff;
  border-color: #cfe0dd;
  color: #1e3230;
}
[data-theme="teal"] .form-control::placeholder { color: #93a8a6; }
[data-theme="teal"] .form-control:focus,
[data-theme="teal"] .form-select:focus {
  background-color: #fff;
  border-color: var(--primary);
  color: #1e3230;
  box-shadow: 0 0 0 .2rem rgba(15,125,111,.2);
}
[data-theme="teal"] .input-group-text {
  background-color: #e8f1ef;
  border-color: #cfe0dd;
  color: #3e5a57;
}
[data-theme="teal"] .table { color: #1e3230; }
[data-theme="teal"] .table td,
[data-theme="teal"] .table th { border-color: #e0eae8; color: #1e3230; }
[data-theme="teal"] .table-light,
[data-theme="teal"] thead.table-light th,
[data-theme="teal"] thead.table-dark th,
[data-theme="teal"] .table > thead > tr > th {
  background-color: #e8f1ef !important;
  color: #3e5a57 !important;
  border-color: #e0eae8 !important;
}
[data-theme="teal"] .table-hover > tbody > tr:hover > td { background-color: #f4faf8; }
[data-theme="teal"] .modal-content { background-color: #ffffff; color: #1e3230; border: 1px solid #e0eae8; }
[data-theme="teal"] .modal-header,
[data-theme="teal"] .modal-footer { border-color: #e0eae8; background-color: #e7f0ee; }
[data-theme="teal"] .alert-danger  { background-color: #fdecea; border-color: #e53935; color: #8a1c14; }
[data-theme="teal"] .alert-success { background-color: #e6f4f1; border-color: #0f7d6f; color: #0b4f47; }
[data-theme="teal"] .alert-warning { background-color: #fcefd9; border-color: #f0a93b; color: #7a4e08; }
[data-theme="teal"] .alert-info    { background-color: #e3f2fd; border-color: #1e88e5; color: #0d47a1; }
[data-theme="teal"] .text-muted    { color: #6f8483 !important; }
[data-theme="teal"] .text-dark     { color: #1e3230 !important; }
[data-theme="teal"] .bg-light      { background-color: #e7f0ee !important; }
[data-theme="teal"] .bg-white      { background-color: #ffffff !important; }
[data-theme="teal"] hr             { border-color: #e0eae8; }
[data-theme="teal"] .border,
[data-theme="teal"] .border-bottom,
[data-theme="teal"] .border-top,
[data-theme="teal"] .border-start,
[data-theme="teal"] .border-end    { border-color: #e0eae8 !important; }
[data-theme="teal"] .list-group-item { background-color: #fff; color: #1e3230; border-color: #e0eae8; }
[data-theme="teal"] .nav-tabs .nav-link { color: #0f7d6f; border-color: #e0eae8; }
[data-theme="teal"] .nav-tabs .nav-link.active { background-color: #fff; border-color: #e0eae8 #e0eae8 #fff; color: #0b665b; }
[data-theme="teal"] .progress { background-color: #e3f3f0; }
[data-theme="teal"] code { background: #e3f3f0; color: #0b665b; }
[data-theme="teal"] .fw-bold { color: inherit; }
[data-theme="teal"] .btn-close { filter: none; }

/* ── Deep teal: warm the large content pages with a hint of teal ── */
/* Topbar: soft teal wash + teal accent line so the page header reads teal */
[data-theme="teal"] .topbar {
  background: linear-gradient(180deg, #ffffff 0%, #f1f8f6 100%);
  border-bottom: 1px solid #cfe3df;
  box-shadow: 0 2px 8px rgba(15,125,111,.07);
}
[data-theme="teal"] .page-title { color: var(--primary); }
/* Content backdrop: a teal wash at the top that fades into the body */
[data-theme="teal"] .content-area {
  background:
    linear-gradient(180deg, rgba(15,125,111,.07) 0%, rgba(15,125,111,0) 220px),
    var(--body-bg);
}
/* Cards: teal top accent + tinted header so big list/table pages feel themed */
[data-theme="teal"] .card {
  border-top: 2px solid rgba(15,125,111,.35);
}
[data-theme="teal"] .card-header {
  background-color: #eaf4f1;
  border-bottom-color: #cfe3df;
}
/* Strengthen the table head tint a touch on the big tables */
[data-theme="teal"] .table > thead > tr > th { font-weight: 600; }

/* ══════════════════════════════════════════════════════
   BASE STYLES  (use variables throughout)
   ══════════════════════════════════════════════════════ */

body {
  background: var(--body-bg);
  font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  color: var(--text-main);
  transition: background 0.3s, color 0.3s;
}

/* Apply Tajawal globally including bootstrap components */
.btn, .form-control, .form-select, .form-label,
.modal, .modal-title, .table, .nav-link, .dropdown-menu,
.alert, .badge, .input-group-text {
  font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
}

/* Sidebar */
.sidebar {
  position: fixed; top: 0; right: 0;
  width: var(--sidebar-width); height: 100vh;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  transition: transform 0.3s, background 0.3s; z-index: 100;
}

/* LTR (English) layout overrides */
body.ltr .sidebar { right: auto; left: 0; }
body.ltr .sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-width))); }
body.ltr .main-content { margin-right: 0; margin-left: var(--sidebar-width); }
body.ltr .main-content.expanded { margin-left: 0; }
.sidebar.collapsed { transform: translateX(var(--sidebar-width)); }
.sidebar-brand {
  padding: 14px 16px; font-size: 0.78rem; font-weight: 700;
  border-bottom: 1px solid var(--sidebar-brand-border);
  display: flex; align-items: center; gap: 10px;
  color: #ffffff; line-height: 1.3;
}
/* Light theme: dark text on gray sidebar */
html:not([data-theme]) .sidebar-brand { color: #1f2937; }
[data-theme="pink"] .sidebar-brand { color: #880e4f; }
.sidebar-brand #sidebar-company-name {
  overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.sidebar-brand i { font-size: 1.4rem; color: var(--sidebar-icon); }
.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }

/* Group headers */
.nav-group-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; color: var(--sidebar-group-text); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; cursor: pointer;
  user-select: none; transition: color 0.2s;
  border-top: 1px solid rgba(255,255,255,.05); margin-top: 4px;
}
.nav-group-header:first-child { border-top: none; margin-top: 0; }
.nav-group-header .group-icon { font-size: 0.8rem; transition: transform 0.2s; }
.nav-group-header:not(.collapsed) .group-icon { transform: rotate(180deg); }
.nav-group-header .left { display: flex; align-items: center; gap: 7px; font-size: 0.78rem; color: var(--sidebar-text); }

/* Nav items */
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 16px 7px 20px; color: var(--sidebar-text); text-decoration: none;
  transition: all 0.15s; font-size: 0.85rem; border-right: 3px solid transparent;
}
.nav-item:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-hover-text); }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); border-right-color: var(--sidebar-active-bar); }
.nav-item i { width: 16px; font-size: 0.9rem; flex-shrink: 0; }

/* Dashboard item — no group */
.nav-item-top {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 16px; color: var(--sidebar-text); text-decoration: none;
  transition: all 0.15s; font-size: 0.88rem; border-right: 3px solid transparent;
}
.nav-item-top:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-hover-text); }
.nav-item-top.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); border-right-color: var(--sidebar-active-bar); }
.nav-item-top i { width: 17px; }

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

.topbar {
  background: var(--topbar-bg); padding: 12px 20px;
  border-bottom: 1px solid var(--topbar-border);
  display: flex; align-items: center; position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: background 0.3s, border-color 0.3s;
}
.page-title { font-weight: 600; color: var(--text-main); white-space: nowrap; }
.content-area { padding: 20px; flex: 1; }

/* تمرير أفقي سلس للجداول (مهم للمس على الموبايل) */
.table-responsive {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.table-responsive::-webkit-scrollbar { height: 7px; }
.table-responsive::-webkit-scrollbar-thumb {
  background: var(--card-border); border-radius: 4px;
}

/* Global Search */
.global-search-wrap { }
.global-search-wrap .input-group { border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 1px #dee2e6; transition: box-shadow 0.15s; }
.global-search-wrap .input-group:focus-within { box-shadow: 0 0 0 2px var(--primary); }
.global-search-wrap .form-control:focus { box-shadow: none; }
.global-search-dropdown { min-width: 320px; }
.gsr-section-title { font-size: 0.72rem; font-weight: 700; color: #6c757d; text-transform: uppercase; letter-spacing: .04em; padding: 8px 14px 4px; }
.gsr-item { display: flex; align-items: center; gap: 10px; padding: 8px 14px; cursor: pointer; transition: background 0.1s; text-decoration: none; color: inherit; }
.gsr-item:hover { background: #f8f9fa; }
.gsr-item .gsr-icon { width: 28px; height: 28px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; flex-shrink: 0; }
.gsr-item .gsr-main { font-size: 0.88rem; font-weight: 500; }
.gsr-item .gsr-sub { font-size: 0.75rem; color: #6c757d; }
.gsr-empty { padding: 20px; text-align: center; color: #adb5bd; font-size: 0.9rem; }

/* Pages */
.page { display: none; }
.page.active { display: block; }

/* Stat Cards */
.stat-card {
  border-radius: 12px; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  height: 100%; min-height: 168px;
}
.stat-icon { font-size: 1.8rem; opacity: 0.85; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; opacity: 0.9; }
.stat-sub { font-size: 0.75rem; opacity: 0.75; }

/* Cards */
.card {
  border: 1px solid var(--card-border) !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  border-radius: 10px;
  background: var(--card-bg);
  transition: background 0.3s, border-color 0.3s;
}
.card-header {
  background: var(--topbar-bg);
  font-weight: 600; font-size: 0.9rem;
  border-bottom: 1px solid var(--card-border);
  color: var(--text-main);
  transition: background 0.3s;
}

/* Tables */
.table th { font-size: 0.82rem; color: var(--text-muted); }
.table td { font-size: 0.85rem; vertical-align: middle; color: var(--text-main); }

/* Invoice items */
.inv-item-row input { font-size: 0.82rem; }

/* ─── Invoice Summary Rows ──────────────────────────────────── */
tr.inv-row-total > td   { background: #d1fae5; color: #065f46 !important; font-weight: 600; }
tr.inv-row-paid > td    { background: #dbeafe; color: #1e40af !important; }
tr.inv-row-remaining > td { background: #fef3c7; color: #92400e !important; font-weight: 600; }
tr.inv-row-remaining .fw-bold { color: #dc2626 !important; }
[data-theme="dark"] tr.inv-row-total > td   { background: #064e3b; color: #6ee7b7 !important; }
[data-theme="dark"] tr.inv-row-paid > td    { background: #1e3a5f; color: #93c5fd !important; }
[data-theme="dark"] tr.inv-row-remaining > td { background: #451a03; color: #fcd34d !important; }
[data-theme="dark"] tr.inv-row-remaining .fw-bold { color: #f87171 !important; }
/* Dark mode: quotation (table-success) & PO (table-primary) total rows */
[data-theme="dark"] tr.table-success > td,
[data-theme="dark"] tr.table-success > th { background: #064e3b !important; color: #6ee7b7 !important; }
[data-theme="dark"] tr.table-primary > td,
[data-theme="dark"] tr.table-primary > th { background: #1e3a5f !important; color: #93c5fd !important; }
/* inputs inside summary rows */
tr.inv-row-paid input.form-control { background: transparent; border-color: rgba(255,255,255,.3); color: inherit; }

/* ─── Inventory Report Row Colors ───────────────────────────── */
tr.rinv-row-out > td { background: #fee2e2; color: #991b1b !important; font-weight: 600; }
tr.rinv-row-low > td { background: #fef9c3; color: #713f12 !important; }
[data-theme="dark"] tr.rinv-row-out > td { background: #450a0a; color: #fca5a5 !important; font-weight: 600; }
[data-theme="dark"] tr.rinv-row-low > td { background: #422006; color: #fde68a !important; }

/* Suggestions */
/* ─── Searchable Select ─────────────────────────────────────── */
.ss-wrap { position: relative; flex: 1 1 auto; min-width: 0; }
.ss-display {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 10px; border: 1px solid var(--input-border, #ced4da);
  border-radius: 6px; cursor: pointer; background: var(--card-bg, #fff);
  min-height: 31px; font-size: .875rem; color: var(--text-main, #212529);
  user-select: none; gap: 6px;
}
.ss-display:hover { border-color: #86b7fe; }
/* مقاس مصغّر ليطابق ارتفاع form-control-sm في صفوف الفلاتر */
.ss-sm .ss-display { min-height: 31px; padding: 2px 8px; font-size: .8125rem; }
.ss-wrap.open .ss-display { border-color: #86b7fe; box-shadow: 0 0 0 3px rgba(13,110,253,.15); }
.ss-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-label.placeholder { color: #6c757d; }
.ss-arrow { font-size: .7rem; color: #6c757d; transition: transform .18s; flex-shrink: 0; }
.ss-wrap.open .ss-arrow { transform: rotate(180deg); }
.ss-dropdown {
  position: absolute; top: calc(100% + 3px); left: 0; right: 0; z-index: 1055;
  background: var(--card-bg, #fff); border: 1px solid var(--card-border, #dee2e6);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.ss-search-wrap { padding: 6px 8px; border-bottom: 1px solid var(--card-border, #dee2e6); }
.ss-search { border-radius: 5px !important; font-size: .85rem; }
.ss-list { max-height: 220px; overflow-y: auto; }
.ss-item {
  padding: 7px 12px; cursor: pointer; font-size: .875rem;
  color: var(--text-main, #212529); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  text-align: start;            /* محاذاة حسب اتجاه الصفحة (يمين في العربية) */
}
/* تأكيد محاذاة عناصر القائمة والنص المختار من اليمين في الواجهة العربية */
[dir="rtl"] .ss-item,
[dir="rtl"] .ss-label,
[dir="rtl"] .ss-search { text-align: right; }
.ss-item:hover { background: var(--primary-light, #e8f0fe); }
.ss-item.ss-selected { background: #e8f4ff; font-weight: 600; }
.ss-item.ss-empty-opt { color: #6c757d; font-style: italic; }
.ss-item.ss-no-result { color: #adb5bd; cursor: default; text-align: center; font-size: .82rem; }
[data-theme="dark"] .ss-display { background: #1f2937; border-color: #374151; color: #f1f5f9; }
[data-theme="dark"] .ss-dropdown { background: #1f2937; border-color: #374151; }
[data-theme="dark"] .ss-item:hover { background: #374151; }
[data-theme="dark"] .ss-item.ss-selected { background: #1e3a5f; }

.suggestions-box {
  position: absolute; z-index: 1000;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 6px; max-height: 200px; overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1); min-width: 250px;
}
.suggestion-item {
  padding: 8px 12px; cursor: pointer; font-size: 0.85rem;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--topbar-border);
  color: var(--text-main);
}
.suggestion-item:hover { background: var(--primary-light); }
.suggestion-item .price { color: var(--primary); font-weight: 600; font-size: 0.8rem; }
.suggestion-item .s-name  { display: flex; flex-direction: column; gap: 3px; }
.suggestion-item .s-stock { display: flex; flex-wrap: wrap; gap: 4px; }
.suggestion-item .s-chip  { display: inline-flex; align-items: center; gap: 3px;
                             font-size: 0.7rem; padding: 1px 5px; border-radius: 4px; }
.suggestion-item .s-chip.my-branch    { background: rgba(99,102,241,0.12); }
.suggestion-item .s-chip.other-branch { background: rgba(34,197,94,0.1); }
.suggestion-item .s-qty   { font-weight: 700; }
.suggestion-item .s-qty.in-stock  { color: #22c55e; }
.suggestion-item .s-qty.low-stock { color: #f59e0b; }
.suggestion-item .s-qty.no-stock  { color: #ef4444; }
.suggestion-item .s-branch { color: var(--text-muted); }

/* Badge */
.badge-paid    { background: #dcfce7; color: #166534; padding:3px 8px; border-radius:20px; font-size:.75rem; font-weight:600; }
.badge-unpaid  { background: #fef9c3; color: #92400e; padding:3px 8px; border-radius:20px; font-size:.75rem; font-weight:600; }
.badge-cancelled { background: #fee2e2; color: #991b1b; padding:3px 8px; border-radius:20px; font-size:.75rem; font-weight:600; }
.badge-pending { background: #e0f2fe; color: #075985; padding:3px 8px; border-radius:20px; font-size:.75rem; font-weight:600; }
.badge-converted { background: #f0fdf4; color: #166534; padding:3px 8px; border-radius:20px; font-size:.75rem; font-weight:600; }
.bg-purple { background-color: #7c3aed !important; color: #fff; }

/* ══════════════════════════════════════════════════════
   LOGIN SCREEN
   ══════════════════════════════════════════════════════ */
.login-screen {
  display: flex; /* ظاهرة افتراضياً لمنع وميض التطبيق قبل التحقق من الجلسة */
  position: fixed; inset: 0; z-index: 9999;
  background: var(--body-bg);
  align-items: center; justify-content: center;
  overflow: auto;
  font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
}
.login-screen.show { display: flex; }

/* الهيكل المقسوم نصفين */
.login-shell {
  display: flex;
  width: 960px; max-width: calc(100% - 32px);
  min-height: 560px;
  margin: 24px auto;
  background: var(--card-bg);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 30px 70px -20px rgba(15,23,42,.35), 0 0 0 1px var(--card-border);
  animation: loginFadeIn .5s ease-out;
}
@keyframes loginFadeIn {
  from { opacity: 0; transform: translateY(20px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── اللوحة التعريفية (Brand) ── */
.login-aside {
  position: relative;
  flex: 0 0 44%;
  padding: 48px 40px;
  display: flex; flex-direction: column; justify-content: center;
  background: var(--login-grad);
  color: #fff;
  overflow: hidden;
}
.login-aside-shapes { position: absolute; inset: 0; pointer-events: none; }
.login-aside-shapes .shape {
  position: absolute; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.25), transparent 70%);
  filter: blur(30px);
  animation: floatShape 14s ease-in-out infinite;
}
.login-aside-shapes .shape-1 { width: 260px; height: 260px; top: -70px; right: -70px; }
.login-aside-shapes .shape-2 {
  width: 220px; height: 220px; bottom: -60px; left: -50px;
  background: radial-gradient(circle, rgba(255,255,255,.18), transparent 70%);
  animation-delay: -5s;
}
.login-aside-shapes .shape-3 {
  width: 160px; height: 160px; top: 45%; left: 30%;
  background: radial-gradient(circle, rgba(255,255,255,.12), transparent 70%);
  animation-delay: -9s;
}
@keyframes floatShape {
  0%, 100% { transform: translate(0,0) scale(1); }
  50% { transform: translate(18px, -26px) scale(1.08); }
}
.login-aside-content { position: relative; z-index: 1; }
.login-logo {
  width: 132px;
  margin-bottom: 22px;
  background: #fff;
  border-radius: 18px;
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 12px 28px rgba(0,0,0,.22);
}
.login-logo img { width: 100%; height: auto; display: block; }
.login-brand-name { margin: 0; font-size: 2rem; font-weight: 800; letter-spacing: .5px; }
.login-brand-tagline { margin: 8px 0 28px; font-size: 1rem; opacity: .92; font-weight: 500; }
.login-features { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.login-features li { display: flex; align-items: center; gap: 12px; font-size: .95rem; font-weight: 500; opacity: .96; }
.login-features li i {
  flex-shrink: 0;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.16);
  border-radius: 10px;
  font-size: .95rem;
}

/* ── لوحة النموذج ── */
.login-main {
  flex: 1 1 56%;
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  background: var(--card-bg);
}
.login-main-inner { width: 100%; max-width: 360px; }

.login-lang-row { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.login-lang-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent;
  border: 1px solid var(--login-field-border);
  color: var(--text-muted); cursor: pointer;
  padding: 6px 14px; border-radius: 20px;
  font-size: .82rem; font-weight: 700; font-family: inherit;
  transition: color .2s, border-color .2s, background .2s;
}
.login-lang-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: rgba(var(--primary-rgb), .07);
}

.login-mobile-logo { display: none; }
.login-mobile-logo img { width: 120px; height: auto; }

.login-welcome { margin-bottom: 24px; }
.login-welcome h2 { margin: 0; font-size: 1.5rem; font-weight: 800; color: var(--text-main); }
.login-welcome p { margin: 6px 0 0; font-size: .9rem; color: var(--text-muted); font-weight: 500; }

.login-version {
  margin-top: 26px;
  text-align: center;
  font-size: .78rem; font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .4px;
}

.login-body { padding: 0; }
.login-field { margin-bottom: 18px; }
.login-label {
  display: block; margin-bottom: 6px;
  font-size: .85rem; font-weight: 700; color: var(--text-main);
}
.login-input-wrap {
  position: relative;
  display: flex; align-items: center;
}
.login-input {
  width: 100%;
  padding: 12px 44px 12px 14px;
  font-size: .95rem; font-weight: 500;
  border: 2px solid var(--login-field-border);
  border-radius: 10px;
  background: var(--login-field-bg);
  color: var(--text-main);
  transition: all .2s;
  font-family: inherit;
}
.login-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--card-bg);
  box-shadow: 0 0 0 4px rgba(var(--primary-rgb), .15);
}
.login-input-icon {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 1rem; pointer-events: none;
  transition: color .2s;
}
.login-input:focus ~ .login-input-icon,
.login-input-wrap:focus-within .login-input-icon { color: var(--primary); }

.login-eye-btn {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none;
  color: var(--text-muted); cursor: pointer;
  padding: 6px 8px; border-radius: 6px;
  transition: color .2s, background .2s;
}
.login-eye-btn:hover { color: var(--primary); background: rgba(var(--primary-rgb), .08); }

.login-btn {
  width: 100%;
  padding: 12px;
  font-size: 1rem; font-weight: 700;
  color: #fff;
  background: var(--login-grad);
  border: none;
  border-radius: 10px;
  box-shadow: 0 8px 18px -6px rgba(var(--primary-rgb), .55);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, filter .15s;
  font-family: inherit;
  letter-spacing: .3px;
}
.login-btn:hover { transform: translateY(-1px); box-shadow: 0 12px 24px -8px rgba(var(--primary-rgb), .65); filter: brightness(1.05); }
.login-btn:active { transform: translateY(0); }

/* استجابة الجوال — إخفاء اللوحة التعريفية وإظهار الشعار المصغّر */
@media (max-width: 768px) {
  .login-shell {
    flex-direction: column;
    width: 420px;
    min-height: 0;
    border-radius: 20px;
  }
  .login-aside { display: none; }
  .login-main { padding: 32px 26px; }
  .login-mobile-logo {
    display: flex; justify-content: center;
    margin-bottom: 18px;
  }
  .login-mobile-logo img {
    background: var(--login-grad);
    padding: 10px 14px; border-radius: 16px;
    box-shadow: 0 10px 24px -8px rgba(var(--primary-rgb), .5);
  }
}

/* Topbar user info */
#topbar-name { color: var(--text-main); }

/* Users page */
code { background: var(--primary-light); padding: 2px 6px; border-radius: 4px; font-size: 0.85rem; color: var(--primary); }

/* Account Transactions */
#tx-summary { display: none; }
#tx-tbody tr:hover td { background: var(--primary-light); }

/* Return Badges */
.badge-full-return {
  background: #fee2e2; color: #991b1b;
  padding: 3px 8px; border-radius: 20px; font-size: .72rem; font-weight: 600;
}
.badge-partial-return {
  background: #fef9c3; color: #854d0e;
  padding: 3px 8px; border-radius: 20px; font-size: .72rem; font-weight: 600;
}
.table-returned-full  > td:first-child { border-right: 3px solid #ef4444; }
.table-returned-partial > td:first-child { border-right: 3px solid #f59e0b; }

.btn-xs { padding: 2px 7px; font-size: 0.75rem; border-radius: 4px; }

/* ── Theme Switcher (Light / Dark only) ───────────────── */
.theme-switcher {
  display: flex; gap: 12px;
  flex-wrap: wrap;
}
.theme-option {
  flex: 1; min-width: 160px;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border: 2px solid var(--card-border);
  border-radius: 12px;
  background: var(--card-bg);
  cursor: pointer;
  transition: all .2s;
  user-select: none;
}
.theme-option:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 6px 14px rgba(0,0,0,.08); }
.theme-option.active { border-color: var(--primary); background: var(--primary-light); }
.theme-option .theme-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: #fff;
  flex-shrink: 0;
}
.theme-option[data-theme="default"] .theme-icon {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
}
.theme-option[data-theme="dark"] .theme-icon {
  background: linear-gradient(135deg, #4338ca, #1e1b4b);
}
.theme-option .theme-text { display: flex; flex-direction: column; }
.theme-option .theme-name { font-weight: 700; font-size: .95rem; color: var(--text-main); }
.theme-option .theme-desc { font-size: .75rem; color: var(--text-muted); }
.theme-option .theme-check {
  margin-right: auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--card-border);
  display: flex; align-items: center; justify-content: center;
  color: #fff; transition: all .2s;
}
.theme-option.active .theme-check {
  background: var(--primary);
  border-color: var(--primary);
}
.theme-option .theme-check i { font-size: .7rem; opacity: 0; transition: opacity .2s; }
.theme-option.active .theme-check i { opacity: 1; }

/* ── Topbar theme dropdown checkmarks ── */
.theme-pick-btn .theme-active-check { display: none; }
.theme-pick-btn.active .theme-active-check { display: inline-block; }

/* ══ Invoice / Document Print Design ══════════════════════ */
.print-area {
  font-family: 'Tajawal', 'Segoe UI', 'Cairo', Tahoma, Arial, sans-serif;
  color: #1a1a1a; direction: rtl; max-width: 860px; margin: 0 auto;
}

/* 1 ── Top: logo + company names — داخل مربع */
.inv-top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border: 1.5px solid #ccc;
  border-radius: 6px;
  margin-bottom: 10px;
}
.inv-company-ar { font-size: 21px; font-weight: 700; line-height: 1.3; }
.inv-company-en { font-size: 14px; font-weight: 600; color: #444; margin-top: 3px; }
.inv-logo img   { max-height: 80px; max-width: 160px; object-fit: contain; }

/* 2 ── Info grid: two columns بدون خلفية سوداء */
.inv-info-grid {
  display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px;
}
.inv-info-col       { flex: 1; display: flex; flex-direction: column; gap: 0; border: 1px solid #ccc; border-radius: 4px; overflow: hidden; }
.inv-info-item      { display: flex; align-items: stretch; border-bottom: 1px solid #e5e5e5; flex: 1; }
.inv-info-item:last-child { border-bottom: none; }
.inv-info-col-flip .inv-info-item { flex-direction: row-reverse; }

.inv-lbl {
  background: #f3f4f6; color: #374151; padding: 5px 10px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
  min-width: 90px; text-align: center; flex-shrink: 0;
  border-left: 1px solid #e5e5e5; display: flex; align-items: center; justify-content: center;
}
.inv-info-col-flip .inv-lbl { border-left: none; border-right: 1px solid #e5e5e5; }
.inv-val { font-size: 13px; color: #111; padding: 5px 10px; display: flex; align-items: center; }

/* 3 ── Document title */
.inv-title {
  text-align: center; font-size: 20px; font-weight: 700;
  margin: 12px 0 8px; letter-spacing: 0.5px;
}

/* ضغط رأس المستند في عرض السعر التفصيلي */
.print-area.dq-compact .inv-top { padding: 6px 14px; margin-bottom: 6px; }
.print-area.dq-compact .inv-company-ar { font-size: 17px; line-height: 1.2; }
.print-area.dq-compact .inv-company-en { font-size: 12px; margin-top: 1px; }
.print-area.dq-compact .inv-logo img { max-height: 50px; max-width: 120px; }
.print-area.dq-compact .inv-info-grid { margin-bottom: 6px; }
.print-area.dq-compact .inv-lbl,
.print-area.dq-compact .inv-val { padding: 2.5px 10px; }
.print-area.dq-compact .inv-lbl { font-size: 11.5px; }
.print-area.dq-compact .inv-val { font-size: 12.5px; }
.print-area.dq-compact .inv-title { font-size: 16px; margin: 6px 0 6px; }

/* 4 ── Items table */
.inv-items-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.inv-items-table th {
  border: 1px solid #444; padding: 8px 5px; text-align: center;
  background: #efefef; font-weight: 700; font-size: 12px; line-height: 1.35;
}
.inv-items-table td {
  border: 1px solid #888; padding: 7px 6px;
  text-align: center; vertical-align: middle;
}
.inv-items-table .td-item { text-align: right; padding-right: 10px; }
.inv-items-table .serial-list {
  margin-top: 4px;
  font-size: 11.5px;
  color: #374151;
  line-height: 1.5;
}
.inv-items-table .serial-label {
  font-weight: 700;
}

/* عرض السعر التفصيلي: كروت الأقسام + ملخص الأقسام (مضغوط لتقليل الصفحات) */
.dq-print-card {
  border: 1px solid #cbd5e1; border-radius: 6px;
  margin-bottom: 8px; overflow: hidden; page-break-inside: avoid;
}
.dq-print-card-head {
  background: #eef2ff; color: #1e293b; font-weight: 700; font-size: 12.5px;
  padding: 5px 12px; border-bottom: 1px solid #c7d2fe;
}
.dq-print-card .dq-print-table { font-size: 11.5px; }
.dq-print-card .dq-print-table th { background: #f6f7fb; padding: 4px 4px; font-size: 11px; }
.dq-print-card .dq-print-table td { padding: 3.5px 5px; }
.dq-print-card .dq-print-table,
.dq-print-card .dq-print-table th,
.dq-print-card .dq-print-table td { border-color: #d1d5db; }
.dq-print-summary { margin: 10px 0; page-break-inside: avoid; }
.dq-print-summary-title { font-weight: 700; font-size: 13px; margin-bottom: 5px; }
.dq-print-summary .inv-items-table th { padding: 5px 6px; }
.dq-print-summary .inv-items-table td { padding: 5px 8px; }
.dq-print-summary .inv-items-table td:last-child { direction: ltr; text-align: left; font-weight: 600; }
.dq-print-summary .dq-summary-grand td {
  background: #eef2ff; font-weight: 800; font-size: 13.5px; border-top: 2px solid #94a3b8;
}

/* 5 ── Bottom: payment method + totals */
.inv-bottom {
  display: flex; justify-content: space-between; align-items: stretch;
  border: 1.5px solid #ccc; border-radius: 6px;
  overflow: hidden; margin-top: 6px; margin-bottom: 18px;
}
/* صفحة دليل النظام (Documentation) */
.doc-wrap { max-width: 920px; margin: 0 auto; }
.doc-cat {
  font-weight: 800; margin: 0 0 .6rem; padding-bottom: .4rem;
  border-bottom: 2px solid var(--bs-primary, #0d6efd);
  color: var(--bs-primary, #0d6efd); scroll-margin-top: 80px;
}
.doc-wrap .accordion-button { font-weight: 700; }
.doc-wrap .accordion-body { line-height: 1.9; }
.doc-wrap .accordion-body ol,
.doc-wrap .accordion-body ul { padding-inline-start: 1.2rem; }
.doc-wrap .accordion-body li { margin-bottom: 4px; }
.doc-wrap .accordion-body em { font-style: normal; font-weight: 600; color: var(--bs-primary, #0d6efd); }

/* تحكّم مقطعي لحالة التوصيل في لوحة التوصيل */
.dlv-status-seg { display: inline-flex; gap: 4px; flex-wrap: nowrap; align-items: center; }
.dlv-seg-btn {
  border: 1.5px solid currentColor; background: transparent;
  border-radius: 7px; padding: 4px 8px; font-size: 12px; line-height: 1;
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  transition: background-color .15s, color .15s, box-shadow .15s;
}
.dlv-seg-btn:not(.active) { opacity: .65; }
.dlv-seg-btn:not(.active):hover { opacity: 1; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.dlv-seg-btn.active { border-color: transparent; font-weight: 700; cursor: default; box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.dlv-seg-lbl { white-space: nowrap; }

/* شريط معلومات التوصيل (السائق) أسفل ترويسة الفاتورة */
.inv-delivery-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 6px;
  padding: 6px 12px; margin: 8px 0; font-size: 12.5px; color: #334155;
}
.inv-delivery-bar i { color: #0ea5e9; }
.inv-delivery-bar .inv-del-lbl { color: #64748b; font-weight: 600; }

.inv-payment-box  { display: flex; align-items: center; flex: 1; }
.inv-payment-lbl  {
  background: #f3f4f6; color: #374151; padding: 8px 12px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
  align-self: stretch; display: flex; align-items: center;
  border-left: 1px solid #e5e5e5;
}
.inv-payment-desc { padding: 8px 12px; font-size: 13px; }
.inv-totals-side  { border-right: 1.5px solid #ccc; min-width: 230px; }
.inv-totals-side table { width: 100%; border-collapse: collapse; }
.inv-totals-side td { padding: 6px 12px; font-size: 13px; border-bottom: 1px solid #e5e5e5; }
.inv-totals-side td:first-child { color: #555; }
.inv-totals-side td:last-child { text-align: left; font-weight: 600; direction: ltr; }
.inv-totals-side tr:last-child td { border-bottom: none; }
/* صندوق المجاميع فقط (عرض السعر — بلا وسيلة دفع) */
.inv-bottom-totals-only { justify-content: flex-end; border: none; overflow: visible; }
.inv-bottom-totals-only .inv-totals-side {
  border: 1.5px solid #ccc; border-radius: 6px; overflow: hidden;
}
.inv-totals-side .inv-final td {
  font-size: 15px; font-weight: 700; background: #f3f4f6;
  border-top: 1.5px solid #ccc;
}

/* 6 ── Signatures */
.inv-signatures {
  display: flex; justify-content: space-between; margin: 16px 0 70px;
}
.inv-sign-col   { text-align: center; flex: 1; }
.inv-sign-dots  { color: #aaa; font-size: 15px; letter-spacing: 3px; margin-bottom: 5px; }
.inv-sign-label { font-size: 13px; font-weight: 600; }

/* 7 ── Notes */
.inv-notes { font-size: 12px; color: #333; line-height: 2.1; margin: 8px 0; }

/* 9 ── Terms & Conditions Box */
.inv-terms-box {
  border: 1px solid #ccc; border-radius: 5px;
  padding: 10px 14px; margin: 12px 0 8px;
  background: #fafafa;
}
.inv-terms-title {
  font-size: 12px; font-weight: 700; color: #333;
  margin-bottom: 6px; padding-bottom: 5px;
  border-bottom: 1px solid #e5e7eb;
}
.inv-terms-text {
  font-size: 11.5px; color: #555; line-height: 1.9;
}

/* 8 ── Footer — داخل مربع */
.inv-footer-box {
  border: 1.5px solid #ccc; border-radius: 6px;
  padding: 8px 16px; margin-top: 14px;
  display: flex; justify-content: center; align-items: center;
  font-size: 12px; color: #555; text-align: center;
  background: #fafafa;
}
.inv-footer-text { flex: 1; line-height: 1.7; }
.inv-footer-qr { flex-shrink: 0; display: flex; align-items: center; }
.inv-footer-qr img { width: 74px; height: 74px; display: block; }

/* ── Print Media ─────────────────────────────────────── */
@media print {
  /* ═══ إعادة تعيين الثيم للطباعة — دايمًا فاتح بغض النظر عن الثيم الحالي ═══ */
  html, html[data-theme="dark"] {
    color-scheme: light !important;
  }

  /* إلغاء CSS variables الداكنة */
  [data-theme="dark"] {
    --bs-body-color:         #212529 !important;
    --bs-body-color-rgb:     33, 37, 41 !important;
    --bs-body-bg:            #ffffff !important;
    --bs-card-bg:            #ffffff !important;
    --bs-card-color:         #212529 !important;
    --bs-table-color:        #212529 !important;
    --bs-table-border-color: #dee2e6 !important;
    --bs-border-color:       #dee2e6 !important;
    --text-main:             #212529 !important;
    --text-muted:            #6c757d !important;
    --card-bg:               #ffffff !important;
    --card-border:           #dee2e6 !important;
    --topbar-bg:             #ffffff !important;
    --body-bg:               #ffffff !important;
  }

  /* إجبار كل العناصر على ألوان الطباعة */
  [data-theme="dark"] body,
  [data-theme="dark"] .modal-content,
  [data-theme="dark"] .modal-body,
  [data-theme="dark"] .card,
  [data-theme="dark"] .card-body,
  [data-theme="dark"] .card-footer,
  [data-theme="dark"] .table,
  [data-theme="dark"] .table td,
  [data-theme="dark"] .table th {
    background-color: #ffffff !important;
    color: #212529 !important;
    border-color: #dee2e6 !important;
  }
  [data-theme="dark"] .text-muted { color: #6c757d !important; }
  [data-theme="dark"] .text-dark  { color: #212529 !important; }
  [data-theme="dark"] .fw-bold    { color: inherit !important; }
  [data-theme="dark"] .form-control,
  [data-theme="dark"] .form-select,
  [data-theme="dark"] .input-group-text {
    background-color: #f8f9fa !important;
    color: #212529 !important;
    border-color: #dee2e6 !important;
  }

  /* إخفاء كل شيء في الصفحة */
  body > * { display: none !important; }

  /* إظهار فقط مودال الطباعة */
  .printable-modal {
    display: block !important;
    position: static !important;
    width: 100% !important;
  }
  .printable-modal .modal-header,
  .printable-modal .modal-footer { display: none !important; }
  .printable-modal .modal-dialog {
    max-width: 100% !important;
    margin: 0 !important;
    position: static !important;
  }
  .printable-modal .modal-content {
    border: none !important;
    box-shadow: none !important;
    background-color: #ffffff !important;
    color: #212529 !important;
  }
  .printable-modal .modal-body { padding: 12px 20px !important; }

  body { background: white !important; color: #212529 !important; }

  /* الحفاظ على ألوان عناصر الفاتورة عند الطباعة */
  .inv-lbl, .inv-payment-lbl,
  .inv-items-table th,
  .inv-totals-side .inv-final td,
  .inv-footer-box {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Footer ثابت في أسفل الصفحة */
  .inv-footer-box {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    margin: 0 !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
    background: white !important;
    color: #555 !important;
  }

  .print-area { padding-bottom: 80px !important; }
  .print-area * { color: #000 !important; }
  .inv-terms-box {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    page-break-inside: avoid;
  }
  .print-area .serial-list { color: #374151 !important; }
  .print-area .serial-label { color: #111 !important; }
  .print-area .text-muted,
  .print-area .inv-company-en,
  .print-area .inv-lbl,
  .print-area .inv-payment-lbl { color: #374151 !important; }
  .print-area .inv-val { color: #111 !important; }
}

/* ══ Invoice Template Picker Cards ════════════════════ */
#invoice-template-picker { }
.inv-tpl-card {
  cursor: pointer; border: 2px solid #dee2e6; border-radius: 10px;
  overflow: hidden; width: 160px; transition: border-color .2s, box-shadow .2s;
  background: var(--card-bg, #fff);
}
.inv-tpl-card:hover { border-color: #0d6efd; box-shadow: 0 2px 12px rgba(13,110,253,.15); }
.inv-tpl-card.active { border-color: #0d6efd; box-shadow: 0 0 0 3px rgba(13,110,253,.2); }
.inv-tpl-card.active .inv-tpl-check { opacity: 1 !important; color: #0d6efd; }
.inv-tpl-name {
  padding: 6px 8px; font-size: 12px; font-weight: 600; text-align: center;
  border-top: 1px solid #dee2e6; background: var(--card-bg, #fff);
}
.inv-tpl-check { opacity: 0; transition: opacity .2s; margin-left: 4px; }

/* Thumbnail preview */
.inv-tpl-preview {
  width: 100%; height: 130px; padding: 6px; background: #fff;
  display: flex; flex-direction: column; gap: 3px;
}
.itp-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 5px; border-radius: 3px; background: #f0f0f0;
}
.itp-logo-box { width: 22px; height: 16px; border-radius: 2px; background: #adb5bd; }
.itp-logo-box.light { background: rgba(255,255,255,.5); }
.itp-title-box { text-align: left; }
.itp-title { font-size: 7px; font-weight: 800; line-height: 1; color: #333; }
.itp-title.light { color: #fff; }
.itp-num { font-size: 5.5px; color: #666; }
.itp-num.light { color: rgba(255,255,255,.75); }
.itp-info-row { display: flex; gap: 3px; }
.itp-cell { flex: 1; height: 14px; background: #f3f4f6; border-radius: 2px; }
.itp-table-hdr { height: 8px; border-radius: 2px; }
.itp-row { height: 7px; background: #f9f9f9; border-radius: 2px; }
.itp-row.alt { background: #f0f0f0; }
.itp-totals { display: flex; justify-content: flex-end; gap: 4px; align-items: flex-end; }
.itp-total-box { width: 60px; height: 12px; border-radius: 2px; }
.itp-footer-bar { height: 10px; border-radius: 2px; margin-top: 2px; }

/* Classic thumbnail */
.classic-preview .itp-header { background: #f0f0f0; }
.classic-hdr { background: #efefef; border: 1px solid #ccc; }
.classic-total { background: #e9ecef; }
.classic-footer { background: #f0f0f0; border: 1px solid #ccc; }

/* Modern thumbnail */
.modern-preview .itp-header.modern-hdr-bar { background: #1e3a5f; }
.modern-tbl-hdr { background: #c0392b; }
.modern-total { background: #1e3a5f; }
.modern-footer-bar { background: #1e3a5f; }

/* Minimal thumbnail */
.minimal-preview .itp-header.minimal-hdr { background: #fff; border-bottom: 2px solid #0f766e; }
.itp-logo-box.minimal-logo { background: #adb5bd; }
.itp-title.minimal-title { color: #0f766e; }
.itp-divider { height: 2px; border-radius: 0; margin: 1px 0; }
.minimal-divider { background: #0f766e; }
.minimal-tbl-hdr { background: transparent; border-bottom: 1.5px solid #0f766e; }
.minimal-total { background: transparent; border-top: 1.5px solid #0f766e; }
.minimal-footer { background: transparent; border-top: 1px solid #d1d5db; }

/* Professional thumbnail */
.itp-top-stripe { height: 6px; border-radius: 0; margin: -6px -6px 3px; }
.professional-stripe { background: #3730a3; }
.professional-preview .itp-header.pro-hdr { background: #f5f3ff; border-radius: 2px; }
.itp-title.pro-title { color: #3730a3; }
.itp-info-2col { display: flex; gap: 3px; }
.itp-cell.pro-cell { flex: 1; height: 18px; background: #ede9fe; border-radius: 2px; }
.professional-tbl-hdr { background: #3730a3; }
.professional-total { background: #3730a3; }
.professional-footer { background: #3730a3; }

/* Compact thumbnail */
.itp-compact-hdr { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 3px 0; }
.itp-logo-box.compact-logo { width: 16px; height: 12px; background: #adb5bd; border-radius: 2px; }
.itp-title.compact-title { font-size: 7px; font-weight: 800; color: #334155; }
.compact-divider { background: #334155; }
.compact-tbl-hdr { background: #334155; }
.compact-row { height: 5px; }
.compact-totals { margin-top: 1px; }
.compact-total { background: #334155; height: 10px; width: 50px; }
.compact-footer { background: #f1f5f9; border-top: 1px solid #334155; }

/* ══ Template 2 — Modern Invoice ══════════════════════ */
.print-area.tpl-modern {
  font-family: 'Tajawal', 'Segoe UI', 'Cairo', Tahoma, Arial, sans-serif;
  color: #1a1a1a; direction: rtl; max-width: 860px; margin: 0 auto;
}

/* Header: dark navy bar with logo + INVOICE */
.print-area.tpl-modern .inv-top {
  background: #1e3a5f; color: #fff; border: none; border-radius: 0;
  padding: 16px 20px; display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0;
}
.print-area.tpl-modern .inv-company-ar { color: #fff; font-size: 18px; }
.print-area.tpl-modern .inv-logo {
  background: rgba(255,255,255,0.95); border-radius: 8px; padding: 6px;
}
.print-area.tpl-modern .inv-logo img { max-height: 60px; }

/* Invoice title badge (top-right) */
.print-area.tpl-modern .m2-inv-badge {
  text-align: left; color: #fff;
}
.print-area.tpl-modern .m2-inv-badge .m2-title {
  font-size: 26px; font-weight: 800; letter-spacing: 1px; line-height: 1;
}
.print-area.tpl-modern .m2-inv-badge .m2-num {
  font-size: 12px; opacity: .8; margin-top: 3px;
}

/* Sub-header: invoice date/number strip */
.print-area.tpl-modern .m2-subheader {
  background: #2c4f7c; color: #e8f0f8;
  padding: 6px 20px; display: flex; gap: 24px;
  font-size: 12px;
}
.print-area.tpl-modern .m2-subheader span b { color: #fff; }

/* Billing info section */
.print-area.tpl-modern .inv-info-grid {
  border: 1px solid #d0d7e0; border-top: none;
  padding: 10px 16px; margin-bottom: 0;
  background: #f8fafc;
}
.print-area.tpl-modern .inv-info-col { border: none; }
.print-area.tpl-modern .inv-lbl {
  background: transparent; color: #6b7a8d; font-size: 10px; border: none; padding: 2px 0;
}
.print-area.tpl-modern .inv-val { padding: 2px 0; font-size: 13px; color: #111; }
.print-area.tpl-modern .inv-info-item { border: none; }
.print-area.tpl-modern .inv-title { display: none; }

/* Items table: red header */
.print-area.tpl-modern .inv-items-table { margin-top: 12px; }
.print-area.tpl-modern .inv-items-table th {
  background: #c0392b; color: #fff; border: 1px solid #a93226; font-size: 12px;
}
.print-area.tpl-modern .inv-items-table td { border: 1px solid #d0d7e0; }
.print-area.tpl-modern .inv-items-table tbody tr:nth-child(even) td { background: #f4f6f9; }

/* Bottom totals */
.print-area.tpl-modern .inv-bottom {
  border: 1px solid #d0d7e0; border-radius: 0; margin-top: 0;
}
.print-area.tpl-modern .inv-payment-lbl { background: #f0f4f8; color: #1e3a5f; }
.print-area.tpl-modern .inv-totals-side { background: #f8fafc; }
.print-area.tpl-modern .inv-final td { background: #1e3a5f !important; color: #fff !important; }

/* Signatures */
.print-area.tpl-modern .inv-signatures { margin-top: 18px; }

/* Footer: dark navy bar */
.print-area.tpl-modern .inv-footer-box {
  background: #1e3a5f !important; color: #e8f0f8 !important;
  border: none; border-radius: 0; margin-top: 16px;
}
.print-area.tpl-modern .inv-footer-text { color: #e8f0f8 !important; }

/* Print: preserve colors for modern template */
@media print {
  .print-area.tpl-modern .inv-top,
  .print-area.tpl-modern .m2-subheader,
  .print-area.tpl-modern .inv-items-table th,
  .print-area.tpl-modern .inv-final td,
  .print-area.tpl-modern .inv-footer-box {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  /* Override general print rules that force black text / white bg */
  .print-area.tpl-modern .inv-top,
  .print-area.tpl-modern .inv-top * { color: #fff !important; }
  .print-area.tpl-modern .m2-subheader,
  .print-area.tpl-modern .m2-subheader * { color: #e8f0f8 !important; }
  .print-area.tpl-modern .inv-items-table th { color: #fff !important; background: #c0392b !important; }
  .print-area.tpl-modern .inv-final td { color: #fff !important; background: #1e3a5f !important; }
  /* Modern footer: fixed at bottom with dark bg */
  .print-area.tpl-modern .inv-footer-box {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: #1e3a5f !important;
    color: #e8f0f8 !important;
  }
  .print-area.tpl-modern .inv-footer-box *,
  .print-area.tpl-modern .inv-footer-text { color: #e8f0f8 !important; }
  /* Logo white bg in print */
  .print-area.tpl-modern .inv-logo {
    background: rgba(255,255,255,0.95) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* ══ Template 3 — Minimal (Teal) ══════════════════════ */
.print-area.tpl-minimal {
  font-family: 'Tajawal', sans-serif;
  color: #1a1a1a; direction: rtl; max-width: 860px; margin: 0 auto;
}
.print-area.tpl-minimal .inv-top {
  border: none; background: transparent; padding: 12px 0 10px;
  border-bottom: 3px solid #0f766e; margin-bottom: 0;
}
.print-area.tpl-minimal .inv-company-ar { color: #0f766e; font-size: 20px; font-weight: 800; }
.print-area.tpl-minimal .inv-logo img { max-height: 70px; }
.print-area.tpl-minimal .inv-info-grid {
  background: transparent; border: none; margin: 8px 0 4px; gap: 0;
}
.print-area.tpl-minimal .inv-info-col { border: none; background: transparent; }
.print-area.tpl-minimal .inv-lbl {
  background: transparent; color: #6b7280; border: none; padding: 2px 0; font-size: 11px;
}
.print-area.tpl-minimal .inv-val { padding: 2px 0; font-size: 13px; color: #111; }
.print-area.tpl-minimal .inv-info-item { border: none; }
.print-area.tpl-minimal .inv-title {
  color: #0f766e; font-size: 17px; font-weight: 700;
  text-align: right; margin: 8px 0 6px; letter-spacing: 1.5px;
  border-bottom: 1px solid #d1fae5; padding-bottom: 6px;
}
.print-area.tpl-minimal .inv-items-table { margin-top: 2px; }
.print-area.tpl-minimal .inv-items-table th {
  background: transparent; border: none;
  border-bottom: 2px solid #0f766e; border-top: 2px solid #0f766e;
  color: #0f766e; font-size: 12px; padding: 8px 5px;
}
.print-area.tpl-minimal .inv-items-table td {
  border: none; border-bottom: 1px solid #e5e7eb; padding: 9px 6px;
}
.print-area.tpl-minimal .inv-bottom {
  border: none; border-top: 1px solid #e5e7eb; margin-top: 2px;
}
.print-area.tpl-minimal .inv-payment-lbl {
  background: transparent; color: #6b7280; border: none; font-size: 12px;
}
.print-area.tpl-minimal .inv-payment-box { border: none; }
.print-area.tpl-minimal .inv-totals-side { background: transparent; border: none; }
.print-area.tpl-minimal .inv-totals-side table td:first-child { color: #6b7280; }
.print-area.tpl-minimal .inv-final td {
  background: transparent !important; color: #0f766e !important;
  font-size: 15px; font-weight: 800; border-top: 2px solid #0f766e !important;
}
.print-area.tpl-minimal .inv-footer-box {
  border: none; border-top: 1px solid #e5e7eb;
  background: transparent; margin-top: 14px;
}
.print-area.tpl-minimal .inv-footer-text { color: #6b7280; }
@media print {
  .print-area.tpl-minimal .inv-top,
  .print-area.tpl-minimal .inv-items-table th,
  .print-area.tpl-minimal .inv-final td {
    -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important;
  }
  .print-area.tpl-minimal .inv-company-ar { color: #0f766e !important; }
  .print-area.tpl-minimal .inv-title { color: #0f766e !important; }
  .print-area.tpl-minimal .inv-items-table th { color: #0f766e !important; background: transparent !important; }
  .print-area.tpl-minimal .inv-final td { color: #0f766e !important; background: transparent !important; }
  .print-area.tpl-minimal .inv-footer-box {
    position: fixed !important; bottom: 0 !important; left: 0 !important; right: 0 !important;
    margin: 0 !important; background: #fff !important; border-top: 1px solid #ccc !important;
  }
}

/* ══ Template 4 — Professional (Indigo) ══════════════ */
.print-area.tpl-professional {
  font-family: 'Tajawal', sans-serif;
  color: #1a1a1a; direction: rtl; max-width: 860px; margin: 0 auto;
}
.print-area.tpl-professional .m4-top-stripe {
  background: #3730a3; height: 8px; margin: 0; border-radius: 0;
}
.print-area.tpl-professional .inv-top {
  background: #f5f3ff; border: none; border-radius: 0;
  padding: 14px 20px; display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid #c7d2fe;
}
.print-area.tpl-professional .inv-company-ar { color: #3730a3; font-size: 18px; font-weight: 800; }
.print-area.tpl-professional .inv-logo img { max-height: 65px; }
.print-area.tpl-professional .m4-inv-badge { text-align: left; }
.print-area.tpl-professional .m4-inv-badge .m4-title {
  font-size: 24px; font-weight: 800; color: #3730a3; line-height: 1; letter-spacing: 1px;
}
.print-area.tpl-professional .m4-inv-badge .m4-num {
  font-size: 12px; color: #6366f1; margin-top: 3px;
}
/* Two-column info grid */
.print-area.tpl-professional .m4-info-grid {
  display: flex; gap: 0; border: 1px solid #c7d2fe; margin-bottom: 10px;
}
.print-area.tpl-professional .m4-info-col {
  flex: 1; padding: 10px 14px;
}
.print-area.tpl-professional .m4-info-col:first-child {
  border-left: 1px solid #c7d2fe;
}
.print-area.tpl-professional .m4-col-title {
  font-size: 10px; font-weight: 700; color: #3730a3; letter-spacing: 1px;
  text-transform: uppercase; margin-bottom: 6px; border-bottom: 1px solid #e0e7ff; padding-bottom: 4px;
}
.print-area.tpl-professional .m4-row {
  display: flex; justify-content: space-between; font-size: 12px; margin: 3px 0;
}
.print-area.tpl-professional .m4-lbl { color: #6b7280; }
.print-area.tpl-professional .m4-val { font-weight: 600; color: #111; }
/* Override unused elements */
.print-area.tpl-professional .inv-info-grid { display: none; }
.print-area.tpl-professional .inv-title { display: none; }
/* Items table */
.print-area.tpl-professional .inv-items-table th {
  background: #3730a3; color: #fff; border: 1px solid #312e81; font-size: 12px;
}
.print-area.tpl-professional .inv-items-table td { border: 1px solid #e0e7ff; }
.print-area.tpl-professional .inv-items-table tbody tr:nth-child(even) td { background: #f5f3ff; }
/* Totals */
.print-area.tpl-professional .inv-bottom { border: 1px solid #c7d2fe; border-radius: 0; margin-top: 0; }
.print-area.tpl-professional .inv-payment-lbl { background: #ede9fe; color: #3730a3; }
.print-area.tpl-professional .inv-totals-side { background: #f9f8ff; }
.print-area.tpl-professional .inv-final td { background: #3730a3 !important; color: #fff !important; }
/* Footer */
.print-area.tpl-professional .inv-footer-box {
  background: #3730a3 !important; color: #e0e7ff !important;
  border: none; border-radius: 0; margin-top: 16px;
}
.print-area.tpl-professional .inv-footer-text { color: #e0e7ff !important; }
@media print {
  .print-area.tpl-professional .m4-top-stripe,
  .print-area.tpl-professional .inv-top,
  .print-area.tpl-professional .inv-items-table th,
  .print-area.tpl-professional .inv-final td,
  .print-area.tpl-professional .inv-footer-box {
    -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important;
  }
  .print-area.tpl-professional .inv-company-ar { color: #3730a3 !important; }
  .print-area.tpl-professional .m4-inv-badge .m4-title { color: #3730a3 !important; }
  .print-area.tpl-professional .m4-col-title { color: #3730a3 !important; }
  .print-area.tpl-professional .inv-items-table th { color: #fff !important; background: #3730a3 !important; }
  .print-area.tpl-professional .inv-final td { color: #fff !important; background: #3730a3 !important; }
  .print-area.tpl-professional .inv-payment-lbl { background: #ede9fe !important; }
  .print-area.tpl-professional .inv-footer-box {
    position: fixed !important; bottom: 0 !important; left: 0 !important; right: 0 !important;
    margin: 0 !important; background: #3730a3 !important; color: #e0e7ff !important;
  }
  .print-area.tpl-professional .inv-footer-box *,
  .print-area.tpl-professional .inv-footer-text { color: #e0e7ff !important; }
}

/* ══ Template 5 — Compact (Slate) ══════════════════════ */
.print-area.tpl-compact {
  font-family: 'Tajawal', sans-serif;
  color: #1a1a1a; direction: rtl; max-width: 860px; margin: 0 auto;
}
.print-area.tpl-compact .inv-top {
  padding: 8px 12px; border: 1px solid #334155; border-radius: 0;
  background: #334155; display: flex; justify-content: space-between; align-items: center;
}
.print-area.tpl-compact .inv-company-ar { color: #fff; font-size: 15px; font-weight: 700; }
.print-area.tpl-compact .inv-logo img { max-height: 45px; }
.print-area.tpl-compact .inv-logo {
  background: rgba(255,255,255,.9); border-radius: 5px; padding: 4px;
}
.print-area.tpl-compact .m5-badge { text-align: left; color: #fff; }
.print-area.tpl-compact .m5-badge .m5-title { font-size: 14px; font-weight: 800; line-height: 1; }
.print-area.tpl-compact .m5-badge .m5-num { font-size: 10px; opacity: .8; }
.print-area.tpl-compact .inv-info-grid {
  border: 1px solid #e2e8f0; border-top: none; margin-bottom: 0; gap: 0;
}
.print-area.tpl-compact .inv-info-col { border: none; flex-direction: row; flex-wrap: wrap; }
.print-area.tpl-compact .inv-lbl {
  background: transparent; border: none; color: #64748b; font-size: 10px; padding: 2px 6px; min-width: 80px;
}
.print-area.tpl-compact .inv-val { font-size: 12px; padding: 2px 4px; color: #111; }
.print-area.tpl-compact .inv-info-item { border-bottom: 1px solid #f1f5f9; }
.print-area.tpl-compact .inv-title {
  background: #f8fafc; border: 1px solid #e2e8f0; border-top: none;
  font-size: 13px; font-weight: 700; color: #334155; margin: 0 0 6px; padding: 4px 12px; text-align: right;
}
/* Items table — compact */
.print-area.tpl-compact .inv-items-table { font-size: 12px; }
.print-area.tpl-compact .inv-items-table th {
  background: #334155; color: #fff; border: 1px solid #1e293b; font-size: 11px; padding: 6px 4px;
}
.print-area.tpl-compact .inv-items-table td { padding: 5px 4px; border: 1px solid #e2e8f0; }
.print-area.tpl-compact .inv-items-table tbody tr:nth-child(even) td { background: #f8fafc; }
/* Totals */
.print-area.tpl-compact .inv-bottom { border: 1px solid #e2e8f0; border-radius: 0; margin-top: 0; }
.print-area.tpl-compact .inv-payment-lbl { background: #f1f5f9; color: #334155; font-size: 11px; }
.print-area.tpl-compact .inv-totals-side table { font-size: 12px; }
.print-area.tpl-compact .inv-final td { background: #334155 !important; color: #fff !important; }
/* Signatures */
.print-area.tpl-compact .inv-signatures { margin-top: 10px; }
.print-area.tpl-compact .inv-sign-dots { font-size: 10px; }
/* Footer */
.print-area.tpl-compact .inv-footer-box {
  background: #f1f5f9 !important; border: 1px solid #334155; border-radius: 0; margin-top: 10px;
}
.print-area.tpl-compact .inv-footer-text { color: #334155 !important; font-size: 11px; }
@media print {
  .print-area.tpl-compact .inv-top,
  .print-area.tpl-compact .inv-items-table th,
  .print-area.tpl-compact .inv-final td,
  .print-area.tpl-compact .inv-logo,
  .print-area.tpl-compact .inv-footer-box {
    -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important;
  }
  .print-area.tpl-compact .inv-top * { color: #fff !important; }
  .print-area.tpl-compact .inv-items-table th { color: #fff !important; background: #334155 !important; }
  .print-area.tpl-compact .inv-final td { color: #fff !important; background: #334155 !important; }
  .print-area.tpl-compact .inv-footer-box {
    position: fixed !important; bottom: 0 !important; left: 0 !important; right: 0 !important;
    margin: 0 !important; background: #f1f5f9 !important; border-top: 1px solid #334155 !important;
    border-left: none !important; border-right: none !important; border-bottom: none !important;
  }
  .print-area.tpl-compact .inv-footer-text { color: #334155 !important; }
}

/* ══ Template 6 — Corporate Invoice ══════════════════════ */

/* Thumbnail */
.corporate-preview { background: #fff; border: 0.5px solid #e2e8f0; }
.itp-corp-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 4px 5px 3px; background: #fff; position: relative; overflow: hidden;
}
.itp-corp-company { display: flex; align-items: center; gap: 3px; }
.itp-logo-box.corp-logo { width: 12px; height: 12px; background: #adb5bd; border-radius: 1px; }
.itp-corp-lines { display: flex; flex-direction: column; gap: 1.5px; }
.itp-corp-name { width: 28px; height: 3.5px; background: #1e293b; border-radius: 1px; }
.itp-corp-sub  { width: 20px; height: 2.5px; background: #94a3b8; border-radius: 1px; }
.itp-corp-right { position: relative; display: flex; flex-direction: column; align-items: flex-end; }
.itp-corp-inv-txt { font-size: 7px; font-weight: 900; color: #2563EB; letter-spacing: 0.5px; line-height: 1; }
.itp-corp-d1 {
  position: absolute; width: 14px; height: 14px; background: #2563EB;
  transform: rotate(45deg); top: -10px; right: -4px;
}
.itp-corp-d2 {
  position: absolute; width: 10px; height: 10px; background: #93c5fd;
  transform: rotate(45deg); top: -5px; right: 6px; opacity: 0.7;
}
.itp-corp-info { display: flex; gap: 3px; padding: 2px 4px 3px; }
.itp-corp-box    { flex: 0 0 28px; height: 14px; background: #f1f5f9; border: 0.5px solid #e2e8f0; border-radius: 1px; }
.itp-corp-client { flex: 1;        height: 14px; background: #f8fafc; border: 0.5px solid #e2e8f0; border-radius: 1px; }
.corp-tbl-hdr  { background: #2563EB; }
.corp-totals   { margin-top: 2px; }
.corp-total-box { background: #f8fafc; border: 0.5px solid #e2e8f0; width: 55px; padding: 2px 2px 1px; border-radius: 2px; }
.corp-total-final { height: 5px; background: #2563EB; border-radius: 1px; margin-top: 1px; }

/* Full template */
.print-area.tpl-corporate {
  font-family: 'Tajawal', sans-serif;
  color: #1e293b; background: #fff; position: relative;
  padding: 0 10px;
}
.print-area.tpl-corporate .m6-header-wrap {
  position: relative; padding: 20px 14px 16px; overflow: hidden;
}
/* Decorative diamonds — hidden */
.print-area.tpl-corporate .m6-deco-tr,
.print-area.tpl-corporate .m6-deco-bl { display: none; }
/* Top section */
.print-area.tpl-corporate .m6-top {
  display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px;
}
.print-area.tpl-corporate .m6-company-block { display: flex; align-items: flex-start; gap: 12px; }
.print-area.tpl-corporate .m6-logo img { max-height: 55px; max-width: 90px; object-fit: contain; }
.print-area.tpl-corporate .m6-company-name { font-size: 17px; font-weight: 800; color: #1e293b; line-height: 1.2; }
.print-area.tpl-corporate .m6-company-sub  { font-size: 10.5px; color: #64748b; margin-top: 2px; line-height: 1.5; }
.print-area.tpl-corporate .m6-inv-title-block { text-align: start; padding-inline-start: 20px; }
.print-area.tpl-corporate .m6-inv-title {
  font-size: 22px; font-weight: 800; color: #111;
  letter-spacing: 1px; line-height: 1.2;
}
/* Info grid */
.print-area.tpl-corporate .m6-info-grid { display: flex; gap: 14px; margin-top: 4px; }
.print-area.tpl-corporate .m6-doc-box {
  flex: 0 0 210px; font-size: 11.5px;
  border: 1px solid #e2e8f0; border-radius: 6px; overflow: hidden;
}
.print-area.tpl-corporate .m6-doc-row { display: flex; padding: 6px 10px; border-bottom: 1px solid #f1f5f9; }
.print-area.tpl-corporate .m6-doc-row:last-child { border-bottom: none; }
.print-area.tpl-corporate .m6-doc-lbl { color: #64748b; flex: 0 0 95px; font-weight: 600; }
.print-area.tpl-corporate .m6-doc-val { color: #1e293b; font-weight: 500; }
.print-area.tpl-corporate .m6-client-grid { flex: 1; display: flex; gap: 12px; }
.print-area.tpl-corporate .m6-client-col {
  flex: 1; padding: 10px 14px;
  border: 1px solid #e2e8f0; border-radius: 6px;
}
.print-area.tpl-corporate .m6-client-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase; color: #111;
  letter-spacing: 0.6px; margin-bottom: 6px; padding-bottom: 5px;
  border-bottom: 1px solid #d1d5db;
}
.print-area.tpl-corporate .m6-client-name { font-size: 13.5px; font-weight: 700; color: #1e293b; margin-bottom: 4px; }
.print-area.tpl-corporate .m6-client-detail { font-size: 11.5px; color: #64748b; line-height: 1.7; }
/* Table — transparent header, black text */
.print-area.tpl-corporate .inv-items-table thead th {
  background: transparent !important; color: #111 !important;
  border-bottom: 1.5px solid #111 !important; font-weight: 700; padding: 10px 12px;
}
.print-area.tpl-corporate .inv-items-table tbody tr:nth-child(even) { background: #f8fafc; }
/* Bottom */
.print-area.tpl-corporate .inv-bottom {
  border: 1px solid #e2e8f0; border-radius: 6px; overflow: hidden; margin-bottom: 16px;
}
.print-area.tpl-corporate .inv-payment-lbl { background: #f8fafc; color: #475569; }
.print-area.tpl-corporate .inv-totals-side { background: #f8fafc; border-color: #e2e8f0; min-width: 240px; }
.print-area.tpl-corporate .inv-totals-side td { font-size: 12.5px; border-color: #e2e8f0; }
.print-area.tpl-corporate .inv-totals-side td:first-child { color: #475569; }
.print-area.tpl-corporate .inv-totals-side .inv-final td {
  background: #111 !important; color: #fff !important;
  font-size: 14px; font-weight: 700; border-top: none;
}
/* Footer */
.print-area.tpl-corporate .inv-footer-box {
  background: #f8fafc !important; border-top: 1.5px solid #cbd5e1 !important;
  border-radius: 0; margin: 10px -10px 0;
}
.print-area.tpl-corporate .inv-footer-text { color: #475569 !important; font-size: 11.5px; }
@media print {
  .print-area.tpl-corporate .inv-totals-side .inv-final td,
  .print-area.tpl-corporate .m6-diamond,
  .print-area.tpl-corporate .inv-footer-box {
    -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important;
  }
  .print-area.tpl-corporate .inv-items-table th {
    background: transparent !important; color: #111 !important;
    border-bottom: 1.5px solid #111 !important;
  }
  .print-area.tpl-corporate .inv-totals-side .inv-final td {
    background: #111 !important; color: #fff !important;
  }
  .print-area.tpl-corporate .inv-footer-box {
    position: fixed !important; bottom: 0 !important;
    left: 30px !important; right: 30px !important;
    margin: 0 !important; background: #f8fafc !important;
    border-top: 1.5px solid #cbd5e1 !important;
    border-left: 1.5px solid #cbd5e1 !important;
    border-right: 1.5px solid #cbd5e1 !important;
    border-bottom: 1.5px solid #cbd5e1 !important;
    border-radius: 0 0 4px 4px !important;
  }
  .print-area.tpl-corporate { border-bottom: none !important; border-radius: 6px 6px 0 0 !important; }
  .print-area.tpl-corporate .inv-footer-text { color: #475569 !important; }
  .print-area.tpl-corporate { padding-bottom: 80px; }
}

/* ══ Template 7 — A2Z Invoice ══════════════════════ */

/* Thumbnail */
.a2z-preview { background: #fff; border: 0.5px solid #e2e8f0; }
.itp-a2z-header {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 5px 3px; border-bottom: 1px solid #222;
}
.itp-logo-box.a2z-logo { width: 12px; height: 12px; background: #adb5bd; border-radius: 1px; flex-shrink: 0; }
.itp-a2z-company { display: flex; flex-direction: column; gap: 1.5px; }
.itp-a2z-name { width: 40px; height: 3.5px; background: #1a1a1a; border-radius: 1px; }
.itp-a2z-sub  { width: 28px; height: 2px; background: #666; border-radius: 1px; }
.itp-a2z-info {
  display: flex; gap: 0; margin: 3px 5px;
  border: 0.5px solid #aaa;
}
.itp-a2z-col { flex: 1; }
.itp-a2z-col:first-child { border-left: 0.5px solid #aaa; }
.itp-a2z-row { height: 5px; border-bottom: 0.5px solid #ddd; background: #f8f8f8; }
.itp-a2z-row:last-child { border-bottom: none; }
.itp-a2z-title { height: 5px; background: #1a1a1a; border-radius: 1px; margin: 3px 15px; }
.a2z-tbl-hdr { background: #efefef; border: 0.5px solid #aaa; }
.a2z-totals { margin-top: 2px; }
.itp-a2z-pay { flex: 1; background: #f8f8f8; border: 0.5px solid #ddd; margin: 0 0 0 2px; border-radius: 1px; }
.itp-a2z-total-box { width: 55px; border: 0.5px solid #aaa; border-radius: 1px; padding: 1px; }
.itp-a2z-final { height: 5px; background: #1a1a1a; border-radius: 1px; margin-top: 1px; }

/* Full template */
.print-area.tpl-a2z {
  font-family: 'Tajawal', 'Segoe UI', 'Cairo', Arial, sans-serif;
  color: #1a1a1a; direction: rtl; max-width: 860px; margin: 0 auto;
}

/* ── A2Z Header ─────────────────────────────────── */
.print-area.tpl-a2z .a2z-top {
  display: flex; align-items: center; gap: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid #1a1a1a;
  margin-bottom: 14px;
}
.print-area.tpl-a2z .a2z-top-logo img {
  max-height: 75px; max-width: 140px; object-fit: contain;
}
.print-area.tpl-a2z .a2z-top-company { flex: 1; text-align: right; }
.print-area.tpl-a2z .a2z-company-ar {
  font-size: 21px; font-weight: 900; line-height: 1.35; color: #111;
}
.print-area.tpl-a2z .a2z-company-en {
  font-size: 16px; font-weight: 800; color: #1a1a1a; margin-top: 3px;
}

/* ── A2Z Info Grid (mirrored bordered-label boxes, no outer border) ─── */
.print-area.tpl-a2z .a2z-info-grid {
  display: flex; gap: 40px; margin-bottom: 4px;
}
.print-area.tpl-a2z .a2z-info-col {
  flex: 1; display: flex; flex-direction: column; gap: 7px;
}
/* كل سطر: مربع label بإطار كامل + قيمة بجانبه */
.print-area.tpl-a2z .a2z-info-row {
  display: flex; align-items: stretch; gap: 10px;
  direction: ltr;            /* ترتيب صريح للعناصر */
}
.print-area.tpl-a2z .a2z-lbl {
  border: 1.5px solid #1a1a1a; background: #fff; color: #1a1a1a;
  font-size: 13px; font-weight: 700;
  padding: 4px 12px; min-width: 100px; white-space: nowrap;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.print-area.tpl-a2z .a2z-val {
  font-size: 13px; display: flex; align-items: center; flex: 1;
  direction: rtl;
}
/* عمود المستند (يسار): المربع يسار، القيمة ملاصقة له على اليسار */
.print-area.tpl-a2z .a2z-col-doc .a2z-info-row { flex-direction: row; }
.print-area.tpl-a2z .a2z-col-doc .a2z-val { justify-content: flex-end; } /* rtl flex-end = يسار */
/* عمود العميل (يمين): المربع يمين، القيمة ملاصقة له على اليمين */
.print-area.tpl-a2z .a2z-col-client .a2z-info-row { flex-direction: row-reverse; }
.print-area.tpl-a2z .a2z-col-client .a2z-val { justify-content: flex-start; } /* rtl flex-start = يمين */

/* ── A2Z Title ────────────────────────────────── */
.print-area.tpl-a2z .a2z-doc-title {
  text-align: center; font-size: 22px; font-weight: 900;
  margin: 10px 0 12px; letter-spacing: 0.5px;
}

/* ── A2Z uses shared items table — header dark ── */
.print-area.tpl-a2z .inv-items-table th {
  background: #e8e8e8; border-color: #555;
  font-size: 12px; line-height: 1.4;
}
.print-area.tpl-a2z .inv-items-table td { border-color: #888; }

/* ── A2Z Bottom (totals: grey label cells, bold final value) ── */
.print-area.tpl-a2z .inv-totals-side table { border-collapse: collapse; width: 100%; }
.print-area.tpl-a2z .inv-totals-side td {
  border: 1px solid #999; padding: 6px 12px;
}
/* خانة الـ label (أول td) خلفية رمادية */
.print-area.tpl-a2z .inv-totals-side td:first-child {
  background: #d9d9d9; font-weight: 700;
}
.print-area.tpl-a2z .inv-totals-side .inv-final td {
  font-size: 18px; font-weight: 900;
  background: #fff; color: #1a1a1a !important;
}
.print-area.tpl-a2z .inv-totals-side .inv-final td:first-child {
  background: #d9d9d9;
}

/* ── A2Z Signatures (dotted lines, bold labels) ── */
.print-area.tpl-a2z .inv-signatures { margin-top: 22px; }
.print-area.tpl-a2z .inv-sign-dots  { color: #555; letter-spacing: 2px; }
.print-area.tpl-a2z .inv-sign-label { font-weight: 700; }

/* ── A2Z Footer (clean rounded rectangle, QR on left + text centered) ── */
.print-area.tpl-a2z .inv-footer-box {
  display: flex; align-items: center; gap: 16px;
  border: 1.5px solid #1a1a1a; border-radius: 16px;
  padding: 12px 24px; margin-top: 16px; background: #fff;
  color: #1a1a1a;
}
.print-area.tpl-a2z .inv-footer-text {
  flex: 1; text-align: center; font-size: 12px; font-weight: 600; line-height: 1.8;
}

/* Print overrides */
@media print {
  .print-area.tpl-a2z .inv-totals-side td:first-child,
  .print-area.tpl-a2z .inv-totals-side .inv-final td:first-child {
    background: #d9d9d9 !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE — Mobile, Tablet & iPad
   ══════════════════════════════════════════════════════ */

/* Sidebar backdrop overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-overlay.show { display: block; }

/* ── Tablet & below (< 992px) — sidebar as overlay ── */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(var(--sidebar-width));
    z-index: 1000;
    box-shadow: none;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: -6px 0 30px rgba(0,0,0,.35);
  }
  body.ltr .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
  }
  body.ltr .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 6px 0 30px rgba(0,0,0,.35);
  }
  .main-content { margin-right: 0 !important; margin-left: 0 !important; }
  body.ltr .main-content { margin-left: 0 !important; }
}

/* ── Mobile (< 768px) ── */
@media (max-width: 767.98px) {
  /* Layout */
  .content-area { padding: 12px; }
  .topbar { padding: 8px 12px; gap: 4px; }

  /* Page title */
  .page-title {
    font-size: .85rem;
    flex-shrink: 1;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Hide global search bar to save topbar space */
  .global-search-wrap { display: none !important; }

  /* Hide user name & badges in topbar */
  #topbar-name, #topbar-role, #topbar-branch { display: none !important; }
  #userDropdownBtn { gap: 0 !important; }

  /* Auto-close sidebar after nav on mobile already done in JS */

  /* POS: stack products + cart vertically */
  body.pos-mode { overflow-y: auto !important; }
  body.pos-mode .main-content { height: auto !important; overflow: visible !important; }
  body.pos-mode .content-area { overflow: visible !important; flex: none !important; padding: 0 !important; }
  #page-pos { height: auto !important; overflow: visible !important; }
  .pos-layout { flex-direction: column !important; overflow: visible !important; height: auto !important; }
  .pos-products-panel {
    flex: none !important;
    height: 45vh !important;
    min-height: 260px;
    border-inline-end: none !important;
    border-bottom: 1px solid var(--card-border) !important;
    overflow: hidden;
  }
  .pos-cart-panel {
    width: 100% !important;
    min-width: 0 !important;
    max-height: 55vh;
    overflow-y: auto;
  }

  /* Filter inputs inside flex-wrap rows: grow to fill available space */
  .d-flex.flex-wrap > .form-control,
  .d-flex.flex-wrap > .form-select,
  .d-flex.gap-2.flex-wrap > .form-control,
  .d-flex.gap-2.flex-wrap > .form-select {
    flex: 1 1 130px;
    min-width: 120px !important;
    width: auto !important;
  }

  /* Page header: allow wrapping when search + add-button are on same row */
  .page > .d-flex.justify-content-between.align-items-center.mb-3 {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Stat cards: compact */
  .stat-card { min-height: 100px !important; }
  .stat-value { font-size: 1.2rem !important; }
  .stat-icon  { font-size: 1.4rem !important; }

  /* ── الجداول على الموبايل ── */
  /* حدّ واضح حول منطقة التمرير ليعرف المستخدم أن الجدول يُمرَّر أفقياً */
  .table-responsive {
    border: 1px solid var(--card-border);
    border-radius: 10px;
    position: relative;
  }
  /* تقليل المسافات والخط لكثافة أعلى */
  .table-responsive > .table > thead > tr > th,
  .table-responsive > .table > tbody > tr > td {
    padding: 7px 9px;
    font-size: 0.82rem;
    vertical-align: middle;
  }
  /* رؤوس الأعمدة لا تلتف حتى تبقى الأعمدة منتظمة */
  .table-responsive > .table > thead > tr > th { white-space: nowrap; }
  /* أزرار الإجراءات داخل الجداول: قابلة للمس ولا تلتف */
  .table-responsive > .table td .btn,
  .table-responsive > .table td .btn-xs {
    padding: 5px 8px;
    white-space: nowrap;
  }

  /* ── الشريط العلوي والتنقل ── */
  /* زر القائمة (الهامبرغر): هدف لمس أكبر */
  #toggleSidebar {
    padding: 8px 11px;
    font-size: 1.05rem;
  }
  /* إعطاء العنوان مساحة أكبر بعد إخفاء البحث */
  .page-title { max-width: none; flex: 1; }
  /* عناصر القائمة الجانبية: هدف لمس مريح (≥44px) */
  .sidebar-nav .nav-item,
  .sidebar-nav .nav-item-top {
    padding-top: 12px;
    padding-bottom: 12px;
    font-size: 0.95rem;
  }
  .sidebar-nav .nav-group-header { padding-top: 11px; padding-bottom: 11px; }
  /* قائمة المستخدم المنسدلة: عناصر أكبر للمس */
  .dropdown-menu .dropdown-item { padding-top: 9px; padding-bottom: 9px; }
}

/* ── Small mobile (< 480px) ── */
@media (max-width: 479.98px) {
  .topbar  { padding: 6px 10px; gap: 3px; }
  .page-title { max-width: 90px; font-size: .78rem; }
  .content-area { padding: 8px; }
  .stat-value { font-size: 1.05rem !important; }

  /* POS grid: smaller cards */
  .pos-products-grid {
    grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)) !important;
  }
  .pos-prod-card  { min-height: 80px !important; padding: 8px 5px !important; }
  .pos-prod-name  { font-size: .72rem !important; }
  .pos-prod-price { font-size: .82rem !important; }
}

/* ── Tablet only (768px – 991px) ── */
@media (min-width: 768px) and (max-width: 991.98px) {
  .content-area { padding: 16px; }
  .pos-cart-panel { width: 360px !important; min-width: 300px !important; }
  #topbar-branch { font-size: .7rem; }
}

/* ── iPad Pro / Large tablet (992px – 1199px) ── */
@media (min-width: 992px) and (max-width: 1199.98px) {
  :root { --sidebar-width: 215px; }
  .pos-cart-panel { width: 390px !important; min-width: 340px !important; }
}

/* ── ميزات جديدة ────────────────────────────────────── */
.badge-partial-paid {
  background: #f59e0b;
  color: #fff;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.78rem;
}

.bg-orange { background: #f97316 !important; color: #fff; }

/* تسوية المخزون — أيقونة + */
.btn-adj-positive { color: #16a34a; font-weight: bold; font-size: 1.1rem; }
.btn-adj-negative { color: #dc2626; font-weight: bold; font-size: 1.1rem; }

/* جرد المخزون — خلية الإدخال */
#take-items-tbody input[type="number"] {
  width: 110px;
}

/* باركود */
#barcode-scanner-wrap video {
  border-radius: 8px;
}

/* تقرير الديون */
.debt-overdue-30  { border-right: 3px solid #16a34a; }
.debt-overdue-60  { border-right: 3px solid #f59e0b; }
.debt-overdue-90  { border-right: 3px solid #f97316; }
.debt-overdue-max { border-right: 3px solid #dc2626; }

/* زر دفعة صغير */
.btn-xs { padding: 2px 6px; font-size: 0.75rem; }

/* ═══════════════════════════════════════════════════════
   نقطة البيع (POS)
   ═══════════════════════════════════════════════════════ */
#page-pos {
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* الارتفاع يُحسب تلقائياً عبر flex في وضع pos-mode */
  height: calc(100vh - 56px);
}

/* وضع POS: نلغي الـ padding والـ scroll من كل الأجداد */
body.pos-mode {
  overflow: hidden;
}
body.pos-mode .main-content {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.pos-mode .content-area {
  padding: 0;
  overflow: hidden;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body.pos-mode #page-pos {
  flex: 1;
  min-height: 0;
  height: auto; /* يرث من flex */
}
.pos-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}
/* لوحة المنتجات */
.pos-products-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-inline-end: 1px solid var(--card-border);
  background: var(--body-bg);
  padding: 12px;
  gap: 10px;
}
.pos-search-bar input { font-size: 1rem; }
.pos-toolbar { display: flex; gap: 6px; flex-wrap: wrap; flex-shrink: 0; align-items: center; }
.pos-cat-tabs { display: flex; gap: 6px; flex-wrap: wrap; flex-shrink: 0; }
.pos-cat-btn {
  padding: 3px 14px; border-radius: 20px;
  border: 1px solid var(--card-border); background: var(--card-bg);
  font-size: 0.8rem; cursor: pointer; transition: all .15s; color: var(--text-main);
}
.pos-cat-btn:hover, .pos-cat-btn.active {
  background: var(--primary); border-color: var(--primary); color: #fff;
}
.pos-products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px; overflow-y: auto; flex: 1; padding: 2px;
  align-content: start;
}
.pos-prod-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 10px 8px; cursor: pointer;
  transition: all .15s; display: flex; flex-direction: column;
  align-items: center; text-align: center; gap: 4px;
  min-height: 88px; justify-content: center;
}
.pos-prod-card:hover {
  border-color: var(--primary); background: var(--primary-light);
  transform: translateY(-1px); box-shadow: 0 4px 12px rgba(var(--primary-rgb),.15);
}
.pos-prod-card:active { transform: scale(.97); }
.pos-prod-card.oos { opacity: .45; cursor: not-allowed; }
.pos-prod-name {
  font-size: .78rem; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pos-prod-price { font-size: .85rem; color: var(--primary); font-weight: 700; }
.pos-prod-stock { font-size: .68rem; color: var(--text-muted); }
/* صورة المنتج في بطاقة نقطة البيع (اختيارية حسب الإعدادات) */
.pos-prod-card.has-img { height: auto; min-height: 150px; justify-content: flex-start; }
/* مع وجود الصورة نعرض الاسم كاملاً بلا قصّ — تتمدّد البطاقة حسب طول الاسم */
.pos-prod-card.has-img .pos-prod-name {
  display: block; -webkit-line-clamp: unset; -webkit-box-orient: unset; overflow: visible;
}
.pos-prod-img {
  width: 100%; height: 64px; object-fit: contain; flex: 0 0 auto;
  border-radius: 8px; background: var(--primary-light); padding: 2px;
}
.pos-prod-img-ph {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 1.4rem;
}
/* لوحة السلة */
.pos-cart-panel {
  width: 400px; min-width: 330px;
  display: flex; flex-direction: column;
  background: var(--card-bg);
}
.pos-cart-header {
  padding: 10px 14px; border-bottom: 1px solid var(--card-border);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
  font-weight: 600;
}
.pos-cart-items { flex: 1; overflow-y: auto; }
.pos-empty-msg {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text-muted); gap: 8px; font-size: .9rem; padding: 20px;
}
.pos-cart-row {
  display: flex; align-items: center; padding: 6px 12px; gap: 6px;
  border-bottom: 1px solid var(--card-border); font-size: .83rem;
}
.pos-cart-row:last-child { border-bottom: none; }
.pos-cart-row-name { flex: 1; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pos-qty-ctrl { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.pos-qty-btn {
  width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--card-border);
  background: var(--body-bg); cursor: pointer; display: flex; align-items: center;
  justify-content: center; font-size: .8rem; transition: all .1s; padding: 0;
}
.pos-qty-btn:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.pos-qty-num { width: 26px; text-align: center; font-weight: 700; }
.pos-cart-row-price { min-width: 50px; text-align: end; color: var(--text-muted); font-size: .75rem; }
.pos-cart-row-total { min-width: 58px; text-align: end; font-weight: 700; color: #198754; }
.pos-del-btn {
  border: none; background: none; color: var(--text-muted); cursor: pointer;
  padding: 2px 4px; border-radius: 4px; font-size: .75rem;
}
.pos-del-btn:hover { color: #dc3545; background: #fee2e2; }
.pos-totals {
  border-top: 1px solid var(--card-border); padding: 10px 14px;
  display: flex; flex-direction: row; align-items: center; justify-content: space-between;
  gap: 16px; flex-shrink: 0; font-size: .82rem;
}
.pos-totals-left { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.pos-totals-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pos-totals-final {
  display: flex; flex-direction: column; align-items: flex-start;
  border-inline-end: 2px solid var(--card-border); padding-inline-end: 16px;
  flex-shrink: 0;
}
.pos-payment-section {
  border-top: 1px solid var(--card-border); padding: 10px 14px;
  display: flex; flex-direction: column; gap: 8px; flex-shrink: 0;
}
.pos-pm-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.pos-pm-btn {
  flex: 1; min-width: 72px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 10px 6px; border-radius: 10px;
  border: 2px solid var(--card-border); background: var(--card-bg);
  color: var(--text-main); font-size: .78rem; font-weight: 600;
  cursor: pointer; transition: all .15s; line-height: 1.2;
}
.pos-pm-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.pos-pm-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(var(--primary-rgb),.35); }
.pos-pm-btn span { font-size: .75rem; }
.pos-pay-row { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.pos-pay-row label { flex-shrink: 0; min-width: 95px; font-weight: 500; color: var(--text-muted); margin-bottom: 0; }
.pos-confirm-section { padding: 10px 14px; flex-shrink: 0; border-top: 1px solid var(--card-border); }
/* إيصال الطباعة */
@media print {
  .pos-receipt { font-family: 'Courier New', monospace; font-size: 12px; width: 72mm; }
}

/* ── تحسينات اللمس لأجهزة POS (كروت أكثف لإظهار منتجات أكثر) ── */
.pos-products-grid {
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 6px;
}
.pos-prod-card {
  min-height: 74px;
  padding: 7px 6px;
  border-radius: 10px;
}
.pos-prod-name  { font-size: .76rem; }
.pos-prod-price { font-size: .85rem; }
.pos-prod-stock { font-size: .68rem; }
.pos-cat-btn    { padding: 6px 16px; font-size: .85rem; }
.pos-qty-btn    { width: 32px; height: 32px; font-size: .9rem; }
.pos-qty-num    { width: 32px; font-size: 1rem; }
.pos-cart-row   { padding: 8px 12px; font-size: .9rem; min-height: 44px; }
.pos-del-btn    { font-size: .85rem; padding: 4px 8px; }
.pos-cart-panel { width: 420px; min-width: 360px; }
.pos-pay-row    { min-height: 40px; }
.pos-pay-row label { min-width: 105px; }
.pos-confirm-section .btn-lg { font-size: 1.15rem; padding: .65rem 1rem; min-height: 52px; }
.pos-search-bar input { font-size: 1.05rem; padding: .45rem .75rem; }
.pos-totals     { font-size: .92rem; padding: 10px 16px; }
.pos-totals-final { font-size: 1.05rem; }
#pos-total      { font-size: 1.6rem !important; }

/* ── آلة حاسبة ── */
.calc-screen {
  background: var(--body-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 8px 14px 6px;
  margin-bottom: 10px;
  text-align: end;
  min-height: 70px;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.calc-expr { font-size: .8rem; color: var(--text-muted); min-height: 18px; word-break: break-all; }
.calc-val  { font-size: 2rem; font-weight: 700; color: var(--text-main); line-height: 1.1; word-break: break-all; }
.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}
.calc-btn {
  height: 58px; border-radius: 10px; border: 1px solid var(--card-border);
  background: var(--card-bg); font-size: 1.15rem; font-weight: 600;
  cursor: pointer; color: var(--text-main); transition: all .1s;
  display: flex; align-items: center; justify-content: center;
}
.calc-btn:active { transform: scale(.93); }
.calc-fn  { background: var(--body-bg); color: var(--text-muted); }
.calc-op  { background: rgba(var(--primary-rgb),.1); color: var(--primary); font-size: 1.2rem; }
.calc-eq  { background: var(--primary); color: #fff; font-size: 1.3rem; }
.calc-zero { grid-column: span 2; }
[data-theme="dark"] .calc-btn { border-color: #333; }
[data-theme="dark"] .calc-fn  { background: #1a1a1a; }

/* ── جدول الصلاحيات (مجموعات الصلاحيات) ───────────────── */
.perm-group {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card-bg);
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.perm-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .55rem .9rem;
  background: linear-gradient(90deg, rgba(var(--primary-rgb),.14), rgba(var(--primary-rgb),.04));
  border-bottom: 2px solid rgba(var(--primary-rgb),.35);
}
.perm-group-title {
  font-weight: 700;
  color: var(--primary);
  font-size: .95rem;
  display: flex;
  align-items: center;
}
.perm-group-selectall {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  padding: .2rem .55rem;
  border-radius: 999px;
  border: 1px solid rgba(var(--primary-rgb),.3);
  background: var(--card-bg);
  transition: background .15s, color .15s;
}
.perm-group-selectall:hover { background: rgba(var(--primary-rgb),.08); color: var(--primary); }
.perm-group-selectall input { cursor: pointer; margin: 0; }

.perm-table { margin: 0; }
.perm-table thead th {
  background: var(--body-bg);
  border-color: var(--card-border) !important;
  vertical-align: middle;
  font-size: .78rem;
  color: var(--text-muted);
  padding: .4rem .5rem;
}
.perm-table .perm-op-col { text-align: start; font-weight: 700; color: var(--text-main); }
.perm-col-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
}
.perm-col-label { font-weight: 600; }
.perm-col-label .fa-trash { color: #ef4444; }
.perm-col-label .fa-pen   { color: #f59e0b; }
.perm-col-label .fa-plus  { color: #22c55e; }
.perm-col-label .fa-eye   { color: var(--primary); }
.perm-col-cb { cursor: pointer; margin: 0; transform: scale(1.05); }

.perm-table tbody td {
  vertical-align: middle;
  border-color: var(--card-border) !important;
  padding: .4rem .5rem;
}
.perm-table tbody tr:nth-child(even) td { background: rgba(var(--primary-rgb),.025); }
.perm-table tbody tr:hover td { background: rgba(var(--primary-rgb),.07); }
.perm-op {
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
}
.perm-op:hover { color: var(--primary); text-decoration: underline dotted; }
.perm-empty { color: var(--text-muted); opacity: .5; }
.perm-cb { cursor: pointer; transform: scale(1.15); margin: 0; }


/* ════ عرض القوائم ككروت على الموبايل ════ */
@media (max-width: 768px) {
  .mobile-cards thead { display: none; }
  .mobile-cards,
  .mobile-cards tbody,
  .mobile-cards tr,
  .mobile-cards td { display: block; width: 100%; }

  .mobile-cards tr {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 4px 4px;
    margin-bottom: 12px;
    box-shadow: 0 1px 4px rgba(15,23,42,.06);
    overflow: hidden;
  }

  /* إلغاء خطوط/تظليل Bootstrap الداخلية وتحويل الخلية لصف عنوان+قيمة */
  .mobile-cards td {
    border: none !important;
    box-shadow: none !important;
    padding: 9px 14px !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    text-align: left;
    word-break: break-word;
  }
  .mobile-cards td + td { border-top: 1px solid var(--card-border) !important; }

  .mobile-cards td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: .76rem;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* عمود الأزرار (رأسه فاضي): صف كامل بدون عنوان */
  .mobile-cards td.mc-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    background: rgba(var(--primary-rgb), .04);
  }
  .mobile-cards td.mc-actions::before { content: none; }

  /* صف "لا توجد بيانات" (colspan) يظل طبيعياً */
  .mobile-cards tr.mc-skip td {
    display: block;
    text-align: center;
    color: var(--text-muted);
  }
  .mobile-cards tr.mc-skip td::before { content: none; }
}
