:root {
  /* Snacks for Change brand palette */
  --teal: #0c5460;       /* deep teal — frame / headings */
  --teal-2: #308484;     /* mid teal — panels / charts */
  --orange: #d86c30;     /* brand accent / CTA */
  --gold: #e4a848;       /* highlight */

  --bg: #eef3f3;
  --surface: #ffffff;
  --surface-2: #e9f0f0;
  --border: #d7e2e2;
  --text: #14343b;
  --muted: #5f7a7f;
  --accent: #d86c30;
  --accent-dim: #fbe9dc;
  --green: #2f8f6f;
  --amber: #c8871c;
  --red: #cf4a3c;
  --purple: #8a6fc0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(12,84,96,.08), 0 1px 2px rgba(12,84,96,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--orange); text-decoration: none; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 224px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 800; font-size: 16px; color: var(--teal); letter-spacing: -.2px; }
.brand .logo { width: 34px; height: 46px; object-fit: contain; flex-shrink: 0; }
.brand-sub { color: var(--orange); font-size: 11px; font-weight: 700; margin: 6px 0 22px 45px; letter-spacing: .3px; text-transform: uppercase; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--muted); font-weight: 600; margin-bottom: 2px; cursor: pointer;
}
.nav a:hover { background: var(--surface-2); color: var(--teal); }
.nav a.active { background: var(--accent-dim); color: var(--orange); }
.nav .ico { width: 18px; text-align: center; }

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 15px 28px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: rgba(255,255,255,.88); backdrop-filter: blur(8px); z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; color: var(--teal); font-weight: 800; }
/* Fill the available width so wide tables (Inventory, Database) reach the page edge
   instead of scrolling right. Cards keep their own max-width for readability. */
.content { padding: 24px 28px 60px; max-width: 100%; }

/* Buttons */
.btn {
  background: var(--surface); color: var(--teal); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 13px; font-weight: 700;
}
.btn:hover { border-color: var(--teal-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #c65f26; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Cards / KPIs */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; font-weight: 700; }
.kpi .value { font-size: 28px; font-weight: 800; margin-top: 6px; color: var(--teal); }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi .value.red { color: var(--red); }
.kpi .value.amber { color: var(--amber); }
.kpi .value.green { color: var(--green); }

.section-title { font-size: 15px; font-weight: 800; margin: 28px 0 12px; color: var(--teal); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 11px; text-align: left; white-space: nowrap; }
thead th { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); background: #f5f9f9; }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f5faf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: .3px; }
.badge.critical { background: rgba(207,74,60,.14); color: var(--red); }
.badge.soon { background: rgba(228,168,72,.20); color: var(--amber); }
.badge.ok { background: rgba(47,143,111,.15); color: var(--green); }
.badge.overstock { background: rgba(138,111,192,.15); color: var(--purple); }
.badge.none { background: var(--surface-2); color: var(--muted); }
.badge.draft { background: var(--surface-2); color: var(--muted); }
.badge.placed { background: rgba(48,132,132,.15); color: var(--teal-2); }
.badge.received { background: rgba(47,143,111,.15); color: var(--green); }
.badge.cancelled { background: rgba(207,74,60,.12); color: var(--red); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.on { background: var(--green); }
.dot.off { background: var(--red); }

/* Fill bar */
.fill { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 70px; }
.fill > span { display: block; height: 100%; background: var(--green); }
.fill.low > span { background: var(--gold); }
.fill.crit > span { background: var(--red); }

/* Inputs */
input[type=number], input[type=text], select, textarea {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 6px 9px; border-radius: 8px; font-size: 13px; width: 90px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal-2); box-shadow: 0 0 0 3px rgba(48,132,132,.12); }
input[type=text] { width: 220px; }
.qty-input { width: 68px; text-align: right; }

/* Machine slot grid */
.machines { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.slot-line { display: grid; grid-template-columns: 46px 1fr 84px 40px; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.slot-line:last-child { border-bottom: none; }
.slot-line .aisle { color: var(--muted); font-variant-numeric: tabular-nums; }
.slot-line .stk { text-align: right; font-variant-numeric: tabular-nums; }

/* Chart */
.chart { width: 100%; height: 160px; }
.chart .bar { fill: var(--teal-2); }
.chart .bar:hover { fill: var(--teal); }
.chart-axis { fill: var(--muted); font-size: 10px; }

/* Toast */
#toast { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--teal-2); padding: 11px 16px; border-radius: 9px; box-shadow: 0 4px 16px rgba(12,84,96,.14); min-width: 240px; animation: slidein .2s ease; }
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.empty { padding: 40px; text-align: center; color: var(--muted); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.pill { background: var(--surface-2); border: 1px solid var(--border); padding: 4px 10px; border-radius: 999px; font-size: 12px; color: var(--muted); }
.provider-pill { background: rgba(48,132,132,.13); color: var(--teal); border-color: transparent; font-weight: 700; }
code { background: var(--surface-2); border-radius: 4px; padding: 1px 4px; }

/* Mobile drawer */
.menu-btn { display: none; background: none; border: 0; font-size: 22px; line-height: 1; color: var(--teal); cursor: pointer; padding: 0 6px 0 0; }
.scrim { display: none; }

@media (max-width: 860px) {
  .menu-btn { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh; z-index: 40;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 6px 0 30px rgba(12,84,96,.18);
  }
  .sidebar.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(12,84,96,.35); z-index: 35; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 16px; }
  .kpis { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .machines { grid-template-columns: 1fr; }
  .topbar .btn.sm { padding: 5px 8px; }
  .topbar .pill { display: none; }
}
@media (max-width: 480px) {
  .kpi .value { font-size: 22px; }
  th, td { padding: 8px 10px; }
}

/* Product thumbnails — contain so the whole product photo is visible (not cropped) */
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: contain; background: #fff; border: 1px solid var(--border); vertical-align: middle; padding: 2px; }
.thumb.lg { width: 56px; height: 56px; }
.prodcell { display: flex; align-items: center; gap: 10px; }

/* Frozen-header (sticky) tables — Database merge view */
.table-wrap.sticky { max-height: 72vh; overflow: auto; }
.table-wrap.sticky thead th { position: sticky; top: 0; z-index: 3; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.linklike { color: var(--orange); cursor: pointer; font-weight: 700; border: none; background: none; padding: 0; font-size: 13px; }
.linklike:hover { text-decoration: underline; }

/* Sales & Cash Flow — impact banner + monthly sub-tables */
.impact-banner { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  background: linear-gradient(120deg, rgba(48,132,132,.10), rgba(216,108,48,.08)); border-color: transparent; }
.impact-title { font-size: 20px; font-weight: 800; color: var(--teal); }
.impact-net { text-align: right; }
.impact-net .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; font-weight: 700; }
.impact-net .value { font-size: 30px; font-weight: 800; }
.impact-net .value.green { color: var(--green); } .impact-net .value.red { color: var(--red); }
table.subtable { margin: 4px 0; background: var(--surface-2); border-radius: 8px; }
table.subtable th { background: transparent; }
.value.green { color: var(--green); } .value.red { color: var(--red); }
b.green, .green { color: var(--green); } b.red, .red { color: var(--red); } b.amber, .amber { color: var(--amber); }

/* Sites */
.sites { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.site-card .activity { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow: auto; }
.act-line { font-size: 12px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.act-line:last-child { border-bottom: none; }

/* Token status + capture snippets (Settings) */
.token-warn { background: rgba(207,74,60,.16); color: var(--red); border-color: transparent; font-weight: 800; text-decoration: none; }
.token-warn:hover { background: rgba(207,74,60,.26); }
.tok-steps { margin: 8px 0 12px; padding-left: 20px; font-size: 12.5px; }
.tok-steps li { margin: 3px 0; }
.tok-detail.bad { color: var(--red); font-weight: 700; }
.snippet-row { display: flex; gap: 8px; align-items: flex-start; }
.snippet { flex: 1; display: block; padding: 8px; background: var(--surface-2); border-radius: 6px; font-size: 11px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.copy-snip { white-space: nowrap; }

/* Insight cards */
.insight { border-left: 3px solid var(--border); }
.insight.high { border-left-color: var(--red); }
.insight.medium { border-left-color: var(--gold); }
.insight.low { border-left-color: var(--teal-2); }

/* Auth gate (login / 2FA / setup) */
.auth-gate { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(140deg, var(--teal) 0%, #0a3b45 100%); }
.auth-card { background: var(--surface); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); width: 100%; max-width: 380px; padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: var(--teal); margin-bottom: 18px; }
.auth-brand img { width: 30px; height: 40px; object-fit: contain; }
.auth-card h2 { margin: 0 0 4px; color: var(--teal); font-size: 20px; }
.auth-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; line-height: 1.45; }
.auth-card input { width: 100%; margin-bottom: 10px; padding: 10px 12px; font-size: 14px; }
.auth-btn { width: 100%; margin-top: 6px; padding: 11px; }
.auth-err { background: rgba(207,74,60,.12); color: var(--red); border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 14px; }
.auth-qr { display: block; width: 180px; height: 180px; margin: 4px auto 12px; border: 1px solid var(--border); border-radius: 8px; }
.auth-secret { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 14px; word-break: break-all; }
.auth-secret code { font-size: 12px; }
.auth-codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 16px; }
.auth-codes span { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; background: var(--surface-2); padding: 8px; border-radius: 6px; text-align: center; letter-spacing: 1px; }

/* Restock print options dialog */
.print-opts { display: flex; flex-direction: column; gap: 16px; }
.opt-group { display: flex; flex-direction: column; gap: 6px; }
.opt-label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.print-opts label { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; cursor: pointer; line-height: 1.35; }
.print-opts input[type=checkbox], .print-opts input[type=radio] { width: auto; margin-top: 2px; flex-shrink: 0; }

/* Notification modal (replaces toasts) */
.modal-card.note { max-width: 440px; }
.modal-card.note.err { border-top: 4px solid var(--red); }
.modal-card.note.ok { border-top: 4px solid var(--green); }
.note-row { display: flex; gap: 12px; align-items: flex-start; }
.note-ico { font-size: 22px; line-height: 1.1; flex-shrink: 0; }
.note-msg { font-size: 14px; line-height: 1.45; padding-top: 1px; word-break: break-word; }

/* Modal (purchase-history drill-down) */
.modal-backdrop { position: fixed; inset: 0; background: rgba(12,84,96,.4); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: var(--surface); border-radius: var(--radius); box-shadow: 0 10px 40px rgba(12,84,96,.3); max-width: 640px; width: 100%; max-height: 82vh; overflow: auto; padding: 22px 24px; }
.modal-card h3 { margin: 0 0 4px; color: var(--teal); }
.modal-close { float: right; }

/* Print (restock run sheet) */
@media print {
  .sidebar, .topbar, .scrim, .btn, .nav { display: none !important; }
  .main, .content { padding: 0 !important; max-width: none !important; }
  body { background: #fff; }
  .card, .table-wrap { box-shadow: none; border-color: #999; break-inside: avoid; }
  .no-print { display: none !important; }
}
