@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700;800&display=swap');

:root {
  --primary: #1e3a5f;
  --primary-light: #2a5298;
  --accent: #e67e22;
  --success: #27ae60;
  --danger: #e74c3c;
  --warning: #f39c12;
  --info: #2980b9;
  --secondary: #6c757d;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-muted: #7f8c8d;
  --border: #dee2e6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
  --sidebar-w: 260px;
  --gradient: linear-gradient(135deg, #1e3a5f 0%, #2a5298 100%);
  --topbar-h: 60px;
}

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Cairo', sans-serif;
  direction: rtl;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}

/* ====================== SIDEBAR ====================== */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--gradient);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  transition: transform 0.3s ease, width 0.3s ease;
}

.sidebar-logo {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-logo img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: contain;
  background: rgba(255,255,255,0.2);
}

.sidebar-logo-icon {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.sidebar-logo-text h2 { font-size: 14px; font-weight: 700; line-height: 1.2; }
.sidebar-logo-text small { font-size: 11px; opacity: 0.7; }

/* Scrollable nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

/* Nav Group */
.nav-group { margin-bottom: 2px; }

.nav-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  cursor: pointer;
  user-select: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.nav-group-header:hover { opacity: 1; }
.nav-group-header .arrow {
  font-size: 10px;
  transition: transform 0.25s;
}
.nav-group-header.open .arrow { transform: rotate(180deg); }

.nav-group-items {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.35s ease;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px 9px 12px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
  border-radius: 6px;
  margin: 1px 8px;
}
.nav-item:hover { background: rgba(255,255,255,0.15); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.2); color: #fff; font-weight: 700; }
.nav-item .nav-icon { width: 20px; text-align: center; font-size: 14px; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 12px;
  opacity: 0.6;
  flex-shrink: 0;
}

/* Sidebar Overlay for mobile/tablet */
#sidebarOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  backdrop-filter: blur(2px);
}
#sidebarOverlay.show { display: block; }

/* ====================== MAIN ====================== */
#main {
  margin-right: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-right 0.3s ease;
}

/* ====================== TOPBAR ====================== */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  gap: 12px;
}

/* Hamburger button - hidden on desktop */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 38px;
  height: 38px;
  background: var(--gradient);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  gap: 5px;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.hamburger-btn:hover { opacity: 0.85; }
.hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: all 0.3s;
}
.hamburger-btn.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger-btn.active span:nth-child(2) { opacity: 0; }
.hamburger-btn.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
}
.user-avatar {
  width: 34px;
  height: 34px;
  background: var(--gradient);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.topbar-search input::placeholder { color: rgba(100,100,100,0.6); }
.topbar-search .form-control { background: rgba(30,58,95,0.07); border: 1px solid var(--border); color: var(--text); }
.search-result-item { display:flex; align-items:center; gap:10px; padding:10px 14px; text-decoration:none; color:#222; border-bottom:1px solid #f0f2f5; font-size:13px; transition:background 0.15s; }
.search-result-item:hover { background:#f0f4f8; }
.sri-icon { font-size:18px; flex-shrink:0; }
.sri-title { font-weight:600; }
.sri-sub { font-size:11px; color:#888; }
.dd-item:hover { background:#e8f0fe !important; }

/* ====================== CONTENT ====================== */
.content { padding: 24px; flex: 1; }

/* Page Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-header h1 { font-size: 20px; font-weight: 700; color: var(--primary); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ====================== CARDS ====================== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 20px;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfc;
  flex-wrap: wrap;
  gap: 8px;
}
.card-header h3 { font-size: 15px; font-weight: 700; color: var(--primary); }
.card-body { padding: 20px; }

/* ====================== STAT CARDS ====================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
  flex-shrink: 0;
}
.stat-info .label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.stat-info .value { font-size: 22px; font-weight: 800; color: var(--text); }

/* ====================== TABLE ====================== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; min-width: 600px; }
thead tr { background: #f8f9fa; }
th {
  padding: 12px 14px;
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 11px 14px;
  border-bottom: 1px solid #f0f2f5;
  font-size: 13px;
  vertical-align: middle;
}
tbody tr:hover { background: #f8f9fa; }

/* Action buttons in table - stack on small screens */
.table-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}

/* ====================== BUTTONS ====================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--gradient); color: #fff; }
.btn-primary:hover { opacity: 0.9; box-shadow: 0 4px 12px rgba(30,58,95,0.3); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { opacity: 0.9; }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { opacity: 0.9; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { opacity: 0.9; }
.btn-light { background: #f0f2f5; color: var(--text); }
.btn-light:hover { background: #e2e6ea; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* ====================== FORMS ====================== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  transition: border-color 0.2s;
  direction: rtl;
}
.form-control:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(42,82,152,0.1); }
.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

/* ====================== BADGES ====================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.badge-success { background: #d4edda; color: #155724; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-primary { background: #d6e4f7; color: #1e3a5f; }
.badge-secondary { background: #e2e3e5; color: #383d41; }

/* ====================== ALERTS ====================== */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13px; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ====================== MODAL ====================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  animation: fadeIn 0.2s ease;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfc;
  position: sticky;
  top: 0;
  z-index: 1;
}
.modal-header h4 { font-size: 15px; font-weight: 700; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); padding: 0 4px; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  background: #fff;
  z-index: 1;
}

/* Large modal */
.modal-box.modal-lg { max-width: 900px; }
.modal-box.modal-xl { max-width: 1100px; }

/* ====================== Import dropzone ====================== */
.import-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafbfc;
}
.import-dropzone:hover { border-color: var(--primary-light); background: #f0f4ff; }

/* ====================== MAP ====================== */
#rep-map { width: 100%; height: 400px; border-radius: var(--radius); border: 1px solid var(--border); }

/* ====================== UTILITIES ====================== */
.btn-back { color: var(--primary); font-weight: 600; font-size: 13px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.w-100 { width: 100%; }
.fw-bold { font-weight: 700; }

/* ====================== SPINNER ====================== */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(30,58,95,0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ====================== TABS ====================== */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: 8px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ====================== LOGIN PAGE ====================== */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--gradient); padding: 16px; }
.login-card { background: #fff; border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.2); padding: 40px; width: 100%; max-width: 400px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon { width: 70px; height: 70px; background: var(--gradient); border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 32px; margin: 0 auto 12px; }

/* ====================== PRINT - PROFESSIONAL ====================== */
@media print {
  #sidebar, .topbar, .no-print, .hamburger-btn, #sidebarOverlay,
  .page-actions, .btn-back, nav, .modal-overlay { display: none !important; }
  #main { margin-right: 0 !important; }
  body { background: #fff; font-size: 12px; color: #000; }
  .content { padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd; }

  /* Print document page */
  .print-page {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .print-header { border-bottom: 2px solid #1e3a5f !important; }
  table { page-break-inside: avoid; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
  .print-footer { page-break-inside: avoid; margin-top: 20px; }

  @page {
    size: A4;
    margin: 15mm 10mm 15mm 10mm;
  }
}

/* ====================== PROFESSIONAL PRINT DOCUMENT ====================== */
.print-page {
  max-width: 900px;
  margin: 0 auto;
  background: #fff;
  padding: 30px;
  font-family: 'Cairo', sans-serif;
  direction: rtl;
}

.print-watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-35deg);
  font-size: 80px;
  font-weight: 900;
  opacity: 0.04;
  color: #1e3a5f;
  pointer-events: none;
  z-index: 0;
  white-space: nowrap;
}

.print-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 3px solid #1e3a5f;
  padding-bottom: 16px;
  margin-bottom: 20px;
}

.print-header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.print-header-logo img {
  width: 60px;
  height: 60px;
  object-fit: contain;
}
.print-header-logo .company-name {
  font-size: 16px;
  font-weight: 800;
  color: #1e3a5f;
  line-height: 1.3;
}
.print-header-logo .company-sub {
  font-size: 11px;
  color: #666;
}

.print-header-doc {
  text-align: center;
}
.print-header-doc .doc-type {
  font-size: 18px;
  font-weight: 800;
  color: #1e3a5f;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.print-header-doc .doc-number {
  font-size: 14px;
  color: #444;
  margin-top: 4px;
}

.print-header-stamp {
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.doc-status-stamp {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  border: 2px solid currentColor;
}
.doc-status-stamp.draft { color: #856404; border-color: #ffc107; background: #fff8e1; }
.doc-status-stamp.original { color: #155724; border-color: #28a745; background: #d4edda; }
.doc-status-stamp.copy { color: #0c5460; border-color: #17a2b8; background: #d1ecf1; }

.print-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 14px;
}
.print-meta-row {
  display: flex;
  gap: 8px;
}
.print-meta-label {
  font-size: 11px;
  color: #666;
  font-weight: 700;
  min-width: 100px;
  flex-shrink: 0;
}
.print-meta-value {
  font-size: 12px;
  color: #222;
  font-weight: 600;
}

.print-party-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.print-party-box {
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 12px 14px;
}
.print-party-box h4 {
  font-size: 11px;
  color: #666;
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 6px;
}
.print-party-box p {
  font-size: 13px;
  font-weight: 700;
  color: #1e3a5f;
  margin-bottom: 3px;
}
.print-party-box small {
  font-size: 11px;
  color: #666;
  display: block;
}

.print-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 12px;
}
.print-items-table thead tr {
  background: #1e3a5f;
  color: #fff;
}
.print-items-table th {
  padding: 10px 12px;
  text-align: right;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  border: none;
  color: #fff;
}
.print-items-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #f0f2f5;
  font-size: 12px;
  vertical-align: middle;
}
.print-items-table tbody tr:nth-child(even) {
  background: #f8f9fa;
}
.print-items-table tbody tr:hover {
  background: #e8f0fe;
}
.print-items-table tfoot tr {
  background: #f8f9fa;
  font-weight: 700;
}
.print-items-table tfoot td {
  border-top: 2px solid #dee2e6;
}

.print-totals {
  margin-right: auto;
  min-width: 260px;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  overflow: hidden;
}
.print-totals table {
  width: 100%;
  min-width: auto;
}
.print-totals td {
  padding: 8px 14px;
  font-size: 12px;
  border-bottom: 1px solid #f0f2f5;
}
.print-totals td:first-child {
  color: #666;
  font-weight: 600;
}
.print-totals td:last-child {
  text-align: left;
  font-weight: 700;
  color: #222;
}
.print-totals .grand-total td {
  background: #1e3a5f;
  color: #fff !important;
  font-size: 14px;
  font-weight: 800;
}

.print-notes {
  margin-top: 16px;
  padding: 12px 14px;
  background: #fffbf0;
  border: 1px solid #ffeeba;
  border-radius: 8px;
  font-size: 12px;
}
.print-notes strong {
  color: #856404;
  display: block;
  margin-bottom: 4px;
}

.print-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
  margin-top: 40px;
  text-align: center;
}
.print-sig-box {
  border-top: 1px solid #aaa;
  padding-top: 8px;
  font-size: 11px;
  color: #666;
  font-weight: 700;
}

.print-footer-bar {
  margin-top: 30px;
  padding-top: 12px;
  border-top: 2px solid #1e3a5f;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #666;
}

.print-btn-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  padding: 14px 20px;
  background: #f8f9fa;
  border-radius: 8px;
  align-items: center;
}
@media print {
  .print-btn-bar { display: none !important; }
  .print-watermark { display: block !important; }
}

/* ====================== IMAGE UPLOAD ====================== */
.img-upload-wrap { position: relative; display: inline-block; }
.img-preview { width: 80px; height: 80px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); background: #f8f9fa; }
.img-upload-btn { position: absolute; bottom: 0; right: 0; background: var(--primary); color: #fff; border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 12px; }

/* ====================== STORE ====================== */
.store-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.product-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; transition: transform 0.2s; }
.product-card:hover { transform: translateY(-2px); }
.product-card img { width: 100%; height: 160px; object-fit: cover; background: #f0f2f5; }
.product-card-body { padding: 14px; }
.product-card-name { font-weight: 700; margin-bottom: 6px; }
.product-card-price { color: var(--primary); font-size: 16px; font-weight: 800; }

/* Cart */
.cart-badge { background: var(--danger); color: #fff; border-radius: 50%; width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; }

/* ====================== FILTER BAR ====================== */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.filter-bar .form-control {
  min-width: 140px;
  flex: 1;
}

/* ====================== GRID LAYOUTS ====================== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ====================== NOTIFICATION PANEL ====================== */
#notifPanel {
  font-family: 'Cairo', sans-serif;
}

/* ====================== RESPONSIVE: TABLET (768px - 1024px) ====================== */
@media (max-width: 1024px) and (min-width: 769px) {
  :root {
    --sidebar-w: 220px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }

  .content { padding: 16px; }

  .topbar { padding: 0 16px; }

  /* Smaller nav items */
  .nav-item { font-size: 12px; padding: 8px 12px 8px 10px; }
  .sidebar-logo-text h2 { font-size: 13px; }
}

/* ====================== RESPONSIVE: MOBILE & SMALL TABLET (≤768px) ====================== */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 270px;
  }

  /* Sidebar: hidden by default, slides in */
  #sidebar {
    transform: translateX(100%);
    transition: transform 0.3s ease;
    width: var(--sidebar-w);
  }
  #sidebar.open {
    transform: translateX(0);
  }

  /* Main takes full width */
  #main {
    margin-right: 0;
  }

  /* Show hamburger */
  .hamburger-btn {
    display: flex;
  }

  /* Topbar adjustments */
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }
  .topbar-title {
    font-size: 14px;
  }

  /* Hide search on small screens, show as icon */
  .topbar-search {
    display: none !important;
  }

  /* Compact user info */
  .topbar-user {
    gap: 6px;
  }
  .topbar-user > span {
    display: none;
  }

  /* Content */
  .content { padding: 12px; }

  /* Stats */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-icon { width: 40px; height: 40px; font-size: 18px; }
  .stat-info .value { font-size: 18px; }

  /* Grids */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  /* Form row */
  .form-row { grid-template-columns: 1fr; }

  /* Page header */
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header h1 { font-size: 17px; }

  /* Modal */
  .modal-box { max-width: 100%; border-radius: 12px 12px 0 0; margin-top: auto; }
  .modal-overlay { align-items: flex-end; padding: 0; }

  /* Buttons */
  .btn { padding: 7px 12px; font-size: 12px; }
  .btn-lg { padding: 10px 18px; font-size: 14px; }

  /* Card header */
  .card-header { flex-direction: column; align-items: flex-start; }

  /* Filter bar */
  .filter-bar { flex-direction: column; }
  .filter-bar .form-control { min-width: 100%; }

  /* Table actions */
  .table-actions { gap: 3px; }
  .table-actions .btn-sm { padding: 4px 7px; font-size: 11px; }

  /* Login */
  .login-card { padding: 28px 20px; }
}

/* ====================== RESPONSIVE: TABLET LANDSCAPE (769px - 1024px) ====================== */
@media (min-width: 769px) and (max-width: 1024px) {
  /* Show hamburger on tablet too for more content space */
  .hamburger-btn {
    display: flex;
  }

  #sidebar {
    transform: translateX(100%);
    transition: transform 0.3s ease;
  }
  #sidebar.open {
    transform: translateX(0);
  }

  #main {
    margin-right: 0;
  }

  .content { padding: 18px; }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }

  .topbar {
    padding: 0 16px;
  }
  .topbar-search {
    max-width: 280px !important;
  }

  /* Form */
  .form-row {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Modal */
  .modal-box {
    max-width: 85%;
  }
  .modal-box.modal-lg {
    max-width: 95%;
  }
}

/* ====================== EXTRA SMALL (≤480px) ====================== */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { flex-direction: row; }

  th, td { padding: 8px 10px; font-size: 12px; }

  .page-header h1 { font-size: 15px; }

  .tabs .tab-btn { padding: 7px 12px; font-size: 12px; }

  .modal-body { padding: 14px; }
  .modal-footer { padding: 10px 14px; }

  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }
}

/* ====================== ITEM LINE TABLE (in forms) ====================== */
.items-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
}
.items-table-wrap table {
  min-width: 700px;
}

/* table-wrap with overflow:visible (for dropdowns in tables) */
.table-wrap[style*="overflow:visible"] {
  overflow: visible !important;
}
.table-wrap[style*="overflow: visible"] {
  overflow: visible !important;
}

/* Totals box */
.totals-box {
  margin-top: 16px;
}
.totals-table {
  min-width: auto !important;
  width: auto;
  margin-right: auto;
}
@media (max-width: 768px) {
  .totals-box {
    overflow-x: auto;
  }
  .totals-table {
    width: 100% !important;
  }
}

/* ====================== CHEQUES STATS ====================== */
.cheque-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 768px) {
  .cheque-stats { grid-template-columns: 1fr; }
}
@media (min-width: 769px) and (max-width: 1024px) {
  .cheque-stats { grid-template-columns: repeat(3, 1fr); }
}

/* ====================== DASHBOARD CHARTS ====================== */
.chart-wrap {
  position: relative;
  height: 300px;
  width: 100%;
}
@media (max-width: 768px) {
  .chart-wrap { height: 220px; }
}

/* ====================== PORTAL PAGES ====================== */
.portal-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--gradient);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
@media (max-width: 768px) {
  .portal-topbar { padding: 10px 14px; }
  .portal-topbar h1 { font-size: 15px; }
}

/* ====================== USER NAME TEXT ====================== */
.user-name-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
@media (max-width: 768px) {
  .user-name-text { display: none; }
}
@media (min-width: 769px) and (max-width: 900px) {
  .user-name-text { display: none; }
}

/* ====================== NOTIFICATION BELL ====================== */
#notifPanel {
  position: absolute;
  top: 48px;
  left: -200px;
  width: 320px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  z-index: 1000;
  max-height: 400px;
  overflow-y: auto;
}
@media (max-width: 768px) {
  #notifPanel {
    left: auto;
    right: 0;
    width: 290px;
  }
}

/* ====================== SCROLL INDICATOR FOR TABLES ====================== */
.table-scroll-hint {
  display: none;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 0;
  text-align: center;
}
@media (max-width: 768px) {
  .table-scroll-hint { display: block; }
}

/* ====================== INLINE GRID RESPONSIVE OVERRIDES ====================== */
/* Makes inline-style grids responsive on tablets and mobile */
@media (max-width: 768px) {
  /* Dashboard 2-column grid to 1 column */
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* 2-col grids */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* 3-col grids */
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* print-header and doc-meta */
  .print-header {
    grid-template-columns: 1fr !important;
    text-align: center;
  }
  .doc-meta {
    grid-template-columns: 1fr !important;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  /* Dashboard 2-col grid stays or collapses */
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* 3-col grids become 2 */
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* Signature grids in print - keep as 2 */
@media (max-width: 768px) {
  [style*="gap:40px;text-align:center"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 16px !important;
  }
}

/* ====================== SIDEBAR CLOSE BUTTON (for mobile) ====================== */
.sidebar-close-btn {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  align-items: center;
  justify-content: center;
}
@media (max-width: 1024px) {
  .sidebar-close-btn { display: flex; }
}

/* ====================== TABLET ENHANCEMENTS (768px - 1024px) ====================== */
/* Tablet-specific improvements for 768-1024px viewport */
@media (min-width: 768px) and (max-width: 1024px) {
  /* Table scrolling on tablet */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  
  /* Touch-friendly button sizing */
  .btn { min-height: 38px; }
  .btn-sm { min-height: 32px; }
  
  /* Form row: 2 columns on tablet */
  .form-row { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  
  /* Stats: 2 columns */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  
  /* Modal full-screen on tablet */
  .modal-box { max-width: 90vw; }
  
  /* Page header wrapping */
  .page-header { flex-wrap: wrap; gap: 10px; }
  
  /* Report tables horizontal scroll */
  table { min-width: 600px; }
  
  /* Finance report grids: single column on tablet */
  [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
}

/* ====================== PWA INSTALL PROMPT ====================== */
#erp-install-btn {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 700;
  font-family: Cairo, sans-serif;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(30,58,95,0.4);
  z-index: 9999;
  gap: 8px;
  align-items: center;
  animation: pulse-btn 2s infinite;
}
@keyframes pulse-btn {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
#erp-install-btn.show { display: flex; }

/* ====================== PRINT IMPROVEMENTS ====================== */
@media print {
  .page-header form, .filter-bar, .btn, .hamburger-btn,
  #sidebar, .topbar, nav, .page-actions { display: none !important; }
  #main { margin: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #dee2e6 !important; }
  body { font-size: 12px; }
  h1 { font-size: 16px; }
  table { font-size: 11px; }
  .badge { border: 1px solid #999; }
}

/* ====================== ACCESSIBILITY IMPROVEMENTS ====================== */
:focus-visible {
  outline: 3px solid #2a5298;
  outline-offset: 2px;
}
@media (hover: none) {
  /* Touch devices: increase tap targets */
  .btn { padding: 10px 16px; }
  .nav-item { padding: 12px 16px; }
  .dropdown-item { padding: 12px 16px; }
}

/* ====================== ENHANCED MOBILE/TABLET COMPATIBILITY ====================== */
/* iOS safe areas */
@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: max(12px, env(safe-area-inset-top)); }
  #sidebar { padding-bottom: env(safe-area-inset-bottom); }
}

/* Ensure buttons don't shrink too much */
@media (max-width: 768px) {
  .btn-sm { padding: 5px 8px; font-size: 11px; min-width: 28px; }
  /* Action buttons in table cells */
  td > div[style*="display:flex"], td > div.d-flex {
    flex-wrap: wrap;
    gap: 3px;
  }
  /* Page header actions wrap */
  .page-actions { flex-wrap: wrap; gap: 6px; }
  /* Form controls full width */
  .form-group { width: 100%; }
  /* User name hidden on mobile */
  .user-name-text { display: none; }
  /* Back button stays visible */
  #hamburgerBtn + button { display: flex !important; }
}

/* Table responsive: add horizontal scroll indicator */
.table-wrap::after {
  content: '';
  display: none;
}
@media (max-width: 768px) {
  .table-wrap {
    border-radius: 8px;
    background: linear-gradient(to left, rgba(0,0,0,0.05) 0%, transparent 100%);
    background-repeat: no-repeat;
    background-size: 40px 100%;
    background-position: 0;
  }
}

/* Modal improvements for mobile */
@media (max-width: 768px) {
  .modal-box {
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* Sticky topbar on scroll */
.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
}

/* Print: hide action buttons */
@media print {
  .page-actions, .page-actions *, 
  button:not(.print-btn),
  .btn:not(.print-btn) { display: none !important; }
  .card { break-inside: avoid; }
}

/* Touch-friendly tap areas */
a, button, [role="button"] {
  -webkit-tap-highlight-color: rgba(30, 58, 95, 0.1);
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

/* Landscape mobile optimization */
@media (max-height: 500px) and (max-width: 900px) {
  .topbar { padding: 6px 12px; }
  .content { padding: 8px; }
  .card-body { padding: 10px; }
}

/* ====================== PRINT STYLES ====================== */
@media print {
  body { background: #fff !important; font-size: 12px; }
  #sidebar, .topbar, .page-actions, .btn:not(.print-visible),
  button:not(.print-visible), .modal-overlay, .no-print,
  nav, .sidebar-toggle, #installBtn { display: none !important; }
  .content { margin: 0 !important; padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd; break-inside: avoid; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; page-break-after: auto; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
  h1 { font-size: 16px !important; }
  @page { margin: 1cm; }
  .print-header { display: block !important; text-align: center; margin-bottom: 10px; font-size: 18px; font-weight: bold; }
}
.print-header { display: none; }

/* ====================== REPORT EXPORT ACTIONS ====================== */
.report-actions {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-bottom: 12px; padding: 10px; background: #f8f9fa; border-radius: 8px;
}

/* ══════════════════════════════════════════════
   TABLET & MOBILE RESPONSIVE - TAMIMI ERP
   ══════════════════════════════════════════════ */

/* ── TABLET (≤1024px) ── */
@media (max-width: 1024px) {
  #sidebar {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 270px;
    z-index: 1050;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    box-shadow: -4px 0 24px rgba(0,0,0,0.18);
  }
  #sidebar.open {
    transform: translateX(0) !important;
  }
  .main-content {
    margin-right: 0 !important;
    width: 100% !important;
  }
  .topbar {
    right: 0 !important;
    left: 0 !important;
    width: 100% !important;
  }
  #hamburgerBtn, .hamburger-btn {
    display: flex !important;
  }
  .stats-row, .kpi-row {
    flex-wrap: wrap;
  }
  .stat-card {
    min-width: calc(50% - 8px);
    flex: 0 0 calc(50% - 8px);
  }
}

/* ── TABLET (≤768px) ── */
@media (max-width: 768px) {
  .page-header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px;
  }
  .page-header h1 {
    font-size: 18px;
    line-height: 1.3;
  }
  .page-actions {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }
  .btn { padding: 6px 12px; font-size: 12px; }
  .btn-sm { padding: 4px 8px; font-size: 11px; }
  .btn-lg { padding: 8px 16px; font-size: 14px; }
  
  /* Table cells */
  td .btn { 
    padding: 3px 6px !important; 
    font-size: 11px !important;
    margin: 1px 1px !important;
  }
  td .btn-sm { padding: 2px 5px !important; font-size: 10px !important; }
  
  /* Tables */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 600px; }
  table th, table td { padding: 7px 9px !important; font-size: 12px; }
  
  /* Cards */
  .card { margin-bottom: 14px; border-radius: 10px; }
  .card-body { padding: 12px 14px; }
  .card-header { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  
  /* Stats cards */
  .stat-card {
    min-width: calc(50% - 8px);
    flex: 0 0 calc(50% - 8px);
    padding: 14px 12px;
  }
  .stat-card .stat-value { font-size: 20px !important; }
  
  /* Forms */
  .form-row { flex-wrap: wrap; }
  .form-row .form-group { 
    min-width: 100% !important;
    flex: 1 1 100%;
  }
  .form-group { margin-bottom: 12px; }
  .form-control { font-size: 14px; }
  
  /* Filters */
  .filter-form, .filter-bar, .search-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .filter-form .form-group { min-width: 48%; }
  
  /* Modals */
  .modal-overlay .modal-dialog,
  .modal-overlay .modal-content {
    width: 96vw !important;
    max-width: 96vw !important;
    margin: 8px auto !important;
    max-height: 90vh;
    overflow-y: auto;
  }
  .modal-body { padding: 14px 12px; }
  .modal-footer { padding: 10px 12px; }
  
  /* Items table in create/edit forms */
  .items-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .items-table-wrap table { min-width: 700px; }
  
  /* Reports tables */
  .report-wrap { overflow-x: auto; }
  
  /* Topbar */
  .topbar { padding: 0 10px; }
  .topbar-brand { font-size: 14px !important; }
  .topbar-actions .btn { font-size: 11px; padding: 4px 8px; }
  
  /* Breadcrumb */
  .breadcrumb { font-size: 11px; }
  
  /* Badge */
  .badge { font-size: 10px; padding: 3px 8px; }
}

/* ── MOBILE (≤576px) ── */
@media (max-width: 576px) {
  body { font-size: 13px; }
  
  .page-header { 
    flex-direction: column; 
    align-items: flex-start; 
    gap: 8px; 
    padding: 10px 12px;
  }
  .page-actions { 
    width: 100%; 
    flex-wrap: wrap; 
    gap: 5px; 
  }
  
  .stat-card { min-width: calc(50% - 6px); flex: 0 0 calc(50% - 6px); }
  .stat-card .stat-value { font-size: 18px !important; }
  .stat-card .stat-label { font-size: 11px; }
  
  .filter-form .form-group { min-width: 100% !important; }
  
  .card-header { flex-direction: column; align-items: flex-start; gap: 6px; }
  
  .table-wrap table { min-width: 550px; }
  table th, table td { padding: 5px 7px !important; font-size: 11px !important; }
  
  input[type="text"].form-control,
  input[type="number"].form-control,
  input[type="email"].form-control,
  input[type="date"].form-control,
  select.form-control,
  textarea.form-control {
    font-size: 14px;
    min-height: 38px;
  }
  
  /* Action buttons in table */
  td .btn { 
    padding: 2px 4px !important; 
    font-size: 10px !important;
    margin: 1px !important;
    min-height: unset !important;
  }
  
  /* Summary/totals */
  .totals-card { min-width: 100%; }
  
  .modal-overlay .modal-dialog { width: 99vw !important; margin: 4px auto !important; }
}

/* ── Touch improvements ── */
@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 36px; }
  .btn-sm { min-height: 30px; }
  .nav-item { min-height: 42px; }
  .form-control { min-height: 40px; }
  input[type="checkbox"], input[type="radio"] { 
    width: 18px; 
    height: 18px; 
    cursor: pointer;
  }
  td .btn { min-height: 28px; }
}
