/* ===== المتغيرات الأساسية ===== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2563eb;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 12px;
  --radius-sm: 8px;
}

/* ===== الأساسيات ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: 'Cairo', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 1rem; }
a { color: var(--primary); text-decoration: none; }

.hidden { display: none !important; }

/* ===== شاشة تسجيل الدخول ===== */
#loginScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #3b82f6 100%);
}

.login-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.logo {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 1rem;
  background: var(--primary-light);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ===== النماذج ===== */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.hint {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.error-msg {
  color: var(--danger);
  text-align: center;
  font-size: 0.9rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
}

/* ===== الأزرار ===== */
.btn {
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-warning { background: var(--warning); color: white; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

.btn-block { width: 100%; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text);
  font-size: 1.2rem;
  transition: background 0.2s;
}
.icon-btn:hover { background: var(--bg); }

/* ===== التطبيق ===== */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #1e293b;
}
.sidebar-header .logo-icon {
  width: 44px;
  height: 44px;
  background: var(--primary);
  font-size: 1.5rem;
}
.sidebar-header h2 {
  font-size: 1rem;
  color: white;
  font-weight: 700;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: #1e293b;
  border-radius: var(--radius-sm);
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}
.user-name { color: white; font-weight: 600; font-size: 0.95rem; }
.user-role { color: #94a3b8; font-size: 0.8rem; }

.nav-menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
  width: 100%;
  text-align: right;
}
.nav-item:hover { background: #1e293b; color: white; }
.nav-item.active { background: var(--sidebar-active); color: white; }
.nav-item .nav-icon { font-size: 1.2rem; }

.logout-btn { color: #fca5a5; }
.logout-btn:hover { background: rgba(239, 68, 68, 0.1); }

/* ===== المحتوى الرئيسي ===== */
.main-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 1.25rem; font-weight: 700; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.date-display { color: var(--text-muted); font-size: 0.9rem; }
.backup-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.backup-status-badge:hover { transform: translateY(-1px); }
.backup-status-badge.connected {
  background: var(--success-light);
  color: var(--success);
}
.backup-status-badge.disconnected {
  background: var(--warning-light);
  color: var(--warning);
}
.backup-status-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.backup-status-badge.connected .dot { animation: pulse-dot 2s infinite; }
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.page-container { padding: 1.5rem; flex: 1; }

/* ===== البطاقات ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.card-header h2 { font-size: 1.1rem; font-weight: 700; }
.card-body { padding: 1.5rem; }

/* ===== بطاقات الإحصائيات ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  inset-inline-end: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before { background: var(--danger); }

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}
.stat-card.success .stat-icon { background: var(--success-light); color: var(--success); }
.stat-card.warning .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-card.danger .stat-icon { background: var(--danger-light); color: var(--danger); }

.stat-label { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.25rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  padding: 0.75rem 1rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
tr:hover td { background: #f8fafc; }

.actions-cell { display: flex; gap: 0.25rem; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }

/* ===== الشارات ===== */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: var(--success-light); color: #065f46; }
.badge-danger { background: var(--danger-light); color: #991b1b; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-info { background: var(--primary-light); color: #1e40af; }

/* ===== النماذج/المودال ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal.active { display: flex; }

/* مودال الإضافة/التعديل (genericModal) يكون تحت السكان */
#genericModal { z-index: 1000; }

/* مودال السكان يكون فوق كل المودالات */
#scannerModal { z-index: 1100; }
#scannerModal .modal-content {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #fff;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}
#scannerModal .modal-header { border-bottom: 1px solid rgba(255,255,255,0.15); }
#scannerModal .modal-header h2 { color: #fff; }
#scannerModal .close-modal { color: #fff; }
#scannerModal .hint { color: rgba(255,255,255,0.7); }

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-content.large { max-width: 900px; }

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  justify-content: flex-start;
}

/* ===== شاشة السكان ===== */
.scanner-modal-content { max-width: 500px; }
.scanner-reader {
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: black;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scanner-reader video { width: 100% !important; height: auto !important; }
.manual-entry {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
}
.manual-entry input { flex: 1; }

/* ===== نافذة البيع ===== */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.5rem;
}
.product-search-area {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.search-input-wrap { position: relative; }
.search-input-wrap input {
  padding-inline-start: 3rem;
  font-size: 1.1rem;
}
.search-input-wrap::before {
  content: '🔍';
  position: absolute;
  inset-inline-start: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
}

.cart-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: fit-content;
  position: sticky;
  top: 5rem;
}
.cart-items {
  max-height: 400px;
  overflow-y: auto;
  padding: 0.5rem;
}
.cart-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-weight: 600; font-size: 0.95rem; }
.cart-item-price { color: var(--text-muted); font-size: 0.85rem; }
.qty-control { display: flex; align-items: center; gap: 0.25rem; }
.qty-control button {
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-weight: 700;
}
.qty-control input {
  width: 50px;
  text-align: center;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.cart-total {
  padding: 1.25rem 1.5rem;
  border-top: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.cart-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
}
.cart-total-row.grand { font-size: 1.2rem; font-weight: 700; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.cart-actions { padding: 1rem 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; }

/* ===== الإشعارات ===== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  inset-inline-end: 1.5rem;
  background: var(--text);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transform: translateY(150%);
  transition: transform 0.3s;
  z-index: 1000;
  max-width: 90vw;
}
.toast.show { transform: translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

/* ===== الشبكة ===== */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ===== الفلاتر ===== */
.filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}
.filters input, .filters select { max-width: 200px; }

/* ===== الصلاحيات ===== */
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.perm-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s;
}
.perm-item:hover { border-color: var(--primary); }
.perm-item input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
.perm-item.checked { background: var(--primary-light); border-color: var(--primary); }

/* ===== الموبايل ===== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    inset-inline-end: -300px;
    width: 280px;
    height: 100vh;
    transition: right 0.3s ease, left 0.3s ease;
    z-index: 100;
    box-shadow: -4px 0 20px rgba(0,0,0,0.2);
    visibility: hidden;
  }
  [dir="rtl"] .sidebar { right: auto; left: -300px; }
  [dir="rtl"] .sidebar.open { left: 0; visibility: visible; }
  .sidebar.open { right: 0; visibility: visible; }
  .pos-layout { grid-template-columns: 1fr; }
  .cart-panel { position: static; }
  .main-content { width: 100%; }
  body { overflow-x: hidden; }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    display: none;
  }
  .sidebar-overlay.show { display: block; }
}

@media (max-width: 600px) {
  .topbar { padding: 0.75rem 1rem; }
  .topbar h1 { font-size: 1rem; }
  .date-display { display: none; }
  .page-container { padding: 1rem; }
  .card-header { padding: 1rem; flex-direction: column; align-items: stretch; }
  .card-header h2 { font-size: 1rem; }
  .card-body { padding: 1rem; }
  .stat-value { font-size: 1.3rem; }
  .stat-card { padding: 1.25rem; }
  th, td { padding: 0.5rem 0.6rem; font-size: 0.85rem; }
  .btn { padding: 0.65rem 1rem; font-size: 0.9rem; }
  .modal-content { max-height: 95vh; }
  .modal-body { padding: 1rem; }
  .cart-items { max-height: 300px; }
}

/* ============================================
   خانة سعر البيع المخصصة في سلة نقطة البيع
   مقترح + حر - تصميم محسّن 2026
   ============================================ */
.cart-item-price {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.cart-item.has-custom-price {
  background: linear-gradient(135deg, #fffbeb 0%, #ffffff 100%);
  border-inline-start: 3px solid var(--warning);
}
.cart-item-price .price-block {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  font-size: 0.85rem;
}
.cart-item-price .price-block-suggested {
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
}
.cart-item-price .price-block-custom {
  background: var(--primary-light);
  border: 2px solid var(--primary);
  position: relative;
}
.cart-item-price .price-block-summary {
  background: transparent;
  padding: 0 0.2rem;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
}
.cart-item-price .price-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}
.cart-item-price .price-suggested-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.cart-item-price .btn-use-suggested {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.cart-item-price .btn-use-suggested:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}
.cart-item-price .custom-price-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex: 1;
  min-width: 110px;
}
.cart-item-price .cart-item-price-input {
  width: 100%;
  max-width: 130px;
  padding: 0.4rem 0.6rem;
  border: 2px solid var(--primary);
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
  background: #fff;
  text-align: center;
  font-family: inherit;
  -moz-appearance: textfield;
}
.cart-item-price .cart-item-price-input::-webkit-outer-spin-button,
.cart-item-price .cart-item-price-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.cart-item-price .cart-item-price-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
  background: #fff;
}
.cart-item-price .cart-item-price-input::placeholder {
  color: #94a3b8;
  font-weight: 500;
  font-size: 0.85rem;
}
.cart-item-price .price-currency {
  font-size: 0.95rem;
  color: var(--primary);
  font-weight: 700;
}
.cart-item-price .price-suggested {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  display: inline-block;
  width: max-content;
}
.cart-item-price .price-suggested strong {
  color: var(--text);
}
.cart-item-price .custom-badge {
  position: absolute;
  top: -8px;
  inset-inline-end: 6px;
  background: var(--warning);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  letter-spacing: 0.3px;
}
.cart-item-price .price-line {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}
.cart-item-subtotal {
  color: var(--success);
  font-size: 1rem;
  font-weight: 700;
}
.cart-item-price .profit-indicator {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
}
.cart-item-price .profit-indicator.profit {
  background: var(--success-light);
  color: var(--success);
}
.cart-item-price .profit-indicator.loss {
  background: var(--danger-light);
  color: var(--danger);
  animation: pulse-loss 1.5s infinite;
}
@keyframes pulse-loss {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
.cart-profit.profit { color: var(--success) !important; }
.cart-profit.loss { color: var(--danger) !important; }

/* ============================================
   تقرير أعضاء الفريق - بطاقات
   ============================================ */
.team-report-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: box-shadow 0.2s;
}
.team-report-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.team-report-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.team-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #1e40af);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  flex-shrink: 0;
}
.team-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.team-username {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.team-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}
.team-stat {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border-right: 4px solid;
  background: #f8fafc;
}
.team-stat--primary { border-right-color: var(--primary); background: #eff6ff; }
.team-stat--success { border-right-color: var(--success); background: #ecfdf5; }
.team-stat--danger  { border-right-color: var(--danger);  background: #fef2f2; }
.team-stat--warning { border-right-color: #f59e0b;         background: #fffbeb; }

.team-stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  font-weight: 600;
}
.team-stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.team-stat-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.team-details {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}
.team-details summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--primary);
  font-weight: 600;
  user-select: none;
  padding: 0.4rem 0;
}
.team-details summary:hover { color: #1e40af; }
.team-mini-table {
  width: 100%;
  font-size: 0.82rem;
  margin-top: 0.5rem;
  border-collapse: collapse;
}
.team-mini-table th {
  text-align: right;
  padding: 0.4rem 0.5rem;
  background: #f1f5f9;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
}
.team-mini-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #f1f5f9;
}

/* ============================================
   كشف حساب عضو الفريق
   ============================================ */
.user-picker {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
  padding: 1rem;
  background: var(--primary-light);
  border-radius: 10px;
  margin-bottom: 0;
}
.user-picker-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.user-picker-field select,
.user-picker-field input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
}
.user-picker-actions { align-self: end; }

@media (max-width: 700px) {
  .user-picker { grid-template-columns: 1fr; }
}

.statement-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: linear-gradient(135deg, #1e40af, #2563eb);
  color: #fff;
  border-radius: 12px;
  margin-bottom: 1rem;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}
.statement-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 3px solid rgba(255,255,255,0.3);
}
.statement-userinfo { flex: 1; }
.statement-username {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}
.statement-userrole {
  font-size: 0.85rem;
  opacity: 0.9;
}
.statement-period {
  font-size: 0.8rem;
  opacity: 0.85;
  margin-top: 0.35rem;
}

.statement-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.stmt-stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  position: relative;
  overflow: hidden;
}
.stmt-stat::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 4px; height: 100%;
  background: var(--primary);
}
.stmt-stat--primary::before { background: var(--primary); }
.stmt-stat--success::before { background: var(--success); }
.stmt-stat--danger::before  { background: var(--danger); }
.stmt-stat--warning::before { background: #f59e0b; }

.stmt-stat-icon {
  font-size: 1.6rem;
  margin-bottom: 0.3rem;
}
.stmt-stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.2rem;
}
.stmt-stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.stmt-stat--primary .stmt-stat-value { color: var(--primary); }
.stmt-stat--success .stmt-stat-value { color: var(--success); }
.stmt-stat--danger  .stmt-stat-value { color: var(--danger); }
.stmt-stat--warning .stmt-stat-value { color: #f59e0b; }
.stmt-stat-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.statement-section {
  margin-bottom: 1rem;
}
.statement-section .card-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

/* ============================================
   تبويبات تحليل المخزون
   ============================================ */
.inv-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}
.inv-tab {
  background: transparent;
  border: none;
  padding: 0.65rem 1.1rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  font-family: inherit;
}
.inv-tab:hover {
  color: var(--primary);
  background: var(--primary-light);
}
.inv-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--primary-light);
}

@media (max-width: 600px) {
  .inv-tab {
    flex: 1 0 auto;
    font-size: 0.82rem;
    padding: 0.55rem 0.7rem;
  }
}

/* ============================================
   🌙 الوضع الداكن (Dark Mode)
   ============================================ */
:root.dark-mode {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #1e3a8a;
  --success: #10b981;
  --success-light: #064e3b;
  --danger: #ef4444;
  --danger-light: #7f1d1d;
  --warning: #f59e0b;
  --warning-light: #78350f;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --sidebar-bg: #020617;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #3b82f6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.5), 0 2px 4px -1px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.6), 0 4px 6px -2px rgba(0,0,0,0.4);
}

.dark-mode body { background: var(--bg); color: var(--text); }
.dark-mode .card { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.dark-mode .stat-card { background: var(--bg-card); border: 1px solid var(--border); }
.dark-mode .login-card { background: var(--bg-card); }
.dark-mode .modal-content { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.dark-mode input, .dark-mode select, .dark-mode textarea {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
.dark-mode table { color: var(--text); }
.dark-mode table tbody tr { border-bottom: 1px solid var(--border); }
.dark-mode table thead { background: var(--primary-light); }
.dark-mode code { background: var(--bg); color: var(--text); }
.dark-mode .cart-item { background: var(--bg-card); border-color: var(--border); }

.dark-mode-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 1.2rem;
  margin-inline-end: 0.5rem;
  transition: transform 0.2s;
}
.dark-mode-btn:hover { transform: scale(1.1); background: var(--primary-light); }

/* ============================================
   🔔 التنبيهات الذكية
   ============================================ */
.alerts-widget {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.alerts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.alerts-header h3 { margin: 0; font-size: 1.1rem; }
.alerts-list { display: flex; flex-direction: column; gap: 0.5rem; }
.alerts-empty {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
}
.alerts-empty p { margin-top: 0.5rem; }
.alert-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border-inline-start: 4px solid;
}
.alert-item.alert-critical { background: var(--danger-light); border-color: var(--danger); }
.alert-item.alert-warning { background: var(--warning-light); border-color: var(--warning); }
.alert-item.alert-danger { background: var(--danger-light); border-color: var(--danger); }
.alert-item.alert-info { background: var(--primary-light); border-color: var(--primary); }
.alert-icon { font-size: 1.5rem; }
.alert-content { flex: 1; }
.alert-title { font-weight: 700; font-size: 0.95rem; }
.alert-body { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ============================================
   🏆 لوحة مقارنة الأعضاء
   ============================================ */
.top-podium {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.podium-item {
  text-align: center;
  padding: 1.25rem 0.5rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  position: relative;
}
.podium-item.rank-1 {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-color: #f59e0b;
  transform: scale(1.05);
}
.dark-mode .podium-item.rank-1 { background: linear-gradient(135deg, #78350f 0%, #92400e 100%); }
.podium-item.rank-2 { background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%); border-color: #cbd5e1; }
.dark-mode .podium-item.rank-2 { background: linear-gradient(135deg, #334155 0%, #475569 100%); }
.podium-item.rank-3 { background: linear-gradient(135deg, #fed7aa 0%, #fdba74 100%); border-color: #ea580c; }
.dark-mode .podium-item.rank-3 { background: linear-gradient(135deg, #7c2d12 0%, #9a3412 100%); }
.podium-medal { font-size: 2rem; }
.podium-avatar {
  width: 60px;
  height: 60px;
  margin: 0.5rem auto;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
}
.podium-name { font-weight: 700; margin-top: 0.5rem; }
.podium-value { font-size: 1.3rem; font-weight: 700; color: var(--primary); margin-top: 0.25rem; }
.podium-count { font-size: 0.85rem; color: var(--text-muted); }

.performance-bar {
  width: 100%;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}
.performance-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: 4px;
  transition: width 0.4s;
}

@media (max-width: 600px) {
  .top-podium { grid-template-columns: 1fr; }
  .podium-item.rank-1 { transform: none; }
}

/* ============================================
   🔍 البحث برقم الفاتورة (شريط علوي)
   ============================================ */
.invoice-search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}
.invoice-search-bar input {
  flex: 1;
  max-width: 400px;
}
.invoice-search-result {
  background: var(--primary-light);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.invoice-search-result .badge { font-size: 0.85rem; }

/* ============================================
   🔐 أزرار إضافية (تغيير كلمة المرور + عرض كلمات المرور)
   ============================================ */
.password-row { display: flex; align-items: center; gap: 0.5rem; }
.user-actions-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

/* ============================================
   📸 صور المنتجات
   ============================================ */
.image-upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: var(--bg);
}
.image-preview {
  width: 100%;
  max-width: 200px;
  height: 200px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin: 0 auto;
}
.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.image-placeholder {
  color: var(--text-muted);
  text-align: center;
  font-size: 0.9rem;
  padding: 1rem;
}
.product-thumb {
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--border);
  display: inline-block;
}
.product-thumb-small { width: 32px; height: 32px; }
.product-thumb-medium { width: 60px; height: 60px; }
.product-thumb-large { width: 120px; height: 120px; }

.product-card-with-image {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}
.product-card-image {
  flex-shrink: 0;
}
.product-card-info {
  flex: 1;
  min-width: 0;
}

/* ============================================
   📅 تذكير الديون - تنبيهات
   ============================================ */
.reminder-quick-btn {
  background: var(--success);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.reminder-quick-btn:hover { background: #059669; transform: translateY(-1px); }
.reminder-quick-btn:disabled { background: #cbd5e1; cursor: not-allowed; }

/* ============================================
   📲 PWA - زر تثبيت التطبيق
   ============================================ */
.pwa-install-btn {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  border-radius: 50px;
  padding: 0.85rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
  z-index: 9998;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.3s ease;
  animation: float-pulse 3s ease-in-out infinite;
}
.pwa-install-btn:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.5);
}
.pwa-install-btn:active {
  transform: translateY(-1px) scale(1.02);
}
@keyframes float-pulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@media (max-width: 640px) {
  .pwa-install-btn {
    bottom: 16px;
    left: 16px;
    padding: 0.7rem 1.1rem;
    font-size: 0.85rem;
  }
}

/* دعم شريط الحالة (Notch) في الموبايل */
@supports (padding: max(0px)) {
  .app {
    padding-top: max(0px, env(safe-area-inset-top));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
  .pwa-install-btn {
    bottom: max(20px, env(safe-area-inset-bottom));
  }
}

/* تحسينات PWA standalone mode */
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; }
  input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }
  /* منع zoom عند double tap */
  * { touch-action: manipulation; }
}

/* ====== تنسيقات toast (مستخدمة في login.html والتطبيق) ====== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #fff;
  padding: 0.7rem 1.2rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: 'Cairo', sans-serif;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 10000;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.info    { background: #2563eb; }
