:root {
  /* ========= THEME COLORS ========= */
  --color-primary: #0ea5e9;
  --color-primary-soft: #e0f2fe;
  --color-primary-dark: #0369a1;

  --color-accent: #facc15;
  --color-accent-soft: #fef9c3;

  --color-bg: #f3f4f6;
  --color-bg-alt: #f9fafb;
  --color-bg-gradient-start: #e0f2fe;
  --color-bg-gradient-end: #f3f4f6;

  --color-card: #ffffff;

  --color-text-main: #0f172a;
  --color-text-muted: #6b7280;

  --color-border: #e5e7eb;

  --color-success: #22c55e;
  --color-success-bg: #dcfce7;
  --color-success-text: #166534;

  --color-danger: #ef4444;
  --color-danger-bg: #fee2e2;
  --color-danger-text: #991b1b;

  --color-warning-bg: #fef9c3;
  --color-warning-text: #854d0e;

  --color-chip-bg: #e5e7eb;
  --color-chip-text: #4b5563;

  --color-invoice-bg: #eef2ff;
  --color-invoice-text: #3730a3;

  /* ========= TYPO ========= */
  --font-family-main: "Tajawal", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* ✅ تكبير خطوط أساسياً */
  --text-xs: 0.82rem;
  --text-sm: 0.92rem;
  --text-md: 1.02rem;
  --text-lg: 1.12rem;
  --text-xl: 1.3rem;
  --text-2xl: 1.55rem;

  /* ========= RADII ========= */
  --radius-pill: 999px;
  --radius-lg: 16px;
  --radius-md: 10px;

  /* ========= SHADOWS ========= */
  --shadow-soft: 0 14px 35px rgba(15, 23, 42, 0.08);
  --shadow-tab: 0 6px 20px rgba(148, 163, 184, 0.25);
  --shadow-strong: 0 12px 26px rgba(37, 99, 235, 0.45);

  /* ========= TRANSITION ========= */
  --transition-fast: 0.2s ease;
  --transition-med: 0.25s ease-out;
}

* {
  box-sizing: border-box;
  font-family: var(--font-family-main);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at top left, var(--color-bg-gradient-start), var(--color-bg-gradient-end));
  color: var(--color-text-main);
}

/* ✅ تحسين عرض المحتوى على الموبايل */
.app-shell {
  max-width: 1280px;
  margin: 20px auto;
  padding: 0 16px 32px;
}

/* =========================
   Header / Top Header
   ========================= */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}

.top-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-badge {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: var(--text-md);
  box-shadow: var(--shadow-soft);
}

.logo-text-title {
  font-weight: 700;
  font-size: var(--text-xl);
}

.logo-text-sub {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* =========================
   Nav Tabs (Desktop)
   ========================= */
.nav-tabs {
  display: flex;
  gap: 10px;
  background: rgba(255, 255, 255, 0.72);
  padding: 6px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-tab);
  backdrop-filter: blur(10px); 
}

.nav-tabs::-webkit-scrollbar {
  height: 8px;
}
.nav-tabs::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.45);
  border-radius: 999px;
}

.nav-btn {
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: var(--text-md);
  cursor: pointer;
  color: var(--color-text-muted);
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  scroll-snap-align: start;
}

.nav-btn span.icon {
  font-size: 1.1rem;
}

.nav-btn.active {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 8px 22px rgba(56, 189, 248, 0.5);
}

/* =========================
   Mobile Nav Toggle
   ========================= */

/* زر التوجل */
.nav-toggle {
  display: none;
  border: none;
  background: white;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

/* Overlay خلف القائمة */
.nav-overlay {
  display: none;
}

/* ===== Mobile ===== */
@media (max-width: 980px) {

  /* اظهار زر التوجل */
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
  }

  /* إخفاء شريط التنقل افتراضيًا */
  .nav-tabs {
    position: fixed;
    top: 88px;
    right: 12px;
    left: 12px;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 12px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: var(--shadow-tab);
    z-index: 1001;

    overflow-x: visible;
    scroll-snap-type: none;
  }

  /* عند الفتح */
  .nav-tabs.is-open {
    display: flex;
    animation: navFadeIn 0.25s ease;
  }

  /* الأزرار داخل القائمة */
  .nav-tabs .nav-btn {
    justify-content: flex-start;
    padding: 12px 14px;
    font-size: var(--text-md);
    width: 100%;
  }

  /* Overlay خلف القائمة */
  .nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(2px);
    z-index: 1000;
  }

  .nav-overlay.is-open {
    display: block;
  }
}

/* حركة بسيطة */
@keyframes navFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

main {
  margin-top: 10px;
}

/* =========================
   IMPORTANT FIX:
   injected pages may contain .page which is hidden by default
   ========================= */
.page {
  display: none;
  animation: fadeIn var(--transition-med);
}
.page.active {
  display: block;
}

/* ✅ لو الصفحة محقونة داخل app-content: لا تخفيها */
#app-content .page,
#app-content .page.active{
  display: block !important;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

/* ✅ كانت تضغط الكروت على الموبايل */
.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 10px;
}

.card-title {
  font-weight: 700;
  font-size: var(--text-lg);
}

.card-sub {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.stat-card {
  padding: 16px 16px;
  border-radius: var(--radius-md);
  background: var(--color-primary-soft);
  border: 1px solid rgba(56, 189, 248, 0.5);
}

.stat-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.stat-value {
  margin-top: 6px;
  font-size: var(--text-2xl);
  font-weight: 800;
}

.stat-chip {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  font-size: var(--text-xs);
  background: var(--color-accent-soft);
  color: var(--color-warning-text);
}

.badge-soft {
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  background: var(--color-chip-bg);
  color: var(--color-chip-text);
}

.primary-btn {
  border: none;
  border-radius: var(--radius-pill);
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: white;
  font-weight: 700;
  font-size: var(--text-md);
  cursor: pointer;
  box-shadow: var(--shadow-strong);
  transition: var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 35px rgba(37, 99, 235, 0.55);
}

.primary-btn:active {
  transform: translateY(0);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.45);
}

.secondary-btn {
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  padding: 10px 14px;
  font-size: var(--text-sm);
  background: white;
  cursor: pointer;
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ✅ Tables: wrapper scroll on mobile */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  min-width: 720px;
}

th, td {
  padding: 10px 10px;
  text-align: right;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

th {
  font-weight: 700;
  color: var(--color-text-muted);
}

tr:last-child td {
  border-bottom: none;
}

.status-pill {
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.status-pending {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.status-done {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.status-cancelled {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
}

.invoice-chip {
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--color-invoice-bg);
  color: var(--color-invoice-text);
  font-size: var(--text-xs);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.muted {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.table-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.icon-btn {
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  padding: 6px 10px;
  background: white;
  cursor: pointer;
  font-size: var(--text-xs);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.icon-btn.danger {
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--color-danger);
}

.search-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.search-input {
  max-width: 280px;
  position: relative;
  width: 100%;
}

.search-input input {
  width: 100%;
  padding-inline-start: 36px;
}

.search-input span {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.filter-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  background: white;
  font-size: var(--text-xs);
  cursor: pointer;
  color: var(--color-text-muted);
}

.chip.active {
  background: var(--color-primary);
  color: white;
  border-color: transparent;
}

.input-row {
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

input, select, textarea {
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  padding: 10px 12px;
  font-size: var(--text-sm);
  outline: none;
  background: var(--color-bg-alt);
  transition: var(--transition-fast);
}

textarea {
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
  background: white;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35);
}

.two-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.section-title-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.pill-small {
  font-size: var(--text-xs);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--color-primary-soft);
  color: var(--color-text-main);
}

.highlight-profit {
  font-weight: 800;
  color: var(--color-success-text);
  font-size: var(--text-lg);
}

/* ===== Blocked Customers ===== */
.status-blocked {
  background: rgba(239, 68, 68, 0.12);
  color: var(--color-danger-text);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 999;
}

.modal-overlay.is-open {
  display: flex;
}

.modal {
  width: min(720px, 100%);
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(148, 163, 184, 0.22);
  overflow: hidden;
}

.modal-header {
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--color-border);
}

.modal-title {
  font-weight: 800;
  font-size: var(--text-lg);
}

.modal-sub {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.modal-body {
  padding: 14px 16px;
}

.modal-footer {
  padding: 12px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--color-border);
}

/* Optional: make costs stand out a bit */
.cost-negative {
  color: var(--color-danger-text);
  font-weight: 800;
}

/* Layout wrapper for split sidebar/main */
.layout{
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  align-items: start;
}
.main{ min-height: 60vh; }

/* Sidebar small styling */
.sidebar{ position: sticky; top: 16px; }
.sidebar-card{
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(148,163,184,0.25);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 10px 26px rgba(15,23,42,0.08);
  margin-bottom: 12px;
}
.sidebar-title{ font-weight: 800; margin-bottom: 10px; }
.sidebar-btn{
  width: 100%;
  margin-bottom: 8px;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  padding: 10px 12px;
  background: #fff;
  cursor: pointer;
  text-align: right;
  font-size: var(--text-sm);
}
.sidebar-btn:hover{ filter: brightness(0.98); }

.spacer-16{ height: 16px; }

/* =========================
   ✅ MOBILE IMPROVEMENTS
   ========================= */
@media (max-width: 980px){
  .layout{ grid-template-columns: 1fr; }
  .sidebar{ position: static; }
}

/* ✅ موبايل: الهيدر وnav والكروت بشكل أجمل */
@media (max-width: 768px) {

  .app-shell {
    margin: 12px auto;
    padding: 0 12px 22px;
  }

  header,
  .top-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .logo-badge {
    width: 44px;
    height: 44px;
    border-radius: 16px;
    font-size: var(--text-lg);
  }

  .logo-text-title {
    font-size: 1.2rem;
    line-height: 1.35;
  }

  .logo-text-sub {
    font-size: var(--text-sm);
  }

  /* ✅ الكروت: خليه صف واحد */
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 14px 14px;
    border-radius: 18px;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .primary-btn {
    width: 100%;
    justify-content: center;
    padding: 12px 16px;
  }

  .secondary-btn {
    width: 100%;
    justify-content: center;
  }

  .search-input {
    max-width: 100%;
  }

  /* ✅ الجداول: لا تصغر، خلّيها scroll */
  table {
    min-width: 780px;
  }

  th, td {
    padding: 10px 10px;
    font-size: var(--text-sm);
  }
}

/* ✅ موبايل صغير جدًا */
@media (max-width: 420px) {
  .logo-text-title { font-size: 1.1rem; }
  .stat-value { font-size: 1.45rem; }
}

/* =========================
   ✅ MOBILE: Tables -> Cards
   ========================= */
@media (max-width: 560px) {

  .card table {
    width: 100%;
    min-width: 0 !important;
    border-collapse: separate;
    border-spacing: 0 10px;
  }

  .card table thead {
    display: none !important;
  }

  .card table tbody,
  .card table tr,
  .card table td {
    display: block;
    width: 100%;
  }

  .card table tr {
    background: rgba(255,255,255,0.95);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 14px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
    overflow: hidden;
    padding: 10px 10px;
  }

  .card table td {
    border: none !important;
    padding: 8px 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    text-align: right;
  }

  .card table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    flex: 0 0 auto;
    max-width: 48%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .card table td:last-child {
    padding-top: 10px;
  }

  .table-actions {
    justify-content: flex-start !important;
    gap: 8px !important;
  }

  .icon-btn {
    padding: 8px 10px !important;
    font-size: var(--text-xs) !important;
  }

  .two-cols {
    grid-template-columns: 1fr !important;
  }
}
/* =========================
   ✅ MOBILE TABLE SCROLL (Keep as Table)
   ========================= */

.table-wrap{
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
}

/* شريط تمرير ناعم */
.table-wrap::-webkit-scrollbar{ height: 10px; }
.table-wrap::-webkit-scrollbar-thumb{
  background: rgba(148, 163, 184, 0.55);
  border-radius: 999px;
}

.table-wrap table{
  width: 100%;
  border-collapse: collapse;
  min-width: 860px; /* مهم: يخلي الجدول أعرض من الهاتف فتظهر إمكانية السحب */
}

/* موبايل: خفف المسافات شوي */
@media (max-width: 768px){
  th, td{
    padding: 10px 10px;
    font-size: var(--text-sm);
    white-space: nowrap; /* مهم: يمنع تكسير النص داخل الخلايا */
  }
}

/* موبايل صغير جدًا */
@media (max-width: 420px){
  th, td{
    padding: 9px 9px;
    font-size: var(--text-xs);
  }
}
