:root {
  --bg: #f6f2ea; --card: #fffdf9; --ink: #2b2420; --muted: #7a6f66; --line: #e5dccf;
  --accent: #b5532a; --accent-ink: #fff; --ok: #1b7f3b;
  --room: #efe6d6; --room-hot: #e8cfae; --wall: #3b332c; --window: #7fb3d5; --door: #b5532a; --glass: #8fbfd8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1715; --card: #24201d; --ink: #ebe4da; --muted: #a39a90; --line: #3a332e;
    --accent: #e07b4f; --accent-ink: #1a1715; --ok: #5fc27f;
    --room: #2c2623; --room-hot: #4b3a2a; --wall: #d8cfc2; --window: #5f94b5; --door: #e07b4f; --glass: #6fa5c2;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
select, button, input, textarea { font: inherit; color: inherit; }
button { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }
select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }

header.site { padding: 20px 16px 8px; max-width: 760px; margin: 0 auto; }
h1 { font: 600 32px/1.1 ui-serif, Georgia, "Times New Roman", serif; margin: 0 0 6px; letter-spacing: -0.01em; }
.tag { margin: 0 0 12px; color: var(--muted); }
.tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 14px; }

main { max-width: 760px; margin: 0 auto; padding: 0 16px 40px; }
.plans { display: grid; gap: 14px; }
@media (min-width: 640px) {
  .plans { grid-template-columns: 1fr 1fr; align-items: start; }
  .plans .fine { grid-column: 1 / -1; }
}
figure { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
figcaption { font-weight: 600; margin: 0 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
figure svg { width: 100%; height: auto; display: block; }
.fine { font-size: 13px; color: var(--muted); margin: 0; }
.loading { color: var(--muted); }

/* floor plan */
.room { fill: var(--room); cursor: pointer; transition: fill 0.15s; }
.room:hover, .room.selected { fill: var(--room-hot); }
.open { fill: transparent; }
.wall { stroke: var(--wall); stroke-width: 3; fill: none; stroke-linecap: square; stroke-linejoin: miter; pointer-events: none; }
.wall.thin { stroke-width: 2; }
.window { stroke: var(--window); stroke-width: 5; fill: none; pointer-events: none; }
.glass { stroke: var(--glass); stroke-width: 3; stroke-dasharray: 6 3; fill: none; pointer-events: none; }
.door { stroke: var(--door); stroke-width: 1.5; fill: none; pointer-events: none; }
.door.front { stroke-width: 2.5; }
.gap { stroke: var(--card); stroke-width: 4; pointer-events: none; }
.label { font: 12px system-ui, sans-serif; fill: var(--ink); text-anchor: middle; pointer-events: none; }
.label.small { font-size: 9px; fill: var(--muted); }
.label.door { font-size: 9px; fill: var(--door); font-weight: 600; }
.tread { stroke: var(--wall); stroke-width: 1; opacity: 0.45; pointer-events: none; }
.flow { stroke: var(--ok); stroke-width: 2; fill: none; pointer-events: none; }
.flow-head { fill: var(--ok); pointer-events: none; }
.tread.faint { opacity: 0.2; }
.room.void { fill: var(--bg); }
.fixture { fill: none; stroke: var(--muted); stroke-width: 1; opacity: 0.7; pointer-events: none; }

/* room cards */
#rooms { margin-top: 22px; display: grid; gap: 10px; }
.floor-h { margin: 14px 0 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
details.room-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
details.room-card.flash { box-shadow: 0 0 0 3px var(--room-hot); }
summary { list-style: none; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 12px 14px; cursor: pointer; }
summary::-webkit-details-marker { display: none; }
summary .name { font-weight: 600; font-size: 17px; }
summary .meta { font-size: 13px; color: var(--muted); white-space: nowrap; }
details[open] summary { border-bottom: 1px solid var(--line); }
.body { padding: 10px 14px 14px; }
.blurb { margin: 0 0 8px; color: var(--muted); font-size: 14px; }

.m { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 8px 0; border-top: 1px solid var(--line); align-items: baseline; }
.m:first-child { border-top: 0; }
.m .label { font-size: 15px; }
.m .value { text-align: right; font-variant-numeric: tabular-nums; }
.m .value b { font-weight: 600; }
.m .value small { display: block; color: var(--muted); font-size: 12px; }
.m .value.empty { color: var(--muted); }
.m .note { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.m.saved { animation: flash 0.9s; }
@keyframes flash { from { background: color-mix(in srgb, var(--ok) 18%, transparent); } to { background: transparent; } }

/* edit mode */
.m.edit { grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: start; }
.m.edit input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; background: var(--bg); min-width: 0; }
.m.edit .label { grid-column: 1 / 3; }
.m.edit .value { text-align: left; }
.m.edit .parsed { color: var(--ok); font-size: 12px; display: block; min-height: 1.2em; margin-top: 2px; }
.m.edit .note { grid-column: 2; }
.m.edit .del { grid-column: 3; grid-row: 1 / 3; align-self: center; border: 0; background: none; color: var(--muted); font-size: 18px; padding: 4px 6px; }
.add-measure, .add-photo { margin-top: 10px; display: inline-block; font-size: 14px; }
.add-photo { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; margin-right: 8px; }
.add-photo input { display: none; }

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 12px; }
.photos:empty { display: none; }
.photo { margin: 0; position: relative; }
.photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; display: block; cursor: zoom-in; background: var(--line); }
.photo figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.photo input.caption { width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; background: var(--bg); font-size: 13px; }
.photo .del { position: absolute; top: 6px; right: 6px; border: 0; background: rgba(0, 0, 0, 0.55); color: #fff; border-radius: 50%; width: 28px; height: 28px; padding: 0; line-height: 28px; text-align: center; }
.photo.uploading img { opacity: 0.5; }

.notes { margin-top: 12px; }
.notes h4 { margin: 0 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.notes p { margin: 0; white-space: pre-wrap; font-size: 14px; }
.notes textarea { width: 100%; min-height: 72px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--bg); resize: vertical; }

footer { max-width: 760px; margin: 0 auto; padding: 0 16px 30px; color: var(--muted); font-size: 13px; }
#editbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-between; align-items: center; font-size: 14px;
}
#editbar button { background: var(--bg); color: var(--ink); border: 0; font-weight: 600; }
body.editing { padding-bottom: 80px; }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 6;
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 14px; max-width: 90vw;
}

/* lightbox */
#lightbox { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.93); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; }
#lightbox img { max-width: 100vw; max-height: 82vh; object-fit: contain; }
#lightbox .cap { padding: 10px 56px; text-align: center; font-size: 14px; margin: 0; min-height: 2.4em; }
#lightbox .nav, #lightbox .close { position: absolute; background: rgba(255, 255, 255, 0.15); color: #fff; border: 0; border-radius: 50%; width: 44px; height: 44px; font-size: 26px; line-height: 44px; padding: 0; }
#lightbox .nav { top: 50%; transform: translateY(-50%); }
#lightbox .prev { left: 8px; } #lightbox .next { right: 8px; }
#lightbox .close { top: 10px; right: 10px; width: 40px; height: 40px; line-height: 40px; }

@media print {
  header .tools, footer, #editbar, .add-measure, .add-photo, .photo .del { display: none !important; }
  details.room-card { break-inside: avoid; }
  .body { display: block !important; }
}
