:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --panel-soft: #f8faf9;
  --text: #20272b;
  --muted: #68737a;
  --line: #dce3e6;
  --accent: #0b7f79;
  --accent-strong: #05645f;
  --danger: #b42318;
  --danger-bg: #fff0ed;
  --warning: #c47a16;
  --good: #2f855a;
  --shadow: 0 18px 50px rgba(25, 35, 40, 0.18);
  --radius: 8px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  position: relative;
}

.map {
  position: absolute;
  inset: 0;
  background: #d8e2de;
}

.topbar {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px;
  border: 1px solid rgba(220, 227, 230, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 30px rgba(25, 35, 40, 0.12);
  backdrop-filter: blur(12px);
}

.brand {
  min-width: 0;
  padding-left: 4px;
}

.brand__title,
.brand__count {
  display: block;
  white-space: nowrap;
}

.brand__title {
  overflow: hidden;
  max-width: 34vw;
  text-overflow: ellipsis;
  font-size: 16px;
  font-weight: 750;
}

.brand__count {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.topbar__actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.button--light {
  border-color: var(--line);
  background: var(--panel);
}

.button--accent {
  background: var(--accent);
  color: #fff;
}

.button--danger {
  border-color: #f1c5bd;
  background: var(--danger-bg);
  color: var(--danger);
}

.button:active,
.icon-button:active {
  transform: translateY(1px);
}

.icon-button {
  display: inline-grid;
  flex: 0 0 auto;
  width: 40px;
  place-items: center;
  border-color: var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 26px;
  line-height: 1;
}

.placement-banner {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 68px);
  left: 50%;
  z-index: 520;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  padding: 8px 8px 8px 14px;
  border: 1px solid #d4c58a;
  border-radius: var(--radius);
  background: #fff8d8;
  box-shadow: 0 10px 30px rgba(25, 35, 40, 0.14);
  color: #4d3f08;
  transform: translateX(-50%);
}

.placement-banner span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel,
.sheet {
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel--left {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 68px);
  left: max(12px, env(safe-area-inset-left));
  z-index: 540;
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 24px));
  max-height: calc(100dvh - 96px - env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.panel__head h2 {
  margin: 0;
  font-size: 18px;
}

.add-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.add-form input,
.details input,
.details textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
}

.add-form input,
.details input {
  height: 42px;
  padding: 0 10px;
}

.details textarea {
  display: block;
  min-height: 74px;
  padding: 10px;
  resize: vertical;
}

.add-form input:focus,
.details input:focus,
.details textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 127, 121, 0.14);
}

.apartment-list {
  overflow: auto;
  padding: 6px;
}

.apartment-item {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 12px;
  width: 100%;
  min-height: 90px;
  padding: 9px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.apartment-item + .apartment-item {
  margin-top: 4px;
}

.apartment-item.is-selected {
  border-color: rgba(11, 127, 121, 0.35);
  background: #edf8f6;
}

.apartment-item__score {
  display: grid;
  width: 78px;
  height: 72px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
}

.apartment-item__score.is-draft {
  background: #5d6971;
}

.apartment-item__score.is-low {
  background: var(--danger);
}

.apartment-item__score.is-mid {
  background: var(--warning);
}

.apartment-item__preview {
  position: relative;
  overflow: hidden;
  width: 78px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.apartment-item__preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.apartment-item__preview-score {
  position: absolute;
  right: 6px;
  bottom: 6px;
  min-width: 30px;
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  background: rgba(17, 24, 28, 0.78);
  color: #fff;
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
  text-align: center;
}

.apartment-item__body {
  min-width: 0;
}

.apartment-item__title,
.apartment-item__meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.apartment-item__title {
  font-weight: 750;
}

.apartment-item__meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 530;
  display: flex;
  max-height: min(76dvh, 760px);
  flex-direction: column;
  border-top: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.sheet--empty {
  max-height: 112px;
}

.sheet__handle {
  flex: 0 0 auto;
  width: 44px;
  height: 4px;
  margin: 9px auto 2px;
  border-radius: 999px;
  background: #c9d1d5;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 12px 18px 20px;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
}

.details {
  overflow: auto;
  padding: 0 14px 14px;
}

.details__head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  padding-top: 4px;
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.title-input {
  font-size: 18px;
  font-weight: 780;
}

.score-block {
  margin-top: 4px;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr 74px;
  gap: 10px;
  align-items: center;
}

.score-row input[type="range"] {
  height: 42px;
  padding: 0;
  accent-color: var(--accent);
}

.score-input {
  text-align: center;
  font-weight: 800;
}

.details__actions,
.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 10px;
}

.photos {
  margin-top: 12px;
  padding-top: 2px;
}

.photos__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.photos__head h3 {
  margin: 0;
  font-size: 16px;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.photo-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.photo-card {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.photo-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-card button {
  position: absolute;
  top: 6px;
  right: 6px;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid rgba(180, 35, 24, 0.25);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.photo-empty {
  min-height: 88px;
  padding: 18px;
  border: 1px dashed #c5d0d5;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.save-status,
.dialog__status {
  min-height: 20px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.dialog {
  width: min(420px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(22, 30, 34, 0.42);
}

.fatal-error {
  position: fixed;
  top: max(90px, calc(env(safe-area-inset-top) + 90px));
  left: 50%;
  z-index: 1000;
  display: grid;
  gap: 6px;
  width: min(420px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid #f1c5bd;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--text);
  transform: translateX(-50%);
}

.fatal-error span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.dialog__body {
  margin: 0;
  padding: 0 14px 14px;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.flat-marker {
  position: relative;
  display: block;
  width: 84px;
  height: 84px;
  border: 2px solid #fff;
  border-radius: var(--radius);
  background: var(--accent);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
  color: #fff;
}

.flat-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -10px;
  z-index: 0;
  width: 18px;
  height: 18px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
}

.flat-marker__photo {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  object-fit: cover;
}

.flat-marker.has-photo.has-badge::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 38%, rgba(0, 0, 0, 0.72) 100%);
}

.flat-marker__inner {
  position: relative;
  z-index: 3;
  display: grid;
  width: 100%;
  height: 100%;
  align-content: center;
  place-items: center;
  padding: 8px;
  line-height: 1;
}

.flat-marker.has-photo .flat-marker__inner {
  align-content: end;
  justify-items: end;
}

.flat-marker__score {
  font-size: 18px;
  font-weight: 850;
}

.flat-marker__notes {
  margin-top: 3px;
  font-size: 11px;
  font-weight: 800;
}

.flat-marker.has-photo .flat-marker__score,
.flat-marker.has-photo .flat-marker__notes {
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  background: rgba(17, 24, 28, 0.76);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
}

.flat-marker.has-photo .flat-marker__score {
  min-width: 34px;
  padding: 5px 7px;
  text-align: center;
}

.flat-marker.has-photo .flat-marker__notes {
  padding: 4px 6px;
}

.flat-marker.is-draft {
  background: #5d6971;
}

.flat-marker.is-low {
  background: var(--danger);
}

.flat-marker.is-mid {
  background: var(--warning);
}

.flat-marker.is-selected {
  outline: 3px solid rgba(11, 127, 121, 0.35);
  outline-offset: 4px;
}

@media (max-width: 430px) {
  .topbar {
    align-items: stretch;
  }

  .brand__title {
    max-width: 28vw;
    font-size: 14px;
  }

  .topbar__actions {
    gap: 4px;
  }

  .button {
    min-height: 38px;
    padding: 0 9px;
    font-size: 13px;
  }

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

@media (max-width: 360px) {
  .brand__title {
    display: none;
  }

  .brand__count {
    max-width: 70px;
    white-space: normal;
  }

  .button {
    padding: 0 7px;
    font-size: 12px;
  }
}

@media (min-width: 680px) {
  .field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .photo-gallery {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .topbar {
    right: auto;
    width: min(620px, calc(100vw - 470px));
  }

  .sheet {
    top: calc(max(12px, env(safe-area-inset-top)) + 68px);
    right: 16px;
    bottom: 16px;
    left: auto;
    width: 430px;
    max-height: none;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding-bottom: 0;
  }

  .sheet--empty {
    max-height: 146px;
  }

  .details {
    padding-bottom: 16px;
  }

  .photo-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
