:root {
  color-scheme: light;
  --font: Geneva, "Helvetica Neue", system-ui, sans-serif;
  --font-mono: Monaco, ui-monospace, "SF Mono", Menlo, monospace;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --grid: #d4d4d4;
  --grid-strong: #a3a3a3;
  --header-bg: #f0f0f0;
  --row-alt: #fafafa;
  --row-hover: #eef4ff;
  --row-tour: #fffbeb;
  --text: #171717;
  --muted: #525252;
  --link: #1d4ed8;
  --danger: #b91c1c;
  --desk: #d6d6d6;
  --chrome: #ececec;
  --window-border: #8a8a8a;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  font-weight: var(--font-weight-normal);
  line-height: 1.35;
  color: var(--text);
  background: var(--desk);
}

.page {
  min-height: 100vh;
}

.page:has(#board:not([hidden])) {
  max-width: none;
  padding: 0;
}

h1 {
  margin: 0;
  font-size: 14px;
  font-weight: var(--font-weight-semibold);
}

.login[hidden],
.board[hidden] {
  display: none !important;
}

.login {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--desk);
}

.login .stack {
  width: min(320px, 100%);
  padding: 1rem;
  background: #fff;
  border: 1px solid var(--window-border);
  box-shadow: 0 2px 8px rgb(0 0 0 / 12%);
}

.board {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 0.5rem;
  background: var(--desk);
}

.sheet-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.45rem 0.65rem;
  background: var(--chrome);
  border: 1px solid var(--window-border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
}

.sheet-header h1 {
  margin: 0;
  font-size: 13px;
  font-weight: var(--font-weight-semibold);
}

.sheet-header .hint {
  flex: 1;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  min-width: 200px;
}

.sheet-header-actions {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
}

.sheet-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  min-height: 0;
  border: 1px solid var(--window-border);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 8%);
}

.sheet-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--grid);
  background: var(--header-bg);
}

.add-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 1 1 auto;
  min-width: 0;
}

.add-row input,
.add-row button {
  font-size: 12px;
  padding: 0.2rem 0.45rem;
  line-height: 1.35;
}

.add-row input {
  width: 12rem;
  max-width: min(18rem, 42vw);
  min-width: 7rem;
  flex: 1 1 12rem;
}

.stack {
  display: grid;
  gap: 0.4rem;
}

label {
  display: grid;
  gap: 0.2rem;
  font-size: 12px;
  color: var(--muted);
}

input,
textarea,
select,
button {
  font: inherit;
  font-size: 13px;
}

input,
textarea,
select {
  border: 1px solid var(--grid);
  padding: 0.25rem 0.4rem;
  background: #fff;
  color: var(--text);
}

input:focus,
textarea:focus,
select:focus {
  outline: 1px solid #737373;
  outline-offset: -1px;
}

button {
  border: 1px solid var(--grid-strong);
  padding: 0.25rem 0.55rem;
  background: #fff;
  cursor: pointer;
}

button:hover {
  background: #f5f5f5;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  margin-left: auto;
}

.filters button {
  font-size: 12px;
  padding: 0.2rem 0.45rem;
}

.filters button[aria-selected="true"] {
  background: #dbeafe;
  border-color: #93c5fd;
}

.sheet-scroll {
  overflow: auto;
  flex: 1;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

.sheet {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.sheet col.transit-col {
  width: 3.5rem;
}

.sheet col.date-col {
  width: 4.5rem;
}

.sheet th.date-col,
.sheet td.date-col {
  font-size: 12px;
  white-space: nowrap;
}

.sheet th,
.sheet td {
  border: 1px solid var(--grid);
  padding: 0.2rem 0.45rem;
  vertical-align: middle;
  white-space: nowrap;
}

.sheet th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--header-bg);
  font-weight: var(--font-weight-semibold);
  font-size: 12px;
  text-align: left;
  border-bottom: 1px solid var(--grid-strong);
}

.sheet th.sortable {
  cursor: pointer;
  user-select: none;
}

.sheet th.sortable:hover {
  background: #ebe8e0;
}

.sheet th .sort-indicator {
  font-size: 10px;
  opacity: 0.85;
}

.sheet th.num.sortable {
  padding-right: 0.35rem;
}

.sheet td {
  background: #fff;
}

.sheet tbody tr:nth-child(even) td {
  background: var(--row-alt);
}

.sheet tbody tr:hover td {
  background: var(--row-hover);
}

.sheet tbody tr.has-tour td {
  background: var(--row-tour);
}

.sheet tbody tr.has-tour:hover td {
  background: #fef3c7;
}

.sheet tbody tr {
  cursor: pointer;
}

.sheet th.num,
.sheet td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.sheet td.wrap {
  white-space: normal;
  min-width: 140px;
  max-width: 220px;
}

.sheet td.tour-cell {
  font-size: 12px;
}

.sheet td.muted-cell {
  color: var(--muted);
}

.apt-link {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.transit.missing {
  color: var(--muted);
}

.error:empty,
.empty[hidden] {
  display: none;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 12px;
}

.sheet-error {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--grid);
}

.empty {
  padding: 1rem;
  text-align: center;
  color: var(--muted);
}

.preview {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--grid);
  font-size: 12px;
}

.detail-dialog:not([open]) {
  display: none;
}

.detail-dialog[open] {
  display: flex;
  flex-direction: column;
  width: min(820px, calc(100% - 2rem));
  max-height: calc(100% - 2rem);
  border: 1px solid var(--window-border);
  padding: 0;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 8px 32px rgb(0 0 0 / 18%);
}

.detail-dialog::backdrop {
  background: rgb(0 0 0 / 30%);
}

.detail-chrome {
  flex-shrink: 0;
  padding: 0.65rem 0.75rem 0.5rem;
  background: var(--chrome);
  border-bottom: 1px solid var(--grid);
}

#detail-body {
  flex: 1;
  min-height: 0;
  padding: 0.75rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
}

.detail {
  display: grid;
  gap: 0.65rem;
}

.detail-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.detail-header-top h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.detail-header-top button {
  margin: 0;
  flex-shrink: 0;
  min-height: 2.25rem;
  padding: 0.35rem 0.65rem;
}

.detail-meta {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 12px;
}

.detail-links a {
  color: var(--link);
}

.detail-galleries {
  display: grid;
  gap: 0.75rem;
}

.detail-gallery-section h4 {
  margin: 0 0 0.35rem;
  font-size: 11px;
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-gallery-section.is-compact h4 {
  margin-bottom: 0.25rem;
}

.detail-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}

.detail-gallery-compact {
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 4px;
}

.detail-gallery-compact .detail-gallery-thumb img {
  aspect-ratio: 1;
}

.detail-gallery-compact .detail-gallery-caption {
  font-size: 10px;
  padding: 0.15rem 0.25rem;
}

.detail-gallery-thumb {
  position: relative;
  display: block;
  padding: 0;
  border: 1px solid var(--grid);
  background: #fff;
  cursor: zoom-in;
  overflow: hidden;
  text-align: left;
}

.detail-gallery-thumb img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  vertical-align: middle;
}

.detail-gallery-thumb.is-floorplan img {
  aspect-ratio: auto;
  height: 280px;
  object-fit: contain;
  object-position: center;
  background: #f5f5f5;
}

.detail-gallery-compact .detail-gallery-thumb.is-floorplan img {
  height: 120px;
}

.detail-gallery-caption {
  display: block;
  padding: 0.25rem 0.35rem;
  font-size: 11px;
  line-height: 1.25;
  color: var(--muted);
  background: #fafafa;
  border-top: 1px solid var(--grid);
}

.photo-lightbox {
  position: relative;
  padding: 0;
  border: none;
  width: min(96vw, 1400px);
  max-height: 96vh;
  background: #000;
}

.photo-lightbox-stage {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.25rem 0.5rem;
}

.photo-lightbox::backdrop {
  background: rgb(0 0 0 / 85%);
}

.photo-lightbox-close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  margin: 0;
  z-index: 1;
}

.photo-lightbox-close button {
  color: #fff;
  background: rgb(0 0 0 / 50%);
  border-color: rgb(255 255 255 / 30%);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.15rem 0.45rem;
}

.photo-lightbox-figure {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.photo-lightbox img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: calc(96vh - 4rem);
  height: auto;
  object-fit: contain;
  object-position: center;
  margin: 0 auto;
}

.photo-lightbox-nav {
  flex-shrink: 0;
  width: 2.25rem;
  height: 3rem;
  padding: 0;
  font-size: 1.75rem;
  line-height: 1;
  color: #fff;
  background: rgb(255 255 255 / 12%);
  border: 1px solid rgb(255 255 255 / 25%);
}

.photo-lightbox-nav:hover:not(:disabled) {
  background: rgb(255 255 255 / 22%);
}

.photo-lightbox-nav:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.photo-lightbox-caption {
  margin: 0;
  padding: 0.45rem 0.75rem 0.15rem;
  color: #e5e5e5;
  font-size: 13px;
  text-align: center;
}

.photo-lightbox-counter {
  margin: 0;
  padding: 0 0.75rem 0.35rem;
  color: #a3a3a3;
  font-size: 12px;
  text-align: center;
}

.visit-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.visit-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--grid);
  background: #fafafa;
}

.visit-item-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  width: 100%;
}

.visit-item-inner .visit-when {
  flex: 1 1 auto;
  min-width: 0;
}

.visit-item-actions {
  flex-shrink: 0;
}

.visit-when {
  font-size: 13px;
}

.visit-action {
  font-size: 12px;
}

.visit-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.45rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--grid);
}

.visit-form label {
  display: grid;
  gap: 0.2rem;
}

.visit-form button[type="submit"] {
  align-self: end;
}

.detail-notes {
  width: 100%;
  min-height: 5rem;
  resize: vertical;
  font: inherit;
  font-size: 12px;
  line-height: 1.45;
  border: 1px solid var(--grid);
  padding: 0.45rem 0.5rem;
  background: #fff;
}

.notes-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.35rem;
}

.sheet col.pick-col {
  width: 9rem;
}

.sheet td.pick-cell,
.sheet thead th:nth-child(9),
.sheet thead th:nth-child(10),
.sheet thead th:nth-child(11),
.sheet thead th:nth-child(12) {
  min-width: 9rem;
  width: 9rem;
}

.sheet td.pick-cell {
  padding: 0.15rem 0.25rem;
  overflow: visible;
}

.sheet td.tour-cell {
  min-width: 8.5rem;
}

.sheet-select {
  display: block;
  width: 100%;
  min-width: 0;
  font-size: 12px;
  line-height: 1.3;
  padding: 0.2rem 1.6rem 0.2rem 0.3rem;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  box-shadow: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  appearance: auto;
  -webkit-appearance: menulist;
}

.sheet-select:hover,
.sheet-select:focus {
  border-color: var(--grid-strong);
  background: #fff;
}

.detail-section {
  padding-top: 0.5rem;
  border-top: 1px solid var(--grid);
}

.detail-section h3 {
  margin: 0 0 0.35rem;
  font-size: 11px;
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-copy {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.detail-actions {
  padding-top: 0.35rem;
  border-top: 1px solid var(--grid);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.4rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.meta-line {
  color: var(--muted);
  font-size: 12px;
}

.sheet th:first-child,
.sheet td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  box-shadow: 1px 0 0 var(--grid);
}

.sheet thead th:first-child {
  z-index: 3;
  background: var(--header-bg);
}

.sheet td:first-child {
  background: #fff;
}

.sheet tbody tr:nth-child(even) td:first-child {
  background: var(--row-alt);
}

.sheet tbody tr:hover td:first-child {
  background: var(--row-hover);
}

.sheet tbody tr.has-tour td:first-child {
  background: var(--row-tour);
}

.sheet tbody tr.has-tour:hover td:first-child {
  background: #fef3c7;
}

@media (max-width: 720px) {
  .sheet-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .sheet-header-actions {
    margin-left: 0;
    flex-wrap: wrap;
  }

  .sheet-toolbar {
    padding: 0.35rem 0.5rem;
  }

  .sheet td.wrap {
    min-width: 8rem;
    max-width: none;
  }

  .detail-dialog[open] {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100dvh;
    margin: 0;
    border: none;
  }

  .detail-chrome {
    padding: max(0.65rem, env(safe-area-inset-top)) 0.65rem 0.5rem;
  }

  #detail-body {
    padding: 0.65rem;
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
  }

  .detail-header-top h2 {
    font-size: 14px;
    -webkit-line-clamp: 3;
  }

  .detail-gallery {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .detail-gallery-thumb.is-floorplan img {
    height: 200px;
  }

  .visit-item,
  .visit-item-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .visit-item-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .visit-form {
    grid-template-columns: 1fr;
  }

  .photo-lightbox {
    width: 100%;
    max-height: 100dvh;
    height: 100dvh;
  }

  .photo-lightbox img {
    max-height: calc(100dvh - 5.5rem);
  }

  .sheet-select {
    padding-right: 1.75rem;
  }

  .sheet td.pick-cell,
  .sheet thead th:nth-child(9),
  .sheet thead th:nth-child(10),
  .sheet thead th:nth-child(11),
  .sheet thead th:nth-child(12) {
    min-width: 10rem;
    width: 10rem;
  }
}

@media (max-width: 480px) {
  .detail-gallery-compact {
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  }
}
