:root {
  --bg: #f5f3ef; --card: #fff; --ink: #1f2328; --muted: #6b6f76; --line: #e3dfd8;
  --brand: #7a4b2a; --brand-ink: #fff; --accent: #2f6f5e;
  --ok: #1f7a4d; --ok-bg: #e3f4ea; --warn: #9a6200; --warn-bg: #fdf1d8;
  --bad: #b3261e; --bad-bg: #fbe4e2; --info: #24579c; --info-bg: #e3edf9; --grey-bg: #eeece8;
  --s-color: #2f6f9e; --a-color: #b06a2c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.logo { background: var(--brand); color: var(--brand-ink); border-radius: 6px; padding: 2px 6px; font-size: 13px; }
.role { font-weight: 500; font-size: 12px; color: var(--muted); background: var(--grey-bg); border-radius: 99px; padding: 2px 10px; text-transform: capitalize; }
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }

/* login */
.login { max-width: 360px; margin: 10vh auto; }
.login .logo { font-size: 22px; padding: 6px 12px; display: inline-block; margin-bottom: 12px; }

/* forms */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 14px; }
.grid .wide { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
label .req { color: var(--bad); }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); font-weight: 400; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
textarea { min-height: 38px; resize: vertical; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
button { cursor: pointer; border: 1px solid transparent; border-radius: 8px; padding: 8px 16px; font-weight: 600; }
.primary { background: var(--brand); color: var(--brand-ink); }
.primary:hover { filter: brightness(1.1); }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.ghost:hover { background: var(--grey-bg); }
.link { background: none; border: 0; padding: 2px 6px; color: var(--info); font-weight: 500; }
.link.danger { color: var(--bad); }
.err { color: var(--bad); font-size: 13px; }

.custbox { position: relative; }
.suggest { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.08); z-index: 3; max-height: 240px; overflow: auto; }
.suggest div { padding: 8px 10px; cursor: pointer; font-weight: 400; color: var(--ink); }
.suggest div.active { background: var(--grey-bg); box-shadow: inset 3px 0 var(--brand); }
.suggest small { color: var(--muted); display: block; }
.idnote { font-size: 12px; margin-top: 10px; color: var(--muted); }

/* tables */
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: top; }
th { background: #faf8f5; position: sticky; top: 0; font-size: 12px; color: var(--muted); z-index: 1; }
th.grp-s { color: var(--s-color); } th.grp-a { color: var(--a-color); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: #fcfbf9; }
td.wrap { white-space: normal; min-width: 160px; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--grey-bg); padding: 1px 6px; border-radius: 4px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.b-Matched { background: var(--ok-bg); color: var(--ok); }
.b-Price { background: var(--warn-bg); color: var(--warn); }
.b-Sales { background: var(--info-bg); color: var(--info); }
.b-Accounts { background: #f6e6d8; color: var(--a-color); }
.b-Duplicate { background: var(--grey-bg); color: var(--muted); }

/* admin */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 14px; color: var(--muted); white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--brand); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { min-width: 220px; }
.toolbar .spacer { flex: 1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 480px) { .kpi .v { font-size: 21px; } .kpi { padding: 12px; } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi .v { font-size: clamp(20px, 2.1vw, 26px); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi .d { color: var(--muted); font-size: 12px; margin-top: 2px; }
.two { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 860px) { .two { grid-template-columns: 1fr; } .grid .wide { grid-column: span 1; } }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bars text { font-size: 11px; fill: var(--muted); }
.statusbar { display: flex; height: 14px; border-radius: 99px; overflow: hidden; margin: 6px 0 12px; background: var(--grey-bg); }
.statuslist div { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.prodlist div { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.meter { grid-column: 1 / -1; height: 6px; background: var(--grey-bg); border-radius: 99px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--a-color); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; transition: transform .25s; z-index: 10; max-width: 90vw; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); }

/* v2 */
.userbox { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.userbox #who { font-weight: 600; margin-right: 4px; }
@media (max-width: 640px) { .userbox #who, #pwBtn { display: none; } }
.mt { margin-top: 12px; }
.muted { color: var(--muted); }
.sm { padding: 4px 10px; font-size: 13px; }
.danger { background: var(--bad); color: #fff; }
.danger-text { color: var(--bad) !important; }
.hint { color: var(--ok); font-weight: 600; min-height: 1em; }
label.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-weight: 500; font-size: 13px; cursor: pointer; }
label.chk input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }
.banner { background: var(--info-bg); color: var(--info); border-radius: 8px; padding: 10px 12px; margin: 0 0 12px; font-size: 13px; }
.warnline { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.count { background: var(--brand); color: #fff; border-radius: 99px; padding: 1px 9px; font-size: 12px; vertical-align: 2px; margin-left: 4px; }
.tabcount:not(:empty) { background: var(--bad-bg); color: var(--bad); border-radius: 99px; padding: 0 7px; font-size: 11px; margin-left: 6px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--grey-bg); color: var(--muted); white-space: nowrap; }
.p-ok { background: var(--ok-bg); color: var(--ok); }
.p-ask { background: var(--warn-bg); color: var(--warn); }
.p-open { background: var(--info-bg); color: var(--info); }
.b-Replacement { background: #ede7f6; color: #5e35b1; }
tr.cancelled td { color: var(--muted); text-decoration: line-through; }
tr.cancelled td:last-child, tr.cancelled td:nth-last-child(2) { text-decoration: none; }
tr.clickable, .clickable { cursor: pointer; }
tr.selrow td { background: #f6efe8; }
td.acts { white-space: nowrap; }
.more { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 10px; color: var(--muted); font-size: 13px; }
.kpi.warn .v { color: var(--bad); } .kpi.good .v { color: var(--ok); }
.statuslist i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.statuslist div.clickable:hover { background: var(--grey-bg); }
.card.attention { border-color: #e9c46a; background: #fffcf3; }
.query { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.query .ask { margin-top: 4px; } .query .answer { margin-top: 4px; color: var(--ok); }
.replyf { display: flex; gap: 6px; align-items: center; } .replyf input { min-width: 240px; }
.dupbox { background: var(--warn-bg); border-radius: 8px; padding: 10px 12px; }

dialog.modal { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--ink); }
dialog.modal.wide { width: min(980px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(30, 25, 20, .45); }
.mhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.mhead h2 { margin: 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mbody { padding: 16px 18px 20px; }
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .sides { grid-template-columns: 1fr; } }
.side { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.side h3 { margin: 0 0 8px; font-size: 14px; } .side h3.grp-s { color: var(--s-color); } .side h3.grp-a { color: var(--a-color); }
.side dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.side dt { color: var(--muted); } .side dd { margin: 0; word-break: break-word; }
.empty-side { background: #faf8f5; }
.resform, .linkbox { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.resform h3, .linkbox h3 { margin: 0 0 8px; font-size: 14px; }
.radios { display: flex; gap: 8px 18px; flex-wrap: wrap; }
.linkbox input[type=search] { width: 100%; margin-bottom: 8px; }
.linkbox td { white-space: normal; }
.hitem { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.hitem .hmeta { margin-bottom: 2px; }
.hitem s { color: var(--bad); }
details summary { cursor: pointer; font-weight: 600; }
