:root {
  --bg: #f6f1ea;
  --surface: #fffaf4;
  --ink: #3b302a;
  --muted: #8a7b70;
  --line: #e4d9cc;
  --accent: #a0674b;
  --accent-soft: #efe0d4;
  --radius: 14px;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-anchor: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

/* header + tabs */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h1 { font: 600 28px/1 var(--serif); margin: 0; letter-spacing: .01em; }
.tabs { display: flex; background: var(--accent-soft); border-radius: 999px; padding: 3px; }
.tab {
  border: 0; background: none; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  font-size: 14px; color: var(--muted); font-weight: 500;
}
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .08); }

/* filters: expanded at the top, collapsed into a toggle bar once the user scrolls */
.filters { margin-top: 10px; }
.filters-toggle {
  display: none; width: 100%; align-items: center; gap: 8px; border: 1px solid var(--line);
  background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 14px;
}
.filters-count { color: var(--accent); font-weight: 600; }
.chevron { margin-left: auto; transition: transform .2s; }
.filters.collapsed .filters-toggle { display: flex; }
.filters.collapsed .filters-body { display: none; }
.filters.collapsed.open .filters-body { display: grid; margin-top: 10px; }
.filters.collapsed.open .chevron { transform: rotate(180deg); }
.filters-body { display: grid; gap: 8px; }
.filter-group { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; align-items: center; }
.filter-group::-webkit-scrollbar { display: none; }
.filter-label { font-size: 12px; color: var(--muted); min-width: 52px; flex-shrink: 0; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 4px 11px; font-size: 13px; white-space: nowrap; cursor: pointer; flex-shrink: 0;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.clear-filters { border: 0; background: none; color: var(--accent); font-size: 13px; padding: 4px 0; cursor: pointer; justify-self: start; }

/* grid: always 2 cards per row */
main { flex: 1; padding: 12px 16px 24px; width: 100%; max-width: 760px; margin: 0 auto; }
.summary { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card {
  border: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden;
  cursor: pointer; aspect-ratio: 3 / 4; box-shadow: 0 1px 2px rgb(59 48 42 / .06);
}
.card img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.card:hover img { transform: scale(1.03); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.foot { padding: 20px 16px calc(env(safe-area-inset-bottom, 0px) + 20px); text-align: center; border-top: 1px solid var(--line); }
.doc-link {
  display: inline-block; padding: 8px 18px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); text-decoration: none; font-size: 14px; background: var(--surface);
}

/* modal */
.modal {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--ink);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
}
.modal::backdrop { background: rgb(40 30 25 / .5); }
.modal-inner { padding: 16px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.modal-head h2 { font: 600 24px/1.15 var(--serif); margin: 0; }
.icon-btn { border: 0; background: var(--accent-soft); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; flex-shrink: 0; font-size: 18px; line-height: 1; }
.big-photo { width: 100%; border-radius: var(--radius); max-height: 62dvh; object-fit: cover; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 14px 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 8px; }
.links { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.link-card { border: 0; background: none; padding: 0; text-align: left; cursor: pointer; font-size: 12px; }
.link-card img { aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 14px; }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 9px 18px; cursor: pointer; font-weight: 500; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* edit mode: small photo + form */
.edit-head { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.edit-head img { width: 72px; height: 96px; object-fit: cover; border-radius: 10px; }
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff;
}
.field textarea { min-height: 70px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.error { color: #b3402a; font-size: 13px; }

@media (min-width: 700px) {
  .grid { gap: 16px; }
}

/* add button */
.fab {
  position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); z-index: 20;
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  font-size: 30px; line-height: 1; cursor: pointer; box-shadow: 0 6px 18px rgb(110 60 35 / .35);
}
.foot { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 86px); }

/* AI status */
.card { position: relative; }
.badge {
  position: absolute; left: 8px; bottom: 8px; background: rgb(255 250 244 / .92); color: var(--accent);
  border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 600; animation: pulse 1.6s ease-in-out infinite;
}
.badge.err { color: #b3402a; animation: none; }
@keyframes pulse { 50% { opacity: .55; } }
.ai-note { margin: 12px 0 0; color: var(--accent); font-size: 14px; }
.ai-note.err { color: #b3402a; }
.description { margin: 14px 0 0; font-size: 15px; }

/* add / edit form: photo picker + AI toggle */
.photo-pick {
  display: flex; align-items: center; gap: 12px; cursor: pointer; border: 1px dashed var(--line);
  border-radius: var(--radius); padding: 8px; background: var(--bg);
}
.photo-pick img { width: 72px; height: 96px; object-fit: cover; border-radius: 10px; }
.photo-pick.new { min-height: 120px; justify-content: center; }
.photo-hint { color: var(--accent); font-weight: 500; }
.photo-change { color: var(--muted); font-size: 14px; }
.ai-toggle {
  display: flex; gap: 10px; align-items: flex-start; background: var(--accent-soft); border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; font-size: 14px;
}
.ai-toggle input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
.ai-toggle small { color: var(--muted); }
.modal { overflow-x: hidden; }
.form > *, .field, .row2 > * { min-width: 0; }
.chips .chip { white-space: normal; text-align: left; flex-shrink: 1; }
