:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --border: #e2e4e9;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --primary: #2f5fdb;
  --primary-dark: #2249b3;
  --primary-bg: #eaf0ff;
  --success: #17845a;
  --success-bg: #e6f6ee;
  --warning: #b3760a;
  --warning-bg: #fff4e0;
  --danger: #c0362c;
  --danger-bg: #fdeae8;
  --accent: #7c4fd0;
  --accent-bg: #f1eafb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.06), 0 1px 8px rgba(20, 20, 40, 0.04);
  --shadow-lg: 0 8px 30px rgba(20, 20, 40, 0.14);
  --nav-w: 220px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
#app { min-height: 100%; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
p { margin: 0 0 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.hint { font-size: 11px; color: var(--text-faint); margin-top: 3px; }

/* ---- layout shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--nav-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { padding: 6px 8px 16px; }
.sidebar-brand .name { font-weight: 700; font-size: 15px; }
.sidebar-brand .role { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text); font-size: 13.5px; font-weight: 500; margin-bottom: 2px; cursor: pointer;
}
.nav-link:hover { background: var(--surface-alt); }
.nav-link.active { background: var(--primary-bg); color: var(--primary-dark); font-weight: 650; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 20px; }
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 650; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.content { padding: 20px; max-width: 1180px; width: 100%; margin: 0 auto; flex: 1; }

.bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 12px; padding-bottom: 76px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
    border-top: 1px solid var(--border); z-index: 30; padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
  }
  .bottom-nav .nav-link { flex: 1; flex-direction: column; gap: 2px; text-align: center; font-size: 10.5px; border-radius: 8px; }
  .bottom-nav .nav-link .ic { font-size: 18px; }
  .bottom-nav button.nav-link { border: 0; background: none; font-family: inherit; }
}

/* ---- primitives ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
/* On a phone a wide table scrolls inside its own card instead of pushing the whole page
   sideways (which also threw dialogs off-centre). */
.card { overflow-x: auto; }
.grid > * { min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; transition: background .1s;
}
.btn:hover { background: var(--surface-alt); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-icon { padding: 7px 9px; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 20px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.badge-neutral { background: #eef0f3; color: #4b5262; }
.badge-primary { background: var(--primary-bg); color: var(--primary-dark); }
.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-accent { background: var(--accent-bg); color: var(--accent); }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--text-muted); }
.empty-state .ic { font-size: 30px; margin-bottom: 8px; }

.star-toggle { cursor: pointer; font-size: 17px; color: var(--text-faint); background: none; border: none; padding: 2px; line-height: 1; }
.star-toggle.on { color: #d99a10; }

.preview-tag { background: var(--accent-bg); color: var(--accent); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 20px; }

dialog#modal-root {
  border: none; border-radius: 14px; padding: 0; width: min(560px, 92vw); box-shadow: var(--shadow-lg);
  background: var(--surface); max-height: 88vh;
}
dialog#modal-root::backdrop { background: rgba(15, 17, 25, 0.45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; overflow-y: auto; max-height: calc(88vh - 130px); }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

#toast-root { position: fixed; top: 14px; right: 14px; z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: toast-in .15s ease-out;
}
.toast.success { background: var(--success); }
.toast.danger { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 380px; max-width: 100%; }
.login-logo { font-size: 26px; margin-bottom: 6px; }
.demo-creds { background: var(--surface-alt); border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 11.5px; }
.demo-creds table { font-size: 11px; }
.demo-creds td { padding: 3px 6px; border: none; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item::before { content: ""; position: absolute; left: -22px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); }
.timeline-item:last-child { padding-bottom: 0; }

.step-track { display: flex; align-items: center; margin-bottom: 16px; overflow-x: auto; }
.step { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 82px; }
.step .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--border); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.step.done .dot { background: var(--success); }
.step.active .dot { background: var(--primary); }
.step .lbl { font-size: 10px; color: var(--text-muted); text-align: center; white-space: nowrap; }
.step.done .lbl, .step.active .lbl { color: var(--text); font-weight: 600; }
.step-line { flex: 1; height: 2px; background: var(--border); min-width: 16px; }
.step-line.done { background: var(--success); }

.product-card { display: flex; gap: 10px; }
.product-thumb { width: 52px; height: 52px; border-radius: 8px; background: var(--surface-alt); display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; border: 1px solid var(--border); }
.qty-input { display: flex; align-items: center; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; width: fit-content; }
.qty-input button { width: 28px; height: 30px; border: none; background: var(--surface-alt); cursor: pointer; font-size: 15px; }
.qty-input input { width: 52px; border: none; text-align: center; padding: 4px; }

.notif-item { display: flex; gap: 10px; padding: 10px 8px; border-radius: var(--radius-sm); cursor: pointer; }
.notif-item:hover { background: var(--surface-alt); }
.notif-item.unread { background: var(--primary-bg); }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; margin-top: 6px; }

.file-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 20px; padding: 4px 10px 4px 8px; font-size: 12px; }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--border); border-radius: 20px; cursor: pointer; transition: .15s; }
.switch .slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }

.gap-note { background: var(--accent-bg); border: 1px solid #e2d4fb; color: #4a2f8a; border-radius: var(--radius-sm); padding: 8px 12px; font-size: 12px; margin-bottom: 12px; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d3d6dc; border-radius: 20px; }

/* Free goods earned from a quantity-slab scheme — shown under a cart preview and
   under an order's items, with the reason spelled out per line. */
.free-goods {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-bg);
}
.free-goods table { margin-top: 4px; }
.free-goods td, .free-goods th { padding-top: 5px; padding-bottom: 5px; }
