:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6b6860;
  --border: #e3e0d8;
  --accent: #6b3fd4;
  --on-accent: #ffffff;
  --error: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --surface: #1e1d1b;
    --text: #ecebe7;
    --muted: #9c998f;
    --border: #2f2d2a;
    --accent: #a888ff;
    --on-accent: #17102e;
    --error: #ff8a7a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar h1 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.topbar h1 span { color: var(--accent); font-weight: 500; }
.topbar h1 a { color: inherit; text-decoration: none; }

h2 { margin: 8px 0 16px; font-size: 22px; letter-spacing: -0.01em; }
.back { color: var(--muted); font-size: 14px; text-decoration: none; }
.back:hover { color: var(--text); }

.home-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  padding: 24px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 20px;
  font-weight: 650;
  text-decoration: none;
  text-align: center;
}
.action:hover { filter: brightness(1.08); }
.action:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}
.stat .num { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: 14px; }

.status { color: var(--muted); font-size: 14px; }
.status.error { color: var(--error); }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
table.inventory {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
table.inventory th,
table.inventory td {
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
table.inventory th {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  position: sticky;
  top: 0;
}
table.inventory tbody tr:last-child td { border-bottom: 0; }
table.inventory tbody tr:hover { background: var(--bg); }
/* Full inventory tables: fit the screen width, no sideways scrolling. */
main.wide { max-width: none; }
table.stack { font-size: 14px; }
table.stack th,
table.stack td { padding: 9px 10px; }
table.stack th,
table.stack td { white-space: normal; line-height: 1.3; }
table.stack td.card-name { min-width: 12ch; font-weight: 500; }

/* Narrow screens: each card becomes a stacked block of label / value lines. */
@media (max-width: 1180px) {
  .table-wrap:has(table.stack) { overflow: visible; background: transparent; border: 0; }
  table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.stack,
  table.stack tbody,
  table.stack tr,
  table.stack td { display: block; width: 100%; }
  table.stack tr {
    margin-bottom: 10px;
    padding: 6px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
  }
  table.stack tbody tr:hover { background: var(--surface); }
  table.stack td {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: normal;
  }
  table.stack td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 13px;
    text-align: left;
    flex: none;
  }
  table.stack td:last-child { border-bottom: 0; }
  table.stack td.card-name { font-size: 16px; font-weight: 600; min-width: 0; }
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Sold / Delete */
table.stack td.actions,
table.stack td.nowrap { white-space: nowrap; }
td.actions button + button { margin-left: 6px; }
button.small { padding: 5px 10px; font-size: 13px; }
button.danger { background: var(--error); border-color: var(--error); color: var(--on-accent); }
tr.out-of-stock td { color: var(--muted); }
td.status-sold { color: var(--accent) !important; font-weight: 600; }
td.status-removed { font-style: italic; }
@media (max-width: 1180px) {
  table.stack td.actions { justify-content: flex-end; gap: 8px; }
  table.stack td.actions::before { content: none; }
  table.stack td.actions button.small { padding: 8px 16px; font-size: 14px; }
}

/* £ shown inside every price box */
.money-field { position: relative; display: inline-flex; align-items: center; }
.money-field::before {
  content: "£";
  position: absolute;
  left: 8px;
  color: var(--muted);
  pointer-events: none;
}
.money-field input { padding-left: 20px !important; }
.grid-3 .money-field { display: flex; }
.grid-3 .money-field input { width: 100%; }

/* Editable price */
.price-input {
  font: inherit;
  width: 9.5ch;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.price-input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.price-input.saving { opacity: 0.6; }
.price-input.saved { border-color: var(--accent); }
.price-input.error { border-color: var(--error); color: var(--error); }
@media (max-width: 1180px) {
  table.stack td.price { align-items: center; }
  .price-input { width: 12ch; padding: 6px 8px; }
}

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.confirm-dialog::backdrop { background: rgb(0 0 0 / 0.5); }
.confirm-dialog h3 { margin: 0 0 8px; font-size: 18px; }
.dlg-card { margin: 0 0 6px; font-weight: 600; }
.dlg-qty { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); margin: 10px 0; }
.dlg-qty input {
  font: inherit;
  width: 120px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.dlg-error:empty { display: none; }
.dlg-buttons { justify-content: flex-end; margin-top: 14px; }

table.clickable tbody tr { cursor: pointer; }
table.clickable a { color: var(--accent); font-weight: 600; text-decoration: none; }
table.clickable a:hover { text-decoration: underline; }
table.inventory .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Add to inventory */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}
.panel h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 16px;
}
.step {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 13px;
  font-weight: 700;
}
.field-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.field-row.center { justify-content: center; }
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.panel label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.panel select,
.panel input[type="text"],
.panel input[type="date"] {
  font: inherit;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}
.lot-picker { display: flex; align-items: flex-end; gap: 10px; max-width: 560px; }
.lot-field { flex: 1; min-width: 0; }
.lot-menu-wrap { position: relative; flex: none; }
#lot-menu-btn { padding: 11px 14px; font-size: 15px; }
.lot-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  width: max-content;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 32px));
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgb(0 0 0 / 0.25);
}
.lot-menu-item {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  text-align: left;
}
.lot-menu-item:hover, .lot-menu-item:focus-visible { background: var(--bg); outline: none; }
.lot-menu-count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.lot-menu-empty { margin: 6px 8px; }
.lot-field input { font-size: 18px !important; }
#lot-match { margin: 8px 0 0; }
.new-lot { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

.dropzone {
  position: relative;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px !important;
  min-height: 120px;
  padding: 20px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
}
.dropzone:hover, .dropzone.over, .dropzone:focus-within { border-color: var(--accent); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone strong { color: var(--accent); font-size: 16px; }

tr.not-found td { background: color-mix(in srgb, var(--error) 8%, transparent); }
@media (max-width: 1180px) {
  table.stack tr.not-found { background: color-mix(in srgb, var(--error) 8%, var(--surface)); }
  table.stack tr.not-found td { background: transparent; }
  table.stack td .note { text-align: right; }
}
td.warn, .warn { color: var(--error); font-weight: 500; }
.note { display: block; font-size: 12px; }

.savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 -6px 18px rgb(0 0 0 / 0.12);
}
.sku-label { color: var(--muted); font-size: 14px; }
.sku-label strong { display: block; color: var(--text); font-size: 22px; letter-spacing: 0.02em; }

.done { text-align: center; padding: 32px 18px; }
.done-label { margin: 0; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; font-size: 13px; }
.done-sku { margin: 6px 0; font-size: 44px; font-weight: 750; letter-spacing: 0.02em; color: var(--accent); }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 8px 0 16px;
}
.page-head h2 { margin: 0; }

button, .button {
  display: inline-block;
  text-decoration: none;
  font: inherit;
  border-radius: 8px;
  padding: 10px 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: wait; }
.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
  padding: 6px 12px;
  font-weight: 500;
  font-size: 14px;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
}
.login-card h1 { margin: 0 0 20px; font-size: 20px; }
.login-card h1 span { color: var(--accent); font-weight: 500; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card label { font-size: 14px; color: var(--muted); }
.password-field { display: flex; gap: 8px; }
.password-field input { flex: 1; min-width: 0; }
.password-field button { flex: none; }
.login-card #password {
  font: inherit;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.login-card #password:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-card .check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.login-card .status { min-height: 1.5em; margin: 0; }
