/* ============================================================
   Reusable components
   ============================================================ */

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 42px;
  padding: 0 var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, transform .05s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: var(--cream-deep); }
.btn-danger { background: var(--surface); border-color: var(--brick-600); color: var(--brick-600); }
.btn-danger:hover { background: var(--brick-100); }
.btn-approve { background: var(--sage-600); color: #fff; }
.btn-approve:hover { background: var(--sage-700); }
.btn-sm { height: 34px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.btn-block { width: 100%; }
.btn-icon { width: 42px; padding: 0; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-5);
}
.card-title {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--wine-700);
  margin-bottom: var(--sp-4);
}

/* Stat tile: flat, distinguished by a colored edge, not a shadow */
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--gold-600);
  border-radius: var(--r-sm);
  padding: var(--sp-4) var(--sp-5);
}
.stat-tile.accent-wine { border-inline-start-color: var(--wine-700); }
.stat-tile.accent-sage { border-inline-start-color: var(--sage-600); }
.stat-tile.accent-rose { border-inline-start-color: var(--rose-500); }
.stat-tile-label { font-size: var(--fs-xs); color: var(--muted); margin-bottom: var(--sp-1); }
.stat-tile-value { font-size: var(--fs-2xl); font-weight: 700; color: var(--ink); }
.stat-tile-value .unit { font-size: var(--fs-sm); font-weight: 600; color: var(--muted); margin-inline-start: var(--sp-1); }
.stat-tile-sub { font-size: var(--fs-xs); color: var(--muted); margin-top: var(--sp-2); }

/* Urgent card — pending approvals, shift alerts */
.card-urgent {
  background: var(--rose-100);
  border: 1px solid var(--rose-300);
  border-radius: var(--r-md);
  padding: var(--sp-5);
}
.card-urgent .card-title { color: var(--wine-800); }

/* ---- Badges / status pills ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  height: 26px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pending { background: var(--color-pending-bg); color: #8B4A64; }
.badge-approved { background: var(--color-approved-bg); color: var(--sage-700); }
.badge-rejected { background: var(--color-danger-bg); color: var(--brick-700); }
.badge-cancelled { background: var(--cream-deep); color: var(--muted); }
.badge-surplus { background: var(--color-surplus-bg); color: var(--gold-700); }
.badge-neutral { background: var(--cream-deep); color: var(--muted); }

/* Count badge (nav / approvals counter) */
.count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--brick-600); color: #fff;
  font-size: 11px; font-weight: 700;
}

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.field-hint { font-size: var(--fs-xs); color: var(--muted); }
.input, .select, .textarea {
  height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface-raised);
  padding: 0 var(--sp-4);
  font-size: var(--fs-base);
  color: var(--ink);
  transition: border-color .15s ease;
  width: 100%;
}
.textarea { height: auto; min-height: 88px; padding: var(--sp-3) var(--sp-4); resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--wine-500); outline: none; }
.input::placeholder { color: var(--muted-2); }
.input-static {
  height: 46px; display: flex; align-items: center;
  padding: 0 var(--sp-4); border-radius: var(--r-sm);
  background: var(--cream-deep); color: var(--muted); font-size: var(--fs-base);
}

.pay-toggle { display: flex; gap: var(--sp-3); }
.pay-option {
  flex: 1; height: 52px; border: 1.5px solid var(--line-strong); border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  font-weight: 700; background: var(--surface-raised);
}
.pay-option.is-active { border-color: var(--wine-700); background: var(--wine-50); color: var(--wine-700); }

.checkbox-row { display: flex; align-items: center; gap: var(--sp-2); }
.switch { position: relative; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; background: var(--line-strong); border-radius: var(--r-pill);
  transition: background-color .15s ease; cursor: pointer;
}
.switch-track::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 3px; inset-inline-start: 3px; transition: inset-inline-start .15s ease;
  box-shadow: var(--shadow-sm);
}
.switch input:checked + .switch-track { background: var(--sage-600); }
.switch input:checked + .switch-track::after { inset-inline-start: 21px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); min-width: 640px; }
.table th {
  text-align: start;
  padding: var(--sp-3) var(--sp-4);
  background: var(--cream-deep);
  color: var(--muted);
  font-weight: 700;
  font-size: var(--fs-xs);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table td.num, .table th.num { text-align: end; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--wine-50); }
.table-row-pending { border-inline-start: 3px solid var(--rose-500); }
.table-row-rejected { opacity: .7; }
.table-empty { padding: var(--sp-10); text-align: center; color: var(--muted); }
.row-actions { display: flex; gap: var(--sp-2); }

/* ---- Nav / shell ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--wine-700);
  color: var(--wine-50);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
}
.sidebar-brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-5); }
.sidebar-brand img { width: 40px; height: 40px; border-radius: var(--r-sm); }
.sidebar-brand-name { font-family: var(--font-display-lat); font-size: var(--fs-lg); line-height: 1.1; }
html[lang="ar"] .sidebar-brand-name { font-family: var(--font-display-ar); }
.sidebar-brand-sub { font-size: 10px; letter-spacing: .08em; color: var(--rose-300); margin-top: 2px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--sp-2) var(--sp-3); display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--rose-100);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.is-active { background: var(--surface); color: var(--wine-700); }
.nav-item-icon { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item-badge { margin-inline-start: auto; }
.sidebar-foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid rgba(255,255,255,.12); font-size: var(--fs-xs); color: var(--rose-300); }

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--sp-6);
  background: var(--cream);
  flex-shrink: 0;
  gap: var(--sp-3);
}
.topbar-title {
  font-size: var(--fs-lg); font-weight: 700; color: var(--wine-700);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: var(--sp-3); flex-shrink: 0; }
.menu-toggle-btn { display: none; }

.sidebar-backdrop { display: none; }
.lang-switch { display: flex; gap: 2px; background: var(--cream-deep); border-radius: var(--r-pill); padding: 3px; }
.lang-switch button {
  border: none; background: transparent; padding: 6px 12px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 700; color: var(--muted);
}
.lang-switch button.is-active { background: var(--surface-raised); color: var(--wine-700); box-shadow: var(--shadow-sm); }
.user-chip { display: flex; align-items: center; gap: var(--sp-2); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--wine-100); color: var(--wine-700);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--fs-xs); flex-shrink: 0;
}
.user-chip-name { font-size: var(--fs-sm); font-weight: 700; }
.user-chip-role { font-size: var(--fs-xs); color: var(--muted); }

.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); display: flex; align-items: center; justify-content: center;
  position: relative;
}
.icon-btn .count-badge { position: absolute; top: -6px; inset-inline-end: -6px; }

/* Mobile bottom nav (employee, phone) */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; inset-inline: 0;
  height: var(--bottomnav-h);
  background: var(--surface-raised);
  border-top: 1px solid var(--line);
  align-items: stretch;
  z-index: 20;
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 700;
}
.bottom-nav-item.is-active { color: var(--wine-700); }
.bottom-nav-item svg { width: 22px; height: 22px; }
.bottom-nav-fab {
  width: 52px; height: 52px; border-radius: 50%; background: var(--wine-700); color: #fff;
  display: flex; align-items: center; justify-content: center;
  margin-top: -22px; box-shadow: var(--shadow-md);
}

/* ---- Divider with brand flourish ---- */
.hr-flourish { display: flex; align-items: center; gap: var(--sp-3); color: var(--gold-600); margin: var(--sp-6) 0; }
.hr-flourish::before, .hr-flourish::after { content: ''; flex: 1; height: 1px; background: var(--gold-300); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(42,27,32,.45);
  display: flex; align-items: center; justify-content: center; padding: var(--sp-5);
  z-index: 50;
}
.modal {
  background: var(--surface-raised); border-radius: var(--r-lg);
  padding: var(--sp-6); width: 100%; max-width: 480px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh; overflow-y: auto;
}
.modal-title { font-size: var(--fs-lg); font-weight: 700; color: var(--wine-700); margin-bottom: var(--sp-4); }
.modal-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-6); }
.modal-actions .btn { flex: 1; }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: var(--sp-12) var(--sp-6); color: var(--muted); }
.empty-state-icon { width: 56px; height: 56px; margin: 0 auto var(--sp-4); color: var(--rose-500); }
.empty-state-title { font-size: var(--fs-md); font-weight: 700; color: var(--ink); margin-bottom: var(--sp-2); }

/* ---- Toast ---- */
.toast-stack { position: fixed; bottom: var(--sp-6); inset-inline-end: var(--sp-6); z-index: 60; display: flex; flex-direction: column; gap: var(--sp-2); }
.toast {
  background: var(--wine-800); color: #fff; padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-sm); font-size: var(--fs-sm); box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: var(--sp-2);
}
.toast.toast-error { background: var(--brick-700); }

/* ---- Diff highlight for edited amounts ---- */
.edited-tag { font-size: var(--fs-xs); color: var(--gold-700); font-weight: 700; }
.edited-values { font-size: var(--fs-xs); color: var(--muted); }
.edited-values .old-val { text-decoration: line-through; }
.edited-values .new-val { color: var(--wine-700); font-weight: 700; }

/* Utility */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.text-muted { color: var(--muted); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.w-full { width: 100%; }
