:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --surface-2: #f4f2ec;
  --border: rgba(0,0,0,0.08);
  --border-2: rgba(0,0,0,0.15);
  --text: #1a1a1a;
  --text-2: #5f5e5a;
  --text-3: #888780;
  --accent: #2a7d6e;
  --accent-bg: #e6f4f1;
  --danger: #a32d2d;
  --warn: #c17c3c;
  --warn-bg: #faf0e6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a; --surface: #252523; --surface-2: #2c2c2a;
    --border: rgba(255,255,255,0.1); --border-2: rgba(255,255,255,0.2);
    --text: #f0ede4; --text-2: #b4b2a9; --text-3: #888780;
    --accent-bg: #0d2e29;
  }
}
body.dark {
  --bg: #1a1a1a; --surface: #252523; --surface-2: #2c2c2a;
  --border: rgba(255,255,255,0.1); --border-2: rgba(255,255,255,0.2);
  --text: #f0ede4; --text-2: #b4b2a9; --text-3: #888780; --accent-bg: #0d2e29;
}
body.light {
  --bg: #fafaf7; --surface: #ffffff; --surface-2: #f4f2ec;
  --border: rgba(0,0,0,0.08); --border-2: rgba(0,0,0,0.15);
  --text: #1a1a1a; --text-2: #5f5e5a; --text-3: #888780; --accent-bg: #e6f4f1;
}
* { box-sizing: border-box; }
body { margin:0; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif; background:var(--bg); color:var(--text); font-size:15px; line-height:1.6; }
.app { max-width:1100px; margin:0 auto; padding:2rem 1.25rem; }

.hdr { display:flex; justify-content:space-between; align-items:center; margin-bottom:1.5rem; gap:1rem; flex-wrap:wrap; }
.hdr-brand { display:flex; align-items:center; gap:12px; }
.hdr-app { font-size:20px; font-weight:500; letter-spacing:-0.3px; }
.sub { font-size:13px; color:var(--text-2); margin-top:2px; }

.stats { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:12px; margin-bottom:1.5rem; }
.stat { background:var(--surface-2); border-radius:8px; padding:1rem; }
.stat-l { font-size:13px; color:var(--text-2); margin-bottom:4px; }
.stat-v { font-size:24px; font-weight:500; font-variant-numeric:tabular-nums; }

.card { background:var(--surface); border:0.5px solid var(--border); border-radius:12px; padding:1rem 1.25rem; margin-bottom:1.25rem; }
.card-title { font-size:15px; font-weight:500; margin-bottom:12px; }
.grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(160px,1fr)); gap:10px; margin-bottom:10px; }
.grid-3 { grid-template-columns:repeat(3,1fr); }
.row { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.field { display:flex; flex-direction:column; gap:4px; }
.field-label { font-size:12px; color:var(--text-2); }

input, select, button { font-family:inherit; font-size:14px; }
input[type="text"], input[type="number"], input[type="date"], select {
  height:36px; padding:0 10px; border:0.5px solid var(--border-2);
  border-radius:8px; background:var(--surface); color:var(--text);
}
input:focus, select:focus { outline:none; box-shadow:0 0 0 2px var(--accent); }
button {
  height:36px; padding:0 16px; border:0.5px solid var(--border-2);
  border-radius:8px; background:transparent; color:var(--text); cursor:pointer; font-weight:500;
}
button:hover { background:var(--surface-2); }
button:active { transform:scale(0.98); }
.btn-primary { background:var(--text); color:var(--surface); border-color:var(--text); }
.btn-primary:hover { opacity:0.85; background:var(--text); }

.toolbar { display:flex; gap:10px; margin-bottom:1rem; flex-wrap:wrap; align-items:center; }
.toolbar-title { font-size:16px; font-weight:500; flex:1; }

.list-card { padding:0; overflow:hidden; }
table { width:100%; border-collapse:collapse; font-size:13px; }
th { text-align:left; padding:12px; font-weight:500; background:var(--surface-2); color:var(--text-2); }
th.right { text-align:right; }
td { padding:12px; border-top:0.5px solid var(--border); vertical-align:middle; }
td.right { text-align:right; font-variant-numeric:tabular-nums; }
.admin-col { width:80px; text-align:right; }
.small-btn { height:24px; padding:0 10px; font-size:12px; }
.del-btn { height:24px; padding:0 8px; font-size:14px; border:none; color:var(--text-3); }
.del-btn:hover { color:var(--danger); background:transparent; }
.empty { padding:2rem 1rem; text-align:center; color:var(--text-2); font-size:14px; }

/* Progress bar for filament remaining */
.spool-info { display:flex; flex-direction:column; gap:4px; }
.spool-label { font-weight:500; }
.spool-sub { font-size:11px; color:var(--text-3); }
.progress-wrap { width:120px; }
.progress-bar { height:6px; background:var(--surface-2); border-radius:3px; overflow:hidden; }
.progress-fill { height:100%; border-radius:3px; background:var(--accent); transition:width 0.3s; }
.progress-fill.warn { background:var(--warn); }
.progress-fill.danger { background:var(--danger); }
.progress-label { font-size:11px; color:var(--text-3); margin-top:2px; }

/* Category pill */
.cat-pill { background:var(--surface-2); padding:3px 10px; border-radius:6px; font-size:12px; text-transform:capitalize; }
.cat-pill.crystal { background:#f0e8ff; color:#5a3a8a; }
.cat-pill.engraveable { background:#e8f4ff; color:#1a5a8a; }
.cat-pill.filament { background:#fff0e0; color:#8a4a00; }
.cat-pill.engraved { background:#e8f4ff; color:#1a5a8a; }
.cat-pill.printed { background:#fff0e0; color:#8a4a00; }
body.dark .cat-pill.crystal { background:#2d1a4a; color:#c8a0ff; }
body.dark .cat-pill.engraveable { background:#0d2a40; color:#60b0ff; }
body.dark .cat-pill.filament { background:#3a2000; color:#ffb060; }

/* Calc table */
.calc-table { width:100%; border-collapse:collapse; font-size:14px; margin-bottom:0.5rem; }
.calc-table td, .calc-table th { padding:8px 4px; border-bottom:0.5px solid var(--border); }
.calc-table th { font-weight:500; color:var(--text-2); font-size:12px; background:none; padding-top:0; }
.calc-table td.right, .calc-table th.right { text-align:right; font-variant-numeric:tabular-nums; }
.total-row td { border-top:1px solid var(--border-2); border-bottom:none; padding-top:12px; }
.highlight-row td { background:var(--accent-bg); color:var(--accent); font-weight:500; }
.highlight-row td:first-child { border-radius:6px 0 0 6px; padding-left:8px; }
.highlight-row td:last-child { border-radius:0 6px 6px 0; padding-right:8px; }
.badge { background:var(--accent); color:white; font-size:10px; padding:2px 6px; border-radius:4px; font-weight:600; margin-left:6px; vertical-align:middle; }
.log-form { border-top:0.5px solid var(--border); padding-top:1rem; }

/* Tabs */
.tabs { display:flex; gap:4px; margin-bottom:1.25rem; border-bottom:1px solid var(--border); padding-bottom:0; overflow-x:auto; }
.tab { background:none; border:none; border-bottom:2px solid transparent; border-radius:0; padding:8px 16px; font-size:14px; font-weight:500; color:var(--text-2); cursor:pointer; margin-bottom:-1px; white-space:nowrap; }
.tab:hover { color:var(--text); background:none; }
.tab.active { color:var(--accent); border-bottom-color:var(--accent); }

/* Modal */
.modal-bg { position:fixed; inset:0; background:rgba(0,0,0,0.55); display:flex; align-items:center; justify-content:center; padding:1rem; z-index:100; }
.modal { background:var(--surface); border-radius:12px; padding:1.25rem; max-width:520px; width:100%; max-height:90vh; overflow-y:auto; }
.modal-hdr { display:flex; justify-content:space-between; align-items:center; margin-bottom:1rem; }
.modal-title { font-size:16px; font-weight:500; }
.modal-close { border:none; background:none; font-size:20px; cursor:pointer; color:var(--text-2); line-height:1; padding:0; }
.modal-actions { display:flex; gap:8px; justify-content:flex-end; margin-top:1rem; }

/* BOM editor */
.bom-section { margin-top:12px; }
.bom-row { display:grid; grid-template-columns:1fr 1fr 80px 32px; gap:6px; margin-bottom:6px; align-items:center; }
.bom-hdr { font-size:12px; color:var(--text-3); margin-bottom:4px; display:grid; grid-template-columns:1fr 1fr 80px 32px; gap:6px; }
.add-bom-btn { background:none; border:0.5px dashed var(--border-2); color:var(--text-2); font-size:12px; height:30px; width:100%; margin-top:4px; }
.add-bom-btn:hover { background:var(--surface-2); }

/* Alerts */
.banner { background:var(--warn-bg); color:var(--warn); padding:10px 14px; border-radius:8px; font-size:13px; margin-bottom:1rem; }
.low-stock-item { display:inline-block; margin-right:8px; }

/* Header actions */
.hdr-actions { display:flex; align-items:center; gap:8px; }
.logout-btn { font-size:13px; color:var(--text-2); text-decoration:none; padding:6px 12px; border:0.5px solid var(--border-2); border-radius:8px; white-space:nowrap; }
.logout-btn:hover { background:var(--surface-2); color:var(--text); }
.theme-btn { width:36px; height:36px; padding:0; font-size:16px; border:0.5px solid var(--border-2); border-radius:8px; }
body.dark { color-scheme:dark; }
body.light { color-scheme:light; }

/* Role gating */
body[data-role="viewer"] .admin-only { display:none !important; }

/* Scan tab */
.scan-wrap { max-width: 440px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.scan-header { text-align: center; }
#scan-reader { border-radius: 12px; overflow: hidden; border: 0.5px solid var(--border); }
#scan-reader video { border-radius: 12px; }
.scan-result { background: var(--surface); border: 0.5px solid var(--border); border-radius: 12px; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.scan-item-name { font-size: 20px; font-weight: 600; text-align: center; }
.scan-item-meta { font-size: 13px; color: var(--text-2); text-align: center; }
.scan-item-stock { font-size: 28px; font-weight: 500; text-align: center; font-variant-numeric: tabular-nums; }
.scan-actions { display: flex; flex-direction: column; gap: 10px; }
.scan-qty-row { display: flex; align-items: center; justify-content: center; gap: 12px; }
.scan-qty-btn { width: 44px; height: 44px; font-size: 22px; border-radius: 50%; padding: 0; display: flex; align-items: center; justify-content: center; }
.scan-qty-input { width: 80px; height: 44px; font-size: 20px; text-align: center; border-radius: 10px; }
.scan-action-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.scan-action { height: 52px; font-size: 16px; font-weight: 600; border-radius: 10px; border: none; cursor: pointer; }
.add-action { background: var(--accent); color: white; }
.add-action:hover { opacity: 0.9; }
.remove-action { background: var(--danger); color: white; }
.remove-action:hover { opacity: 0.9; }
.scan-feedback { text-align: center; font-size: 15px; font-weight: 500; padding: 10px; border-radius: 8px; background: var(--accent-bg); color: var(--accent); }
.scan-feedback.error { background: #fde8e8; color: var(--danger); }
.scan-again-btn { width: 100%; height: 44px; font-size: 15px; border-radius: 10px; }

/* SKU + QR */
.sku-cell { font-family: monospace; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.qr-btn { height: 22px; padding: 0 7px; font-size: 11px; border-color: var(--border-2); }
.qr-modal-body { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 0.5rem 0; }
.qr-label-name { font-size: 15px; font-weight: 500; text-align: center; }
.qr-label-sku { font-family: monospace; font-size: 13px; color: var(--text-2); letter-spacing: 0.05em; }
.qr-canvas-wrap { padding: 12px; background: white; border-radius: 8px; border: 0.5px solid var(--border); }

@media print {
  body * { visibility: hidden; }
  .print-label, .print-label * { visibility: visible; }
  .print-label {
    position: fixed; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  }
  .print-label canvas { width: 180px !important; height: 180px !important; }
  .print-label .qr-label-name { font-size: 14pt; font-weight: bold; }
  .print-label .qr-label-sku { font-size: 11pt; font-family: monospace; }
}

/* Inline threshold editor */
.threshold-cell { display:flex; align-items:center; justify-content:flex-end; gap:6px; }
.threshold-val { font-variant-numeric:tabular-nums; cursor:pointer; border-bottom:1px dashed var(--border-2); padding-bottom:1px; }
.threshold-val:hover { color:var(--accent); border-bottom-color:var(--accent); }
.threshold-input { width:60px; height:26px; padding:0 6px; font-size:12px; text-align:right; }
.threshold-save { height:26px; padding:0 8px; font-size:12px; }

/* Alerts */
.alert-row td { background:var(--warn-bg); }
.alert-deficit { color:var(--danger); font-weight:500; }

/* Produce/Sell buttons */
.action-btns { display:flex; gap:4px; }
.produce-btn { height:24px; padding:0 8px; font-size:11px; color:var(--accent); border-color:var(--accent); }
.sell-btn { height:24px; padding:0 8px; font-size:11px; }
