:root {
  --ink: #2F3337;
  --muted: #6B7280;
  --paper: #F6F7F9;
  --panel: #FFFFFF;
  --line: #E2E5E9;
  --green: #FF7A00;
  --green-soft: #FFF3E6;
  --accent: #FFA94D;
  --danger: #B42318;
  --ok: #2F7A4A;
  --shadow: 0 10px 30px rgba(47, 51, 55, 0.06);
  --serif: "Literata", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 400 16px/1.5 var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #FFE8D1 0%, transparent 55%),
    linear-gradient(180deg, #F8F9FA 0%, var(--paper) 40%, #EEF0F2 100%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); }
[hidden] { display: none !important; }

.eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
h1, h2, h3 { font-family: var(--serif); font-weight: 650; letter-spacing: -0.02em; }
h1 { font-size: clamp(28px, 4vw, 36px); margin: 0 0 10px; line-height: 1.15; }
h2 { font-size: 22px; margin: 0 0 6px; }
h3 { font-size: 17px; margin: 0 0 8px; }
.lede { margin: 0; max-width: 54ch; color: var(--muted); }
.meta { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.optional { color: var(--muted); font-size: 12px; font-weight: 400; }
code { font-size: 0.92em; background: var(--green-soft); padding: 1px 6px; border-radius: 4px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--green-soft);
  color: var(--green);
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 650;
  overflow: hidden;
}
.brand-mark img { width: 28px; height: 28px; display: block; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  padding: 36px 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.login-card .brand-mark { margin-bottom: 18px; }
.login-card .primary { width: 100%; margin-top: 8px; }
#login-error { min-height: 1.2em; margin: 10px 0 0; color: var(--danger); font-size: 14px; }

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}
.rail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 28px 20px;
  background: #20352c;
  color: #e8f0ea;
}
.rail-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}
.rail-brand strong { display: block; font-family: var(--serif); font-size: 20px; }
.rail-brand small { color: #a7bdb0; font-size: 12px; }
.rail-caption {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #93aa9c;
}
.house-list { display: grid; gap: 8px; flex: 1; align-content: start; }
.house-list button {
  text-align: left;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.04);
  color: #e8f0ea;
  border-radius: 12px;
  padding: 12px 14px;
}
.house-list button:hover,
.house-list button.active {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.12);
}
.house-list .empty {
  color: #93aa9c;
  font-size: 14px;
  padding: 8px 4px;
}
.house-name { display: block; font-weight: 600; }
.house-meta { display: block; margin-top: 4px; font-size: 12px; color: #a7bdb0; }
.rail-new {
  margin-top: 8px;
  border: 1px dashed rgba(255,255,255,0.28);
  background: transparent;
  color: #d7e8dc;
  border-radius: 12px;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
}
.rail-new:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.4);
}
.rail-foot {
  margin-top: auto;
  padding-top: 20px;
  display: grid;
  gap: 10px;
  font-size: 13px;
}
.rail-foot a { color: #d7e8dc; text-decoration: none; }
.rail-foot a:hover { text-decoration: underline; }
.text-link {
  background: none;
  border: 0;
  padding: 0;
  color: #a7bdb0;
  text-align: left;
}

main { padding: 36px clamp(20px, 4vw, 48px) 64px; max-width: 980px; }
.site-switch {
  display: inline-flex;
  gap: 4px;
  background: #efebe3;
  padding: 4px;
  border-radius: 999px;
  margin-bottom: 18px;
}
.site-switch a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
}
.site-switch a.current,
.site-switch a:hover {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(30,42,36,0.08);
}
.page-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: start;
  margin-bottom: 22px;
}
.status-pill {
  flex: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.step-head {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
.step-head.compact { margin-top: 28px; }
.step-head p { margin: 0; color: var(--muted); font-size: 14px; max-width: 62ch; }
.step-num {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  font-family: var(--serif);
  font-weight: 650;
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.stack { display: grid; gap: 12px; }
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  margin: 12px 0;
}
.form-grid-3 > span { display: block; min-height: 1px; }
.form-grid-3 .form-grid-span,
.form-grid-3 > button[type=submit] {
  justify-self: stretch;
}
.form-grid-3 > button.text-link {
  justify-self: start;
  align-self: end;
  margin-bottom: 8px;
}
.term-pick {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 4px;
}
.term-card {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 14px 12px;
  font-weight: 600;
  text-align: center;
}
.term-card:hover { border-color: #b9cbb8; }
.term-card.active {
  background: var(--green-soft);
  border-color: #c9dbc8;
  color: var(--green);
  box-shadow: inset 0 0 0 1px #c9dbc8;
}
.template-box {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.template-box h4 {
  margin: 0 0 4px;
  font-size: 15px;
}
.house-list button.orphan {
  border-style: dashed;
  opacity: 0.95;
}
.house-list button.orphan .house-meta { color: var(--accent); }

@media (max-width: 900px) {
  .form-grid-3, .term-pick {
    grid-template-columns: 1fr;
  }
  .form-grid-3 > span { display: none; }
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #4f5d55;
  font-weight: 500;
}
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #8fb39a;
  outline-offset: 1px;
}

button.primary, button.secondary {
  border: 0;
  border-radius: 999px;
  padding: 11px 18px;
  font-weight: 600;
}
button.primary { background: var(--green); color: #fff; }
button.primary:hover { background: #254836; }
button.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
button.secondary:hover { background: #f5f1e8; }

.editor-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}
.ghost-edit {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  color: var(--green);
}
.ghost-edit:hover { background: var(--green-soft); }
.building-summary {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #faf7f1;
}
.building-summary p { margin: 0; }
.building-summary .meta { margin-top: 4px; }
.map-subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 4px;
}
.map-subtab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.map-subtab.active {
  background: var(--green-soft);
  border-color: #c9dbc8;
  color: var(--green);
}
.field-control,
.form-grid-3 input,
.form-grid-3 select,
.inline-form input,
.inline-form select {
  width: 100%;
  height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-sizing: border-box;
  font: inherit;
  color: inherit;
  appearance: none;
  -webkit-appearance: none;
}
.form-grid-3 select,
.inline-form select,
select.field-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7870' d='M1.1 1.3 6 6.2l4.9-4.9 1.1 1.1L6 8.4 0 2.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
.form-grid-3 input[type=number]::-webkit-outer-spin-button,
.form-grid-3 input[type=number]::-webkit-inner-spin-button {
  opacity: 1;
  height: 100%;
}
.lifts-list { display: grid; gap: 8px; margin: 12px 0 16px; }
.lift-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 14px;
}
.step-tabs {
  display: flex;
  gap: 6px;
  background: #efebe3;
  padding: 4px;
  border-radius: 999px;
}
.step-tab {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}
.step-tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(30,42,36,0.08);
}

.carousel-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}
.carousel-step[hidden] { display: none !important; }
.selected-org {
  margin: 0;
  padding: 12px 14px;
  background: var(--green-soft);
  border-radius: 10px;
  font-size: 14px;
}
.org-pick { margin-top: 22px; }
.org-pick-list { display: grid; gap: 8px; margin-top: 8px; }
.org-pick-list button {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
}
.org-pick-list button:hover { background: #f5f1e8; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
}
.chip:hover, .chip.active {
  border-color: #8fb39a;
  background: #fff;
}
.edit-building {
  margin: 0 0 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.map-card {
  margin-top: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #faf7f1;
}
.map-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.map-card-head h3 { margin: 0; font-size: 15px; }
#map-count { color: var(--muted); font-size: 13px; }
.map-body { padding: 16px; font-size: 14px; line-height: 1.55; }
.map-body.empty-map { color: var(--muted); }
.section-block + .section-block { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--line); }
.section-block h4 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 16px;
}
.floor-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
}
.floor-row .label { color: var(--muted); }
.floor-row .nonres { color: var(--accent); }

.connect-box {
  margin-top: 16px;
  padding: 16px;
  border-radius: 12px;
  background: var(--green-soft);
  border: 1px solid #c9dbc8;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
}
.channel-list { margin-top: 14px; color: var(--muted); font-size: 14px; white-space: pre-wrap; }
.howto {
  margin: 20px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
}
.howto li { margin: 6px 0; }
.soft-pre {
  margin: 0;
  white-space: pre-wrap;
  background: #f4efe6;
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.2em;
}

.banner-error, .banner-ok {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
}
.banner-error {
  color: var(--danger);
  background: #f8ece9;
  border: 1px solid #ecd2cb;
  min-height: 0;
}
.banner-error:empty { display: none; }
.banner-ok {
  color: var(--ok);
  background: var(--green-soft);
  border: 1px solid #c9dbc8;
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    min-height: auto;
  }
  .rail-brand { margin: 0; }
  .rail-caption { width: 100%; margin: 4px 0 0; }
  .house-list {
    display: flex;
    gap: 8px;
    overflow: auto;
    width: 100%;
    max-height: none;
    padding-bottom: 4px;
  }
  .house-list button {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .rail-new { width: auto; margin-left: auto; }
  .rail-foot {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-top: 4px;
  }
  main { padding: 14px 12px 36px; }
  .split { grid-template-columns: 1fr; }
  .editor-top { flex-direction: column; align-items: start; gap: 10px; }
  .page-head { flex-direction: column; gap: 10px; }
  .inline-form, .edit-building {
    grid-template-columns: 1fr !important;
  }
  .carousel-nav {
    flex-wrap: wrap;
    gap: 8px;
  }
  .step-tabs { flex-wrap: wrap; }
  .panel { padding: 14px; }
  .map-body { overflow: auto; }
  .chip-row { gap: 6px; }
}
