:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #334155;
  --primary: #3b82f6;
  --primary-dark: #60a5fa;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #f87171;
  color-scheme: dark;
}

:root[data-theme="dark"] .topbar nav a.active,
:root[data-theme="dark"] .topbar nav a:hover {
  background: #1e3a8a33;
}

:root[data-theme="dark"] .badge-warning { background: #78350f; }
:root[data-theme="dark"] .badge-danger { background: #7f1d1d; }
:root[data-theme="dark"] .badge-success { background: #14532d; }
:root[data-theme="dark"] .badge-muted { background: #1e293b; }

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 10px;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary-dark);
  flex-shrink: 0;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 1rem;
}

.hamburger-btn {
  display: none;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text);
}

.topbar nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}

.topbar nav a {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 600;
}

.topbar nav a.active,
.topbar nav a:hover {
  background: #eff4ff;
  color: var(--primary-dark);
}

.topbar .user-area {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--muted);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eef1f5; color: var(--text); }
.btn-secondary:hover { background: #e2e6eb; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

@media (max-width: 900px) {
  .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .grid-4, .grid-3 { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.stat-card .label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-card .sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 28px 0 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.9rem;
}

th {
  background: #fafbfc;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
}

tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-warning { background: #fef3c7; color: var(--warning); }
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-success { background: #dcfce7; color: var(--success); }
.badge-muted { background: #f1f5f9; color: var(--muted); }

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

.toolbar .filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

input, select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tabs button {
  border: 1px solid var(--border);
  background: var(--card);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
}

.tabs button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 { margin-top: 0; }

.field {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.field input, .field select, .field textarea { width: 100%; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2563eb, #1e3a8a);
}

.login-card {
  background: white;
  padding: 36px;
  border-radius: 14px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.login-card h1 {
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.login-card p.sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0;
  margin-bottom: 20px;
}

.error-msg {
  background: #fee2e2;
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 12px;
  display: none;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 14px;
  text-align: center;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: #eef1f5;
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar .fill {
  height: 100%;
  background: var(--success);
}

/* ---------------------------------------------------------------------- */
/* Toast notifications                                                     */
/* ---------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  max-width: calc(100vw - 40px);
}

.toast {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  font-size: 0.88rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: var(--success); }
.toast-danger { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--warning); }

.toast-undo-btn {
  border: none;
  background: none;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
}

/* ---------------------------------------------------------------------- */
/* Responsive / mobile                                                     */
/* ---------------------------------------------------------------------- */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius);
}

.table-wrapper table { min-width: 640px; }

@media (max-width: 780px) {
  .hamburger-btn { display: block; }

  .topbar nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 8px;
    gap: 2px;
  }

  .topbar nav.open { display: flex; }
  .topbar nav a { padding: 12px 14px; }

  .container { padding: 14px; }
  .section-title { font-size: 1rem; }

  .modal { max-width: 100%; margin: 0 8px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .filters { width: 100%; }
  .toolbar input, .toolbar select { width: 100%; }

  .btn { padding: 11px 16px; }

  .toast-container { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}
/* Bulletproof override for Quick Links buttons */
html body :not(.modal) .card.stat-card a.btn.btn-secondary,
html body :not(.modal) .card.stat-card a.btn.btn-secondary:visited {
    background-color: #ffffff !important;
    color: #000000 !important;
    border-color: #d1d5db !important;
    box-shadow: none !important;
}

html body :not(.modal) .card.stat-card a.btn.btn-secondary:hover {
    background-color: #f3f4f6 !important;
    color: #000000 !important;
}

/* ---------------------------------------------------------------------- */
/* Inline quantity stepper (inventory table)                               */
/* ---------------------------------------------------------------------- */
.qty-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.qty-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }
.qty-btn:active { transform: scale(0.92); }

.qty-value {
  min-width: 60px;
  text-align: center;
  font-weight: 600;
  font-size: 0.88rem;
}