:root {
  --primary: #6F4E37;
  --primary-dark: #4a3324;
  --accent: #C08552;
  --bg: #F5F1EC;
  --card: #ffffff;
  --text: #2d2521;
  --muted: #8b7d72;
  --danger: #e74c3c;
  --warning: #f39c12;
  --success: #27ae60;
  --border: #e5ddd4;
  --radius: 12px;
  --navbar-h: 65px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ============ تسجيل دخول ============ */
.login-body {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  padding: 20px;
}
.login-card {
  background: #fff; padding: 40px 30px; border-radius: 20px;
  width: 100%; max-width: 400px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo { font-size: 60px; margin-bottom: 10px; }
.login-card h1 { font-size: 22px; margin-bottom: 8px; }
.login-card input {
  width: 100%; padding: 14px; margin: 10px 0;
  border: 2px solid var(--border); border-radius: 10px;
  font-size: 15px; transition: .2s;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.login-card button {
  width: 100%; padding: 14px; margin-top: 10px;
  background: var(--primary); color: #fff; border: none;
  border-radius: 10px; font-size: 16px; cursor: pointer; transition: .2s;
}
.login-card button:hover { background: var(--primary-dark); }
.login-card button:disabled { opacity: .6; cursor: not-allowed; }
.muted { color: var(--muted); font-size: 14px; margin-bottom: 15px; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 20px; }

/* ============ Navbar ============ */
.navbar {
  background: var(--primary);
  color: #fff;
  padding: 0 30px;
  display: flex; align-items: center; gap: 20px;
  height: var(--navbar-h);
  box-shadow: 0 2px 10px rgba(0,0,0,.1);
  position: sticky; top: 0; z-index: 100;
}
.brand { font-weight: bold; font-size: 18px; white-space: nowrap; }
.nav-links { display: flex; gap: 3px; flex: 1; flex-wrap: nowrap; overflow-x: auto; }
.nav-links a {
  color: #fff; text-decoration: none; padding: 9px 12px;
  border-radius: 8px; font-size: 13.5px; transition: .2s;
  white-space: nowrap;
}
.nav-links a:hover { background: rgba(255,255,255,.15); }
.nav-links a.active { background: rgba(255,255,255,.25); font-weight: bold; }
.logout-btn {
  background: rgba(255,255,255,.2); color: #fff;
  border: none; padding: 8px 16px; border-radius: 8px;
  cursor: pointer; font-size: 13.5px; white-space: nowrap;
}
.logout-btn:hover { background: rgba(255,255,255,.3); }

.menu-toggle {
  display: none;
  background: rgba(255,255,255,.2); color: #fff; border: none;
  font-size: 22px; width: 42px; height: 42px;
  border-radius: 8px; cursor: pointer;
}

/* ============ Sidebar (جوال) ============ */
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 998; opacity: 0; visibility: hidden;
  transition: .3s;
}
.sidebar-overlay.show { opacity: 1; visibility: visible; }

.sidebar {
  position: fixed; top: 0; right: -300px;
  width: 280px; height: 100vh;
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  color: #fff; z-index: 999;
  transition: right .3s ease;
  display: flex; flex-direction: column;
  box-shadow: -5px 0 20px rgba(0,0,0,.3);
}
.sidebar.show { right: 0; }
.sidebar-header {
  padding: 25px 20px; border-bottom: 1px solid rgba(255,255,255,.15);
  display: flex; justify-content: space-between; align-items: center;
}
.sidebar-header h2 { font-size: 18px; }
.sidebar-close {
  background: none; border: none; color: #fff;
  font-size: 26px; cursor: pointer; padding: 0 5px;
}
.sidebar-links {
  flex: 1; padding: 15px 0; overflow-y: auto;
}
.sidebar-links a {
  display: flex; align-items: center; gap: 12px;
  color: #fff; text-decoration: none;
  padding: 15px 22px; font-size: 15px;
  border-right: 4px solid transparent;
  transition: .2s;
}
.sidebar-links a:hover { background: rgba(255,255,255,.1); }
.sidebar-links a.active {
  background: rgba(255,255,255,.15);
  border-right-color: var(--accent);
  font-weight: bold;
}
.sidebar-footer {
  padding: 20px; border-top: 1px solid rgba(255,255,255,.15);
}
.sidebar-footer button {
  width: 100%; background: rgba(255,255,255,.15); color: #fff;
  border: none; padding: 12px; border-radius: 10px;
  cursor: pointer; font-size: 15px; font-weight: 600;
}
.sidebar-footer button:hover { background: rgba(255,255,255,.25); }

/* ============ Container ============ */
.container { max-width: 1300px; margin: 0 auto; padding: 30px; }
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 25px; flex-wrap: wrap; gap: 12px;
}
h1 { font-size: 26px; color: var(--primary-dark); }

/* ============ Stats ============ */
.stats-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-bottom: 30px;
}
.stat-card {
  background: var(--card); padding: 22px; border-radius: var(--radius);
  display: flex; gap: 15px; align-items: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
  border-right: 5px solid var(--primary);
}
.stat-card.danger { border-right-color: var(--danger); }
.stat-card.warning { border-right-color: var(--warning); }
.stat-icon { font-size: 32px; }
.stat-info { display: flex; flex-direction: column; }
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.stat-value { font-size: 26px; font-weight: bold; color: var(--primary-dark); }

/* ============ Alert banner ============ */
.alert-banner {
  width: 100%; padding: 22px 30px;
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: #fff; border: none; border-radius: var(--radius);
  cursor: pointer; display: flex; align-items: center; gap: 18px;
  font-size: 17px; font-weight: bold;
  box-shadow: 0 8px 25px rgba(231,76,60,.35);
  transition: .3s;
  animation: pulse 2s infinite;
}
.alert-banner:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(231,76,60,.5); }
.alert-banner.ok {
  background: linear-gradient(135deg, #27ae60, #1e8449);
  box-shadow: 0 8px 25px rgba(39,174,96,.35);
  animation: none;
}
.alert-banner > span:first-child { font-size: 30px; }
.alert-banner .arrow { margin-right: auto; opacity: .85; font-size: 14px; font-weight: normal; }

@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.01); }
}

/* ============ Tables ============ */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
  background: var(--card);
}
.data-table {
  width: 100%; background: var(--card);
  border-collapse: collapse;
  min-width: 600px;
}
.data-table.compact th, .data-table.compact td { padding: 8px 12px; font-size: 13px; }
.data-table th {
  background: var(--primary); color: #fff; text-align: right;
  padding: 14px; font-size: 14px; white-space: nowrap;
}
.data-table td { padding: 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: #faf6f2; }
.row-danger { background: #fdedec !important; }
.row-warning { background: #fef5e7 !important; }

.user-cell {
  font-size: 12px;
  color: var(--muted);
}
.user-cell strong { color: var(--primary-dark); display: block; }

/* ============ Buttons ============ */
.btn-primary {
  background: var(--primary); color: #fff; border: none;
  padding: 12px 22px; border-radius: 10px; cursor: pointer;
  font-size: 15px; font-weight: 600; transition: .2s;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary {
  background: #eee; color: var(--text); border: none;
  padding: 12px 22px; border-radius: 10px; cursor: pointer;
  font-size: 15px; font-weight: 600;
}
.btn-secondary:hover { background: #ddd; }
.btn-danger {
  background: var(--danger); color: #fff; border: none;
  padding: 12px 22px; border-radius: 10px; cursor: pointer;
  font-size: 15px; font-weight: 600;
}
.btn-danger:hover { background: #c0392b; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  font-size: 18px; padding: 6px 10px; border-radius: 6px;
}
.btn-icon:hover { background: #f0e8e0; }
.btn-icon.danger:hover { background: #fdedec; }

/* ============ Badges ============ */
.badge {
  padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-success { background: #d4efdf; color: #1e8449; }
.badge-warning { background: #fdebd0; color: #b9770e; }
.badge-danger { background: #fadbd8; color: #a93226; }
.badge-info { background: #d6eaf8; color: #2874a6; }

/* ============ Search ============ */
.search-bar { margin-bottom: 20px; }
.search-bar input {
  width: 100%; max-width: 400px; padding: 12px 18px;
  border: 2px solid var(--border); border-radius: 10px; font-size: 15px;
}
.search-bar input:focus { outline: none; border-color: var(--primary); }

/* ============ Modal ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 15px;
  backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px;
  width: 100%; max-width: 520px;
  max-height: 92vh; overflow-y: auto;
  animation: slideUp .3s;
}
.modal-large { max-width: 900px; }
.modal-small { max-width: 400px; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 25px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: #fff; z-index: 2;
  border-radius: 16px 16px 0 0;
}
.modal-header h2 { font-size: 19px; color: var(--primary-dark); }
.close-btn {
  background: none; border: none; font-size: 22px;
  cursor: pointer; color: var(--muted); padding: 0 5px;
}
.modal-body { padding: 25px; }
.modal-body label {
  display: block; margin: 12px 0 6px;
  font-size: 14px; font-weight: 600; color: var(--text);
}
.modal-body input, .modal-body select, .modal-body textarea {
  width: 100%; padding: 11px 14px;
  border: 2px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; transition: .2s;
  background: #fff;
}
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus {
  outline: none; border-color: var(--primary);
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 25px; padding-top: 20px; border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* ============ Product search ============ */
.product-search-wrapper { position: relative; }
.product-results {
  display: none; position: absolute; top: 100%; left: 0; right: 0;
  background: #fff; border: 2px solid var(--primary);
  border-radius: 10px; margin-top: 5px; max-height: 320px; overflow-y: auto;
  z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.15);
}
.product-results.show { display: block; }
.result-item {
  padding: 12px 16px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border); transition: .15s;
  gap: 10px;
}
.result-item:hover { background: #faf6f2; }
.result-item:last-child { border-bottom: none; }
.result-item strong { display: block; font-size: 14px; }
.result-item small { color: var(--muted); font-size: 12px; }
.qty-badge {
  background: #f0e8e0; padding: 4px 10px;
  border-radius: 20px; font-size: 12px; color: var(--primary-dark);
  white-space: nowrap;
}
.result-empty { padding: 20px; text-align: center; color: var(--muted); }

.section-title {
  margin: 25px 0 12px; font-size: 16px; color: var(--primary-dark);
}

/* ============ Alert tabs ============ */
.alert-tabs {
  display: flex; gap: 10px; margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
}
.alert-tabs .tab {
  background: none; border: none; padding: 12px 20px;
  cursor: pointer; font-size: 15px; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent;
  margin-bottom: -2px; transition: .2s; white-space: nowrap;
}
.alert-tabs .tab.active {
  color: var(--primary-dark); border-bottom-color: var(--primary);
}

/* ============ Empty state ============ */
.empty-state {
  text-align: center !important; color: var(--muted);
  padding: 40px 20px !important; font-size: 15px;
}

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: 30px; left: 50%;
  transform: translateX(-50%);
  background: var(--success); color: #fff;
  padding: 14px 26px; border-radius: 10px;
  box-shadow: 0 8px 25px rgba(0,0,0,.2);
  z-index: 2000; animation: slideUp .3s;
  font-weight: 600; max-width: 90vw;
}
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }

/* ============ Print ============ */
.print-body { background: #fff; }
.print-header { margin-bottom: 30px; padding-bottom: 20px; border-bottom: 3px double var(--primary); }
.print-header h1 { margin-bottom: 20px; }
.print-meta {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; font-size: 14px;
}
.print-notes {
  margin-top: 25px; padding: 15px;
  background: #faf6f2; border-radius: 10px; font-size: 14px;
}
.print-signatures {
  display: flex; justify-content: space-between;
  margin-top: 60px; font-size: 15px; gap: 20px;
}

/* ============ Responsive ============ */
@media (max-width: 1200px) {
  .navbar { padding: 0 20px; gap: 15px; }
  .nav-links a { padding: 8px 10px; font-size: 13px; }
  .brand { font-size: 16px; }
}

@media (max-width: 1000px) {
  .nav-links a { padding: 8px 8px; font-size: 12.5px; }
}

@media (max-width: 900px) {
  .navbar { padding: 0 15px; gap: 12px; }
  .nav-links { display: none; }
  .menu-toggle { display: block; }
  .brand { flex: 1; }

  .container { padding: 15px; }
  .row-2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card { padding: 15px; gap: 10px; }
  .stat-icon { font-size: 24px; }
  .stat-value { font-size: 20px; }
  .stat-label { font-size: 11px; }

  h1 { font-size: 20px; }
  .alert-banner { padding: 16px 20px; font-size: 14px; gap: 12px; }
  .alert-banner > span:first-child { font-size: 22px; }
  .alert-banner .arrow { display: none; }

  .modal-body { padding: 18px; }
  .modal-header { padding: 15px 18px; }
  .modal-header h2 { font-size: 17px; }

  .btn-primary, .btn-secondary, .btn-danger {
    padding: 10px 16px; font-size: 14px;
  }

  .print-meta { grid-template-columns: 1fr; }
  .print-signatures { flex-direction: column; gap: 30px; margin-top: 40px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .btn-primary { width: 100%; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
}