/* ================================================================
   MARTELTECH — layout.css
   نظام التخطيط الكامل: هيدر + سايدبار + محتوى + موبايل
   يعمل مع متغيرات marteltech.css
   ================================================================ */

/* ----------------------------------------------------------------
   1. VARIABLES (override هنا إذا احتجت)
   ---------------------------------------------------------------- */
:root {
  --sidebar-w:      270px;
  --sidebar-sm:     70px;
  --header-h:       64px;
  --content-pad:    1.5rem;
  --content-pad-sm: 1rem;
  --transition:     0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ----------------------------------------------------------------
   2. BASE RESET
   ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  overflow-x: hidden; /* يمنع الـ scroll الأفقي دون كسر position:fixed */
}
body {
  font-family: 'Tajawal', sans-serif;
  background: #F0F2F5;
  color: #2C3E50;
  direction: rtl;
  overflow-x: hidden;
  margin: 0; padding: 0;
}

/* ----------------------------------------------------------------
   3. HEADER LAYOUT
   ---------------------------------------------------------------- */
#header {
  position: fixed;
  top: 0;
  right: var(--sidebar-w);
  left: 0;
  height: var(--header-h);
  z-index: 1030;
  transition: right var(--transition);
  /* الخلفية والتصميم من marteltech.css */
}

/* عندما السايدبار مطوي */
body.sidebar-collapsed #header {
  right: var(--sidebar-sm);
}

/* موبايل: الهيدر كامل العرض */
@media (max-width: 991.98px) {
  #header {
    right: 0 !important;
  }
}

/* ----------------------------------------------------------------
   4. SIDEBAR LAYOUT
   ---------------------------------------------------------------- */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--sidebar-w);
  z-index: 1040;
  transition: width var(--transition), transform var(--transition);
  overflow: hidden;
  /* الخلفية والتصميم من marteltech.css */
}

/* حالة المطوي (ديسكتوب) */
body.sidebar-collapsed #sidebar {
  width: var(--sidebar-sm);
}

/* موبايل: مخفي خارج الشاشة */
@media (max-width: 991.98px) {
  #sidebar {
    transform: translateX(110%);
    width: var(--sidebar-w) !important;
    box-shadow: none;
  }
  #sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: -8px 0 40px rgba(0,0,0,0.3);
  }
}

/* ----------------------------------------------------------------
   5. MAIN CONTENT LAYOUT
   ---------------------------------------------------------------- */
#main {
  margin-right: var(--sidebar-w);
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
  padding: var(--content-pad);
  transition: margin-right var(--transition);
  background: #F0F2F5;
  width: calc(100% - var(--sidebar-w));
  max-width: calc(100% - var(--sidebar-w));
  overflow-x: hidden;
  box-sizing: border-box;
}

body.sidebar-collapsed #main {
  margin-right: var(--sidebar-sm);
  width: calc(100% - var(--sidebar-sm));
  max-width: calc(100% - var(--sidebar-sm));
}

/* موبايل */
@media (max-width: 991.98px) {
  #main {
    margin-right: 0 !important;
    width: 100% !important;
    padding: var(--content-pad-sm);
  }
}

/* ----------------------------------------------------------------
   6. OVERLAY (موبايل)
   ---------------------------------------------------------------- */
#mtOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13, 27, 42, 0.6);
  z-index: 1035;
  backdrop-filter: blur(2px);
}
#mtOverlay.active { display: block; }

/* ----------------------------------------------------------------
   7. PAGE TITLE BAR
   ---------------------------------------------------------------- */
.page-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #E8ECF0;
}
.page-title-bar h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: #0D1B2A;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.page-title-bar h1 .title-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #F5821F, #00A99D);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 1rem;
  flex-shrink: 0;
}
.page-title-bar .title-meta {
  font-size: 0.82rem;
  color: #8A9BB0;
  font-weight: 500;
  display: flex; align-items: center; gap: 0.4rem;
}
.page-title-bar .title-meta i { color: #F5821F; }

/* ----------------------------------------------------------------
   8. CARDS
   ---------------------------------------------------------------- */
.mt-card {
  background: #fff;
  border: 1px solid #E8ECF0;
  min-width: 0;      /* يمنع تجاوز الـ flex children للحاوية */
  overflow: hidden;
  border-radius: 14px;
  box-shadow: 0 2px 12px rgba(13,27,42,0.06);
  overflow: hidden;
  transition: box-shadow 0.25s, transform 0.25s;
}
.mt-card:hover {
  box-shadow: 0 6px 24px rgba(13,27,42,0.10);
}
.mt-card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #F0F2F5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem;
}
.mt-card-header .mt-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #0D1B2A;
  margin: 0;
  display: flex; align-items: center; gap: 0.4rem;
}
.mt-card-header .mt-card-title i { color: #00A99D; }
.mt-card-body { padding: 1.25rem; }

/* ----------------------------------------------------------------
   9. STAT CARDS (بطاقات الإحصاء)
   ---------------------------------------------------------------- */
.kpi-card {
  background: #fff;
  border-radius: 14px;
  padding: 1.25rem;
  border: 1px solid #E8ECF0;
  box-shadow: 0 2px 12px rgba(13,27,42,0.05);
  position: relative;
  overflow: hidden;
  transition: all 0.28s;
  height: 100%;
}
.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 28px rgba(13,27,42,0.12);
}
/* خط علوي ملون */
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0; left: 0;
  height: 3px;
}
.kpi-card.kpi-revenue::before  { background: linear-gradient(90deg,#27AE60,#2ECC71); }
.kpi-card.kpi-expense::before  { background: linear-gradient(90deg,#E74C3C,#C0392B); }
.kpi-card.kpi-balance::before  { background: linear-gradient(90deg,#F5821F,#D96B10); }
.kpi-card.kpi-profit::before   { background: linear-gradient(90deg,#00A99D,#007D74); }

.kpi-card .kpi-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 0.75rem;
}
.kpi-card .kpi-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #8A9BB0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kpi-card .kpi-icon {
  width: 44px; height: 44px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.kpi-card.kpi-revenue .kpi-icon { background: #E9FBF0; color: #27AE60; }
.kpi-card.kpi-expense .kpi-icon { background: #FEE8E8; color: #E74C3C; }
.kpi-card.kpi-balance .kpi-icon { background: #FFF0E0; color: #F5821F; }
.kpi-card.kpi-profit  .kpi-icon { background: #E0F7F5; color: #00A99D; }

.kpi-card .kpi-value {
  font-size: 1.65rem;
  font-weight: 900;
  color: #0D1B2A;
  line-height: 1;
  margin-bottom: 0.4rem;
  direction: ltr;
  text-align: right;
}
.kpi-card .kpi-footer {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.78rem; color: #8A9BB0;
}
.kpi-card .kpi-badge {
  padding: 0.2rem 0.5rem;
  border-radius: 20px;
  font-size: 0.75rem; font-weight: 700;
}
.kpi-badge.up   { background: #E9FBF0; color: #27AE60; }
.kpi-badge.down { background: #FEE8E8; color: #E74C3C; }

/* ----------------------------------------------------------------
   10. BRANCH CARD
   ---------------------------------------------------------------- */
.branch-item {
  background: #F8FAFC;
  border: 1px solid #E8ECF0;
  border-radius: 12px;
  padding: 1rem;
  transition: all 0.25s;
  height: 100%;
}
.branch-item:hover {
  border-color: #00A99D;
  background: #F0FAFA;
  box-shadow: 0 4px 16px rgba(0,169,157,0.10);
}
.branch-item .branch-name {
  font-weight: 700; font-size: 0.92rem; color: #0D1B2A;
  display: flex; align-items: center; gap: 0.4rem;
}
.branch-item .branch-name i { color: #F5821F; }
.branch-item .branch-status {
  font-size: 0.72rem; padding: 0.2rem 0.6rem; border-radius: 12px;
  background: #E0F7F5; color: #007D74; font-weight: 700;
}
.branch-balance-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px dashed #E8ECF0;
  font-size: 0.82rem;
}
.branch-balance-row:last-child { border-bottom: none; }
.branch-balance-row .bl-label { color: #8A9BB0; font-weight: 600; }
.branch-balance-row .bl-values { display: flex; gap: 0.5rem; direction: ltr; }
.branch-balance-row .bl-dr { color: #E74C3C; font-weight: 700; }
.branch-balance-row .bl-cr { color: #27AE60; font-weight: 700; }

/* ----------------------------------------------------------------
   11. DATA TABLE
   ---------------------------------------------------------------- */
.mt-table-wrap {
  border-radius: 12px;
  overflow-x: auto;   /* تمرير أفقي بدل القطع */
  overflow-y: hidden;
  border: 1px solid #E8ECF0;
  -webkit-overflow-scrolling: touch;
}
.mt-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.88rem; margin: 0;
}
.mt-table thead tr {
  background: #0D1B2A;
}
.mt-table thead th {
  padding: 0.85rem 1rem;
  color: rgba(255,255,255,0.85);
  font-weight: 700; font-size: 0.8rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border: none;
}
.mt-table tbody tr {
  border-bottom: 1px solid #F0F2F5;
  transition: background 0.2s;
}
.mt-table tbody tr:last-child { border-bottom: none; }
.mt-table tbody tr:hover td { background: #F5FDFC; }
.mt-table tbody td {
  padding: 0.8rem 1rem;
  vertical-align: middle;
  color: #2C3E50;
}
.mt-table tbody tr:nth-child(even) td { background: #FAFBFC; }
.mt-table tbody tr:nth-child(even):hover td { background: #F5FDFC; }

/* تمييز المبالغ */
.mt-amount { font-weight: 700; color: #27AE60; direction: ltr; display: inline-block; }
.mt-amount.negative { color: #E74C3C; }

/* ----------------------------------------------------------------
   12. FILTER BAR
   ---------------------------------------------------------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.filter-bar .form-control,
.filter-bar .form-select {
  font-size: 0.85rem;
  border-radius: 8px;
  border: 1.5px solid #E8ECF0;
  padding: 0.4rem 0.75rem;
  height: 36px;
  min-width: 140px;
  color: #2C3E50;
  background: #fff;
}
.filter-bar .form-control:focus,
.filter-bar .form-select:focus {
  border-color: #00A99D;
  box-shadow: 0 0 0 3px rgba(0,169,157,0.12);
}
.filter-bar .btn-filter {
  height: 36px;
  padding: 0 1rem;
  background: #00A99D;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex; align-items: center; gap: 0.4rem;
  cursor: pointer;
  transition: all 0.25s;
  white-space: nowrap;
}
.filter-bar .btn-filter:hover {
  background: #007D74;
  box-shadow: 0 4px 12px rgba(0,169,157,0.3);
  transform: translateY(-1px);
}
.filter-bar .sep {
  color: #8A9BB0; font-size: 0.82rem; padding: 0 0.25rem;
}

/* ----------------------------------------------------------------
   13. RECENT INVOICE LIST
   ---------------------------------------------------------------- */
.inv-list { display: flex; flex-direction: column; gap: 0.5rem; }
.inv-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  background: #F8FAFC;
  border: 1px solid #E8ECF0;
  border-radius: 10px;
  transition: all 0.2s;
  cursor: pointer;
}
.inv-item:hover {
  background: #F0FAFA;
  border-color: #00A99D;
  transform: translateX(-4px);
}
.inv-item .inv-num {
  font-size: 0.85rem; font-weight: 800; color: #0D1B2A; white-space: nowrap;
}
.inv-item .inv-branch { font-size: 0.75rem; color: #8A9BB0; }
.inv-item .inv-date   { font-size: 0.73rem; color: #8A9BB0; margin-right: auto; white-space: nowrap; }
.inv-item .inv-amount {
  font-weight: 800; color: #27AE60; font-size: 0.88rem;
  direction: ltr; white-space: nowrap;
}

/* ----------------------------------------------------------------
   14. CHART WRAPPER
   ---------------------------------------------------------------- */
.chart-wrap { min-height: 280px; position: relative; }
.chart-wrap .apexcharts-canvas { direction: ltr !important; }

/* ----------------------------------------------------------------
   15. BUTTONS
   ---------------------------------------------------------------- */
.btn-mt-primary {
  background: #00A99D; color: #fff; border: none;
  border-radius: 8px; font-size: 0.88rem; font-weight: 700;
  padding: 0.45rem 1rem; cursor: pointer; transition: all 0.25s;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn-mt-primary:hover { background: #007D74; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,169,157,0.3); color: #fff; }

.btn-mt-orange {
  background: #F5821F; color: #fff; border: none;
  border-radius: 8px; font-size: 0.88rem; font-weight: 700;
  padding: 0.45rem 1rem; cursor: pointer; transition: all 0.25s;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn-mt-orange:hover { background: #D96B10; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(245,130,31,0.3); color: #fff; }

.btn-mt-sm { padding: 0.3rem 0.65rem !important; font-size: 0.78rem !important; }

.btn-icon {
  width: 30px; height: 30px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid #E8ECF0; background: #fff; cursor: pointer;
  color: #5A6A7A; font-size: 0.9rem; transition: all 0.2s;
}
.btn-icon:hover { border-color: #00A99D; color: #00A99D; background: #F0FAFA; }
.btn-icon.active { border-color: #00A99D; background: #00A99D; color: #fff; }

/* ----------------------------------------------------------------
   16. BADGES
   ---------------------------------------------------------------- */
.mt-badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem; border-radius: 20px;
  font-size: 0.72rem; font-weight: 700;
}
.mt-badge.success { background: #E9FBF0; color: #1D7A45; }
.mt-badge.danger  { background: #FEE8E8; color: #952828; }
.mt-badge.warning { background: #FFF8E1; color: #8A6100; }
.mt-badge.info    { background: #E0F7F5; color: #007D74; }
.mt-badge.navy    { background: #E8EDF2; color: #0D1B2A; }

/* ----------------------------------------------------------------
   17. EMPTY STATE
   ---------------------------------------------------------------- */
.empty-state {
  text-align: center; padding: 2.5rem 1rem;
  color: #8A9BB0;
}
.empty-state i { font-size: 2.5rem; color: #D0D9E4; margin-bottom: 0.75rem; display: block; }
.empty-state p { font-size: 0.88rem; margin: 0; }

/* ----------------------------------------------------------------
   18. LOADING SPINNER
   ---------------------------------------------------------------- */
.mt-spinner {
  display: flex; align-items: center; justify-content: center;
  gap: 0.5rem; padding: 1.5rem; color: #8A9BB0; font-size: 0.88rem;
}
.mt-spinner .spinner-border-sm { color: #00A99D; }

/* ----------------------------------------------------------------
   19. RESPONSIVE GRID HELPERS
   ---------------------------------------------------------------- */
@media (max-width: 575.98px) {
  .hide-xs { display: none !important; }
  #main { padding: 0.75rem 0.6rem; }
  .kpi-card .kpi-value { font-size: 1.35rem; }
  .mt-table thead th:nth-child(n+4) { display: none; }
  .mt-table tbody td:nth-child(n+4) { display: none; }
}

@media (max-width: 767.98px) {
  .hide-sm { display: none !important; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .form-control,
  .filter-bar .form-select,
  .filter-bar .btn-filter { width: 100%; min-width: unset; }
  .filter-bar .sep { display: none; }
  .page-title-bar h1 { font-size: 1.15rem; }
}

@media (max-width: 991.98px) {
  .hide-md { display: none !important; }
}

/* ----------------------------------------------------------------
   20. SCROLLBAR GLOBAL
   ---------------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #F0F2F5; }
::-webkit-scrollbar-thumb { background: #C8D0DA; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #00A99D; }

/* ----------------------------------------------------------------
   21. PRINT
   ---------------------------------------------------------------- */
@media print {
  #sidebar, #header, .filter-bar, .btn-icon, .btn-mt-primary, .btn-mt-orange { display: none !important; }
  #main { margin: 0 !important; width: 100% !important; padding: 0 !important; }
}
