/* things: shared styles for the app and the info pages (connect, privacy, terms). */

:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e2dc;
  --accent: #2f6f4f;
  --accent-soft: #e6f0ea;
  --accent-fg: #fff;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --danger: #a33;
  --radius: 0.6rem;
  --tabs-h: 3.75rem;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1c1c1a;
    --fg: #ececea;
    --muted: #9a9a94;
    --line: #2e2e2b;
    --accent: #6fbf94;
    --accent-soft: #1d3327;
    --accent-fg: #0d1f15;
    --warn: #f0c060;
    --warn-soft: #3a2f16;
    --danger: #ee8080;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 1rem; margin: 1.75rem 0 0.6rem; }
.meta { color: var(--muted); font-size: 0.9rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

button, a.button {
  font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 2.6rem; padding: 0.5rem 1rem; border: 1px solid transparent; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-fg); text-decoration: none; cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }
button.secondary, a.button.secondary { background: transparent; color: var(--fg); border-color: var(--line); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.link { background: none; color: var(--accent); padding: 0; min-height: 0; border: 0; text-decoration: underline; }
button.big { min-height: 3rem; padding: 0.6rem 1.4rem; font-size: 1.05rem; }
a.button.small, button.small { min-height: 2.2rem; padding: 0.3rem 0.8rem; font-size: 0.9rem; }

input, select, textarea {
  font: inherit; width: 100%; color: var(--fg); background: var(--surface);
  padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: var(--radius);
}
textarea { resize: vertical; }
input.short { max-width: 7rem; }
.field { display: grid; gap: 0.25rem; }
.field > span { font-size: 0.85rem; color: var(--muted); }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.row > .field { flex: 1 1 8rem; }
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.75rem; }

/* ---------- App shell ---------- */

.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 0.5rem; z-index: 10; background: var(--surface); padding: 0.4rem 0.8rem; }

.topbar {
  position: sticky; top: 0; z-index: 5; 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: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.2rem; color: var(--fg); text-decoration: none; letter-spacing: -0.01em; }
.nav { display: none; gap: 0.25rem; }
.nav a, .tabs a { color: var(--muted); text-decoration: none; position: relative; }
.nav a { padding: 0.4rem 0.8rem; border-radius: var(--radius); }
.nav a[aria-current] { color: var(--fg); background: var(--accent-soft); }

#view { max-width: 44rem; margin: 0 auto; padding: 1rem 1rem calc(var(--tabs-h) + 2rem + env(safe-area-inset-bottom)); }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 5; display: none; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.15rem; font-size: 0.75rem; }
.tabs svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current] { color: var(--accent); }
.nav-badge {
  min-width: 1.15rem; height: 1.15rem; padding: 0 0.3rem; border-radius: 1rem; font-size: 0.7rem; line-height: 1.15rem;
  text-align: center; background: var(--danger); color: #fff; font-weight: 600;
}
.tabs .nav-badge { position: absolute; top: 0.4rem; left: calc(50% + 0.5rem); }

/* Signed in: bottom tabs on phones, top nav from tablet width up. */
body.signed-in .tabs { display: grid; }
@media (min-width: 720px) {
  body.signed-in .tabs { display: none; }
  body.signed-in .nav { display: flex; }
  #view { padding-bottom: 3rem; }
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20; max-width: calc(100% - 2rem);
  bottom: calc(var(--tabs-h) + 1rem + env(safe-area-inset-bottom));
  padding: 0.6rem 1rem; border-radius: var(--radius); background: var(--fg); color: var(--bg);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.2);
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Views ---------- */

.view-title { font-size: 1.6rem; margin: 0.5rem 0 1rem; letter-spacing: -0.01em; outline: none; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.view-head.top { align-items: flex-start; }
.view-head.top .button { margin-top: 0.6rem; flex: none; }
.back { display: inline-block; margin-top: 0.25rem; text-decoration: none; font-size: 0.95rem; }
.loading { margin-top: 3rem; text-align: center; }

.card {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.85rem 1rem; margin-bottom: 0.6rem; color: inherit; text-decoration: none;
}
a.card:hover { border-color: var(--accent); }
.card-title { font-weight: 600; }
.card.alert { border-left: 4px solid var(--accent); }
.card.alert.read { border-left-color: var(--line); opacity: 0.8; }
.card.notice { border-color: var(--warn); background: var(--warn-soft); }
.card h2 { margin-top: 0; }
.card.block { margin-bottom: 1rem; }
.way .actions { margin-top: 0.25rem; }

.empty { text-align: center; padding: 1.5rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-title { font-weight: 600; margin: 0 0 0.25rem; }

.badge {
  display: inline-block; padding: 0 0.45rem; border-radius: 1rem; font-size: 0.75rem; line-height: 1.4rem;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap; font-weight: 500;
}
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.muted { background: var(--line); color: var(--muted); }
.badges { display: flex; gap: 0.3rem; flex-wrap: wrap; }

.list { list-style: none; padding: 0; margin: 0; }
.list li a, .list li .pick-item {
  display: grid; gap: 0.1rem; padding: 0.7rem 0.25rem; border-bottom: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
.list li a:hover .list-main { color: var(--accent); }
.list-main { font-weight: 500; }
.list .badges { margin-top: 0.2rem; }
.pick-item {
  width: 100%; text-align: left; background: none; color: var(--fg); border: 0; border-radius: 0;
  min-height: 0; justify-content: start;
}
.pick-item:hover { color: var(--accent); }
/* Folding groups in the list: the toggle sits at the right end of the row */
.list li.has-parts { display: flex; align-items: stretch; }
.list li.has-parts > a { flex: 1; min-width: 0; }
.fold {
  flex: none; width: 2.75rem; min-height: 0; padding: 0; border: 0; border-radius: 0;
  border-bottom: 1px solid var(--line); background: none; color: var(--muted); font-size: 1.35rem;
}
.fold:hover { color: var(--accent); background: var(--accent-soft); }
/* Parts nested under their thing in the list */
.list li.part a { border-left: 2px solid var(--line); }
.list li.depth-1 a { margin-left: 0.75rem; padding-left: 0.75rem; }
.list li.depth-2 a { margin-left: 1.75rem; padding-left: 0.75rem; }
.list li.depth-3 a { margin-left: 2.75rem; padding-left: 0.75rem; }
.card.part-of { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.picker { width: min(32rem, calc(100% - 2rem)); }
.pick-list { max-height: 50vh; overflow-y: auto; }
.pick-option { display: flex; gap: 0.6rem; align-items: center; padding: 0.55rem 0.25rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick-option input { width: auto; flex: none; }

.search { margin-bottom: 0.75rem; }
.chips { display: flex; gap: 0.4rem; overflow-x: auto; padding-bottom: 0.25rem; margin-bottom: 0.25rem; scrollbar-width: none; }
.chip {
  flex: none; padding: 0.3rem 0.8rem; border: 1px solid var(--line); border-radius: 2rem;
  color: var(--fg); text-decoration: none; font-size: 0.9rem; background: var(--surface);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.chip-count { opacity: 0.7; }
.count { margin: 0.25rem 0 0; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-bottom: 0.5rem; }
.stat {
  display: grid; padding: 0.8rem 1rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: inherit; text-decoration: none;
}
.stat strong { font-size: 1.6rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 0.85rem; }

.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.steps li { counter-increment: step; display: flex; gap: 0.75rem; align-items: baseline; padding: 0.5rem 0; }
.steps li::before {
  content: counter(step); flex: none; width: 1.6rem; height: 1.6rem; border-radius: 50%; text-align: center;
  line-height: 1.6rem; font-size: 0.85rem; background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.steps li.done::before { content: "✓"; background: var(--accent); color: var(--accent-fg); }
.steps li.done .step-title { color: var(--muted); text-decoration: line-through; }
.steps a { display: grid; text-decoration: none; color: inherit; }
.steps a .step-title { color: var(--accent); font-weight: 500; }

.past { margin-top: 1.5rem; }
.past summary { cursor: pointer; color: var(--muted); margin-bottom: 0.6rem; }

/* Item page */
.detail h2 { margin-bottom: 0.4rem; }
.detail dl { margin: 0; border-top: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: 7.5rem 1fr; gap: 0.75rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; margin: 0; }
.source { margin-top: 1.5rem; }
.sticky-actions { margin-top: 1.5rem; }
@media (max-width: 340px) { .kv { grid-template-columns: 1fr; gap: 0; } }

/* Forms */
.item-form { display: grid; gap: 0.85rem; }
.group { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 1rem 1rem; margin: 0; display: grid; gap: 0.65rem; }
.group legend { padding: 0 0.3rem; font-weight: 600; font-size: 0.95rem; }
.item-form details > summary { cursor: pointer; color: var(--accent); margin-bottom: 0.6rem; }
.item-form details[open] > *:not(summary) { margin-bottom: 0.85rem; }
form.plain { display: grid; gap: 0.75rem; }
form.plain > button { justify-self: start; }
.preview { display: block; max-width: 100%; max-height: 18rem; object-fit: contain; border-radius: var(--radius); border: 1px solid var(--line); }

/* Photos: thumbnails, full-screen viewer, cropper */
.thumbs { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.75rem; }
.thumb {
  padding: 0; width: 7rem; height: 7rem; min-height: 0; overflow: hidden; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.thumb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.pdf {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.3rem;
  color: var(--fg); background: var(--surface); padding: 0.5rem;
}
.thumb.pdf.big { width: 9rem; height: 9rem; margin-bottom: 0.5rem; }
.pdf-mark { font-weight: 700; color: #fff; background: var(--danger); border-radius: 0.3rem; padding: 0.1rem 0.5rem; font-size: 0.85rem; }
.pdf-label { font-size: 0.75rem; color: var(--muted); text-align: center; line-height: 1.2; }
.viewer-pdf { width: 100%; height: 100%; border: 0; background: #fff; }
/* PDFs: buttons in a bar above the document, so they don't cover the PDF viewer's own toolbar. */
.viewer.pdf[open] { flex-direction: column; justify-content: flex-start; padding-top: calc(4rem + env(safe-area-inset-top)); }
.viewer.pdf .viewer-pdf { flex: 1; }
.viewer-open { position: absolute; top: max(0.75rem, env(safe-area-inset-top)); left: 0.75rem; }
.thumb.broken::after { content: "Photo unavailable"; font-size: 0.75rem; color: var(--muted); padding: 0.5rem; }
.viewer, .cropper {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #000; color: #fff;
}
.viewer[open] { display: flex; align-items: center; justify-content: center; }
.viewer::backdrop, .cropper::backdrop { background: #000; }
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-close {
  position: absolute; top: max(0.75rem, env(safe-area-inset-top)); right: 0.75rem; z-index: 1;
  width: 2.75rem; height: 2.75rem; padding: 0; border-radius: 50%; background: rgb(0 0 0 / 0.6); color: #fff;
  border: 1px solid rgb(255 255 255 / 0.4); font-size: 1.2rem;
}
.viewer-delete {
  position: absolute; bottom: max(1rem, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: rgb(0 0 0 / 0.6); color: #fff; border: 1px solid rgb(255 255 255 / 0.4);
}
.cropper[open] {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.75rem;
  padding: max(0.75rem, env(safe-area-inset-top)) 0.75rem max(0.75rem, env(safe-area-inset-bottom));
}
.crop-help { margin: 0; color: #ddd; font-size: 0.9rem; text-align: center; }
.crop-area { position: relative; display: inline-block; touch-action: none; user-select: none; line-height: 0; }
.crop-canvas { display: block; max-width: calc(100vw - 1.5rem); max-height: calc(100dvh - 9rem); width: auto; height: auto; }
.crop-box {
  position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgb(0 0 0 / 0.55); cursor: move; touch-action: none;
}
.crop-handle {
  position: absolute; width: 1.75rem; height: 1.75rem; border: 3px solid #fff; background: rgb(255 255 255 / 0.15);
  touch-action: none;
}
.crop-handle.nw { left: -0.9rem; top: -0.9rem; border-right: 0; border-bottom: 0; cursor: nwse-resize; }
.crop-handle.ne { right: -0.9rem; top: -0.9rem; border-left: 0; border-bottom: 0; cursor: nesw-resize; }
.crop-handle.sw { left: -0.9rem; bottom: -0.9rem; border-right: 0; border-top: 0; cursor: nesw-resize; }
.crop-handle.se { right: -0.9rem; bottom: -0.9rem; border-left: 0; border-top: 0; cursor: nwse-resize; }
.cropper .actions { justify-content: center; margin-top: 0; }
.cropper button.secondary { color: #fff; border-color: rgb(255 255 255 / 0.4); }

.dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--fg);
  max-width: min(28rem, calc(100% - 2rem)); padding: 1.25rem;
}
.dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog p { margin-top: 0; }

/* Landing (signed out) */
.landing { padding-top: 1.5rem; }
.landing .view-title { font-size: 2rem; }
.lead { font-size: 1.15rem; color: var(--muted); margin-top: 0; }
.benefits { padding-left: 1.2rem; margin: 1.25rem 0 1.75rem; }
.benefits li { margin: 0.5rem 0; }
.legal { margin-top: 2rem; text-align: center; }

/* ---------- Info pages (connect, privacy, terms) ---------- */

body:not(.app) > header { display: flex; align-items: center; padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); }
body:not(.app) > header h1 { margin: 0; font-size: 1.2rem; }
h1 a { color: inherit; text-decoration: none; }
body:not(.app) main { max-width: 44rem; margin: 0 auto; padding: 1rem; }
footer { max-width: 44rem; margin: 2rem auto; padding: 0 1rem; color: var(--muted); font-size: 0.85rem; }
.doc h3 { font-size: 1rem; margin: 1.5rem 0 0.25rem; }
.doc .meta { margin-top: -0.25rem; }
.doc ul, .doc ol { padding-left: 1.3rem; }
.doc li { margin: 0.4rem 0; }
.doc code { font-size: 0.9em; padding: 0.05rem 0.3rem; border: 1px solid var(--line); border-radius: 0.25rem; }
.copy-box { display: grid; gap: 0.3rem; margin: 1rem 0; }
.copy-box label { font-size: 0.9rem; color: var(--muted); }
.copy-row { display: flex; gap: 0.5rem; }
.copy-row input { flex: 1; min-width: 0; }
.buttons { display: flex; flex-wrap: wrap; gap: 0.75rem; }
