/* ============================================================
   ZERP — Mobile-First Design System v2
   Architecture: mobile base → tablet (640px) → desktop (1024px)
   No duplicate rules, no override conflicts
   ============================================================ */

/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; overflow-x: hidden; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ─── CSS Variables ──────────────────────────────────────── */
:root {
  --primary:       #1a56db;
  --primary-dark:  #1e3a8a;
  --primary-light: #3b82f6;
  --primary-bg:    #eff6ff;

  --sidebar-bg:    #0f172a;
  --sidebar-text:  rgba(255,255,255,0.7);
  --sidebar-active:#fff;
  --sidebar-w:     256px;
  --sidebar-w-collapsed: 76px;
  --header-h:      56px;
  --mobile-nav-h:  60px;

  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --surface-hover: #f8fafc;
  --border:        #e2e8f0;
  --border-dark:   #cbd5e1;

  --text:          #0f172a;
  --text-2:        #475569;
  --text-3:        #5c6c82;
  --text-inv:      #ffffff;

  --success:       #059669;
  --success-bg:    #ecfdf5;
  --warning:       #d97706;
  --warning-bg:    #fffbeb;
  --danger:        #dc2626;
  --danger-bg:     #fef2f2;
  --info:          #2563eb;
  --info-bg:       #eff6ff;

  --r:             6px;
  --r-lg:          10px;
  --r-xl:          14px;

  --shadow-sm:     0 1px 2px rgba(0,0,0,0.05);
  --shadow:        0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:     0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg:     0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);

  --font-mono:     'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
}

/* ─── Typography ─────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.25; color: var(--text); }
h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; color: var(--text); }
h3 { font-size: 1.05rem; font-weight: 600; line-height: 1.3; color: var(--text); }
h4 { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.text-sm    { font-size: 0.82rem; }
.text-xs    { font-size: .78rem; }
.text-lg    { font-size: 1.1rem; }
.text-muted { color: var(--text-3); }
.text-secondary { color: var(--text-2); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger  { color: var(--danger); }
.text-primary { color: var(--primary); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.font-bold   { font-weight: 700; }
.font-medium { font-weight: 500; }
.font-mono   { font-family: var(--font-mono); }
.nowrap      { white-space: nowrap; }

/* ─── Layout Shell ───────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  -webkit-overflow-scrolling: touch;
}
.sidebar.open { transform: translateX(0); }

/* Collapse toggle: a small circular button pinned to the sidebar's edge (desktop only, see media query) */
.sidebar-collapse-btn {
  display: none;
  position: absolute;
  top: 20px;
  right: -12px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
  z-index: 201;
  transition: background 0.15s, transform 0.25s, right 0.28s;
}
.sidebar-collapse-btn:hover { background: var(--bg); color: var(--text); }
.sidebar-collapse-btn svg { transition: transform 0.25s; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  min-height: var(--header-h);
  flex-shrink: 0;
}
.brand-icon {
  width: 34px; height: 34px;
  border-radius: var(--r);
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-brand img { width: 34px; height: 34px; border-radius: var(--r); object-fit: cover; flex-shrink: 0; }
.sidebar-brand h2 { font-size: 0.92rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-nav { flex: 1; padding: 8px 0 20px; }
.nav-section {
  padding: 14px 16px 4px;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: rgba(255,255,255,0.3);
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.75; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.05); }
.nav-item.active { color: #fff; background: rgba(255,255,255,0.08); border-left-color: var(--primary-light); }
.nav-item.active svg { opacity: 1; }

/* Sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 199;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ─── Main Content ───────────────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  /* On mobile: no margin (sidebar overlays) */
}

/* ─── Top Bar ────────────────────────────────────────────── */
.top-bar {
  height: var(--header-h);
  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: 50;
  gap: 12px;
}
.top-bar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-bar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--r);
  background: none;
  border: none;
  color: var(--text);
  flex-shrink: 0;
  transition: background 0.15s;
}
.menu-toggle:hover { background: var(--bg); }
.menu-toggle svg { width: 20px; height: 20px; }

.page-title {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background 0.15s;
}
.user-menu:hover { background: var(--bg); }
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.8rem;
  flex-shrink: 0;
}
img.user-avatar { object-fit: cover; background: var(--bg); }
.user-name { font-size: 0.82rem; font-weight: 500; display: none; }

/* My Profile */
.profile-head { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.profile-avatar { width: 112px; height: 112px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 3px solid var(--border); background: var(--bg); display: block; }
.profile-avatar[hidden] { display: none; }
.profile-avatar-initial { display: flex; align-items: center; justify-content: center; background: var(--primary); color: #fff; font-size: 2.6rem; font-weight: 600; border-color: transparent; }
.profile-name { font-size: 1.2rem; font-weight: 700; margin-bottom: 2px; }

/* ─── Page Content ───────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--mobile-nav-h) + 16px);
  max-width: 100%;
  overflow-x: hidden;
}

/* ─── Page Header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.3rem; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}
.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.card-header h3 { font-size: 0.95rem; }
.card-body { padding: 16px; }
.card-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 20px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 20px; }

/* ─── Stat Cards ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 42px; height: 42px;
  border-radius: var(--r);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.blue   { background: #dbeafe; color: #2563eb; }
.stat-icon.green  { background: #dcfce7; color: #16a34a; }
.stat-icon.orange { background: #ffedd5; color: #ea580c; }
.stat-icon.red    { background: #fee2e2; color: #dc2626; }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }
.stat-icon.teal   { background: #ccfbf1; color: #0d9488; }
.stat-info { flex: 1; min-width: 0; }
.stat-label { font-size: .78rem; color: var(--text-3); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.2rem; font-weight: 700; line-height: 1.25; margin-top: 2px; word-break: break-all; }
.stat-change { font-size: .78rem; margin-top: 2px; }
.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1.4;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); color: var(--text); }
.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #047857; color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover  { background: #b91c1c; color: #fff; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover   { background: var(--bg); color: var(--text); }
.btn-sm  { padding: 5px 10px; font-size: 0.78rem; }
.btn-lg  { padding: 10px 20px; font-size: 0.95rem; }
.btn-block { width: 100%; }
.btn-icon  { padding: 7px; }

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: .78rem;
  font-weight: 600;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--info-bg);    color: var(--info); }
.badge-neutral { background: #f1f5f9; color: #64748b; }

/* ─── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 11px 14px;
  border-radius: var(--r);
  font-size: 0.875rem;
  margin-bottom: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: slideDown 0.25s ease;
}
.alert-success { background: var(--success-bg); color: #065f46; border-left: 4px solid var(--success); }
.alert-error   { background: var(--danger-bg);  color: #991b1b; border-left: 4px solid var(--danger); }
.alert-warning { background: var(--warning-bg); color: #92400e; border-left: 4px solid var(--warning); }
.alert-info    { background: var(--info-bg);    color: #1e40af; border-left: 4px solid var(--info); }
.close-alert { margin-left: auto; cursor: pointer; opacity: 0.6; background: none; border: none; font-size: 1.1rem; flex-shrink: 0; line-height: 1; color: inherit; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--text-2);
}
.form-label .required { color: var(--danger); }

.form-control {
  width: 100%;
  padding: 9px 12px;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}
.form-control::placeholder { color: var(--text-3); }
.form-control:disabled, .form-control[readonly] { background: var(--bg); color: var(--text-2); cursor: default; }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
textarea.form-control { resize: vertical; min-height: 76px; }

/* Mobile: full-width stacked forms */
.form-row   { display: flex; flex-direction: column; gap: 0; }
.form-row-3 { display: flex; flex-direction: column; gap: 0; }

.form-text  { font-size: .78rem; color: var(--text-3); margin-top: 3px; }
.form-error { font-size: .78rem; color: var(--danger); margin-top: 3px; }
.form-control.error { border-color: var(--danger); }

.input-group { display: flex; align-items: stretch; }
.input-group .form-control { border-radius: var(--r) 0 0 var(--r); flex: 1; }
.input-group-append {
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 var(--r) var(--r) 0;
  display: flex; align-items: center;
  font-size: 0.82rem; color: var(--text-2);
  white-space: nowrap;
}

/* ─── Filters Bar ────────────────────────────────────────── */
.filters-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.search-input { position: relative; width: 100%; }
.search-input input { padding-left: 34px; }
.search-input svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); pointer-events: none; }
.filters-bar .form-control { width: 100%; }

/* ─── Tables ─────────────────────────────────────────────── */
/* Tables are always visible and scroll sideways when they don't fit. Below 1024px a table is only
   swapped for the card list when the page actually provides one (see the media query near .mobile-cards)
   — previously every page without cards showed NO data on phones and tablets. */
.table-wrapper { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  padding: 9px 14px;
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-hover); }
.data-table tfoot td { padding: 10px 14px; background: var(--bg); border-top: 2px solid var(--border); font-weight: 600; }
.data-table .amount { text-align: right; font-family: var(--font-mono); }
.data-table .actions { white-space: nowrap; }

/* ─── Mobile Card List ───────────────────────────────────── */
.mobile-cards { display: none; }
@media (max-width: 1023.98px) {
  .mobile-cards { display: block; }
  .table-wrapper:has(~ .mobile-cards) { display: none; }
}
.mobile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 13px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.mobile-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 9px;
  gap: 8px;
}
.mobile-card-title { font-weight: 600; font-size: 0.9rem; color: var(--text); word-break: break-word; }
.mobile-card-rows { display: grid; gap: 5px; }
.mobile-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  gap: 8px;
}
.mobile-card-row .label { color: var(--text-3); flex-shrink: 0; }
.mobile-card-row .value { font-weight: 500; text-align: right; word-break: break-word; }
.mobile-card-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ─── Tabs ───────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  gap: 0;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 9px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color 0.15s;
  text-decoration: none;
  flex-shrink: 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── Line Items (Invoice / Purchase) ───────────────────── */
.line-items { margin-bottom: 16px; }

/* Mobile: each item is a stacked card */
.line-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px;
  margin-bottom: 8px;
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.line-item .product-col { grid-column: 1 / -1; position: relative; }
.line-item .line-total-col { grid-column: 1 / -1; }
.line-item .disc-col { grid-column: 1 / -1; }
.line-foc-label {
  display: flex; align-items: center; gap: 4px;
  margin-top: 5px; font-size: .78rem; color: var(--text-2);
  cursor: pointer; user-select: none;
}
.line-foc-label input { width: 13px; height: 13px; cursor: pointer; }
.line-item.is-foc-row { background: var(--success-bg, #f0fdf4); border-color: var(--success, #16a34a); }
.line-total-foc { color: var(--success) !important; font-weight: 700; }
.line-item .btn-remove {
  position: absolute;
  top: 8px; right: 8px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--danger-bg);
  border: none; border-radius: 50%;
  color: var(--danger);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.line-item .btn-remove svg { width: 13px; height: 13px; }
.line-item .form-control { padding: 7px 10px; font-size: 0.82rem; }
.line-item-label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.line-item .line-total-col input { background: var(--surface-hover); font-weight: 600; }

/* Header row – hidden on mobile */
.line-item-header { display: none; }

/* Totals block */
.line-totals {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding-top: 14px;
  border-top: 2px solid var(--border);
}
.line-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  gap: 8px;
}
.line-total-row .label { color: var(--text-2); flex: 1; }
.line-total-row .value { font-weight: 600; font-family: var(--font-mono); min-width: 100px; text-align: right; }
.line-total-row.grand { font-size: 1rem; padding-top: 8px; border-top: 2px solid var(--border); }
.line-total-row.grand .value { font-size: 1.1rem; color: var(--primary); }

/* Inline input in totals */
.totals-inline-input {
  width: 70px; padding: 3px 6px; font-size: 0.8rem;
  border: 1px solid var(--border); border-radius: 4px; text-align: center;
  background: var(--surface);
}
.totals-inline-input:focus { border-color: var(--primary); outline: none; }

/* Product suggestions */
.product-suggestions {
  position: absolute;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  max-height: 200px;
  overflow-y: auto;
  width: 100%;
  margin-top: 2px;
  left: 0; top: 100%;
}
.suggestion {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.suggestion:last-child { border-bottom: none; }
.suggestion:hover { background: var(--bg); }
.suggestion strong { display: block; font-size: 0.85rem; }
.suggestion span { color: var(--text-3); }
.suggestion-thumb { width: 32px; height: 32px; border-radius: 5px; object-fit: cover; flex-shrink: 0; border: 1px solid var(--border); }
.suggestion-text { min-width: 0; flex: 1; }

/* ─── Grids ──────────────────────────────────────────────── */
/* Mobile: always single column */
.grid-2, .grid-3, .grid-4 { display: flex; flex-direction: column; gap: 12px; }

/* ─── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px; height: 34px;
  padding: 0 8px;
  font-size: 0.82rem;
  border-radius: var(--r);
  border: 1px solid var(--border);
  color: var(--text-2);
  transition: all 0.15s;
}
.pagination a:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ─── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  align-items: flex-end;  /* mobile: sheet from bottom */
  justify-content: center;
  padding: 0;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: sheetUp 0.25s ease;
}
.modal-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-body { padding: 16px; }
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
@keyframes sheetUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ─── Empty State ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-3);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 14px; opacity: 0.35; }
.empty-state h3 { color: var(--text-2); margin-bottom: 6px; font-size: 1rem; }
.empty-state p { font-size: 0.875rem; margin-bottom: 16px; }

/* ─── Dropdown ───────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0; top: 100%;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  padding: 4px;
  margin-top: 4px;
}
.dropdown-menu.open { display: block; }
.pdc-bell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.pdc-bell:hover { background: var(--bg); color: var(--text); }
.pdc-bell-badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 8px;
  background: var(--warning, #d97706);
  color: #fff;
  font-size: .78rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  border: 2px solid var(--surface);
}
.pdc-bell-badge.urgent { background: var(--danger); }
.pdc-bell-menu { width: 320px; max-height: 420px; overflow-y: auto; padding: 0; right: 0; left: auto; }
.pdc-bell-header { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pdc-bell-empty { padding: 24px 14px; text-align: center; color: var(--text-3); font-size: 0.85rem; }
.pdc-bell-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
  transition: background 0.12s;
}
.pdc-bell-item:hover { background: var(--bg); }
.pdc-bell-item:last-of-type { border-bottom: none; }
.pdc-bell-footer {
  display: block; text-align: center; padding: 10px;
  font-size: 0.82rem; font-weight: 600; color: var(--primary);
  text-decoration: none; border-top: 1px solid var(--border);
}
.pdc-bell-footer:hover { background: var(--bg); }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 0.82rem;
  color: var(--text);
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s;
}
.dropdown-item:hover { background: var(--bg); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ─── Mobile Bottom Nav ──────────────────────────────────── */
.mobile-nav {
  display: block;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}
.mobile-nav-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 100%;
  padding: 0 4px;
}
.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-3);
  padding: 5px 8px;
  border-radius: var(--r);
  text-decoration: none;
  transition: color 0.15s;
  min-width: 52px;
}
.mobile-nav-item svg { width: 21px; height: 21px; }
.mobile-nav-item.active { color: var(--primary); }

/* ─── Charts ─────────────────────────────────────────────── */
.chart-container { position: relative; height: 220px; width: 100%; }

/* ─── Spinner ────────────────────────────────────────────── */
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Utilities ──────────────────────────────────────────── */
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap    { flex-wrap: wrap; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.p-0    { padding: 0; }
.p-16   { padding: 16px; }

/* Print rules consolidated below in the "Documents" section — see @media print near invoice_doc styles */

/* ============================================================
   TABLET — 640px+
   ============================================================ */
@media (min-width: 640px) {
  .page-content { padding: 20px; padding-bottom: calc(var(--mobile-nav-h) + 16px); }
  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .stat-value { font-size: 1.35rem; }
  h1 { font-size: 1.6rem; }

  /* Forms: 2-col on tablet */
  .form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .form-row-3 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

  /* Grids */
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .grid-3 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .grid-4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

  /* Filters bar: horizontal on tablet+ */
  .filters-bar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .search-input { flex: 1; min-width: 180px; max-width: 320px; }
  .filters-bar .form-control { width: auto; min-width: 130px; }

  /* Line items: grid on tablet+ */
  .line-item {
    display: grid;
    grid-template-columns: 3fr 80px 90px 110px 90px 32px;
    gap: 6px;
    padding: 8px 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    margin-bottom: 0;
  }
  .line-item .product-col  { grid-column: auto; }
  .line-item .line-total-col { grid-column: auto; }
  .line-item .disc-col     { grid-column: auto; }
  .line-item .btn-remove {
    position: static;
    background: none;
    border-radius: var(--r);
    width: 28px; height: 28px;
  }
  .line-item-label { display: none; }
  .line-item-header {
    display: grid;
    grid-template-columns: 3fr 80px 90px 110px 90px 32px;
    gap: 6px;
    padding: 6px 0;
    border-bottom: 2px solid var(--border);
    font-weight: 600; font-size: .78rem;
    color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em;
  }

  /* Modal: centered dialog on tablet */
  .modal-overlay { align-items: center; padding: 20px; }
  .modal { border-radius: var(--r-xl); max-width: 540px; animation: fadeScale 0.2s ease; }
  @keyframes fadeScale { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

  .user-name { display: block; }
  .chart-container { height: 280px; }
}

/* ============================================================
   DESKTOP — 1024px+
   ============================================================ */
@media (min-width: 1024px) {
  /* Sidebar always visible */
  .sidebar { transform: translateX(0); }
  .sidebar-overlay { display: none !important; }
  .menu-toggle { display: none; }
  .sidebar-collapse-btn { display: flex; }

  /* Main content offset */
  .main-content { margin-left: var(--sidebar-w); transition: margin-left 0.28s cubic-bezier(0.4,0,0.2,1); }
  .sidebar { transition: width 0.28s cubic-bezier(0.4,0,0.2,1), transform 0.28s cubic-bezier(0.4,0,0.2,1); }

  /* ── Collapsed state — icon rail only, persisted via localStorage (see app.js) ── */
  html.nav-collapsed .sidebar { width: var(--sidebar-w-collapsed); overflow: visible; }
  html.nav-collapsed .main-content { margin-left: var(--sidebar-w-collapsed); }
  html.nav-collapsed .sidebar-brand { justify-content: center; padding-left: 8px; padding-right: 8px; }
  html.nav-collapsed .sidebar-brand h2 { display: none; }
  html.nav-collapsed .nav-section { display: none; }
  html.nav-collapsed .nav-label { display: none; }
  html.nav-collapsed .nav-item { justify-content: center; padding: 11px 0; border-left: none; border-radius: var(--r); margin: 2px 10px; }
  html.nav-collapsed .nav-item svg { margin: 0; }
  html.nav-collapsed .nav-item.active { background: var(--primary); color: #fff; }
  html.nav-collapsed .nav-item.active svg { opacity: 1; }
  html.nav-collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }

  .top-bar { padding: 0 24px; }
  .page-content { padding: 24px; padding-bottom: 24px; } /* no bottom nav on desktop */
  .mobile-nav { display: none; }

  /* 3-col form rows */
  .form-row-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }

  .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }
  .stat-value { font-size: 1.45rem; }
  h1 { font-size: 1.75rem; }
  .chart-container { height: 300px; }

  /* Tables visible, mobile cards hidden */
  .table-wrapper { display: block; }
  .mobile-cards { display: none; }

  /* Line items on desktop: more space for product column */
  .line-item { grid-template-columns: 3fr 90px 100px 120px 100px 32px; }
  .line-item-header { grid-template-columns: 3fr 90px 100px 120px 100px 32px; }
}

.disc-type-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-left: 4px;
  vertical-align: middle;
}
.disc-type-btn {
  padding: 1px 6px;
  font-size: .78rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--text-3);
  line-height: 1.6;
}
.disc-type-btn.disc-type-active {
  background: var(--primary);
  color: #fff;
}

/* ─── Report Cards Hover ─────────────────────────────────── */
.grid-3 > a.card, .grid-2 > a.card {
  transition: transform 0.2s, box-shadow 0.2s;
  display: block;
}
.grid-3 > a.card:hover, .grid-2 > a.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ─── Fixes & Patches ────────────────────────────────────── */

/* Sidebar must always sit ABOVE page content overlay */
.sidebar { z-index: 200; }

/* Prevent stat values from overflowing on small screens */
.stat-value { word-break: break-word; hyphens: auto; }

/* Stats grid: 2-col base, scales up */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }

/* Table wrapper: always allow horizontal scroll, never clip */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; min-width: 0; }
.table-wrapper table { min-width: 500px; } /* prevent squishing */

/* Card overflow protection */
.card { min-width: 0; }
.card-header { min-width: 0; }

/* Page content: must not overflow viewport */
.page-content { min-width: 0; overflow-x: auto; } /* wide content scrolls instead of being clipped */
.main-content  { min-width: 0; overflow-x: hidden; }

/* Document max-width now handled by .doc-wrap in the Documents section below */

/* Form controls inside tables */
.data-table .form-control { min-width: 60px; }

/* Delivery sheet customer item rows */
.cust-item-row input.form-control { min-width: 0; width: 100%; }

/* Badge text never wraps */
.badge { white-space: nowrap; flex-shrink: 0; }

/* Flex-between on mobile: allow wrap */
.flex-between { flex-wrap: wrap; gap: 4px; }

/* Page header: keep button group from wrapping badly */
.page-header-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* Mobile: action buttons full width */
@media (max-width: 480px) {
  .page-header { gap: 8px; }
  .page-header-actions .btn { padding: 7px 12px; font-size: 0.8rem; }
  .stat-card { padding: 10px; gap: 8px; }
  .stat-icon { width: 36px; height: 36px; }
  .stat-icon svg { width: 16px; height: 16px; }
  .stat-value { font-size: 1.05rem; }
  .stat-label { font-size: .78rem; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .filters-bar { gap: 6px; }
}

/* ─── Documents (Invoice / Purchase Order / print view) ──────────────────
   $doc-accent is set per-document via inline style="--doc-accent: ..." on
   .doc-wrap, using the company's own primary_color, so branding stays
   per-tenant exactly like the rest of the app. */
.doc-wrap { max-width: 820px; margin: 0 auto; position: relative; --doc-accent: var(--primary); }
.doc-card { background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.08); border: 1px solid var(--border); position: relative; }
.doc-body { padding: 0 32px 32px; position: relative; }

/* Large translucent diagonal status stamp — the kind every printed invoice/PO needs */
.doc-watermark {
  position: absolute; top: 46%; left: 50%; transform: translate(-50%, -50%) rotate(-20deg);
  font-size: 5.5rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  opacity: 0.06; pointer-events: none; z-index: 0; white-space: nowrap; user-select: none;
}
.doc-watermark.paid, .doc-watermark.reconciled { color: var(--success); }
.doc-watermark.overdue, .doc-watermark.cancelled { color: var(--danger); }
.doc-watermark.draft { color: var(--text-3); }

.doc-parties { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin: 24px 0 24px; position: relative; z-index: 1; }
.doc-party-label { font-size: .78rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-3); font-weight: 700; margin-bottom: 6px; }
.doc-party-name { font-size: 1.08rem; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.doc-party-line { font-size: 0.85rem; color: var(--text-2); line-height: 1.5; }

.doc-table-wrap { overflow-x: auto; margin-bottom: 22px; position: relative; z-index: 1; }
.doc-table { width: 100%; border-collapse: collapse; min-width: 480px; }
.doc-table thead th {
  text-align: left; padding: 11px 12px; font-size: .78rem; text-transform: uppercase;
  letter-spacing: 0.07em; color: #fff; background: var(--doc-accent); white-space: nowrap;
}
.doc-table thead th:first-child { border-radius: 6px 0 0 0; }
.doc-table thead th:last-child { border-radius: 0 6px 0 0; }
.doc-table thead th.text-right { text-align: right; }
.doc-table tbody tr:nth-child(even) { background: var(--bg); }
.doc-table tbody tr:hover { background: var(--surface-hover, var(--bg)); }
.doc-table tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc-table tbody tr:last-child td { border-bottom: 2px solid var(--doc-accent); }
.doc-item-name { font-weight: 500; }
.doc-item-meta { font-size: .78rem; color: var(--text-3); margin-top: 2px; }
.doc-foc-badge { display: inline-block; margin-top: 3px; font-size: .78rem; font-weight: 700; letter-spacing: 0.03em; color: #fff; background: var(--success); border-radius: 4px; padding: 1px 6px; }

.doc-totals { display: flex; justify-content: flex-end; position: relative; z-index: 1; }
.doc-totals-box { width: 290px; max-width: 100%; }
.doc-totals-row { display: flex; justify-content: space-between; padding: 8px 2px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.doc-totals-row .label { color: var(--text-2); }
.doc-totals-row .val { font-family: var(--font-mono); }
.doc-totals-row .val.neg { color: var(--danger); }
.doc-grand-total { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px; margin-top: 10px; border-radius: 8px; background: var(--primary-bg, #eff6ff); background: color-mix(in srgb, var(--doc-accent) 10%, transparent); font-size: 1.18rem; font-weight: 800; }
.doc-grand-total .val { font-family: var(--font-mono); color: var(--doc-accent); }
.doc-balance-pill { display: flex; justify-content: space-between; padding: 12px 14px; border-radius: 8px; margin-top: 8px; font-weight: 700; }
.doc-balance-pill.due { background: var(--danger-bg); color: var(--danger); }
.doc-balance-pill.clear { background: var(--success-bg); color: var(--success); }
.doc-paid-row { display: flex; justify-content: space-between; padding: 8px 2px; border-bottom: 1px solid var(--border); color: var(--success); }

.doc-notes { margin-top: 22px; padding: 13px 16px; background: var(--bg); border-radius: 8px; border-left: 3px solid var(--doc-accent); position: relative; z-index: 1; }
.doc-notes .doc-party-label { margin-bottom: 5px; }
.doc-footer { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--border); text-align: center; color: var(--text-3); font-size: 0.8rem; position: relative; z-index: 1; }

@media print {
  .no-print, .sidebar, .mobile-nav, .top-bar, .menu-toggle { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .page-content { padding: 0 !important; background: #fff !important; }
  body { background: #fff; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; }
  .table-wrapper { display: block !important; overflow: visible !important; }
  .mobile-cards { display: none !important; }
  a { color: inherit !important; text-decoration: none !important; }

  /* Documents: keep the brand colors — most browsers strip background colors by default */
  .doc-wrap { max-width: 100% !important; }
  .doc-card { box-shadow: none !important; border: none !important; }
  .doc-body { padding: 0 12px !important; }
  .doc-table, .doc-grand-total, .doc-watermark, .doc-balance-pill {
    -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important;
  }
  .doc-table thead th { page-break-inside: avoid; }
  .doc-table tbody tr { page-break-inside: avoid; }
  .doc-watermark { opacity: 0.08; }
  @page { margin: 1.4cm; }
}


/* ─── Accessibility & polish (audit fixes) ───────────────── */
:focus-visible { outline: 3px solid var(--primary-light, #3b82f6); outline-offset: 2px; }
.btn:focus-visible, .nav-item:focus-visible, .tab:focus-visible, .dropdown-item:focus-visible { outline: 3px solid var(--primary-light, #3b82f6); outline-offset: 2px; }
.form-control:focus-visible { outline: none; } /* .form-control already draws its own focus ring */

.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 1000;
  background: var(--primary); color: #fff; padding: 10px 14px; border-radius: var(--r);
  font-weight: 600; text-decoration: none; transition: top .15s;
}
.skip-link:focus { top: 8px; }
#main-content:focus { outline: none; }

.suggestion.active { background: var(--primary-bg); }
.pagination .ellipsis { border-color: transparent; min-width: 20px; padding: 0; }
.pagination a[aria-current="page"], .pagination span[aria-current="page"] { background: var(--primary); color: #fff; border-color: var(--primary); }
.card-footer { padding: 4px 16px 16px; }

/* Long words and numbers must never push a card wider than the screen */
.card, .mobile-card { min-width: 0; overflow-wrap: anywhere; }

/* iOS zooms into inputs below 16px; keep forms comfortable on phones */
@media (max-width: 640px) {
  .form-control, select.form-control, textarea.form-control { font-size: 16px; }
  .btn { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}


/* ─── Units, pack size & stock (product form + inventory list) ─── */
.unit-box { border: 1px solid var(--border); background: var(--bg); border-radius: var(--r); padding: 16px; margin: 8px 0 18px; min-width: 0; }
.unit-box legend { font-weight: 700; font-size: .95rem; padding: 0 8px; color: var(--text); }
.unit-box .muted, .form-label .muted { font-weight: 400; color: var(--text-3); font-size: .78rem; }
.unit-preview { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; background: var(--primary-bg); border: 1px dashed var(--primary-light); border-radius: var(--r); padding: 10px 14px; margin-top: 4px; }
.unit-preview .lbl { font-size: .78rem; color: var(--text-2); }
.unit-preview strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; color: var(--primary); }
.unit-preview #pvSub { font-size: .82rem; color: var(--text-2); }
.stock-readout { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.stock-readout strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.stock-readout span { font-size: .78rem; color: var(--text-2); }
.stock-cell { line-height: 1.25; text-align: right; }
.stock-main { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stock-sub { font-size: .78rem; color: var(--text-3); white-space: nowrap; }
.stock-cell.low .stock-main { color: var(--danger); }
.sold-as { display: block; font-size: .78rem; color: var(--text-3); font-weight: 400; }
.pack-tip { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--warning); background: var(--warning-bg); border-radius: var(--r); font-size: .82rem; color: var(--text); display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.pack-tip[hidden], .pack-tip [hidden] { display: none !important; }
.unit-fix td { vertical-align: middle; }
.unit-fix .res { font-weight: 700; font-variant-numeric: tabular-nums; }
.unit-fix .res small { display: block; font-weight: 400; color: var(--text-2); }


/* ─── Brand / vendor filters (inventory) ─── */
.filter-summary { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin: -4px 0 12px; min-height: 28px; }
.filter-count { font-size: .85rem; color: var(--text-2); margin-right: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; background: var(--primary-bg); color: var(--primary); border: 1px solid var(--primary-light); font-size: .8rem; text-decoration: none; }
.chip:hover { background: var(--primary); color: #fff; }
.chip .chip-k { opacity: .75; }
.chip-clear { font-size: .8rem; color: var(--text-2); text-decoration: underline; margin-left: 4px; }
.filter-link { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--text-3); }
.filter-link:hover { color: var(--primary); border-bottom-color: var(--primary); }
.text-muted { color: var(--text-3); }
.upgrade-banner { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; padding: 12px 14px; border: 1px solid var(--info); background: var(--info-bg); border-radius: var(--r); }
.upgrade-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between; margin: 0; font-size: .86rem; }
.upgrade-row > div { flex: 1 1 320px; }
.brand-vendor-box { border: 1px solid var(--border); background: var(--bg); border-radius: var(--r); padding: 14px 16px; margin: 4px 0 18px; min-width: 0; }
.brand-vendor-box legend { font-weight: 700; font-size: .95rem; padding: 0 8px; }
@media (max-width: 1279.98px) { .col-xl { display: none; } }
@media (min-width: 640px) { .filters-bar .form-control[name="brand"], .filters-bar .form-control[name="vendor"] { max-width: 220px; } }


/* ─── Live print preview (iframe of ?print=1&embed=1) ─── */
.doc-preview-wrap { max-width: 900px; margin: 0 auto 8px; }
.doc-preview { display: block; width: 100%; height: 1200px; border: 0; background: transparent; overflow: hidden; }
@media print { .doc-preview-wrap { display: none !important; } }

/* ─── Confirm dialog (zConfirm) and delete-impact lists ───── */
.zc-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 2000; display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.zc-overlay[hidden] { display: none; }
.zc-box { background: var(--surface); width: 100%; max-width: 440px; border-radius: var(--r-xl) var(--r-xl) 0 0; padding: 22px 20px calc(18px + env(safe-area-inset-bottom, 0px)); box-shadow: var(--shadow-lg); animation: sheetUp .2s ease; text-align: left; }
.zc-icon { width: 40px; height: 40px; border-radius: 999px; margin-bottom: 12px; display: grid; place-items: center; font-weight: 700; font-size: 1.2rem; background: var(--primary-bg); color: var(--primary); }
.zc-icon::before { content: "?"; }
.zc-box[data-tone="danger"] .zc-icon { background: var(--danger-bg); color: var(--danger); } .zc-box[data-tone="danger"] .zc-icon::before { content: "!"; }
.zc-box[data-tone="warning"] .zc-icon { background: var(--warning-bg); color: var(--warning); } .zc-box[data-tone="warning"] .zc-icon::before { content: "!"; }
.zc-title { margin: 0 0 6px; font-size: 1.1rem; color: var(--text); }
.zc-msg p { margin: 0 0 6px; color: var(--text-2); font-size: .92rem; line-height: 1.5; }
.zc-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.zc-actions .btn { min-width: 110px; min-height: 40px; }
@media (min-width: 640px) { .zc-overlay { align-items: center; padding: 20px; } .zc-box { border-radius: var(--r-xl); animation: fadeScale .18s ease; } }
.zc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.zc-list li { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--r-md, 8px); font-size: .9rem; color: var(--text-2); }
.zc-list li > span { flex: 1; min-width: 0; }
.zc-list:not(.zc-list-blockers) li { border: 0; padding: 2px 0 2px 18px; position: relative; }
.zc-list:not(.zc-list-blockers) li::before { content: "•"; position: absolute; left: 4px; color: var(--text-3); }
.zc-list-blockers li { background: var(--warning-bg); border-color: transparent; align-items: center; flex-wrap: wrap; }
.zc-list-blockers .btn { white-space: normal; }
.zc-input { margin-top: 10px; width: 100%; resize: vertical; }
.zc-input[hidden] { display: none; }
