/* The Ashen Merchant — an Ashlander tent in Skyrim. Volcanic ash
   instead of slate, bone instead of paper, an ember accent. The one
   bold element is still the price tag, recast as a bone plate on a cord
   with an ember bead. (Variable names are the template's; the values
   are the Ashlands'.) */
:root {
  color-scheme: dark;
  --slate: #29231f;        /* ash */
  --slate-deep: #201b18;   /* scorched ash */
  --slate-raised: #342c27;
  --line: #4e423a;
  --chalk: #ede3d0;        /* bone */
  --chalk-dim: #b3a596;
  --tag: #e6d5b2;          /* bonemold */
  --tag-ink: #2b1d14;
  --string: #e07a3f;       /* ember */
  --string-ink: #231510;
  --red: #a8453b;
  --red-text: #f08c7c;
  --serif: 'Almendra', Georgia, serif;
  --sans: 'Atkinson Hyperlegible', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--slate); color: var(--chalk); font-family: var(--sans); font-size: 16px; line-height: 1.5; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.15; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--string); outline-offset: 2px; }
.boot { padding: 48px 24px; color: var(--chalk-dim); }
.muted { color: var(--chalk-dim); }
.error-text { color: var(--red-text); }

/* ---- Top bar ------------------------------------------------------- */
.topbar { background: var(--slate-deep); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 960px; margin: 0 auto; padding: 14px 24px 0; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 24px; }
.store-name { font-family: var(--serif); font-size: 26px; font-weight: 700; padding-bottom: 12px; margin-right: auto; }
.who { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; font-size: 14px; color: var(--chalk-dim); }
.who strong { color: var(--chalk); font-weight: 700; }
.tabs { width: 100%; display: flex; gap: 4px; overflow-x: auto; }
.tabs button { background: none; border: none; border-bottom: 3px solid transparent; padding: 10px 14px; color: var(--chalk-dim); cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--chalk); }
.tabs button[aria-current="page"] { color: var(--chalk); border-bottom-color: var(--string); font-weight: 700; }

main { max-width: 960px; margin: 0 auto; padding: 28px 24px 96px; }
.page-title { font-size: 32px; margin-bottom: 6px; }
.page-lead { color: var(--chalk-dim); margin: 0 0 24px; max-width: 64ch; }
section.block { margin-bottom: 36px; }
section.block > h2 { font-size: 22px; margin-bottom: 12px; }

/* ---- Controls ------------------------------------------------------ */
label.field { display: block; margin-bottom: 14px; }
/* Buttons sit beside fields in a row but must never be inside a <label>,
   or the label takes over the button's accessible name. */
.field-action { margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; color: var(--chalk-dim); margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; background: var(--slate-deep); border: 1px solid var(--line); border-radius: 4px; padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { border-color: var(--string); outline: none; box-shadow: 0 0 0 1px var(--string); }
.btn { background: var(--string); color: var(--string-ink); border: 1px solid var(--string); border-radius: 4px; padding: 9px 16px; font-weight: 700; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.55; cursor: default; filter: none; }
.btn.quiet { background: transparent; color: var(--chalk); border-color: var(--line); font-weight: 400; }
.btn.quiet:hover { border-color: var(--chalk-dim); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.row > .grow { flex: 1 1 220px; }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--chalk-dim); font-size: 15px; cursor: pointer; }

/* ---- Sign-in / setup ---------------------------------------------- */
.gate { max-width: 400px; margin: 10vh auto 0; padding: 0 24px; }
.gate h1 { font-size: 34px; margin-bottom: 4px; }
.gate p.motto { font-family: var(--serif); font-style: italic; color: var(--string); margin: 0 0 10px; font-size: 17px; }
.gate p.lead { color: var(--chalk-dim); margin: 0 0 24px; }
.gate .btn { width: 100%; margin-top: 6px; padding: 11px; }
.form-error { color: var(--red-text); margin: 0 0 12px; min-height: 1.5em; }

/* ---- Price board (Clerk) ------------------------------------------ */
.board-cat { margin-bottom: 30px; }
.board-cat h2 { font-size: 22px; margin-bottom: 10px; color: var(--chalk); }
.board-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.board-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-row .leader { flex: 1; border-bottom: 2px dotted var(--line); transform: translateY(4px); min-width: 16px; }
.tag {
  position: relative; flex-shrink: 0; min-width: 92px; text-align: right;
  background: var(--tag); color: var(--tag-ink); font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 4px 10px 4px 20px;
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 10px 100%, 0 50%);
}
.tag::before { content: ''; position: absolute; left: 8px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--string); box-shadow: 0 0 0 1.5px var(--tag-ink); }

/* ---- Price editor (Shopkeeper) ------------------------------------ */
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin-bottom: 20px; }
.editor-toolbar input[type="search"] { flex: 1 1 260px; }
.edit-row { display: grid; grid-template-columns: 1fr 120px 120px; gap: 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--slate-raised); }
.edit-row input { text-align: right; font-variant-numeric: tabular-nums; }
.edit-row input.changed { border-color: var(--string); }
.edit-row .unpriced { color: var(--chalk-dim); }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--slate-deep); border-top: 1px solid var(--string);
  padding: 12px 24px; display: flex; justify-content: center; gap: 12px; align-items: center;
}
.savebar[hidden] { display: none; }

/* ---- Tables (purchases, employees) -------------------------------- */
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; font-weight: 700; color: var(--chalk-dim); font-size: 14px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--slate-raised); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.status-off { color: var(--red-text); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.line-grid { display: grid; grid-template-columns: 1fr 110px 120px 40px; gap: 8px; align-items: center; margin-bottom: 8px; }
.line-grid .remove { background: none; border: none; color: var(--chalk-dim); font-size: 20px; cursor: pointer; line-height: 1; }
.line-grid .remove:hover { color: var(--red-text); }
.purchase-total { font-family: var(--serif); font-size: 20px; margin-left: auto; }
.empty { color: var(--chalk-dim); padding: 18px 0; }

#toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: var(--chalk); color: var(--slate-deep); padding: 10px 18px; border-radius: 4px; font-weight: 700; display: none; max-width: calc(100vw - 32px); z-index: 30; }
#toast.show { display: block; }
#toast.bad { background: var(--red); color: #fff; }

@media (max-width: 600px) {
  main { padding: 20px 16px 96px; }
  .topbar-inner { padding: 12px 16px 0; }
  .page-title { font-size: 27px; }
  .line-grid { grid-template-columns: 1fr 80px 90px 32px; }
  .edit-row, .edit-head { grid-template-columns: 1fr 84px 84px; }
  .tag, .board-head span { min-width: 74px; }
}

/* ---- Quick purchase pop-up ---------------------------------------- */
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-bottom: 12px; }
.section-head h2 { font-size: 22px; }
.modal-overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.62); display: flex; justify-content: center; align-items: flex-start; padding: 5vh 16px; overflow-y: auto; }
.modal { width: min(880px, 100%); background: var(--slate); border: 1px solid var(--line); border-radius: 6px; padding: 20px 22px; }
.modal-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-bottom: 6px; }
.modal-head h2 { font-size: 26px; }
.modal-actions { display: flex; gap: 8px; }
.modal-lead { margin: 0 0 12px; }
.qp-scroll { max-height: 46vh; overflow-y: auto; margin: 12px 0; padding: 0 6px 12px 0; border-bottom: 1px solid var(--line); }
.qp-cat { font-family: var(--serif); font-weight: 700; font-size: 18px; margin: 14px 0 6px; }
.qp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; }
.qp-cell { display: grid; grid-template-columns: 1fr 88px 68px; gap: 8px; align-items: center; }
.qp-cell input { padding: 6px 8px; text-align: right; font-variant-numeric: tabular-nums; }
.qp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qp-total { font-family: var(--serif); font-size: 19px; margin: 0 0 14px; }
@media (max-width: 720px) {
  .qp-grid { grid-template-columns: 1fr; }
  .modal { padding: 16px; }
}

/* ---- Hold prices (Shopkeeper only) -------------------------------- */
.hold-note { display: block; font-size: 13px; color: var(--chalk-dim); }
.profit { font-size: 13px; color: var(--chalk-dim); }
.loss { font-size: 13px; color: var(--red-text); }
.small-note { font-size: 12px; }

/* ---- Buy / sell columns ------------------------------------------- */
.edit-head { display: grid; grid-template-columns: 1fr 120px 120px; gap: 12px; font-size: 14px; font-weight: 700; color: var(--chalk-dim); text-align: right; margin-bottom: -4px; }
.board-head { display: flex; justify-content: flex-end; gap: 12px; font-size: 14px; font-weight: 700; color: var(--chalk-dim); margin-bottom: -10px; }
.board-head span { min-width: 92px; text-align: right; }
.board-row .tag + .tag { margin-left: 0; }
.tag-empty { background: transparent; color: var(--chalk-dim); clip-path: none; font-weight: 400; }
.tag-empty::before { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.history-note { margin: -4px 0 12px; font-size: 14px; }
.nowrap, th.num { white-space: nowrap; }

/* ---- Products page ------------------------------------------------ */
.product-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--slate-raised); }
.custom-mark { font-size: 12px; font-style: italic; color: var(--chalk-dim); margin-left: 6px; }
.hold-input { width: 150px; }
.removed-block .product-row > span { color: var(--chalk-dim); }

.row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.product-edit { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 12px; padding: 12px 0 4px; border-bottom: 1px solid var(--slate-raised); }
.product-edit .grow { flex: 1 1 180px; }
.edit-actions { display: flex; gap: 8px; }
.edit-hint { flex-basis: 100%; margin: 0 0 10px; }
.edited-mark { font-style: italic; }

/* ---- Purchase ledger ---------------------------------------------- */
.ledger-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.ledger-store { font-family: var(--serif); font-size: 18px; margin: 0 0 2px; color: var(--chalk-dim); }
.ledger-meta { margin: 0 0 18px; }
.ledger-subtotal td { font-weight: 700; border-bottom: 2px solid var(--line); }
.ledger-subtotal td:first-child { text-align: right; }
.ledger-grand td { font-family: var(--serif); font-weight: 700; font-size: 18px; border-top: 2px solid var(--chalk-dim); border-bottom: none; }
.ledger-grand td:first-child { text-align: right; }

/* Printing (or "Save as PDF"): just the ledger, black on white. */
@media print {
  html, body { background: #fff !important; }
  .topbar, .no-print, #toast, .savebar { display: none !important; }
  main { max-width: none; padding: 0; }
  .ledger, .ledger * { color: #000 !important; }
  .ledger th, .ledger td { border-color: #999 !important; }
  .ledger .table-wrap { overflow: visible; }
  .ledger tr { break-inside: avoid; }
}

/* ---- Overview ----------------------------------------------------- */
.summary-table th[scope="row"] { font-weight: 400; color: var(--chalk); font-size: 15px; border-bottom: 1px solid var(--slate-raised); white-space: nowrap; }
.summary-table td { font-variant-numeric: tabular-nums; }
.signed-pos { color: var(--chalk); }
.signed-neg { color: var(--red-text); }
.issue-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--slate-raised); }
.issue-row p { margin: 0; max-width: 70ch; }
.overview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 28px; }

/* ---- Receipts ----------------------------------------------------- */
.receipt { width: min(420px, 100%); }
.receipt-paper { background: var(--tag); color: var(--tag-ink); padding: 26px 26px 18px; border-radius: 2px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4); }
.receipt-store { font-family: var(--serif); font-size: 20px; font-weight: 700; text-align: center; margin: 0; }
.receipt-paper h2 { text-align: center; font-size: 17px; font-family: var(--sans); margin: 2px 0 14px; }
.receipt-meta { font-size: 14px; margin: 0 0 12px; padding-bottom: 12px; border-bottom: 1px dashed rgba(58, 46, 28, 0.45); }
.receipt-lines { width: 100%; font-size: 15px; }
.receipt-lines td, .receipt-lines th { color: var(--tag-ink); border-bottom: 1px dashed rgba(58, 46, 28, 0.3); padding: 7px 0; }
.receipt-each { font-size: 13px; opacity: 0.8; }
.receipt-lines tfoot th, .receipt-lines tfoot td { font-size: 17px; font-weight: 700; border-bottom: none; border-top: 2px solid var(--tag-ink); padding-top: 10px; text-align: left; }
.receipt-lines tfoot td { text-align: right; }
.receipt-foot { text-align: center; font-size: 12.5px; margin: 14px 0 0; opacity: 0.85; }
.receipt-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* Printing with a receipt open: just the receipt. */
@media print {
  html.receipt-open .topbar, html.receipt-open main > :not(.receipt-overlay), html.receipt-open .receipt-actions { display: none !important; }
  html.receipt-open .receipt-overlay { position: static; background: none; padding: 0; display: block; }
  html.receipt-open .receipt-paper { box-shadow: none; border: 1px solid #999; }
}
