:root {
  --bg: #f7f6f2;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --border: #e2e0d6;
  --brand: #2f6f4f;
  --brand-ink: #ffffff;
  --danger: #c54b3a;
  --tier-1: #f1d6d6;
  --tier-2: #f3e8c8;
  --tier-3: #d8e5f1;
  --inbox: #ece9e0;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

.muted { color: var(--muted); font-size: 13px; }
.error { background: #fde2dd; color: var(--danger); padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topnav {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 22px; color: var(--ink); }
.nav-links { display: flex; gap: 16px; flex: 1; }
.nav-links a { color: var(--ink); }
.nav-logout { display: flex; align-items: center; gap: 12px; margin: 0; }
.nav-logout .user { font-weight: 600; }
.nav-logout button.link {
  background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 13px;
}

.container { max-width: 1400px; margin: 0 auto; padding: 24px; }

h1 { margin-top: 0; font-size: 24px; }
h2 { font-size: 17px; margin: 0 0 8px; }

button, .button {
  font: inherit;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
}
button.primary, .button.primary {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: var(--brand);
}
button.primary:hover { filter: brightness(1.05); }
button.danger { color: var(--danger); border-color: var(--danger); background: var(--panel); }
button.link { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; }

label { display: block; margin: 8px 0; font-size: 13px; color: var(--muted); }
input[type=text], input[type=url], input[type=password], input[type=file], textarea, select {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  margin-top: 4px;
}
textarea { resize: vertical; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.row .grow { flex: 3 1 200px; }
.row.spread { justify-content: space-between; align-items: center; }

.login-card {
  max-width: 360px;
  margin: 80px auto;
  padding: 32px;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 36px; margin: 0 0 4px; }

/* Board */
.board-header { margin-bottom: 16px; }
.tier-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  align-items: start;
}
.tier-column {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  min-height: 200px;
}
.tier-column[data-tier=""]   header { border-left: 4px solid var(--inbox); padding-left: 8px; }
.tier-column[data-tier="1"] header { border-left: 4px solid var(--tier-1); padding-left: 8px; }
.tier-column[data-tier="2"] header { border-left: 4px solid var(--tier-2); padding-left: 8px; }
.tier-column[data-tier="3"] header { border-left: 4px solid var(--tier-3); padding-left: 8px; }
.tier-column header { position: relative; margin-bottom: 12px; }
.tier-column header h2 { margin: 0; }
.tier-column header .count {
  position: absolute; top: 0; right: 0;
  background: var(--bg); padding: 2px 8px; border-radius: 99px; font-size: 12px; color: var(--muted);
}
.cards { display: flex; flex-direction: column; gap: 10px; min-height: 100px; }

.card {
  display: block;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  color: var(--ink);
  cursor: grab;
  transition: transform .08s ease, box-shadow .08s ease;
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }
.card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #f0eee6; }
.card .no-image {
  aspect-ratio: 4/3; display: grid; place-items: center; color: var(--muted); background: #f0eee6;
}
.card-body { padding: 10px 12px; }
.card-title { font-weight: 600; margin-bottom: 6px; }
.card-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12px; }
.badge { background: #eef2ee; padding: 2px 8px; border-radius: 99px; font-size: 11px; color: var(--brand); }
.price { font-weight: 600; color: var(--ink); }
.dims, .comment-count { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Add page */
.add-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.add-grid .wide { grid-column: 1 / -1; }
.card-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

/* Detail */
.back { display: inline-block; margin-bottom: 12px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.detail-images img.hero { width: 100%; border-radius: 8px; background: #eee; }
.detail-images .no-image.hero { aspect-ratio: 4/3; border-radius: 8px; }
.thumbs { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.thumbs img { width: 80px; height: 60px; object-fit: cover; border-radius: 4px; }
.detail-form { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }

.comments { margin-top: 32px; max-width: 700px; }
.comment {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.comment-head { display: flex; gap: 8px; align-items: baseline; font-size: 12px; }
.comment-head .inline { margin-left: auto; }
.comment-body { margin-top: 4px; white-space: pre-wrap; }
.comment-form textarea { font-family: inherit; }

/* Gallery */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.gallery-item {
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.gallery-item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #eee; }
.gallery-item figcaption { padding: 10px; font-size: 13px; }
.gallery-item figcaption .badge { margin-left: 6px; }

.inline { display: inline; margin: 0; }

/* Drag feedback */
.cards.dragging-over { background: #fafaf3; border-radius: 6px; }
.card.sortable-ghost { opacity: 0.4; }
.card.sortable-drag  { box-shadow: 0 8px 20px rgba(0,0,0,.18); }

@media (max-width: 900px) {
  .tier-board { grid-template-columns: 1fr 1fr; }
  .add-grid, .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .tier-board { grid-template-columns: 1fr; }
}

/* ---- Need + Option (v2) additions ---- */

.col-stats { display: flex; gap: 12px; align-items: baseline; margin-top: 6px; }
.col-stats .total { font-weight: 700; color: var(--brand); }
.col-stats .count { font-size: 12px; color: var(--muted); }
.tier-column header { display: block; }
.tier-column header .count { position: static; background: none; padding: 0; }

.need-card .card-total { font-weight: 700; margin-top: 6px; }
.need-card .card-total.muted { font-weight: 400; font-size: 12px; }
.need-card .option-count { font-size: 11px; color: var(--muted); }

.section-title { margin-top: 32px; margin-bottom: 8px; }

.need-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.need-header h1 { margin: 0 0 6px; }
.need-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.badge.tier { background: var(--tier-1); color: var(--ink); }
.badge.bought { background: var(--brand); color: var(--brand-ink); }
.badge.muted { background: var(--inbox); color: var(--muted); }
.big-total { margin-top: 8px; font-size: 18px; }
.big-total strong { color: var(--brand); }

.collapsible details > summary {
  cursor: pointer;
  padding: 8px 0;
  list-style: none;
}
.collapsible details > summary::-webkit-details-marker { display: none; }
.collapsible details > summary::before { content: "▸ "; color: var(--muted); }
.collapsible details[open] > summary::before { content: "▾ "; }

/* Options grid */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.option-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.option-card.is-best {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(47,111,79,.18);
}
.opt-image { position: relative; }
.opt-image img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #eee; }
.opt-image .no-image { aspect-ratio: 4/3; display: grid; place-items: center; color: var(--muted); background: #eee; }
.best-flag {
  position: absolute; top: 8px; left: 8px;
  background: var(--brand); color: var(--brand-ink);
  padding: 3px 8px; border-radius: 99px; font-size: 11px; font-weight: 600;
}
.opt-body { padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.opt-title { font-weight: 600; }
.opt-meta { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.opt-meta .price { font-weight: 700; }
.opt-desc { font-size: 12px; line-height: 1.4; }
.opt-edit { margin-top: 6px; }
.opt-edit summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.opt-actions { display: flex; gap: 12px; margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--border); }
.opt-actions .link.danger { color: var(--danger); }

.add-grid.two { grid-template-columns: 1fr 1fr; }
.manual-toggle { margin-top: 16px; }
.manual-toggle summary { cursor: pointer; padding: 4px 0; color: var(--muted); }

.bought-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.bought-list .need-card { opacity: 0.85; }
.upload-link { cursor: pointer; }
.inline-edit { display: inline-block; margin-right: 8px; }
.inline-edit summary { cursor: pointer; font-size: 12px; color: var(--muted); display: inline; }
.inline-edit form { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.inline-edit input { font-size: 12px; padding: 4px 6px; }
.inline-edit button { font-size: 12px; padding: 4px 10px; align-self: flex-start; }

/* ---- Floor plans v3: room overlay + extraction ---- */

.floor-plan-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 24px;
}
.fp-header { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.fp-header h2 { margin: 0; }
.fp-header .fp-actions { margin-left: auto; display: flex; gap: 12px; align-items: center; }

.plan-with-rooms {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) { .plan-with-rooms { grid-template-columns: 1fr; } }

.plan-img-wrap { position: relative; line-height: 0; }
.plan-img-wrap img { width: 100%; display: block; border-radius: 8px; }

.room-box {
  position: absolute;
  border: 2px solid rgba(47,111,79,.85);
  background: rgba(47,111,79,.10);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  transition: background .15s ease;
}
.room-box:hover { background: rgba(47,111,79,.22); }
.room-label {
  background: rgba(255,255,255,.92);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  line-height: 1.2;
  pointer-events: auto;
}
.room-label small { display: block; color: var(--muted); }

.rooms-list h3 { margin: 0 0 8px; }
.room-row {
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
}
.room-row > summary { cursor: pointer; list-style: none; }
.room-row > summary::-webkit-details-marker { display: none; }
.room-edit-form { margin-top: 8px; }
.room-edit-form .row label { font-size: 11px; }

.add-room { margin-top: 12px; }

.badge.room { background: #eaf2ec; color: var(--brand); }

.fit-check {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.fit-check.ok { background: #e8f3ec; color: #1b5e3a; }
.fit-check.warn { background: #fdecea; color: #842d22; }

/* Cap floor plan and large gallery images so they don't dominate the screen */
.plan-img-wrap img { max-height: 60vh; object-fit: contain; }
.gallery-item img { max-height: 200px; }
.bought-list .card img { max-height: 200px; }
.detail-images img.hero { max-height: 50vh; object-fit: contain; }

/* Suggestions */
.suggestions-section { margin-top: 24px; }
.suggestions-head { display: flex; align-items: baseline; gap: 12px; }
.suggestion-card { border-style: dashed; opacity: 0.95; }
.suggestion-card:hover { opacity: 1; }
.suggestion-flag {
  position: absolute; top: 8px; left: 8px;
  background: #f0b400; color: #4a3500;
  padding: 3px 8px; border-radius: 99px; font-size: 11px; font-weight: 600;
}
button.primary.small { padding: 4px 10px; font-size: 12px; }

/* ---- Budget visibility + lead time (v5) ---- */

.board-header-top { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.grand-total { font-size: 16px; }
.grand-total strong { color: var(--brand); font-size: 22px; }

.budget-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 4px; }
.budget-text { font-weight: 600; font-size: 13px; }
.budget-text.over { color: var(--danger); }
.budget-edit { margin: 0; }

.budget-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}
.budget-fill { height: 100%; background: var(--brand); transition: width .2s ease; }
.budget-fill.over { background: var(--danger); }

.best-name { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-extras { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.lead-badge {
  background: #fff4e2;
  color: #8a5a00;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.opt-lead { font-size: 12px; color: #8a5a00; margin-top: 4px; }

.opt-image-url { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.opt-image-url summary { font-size: 12px; cursor: pointer; }
.opt-image-url form { display: flex; gap: 6px; margin-top: 6px; }
.opt-image-url input { font-size: 12px; padding: 4px 6px; flex: 1; }
.opt-image-url button { font-size: 12px; padding: 4px 10px; }

.opt-meta .qty { font-size: 12px; color: var(--muted); }
.opt-meta .qty strong { color: var(--ink); }

/* ---- Tasks (v7) ---- */
.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-list.done { opacity: 0.6; }

.task-row {
  display: flex;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  align-items: flex-start;
}
.task-row.done .task-title { text-decoration: line-through; color: var(--muted); }

.task-check { flex-shrink: 0; }
.check-btn {
  background: none; border: none; font-size: 22px; cursor: pointer; padding: 0;
  line-height: 1; color: var(--brand);
}

.task-body { flex: 1; }
.task-title-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.task-title { font-weight: 600; }
.task-notes { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; }
.task-edit { margin-top: 6px; }
.task-edit summary { cursor: pointer; font-size: 12px; color: var(--muted); }

.prio-badge {
  padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600;
}
.prio-high { background: #fde2dd; color: #842d22; }
.prio-med { background: #fff4e2; color: #8a5a00; }
.prio-low { background: #e8f3ec; color: #1b5e3a; }
.due-badge { font-size: 11px; color: var(--muted); }

.done-wrap { margin-top: 24px; }
.done-wrap summary { cursor: pointer; list-style: none; }
.done-wrap summary::-webkit-details-marker { display: none; }
.inline-h2 { display: inline; margin: 0; }
