* { box-sizing: border-box; margin: 0; }
:root {
  --bg: #f4f6f8; --panel: #fff; --border: #dde3ea; --text: #1d2733; --muted: #64748b;
  --accent: #2563eb; --accent-dark: #1d4ed8; --green: #16a34a; --red: #dc2626; --amber: #d97706;
  --radius: 8px; --shadow: 0 1px 3px rgba(16,24,40,.08);
}
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }

/* login */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); padding: 36px; border-radius: 12px; box-shadow: var(--shadow); width: 340px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; text-align: center; margin-bottom: 8px; }

/* layout */
#app { display: flex; min-height: 100vh; }
/* icon rail navigation */
#sidebar { width: 64px; background: #111827; color: #e5e7eb; display: flex; flex-direction: column; justify-content: space-between; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.rail { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 0; }
.rail-footer { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 0; }
.brand-icon { color: #fff; padding: 4px 0 8px; }
.brand-icon svg { width: 26px; height: 26px; }
.rail-btn { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: transparent; border: 0; border-radius: 10px; color: #cbd5e1; cursor: pointer; text-decoration: none; flex-shrink: 0; }
.rail-btn svg { width: 22px; height: 22px; }
.rail-btn:hover { background: #1f2937; color: #fff; }
.rail-btn.active { background: var(--accent); color: #fff; }
.rail-group { position: relative; }
.flyout { display: none; position: absolute; left: 100%; top: -6px; margin-left: 8px; background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 34px rgba(0,0,0,.2); min-width: 210px; padding: 8px; z-index: 60; }
.flyout::before { content: ''; position: absolute; left: -8px; top: 0; width: 8px; height: 100%; }
.rail-group:hover .flyout, .rail-group.open .flyout { display: block; }
.flyout-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 4px 10px 8px; font-weight: 600; }
.flyout a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 14px; white-space: nowrap; }
.flyout a:hover { background: #f1f5f9; }
.flyout a.active { background: var(--accent); color: #fff; }
.rail-user { width: 34px; height: 34px; border-radius: 50%; background: #374151; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; }
#main { flex: 1; padding: 24px 32px; max-width: 1640px; }

/* elements */
h2 { font-size: 20px; margin-bottom: 4px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h3 { font-size: 15px; font-weight: 600; }
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
.card table { margin: 0 -18px; width: calc(100% + 36px); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f1f5f9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.btn { background: #fff; border: 1px solid var(--border); color: var(--text); padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #374151; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.checkbox-label { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-label input { width: auto; }
/* Role editor: per-area None/View/Full control */
.area-row { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.area-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.area-label { font-weight: 600; font-size: 13px; }
.seg-group { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg { font-size: 12px; padding: 4px 12px; cursor: pointer; border-right: 1px solid var(--border); user-select: none; }
.seg:last-child { border-right: none; }
.seg input { display: none; }
.seg.on { background: var(--accent); color: #fff; }
.area-extras { margin-top: 6px; padding-left: 2px; display: flex; flex-wrap: wrap; gap: 2px 16px; }
.checkbox-label.sub { font-size: 12px; color: var(--muted); }
/* User editor: per-user permission overrides (Inherit / Allow / Deny) */
details.user-adv { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
details.user-adv > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: #374151; user-select: none; }
.ov-group-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 0 2px; }
.ov-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; padding: 1px 0; font-size: 12.5px; }
.ov-row span { flex: 1; }
.ov-row select { width: 150px; padding: 3px 8px; font-size: 12px; }
.ov-row select.ov-set { border-color: var(--accent); background: #eff6ff; font-weight: 600; }
.banner-warn { background: #fef3c7; border: 1px solid #fcd34d; color: #92400e; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
/* Interactive walkthroughs */
.wt-block { position: fixed; inset: 0; z-index: 200; }
.wt-mask { position: fixed; z-index: 201; border-radius: 8px; box-shadow: 0 0 0 9999px rgba(15,23,42,.55); outline: 3px solid var(--accent); outline-offset: 0; pointer-events: none; display: none; transition: top .2s, left .2s, width .2s, height .2s; }
.wt-pop { position: fixed; z-index: 202; width: 340px; max-width: calc(100vw - 24px); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 18px 50px rgba(0,0,0,.30); padding: 14px 16px; }
.wt-head { font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.wt-body { font-size: 13px; line-height: 1.5; color: var(--text); }
.wt-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.wt-prog { font-size: 12px; color: var(--muted); }
.wt-btns { display: flex; gap: 6px; }
.wt-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.wt-item { display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); cursor: pointer; }
.wt-item:hover { border-color: var(--accent); background: #f8fafc; }
.wt-ic { font-size: 22px; line-height: 1; }
.wt-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.wt-t { font-weight: 600; font-size: 14px; }
.wt-d { font-size: 12px; color: var(--muted); }
.wt-go { color: var(--accent); font-weight: 600; font-size: 13px; white-space: nowrap; }
.field-hint { font-size: 11px; color: var(--muted); line-height: 1.3; }
.ico { width: 1em; height: 1em; vertical-align: -0.14em; flex-shrink: 0; }
.namelink { color: var(--accent); text-decoration: none; }
.namelink:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.open { background: #dbeafe; color: #1e40af; }
.badge.partial { background: #fef3c7; color: #92400e; }
.badge.fulfilled, .badge.received { background: #dcfce7; color: #166534; }
.badge.paid { background: #d1fae5; color: #065f46; }
.badge.cancelled, .badge.removed { background: #f3f4f6; color: #6b7280; }
.badge.in_stock { background: #dcfce7; color: #166534; }
.badge.sold { background: #e0e7ff; color: #3730a3; }
.badge.low { background: #fee2e2; color: #991b1b; }
.badge.defective { background: #fef3c7; color: #92400e; }
.badge.replaced { background: #dcfce7; color: #166534; }
.badge.repaired { background: #dbeafe; color: #1e40af; }
.badge.refunded { background: #e0e7ff; color: #3730a3; }
.badge.rejected { background: #f3f4f6; color: #6b7280; }
.badge.quote { background: #f0f9ff; color: #0369a1; }

.error { color: var(--red); font-size: 13px; min-height: 1em; }
.muted { color: var(--muted); }
.right { text-align: right; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { width: 240px; }
.toolbar select { width: auto; }

/* modal */
#modal-root .overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 600px; max-width: 100%; padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal.wide { width: 860px; }
.modal h3 { margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); animation: fadein .2s; }
.toast.error { background: var(--red); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* product picker */
.picker { position: relative; }
.picker .suggestions { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); max-height: 220px; overflow-y: auto; z-index: 20; }
.picker .suggestions div { padding: 8px 10px; cursor: pointer; }
.picker .suggestions div:hover, .picker .suggestions div.active { background: #e6efff; }

/* keyboard hint chips */
.kbd { display: inline-block; font: 11px/1.7 ui-monospace, Menlo, Consolas, monospace; background: #f1f5f9; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; color: #334155; }
.shortcut-help td { padding: 8px 10px; vertical-align: top; }
.shortcut-help td:first-child { white-space: nowrap; }

/* product detail two-column layout (stacks on phones) */
.prod-2col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.price-table th, .price-table td { padding: 6px 12px; }
.price-table input { padding: 5px 8px; }

/* command palette */
.cmdk-overlay { align-items: flex-start; padding: 10vh 16px; }
.cmdk { background: #fff; border-radius: 12px; width: 600px; max-width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow: hidden; }
.cmdk-input { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 16px 18px; font-size: 16px; }
.cmdk-input:focus { outline: none; }
.cmdk-results { max-height: 52vh; overflow-y: auto; }
.cmdk-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; cursor: pointer; }
.cmdk-item.active { background: #eef4ff; }
.cmdk-type { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: #fff; background: var(--muted); border-radius: 4px; padding: 2px 6px; flex-shrink: 0; min-width: 64px; text-align: center; }
.cmdk-item.active .cmdk-type { background: var(--accent); }
.cmdk-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-meta { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.cmdk-empty { padding: 16px; }
.cmdk-hint { display: flex; gap: 16px; padding: 8px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }

/* live order totals on Sales / PO forms */
.order-totals { margin-top: 14px; display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }
.order-totals .grand { font-size: 17px; margin-top: 3px; }
/* order detail: Inflow-style stacked totals */
.so-totals { margin: 14px 0 0 auto; width: 300px; max-width: 100%; }
.so-totals .row { display: flex; justify-content: space-between; gap: 16px; padding: 4px 0; }
.so-totals .row.grand { font-size: 16px; font-weight: 600; }
.so-totals .row.grand span:last-child { font-weight: 700; }
.so-totals .row.balance { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; font-size: 16px; font-weight: 700; }
.so-totals .row.paylink { cursor: pointer; color: var(--accent); }
.so-totals .row.paylink:hover { text-decoration: underline; }

/* hide the product-list Cost column for users without cost visibility (column kept for layout stability) */
#product-table.hide-cost th:nth-child(5), #product-table.hide-cost td:nth-child(5) { display: none; }
.card > .actions, .form-grid > .actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* line editor */
.lines-table input { min-width: 64px; }
.lines-table .picker input { min-width: 200px; }
.scan-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding: 8px 12px; background: #eef4ff; border: 1px solid #cfe0f5; border-radius: 8px; }
.scan-row input { max-width: 340px; }

/* product image manager */
.pimg-wrap { position: relative; flex-shrink: 0; }
.pimg-wrap .pimg-actions { position: absolute; top: -6px; right: -6px; display: none; gap: 2px; }
.pimg-wrap:hover .pimg-actions { display: flex; }
.pimg-actions button { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 11px; line-height: 1; box-shadow: var(--shadow); }
.pimg-actions button:hover { background: #f1f5f9; }
#pimg { cursor: zoom-in; }

/* inline editing */
.inline-edit { cursor: text; border-bottom: 1px dashed transparent; border-radius: 3px; transition: background .12s; }
.inline-edit:hover { background: #eef4ff; border-bottom-color: var(--accent); }
.inline-input { font: inherit; padding: 2px 6px; border: 1.5px solid var(--accent); border-radius: 4px; }
h2 .inline-input { font-size: 20px; font-weight: 700; }

/* pill tabs (Inflow-style) */
.pill-tabs { display: inline-flex; gap: 4px; background: #e9eef4; border-radius: 999px; padding: 4px; margin-bottom: 18px; }
.pill-tabs a { padding: 7px 18px; border-radius: 999px; color: var(--text); text-decoration: none; font-size: 13px; font-weight: 500; }
.pill-tabs a:hover { background: #dde5ee; }
.pill-tabs a.active { background: var(--accent); color: #fff; }

/* Order → Pick → Ship pipeline */
.pipeline { display: flex; align-items: center; justify-content: flex-start; margin: 0 0 16px; padding: 14px 20px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.pl-step { display: flex; align-items: center; gap: 8px; }
.pl-dot { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; background: #e9eef4; color: var(--muted); border: 2px solid transparent; flex-shrink: 0; }
.pl-label { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.pl-step.done .pl-dot { background: var(--green); color: #fff; }
.pl-step.done .pl-label { color: var(--text); }
.pl-step.current .pl-dot { background: #fff; color: var(--accent); border-color: var(--accent); }
.pl-step.current .pl-label { color: var(--accent); }
.pl-bar { flex: 0 0 110px; height: 2px; background: var(--border); margin: 0 14px; }
.pl-bar.done { background: var(--green); }
.ship-toggle:hover { color: var(--accent); }

/* SO detail info card: Customer · Order · Invoicing + custom fields */
.so-info { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.info-col h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 9px; font-weight: 700; }
.info-line { display: flex; gap: 7px; align-items: flex-start; font-size: 13px; color: var(--text); margin-bottom: 6px; line-height: 1.45; }
.info-line .ico { color: var(--muted); margin-top: 2px; flex-shrink: 0; }
.info-line.info-name { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.info-cust { color: var(--accent); text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.info-cust:hover { text-decoration: underline; }
.info-cust .ico { width: .82em; height: .82em; color: var(--muted); }
.cf-section { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 13px; }
.cf-head { display: flex; justify-content: space-between; align-items: center; min-height: 22px; }
.cf-head h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0; font-weight: 700; }
.cf-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 28px; margin-top: 10px; }
.cf-item { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.cf-key { color: var(--muted); }
.cf-val { font-weight: 500; text-align: right; }
@media (max-width: 760px) { .so-info { grid-template-columns: 1fr; gap: 16px; } .cf-grid { grid-template-columns: 1fr; } }
/* SO form top: Customer · Order · Invoicing columns, mirroring the detail card */
.so-form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; align-items: start; margin-bottom: 12px; }
.so-fcol { display: flex; flex-direction: column; gap: 10px; }
.so-fcol h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0; font-weight: 700; }
@media (max-width: 760px) { .so-form-grid { grid-template-columns: 1fr; gap: 16px; } }

/* customer auto-populate chip on the SO form */
.cust-chip { font-size: 13px; color: var(--text); padding: 7px 0 2px; display: flex; flex-wrap: wrap; align-items: center; }
.cust-chip .ico { color: var(--muted); vertical-align: -.14em; margin-right: 3px; }
.cust-chip .dot { color: var(--muted); }

/* Picking modal: per-line bin allocation */
.pick-list { display: flex; flex-direction: column; gap: 10px; max-height: 56vh; overflow-y: auto; }
.pick-line { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.pick-head { font-size: 13px; margin-bottom: 4px; }
.pick-prog { color: var(--muted); font-size: 12px; }
.pick-prog.done { color: var(--green); font-weight: 600; }
.pick-bin { display: flex; align-items: center; gap: 12px; padding: 4px 0; font-size: 13px; }
.pick-binname { min-width: 170px; font-weight: 500; }
.pick-bin .muted { flex: 1; }
.pick-bin .pick-qty { width: 90px; }
.bin-row td { font-size: 12px; color: var(--muted); padding-top: 3px; padding-bottom: 3px; background: #fafbfc; }
.star-toggle { cursor: pointer; color: var(--muted); font-size: 0.8em; vertical-align: 2px; user-select: none; }
.star-toggle.on { color: #f59e0b; }
.star-toggle:hover { color: #f59e0b; }
/* Operator-grade SO list */
.prio { color: #d4d9e0; font-size: 15px; }
.prio.on { color: #f59e0b; }
.so-fb { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.fb-unf { background: #fef3c7; color: #92400e; box-shadow: inset 0 0 0 1px #fcd34d; }
.fb-rts { background: #dbeafe; color: #1e40af; }
.fb-ful { background: #dcfce7; color: #166534; }
.fb-ship { background: #cffafe; color: #155e75; }
.fb-canc { background: #f3f4f6; color: #6b7280; }
.bal-paid { color: var(--green); font-weight: 700; }
.bal-part { color: var(--amber); font-weight: 700; }
.bal-due { color: var(--text); font-weight: 700; }
.mtag { font-size: 10px; font-weight: 600; border-radius: 5px; padding: 1px 6px; vertical-align: 1px; }
.mtag-paid { background: #dcfce7; color: #166534; }
.mtag-part { background: #fef3c7; color: #92400e; }
.mtag-due { background: #f1f5f9; color: #475569; }
.av { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.av-ok { background: #dcfce7; color: #166534; }
.av-vend { background: #dbeafe; color: #1e40af; }
.av-short { background: #fee2e2; color: #991b1b; }
/* Product Overview redesign (Direction D): KPI hero + calm bands */
.kpi-hero { display: grid; grid-template-columns: repeat(6, 1fr); border: 1px solid var(--border); border-radius: 12px; background: #fcfdfe; box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.kpi-tile { padding: 14px 18px; border-right: 1px solid var(--border); }
.kpi-tile:last-child { border-right: none; }
.kpi-tile.hl { background: #f0f7ff; box-shadow: inset 3px 0 0 var(--accent); }
.kpi-tile .kl { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kpi-tile .kv { font-size: 22px; font-weight: 750; margin-top: 3px; }
.kpi-tile.hl .kv { color: var(--accent); }
.kpi-tile.good .kv { color: var(--green); }
.kpi-tile.warn .kv { color: var(--amber); }
.kpi-tile.bad .kv { color: var(--red); }
.kpi-tile .ks { font-size: 12px; color: var(--muted); margin-top: 1px; }
.pband { display: grid; grid-template-columns: 210px 1fr; gap: 28px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 14px; }
.pband-head h3 { font-size: 15px; }
.pband-links { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; font-size: 12.5px; }
.pband-links a { color: var(--accent); text-decoration: none; }
.pband-links a:hover { text-decoration: underline; }
.pband-body { min-width: 0; }
.thumb-brand { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: linear-gradient(135deg, #dbeafe, #eef2ff); border: 1px solid #dbe4f5; }
.thumb-brand b { font-size: 17px; color: #3056b5; line-height: 1; }
.thumb-brand span { font-size: 9px; color: #7c93c4; text-transform: uppercase; letter-spacing: .04em; }
.price-table .cost-row td { border-bottom: 2px solid var(--border); font-weight: 600; }
.dl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 36px; }
.dl-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #eef2f6; font-size: 13.5px; }
@media (max-width: 980px) { .kpi-hero { grid-template-columns: repeat(3, 1fr); } .kpi-tile:nth-child(3) { border-right: none; } .pband { grid-template-columns: 1fr; gap: 12px; } .dl-grid { grid-template-columns: 1fr; } }
.gallery { display: flex; flex-wrap: wrap; gap: 10px; }
.gal-item { position: relative; width: 120px; height: 120px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fafbfc; }
.gal-item.is-default { border-color: #f59e0b; box-shadow: 0 0 0 1px #f59e0b; }
.gal-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gal-badge { position: absolute; top: 4px; left: 4px; background: #f59e0b; color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 10px; }
.gal-actions { position: absolute; top: 4px; right: 4px; display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.gal-item:hover .gal-actions { opacity: 1; }
.gal-actions button { width: 24px; height: 24px; border: none; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 12px; line-height: 1; }
.gal-actions button:hover { background: rgba(0,0,0,.85); }
.gal-add { width: 120px; height: 120px; border: 1px dashed var(--border); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); }
.gal-add:hover { border-color: var(--accent); color: var(--accent); }
.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fb-panel { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; width: 100%; margin-top: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: #fafbfc; }
.fb-panel.hidden { display: none; }
.fb-field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.fb-field select, .fb-field input { font-size: 13px; }
.fb-chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.fb-chip { display: inline-flex; align-items: center; gap: 6px; background: #eef2ff; color: #3730a3; border-radius: 12px; padding: 2px 10px; font-size: 12px; }
.fb-chip a { cursor: pointer; color: #6366f1; font-weight: 600; }
.fb-chip a:hover { color: #3730a3; }
.bal-card { display: flex; flex-wrap: wrap; gap: 28px; background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 10px; padding: 14px 20px; margin-bottom: 14px; }
.bal-cell { display: flex; flex-direction: column; gap: 2px; }
.bal-cell span { font-size: 12px; color: var(--muted); }
.bal-cell strong { font-size: 18px; }
.bal-cell.overdue strong { color: var(--red); }
.cust-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.cust-grid .card { margin: 0; }
.dl-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.dl-row:last-child { border-bottom: none; }
.dl-k { color: var(--muted); }
.dl-v { text-align: right; font-weight: 500; }
.aging { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.aging-cell { flex: 1; min-width: 120px; background: #fafbfc; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
.aging-cell span { font-size: 12px; color: var(--muted); }
.aging-cell.due { background: #ecfdf5; border-color: #a7f3d0; }
.dup-box { border: 1px solid #f59e0b; background: #fffbeb; border-radius: 8px; padding: 10px 12px; }
.dup-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 5px 0; border-top: 1px solid #fde68a; }
.dup-reason { font-size: 11px; color: #b45309; background: #fef3c7; border-radius: 8px; padding: 1px 7px; margin-left: 4px; }
.form-sub { font-weight: 600; font-size: 13px; color: var(--muted); margin-top: 6px; border-bottom: 1px solid var(--border); padding-bottom: 3px; }
.so-filterbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 2px; }
.filter-pills { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.fpill { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 16px; background: #fff; cursor: pointer; color: var(--muted); }
.fpill:hover { border-color: var(--accent); }
.fpill.on { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; }
.fpill .fpx { cursor: pointer; font-weight: 600; opacity: .7; }
.fpill .fpx:hover { opacity: 1; }
.filter-pop { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 6px 0; box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.filter-pop .fp-title { font-weight: 600; font-size: 13px; align-self: center; }
.filter-pop label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.fp-actions { display: flex; gap: 6px; margin-left: auto; }
.filter-pop.all-filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); align-items: center; }
.aff-title { font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.aff-row { flex-direction: row !important; align-items: center; gap: 6px !important; font-size: 13px !important; color: var(--text) !important; }
.aff-row input { width: auto; }
.act-add { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.act-add textarea { width: 100%; resize: vertical; }
.act-timeline { display: flex; flex-direction: column; }
.act-row { display: flex; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.act-row:last-child { border-bottom: none; }
.act-dot { flex: 0 0 18px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.5; }
.act-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.act-meta { font-size: 11px; color: var(--muted); }
.act-meta a { cursor: pointer; color: var(--red); }
.act-event .act-body > span:first-child { color: var(--muted); }

/* location rows on product page */
.loc-row { display: flex; align-items: center; gap: 12px; }
.loc-bar { flex: 1; max-width: 180px; height: 10px; background: #eef2f7; border-radius: 5px; overflow: hidden; }
.loc-bar > div { height: 10px; background: var(--accent); border-radius: 5px; }

/* product thumbnails */
.thumb { width: 38px; height: 38px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); flex-shrink: 0; }
.thumb-empty { display: flex; align-items: center; justify-content: center; background: #f1f5f9; font-size: 16px; }
.thumb-lg { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

/* charts */
.chart-wrap { overflow-x: auto; }
svg.chart text { font-size: 11px; fill: var(--muted); }

/* print */
@media print {
  body > * { display: none !important; }
  #print-root { display: block !important; }
  #print-root .invoice { font-size: 13px; color: #000; }
}
#print-root { display: none; }
.invoice h1 { font-size: 22px; margin-bottom: 2px; }
.invoice .inv-head { display: flex; justify-content: space-between; margin-bottom: 24px; }
.invoice table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.invoice th, .invoice td { border: 1px solid #999; padding: 6px 8px; }
.invoice .totals { margin-left: auto; width: 260px; }
.invoice .totals td { border: none; padding: 3px 8px; }

@media (max-width: 760px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 40; flex-direction: row; justify-content: flex-start; }
  .rail { flex-direction: row; padding: 6px 6px; gap: 0; overflow-x: auto; }
  .rail-footer { flex-direction: row; padding: 6px 6px; margin-left: auto; gap: 2px; }
  .rail-btn { width: 40px; height: 40px; }
  .rail-user { width: 30px; height: 30px; }
  .brand-icon { display: none; }
  .flyout { position: fixed; left: 8px; right: 8px; top: 56px; margin: 0; min-width: 0; }
  .flyout::before { display: none; }
  #main { padding: 14px; max-width: 100%; }
  .card { padding: 14px; overflow-x: auto; }
  .toolbar input[type=search] { width: 100%; flex: 1 1 100%; }
  .toolbar select { flex: 1; }
  .prod-2col { grid-template-columns: 1fr; }
  .btn { padding: 10px 14px; }
  .btn.small { padding: 6px 10px; }
  /* product list: drop low-priority columns (Category, Type, Cost) — keep Item, On hand, Price */
  #product-table th:nth-child(2), #product-table td:nth-child(2),
  #product-table th:nth-child(3), #product-table td:nth-child(3),
  #product-table th:nth-child(5), #product-table td:nth-child(5) { display: none; }
  /* sales list: drop Location + Date on narrow screens */
  #so-table th:nth-child(2), #so-table td:nth-child(2),
  #so-table th:nth-child(4), #so-table td:nth-child(4) { display: none; }
  .cmdk-overlay { padding: 6vh 10px; }
  .modal, .modal.wide { width: 100%; padding: 16px; }
}
