/* ══════════════════════════════════════════════════════
   مصنع أجيوس للحديد — نظام الإدارة
   نظام التصميم الكامل (RTL/LTR + فاتح/داكن)
   ══════════════════════════════════════════════════════ */

:root {
  /* الأخضر الأساسي */
  --primary-50:  #e9f6ef;
  --primary-100: #c9e9d7;
  --primary-200: #a2d9ba;
  --primary-300: #76c79a;
  --primary-400: #52b881;
  --primary-500: #3dae6b;
  --primary-600: #2d9459;
  --primary-700: #1f7a48;
  --primary-800: #155e37;
  --primary-900: #0c4126;

  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  --bg:        #f4f7f9;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --border:    #e5eaf0;
  --text:      #0f172a;
  --text-soft: #475569;
  --muted:     #94a3b8;

  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;
  --info:    #3b82f6;

  --shadow-xs: 0 1px 2px rgba(15,23,42,.05);
  --shadow-sm: 0 1px 3px rgba(15,23,42,.07), 0 1px 2px rgba(15,23,42,.04);
  --shadow:    0 4px 12px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.04);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.12), 0 4px 8px rgba(15,23,42,.05);

  --radius-sm: 7px;
  --radius:    11px;
  --radius-lg: 16px;

  --sidebar-w: 258px;
  --topbar-h:  62px;

  --font: 'Cairo', 'Segoe UI', system-ui, sans-serif;
  --font-en: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Cascadia Mono', 'Courier New', monospace;

  --ease: cubic-bezier(.22,.68,.32,1);
}

[data-theme="dark"] {
  --bg:        #080e1a;
  --surface:   #0f1829;
  --surface-2: #16223a;
  --border:    #1e2c47;
  --text:      #e8eef7;
  --text-soft: #b6c4d8;
  --muted:     #7d8ca5;

  --gray-50:  #16223a;
  --gray-100: #16223a;
  --gray-200: #1e2c47;
  --gray-300: #2b3c5c;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.3);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow:    0 4px 14px rgba(0,0,0,.4);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.55);
}

/* ── إعادة ضبط ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background .25s var(--ease), color .25s var(--ease);
}
body[dir="ltr"] { font-family: var(--font-en); }
a { color: var(--primary-600); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; color: inherit; }
h1, h2, h3, h4, h5 { margin: 0; font-weight: 700; }
p { margin: 0; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }
::selection { background: var(--primary-200); color: var(--primary-900); }

/* ══════════ شاشة الدخول ══════════ */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(140deg, var(--primary-800) 0%, var(--primary-600) 45%, var(--primary-400) 100%);
  overflow: hidden; padding: 20px; z-index: 90;
}
.login-bg-shapes { position: absolute; inset: 0; pointer-events: none; }
.login-bg-shapes span {
  position: absolute; border-radius: 50%; background: rgba(255,255,255,.12); filter: blur(50px);
  animation: float 14s ease-in-out infinite;
}
.login-bg-shapes span:nth-child(1) { width: 340px; height: 340px; top: -90px; inset-inline-end: -70px; }
.login-bg-shapes span:nth-child(2) { width: 400px; height: 400px; bottom: -120px; inset-inline-start: -90px; animation-delay: -5s; }
.login-bg-shapes span:nth-child(3) { width: 240px; height: 240px; top: 38%; inset-inline-start: 32%; animation-delay: -9s; }
@keyframes float { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-26px) } }

.login-card {
  position: relative; z-index: 1;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 410px;
  padding: 38px 32px;
  animation: cardIn .55s var(--ease);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(24px) scale(.97) } to { opacity: 1; transform: none } }

.login-brand { text-align: center; margin-bottom: 26px; }
.login-logo {
  width: 76px; height: 76px; border-radius: 20px;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 32px; margin: 0 auto 14px; overflow: hidden;
  box-shadow: 0 10px 24px rgba(31,122,72,.35);
}
.login-logo.has-image { background: #fff; border: 1px solid var(--border); }
.login-logo img { width: 100%; height: 100%; object-fit: contain; }
.login-brand h1 { font-size: 21px; margin-bottom: 5px; }
.login-brand p { color: var(--muted); font-size: 13.5px; }

.login-error {
  background: rgba(239,68,68,.1); color: var(--danger);
  border: 1px solid rgba(239,68,68,.25);
  padding: 11px 14px; border-radius: var(--radius);
  font-size: 13px; margin-bottom: 16px; text-align: center;
  animation: shake .4s;
}
@keyframes shake { 25% { transform: translateX(-6px) } 75% { transform: translateX(6px) } }

.password-wrapper { position: relative; }
.password-toggle {
  position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%);
  color: var(--muted); padding: 6px 9px; border-radius: 6px;
}
.password-toggle:hover { color: var(--primary-600); background: var(--gray-100); }

/* ══════════ النماذج ══════════ */
.form-group { margin-bottom: 15px; min-width: 0; }
.form-group label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--text-soft); margin-bottom: 6px;
}
.form-group label i { margin-inline-end: 5px; color: var(--primary-600); }
.req { color: var(--danger); }

.form-group input, .form-group select, .form-group textarea,
.form-control, .invoice-items-table input, .invoice-items-table select {
  width: 100%;
  padding: 10px 13px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.form-group textarea { resize: vertical; min-height: 70px; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus,
.form-control:focus, .invoice-items-table input:focus, .invoice-items-table select:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(61,174,107,.14);
  background: var(--surface);
}
.form-group input::placeholder, .form-control::placeholder { color: var(--muted); }
input[type="date"] { min-height: 41px; }
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.7); }

.field-hint { display: block; font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 14px; }
.form-grid .col-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.form-actions.start { justify-content: flex-start; }

/* ══════════ الأزرار ══════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 17px; border-radius: var(--radius);
  font-weight: 600; font-size: 13.5px; white-space: nowrap;
  background: var(--gray-100); color: var(--text);
  transition: all .18s var(--ease);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
  color: #fff; box-shadow: 0 4px 12px rgba(31,122,72,.28);
}
.btn-primary:hover { box-shadow: 0 7px 18px rgba(31,122,72,.36); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; box-shadow: 0 4px 12px rgba(239,68,68,.25); }
.btn-ghost   { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--gray-100); color: var(--text); }
.btn-outline { background: transparent; color: var(--primary-600); border: 1.5px solid var(--primary-300); }
.btn-outline:hover { background: var(--primary-50); border-color: var(--primary-500); }
[data-theme="dark"] .btn-outline:hover { background: rgba(61,174,107,.12); }
.btn-block { width: 100%; }
.btn-lg { padding: 13px 20px; font-size: 15px; }
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
label.btn { cursor: pointer; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 37px; height: 37px; border-radius: var(--radius);
  color: var(--text-soft); transition: all .18s;
}
.icon-btn:hover { background: var(--gray-100); color: var(--primary-600); }
.icon-btn.sm { width: 31px; height: 31px; font-size: 12.5px; }
.icon-btn.currency-toggle { font-size: 10px; font-weight: 800; letter-spacing: .2px; }
.icon-btn.danger:hover  { background: rgba(239,68,68,.12); color: var(--danger); }
.icon-btn.success:hover { background: rgba(16,185,129,.12); color: var(--success); }

.link-btn { color: var(--primary-600); font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.link-soft { color: var(--text-soft); }
.link-soft:hover { color: var(--primary-600); }

/* ══════════ الهيكل ══════════ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; inset-block: 0; inset-inline-start: 0;
  z-index: 60; transition: transform .28s var(--ease);
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 17px; overflow: hidden;
}
.brand-logo.has-image { background: var(--surface-2); border: 1px solid var(--border); }
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-title { font-weight: 800; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-close { display: none; width: 34px; height: 34px; border-radius: 8px; color: var(--text-soft); }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px; border-radius: var(--radius);
  color: var(--text-soft); font-weight: 600; font-size: 13.5px;
  transition: all .18s var(--ease); position: relative;
}
.nav-item i { width: 19px; text-align: center; font-size: 15px; }
.nav-item:hover { background: var(--gray-100); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
  color: #fff; box-shadow: 0 5px 14px rgba(31,122,72,.3);
}
.sidebar-footer {
  display: flex; gap: 6px; padding: 11px; justify-content: center;
  border-top: 1px solid var(--border);
}

.main-area {
  flex: 1; min-width: 0;
  margin-inline-start: var(--sidebar-w);
  display: flex; flex-direction: column;
}
.topbar {
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px; position: sticky; top: 0; z-index: 30;
}
.menu-btn { display: none; }
.page-title { font-size: 17px; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.user-chip {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 13px; border-radius: 20px;
  background: var(--primary-50); color: var(--primary-700);
  font-size: 12.5px; font-weight: 700;
}
[data-theme="dark"] .user-chip { background: rgba(61,174,107,.14); color: var(--primary-300); }

.content { padding: 20px; flex: 1; }
.page-loading { display: flex; justify-content: center; padding: 70px 0; }

/* ══════════ بطاقات الإحصاء ══════════ */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 15px; margin-bottom: 18px;
}
.stats-grid.compact { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }

.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 17px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card.mini { padding: 14px; }
.stat-card.mini .stat-icon { width: 42px; height: 42px; font-size: 17px; border-radius: 11px; }
.stat-card.mini .stat-value { font-size: 17px; }

.stat-icon {
  width: 50px; height: 50px; border-radius: 14px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
}
.stat-icon.green  { background: linear-gradient(135deg, #34d399, #059669); }
.stat-icon.blue   { background: linear-gradient(135deg, #60a5fa, #2563eb); }
.stat-icon.amber  { background: linear-gradient(135deg, #fbbf24, #d97706); }
.stat-icon.red    { background: linear-gradient(135deg, #f87171, #dc2626); }
.stat-icon.purple { background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.stat-icon.cyan   { background: linear-gradient(135deg, #22d3ee, #0891b2); }

.stat-info { min-width: 0; flex: 1; }
.stat-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.stat-value {
  font-size: 21px; font-weight: 800; margin-top: 2px;
  letter-spacing: -.4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* ══════════ الكروت ══════════ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden;
}
.card + .card, .card.mt-3 { margin-top: 16px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14.5px; display: flex; align-items: center; gap: 8px; }
.card-title i { color: var(--primary-600); }
.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-body { padding: 18px; }
.card-body.pad-0 { padding: 0; }
.card-body.pad-sm { padding: 14px; }
.sub-card { box-shadow: none; }
.sub-card .card-header { padding: 12px 15px; }
.sub-card .card-title { font-size: 13px; }

/* ══════════ الجداول ══════════ */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table thead th {
  background: var(--surface-2); color: var(--text-soft);
  text-align: start; font-weight: 700; font-size: 11.5px;
  padding: 11px 13px; border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0;
}
.table tbody td { padding: 11px 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .15s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td {
  padding: 12px 13px; background: var(--surface-2);
  border-top: 2px solid var(--primary-300); font-size: 13.5px;
}
.table .num, .table th.num { text-align: end; font-variant-numeric: tabular-nums; }
.table .th-actions { width: 1%; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover { background: var(--primary-50); }
[data-theme="dark"] .table tr.clickable:hover { background: rgba(61,174,107,.08); }
.table-foot { padding: 10px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }

.cell-main { font-weight: 600; }
.cell-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.cell-avatar { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  background: var(--primary-100); color: var(--primary-800);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px;
}
[data-theme="dark"] .avatar { background: rgba(61,174,107,.16); color: var(--primary-300); }
.mono { font-family: var(--mono); font-size: .94em; }
.actions { display: flex; gap: 2px; }

.qty-pill {
  display: inline-block; padding: 3px 10px; border-radius: 8px;
  font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--gray-100); color: var(--text);
}
.qty-pill.ok     { background: rgba(16,185,129,.12); color: #059669; }
.qty-pill.warn   { background: rgba(245,158,11,.14); color: #b45309; }
.qty-pill.danger { background: rgba(239,68,68,.12); color: #dc2626; }
[data-theme="dark"] .qty-pill.ok { color: #6ee7b7; }
[data-theme="dark"] .qty-pill.warn { color: #fcd34d; }
[data-theme="dark"] .qty-pill.danger { color: #fca5a5; }

/* ══════════ الشارات ══════════ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3.5px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
  background: var(--gray-100); color: var(--text-soft);
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-primary { background: var(--primary-100); color: var(--primary-800); }
[data-theme="dark"] .badge-success { background: rgba(16,185,129,.16); color: #6ee7b7; }
[data-theme="dark"] .badge-warning { background: rgba(245,158,11,.16); color: #fcd34d; }
[data-theme="dark"] .badge-danger  { background: rgba(239,68,68,.16);  color: #fca5a5; }
[data-theme="dark"] .badge-info    { background: rgba(59,130,246,.16); color: #93c5fd; }
[data-theme="dark"] .badge-primary { background: rgba(61,174,107,.16); color: var(--primary-300); }

/* ══════════ شريط الأدوات ══════════ */
.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .search { position: relative; flex: 1; min-width: 200px; }
.toolbar .search i {
  position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 13px; pointer-events: none;
}
.toolbar .search input {
  width: 100%; padding: 10px 13px; padding-inline-start: 35px;
  background: var(--surface-2); border: 1.5px solid var(--border);
  border-radius: var(--radius); color: var(--text);
}
.toolbar .search input:focus {
  outline: none; border-color: var(--primary-500); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(61,174,107,.14);
}
.form-control.auto { width: auto; min-width: 140px; }
.date-range { display: flex; align-items: center; gap: 6px; }
.date-range span { color: var(--muted); }

.chip-toggle { display: inline-flex; cursor: pointer; }
.chip-toggle input { display: none; }
.chip-toggle span {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: var(--radius);
  border: 1.5px solid var(--border); background: var(--surface-2);
  font-size: 12.5px; font-weight: 600; color: var(--text-soft);
  transition: all .18s;
}
.chip-toggle input:checked + span {
  background: var(--primary-50); border-color: var(--primary-400); color: var(--primary-700);
}
[data-theme="dark"] .chip-toggle input:checked + span { background: rgba(61,174,107,.14); color: var(--primary-300); }

.chip {
  padding: 7px 14px; border-radius: 20px; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); border: 1.5px solid var(--border); color: var(--text-soft);
  transition: all .18s;
}
.chip:hover { border-color: var(--primary-300); }
.chip.active { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }

.range-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding-bottom: 4px;
}
.range-presets { display: flex; gap: 7px; flex-wrap: wrap; }

/* ══════════ الحالات الفارغة ══════════ */
.empty-state { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty-state.compact { padding: 26px 16px; }
.empty-state i { font-size: 42px; margin-bottom: 12px; opacity: .45; display: block; }
.empty-state p { font-size: 13.5px; }

/* ══════════ لوحة التحكم ══════════ */
.dashboard-grid { display: grid; grid-template-columns: 1.75fr 1fr; gap: 16px; }
.chart-container { position: relative; height: 300px; width: 100%; }
.chart-container.sm { height: 230px; }

.alert-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.alert-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius);
  background: rgba(245,158,11,.07); border: 1px solid rgba(245,158,11,.18);
}
.alert-item.critical { background: rgba(239,68,68,.07); border-color: rgba(239,68,68,.2); }
.alert-icon {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(245,158,11,.18); color: #b45309; font-size: 13px;
}
.alert-item.critical .alert-icon { background: rgba(239,68,68,.16); color: #dc2626; }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 600; font-size: 13px; }
.alert-meta { font-size: 11px; color: var(--muted); }
.alert-value { font-weight: 800; font-size: 14px; white-space: nowrap; }
.alert-value small { font-size: 10.5px; font-weight: 600; opacity: .75; }

.rank-list { display: flex; flex-direction: column; gap: 13px; }
.rank-item { display: flex; gap: 11px; align-items: flex-start; }
.rank-no {
  width: 25px; height: 25px; border-radius: 8px; flex-shrink: 0;
  background: var(--primary-100); color: var(--primary-800);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 12px;
}
[data-theme="dark"] .rank-no { background: rgba(61,174,107,.16); color: var(--primary-300); }
.rank-body { flex: 1; min-width: 0; }
.rank-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; }
.rank-name { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-value { font-size: 12.5px; font-weight: 800; color: var(--primary-600); white-space: nowrap; }
.rank-bar { height: 6px; border-radius: 4px; background: var(--gray-100); overflow: hidden; }
.rank-bar span {
  display: block; height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--primary-400), var(--primary-600));
}
.rank-meta { font-size: 10.5px; color: var(--muted); margin-top: 4px; }

/* ══════════ النوافذ ══════════ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8,14,26,.6);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 120; padding: 16px; animation: fadeIn .18s;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 620px; max-height: 92vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-lg); animation: modalIn .26s var(--ease);
}
.modal.lg { max-width: 1000px; }
.modal.sm { max-width: 420px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(22px) scale(.97) } to { opacity: 1; transform: none } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.modal-title i { color: var(--primary-600); }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 13px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
}
.modal form { display: contents; }
.confirm-text { font-size: 14.5px; line-height: 1.7; }

/* ══════════ الإشعارات ══════════ */
.toast-container {
  position: fixed; top: 16px; inset-inline-end: 16px;
  z-index: 200; display: flex; flex-direction: column; gap: 9px;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--primary-500);
  padding: 12px 15px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); min-width: 270px; max-width: 400px;
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 13.5px; line-height: 1.6;
  animation: toastIn .28s var(--ease);
  transition: opacity .25s, transform .25s;
}
@keyframes toastIn { from { transform: translateY(-14px); opacity: 0 } to { transform: none; opacity: 1 } }
.toast > i { font-size: 16px; margin-top: 1px; flex-shrink: 0; }
.toast > span { flex: 1; }
.toast-close { color: var(--muted); padding: 0 2px; font-size: 12px; flex-shrink: 0; }
.toast-close:hover { color: var(--text); }
.toast.success { border-inline-start-color: var(--success); }
.toast.success > i { color: var(--success); }
.toast.error { border-inline-start-color: var(--danger); }
.toast.error > i { color: var(--danger); }
.toast.warning { border-inline-start-color: var(--warning); }
.toast.warning > i { color: var(--warning); }
.toast.info { border-inline-start-color: var(--info); }
.toast.info > i { color: var(--info); }

/* ══════════ منشئ الفاتورة ══════════ */
.builder-items { margin-top: 6px; }
.builder-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; gap: 10px;
}
.builder-head h4 { font-size: 13.5px; display: flex; align-items: center; gap: 7px; }
.builder-head h4 i { color: var(--primary-600); }

.invoice-items-table { font-size: 13px; }
.invoice-items-table thead th { background: var(--surface-2); }
.invoice-items-table td { padding: 7px 8px; vertical-align: top; }
.invoice-items-table input, .invoice-items-table select { padding: 8px 10px; font-size: 13px; }
.invoice-items-table input.num { text-align: end; font-variant-numeric: tabular-nums; }
.invoice-items-table .row-total { padding-top: 16px; white-space: nowrap; }

.builder-bottom {
  display: grid; grid-template-columns: 1fr 320px; gap: 16px;
  margin-top: 14px; align-items: start;
}
.invoice-summary {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.invoice-summary .row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding: 7px 0; font-size: 13.5px;
}
.invoice-summary .row + .row { border-top: 1px dashed var(--border); }
.invoice-summary .row.total {
  border-top: 2px solid var(--primary-400); margin-top: 5px; padding-top: 11px;
  font-size: 17px; font-weight: 800; color: var(--primary-700);
}
[data-theme="dark"] .invoice-summary .row.total { color: var(--primary-300); }
.summary-input {
  width: 110px !important; padding: 6px 10px !important;
  text-align: end; font-variant-numeric: tabular-nums;
}

/* ══════════ عرض الفاتورة ══════════ */
.view-head {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 16px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.view-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.view-value { font-size: 15px; font-weight: 700; margin-top: 2px; }
.view-totals { display: flex; justify-content: flex-end; margin-top: 14px; }
.view-totals .invoice-summary { width: 320px; max-width: 100%; }
.note-box {
  margin-top: 14px; padding: 11px 14px; border-radius: var(--radius);
  background: rgba(245,158,11,.08); border-inline-start: 3px solid var(--warning);
  font-size: 13px; line-height: 1.7;
}
.note-box i { color: var(--warning); margin-inline-end: 6px; }
.section-title {
  font-size: 13.5px; margin: 20px 0 10px;
  display: flex; align-items: center; gap: 7px;
}
.section-title i { color: var(--primary-600); }

/* ══════════ كشف الحساب ══════════ */
.statement-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.statement-summary > div {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 13px;
}
.statement-summary > div.highlight { border-color: var(--primary-300); background: var(--primary-50); }
[data-theme="dark"] .statement-summary > div.highlight { background: rgba(61,174,107,.1); }
.statement-summary span { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.statement-summary b { font-size: 16px; display: block; margin-top: 3px; }
.statement-table .debit { color: var(--danger); font-weight: 700; }
.statement-table .credit { color: var(--success); font-weight: 700; }

/* ══════════ التبويبات ══════════ */
.tabs {
  display: flex; gap: 3px; border-bottom: 1.5px solid var(--border);
  margin-bottom: 16px; overflow-x: auto;
}
.tab {
  padding: 10px 16px; color: var(--text-soft); font-weight: 600; font-size: 13.5px;
  border-bottom: 2.5px solid transparent; margin-bottom: -1.5px;
  white-space: nowrap; display: flex; align-items: center; gap: 7px;
  transition: color .18s, border-color .18s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary-600); border-bottom-color: var(--primary-500); }

/* ══════════ التقارير ══════════ */
.report-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ══════════ الإعدادات ══════════ */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.logo-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo-preview {
  width: 84px; height: 84px; border-radius: var(--radius-lg); flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 32px; overflow: hidden;
}
.logo-preview.has-image { background: var(--surface-2); border: 1px solid var(--border); }
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 13px 0;
}
.setting-row + .setting-row { border-top: 1px solid var(--border); }
.setting-title { font-size: 13.5px; font-weight: 600; }
.rate-input { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); flex-wrap: wrap; }

/* ══════════ مؤشر التحميل ══════════ */
.spinner {
  width: 34px; height: 34px; border: 3px solid var(--gray-200);
  border-top-color: var(--primary-500); border-radius: 50%;
  animation: spin .8s linear infinite; display: inline-block;
}
.spinner-sm { width: 15px; height: 15px; border-width: 2px; border-top-color: #fff; border-color: rgba(255,255,255,.35); }
@keyframes spin { to { transform: rotate(360deg) } }
.loading-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(244,247,249,.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
}
[data-theme="dark"] .loading-overlay { background: rgba(8,14,26,.6); }

/* ══════════ أدوات مساعدة ══════════ */
.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-center { text-align: center; }
.text-end { text-align: end; }
.font-bold { font-weight: 700; }
.small { font-size: 12.5px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }

.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(8,14,26,.55); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

/* ══════════ الشاشات الصغيرة ══════════ */
@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .report-cols { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .builder-bottom { grid-template-columns: 1fr; }
  .view-totals .invoice-summary { width: 100%; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(100%); }
  body[dir="ltr"] .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-close { display: inline-flex; }
  .main-area { margin-inline-start: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 13px; }
  .topbar { padding: 0 12px; }
  .hide-sm { display: none; }
  .stat-value { font-size: 18px; }
  .modal { max-height: 95vh; }
  .modal-footer { justify-content: stretch; }
  .modal-footer .btn { flex: 1; }
  .toast-container { top: 10px; inset-inline: 10px auto; }
  .toast { min-width: auto; width: calc(100vw - 20px); max-width: 400px; }
}
@media (max-width: 520px) {
  .stats-grid, .stats-grid.compact { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 13px; gap: 10px; flex-direction: column; align-items: flex-start; }
  .stat-card .stat-icon { width: 38px; height: 38px; font-size: 15px; }
  .stat-value { font-size: 16px; }
  .card-header { padding: 13px 14px; }
  .card-body { padding: 14px; }
  .table { font-size: 12.5px; }
  .table thead th, .table tbody td { padding: 9px 10px; }
}

/* ══════════ الطباعة من داخل التطبيق ══════════ */
@media print {
  .sidebar, .topbar, .toast-container, .modal-backdrop, .loading-overlay { display: none !important; }
  .main-area { margin: 0 !important; }
  .content { padding: 0 !important; }
  .card { border: none; box-shadow: none; }
}
