/* Procurement v2 — one dense stylesheet. No frameworks, fonts, or animations.
   Palette tokens mirror website/src/styles/global.css: cream background, ink
   text, orange accents.
   Rhythm: every control is 2.4rem tall, toolbars are soft plates, tables are
   dense but even. */

* { box-sizing: border-box; }

:root {
  --ink: #1c1c1c;
  --ink-soft: #44433c;
  --muted: #5f5d54;
  --line: #ddd9cb;
  --line-strong: #c9c4b1;
  --accent: #ef7334;
  --accent-deep: #d85f22;
  --accent-text: #b34a0a;
  --on-accent: #1c1c1c;
  --bg: #f7f5e7;
  --bg-soft: #efecd9;
  --card: #ffffff;
  --danger: #b3261e;
  --ok: #1e6b34;
  --warn: #8a6d00;
  --radius: 6px;
}

html {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}

/* Laptops have the room: use the viewport with a comfortable gutter
   instead of a centred 1100px column. */
body { margin: 0; padding: 0 clamp(1rem, 2vw, 2rem) 3rem; }

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.3rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.6rem; }

/* form controls: one consistent box — same height, border, radius, fill.
   :where keeps the base at zero specificity so contexts (sheet grid, table
   cells) can override without specificity fights. */

input,
select,
textarea { font: inherit; color: var(--ink); }

:where(input:not([type='checkbox']):not([type='radio']), select, textarea) {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
}

:where(input:not([type='checkbox']):not([type='radio']):not([type='file']), select) {
  height: 2.4rem;
}

input[type='checkbox'],
input[type='radio'] { accent-color: var(--accent); }

:is(input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* the server refuses a bad save loudly; the browser points at the exact cell
   first: modern engines flag a touched, invalid control (type=number junk,
   out-of-range values) so the user sees which cell to fix before saving */
input:user-invalid {
  border-color: var(--warn);
  box-shadow: 0 0 0 2px #fdebd3;
}

button:focus-visible,
.button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* header + nav */

.site-header {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.75rem 0; border-bottom: 1px solid var(--line-strong); margin-bottom: 1.5rem;
}

.brand { font-weight: 700; font-size: 1.05rem; color: var(--ink); }

.site-nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }

.site-nav a { padding: 0.35rem 0.75rem; border-radius: var(--radius); color: var(--muted); }

.site-nav a:hover { color: var(--ink); text-decoration: none; background: var(--bg-soft); }

.site-nav a.active { color: var(--on-accent); background: var(--accent); }

.user-chip { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; color: var(--muted); }

.user-chip .who { font-weight: 600; color: var(--ink); }

/* dense tables */

table { border-collapse: collapse; width: 100%; background: var(--card); font-variant-numeric: tabular-nums; }

th,
td {
  padding: 0.5rem 0.65rem; border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: middle;
}

thead th { background: var(--bg-soft); border-bottom: 1px solid var(--line-strong); }

tbody tr:nth-child(even) { background: #faf8ee; }

td.num,
th.num { text-align: right; font-variant-numeric: tabular-nums; }

.total-row td { font-weight: 700; background: var(--bg-soft); border-top: 1px solid var(--line-strong); }

.total-row.grand td { border-top: 2px solid var(--line-strong); }

/* the department sheet grid: one input per cell, sized to its column (kept
   denser than the global controls — it is a data-entry grid) */

.sheet-scroll { overflow-x: auto; max-width: 100%; }
.sheet-scroll table td .row-input { width: 100%; min-width: 0; }
.row-form { display: none; }
/* Audit timestamps never wrap; sheet first columns (dates, dept) may wrap
   rather than paint over the next cell. */
.audit-table td:first-child { white-space: nowrap; }
.sheet-grid input[type='number'] { appearance: textfield; -moz-appearance: textfield; }
.sheet-grid input[type='number']::-webkit-inner-spin-button,
.sheet-grid input[type='number']::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Long marketing URLs must not starve the Item column: the cell clips its
   link to one line with an ellipsis; the full URL stays in the DOM. */
.order-table td.order-link { overflow: hidden; }
.order-table td.order-link a { display: block; width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-table td.num { white-space: nowrap; }
/* The sheet tables share fixed column proportions (colgroups in the views):
   every column and the SUBTOTAL stay on screen at any width. */
.order-table { table-layout: fixed; width: 100%; }
.order-table th { white-space: nowrap; font-size: 0.72rem; overflow: hidden; text-overflow: ellipsis; }
.order-table td { overflow-wrap: anywhere; }
.sheet-grid input, .sheet-grid select { width: 100%; min-width: 0; }

.sheet-grid td { padding: 4px 6px; }

.sheet-grid input {
  height: auto; min-height: 0;
  width: 100%; padding: 5px 6px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
}

/* Same specificity beat as the cell rule above: the invalid highlight must
   win inside the grid too, not only on plain form fields. */
.sheet-grid input:user-invalid {
  border-color: var(--warn);
  box-shadow: 0 0 0 2px #fdebd3;
}

.sheet-grid input::placeholder { color: var(--muted); }

/* No per-input minimums: the column proportions own the width, and a
   min-width here would overflow the fixed-layout cell and overlap the next
   input. Numeric cells still right-align. */
.sheet-grid .in-num,
.sheet-grid .in-qty { text-align: right; }
.sheet-grid input[type='date'] { padding-inline: 4px; font-size: 0.85rem; }
.sheet-grid input[type='number'] { padding-inline: 2px; font-size: 0.85rem; }
.sheet-grid input[type='checkbox'] { width: auto; }

.sheet-grid th.check,
.sheet-grid td.check { text-align: center; padding: 4px; }

.row-error-row td {
  padding: 0 6px 5px; background: #fbeeea; border-bottom: 1px solid #f0c4c0;
}

.row-error { color: var(--danger); font-size: 0.85rem; }

/* forms */

form.inline {
  display: inline-flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  vertical-align: middle;
}

.field { margin-bottom: 0.9rem; }

.field label {
  display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem;
}

.field input,
.field select,
.field textarea { width: 100%; }

/* buttons: same 2.4rem height as the controls they sit next to */

button,
.button {
  font: inherit; display: inline-flex; align-items: center; justify-content: center;
  height: 2.4rem; padding: 0 1rem; line-height: 1;
  border: 1px solid var(--accent-deep); border-radius: var(--radius);
  background: var(--accent); color: var(--on-accent);
  cursor: pointer; text-decoration: none;
}

button:hover,
.button:hover { background: var(--accent-deep); color: var(--on-accent); text-decoration: none; }

button:disabled { opacity: 0.55; cursor: default; }

button.subtle,
.button.subtle,
button.secondary,
.button.muted { background: var(--card); color: var(--accent-text); border-color: var(--line-strong); }

button.subtle:hover,
.button.subtle:hover,
.button.muted:hover { background: var(--bg-soft); }

button.link {
  display: inline; min-height: 0; padding: 0; border: none; background: none;
  color: var(--accent-text); text-decoration: underline;
}

button.link:hover { background: none; color: var(--accent-deep); }

button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

button.danger:hover { background: #921d16; }

/* status + role badges */

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.78rem;
  border: 1px solid var(--line-strong); background: var(--bg-soft); color: var(--ink); white-space: nowrap;
}

.badge.role-admin { background: #3b1f5e; border-color: #3b1f5e; color: #fff; }

.badge.role-procurement { background: var(--accent); border-color: var(--accent-deep); color: var(--on-accent); }

.badge.role-id,
.badge.role-ea,
.badge.role-op { background: #f3e3c8; border-color: #e0cb9f; color: var(--ink-soft); }

.badge.sheet-empty { background: var(--bg-soft); color: var(--muted); }

.badge.sheet-draft { background: #fff4d6; border-color: #e8d49a; }

.badge.sheet-locked { background: #fdebd3; border-color: #ecc794; color: var(--warn); }

.badge.sheet-submitted { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.badge.sheet-completed { background: #dce7dd; border-color: #b5cbb8; color: var(--ok); }

.badge.status-recorded { background: var(--card); color: var(--muted); }

.badge.status-ordered { background: #fff4d6; border-color: #e8d49a; }

.badge.status-received { background: #dce7dd; border-color: #b5cbb8; color: var(--ok); }

.badge.status-paid { background: #fdebd3; border-color: #ecc794; color: var(--warn); }

.badge.status-arrived { background: #e6f4ea; border-color: #bfe3c9; color: var(--ok); }

.badge.status-collected { background: #dce7dd; border-color: #b5cbb8; color: var(--ok); }

.badge.status-cancelled { background: #fbe9e7; border-color: #f0c4c0; color: var(--danger); }

.badge.status-open { background: var(--card); color: var(--ink); }

.badge.status-locked { background: #fdebd3; border-color: #ecc794; color: var(--warn); }

.badge.status-sent { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* row-status tones on the main grid: recorded draft, ordered neutral, paid
   accent, received ink, arrived ok, collected ink, cancelled muted struck */
.badge.row-recorded { background: var(--bg-soft); border-color: var(--line); color: var(--muted); }

.badge.row-ordered { background: var(--card); color: var(--ink); }

.badge.row-received { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.badge.row-paid { background: var(--accent); border-color: var(--accent-deep); color: var(--on-accent); }

.badge.row-arrived { background: #e6f4ea; border-color: #bfe3c9; color: var(--ok); }

.badge.row-collected { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.badge.row-cancelled {
  background: var(--bg-soft); border-color: var(--line-strong); color: var(--muted);
  text-decoration: line-through;
}

/* flash + errors */

.flash {
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
  padding: 0.6rem 0.85rem; margin-bottom: 1rem;
  box-shadow: inset 3px 0 0 var(--line-strong);
}

.flash-ok { border-color: #bfe3c9; background: #e6f4ea; box-shadow: inset 3px 0 0 var(--ok); }

.flash-error { border-color: #f0c4c0; background: #fbe9e7; color: var(--danger); box-shadow: inset 3px 0 0 var(--danger); }

.error { color: var(--danger); font-weight: 600; }

/* one-line hints: small, muted, only where the flow is non-obvious */

.hint { font-size: 0.85rem; color: var(--muted); margin: 0.1rem 0 0.75rem; }

/* cards + layout helpers */

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }

.card.narrow { max-width: 24rem; margin-inline: auto; }

/* toolbars: one soft plate — breathing room, controls aligned, wraps on
   narrow screens. Table cells embed toolbars as plain control rows. */

.toolbar {
  display: flex; gap: 0.6rem; align-items: flex-end; flex-wrap: wrap;
  padding: 0.6rem 0.75rem; margin-bottom: 1rem;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius);
}

.toolbar > label,
form.inline > label {
  display: inline-flex; align-items: center; gap: 0.4rem; color: var(--muted);
  line-height: 1.45; min-width: 0;
}

.toolbar .field { margin-bottom: 0; min-width: 0; }

.toolbar form { margin: 0; min-width: 0; }

.toolbar input[type='search'] { flex: 1 1 12rem; min-width: 0; }

/* Toolbar forms put a bare link (e.g. the history filter bar's "Clear") next
   to 2.4rem controls; without a box of its own it hangs from the plate's
   bottom edge below the button centreline. Same treatment as a.button. */
form.toolbar > a {
  display: inline-flex; align-items: center; height: 2.4rem;
}

td .toolbar { margin: 0; padding: 0; background: none; border: 0; }

/* The schedule card is the narrow admin column; a datetime input must be
   allowed below its intrinsic width or the card scrolls the page sideways. */
.order-schedule input[type='datetime-local'] { min-width: 0; max-width: 100%; }

/* exports + filters toolbars: one visual baseline — the picker form (label +
   select + submit) and the a.button export links center on the same line
   instead of hanging from the plate's bottom edge, and every link gets the
   same 2.4rem box the selects and buttons use */
.toolbar.order-exports,
.toolbar.order-filters { align-items: center; }

.toolbar.order-exports a.button { height: 2.4rem; }

.muted { color: var(--muted); }

/* order page: sidebar + sheet */

/* Order page: the tables are the main surface and span the content width.
   Admin controls break into columns above them: the three action bars beside
   the new-order card, then find/export side by side. The sheet tabs sit
   directly above the table they switch. */
.order-layout { display: flex; flex-direction: column; gap: 1rem; align-items: stretch; }

.order-content { min-width: 0; }

.order-admin {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(17rem, 22rem);
  gap: 1rem; align-items: start; margin-bottom: 1rem;
}

.order-actionbars {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 0.75rem; align-items: start;
}

.order-actionbar .toolbar { margin-bottom: 0; }
.order-actionbar .panel-title,
.order-tool .panel-title { padding-left: 0.75rem; }
.order-clear { white-space: nowrap; }
.order-actionbar .panel-title { margin-top: 0; }

.order-tools {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  gap: 1rem; align-items: start; margin-bottom: 1rem;
}

.order-tool .toolbar { margin-bottom: 0; }

.order-sheets {
  display: flex; flex-wrap: wrap; width: 100%;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  margin-bottom: 0.75rem;
}

.sheet-mode { align-items: center; }

@media (max-width: 900px) {
  .order-admin { grid-template-columns: minmax(0, 1fr); }
  /* Keep status chips inside their column on narrow laptop windows. */
  .badge { font-size: 0.68rem; padding: 1px 4px; }
}

.order-sheet-link {
  display: flex; flex-wrap: wrap; align-items: center; gap: 3px 8px;
  flex: 1 1 9rem; padding: 8px 10px; color: var(--ink);
  border-right: 1px solid var(--line);
}

.order-sheet-link:last-child { border-right: none; }

.order-sheet-link:hover { background: var(--bg-soft); text-decoration: none; }

.order-sheet-link.active { background: var(--bg-soft); box-shadow: inset 3px 0 0 var(--accent); }

.order-sheet-name { font-weight: 600; margin-right: auto; }

.order-sheet-link .muted { font-size: 0.85rem; }

.order-sheet-subtotal { flex-basis: 100%; font-size: 0.85rem; color: var(--ink-soft); }

/* per-row delete: a compact danger button in the sheet's Delete column.
   Saved rows point at an external #row-delete-<id> form (the grid is one big
   save form and forms never nest); template rows keep the discard checkbox. */
.sheet-grid button.row-delete { height: 1.8rem; padding: 0 0.45rem; font-size: 0.8rem; }

.row-delete-form { display: none; }

/* titled groups in the order action bars, filters and export bars */
.panel-title {
  margin: 0 0 0.35rem; font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}

.order-new { margin-bottom: 0; }

.order-new h2 { margin-top: 0; }

.order-head { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }

.order-head h1 { margin-bottom: 0.25rem; }

.order-submission { margin-left: auto; }

.order-submission label { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; }

.more-rows { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--ink-soft); }

.sheet-tools { margin-top: 0.75rem; }

/* paste-import: the secondary power tool */

details.paste-box {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  padding: 0.6rem 0.85rem; margin-top: 0.75rem;
}

details.paste-box summary {
  cursor: pointer; font-weight: 600; color: var(--ink-soft); padding: 0.25rem 0; list-style-position: inside;
}

details.paste-box textarea {
  display: block; width: 100%; min-height: 7rem; margin-top: 0.5rem;
}

/* receiving queue actions */

td.actions form { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin: 2px 0; }

/* the arrival picker takes the whole cell width so name + Mark received +
   Cancel share one line beneath it instead of wrapping mid-control */
td.actions input[type='file'] { flex: 1 1 100%; max-width: none; font-size: 0.85rem; }

td.actions input[type='text'] { width: 11rem; }

/* small screens: toolbar items become full-width rows instead of a cramped
   strip; controls stretch to fill their row */

@media (max-width: 640px) {
  body { padding: 0 0.75rem 2.5rem; }

  .toolbar { gap: 0.5rem; padding: 0.5rem 0.6rem; }

  .toolbar > label,
  .toolbar > .field,
  .toolbar > input[type='search'] { flex: 1 1 100%; }

  .toolbar > label > :is(input, select) { flex: 1 1 auto; min-width: 0; }
}
