:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e4e7ec;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --info: #1d4ed8;
  --info-soft: #eff6ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --sidebar: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --surface: #171b23; --surface-2: #1d222c; --text: #e6e8ec; --muted: #9aa3b2;
    --border: #2a303c; --primary: #818cf8; --primary-hover: #a5b4fc; --primary-soft: #23264a;
    --danger: #f87171; --danger-soft: #3a1d1f; --warn: #fbbf24; --warn-soft: #3a2f14;
    --ok: #34d399; --ok-soft: #12302a; --info: #93c5fd; --info-soft: #172a45;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 12px; }
p { margin: 0 0 10px; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small, small { font-size: 12px; }
.pre { white-space: pre-wrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.neg { color: var(--danger); }
.pos { color: var(--ok); }
.boot, .loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); padding: 4px 8px 16px; }
.brand:hover { text-decoration: none; }
.brand.big { font-size: 24px; justify-content: center; padding: 0 0 6px; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 800; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); font-weight: 500; }
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav-icon { width: 20px; text-align: center; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.me { display: flex; flex-direction: column; color: var(--text); padding: 6px 8px; border-radius: 8px; overflow: hidden; }
.me:hover { background: var(--surface-2); text-decoration: none; }
.me small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { margin-left: auto; background: var(--primary); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.topbar { display: none; }
main { padding: 24px 28px 48px; max-width: 1280px; width: 100%; outline: none; }

/* ---------- Page pieces ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 6px; font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-head h3 { margin: 0; }
.table-card { padding: 0; overflow-x: auto; }
.table-card .card-head { padding: 14px 18px 0; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.stack > .card:last-child { margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.grid-2 > .card, .grid-2-1 > .card { margin-bottom: 0; }
.grid-2, .grid-2-1 { margin-bottom: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.error-card { border-color: var(--danger); }
.notice { padding: 12px 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 16px; }
.notice-info { background: var(--info-soft); border-color: transparent; color: var(--info); }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; margin-bottom: 12px; font-size: 13px; }
label.inline { flex-direction: row; align-items: center; margin: 0; font-weight: 400; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%;
}
label.inline input, .toolbar input, .toolbar select, .range input, .range select { width: auto; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input:disabled { opacity: .6; }
textarea { resize: vertical; }
input.qty { width: 76px; text-align: right; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; margin: 8px 0; font-size: 13px; }
.form-error[hidden] { display: none; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1 1 220px; max-width: 360px; }
.inline-toolbar { margin: 0; flex-wrap: nowrap; }
.inline-toolbar input[type=search] { flex: 1 1 260px; }
.range { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 500;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(.92); }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 11px 18px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 16px; color: var(--muted); padding: 6px; border-radius: 6px; position: relative; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table.compact td { padding: 7px 4px; }
.table tr.inactive td { opacity: .6; }
.table tr.problem { background: var(--danger-soft); }
.item-cell { display: flex; gap: 10px; align-items: center; }
.thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); flex: none; }
.thumb-empty { display: inline-block; background: var(--surface-2); }

/* ---------- Badges & status ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle; }
.badge[class*="status-"] { text-transform: capitalize; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.status-pending { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.status-processing { background: var(--info-soft); color: var(--info); border-color: transparent; }
.status-shipped { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.status-complete { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status-canceled { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
select.status-select { width: auto; padding: 4px 8px; font-weight: 600; text-transform: capitalize; font-size: 12px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; text-transform: capitalize; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.count { font-size: 11px; background: var(--surface-2); border-radius: 999px; padding: 0 6px; color: var(--muted); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 500; }
.chip:hover { text-decoration: none; border-color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.active .count { background: rgba(255, 255, 255, .25); color: #fff; }
.sub-chips { margin-top: -8px; padding-left: 12px; border-left: 3px solid var(--primary-soft); }
.sub-chips .chip { padding: 4px 10px; font-size: 13px; }
.sub-chips .chip.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.sub-chips .chip.active .count { background: var(--surface); color: var(--primary); }
.table tr.sub-row td:first-child { padding-left: 34px; }
.sub-name { color: var(--text); }

.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); }
.timeline li { margin-bottom: 12px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }

/* ---------- KPIs & charts ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--muted); font-size: 12px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 140px) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.bar-value { font-variant-numeric: tabular-nums; text-align: right; }
.columns { display: flex; align-items: flex-end; gap: 3px; height: 180px; padding-bottom: 22px; overflow-x: auto; }
.col { flex: 1 0 14px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.col-fill { width: 100%; max-width: 36px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.col:hover .col-fill { background: var(--primary-hover); }
.col-label { position: absolute; bottom: -20px; font-size: 10px; color: var(--muted); white-space: nowrap; }
.col:nth-child(even) .col-label { visibility: hidden; }
.columns:has(.col:nth-child(-n+12):last-child) .col-label { visibility: visible; }
.empty-chart { padding: 24px 0; text-align: center; }

/* ---------- Product form ---------- */
.gallery { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.gallery:empty { display: none; }
.gallery figure { margin: 0; position: relative; width: 96px; height: 96px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.gallery img { width: 100%; height: 100%; object-fit: cover; }
.gallery figure .icon-btn { position: absolute; top: 3px; right: 3px; background: var(--surface); padding: 2px 6px; font-size: 12px; }
.gallery figcaption { position: absolute; bottom: 0; left: 0; right: 0; background: var(--primary); color: #fff; font-size: 10px; text-align: center; }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; font-weight: 400; margin: 0; }
.dropzone:hover { border-color: var(--primary); color: var(--primary); }
.dropzone input { display: none; }
.margin { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.margin:empty { display: none; }

/* ---------- Shop ---------- */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.product-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; }
.product-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16, 24, 40, .1); }
.product-img { aspect-ratio: 4/3; background: var(--surface-2); display: grid; place-items: center; position: relative; overflow: hidden; }
.product-img img { width: 100%; height: 100%; object-fit: cover; }
.no-img { color: var(--muted); font-size: 13px; }
.ribbon { position: absolute; top: 10px; left: 10px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px; }
.product-body { padding: 12px 14px 4px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.product-name { color: var(--text); font-weight: 600; font-size: 15px; }
.price { font-weight: 700; font-size: 16px; }
.price.sale { color: var(--danger); }
.product-buy { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px 14px; }
.product-buy input { width: 64px; flex: 1 0 56px; max-width: 80px; }
.product-buy .btn { flex: 1 1 100px; }
.product-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; padding: 24px; }
.main-img { aspect-ratio: 1; background: var(--surface-2); border-radius: var(--radius); display: grid; place-items: center; overflow: hidden; }
.main-img img { width: 100%; height: 100%; object-fit: contain; }
.thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.thumb-btn { width: 64px; height: 64px; padding: 0; border: 2px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; background: none; }
.thumb-btn.active { border-color: var(--primary); }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; }
.detail-info h1 { font-size: 26px; margin: 4px 0 10px; }
.detail-price .price { font-size: 26px; }
.save { color: var(--ok); font-weight: 600; }
.buy-row { display: flex; gap: 10px; margin: 16px 0 24px; }
.buy-row input { width: 80px; }
.summary-row { display: flex; justify-content: space-between; padding: 6px 0; }
.summary-row.total { font-size: 18px; font-weight: 700; border-top: 1px solid var(--border); margin: 6px 0 14px; padding-top: 12px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--primary-soft), var(--bg)); }
.login-card { width: 100%; max-width: 380px; padding: 28px; text-align: center; }
.login-card label { text-align: left; }

/* ---------- Modal & toasts ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
dialog.wide { width: min(820px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 18, 24, .5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px 6px; max-height: 65vh; overflow-y: auto; }
.modal-form > .form-error { margin: 0 20px 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: 360px; transition: opacity .4s, transform .4s; }
.toast-error { background: var(--danger); color: #fff; }
.toast.hide { opacity: 0; transform: translateY(8px); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .grid-2, .grid-2-1, .product-detail { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; width: var(--sidebar); transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  .page-head .actions { width: 100%; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 12px; }
  .topbar .icon-btn:last-child { margin-left: auto; }
  .brand-sm { font-weight: 700; }
  .topbar .pill { position: absolute; top: -2px; right: -4px; }
  main { padding: 16px; }
  .row { grid-template-columns: 1fr; }
  .toolbar input[type=search] { max-width: none; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  #toasts { left: 16px; right: 16px; }
}

@media print {
  .sidebar, .topbar, .actions, .toolbar, .tabs, #toasts, .card-foot, #status-form, .btn { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  body { background: #fff; color: #000; }
}
