:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --primary: #4f8cff;
  --primary-ink: #ffffff;
  --green: #3ecf8e;
  --amber: #f5a623;
  --red: #ff5c5c;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

#app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand-mark { font-size: 26px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.site-switch { padding: 4px 8px 14px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
.site-switch label { font-size: 10px; letter-spacing: .05em; }
.site-switch select { font-weight: 600; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary); color: var(--primary-ink); }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; padding: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }

/* Content */
.content { flex: 1; min-width: 0; padding: 26px 30px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; }
.page-sub { color: var(--muted); margin: 2px 0 0; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: #3a4150; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--red); border-color: #4a2b2f; }
.btn.danger:hover { background: #2a1a1c; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12px; }

/* Cards / stats */
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 22px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat-value.warn { color: var(--amber); }
.stat-value.bad { color: var(--red); }
.stat-value.good { color: var(--green); }
.two-col { grid-template-columns: 1fr 1fr; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* Toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; min-width: 160px; }
input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }

/* Tables */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; font-weight: 600; cursor: default; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.muted { color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.green { background: rgba(62,207,142,.15); color: var(--green); }
.badge.amber { background: rgba(245,166,35,.15); color: var(--amber); }
.badge.red { background: rgba(255,92,92,.15); color: var(--red); }
.badge.grey { background: rgba(154,163,178,.15); color: var(--muted); }
.badge.blue { background: rgba(79,140,255,.15); color: var(--primary); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50; overflow: auto; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: var(--shadow); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.close-x { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }

/* Toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--primary); padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow); min-width: 220px; animation: slideIn .18s ease; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.mono { font-variant-numeric: tabular-nums; }

/* ---- Auth ---- */
.auth-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg); z-index: 100; }
.auth-card { width: 100%; max-width: 380px; }
.sidebar-user { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 8px 4px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.sidebar-user + .sidebar-foot { margin-top: 0; }
.auth-links a { color: var(--primary); text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }

/* ---- Grouped sidebar (MarketMan-style) ---- */
.nav-group { margin: 14px 8px 4px; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* ---- COGS report ---- */
.banner-info { background: rgba(79,140,255,.10); border: 1px solid rgba(79,140,255,.35); color: var(--text); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 13px; }
.banner-info a { color: var(--primary); }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: baseline; }
.cogs-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0; margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; text-align: center; }
.cogs-stats > div { border-right: 1px solid var(--border); padding: 0 8px; }
.cogs-stats > div:last-child { border-right: none; }
.cogs-stat-value { font-size: 19px; font-weight: 700; margin-top: 4px; }
.cogs-pct { font-size: 15px; font-weight: 700; margin-top: 2px; }
tr.filter-row th { padding: 6px 10px; background: var(--surface); }
tr.filter-row input { padding: 6px 8px; font-size: 12px; }

/* ---- Card-wall dashboard (MarketMan-style) ---- */
.dash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1280px) { .dash-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-link { color: var(--primary); font-size: 12px; text-decoration: none; white-space: nowrap; }
.card-link:hover { text-decoration: underline; }
.mini-row { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.mini-stat { flex: 1; min-width: 110px; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.mini-label { color: var(--muted); font-size: 11px; }
.mini-value { font-size: 18px; font-weight: 700; margin-top: 3px; }
.mini-value.good { color: var(--green); }
.mini-value.bad { color: var(--red); }
.mini-value.accent { color: var(--primary); }
.mini-chart { width: 100%; display: block; }
.dash-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.dash-table th { text-align: left; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 6px; border-bottom: 1px solid var(--border); }
.dash-table td { padding: 7px 6px; border-bottom: 1px solid var(--border); }
.dash-table tr:last-child td { border-bottom: none; }
.dash-table th.num, .dash-table td.num { text-align: right; }

/* ---- Invoices tabs + scans list ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { background: none; border: none; color: var(--muted); padding: 10px 16px; font-weight: 700; font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent; letter-spacing: .03em; text-transform: uppercase; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.scan-row { display: flex; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.scan-row:last-child { border-bottom: none; }
.scan-row:hover { background: var(--surface-2); }
.scan-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.mx-pct { font-weight: 700; color: var(--green); font-size: 15px; margin-bottom: 4px; }
.mx-chip { display: inline-block; background: rgba(79,140,255,.10); border-radius: 4px; padding: 2px 6px; margin: 1px 2px 1px 0; font-size: 10.5px; color: var(--text); }

/* ---- Mobile app view (bottom tabs + drawer sidebar) ---- */
.mobile-nav { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 60; width: 240px; transition: left .2s ease; }
  .sidebar.open { left: 0; box-shadow: 0 0 50px rgba(0,0,0,.65); }
  .content { padding: 16px 14px 84px; }
  .mobile-nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--surface); border-top: 1px solid var(--border); z-index: 55; padding-bottom: env(safe-area-inset-bottom); }
  .mobile-nav a, .mobile-nav button { flex: 1; background: none; border: none; color: var(--muted); text-align: center; padding: 8px 0 9px; font-size: 19px; text-decoration: none; cursor: pointer; }
  .mobile-nav span { display: block; font-size: 10px; margin-top: 2px; }
  .mobile-nav .active { color: var(--primary); }
  .dash-grid, .two-col { grid-template-columns: 1fr !important; }
  .page-title { font-size: 19px; }
  .modal { max-width: 96vw; }
}

/* ---- Nory-style sales insights ---- */
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.date-nav { display: flex; gap: 6px; align-items: center; }
.delta { font-weight: 700; font-size: 12px; padding: 2px 7px; border-radius: 6px; }
.delta.up { color: var(--green); background: rgba(62,207,142,.12); }
.delta.down { color: var(--red); background: rgba(255,92,92,.12); }
.seg-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface-2); }
.seg-bar span { display: block; height: 100%; }
.seg-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
@media (max-width: 1100px) { .grid[style*="2fr 2fr 1fr"] { grid-template-columns: 1fr !important; } }

/* ---- Flash P&L ---- */
.chip { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: 12.5px; color: var(--muted); }
.chip strong { color: var(--text); }
.pnl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; align-items: start; }
.pnl-card h3 { font-size: 14.5px; }
.pnl-row { border-top: 1px solid var(--border); padding: 10px 0 8px; }
.pnl-row-head { display: flex; justify-content: space-between; align-items: center; }
.pnl-val { font-size: 19px; font-weight: 700; margin-top: 3px; }
.pnl-pct { float: right; font-size: 17px; }
.pnl-sub { display: flex; justify-content: space-between; margin-top: 6px; }
.pnl-box { background: var(--surface-2); border-radius: 6px; padding: 3px 8px; font-size: 11.5px; color: var(--muted); }

/* ---- Order sheet (Nory-style) ---- */
.order-row { border-bottom: 1px solid var(--border); padding: 12px 0; }
.order-row:last-child { border-bottom: none; }
.order-row-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pack-chip { background: #2a2f3a; border-radius: 6px; padding: 2px 8px; font-size: 11px; margin-left: 8px; color: var(--text); }
.stepper { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stepper button { background: var(--surface-2); border: none; color: var(--text); width: 34px; height: 32px; font-size: 16px; cursor: pointer; }
.stepper span { min-width: 40px; text-align: center; font-weight: 700; }
.usage-strip { display: flex; gap: 14px; align-items: center; margin-top: 8px; overflow-x: auto; }
.usage-cell { text-align: center; font-size: 12px; color: var(--green); min-width: 32px; }
.usage-cell em { display: block; font-style: normal; color: var(--green); font-size: 10.5px; opacity: .85; }
.cover-banner { margin-top: 8px; background: rgba(62,207,142,.10); border: 1px solid rgba(62,207,142,.35); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; }
.order-foot { position: sticky; bottom: 0; display: flex; gap: 10px; padding: 12px 0 4px; background: linear-gradient(transparent, var(--bg) 30%); margin-top: 12px; }
@media (max-width: 860px) { .order-foot { bottom: 64px; } }
.cart-badge { background: var(--amber); color: #1a1408; border-radius: 999px; padding: 1px 8px; font-size: 11.5px; font-weight: 800; margin-left: 6px; }
.cart-totals { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; margin-top: 14px; }
.cart-totals div { display: flex; justify-content: space-between; padding: 3px 0; }

/* ---- HelchPOS brand + collapsible Inventory tab ---- */
.brand-name { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-weight: 700; font-size: 20px; letter-spacing: -0.02em; }
.nav-drop { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: none; color: var(--muted); padding: 9px 12px; border-radius: 8px; font-size: 14px; cursor: pointer; text-align: left; }
.nav-drop:hover { background: var(--surface-2); color: var(--text); }
.drop-arrow { margin-left: auto; font-size: 11px; }
.nav-sub { display: none; flex-direction: column; gap: 2px; padding-left: 14px; }
.nav-sub.open { display: flex; }

/* ---- Login page (Lightspeed-style, light theme) ---- */
.auth-screen { position: fixed; inset: 0; z-index: 100; overflow: auto; background: #f2f2f3; color: #18181b; display: block; padding: 0; }
.ls-bar { background: #000; display: flex; align-items: center; justify-content: space-between; padding: 15px 26px; }
.ls-brand { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-weight: 700; font-size: 21px; color: #fff; letter-spacing: -0.02em; }
.ls-help { color: #fff; font-size: 15px; text-decoration: none; }
.ls-card { background: #fff; border: 1px solid #e4e4e7; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.07); max-width: 860px; margin: 96px auto 0; padding: 52px 48px 56px; }
.ls-title { margin: 0 0 30px; font-size: 27px; font-weight: 700; color: #18181b; }
.ls-sub { margin: -18px 0 26px; color: #52525b; font-size: 15px; }
.ls-label { display: block; font-weight: 600; font-size: 15px; color: #27272a; margin: 20px 0 8px; }
.ls-input { width: 100%; background: #fff; border: 1px solid #d4d4d8; border-radius: 4px; padding: 13px 14px; font-size: 15px; color: #18181b; }
.ls-input:focus { outline: none; border-color: #4f46e5; box-shadow: 0 0 0 1px #4f46e5; }
.ls-row { display: flex; align-items: center; justify-content: space-between; margin-top: 30px; }
.ls-links a { color: #18181b; font-size: 15px; text-decoration: underline; }
.ls-btn { background: #4f46e5; color: #fff; border: none; border-radius: 6px; padding: 14px 32px; font-size: 15px; font-weight: 600; cursor: pointer; }
.ls-btn:hover { filter: brightness(1.08); }
.ls-err { color: #dc2626; font-size: 14px; margin: 14px 0 0; min-height: 18px; }
.ls-foot { text-align: center; margin: 28px 0 48px; }
.ls-foot a { color: #18181b; font-size: 15px; text-decoration: underline; }
@media (max-width: 920px) { .ls-card { margin: 40px 16px 0; padding: 32px 22px 40px; } }

/* ---- Team / timecards ---- */
.tc-day { font-weight: 700; font-size: 13.5px; padding: 14px 0 4px; color: var(--text); }
.tc-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.tc-row:last-child { border-bottom: none; }
.tc-avatar { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%; background: rgba(139,124,248,.18); color: #b3a9fb; font-weight: 700; font-size: 12.5px; flex: none; }
.tc-times { text-align: right; font-weight: 600; font-size: 13.5px; }
.tc-approve { background: #2a9d74; border-color: #2a9d74; color: #fff; }
