:root {
  color-scheme: light;
  --paper: #F3F6F0;
  --card: #FFFFFF;
  --ink: #1A2A1F;
  --muted: #4E6356;
  --line: #D4DDD2;
  --green: #2A5F36;
  --green-ink: #FFFFFF;
  --header: #1E3528;
  --header-ink: #F3F7F2;
  --header-muted: #B7C8BB;
  --warn: #6A4E16;
  --warn-bg: #F6EEDD;
  --bad: #8B2E28;
  --bad-bg: #F8E8E5;
  --ok-bg: #E4F0E7;
  --ok-ink: #1C4A2C;
  --soft: #E4EFE6;
  --pill-bg: #E4EBE4;
  --shadow: 0 7px 28px rgba(26, 42, 31, 0.06);
  --font-fallback: "Segoe UI", system-ui, sans-serif;
  font-family: "Plus Jakarta Sans", var(--font-fallback);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--green); }

.app { min-height: 100vh; }

.site-header {
  background: var(--header);
  color: var(--header-ink);
  min-height: 56px;
  padding: 12px max(20px, calc((100vw - 1000px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--header-ink);
  text-decoration: none;
  font-family: Fraunces, Georgia, var(--font-fallback);
  font-weight: 700;
  font-size: clamp(20px, 2.4vw, 26px);
  letter-spacing: 0.01em;
  line-height: 1;
}
.mark { width: 26px; height: 26px; flex: none; }
.header-actions { display: flex; align-items: center; gap: 14px; color: var(--header-muted); font-size: 14px; }
.header-actions a { color: var(--header-ink); font-weight: 700; text-decoration: none; }
.header-actions a:hover { text-decoration: underline; }

.shell { width: min(1000px, 100%); margin: 0 auto; padding: 16px 20px 96px; }
.shell.compact { padding-top: 12px; padding-bottom: 220px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin: 12px 0;
}

h1, h2, h3 { font-family: Fraunces, Georgia, var(--font-fallback); font-weight: 650; }
h1 { font-size: clamp(26px, 4vw, 36px); line-height: 1.15; margin: 0 0 8px; }
h1.crumb { font-family: Fraunces, Georgia, var(--font-fallback); font-size: clamp(18px, 2.6vw, 22px); line-height: 1.35; font-weight: 650; }
h1.crumb a { color: inherit; text-decoration: none; border-bottom: 1px solid transparent; }
h1.crumb a:hover { border-bottom-color: var(--line); }
.tree { display: grid; gap: 2px; }
.tree-children { margin: 0 0 8px 16px; padding-left: 8px; border-left: 1px solid var(--line); display: grid; gap: 2px; }
.tree-children[hidden], .new-room[hidden] { display: none !important; }
.tree button.tree-row, .tree a.tree-row, .tree button.tree-add, .tree a.tree-add {
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  width: 100%;
  justify-content: flex-start;
  gap: 10px;
  padding: 8px 10px;
  text-align: left;
  text-decoration: none;
  font-weight: 550;
  box-shadow: none;
}
.tree button.tree-add, .tree a.tree-add { color: var(--green); font-weight: 650; }
.tree-label { flex: 1; min-width: 0; margin-right: 8px; }
.tree-room > .tree-row .tree-label { display: flex; align-items: baseline; gap: 6px; margin-right: 0; }
.tree-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-count { flex: none; white-space: nowrap; color: var(--muted); font-weight: 550; }
.tree-count-short { display: none; }
.notes-mark { flex: none; }
.tree .ico, .tree .chevron { width: 20px; height: 20px; flex: none; }
.tree .ico { margin-right: 8px; }
.tree .chevron { transition: transform .15s ease; }
.tree [aria-expanded="true"] > .chevron { transform: rotate(90deg); }
.tree-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 4px 10px 8px; }
.new-room { display: grid; gap: 8px; padding: 4px 10px 8px; }
.tree-room { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.tree .tree-room > button.tree-row { flex: 1 1 0; width: auto; min-width: 0; max-width: 100%; }
@media (max-width: 719px) {
  .tree .tree-room > button.tree-row { padding-left: 6px; padding-right: 4px; gap: 6px; }
  .tree .tree-room > button.tree-row .ico { margin-right: 4px; }
  .tree-room > .tree-row .tree-label { gap: 4px; }
  .tree-count-full { display: none; }
  .tree-count-short {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35em;
    height: 1.35em;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--pill-bg);
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
    line-height: 1;
  }
  .notes-word { display: none; }
}
.rename-room { flex: 1 0 100%; display: grid; gap: 8px; padding: 0 10px 8px; }
.rename-room[hidden] { display: none !important; }
button.tree-rename { background: transparent; color: var(--ink); border: 0; width: 44px; min-width: 44px; min-height: 44px; padding: 0; border-radius: 12px; box-shadow: none; }
button.tree-edit { background: transparent; color: var(--green); border: 0; min-width: 44px; min-height: 44px; padding: 0 8px; border-radius: 12px; box-shadow: none; font-weight: 650; }
.notes-mark { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; color: var(--muted); font-size: 12px; font-weight: 650; }
.notes-mark .ico { width: 14px; height: 14px; }
.locked-banner, .record-banner { background: var(--soft); color: var(--ink); border-radius: 12px; padding: 12px 14px; font-weight: 650; margin: 0 0 12px; }
.inventory-banner { background: var(--ok-bg); color: var(--ok-ink); border-radius: 12px; padding: 12px 14px; font-weight: 650; margin: 0 0 12px; }
.history-list { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 8px; }
.history-list a { display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: inherit; text-decoration: none; }
a.continue-recording, button.continue-recording, a.home-continue { width: 100%; }
.home-section { margin: 0 0 28px; }
.home-section h2 { font-size: 20px; margin: 0 0 10px; }
a.home-add { width: 100%; margin: 0 0 14px; font-size: 17px; font-weight: 700; }
.home-row { display: grid; gap: 4px; }
.home-row p,
.home-row .field-note { margin: 0; }
.home-row > .button,
.home-row > button,
.home-row > .home-actions { margin-top: 8px; }
.home-actions { display: flex; flex-wrap: wrap; gap: 8px; }
a.home-continue { min-height: 52px; font-size: 18px; font-weight: 700; }
.history-draft { display: grid; gap: 8px; }
.sync-state { min-height: 1.2em; margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.recording-intro { margin: 0 0 8px; }
.recording-intro h2 { font-size: 22px; line-height: 1.2; margin: 0 0 2px; }
.recording-intro p { margin: 0; color: var(--muted); }
.record-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; gap: 8px; padding: 10px max(16px, calc((100vw - 1000px) / 2)) calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.record-actions .button, .record-actions button { width: 100%; }
.record-actions .sync-state { min-height: 0; margin: 0; }
.history-fresh { background: var(--ok-bg); border-radius: 14px; padding: 8px; }
.history-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; padding: 12px; border: 1px dashed var(--line); border-radius: 14px; background: var(--soft); }
.readonly-value { margin: 10px 0; padding: 0; background: transparent; border: 0; color: var(--ink); }
.field-error { color: var(--bad); font-size: 14px; margin: 6px 0 0; }
.field-note { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.nav-actions { display: flex; gap: 8px; margin: 4px 0 16px; }
.nav-actions .button { min-height: 44px; }
h2 { font-size: clamp(18px, 2.4vw, 22px); margin: 0 0 8px; }

label { display: block; font-size: 14px; margin: 12px 0 6px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 11px;
  padding: 12px 14px;
  font-size: 16px;
}

textarea { min-height: 88px; resize: vertical; }

.row { display: grid; gap: 12px; }
@media (min-width: 720px) {
  .row.two { grid-template-columns: 1fr 1fr; }
  .row.three { grid-template-columns: 1.4fr .8fr .6fr; }
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

button, .button {
  appearance: none;
  border: 1px solid var(--green);
  background: var(--green);
  color: var(--green-ink);
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 47px;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button.secondary,
a.secondary,
button.secondary:hover,
a.secondary:hover,
button.secondary:focus,
a.secondary:focus,
button.secondary:focus-visible,
a.secondary:focus-visible {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  text-decoration: none;
}
button.danger,
a.danger,
button.danger:hover,
a.danger:hover,
button.danger:focus,
a.danger:focus,
button.danger:focus-visible,
a.danger:focus-visible {
  background: var(--bad-bg);
  color: var(--bad);
  border-color: #E4C4BE;
  text-decoration: none;
}
a.button:not(.secondary):not(.danger),
a.button:not(.secondary):not(.danger):hover,
a.button:not(.secondary):not(.danger):focus,
a.button:not(.secondary):not(.danger):focus-visible,
a.button:not(.secondary):not(.danger):active {
  color: var(--green-ink);
  text-decoration: none;
}
.drafts { list-style: none; margin: 12px 0 18px; padding: 0; display: grid; gap: 10px; }
.drafts li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
button:disabled { opacity: 0.45; }

.list { display: grid; gap: 10px; }
.list a.item, button.item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  text-decoration: none;
  box-shadow: none;
  min-height: 0;
}

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--pill-bg);
}
.pill.pending { background: var(--pill-bg); }
.pill.uploading { background: var(--warn-bg); color: var(--warn); }
.pill.complete, .pill.locked { background: var(--ok-bg); color: var(--ok-ink); }
.pill.draft { background: var(--warn-bg); color: var(--warn); }

.banner {
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--bad-bg);
  color: var(--bad);
  margin: 8px 0;
}
.banner.ok { background: var(--ok-bg); color: var(--ok-ink); }
#load-error button { margin-left: 8px; min-height: 40px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.info { background: var(--soft); color: var(--ink); }

.bar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 0 4px;
  background: linear-gradient(transparent, var(--paper) 20%);
}

code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }

.photo-input { padding: 14px; background: var(--soft); }

.tabs, .chips, .conditions { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs button, .chips button, .conditions button { background: transparent; color: var(--ink); }
.tabs button[aria-pressed="true"], .chips button[aria-pressed="true"], .conditions button[aria-pressed="true"] {
  background: var(--green);
  color: var(--green-ink);
  border-color: var(--green);
}
.choice { display: grid; gap: 12px; margin: 8px 0 18px; }
a.choice-button, button.choice-button {
  display: flex;
  width: 100%;
  min-height: 92px;
  align-items: center;
  justify-content: center;
  padding: 18px;
  border-radius: 20px;
  font-size: 22px;
  text-decoration: none;
}
a.choice-button[data-flow="contents"], button.choice-button[data-start="contents"], #open-possessions, a.button.contents {
  background: var(--green);
  border-color: var(--green);
  color: var(--green-ink);
}
.capture { display: flex; gap: 8px; }
.capture button { flex: 1; min-height: 47px; font-size: 15px; padding: 8px 12px; }
.card a:not(.button), .home-row a:not(.button), .list a.item:not(.button) { color: inherit; text-decoration: none; }
.card a:not(.button):hover, .home-row a:not(.button):hover, .list a.item:not(.button):hover { text-decoration: underline; }
.status-line { font-size: 15px; margin: 8px 0; }
.hidden-file { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); visibility: hidden; border: 0; }
[hidden] { display: none !important; }

.evidence { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 8px 0 16px; }
@media (min-width: 720px) { .evidence { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { margin: 0; min-width: 0; }
.tile figcaption { font-size: 12px; line-height: 1.3; color: var(--muted); margin-top: 4px; }
.tile .actions { margin-top: 6px; }
.tile .actions button { min-height: 40px; padding: 8px 12px; }
.pick-preview { display: grid; gap: 12px; margin: 12px 0; }
.media-field { margin: 0 0 8px; }
.media-field > button { width: 100%; }
.field-media { margin: 8px 0 4px; }
.field-files .evidence { grid-template-columns: 1fr; }
.field-files .tile > img,
.field-files button.thumb,
.field-files button.thumb img,
.field-files .pdf-tile,
.field-files .tile-fallback {
  width: 100%;
  height: 160px;
  max-height: 180px;
  object-fit: contain;
}
.field-files .tile .actions button { flex: 1 1 30%; }
.field-media .pick-preview { margin: 8px 0; }
.field-media img.pick-shot { min-height: 96px; max-height: 200px; }
.pick-card { display: grid; gap: 8px; }
.pick-file {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-weight: 650;
}
.file-icon { width: 36px; height: 36px; flex: none; }
.field-status { display: grid; gap: 8px; }
.upload-line { display: grid; gap: 8px; margin: 0; }
.upload-line button { justify-self: start; }
.upload-bar { width: 100%; height: 10px; accent-color: var(--green); }
.form-save {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-left: max(16px, calc((100vw - 1000px) / 2));
  padding-right: max(16px, calc((100vw - 1000px) / 2));
}
.form-save .button, .form-save button { width: 100%; }
.shell:has(.form-save) { padding-bottom: 260px; }
.row-menu { flex: 1 0 100%; display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 8px; align-items: flex-start; }
.row-menu[hidden] { display: none !important; }
.row-menu .field-error, .row-menu .rename-room { flex: 1 0 100%; }
#note-status.bad { color: var(--bad); }
img.pick-shot {
  width: 100%;
  min-height: 240px;
  max-height: 70vh;
  object-fit: contain;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.pick-fallback {
  display: grid;
  place-items: center;
  min-height: 160px;
  margin: 0;
  padding: 16px;
  text-align: center;
  background: var(--soft);
  border-radius: 16px;
}
button.thumb {
  display: block;
  width: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: inherit;
}
button.thumb img, .tile > img, .tile video {
  width: 100%;
  height: 112px;
  object-fit: cover;
  display: block;
  background: var(--soft);
}
.pdf-tile, .tile-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 112px;
  border-radius: 12px;
  background: var(--soft);
  color: inherit;
  text-decoration: none;
  font-weight: 650;
}
dialog#viewer {
  border: 0;
  margin: 0;
  padding: 16px;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  background: #141210;
  color: #f6f1e8;
}
dialog#viewer img, dialog#viewer video {
  display: block;
  margin: 0 auto;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}
dialog#viewer a { color: #f6f1e8; }
dialog#viewer::backdrop { background: rgba(12, 10, 8, 0.82); }

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

@media (min-width: 780px) {
  .home-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 20px;
    align-items: start;
  }
  .home-split .home-section { margin-bottom: 0; }
  .tree {
    grid-template-columns: 1fr 1fr;
    column-gap: 20px;
    align-items: start;
  }
  .tree > [data-branch="inspection"] { grid-column: 1; grid-row: 1; }
  .tree > #branch-inspection { grid-column: 1; grid-row: 2; }
  .tree > [data-branch="possessions"] { grid-column: 2; grid-row: 1; }
  .tree > #branch-possessions { grid-column: 2; grid-row: 2; }
}

@media (max-width: 650px) {
  .capture { display: grid; grid-template-columns: 1fr; }
  .home-actions, .actions { display: grid; grid-template-columns: 1fr; }
  .home-actions .button, .home-actions button, .actions .button, .actions button { width: 100%; }
  .card { padding: 16px 18px; }
}

@media (max-width: 430px) {
  .shell { padding: 14px 14px 96px; }
  .shell.compact { padding-bottom: 220px; }
  .card { padding: 16px; }
  h1 { font-size: 24px; }
  .wordmark { font-size: 20px; }
}
