:root {
  --bg: #f3f5fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #e6e9f4;
  --text: #1c2033;
  --text-muted: #6b7290;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0891b2;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(30, 41, 82, 0.06);
  --shadow-lg: 0 12px 40px rgba(30, 41, 82, 0.12);
  --sidebar-w: 250px;
  --sidebar-w-collapsed: 78px;
}

[data-bs-theme="dark"] {
  --bg: #0f1220;
  --surface: #171b2e;
  --surface-2: #1d2238;
  --border: #2a2f4a;
  --text: #eef0fb;
  --text-muted: #9aa0c3;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  transition: background .25s ease, color .25s ease;
}

a { text-decoration: none; }

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

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 1040;
  transition: width .22s ease, transform .25s ease;
}

.sidebar-collapse-btn {
  position: absolute; top: 28px; right: -14px;
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  align-items: center; justify-content: center;
  box-shadow: var(--shadow); z-index: 1050; transition: all .15s ease;
}
.sidebar-collapse-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); transform: scale(1.08); }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 20px; font-weight: 800; font-size: 1.15rem;
  border-bottom: 1px solid var(--border); position: relative;
}
.brand-icon {
  width: 38px; height: 38px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-size: 1.1rem;
  box-shadow: 0 6px 16px rgba(99, 102, 241, .35);
  flex-shrink: 0;
}
.brand-text { white-space: nowrap; overflow: hidden; }

.sidebar-nav { flex: 1; padding: 14px 12px; overflow-y: auto; overflow-x: hidden; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; margin-bottom: 4px;
  border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 600; font-size: .92rem;
  transition: all .15s ease; white-space: nowrap; overflow: hidden;
}
.nav-item i { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); transform: translateX(2px); }
.nav-item.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; box-shadow: 0 6px 18px rgba(99, 102, 241, .35);
}

.sidebar-footer { padding: 10px 12px 14px; border-top: 1px solid var(--border); position: relative; }
.sidebar-profile-menu { max-height: 0; overflow: hidden; opacity: 0; transition: max-height .22s ease, opacity .18s ease, margin .22s ease; }
.sidebar-profile-menu.open { max-height: 140px; opacity: 1; margin-bottom: 6px; }
.sidebar-profile-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer; transition: all .15s ease;
}
.sidebar-profile-btn:hover { background: var(--surface); border-color: var(--primary); }
.sidebar-profile-info { display: flex; flex-direction: column; text-align: left; flex: 1; min-width: 0; }
.sidebar-profile-name { font-weight: 700; font-size: .85rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-profile-role { font-size: .72rem; color: var(--text-muted); white-space: nowrap; }
.sidebar-profile-caret { color: var(--text-muted); transition: transform .2s ease; flex-shrink: 0; }
.sidebar-profile-btn.open .sidebar-profile-caret { transform: rotate(180deg); }

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

.sidebar.collapsed { width: var(--sidebar-w-collapsed); }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .sidebar-profile-info,
.sidebar.collapsed .sidebar-profile-caret,
.sidebar.collapsed .sidebar-profile-menu span { display: none; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 22px 10px; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 11px; }
.sidebar.collapsed .sidebar-profile-btn { justify-content: center; padding: 8px; }
.sidebar.collapsed .sidebar-profile-menu.open { max-height: 100px; }
.sidebar.collapsed .sidebar-profile-menu .nav-item { justify-content: center; }

body.sidebar-collapsed .main-wrap { margin-left: var(--sidebar-w-collapsed); }
.main-wrap { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; transition: margin-left .22s ease; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1030;
}
.page-title { font-size: 1.25rem; font-weight: 800; margin: 0; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.btn-icon {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); display: flex; align-items: center; justify-content: center;
  transition: all .15s ease;
}
.btn-icon:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.content { padding: 26px 28px 60px; flex: 1; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card {
  border-radius: var(--radius); padding: 20px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); position: relative; overflow: hidden; transition: transform .18s ease, box-shadow .18s ease;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat-card .stat-icon {
  width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; color: #fff; margin-bottom: 12px;
}
.stat-card .stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.stat-card .stat-label { color: var(--text-muted); font-size: .85rem; font-weight: 600; margin-top: 4px; }

.bg-grad-indigo { background: linear-gradient(135deg,#6366f1,#8b5cf6); }
.bg-grad-green { background: linear-gradient(135deg,#22c55e,#16a34a); }
.bg-grad-orange { background: linear-gradient(135deg,#f59e0b,#d97706); }
.bg-grad-red { background: linear-gradient(135deg,#ef4444,#dc2626); }
.bg-grad-blue { background: linear-gradient(135deg,#0ea5e9,#0891b2); }
.bg-grad-pink { background: linear-gradient(135deg,#ec4899,#db2777); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.panel-title { display: flex; align-items: center; gap: 8px; font-weight: 800; margin-bottom: 16px; font-size: 1.02rem; }
.panel-title i { font-size: 1.05rem; flex-shrink: 0; }

/* ---------- Tables ---------- */
.table { color: var(--text); margin-bottom: 0; }
.table thead th {
  color: var(--text-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); font-weight: 700; padding: 12px 14px; white-space: nowrap;
}
.table tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table-hover tbody tr:hover { background: var(--surface-2); }

.badge-status { padding: 5px 11px; border-radius: 999px; font-weight: 700; font-size: .72rem; }
.badge-success { background: rgba(22,163,74,.12); color: var(--success); }
.badge-warning { background: rgba(217,119,6,.14); color: var(--warning); }
.badge-danger { background: rgba(220,38,38,.12); color: var(--danger); }
.badge-info { background: rgba(8,145,178,.12); color: var(--info); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }

.prod-thumb { width: 46px; aspect-ratio: 1 / 1; border-radius: 10px; object-fit: cover; border: 1px solid var(--border); background: var(--surface-2); }

/* ---------- Forms ---------- */
.form-control, .form-select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: .92rem;
}
.form-control:focus, .form-select:focus {
  background: var(--surface-2); color: var(--text); border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-label { font-weight: 700; font-size: .84rem; margin-bottom: 6px; color: var(--text-muted); }

.btn { border-radius: var(--radius-sm); font-weight: 700; padding: 10px 18px; font-size: .9rem; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); border: none; box-shadow: 0 6px 16px rgba(99,102,241,.3); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-outline-secondary { border-color: var(--border); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.product-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: transform .15s ease, box-shadow .15s ease; }
.product-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.product-card img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; background: var(--surface-2); }
.product-card .pc-body { padding: 14px; }
.product-card .pc-title { font-weight: 700; font-size: .92rem; margin-bottom: 4px; }
.product-card .pc-sku { color: var(--text-muted); font-size: .78rem; }

.view-toggle .btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.upload-drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; cursor: pointer;
  background: var(--surface-2); transition: all .15s ease;
}
.upload-drop:hover, .upload-drop.dragover { border-color: var(--primary); background: rgba(99,102,241,.06); }

@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  .sidebar.show { transform: translateX(0); }
  .main-wrap, body.sidebar-collapsed .main-wrap { margin-left: 0; }
  .sidebar.collapsed .brand-text,
  .sidebar.collapsed .nav-item span,
  .sidebar.collapsed .sidebar-profile-info,
  .sidebar.collapsed .sidebar-profile-caret { display: revert; }
}

.spinner-mini { width: 1rem; height: 1rem; border-width: .15em; }

/* ---------- Delete confirmation modal ---------- */
.confirm-modal-content { border-radius: var(--radius); border: 1px solid var(--border); }
.confirm-icon {
  width: 60px; height: 60px; border-radius: 50%; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
  background: rgba(220, 38, 38, .12); color: var(--danger);
}

.chart-wrapper { position: relative; width: 100%; }

/* ---------- Searchable product select (live search dropdown) ---------- */
.searchable-select-wrapper { position: relative; }
.searchable-select-display { cursor: pointer; display: flex; align-items: center; justify-content: space-between; user-select: none; }
.searchable-select-display-content { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; }
.searchable-select-display-content span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.searchable-select-display-img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; flex-shrink: 0; border: 1px solid var(--border); background: #fff; }
.searchable-select-display::after { content: "\f64d"; font-family: "bootstrap-icons"; font-size: .75rem; color: var(--text-muted); margin-left: 8px; flex-shrink: 0; }
.searchable-select-display.placeholder-text { color: var(--text-muted); }
.searchable-select-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1060;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 10px;
  height: 340px; max-height: min(420px, 60vh);
  display: flex; flex-direction: column;
}
.searchable-select-input { margin-bottom: 8px; flex-shrink: 0; }
.searchable-select-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.searchable-select-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: .9rem; }
.searchable-select-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.searchable-select-item-img { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; flex-shrink: 0; border: 1px solid var(--border); background: #fff; }
.searchable-select-item:hover, .searchable-select-item.active { background: var(--primary); color: #fff; }
.searchable-select-empty { text-align: center; padding: 24px 10px !important; }

/* ---------- Chip input (dynamic variant generator) ---------- */
.chip-input-box {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  padding: 8px 10px; min-height: 46px;
}
.chip-input-box input {
  border: none; background: transparent; outline: none; flex: 1; min-width: 100px;
  font-size: .9rem; color: var(--text); padding: 4px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(99,102,241,.12); color: var(--primary); font-weight: 700; font-size: .82rem;
  padding: 5px 8px 5px 12px; border-radius: 999px;
}
.chip .chip-remove { cursor: pointer; font-size: .7rem; opacity: .7; }
.chip .chip-remove:hover { opacity: 1; }

.variant-preview-table th, .variant-preview-table td { font-size: .84rem; }

/* Invoice print styling scoped */
.invoice-box { background: #fff; color: #111; border-radius: 10px; padding: 30px; }

/* ---------- Site-wide print styles ---------- */
@media print {
  .sidebar, .topbar, .no-print, .toast-container, .modal { display: none !important; }
  .main-wrap { margin-left: 0 !important; }
  .content { padding: 0 !important; }
  body { background: #fff !important; }
  .panel { box-shadow: none !important; border: 1px solid #ddd !important; }
  a[href]::after { content: none !important; }
}
