/* Stable Book Group brand: gold #fcd68f, sage #8e9663, rust #c64b14 */
:root {
  color-scheme: light;
  --gold: #fcd68f; --sage: #8e9663; --rust: #c64b14; --gold-sage: #8c7e38; --sage-rust: #6e2c08;
  --page: #f7f3ea;
  --surface: #fffdf8;
  --ink: #16140f;
  --ink-2: #4f4b40;
  --muted: #7a7466;
  --grid: #ece6d7;
  --axis: #cfc7b3;
  --border: rgba(40, 32, 10, 0.10);
  --series: #c64b14;
  --accent-ink: #5f6640;
  --btn: #c64b14; --btn-hover: #a93d0e;
  --good: #3f6b1f;
  --bad: #9f1d2b;
  --wash: rgba(70, 60, 20, 0.06);
  --band: #fbf6ea; --hover: #f5efe1; --field-border: rgba(40, 32, 10, 0.18);
  --shadow: 0 1px 2px rgba(60, 40, 0, 0.04), 0 8px 24px rgba(60, 40, 0, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #12110e; --surface: #1d1b17; --ink: #fbf7ee; --ink-2: #cdc6b4; --muted: #9a9382;
    --grid: #2e2b24; --axis: #48443a; --border: rgba(255, 245, 220, 0.10);
    --series: #e8743f; --accent-ink: #c2c99a; --btn: #c64b14; --btn-hover: #d9591f;
    --good: #8fc35f; --bad: #ff8f8f; --wash: rgba(255, 245, 220, 0.06); --shadow: none;
    --band: #221f1a; --hover: #29261f; --field-border: rgba(255, 245, 220, 0.18);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #12110e; --surface: #1d1b17; --ink: #fbf7ee; --ink-2: #cdc6b4; --muted: #9a9382;
  --grid: #2e2b24; --axis: #48443a; --border: rgba(255, 245, 220, 0.10);
  --series: #e8743f; --accent-ink: #c2c99a; --btn: #c64b14; --btn-hover: #d9591f;
  --good: #8fc35f; --bad: #ff8f8f; --wash: rgba(255, 245, 220, 0.06); --shadow: none;
    --band: #221f1a; --hover: #29261f; --field-border: rgba(255, 245, 220, 0.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, p, dl, dd { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-ink); }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--series); outline-offset: 2px; }
.error { color: var(--bad); font-size: 13px; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); }
.mark { display: block; flex: none; }
.mark .m-gold { fill: var(--gold); } .mark .m-sage { fill: var(--sage); } .mark .m-rust { fill: var(--rust); }
.mark .m-gold-sage { fill: var(--gold-sage); } .mark .m-sage-rust { fill: var(--sage-rust); }
.wordmark { display: grid; justify-items: center; font-family: "Jost", "Futura", "Century Gothic", system-ui, sans-serif; line-height: 1; }
.wm-1 { font-size: 17px; font-weight: 500; letter-spacing: .28em; margin-right: -.28em; }
.wm-2 { font-size: 8.5px; font-weight: 500; letter-spacing: .34em; margin-right: -.34em; margin-top: 6px; }
.brand-stack { flex-direction: column; gap: 14px; margin-bottom: 8px; }
.brand-stack .mark { width: 124px; }
.brand-stack .wm-1 { font-size: 22px; }
.brand-stack .wm-2 { font-size: 11px; margin-top: 8px; }
.brand-tag { font-size: 12px; color: var(--muted); border-left: 1px solid var(--border); padding-left: 12px; margin-left: 4px; }

/* ---------- Buttons ---------- */
.ghost {
  background: transparent; color: var(--ink-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; white-space: nowrap;
}
.ghost:hover { background: var(--wash); }
.ghost:disabled { opacity: .5; cursor: progress; }
.primary { background: var(--btn); color: #fff; border: 0; border-radius: 9px; padding: 9px 16px; font-weight: 600; }
.primary:hover:not(:disabled) { background: var(--btn-hover); }
.primary:disabled { opacity: .35; cursor: not-allowed; }
.primary.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

/* ---------- Sign in ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); display: grid; gap: 16px; text-align: center;
}
.login-card h1 { font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
.login-card .muted { margin-top: -8px; font-size: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 550; color: var(--ink-2); text-align: left; }
.login-card input {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--page);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.login-card input:focus { outline: 2px solid var(--series); outline-offset: 0; border-color: transparent; }
.login-card button {
  margin-top: 4px; padding: 11px; border: 0; border-radius: 10px; font-weight: 600; background: var(--btn); color: #fff;
}
.login-card button:hover { background: var(--btn-hover); }
.login-card .rule { height: 1px; background: var(--border); margin: 4px 0 0; }

/* ---------- Layout ---------- */
.brandbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.brandbar-inner, .topbar, .wrap { max-width: 1680px; margin: 0 auto; }
.brandbar-inner { padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brandbar .mark { width: 46px; }
.bar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.bar-actions form { margin: 0; }
.who { font-size: 13px; }
.pub-pick select {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--page);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
}
.topbar { padding: 24px 24px 4px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 28px; font-weight: 650; letter-spacing: -.015em; margin-top: 2px; }
.updated { font-size: 13px; }
.wrap { padding: 16px 24px 40px; display: grid; gap: 18px; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.stat, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.stat { padding: 14px 18px; }
.stat h2 { font-size: 13px; font-weight: 550; color: var(--ink-2); }
.stat-value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.filter input {
  font: inherit; width: 100%; max-width: 360px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px;
}

.card { overflow: hidden; }
.card-head { padding: 16px 18px 10px; display: flex; align-items: baseline; gap: 6px 16px; flex-wrap: wrap; }
.card-head h2 { font-size: 17px; font-weight: 650; }
.card-head .muted { font-size: 13px; }
.count {
  font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--wash);
  border-radius: 999px; padding: 1px 8px; margin-left: 4px; vertical-align: 2px;
}

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; max-height: 70vh; border-top: 1px solid var(--border); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  position: sticky; top: 0; z-index: 2; background: var(--surface); color: var(--ink-2);
  font-weight: 600; font-size: 12px; line-height: 1.25; white-space: nowrap;
}
th.r, td.r { text-align: right; }
tbody tr:hover td { background: var(--hover); }
td.c-isbn { white-space: nowrap; color: var(--ink-2); }
td.c-title { min-width: 200px; max-width: 280px; font-weight: 550; }
td.c-pub_date, td.c-order_date, td.c-est_warehouse_date { white-space: nowrap; }
td.warn { color: var(--rust); font-weight: 650; }
td.zero { color: var(--bad); }
td.empty { text-align: center; color: var(--muted); padding: 24px; }

/* keep ISBN + title visible while scrolling sideways */
th.c-isbn, td.c-isbn { position: sticky; left: 0; z-index: 1; background: var(--surface); }
th.c-title, td.c-title { position: sticky; left: 118px; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--border); }
th.c-isbn, th.c-title { z-index: 3; }
th.c-isbn, td.c-isbn { min-width: 118px; }

/* print-run columns get a tinted band */
th.c-po_number, th.c-order_date, th.c-est_warehouse_date, th.c-quantity, th.c-printer, th.c-carton_qty,
td.in, td.run { background: var(--band); }
th.c-po_number, td.c-po_number { border-left: 1px solid var(--border); }
td.in { padding: 5px 4px; }
td.in input {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--field-border); border-radius: 7px; padding: 5px 7px; width: 100%;
}
td.in input:focus { outline: 2px solid var(--series); outline-offset: -1px; border-color: transparent; }
td.in input.bad { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
td.c-po_number input { min-width: 104px; }
td.c-order_date input, td.c-est_warehouse_date input { min-width: 128px; }
td.c-quantity input { min-width: 76px; }
td.c-printer input { min-width: 110px; }
td.c-carton_qty input { min-width: 64px; }
td.c-action { padding: 5px 12px 5px 6px; }
.due { display: inline-block; margin-left: 6px; font-size: 11px; color: var(--accent-ink); background: var(--wash); border-radius: 999px; padding: 0 6px; }
tr.frozen td { color: var(--ink-2); }

/* ---------- Dialog + toast ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0,0,0,.25); width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(20, 16, 6, .45); }
.dialog-body { padding: 22px 22px 18px; display: grid; gap: 12px; }
.dialog-body h2 { font-size: 18px; font-weight: 650; line-height: 1.3; }
.dialog-body dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; background: var(--wash); border-radius: 10px; padding: 12px 14px; }
.dialog-body dt { color: var(--ink-2); }
.dialog-body dd { font-weight: 600; font-variant-numeric: tabular-nums; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px);
}
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 1000px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .brandbar-inner { padding: 10px 16px; }
  .brand-tag, .who { display: none; }
  .topbar { padding: 18px 16px 0; }
  .topbar h1 { font-size: 22px; }
  .wrap { padding: 12px 16px 32px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 22px; }
  th.c-title, td.c-title { position: static; }
  td.c-title { min-width: 160px; }
}

/* ---------- Nav + admin ---------- */
a.brand { text-decoration: none; }
.tabs { display: inline-flex; background: var(--wash); border-radius: 999px; padding: 2px; }
.tabs a { color: var(--ink-2); text-decoration: none; font-size: 13px; padding: 5px 12px; border-radius: 999px; }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.brandbar-sub { border-bottom: 1px solid var(--border); background: var(--band); }
.brandbar-sub .brandbar-inner { padding: 8px 24px; justify-content: flex-start; }
.pub-pick { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }

.admin a { color: var(--rust); }
.card.pad { padding: 18px; display: grid; gap: 10px; align-content: start; }
.card.pad h2, .admin .card-head h2 { font-size: 17px; font-weight: 650; }
.card.pad > .muted { font-size: 13px; }
.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-form.pad-x { padding: 14px 18px 18px; }
.form-label { font-size: 13px; margin-right: 4px; }
.row-form input[type="text"], .row-form input[type="email"], .row-form select, .inline-form input {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--field-border); border-radius: 8px; padding: 7px 10px; min-width: 200px;
}
.row-form input[type="file"] { font-size: 13px; }
.inline-form { display: flex; gap: 6px; }
.inline-form input { min-width: 180px; padding: 5px 8px; }
table.simple td, table.simple th { white-space: nowrap; }
table.simple th { position: static; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.links { margin: 0; padding-left: 18px; font-size: 14px; display: grid; gap: 4px; }
.banner { border-radius: 12px; padding: 12px 16px; font-size: 14px; border: 1px solid var(--border); }
.banner.ok { background: color-mix(in srgb, var(--good) 12%, var(--surface)); }
.banner.bad { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); color: var(--bad); }
.banner.pw { background: color-mix(in srgb, var(--gold) 35%, var(--surface)); display: grid; gap: 8px; }
.pw-code { font: 600 18px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; user-select: all; }
@media (max-width: 800px) { .two-col { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) { .brandbar-sub .brandbar-inner { padding: 8px 16px; } .tabs a { padding: 5px 9px; } }

/* ---------- Sort + filter headers ---------- */
thead { position: sticky; top: 0; z-index: 3; }
thead th { position: static; }
th.c-isbn, th.c-title { position: sticky; }
thead tr.labels th { padding-bottom: 2px; border-bottom: 0; }
thead tr.filters th { padding-top: 2px; padding-bottom: 6px; }
button.sort {
  all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 3px; white-space: nowrap;
  font-weight: 600; font-size: 12px; color: var(--ink-2);
}
button.sort:hover { color: var(--ink); }
button.sort:focus-visible { outline: 2px solid var(--series); outline-offset: 2px; border-radius: 3px; }
th[aria-sort="ascending"] button.sort, th[aria-sort="descending"] button.sort { color: var(--rust); }
.arrow { font-size: 9px; min-width: 9px; }
th.r button.sort { justify-content: flex-end; width: 100%; }
.col-filter {
  font: inherit; font-size: 12px; font-weight: 400; width: 100%; min-width: 64px; color: var(--ink);
  background: var(--page); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px;
}
.col-filter::placeholder { color: var(--muted); opacity: .7; }
th.active .col-filter { border-color: var(--rust); background: var(--surface); }
th.r .col-filter { text-align: right; }
th.band, td.band { background: var(--band); }
td.c-format.muted { color: var(--muted); }
td.c-country_of_origin select, td.in select {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--field-border); border-radius: 7px; padding: 5px 4px; min-width: 150px; max-width: 190px;
}
td.in select.bad { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
td.c-format { white-space: nowrap; }
td.strong { font-weight: 600; }
.filter { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card-head .csv { margin-left: auto; }
.link-btn { background: none; border: 0; padding: 0; color: var(--bad); font-size: 12px; text-decoration: underline; }

/* ---------- Admin additions ---------- */
.upload-form { display: grid; gap: 10px; }
.upload-form label { display: grid; gap: 4px; font-size: 13px; font-weight: 550; color: var(--ink-2); }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--ink-2); }
.head-action { margin-left: auto; }
.tag { font-size: 11px; font-weight: 600; color: var(--rust); background: color-mix(in srgb, var(--rust) 12%, var(--surface)); border-radius: 999px; padding: 1px 7px; margin-left: 4px; }
.pw-table { border-collapse: collapse; width: auto; font-size: 14px; }
.pw-table td { border: 0; padding: 3px 18px 3px 0; white-space: nowrap; }
.pw-table .pw-code { font-size: 15px; }
td.wrap-cell { white-space: normal !important; min-width: 280px; }
@media (max-width: 1000px) { .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
table.no-sticky th.c-isbn, table.no-sticky td.c-isbn, table.no-sticky th.c-title, table.no-sticky td.c-title {
  position: static; box-shadow: none; background: transparent;
}
table.no-sticky th { background: var(--surface); }
table.no-sticky th.band { background: var(--band); }
.pb-actions { display: grid; gap: 10px; padding-top: 0; padding-bottom: 14px; }
.pb-actions p { margin: 0; font-size: 14px; }
.inline-label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.inline-label input { font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--field-border); border-radius: 8px; padding: 6px 8px; }
td.c-price_change_us input, td.c-price_change_ca input { min-width: 84px; }
td.c-print_number input { min-width: 64px; }
.money-in { position: relative; display: block; }
.money-in::before { content: "$"; position: absolute; left: 7px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }
.money-in input { padding-left: 16px !important; }

/* ---------- Perfect Bound logo, centered in the header ---------- */
.brandbar > .brandbar-inner { display: grid; grid-template-columns: 1fr auto 1fr; }
.brandbar > .brandbar-inner > .brand { justify-self: start; }
.brandbar > .brandbar-inner > .bar-actions { justify-self: end; }
.pb-logo { display: block; border-radius: 50%; line-height: 0; transition: transform .15s ease; }
.pb-logo:hover { transform: scale(1.06); }
.pb-logo img { display: block; width: 40px; height: 40px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pb-logo { box-shadow: 0 0 0 1.5px rgba(255, 245, 220, .35); }
}
:root[data-theme="dark"] .pb-logo { box-shadow: 0 0 0 1.5px rgba(255, 245, 220, .35); }
@media (max-width: 640px) { .pb-logo img { width: 32px; height: 32px; } }
.wordmark span { white-space: nowrap; }
@media (max-width: 640px) {
  .brandbar > .brandbar-inner { grid-template-columns: auto 1fr auto; gap: 10px; }
  .brandbar > .brandbar-inner > .pb-logo { justify-self: center; }
  .brandbar .mark { width: 38px; }
  .brandbar .wm-1 { font-size: 13px; letter-spacing: .2em; margin-right: -.2em; }
  .brandbar .wm-2 { font-size: 7px; }
}
