:root {
  --fg: #1b1b1b; --muted: #6b6b6b; --bg: #fafaf7; --card: #fff; --line: #ddd;
  --accent: #2f6fde; --danger: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root { --fg: #eee; --muted: #9a9a9a; --bg: #161616; --card: #222; --line: #3a3a3a; --accent: #6c9cff; --danger: #ff6b5e; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 17px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--fg); background: var(--bg); }
main { max-width: 720px; margin: 0 auto; padding: 16px; }
h1 { font-size: 2rem; margin: .1em 0; }
h2 { font-size: .95rem; margin: 1.6em 0 .5em; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
a { color: var(--accent); }
.muted { color: var(--muted); }
.box-head p { margin: 0; }
.where { font-size: 1.6rem; font-weight: 700; }
.error { border-left: 4px solid var(--danger); background: var(--card); padding: .5em .8em; }
.error-text { color: var(--danger); }
button, .button {
  font: inherit; padding: .6em 1em; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--fg); cursor: pointer; display: inline-block;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.small, .button.small { padding: .25em .6em; font-size: .85rem; }
button.danger { color: var(--danger); }
input {
  font: inherit; padding: .55em .7em; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--fg); min-width: 0;
}
input.wide { width: 100%; }
form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
form.inline input:not([type=number]) { flex: 1 1 9em; }
.locations { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 8px; }
.locations button { min-height: 56px; }
.locations button.current { outline: 3px solid var(--accent); }
.undo { display: flex; gap: 10px; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; margin: 12px 0; }
.photo-form { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-form label { position: relative; overflow: hidden; }
.photo-form input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
ul.items { list-style: none; padding: 0; margin: 8px 0; }
ul.items li { display: flex; gap: 4px; align-items: center; border-bottom: 1px solid var(--line); }
ul.items input { border-color: transparent; background: transparent; }
ul.items input:focus { border-color: var(--line); background: var(--card); }
.note { background: var(--card); padding: .5em .8em; border-radius: 8px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.photos figcaption { font-size: .85rem; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.photos figcaption form { margin: 0; }
ul.plain { list-style: none; padding: 0; }
ul.plain li { padding: 4px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* Move page: name, with links to its edit and admin pages. */
.move-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .2em 1rem; }
.page-links { white-space: nowrap; }
.location-list li { padding: 0; }
.location-list form.inline { flex: 1; margin: 3px 0; }
table.boxes { width: 100%; border-collapse: collapse; }
table.boxes th, table.boxes td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
/* Box number with the current location beside it. */
.title-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: .2em 1rem; }

/* One header style for every section; collapsible ones get a ▸/▾ arrow. */
.section-title { font-size: .95rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0; }
h2.section-title { margin: 1.6em 0 .5em; }
details.section { margin: 1.2em 0 0; }
details.section > summary.section-head { list-style: none; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-height: 2.2em; cursor: pointer; }
details.section > summary.section-head::-webkit-details-marker { display: none; }
details.section > summary.section-head::before { content: "▸"; color: var(--muted); width: 1em; }
details.section[open] > summary.section-head::before { content: "▾"; }
.section-head .section-title { margin-right: auto; }
/* Editing only makes sense on an open list. */
details.section:not([open]) .list-edit, details.section:not([open]) .list-save,
details.section:not([open]) .section-edit { display: none !important; }

/* Photo detail page: full-size image with a draggable crop rectangle. */
/* The wrapper allows pinch-zoom; only the drag handles swallow touches. */
.crop { position: relative; display: inline-block; max-width: 100%; }
.crop img { max-width: 100%; max-height: 65vh; width: auto; height: auto; display: block; border-radius: 8px; }
.crop.zoomed { max-width: none; }
.crop.zoomed img { max-height: none; max-width: none; width: auto; }
.crop-scroll { overflow: auto; -webkit-overflow-scrolling: touch; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45); }
.crop-box .handle {
  position: absolute; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; touch-action: none; cursor: grab;
}
.crop-box .handle[data-corner=tl] { left: -18px; top: -18px; }
.crop-box .handle[data-corner=br] { right: -18px; bottom: -18px; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.photo-actions form { margin: 0; }

/* Contents grouped by source: typed, packing sheet, photo, containers.
   Each list reads as plain text; "Edit" swaps in text boxes, Hide/Show, delete and Save. */
.item-text { flex: 1; padding: .55em .7em; }
.item-list .item-input, .item-list .item-toggle, .item-list .item-delete, .item-list .list-save { display: none; }
.item-list.editing .item-text { display: none; }
.item-list.editing .item-input { display: block; flex: 1; border-color: var(--line); background: var(--card); }
.item-list.editing .item-toggle, .item-list.editing .item-delete, .item-list.editing .list-save { display: inline-block; }
.item-list:not(.editing) li.is-hidden { display: none; }
.item-list.editing li.is-hidden .item-input { opacity: .45; text-decoration: line-through; }
.list-save:disabled { opacity: .45; cursor: default; }
.sheet-fields { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; background: var(--card); border-radius: 8px; padding: .5em .8em; margin: 8px 0; }
.sheet-fields form { margin: 0; }

/* Photos shown large. In edit mode: a ✕ on each photo's top-right corner, small camera buttons below. */
.photos { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.photos figure { position: relative; }
.photos img { aspect-ratio: auto; max-height: 70vh; object-fit: contain; background: var(--card); }
.photo-delete-form { position: absolute; top: 6px; right: 6px; margin: 0; z-index: 1; }
.photo-delete { width: 2.2em; height: 2.2em; padding: 0; border-radius: 50%; background: var(--card); }
.photos-section:not(.editing) .photo-delete-form { display: none; }

/* Contents: closed, an inline list under the header; open, one line per row with Edit in the
   header; editing, text boxes plus "Add an item". */
.section-head .inline-items { flex-basis: 100%; margin: 0 0 0 1.4em; }
.inline-items { margin: .2em 0; line-height: 1.6; }
.contents-list details[open] .inline-items { display: none; }
.empty-note { margin: .2em 0; }
.contents .photo-form { margin-top: 12px; }
.review-note { margin: .4em 0; }
.review-name { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; }
.review-name input { flex: 1; }
.contents-list .add-line { display: none; }
.contents-list.editing .add-line { display: flex; margin-top: 6px; }
.add-line input { flex: 1; }

/* Header: "Box 001  Art supplies", then "Current location: Kitchen, packed on Tuesday." */
.title-row h1 { margin: 0; }
.box-name { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; margin: 0; }
.box-name .name-show { font: inherit; font-size: 2rem; font-weight: 400; background: none; border: 0; padding: 0; color: var(--fg); cursor: pointer; text-align: left; }
.box-name .name-show.muted { color: var(--muted); }
.box-name input, .box-name .name-save { display: none; }
.box-name.editing .name-show { display: none; }
.box-name.editing input { display: block; font-size: 1.2rem; }
.box-name.editing .name-save { display: inline-block; }
.where-line { margin: .3em 0 0; font-size: 1.1rem; }
.where-line .where { font-size: inherit; font-weight: 700; }
