/* ==========================================
   MOAMEN PRINTING PRESS - THEME (Laravel Edition)
   مبني على نظام الألوان الأصلي
   ========================================== */

:root {
  --color-bg: #030712;
  --color-sidebar: rgba(9, 14, 32, 0.9);
  --color-card: rgba(17, 25, 54, 0.55);
  --color-card-border: rgba(255, 255, 255, 0.08);
  --color-card-hover-border: rgba(212, 175, 55, 0.3);

  --color-gold: #b79a6d;
  --color-gold-glow: rgba(183, 154, 109, 0.15);
  --color-cobalt: #206787;
  --color-cobalt-glow: rgba(32, 103, 135, 0.25);

  --color-white: #ffffff;
  --color-text: #f1f5f9;
  --color-text-muted: #94a3b8;
  --color-success: #10b981;
  --color-danger: #f43f5e;
  --color-warning: #f59e0b;

  --font-ar: 'Cairo', sans-serif;

  --shadow-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

/* ---------- المظهر الفاتح (Light Theme) ---------- */
:root[data-theme="light"] {
  --color-bg: #eef1f7;
  --color-sidebar: rgba(255, 255, 255, 0.92);
  --color-card: rgba(255, 255, 255, 0.85);
  --color-card-border: rgba(15, 23, 42, 0.08);
  --color-card-hover-border: rgba(183, 154, 109, 0.4);

  --color-gold-glow: rgba(183, 154, 109, 0.12);
  --color-cobalt-glow: rgba(32, 103, 135, 0.1);

  --color-white: #0f172a;
  --color-text: #1e293b;
  --color-text-muted: #64748b;

  --shadow-glow: 0 8px 32px 0 rgba(15, 23, 42, 0.08);
}
:root[data-theme="light"] body {
  background-image:
    radial-gradient(circle at 15% 20%, var(--color-cobalt-glow), transparent 45%),
    radial-gradient(circle at 85% 80%, var(--color-gold-glow), transparent 45%);
}
:root[data-theme="light"] .mp-input,
:root[data-theme="light"] .mp-select,
:root[data-theme="light"] .mp-textarea {
  background: rgba(15, 23, 42, 0.03);
}
:root[data-theme="light"] .btn-ghost {
  background: rgba(15, 23, 42, 0.05);
  color: var(--color-text);
}
:root[data-theme="light"] .btn-ghost:hover {
  background: rgba(15, 23, 42, 0.1);
}
:root[data-theme="light"] .menu-item:hover {
  color: var(--color-white);
}
:root[data-theme="light"] .sidebar {
  box-shadow: 0 0 24px rgba(15, 23, 42, 0.06);
}
:root[data-theme="light"] .theme-toggle-btn .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle-btn .icon-sun { display: inline-flex; }
.theme-toggle-btn .icon-sun { display: none; }

* { box-sizing: border-box; }

body {
  font-family: var(--font-ar);
  background-color: var(--color-bg);
  background-image:
    radial-gradient(circle at 15% 20%, var(--color-cobalt-glow), transparent 40%),
    radial-gradient(circle at 85% 80%, var(--color-gold-glow), transparent 40%);
  background-attachment: fixed;
  color: var(--color-text);
  min-height: 100vh;
  margin: 0;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ---------- زر تبديل المظهر (فاتح/غامق) ---------- */
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--color-card-border);
  color: var(--color-white);
  cursor: pointer;
  transition: background 0.2s ease;
}
:root[data-theme="light"] .theme-toggle-btn {
  background: rgba(15,23,42,0.05);
}
.theme-toggle-btn:hover {
  background: var(--color-cobalt-glow);
}
.theme-toggle-btn svg { width: 18px; height: 18px; }

a { text-decoration: none; color: inherit; }

/* ---------- Layout Shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--color-sidebar);
  backdrop-filter: blur(16px);
  border-left: 1px solid var(--color-card-border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 0 8px 20px;
  border-bottom: 1px solid var(--color-card-border);
  margin-bottom: 20px;
}
.sidebar-brand img { width: 40px; height: 40px; object-fit: contain; }
.sidebar-brand-text { font-weight: 700; font-size: 15px; color: var(--color-white); }
.sidebar-brand-sub { font-size: 11px; color: var(--color-text-muted); }

.sidebar-menu { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 14px;
  transition: all 0.25s ease;
}
.menu-item:hover {
  background: var(--color-cobalt-glow);
  color: var(--color-white);
}
.menu-item.active {
  background: linear-gradient(90deg, var(--color-cobalt-glow), transparent);
  color: var(--color-gold);
  border-right: 3px solid var(--color-gold);
}
.menu-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  border-top: 1px solid var(--color-card-border);
  padding-top: 16px;
  margin-top: 12px;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; }
.sidebar-user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--color-gold-glow);
  color: var(--color-gold);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}
.sidebar-user-name { font-size: 13px; color: var(--color-white); }
.sidebar-user-role { font-size: 11px; color: var(--color-text-muted); }
.logout-btn {
  display: block; width: 100%; text-align: right; margin-top: 10px;
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: rgba(244, 63, 94, 0.08);
  color: var(--color-danger);
  font-size: 13px; border: none; cursor: pointer; font-family: inherit;
}
.logout-btn:hover { background: rgba(244, 63, 94, 0.15); }

/* ---------- Main Content ---------- */
.main-content { flex: 1; min-width: 0; }

.topbar {
  padding: 18px 32px;
  border-bottom: 1px solid var(--color-card-border);
  background: rgba(3, 7, 18, 0.4);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar h1 { font-size: 18px; font-weight: 700; color: var(--color-white); margin: 0; }

.content-area { padding: 28px 32px; }

/* ---------- Cards ---------- */
.mp-card {
  background: var(--color-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glow);
  padding: 24px;
  margin-bottom: 20px;
  color: var(--color-text);
}
.mp-card h3 { color: var(--color-white); margin: 0 0 4px; font-size: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  border: none; cursor: pointer; font-family: inherit;
  transition: var(--transition-smooth);
}
.btn-primary { background: var(--color-cobalt); color: white; }
.btn-primary:hover { filter: brightness(1.15); }
.btn-gold { background: var(--color-gold); color: #1a1408; }
.btn-gold:hover { filter: brightness(1.1); }
.btn-danger { background: rgba(244, 63, 94, 0.12); color: var(--color-danger); }
.btn-danger:hover { background: rgba(244, 63, 94, 0.22); }
.btn-ghost { background: rgba(255,255,255,0.05); color: var(--color-text); }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn svg { width: 16px; height: 16px; }

/* ---------- Forms ---------- */
.mp-label { display: block; font-size: 13px; color: var(--color-text-muted); margin-bottom: 6px; }
.mp-input, .mp-select, .mp-textarea {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--color-text);
  font-family: inherit;
  font-size: 14px;
}
.mp-input:focus, .mp-select:focus, .mp-textarea:focus {
  outline: none;
  border-color: var(--color-cobalt);
  box-shadow: 0 0 0 3px var(--color-cobalt-glow);
}

/* ---------- Tables ---------- */
.mp-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.mp-table th {
  text-align: right; padding: 10px 12px;
  color: var(--color-text-muted); font-weight: 600; font-size: 12px;
  border-bottom: 1px solid var(--color-card-border);
}
.mp-table td {
  padding: 12px; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.mp-table tr:hover td { background: rgba(255,255,255,0.02); }

/* ---------- Badges / Alerts ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-gold { background: var(--color-gold-glow); color: var(--color-gold); }
.badge-cobalt { background: var(--color-cobalt-glow); color: #6bb7d8; }
.badge-gray { background: rgba(255,255,255,0.06); color: var(--color-text-muted); }
.badge-success { background: rgba(16,185,129,0.12); color: var(--color-success); }
.badge-danger { background: rgba(244,63,94,0.12); color: var(--color-danger); }

.alert { padding: 14px 18px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 14px; }
.alert-success { background: rgba(16,185,129,0.1); color: var(--color-success); border: 1px solid rgba(16,185,129,0.25); }
.alert-error { background: rgba(244,63,94,0.1); color: var(--color-danger); border: 1px solid rgba(244,63,94,0.25); }

/* ---------- Auth Pages (Login) ---------- */
.auth-wrapper {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, var(--color-cobalt-glow), transparent 45%),
    radial-gradient(circle at 80% 75%, var(--color-gold-glow), transparent 45%),
    var(--color-bg);
}
.auth-card {
  background: var(--color-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glow);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  position: relative;
  z-index: 1;
}
.auth-logo { display: flex; flex-direction: column; align-items: center; margin-bottom: 24px; }
.auth-logo img { width: auto; height: 90px; object-fit: contain; margin-bottom: 12px; }
.auth-logo h1 { font-size: 18px; color: var(--color-white); margin: 0; }
.auth-logo p { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }

/* ---------- إصلاح مؤقت: البطاقات البيضاء (Tailwind) داخل الصفحات
   القديمة (الأساتذة/الموظفين) تحتاج لون نص غامق حتى تنقرى فوق الخلفية الداكنة ---------- */
.bg-white {
  color: #1e293b;
}
.bg-white h1, .bg-white h2, .bg-white h3, .bg-white h4 {
  color: #0f172a;
}
.bg-white .text-gray-500,
.bg-white .text-gray-600 {
  color: #64748b !important;
}

/* ---------- أزرار الإجراءات الصغيرة (عرض / تعديل / حذف / طباعة) ---------- */
.btn-xs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.2s ease, background 0.2s ease;
}
.btn-xs-view {
  background: rgba(255,255,255,0.07);
  color: var(--color-text);
}
.btn-xs-view:hover { background: rgba(255,255,255,0.14); }

.btn-xs-edit {
  background: var(--color-cobalt-glow);
  color: #6bb7d8;
}
.btn-xs-edit:hover { background: rgba(32,103,135,0.4); }

.btn-xs-danger {
  background: rgba(244, 63, 94, 0.12);
  color: var(--color-danger);
}
.btn-xs-danger:hover { background: rgba(244, 63, 94, 0.25); }

.btn-xs-gold {
  background: var(--color-gold-glow);
  color: var(--color-gold);
}
.btn-xs-gold:hover { background: rgba(183, 154, 109, 0.3); }

.actions-cell {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- إصلاح القوائم المنسدلة (select): خلفية بيضاء افتراضية
   من المتصفح تخلي النص الفاتح يختفي، فنفرض لون غامق على الخيارات ---------- */
.mp-select option {
  background: #ffffff;
  color: #1e293b;
}

/* ==========================================
   دعم التجاوب مع الأجهزة اللوحية والموبايل
   (Responsive: Tablet & Mobile)
   ========================================== */

/* شعار البرنامج بالـ topbar - يظهر بالموبايل فقط بالمنتصف */
.topbar-mobile-brand {
  display: none;
}

/* ==========================================
   شريط تنبيه المخزون المنخفض
   ========================================== */
.low-stock-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(244, 63, 94, 0.12);
  border-bottom: 1px solid rgba(244, 63, 94, 0.3);
  color: var(--color-danger);
  padding: 10px 24px;
  font-size: 13px;
  flex-wrap: wrap;
}
.low-stock-bar svg { width: 18px; height: 18px; flex-shrink: 0; }
.low-stock-bar-label { font-weight: 700; white-space: nowrap; }
.low-stock-bar-items {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  flex: 1;
}
.low-stock-chip {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.3);
  border-radius: 20px;
  padding: 3px 12px;
  white-space: nowrap;
  font-weight: 600;
}

/* ==========================================
   نافذة التأكيد المنبثقة العامة
   ========================================== */
.confirm-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.confirm-modal-overlay.active {
  display: flex;
}
.confirm-modal-box {
  background: var(--color-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glow);
  padding: 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
:root[data-theme="light"] .confirm-modal-box {
  background: #ffffff;
}
.confirm-modal-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-cobalt-glow);
  color: var(--color-cobalt);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}
.confirm-modal-icon svg { width: 26px; height: 26px; }
.confirm-modal-icon-danger {
  background: rgba(244, 63, 94, 0.15);
  color: var(--color-danger);
}
.confirm-modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-white);
  margin: 0 0 8px;
}
.confirm-modal-message {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: 0 0 20px;
}
.confirm-modal-actions {
  display: flex;
  gap: 10px;
}
.confirm-modal-actions .btn {
  flex: 1;
  justify-content: center;
}

/* زر فتح/إغلاق القائمة الجانبية - يظهر بالموبايل والتابلت فقط */
.sidebar-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--color-card-border);
  color: var(--color-white);
  cursor: pointer;
}
.sidebar-toggle-btn svg { width: 20px; height: 20px; }

/* طبقة التعتيم خلف القائمة عند فتحها بالموبايل */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 40;
}
.sidebar-overlay.active { display: block; }

/* ---------- أجهزة لوحية (Tablet): حتى 1024px ---------- */
@media (max-width: 1024px) {
  .sidebar {
    width: 220px;
    padding: 20px 12px;
  }
  .content-area { padding: 20px; }
  .topbar { padding: 16px 20px; }

  .mp-card { padding: 18px; }

  .sidebar-brand {
    flex-direction: column;
    text-align: center;
    justify-content: center;
  }

  /* الجداول تصير قابلة للتمرير أفقياً بدل ما تنكسر */
  .mp-table, table {
    display: block;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* ---------- موبايل: حتى 768px ---------- */
@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  /* أي عنصر فيه grid عبر inline style (متل بطاقات لوحة التحكم)
     يتحول عمود واحد بالموبايل، بغض النظر عن الصفحة */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* أي صف flex بفجوة (gap) عبر inline style يلتف عمودياً بدل ما يضغط جنب بعض */
  [style*="display:flex"][style*="gap"] {
    flex-wrap: wrap !important;
  }
  [style*="display: flex"][style*="gap"] {
    flex-wrap: wrap !important;
  }

  /* الشريط الجانبي يصير قائمة منسدلة (Drawer) فوق المحتوى بدل عمود ثابت */
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 78%;
    max-width: 300px;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -8px 0 24px rgba(0,0,0,0.4);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-menu {
    flex-shrink: 0;
  }

  .sidebar-footer {
    flex-shrink: 0;
  }

  .sidebar-toggle-btn {
    display: inline-flex;
  }

  .main-content {
    width: 100%;
  }

  .sidebar-brand {
    flex-direction: column;
    text-align: center;
    justify-content: center;
    gap: 6px;
  }
  .sidebar-brand img {
    margin: 0 auto;
  }

  .topbar {
    padding: 14px 16px;
    gap: 12px;
    position: relative;
    justify-content: flex-start;
  }
  .topbar h1 {
    display: none;
  }

  .topbar-mobile-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
  }
  .topbar-mobile-brand img {
    width: 30px;
    height: 30px;
    object-fit: contain;
  }
  .topbar-mobile-brand span {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-white);
  }

  .content-area { padding: 14px; }

  .mp-card {
    padding: 16px;
    border-radius: var(--radius-md);
  }

  /* البطاقات اللي فيها بيانات مالية (متبقي/مدفوع/إجمالي) تصير عمود واحد */
  .mp-card > div[style*="grid"],
  .mp-card > div[style*="flex"] {
    flex-wrap: wrap !important;
  }

  /* الجداول بالموبايل: تمرير أفقي إجباري */
  .mp-table, table {
    display: block;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* الفورمات والأزرار تاخذ العرض الكامل بالموبايل لسهولة اللمس */
  .btn {
    width: 100%;
    justify-content: center;
    padding: 12px 18px;
  }
  form[style*="flex-direction:column"] > div[style*="display:flex"] {
    flex-direction: column;
  }

  .mp-input, .mp-select, .mp-textarea {
    font-size: 16px; /* يمنع تكبير الصفحة تلقائياً بالآيفون عند الضغط على حقل */
    padding: 12px;
  }

  .auth-card {
    padding: 24px;
    max-width: 92%;
  }

  .actions-cell {
    gap: 6px;
  }
  .btn-xs {
    padding: 7px 10px;
    font-size: 11px;
  }
}

/* ---------- موبايل صغير جداً: حتى 400px ---------- */
@media (max-width: 400px) {
  .sidebar-brand-text { font-size: 13px; }
  .topbar h1 { font-size: 14px; }
  .mp-card { padding: 12px; }
}