:root {
  --orange: #f97316;
  --orange-dark: #ea580c;
  --orange-soft: rgba(249, 115, 22, .12);
  --orange-ring: rgba(249, 115, 22, .18);

  --bg: #0b1220;
  --surface: rgba(255,255,255,.06);
  --surface-2: rgba(255,255,255,.08);
  --surface-3: rgba(255,255,255,.12);
  --text: #e5e7eb;
  --text-secondary: #cbd5e1;
  --text-muted: rgba(226,232,240,.72);
  --border: rgba(148, 163, 184, .22);
  --border-strong: rgba(148, 163, 184, .35);
  --shadow: 0 1px 0 rgba(255,255,255,.04), 0 18px 60px rgba(0,0,0,.42);

  --radius-sm: 12px;
  --radius: 14px;
  --radius-lg: 18px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;

  --topbar-h: 64px;
  --sidebar-w: 280px;
  --transition: all .18s cubic-bezier(.2,.9,.2,1);

  --font: 'Tajawal', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;

  --btn-h: 44px;
  --control-h: 44px;
  
  /*------------------------------------ اضفتها مؤخراً */
  --orange-border:  rgba(249,115,22,.3);
  --black-card:     #1c1c1c;
  --white:          #ffffff;
  --white-soft:     rgba(255,255,255,.85);
  --white-muted:    rgba(255,255,255,.45);
  --white-dim:      rgba(255,255,255,.08);
  --white-border:   rgba(255,255,255,.09);
  --success:        #4ade80;
  --success-bg:     rgba(74,222,128,.1);
  --success-border: rgba(74,222,128,.3);
  --danger:         #f87171;
  --danger-bg:      rgba(248,113,113,.1);
  --danger-border:  rgba(248,113,113,.3);
  --warning:        #fbbf24;
  --warning-bg:     rgba(251,191,36,.1);
  --warning-border: rgba(251,191,36,.3);
  --radius-xl:      20px;
  --font-display:   'Tajawal', sans-serif;
  
}

html { color-scheme: dark; }
html, body {
  overflow-x: hidden;
  min-width: 0;
}

/* Base box sizing */
*, *::before, *::after { box-sizing: border-box; }

/* Media should never overflow */
img, video, iframe, svg { max-width: 100%; height: auto; }

/* Tables: keep them inside their wrapper; allow horizontal scroll via /* .table-wrap */
table { width: 100%; table-layout: fixed; }

/* Ensure grid/flex items never overflow */
.grid, .row, .card-header, .page-header, .page-actions {
  min-width: 0;
}

/* Safe viewport units for mobile browsers */
:root {
  --vh: 1vh;
}
@supports (height: 100dvh) {
  :root { --vh: 1dvh; }
}

:focus-visible {
  outline: 2px solid rgba(249, 115, 22, .55);
  outline-offset: 2px;
}

body {
  background: radial-gradient(1200px 600px at 70% -10%, rgba(249, 115, 22, .20), transparent 60%),
              radial-gradient(900px 540px at 10% 10%, rgba(20, 184, 166, .14), transparent 55%),
              linear-gradient(180deg, #0b1220 0%, #070b13 100%);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
  overflow-x: hidden;
  min-width: 0;
  max-width: 100%;
}

body::before { display: none !important; }
body::after  { pointer-events: none; }

a { color: inherit; }

h1, h2, h3 { margin: 0; letter-spacing: 0; }
.page-title, .page-header h1 { font-size: 1.28rem; font-weight: 700; color: var(--text); line-height: 1.25; }
.section-title, .card-header h2 { font-size: 1.02rem; font-weight: 700; color: var(--text-secondary); line-height: 1.3; }
small, .text-small { font-size: .86rem; color: var(--text-muted); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  height: var(--topbar-h);
  background: rgba(11,18,32,.72);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-logo {
  height: 32px;
  width: auto;
  display: block;
  object-fit: contain;
}

.topbar-brand {
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: 0;
  color: var(--text);
}

.topbar-nav a {
  color: var(--text-muted);
  border: 1px solid transparent;
}

.topbar-nav a:hover {
  color: var(--text);
  background: rgba(255,255,255,.06);
}

.topbar-nav a.active {
  color: var(--text);
  background: rgba(249, 115, 22, .14);
  border-color: rgba(249, 115, 22, .28);
}

.topbar-user { color: var(--text-secondary); }

.topbar-user .avatar {
  background: rgba(249, 115, 22, .20);
  color: #ffedd5;
}

.topbar-logout {
  color: var(--text);
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.topbar-logout:hover {
  background: rgba(255,255,255,.08);
}

.topbar-toggle {
  display: none;
  height: 44px;
  width: 44px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
  align-items: center;
  justify-content: center;
}

.topbar-toggle:hover { background: var(--surface-2); }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 0;
  min-height: calc(100 * var(--vh) - var(--topbar-h));
}

/* RTL: اجعل السايدبار على اليمين */
[dir="rtl"] .app-shell {
  grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
}

[dir="rtl"] .sidebar {
  grid-column: 2;
  border-right: 0 !important;
  border-left: 1px solid var(--border) !important;
}

[dir="rtl"] .main {
  grid-column: 1;
}

html[dir="rtl"] .app-shell > .sidebar { grid-column: 2 !important; }
html[dir="rtl"] .app-shell > .main { grid-column: 1 !important; }

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100 * var(--vh) - var(--topbar-h));
  padding: 18px 14px;
  border-right: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.sidebar .nav-group-title {
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .06em;
  margin: 14px 10px 8px;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 14px;
  color: var(--text-secondary);
  border: 1px solid transparent;
  transition: var(--transition);
  font-size: .92rem;
  font-weight: 600;
}

.sidebar a:hover { background: rgba(255,255,255,.06); color: var(--text); }

.sidebar a.active {
  background: rgba(249, 115, 22, .12);
  border-color: rgba(249, 115, 22, .28);
  color: #fff7ed;
  box-shadow: 0 0 0 1px rgba(249, 115, 22, .06), 0 10px 30px rgba(249, 115, 22, .10);
}

.main {
  padding: 26px 22px 44px;
}

.page-wrapper {
  max-width: 1120px;
  padding: 0;
}

.page-wrapper.narrow { max-width: 860px; }

.page {
  display: block;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 12px;
}

.row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.grid {
  display: grid;
  gap: var(--space-3);
}

.muted { color: var(--text-muted); }

.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: 16px 0;
}

.spacer-1 { height: var(--space-2); }
.spacer-2 { height: var(--space-4); }
.spacer-3 { height: var(--space-6); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-2); }
.mb-2 { margin-bottom: var(--space-4); }
.mb-3 { margin-bottom: var(--space-6); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-2); }
.mt-2 { margin-top: var(--space-4); }
.mt-3 { margin-top: var(--space-6); }

.mr-1 { margin-right: var(--space-2); }
.ml-1 { margin-left: var(--space-2); }

.p-0 { padding: 0; }
.p-1 { padding: var(--space-2); }
.p-2 { padding: var(--space-4); }
.px-2 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

.text-xs { font-size: .82rem; }
.text-sm { font-size: .88rem; }
.text-md { font-size: .95rem; }

.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--orange); }

.anim-fade-up { animation: fadeUp .4s ease; }

.mono { font-family: var(--font-mono); }

.nowrap { white-space: nowrap; }

.mw-300 { max-width: 300px; }
.mw-320 { max-width: 320px; }
.mw-220 { max-width: 220px; }
.mw-400 { max-width: 400px; }

.w-150 { width: 150px; }
.w-220 { width: 220px; }
.w-36 { width: 36px; }
.w-48 { width: 48px; }

.row-between { justify-content: space-between; }

.text-left { text-align: left; }
.text-right { text-align: right; }

.divider-inline {
  margin: 0 6px;
  color: rgba(148, 163, 184, .6);
}

.hint {
  background: rgba(249, 115, 22, .10);
  border: 1px solid rgba(249, 115, 22, .22);
  border-radius: 16px;
  padding: 16px;
  font-size: .9rem;
  line-height: 1.9;
  color: var(--text-secondary);
}

.panel-dashed {
  background: rgba(148, 163, 184, .06);
  border: 2px dashed rgba(148, 163, 184, .25);
  border-radius: 12px;
  padding: 22px;
  text-align: center;
  color: var(--text-muted);
}

.logo-preview {
  background: rgba(15, 23, 42, .04);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, .22);
  display: inline-block;
}

.logo-preview img {
  max-height: 80px;
  max-width: 300px;
  display: block;
}

.upload-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.form-group.mb-0 { margin: 0; }

.check-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .9rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 10px 14px;
  background: rgba(249, 115, 22, .08);
  border: 1px solid rgba(249, 115, 22, .22);
  border-radius: var(--radius);
}

.check-pill input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.modal-pad-sm { padding: 16px 20px; }
.modal-pad { padding: 20px; }

.form-inline {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.td-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  position: relative;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.02);
}

.toolbar .toolbar-left,
.toolbar .toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.more-menu { position: relative; }

.more-menu > summary {
  list-style: none;
}

.more-menu > summary::-webkit-details-marker { display: none; }

.more-menu > summary.btn {
  user-select: none;
}

.more-menu[open] > summary.btn {
  background: rgba(255,255,255,.08);
  border-color: var(--border-strong);
}

.more-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  min-width: 180px;
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0,0,0,.60);
  overflow: hidden;
  z-index: 9999;
}

.more-menu-panel a,
.more-menu-panel button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
  border-bottom: 1px solid rgba(148,163,184,.14);
}

.more-menu-panel form {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(148,163,184,.14);
}

.more-menu-panel form:last-child { border-bottom: 0; }

.more-menu-panel .menu-title {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.more-menu-panel .menu-form-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.more-menu-panel .menu-form-row .form-control { flex: 1 1 160px; min-width: 160px; }

.more-menu-panel a:last-child,
.more-menu-panel button:last-child { border-bottom: 0; }

.more-menu-panel a:hover,
.more-menu-panel button:hover { background: rgba(255,255,255,.06); }

.more-menu-panel .danger { color: #fecaca; }
.more-menu-panel .danger:hover { background: rgba(239,68,68,.12); }

.td-actions-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.hidden { display: none; }
.is-hidden { display: none; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.pager .meta {
  color: var(--text-muted);
  font-size: .86rem;
}

.page-header h1 {
  font-size: 1.25rem;
  color: var(--text);
}

.page-header p {
  color: var(--text-muted);
}

.tabs {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap;
}

.tabs::-webkit-scrollbar { height: 6px; }
.tabs::-webkit-scrollbar-thumb { background: rgba(148,163,184,.35); border-radius: 99px; }

.tab-link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 700;
  font-size: .92rem;
  white-space: nowrap;
  transition: var(--transition);
}

.tab-link:hover {
  background: rgba(255,255,255,.06);
  color: var(--text);
}

.tab-link.active {
  background: rgba(249,115,22,.14);
  border-color: rgba(249,115,22,.30);
  color: #fff7ed;
}

.card,
.stat-card,
.kpi {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 18px;
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi {
  padding: 14px 16px;
}

.kpi.kpi-link {
  display: block;
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.kpi.kpi-link:hover { border-color: rgba(249,115,22,.26); }

.kpi.kpi-link:active { transform: translateY(1px); }

.kpi.kpi-link:focus-visible {
  outline: 2px solid rgba(249,115,22,.25);
  outline-offset: 2px;
}

.kpi .kpi-num {
  font-family: var(--font-mono);
  font-size: 1.9rem;
  letter-spacing: 2px;
  line-height: 1;
  color: var(--orange);
}

.kpi .kpi-label {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.card::before,
.kpi::before,
.stat-card::before { display: none; }

.card-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-header > * { min-width: 0; }

.card-header .badge { flex: 0 0 auto; }

.card-header .td-actions { justify-content: flex-end; }

.card-header h2 { color: var(--text-secondary); }

.card-body { padding: 16px; }

.btn {
  height: var(--btn-h);
  min-height: var(--btn-h);
  padding: 0 16px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  font-size: .95rem;
  line-height: 1;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: translateY(1px); }

.btn:disabled,
.btn.disabled {
  opacity: .55;
  cursor: not-allowed;
  box-shadow: none !important;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(180deg, rgba(249,115,22,1) 0%, rgba(234,88,12,1) 100%);
  color: #111827;
  box-shadow: 0 12px 28px rgba(249, 115, 22, .20);
}

.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 16px 34px rgba(249, 115, 22, .26); }

.btn-secondary {
  background: rgba(255,255,255,.04);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { background: rgba(255,255,255,.08); border-color: var(--border-strong); }

.btn-ghost {
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: rgba(255,255,255,.02);
}

.btn-ghost:hover { background: rgba(255,255,255,.08); border-color: var(--border-strong); }

.btn-danger {
  background: rgba(239, 68, 68, .12);
  border-color: rgba(239, 68, 68, .26);
  color: #fecaca;
}

.btn-danger:hover { background: rgba(239, 68, 68, .18); border-color: rgba(239, 68, 68, .38); }

.btn-sm { height: 40px; min-height: 40px; padding: 0 12px; font-size: .88rem; border-radius: 10px; }
.btn-full { width: 100%; }

.table-wrap {
  border-radius: var(--radius-lg);
  overflow-x: auto;
  overflow-y: visible;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  min-width: 0;
  position: relative;
}

/* Ensure tables never cause horizontal scroll */
.table-wrap table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

/* Form overflow protection */
.form-group, .filter-bar, .jex-stats-filterwrap {
  min-width: 0;
  overflow-wrap: break-word;
}

/* Customer portal mobile protection */
.site-header, .hero, .search-wrap, .search-card, .search-row, .alert-box {
  max-width: 100% !important;
  min-width: 0 !important;
  overflow-wrap: break-word !important;
  word-break: break-word !important;
}

.search-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.search-input {
  flex: 1;
  min-width: 0;
}

.search-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .search-row {
    flex-direction: column;
  }
  .search-btn {
    width: 100%;
  }
}

/* Invoice viewer mobile protection */
.wrap, .topbar, .viewer, .frame, iframe {
  max-width: 100% !important;
  min-width: 0 !important;
  overflow-x: hidden !important;
}

.frame {
  margin: 8px;
}

@media (max-width: 520px) {
  .frame {
    margin: 4px;
    border-radius: 12px;
  }
}

/* Login page mobile protection */
.login-page, .login-card {
  max-width: 100% !important;
  min-width: 0 !important;
  overflow-x: hidden !important;
}

.login-card {
  margin: 16px;
}

@media (max-width: 520px) {
  .login-card {
    margin: 8px;
    padding: 20px 16px;
  }
}

/* Legacy style.css overrides to prevent mobile overflow */
.jex-filtergrid, .jex-stats-filtergrid, .filter-bar .form-group, .filters-row .form-group {
  min-width: 0 !important;
  flex: 1 1 0 !important;
}

.jex-filter-actions, .jex-stats-actions {
  flex-wrap: wrap;
  gap: 8px;
}

.jex-filter-actions button, .jex-filter-actions a,
.jex-stats-actions button, .jex-stats-actions a {
  width: auto;
  min-width: 0;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .jex-filter-actions button, .jex-filter-actions a,
  .jex-stats-actions button, .jex-stats-actions a {
    width: 100%;
    min-width: 0;
  }
}

.table,
.table-wrap table,
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .92rem;
}

thead th {
  background: rgba(255,255,255,.05);
  color: rgba(226,232,240,.78);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  color: var(--text-secondary);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover td { background: rgba(255,255,255,.04); }

tbody tr:nth-child(even) td { background: rgba(255,255,255,.02); }

thead th:first-child { border-top-right-radius: var(--radius-lg); }
thead th:last-child { border-top-left-radius: var(--radius-lg); }

.form-label { color: var(--text-secondary); }

.input,
.select,
.textarea,
.form-control {
  background: rgba(255,255,255,.03);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  height: var(--control-h);
  padding: 0 14px;
  outline: none;
  transition: var(--transition);
}

textarea.form-control,
.textarea,
textarea {
  height: auto;
  min-height: 120px;
  padding: 12px 14px;
}

select.form-control,
.select,
select {
  height: var(--control-h);
}

.form-control::placeholder { color: #94a3b8; }

.form-control:focus-visible {
  border-color: rgba(249, 115, 22, .55);
  box-shadow: 0 0 0 4px rgba(249, 115, 22, .18);
}

.form-control:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  background: rgba(255,255,255,.02);
  color: rgba(226,232,240,.45);
  cursor: not-allowed;
}

.is-invalid,
.form-control.is-invalid { border-color: rgba(239, 68, 68, .45) !important; box-shadow: 0 0 0 4px rgba(239, 68, 68, .12) !important; }
.is-valid,
.form-control.is-valid { border-color: rgba(34, 197, 94, .45) !important; box-shadow: 0 0 0 4px rgba(34, 197, 94, .10) !important; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text-secondary);
}

.badge-blue {
  background: rgba(249, 115, 22, .14);
  border-color: rgba(249, 115, 22, .26);
  color: #ffedd5;
}

.hint { color: var(--text-muted); font-size: .86rem; }

.alert {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.alert-success { background: rgba(34,197,94,.10); border-color: rgba(34,197,94,.22); color: #bbf7d0; }
.alert-warning { background: rgba(245,158,11,.10); border-color: rgba(245,158,11,.22); color: #fde68a; }
.alert-danger,
.alert-error { background: rgba(239,68,68,.10); border-color: rgba(239,68,68,.22); color: #fecaca; }

@media (max-width: 980px) {
  :root { --sidebar-w: 220px; }
}

@media (max-width: 820px) {
  html, body { overflow-x: hidden; }
  .app-shell,
  [dir="rtl"] .app-shell { grid-template-columns: 1fr !important; }
  
  /* Force key containers to respect mobile viewport (without clipping menus) */
  .page-wrapper, .page, .main {
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: clip;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
    width: 100% !important;
  }

  /* Cards should allow popovers/menus; keep text safe */
  .card, .card-body {
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: visible !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  /* Table wrapper stays scrollable */
  .table-wrap {
    max-width: 100% !important;
    min-width: 0 !important;
  }

/* Ensure tables never cause overflow */
  .table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap table {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
  }
  
  .sidebar {
    position: fixed;
    right: 0;
    left: auto;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    width: min(86vw, 320px);
    max-width: 320px;
    border-right: 0;
    border-left: 1px solid var(--border);
    border-bottom: 0;
    transform: translateX(100%);
    transition: var(--transition);
    z-index: 9999;
  }

  .page-wrapper, .page { position: relative; z-index: 2; }

  .main { 
    width: 100%;
    max-width: 100%;
    padding: 16px 14px 28px; 
    margin-right: 0; 
    margin-left: 0; 
    position: relative; 
    z-index: 2; 
  }

  .btn-mobile-full { width: 100%; }

  .topbar-toggle { display: inline-flex; }

  /* Counter global [dir="rtl"] .main { margin-right: var(--sidebar-w) } — higher specificity wins */
  [dir="rtl"] .main { margin-right: 0 !important; margin-left: 0 !important; }
  .main { margin-left: 0 !important; margin-right: 0 !important; }

  /* Counter global .sidebar { z-index: 100 } which comes after this media block */
  .sidebar { z-index: 9999 !important; }

  /* Hide desktop nav links — sidebar handles navigation on mobile */
  .topbar-nav { display: none !important; }

  /* Prevent topbar from wrapping (style.css @media ≤640px sets flex-wrap:wrap) */
  .topbar { flex-wrap: nowrap !important; height: var(--topbar-h) !important; overflow: hidden; align-items: center; }

  /* Counter style.css: .topbar-right{width:100%} squeezes .topbar-left to 0 → toggle hidden */
  .topbar-right { width: auto !important; flex-wrap: nowrap !important; row-gap: 0 !important; }
  .topbar > div:first-child { flex-wrap: nowrap !important; }

  /* Reduce modal padding so modal box fits at 375px viewport */
  .modal-wrap { padding: 8px !important; }

  body.sb-open .sidebar { transform: translateX(0); }

  body.sb-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 9998;
    pointer-events: auto;
  }
}

.action-btn {
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.action-btn:hover {
  background: rgba(255,255,255,.07);
  color: var(--text);
  border-color: rgba(249, 115, 22, .32);
}

.action-dropdown {
  background: #0b1220;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  z-index: 9999;
  position: absolute;
}

.action-dropdown button {
  color: var(--text-secondary);
}

.action-dropdown button:hover {
  background: rgba(255,255,255,.06);
  color: var(--text);
}

#addStaffModal { background: rgba(15, 23, 42, .55); }

.modal-card {
  background: #0b1220;
  border: 1px solid var(--border);
  box-shadow: 0 26px 80px rgba(0,0,0,.6);
}

.modal-header h3 { color: var(--text); }

.checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.input-sm {
  height: 36px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: .88rem;
}

.bulk-bar {
  display: none;
  padding: 12px 16px;
  background: rgba(239, 68, 68, .08);
  border-bottom: 1px solid rgba(239, 68, 68, .22);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: var(--radius-lg);
  flex-wrap: wrap;
}

.bulk-bar.is-visible { display: flex; }

.bulk-bar form { margin: 0; }

.bulk-count {
  font-size: .88rem;
  color: #fecaca;
  font-weight: 700;
}

.review-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 1000;
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
}

.review-modal.is-open { display: flex; }

.review-modal-card {
  background: #0b1220;
  border: 1px solid rgba(249, 115, 22, .28);
  border-radius: 16px;
  width: min(860px, 95vw);
  height: min(90vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 32px 90px rgba(0,0,0,.62);
}

.review-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.review-modal-title {
  font-size: .92rem;
  font-weight: 800;
  color: var(--text-secondary);
}

.review-modal-title strong { color: var(--orange-dark); }

.review-modal-close {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.review-modal-close:hover { background: var(--surface-2); }

.review-modal-body {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--surface);
}

.review-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: .9rem;
  background: var(--surface);
}

.review-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(249,115,22,.20);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.review-iframe {
  width: 100%;
  height: 100%;
  border: none;
  opacity: 0;
  transition: opacity .2s ease;
}

.review-iframe.review-loaded { opacity: 1; }

@media (max-width: 520px) {
  .card-header { flex-wrap: wrap; }
  .card-header .td-actions { width: 100%; justify-content: flex-start; }

  .bulk-bar { padding: 12px 14px; }

  .review-modal-card { width: 98vw; height: 92vh; }
  .review-modal-header { padding: 12px 14px; }
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 14px;
  background: radial-gradient(900px 520px at 70% 10%, rgba(249, 115, 22, .22), transparent 60%),
              linear-gradient(180deg, #0b1220 0%, #070b13 100%);
  overflow-x: hidden;
}

.login-page .login-card {
  width: 100%;
  max-width: 420px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  box-shadow: 0 26px 90px rgba(0,0,0,.55);
  border-radius: 20px;
  padding: 22px 20px;
}

.login-logo {
  text-align: center;
  margin-bottom: 16px;
}

.login-logo img {
  max-height: 44px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: inline-block;
  margin-bottom: 10px;
}

.login-logo .brand-name {
  display: block;
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.login-logo .brand-sub {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.login-logo .portal-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.login-page .form-group {
  margin-bottom: 12px;
}

.login-page .form-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: block;
}

.login-page .form-control {
  height: var(--control-h);
}

.login-page input.form-control {
  height: var(--control-h);
}

.login-page .form-control::placeholder {
  color: #94a3b8;
}

.login-page .alert {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 500;
}

.login-page .alert.alert-error,
.login-page .alert.alert-danger {
  color: #fecaca;
  background: rgba(239, 68, 68, .10);
  border-color: rgba(239, 68, 68, .22);
}

.login-page .btn {
  height: var(--btn-h);
}

.login-page button.btn,
.login-page a.btn {
  height: var(--btn-h);
}

.login-page .btn-primary {
  box-shadow: none;
}

.login-page .btn-primary:hover {
  box-shadow: 0 16px 34px rgba(249, 115, 22, .22);
}

.site-header {
  position: relative;
  z-index: 10;
  background: rgba(0,0,0,.35);
  border-bottom: 1px solid rgba(249,115,22,.18);
  padding: 0 20px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.header-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 22px 0 18px;
  gap: 10px;
}

.logo-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.logo-wrap img { height: 52px; width: auto; display: block; object-fit: contain; }
.logo-subtitle { font-size: .78rem; color: var(--text-muted); letter-spacing: 2px; text-align: center; }
.logo-text { display: flex; flex-direction: column; align-items: center; }
.logo-text .brand-name { font-size: 2rem; font-weight: 800; color: var(--orange); letter-spacing: 3px; line-height: 1; }
.logo-text .brand-sub { font-size: .72rem; color: var(--text-muted); letter-spacing: 2px; text-transform: uppercase; margin-top: 3px; text-align: center; }

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: .82rem;
  color: var(--text-muted);
}

.header-badge .dot {
  width: 8px;
  height: 8px;
  background: var(--orange);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(249,115,22,.14);
}

.hero { position: relative; z-index: 5; text-align: center; padding: 44px 20px 0; }

.hero-tag {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(249,115,22,.10);
  border: 1px solid rgba(249,115,22,.20);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: .74rem;
  color: #ffedd5;
  letter-spacing: 1px;
  margin-bottom: 18px;
}

.hero h1 { font-size: clamp(1.55rem, 5vw, 2.5rem); font-weight: 800; line-height: 1.18; margin-bottom: 12px; }
.hero h1 span { color: var(--orange); }
.hero p { color: var(--text-muted); font-size: .92rem; line-height: 1.8; max-width: 520px; margin: 0 auto 34px; }

.search-wrap { position: relative; z-index: 10; max-width: 620px; margin: 0 auto; padding: 0 16px; }

.search-card {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 26px 90px rgba(0,0,0,.55);
  position: relative;
  overflow: hidden;
}

.search-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(249,115,22,.9), transparent);
}

.search-label { font-size: .9rem; color: var(--text-muted); margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.search-label::before { content: ''; width: 3px; height: 14px; background: var(--orange); border-radius: 2px; display: block; }

.search-row { display: flex; gap: 10px; }

.search-input {
  flex: 1;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(148,163,184,.22);
  border-radius: 14px;
  color: var(--text);
  font-size: 1.05rem;
  padding: 0 16px;
  height: var(--control-h);
  direction: ltr;
  text-align: center;
  letter-spacing: 2px;
  transition: var(--transition);
  outline: none;
}

.search-input::placeholder { color: rgba(226,232,240,.35); letter-spacing: 1px; }

.search-input:focus-visible {
  border-color: rgba(249,115,22,.55);
  background: rgba(249,115,22,.04);
  box-shadow: 0 0 0 4px rgba(249,115,22,.18);
}

.search-input:disabled { opacity: .55; cursor: not-allowed; }

.search-btn {
  height: var(--btn-h);
  padding: 0 18px;
  border: 1px solid rgba(249,115,22,.28);
  border-radius: 14px;
  background: rgba(249,115,22,.14);
  color: #fff7ed;
  font-size: .95rem;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.search-btn:hover:not(:disabled) { background: rgba(249,115,22,.20); border-color: rgba(249,115,22,.40); }
.search-btn:disabled { opacity: .45; cursor: not-allowed; }
.search-btn:focus-visible { outline: 2px solid rgba(249,115,22,.55); outline-offset: 2px; }

.phone-hint {
  margin-top: 10px;
  font-size: .86rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(226,232,240,.55);
  transition: color .2s;
}

.phone-hint.is-valid { color: rgba(74, 222, 128, .95); }
.phone-hint.is-invalid { color: rgba(248, 113, 113, .95); }

.search-input.is-valid {
  border-color: rgba(74, 222, 128, .55);
  box-shadow: 0 0 0 4px rgba(74, 222, 128, .14);
}

.search-input.is-invalid {
  border-color: rgba(248, 113, 113, .55);
  box-shadow: 0 0 0 4px rgba(248, 113, 113, .14);
}

.inquiry-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding: 10px 14px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: .86rem;
  color: var(--text-muted);
}

.inquiry-meta { display: flex; align-items: center; gap: 10px; }
.inquiry-remaining { font-size: .86rem; color: var(--text-muted); }

.inquiry-dots { display: flex; gap: 6px; }
.inq-dot { width: 10px; height: 10px; border-radius: 50%; transition: var(--transition); }
.inq-dot.used  { background: var(--orange); box-shadow: 0 0 10px rgba(249,115,22,.25); }
.inq-dot.avail { background: rgba(226,232,240,.18); }

.alert-box {
  border-radius: 16px;
  padding: 16px 18px;
  margin-top: 16px;
  font-size: .92rem;
  line-height: 1.85;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  color: var(--text-secondary);
}

.alert-icon { font-size: 1.4rem; flex-shrink: 0; margin-top: 2px; }
.alert-title { font-weight: 800; display: block; margin-bottom: 4px; font-size: .95rem; }
.alert-error    { border-color: rgba(239,68,68,.22); background: rgba(239,68,68,.08); color: #fecaca; }
.alert-warning  { border-color: rgba(249,115,22,.22); background: rgba(249,115,22,.07); color: #ffedd5; }
.alert-blocked  { border-color: rgba(239,68,68,.22); background: rgba(239,68,68,.08); color: #fecaca; }
.alert-contact  { font-size: .86rem; color: rgba(254,202,202,.7); margin-top: 8px; }
.countdown { font-size: 1.2rem; color: var(--orange); letter-spacing: 1px; margin-top: 6px; display: block; }

.results-wrap { max-width: 620px; margin: 26px auto 0; padding: 0 16px; }
.results-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.results-title { font-size: .92rem; color: var(--text-muted); display: inline-flex; align-items: center; gap: 8px; }
.results-count { background: rgba(249,115,22,.16); color: #ffedd5; font-size: .78rem; font-weight: 800; padding: 4px 10px; border-radius: 999px; border: 1px solid rgba(249,115,22,.22); }

.invoice-card {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.invoice-card::before {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--orange);
  border-radius: 0 18px 18px 0;
}

.invoice-card:hover { border-color: rgba(249,115,22,.28); background: rgba(249,115,22,.03); transform: translateY(-1px); }

.inv-num { font-size: .82rem; color: #ffedd5; font-weight: 700; letter-spacing: 1px; margin-bottom: 6px; }
.inv-type { font-size: 1.02rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.inv-date { font-size: .82rem; color: var(--text-muted); direction: ltr; text-align: right; }

.btn-view {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--btn-h);
  padding: 0 16px;
  background: rgba(249,115,22,.14);
  border: 1px solid rgba(249,115,22,.26);
  color: #fff7ed;
  border-radius: 14px;
  font-size: .9rem;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-view:hover { background: rgba(249,115,22,.20); border-color: rgba(249,115,22,.38); }
.btn-view:focus-visible { outline: 2px solid rgba(249,115,22,.55); outline-offset: 2px; }

.empty-state { text-align: center; padding: 44px 18px; color: var(--text-muted); }
.empty-icon { font-size: 3rem; margin-bottom: 14px; opacity: .55; }
.empty-state p { font-size: 1rem; }

.site-footer { position: relative; z-index: 5; text-align: center; padding: 44px 20px 30px; color: rgba(226,232,240,.35); font-size: .86rem; }
.site-footer strong { color: var(--orange); }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  z-index: 1000;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-overlay.active { display: flex; }

.modal-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 20px;
}

.modal-box {
  background: #0b1220;
  border: 1px solid rgba(249,115,22,.24);
  border-radius: 18px;
  width: min(860px, 95vw);
  height: min(90vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 32px 90px rgba(0,0,0,.65);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: rgba(255,255,255,.02);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.modal-title { font-size: .95rem; font-weight: 800; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.modal-title span { color: #ffedd5; }
.modal-actions { display: flex; align-items: center; gap: 10px; }

.btn-print {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 12px;
  font-size: .86rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-print:hover { background: rgba(255,255,255,.08); border-color: var(--border-strong); }

.btn-close {
  width: 38px;
  height: 38px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-close:hover { background: rgba(239,68,68,.14); border-color: rgba(239,68,68,.28); color: #fecaca; }

.modal-body { flex: 1; overflow: hidden; position: relative; background: #0b1220; }

.modal-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: .95rem;
  background: #0b1220;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(249,115,22,.16);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.iframe-wrap { width: 100%; height: 100%; overflow: hidden; position: relative; }

.invoice-iframe {
  border: none;
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== إصلاحات Layout ===== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-shell {
  margin-top: var(--topbar-h);
}

.topbar {
  position: fixed !important;
  top: 0; left: 0; right: 0;
  z-index: 200;
}

.sidebar {
  position: fixed !important;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  z-index: 100;
}

[dir="rtl"] .sidebar { right: 0; left: auto; }

[dir="rtl"] .main { margin-right: var(--sidebar-w); margin-left: 0; }

.main { margin-left: var(--sidebar-w); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin: 20px 0 28px;
}