/* ============================================================
   RepairFlow — Design System v2
   Palette :
     Sidebar    : #0f172a / #1e293b
     Primary    : var(--color-primary)
     Success    : #16a34a
     Danger     : #dc2626
     Warning    : #d97706
     Surface    : #f8fafc
     Border     : #e2e8f0
   ============================================================ */

/* ----------------------------------------------------------
   1. Reset & Base
   ---------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
ul, ol { list-style: none; }

/* ----------------------------------------------------------
   2. App Shell — Sidebar + Content
   ---------------------------------------------------------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 200;
  transition: transform 0.25s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

.brand-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -0.02em;
}

.brand-tagline {
  font-size: 0.7rem;
  color: #475569;
  font-weight: 400;
  display: block;
  line-height: 1;
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
}

.sidebar-section-label {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #475569;
  padding: 0.75rem 1.25rem 0.35rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #94a3b8;
  text-decoration: none;
  border-radius: 0;
  transition: background 0.12s, color 0.12s;
  position: relative;
  margin: 1px 0;
}

.sidebar-nav a:hover {
  background: #1e293b;
  color: #e2e8f0;
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--color-primary);
  color: #ffffff;
}

.sidebar-nav a.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  width: 3px;
  background: #60a5fa;
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  border-top: 1px solid #1e293b;
  padding: 1rem 1.25rem;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.8125rem;
  color: #cbd5e1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  width: 100%;
  background: transparent;
  border: 1px solid #334155;
  color: #64748b;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-logout:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

/* ---------- Mobile: hamburger ---------- */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 300;
  background: #0f172a;
  border: none;
  color: #f8fafc;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 1.25rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 150;
}

/* ---------- Main wrapper ---------- */
.main-wrapper {
  flex: 1;
  margin-left: 240px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ----------------------------------------------------------
   3. Top bar (optional page header strip)
   ---------------------------------------------------------- */
.topbar {
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  padding: 0 2rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #0f172a;
}

/* ----------------------------------------------------------
   4. Page content
   ---------------------------------------------------------- */
.page-content {
  flex: 1;
  padding: 2rem;
}

/* ----------------------------------------------------------
   5. Containers
   ---------------------------------------------------------- */
.container    { width: 100%; }
.container-md { width: 100%; max-width: 900px;  margin: 0 auto; }
.container-sm { width: 100%; max-width: 600px;  margin: 0 auto; }

/* ----------------------------------------------------------
   6. Page header
   ---------------------------------------------------------- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.2;
}

.page-subtitle {
  font-size: 0.875rem;
  color: #64748b;
  margin-top: 0.2rem;
  font-weight: 400;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ----------------------------------------------------------
   7. Auth pages
   ---------------------------------------------------------- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  padding: 2rem 1rem;
}

.auth-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35);
  padding: 2.75rem 2.25rem;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-logo-icon {
  font-size: 2.5rem;
  line-height: 1;
  display: block;
  margin-bottom: 0.4rem;
}

.auth-logo-name {
  font-size: 1.25rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.02em;
}

.auth-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
  text-align: center;
  margin-bottom: 0.25rem;
}

.auth-subtitle {
  font-size: 0.875rem;
  color: #64748b;
  text-align: center;
  margin-bottom: 1.75rem;
}

.auth-form .form-group { margin-bottom: 1rem; }

.auth-link {
  display: block;
  text-align: center;
  font-size: 0.875rem;
  color: #64748b;
  margin-top: 1.25rem;
}

.auth-link a { color: var(--color-primary); font-weight: 500; }

/* ----------------------------------------------------------
   8. Cards
   ---------------------------------------------------------- */
.card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.03);
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.card:last-child { margin-bottom: 0; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #f1f5f9;
  background: #fafafa;
  gap: 0.75rem;
}

.card-header h2, .card-header h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #0f172a;
}

.card-body { padding: 1.25rem; }

/* ----------------------------------------------------------
   9. Stats grid — Dashboard
   ---------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  padding: 1.25rem 1.25rem 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}

.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.stat-ca::after       { background: linear-gradient(90deg, var(--color-primary), #60a5fa); }
.stat-profit::after   { background: linear-gradient(90deg, #16a34a, #4ade80); }
.stat-expenses::after { background: linear-gradient(90deg, #dc2626, #f87171); }
.stat-invoices::after { background: linear-gradient(90deg, #d97706, #fbbf24); }

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.stat-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.stat-ca       .stat-icon { background: #dbeafe; }
.stat-profit   .stat-icon { background: #dcfce7; }
.stat-expenses .stat-icon { background: #fee2e2; }
.stat-invoices .stat-icon { background: #fef3c7; }

.stat-value {
  font-size: 1.625rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.stat-ca       .stat-value { color: color-mix(in srgb, var(--color-primary) 85%, #000); }
.stat-profit   .stat-value { color: #15803d; }
.stat-expenses .stat-value { color: #dc2626; }
.stat-invoices .stat-value { color: #b45309; }

.stat-footer {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-top: 0.4rem;
}

/* Dashboard grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 1.25rem;
}

/* ----------------------------------------------------------
   10. Buttons
   ---------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  padding: 0.5rem 1rem;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s,
    box-shadow 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  user-select: none;
  position: relative;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(var(--color-primary-rgb),0.3);
}
.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-primary) 85%, #000);
  border-color: color-mix(in srgb, var(--color-primary) 85%, #000);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 3px 8px rgba(var(--color-primary-rgb),0.35);
}

.btn-success {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
  box-shadow: 0 1px 3px rgba(22,163,74,0.3);
}
.btn-success:hover:not(:disabled) {
  background: #15803d;
  border-color: #15803d;
  color: #fff;
  text-decoration: none;
}

.btn-danger {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
  text-decoration: none;
}

.btn-outline {
  background: transparent;
  border-color: #d1d5db;
  color: #374151;
}
.btn-outline:hover:not(:disabled) {
  background: #f9fafb;
  border-color: #9ca3af;
  color: #111827;
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: #6b7280;
}
.btn-ghost:hover:not(:disabled) {
  background: #f3f4f6;
  color: #1f2937;
  text-decoration: none;
}

.btn-sm  { font-size: 0.8125rem; padding: 0.3rem 0.65rem; border-radius: 5px; }
.btn-lg  { font-size: 1rem; padding: 0.75rem 1.5rem; border-radius: 8px; font-weight: 600; }
.btn-block { width: 100%; }

.btn-loading::after {
  content: '';
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 0.35rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------
   11. Forms
   ---------------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #374151;
  letter-spacing: 0.01em;
}

.form-group input,
.form-group select,
.form-group textarea {
  font-family: inherit;
  font-size: 0.9375rem;
  color: #1e293b;
  background: #fff;
  border: 1.5px solid #d1d5db;
  border-radius: 7px;
  padding: 0.55rem 0.8rem;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.5;
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
  border-color: #9ca3af;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb),0.12);
}

.form-group input::placeholder,
.form-group textarea::placeholder { color: #9ca3af; }

.form-group textarea { resize: vertical; min-height: 80px; }

.form-hint { font-size: 0.8rem; color: #6b7280; }

.form-row   { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e5e7eb;
  flex-wrap: wrap;
}

.inline-form { display: inline; }

/* ----------------------------------------------------------
   12. Toast notifications (fixed top-right)
   ---------------------------------------------------------- */
.toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 500;
  max-width: 360px;
  min-width: 260px;
  pointer-events: all;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.08);
  animation: toast-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.hiding {
  opacity: 0;
  transform: translateX(100%);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(100%); }
  to   { opacity: 1; transform: translateX(0); }
}

.toast-success {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #15803d;
}

.toast-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.toast-warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.toast-info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.toast-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-body { flex: 1; line-height: 1.4; }

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.5;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.toast-close:hover { opacity: 1; }

/* Hidden flash data (read by JS to create toasts) */
.flash-data { display: none; }

/* Inline alerts (fallback for auth pages) */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.alert-success { background: #f0fdf4; border-color: #86efac; color: #166534; }
.alert-error   { background: #fef2f2; border-color: #fca5a5; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fcd34d; color: #92400e; }

/* ----------------------------------------------------------
   13. Badges
   ---------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  line-height: 1;
  white-space: nowrap;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-neutral { background: #f1f5f9; color: #475569; }

.status-select {
  border: none; border-radius: 999px; padding: .2rem .7rem;
  font-size: .75rem; font-weight: 700; cursor: pointer;
  appearance: none; -webkit-appearance: none; outline: none;
}
.status-select.status-paid    { background: #dcfce7; color: #166534; }
.status-select.status-pending { background: #fef3c7; color: #92400e; }
.status-select.status-partial { background: #dbeafe; color: #1e40af; }

/* ----------------------------------------------------------
   14. Tables
   ---------------------------------------------------------- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

.table thead tr {
  background: #f8fafc;
  border-bottom: 1.5px solid #e2e8f0;
}

.table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  white-space: nowrap;
}

.table td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  color: #1e293b;
  vertical-align: middle;
}

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

.table-hover tbody tr {
  transition: background 0.1s;
}
.table-hover tbody tr:hover {
  background: #f8fafc;
  cursor: pointer;
}

.table-invoice { border: 1px solid #e2e8f0; }
.table-invoice th, .table-invoice td { padding: 0.65rem 0.85rem; }

.total-row td {
  font-weight: 700;
  background: #f8fafc;
  border-top: 1.5px solid #e2e8f0;
  font-size: 0.9375rem;
}

.total-amount {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
}

.product-select { width: 100%; }

.actions-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  flex-wrap: nowrap;
}

.row-danger td { background: #fff1f2; }
.row-danger:hover td { background: #ffe4e6 !important; }
.row-warning td { background: #fffbeb; }
.row-warning:hover td { background: #fef3c7 !important; }

/* ----------------------------------------------------------
   15. Filters bar
   ---------------------------------------------------------- */
.filters-bar {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.875rem 1.25rem;
  margin-bottom: 1.25rem;
}

.filters-form {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filters-form .form-group { margin-bottom: 0; min-width: 150px; }
.filters-form .form-group label { font-size: 0.75rem; }

/* Bare inputs / selects in filters (not wrapped in .form-group) */
.filters-form input,
.filters-form select {
  font-family: inherit;
  font-size: 0.875rem;
  color: #1e293b;
  background: #fff;
  border: 1.5px solid #d1d5db;
  border-radius: 7px;
  padding: 0.5rem 0.75rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.5;
}

.filters-form input:focus,
.filters-form select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb),0.12);
}

/* Search input */
.filters-form input[name="search"] {
  background: #f9fafb;
  min-width: 200px;
}

/* ----------------------------------------------------------
   16. Empty states
   ---------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: #6b7280;
}

.empty-state-full {
  text-align: center;
  padding: 3.5rem 1.5rem;
  color: #6b7280;
}

.empty-state .empty-icon,
.empty-state-full .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  display: block;
  opacity: 0.4;
}

.empty-state h3, .empty-state-full h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.35rem;
}

.empty-state p, .empty-state-full p {
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
}

.empty-state.success { color: #166534; }

/* ----------------------------------------------------------
   17. Stock alerts
   ---------------------------------------------------------- */
.stock-alerts { display: flex; flex-direction: column; gap: 0.5rem; }

.stock-alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.875rem;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #fafafa;
  font-size: 0.875rem;
  gap: 0.5rem;
  transition: background 0.12s;
}

.stock-alert-item .product-name {
  font-weight: 500;
  color: #1e293b;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-alert-item.out {
  background: #fef2f2;
  border-color: #fca5a5;
}

.stock-alert-item.out .product-name { color: #991b1b; }

.stock-alert-item.low {
  background: #fffbeb;
  border-color: #fcd34d;
}

.stock-alert-item.low .product-name { color: #78350f; }

.stock-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.stock-alert-item.out .stock-badge { background: #dc2626; color: #fff; }
.stock-alert-item.low .stock-badge { background: #d97706; color: #fff; }

/* ----------------------------------------------------------
   18. Invoice preview
   ---------------------------------------------------------- */
.invoice-preview {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 2.5rem;
  max-width: 860px;
  margin: 0 auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--color-primary);
  gap: 1.5rem;
}

.invoice-info { display: flex; flex-direction: column; gap: 0.3rem; }
.invoice-info h2 { font-size: 1.625rem; font-weight: 800; color: #0f172a; }

.client-info {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

.client-info h3 {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
  margin-bottom: 0.5rem;
}

.client-info p { font-size: 0.9375rem; color: #1e293b; line-height: 1.6; }

.invoice-notes {
  margin-top: 1.5rem;
  padding: 1rem 1.25rem;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: 0.875rem;
  color: #78350f;
}

/* ----------------------------------------------------------
   19. Margin preview
   ---------------------------------------------------------- */
#margin-preview {
  display: none;
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: #166534;
  font-weight: 500;
}

#margin-preview.negative {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

/* ----------------------------------------------------------
   20. Helpers / Utilities
   ---------------------------------------------------------- */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-left   { text-align: left; }
.text-muted  { color: #6b7280; }
.text-success { color: #16a34a; }
.text-danger  { color: #dc2626; }
.text-warning { color: #d97706; }

.fw-bold    { font-weight: 700; }
.fw-semibold { font-weight: 600; }
.fs-sm      { font-size: 0.8125rem; }

.d-flex      { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }

.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.ml-1 { margin-left: 0.25rem; }
.mr-1 { margin-right: 0.25rem; }

.divider { border: none; border-top: 1px solid #e2e8f0; margin: 1.25rem 0; }

/* ----------------------------------------------------------
   21. Print
   ---------------------------------------------------------- */
@media print {
  .sidebar, .sidebar-toggle, .page-header .header-actions,
  .btn, .filters-bar, .no-print, .toast-container { display: none !important; }

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

  body { background: #fff; font-size: 12pt; }

  .invoice-preview { box-shadow: none; border: none; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}

/* ----------------------------------------------------------
   22. Responsive — Tablet (≤ 1024px)
   ---------------------------------------------------------- */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* ----------------------------------------------------------
   23. Responsive — Mobile (≤ 768px)
   ---------------------------------------------------------- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }

  .sidebar-overlay.active { display: block; }

  .sidebar-toggle {
    display: flex;
  }

  .main-wrapper {
    margin-left: 0;
  }

  .page-content { padding: 1.25rem 1rem 1rem; }

  .page-content .container,
  .page-content .container-md {
    padding-top: 2.75rem; /* room for hamburger button */
  }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

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

  .invoice-header { flex-direction: column; }

  .filters-form {
    flex-direction: column;
    align-items: stretch;
  }

  .filters-form .form-group { min-width: 100%; }

  .page-header { flex-direction: column; align-items: flex-start; }

  .table th, .table td { padding: 0.6rem 0.65rem; }

  .toast-container { right: 0.75rem; left: 0.75rem; top: 0.75rem; }
  .toast { min-width: 0; max-width: 100%; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 1.75rem 1.25rem; }
  .invoice-preview { padding: 1.25rem; }
  .stat-value { font-size: 1.375rem; }
}

/* ----------------------------------------------------------
   24. Settings — Color picker, Logo, Onboarding
   ---------------------------------------------------------- */
.color-picker-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.color-input {
  width: 48px;
  height: 48px;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  cursor: pointer;
  padding: 2px;
  background: #fff;
  flex-shrink: 0;
}

.color-presets {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.color-preset {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  flex-shrink: 0;
}

.color-preset:hover {
  transform: scale(1.2);
  border-color: rgba(0,0,0,0.2);
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.logo-preview-wrap {
  width: 120px;
  height: 80px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-preview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-placeholder {
  width: 120px;
  height: 80px;
  border: 2px dashed #d1d5db;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.8125rem;
  flex-shrink: 0;
}

.logo-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}

/* Onboarding */
.onboarding-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  padding: 2rem 1rem;
}

.onboarding-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35);
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 520px;
}

.onboarding-header {
  text-align: center;
  margin-bottom: 2rem;
}

.onboarding-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 0.4rem;
}

.onboarding-header p {
  color: #64748b;
  font-size: 0.9375rem;
}


@media print {
  .sidebar, .navbar, .page-header .header-actions, .form-actions, .filters-bar { display: none !important; }
  .main-content { margin-left: 0 !important; padding: 0 !important; }
  .container, .container-md { max-width: 100% !important; padding: 0 !important; }
  .card { box-shadow: none !important; border: none !important; }
  body { background: #fff !important; }
}
