:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #6b7684;
  --line: #dfe3e8;
  --brand: #0b5fff;
  --good: #1a7f45;
  --warn: #b23c17;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

header h1 { font-size: 17px; margin: 0; }
header .sub { color: var(--muted); font-size: 13px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 30px; width: auto; display: block; flex: 0 0 auto; }

/* Drag a column header's right edge to resize it. Native CSS resize; survives
   body re-renders because the <th> elements are static. */
table.resizable th { resize: horizontal; overflow: hidden; min-width: 3em; }

main { max-width: 1040px; margin: 0 auto; padding: 20px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.panel h2 { font-size: 15px; margin: 0 0 12px; }

.centred { max-width: 380px; margin: 12vh auto; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  color: inherit;
}

textarea { min-height: 120px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; }

button {
  padding: 9px 16px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.secondary { background: #fff; color: var(--ink); border-color: var(--line); font-weight: 500; }
button.small { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Icon buttons: square and inline, so a row of actions can't stack and
   triple the row height. */
button.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: #fff;
  color: var(--muted);
  border-color: var(--line);
}

button.icon:hover { color: var(--brand); border-color: var(--brand); }
button.icon.danger:hover { color: var(--warn); border-color: var(--warn); }

/* Keep an action group on one line - wrapped buttons were setting the row
   height across the whole table. */
td.actions {
  white-space: nowrap;
  text-align: right;
}

/* Uniform height so a text button and an icon button sit flush. */
td.actions button { margin-left: 4px; vertical-align: middle; height: 30px; }

/* One width for every row action, so the cancel icon lines up down the column
   instead of shifting with each label's length. */
td.actions button.small {
  padding: 0 10px;
  min-width: 92px;
}

td.nowrap { white-space: nowrap; }

td a { color: var(--brand); text-decoration: none; }
td a:hover { text-decoration: underline; }

/* Truncate to one line; the full value is in the cell's title attribute. */
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

td.buyer-cell { max-width: 240px; }
td.items-cell { max-width: 220px; }

/* A cancelled order stays in the list as history, visibly struck out. */
tr.cancelled-row td { color: var(--muted); }
tr.cancelled-row td:nth-child(2),
tr.cancelled-row td:nth-child(3),
tr.cancelled-row td:nth-child(5) { text-decoration: line-through; }
tr.cancelled-row { background: repeating-linear-gradient(45deg, transparent, transparent 8px, rgba(0, 0, 0, .015) 8px, rgba(0, 0, 0, .015) 16px); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td.num, th.num { text-align: right; }
td input[type="number"] { width: 90px; text-align: right; }

.msg { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 14px; }
.msg.error { background: #fdeceb; color: var(--warn); }
.msg.ok { background: #e8f5ec; color: var(--good); }
.msg ul { margin: 6px 0 0 18px; padding: 0; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: #eef1f5;
  color: var(--muted);
}

.tag.submitted { background: #fff3e0; color: #91560a; }
.tag.invoiced { background: #e7effe; color: #0b47b8; }
.tag.paid { background: #e8f5ec; color: var(--good); }
.tag.error { background: #fdeceb; color: var(--warn); }

.muted { color: var(--muted); font-size: 13px; }
.oos { color: var(--muted); }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button { background: #fff; color: var(--ink); border-color: var(--line); font-weight: 500; }
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Second-level nav. Underlined rather than pilled so it reads as subordinate
   to the primary tabs instead of competing with them. */
.subtabs {
  display: flex;
  gap: 4px;
  margin: -6px 0 16px;
  border-bottom: 1px solid var(--line);
}

.subtabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 12px;
  color: var(--muted);
  font-weight: 500;
}

.subtabs button:hover { color: var(--ink); }

.subtabs button.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

.code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 17px;
  letter-spacing: .12em;
  background: #eef1f5;
  padding: 4px 8px;
  border-radius: 5px;
}

.hidden { display: none; }

.total-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

.total-bar strong { font-size: 18px; }

/* Buyer offer table: header and action bar stay put while the list scrolls.
   The table deliberately has no overflow wrapper - position:sticky resolves
   against the nearest scrolling ancestor, and an overflow wrapper would make
   that the wrapper instead of the page, so nothing would appear to stick. */
.offer-table { width: 100%; border-collapse: separate; border-spacing: 0; }

.offer-table th,
.offer-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}

.offer-table th.num, .offer-table td.num { text-align: right; }

.offer-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  /* A sticky cell's own border scrolls away with the row, so draw the rule
     as an inset shadow instead. */
  border-bottom: 0;
  box-shadow: inset 0 -1px var(--line);
}

.total-bar.sticky {
  position: sticky;
  bottom: 0;
  z-index: 3;
  background: var(--panel);
  margin: 4px -18px -18px;
  padding: 14px 18px;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 -6px 14px -12px rgba(0, 0, 0, .5);
}

/* Narrow screens: compress the table rather than wrap it in a scroller, which
   would take the sticky header's scroll container away from the page. */
@media (max-width: 700px) {
  .offer-table th,
  .offer-table td { padding: 7px 4px; font-size: 13px; }
  /* Give the item name all the leftover width; shrink every other column to
     its content so a long title wraps in 2-3 lines instead of ~15. */
  .offer-table th:nth-child(3), .offer-table td:nth-child(3),
  .offer-table th:nth-child(4), .offer-table td:nth-child(4),
  .offer-table th:nth-child(5), .offer-table td:nth-child(5) { width: 1%; }
  .offer-table td:nth-child(3),
  .offer-table td:nth-child(4),
  .offer-table td:nth-child(5) { white-space: nowrap; }
  .offer-table td:nth-child(2) { word-break: break-word; }
  /* Hide SKU (col 1) and Line total (col 6) on a phone - keep Available so the
     buyer sees what's left to buy; the running total is already in the bar. */
  .offer-table th:nth-child(1), .offer-table td:nth-child(1),
  .offer-table th:nth-child(6), .offer-table td:nth-child(6) { display: none; }
  .offer-table td input[type="number"] { width: 48px; }
  /* Dragging column widths isn't practical on touch; drop the handle + clipping. */
  table.resizable th { resize: none; overflow: visible; }
  .total-bar.sticky { flex-wrap: wrap; gap: 6px 12px; padding: 10px 14px; }
  .total-bar.sticky button { flex: 1 1 100%; }
  main { padding: 12px; }
  .panel { padding: 14px; }
  .total-bar.sticky { margin: 4px -14px -14px; }
}

/* Order history cards */
.order-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.order-card header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  background: none;
  border: 0;
  padding: 0 0 8px;
}

.order-card .lines {
  margin: 8px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.order-card .lines div { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }

.tag.pending-confirmation { background: #fff3e0; color: #91560a; }
.tag.pending-payment { background: #e7effe; color: #0b47b8; }
.tag.processing { background: #ece7fd; color: #4c2fb8; }
.tag.fulfilled { background: #e8f5ec; color: var(--good); }
.tag.cancelled, .tag.attention { background: #fdeceb; color: var(--warn); }

.track {
  display: inline-block;
  margin: 6px 8px 0 0;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  text-decoration: none;
  color: var(--brand);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 10px;
}

.filters > * { flex: 0 1 150px; }
.filters .grow { flex: 1 1 260px; }
.filters .narrow { flex: 0 1 110px; }
.filters label { margin-bottom: 4px; }
.filters button { width: 100%; }
