:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --ink: #22221f;
  --muted: #77776f;
  --line: #e2e2dc;
  --accent: #8a6a4f;
  --danger: #b03a2e;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

/* --- top bar --- */
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; text-decoration: none; color: var(--ink); }
.topbar nav { display: flex; gap: 16px; }
.topbar nav a { text-decoration: none; }
.whoami { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; }

main { max-width: 960px; margin: 0 auto; padding: 24px 16px 60px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0 0 4px; }

/* --- cards & forms --- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 20px; margin-top: 16px;
}
.card.empty { color: var(--muted); text-align: center; padding: 40px 20px; }
.form { max-width: 520px; }
.form label, fieldset .check { display: block; margin-bottom: 14px; }
label > input, label > select {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 6px; font-size: 15px; background: #fff;
}
label.check, fieldset label.check { display: flex; align-items: flex-start; gap: 8px; font-weight: normal; }
label.check input { width: auto; margin: 3px 0 0; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 14px; margin: 0 0 16px; }
legend { padding: 0 6px; font-weight: 600; font-size: 14px; }
.site-picker { margin-top: 10px; max-height: 240px; overflow-y: auto; }
.hint { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }

button, .button {
  display: inline-block; padding: 9px 14px; border-radius: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-size: 14px; text-decoration: none; cursor: pointer;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.small { padding: 4px 10px; font-size: 13px; }
button.link { border: none; background: none; color: var(--accent); padding: 0; text-decoration: underline; }

/* --- tables --- */
.grid { width: 100%; border-collapse: collapse; margin-top: 16px; background: var(--card); }
.grid th, .grid td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.grid th { font-size: 13px; color: var(--muted); font-weight: 600; }
.grid tr.inactive td { opacity: .5; }
.right { text-align: right; }

.role-chip {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  background: #efece6; font-size: 12px; color: #5c503f;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error {
  background: #fdecea; border: 1px solid #f5c6c0; color: var(--danger);
  padding: 10px 12px; border-radius: 6px; margin: 0 0 16px;
}

/* --- login --- */
.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login { width: 100%; max-width: 360px; }
.login h1 { margin-bottom: 20px; text-align: center; }

@media (max-width: 600px) {
  .whoami { margin-left: 0; width: 100%; }
  .grid th:nth-child(4), .grid td:nth-child(4) { display: none; }
}

/* ================= Floor plan (Phase B) ================= */

.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { margin: 0 0 6px; font-size: 14px; }
.center { text-align: center; }

/* The plan image and its clickable rooms share one positioning context.
   Room boxes are placed in percentages, so they track the image at any size. */
.plan-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}
.plan-img { display: block; max-width: 100%; height: auto; user-select: none; }
.plan-stage.editing { cursor: crosshair; }
.plan-stage.editing .plan-img { pointer-events: none; }

.room-region {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid rgba(138, 106, 79, .85);
  background: rgba(138, 106, 79, .16);
  border-radius: 4px;
  text-decoration: none;
  color: var(--ink);
  line-height: 1.3;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 4px;
  transition: background .12s;
}
.room-region:hover { background: rgba(138, 106, 79, .32); }

.room-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, .88);
  border-radius: 3px;
  padding: 1px 5px;
  align-self: flex-start;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-pct { color: var(--accent); margin-left: 5px; }

.room-bar {
  display: block; height: 4px; margin-top: 4px; border-radius: 2px;
  background: rgba(255, 255, 255, .7); overflow: hidden;
}
.room-bar-fill { display: block; height: 100%; background: var(--accent); }

/* editor-only states */
.room-region.edit { cursor: move; }
.room-region.selected { border-color: #2f6f4f; background: rgba(47, 111, 79, .28); }
.room-region.ghost { border-style: dashed; background: rgba(138, 106, 79, .1); pointer-events: none; }
.resize-handle {
  position: absolute; right: -6px; bottom: -6px; width: 13px; height: 13px;
  background: #fff; border: 2px solid #2f6f4f; border-radius: 3px; cursor: nwse-resize;
}
.room-region:not(.selected) .resize-handle { display: none; }

.editor-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 14px 0 4px; }
.save-status { font-size: 13px; color: var(--muted); }
.save-status.unsaved { color: #b06a00; font-weight: 600; }
.save-status.saved { color: #2f6f4f; font-weight: 600; }

/* ================= Progress bars ================= */

.bar {
  display: block; height: 8px; border-radius: 4px;
  background: #e9e6e0; overflow: hidden; margin: 6px 0;
}
.bar.big { height: 14px; border-radius: 7px; }
.bar-fill { display: block; height: 100%; background: var(--accent); }
.bar-caption { margin: 4px 0 16px; font-size: 14px; color: var(--muted); }
.bar-mini { width: 90px; }

.inline-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { margin: 0; }
.inline-form input { width: auto; }

h2 { font-size: 17px; margin: 0 0 10px; }

@media (max-width: 600px) {
  .room-label { font-size: 10px; padding: 0 3px; }
  .inline-form { gap: 10px; }
}

/* ================= Room content (Phase C) ================= */

.section-nav {
  display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px;
  padding-bottom: 10px; border-bottom: 1px solid var(--line);
}
.section-nav a {
  padding: 5px 11px; border-radius: 16px; background: var(--card);
  border: 1px solid var(--line); text-decoration: none; font-size: 13px;
}
.section-nav a:hover { background: #efece6; }

/* image grids */
.thumb-grid {
  display: grid; gap: 14px; margin: 12px 0;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.thumb { margin: 0; }
.thumb img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--line); background: #f0efeb;
  display: block;
}
.thumb figcaption { font-size: 13px; line-height: 1.45; margin-top: 6px; }

.upload-form {
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
  border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px;
}
.upload-form label, .addrow label { margin: 0; }
.upload-form input[type=file] { border: none; padding-left: 0; }

.addrow {
  border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px;
}
.addrow input { min-width: 120px; }

/* editable tables */
.table-scroll { overflow-x: auto; }
.grid input {
  width: 100%; min-width: 90px; padding: 5px 7px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 4px; background: #fff;
}
.grid input.narrow { min-width: 70px; max-width: 100px; }
.grid input.right { text-align: right; }
.grid td { vertical-align: middle; }
.total-row td { border-top: 2px solid var(--line); border-bottom: none; font-size: 15px; }
.nowrap { white-space: nowrap; }
form.inline { display: inline; }

button.danger, .button.danger { color: var(--danger); border-color: #e8c9c4; }
button.link.danger { border: none; background: none; padding: 0; font-size: 13px; }
button.small { padding: 4px 9px; font-size: 13px; }

@media (max-width: 600px) {
  .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .upload-form, .addrow { gap: 10px; }
  .upload-form label, .addrow label { width: 100%; }
  .addrow input, .upload-form input { width: 100%; }
}

.date-src {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  border-radius: 10px; background: #eef1ea; color: #4a5a44;
  font-size: 11px; font-weight: 600; vertical-align: 1px;
}
.date-src.muted { background: #f0efec; color: var(--muted); }

/* ================= Site chat (Phase D) ================= */

.chat-card { padding: 0; overflow: hidden; }

.thread {
  max-height: 60vh; min-height: 240px; overflow-y: auto;
  padding: 16px 18px; background: #faf9f7;
}
.chat-empty { padding: 40px 0; }

.msg {
  max-width: 78%; margin-bottom: 14px; padding: 9px 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px 10px 10px 2px;
}
/* your own messages sit on the right, like every chat app */
.msg.mine {
  margin-left: auto; background: #f2ede4; border-color: #e3dbcc;
  border-radius: 10px 10px 2px 10px;
}
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
.msg-head strong { font-size: 13px; }
.msg-body { margin: 0; white-space: pre-wrap; word-break: break-word; }

.msg-images { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.msg-images img {
  width: 130px; height: 100px; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--line); display: block;
}

.compose { border-top: 1px solid var(--line); padding: 12px 16px; background: var(--card); }
.compose textarea {
  width: 100%; padding: 9px 10px; font: inherit; resize: vertical;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.compose-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 9px; flex-wrap: wrap;
}
.attach { font-size: 13px; color: var(--muted); margin: 0; }
.attach input { display: inline-block; width: auto; margin-left: 6px; border: none; padding: 0; }
.chat-card + .hint, .chat-card .hint { padding: 0 16px 12px; }

@media (max-width: 600px) {
  .msg { max-width: 92%; }
  .thread { max-height: 55vh; padding: 12px; }
  .msg-images img { width: 100px; height: 78px; }
}
