:root {
  --brand: #c80000; --brand-ink: #fff; --brand-soft: #fbeaea; --brand-text: #c80000;
  --bg: #f5f5f6; --panel: #fff; --text: #1e2024; --muted: #6a6f78; --line: #e7e8eb; --line-strong: #d5d7dc; --hover: #f6f6f8;
  --ok: #17753f; --ok-bg: #e5f4ea; --warn: #a55300; --warn-bg: #fdf0dd; --bad: #c80000; --bad-bg: #fbe8e8;
  --shadow: 0 1px 2px rgba(20, 22, 28, .05);
  --r: 10px; color-scheme: light;
}
/* Dark palette: used when the user picks dark, or when they haven't picked and the system prefers dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --brand: #e01f1f; --brand-ink: #fff; --brand-soft: #35191b; --brand-text: #ff8078;
    --bg: #131416; --panel: #1b1c1f; --text: #ececee; --muted: #9a9ea8; --line: #2a2c31; --line-strong: #3a3d44; --hover: #23252a;
    --ok: #5fcf8d; --ok-bg: #15301f; --warn: #f1a54f; --warn-bg: #362813; --bad: #ff6b60; --bad-bg: #3a1a18;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme=dark] {
    --brand: #e01f1f; --brand-ink: #fff; --brand-soft: #35191b; --brand-text: #ff8078;
    --bg: #131416; --panel: #1b1c1f; --text: #ececee; --muted: #9a9ea8; --line: #2a2c31; --line-strong: #3a3d44; --hover: #23252a;
    --ok: #5fcf8d; --ok-bg: #15301f; --warn: #f1a54f; --warn-bg: #362813; --bad: #ff6b60; --bad-bg: #3a1a18;
    --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 650; }
p { margin: 0 0 12px; }

/* ---- layout: left sidebar + content ---- */
.app { display: flex; min-height: 100vh; }
.side { width: 240px; flex: none; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 18px 12px 14px;
  background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 2px 10px 18px; color: var(--text); font-weight: 700; font-size: 15px; }
.side .brand:hover { text-decoration: none; }
.side .brand img { height: 28px; width: auto; display: block; flex: none; }
.side .menu { display: flex; flex-direction: column; gap: 2px; }
.side .foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; padding-top: 12px; border-top: 1px solid var(--line); }
.side .item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; cursor: pointer;
  border: 0; background: none; width: 100%; text-align: left; min-height: 0; font-size: 14px; position: relative; }
.side .item:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.side .item.on { background: var(--brand-soft); color: var(--brand-text); }
.side .item.on::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.side .item svg { width: 19px; height: 19px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side .account { display: flex; align-items: center; gap: 10px; padding: 10px 8px 2px; }
.side .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.side .who { min-width: 0; flex: 1; line-height: 1.25; }
.side .who b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .who span { font-size: 12px; color: var(--muted); }
.side .account button { padding: 6px; min-height: 0; border: 0; background: none; color: var(--muted); border-radius: 8px; display: grid; place-items: center; }
.side .account button:hover { background: var(--hover); color: var(--text); }
.side .account svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.content { flex: 1; min-width: 0; }
main { max-width: 1680px; margin: 0 auto; padding: 32px 36px 72px; container-type: inline-size; }
@media (max-width: 1000px) {
  .side { width: 64px; padding-left: 8px; padding-right: 8px; align-items: stretch; }
  .side .brand { padding: 2px 4px 16px; justify-content: center; }
  .side .brand span, .side .item .label, .side .who { display: none; }
  .side .item { justify-content: center; padding: 11px 0; }
  .side .item.on::before { left: -8px; }
  .side .account { flex-direction: column; padding: 10px 0 0; gap: 6px; }
  main { padding: 24px 20px 56px; }
}
@media (max-width: 560px) { main { padding: 18px 12px 48px; } }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.head .sub { color: var(--muted); margin-top: 2px; }
.stack > * + * { margin-top: 20px; }
.stack > :empty { display: none; }
.stack.tight > * + * { margin-top: 8px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; box-shadow: var(--shadow); }
.panel > :last-child { margin-bottom: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid2.tight { gap: 0 16px; }
.grid2.wide { grid-template-columns: 1.2fr 1fr; }
@media (max-width: 900px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 220px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.mt { margin-top: 16px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---- forms ---- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=number], input[type=password], input[type=date], select, textarea {
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 12px; width: 100%; min-height: 38px;
}
input::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
input[type=number] { width: 84px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
select { width: auto; padding-right: 30px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }

button { border: 1px solid var(--line-strong); background: var(--panel); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; min-height: 36px; }
button:hover { background: var(--hover); }
button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-bg); }
button.small { padding: 4px 10px; font-size: 12px; min-height: 28px; }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--hover); color: var(--text); }
button:disabled { opacity: .45; cursor: default; }

.seg { display: inline-flex; background: var(--hover); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; }
.seg button { border: 0; background: transparent; border-radius: 7px; color: var(--muted); flex: none; }
.seg button.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td, tr:last-child > td { border-bottom: 0; }
table.click tbody tr { cursor: pointer; }
table.click tbody tr:hover { background: var(--hover); }
.scroll { overflow-x: auto; margin: 0 -12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sub { font-size: 12px; color: var(--muted); }

.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--hover); color: var(--muted); white-space: nowrap; line-height: 1.5; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.bti { background: var(--brand-soft); color: var(--brand-text); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.neg { color: var(--bad); font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.stat b { display: block; font-size: 28px; line-height: 1.1; color: var(--text); margin-bottom: 2px; letter-spacing: -.02em; }
.stat.alert b { color: var(--bad); }

/* ---- type-ahead ---- */
.ta { position: relative; }
.ta-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px; margin-top: 4px;
  box-shadow: 0 12px 32px rgba(0,0,0,.18); max-height: 380px; overflow-y: auto; padding: 4px; }
.ta-item { padding: 9px 12px; cursor: pointer; border-radius: 7px; display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.ta-item.on, .ta-item:hover { background: var(--hover); }
.ta-empty { padding: 12px; color: var(--muted); }

/* ---- orders ---- */
.order-card { border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 14px; overflow: hidden; background: var(--panel); }
.order-card:last-child { margin-bottom: 0; }
.order-card > header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; background: var(--hover); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.order-card table td { padding: 10px 16px; }
.order-card header a { color: var(--text); }
.order-card header a:hover { color: var(--brand-text); }
.order-card .note { padding: 8px 16px 10px; border-top: 1px solid var(--line); }
tr.shipped td { color: var(--muted); }
.shipctl { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; }
.shipctl input { width: 64px; padding: 4px 8px; min-height: 30px; }
.bticard { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--brand-soft); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 9px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 24px; width: min(680px, 94vw); max-height: 90vh; box-shadow: 0 24px 64px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10, 12, 16, .55); }
dialog h2 { font-size: 17px; }
dialog.wide { width: min(980px, 95vw); padding: 28px; }

.login { max-width: 360px; margin: 12vh auto 0; padding: 28px; }
.login .logo { display: block; height: 48px; margin: 0 0 20px; }
.err-text { color: var(--bad); margin: 0 0 12px; }

@media (max-width: 700px) { .panel { padding: 16px; } }

/* ---- dashboard tables ---- */
table.fixed { table-layout: fixed; }
table.fixed td { overflow-wrap: anywhere; }
.order-card table.fixed td { padding: 10px 8px; }
.order-card table.fixed td:first-child, .order-card table.fixed th:first-child { padding-left: 16px; }
.order-card table.fixed td:last-child { padding-right: 16px; }
.order-card table.fixed td.num { text-align: center; }
table.needed td.num, table.needed th.num { padding-left: 6px; padding-right: 6px; }

/* ---- item popup ---- */
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.dlg-head h2 { font-size: 20px; margin: 0 0 8px; letter-spacing: -.01em; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.tile { background: var(--hover); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.tile-v { font-size: 22px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; overflow-wrap: anywhere; }
.dlg-grid { display: grid; grid-template-columns: 300px 1fr; gap: 28px; align-items: start; }
dialog h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
dl { margin: 0; }
.kv { display: grid; grid-template-columns: 124px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.grid3 input[type=number] { width: 100%; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } .dlg-grid, .grid3 { grid-template-columns: minmax(0, 1fr); } }

.chart { position: relative; margin-top: 4px; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart-svg .tick { fill: var(--muted); font-size: 11px; }
.chart-svg .peak { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart-svg .empty { fill: var(--muted); font-size: 13px; }
.chart-svg .bar { fill: var(--brand); transition: filter .1s; }
.chart-svg .bar.hot { filter: brightness(1.2); }
.chart-svg .hit { cursor: default; }
.chart-tip { position: absolute; transform: translate(-50%, calc(-100% - 8px)); background: var(--text); color: var(--bg); padding: 6px 10px; border-radius: 7px; pointer-events: none; white-space: nowrap; font-size: 12px; z-index: 2; }
.chart-tip .sub { color: inherit; opacity: .7; }

.notice { padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.notice.warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.notice.warn a { color: inherit; text-decoration: underline; font-weight: 600; }
input[type=time] { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 12px; min-height: 38px; }
input[type=time]:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
label.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.col { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }

/* ---- dashboard ---- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 14px; }
.cards .order-card { margin: 0; }
@container (max-width: 700px) { .cards { grid-template-columns: minmax(0, 1fr); } }
.chartpanel .chart { margin-top: 8px; }
.narrow { max-width: 920px; }

/* ---- stock rows / locations ---- */
tr.negrow td { background: color-mix(in srgb, var(--bad) 6%, transparent); }
table.click tbody tr.negrow:hover td { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.loc { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.loc i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.28); flex: none; }
.loc.white i, .loc.black i { box-shadow: inset 0 0 0 1px var(--line-strong); }

dialog .kv { grid-template-columns: 130px 1fr; }
.tile-v .loc { font-size: 18px; }

/* ---- price list grid ---- */
.grid-wrap { max-height: calc(100vh - 330px); min-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); outline: none; }
.grid-wrap:focus-within { border-color: var(--line-strong); }
table.sheet { border-collapse: separate; border-spacing: 0; width: max-content; table-layout: fixed; font-size: 13px; }
table.sheet td, table.sheet th { padding: 5px 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--panel); text-transform: none; letter-spacing: 0; }
table.sheet td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.sheet td.err { color: var(--bad); font-weight: 600; }
table.sheet td.sel { outline: 2px solid var(--brand); outline-offset: -2px; }
table.sheet td.editing { padding: 0; }
table.sheet thead th, table.sheet thead td { position: sticky; top: 0; z-index: 3; background: var(--hover); font-weight: 600; color: var(--text); }
table.sheet thead tr:nth-child(2) th, table.sheet thead tr:nth-child(2) td { color: var(--muted); font-weight: 500; }
table.sheet th.rn { position: sticky; left: 0; z-index: 2; background: var(--hover); color: var(--muted); font-size: 11px; font-weight: 500; text-align: right; padding-left: 22px; }
table.sheet thead th.rn { z-index: 4; }
table.sheet tr.section td { font-weight: 700; background: color-mix(in srgb, var(--hover) 60%, var(--panel)); }
table.sheet tr.prod:hover td { background: var(--hover); }
table.sheet tr.flash td { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: var(--brand-soft); } to { background: var(--panel); } }
.cell-input { width: 100%; border: 0; border-radius: 0; padding: 5px 8px; min-height: 0; font: inherit; background: var(--panel); box-shadow: inset 0 0 0 2px var(--brand); }
.cell-input:focus { box-shadow: inset 0 0 0 2px var(--brand); }
.fbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.fbar .addr { min-width: 54px; text-align: center; font-weight: 600; font-size: 12px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--hover); }
.fbar .fxl { color: var(--muted); font-style: italic; font-size: 13px; }
.fbar .fx { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.linkdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 0; padding: 0; min-height: 0; background: var(--muted); vertical-align: middle; cursor: pointer; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); }
p .linkdot { position: static; transform: none; cursor: default; margin: 0 2px 1px 8px; }
.linkdot.matched { background: var(--ok); }
.linkdot.suggested { background: #e0a020; }
.linkdot.unmatched { background: transparent; box-shadow: inset 0 0 0 2px var(--muted); }
.linkdot.not_stocked { background: transparent; box-shadow: inset 0 0 0 2px var(--line-strong); opacity: .7; }
table.sheet th.rn { position: sticky; }
.workings { margin-bottom: 16px; }
.pricecard { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--hover); }
.pricecard .kv { padding: 6px 0; grid-template-columns: 120px 1fr; }
.seg.tabs button { white-space: nowrap; }

/* ---- product page ---- */
.skuopt { text-align: left; padding: 16px; border-radius: 10px; }
.skuopt b { font-size: 16px; }
.pinput { max-width: 150px; text-align: right; font-variant-numeric: tabular-nums; }
table.calc td { padding: 7px 10px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; overflow-wrap: anywhere; }
.pricecard, .pricing-block { }

/* ---- CRM ---- */
.navlabel { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 10px 4px; font-weight: 600; }
.navgroup:first-child .navlabel { padding-top: 0; }
@media (max-width: 1000px) { .navlabel { display: none; } .navgroup + .navgroup { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; } }
.chip.info { background: color-mix(in srgb, #2f7de1 14%, transparent); color: #2f7de1; }
.chip.brand { background: var(--brand-soft); color: var(--brand-text); }
.chip.muted { background: var(--hover); color: var(--muted); text-decoration: line-through; text-decoration-color: transparent; }
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) .chip.info { color: #6da8ff; } }
:root[data-theme=dark] .chip.info { color: #6da8ff; }
.overdue { color: var(--bad); font-weight: 600; }
.split { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 20px; align-items: start; }
@container (max-width: 1000px) { .split { grid-template-columns: minmax(0, 1fr); } }
.logtext { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.logtext.clamp { display: -webkit-box; -webkit-line-clamp: 7; -webkit-box-orient: vertical; overflow: hidden; }
.tl { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); margin-bottom: 12px; }
.tl > header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 14px; background: var(--hover); border-bottom: 1px solid var(--line); border-radius: var(--r) var(--r) 0 0; }
.tl > .body { padding: 12px 14px; }
.tl > footer { display: flex; gap: 8px; align-items: center; padding: 8px 14px 12px; }
.tl.done { opacity: .92; }
.tl input.noteinput { flex: 1; min-height: 32px; padding: 5px 10px; }
.contactrow { padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.contactrow:last-child { border-bottom: 0; }
.contactrow:hover b { color: var(--brand-text); }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.catchips { display: flex; flex-wrap: wrap; gap: 8px; }
.catchips button { display: inline-flex; gap: 8px; align-items: center; }
textarea.big { min-height: 260px; resize: vertical; font-family: inherit; line-height: 1.5; }
.hdrchips { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: -14px 0 22px; }
td .clamp2 { min-width: 200px; max-width: 520px; overflow-wrap: anywhere; }
button.small { white-space: nowrap; }
.grow input[type=search] { min-width: 260px; }

/* ---- support ---- */
.chip.gold { background: #fbeec0; color: #7a5600; }
.chip.silver { background: #e6e8ec; color: #4b5563; }
.chip.bronze { background: #f3dfcf; color: #8a4b1c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) .chip.gold { background: #4a3a10; color: #f0c860; } :root:not([data-theme=light]) .chip.silver { background: #363b44; color: #c4cad4; } :root:not([data-theme=light]) .chip.bronze { background: #48301f; color: #e6b088; } }
:root[data-theme=dark] .chip.gold { background: #4a3a10; color: #f0c860; }
:root[data-theme=dark] .chip.silver { background: #363b44; color: #c4cad4; }
:root[data-theme=dark] .chip.bronze { background: #48301f; color: #e6b088; }
.chip.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; letter-spacing: 0; }
.soon { color: var(--warn); font-weight: 600; }
.plancard { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: var(--hover); }
.plancard .kv { padding: 4px 0; grid-template-columns: 90px 1fr; border: 0; }

/* ---- sales ---- */
.board { display: grid; grid-template-columns: repeat(5, minmax(205px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.bcol { background: var(--hover); border: 1px solid var(--line); border-radius: var(--r); min-height: 220px; display: flex; flex-direction: column; }
.bcol.over { outline: 2px dashed var(--brand); outline-offset: -4px; }
.bcol > header { padding: 12px 14px 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.bcol > header b { font-size: 13px; }
.bcol > header .sub { font-variant-numeric: tabular-nums; }
.bcol .cards { display: flex; flex-direction: column; gap: 10px; padding: 4px 10px 12px; }
.deal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; cursor: pointer; box-shadow: var(--shadow); }
.deal:hover { border-color: var(--line-strong); }
.deal.dragging { opacity: .45; }
.deal .t { font-weight: 600; line-height: 1.3; margin-bottom: 2px; }
.deal .m { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.stepper { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.stepper button { border-radius: 99px; padding: 5px 14px; }
.stepper button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.stepper button.past { background: var(--brand-soft); color: var(--brand-text); border-color: transparent; }
.chip.enquiry { background: var(--hover); color: var(--muted); }
.chip.quoted { background: color-mix(in srgb, #2f7de1 14%, transparent); color: #2f7de1; }
.chip.following_up { background: var(--warn-bg); color: var(--warn); }
.chip.won { background: var(--ok-bg); color: var(--ok); }
.chip.lost { background: var(--bad-bg); color: var(--bad); }
.checklist .step { display: grid; grid-template-columns: 26px 1fr auto; gap: 12px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.checklist .step:last-child { border-bottom: 0; }
.checklist .step > * { min-width: 0; }   /* a grid track's content-based min-width otherwise overflows the panel instead of wrapping */
.tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-strong); display: grid; place-items: center; color: transparent; font-size: 13px; font-weight: 700; }
.tick.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.tick.na { border-style: dashed; }
.progressbar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 6px 0 4px; }
.progressbar > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
table.q td { padding: 6px 8px; vertical-align: top; }
table.q input[type=text], table.q input[type=number] { min-height: 34px; padding: 5px 8px; }
table.q input[type=number] { width: 100%; text-align: right; }
.sumbox dl { margin: 0; }
.sumbox .kv { grid-template-columns: 1fr auto; padding: 7px 0; }
.sumbox .kv dd { text-align: right; font-variant-numeric: tabular-nums; }
.sumbox .total .kv, .sumbox .kv.total { font-weight: 700; font-size: 16px; }
.qsplit { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
@container (max-width: 1100px) { .qsplit { grid-template-columns: minmax(0, 1fr); } .board { grid-template-columns: repeat(5, 260px); } }
.savestate { font-size: 12px; color: var(--muted); min-width: 70px; }
.notice.info { background: color-mix(in srgb, #2f7de1 10%, transparent); color: var(--text); border-color: transparent; }

/* ---- home ---- */
.snapgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 16px; margin-bottom: 20px; }
.snap { display: flex; flex-direction: column; }
.snap h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 12px; }
.figs { display: flex; gap: 22px; flex-wrap: wrap; }
.fig { display: flex; flex-direction: column; }
.fig b { font-size: 22px; line-height: 1.15; letter-spacing: -.02em; }
.fig span { font-size: 12px; color: var(--muted); }
.snaplinks { margin-top: auto; padding-top: 14px; display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; }
.snap table td { padding: 6px 4px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
dialog.narrowdlg { width: min(520px, 94vw); padding: 24px; }

/* ---- the company page: a wide facts grid instead of a single cramped label column, and a row of cards ---- */
.factgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px 24px; }
.fact dt { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.fact dd { margin: 0; overflow-wrap: anywhere; }
.ccards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
@container (max-width: 700px) { .factgrid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } }

/* ---- starring, and the recent/starred landing view on Companies & Contacts ---- */
.starbtn { border: 0; background: transparent; padding: 4px; min-height: 0; color: var(--line-strong); line-height: 0; }
.starbtn:hover { background: transparent; color: var(--warn); }
.starbtn svg, .star-ic svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linejoin: round; }
.starbtn.on, .star-ic.on { color: #d9a419; }
.starbtn.on svg, .star-ic.on svg { fill: currentColor; }
.recentgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.recentcard { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; background: var(--panel); }
.recentcard:hover { border-color: var(--line-strong); background: var(--hover); }
.recentcard .row { justify-content: space-between; flex-wrap: nowrap; }
.recentcard b { display: block; }
.browsebar { text-align: center; padding: 4px 0 6px; }

/* ---- calendar ---- */
.calgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calhead { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; text-align: center; padding-bottom: 4px; }
.calday { border: 1px solid var(--line); border-radius: 8px; min-height: 96px; padding: 6px; cursor: default; }
.calday.off { border-color: transparent; }
.calday.today { border-color: var(--brand); background: var(--brand-soft); }
.calday:not(.off) .calevs:not(:empty) { cursor: pointer; }
.calnum { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.calday.today .calnum { color: var(--brand-text); }
.calevs { display: flex; flex-direction: column; gap: 3px; }
.calev { display: block; font-size: 11px; line-height: 1.4; }
.calev .chip { padding: 1px 6px; font-size: 10px; margin-right: 4px; }
.calev b { font-size: 11.5px; }
/* In the month grid (not the day's own popup), a long subject shouldn't stretch that whole week's row — clip it. */
.calev.compact { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.calev.compact .sub { display: none; }
@container (max-width: 900px) { .calgrid { grid-template-columns: repeat(7, minmax(0, 1fr)); } .calday { min-height: 64px; font-size: 11px; } .calev b { display: block; } .calev.compact { -webkit-line-clamp: 1; } }

/* ---- sites (customer addresses) and devices (BTI numbers on the account) ---- */
.sitecard { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.sitecard + .sitecard { margin-top: 8px; }
.sitecard header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sitecard address { font-style: normal; color: var(--muted); font-size: 12.5px; line-height: 1.5; margin-top: 3px; }
.devtable td, .devtable th { padding: 7px 10px; }
.devtable th { position: sticky; top: 0; background: var(--panel); }

/* ---- responsive rules (kept last so they win) ---- */
@container (max-width: 1050px) { .dash-grid { grid-template-columns: minmax(0, 1fr); } }
@container (max-width: 900px) { .stats { grid-template-columns: repeat(2, 1fr); } }
@container (max-width: 620px) { .snapgrid { grid-template-columns: minmax(0, 1fr); } .head { align-items: flex-start; } }

/* ---- global search ---- */
.searchbtn { border: 1px solid var(--line) !important; margin-bottom: 10px; color: var(--muted) !important; }
.searchbtn kbd { margin-left: auto; font: 11px ui-monospace, Menlo, monospace; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; color: var(--muted); }
@media (max-width: 1000px) { .searchbtn kbd { display: none; } }
dialog.searchdlg { width: min(640px, 94vw); padding: 0; top: 12vh; margin: 0 auto; overflow: hidden; }
dialog.searchdlg > input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 16px 18px; font-size: 15px; min-height: 0; }
dialog.searchdlg > input:focus { box-shadow: none; }
.sresults { max-height: 55vh; overflow-y: auto; padding: 6px; }
.sgroup { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 10px 12px 4px; }
.sitem { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.sitem.on, .sitem:hover { background: var(--hover); }
.sempty { padding: 26px 12px; text-align: center; color: var(--muted); }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover, .fig:hover b { border-color: var(--line-strong); }
.bcol .empty { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 8px; border: 1px dashed var(--line-strong); border-radius: 10px; margin: 4px 0; }
