:root {
  color-scheme: light;
  --navy: #003f63;
  --blue: #0073a8;
  --green: #58b947;
  --orange: #f58220;
  --ink: #0b2436;
  --muted: #607487;
  --line: #d8e5ec;
  --panel: #ffffff;
  --bg: #eef5f8;
  --shadow: 0 18px 50px rgba(9, 36, 54, .14);
  --soft-shadow: 0 8px 24px rgba(9, 36, 54, .10);
  --tap: 44px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #edf7fb 0%, #f7fafc 52%, #e8f4ee 100%);
  overflow: hidden;
}
button, input, select, textarea { font: inherit; }
button { min-height: var(--tap); cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(245, 130, 32, .45);
  outline-offset: 2px;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(246, 250, 252, .96);
}
.loading.done { opacity: 0; pointer-events: none; transition: opacity .25s ease; }
.loading-card {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}
.loading-card img { width: 172px; }
.progress { height: 8px; border-radius: 999px; overflow: hidden; background: #e6eef3; }
.progress span { display: block; width: 18%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--green)); transition: width .25s ease; }

.app-header {
  height: 68px;
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(260px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(195, 214, 224, .92);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { min-width: 0; display: flex; gap: 14px; align-items: center; }
.brand img { width: 170px; height: auto; flex: 0 0 auto; }
.brand h1 { margin: 0; font-size: 18px; line-height: 1.15; letter-spacing: 0; }
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.search-shell {
  min-width: 0;
  height: 46px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.search-shell span { color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; }
.search-shell input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--ink); }
.header-actions { display: flex; gap: 8px; align-items: center; }
.button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 16px;
  background: #fff;
  color: var(--ink);
  font-weight: 750;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.button.primary { border-color: var(--orange); background: var(--orange); color: #fff; }
.button.secondary.active { border-color: var(--blue); background: #e7f5fb; color: var(--navy); }

.menu {
  position: fixed;
  top: 62px;
  right: 14px;
  z-index: 50;
  display: none;
  width: 230px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
}
.menu.open { display: grid; gap: 4px; }
.menu button, .menu-file {
  display: flex;
  align-items: center;
  min-height: 40px;
  width: 100%;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 650;
}
.menu button:hover, .menu-file:hover { background: #eff7fb; }
.menu-file input { display: none; }

.app-shell {
  height: calc(100svh - 68px);
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 420px;
  gap: 12px;
  padding: 12px;
}
.sidebar, .properties {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel-card, .properties {
  border: 1px solid rgba(196, 215, 225, .92);
  border-radius: 18px;
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--soft-shadow);
}
.panel-card { padding: 14px; }
.section-title {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-title h2 { margin: 0; font-size: 16px; letter-spacing: 0; }
.count-pill, .condition-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e7f5fb;
  color: var(--navy);
  font-weight: 800;
  font-size: 13px;
}
.muted { color: var(--muted); font-size: 12px; }
.status-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.status-card {
  display: grid;
  gap: 4px;
  min-height: 72px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdfe;
}
.status-card strong { font-size: 20px; }
.status-card span { color: var(--muted); font-size: 12px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip, .link-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 750;
}
.chip.active { border-color: var(--blue); background: #e7f5fb; color: var(--navy); }
.link-button { min-height: 32px; color: var(--blue); }
.list-card { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.damper-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 4px;
}
.damper-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 62px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: left;
}
.damper-row.active { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 115, 168, .14); }
.damper-row strong { display: block; }
.damper-row span { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }

.map-workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}
.map-topline {
  min-height: 52px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid rgba(196, 215, 225, .92);
  border-radius: 18px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--soft-shadow);
}
.map-tools { display: flex; gap: 6px; }
.map-tools button {
  min-width: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 850;
}
#mobileActionsBtn { display: none; }
.map-shell {
  min-height: 0;
  overflow: auto;
  border: 1px solid rgba(196, 215, 225, .92);
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
}
.map-surface {
  position: relative;
  width: 1400px;
  transform-origin: top left;
}
.map-surface img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}
.pin-layer { position: absolute; inset: 0; }
.pin {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: calc(var(--w) * 1%);
  height: calc(var(--h) * 1%);
  transform: translate(-50%, -50%) rotate(calc(var(--r) * 1deg));
  display: grid;
  place-items: center;
  min-width: 46px;
  padding: 0 3px;
  border: 2px solid #14833b;
  border-radius: 5px;
  background: rgba(120, 225, 138, .72);
  color: #042813;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  word-break: keep-all;
  overflow: visible;
  box-shadow: 0 0 0 1px rgba(255,255,255,.4);
  transition: box-shadow .2s ease, filter .2s ease;
}
.pin-label {
  display: block;
  max-width: none;
  white-space: nowrap;
  word-break: keep-all;
  overflow-wrap: normal;
  hyphens: none;
  transform: scale(.92);
  transform-origin: center;
}
.pin.active {
  z-index: 5;
  box-shadow: 0 0 0 5px rgba(0, 115, 168, .24), 0 0 24px rgba(0, 115, 168, .38);
  filter: saturate(1.2);
}
.pin.hidden-match { opacity: .18; }
.pin.not-inspected { border-color: #2563eb; background: repeating-linear-gradient(45deg, #bfdbfe, #bfdbfe 5px, #dbeafe 5px, #dbeafe 9px); }
.pin.good { border-color: #14833b; background: rgba(134, 239, 172, .82); }
.pin.monitor { border-color: #b7791f; background: repeating-linear-gradient(-45deg, #fde047, #fde047 6px, #fef3c7 6px, #fef3c7 10px); }
.pin.repair-required { border-color: #c92a2a; background: repeating-linear-gradient(45deg, #fca5a5, #fca5a5 5px, #fecaca 5px, #fecaca 10px); }
.pin.blocked { border-color: #6d28d9; background: repeating-linear-gradient(90deg, #c4b5fd, #c4b5fd 4px, #ddd6fe 4px, #ddd6fe 8px); }
.pin.admin-editing { cursor: move; }

.properties { overflow: hidden; }
.sheet-handle { display: none; width: 56px; height: 5px; min-height: 5px; margin: 9px auto 0; padding: 0; border: 0; border-radius: 999px; background: #b9ccd6; }
.property-head { padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.property-head h2 { margin: 2px 0 8px; font-size: 26px; }
.property-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.request-access {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}
.request-access:hover,
.request-access:focus-visible {
  text-decoration: underline;
}
.save-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--orange);
  border-radius: 999px;
  background: var(--orange);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}
.save-button:disabled {
  border-color: var(--line);
  background: #eef4f7;
  color: var(--muted);
  cursor: default;
}
.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px 0;
  overflow-x: auto;
}
.tab {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 750;
}
.tab.active { border-color: var(--blue); background: #e7f5fb; color: var(--navy); }
.property-form { min-height: 0; overflow: auto; padding: 14px 16px 18px; }
.tab-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tab-panel.hidden, .hidden { display: none !important; }
.field { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 750; }
.field.full { grid-column: 1 / -1; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}
.field textarea { min-height: 260px; resize: vertical; }
.notes-large textarea { min-height: 380px; }
.photo-grid { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.photo-thumb {
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb:hover, .photo-thumb:focus-visible { box-shadow: 0 0 0 4px rgba(0, 115, 168, .16); border-color: var(--blue); }
.admin-only { display: none; }
body.admin .admin-only { display: inline-flex; }

.mobile-fab-row { display: none; }
.mobile-drawer, .modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  background: rgba(8, 31, 47, .38);
}
.mobile-drawer.open, .modal.open { display: block; }
.drawer-card, .modal-card {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  max-height: 78svh;
  overflow: auto;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 16px;
}
.modal-card {
  top: 50%;
  bottom: auto;
  left: 50%;
  right: auto;
  width: min(560px, calc(100vw - 28px));
  transform: translate(-50%, -50%);
}
.icon-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}
.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.help-grid p { margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fbfdfe; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 90;
  transform: translateX(-50%) translateY(120%);
  min-width: min(420px, calc(100vw - 28px));
  padding: 12px 14px;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform .22s ease;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(4, 20, 31, .78);
}
.photo-viewer.open { display: grid; }
.photo-viewer-card {
  width: min(1120px, calc(100vw - 28px));
  height: min(880px, calc(100svh - 28px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 20px;
  overflow: hidden;
  background: #071b29;
  box-shadow: var(--shadow);
}
.photo-viewer-bar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, .96);
  color: var(--ink);
}
.inline-close {
  position: static;
  flex: 0 0 auto;
}
.photo-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 12px 64px;
  overflow: hidden;
}
.photo-stage img {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: calc(100svh - 150px);
  object-fit: contain;
  border-radius: 10px;
  background: #04141f;
}
.photo-nav {
  position: absolute;
  top: 50%;
  width: 48px;
  min-height: 64px;
  transform: translateY(-50%);
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  background: rgba(255, 255, 255, .92);
  color: var(--navy);
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
}
.photo-prev { left: 14px; }
.photo-next { right: 14px; }
.photo-caption {
  min-height: 44px;
  padding: 11px 14px;
  color: #dce9ef;
  font-size: 13px;
  background: rgba(0, 0, 0, .24);
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 300px minmax(0, 1fr); }
  .properties {
    position: fixed;
    top: 80px;
    right: 12px;
    bottom: 12px;
    z-index: 35;
    width: min(420px, calc(100vw - 24px));
  }
}

@media (max-width: 760px) {
  body { overflow: hidden; }
  .app-header {
    height: 118px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "search search";
    gap: 8px;
    padding: 8px 10px;
  }
  .brand { grid-area: brand; gap: 8px; }
  .brand img { width: 108px; }
  .brand h1 { font-size: 13px; }
  .brand .eyebrow { font-size: 9px; }
  .brand > div { min-width: 0; }
  .search-shell { grid-area: search; height: 42px; }
  .search-shell span { display: none; }
  .header-actions {
    display: none;
  }
  #syncBtn, #adminBtn { display: none; }
  .button { padding: 0 12px; }
  .brand { padding-right: 0; }
  .menu { top: 56px; right: 8px; }
  .app-shell {
    height: calc(100svh - 118px);
    display: block;
    padding: 8px;
  }
  .sidebar { display: none; }
  .map-workspace { height: 100%; grid-template-rows: auto minmax(0, 1fr) auto; }
  .map-topline {
    min-height: 44px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    border-radius: 14px;
    padding: 8px 10px;
  }
  .map-topline .eyebrow { display: none; }
  .map-tools { max-width: 224px; overflow-x: auto; }
  .map-tools button { min-width: 40px; min-height: 38px; padding: 0 10px; }
  #resetView { min-width: 62px; }
  #mobileActionsBtn {
    display: inline-block;
    order: -1;
    min-width: 62px;
    background: var(--orange);
    border-color: var(--orange);
    color: #fff;
  }
  .map-shell { border-radius: 16px; }
  .map-surface { width: 980px; }
  .mobile-fab-row {
    display: flex;
    gap: 8px;
    padding: 8px 2px 0;
  }
  .fab {
    flex: 1;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    font-weight: 800;
    box-shadow: var(--soft-shadow);
  }
  .fab.primary { border-color: var(--orange); background: var(--orange); color: #fff; }
  .properties {
    top: auto;
    left: 6px;
    right: 6px;
    bottom: 6px;
    width: auto;
    max-height: 32svh;
    min-height: 0;
    border-radius: 22px 22px 18px 18px;
    transition: max-height .22s ease;
  }
  .properties.expanded { max-height: 82svh; }
  .sheet-handle { display: block; }
  .property-head { padding: 10px 14px; }
  .property-head h2 { font-size: 20px; }
  .tabs { padding: 8px 12px 0; }
  .property-form { padding: 12px; }
  .tab-panel { grid-template-columns: 1fr; }
  .field textarea, .notes-large textarea { min-height: 220px; }
  .help-grid { grid-template-columns: 1fr; }
  .photo-viewer { padding: 6px; }
  .photo-viewer-card {
    width: calc(100vw - 12px);
    height: calc(100svh - 12px);
    border-radius: 16px;
  }
  .photo-stage { padding: 8px 48px; }
  .photo-stage img { max-height: calc(100svh - 126px); }
  .photo-nav { width: 40px; min-height: 54px; font-size: 28px; }
  .photo-prev { left: 6px; }
  .photo-next { right: 6px; }
}
