: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 15px/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(26px, 3.5vw, 34px); margin: 0 0 10px; line-height: 1.15; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 10px; }
.lede { margin: 0; max-width: 54ch; color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }
.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: 250px 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;
}
.rail-nav { display: grid; gap: 6px; }
.nav {
  text-align: left;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.04);
  color: #e8f0ea;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 14px;
}
.nav:hover, .nav.active {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.12);
}
.rail-foot {
  margin-top: auto;
  padding-top: 20px;
  display: grid;
  gap: 10px;
  font-size: 13px;
  color: #a7bdb0;
}
.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;
  font-size: 13px;
}
.pulse {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9eaa0;
}

main { padding: 28px clamp(18px, 3vw, 42px) 48px; max-width: 1280px; }

.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);
}

.topline {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 13px;
  color: var(--muted);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.topline strong { color: var(--ink); font-weight: 600; }

.demo-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 0;
  padding: 12px 14px;
  background: #f4efe6;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  color: #6e6348;
}
.demo-banner strong { white-space: nowrap; }
.demo-banner .text-link { margin-left: auto; color: var(--accent); }

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: start;
  padding: 28px 0 22px;
}
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

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;
}
textarea { resize: vertical; min-height: 90px; }
input[type=checkbox] { width: auto; display: inline; margin: 0 8px 0 0; }

button.primary, button.secondary, button.danger {
  border-radius: 999px;
  padding: 11px 18px;
  font-weight: 600;
}
button.primary {
  border: 0;
  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; }
button.danger {
  color: var(--danger);
  background: #f8ece9;
  border: 1px solid #ecd2cb;
}
button:disabled { cursor: wait; opacity: 0.55; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  position: relative;
  box-shadow: var(--shadow);
}
.stat:first-child { background: var(--green-soft); border-color: #c9dbc8; }
.stat span { font-size: 13px; color: var(--muted); }
.stat strong {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 650;
  display: block;
  letter-spacing: -0.03em;
  margin: 8px 0 6px;
}
.stat small { font-size: 12px; color: var(--muted); }
.stat i { font-style: normal; position: absolute; right: 18px; top: 16px; color: #90ab7c; }

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.incidents { padding: 20px; }
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
}
.count {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 12px;
  color: var(--muted);
}
.filters {
  display: flex;
  background: #efebe3;
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 14px;
  gap: 3px;
}
.filters button {
  border: 0;
  background: transparent;
  flex: 1;
  padding: 8px 4px;
  font-size: 12px;
  color: var(--muted);
  border-radius: 999px;
  font-weight: 600;
}
.filters .selected {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(30,42,36,0.08);
}

.incident-card {
  display: block;
  text-align: left;
  border-radius: 14px;
  width: 100%;
  padding: 16px;
  margin-bottom: 10px;
  background: #fff;
  border: 1px solid var(--line);
}
.incident-card.selected {
  border-color: #8fb39a;
  box-shadow: 0 0 0 1px #8fb39a;
  background: #f7fbf7;
}
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 12px;
}
.badge {
  font-size: 11px;
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 600;
}
.badge.active { background: #f4efe6; color: var(--accent); }
.badge.pending { background: #edf0f9; color: #667aa1; }
.badge.closed, .badge.rejected, .badge.expired { background: #eceeeb; color: #8b9488; }
.incident-card h3 { font-size: 16px; margin: 0 0 6px; }
.incident-card p { font-size: 12px; color: var(--muted); margin: 0; }
.card-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #efebe3;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}
.card-footer .urgent { color: var(--danger); font-weight: 600; }

.detail { overflow: hidden; min-height: 520px; }
.detail-header { padding: 22px 24px 18px; border-bottom: 1px solid var(--line); }
.detail-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
  margin: 12px 0 8px;
}
.detail-heading h2 { font-size: 22px; }
.detail-header p { font-size: 13px; color: var(--muted); margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.actions button, .actions a {
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 999px;
}
.actions a {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: var(--green);
  border: 1px solid var(--line);
  background: #fff;
}
.tabs {
  display: flex;
  padding: 0 22px;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  overflow: auto;
}
.tabs button {
  border: 0;
  border-radius: 0;
  padding: 14px 0 12px;
  white-space: nowrap;
  background: none;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-weight: 600;
}
.tabs button.selected { color: var(--green); border-color: var(--green); }
.detail-body { padding: 20px 24px; }

.map-head {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 16px;
}
.map-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.entrance {
  background: #faf7f1;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.entrance h3 { font-size: 12px; letter-spacing: 0.04em; margin-bottom: 12px; color: var(--muted); }
.floor {
  display: grid;
  grid-template-columns: 42px 1fr 34px;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
  font-size: 11px;
  color: var(--muted);
}
.floor-cells { display: flex; gap: 3px; height: 14px; }
.cell { flex: 1; min-width: 2px; border-radius: 3px; background: #e7ebe2; }
/* Logical tones: good=green, bad=red. Emergency: safe=good, danger=bad.
   Collection (map-invert): safe=refuse=bad, danger=ready=good. */
.cell.safe { background: #3f7d52; }
.cell.warning { background: #d4a017; }
.cell.danger { background: #b42318; }
.cell.help { background: #7a3e9d; }
.cell.paid { background: #2f5a45; }
.map-invert .cell.safe { background: #b42318; }
.map-invert .cell.danger { background: #3f7d52; }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 16px;
}
.legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-radius: 2px;
}
.legend .safe { background: #3f7d52; }
.legend .warning { background: #d4a017; }
.legend .danger { background: #b42318; }
.legend .help { background: #7a3e9d; }
.legend .unknown { background: #e7ebe2; }
.legend .paid { background: #2f5a45; }
.map-invert .legend .safe { background: #b42318; }
.map-invert .legend .danger { background: #3f7d52; }

.note {
  padding: 12px 14px;
  border: 1px solid #eee5d5;
  background: #fcf9f1;
  color: #91805c;
  border-radius: 10px;
  font-size: 13px;
  margin-top: 16px;
  line-height: 1.55;
}
.help-item {
  border: 1px solid #eedacf;
  background: #fff8f3;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}
.help-item p { margin: 5px 0; font-size: 13px; }
.contact-link {
  font-weight: 600;
  text-decoration: none;
}
.contact-link:hover { text-decoration: underline; }
.timeline-item {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid #efebe3;
  font-size: 13px;
}
.timeline-item time { font-size: 11px; color: var(--muted); }

.channel-box { padding: 22px 2px 0; }
.channel-box h3 { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.channel-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
}
.channel-row small { font-size: 12px; color: var(--muted); }
.channel-box p { font-size: 12px; color: var(--muted); }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 12px;
}
.photo-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: #fff;
}
.photo-card img {
  width: 100%;
  height: 160px;
  object-fit: contain;
  background: #faf7f1;
}
.photo-card p { font-size: 12px; }
.photo-card button { font-size: 12px; width: 100%; margin-top: 6px; }
.info-title { margin-top: 22px; }

.test-panel {
  margin-top: 22px;
  padding: 22px;
  background: var(--green-soft);
  border: 1px solid #c9dbc8;
  border-radius: 16px;
}
.test-panel p { font-size: 13px; color: var(--muted); }
.test-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  max-width: 580px;
  margin-top: 16px;
}
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.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;
}
.compact-head { padding-top: 12px; }
.people-panel { padding: 14px; }
.people-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
}
.people-toolbar label { min-width: 140px; }
.people-board { display: block; }
.scope-selects {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}
.scope-selects label {
  min-width: 140px;
  margin: 0;
}
.topline { align-items: end; }
.entrance-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
}
.entrance-board {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf7f1;
  padding: 6px;
  width: max-content;
  max-width: 100%;
}
.entrance-board h3 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
}
.board-floor {
  display: flex;
  gap: 3px;
  align-items: center;
  margin: 0;
  width: max-content;
  min-height: 0;
  height: auto;
}
.board-floor-label {
  font-size: 9px;
  color: var(--muted);
  text-align: right;
  width: 1.3em;
  flex: 0 0 auto;
  line-height: 1;
  align-self: center;
}
.board-cells {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 1px;
  width: max-content;
  height: auto;
}
.apt-cell {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #eceae4;
  border-radius: 3px;
  padding: 1px 4px;
  margin: 0;
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--sans);
  line-height: 1.05;
  height: fit-content;
  min-height: 0;
  max-height: none;
  cursor: pointer;
  width: auto;
  min-width: 0;
  flex: 0 0 auto;
  align-self: center;
}
.apt-cell.empty {
  color: var(--muted);
  font-weight: 500;
  background: #eceae4;
}
.apt-cell.taken {
  background: var(--green-soft);
  border-color: #c9dbc8;
  color: var(--green);
}
.apt-cell.selected { box-shadow: 0 0 0 1px var(--green); }
.apt-cell small { display: none; }
.resident-card {
  display: grid;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid #c9dbc8;
}
.resident-card:last-child { border-bottom: 0; }
.resident-card-top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.resident-card .danger { width: fit-content; }
.invite-box {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.lifts-list { display: grid; gap: 8px; margin-bottom: 18px; }
.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;
}
.view[hidden] { display: none !important; }
#stats.is-hidden, #incidents-head.is-hidden { display: none !important; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-stack { display: grid; gap: 14px; }
.form-stack .primary { margin-top: 4px; }
.empty {
  padding: 42px 20px;
  text-align: center;
  color: var(--muted);
}
#toast {
  position: fixed;
  left: 24px;
  bottom: 24px;
  max-width: 420px;
  padding: 14px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  z-index: 40;
  box-shadow: 0 12px 40px rgba(28, 24, 18, 0.25);
}
#toast[hidden] { display: none; }
dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  max-width: min(560px, calc(100vw - 28px));
  width: 100%;
  box-shadow: 0 24px 80px rgba(28, 24, 18, 0.28);
}
dialog::backdrop { background: rgba(28, 24, 18, 0.35); }
.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  padding: 20px 22px 0;
}
.modal-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
}
#modal-body { padding: 14px 22px 22px; }
.icon-button {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.stack { display: grid; gap: 12px; }
#modal-close {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.report-text {
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.45;
  max-height: 60vh;
  overflow: auto;
}
.muted { color: var(--muted); font-size: 13px; }
.contact-link { color: var(--green); font-weight: 600; text-decoration: none; }
.contact-link:hover { text-decoration: underline; }
.note {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.scroll-table { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
}
.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}
.legend i.safe { background: #3f7d52; }
.legend i.warning { background: #d4a017; }
.legend i.danger { background: #b42318; }
.legend i.help { background: #7a3e9d; }
.legend i.unknown { background: #cfc8bc; }
.legend i.paid { background: #2f5a45; }
.map-invert .legend i.safe { background: #b42318; }
.map-invert .legend i.danger { background: #3f7d52; }

@media (max-width: 800px) {
  .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;
  }
  .rail-brand { margin: 0 8px 0 0; }
  .rail-caption { display: none; }
  .rail-nav {
    display: flex;
    flex: 1 1 100%;
    gap: 6px;
  }
  .nav { flex: 1; text-align: center; padding: 10px 8px; font-size: 13px; }
  .rail-foot {
    margin: 0;
    padding: 0;
    display: flex;
    gap: 12px;
    width: 100%;
  }
  main { padding: 14px 12px 36px; }
  .page-head, .topline, .scope-selects, .people-toolbar, .demo-banner { gap: 10px; }
  .page-head { padding-top: 10px; }
  .page-actions { width: 100%; justify-content: stretch; }
  .page-actions .primary, .page-actions .secondary { flex: 1; }
  .stats { grid-template-columns: 1fr; }
  .panel { padding: 14px; border-radius: 14px; }
  .people-panel { padding: 10px; }
  .entrance-board { padding: 4px; }
  .apt-cell { padding: 1px 2px; font-size: 9px; }
  .board-floor { width: max-content; }
  .board-floor-label { font-size: 8px; }
  .fields { grid-template-columns: 1fr; }
  .test-controls { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; }
  #incident-list { display: flex; gap: 10px; overflow: auto; }
  .incident-card { min-width: 230px; max-width: 230px; }
  .demo-banner { flex-wrap: wrap; }
  .demo-banner .text-link { margin: 0; }
  #toast { left: 14px; right: 14px; bottom: 14px; }
  dialog { max-width: calc(100vw - 16px); }
  .modal-head, #modal-body { padding-left: 14px; padding-right: 14px; }
}
@media (min-width: 1100px) {
  .entrance-grid { gap: 12px; }
}
