/* Crate Inventory — one hand, a garage, bad light.
   Dark by default because that is where this gets used, high contrast,
   nothing smaller than a 48px tap target. System fonts only: this loads
   over VPN and a webfont is a round trip you feel. */

:root {
  --bg: #0e1014;
  --bg-far: #0a0c0f;
  --surface: #161a21;
  --surface-hi: #1c212a;
  --line: #252b35;
  --line-hi: #333b47;

  --text: #e9ecf1;
  --text-dim: #97a0b0;
  --text-faint: #6b7484;

  --accent: #ffa53d;
  --accent-hi: #ffbb6b;
  --accent-ink: #2a1804;
  --accent-ghost: rgba(255, 165, 61, 0.12);

  --ok: #56d68a;
  --danger: #f4736e;
  --danger-ghost: rgba(244, 115, 110, 0.12);

  --r-sm: 9px;
  --r: 13px;
  --r-lg: 18px;
  --r-pill: 999px;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px -8px rgba(0, 0, 0, 0.6);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.45), 0 14px 32px -12px rgba(0, 0, 0, 0.75);

  --tap: 48px;
  --gap: 0.65rem;
  --pad: 1.05rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 0 7rem;
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 50% -12%, #1a2030 0%, transparent 62%),
    var(--bg);
  color: var(--text);
  font: 16.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", system-ui, sans-serif;
  letter-spacing: -0.006em;
}

main { padding: 1.15rem 1rem 0; max-width: 46rem; margin: 0 auto; }

a { color: var(--accent); }

.icon { flex: none; vertical-align: -0.18em; }

/* ---- Header ---------------------------------------------------------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1rem;
  padding-top: max(0.7rem, env(safe-area-inset-top));
  background: rgba(14, 16, 20, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(1.5) blur(12px);
  -webkit-backdrop-filter: saturate(1.5) blur(12px);
}

.bar a { text-decoration: none; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.brand .icon { color: var(--accent); }

.bar-links { display: flex; align-items: center; gap: 0.4rem; }

.bar-link {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
  padding: 0.45rem 0.7rem;
  border-radius: var(--r-pill);
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 550;
}
.bar-new { color: var(--accent); background: var(--accent-ghost); }

/* ---- Type ------------------------------------------------------------ */

h1 {
  margin: 0 0 0.2rem;
  font-size: 1.62rem;
  font-weight: 680;
  letter-spacing: -0.03em;
  line-height: 1.18;
}

h2 {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 2rem 0 0.7rem;
  font-size: 0.76rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
}
h2 .icon { color: var(--text-faint); }

.sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.9rem;
  color: var(--text-dim);
  font-size: 0.94rem;
}

.tag-id {
  font: 600 0.78rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.04em;
  padding: 0.34rem 0.5rem;
  border-radius: var(--r-sm);
  background: var(--surface-hi);
  border: 1px solid var(--line);
  color: var(--text-dim);
}

.where { display: inline-flex; align-items: center; gap: 0.28rem; }

.notes {
  margin: 0 0 1.1rem;
  padding: 0.75rem 0.9rem;
  border-left: 2px solid var(--line-hi);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--surface);
  color: var(--text-dim);
}

.hint { color: var(--text-faint); font-size: 0.86rem; }
.crumb { margin: 0 0 0.9rem; }
.crumb a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 550;
}

.qty {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.42rem;
  border-radius: var(--r-pill);
  background: var(--accent-ghost);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0;
}

/* ---- Empty states ---------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  padding: 2.6rem 1.2rem;
  border: 1px dashed var(--line-hi);
  border-radius: var(--r-lg);
  color: var(--text-faint);
  text-align: center;
}
.empty .icon { color: var(--line-hi); }

/* ---- Controls -------------------------------------------------------- */

input, button, select {
  font: inherit;
  border-radius: var(--r);
  border: 1px solid var(--line);
}

input {
  width: 100%;
  min-height: var(--tap);
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
input::placeholder { color: var(--text-faint); }
input:focus { border-color: var(--line-hi); background: var(--surface-hi); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus { outline: none; }
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--tap);
  padding: 0.6rem 1.15rem;
  border: none;
  border-radius: var(--r);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: filter 0.15s, transform 0.06s;
}
button:active { transform: translateY(1px); }
@media (hover: hover) { button:hover { filter: brightness(1.07); } }

label { display: block; margin-top: 0.7rem; color: var(--text-dim); font-size: 0.88rem; }
label input { margin-top: 0.3rem; }

.field-label {
  display: block;
  margin: 0.85rem 0 0.4rem;
  color: var(--text-dim);
  font-size: 0.88rem;
}

/* ---- Search ---------------------------------------------------------- */

.search { display: flex; gap: var(--gap); margin-bottom: 1.4rem; }

.search-field { position: relative; flex: 1; }
.search-field .icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
.search-field input {
  padding-left: 2.6rem;
  border-radius: var(--r-pill);
  font-size: 1rem;
}
.search-field input:focus { border-color: var(--accent); }
.search button { border-radius: var(--r-pill); padding-inline: 1.3rem; }

/* ---- Cards and lists ------------------------------------------------- */

.cards, .items { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--gap); }

.card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-height: var(--tap);
  padding: var(--pad);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--surface-hi), var(--surface));
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, transform 0.06s, box-shadow 0.15s;
}
.card:active { transform: translateY(1px); }
@media (hover: hover) {
  .card:hover { border-color: var(--line-hi); box-shadow: var(--shadow-lift); }
}

.card-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: var(--r);
  background: var(--accent-ghost);
  color: var(--accent);
}

.card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.16rem; }
.card-title { font-weight: 620; letter-spacing: -0.012em; }
.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.55rem;
  color: var(--text-dim);
  font-size: 0.87rem;
}
.card-note { color: var(--text-faint); font-size: 0.87rem; }
.card-chevron { color: var(--text-faint); flex: none; }

.count {
  flex: none;
  padding: 0.24rem 0.55rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--bg-far);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
}

/* Items are cards too, but they hold their own controls rather than being
   one big link. */
.items > li {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: var(--pad);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--surface-hi), var(--surface));
  box-shadow: var(--shadow);
}
.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.22rem; }
.item-name { font-weight: 620; letter-spacing: -0.012em; }
.item-notes { color: var(--text-dim); font-size: 0.88rem; }

.remove {
  flex: none;
  min-height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: var(--r-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-faint);
}
@media (hover: hover) {
  .remove:hover { color: var(--danger); background: var(--danger-ghost); border-color: var(--danger-ghost); filter: none; }
}

/* ---- Forms that sit on the page as panels ---------------------------- */

.add, .panel {
  padding: var(--pad);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  margin-bottom: 1.3rem;
}
.add { display: flex; flex-wrap: wrap; gap: var(--gap); }
.add > input[type="text"] { flex: 1 1 11rem; }
.add > button { flex: 0 0 auto; }

.stack { display: flex; flex-direction: column; gap: 0.15rem; }
.stack button { align-self: flex-start; margin-top: 1.1rem; }

details { flex: 1 1 100%; }
summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.4rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 550;
  cursor: pointer;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::after {
  content: "";
  width: 6px; height: 6px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.15s;
}
details[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }

/* ---- Photo pickers --------------------------------------------------- */

.pickers { display: flex; flex-wrap: wrap; gap: var(--gap); width: 100%; }
.picker { flex: 1 1 9rem; margin: 0; position: relative; }
.picker-face {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: var(--tap);
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--line-hi);
  border-radius: var(--r);
  background: var(--surface-hi);
  color: var(--text);
  font-size: 0.93rem;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.picker-face .icon { color: var(--accent); }
.picker-face:active { background: var(--line); }

/* Kept in the layout and focusable rather than display:none, so the label
   still opens it and keyboard focus still lands somewhere visible. */
.picker input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
.picker:focus-within .picker-face { outline: 2px solid var(--accent); outline-offset: 2px; }

.photos { display: flex; flex-wrap: wrap; gap: var(--gap); align-items: center; }
.file-count { flex: 1 1 100%; color: var(--accent); font-size: 0.85rem; }

/* ---- Galleries ------------------------------------------------------- */

.gallery {
  list-style: none;
  margin: 0 0 1.3rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(106px, 1fr));
  gap: 0.5rem;
}
.gallery li { position: relative; }
.gallery a { display: block; border-radius: var(--r); overflow: hidden; }
.gallery img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface);
  transition: transform 0.2s, border-color 0.15s;
}
@media (hover: hover) {
  .gallery a:hover img { transform: scale(1.035); border-color: var(--line-hi); }
}
.gallery.thumbs {
  margin: 0.5rem 0 0;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
}

.remove-photo {
  position: absolute;
  top: 5px;
  right: 5px;
  min-height: 30px;
  min-width: 30px;
  padding: 0;
  border-radius: var(--r-pill);
  background: rgba(8, 9, 12, 0.72);
  color: #fff;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
@media (hover: hover) { .remove-photo:hover { background: var(--danger); color: #1a0505; filter: none; } }

.item-photos summary { min-height: 2.1rem; font-size: 0.85rem; }
.item-photos .photos { margin-top: 0.35rem; }

/* ---- Bottom action bar ----------------------------------------------- */

.actions {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  gap: var(--gap);
  margin-top: 2rem;
  padding: 0.85rem 0;
  padding-bottom: max(0.85rem, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: var(--tap);
  padding: 0.6rem 1rem;
  border-radius: var(--r);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: filter 0.15s, transform 0.06s;
}
.btn:active { transform: translateY(1px); }
@media (hover: hover) { .btn:hover { filter: brightness(1.07); } }

.btn-secondary {
  background: var(--surface-hi);
  color: var(--text);
  border: 1px solid var(--line-hi);
}

/* ---- Photo viewer ---------------------------------------------------- */

.viewer { position: relative; margin: 0; }
.viewer img {
  display: block;
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--bg-far);
}

.viewer figcaption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 0.8rem;
  color: var(--text-dim);
  font-size: 0.92rem;
}
.viewer-caption { color: var(--text); font-weight: 600; }
.viewer-count {
  white-space: nowrap;
  padding: 0.24rem 0.6rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 600;
}

/* Overlaid rather than below the photo, so both are reachable with one
   thumb without moving the hand. */
.arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  display: grid;
  place-items: center;
  width: 46px;
  height: 84px;
  color: #fff;
  text-decoration: none;
  background: rgba(8, 9, 12, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s;
}
.arrow:active { background: rgba(8, 9, 12, 0.85); }
.arrow-prev { left: 0; border-left: none; border-radius: 0 var(--r) var(--r) 0; }
.arrow-next { right: 0; border-right: none; border-radius: var(--r) 0 0 var(--r); }

.viewer-full {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.9rem;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.88rem;
}

/* ---- NFC ------------------------------------------------------------- */

.nfc { margin-top: 0.9rem; }
.nfc-buttons { display: flex; gap: var(--gap); }
.nfc-buttons .btn { flex: 0 1 15rem; }

.nfc-status { min-height: 1.4rem; margin: 0.7rem 0 0; color: var(--text-dim); font-size: 0.9rem; }
.nfc-status[data-tone="waiting"] { color: var(--accent); }
.nfc-status[data-tone="ok"] { color: var(--ok); }
.nfc-status[data-tone="bad"] { color: var(--danger); }

.tagurl { margin: 0 0 0.8rem; overflow-wrap: anywhere; }
.tagurl code {
  display: block;
  padding: 0.65rem 0.8rem;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--bg-far);
  color: var(--text-dim);
  font: 500 0.84rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---- Delete ---------------------------------------------------------- */

.tally { margin: 0.4rem 0 1.1rem; padding-left: 1.15rem; color: var(--text-dim); }
.tally li { margin-bottom: 0.3rem; }

.warn {
  display: flex;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--danger-ghost);
  border-left: 3px solid var(--danger);
  border-radius: 0 var(--r) var(--r) 0;
  background: var(--danger-ghost);
  color: var(--text-dim);
}
.warn .icon { color: var(--danger); }

.danger { background: var(--danger); color: #2a0806; width: 100%; }
.danger-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: var(--tap);
  color: var(--danger);
  text-decoration: none;
  font-weight: 550;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- Crate tiles ----------------------------------------------------- */

.tiles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: var(--gap);
}

.tile {
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--surface-hi), var(--surface));
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.06s, box-shadow 0.15s;
}
.tile:active { transform: translateY(1px); }
@media (hover: hover) {
  .tile:hover { border-color: var(--line-hi); box-shadow: var(--shadow-lift); }
  .tile:hover img { transform: scale(1.04); }
}

.tile-media {
  display: block;
  aspect-ratio: 1;
  background: var(--bg-far);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.tile-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s;
}
.tile-blank {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--line-hi);
  background:
    repeating-linear-gradient(45deg, transparent 0 9px, rgba(255,255,255,0.017) 9px 18px),
    var(--bg-far);
}

.tile-body {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.8rem;
}
.tile-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.1rem; }
.tile-title {
  font-weight: 620;
  letter-spacing: -0.012em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-where {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Select --------------------------------------------------------- */

.selectwrap { position: relative; display: block; margin-top: 0.3rem; }
.selectwrap .icon {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%) rotate(90deg);
  color: var(--text-faint);
  pointer-events: none;
}

select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: var(--tap);
  padding: 0.65rem 2.4rem 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
select:focus { border-color: var(--line-hi); background: var(--surface-hi); }
select option { background: var(--surface); color: var(--text); }

/* ---- Location filter chips ------------------------------------------- */

/* Scrolls sideways rather than wrapping to three lines and pushing the
   crates off screen when there are a lot of locations. */
.chips {
  display: flex;
  gap: 0.4rem;
  margin: 0 -1rem 1.2rem;
  padding: 0.15rem 1rem 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex: none;
  min-height: 38px;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.88rem;
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.chip .icon { color: var(--text-faint); }
@media (hover: hover) { .chip:hover { border-color: var(--line-hi); color: var(--text); } }

.chip-on {
  background: var(--accent-ghost);
  border-color: rgba(255, 165, 61, 0.42);
  color: var(--accent);
}
.chip-on .icon { color: var(--accent); }

.chip-n {
  padding: 0.03rem 0.4rem;
  border-radius: var(--r-pill);
  background: var(--bg-far);
  border: 1px solid var(--line);
  font-size: 0.76rem;
  font-weight: 600;
}
.chip-on .chip-n { background: rgba(0, 0, 0, 0.28); border-color: transparent; }

/* The admin list's name field: an input that reads as the heading it replaces,
   so the list still scans as a list rather than as a form. */
.rename {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
}
.rename input.item-name {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 0.2rem 0.35rem;
  color: var(--text);
}
.rename input.item-name:hover { border-color: var(--line); }
.rename input.item-name:focus { border-color: var(--line-hi); background: var(--surface-hi); }
