:root {
  --navy: #0A1530; --navy-deep: #070F24; --navy-on: #1B2B57;
  --gold: #E9CF7A; --gold-pale: #F4E3A6; --gold-line: #B8923A; --bronze: #7A5A12;
  --page: #FAF8F3; --stone: #EFEBE2; --stone-on: #E0D9C8; --line: #D8D2C4;
  --ink: #14181F; --muted: #555B66; --card: #FFFFFF; --cream: #F6F2E6; --danger: #8A1F1F;
  --display: 'Cinzel', 'Times New Roman', serif;
  --ui: 'Jost', 'Century Gothic', sans-serif;
  --text: 'Lora', Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font-family: var(--text); font-size: 19px; line-height: 1.5; }
a { color: var(--bronze); }
a:hover { color: #5A4208; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold-line); outline-offset: 2px; }
.loading { padding: 60px 24px; font-family: var(--ui); font-size: 21px; }
h1, h2, h3 { margin: 0; }

/* Buttons */
.btn { min-height: 52px; padding: 0 20px; display: inline-flex; align-items: center; gap: 10px; background: transparent; border: 2px solid var(--gold-line); color: var(--ink); font-family: var(--ui); font-weight: 600; font-size: 19px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--stone); color: var(--ink); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: var(--cream); }
.btn.primary:hover { background: var(--navy-on); }
.btn.danger { border-color: var(--danger); color: var(--danger); margin-left: auto; }
.btn.small { min-height: 46px; padding: 0 14px; font-size: 18px; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn svg, .tab svg, .rail button svg { flex: none; }
.linkbtn { background: none; border: 0; padding: 0; min-height: 44px; color: var(--bronze); font-family: var(--ui); font-weight: 600; font-size: 19px; text-decoration: underline; cursor: pointer; }

/* Sign in */
.signin { min-height: 100vh; display: flex; flex-wrap: wrap; }
.signin-brand { flex: 1 1 360px; background: var(--navy); color: var(--gold); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; text-align: center; }
.signin-brand .the { font-family: var(--display); font-size: 26px; letter-spacing: 0.6em; margin: 18px -0.6em 0 0; color: var(--gold-pale); }
.signin-brand .house { font-family: var(--display); font-weight: 600; font-size: clamp(64px, 9vw, 112px); line-height: 1; letter-spacing: 0.02em; }
.signin-brand .book { font-family: var(--display); font-size: 40px; letter-spacing: 0.5em; margin-right: -0.5em; color: var(--gold-pale); }
.signin-brand .motto { margin-top: 26px; font-family: var(--ui); font-weight: 500; font-size: 18px; letter-spacing: 0.3em; }
.signin-form { flex: 1 1 360px; display: flex; align-items: center; justify-content: center; padding: 48px 24px; }
.signin-form form { width: 100%; max-width: 420px; }
.signin-form h1 { font-family: var(--display); font-weight: 600; font-size: 38px; margin-bottom: 22px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; font-family: var(--ui); font-weight: 600; font-size: 18px; }
.field input, .field select, .field textarea { width: 100%; min-height: 54px; padding: 10px 14px; background: var(--card); border: 2px solid #8C8778; font-family: var(--ui); font-weight: 500; font-size: 19px; }
.field textarea { min-height: 110px; resize: vertical; }
.field .hint { font-weight: 400; font-size: 17px; color: var(--muted); }
.field.half { display: inline-flex; width: calc(50% - 6px); vertical-align: bottom; }
.field.half.second { margin-left: 12px; }
.form-note { margin: 0 0 14px; font-size: 18px; color: var(--muted); }
.form-error { color: var(--danger); font-family: var(--ui); font-weight: 600; }
.form-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
dialog { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 2px solid var(--gold-line); background: var(--page); color: var(--ink); }
dialog::backdrop { background: rgba(10, 21, 48, 0.6); }
dialog .form { padding: 26px 26px 28px; }
dialog h2 { font-family: var(--display); font-weight: 600; font-size: 30px; margin-bottom: 20px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 14px 20px; background: var(--navy); color: var(--cream); font-family: var(--ui); font-weight: 600; font-size: 18px; border: 2px solid var(--gold-line); display: none; z-index: 50; }
#toast.show { display: block; }

/* App frame */
.app { min-height: 100vh; display: flex; }
.topbar { display: none; }
.rail { flex: 0 0 112px; background: var(--navy-deep); padding: 18px 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rail .logo { margin-bottom: 14px; }
.rail button { width: 104px; min-height: 76px; padding: 8px 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: transparent; border: 0; color: #C9CFE0; font-family: var(--ui); font-weight: 600; font-size: 16px; line-height: 1.15; cursor: pointer; }
.rail button:hover, .rail button.on { background: var(--navy-on); color: var(--cream); }
.rail .spacer { flex: 1; }
.panel { flex: 0 0 290px; background: var(--stone); border-right: 1px solid var(--line); padding: 22px 0; }
.panel-head { padding: 0 22px 16px; border-bottom: 2px solid var(--gold-line); }
.panel-head .label { font-family: var(--ui); font-weight: 600; font-size: 16px; letter-spacing: 0.16em; color: var(--bronze); }
.panel-head .name { margin-top: 4px; font-family: var(--display); font-weight: 600; font-size: 24px; line-height: 1.2; }
.floor-btn { width: 100%; min-height: 50px; padding: 0 22px; display: flex; align-items: center; justify-content: space-between; background: transparent; border: 0; border-bottom: 1px solid var(--line); font-family: var(--ui); font-weight: 600; font-size: 20px; text-align: left; cursor: pointer; }
.floor-btn span { color: var(--bronze); }
.room-link { display: flex; align-items: center; min-height: 48px; padding: 0 22px 0 40px; color: var(--muted); text-decoration: none; }
.room-link:hover { background: var(--stone-on); color: var(--ink); }
.room-link.on { background: var(--stone-on); color: var(--ink); font-weight: 700; }
.room-link.whole { color: var(--bronze); font-family: var(--ui); font-weight: 600; }
.panel-actions { display: flex; flex-direction: column; gap: 10px; padding: 20px 22px 0; }
main { flex: 1 1 0; min-width: 0; }

/* Room */
.banner { position: relative; height: 210px; overflow: hidden; background: var(--navy); color: var(--cream); }
.banner img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.banner .shade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10,21,48,0.94) 0%, rgba(10,21,48,0.78) 45%, rgba(10,21,48,0.15) 100%); }
.banner .words { position: absolute; left: 32px; right: 32px; bottom: 22px; }
.banner h1 { font-family: var(--display); font-weight: 600; font-size: clamp(44px, 6vw, 72px); line-height: 1; letter-spacing: 0.04em; text-transform: uppercase; }
.banner .meta { margin-top: 10px; font-family: var(--ui); font-weight: 500; font-size: 20px; color: var(--gold-pale); }
.banner .edit { position: absolute; right: 20px; top: 18px; background: var(--navy); color: var(--cream); }
.tabs { display: flex; flex-wrap: wrap; gap: 0 6px; padding: 0 26px; border-bottom: 1px solid var(--line); background: var(--stone); }
.tab { min-height: 62px; padding: 0 14px; display: flex; align-items: center; gap: 10px; border-bottom: 4px solid transparent; color: var(--muted); font-family: var(--ui); font-weight: 600; font-size: 19px; text-decoration: none; }
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); border-bottom-color: var(--gold-line); }
.content { padding: 30px 32px 56px; }
.sec-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 22px; }
.sec-head h2 { font-family: var(--display); font-weight: 600; font-size: 36px; letter-spacing: 0.06em; color: var(--bronze); line-height: 1.1; text-transform: uppercase; }
.sec-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 12px; }
.sub { margin: 26px 0 8px; font-family: var(--ui); font-weight: 600; font-size: 21px; letter-spacing: 0.14em; color: var(--bronze); text-transform: uppercase; }
.empty { padding: 26px 0; color: var(--muted); font-size: 20px; }
.stats { display: flex; flex-wrap: wrap; gap: 24px; margin-bottom: 40px; }
.stat { flex: 1 1 150px; border-top: 3px solid var(--gold-line); padding-top: 14px; }
.stat b { display: block; font-family: var(--display); font-weight: 600; font-size: 50px; line-height: 1.05; }
.stat span { display: block; margin-top: 6px; font-family: var(--ui); font-weight: 500; font-size: 20px; color: var(--bronze); }
.cols { display: flex; flex-wrap: wrap; gap: 32px 48px; }
.cols > div { flex: 1 1 280px; }
.line { padding: 14px 0; border-top: 1px solid var(--line); font-size: 20px; }
.cards { display: flex; flex-wrap: wrap; gap: 22px; }
.card { flex: 1 1 240px; max-width: 340px; background: var(--card); border: 1px solid var(--line); display: flex; flex-direction: column; }
.card img, .card .noimg { display: block; width: 100%; height: 200px; object-fit: cover; background: var(--stone); }
.card .noimg { display: flex; align-items: center; justify-content: center; color: var(--muted); font-family: var(--ui); }
.card .body { padding: 18px 20px 20px; display: flex; flex-direction: column; flex: 1; }
.card .role { font-family: var(--ui); font-weight: 600; font-size: 16px; letter-spacing: 0.14em; color: var(--bronze); text-transform: uppercase; }
.card .name { margin-top: 6px; font-family: var(--display); font-weight: 600; font-size: 23px; line-height: 1.2; }
.card .spec { margin-top: 8px; font-size: 18px; }
.card .src { margin-top: 2px; font-size: 18px; color: var(--muted); }
.card .foot { margin-top: auto; padding-top: 16px; display: flex; flex-wrap: wrap; gap: 10px; }
.segs { display: flex; gap: 5px; margin-top: 16px; }
.segs i { width: 34px; height: 7px; background: #DDD6C6; }
.segs i.on { background: var(--gold-line); }
.status { margin-top: 8px; font-family: var(--ui); font-weight: 600; font-size: 19px; }
.row { display: flex; flex-wrap: wrap; gap: 10px 26px; align-items: center; padding: 16px 0; border-top: 1px solid var(--line); }
.row .what { flex: 3 1 300px; min-width: 0; }
.row .what b { display: block; font-family: var(--display); font-weight: 600; font-size: 23px; line-height: 1.2; }
.row .what span { display: block; margin-top: 2px; font-size: 18px; color: var(--muted); }
.row .state { flex: 1 1 210px; }
.row .state .segs { margin-top: 0; }
.row .do { flex: 0 0 auto; display: flex; gap: 10px; }
.figs { display: flex; flex-wrap: wrap; gap: 22px; align-items: flex-start; }
.figs figure { flex: 1 1 320px; max-width: 440px; margin: 0; }
.figs img { display: block; width: 100%; height: 300px; object-fit: contain; background: #fff; border: 1px solid var(--line); }
.figs figcaption { margin-top: 10px; font-size: 18px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.house-card { flex: 1 1 320px; max-width: 520px; background: var(--card); border: 1px solid var(--line); padding: 26px; }
.house-card h3 { font-family: var(--display); font-weight: 600; font-size: 30px; line-height: 1.2; }
.house-card p { margin: 6px 0 0; color: var(--muted); }
.house-card .foot { margin-top: 20px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.page-title { padding: 34px 32px 26px; background: var(--navy); color: var(--cream); border-bottom: 2px solid var(--gold-line); }
.page-title .label { font-family: var(--ui); font-weight: 600; font-size: 18px; letter-spacing: 0.16em; color: var(--gold); text-transform: uppercase; }
.page-title h1 { margin-top: 6px; font-family: var(--display); font-weight: 600; font-size: clamp(44px, 6vw, 72px); line-height: 1; letter-spacing: 0.04em; text-transform: uppercase; }
.floor-list { max-width: 640px; margin-bottom: 28px; border-bottom: 1px solid var(--line); }
.floor-list details { border-top: 1px solid var(--line); }
.floor-list summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; cursor: pointer; list-style: none; font-family: var(--display); font-weight: 600; font-size: 24px; }
.floor-list summary::-webkit-details-marker { display: none; }
.floor-list summary small { font-family: var(--ui); font-weight: 600; font-size: 18px; color: var(--bronze); }
.floor-list summary small::after { content: '+'; display: inline-block; width: 28px; text-align: right; font-size: 26px; }
.floor-list details[open] summary small::after { content: '\2212'; }
.floor-list a { display: flex; align-items: center; min-height: 54px; padding-left: 18px; border-top: 1px solid var(--line); color: var(--ink); font-size: 20px; text-decoration: none; }
.floor-list a:hover, .floor-list summary:hover { background: var(--stone); }
.floor-list a.whole { color: var(--bronze); font-family: var(--ui); font-weight: 600; }
.row .thumb { flex: 0 0 96px; }
.row .thumb img { display: block; width: 96px; height: 96px; object-fit: cover; border: 1px solid var(--line); }
.photo-edit { margin: 0 0 18px; padding: 0; border: 0; }
.photo-edit legend { padding: 0; margin-bottom: 8px; font-family: var(--ui); font-weight: 600; font-size: 18px; }
.photo-line { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; padding: 10px 0; border-top: 1px solid var(--line); }
.photo-line img { width: 96px; height: 96px; object-fit: cover; background: var(--stone); border: 1px solid var(--line); }
.photo-line label { display: inline-flex; align-items: center; gap: 10px; min-height: 46px; font-family: var(--ui); font-weight: 600; font-size: 18px; cursor: pointer; }
.photo-line input { width: 26px; height: 26px; accent-color: var(--navy); }

/* Large viewer for plans, drawings and photos */
#viewer { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: var(--navy-deep); color: var(--cream); }
#viewer[open] { display: flex; flex-direction: column; }
.viewer-bar { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 16px; background: var(--navy); border-bottom: 2px solid var(--gold-line); }
.viewer-title { flex: 1 1 200px; min-width: 0; font-family: var(--display); font-weight: 600; font-size: 24px; color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-tools, .viewer-sheets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.viewer-sheets[hidden], .viewer-note[hidden], .viewer-stage canvas[hidden] { display: none; }
.viewer-tools button { min-height: 52px; padding: 0 14px; display: inline-flex; align-items: center; gap: 8px; background: transparent; border: 2px solid var(--gold-line); color: var(--cream); font-family: var(--ui); font-weight: 600; font-size: 18px; cursor: pointer; }
.viewer-tools button:hover { background: var(--navy-on); }
.viewer-tools button[disabled] { opacity: 0.45; cursor: default; }
.viewer-count { padding: 0 6px; font-family: var(--ui); font-weight: 600; font-size: 18px; }
.viewer-stage { position: relative; flex: 1 1 0; min-height: 0; overflow: hidden; touch-action: none; user-select: none; cursor: grab; }
.viewer-stage.moving { cursor: grabbing; }
.viewer-stage canvas, .viewer-stage img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; }
.viewer-note { position: absolute; left: 16px; right: 16px; top: 40%; margin: 0; text-align: center; font-family: var(--ui); font-weight: 500; font-size: 21px; }
.zoomable { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.figs .noimg { display: flex; align-items: center; justify-content: center; height: 300px; padding: 16px; background: var(--stone); border: 1px solid var(--line); color: var(--muted); font-family: var(--ui); font-size: 19px; text-align: center; }
@media (max-width: 900px) {
  .viewer-title { flex-basis: 100%; font-size: 20px; }
  .viewer-tools button { width: 54px; padding: 0; justify-content: center; }
  .viewer-tools button span { display: none; }
}

/* Measuring on a plan */
.viewer-measure { display: flex; flex-wrap: wrap; gap: 8px; }
.viewer-measure[hidden], .viewer-panel[hidden], .vp-error[hidden] { display: none; }
.viewer-panel { flex: none; max-height: 34vh; overflow: auto; padding: 12px 16px; background: var(--page); color: var(--ink); border-bottom: 2px solid var(--gold-line); font-family: var(--ui); font-size: 19px; }
.viewer-panel p { margin: 0 0 8px; }
.viewer-panel form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; }
.viewer-panel form p { flex-basis: 100%; }
.viewer-panel label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 18px; }
.viewer-panel input, .viewer-panel select { min-height: 50px; width: 190px; max-width: 100%; padding: 6px 12px; background: var(--card); border: 2px solid #8C8778; font: inherit; font-weight: 500; }
.viewer-panel input[type=number] { width: 120px; }
.viewer-panel p.vp-how { padding: 8px 14px; border-left: 5px solid var(--gold-line); background: var(--cream); font-weight: 600; font-size: 20px; }
.viewer-marks .vm-dot { r: 8px; }
.vp-acts { display: flex; flex-wrap: wrap; gap: 10px; }
.viewer-panel button { min-height: 50px; padding: 0 16px; background: transparent; border: 2px solid var(--gold-line); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.viewer-panel button.main { background: var(--navy); border-color: var(--navy); color: var(--cream); }
.viewer-panel button[disabled] { opacity: 0.45; cursor: default; }
.vp-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 8px 0; border-top: 1px solid var(--line); }
.vp-error { flex-basis: 100%; margin: 8px 0 0; color: var(--danger); font-weight: 600; }
/* The panel lies over the top of the drawing, so the drawing does not shift while measuring. */
.viewer-stage .viewer-panel { position: absolute; left: 0; right: 0; top: 0; z-index: 3; max-height: 45%; cursor: auto; user-select: text; box-shadow: 0 6px 18px rgba(7, 15, 36, 0.35); }
.viewer-stage.marking { cursor: crosshair; }
.viewer-marks { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.vm-area { fill: rgba(184, 146, 58, 0.3); stroke: #7A5A12; stroke-width: 2.5; }
.vm-scale { fill: none; stroke: #8A1F1F; stroke-width: 3; stroke-dasharray: 9 6; }
.vm-draft { fill: rgba(10, 21, 48, 0.16); stroke: #0A1530; stroke-width: 2.5; }
.vm-draft.open { fill: none; }
.vm-dot { fill: #0A1530; stroke: #FFFFFF; stroke-width: 2; }
.vm-label { font-family: var(--ui); font-weight: 600; font-size: 18px; fill: #14181F; stroke: #FFFFFF; stroke-width: 4px; paint-order: stroke; }

/* Phone */
@media (max-width: 900px) {
  .app { display: block; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--navy); border-bottom: 2px solid var(--gold-line); }
  .topbar .brand { display: flex; align-items: center; gap: 12px; font-family: var(--display); font-weight: 600; font-size: 18px; letter-spacing: 0.1em; color: var(--gold); text-decoration: none; }
  .topbar button { width: 58px; height: 58px; display: flex; align-items: center; justify-content: center; background: transparent; border: 2px solid var(--gold-line); cursor: pointer; }
  .rail, .panel { display: none; }
  .app.menu-open .rail, .app.menu-open .panel { display: block; }
  .app.menu-open main { display: none; }
  .rail { background: var(--stone); padding: 0; }
  .rail .logo, .rail .spacer { display: none; }
  .rail button { width: 100%; min-height: 64px; padding: 0 20px; flex-direction: row; justify-content: flex-start; gap: 16px; color: var(--ink); font-size: 21px; border-bottom: 1px solid var(--line); }
  .rail button:hover, .rail button.on { background: var(--stone-on); color: var(--ink); }
  .rail button svg { stroke: var(--bronze); }
  .panel { border-right: 0; min-height: 60vh; }
  .banner .words { left: 18px; right: 18px; bottom: 16px; }
  .banner .meta { font-size: 18px; }
  .tabs { padding: 0 6px; gap: 0 2px; }
  .content { padding: 24px 18px 48px; }
  .page-title { padding: 24px 18px 20px; }
  .sec-head h2 { font-size: 30px; }
  .btn.danger { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto; } }
