:root {
  /* Warm artisan palette — terracotta accent over cream/linen neutrals, instead of the cooler
     slate/green scheme this started with. --accent is also the one thing a shop can override
     for itself (Settings → Branding); --accent-soft/--warn-soft/--danger-soft derive from it and
     the current background with color-mix() so a custom accent always gets a sensible tint
     without needing its own stored value, in both themes. */
  --bg: #f7f1e6; --card: #fffcf6; --ink: #2b2219; --muted: #7d6f5e; --line: #e7dac2;
  --accent: #c1623d; --warn: #a8641a; --danger: #b8463a;
  --accent-soft: color-mix(in srgb, var(--accent) 15%, var(--bg));
  --warn-soft: color-mix(in srgb, var(--warn) 15%, var(--bg));
  --danger-soft: color-mix(in srgb, var(--danger) 13%, var(--bg));
  --shadow: 0 1px 2px rgba(43,30,15,.05), 0 8px 24px rgba(43,30,15,.08); --overlay: rgba(38,26,14,.5);
  --font-display: 'Fraunces', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1611; --card: #251f17; --ink: #f1e8da; --muted: #a99b87; --line: #3b3122;
    --accent: #e08a5f; --warn: #e8a85c; --danger: #e5776b;
    --accent-soft: color-mix(in srgb, var(--accent) 20%, var(--bg));
    --warn-soft: color-mix(in srgb, var(--warn) 20%, var(--bg));
    --danger-soft: color-mix(in srgb, var(--danger) 18%, var(--bg));
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3); --overlay: rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 7%, var(--bg)), var(--bg) 55%); color: var(--ink); font-family: Inter, system-ui, sans-serif; font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 32px 16px 64px; }
header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
header .brand-row { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 42px; width: auto; max-width: 160px; border-radius: 8px; object-fit: contain; }
header h1 { margin: 0 0 4px; font-size: 30px; letter-spacing: -.01em; font-family: var(--font-display); font-weight: 600; }
header p { margin: 0; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 24px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
@media (max-width: 520px) { .tabs button { padding: 10px 8px; font-size: 14px; } }
.tabs button { border: none; background: none; font: inherit; font-weight: 500; color: var(--muted); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs.sub { margin-bottom: 0; }
.tabs.sub button { padding: 8px 12px; font-size: 13px; }
.count { font-size: 11px; background: var(--line); color: var(--muted); border-radius: 99px; padding: 1px 7px; font-weight: 600; }
.count:empty { display: none; }

.grid { display: grid; grid-template-columns: 1fr 360px; gap: 20px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 20px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 14px; font-weight: 600; }
h2.collapsible-header { cursor: pointer; user-select: none; display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card.collapsed h2.collapsible-header { margin-bottom: 0; }
.collapse-chevron { display: inline-block; transition: transform .15s; color: var(--muted); font-size: 11px; }
.card.collapsed .collapse-chevron { transform: rotate(-90deg); }
.card.collapsed > :not(h2) { display: none; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
input, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); font: inherit; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.labor-field.dim, .ovh-field.dim { opacity: .45; }
input:disabled { cursor: not-allowed; }
input[readonly] { background: transparent; border-style: dashed; color: var(--muted); }
.row { display: grid; gap: 12px; }
.r4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.r3 { grid-template-columns: 1fr 1fr 1fr; }
.r2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) { .r3, .r4 { grid-template-columns: 1fr 1fr; } }

table { width: 100%; border-collapse: collapse; font-size: inherit; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 0 6px 8px; }
th.r, td.r { text-align: right; }
td { padding: 4px 6px; vertical-align: middle; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.num small { display: block; font-size: 11px; color: var(--muted); }
.in-name { min-width: 140px; }
.in-small { width: 88px; }
.tag { display: none; font-size: 11px; color: var(--accent); margin-top: 3px; font-weight: 500; }
tr.linked .tag { display: block; }
tr.linked .lib-chk-wrap { display: none; }
.acts { white-space: nowrap; text-align: right; }
/* The Users row's actions cell holds a role <select> plus two buttons — too wide to force onto
   one line (that's what .acts above assumes, for the single-icon case elsewhere) without
   spilling out of the card on anything narrower than a wide desktop. Flex-wrap lets it break
   onto a second line instead of overflowing. */
.user-acts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; white-space: normal; }
.user-acts select { width: auto; min-width: 110px; }
/* The Items row packs a quantity control plus up to five buttons into .acts — more than fits
   on one line at every card width even once sized down. Keep it on one line (no wrap — a
   wrapped row read as messy) by sizing everything in it down a notch and, as a last resort on
   narrow screens, letting the row itself scroll sideways rather than spilling into the next
   column or getting clipped. This lives on an INNER div, not the <td class="acts"> itself —
   putting overflow-x:auto directly on a table cell breaks its normal full-row-height stretch in
   Chrome/Edge (the cell's box and border collapse to just its own short content instead of the
   row's height), which left that cell's bottom border sitting well above the rest of the row's
   — a wrapper div keeps the <td> a plain, normally-stretching cell. */
/* justify-content must stay flex-start, not flex-end: with overflow-x:auto, flex-end pushes
   overflow onto the row's start edge, which a LTR scroll container can't actually scroll to
   (only end-side overflow is reachable) — the first button or two would silently clip with no
   way to reach them, worse than not scrolling at all. */
.items-acts { display: flex; flex-wrap: nowrap; gap: 4px; align-items: center; justify-content: flex-start; overflow-x: auto; padding-bottom: 2px; min-width: 0; max-width: 100%; }
.items-acts .btn.sm { padding: 4px 7px; font-size: 12px; flex-shrink: 0; }
.items-acts .icon-btn { flex-shrink: 0; }
.items-acts .qty-ctrl { flex-shrink: 0; gap: 3px; }
.items-acts .qty-ctrl input { width: 30px; padding: 4px 2px; }
.lib-chk-wrap { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); cursor: pointer; vertical-align: middle; margin-right: 6px; user-select: none; }
.lib-chk-wrap input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 17px; padding: 4px 8px; border-radius: 6px; line-height: 1; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn.del:hover { color: var(--danger); }
.help { background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.help b { color: var(--ink); font-weight: 600; }
tr.lib-detail td { padding: 0 0 14px; border-bottom: 1px solid var(--line); }
.lib-detail-inner { background: var(--bg); border-radius: 10px; padding: 12px 14px; }
.lib-detail-inner label { margin-bottom: 6px; }
.lib-detail-inner input { max-width: 480px; }
.checkPriceResult:not(:empty) { margin-top: 10px; }
@media (max-width: 700px) {
  .erow-table thead { display: none; }
  tr.erow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  tr.erow td { padding: 0; }
  tr.erow td:first-child { grid-column: 1 / -1; }
  tr.erow td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
  tr.erow td.num { text-align: left; align-self: end; padding-bottom: 10px; }
  tr.erow td.acts { grid-column: 3; }
  .in-small { width: 100%; }
}

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: none; background: none; padding: 7px; border-radius: 7px; font: inherit; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.link { background: none; border: none; padding: 0; font: inherit; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; }

.summary { position: sticky; top: 20px; }

/* Sell page on a phone: the ticket moves out of normal document flow into a bottom sheet —
   otherwise checking out means scrolling past the entire item grid, recent sales, and past
   events first. A persistent bar shows the live total; tapping it slides the full ticket
   (lines, tax, tender, checkout) up from the bottom. Desktop/tablet keep the original
   side-by-side layout untouched — this only kicks in alongside the existing 1-column
   breakpoint below. */
.mobile-cart-bar, .cart-backdrop { display: none; }
@media (max-width: 860px) {
  #tab-pos .summary {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0;
    max-height: 82vh; overflow-y: auto; z-index: 9;
    transform: translateY(100%); transition: transform .25s ease;
    padding: 0 16px calc(16px + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0; box-shadow: 0 -8px 28px rgba(0,0,0,.18);
  }
  #tab-pos .summary.open { transform: translateY(0); }
  #tab-pos .summary .card { border: none; box-shadow: none; padding: 16px 0 0; margin: 0; }
  #tab-pos main { padding-bottom: 76px; } /* room for the fixed bar so it never covers the last card */
  .cart-backdrop { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 8; }
  .mobile-cart-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 9; border: none; border-radius: 14px; padding: 14px 18px;
    background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
    box-shadow: var(--shadow);
  }
  .mobile-cart-bar .chev { transition: transform .2s; }
  .mobile-cart-bar.open .chev { transform: rotate(180deg); }
}
.price-box { background: var(--accent-soft); border-radius: 12px; padding: 20px; text-align: center; margin-bottom: 16px; }
.price-box .lbl { font-size: 13px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.price-box .big { font-size: 44px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin: 4px 0; }
.price-box .sub { font-size: 13px; color: var(--muted); }
.price-box.override { background: var(--warn-soft); }
.price-box.override .lbl { color: var(--warn); }
.override-row { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.neg { color: var(--danger) !important; }
.line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.line span:first-child { color: var(--muted); }
.line.total { font-weight: 600; border-bottom: 1px solid var(--line); }
.line.profit span:last-child { color: var(--accent); font-weight: 600; }
.bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; margin: 14px 0 8px; background: var(--bg); }
.bar div { transition: width .25s; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; font-weight: 500; }
.scroll { overflow-x: auto; }
/* Top-aligned, not the generic td's vertical-align:middle — Sales price and Item often wrap to
   two or three lines (suggested-price note, margin, category badges) while Cost/Stock/Actions
   don't, and middle-aligning against whichever cell is tallest pushed the action row down out
   of line with the item name above it instead of sitting level with it. */
.items-table td { padding: 12px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; vertical-align: top; }
.items-table tr:last-child td { border-bottom: none; }
.items-table th { padding: 0 8px 8px; white-space: nowrap; }
.items-table .iname { font-weight: 600; cursor: pointer; }
.items-table .iname:hover { color: var(--accent); }
.items-table .meta { font-size: 12px; color: var(--muted); }
.chg { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); margin-left: 6px; }
@media (max-width: 600px) {
  .items-table thead { display: none; }
  .items-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 14px 0; border-bottom: 1px solid var(--line); }
  .items-table tr:last-child { border-bottom: none; }
  .items-table td { padding: 0; border: none; }
  .items-table td:first-child, .items-table td.acts { grid-column: 1 / -1; }
  .items-table td.num { text-align: left; white-space: normal; }
  .items-table td.num::before { content: attr(data-l); display: block; font-size: 11px; color: var(--muted); }
}
.old { color: var(--muted); text-decoration: line-through; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 24px 0; }

.head-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
@media (max-width: 600px) { .head-side { align-items: flex-start; } }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); font-weight: 500; }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.modal { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-card { background: var(--card); color: var(--ink); border-radius: 14px; padding: 22px; max-width: 420px; width: 100%; box-shadow: var(--shadow); }
.modal-card p { margin: 0; line-height: 1.5; }
.image-lightbox { z-index: 20; cursor: zoom-out; }
.lightbox-card { position: relative; background: none; box-shadow: none; padding: 0; max-width: 92vw; width: auto; cursor: default; }
.lightbox-card img { display: block; max-width: 92vw; max-height: 88vh; border-radius: 10px; box-shadow: var(--shadow); }
.lightbox-close { position: absolute; top: -14px; right: -14px; background: var(--card); box-shadow: var(--shadow); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500; transition: opacity .2s, transform .2s; box-shadow: var(--shadow); max-width: calc(100% - 32px); z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.stock-cell { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.stock-badge { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--danger); color: #fff; }
.qty-ctrl { display: inline-flex; align-items: center; gap: 4px; }
.qty-ctrl input { width: 46px; padding: 6px 4px; text-align: center; }
.in-tiny { width: 64px !important; }
.in-tiny.low-input { border-color: var(--danger); color: var(--danger); }

.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.pos-item { text-align: left; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--card); cursor: pointer; font: inherit; color: var(--ink); }
.pos-item:hover { border-color: var(--accent); }
.pos-item .nm { font-weight: 600; display: block; margin-bottom: 2px; }
.pos-item .pr { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.pos-item .st { font-size: 11px; color: var(--muted); margin-top: 2px; }
.pos-item .st.low { color: var(--danger); font-weight: 600; }
.pos-item.out { background: var(--danger-soft); border-color: var(--danger); }
.pos-item.out:hover { border-color: var(--danger); }
.pos-item.out .nm, .pos-item.out .pr { color: var(--danger); }
.cat-badge { display: inline-block; font-size: 11px; font-weight: 600; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; }
.cat-badge.warn-badge { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.tline { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.tline .nm { flex: 1; font-weight: 500; min-width: 0; overflow-wrap: break-word; }
.tline .qstep { display: inline-flex; align-items: center; gap: 4px; }
.tline .qstep button { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; font: inherit; line-height: 1; }
.tline .qstep span { width: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.tline .amt { min-width: 62px; text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.tline .amt .old { display: block; font-size: 11px; }
.tline .taxmini { display: inline-flex; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); flex-shrink: 0; }
.tline .taxmini input { width: 34px; padding: 5px 2px; text-align: center; font-size: 12px; }
.tline .taxmini input.overridden { border-color: var(--accent); color: var(--accent); }
.tline .discBtn { font-size: 11px; font-weight: 600; }
.tline .discBtn.on { color: var(--accent); }
.tline-discount { display: flex; align-items: center; gap: 8px; padding: 0 0 9px; margin-top: -9px; border-bottom: 1px dashed var(--line); }
.tline-discount .discType { padding: 5px 6px; font-size: 12px; }
.tline-discount .discValue { width: 70px; padding: 5px 6px; font-size: 12px; }

.receipt { border-bottom: 1px solid var(--line); }
.receipt:last-child { border-bottom: none; }
.receipt-head { width: 100%; display: flex; justify-content: space-between; gap: 8px; background: none; border: none; padding: 10px 0; cursor: pointer; font: inherit; color: var(--ink); text-align: left; }
.receipt-head .rh-time { color: var(--muted); font-size: 12px; align-self: center; }
.receipt-head .rh-total { font-weight: 600; font-variant-numeric: tabular-nums; }
.receipt-body { padding: 0 0 12px; }
.rline { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.rline.sub span:first-child { color: var(--muted); padding-left: 14px; font-size: 12px; }
.rline.sub span:last-child { color: var(--muted); font-size: 12px; }
.rline.subtot { border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 6px; color: var(--muted); }
.rline.grand { font-weight: 700; border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; }
.rline.meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.sale-void { font-size: 12px; color: var(--muted); background: none; border: none; cursor: pointer; text-decoration: underline; padding: 0; margin-top: 8px; margin-right: 14px; }
.sale-void:hover { color: var(--danger); }
.return-form { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.return-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.return-row-name { flex: 1; font-size: 13px; }
.return-row-left { font-size: 11px; color: var(--muted); }
.ev-view-btn { font-size: 12px; color: var(--accent); background: none; border: none; cursor: pointer; text-decoration: underline; padding: 0; margin-top: 4px; margin-right: 12px; }
.ev-sales { margin-top: 8px; padding-top: 4px; border-top: 1px dashed var(--line); }

.chk-field { display: flex; align-items: flex-start; gap: 9px; font-size: 14px; color: var(--ink); cursor: pointer; user-select: none; margin-top: 12px; }
.chk-field input { width: 17px; height: 17px; flex-shrink: 0; margin: 2px 0 0; accent-color: var(--accent); cursor: pointer; }

.ev-item-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.ev-item-row .ev-item-qty { width: 64px !important; flex-shrink: 0; }

.event-link { background: none; border: none; color: var(--muted); font-size: 13px; text-decoration: underline; cursor: pointer; padding: 0; margin-bottom: 16px; }
.event-link:hover { color: var(--ink); }
.test-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.test-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--warn); }
.event-bar-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 20px; box-shadow: var(--shadow); }
.event-bar-wrap.met { border-color: var(--accent); }
.event-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.event-title { font-weight: 600; font-size: 14px; }
.event-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.event-pct { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.event-bar-wrap.met .event-pct { color: var(--accent); }
.event-bar { height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; margin-top: 10px; }
.event-bar-fill { height: 100%; background: var(--accent); transition: width .25s; }
.event-bar-wrap:not(.met) .event-bar-fill { background: var(--warn); }

.disk-gauge { height: 10px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.disk-gauge-fill { height: 100%; background: var(--accent); transition: width .25s; }
.disk-gauge-fill.warn { background: var(--warn); }
.disk-gauge-fill.danger { background: var(--danger); }
.ev-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.ev-row:last-child { border-bottom: none; }
.ev-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ev-top b { font-size: 14px; }
.ev-net { font-variant-numeric: tabular-nums; font-weight: 600; }
.ev-net.pos { color: var(--accent); }
.ev-net.neg { color: var(--danger); }
.ev-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ev-del { font-size: 12px; color: var(--muted); background: none; border: none; cursor: pointer; text-decoration: underline; padding: 0; margin-top: 4px; }

.ev-charity-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.ev-charity-row:last-child { border-bottom: none; }
.ev-charity-row .ev-charity-name { font-weight: 500; }
.ev-charity-row .ev-charity-pct { color: var(--warn); font-weight: 600; font-variant-numeric: tabular-nums; }
.ev-charity-row .icon-btn { font-size: 15px; padding: 2px 6px; }

.app-footer { text-align: center; font-size: 12px; color: var(--muted); margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line); }

/* A small, always-present Craftium credit — independent of a tenant's own custom branding
   (name/logo/accent, all set in Settings → Branding), so it's always clear what the app
   underneath a rebranded install actually is. Reused on the login screen and in the footer;
   never printed (packing lists/purchase orders already hide header/footer for print). */
.craftium-credit { display: inline-flex; align-items: center; gap: 6px; vertical-align: middle; }
.craftium-credit img { width: 16px; height: 16px; border-radius: 4px; }

/* The login screen's own, much bigger Craftium mark — see the comment above .craftium-credit;
   same independence from a tenant's own branding, just given the most prominent spot on the
   page it's reasonable to put it. */
.login-craftium-banner { text-align: center; margin: -4px 0 18px; }
.login-craftium-banner img { width: 100%; max-width: 280px; height: auto; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat-tile { background: var(--bg); border-radius: 10px; padding: 14px; }
.stat-tile .lbl { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-tile .val { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.stat-tile .val.neg { color: var(--danger); }
.stat-tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-tile.highlight { background: var(--accent-soft); }
.stat-tile.highlight .lbl { color: var(--accent); }
.stat-tile.highlight .val.neg { color: var(--danger); }
.stat-tile.clickable { cursor: pointer; }
.stat-tile.clickable:hover { background: var(--line); }

.rpt-chart { display: flex; align-items: flex-end; gap: 4px; height: 170px; padding-top: 24px; overflow-x: auto; }
.rpt-bar-col { flex: 1 1 0; min-width: 8px; max-width: 42px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; }
.rpt-bar { width: 100%; max-width: 26px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 3px; }
.rpt-bar-tip { position: absolute; bottom: 100%; left: 50%; transform: translate(-50%, -6px); background: var(--ink); color: var(--card); font-size: 11px; line-height: 1.4; padding: 6px 9px; border-radius: 8px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 2; }
.rpt-bar-col:hover .rpt-bar-tip { opacity: 1; }
.rpt-bar-col:hover .rpt-bar { filter: brightness(1.12); }
.rpt-bar-label { font-size: 10px; color: var(--muted); margin-top: 6px; white-space: nowrap; }

.rpt-top-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.rpt-top-row:last-child { border-bottom: none; }
.rpt-top-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.rpt-top-track { flex-basis: 120px; flex-shrink: 0; height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.rpt-top-fill { height: 100%; background: var(--accent); }
.rpt-top-num { flex-shrink: 0; width: 100px; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .rpt-top-track { display: none; } }

.rpt-cost-headerrow { display: flex; align-items: center; gap: 10px; padding: 0 14px 8px; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.rpt-cost-headerrow span:first-child { flex: 1; }
.rpt-cost-headerrow span:not(:first-child) { width: 90px; text-align: right; }
.rpt-cost-row { border-bottom: 1px solid var(--line); }
.rpt-cost-row:last-child { border-bottom: none; }
.rpt-cost-head { width: 100%; display: flex; align-items: center; gap: 10px; background: none; border: none; padding: 10px 14px; cursor: pointer; font: inherit; color: var(--ink); text-align: left; }
.rpt-cost-head:hover { background: var(--bg); }
.rpt-cost-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.rpt-cost-qty, .rpt-cost-rev, .rpt-cost-cost, .rpt-cost-profit, .rpt-cost-num { width: 90px; text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.rpt-cost-profit { font-weight: 600; color: var(--accent); }
.rpt-cost-profit.neg { color: var(--danger); }
.rpt-cost-body { padding: 0 14px 14px; }
.rpt-mat-table th { font-size: 11px; }
.rpt-mat-table td, .rpt-mat-table th { padding: 5px 6px; }
@media (max-width: 640px) {
  .rpt-cost-headerrow { display: none; }
  .rpt-cost-head { flex-wrap: wrap; }
  .rpt-cost-qty, .rpt-cost-rev, .rpt-cost-cost, .rpt-cost-profit, .rpt-cost-num { width: auto; }
}

.rpt-ev-row { border-bottom: 1px solid var(--line); }
.rpt-ev-row:last-child { border-bottom: none; }
.rpt-ev-head { width: 100%; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; background: none; border: none; padding: 12px 0; cursor: pointer; font: inherit; color: var(--ink); text-align: left; }
.rpt-ev-head:hover .rpt-ev-name { color: var(--accent); }
.rpt-ev-name { font-weight: 600; }
.rpt-ev-meta { font-size: 12px; color: var(--muted); flex: 1; }
.rpt-ev-net { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rpt-ev-net.pos { color: var(--accent); }
.rpt-ev-net.neg { color: var(--danger); }
.rpt-ev-body { padding: 0 0 16px; }
.rpt-ev-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 8px; margin-bottom: 8px; }
.rpt-ev-stats div { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.rpt-ev-stats span { display: block; font-size: 11px; color: var(--muted); }
.rpt-ev-stats b { font-variant-numeric: tabular-nums; }
.rpt-ev-stats b.pos { color: var(--accent); }
.rpt-ev-stats b.neg { color: var(--danger); }
.rpt-ev-items { margin-top: 8px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }

@media print {
  :root, :root:not([data-theme="light"]) {
    --bg: #fff; --card: #fff; --ink: #000; --muted: #444; --line: #ccc; --shadow: none;
    --accent-soft: color-mix(in srgb, var(--accent) 10%, #fff);
  }
  body { background: #fff; }
  header, .tabs, .app-footer, #rptExportPdf, .toast, .modal, .seg#rptRangeSeg, .rpt-bar-tip { display: none !important; }
  .wrap { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}
/* Logo + business name printed at the top of a document, when branding is set (Settings →
   Branding) — otherwise the card just starts at its own title, no empty bar. */
.print-letterhead { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 2px solid var(--line); }
.print-letterhead img { height: 48px; width: auto; max-width: 180px; object-fit: contain; }
.print-letterhead .biz-name { font-family: var(--font-display); font-weight: 600; font-size: 21px; }
/* Packing lists and price tags each get their own printable card, sitting outside any tab so
   they print regardless of which tab happens to be open — shown only while actively printing,
   with everything else on the page hidden for that moment (toggled in app.js, restored right
   after via the 'afterprint' event). */
.packing-list-print, .price-tags-print, .purchase-order-print { display: none; }
body.printing-packing-list #packingListCard,
body.printing-price-tags #priceTagsCard,
body.printing-purchase-order #purchaseOrderCard {
  display: block !important;
}
body.printing-packing-list > :not(#packingListCard),
body.printing-price-tags > :not(#priceTagsCard),
body.printing-purchase-order > :not(#purchaseOrderCard) {
  display: none !important;
}
/* Same small Craftium mark as the app footer/sign-in screen, independent of whatever
   business-name letterhead a document itself has — see the comment above .craftium-credit.
   Hidden outside an actual print: the packing list/price tags/purchase order cards it lives in
   are already screen-hidden the rest of the time, but the Reports one is injected straight
   into the always-visible live tab just for the moment of printing, so this needs its own
   print-only visibility rather than relying on a parent being hidden. */
.print-credit { display: none; }
@media print {
  .print-credit { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
  .print-credit img { width: 14px; height: 14px; border-radius: 3px; }
}

/* Plain-paper mode (the original design): a free-flowing, unbounded grid of cut-it-yourself
   tags with a dashed guide line, any number of pages, no sheet to align to. */
.tag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.4in, 1fr)); gap: 0.15in; }
.price-tag { text-align: center; break-inside: avoid; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; overflow: hidden; }
.price-tag.cutout { border: 1px dashed #999; border-radius: 6px; padding: 0.12in; min-height: 1.3in; }
.price-tag .tag-name { font-weight: 600; font-size: 13px; word-break: break-word; }
.price-tag .tag-price { font-size: 18px; font-weight: 700; }
.price-tag .tag-barcode { max-width: 100%; height: 40px; }
.price-tag .tag-no, .price-tag .tag-booth { font-size: 10px; color: #666; letter-spacing: 1px; }
/* Avery sheet mode: each .avery-sheet is one physical 8.5x11 sheet, sized and padded to match
   that template's real margins/pitch (set inline per-template in app.js, from AVERY_TEMPLATES —
   see that file for how each one's numbers were sourced), so tags land inside each sticker's
   actual edges. Tags get no border of their own here — the adhesive label's edge is the only
   outline — and text shrinks to fit the smallest supported label (half an inch tall). One
   sheet per printed page; named `page` box below drops the browser's default page margin so
   the sheet's own padding is the only margin that counts (tell people to still set the print
   dialog's margin to "None" — some browsers add their own on top of @page otherwise). */
.avery-sheet { width: 8.5in; height: 11in; box-sizing: border-box; display: grid; justify-content: start; align-content: start; overflow: hidden; page: avery-sheet; }
.avery-sheet:not(:last-child) { page-break-after: always; break-after: page; }
@page avery-sheet { size: letter; margin: 0; }
.price-tag.avery { font-size: 10px; }
.price-tag.avery.round { border-radius: 50%; }
.price-tag.avery .tag-name { font-size: 10px; }
.price-tag.avery .tag-price { font-size: 13px; }
.price-tag.avery .tag-barcode { height: 22px; }
.price-tag.avery .tag-no, .price-tag.avery .tag-booth { font-size: 7px; }
/* 5167/5195 — half-inch/two-thirds-inch-tall strips, no barcode (see AVERY_TEMPLATES'
   noBarcode), just name/price/item-no/booth squeezed into a much shorter label. */
.price-tag.avery.compact { padding: 1px 3px; gap: 0; line-height: 1.1; }
.price-tag.avery.compact .tag-name { font-size: 7px; }
.price-tag.avery.compact .tag-price { font-size: 9px; }
.price-tag.avery.compact .tag-no, .price-tag.avery.compact .tag-booth { font-size: 6px; letter-spacing: 0; }

/* ---- login / first-run setup ---- */
.login-screen { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; max-width: 380px; width: 100%; box-shadow: var(--shadow); }
.login-card h1 { font-size: 24px; margin: 0 0 4px; font-family: var(--font-display); font-weight: 600; }
.login-card .brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-card .brand-logo { height: 36px; max-width: 140px; }
.login-card label { margin-top: 0; }
.login-error { background: var(--danger); color: #fff; border-radius: 8px; padding: 9px 12px; font-size: 13px; margin: 12px 0; }

/* ---- roles ---- */
.role-badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--line); color: var(--muted); }
.role-badge.admin { background: var(--accent-soft); color: var(--accent); }
.role-badge.manager { background: #dce8fb; color: #2b5fa8; }
.role-badge.lead { background: #ede4fb; color: #6b3fa0; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .role-badge.manager { background: #203552; color: #8fb4e8; }
  :root:not([data-theme="light"]) .role-badge.lead { background: #342850; color: #c6a8ec; }
}
.role-pick { display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; cursor: pointer; font-size: 13px; }
.role-pick:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.role-pick input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.role-pick span { display: flex; flex-direction: column; }
.role-pick small { color: var(--muted); }

/* ---- release notes ---- */
.rn-entry { padding: 12px 0; border-bottom: 1px solid var(--line); }
.rn-entry:last-child { border-bottom: none; }
.rn-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.rn-head span { font-size: 12px; color: var(--muted); }
.rn-entry ul { margin: 0; padding-left: 20px; font-size: 14px; }
.rn-entry li { margin-bottom: 4px; }
#appVersion { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- duplicate items/materials (Settings) ---- */
.dup-group { background: var(--bg); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; }
.dup-group-title { font-weight: 600; margin-bottom: 4px; }
.dup-group-title .count { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--card); border-radius: 99px; padding: 1px 8px; margin-left: 6px; }
.dup-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.dup-row:last-child { border-bottom: none; }
.dup-info { font-size: 13px; color: var(--muted); }

/* ---- branding (Settings → Branding) ---- */
.logo-pick { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.logo-preview { width: 72px; height: 72px; border-radius: 10px; border: 1px dashed var(--line); background: var(--bg); display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.matPhotoPreview img, #itemPhotoPreview img { cursor: zoom-in; }
.logo-preview .ph { font-size: 11px; color: var(--muted); text-align: center; padding: 4px; }
.item-name-cell { display: flex; align-items: center; gap: 10px; }
.item-thumb { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; background-size: cover; background-position: center; flex-shrink: 0; border: 1px solid var(--line); }
img.item-thumb { cursor: zoom-in; }
button.item-thumb { appearance: none; background-color: var(--card); color: var(--muted); font: inherit; font-size: 16px; cursor: pointer; padding: 0; }
button.item-thumb.empty { border-style: dashed; }
button.item-thumb.empty:hover { color: var(--accent); border-color: var(--accent); }
button.item-thumb:not(.empty) { border-style: solid; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 2px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--card); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }
.color-field { display: flex; align-items: center; gap: 10px; }
.color-field input[type="color"] { width: 44px; height: 38px; padding: 2px; flex-shrink: 0; cursor: pointer; }
