:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --border: #e4e1da;
  --border-strong: #cfcbc2;
  --text: #22201c;
  --text-2: #4a463f;
  --muted: #7a756b;
  --accent: #2f6b4f;
  --accent-hover: #255940;
  --accent-soft: #e8f0eb;
  --danger: #a8322a;
  --danger-soft: #f8e9e7;
  --warn: #8a5a12;
  --warn-soft: #fbf1df;
  --ok: #2f6b4f;
  --ok-soft: #e8f0eb;
  --info: #2c5a85;
  --info-soft: #e6eef6;
  --radius: 6px;
  --sidebar: 210px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior-x: none; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
code, .mono { font-family: Menlo, Consolas, monospace; font-size: 12.5px; background: var(--surface-2); padding: 1px 4px; border-radius: 3px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.hidden { display: none !important; }
.hint { font-size: 12.5px; color: var(--muted); font-weight: 400; }

/* Layout */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.layout > * { min-width: 0; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 20px 18px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.nav { display: flex; flex-direction: column; }
.nav a { display: flex; align-items: center; padding: 8px 20px; color: var(--text-2); border-left: 3px solid transparent; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { border-left-color: var(--accent); color: var(--text); font-weight: 600; background: var(--surface-2); }
.nav a:focus { outline: none; }
.nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav .count { margin-left: auto; background: var(--accent); color: #fff; border-radius: 3px; font-size: 11px; padding: 0 6px; font-weight: 600; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 20px 0; font-size: 13px; }
.live { font-size: 12px; color: var(--muted); }
.live.on { color: var(--ok); }
.main { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 16px 18px; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.grid { display: grid; gap: 14px; }
.grid > * { min-width: 0; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.two { grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); align-items: start; }
@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi-action { cursor: pointer; border-color: var(--accent); }
.kpi-action:hover { background: var(--accent-soft); }
.delta { font-weight: 600; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 4px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 4px;
  padding: 0 9px; height: 32px; min-width: 0;
}
textarea { padding: 8px 9px; height: auto; resize: vertical; }
input::placeholder { color: #a39e94; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: 15px; height: 15px; padding: 0; accent-color: var(--accent); }
input[type=color] { padding: 2px; width: 44px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); }
label.field input, label.field select, label.field textarea { width: 100%; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.filters input[type=search] { flex: 1 1 220px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 4px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--text-2); padding: 0 12px; height: 30px; font: inherit; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.t td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t tbody tr:last-child td { border-bottom: 0; }
.t tr.clickable { cursor: pointer; }
.t tr.clickable:hover td { background: var(--surface-2); }
.t tr.selected td { background: var(--accent-soft); }
.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t .order-no { font-weight: 600; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.pager .grow { flex: 1; }
.bulkbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--accent-soft); border-bottom: 1px solid var(--border); font-size: 13px; flex-wrap: wrap; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 0 7px; border-radius: 3px; font-size: 12px; font-weight: 500; white-space: nowrap; background: #efede8; color: var(--text-2); line-height: 20px; }
.badge.s-new { background: var(--info-soft); color: var(--info); }
.badge.s-confirmed, .badge.s-processing, .badge.s-packed { background: #eeeae2; color: #5b4a2c; }
.badge.s-shipped { background: #e4eef2; color: #2b5d70; }
.badge.s-delivered, .badge.p-paid { background: var(--ok-soft); color: var(--ok); }
.badge.s-on_hold, .badge.p-unpaid, .badge.p-authorized, .badge.p-partially_paid { background: var(--warn-soft); color: var(--warn); }
.badge.s-cancelled, .badge.s-returned, .badge.s-refunded, .badge.p-refunded, .badge.p-failed, .badge.p-voided, .badge.p-partially_refunded { background: var(--danger-soft); color: var(--danger); }
.store-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 2px; flex: none; display: inline-block; }
.risk { color: var(--danger); font-size: 12px; }
.tag-repeat { color: var(--ok); }
.pill-cod { font-size: 11px; font-weight: 600; color: var(--warn); border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; }

/* Chart */
.chart { width: 100%; height: auto; max-height: 300px; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--border); }
.chart rect.bar:hover { opacity: .8; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.bars .bar-row { display: grid; grid-template-columns: 100px 1fr 40px; gap: 10px; align-items: center; font-size: 13px; margin-bottom: 9px; }
.bars .track { height: 6px; background: #efede8; border-radius: 2px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--accent); }

/* Drawer & modal */
.overlay { position: fixed; inset: 0; background: rgba(34, 32, 28, .35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(700px, 100vw); background: var(--bg); z-index: 41;
  border-left: 1px solid var(--border-strong); display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.drawer-body { overflow-y: auto; padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 12px; }
.modal {
  position: fixed; z-index: 51; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(680px, calc(100vw - 24px));
  max-height: calc(100vh - 40px); overflow-y: auto; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border-strong);
}
.modal-overlay { z-index: 50; }
.modal-head { display: flex; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }
.items img { width: 40px; height: 40px; object-fit: cover; border-radius: 3px; border: 1px solid var(--border); background: var(--surface-2); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
.timeline li.note > div:first-child { font-weight: 500; }
.alert { padding: 10px 14px; border-radius: 4px; font-size: 13px; border: 1px solid transparent; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #efd9b0; }
.alert.danger { background: var(--danger-soft); color: var(--danger); border-color: #ecc9c4; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--info-soft); color: var(--info); border-color: #c9d9ea; }
.copy-box { display: flex; gap: 6px; }
.copy-box input { flex: 1; font-family: Menlo, Consolas, monospace; font-size: 12px; }
.steps { margin: 6px 0 0; padding-left: 20px; font-size: 13px; color: var(--text-2); }
.steps li { margin-bottom: 4px; }

/* Websites */
.stores-grid { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.store-card .top { display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; }
.store-card .swatch { width: 6px; align-self: stretch; border-radius: 2px; flex: none; font-size: 0; }
.store-card .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; padding: 0 18px 14px; font-size: 13px; }
.store-card .foot { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }
.health { font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.health.ok { color: var(--ok); } .health.err { color: var(--danger); } .health.idle { color: var(--muted); }

/* Sign in */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); padding: 28px; }

/* Toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 4px; font-size: 13px; min-width: 240px; max-width: 380px; cursor: pointer; box-shadow: 0 4px 12px rgba(0, 0, 0, .08); }
.toast.err { border-left-color: var(--danger); }
.toast strong { display: block; }

/* Mobile */
.mobile-bar { display: none; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 45; left: 0; width: 240px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 24px rgba(0, 0, 0, .12); }
  .layout.nav-open .sidebar { transform: none; }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .main { padding: 16px; }
  .hide-sm { display: none; }
  .dl { grid-template-columns: 96px 1fr; }
}
@media print { .sidebar, .mobile-bar, #toasts { display: none; } }

/* Status tabs above the orders table */
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px 8px; font: inherit; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.on { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
.tab-n { color: var(--muted); font-weight: 400; font-size: 12.5px; margin-left: 2px; }

/* Full-page order */
.order-top { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.order-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; align-items: start; }
.order-layout > * { min-width: 0; }
@media (max-width: 1100px) { .order-layout { grid-template-columns: minmax(0, 1fr); } }
.dl.totals { grid-template-columns: 1fr auto; max-width: 320px; margin-left: auto; }
.dl.totals dd { text-align: right; }
@media (max-width: 860px) { .order-top { flex-wrap: wrap; } }

/* Dashboard: two independent columns so neither side leaves gaps */
.dash { display: grid; grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); gap: 14px; align-items: start; }
.dash > .stack { gap: 14px; min-width: 0; }
@media (max-width: 1100px) { .dash { grid-template-columns: minmax(0, 1fr); } }

.sync-note { font-size: 12.5px; color: var(--text-2); background: var(--accent-soft); border: 1px solid #cfe0d5; border-radius: 4px; padding: 8px 12px; }
.timeline li.website > div:first-child { color: var(--accent); }

/* Operations dashboard */
.tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 14px; }
@media (max-width: 1300px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
a.tile { color: inherit; text-decoration: none; display: block; }
a.tile:hover { border-color: var(--accent); background: var(--surface-2); }
.tile-err { border-color: #e0b4ae; background: var(--danger-soft); }
.tile-err .value { color: var(--danger); }
.tile-warn { border-color: #efd9b0; background: var(--warn-soft); }
.today { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 26px; padding: 12px 18px; margin-bottom: 14px; }
.today strong { font-size: 17px; }
.today .aging { margin-left: auto; display: flex; gap: 14px; flex-wrap: wrap; }
.pipeline td, .pipeline th { white-space: nowrap; }
a.pipe { display: inline-block; min-width: 30px; padding: 1px 8px; border-radius: 3px; background: var(--accent-soft); color: var(--accent); font-weight: 600; text-align: center; }
a.pipe:hover { background: var(--accent); color: #fff; text-decoration: none; }
a.pipe.warn { background: var(--warn-soft); color: var(--warn); }
a.pipe.err { background: var(--danger-soft); color: var(--danger); }
.pipe.zero { color: var(--border-strong); display: inline-block; min-width: 30px; text-align: center; }
.age { display: inline-block; min-width: 52px; padding: 1px 6px; border-radius: 3px; background: #efede8; font-size: 12px; font-weight: 600; text-align: center; }
.age.late { background: var(--danger-soft); color: var(--danger); }
ul.attn { list-style: none; margin: 0; padding: 4px 0; }
ul.attn li a { display: flex; gap: 12px; align-items: flex-start; padding: 9px 18px; color: var(--text); }
ul.attn li a:hover { background: var(--surface-2); text-decoration: none; }
.attn-n { min-width: 34px; text-align: center; font-weight: 700; border-radius: 3px; padding: 0 6px; }
.attn-n.err { background: var(--danger-soft); color: var(--danger); }
.attn-n.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- order origin ---------- */
.origin { display: inline-block; font-size: 12px; line-height: 18px; padding: 0 7px; border-radius: 3px; white-space: nowrap; font-weight: 500;
  background: var(--o-soft, var(--surface-2)); color: var(--o, var(--text-2)); border: 1px solid color-mix(in srgb, var(--o, var(--border)) 25%, transparent); }
.o-paid { --o: #b23c0a; --o-soft: #fbece3; }
.o-organic { --o: #2f6b4f; --o-soft: #e8f0eb; }
.o-social { --o: #2c5a85; --o-soft: #e6eef6; }
.o-whatsapp { --o: #16733a; --o-soft: #e3f4e8; }
.o-ai { --o: #6d32d6; --o-soft: #efe8fb; }
.o-referral { --o: #8a5a12; --o-soft: #fbf1df; }
.o-email { --o: #0e6277; --o-soft: #e2f2f6; }
.o-campaign { --o: #a3175a; --o-soft: #f9e6ef; }
.o-direct { --o: #4a463f; --o-soft: #efede8; }
.o-staff { --o: #334155; --o-soft: #e8ebef; }
.o-unknown { --o: #7a756b; --o-soft: transparent; border-style: dashed; }
.bar-row { background: var(--surface-2); border-radius: 3px; height: 10px; overflow: hidden; }
.o-bar { display: block; height: 100%; background: var(--o, var(--accent)); border-radius: 3px; min-width: 2px; }
.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono-ish { font-family: Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
.kpi .value.small-value { font-size: 17px; line-height: 1.5; }
.order-no { white-space: nowrap; }
