:root {
  --bg: #f5f5f2;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6b66;
  --line: #deded8;
  --accent: #1f5fd1;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --ok: #1e7a3c;
  --warn-bg: #fff4d6;
  --radius: 6px;

  /* Room types. Same hue for the SVG fill and the sidebar swatch. */
  --t-bathroom: #2a9dd8;
  --t-kitchen: #e8912d;
  --t-technical: #8a5cc8;
  --t-stairwell: #d0457a;
  --t-corridor: #9a9a3a;
  --t-residential: #3aa35b;
  --t-commercial: #c9503a;
  --t-other: #6f7f8f;
  --t-unknown: #a0a0a0;
  --t-none: #222222;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
code, kbd { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; background: #fafafa; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pre { white-space: pre-wrap; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ chrome */

.topbar {
  display: flex; align-items: center; gap: 24px;
  height: 52px; padding: 0 20px;
  background: var(--ink); color: #fff;
}
.topbar a { color: #fff; }
.brand { font-weight: 600; }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { opacity: .7; }
.topbar nav a.active, .topbar nav a:hover { opacity: 1; text-decoration: none; }
.who { display: flex; align-items: center; gap: 12px; }
.who form { margin: 0; }
.pill { font-size: 11px; background: rgba(255,255,255,.18); padding: 1px 6px; border-radius: 10px; }

.page { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }

.flash { background: #e4f3e8; border: 1px solid #b8dcc2; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.flash.error { background: #fbe7e5; border-color: #efbdb8; }
.flash ul { margin: 0; padding-left: 18px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; margin: 0 auto 20px; }
.card.narrow { max-width: 380px; margin-top: 60px; }
.card.medium { max-width: 640px; }
.card.empty { text-align: center; }

.callout { background: #eef3fc; border: 1px solid #cfdcf3; border-radius: var(--radius); padding: 10px 12px; margin: 12px 0; }
.callout.warn { background: var(--warn-bg); border-color: #f0d68a; }
.callout ul { margin: 6px 0 0; padding-left: 18px; }

/* ------------------------------------------------------------ forms */

label { display: block; margin-bottom: 14px; font-weight: 500; }
label.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; white-space: nowrap; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 3px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

input[type=text], input[type=email], input[type=password], input[type=url], input[type=file], textarea, select {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; color: inherit;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input:disabled, textarea:disabled, select:disabled { background: #f3f3f0; color: var(--muted); }
textarea { resize: vertical; }

button, .button {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; color: var(--ink); cursor: pointer;
  padding: 7px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
  white-space: nowrap;
}
button:hover, .button:hover { background: #f0f0ec; text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .button.primary:hover { background: #184fb3; }
button.danger { color: var(--danger); }
button.small, .button.small { padding: 4px 9px; font-size: 13px; }
button.link { border: 0; background: none; color: inherit; padding: 0; opacity: .7; }
button.link:hover { opacity: 1; background: none; }
button.icon { border: 0; background: none; font-size: 18px; line-height: 1; padding: 2px 6px; color: var(--muted); }
button.icon:hover { color: var(--danger); background: none; }

/* ------------------------------------------------------------ plans list */

.tabs { display: flex; gap: 4px; align-items: center; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--ink); border-color: var(--ink); }
.tabs a span { font-size: 12px; background: #e9e9e4; border-radius: 10px; padding: 0 6px; margin-left: 2px; }
.tabs .mine { margin-left: auto; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 500; background: #fafaf8; }
td.num, th.num { text-align: right; }
table.plans tbody tr { cursor: pointer; }
table.plans tbody tr:hover { background: #fafaf7; }
.thumb { width: 72px; }
.thumb img { width: 64px; height: 48px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 3px; display: block; }

.status { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #eee; white-space: nowrap; }
.status.draft { background: #ececea; }
.status.submitted { background: #dfe9fb; color: #184fb3; }
.status.changes_requested { background: var(--warn-bg); color: #8a5a00; }
.status.approved { background: #e0f2e5; color: var(--ok); }

.pager { display: flex; justify-content: space-between; margin-top: 12px; }

table.users form.inline { display: flex; gap: 8px; align-items: center; margin: 0; }
table.users form.inline input { margin: 0; }

/* ------------------------------------------------------------ editor */

body.editor-page { height: 100vh; overflow: hidden; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 390px; height: calc(100vh - 52px); }

.stage-wrap { display: flex; flex-direction: column; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.toolbar .group { display: flex; }
.toolbar .group button { border-radius: 0; margin-left: -1px; }
.toolbar .group button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.toolbar .group button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.toolbar button.active { background: var(--ink); color: #fff; border-color: var(--ink); position: relative; }
.toolbar button.active kbd { background: transparent; color: #ccc; border-color: #555; }
.hint-line { color: var(--muted); font-size: 12px; flex-basis: 100%; }

.stage { flex: 1; position: relative; overflow: hidden; background: #d9d9d4; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; }
.stage[data-tool=polygon], .stage[data-tool=rect] { cursor: crosshair; }
.stage[data-tool=select] { cursor: default; }
.stage[data-tool=pan], .stage.panning { cursor: grabbing; }

.room { fill: var(--c, #222); fill-opacity: .2; stroke: var(--c, #222); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.room.selected { fill-opacity: .32; stroke-width: 3; stroke-dasharray: 8 4; }
.room.ghost { fill: none; stroke: #555; stroke-opacity: .35; stroke-dasharray: 3 3; pointer-events: none; }
.stage[data-tool=select] .room:not(.ghost) { cursor: pointer; }
.no-fill .room { fill-opacity: 0; }
.no-fill .room-label { display: none; }
.room-label { fill: #111; stroke: rgba(255,255,255,.85); paint-order: stroke; text-anchor: middle; dominant-baseline: middle; pointer-events: none; font-weight: 600; }
.room-label.selected { fill: var(--accent); }
.handle { fill: #fff; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; cursor: move; }
.handle.first { fill: var(--accent); }
.draft { fill: rgba(31, 95, 209, .12); stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
polyline.draft { fill: none; }

.t-bathroom { --c: var(--t-bathroom); }
.t-kitchen { --c: var(--t-kitchen); }
.t-technical { --c: var(--t-technical); }
.t-stairwell { --c: var(--t-stairwell); }
.t-corridor { --c: var(--t-corridor); }
.t-residential { --c: var(--t-residential); }
.t-commercial { --c: var(--t-commercial); }
.t-other { --c: var(--t-other); }
.t-unknown { --c: var(--t-unknown); }
.t-none { --c: var(--t-none); }

.sidebar { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px 16px 40px; }
.side-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.side-head h1 { font-size: 17px; margin: 4px 0; }
.save-state { font-size: 12px; color: var(--ok); white-space: nowrap; padding-top: 2px; }
.save-state.dirty { color: var(--muted); }
.save-state.error { color: var(--danger); white-space: normal; }

.panel { border-top: 1px solid var(--line); padding: 12px 0; }
.panel label { font-weight: 400; margin-bottom: 8px; }
.panel details summary { cursor: pointer; font-weight: 500; }
.panel details[open] summary { margin-bottom: 8px; }

.floor-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.floor-tabs button { padding: 3px 9px; font-size: 13px; }
.floor-tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.floor-tabs button.active .muted { color: #bbb; }
.floor-edit { display: flex; gap: 6px; align-items: center; }
.floor-edit input { margin: 0; }

ol.rooms { list-style: none; margin: 0; padding: 0; }
.room-item { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; margin-bottom: 6px; }
.room-item.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.room-row { display: flex; align-items: center; gap: 6px; }
.room-row + .room-row { margin-top: 5px; }
.room-row input, .room-row select { margin: 0; padding: 5px 7px; }
.room-row select { flex: 1; }
.swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--c); flex: none; }
.empty-rooms { margin: 4px 0; }

fieldset.tiers { border: 0; padding: 0; margin: 0 0 10px; }
fieldset.tiers legend { font-weight: 500; margin-bottom: 4px; padding: 0; }
.tier { display: flex !important; gap: 8px; align-items: flex-start; margin-bottom: 4px !important; }
.tier input { margin-top: 3px; }
.tier .muted { font-size: 12px; }

.guide { padding-left: 18px; margin: 0; }
.guide li { margin-bottom: 6px; }

.problems ul { margin: 0; padding-left: 18px; color: #8a5a00; }
.problems .ok { color: var(--ok); margin: 0; }

.side-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; border-top: 1px solid var(--line); padding: 12px 0; }
.side-actions form { margin: 0; }

.review textarea { margin-bottom: 8px; }

/* ------------------------------------------------------------ add a plan */

.field { margin-bottom: 14px; }
.field-label { display: block; font-weight: 500; margin-bottom: 4px; }
.field input[type=file] { margin-top: 8px; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 150px; padding: 18px; text-align: center; cursor: pointer;
  border: 2px dashed var(--line); border-radius: var(--radius); background: #fafaf8;
}
.dropzone:hover, .dropzone:focus { border-color: var(--accent); outline: none; background: #f3f6fc; }
.dropzone.over { border-color: var(--accent); background: #e8effb; }
.dropzone img { max-width: 100%; max-height: 260px; object-fit: contain; border: 1px solid var(--line); background: #fff; }
.dropzone.has-image .dropzone-text strong { font-weight: 400; }
.dropzone-status { font-size: 12px; color: var(--muted); }
.dropzone-status.error { color: var(--danger); }

/* ------------------------------------------------------------ structure layers */

.shape { stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.shape.walls { fill: #2b2b2b; fill-opacity: .55; stroke: #111; }
.shape.doors { fill: #e07b00; fill-opacity: .6; stroke: #a45700; }
.shape.windows { fill: #12a5d8; fill-opacity: .6; stroke: #0a6f93; }
.shape.icons { fill: #8a5cc8; fill-opacity: .25; stroke: #6a3fb0; }
.shape.selected { stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 3; fill-opacity: .85; }
.stage[data-tool=select] .shape { cursor: pointer; }
.no-fill .shape { fill-opacity: 0; }
.icon-label { fill: #4b2a86; stroke: rgba(255,255,255,.85); paint-order: stroke; text-anchor: middle; dominant-baseline: middle; pointer-events: none; font-weight: 600; }
.no-fill .icon-label { display: none; }

.layer-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.layer-tabs button { padding: 3px 9px; font-size: 13px; }
.layer-tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.layer-tabs button.active .muted, .layer-tabs button.active kbd { color: #bbb; }
.layer-tabs button.active kbd { background: transparent; border-color: #555; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.sw.rooms { background: var(--t-residential); }
.sw.walls { background: #2b2b2b; }
.sw.doors { background: #e07b00; }
.sw.windows { background: #12a5d8; }
.sw.icons { background: #8a5cc8; }
.visibility { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.visibility .check { font-size: 12px; }

.inline-field { display: flex; align-items: center; gap: 8px; }
.inline-field input, .inline-field select { width: auto; margin: 0; padding: 4px 6px; }

ol.shapes { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.shape-item { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: var(--radius); padding: 1px 1px 1px 8px; font-size: 13px; cursor: pointer; }
.shape-item.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.shape-item select { margin: 0; padding: 2px 4px; width: auto; font-size: 12px; }
.shape-item button.icon { font-size: 15px; }
.room-number { font-size: 13px; color: var(--muted); white-space: nowrap; }
