:root {
  color-scheme: light;
  --ink: #263d39;
  --muted: #71817a;
  --line: #dbe0d6;
  --paper: #fafbf6;
  --accent: #dce9b6;
  --orange: #b75a37;
  --workspace: #edf0e8;
  --field: #fff;
  --hover: #e6edda;
  --label: #566860;
  --status: #657253;
  --primary-bg: #263d39;
  --primary-ink: #fff;
  --accent-ink: #263d39;
  --focus: #719047;
  --symbol: #8a9a6b;
  --note: #eef0e5;
  --warning: #f5e9dc;
  --good: #547047;
  --error: #a33;
  --link: #315d87;
  --danger-bg: #b75a37;
  --danger-hover: #974a2e;
  --danger-ink: #fff;
  --backdrop: #18322e66;
  --shadow: #263d3920;
  --drawing-paper: #fafbf6;
  --drawing-text: #46605a;
  --drawing-wall: #8c9e86;
  --drawing-wall-line: #6c7e6e;
  --drawing-item: #e8e9dd;
  --drawing-item-line: #7b8d7a;
  --drawing-item-selected: #dce9b6;
  --drawing-structure: #bdc9b5;
  --drawing-guide: #84977b;
  --drawing-dot: #bcc5b9;
  --utility-electricity: #b77900;
  --utility-electricity-fill: #fff3ce;
  --utility-water: #2563eb;
  --utility-water-fill: #dbeafe;
  --utility-drain: #087f8c;
  --utility-drain-fill: #d5f3ee;
  --utility-ventilation: #8b5cf6;
  --utility-ventilation-fill: #ede3ff;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e1e9df;
  --muted: #a6b7ad;
  --line: #40524a;
  --paper: #1e2925;
  --accent: #405a36;
  --orange: #f0b18b;
  --workspace: #17211d;
  --field: #26362e;
  --hover: #344637;
  --label: #bfd0c3;
  --status: #b3d292;
  --primary-bg: #c4dda9;
  --primary-ink: #1b2a21;
  --accent-ink: #e1f0cc;
  --focus: #badb8d;
  --symbol: #b8cb96;
  --note: #2a382b;
  --warning: #3b2c24;
  --good: #b2d195;
  --error: #ffaba5;
  --link: #acd0ee;
  --danger-bg: #a45433;
  --danger-hover: #bf6540;
  --danger-ink: #fff8ee;
  --backdrop: #050b08bb;
  --shadow: #0006;
  --drawing-paper: #17221d;
  --drawing-text: #c3d3c5;
  --drawing-wall: #61765c;
  --drawing-wall-line: #9eb591;
  --drawing-item: #344334;
  --drawing-item-line: #a5b99b;
  --drawing-item-selected: #4a643a;
  --drawing-structure: #52674b;
  --drawing-guide: #8d9f83;
  --drawing-dot: #3b4d40;
  --utility-electricity: #f3c75e;
  --utility-electricity-fill: #493b1b;
  --utility-water: #8eb9ff;
  --utility-water-fill: #1b3554;
  --utility-drain: #70d3cd;
  --utility-drain-fill: #163d3b;
  --utility-ventilation: #c0a2ff;
  --utility-ventilation-fill: #38284e;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--workspace);
  color: var(--ink);
  font:
    14px "Segoe UI",
    sans-serif;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
button,
select {
  cursor: pointer;
}
a:not(.brand) {
  color: var(--link);
}
button {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 5px;
  padding: 9px 12px;
  min-height: 38px;
}
button:hover {
  background: var(--hover);
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
input,
select {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 9px;
  width: 100%;
  min-width: 0;
}
header {
  height: 78px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
  font:
    italic 48px Georgia,
    serif;
  margin-right: 28px;
}
.brand span {
  font:
    600 16px "Segoe UI",
    sans-serif;
  letter-spacing: 3px;
}
.brand small {
  display: block;
  font-size: 8px;
  letter-spacing: 2px;
  margin-top: 5px;
}
#projectName {
  background: transparent;
  border: 0;
  width: 300px;
  font:
    18px Georgia,
    serif;
}
#themeToggle {
  white-space: nowrap;
  flex-shrink: 0;
}
#status {
  margin-left: auto;
  font-size: 12px;
  color: var(--status);
}
nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
nav > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
nav select {
  width: 145px;
}
.active,
.primary {
  background: var(--primary-bg);
  color: var(--primary-ink);
  border-color: var(--primary-bg);
}
.active:hover,
.primary:hover {
  background: var(--primary-bg);
}
main {
  display: grid;
  grid-template-columns: 260px minmax(300px, 1fr) 266px;
  grid-template-rows: minmax(0, 1fr);
  height: calc(100dvh - 138px);
}
aside {
  padding: 20px 18px;
  overflow: auto;
  background: var(--paper);
}
.left {
  border-right: 1px solid var(--line);
}
.right {
  border-left: 1px solid var(--line);
}
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin: 6px 0 20px;
}
.section-title b {
  color: var(--ink);
  font-weight: 600;
}
.section-title button {
  margin-left: auto;
  padding: 0 8px;
}
label {
  display: block;
  font-size: 12px;
  margin: 10px 0;
  color: var(--label);
}
label input,
label select {
  margin-top: 5px;
}
label input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--focus);
}
details {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
  margin: 18px 0;
}
summary {
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
details > button {
  width: 100%;
  margin-top: 8px;
}
.row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.row > * {
  flex: 1;
}
.layout-label {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 10px;
}
.layout-list {
  display: grid;
  gap: 6px;
}
.layout-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  text-align: left;
  background: var(--field);
}
.layout-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
.layout-button[aria-pressed="true"] {
  color: var(--primary-ink);
  background: var(--primary-bg);
  border-color: var(--primary-bg);
}
.layout-main {
  flex-shrink: 0;
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 9px;
  color: var(--accent-ink);
  background: var(--accent);
}
.layout-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 10px 0 6px;
}
.layout-actions button {
  padding: 8px 6px;
  font-size: 11px;
  overflow-wrap: anywhere;
}
.layout-delete {
  grid-column: 1 / -1;
  color: var(--orange);
}
.layout-actions button:disabled {
  background: var(--paper);
  color: var(--muted);
  opacity: 0.6;
  cursor: default;
}
.layout-confirm-name {
  font:
    24px Georgia,
    serif;
  overflow-wrap: anywhere;
}
.layout-replacements {
  border: 1px solid var(--line);
  padding: 12px;
  min-width: 0;
  margin: 20px 0;
}
.layout-replacements legend {
  padding: 0 6px;
  font-size: 12px;
}
.layout-replacement {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px;
  margin: 6px 0 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}
.layout-replacement:has(input:checked) {
  background: var(--workspace);
  border-color: var(--ink);
}
.layout-replacement input {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--focus);
}
.layout-replacement span {
  min-width: 0;
  overflow-wrap: anywhere;
}
button.danger {
  background: var(--danger-bg);
  border-color: var(--danger-bg);
  color: var(--danger-ink);
}
button.danger:hover {
  background: var(--danger-hover);
}
.hint {
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}
.utility-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 10px;
  margin: 12px 0;
}
.utility-legend > span {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}
.utility-legend i {
  display: inline-block;
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--utility-color);
}
.viewpoint-panel {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 20px 0;
  padding: 16px 0;
}
.viewpoint-panel h3 {
  margin: 0 0 10px;
  font:
    18px Georgia,
    serif;
}
#viewpointStatus {
  color: var(--label);
  overflow-wrap: anywhere;
}
.viewpoint-panel .hint {
  margin: 8px 0;
}
.viewpoint-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 10px 0;
}
.viewpoint-actions button {
  min-width: 0;
  min-height: 44px;
  padding: 8px 6px;
  font-size: 11px;
  overflow-wrap: anywhere;
}
.viewpoint-actions button:disabled {
  color: var(--muted);
  background: var(--paper);
  opacity: 0.6;
  cursor: default;
}
.catalogue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  padding: 12px 10px;
  margin-bottom: 8px;
  border-radius: 5px;
  background: var(--field);
}
.catalogue-item .symbol {
  font-size: 26px;
  color: var(--symbol);
}
.catalogue-item p {
  margin: 0;
  font-size: 12px;
}
.catalogue-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}
.catalogue-item button {
  margin-left: auto;
  padding: 4px 8px;
}
.local-note {
  margin-top: 28px;
  padding: 14px;
  background: var(--note);
  font-size: 10px;
  line-height: 1.8;
}
.workspace {
  min-height: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.drawing-title {
  padding: 25px 30px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.drawing-title span {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--muted);
}
h1 {
  font:
    28px Georgia,
    serif;
  margin: 8px 0;
}
.pill {
  border: 1px solid var(--line);
  padding: 7px;
  border-radius: 4px;
  font-size: 8px !important;
}
#canvasWrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background-image: radial-gradient(
    var(--drawing-dot) 0.65px,
    transparent 0.65px
  );
  background-size: 18px 18px;
}
#canvas {
  /* Keep the SVG out of flex/grid intrinsic sizing and remove its inline baseline. */
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}
#canvas.placing-utility,
#canvas.placing-utility *,
#canvas.placing-viewpoint,
#canvas.placing-viewpoint * {
  cursor: crosshair !important;
}
#canvas [data-utility]:focus-visible,
#canvas [data-viewpoint]:focus-visible,
#canvas [data-wall]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.placement-toolbar {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--focus);
  border-radius: 5px;
  background: var(--paper);
  box-shadow: 0 3px 12px var(--shadow);
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
}
.placement-toolbar[hidden] {
  display: none;
}
.placement-toolbar span {
  min-width: 0;
  overflow-wrap: anywhere;
}
.placement-toolbar button {
  flex-shrink: 0;
  pointer-events: auto;
}
#applyUtility,
#deleteUtility {
  width: 100%;
  margin-top: 10px;
}
@media (max-width: 650px) {
  .placement-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
  }
}
.zoom {
  position: absolute;
  bottom: 16px;
  left: 18px;
  display: flex;
  align-items: center;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.zoom button {
  border: 0;
  background: transparent;
}
.zoom span {
  font-size: 11px;
  padding: 0 10px;
}
footer {
  display: flex;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  color: var(--muted);
}
.empty {
  padding: 20px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}
.warning {
  border-left: 3px solid var(--orange);
  background: var(--warning);
  margin: 8px 0;
  padding: 10px;
  font-size: 11px;
  line-height: 1.6;
}
.good {
  color: var(--good);
  font-size: 12px;
}
.item-title {
  font:
    24px Georgia,
    serif;
  margin: 8px 0;
}
.subtle {
  font-size: 10px;
  color: var(--muted);
}
#toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-bg);
  color: var(--primary-ink);
  padding: 12px 22px;
  border-radius: 6px;
  display: none;
  z-index: 10;
}
dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  width: min(540px, 94vw);
  max-height: 90dvh;
  overflow: auto;
  padding: 26px;
  color: var(--ink);
  background: var(--paper);
}
dialog::backdrop {
  background: var(--backdrop);
}
h2 {
  font:
    25px Georgia,
    serif;
}
#dialogError {
  color: var(--error);
  font-size: 12px;
}
textarea {
  color: var(--ink);
  background: var(--field);
  width: 100%;
  min-height: 100px;
  font: 13px monospace;
  border: 1px solid var(--line);
  padding: 10px;
}
#checkpoint,
#restore {
  margin: 8px 0;
  width: 100%;
}
@media (max-width: 1000px) {
  main {
    grid-template-columns: 220px minmax(260px, 1fr);
  }
  .right {
    position: fixed;
    right: 12px;
    bottom: 16px;
    max-height: 40dvh;
    width: 250px;
    box-shadow: 0 4px 24px var(--shadow);
    border: 1px solid var(--line);
    border-radius: 8px;
    z-index: 2;
  }
  header {
    padding: 10px;
  }
  .brand {
    margin: 0;
  }
  #projectName {
    width: 180px;
  }
  .drawing-title {
    padding: 15px;
  }
  .pill {
    display: none;
  }
}
@media (max-width: 650px) {
  header {
    height: auto;
    flex-wrap: wrap;
    gap: 6px;
  }
  .brand {
    font-size: 34px;
  }
  .brand span {
    font-size: 12px;
  }
  #projectName {
    width: 170px;
    font-size: 15px;
  }
  #status {
    font-size: 10px;
  }
  header button {
    font-size: 11px;
    padding: 5px 9px;
  }
  nav {
    padding: 7px;
    flex-wrap: wrap;
  }
  nav button {
    font-size: 11px;
    padding: 7px;
  }
  main {
    display: flex;
    flex-wrap: wrap;
    height: auto;
  }
  .left {
    width: 100%;
    padding: 10px;
    max-height: 200px;
    order: 2;
    display: block;
  }
  .workspace {
    width: 100%;
    height: 58dvh;
    min-height: 380px;
  }
  .right {
    position: relative;
    width: 100%;
    max-height: none;
    right: auto;
    bottom: auto;
    order: 3;
    margin: 0;
    box-shadow: none;
    border-radius: 0;
    padding: 16px;
  }
  .drawing-title h1 {
    font-size: 22px;
    margin: 3px 0;
  }
  footer {
    font-size: 9px;
    padding: 8px;
  }
  button {
    min-height: 44px;
  }
  .left .section-title {
    margin: 10px 0;
  }
  .catalogue-item {
    display: inline-flex;
    width: 48%;
    margin: 1%;
  }
  .local-note {
    margin-top: 10px;
  }
}
@media print {
  :root,
  :root[data-theme="dark"] {
    color-scheme: light;
    --ink: #263d39;
    --muted: #71817a;
    --line: #dbe0d6;
    --paper: #fafbf6;
    --drawing-paper: #fafbf6;
    --drawing-text: #46605a;
    --drawing-wall: #8c9e86;
    --drawing-wall-line: #6c7e6e;
    --drawing-item: #e8e9dd;
    --drawing-item-line: #7b8d7a;
    --drawing-item-selected: #dce9b6;
    --drawing-structure: #bdc9b5;
    --drawing-guide: #84977b;
    --drawing-dot: #bcc5b9;
    --utility-electricity: #b77900;
    --utility-electricity-fill: #fff3ce;
    --utility-water: #2563eb;
    --utility-water-fill: #dbeafe;
    --utility-drain: #087f8c;
    --utility-drain-fill: #d5f3ee;
    --utility-ventilation: #8b5cf6;
    --utility-ventilation-fill: #ede3ff;
  }
  header,
  nav,
  aside,
  footer,
  .zoom,
  .placement-toolbar {
    display: none !important;
  }
  main {
    display: block;
    height: auto;
  }
  .workspace {
    height: 85vh;
    width: 100%;
  }
  .drawing-title {
    padding: 0;
  }
  #canvasWrap {
    background: white;
  }
  .pill {
    display: block !important;
  }
  body {
    background: white;
  }
}
#propertiesToggle {
  display: none;
}
@media (max-width: 650px) {
  .workspace {
    height: 62dvh;
  }
  .right {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 48dvh;
    overflow: auto;
    z-index: 5;
    box-shadow: 0 -8px 30px var(--shadow);
    border-radius: 14px 14px 0 0;
    padding: 8px 16px 18px;
    transform: translateY(calc(100% - 62px));
    transition: transform 0.18s ease;
  }
  .right.expanded {
    transform: translateY(0);
  }
  #propertiesToggle {
    display: block;
    position: sticky;
    top: 0;
    width: 100%;
    background: var(--paper);
    z-index: 1;
    border: 0;
  }
  .right .section-title {
    margin: 14px 0;
  }
  .left {
    padding-bottom: 80px;
  }
  .right input {
    font-size: 16px;
    scroll-margin-bottom: 100px;
  }
  dialog input,
  dialog select {
    font-size: 16px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
#editorStatus {
  font-size: 10px;
  max-width: 160px;
  color: var(--status);
  overflow-wrap: anywhere;
}
@media (max-width: 650px) {
  #editorStatus {
    max-width: 140px;
  }
}

#canvasWrap {
  background-color: var(--drawing-paper);
}

/* Transient drag instructions must not resize the drawing viewport. */
.drawing-title,
footer {
  flex-shrink: 0;
}
footer {
  line-height: 16px;
}
#instruction {
  min-width: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
footer > span:last-child {
  flex-shrink: 0;
}
