/* ============================================================
   أعمالي ERP — Dashboard Styles
============================================================ */

html, body {
  overflow-x: hidden;
  max-width: 100%;
}

.hide-sm { display: none !important; }
@media (min-width: 641px)  { .hide-sm  { display: flex !important; } }

.hide-md { display: none !important; }
@media (min-width: 769px)  { .hide-md  { display: flex !important; } }

.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  position: fixed;
  top: 0;
  right: 0;
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: var(--z-300);
  transition: width var(--tr-slow), transform var(--tr-slow);
  overflow-x: clip;
  overflow-y: auto;
}

[data-lang="en"] .sidebar { right: auto; left: 0; border-left: none; border-right: 1px solid var(--border); }

.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5);
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  text-decoration: none;
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--blue-600), var(--violet-600));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  flex-shrink: 0;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity var(--tr), width var(--tr-slow);
}
.sidebar.collapsed .sidebar-logo-text { opacity: 0; width: 0; }

.sidebar-logo-name {
  font-size: var(--text-base);
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  white-space: nowrap;
}

.sidebar-logo-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-3) 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.sidebar-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) var(--sp-2);
  margin: var(--sp-1) var(--sp-2) 0;
  border-radius: var(--r);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: .08em;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  transition: opacity var(--tr), background var(--tr-fast), color var(--tr-fast);
  touch-action: manipulation;
}
.sidebar-section:hover { background: var(--surface-2); color: var(--text-muted); }
.sidebar-section-text { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sidebar-section-chevron { font-size: 1rem; line-height: 1; flex-shrink: 0; transition: transform var(--tr); }

.sidebar-group-body {
  overflow: hidden;
  max-height: 600px;
  transition: max-height var(--tr-slow) ease, opacity var(--tr);
}
.sidebar-group:not(.open) > .sidebar-group-body { max-height: 0; opacity: 0; }
.sidebar-group:not(.open) > .sidebar-section .sidebar-section-chevron { transform: rotate(-90deg); }

.sidebar.collapsed .sidebar-section { opacity: 0; height: 0; padding: 0; margin: 0; pointer-events: none; }
.sidebar.collapsed .sidebar-group-body { max-height: none !important; opacity: 1 !important; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  margin: 2px var(--sp-3);
  border-radius: var(--r);
  cursor: pointer;
  transition: background var(--tr-fast), color var(--tr-fast);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  user-select: none;
  position: relative;
  min-height: 40px;
  touch-action: manipulation;
}
.sidebar-item:hover  { background: var(--surface-2); color: var(--text); }
.sidebar-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
[data-theme="dark"] .sidebar-item.active { background: rgba(37,99,235,.2); }

.sidebar-item-icon {
  font-size: 1.2rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-item-label {
  flex: 1;
  overflow: hidden;
  transition: opacity var(--tr), width var(--tr-slow);
}
.sidebar.collapsed .sidebar-item-label { opacity: 0; width: 0; }

.sidebar-item-badge {
  min-width: 20px;
  height: 20px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  transition: opacity var(--tr);
}
.sidebar.collapsed .sidebar-item-badge { opacity: 0; }

.sidebar.collapsed .sidebar-item::after {
  content: attr(data-tooltip);
  position: absolute;
  right: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--slate-900);
  color: #fff;
  padding: 4px 10px;
  border-radius: var(--r);
  font-size: var(--text-xs);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--tr);
}
[data-lang="en"] .sidebar.collapsed .sidebar-item::after { right: auto; left: calc(100% + 8px); }
.sidebar.collapsed .sidebar-item:hover::after { opacity: 1; }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: var(--sp-3);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2);
  border-radius: var(--r);
  cursor: pointer;
  transition: background var(--tr);
  min-height: 44px;
  touch-action: manipulation;
}
.sidebar-user:hover { background: var(--surface-2); }

.sidebar-user-info {
  flex: 1;
  overflow: hidden;
  transition: opacity var(--tr), width var(--tr-slow);
}
.sidebar.collapsed .sidebar-user-info { opacity: 0; width: 0; }

.sidebar-user-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: calc(var(--z-200) - 1);
  touch-action: manipulation;
}
.sidebar-overlay.show { display: block; }

.main-wrapper {
  flex: 1;
  margin-right: var(--sidebar-w);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: margin var(--tr-slow);
  position: relative;
  overflow-x: hidden;
  background:
    radial-gradient(1100px 560px at 100% -8%, var(--primary-light), transparent 58%),
    radial-gradient(900px 480px at -5% 108%, var(--primary-light), transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
}

[data-lang="en"] .main-wrapper { margin-right: 0; margin-left: var(--sidebar-w); }

.sidebar.collapsed ~ .main-wrapper,
.main-wrapper.expanded { margin-right: var(--sidebar-collapsed); }
[data-lang="en"] .sidebar.collapsed ~ .main-wrapper,
[data-lang="en"] .main-wrapper.expanded { margin-right: 0; margin-left: var(--sidebar-collapsed); }

.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5);
  position: sticky;
  top: 0;
  z-index: var(--z-300);
  box-shadow: var(--sh-xs);
  overflow: visible;
}

.header-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.25rem;
  transition: background var(--tr), color var(--tr);
  flex-shrink: 0;
  touch-action: manipulation;
  cursor: pointer;
}
.header-toggle:hover { background: var(--surface-2); color: var(--text); }

.header-search {
  flex: 1;
  max-width: 420px;
  position: relative;
}

.header-right {
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}
[data-lang="en"] .header-right { margin-right: 0; margin-left: auto; }

.header-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.1rem;
  position: relative;
  transition: background var(--tr), color var(--tr);
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
}
.header-btn:hover { background: var(--surface-2); color: var(--text); }

.header-btn-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--danger);
  border: 2px solid var(--surface);
  display: none;
}
.header-btn-badge.has-notif { display: block; }

.header-lang {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--tr);
  white-space: nowrap;
  touch-action: manipulation;
  min-height: 36px;
}
.header-lang:hover { background: var(--surface-2); color: var(--text); }

.content-area {
  flex: 1;
  padding: clamp(var(--sp-4), 2.4vw, var(--sp-10));
  overflow-y: auto;
  overflow-x: hidden;
  background: transparent;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  -webkit-overflow-scrolling: touch;
}
.content-area::-webkit-scrollbar { width: 8px; }
.content-area::-webkit-scrollbar-track { background: transparent; }
.content-area::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
.content-area::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); background-clip: padding-box; }

.module-wrap {
  width: 100%;
  max-width: var(--content-max, 1600px);
  margin-inline: auto;
  animation: moduleIn var(--tr-slow) cubic-bezier(.16, .84, .44, 1) forwards;
}
@keyframes moduleIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: var(--sp-5);
}

.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--sh-sm);
  overflow: hidden;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.chart-title { font-size: var(--text-base); font-weight: 700; }

.chart-svg-wrap {
  width: 100%;
  height: 220px;
  position: relative;
  overflow: hidden;
}
.chart-svg-wrap svg { width: 100%; height: 100%; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  height: 180px;
  padding: 0 var(--sp-2);
  overflow: hidden;
}

.bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  height: 100%;
  justify-content: flex-end;
  min-width: 0;
}

.bar {
  width: 100%;
  min-height: 4px;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  background: var(--primary);
  opacity: .8;
  transition: opacity var(--tr), transform var(--tr);
  cursor: pointer;
  position: relative;
}
.bar:hover { opacity: 1; transform: scaleY(1.02); transform-origin: bottom; }
.bar.alt { background: linear-gradient(180deg, var(--blue-400), var(--blue-600)); }

.bar-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.activity-feed { display: flex; flex-direction: column; gap: 0; }

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--r-full);
  background: var(--primary);
  margin-top: 6px;
  flex-shrink: 0;
}

.activity-body { flex: 1; min-width: 0; }
.activity-title { font-size: var(--text-sm); font-weight: 500; }
.activity-time  { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

.module-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
  padding-bottom: var(--sp-4);
  gap: var(--sp-4);
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.module-title {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: clamp(var(--text-xl), 3vw, var(--text-2xl));
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.module-title::before {
  content: "";
  flex-shrink: 0;
  width: 5px;
  align-self: stretch;
  min-height: 1.4em;
  border-radius: var(--r-full);
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  box-shadow: 0 2px 8px -1px var(--primary-ring);
}

.module-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--sp-2);
  padding-inline-start: calc(5px + var(--sp-3));
}

.module-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.module-toolbar .search-wrap { min-width: 200px; flex: 1; }

.filter-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  transition: all var(--tr);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  min-height: 40px;
}
.filter-btn:hover  { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--r);
  width: 100%;
}

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

.table th, .table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th { font-weight: 600; background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--sh-sm);
  transition: box-shadow var(--tr), transform var(--tr);
  cursor: pointer;
}
.doc-card:hover { box-shadow: var(--sh-md); transform: translateY(-2px); }
.doc-number { font-size: var(--text-xs); color: var(--text-muted); }
.doc-title  { font-size: var(--text-base); font-weight: 700; margin: var(--sp-1) 0; }
.doc-amount { font-size: var(--text-xl); font-weight: 800; color: var(--primary); }

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: box-shadow var(--tr), transform var(--tr);
  cursor: pointer;
}
.product-card:hover { box-shadow: var(--sh-md); transform: translateY(-2px); }

.product-card-img {
  width: 100%;
  height: 160px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  border-bottom: 1px solid var(--border);
}

.product-card-body { padding: var(--sp-4); }
.product-name  { font-weight: 600; margin-bottom: var(--sp-1); }
.product-sku   { font-size: var(--text-xs); color: var(--text-muted); }
.product-price { font-size: var(--text-lg); font-weight: 800; color: var(--primary); margin-top: var(--sp-2); }

.stock-bar { margin-top: var(--sp-2); }
.stock-label { display: flex; justify-content: space-between; font-size: var(--text-xs); color: var(--text-muted); margin-bottom: 4px; }

.person-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  box-shadow: var(--sh-sm);
  transition: box-shadow var(--tr), transform var(--tr);
  cursor: pointer;
}
.person-card:hover { box-shadow: var(--sh-md); transform: translateY(-2px); }
.person-info { flex: 1; min-width: 0; }
.person-name  { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-meta  { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.person-actions { display: flex; gap: var(--sp-2); flex-shrink: 0; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-200, 500);
  background: rgba(0,0,0,.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: fadeIn .2s ease;
}
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: var(--text-lg); font-weight: 700; }
.modal-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--tr-fast);
  flex-shrink: 0;
  touch-action: manipulation;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5);
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.notif-panel {
  position: absolute;
  top: calc(var(--header-h) + 4px);
  left: var(--sp-5);
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-xl);
  z-index: var(--z-200);
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity var(--tr), transform var(--tr);
}
[dir="rtl"] .notif-panel { left: auto; right: var(--sp-5); }
.notif-panel.open { opacity: 1; transform: translateY(0); pointer-events: all; }

.notif-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--tr-fast);
  touch-action: manipulation;
}
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: var(--primary-light); }
[data-theme="dark"] .notif-item.unread { background: rgba(37,99,235,.12); }

.notif-icon { font-size: 1.5rem; flex-shrink: 0; }
.notif-body { flex: 1; min-width: 0; }
.notif-text { font-size: var(--text-sm); }
.notif-time { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: var(--sp-3);
}

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: all var(--tr);
  text-align: center;
  touch-action: manipulation;
  min-height: 72px;
}
.quick-action:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); transform: translateY(-2px); box-shadow: var(--sh); }
.quick-action-icon  { font-size: 1.75rem; }
.quick-action-label { font-size: var(--text-xs); font-weight: 600; }

.chart-legend { display: flex; flex-wrap: wrap; gap: var(--sp-4); margin-top: var(--sp-4); }
.legend-item  { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--text-xs); color: var(--text-muted); }
.legend-dot   { width: 10px; height: 10px; border-radius: var(--r-full); flex-shrink: 0; }

.sync-indicator {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-full);
  transition: background var(--tr);
}
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--success);
  animation: none;
  flex-shrink: 0;
}
.sync-indicator.syncing .sync-dot { background: var(--warning); animation: pulse 1s infinite; }
.sync-indicator.offline  .sync-dot { background: var(--danger); }

@media (max-width: 1280px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1024px) {
  html, body { overflow-x: hidden; }

  .sidebar {
    transform: translateX(100%);
    z-index: var(--z-300);
    box-shadow: var(--sh-xl);
    width: min(var(--sidebar-w), 80vw) !important;
  }
  [data-lang="en"] .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { width: min(var(--sidebar-w), 80vw) !important; }

  .main-wrapper { margin-right: 0 !important; margin-left: 0 !important; }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: calc(var(--z-300) - 1);
    display: none;
    touch-action: manipulation;
  }
  .sidebar-overlay.show { display: block; }

  .app-header { padding: 0 var(--sp-4); }
}

@media (max-width: 768px) {
  .content-area { padding: var(--sp-4); }

  .module-header { flex-direction: column; align-items: flex-start; }
  .module-header > div:last-child { width: 100%; flex-wrap: wrap; }
  .module-header .btn { min-height: 40px; }

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

  
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: 600px; }
  .table th, .table td { padding: var(--sp-2) var(--sp-3); }

  
  .settings-layout { grid-template-columns: 1fr !important; }
  .settings-sidebar {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: var(--sp-1) !important;
    flex-direction: row !important;
  }

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

  
  .notif-panel {
    width: calc(100vw - 32px);
    left: 16px;
    right: 16px;
    max-height: 70vh;
    overflow-y: auto;
  }
  [dir="rtl"] .notif-panel { left: 16px; right: 16px; }

  .app-header { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .header-lang { display: flex; padding: 4px 10px; font-size: var(--text-xs); }

  
  .modal, .modal-lg, .modal-xl { max-width: 94vw; }
}

@media (max-width: 480px) {
  html, body { overflow-x: hidden; }

  .content-area { padding: var(--sp-3); }

  .kpi-grid { gap: var(--sp-3); }

  .module-toolbar { flex-direction: column; align-items: stretch; }
  .module-toolbar .search-wrap { width: 100%; min-width: unset; }
  .module-toolbar select,
  .module-toolbar input[type="date"],
  .module-toolbar .filter-btn,
  .module-toolbar .btn { width: 100%; }

  .module-header { gap: var(--sp-3); }
  .module-header > div:last-child { display: flex; flex-direction: column; gap: var(--sp-2); }
  .module-header .btn { width: 100%; justify-content: center; }

  .module-title { font-size: var(--text-xl); }
  .kpi-value { font-size: var(--text-xl) !important; }

  #emp-cards-grid { grid-template-columns: 1fr !important; }
  .quick-actions { grid-template-columns: repeat(2, 1fr); }

  
  .form-grid  { grid-template-columns: 1fr !important; }
  .form-row, .form-row-3 { grid-template-columns: 1fr !important; }

  
  .tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: var(--sp-1); -webkit-overflow-scrolling: touch; }
  .tab-btn { flex-shrink: 0; }

  
  .modal,
  .modal-lg,
  .modal-xl {
    margin: var(--sp-3);
    width: calc(100vw - 24px);
    max-width: unset !important;
    border-radius: var(--r-lg);
    max-height: 92vh;
  }
  .modal-header { padding: var(--sp-4); }
  .modal-body   { padding: var(--sp-4); }
  .modal-footer { padding: var(--sp-4); flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; min-width: 110px; }

  
  .table { min-width: 520px; }

  
  .header-search { display: none; }
  #header-sync   { display: none; }

  
  .dashboard-grid { grid-template-columns: 1fr; gap: var(--sp-4); }

  
  .notif-panel {
    width: calc(100vw - 24px);
    left: 12px;
    right: 12px;
    max-height: 65vh;
  }
  [dir="rtl"] .notif-panel { left: 12px; right: 12px; }

  
  .chart-svg-wrap { height: 160px; }
  .bar-chart { height: 140px; }
}

@media (max-width: 360px) {
  .content-area { padding: var(--sp-2); }

  .quick-actions { grid-template-columns: 1fr 1fr; }

  .module-title { font-size: var(--text-lg); }

  .kpi-grid { gap: var(--sp-2); }

  .app-header { padding: 0 var(--sp-2); gap: var(--sp-1); }
  .header-toggle { width: 36px; height: 36px; }

  .modal,
  .modal-lg,
  .modal-xl { margin: var(--sp-2); width: calc(100vw - 16px); }

  .modal-header { padding: var(--sp-3); }
  .modal-body   { padding: var(--sp-3); }
  .modal-footer { padding: var(--sp-3); }

  
  .sidebar { width: 100vw !important; }

  
  .table { min-width: 460px; }

  
  .chart-box { padding: var(--sp-3); }
  .chart-svg-wrap { height: 140px; }
}

@media (max-width: 320px) {
  .content-area { padding: var(--sp-2); }
  .quick-actions { grid-template-columns: 1fr 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }

  .app-header { padding: 0 var(--sp-1); gap: 4px; }
  .header-btn { width: 34px; height: 34px; }

  .modal,
  .modal-lg,
  .modal-xl { margin: 4px; width: calc(100vw - 8px); }

  .module-toolbar .btn,
  .module-toolbar select { width: 100%; }
}

@media (max-width: 1024px) {
  html, body { overflow-x: hidden; }
  .main-wrapper { overflow-x: hidden; }
  .content-area { overflow-x: hidden; }
}
