:root {
  --bg: #faf6ef;
  --bg-elevated: #ffffff;
  --text: #241d16;
  --text-muted: #8a7d6c;
  --border: #e9decf;
  --accent: #c9702f;
  --accent-soft: #f4e3cf;
  --accent-text: #8a4a1c;
  --danger: #b3392c;
  --danger-soft: #f7e4e0;
  --header-bg: #1c1712;
  --header-text: #f3ece2;
  --good: #4a7c4e;
  --good-soft: #e3ecdf;
  --font: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "Space Grotesk", var(--font);
  --font-mono: "Space Grotesk", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17130f;
    --bg-elevated: #221c15;
    --text: #f1e9dd;
    --text-muted: #a79a86;
    --border: #362c22;
    --accent: #e0894a;
    --accent-soft: #3a2a1a;
    --accent-text: #f0a86a;
    --danger: #e06a58;
    --danger-soft: #3a2420;
    --good: #7fb583;
    --good-soft: #223425;
    --header-bg: #100d0a;
    --header-text: #f1e9dd;
  }
}
:root[data-theme="dark"] {
  --bg: #17130f;
  --bg-elevated: #221c15;
  --text: #f1e9dd;
  --text-muted: #a79a86;
  --border: #362c22;
  --accent: #e0894a;
  --accent-soft: #3a2a1a;
  --accent-text: #f0a86a;
  --danger: #e06a58;
  --danger-soft: #3a2420;
  --good: #7fb583;
  --good-soft: #223425;
  --header-bg: #100d0a;
  --header-text: #f1e9dd;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; }
button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: var(--header-bg); color: var(--header-text);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark { font-size: 19px; line-height: 1; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 16.5px; letter-spacing: -0.01em; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.space-select {
  font-family: var(--font); font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,0.08); color: var(--header-text);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 8px;
  padding: 6px 8px; max-width: 40vw;
}
.logout-link {
  background: none; border: none; padding: 0; cursor: pointer; font-family: var(--font);
  color: var(--header-text); opacity: 0.7; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.logout-link:hover { opacity: 1; text-decoration: underline; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; overflow-x: auto; gap: 2px;
  background: var(--bg-elevated); border-top: 1px solid var(--border);
  padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
}
.tab { flex: 0 0 auto; appearance: none; border: none; background: transparent; color: var(--text-muted); font-size: 12.5px; font-weight: 600; padding: 8px 14px; border-radius: 9px; cursor: pointer; }
.tab.active { color: var(--accent-text); background: var(--accent-soft); }
@media (min-width: 640px) { .tabbar { justify-content: center; } }

/* ---------- layout / states ---------- */
main#app { padding: 16px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); max-width: 860px; margin: 0 auto; }
.loading, .empty-state { text-align: center; color: var(--text-muted); padding: 48px 20px; font-size: 14px; }
.section-title { font-family: var(--font-display); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 22px 0 10px; }
.section-title:first-child { margin-top: 0; }
.auth-gate { display: flex; justify-content: center; padding: 48px 16px; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font); font-size: 14px; font-weight: 600; border-radius: 10px; padding: 10px 16px;
  border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.05); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-outline { border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { font-size: 12.5px; padding: 7px 12px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text-muted); cursor: pointer; flex-shrink: 0; }
.icon-btn:hover { color: var(--text); border-color: var(--text-muted); }
.icon-btn svg { width: 15px; height: 15px; }

/* ---------- search bar ---------- */
.search-bar { position: relative; margin-bottom: 16px; }
.search-input {
  width: 100%; font-family: var(--font); font-size: 15px; padding: 12px 14px 12px 40px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
}
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-icon svg { width: 16px; height: 16px; }

/* ---------- container grid ---------- */
.container-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.container-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  cursor: pointer; display: flex; flex-direction: column; text-align: left; padding: 0;
}
.container-card:hover { border-color: var(--accent); }
.container-card-photo { aspect-ratio: 1; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.container-card-photo img { width: 100%; height: 100%; object-fit: cover; }
.container-card-photo-placeholder { font-size: 28px; opacity: 0.4; }
.container-card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.container-card-name { font-weight: 700; font-size: 14px; }
.container-card-location { font-size: 12px; color: var(--text-muted); }
.container-card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }

/* ---------- tag chips ---------- */
.tag-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text);
  font-family: var(--font-mono); text-transform: lowercase;
}
.tag-chip-manual { background: var(--good-soft); color: var(--good); }
.tag-chip-remove { cursor: pointer; opacity: 0.6; font-weight: 700; }
.tag-chip-remove:hover { opacity: 1; }
.tag-add-row { display: flex; gap: 8px; margin-top: 10px; }
.tag-add-input { flex: 1; }

/* ---------- container detail ---------- */
.container-detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.container-detail-title { font-family: var(--font-display); font-size: 21px; font-weight: 700; }
.container-detail-location { color: var(--text-muted); font-size: 13.5px; margin-top: 2px; }
.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; }
.photo-strip img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); flex-shrink: 0; }
.photo-add-tile {
  width: 96px; height: 96px; border-radius: 10px; border: 1.5px dashed var(--border); background: none;
  color: var(--text-muted); font-size: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer;
}
.photo-add-tile:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- cards / lists ---------- */
.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.card-detail { font-size: 13.5px; color: var(--text-muted); }
.people-list { display: flex; flex-direction: column; }
.people-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; font-size: 13.5px; }
.people-row + .people-row { border-top: 1px solid var(--border); }
.people-row-pending { color: var(--text-muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(8px);
  background: var(--header-bg); color: var(--header-text); font-size: 13.5px; padding: 10px 16px; border-radius: 10px;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; z-index: 50; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { background: var(--danger); }

/* ---------- modal / form ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,15,10,0.5); display: flex; align-items: flex-end; justify-content: center; z-index: 40; }
.modal { background: var(--bg-elevated); border-radius: 16px 16px 0 0; width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto; padding: 18px; }
@media (min-width: 640px) { .modal-backdrop { align-items: center; } .modal { border-radius: 16px; } }
.modal-title { font-family: var(--font-display); font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.form-input {
  font-family: var(--font); font-size: 14.5px; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); width: 100%;
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.form-input { resize: vertical; min-height: 60px; }
.form-multiselect { border: 1px solid var(--border); border-radius: 9px; background: var(--bg); padding: 2px 10px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--border); font-size: 14px; }
.check-row:last-child { border-bottom: none; }
.check-row input { width: 17px; height: 17px; accent-color: var(--accent); }
.modal-footer { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.modal-spacer { flex: 1; }

/* ---------- checklist ---------- */
.checklist-list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 0 12px; }
.checklist-list-head:first-child { margin-top: 0; }
.checklist-list-title { font-family: var(--font-display); font-size: 18px; font-weight: 700; margin: 0; }
.checklist-card-badge { font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: var(--text-muted); white-space: nowrap; }

/* Each category is its own visually distinct card -- a colored left
   edge + its own header/progress/badge, not a plain text label buried
   in one long scrolling list -- so a 27-item section reads as clearly
   separate from a 13-item one, and progress is checkable per section
   at a glance without opening it. */
.checklist-category-card { padding: 0; overflow: hidden; margin-bottom: 12px; border-left: 3px solid var(--accent); }
.checklist-category-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 14px; }
.checklist-category-title-wrap { display: flex; align-items: center; gap: 9px; min-width: 0; }
.checklist-collapse-chevron { display: inline-block; color: var(--text-muted); font-size: 11px; transition: transform 0.15s ease; flex-shrink: 0; }
.checklist-collapse-chevron.open { transform: rotate(90deg); }
.checklist-card-title { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.checklist-category-head-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.progress-track { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; margin: 0 14px 14px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.4s ease; }
.checklist-item-list { border-top: 1px solid var(--border); }
.task-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; cursor: pointer; }
.task-row:last-child { border-bottom: none; }
.task-row input[type="checkbox"] { width: 19px; height: 19px; accent-color: var(--accent); flex-shrink: 0; }
.task-row.checked { background: var(--good-soft); }
.task-row.checked .task-text { color: var(--text-muted); text-decoration: line-through; }
.task-text { flex: 1; word-break: break-word; }
.checklist-add-row { display: flex; gap: 8px; padding: 12px 14px; align-items: center; border-top: 1px solid var(--border); }
.checklist-add-row input { flex: 1; }

/* ---------- space switcher / list ---------- */
.space-list { display: flex; flex-direction: column; gap: 10px; }
.space-card { display: flex; align-items: center; gap: 12px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px; padding: 14px; cursor: pointer; text-align: left; }
.space-card:hover { border-color: var(--accent); }
.space-card-emoji { font-size: 24px; }
.space-card-name { font-weight: 700; font-size: 15px; }
