/* styles.css - Waznah PRO v22.0 (Forced Scrolling) */
:root {
  --primary: #0f172a;
  --primary-light: #e2e8f0;
  --accent: #3b82f6;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --bg-body: #f1f5f9;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

/* ✅ تم التعديل: السماح بالتمرير بشكل افتراضي */
body {
  margin: 0;
  font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

/* === Layout === */
/* ✅ تم التعديل: قفل التمرير فقط في صفحة الأدمن للحفاظ على التصميم */
.admin-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  /* Fallback */
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  background: white;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.main-content {
  padding: 25px;
  overflow-y: auto;
  height: 100%;
}

/* === Sidebar === */
.sidebar-brand {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand img {
  height: 40px;
}

.sidebar-brand h3 {
  margin: 0;
  color: var(--primary);
  font-size: 18px;
}

.sidebar-nav {
  padding: 15px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto !important;
  max-height: calc(100vh - 120px) !important;
  scrollbar-width: thin;
}

.nav-item {
  padding: 8px 12px;
  /* Reduced padding */
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s;
  border: none;
  background: none;
  width: 100%;
  text-align: right;
  font-size: 13px;
  /* Slightly smaller font */
}

.nav-item:hover,
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item.logout {
  color: var(--danger);
}

.nav-item.logout:hover {
  background: #fee2e2;
}

/* === Top Bar === */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: #dcfce7;
  color: #166534;
  padding: 5px 12px;
  border-radius: 20px;
  font-weight: 600;
}

.dot {
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
}

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 15px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.stat-card.red::before {
  background: var(--danger);
}

.stat-card.blue::before {
  background: var(--accent);
}

.stat-card.yellow::before {
  background: var(--warning);
}

.stat-card.green::before {
  background: var(--success);
}

.stat-card .icon {
  font-size: 32px;
  opacity: 0.2;
}

.stat-card.red .icon {
  color: var(--danger);
}

.stat-card.blue .icon {
  color: var(--accent);
}

.stat-card.yellow .icon {
  color: var(--warning);
}

.stat-card.green .icon {
  color: var(--success);
}

.stat-card .info h3 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
}

.stat-card .info p {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* === Table Card === */
.card {
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.table-card {
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 500px;
  flex: 1;
}

.table-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 15px;
}

.filters-group {
  display: flex;
  gap: 8px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
}

.filter-btn {
  background: none;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: 0.2s;
}

.filter-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.search-group {
  flex: 1;
  max-width: 400px;
}

.search-group input {
  width: 100%;
  padding: 10px 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.table-responsive {
  overflow-y: auto;
  overflow-x: auto;
  flex: 1;
}

.main-table {
  width: 100%;
  border-collapse: collapse;
}

.main-table th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  padding: 12px 20px;
  text-align: right;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.main-table td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.main-table tr:hover {
  background: #f8fafc;
}

/* === Status Pills === */
.status-pill {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  display: inline-block;
}

.step-0,
.step-1 {
  background: #e0f2fe;
  color: #0369a1;
}

.step-2,
.step-3,
.step-4 {
  background: #ffedd5;
  color: #c2410c;
}

.step-5,
.step-6 {
  background: #f3e8ff;
  color: #7e22ce;
}

.step-7 {
  background: #fef08a;
  color: #854d0e;
}

.step-8 {
  background: #dbeafe;
  color: #1d4ed8;
}

.step-9 {
  background: #dcfce7;
  color: #15803d;
}

.step-10 {
  background: #f1f5f9;
  color: #64748b;
}

/* === Login Screen === */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-body);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  width: 100%;
  max-width: 400px;
}

.error-text {
  color: var(--danger);
  font-size: 12px;
  margin-top: 10px;
  text-align: center;
}

/* === Buttons & Inputs === */
.btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  transition: 0.2s;
}

.btn.action {
  background: var(--primary);
  color: white;
}

.btn.action:hover {
  background: #1e293b;
}

.btn.secondary {
  background: #e2e8f0;
  color: #334155;
}

.btn.secondary:hover {
  background: #cbd5e1;
}

.btn.danger {
  background: var(--danger);
  color: white;
}

.btn.outline {
  background: transparent;
  border: 1px solid currentColor;
}

.btn.danger.outline {
  color: var(--danger);
  border-color: var(--danger);
}

.btn.sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn.full-width {
  width: 100%;
  display: block;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.input-style {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  font-family: inherit;
}

.input-style:focus {
  border-color: var(--accent);
  outline: none;
}

/* === Modal Styles === */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* .modal-box.large removed (merged with grid definition below) */

.modal-box.medium {
  width: 500px;
  max-width: 95%;
}

.modal-box.small {
  width: 350px;
  max-width: 95%;
}

.modal-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  /* Allow wrapping on small screens */
  gap: 10px;
  background: #fafafa;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: #666;
  cursor: pointer;
}

/* === Cockpit Grid === */
/* === Cockpit Grid === */
.cockpit-grid {
  display: grid;
  /* Right (Content): Fluid, Left (Actions): Fixed/Min width */
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
  /* Prevent stretching height unnecessarily */
}

/* Make modal wider to accommodate the sidebar, but responsive */
/* Make modal wider to accommodate the sidebar, but responsive */
.modal-box.large {
  width: 96% !important;
  /* Forced width to ensure no overrides */
  max-width: 1400px !important;
  height: 92vh !important;
  max-height: 92vh !important;
  margin: 2vh auto !important;
  display: flex !important;
  flex-direction: column !important;
}

/* On smaller screens, stack the grid to avoid squishing */
@media (max-width: 1200px) {

  /* Increased breakpoint from 1000px to 1200px for safety */
  .cockpit-grid {
    grid-template-columns: 1fr;
    /* Stack vertically */
  }

  .modal-box.large {
    width: 96%;
    height: 90vh;
  }
}

.section {
  background: #f8fafc;
  padding: 15px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.customer-card {
  grid-column: span 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  /* Safety wrap */
  gap: 10px;
  background: white;
  border: 1px solid var(--primary);
}

.context-area {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.action-zone-wrapper {
  background: white;
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
}

.zone-header {
  padding: 10px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.actions-grid {
  padding: 15px;
  display: grid;
  gap: 10px;
}

/* === Mobile (Phones) === */
@media (max-width: 767px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .cockpit-grid {
    grid-template-columns: 1fr;
  }

  .customer-card,
  .action-zone-wrapper {
    grid-column: span 1;
  }

  /* Stack card info on mobile to prevent overflow */
  .customer-card {
    flex-direction: column;
    text-align: center;
    gap: 10px;
  }
}

/* === Chat UI Styles (Modern & Professional) === */
#chatMessages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  max-height: 500px;
  overflow-y: auto;
  background-color: #f8fafc;
  background-image: radial-gradient(#e2e8f0 0.5px, transparent 0.5px);
  background-size: 20px 20px; /* ورق مربعات خفيف جداً للهوية */
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  margin-bottom: 15px;
  scroll-behavior: smooth;
}

.msg-bubble {
  max-width: 85%;
  padding: 12px 18px;
  font-size: 14.5px;
  line-height: 1.6;
  position: relative;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s ease;
}

.msg-bubble:hover {
  transform: translateY(-2px);
}

/* رسائل الإدارة (أنت) - الجهة اليمنى (RTL) */
.msg-admin {
  align-self: flex-start;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  color: #f8fafc;
  border-radius: 20px 2px 20px 20px;
  text-align: right;
}

/* رسائل العميل - الجهة اليسرى (RTL) */
.msg-customer {
  align-self: flex-end;
  background: #ffffff;
  color: #1e293b;
  border-radius: 2px 20px 20px 20px;
  text-align: right;
  border: 1px solid #cbd5e1;
}

.msg-admin::after {
  content: "المشرف";
  position: absolute;
  top: -18px;
  right: 5px;
  font-size: 10px;
  color: #64748b;
  font-weight: bold;
}

.msg-customer::after {
  content: "العميل";
  position: absolute;
  top: -18px;
  left: 5px;
  font-size: 10px;
  color: #3b82f6;
  font-weight: bold;
}

.msg-time {
  display: block;
  font-size: 10px;
  margin-top: 5px;
  opacity: 0.6;
}

/* Force wrapping for consistency */
#chatMessages div,
#detDesc,
.problem-box p {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.customer-card .cust-info,
.customer-card .car-info {
  width: 100%;
  /* Ensure full width availability */
}

.car-info div {
  justify-content: center !important;
  /* Center the VIN tags */
}

.modal-box {
  max-height: 85vh;
  /* Fallback */
  max-height: 85dvh;
  width: 95% !important;
  /* Force fit */
}

/* === Tablet (iPad) === */
@media (min-width: 768px) and (max-width: 1100px) {
  .admin-layout {
    grid-template-columns: 200px 1fr;
    /* Sidebar smaller */
  }

  .sidebar-nav .nav-item {
    font-size: 13px;
    padding: 10px 12px;
  }

  .main-content {
    padding: 15px;
  }

  /* Modal Adjustments for Tablet */
  .cockpit-grid {
    grid-template-columns: 1fr;
    /* Stack columns on tablet */
    gap: 15px;
  }

  .customer-card {
    grid-column: span 1;
    /* Reset span */
  }

  .modal-box.large {
    width: 90%;
    /* Slight margin on sides */
    max-height: 90vh;
  }

  .stat-card {
    padding: 15px;
  }

  .stat-card .icon {
    font-size: 24px;
  }

  .stat-card .info h3 {
    font-size: 20px;
  }

  /* Fix map aspect ratio on tablet */
  .map-box {
    height: 400px;
  }
}

/* === Admin Specific Styles (Moved from admin.html) === */
/* تنسيقات خاصة بالخريطة لتظهر بشكل صحيح */
.map-box {
  height: 250px;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  border: 2px solid #ddd;
  z-index: 1;
}

#miniMap {
  height: 100%;
  width: 100%;
}

/* تنسيق الرسوم البيانية */
.charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 25px;
}

.chart-card {
  background: white;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  height: 350px;
  position: relative;
}

/* تنسيقات الجوال للشارت */
@media (max-width: 1100px) {
  .charts-row {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chart-card {
    height: 300px;
    margin-bottom: 15px;
  }
}

/* شارات الحالة */
.badge {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: bold;
  display: inline-block;
  white-space: nowrap;
}

.badge.green {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #10b981;
}

.badge.yellow {
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #facc15;
}

.badge.red {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #ef4444;
}

/* عداد الوقت */
.timer-badge {
  font-size: 11px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 4px;
  display: inline-block;
  width: 100%;
  text-align: center;
}

.timer-badge.green {
  background: #ecfdf5;
  color: #047857;
  border: 1px dashed #059669;
}

.timer-badge.red {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px dashed #ef4444;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }

  100% {
    opacity: 1;
  }
}

/* تحسين زر التصدير */
.export-btn {
  background: #1e293b;
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  transition: 0.3s;
}

.export-btn:hover {
  background: #334155;
}