/* ========================================================================
   FAIRFOOD RESTAURANT DASHBOARD - FINAL COMPLETE STYLESHEET
   الهوية: برتقالي (#FF5A00) | Mobile-first | RTL / Dark mode دعم كامل
   ======================================================================== */

/* =========================== المتغيرات الأساسية =========================== */
:root {
  --primary: #FF5A00;
  --primary-dark: #E04E00;
  --secondary: #64748b;
  --background: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.02);
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
}

/* =========================== الثيم الداكن =========================== */
body.theme-dark {
  --background: #111827;
  --surface: #1f2937;
  --text: #f9fafb;
  --text-light: #9ca3af;
  --border: #374151;
}

/* =========================== إعادة الضبط العامة =========================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--background);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow-x: hidden;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  font-family: inherit;
}

/* =========================== روابط التخطي وتحذير المتصفح =========================== */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: white;
  padding: 8px 16px;
  z-index: 10000;
  border-radius: 0 0 8px 0;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
}

.noscript-warning {
  background: var(--danger);
  color: white;
  text-align: center;
  padding: 12px;
  font-weight: bold;
}

/* =========================== اللافتات (Banners) =========================== */
.offline-banner,
.reconnect-banner,
.install-banner {
  padding: 12px 16px;
  text-align: center;
  font-weight: 500;
  width: 100%;
}
.offline-banner {
  background: var(--danger);
  color: white;
}
.reconnect-banner {
  background: var(--warning);
  color: black;
}
.install-banner {
  background: var(--info);
  color: white;
  cursor: pointer;
}
/* إخفاء اللافتات فقط مع الكلاس المخفي */
.offline-banner.is-hidden,
.reconnect-banner.is-hidden,
.install-banner.is-hidden {
  display: none;
}

/* =========================== شاشة التحميل (App Loader) =========================== */
.app-loader {
  position: fixed;
  inset: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s;
}
.app-loader.is-hidden {
  display: none;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}
.app-loader span {
  color: var(--text-light);
  font-size: 0.95rem;
  display: block;
  text-align: center;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =========================== أوفرلي عام =========================== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.overlay.is-hidden {
  display: none;
}

/* =========================== توست (Toast) =========================== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 350px;
}
[dir="rtl"] .toast-container {
  right: auto;
  left: 20px;
}

.toast {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================== هيكل التطبيق (Restaurant App) =========================== */
.restaurant-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* المحتوى الرئيسي */
.restaurant-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* =========================== هيدر التطبيق (App Header) =========================== */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 1000;
  gap: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

/* أيقونات الأزرار */
.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  position: relative;
  transition: background 0.2s;
}
.icon-btn:hover {
  background: var(--border);
}

/* الشارة (Badge) */
.badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
  font-weight: bold;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  border-radius: 9px;
  padding: 0 4px;
  text-align: center;
}
.badge.is-hidden {
  display: none;
}

/* مبدل اللغة */
.lang-switcher {
  display: flex;
  gap: 4px;
}
.lang-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.lang-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* قائمة الإشعارات */
.notification-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  width: 320px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
  z-index: 2000;
  color: var(--text);
  padding: 16px;
  margin-top: 8px;
  transform-origin: top right;
  animation: dropdownIn 0.2s ease;
}
.notification-dropdown.is-hidden {
  display: none;
}
@keyframes dropdownIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* شريط معلومات السائق */
.driver-info-bar {
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  width: 100%;
}

/* =========================== علامات التبويب (Tabs) =========================== */
.restaurant-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 16px;
  gap: 8px;
}
.tab-btn {
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-light);
  border: none;
  background: none;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

/* شارة التبويب */
.tab-badge {
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
  font-weight: bold;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: inline-block;
  vertical-align: middle;
}
[dir="rtl"] .tab-badge {
  margin-left: 0;
  margin-right: 6px;
}

/* =========================== لوحة القياس (Dashboard Metrics) =========================== */
.dashboard-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.metric-card strong {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
  display: block;
  margin-top: 8px;
}

/* =========================== ملخص الأرباح =========================== */
.earnings-summary {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

/* =========================== الأقسام العامة (الطلبات، القائمة) =========================== */
.orders-section,
.menu-section {
  margin-bottom: 24px;
}

.orders-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.order-card {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
}

.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.menu-items-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

/* بطاقة عنصر القائمة */
.menu-item-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s;
}
.menu-item-card:hover {
  transform: translateY(-2px);
}
.menu-item-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
}
.menu-item-card .item-details {
  padding: 12px;
}
.menu-item-card .item-name {
  font-weight: 700;
  margin-bottom: 4px;
}
.menu-item-card .item-price {
  color: var(--primary);
  font-weight: 700;
  font-size: 1.1rem;
}

/* أزرار القائمة */
.menu-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* =========================== الحالة الفارغة =========================== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}
.empty-state .icon {
  font-size: 3rem;
  opacity: 0.4;
  margin-bottom: 12px;
}
.empty-state p {
  margin-bottom: 16px;
}

/* =========================== مجموعة الإعدادات =========================== */
.settings-group {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* =========================== هيكل عظمي للتحميل (Skeleton) =========================== */
.skeleton-card {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
  height: 80px;
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* =========================== المودالات =========================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s, visibility 0.25s;
}
.modal.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.modal-content {
  background: var(--surface);
  border-radius: 20px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.3);
  animation: modalSlideIn 0.3s ease;
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-body {
  padding: 10px 0;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* رفع الصور */
.item-image-upload {
  border: 2px dashed var(--border);
  padding: 30px;
  text-align: center;
  margin: 15px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.2s;
  background: var(--background);
}
.item-image-upload:hover {
  border-color: var(--primary);
}

/* =========================== الفورمات =========================== */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 90, 0, 0.1);
}
textarea {
  min-height: 100px;
  resize: vertical;
}

/* زر التبديل (Switch) */
.switch-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}
.switch-label input[type="checkbox"] {
  width: 44px;
  height: 24px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 12px;
  position: relative;
  outline: none;
  transition: background 0.2s;
}
.switch-label input[type="checkbox"]::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch-label input[type="checkbox"]:checked {
  background: var(--primary);
}
.switch-label input[type="checkbox"]:checked::before {
  transform: translateX(20px);
}

/* أوقات العمل */
.working-hours {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  align-items: center;
}

/* =========================== الأزرار الأساسية =========================== */
.btn-primary,
.btn-secondary,
.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  padding: 10px 20px;
  font-weight: 600;
  transition: background 0.2s, transform 0.1s;
  cursor: pointer;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-dark);
}
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover {
  background: var(--border);
}
.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
  border-radius: 8px;
}

/* =========================== دعم RTL =========================== */
[dir="rtl"] {
  text-align: right;
}
[dir="rtl"] .header-actions {
  flex-direction: row-reverse;
}
[dir="rtl"] .icon-btn .badge {
  right: auto;
  left: -2px;
}
[dir="rtl"] .notification-dropdown {
  right: auto;
  left: 0;
  transform-origin: top left;
}
[dir="rtl"] .modal-actions {
  justify-content: flex-start;
}
[dir="rtl"] .switch-label input[type="checkbox"]::before {
  left: auto;
  right: 2px;
}
[dir="rtl"] .switch-label input[type="checkbox"]:checked::before {
  transform: translateX(-20px);
}
[dir="ltr"] .ml-auto { margin-left: auto; }
[dir="ltr"] .mr-auto { margin-right: auto; }
[dir="rtl"] .ml-auto { margin-right: auto; }
[dir="rtl"] .mr-auto { margin-left: auto; }

/* =========================== تحسينات الموبايل =========================== */
@media (max-width: 640px) {
  .modal-content {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    animation: mobileModalSlideUp 0.3s ease;
  }
  @keyframes mobileModalSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .driver-info-bar {
    flex-wrap: wrap;
    font-size: 0.9rem;
  }
  .notification-dropdown {
    right: 10px;
    left: 10px;
    width: auto;
  }
  [dir="rtl"] .notification-dropdown {
    right: 10px;
    left: 10px;
  }
}

/* =========================== أدوات مساعدة =========================== */
/* إخفاء تام (بدون أنيميشن) */
.is-hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =========================== ملاحظة CSP =========================== */
/* لتجنب منع inline scripts بسبب CSP، انقل window.APP_CONFIG إلى ملف config.js خارجي */