@font-face { font-family: "Saira Stencil"; src: url("/fonts/stencil.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Atkinson"; font-weight: 400; src: url("/fonts/atkinson-400.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Atkinson"; font-weight: 700; src: url("/fonts/atkinson-700.woff2") format("woff2"); font-display: swap; }

:root {
  color-scheme: light;
  --ground: #e6eadb;
  --surface: #f8f9f2;
  --sunk: #d9dfcd;
  --line: #bcc6b1;
  --ink: #17231c;
  --muted: #4f5f54;
  --pine: #1f3d2f;
  --on-pine: #f4f6ec;
  --pine-soft: #cfe0d0;
  --signal: #f0b323;
  --on-signal: #1d1802;
  --ok: #24663e;
  --ok-soft: #d5e8d6;
  --loan: #8a4b00;
  --loan-soft: #f8e3b9;
  --bad: #a3211a;
  --bad-soft: #f7d7d3;
  --gap: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ground: #101b16;
    --surface: #18261f;
    --sunk: #0c1511;
    --line: #34473b;
    --ink: #e9efe6;
    --muted: #a6b5aa;
    --pine: #0b1410;
    --on-pine: #e9efe6;
    --pine-soft: #24392d;
    --ok: #86d29e;
    --ok-soft: #1c3a29;
    --loan: #f3c26c;
    --loan-soft: #3f2e0d;
    --bad: #ff9d94;
    --bad-soft: #451c18;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 17px/1.45 "Atkinson", system-ui, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 700; }
p { margin: 0; }
a { color: inherit; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.stencil { font-family: "Saira Stencil", "Atkinson", sans-serif; font-weight: 400; letter-spacing: .02em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* App frame: a bottom bar on phones, a side rail on desks */
.frame { min-height: 100dvh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.topbar {
  background: var(--pine); color: var(--on-pine);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { font-family: "Saira Stencil", sans-serif; font-size: 1.25rem; text-decoration: none; color: var(--signal); }
.topbar .who { font-size: .9rem; color: var(--on-pine); opacity: .85; text-align: right; }
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--pine); padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  display: flex; align-items: center; justify-content: center; min-height: 60px; padding: 8px 4px;
  color: var(--on-pine); text-decoration: none; font-weight: 700; font-size: .95rem; text-align: center;
  border-top: 4px solid transparent;
}
.nav a[aria-current="page"] { border-top-color: var(--signal); color: var(--signal); }
main.page { max-width: 760px; margin: 0 auto; padding: var(--gap); display: grid; gap: 18px; }
@media (min-width: 900px) {
  .frame { display: grid; grid-template-columns: 200px minmax(0, 1fr); grid-template-rows: auto 1fr; padding-bottom: 0; }
  .topbar { grid-column: 1 / -1; }
  .nav { position: static; display: flex; flex-direction: column; justify-content: flex-start; padding: 12px 0; }
  .nav a { justify-content: flex-start; min-height: 48px; padding: 8px 20px; border-top: 0; border-left: 4px solid transparent; }
  .nav a[aria-current="page"] { border-left-color: var(--signal); }
  main.page { padding: 24px; width: 100%; }
}

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border: 2px solid var(--pine); border-radius: 6px;
  background: transparent; color: var(--ink); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  text-align: center;
}
@media (prefers-color-scheme: dark) { .btn { border-color: var(--line); } }
.btn-primary { background: var(--signal); border-color: var(--signal); color: var(--on-signal); }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-small { min-height: 40px; padding: 6px 12px; font-size: .95rem; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row > .btn { flex: 1 1 140px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; min-height: 32px; }

label.field, .field { display: grid; gap: 4px; }
.field > span.label, .field > legend { font-weight: 700; padding: 0; }
.field .hint { font-size: .88rem; color: var(--muted); }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--surface); border: 2px solid var(--line); border-radius: 6px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--pine); outline: 2px solid var(--signal); outline-offset: 0; }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 40px; padding: 6px 0; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--pine); flex: none; }
@media (prefers-color-scheme: dark) { .check input { accent-color: var(--signal); } }
form.form { display: grid; gap: 22px; }
.form-group { display: grid; gap: 14px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.two { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.error { padding: 10px 12px; background: var(--bad-soft); color: var(--bad); border-radius: 6px; font-weight: 700; }
.notice { padding: 12px 14px; background: var(--loan-soft); color: var(--ink); border-left: 5px solid var(--loan); border-radius: 4px; }
.success { padding: 12px 14px; background: var(--ok-soft); border-left: 5px solid var(--ok); border-radius: 4px; }
progress { width: 100%; height: 12px; accent-color: var(--pine); }

/* Gear list */
.tally { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tally > * { display: block; padding: 12px 14px; background: var(--surface); text-decoration: none; color: inherit; }
.tally b { display: block; font-size: 1.45rem; line-height: 1.15; }
.tally .is-bad b { color: var(--bad); }
.filters { display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { flex: none; min-height: 40px; padding: 6px 14px; border-radius: 20px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--pine); border-color: var(--pine); color: var(--on-pine); font-weight: 700; }
@media (prefers-color-scheme: dark) { .chip[aria-pressed="true"] { background: var(--signal); border-color: var(--signal); color: var(--on-signal); } }
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.rows > li + li { border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 60px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px; text-decoration: none; color: inherit; min-height: 76px; }
.more-row { grid-template-columns: minmax(0, 1fr); }
.label-row { padding: 8px 12px; align-items: center; }
.section-inner { display: grid; gap: 12px; }
.thumb { width: 60px; height: 60px; border-radius: 4px; object-fit: cover; background: var(--sunk); }
.thumb-empty { display: grid; place-items: center; font-size: .72rem; color: var(--muted); text-align: center; line-height: 1.1; }
.row .code { font-family: "Saira Stencil", sans-serif; font-size: .95rem; color: var(--muted); }
.row .name { font-weight: 700; overflow-wrap: anywhere; }
.row .sub { font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.state { display: inline-block; padding: 3px 9px; border-radius: 4px; font-size: .85rem; font-weight: 700; white-space: nowrap; background: var(--ok-soft); color: var(--ok); }
.state-on_loan { background: var(--loan-soft); color: var(--loan); }
.state-overdue { background: var(--bad-soft); color: var(--bad); }
.state-retired { background: var(--sunk); color: var(--muted); }
.page-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.empty { padding: 28px 16px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: 8px; display: grid; gap: 12px; justify-items: center; }

/* The gear tag: the one loud thing in the app */
.tag {
  position: relative; background: var(--signal); color: var(--on-signal);
  padding: 18px 18px 18px 56px;
  clip-path: polygon(30px 0, 100% 0, 100% 100%, 30px 100%, 0 calc(100% - 30px), 0 30px);
}
.tag::before {
  content: ""; position: absolute; left: 20px; top: 50%; width: 18px; height: 18px; margin-top: -9px;
  border-radius: 50%; background: var(--ground);
}
.tag-code { font-family: "Saira Stencil", sans-serif; font-size: clamp(2.3rem, 12vw, 3.6rem); line-height: 1; }
.tag-name { margin-top: 6px; font-size: 1.25rem; font-weight: 700; overflow-wrap: anywhere; }
.status-panel { padding: 14px 16px; border-radius: 8px; display: grid; gap: 12px; background: var(--ok-soft); }
.status-panel.state-on_loan { background: var(--loan-soft); color: var(--ink); }
.status-panel.state-overdue { background: var(--bad-soft); color: var(--ink); }
.status-panel.state-retired { background: var(--sunk); color: var(--ink); }
.status-panel .headline { font-size: 1.2rem; font-weight: 700; }
.gallery { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(70%, 1fr); gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; }
.gallery figure { margin: 0; position: relative; scroll-snap-align: start; display: grid; gap: 6px; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: var(--sunk); }
@media (min-width: 600px) { .gallery { grid-auto-columns: minmax(40%, 1fr); } }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px 18px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: .85rem; color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.section { display: grid; gap: 12px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history li { padding-left: 12px; border-left: 3px solid var(--line); overflow-wrap: anywhere; }
.qr-box { width: 148px; padding: 8px; background: #fff; border-radius: 4px; }
.qr-box svg { display: block; width: 100%; height: auto; }
.qr-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.pending-photos { display: flex; flex-wrap: wrap; gap: 8px; }
.pending-photos img { width: 72px; height: 72px; object-fit: cover; border-radius: 4px; }
.pending-photos figure { margin: 0; display: grid; gap: 2px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.plain { width: 100%; border-collapse: collapse; font-size: .96rem; }
table.plain th, table.plain td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.plain .num { text-align: right; font-variant-numeric: tabular-nums; }
table.plain tfoot td { font-weight: 700; border-bottom: 0; }

dialog { border: 0; border-radius: 10px; background: var(--surface); color: var(--ink); padding: 18px; width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(8, 16, 12, .6); }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; max-width: min(90vw, 480px); padding: 12px 16px; background: var(--ink); color: var(--surface); border-radius: 6px; font-weight: 700; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* Signed-out pages */
.public-body { background: var(--pine); color: var(--on-pine); min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.public-page { width: min(520px, 100%); display: grid; gap: 16px; padding: 24px; background: var(--surface); color: var(--ink); border-radius: 10px; }
.public-code { font-family: "Saira Stencil", sans-serif; font-size: clamp(2.4rem, 13vw, 3.6rem); line-height: 1; color: var(--ink); }
.public-contact { display: grid; gap: 10px; }
.public-signin { font-size: .95rem; color: var(--muted); }

@media (prefers-reduced-motion: no-preference) {
  .tag { animation: tag-in .28s ease-out; transform-origin: left center; }
  @keyframes tag-in { from { transform: rotate(-1.5deg); opacity: .4; } to { transform: none; opacity: 1; } }
}
@media print { .nav, .topbar { display: none; } }
