/* Roomwright: drafting paper and blue pencil by day, a cyanotype by night.
   Type is the drawing office's: engineering lettering for labels (DIN on a Mac,
   Bahnschrift on Windows), a bookish serif for names. */

:root {
  color-scheme: light;
  --paper: #f1ede2;
  --sheet: #f8f5ec;
  --card: #fffdf7;
  --ink: #1d232b;
  --ink-2: #545c66;
  --line: #cfc7b4;
  --line-2: #e3dccb;
  --blue: #2447b3;
  --blue-soft: #dfe5f7;
  --blue-ink: #ffffff;
  --red: #b3341f;
  --red-soft: #f8ded8;
  --amber: #8a5a00;
  --amber-soft: #f6e7c4;
  --green: #2f6b45;
  --grid-minor: #e9e3d3;
  --grid-major: #dbd3bf;
  --wall: #1d232b;
  --piece: #fffdf7;
  --piece-line: #3a424d;
  --walk: rgba(36, 71, 179, 0.2);
  --f-living: #efe2c8; --f-bedroom: #eadfd2; --f-kitchen: #e2e4da; --f-bath: #d9e6e7; --f-office: #e8dec9; --f-hall: #e7e0d1;
  --label: "DIN Alternate", "Bahnschrift", "Roboto Condensed", "Avenir Next Condensed", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --body: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0b1b2e;
  --sheet: #0f243d;
  --card: #132c49;
  --ink: #e4f0ff;
  --ink-2: #a3c0de;
  --line: #2d5278;
  --line-2: #1f4064;
  --blue: #8ecbff;
  --blue-soft: #1d4670;
  --blue-ink: #06182b;
  --red: #ff9d8a;
  --red-soft: #53282c;
  --amber: #ffd27a;
  --amber-soft: #463a1d;
  --green: #8fe0b0;
  --grid-minor: #15304f;
  --grid-major: #1d3f64;
  --wall: #cfe6ff;
  --piece: #17375a;
  --piece-line: #b4d8fb;
  --walk: rgba(142, 203, 255, 0.2);
  --f-living: #143253; --f-bedroom: #163556; --f-kitchen: #122f4e; --f-bath: #123a5a; --f-office: #153252; --f-hall: #112b48;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 324px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head head head" "rail stage drawer" "block block block";
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.45 var(--body);
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 3px;
  padding: 7px 12px;
  cursor: pointer;
  min-height: 34px;
}
button:hover { border-color: var(--ink-2); }
button:disabled { opacity: 0.42; cursor: default; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); font-weight: 600; }
.primary:hover { filter: brightness(1.08); border-color: var(--blue); }
.quiet { background: transparent; color: var(--red); }
.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--blue); text-decoration: underline; }
.chip { font-family: var(--label); letter-spacing: 0.03em; min-height: 30px; padding: 4px 10px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.icon { display: inline-flex; flex: none; }
.icon-button { display: inline-grid; place-items: center; width: 34px; padding: 0; }

/* masthead: also the drag area in Entry's desktop window */
.masthead {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1.5px solid var(--ink);
  background: var(--paper);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand .icon { color: var(--blue); }
.wordmark { font: italic 600 21px/1 var(--serif); letter-spacing: -0.01em; }
.plan-switch { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 240px; border-style: dashed; background: transparent; }
.plan-switch #plan-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; align-self: stretch; }
.group { display: flex; gap: 6px; align-items: center; }
.segmented { display: flex; border: 1px solid var(--ink); border-radius: 3px; overflow: hidden; flex: none; }
.segmented button { border: 0; border-radius: 0; background: transparent; font-family: var(--label); text-transform: uppercase; letter-spacing: 0.09em; font-size: 12px; padding: 4px 14px; min-height: 32px; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.account { display: flex; align-items: center; gap: 6px; max-width: 170px; }
.account span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account.signed { border-color: var(--green); }

/* In Entry for Mac and Windows there's no title bar: the masthead is it. */
:root[data-host] .masthead { app-region: drag; -webkit-app-region: drag; min-height: max(52px, env(titlebar-area-height, 36px)); }
:root[data-host] .masthead button { app-region: no-drag; -webkit-app-region: no-drag; }
:root[data-host="darwin"] .masthead { padding-left: max(84px, env(titlebar-area-x, 0px)); }
:root[data-host="win32"] .masthead { padding-right: calc(100vw - env(titlebar-area-width, calc(100vw - 140px)) + 8px); }

.rail { grid-area: rail; display: flex; flex-direction: column; gap: 4px; padding: 8px 6px; border-right: 1px solid var(--line); overflow-y: auto; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px; border-color: transparent; background: transparent; font: 10.5px/1.1 var(--label); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
.tool[aria-pressed="true"] { background: var(--blue-soft); border-color: var(--blue); color: var(--ink); }

.stage { grid-area: stage; position: relative; overflow: hidden; background: var(--sheet); min-width: 0; min-height: 0; }
.sheet, .model { position: absolute; inset: 0; width: 100%; height: 100%; }
.sheet { touch-action: none; user-select: none; -webkit-user-select: none; }
.sheet:focus-visible { outline-offset: -3px; }
.sheet[data-tool="room"], .sheet[data-tool="door"], .sheet[data-tool="window"], .sheet[data-tool="gap"], .sheet[data-tool="calibrate"] { cursor: crosshair; }
.sheet[data-tool="underlay"] { cursor: move; }
select.chip { min-height: 34px; max-width: 160px; background: var(--card); border: 1px solid var(--line); border-radius: 3px; }
.walk-pad { position: absolute; left: 50%; bottom: 14px; translate: -50% 0; display: flex; gap: 8px; }
.walk-pad button { width: 52px; height: 52px; background: color-mix(in srgb, var(--card) 88%, transparent); touch-action: none; user-select: none; -webkit-user-select: none; }
.model-note { position: absolute; inset: 0; display: grid; place-content: center; margin: 0; background: var(--sheet); font: italic 600 17px/1.4 var(--serif); z-index: 1; }
.model canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.stage-tools { position: absolute; right: 10px; top: 10px; left: 10px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; pointer-events: none; }
.stage-tools > * { pointer-events: auto; }
.selection-bar { position: absolute; left: 50%; bottom: 12px; translate: -50% 0; display: flex; gap: 6px; padding: 6px; background: var(--card); border: 1px solid var(--ink); border-radius: 4px; box-shadow: 3px 3px 0 var(--line); max-width: calc(100% - 20px); }
.selection-bar button { white-space: nowrap; }
.hint { position: absolute; left: 10px; top: 10px; margin: 0; max-width: calc(100% - 150px); padding: 7px 11px; background: var(--ink); color: var(--paper); border-radius: 3px; font-size: 13px; }
.banner { position: absolute; left: 10px; right: 10px; top: 52px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; background: var(--amber-soft); border: 1px solid var(--amber); border-radius: 3px; font-size: 13px; }
.banner span { flex: 1 1 200px; }

/* the drawing */
.grid line { stroke-width: 1; vector-effect: non-scaling-stroke; }
.grid .minor { stroke: var(--grid-minor); }
.grid .major { stroke: var(--grid-major); }
.floor { fill: var(--f-living); stroke: none; }
.floor.k-bedroom { fill: var(--f-bedroom); }
.floor.k-kitchen { fill: var(--f-kitchen); }
.floor.k-bath { fill: var(--f-bath); }
.floor.k-office { fill: var(--f-office); }
.floor.k-hall { fill: var(--f-hall); }
.floor.see-through { fill-opacity: 0.2; }
.floor.selected { stroke: var(--blue); stroke-width: 3; vector-effect: non-scaling-stroke; }
.underlay { pointer-events: none; }
:root[data-theme="dark"] .underlay { filter: invert(1) hue-rotate(180deg); }
.walkway { fill: var(--walk); pointer-events: none; }
.wall { fill: var(--wall); }
.opening-hit { fill: transparent; }
.opening line, .opening polyline { fill: none; stroke: var(--wall); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.opening .leaf { stroke-width: 2.5; }
.opening .swing { stroke-dasharray: 3 3; stroke: var(--ink-2); }
.opening .passage { stroke-dasharray: 5 5; stroke: var(--ink-2); }
.opening.selected .opening-hit { fill: var(--blue-soft); }
.opening.selected line, .opening.selected polyline { stroke: var(--blue); }
.part { fill: var(--piece); stroke: var(--piece-line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.part.m-fabric { fill: color-mix(in srgb, var(--piece) 82%, #5f7f78); }
.part.m-accent { fill: color-mix(in srgb, var(--piece) 74%, #c9704c); }
.part.m-wood, .part.m-darkwood { fill: color-mix(in srgb, var(--piece) 80%, #a97a42); }
.part.m-linen { fill: color-mix(in srgb, var(--piece) 90%, #a99362); }
.part.m-glass { fill: color-mix(in srgb, var(--piece) 65%, #6fb4cc); }
.part.m-green { fill: color-mix(in srgb, var(--piece) 62%, #4f7f45); }
.part.m-metal, .part.m-stone { fill: color-mix(in srgb, var(--piece) 84%, #77808a); }
.part.m-dark { fill: color-mix(in srgb, var(--piece) 45%, #39414d); }
.part.m-clay { fill: color-mix(in srgb, var(--piece) 65%, #a8603f); }
.piece .outline { fill: transparent; stroke: transparent; stroke-width: 2; vector-effect: non-scaling-stroke; }
.piece.flat .part { stroke-opacity: 0.35; fill-opacity: 0.8; }
.piece.warn .outline { stroke: var(--amber); stroke-dasharray: 5 3; }
.piece.bad .outline { stroke: var(--red); fill: color-mix(in srgb, var(--red) 18%, transparent); }
.piece.selected .outline { stroke: var(--blue); stroke-width: 2.5; stroke-dasharray: none; }
.piece { cursor: grab; }
.zone { pointer-events: none; stroke-width: 1; vector-effect: non-scaling-stroke; stroke-dasharray: 4 3; }
.zone.clear { fill: color-mix(in srgb, var(--green) 12%, transparent); stroke: var(--green); }
.zone.blocked { fill: color-mix(in srgb, var(--red) 14%, transparent); stroke: var(--red); }
.notes { pointer-events: none; }
.room-name { font-family: var(--label); letter-spacing: 0.12em; fill: var(--ink); }
.room-area { font-family: var(--serif); font-style: italic; fill: var(--ink-2); }
.room-name, .room-area, .dim-text { paint-order: stroke; stroke: var(--sheet); stroke-width: 0.25em; stroke-linejoin: round; }
.dim line { stroke: var(--blue); stroke-width: 1; vector-effect: non-scaling-stroke; }
.dim-text { font-family: var(--label); fill: var(--blue); }
.grip { fill: var(--blue); }
.marks { pointer-events: none; }
.guide { stroke: var(--red); stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.draft { fill: var(--blue-soft); fill-opacity: 0.6; stroke: var(--blue); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.mark { fill: var(--red); stroke: var(--red); stroke-width: 2; vector-effect: non-scaling-stroke; }

/* side panel */
.drawer { grid-area: drawer; display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--paper); }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tabs [role="tab"] { flex: 1; border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; font: 12px/1 var(--label); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-2); min-height: 42px; padding: 0 6px; }
.tabs [role="tab"][aria-selected="true"] { border-bottom-color: var(--blue); color: var(--ink); }
.count:not(:empty) { display: inline-block; min-width: 18px; padding: 2px 4px; margin-left: 3px; border-radius: 9px; background: var(--amber-soft); color: var(--amber); }
.count[data-level="bad"] { background: var(--red-soft); color: var(--red); }
.sheet-toggle { display: none; }
.inspector { flex: none; max-height: 45%; overflow: auto; padding: 12px; border-bottom: 1.5px solid var(--ink); background: var(--card); }
.inspector h2 { margin: 0 0 8px; font: italic 600 17px/1.25 var(--serif); }
.fields { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.field { display: flex; align-items: center; gap: 6px; }
.field > span { font: 11px/1.2 var(--label); text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-2); }
.field input[type="number"] { width: 68px; }
.field em { font-style: normal; font-size: 12px; color: var(--ink-2); }
.field.wide { width: 100%; justify-content: space-between; }
.field.wide input, .field.wide select { flex: 1; min-width: 0; max-width: 200px; }
input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 3px; padding: 6px 8px; min-height: 32px; }
textarea { width: 100%; resize: vertical; }
.note { margin: 8px 0; font-size: 12.5px; color: var(--ink-2); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.panel { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }
#piece-search { width: 100%; }
.shelves { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0; }
.pieces { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pieces .empty { grid-column: 1 / -1; color: var(--ink-2); }
.piece-card { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 6px; text-align: center; }
.thumb { width: 100%; height: 64px; pointer-events: none; }
.piece-card .name { font-size: 12.5px; line-height: 1.25; }
.piece-card .size { font: 11px/1 var(--label); color: var(--ink-2); letter-spacing: 0.04em; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.check input { min-height: 0; width: 16px; height: 16px; accent-color: var(--blue); }
.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.issue { width: 100%; display: flex; gap: 8px; text-align: left; align-items: flex-start; border-radius: 3px; }
.issue.bad { background: var(--red-soft); border-color: var(--red); }
.issue.warn { background: var(--amber-soft); border-color: var(--amber); }
.issue.bad .icon { color: var(--red); }
.issue.warn .icon { color: var(--amber); }
.all-clear { display: flex; gap: 8px; color: var(--green); }
.card { border: 1px solid var(--line); background: var(--card); padding: 12px; border-radius: 3px; margin-bottom: 12px; display: grid; gap: 8px; }
.card h3 { margin: 0; font: italic 600 16px/1.2 var(--serif); }
.card .pieces { grid-template-columns: minmax(0, 160px); }
.proposal { border-top: 1px dashed var(--line); padding-top: 8px; }
.proposal p { margin: 4px 0; }
.error { color: var(--red); background: var(--red-soft); padding: 8px 10px; border-radius: 3px; }

/* the title block, as on a drawing */
.titleblock { grid-area: block; display: flex; border-top: 1.5px solid var(--ink); background: var(--card); min-width: 0; padding-bottom: env(safe-area-inset-bottom); }
.titleblock .cell { display: flex; flex-direction: column; justify-content: center; padding: 5px 16px 6px; border-right: 1px solid var(--ink); min-width: 0; }
.titleblock .cell:last-child { border-right: 0; }
.titleblock .grow { flex: 1; }
.k { font: 10px/1.2 var(--label); text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-2); }
.v { font: 600 15px/1.3 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tb-checks[data-level="bad"] { color: var(--red); }
#tb-checks[data-level="warn"] { color: var(--amber); }
#tb-checks[data-level="ok"] { color: var(--green); }
#tb-save { font: 13px/1.4 var(--body); }
#tb-save[data-state="offline"], #tb-save[data-state="error"], #tb-save[data-state="conflict"] { color: var(--amber); }

dialog { border: 1.5px solid var(--ink); border-radius: 4px; background: var(--paper); color: var(--ink); padding: 16px; width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.18); }
dialog::backdrop { background: rgba(10, 18, 30, 0.45); }
dialog.side { margin-right: 12px; margin-top: 64px; width: min(340px, calc(100vw - 24px)); }
dialog.side::backdrop { background: transparent; }
dialog h2 { margin: 0 0 10px; font: italic 600 20px/1.2 var(--serif); }
dialog h3 { margin: 16px 0 8px; font: 12px/1 var(--label); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-2); }
dialog form { display: grid; gap: 10px; }
#plans-dialog { width: min(620px, calc(100vw - 24px)); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.plans-body { margin-top: 12px; }
.plan-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.plan-list li { display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 3px; }
.plan-list li.open { border-color: var(--blue); box-shadow: inset 3px 0 0 var(--blue); }
.mini { width: 76px; height: 60px; }
.mini .floor { stroke: var(--wall); stroke-width: 14; }
.mini-piece { fill: var(--ink-2); opacity: 0.45; }
.meta { display: flex; flex-direction: column; min-width: 0; }
.meta strong { font-family: var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta span { font-size: 12px; color: var(--ink-2); }
.actions { display: flex; gap: 5px; }

.toast { position: fixed; left: 50%; top: 66px; translate: -50% 0; z-index: 20; max-width: min(460px, calc(100vw - 24px)); padding: 10px 14px; background: var(--ink); color: var(--paper); border-radius: 3px; font-size: 13.5px; }
.toast.bad { background: var(--red); color: var(--paper); }
.ghost { position: fixed; left: 0; top: 0; z-index: 30; pointer-events: none; padding: 5px 9px; background: var(--blue); color: var(--blue-ink); border-radius: 3px; font-size: 12.5px; }

@media (max-width: 1060px) {
  body { grid-template-columns: 64px minmax(0, 1fr) 272px; }
  .wordmark, .wide-only { display: none !important; }
}

@media (max-width: 760px) {
  body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto auto; grid-template-areas: "head" "rail" "stage" "drawer" "block"; }
  .masthead { flex-wrap: wrap; gap: 6px 8px; padding: 6px 8px; }
  .plan-switch { flex: 1; max-width: none; }
  /* The second row: undo and redo on the left, the rest on the right. */
  .spacer { flex: 0 0 100%; height: 0; }
  #top-actions { margin-left: auto; }
  .account span:last-child { display: none; }
  .account { width: 34px; padding: 0; justify-content: center; }
  .segmented button { padding: 4px 10px; }
  .rail { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); padding: 3px 4px; overflow-x: auto; }
  .tool { flex: 1 1 0; min-width: 0; padding: 4px 0; font-size: 9px; letter-spacing: 0.02em; }
  .drawer { border-left: 0; border-top: 1.5px solid var(--ink); max-height: 46dvh; }
  .drawer:not(.open) .panel, .drawer:not(.open) .inspector { display: none; }
  .drawer.open { height: 46dvh; }
  .drawer.open .inspector { max-height: 40%; }
  .sheet-toggle { display: block; border: 0; background: transparent; border-radius: 0; width: 44px; }
  .drawer.open .sheet-toggle { transform: scaleY(-1); }
  .pieces { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .titleblock .cell { padding: 4px 8px; }
  .titleblock .cell:first-child { display: none; }
  .k { font-size: 9px; letter-spacing: 0.1em; }
  .v { font-size: 13px; }
  #tb-save { font-size: 11px; white-space: normal; line-height: 1.2; }
  .plan-list li { grid-template-columns: 56px minmax(0, 1fr); }
  .plan-list .actions { grid-column: 1 / -1; justify-content: flex-end; }
  .mini { width: 56px; height: 46px; }
  .toast { top: 112px; }
}

@media (max-width: 760px) and (pointer: coarse) {
  .fine-only { display: none !important; }
  .stage-tools .chip { padding: 4px 8px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
