/* Ontario Kettle Corn — app styles every Worker's admin and form pages share (admin shell, cards, tables, forms,
   notices, sign-in). Brand palette and spacing scale live in tokens.css; each Worker adds its own sheet after this. */
/* Focus ring: maroon on light surfaces (--focus in tokens.css), gold only on the charcoal topbar. */
/* Elements hidden from script stay hidden even when a class sets display (e.g. grid). */
[hidden] {
  display: none !important;
}

:root {
  --ink: #2d2d2d;
  --caramel: #db953c;
  --cream: #f7e9d3;
  --paper: #fffaf2;
  --card-bg: #fff;
  --line: #e7dccb;
  --gold-soft: #f1dca6;
  --disabled-fill: #767170;
  --ok: #2f6b3a;
  --warn: #8a5a00;
  --err: #a1261b;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(40 39 39 / 6%), 0 4px 16px rgb(40 39 39 / 6%);
  --font: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}
img {
  max-width: 100%;
}
a {
  color: var(--maroon);
}
h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.5em;
  color: var(--charcoal);
}
h1 {
  font-size: 1.6rem;
  font-weight: 800;
  text-wrap: balance;
}
h2 {
  font-size: 1.2rem;
  font-weight: 700;
}
h3 {
  font-size: 1rem;
  font-weight: 700;
}
p {
  margin: 0 0 1em;
}
small,
.muted {
  color: var(--muted);
}
small {
  font-size: max(0.8em, 0.75rem);
}

/* ---------- Admin shell ---------- */
.topbar {
  background: var(--charcoal);
  color: #fff;
  border-bottom: 4px solid var(--gold);
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
}
.brand img {
  height: 44px;
  width: auto;
}
.nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}
.nav a {
  color: #f3eadc;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
}
.nav-toggle {
  display: none;
  align-items: center;
  min-height: 44px;
  margin-left: auto;
  padding: 6px 14px;
  border: 1px solid #f3eadc;
  border-radius: 999px;
  background: none;
  color: #f3eadc;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.nav-toggle[aria-expanded="true"] {
  background: rgb(233 188 84 / 18%);
  color: var(--gold);
  border-color: var(--gold);
}
.nav a {
  transition:
    background-color 120ms ease-out,
    color 120ms ease-out;
}
.nav a:hover,
.nav a[aria-current="page"],
.nav a[aria-current="true"] {
  background: rgb(233 188 84 / 18%);
  color: var(--gold);
}
/* Grouped nav: wide screens show each section's link (its pages are the tab row below the bar); the phone menu shows
   each section as a heading with its pages instead. The first end link (Settings) sits on the right by Sign out. */
.nav-group {
  display: contents;
}
.nav-heading,
.nav-pages {
  display: none;
}
.nav .nav-end {
  margin-left: auto;
}
.subnav {
  background: var(--card-bg);
  border-bottom: 1px solid var(--line);
}
.subnav-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}
.subnav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.subnav a:hover {
  color: var(--ink);
  border-bottom-color: var(--line);
}
.subnav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--gold);
}
.subnav a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}
.topbar form {
  margin: 0;
}
.link-button {
  background: none;
  border: 0;
  padding: 6px 2px;
  color: #f3eadc;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}
/* Account mode: the strip above the top bar with the products, who's signed in, "Your account" and "Sign out". */
.account-bar {
  border-bottom: 1px solid rgb(255 255 255 / 0.14);
  font-size: 0.85rem;
}
.account-bar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2px 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 16px;
}
.account-products {
  display: flex;
  flex: 1;
  gap: 4px;
}
.account-products a,
.account-link {
  color: #f3eadc;
  padding: 6px 8px;
  border-radius: 8px;
}
.account-products a[aria-current] {
  background: rgb(255 255 255 / 0.12);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}
.account-who {
  color: #f3eadc;
}

/* Phones: the products, "Your account" and "Sign out" share one row, with who's signed in on a small line under it. */
@media (max-width: 600px) {
  .account-bar-inner {
    gap: 0 4px;
    padding: 0 12px;
  }
  .account-who {
    order: 3;
    flex-basis: 100%;
    padding: 0 8px 8px;
    font-size: 0.8rem;
    overflow-wrap: anywhere;
  }
}

main.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 {
  margin: 0;
}
.page-head .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.crumbs {
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.crumbs a {
  color: var(--muted);
}

.card {
  /* Grid and flex children default to min-width: auto, which lets a wide table stretch the card off a phone screen. */
  min-width: 0;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card > h2:first-child {
  margin-top: 0;
}
.grid {
  display: grid;
  gap: 16px;
}
.grid.items-start {
  align-items: start;
}
.grid-2 {
  /* Side by side only when each column gets at least 360px (stacked on phones and most tablets). */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
}
.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.grid-4 {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}
.stat .value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--charcoal);
  font-variant-numeric: tabular-nums;
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
}
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
tr:last-child td,
tbody tr:last-child th,
tfoot tr:last-child th {
  border-bottom: 0;
}
tbody tr:hover {
  background: #fffdf8;
}
code,
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  letter-spacing: 0.04em;
}

/* ---------- Forms ---------- */
.stack {
  display: grid;
  gap: 14px;
}
/* Quantity and price boxes in tables keep a usable width when the table is squeezed on a phone. */
td input[type="number"],
td input[inputmode="decimal"] {
  min-width: 4.5rem;
}
.field {
  display: grid;
  gap: 4px;
  align-content: start;
  min-width: 0;
}
.field label,
.label-text {
  font-weight: 600;
  font-size: 0.9rem;
}
.hint {
  font-size: 0.85rem;
  color: var(--muted);
}
.field .hint {
  font-size: 0.8rem;
}
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="search"],
input[type="url"],
select,
textarea {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #8a7d6c;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
  max-width: 100%;
}
input[type="color"] {
  width: 56px;
  height: 38px;
  padding: 2px;
  border: 1px solid #8a7d6c;
  border-radius: 8px;
  background: #fff;
}
textarea {
  min-height: 90px;
  resize: vertical;
}
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}
a:focus-visible,
.btn:focus-visible,
.nav a:focus-visible,
.nav-toggle:focus-visible,
.link-button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.topbar {
  --focus: var(--gold);
}
/* "Skip to content": off screen until a keyboard user tabs to it, then over the top bar's corner. */
.skip-link {
  position: absolute;
  left: 8px;
  top: -100px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: 6px;
  background: #fff;
  color: var(--charcoal);
  font-weight: 700;
}
.skip-link:focus-visible {
  top: 8px;
}
main:focus {
  outline: none;
}
.check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-weight: 500;
}
.check input {
  margin-top: 0;
}
.check small {
  display: block;
  color: var(--muted);
  font-weight: 400;
}
fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  margin: 0;
}
legend {
  font-weight: 700;
  padding: 0 6px;
  color: var(--charcoal);
}
.row {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  align-items: start;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 9px 16px;
  border-radius: 999px;
  border: 2px solid var(--charcoal);
  background: var(--charcoal);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color 120ms ease-out,
    transform 80ms ease-out;
}
.btn:active {
  transform: scale(0.98);
}
.btn:hover {
  background: #000;
}
.btn.gold {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--charcoal);
}
.btn.gold:hover {
  background: #dfae3c;
}
.btn.ghost {
  background: transparent;
  color: var(--charcoal);
}
.btn.ghost:hover {
  background: var(--cream);
}
.btn.danger {
  background: transparent;
  color: var(--err);
  border-color: var(--err);
}
.btn.small {
  padding: 5px 11px;
  font-size: 0.82rem;
}
.badge.leading {
  margin-left: 8px;
}
.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- Notices & badges ---------- */
.notice {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  border: 1px solid;
}
.notice.ok {
  background: #eef7ef;
  border-color: #b9dcbf;
  color: var(--ok);
}
.notice.warn {
  background: #fff7e6;
  border-color: #f1d18f;
  color: var(--warn);
}
.notice.err {
  background: #fdeeee;
  border-color: #efbcb7;
  color: var(--err);
}
.notice ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--cream);
  color: var(--maroon);
}
.badge.active {
  background: #e3f3e5;
  color: var(--ok);
}
.badge.grace {
  background: #fff1d1;
  color: var(--warn);
}
.badge.closed,
.badge.locked {
  background: #ece8e3;
  color: #534b42;
}
.badge.draft {
  background: #f1f1f1;
  color: #555;
}
.badge.alert {
  background: #fdeeee;
  color: var(--err);
}
.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  vertical-align: -2px;
  border: 1px solid rgb(0 0 0 / 15%);
}

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
}

/* ---------- Login ---------- */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: var(--charcoal);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 10px 40px rgb(0 0 0 / 35%);
}
.auth-card img {
  display: block;
  width: 150px;
  margin: 0 auto 12px;
}
.auth-card h1 {
  text-align: center;
  font-size: 1.4rem;
}

@media (max-width: 640px) {
  main.container {
    padding: 16px 16px 48px;
  }
  .card {
    padding: 16px;
  }
  /* Wide tables scroll inside their card instead of pushing the whole page sideways. */
  .card:has(table) {
    overflow-x: auto;
  }
  .brand span {
    display: none;
  }
  /* Top bar: logo, Menu button and sign-out share the first row. With scripting on, the links collapse into a dropdown
     under the Menu button; without it they stay visible as a wrapped list. */
  .topbar-inner {
    gap: 6px 12px;
    justify-content: space-between;
  }
  .brand img {
    height: 36px;
  }
  .topbar .nav {
    order: 3;
    flex: 1 0 100%;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding-bottom: 4px;
  }
  .topbar.nav-js .nav-toggle {
    display: inline-flex;
  }
  .topbar.nav-js .nav-toggle[aria-expanded="false"] ~ .nav {
    display: none;
  }
  .topbar .nav a {
    border-radius: 10px;
    padding: 10px 12px;
  }
  .topbar .nav-section,
  .subnav {
    display: none;
  }
  .topbar .nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .topbar .nav-heading {
    display: block;
    margin: 10px 12px 2px;
    color: var(--gold-soft);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .topbar .nav-pages {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .topbar .nav .nav-end {
    margin-left: 0;
    margin-top: 10px;
  }
}

/* Touch targets: 44px minimum on phones and tablets (WCAG 2.5.5 target size). */
@media (pointer: coarse), (max-width: 900px) {
  .btn.small,
  .nav a,
  .account-bar a,
  .link-button,
  .crumbs a,
  td > a:not(.btn) {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
  .link-button {
    padding: 6px 8px;
  }
  .crumbs a {
    padding-inline: 4px;
  }
}

@media print {
  .topbar,
  .subnav,
  .no-print {
    display: none !important;
  }
  body {
    background: #fff;
  }
  .card {
    box-shadow: none;
    border: 0;
    padding: 0;
  }
}

.btn:disabled,
.btn[disabled] {
  /* Keep the label colour and lighten the fill, so a busy "Processing…" button still reads as a button. */
  background: var(--disabled-fill);
  border-color: var(--disabled-fill);
  cursor: not-allowed;
  transform: none;
}
.btn.gold:disabled,
.btn.gold[disabled] {
  background: var(--gold-soft);
  border-color: var(--gold-soft);
}
.btn.ghost:disabled,
.btn.ghost[disabled],
.btn.danger:disabled,
.btn.danger[disabled] {
  background: transparent;
  color: var(--disabled-fill);
  border-color: var(--disabled-fill);
}

/* ---------- Utilities (4px scale) ---------- */
.mt-2 {
  margin-top: var(--space-2);
}
.mt-4 {
  margin-top: var(--space-4);
}
.mt-3 {
  margin-top: var(--space-3);
}
.mb-4 {
  margin-bottom: var(--space-4);
}
.mb-5 {
  margin-bottom: var(--space-5);
}
.text-center {
  text-align: center;
}
.pre-wrap {
  white-space: pre-wrap;
}
.self-end {
  align-self: end;
}
.stat-of {
  font-size: 1rem;
  font-weight: 600;
}
.col-check {
  width: 2em;
}
.maxw-88 {
  max-width: 88px;
}
.maxw-140 {
  max-width: 140px;
}
.maxw-152 {
  max-width: 152px;
}
.maxw-172 {
  max-width: 172px;
}
.maxw-220 {
  max-width: 220px;
}
.nowrap {
  white-space: nowrap;
}
.maxw-280 {
  max-width: 280px;
}
.maxh-80 {
  max-height: 80px;
}

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

/* Form controls: comfortable tap targets (WCAG 2.5.8) and brand-colored checks. */
input[type="checkbox"],
input[type="radio"] {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  accent-color: var(--maroon);
  vertical-align: middle;
}
input[type="file"] {
  /* The native control has a wide intrinsic size; let it shrink to its field instead of poking out of the card. */
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font: inherit;
  padding: 6px 0;
  min-height: 36px;
}
input[type="file"]::file-selector-button {
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 5px 11px;
  margin-right: 10px;
  border: 2px solid var(--charcoal);
  border-radius: 999px;
  background: transparent;
  color: var(--charcoal);
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover {
  background: var(--cream);
}
/* Long unbroken values (ids, references) wrap instead of widening their table. */
.wrap-anywhere {
  overflow-wrap: anywhere;
}
.nowrap {
  white-space: nowrap;
}
[data-error-summary]:focus {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}
[aria-invalid="true"] {
  border-color: var(--err);
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .nav a {
    transition: none;
  }
  .btn:active {
    transform: none;
  }
}
