:root {
  /* ---- Light theme (original palette) ---- */
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --text: #0F172A;
  --muted: #64748B;
  --border: #D9E2EC;

  --primary: #0057B8;
  --primary-hover: #00458F;
  --secondary: #FF7A00;
  --secondary-hover: #E56A00;
  --accent: #16A34A;
  --danger: #DC2626;

  --sidebar-bg: var(--surface);
  --sidebar-active: #E7F0FB;
  --shadow: rgba(15, 23, 42, 0.08);
  --menu-active-text: var(--primary);

  /* Fixed status colors (same in both themes) */
  --status-success: #22C55E;
  --status-warning: #F59E0B;
  --status-error: #EF4444;
  --status-info: #3B82F6;
}

body.dark-mode {
  --bg: #0F172A;
  --surface: #1E293B;
  --text: #F8FAFC;
  --muted: #CBD5E1;
  --border: #334155;

  --primary: #3B82F6;
  --primary-hover: #2563EB;
  --secondary: #FB923C;
  --accent: #22C55E;
  --danger: #EF4444;

  --sidebar-bg: var(--surface);
  --sidebar-active: rgba(59, 130, 246, 0.18);
  --shadow: rgba(0, 0, 0, 0.4);
  --menu-active-text: #93C5FD; /* light blue - readable on the blue-tinted dark active bg, unlike --primary */
  --secondary-hover: #F97316;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}

a { color: inherit; }

/* ---------- Modern scrollbar ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

*::-webkit-scrollbar-track { background: transparent; }

*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 20px;
}

*::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- Topbar ---------- */
.topbar {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text);
  padding: 4px 8px;
}

.topbar-logo {
  height: 48px;
  width: auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.theme-toggle {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  padding: 6px 12px;
  font-size: 1rem;
  color: var(--text);
}

/* Standalone toggle used on the login page */
.login-theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
}

/* ---------- Account circle + dropdown ---------- */
.account-circle-wrap {
  position: relative;
}

.account-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

/* Dropdown sits flush against the circle (no gap) so the hover chain
   never breaks while moving the pointer down into it. Visual breathing
   room comes from padding-top inside the menu, not from an external gap. */
.account-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 24px var(--shadow);
  min-width: 180px;
  overflow: hidden;
  padding-top: 6px;
  opacity: 0;
  visibility: hidden;
  transform: scaleY(0.85) translateY(-4px);
  transform-origin: top right;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
  z-index: 200;
}

.account-circle-wrap.open .account-dropdown,
.account-circle-wrap:hover .account-dropdown,
.account-circle-wrap:focus-within .account-dropdown {
  opacity: 1;
  visibility: visible;
  transform: scaleY(1) translateY(0);
  pointer-events: auto;
}

.account-dropdown a {
  display: block;
  padding: 10px 14px;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--text);
}

.account-dropdown a:hover {
  background: var(--sidebar-active);
}

.account-dropdown a.logout-link {
  color: var(--danger);
  border-top: 1px solid var(--border);
}

/* ---------- Topbar more (mobile) ---------- */
.topbar-desktop-items {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-more-wrap {
  position: relative;
  display: none;
}

.topbar-more-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.topbar-more-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 24px var(--shadow);
  min-width: 200px;
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: scaleY(0.85) translateY(-4px);
  transform-origin: top right;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topbar-more-wrap.open .topbar-more-dropdown,
.topbar-more-wrap:hover .topbar-more-dropdown,
.topbar-more-wrap:focus-within .topbar-more-dropdown {
  opacity: 1;
  visibility: visible;
  transform: scaleY(1) translateY(0);
  pointer-events: auto;
}

.topbar-more-dropdown .theme-toggle {
  width: 100%;
  border-radius: 8px;
  padding: 10px 14px;
  text-align: left;
  font-size: 0.9rem;
}

.topbar-more-dropdown .notification-wrap {
  position: static;
}

.topbar-more-dropdown .notification-btn {
  width: 100%;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  justify-content: flex-start;
}

.topbar-more-dropdown .notification-dropdown {
  position: fixed;
  left: 16px;
  right: 16px;
  top: auto;
  min-width: auto;
  width: auto;
}

.topbar-more-link {
  display: block;
  padding: 10px 14px;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--text);
  border-radius: 8px;
}

.topbar-more-link:hover {
  background: var(--sidebar-active);
}

.topbar-more-link--danger {
  color: var(--danger);
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 12px;
}

/* ---------- App shell (sidebar + main) ---------- */
.app-shell {
  min-height: calc(100vh - 64px);
}

.sidebar {
  position: fixed;
  top: 64px;
  left: 0;
  bottom: 0;
  width: 240px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 140;
}

.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-menu { flex: 1; }
.sidebar-menu > li { margin-bottom: 4px; }

.sidebar a.menu-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.92rem;
}

.sidebar a.menu-link:hover {
  background: var(--sidebar-active);
}

.sidebar a.menu-link.active {
  background: var(--sidebar-active);
  font-weight: 700;
  color: var(--menu-active-text);
  border-left: 3px solid var(--primary);
  padding-left: 9px; /* 12px base minus the 3px border, keeps text aligned */
}

.menu-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.menu-icon svg { width: 100%; height: 100%; }

.sidebar-logout {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 10px;
}

.sidebar-logout a.menu-link { color: var(--danger); }
.sidebar-logout a.menu-link:hover { background: rgba(220, 38, 38, 0.1); }

.main-content {
  margin-left: 240px;
  padding: 28px 24px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.page-header h1 { margin: 0; }

.page-header-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }

/* Summary stat cards (used on the CRM overview / schedules and the
   delivery settlement pages) */
.settle-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 16px 0 22px; }
.settle-stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: 0 2px 8px var(--shadow); }
.settle-stat .v { font-size: 1.45rem; font-weight: 800; line-height: 1.1; }
.settle-stat .l { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.settle-stat.due .v { color: var(--status-danger); }
.settle-stat.warn .v { color: var(--status-warning); }
.settle-stat.blue .v { color: var(--status-info); }
.settle-stat.done .v { color: var(--status-success); }

/* Filled action buttons (used for inline header actions like
   "View Sales" / "View Purchases") - solid fill, clear in both themes. */
.btn-action {
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  box-shadow: 0 2px 6px var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn-action:hover {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow);
}

.btn-action.btn-action-primary { background: var(--primary); }
.btn-action.btn-action-primary:hover { background: var(--primary-hover); }

.btn-action.btn-action-secondary { background: var(--secondary); }
.btn-action.btn-action-secondary:hover { background: var(--secondary-hover); }

.btn-action.btn-action-danger { background: var(--danger); }
.btn-action.btn-action-danger:hover { background: #B91C1C; }

/* ---------- Default / welcome (Home) view ---------- */
.welcome-view {
  min-height: calc(100vh - 64px - 56px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.welcome-view img.welcome-logo {
  width: 140px;
  height: auto;
  margin-bottom: 12px;
}

.welcome-view h1 {
  margin: 0 0 4px;
  font-size: 1.6rem;
  color: var(--primary);
}

.welcome-view p {
  margin: 2px 0;
  color: var(--muted);
}

.welcome-view .btn-login {
  margin-top: 20px;
  width: auto;
  padding: 10px 28px;
  text-decoration: none;
  display: inline-block;
}

/* ---------- Deliveryman view ---------- */
.delivery-view { padding: 24px; }

.delivery-view h1 { margin-bottom: 4px; }
.delivery-view .subtitle { color: var(--muted); margin-bottom: 20px; }

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 18px 16px 22px;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

.order-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px var(--shadow);
}

.order-card .order-top {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.order-card .order-id { font-weight: 700; }

.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(245, 158, 11, 0.18);
  color: var(--status-warning);
}

.status-pill.status-done {
  background: rgba(34, 197, 94, 0.18);
  color: var(--status-success);
}

.status-pill.status-pending {
  background: rgba(245, 158, 11, 0.18);
  color: var(--status-warning);
}

.order-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.order-actions button, .order-actions a {
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
}

.order-actions .btn-done {
  background: var(--status-success);
  color: #fff;
  border-color: var(--status-success);
}

.order-actions .btn-view {
  background: var(--status-info);
  color: #fff;
  border-color: var(--status-info);
}

.order-actions .btn-report {
  background: rgba(239, 68, 68, 0.12);
  color: var(--status-error);
  border-color: var(--status-error);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-size: 1.05rem;
}

.placeholder-box {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

/* ---------- Profile page ---------- */
.profile-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
}

.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 10px var(--shadow);
  padding: 28px 20px;
  text-align: center;
}

.profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 2.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}

.profile-card h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  color: var(--text);
}

.profile-card .profile-position {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.profile-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--sidebar-active);
  color: var(--primary);
  margin-bottom: 4px;
}

.profile-badge.status-active { background: rgba(34, 197, 94, 0.18); color: var(--status-success); }
.profile-badge.status-inactive { background: rgba(239, 68, 68, 0.12); color: var(--status-error); }

.profile-stats {
  display: flex;
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 14px;
}

.profile-stats > div {
  flex: 1;
  text-align: center;
}

.profile-stats .stat-value {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  display: block;
}

.profile-stats .stat-label {
  font-size: 0.75rem;
  color: var(--muted);
}

.profile-tabs-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 10px var(--shadow);
  overflow: hidden;
}

.profile-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.profile-tab-btn {
  padding: 14px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.profile-tab-btn:hover { color: var(--text); }

.profile-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.profile-tab-panel { display: none; padding: 22px; }
.profile-tab-panel.active { display: block; }

.info-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.info-list li {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.info-list li:last-child { border-bottom: none; }
.info-list .info-label { color: var(--muted); }
.info-list .info-value { color: var(--text); font-weight: 600; text-align: right; }

.profile-form .form-group { margin-bottom: 16px; }
.switch-row { display: flex; align-items: center; gap: 10px; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch-slider { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background 0.2s ease; pointer-events: none; }
.switch-slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.2s ease; box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25); }
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }
.switch-label { font-size: 0.88rem; font-weight: 600; color: var(--text); cursor: pointer; margin: 0; }

.profile-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.profile-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.profile-form select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}

.profile-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  resize: vertical;
  font-family: inherit;
}

.profile-form input:focus,
.profile-form select:focus,
.profile-form textarea:focus { outline: none; border-color: var(--primary); }

/* Plain in-field show/hide password button - used on login, Add Users,
   and anywhere else a password field appears. */
.password-wrapper {
  position: relative;
}

.password-wrapper input {
  padding-right: 44px;
}

.toggle-password {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 600;
  padding: 4px;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .hamburger { display: inline-block; }
  .topbar-desktop-items { display: none; }
  .topbar-more-wrap { display: block; }

  .sidebar {
    left: -260px;
    z-index: 150;
    transition: left 0.2s ease;
    box-shadow: 2px 0 12px var(--shadow);
  }

  .sidebar.open { left: 0; }

  .main-content { margin-left: 0; padding: 20px 14px; }

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

@media (max-width: 480px) {
  .order-actions { flex-direction: column; }
  .order-actions button, .order-actions a { width: 100%; text-align: center; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header-actions { width: 100%; }
  .page-header-actions .btn-action { flex: 1; justify-content: center; }
}

/* ---------- Logo backdrop chips ----------
   Your logo PNGs are fully transparent behind the artwork (checked: alpha
   is 0 at every corner and even at the center), and the navy ink they use
   is very close in darkness to the dark-mode background - so without a
   light backing, most of the logo (everything except the flame) nearly
   disappears in dark mode, and also loses contrast against the blue login
   gradient. A light chip behind the logo fixes this in every case; it's
   applied always (harmless in light mode, where it blends right in). */
.logo-chip {
  display: inline-flex;
  align-items: center;
  background: #FFFFFF;
  border-radius: 10px;
  padding: 5px 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.logo-chip-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #FFFFFF;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

/* ---------- Loading screen ---------- */
.site-loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 9999;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.site-loader.loader-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-flame-wrap {
  position: relative;
  width: 110px;
  height: 110px;
}

.loader-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.loader-ring circle {
  fill: none;
  stroke: var(--primary);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 220;
  stroke-dashoffset: 220;
  animation: loader-ring-draw 1.6s ease-in-out infinite;
}

.loader-flame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%) scale(0);
  animation: loader-flame-pop 1.6s ease-in-out infinite;
}

.loader-text {
  font-weight: 700;
  color: var(--text);
  font-size: 0.95rem;
  letter-spacing: 0.5px;
}

@keyframes loader-flame-pop {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  22%  { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  32%  { transform: translate(-50%, -50%) scale(0.92); }
  42%  { transform: translate(-50%, -50%) scale(1.05); }
  55%  { transform: translate(-50%, -50%) scale(1); }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes loader-ring-draw {
  0%   { stroke-dashoffset: 220; opacity: 0; }
  20%  { opacity: 1; }
  65%  { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: 0; opacity: 1; }
}

/* ---------- Toast notifications ---------- */
.toast-container {
  position: fixed;
  top: 78px; /* sits below the topbar */
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 340px;
  max-width: calc(100vw - 32px);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--status-info);
  border-radius: 10px;
  box-shadow: 0 8px 24px var(--shadow);
  padding: 12px 14px;
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast-visible { opacity: 1; transform: translateX(0); }
.toast-hiding { opacity: 0; transform: translateX(24px); }

.toast-success { border-left-color: var(--status-success); }
.toast-error { border-left-color: var(--status-error); }
.toast-warning { border-left-color: var(--status-warning); }
.toast-info { border-left-color: var(--status-info); }

.toast-icon { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.toast-icon svg { width: 100%; height: 100%; }

.toast-success .toast-icon { color: var(--status-success); }
.toast-error .toast-icon { color: var(--status-error); }
.toast-warning .toast-icon { color: var(--status-warning); }
.toast-info .toast-icon { color: var(--status-info); }

.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 700; font-size: 0.9rem; color: var(--text); }
.toast-message { font-size: 0.85rem; color: var(--muted); margin-top: 2px; white-space: pre-line; }

.toast-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
}

.toast-close:hover { color: var(--text); }

@media (max-width: 480px) {
  .toast-container {
    left: 16px;
    right: 16px;
    top: 72px;
    width: auto;
  }
}

/* ---------- Form validation feedback ---------- */
.form-group.has-error input,
.form-group.has-error select {
  border-color: var(--danger);
}

.field-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 5px;
}

.form-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.form-center .form-group,
.form-center .password-strength-wrap {
  width: 100%;
  max-width: 380px;
}

.form-center .password-section {
  width: 100%;
  max-width: 380px;
}

.form-center .btn-action {
  margin-top: 6px;
}

/* ---------- Password strength meter ---------- */
.password-strength-wrap {
  margin: -6px 0 16px;
  display: none;
}

.password-strength-wrap.visible { display: block; }

.password-strength-bar {
  height: 6px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 4px;
}

.password-strength-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  transition: width 0.2s ease, background 0.2s ease;
  background: var(--danger);
}

.password-strength-label {
  font-size: 0.78rem;
  color: var(--muted);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 5000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.modal-open {
  opacity: 1;
  visibility: visible;
}

.modal-box {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.94) translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.modal-open .modal-box {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; font-size: 1.1rem; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 22px; }

.modal-body .form-group input:disabled,
.modal-body .form-group select:disabled {
  background: var(--border);
  cursor: not-allowed;
  opacity: 0.7;
}

/* ---------- Custom confirmation dialog (showConfirmDialog in app.js) ---------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 6000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.confirm-overlay.open {
  opacity: 1;
  visibility: visible;
}

.confirm-box {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 400px;
  transform: scale(0.94) translateY(10px);
  transition: transform 0.2s ease;
}

.confirm-overlay.open .confirm-box {
  transform: scale(1) translateY(0);
}

.confirm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.confirm-header h3 { margin: 0; font-size: 1.05rem; }

.confirm-body { padding: 20px; }

.confirm-message {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-line;
}

.confirm-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ---------- Notification bell ---------- */
.notification-wrap { position: relative; }

.notification-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  position: relative;
}

.notification-btn svg { width: 19px; height: 19px; }

.notification-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  display: none; /* toggled on when there are unread notifications */
}

.notification-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 24px var(--shadow);
  width: 280px;
  max-width: calc(100vw - 32px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
  z-index: 200;
}

.notification-wrap.open .notification-dropdown,
.notification-wrap:focus-within .notification-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.notification-dropdown-header {
  padding: 12px 14px;
  font-weight: 700;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
}

.notification-empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.notification-list {
  max-height: 340px;
  overflow-y: auto;
}

.notification-item {
  display: block;
  padding: 10px 14px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.4;
  border-bottom: 1px solid var(--border);
}

.notification-item:hover {
  background: var(--bg);
}

.notification-item:last-child {
  border-bottom: none;
}

.notification-item-msg {
  display: block;
  white-space: normal;
}

.notification-item-time {
  display: block;
  margin-top: 2px;
  font-size: 0.7rem;
  color: var(--muted);
}

/* ---------- Data table (Users list, etc.) ---------- */
.data-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  box-shadow: 0 2px 10px var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--sidebar-active); }

.table-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.76rem;
  font-weight: 700;
}

.table-badge.status-active { background: rgba(34, 197, 94, 0.15); color: var(--status-success); }
.table-badge.status-inactive { background: rgba(239, 68, 68, 0.12); color: var(--status-error); }
.table-badge.status-nologin { background: rgba(148, 163, 184, 0.18); color: var(--muted); }

.btn-edit-row {
  padding: 6px 14px;
  border-radius: 7px;
  border: 1px solid var(--primary);
  background: none;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-edit-row:hover { background: var(--sidebar-active); }

a.btn-edit-row { text-decoration: none; display: inline-block; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: flex-end;
}

.filter-bar > form { display: contents; }

.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }

.filter-group select,
.filter-group input[type="month"],
.filter-group input[type="date"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.87rem;
  cursor: pointer;
  color-scheme: light;
}

/* ---------------------------------------------------------------------
   Shared AJAX-search affordances
   --------------------------------------------------------------------- */
/* Wraps a .search-input so a spinner can sit inside its right edge. The input
   itself reuses the shared .search-input class rather than being restyled
   here; the only extra rule is right padding, to leave room for the spinner.
   The .dues-* names are the same rules under their original selectors. */
.search-wrap,
.dues-search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap .search-input,
.dues-search-wrap .search-input { padding-right: 34px; }

.search-spinner,
.dues-search-spinner {
  position: absolute;
  right: 11px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: search-spin 0.7s linear infinite;
  pointer-events: none;
}
.search-spinner[hidden],
.dues-search-spinner[hidden] { display: none; }
@keyframes search-spin { to { transform: rotate(360deg); } }
/* @keyframes dues-spin kept: referenced by any stylesheet cached from before
   this was shared. Both names animate identically. */
@keyframes dues-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .search-spinner,
  .dues-search-spinner { animation-duration: 2.4s; }
}

/* The region swapped by the AJAX filter dims slightly while it reloads. */
.search-results { transition: opacity 0.15s ease; }

.search-group { flex: 1; min-width: 220px; }

/* ---------------------------------------------------------------------
   Customer Dues page
   --------------------------------------------------------------------- */
.dues-filter-actions { flex-direction: row; align-items: center; gap: 8px; }

#duesResults { transition: opacity 0.15s ease; }

/* Card header: title + count on one line, matching the other list pages. */
.dues-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.dues-card-head h3 { margin: 0; font-size: 1.05rem; }
.dues-card-meta { color: var(--muted); font-size: 0.85rem; }

.dues-table-wrap { border: none; }

/* Breathing room between the Outstanding and Collected History cards. */
.dues-sections > .profile-tabs-card + .profile-tabs-card { margin-top: 24px; }

/* Money and counts read better right-aligned; keep dates/buttons on one line. */
.dues-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dues-amount { font-weight: 700; }
.dues-nowrap { white-space: nowrap; }

/* Compact buttons so a 10-column table still fits without a scrollbar. */
.btn-action.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  line-height: 1.2;
}

.filter-group input[type="month"],
.filter-group input[type="date"] {
  font-family: inherit;
}

.search-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.search-input:focus { outline: none; border-color: var(--primary); }

/* ---------- Searchable select (for any field linked to another table's
   ID/Name - Product, Customer, Supplier, Deliveryman, etc). Enforces
   "list only": blurring without a matching selection clears the field. */
.searchable-select {
  position: relative;
}

.searchable-select-input {
  width: 100%;
  padding: 10px 12px;
  padding-right: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.searchable-select-input:focus { outline: none; border-color: var(--primary); }

.searchable-select-clear {
  display: none;
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--muted);
  color: var(--surface);
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  z-index: 1;
}
.searchable-select-clear:hover { background: var(--danger); }
.searchable-select-clear.visible { display: block; }

.searchable-select-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 20px var(--shadow);
  z-index: 50;
}

.searchable-select-dropdown.open { display: block; }

.searchable-select-option {
  padding: 9px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text);
}

.searchable-select-option:hover { background: var(--sidebar-active); }

.searchable-select-empty {
  padding: 9px 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

@media (max-width: 700px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.page-link {
  padding: 7px 13px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  text-decoration: none;
}

.page-link:hover { background: var(--sidebar-active); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }

/* ---------- Dual scrollbar (top + bottom) for wide tables ----------
   The bottom scrollbar is the wrapper's own native overflow-x (either
   .data-table-wrap or .data-table-scroll injected by app.js for bare
   tables like dashboard/ledger cards). The top one is a synced phantom
   strip injected by app.js. Hidden when the table doesn't overflow. */
.data-table-top-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  height: 14px;
  margin-bottom: 6px;
}

.data-table-top-scroll > div {
  height: 1px;
}

.data-table-top-scroll-hidden {
  display: none;
}

/* Scroll container for tables not already inside .data-table-wrap. */
.data-table-scroll {
  overflow-x: auto;
}

/* ---------- Suggested Customer ID ---------- */
.cust-id-suggestion {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.cust-id-suggestion-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px dashed var(--primary);
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.cust-id-suggestion-btn:hover {
  background: var(--primary);
  border-style: solid;
  color: #fff;
  transform: translateY(-1px);
}

.cust-id-suggestion-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.ledger-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.ledger-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 2px 10px var(--shadow);
}

.ledger-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 12px;
}

.ledger-card .card-period {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}

.ledger-card .card-period:last-child {
  border-bottom: none;
}

.ledger-card .period-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.ledger-card .period-value {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}

.ledger-rows-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 10px var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}

.ledger-rows-card .ledger-rows-head {
  padding: 14px 18px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.ledger-rows-card table.data-table {
  border: none;
  box-shadow: none;
  margin: 0;
}

/* ---------- Dashboard ---------- */
.dash-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

.dash-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 2px 10px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dash-stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}

.dash-stat-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dash-stat-sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.dash-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin: 26px 0 12px;
}

.dash-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.dash-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  box-shadow: 0 2px 6px var(--shadow);
}

.dash-chip strong {
  font-size: 1.05rem;
  color: var(--text);
}

.low-stock {
  color: var(--danger);
  font-weight: 700;
}

.dash-muted { color: var(--muted); }
