* {
  box-sizing: border-box;
}

:root {
  --color-primary: #ec5d8c;
  --color-secondary: #f8bc52;
  --color-neutral: #004867;

  --color-text-placeholder: #767676;

  --space: 12px;
  --clear-button-height: 30px;
  --radius-sm: 8px;
  --radius-lg: 20px;

  --text-sm: 0.75rem;
}

html,
body,
.page,
#map {
  height: 100%;
  margin: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.is-chat-typing {
  overflow: hidden;
}

.page {
  position: relative;
  overflow: hidden;
}

.spot-panel {
  border-radius: var(--radius-lg);
  background: var(--spot-panel-background, rgba(255, 255, 255, 0.5));
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.30);
  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
}

.spot-soft-panel {
  border-radius: var(--radius-lg);
  background: var(--spot-panel-background, rgba(255, 255, 255, 0.72));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10);
  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
}

.spot-logo {
  position: absolute;
  z-index: 1000;
  top: var(--space);
  right: var(--space);
  width: 70px;
  height: auto;
  pointer-events: none;
}

.chat-panel {
  position: absolute;
  z-index: 1000;
  top: var(--space);
  bottom: var(--space);
  left: var(--space);
  width: 300px;
  display: flex;
  flex-direction: column;
  padding: var(--space);
}

.listings-panel {
  position: absolute;
  z-index: 1000;
  top: var(--space);
  bottom: var(--space);
  right: var(--space);
  width: 370px;
  display: flex;
  flex-direction: column;
  padding: var(--space);
}

.listings-panel[hidden] {
  display: none;
}

.listings-tray-handle {
  display: none;
}

.clear-history-button {
  --spot-panel-background: rgba(255, 255, 255, 0.72);

  min-height: var(--clear-button-height);
  padding: 8px 16px;
  border: none;
  color: #000000;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
}

.clear-history-button:hover,
.clear-history-button:focus {
  background: rgba(255, 255, 255, 0.86);
}

.clear-history-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  margin-bottom: var(--space);
}

.listings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space);
  margin-bottom: var(--space);
}

.spot-label {
  width: auto;
  color: #000000;
  font: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: right;
}

.listing-sort-controls {
  display: flex;
  gap: 6px;
}

.listing-sort-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  padding: 7px 9px;
  border: none;
  color: #000000;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
}

.listing-sort-button-top-five {
  min-width: 72px;
}

.listing-sort-logo {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex: 0 0 auto;
}

.listing-sort-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.48);
  border-top-color: #ffffff;
  border-radius: 50%;
  flex: 0 0 auto;
  animation: chat-loading-spin 0.8s linear infinite;
}

.listing-sort-button.is-loading .listing-sort-logo {
  display: none;
}

.listing-sort-button.is-loading .listing-sort-spinner {
  display: block;
}

.listing-sort-button:hover,
.listing-sort-button:focus {
  --spot-panel-background: rgba(255, 255, 255, 0.9);
}

.listing-sort-button.is-active {
  --spot-panel-background: var(--color-neutral);
  color: #ffffff;
}

.listing-sort-button-top-five.is-active {
  --spot-panel-background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: #ffffff;
}

.chat-history {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.chat-message {
  max-width: 85%;
  margin: 0 var(--space) calc(var(--space) / 2) 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: var(--text-sm);
  word-break: break-word;
}

.chat-message-user {
  align-self: flex-end;
  background: var(--color-neutral);
}

.chat-message-response {
  align-self: flex-start;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
}

.chat-empty-state {
  max-width: 85%;
  margin: 0 var(--space) calc(var(--space) / 2) 0;
  color: var(--color-text-placeholder);
  font-size: var(--text-sm);
  line-height: 1.35;
  white-space: pre-line;
}

.chat-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 var(--space) calc(var(--space) / 2) 0;
  color: #767676;
  font-size: var(--text-sm);
}

.chat-loading-wheel {
  width: 14px;
  height: 14px;
  border: 2px solid #c6c6c6;
  border-top-color: #767676;
  border-radius: 50%;
  animation: chat-loading-spin 0.8s linear infinite;
}

@keyframes chat-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.chat-panel form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: var(--space);
}

#chatInput {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  max-height: 200px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: #dddddd;
  color: inherit;
  font: inherit;
  font-size: var(--text-sm);
  line-height: 1.25;
  outline: none;
  resize: none;
  overflow-y: auto;
  field-sizing: content;
}

#chatInput:disabled {
  cursor: wait;
  opacity: 0.72;
}

#chatInput::placeholder {
  color: var(--color-text-placeholder);
}

.search-button {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 31px;
  height: 31px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--color-neutral);
  color: #ffffff;
  cursor: pointer;
}

.search-button:hover,
.search-button:focus {
  background: #00638c;
}

.search-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.search-button-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.feedback-link {
  align-self: center;
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-neutral);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
}

.feedback-link:disabled {
  cursor: default;
}

.feedback-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: var(--space);
  border: 0;
  border-radius: var(--radius-sm);
}

.feedback-dialog::backdrop {
  background: rgba(0, 0, 0, 0.38);
}

.chat-panel .feedback-form {
  display: block;
  margin: 0;
}

#feedbackInput {
  width: 100%;
  min-height: 160px;
  padding: 10px;
  border: 1px solid #c6c6c6;
  border-radius: var(--radius-sm);
  font: inherit;
  resize: vertical;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: var(--space);
}

.feedback-action {
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
}

.feedback-submit {
  background: var(--color-neutral);
  color: #ffffff;
}

.listings-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  margin: -8px;
  padding: 8px 12px 8px 8px;
}

.property-pin {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: max-content;
  min-width: 48px;
  height: 28px;
  margin: 0 auto;
  padding: 0 10px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  color: #111111;
  font-size: 13px;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
}

.property-pin.is-selected {
  border-color: var(--color-neutral);
  background: var(--color-neutral);
  color: #ffffff;
}

.property-pin.is-ranked:not(.is-selected) {
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: #ffffff;
}

.property-pin::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 18px;
  height: 18px;
  border-right: 2px solid #ffffff;
  border-bottom: 2px solid #ffffff;
  background: #ffffff;
  transform: translateX(-50%) rotate(45deg);
  transform-origin: center;
}

.property-pin.is-selected::after {
  border-right-color: var(--color-neutral);
  border-bottom-color: var(--color-neutral);
  background: var(--color-neutral);
}

.property-pin.is-ranked:not(.is-selected)::after {
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
}

.property-pin span {
  position: relative;
  z-index: 1;
}

@media (max-width: 840px) {
  html,
  body,
  .page,
  #map {
    height: 100dvh;
  }

  .page {
    --mobile-listings-anchored-height: clamp(220px, 36dvh, 420px);
    --mobile-listings-collapsed-height: 84px;
    --mobile-listings-expanded-height: calc(100dvh - 150px);
    --mobile-listings-current-height: var(--mobile-listings-anchored-height);
  }

  .spot-logo {
    display: none;
  }

  .chat-panel {
    top: var(--space);
    bottom: auto;
    left: var(--space);
    right: var(--space);
    width: auto;
    min-height: 0;
    max-height: calc(100dvh - var(--mobile-listings-current-height) - (var(--space) * 3));
    transition: border-radius 0.16s ease, height 0.16s ease, max-height 0.16s ease, top 0.16s ease;
  }

  .page:has(.listings-panel[hidden]) .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) {
    max-height: calc(100dvh - (var(--space) * 2));
  }

  .chat-panel:is(.is-typing, :has(#chatInput:not(:disabled):focus-within)) {
    position: fixed;
    z-index: 1100;
    top: var(--chat-viewport-top, 0px);
    right: 0;
    bottom: auto;
    left: 0;
    width: auto;
    height: var(--chat-viewport-height, 100dvh);
    max-height: var(--chat-viewport-height, 100dvh);
    border-radius: 0;
    overflow: hidden;
    padding:
      max(var(--space), env(safe-area-inset-top))
      max(var(--space), env(safe-area-inset-right))
      max(var(--space), env(safe-area-inset-bottom))
      max(var(--space), env(safe-area-inset-left));
  }

  .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) .chat-header {
    display: none;
  }

  .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) .chat-history {
    flex: 0 0 auto;
    max-height: min(24dvh, 180px);
    overflow-y: auto;
  }

  .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) .chat-history:empty {
    display: none;
  }

  .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) .chat-history.is-empty {
    max-height: none;
  }

  .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) .chat-history > :not(:last-child) {
    display: none;
  }

  .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) .chat-message {
    max-width: 100%;
    margin-right: 0;
    margin-bottom: 0;
  }

  .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) .chat-loading {
    margin-right: 0;
    margin-bottom: 0;
  }

  .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) .chat-empty-state {
    max-width: 100%;
    margin-right: 0;
    margin-bottom: 0;
  }

  .chat-panel:not(.is-typing):not(:has(#chatInput:not(:disabled):focus-within)) .chat-history:empty + form {
    margin-top: 0;
  }

  .listings-panel {
    top: auto;
    bottom: var(--space);
    left: var(--space);
    right: var(--space);
    width: auto;
    height: var(--mobile-listings-current-height);
    min-height: 0;
    overflow: hidden;
    transition: height 0.18s ease, border-radius 0.18s ease;
    will-change: height;
  }

  .listings-panel.is-tray-collapsed {
    --mobile-listings-current-height: var(--mobile-listings-collapsed-height);
  }

  .listings-panel.is-tray-anchored {
    --mobile-listings-current-height: var(--mobile-listings-anchored-height);
  }

  .listings-panel.is-tray-expanded {
    --mobile-listings-current-height: var(--mobile-listings-expanded-height);
  }

  .listings-panel.is-tray-dragging {
    --mobile-listings-current-height: var(--mobile-listings-drag-height);
    transition: none;
  }

  .listings-tray-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 20px;
    margin: -4px 0 4px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: grab;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  .listings-panel.is-tray-dragging .listings-tray-handle {
    cursor: grabbing;
  }

  .listings-tray-handle span {
    display: block;
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: rgba(0, 72, 103, 0.34);
  }

  .listings-tray-handle:hover span,
  .listings-tray-handle:focus span {
    background: rgba(0, 72, 103, 0.52);
  }

  .listings-header {
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    margin-bottom: 8px;
    touch-action: none;
    user-select: none;
  }

  .listings-panel.is-tray-collapsed .listings-header {
    margin-bottom: 0;
  }

  .listings-panel.is-tray-collapsed .listings-grid {
    display: none;
  }

  #listingsTitle {
    flex: 0 0 auto;
    line-height: 1;
    text-align: left;
    white-space: nowrap;
  }

  .listing-sort-controls {
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
  }

  .listing-sort-button {
    flex: 0 1 auto;
    min-width: 0;
  }

  .listings-grid {
    margin: 0 -8px -8px -8px;
  }

  .chat-history,
  .listings-grid {
    -webkit-overflow-scrolling: touch;
  }

  #chatInput {
    font-size: 16px;
    max-height: 96px;
  }

  .feedback-dialog {
    width: calc(100vw - 24px);
    max-width: none;
  }

  #feedbackInput {
    min-height: calc(100dvh - 170px);
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .listings-header {
    align-items: center;
    flex-wrap: nowrap;
  }

  .listing-sort-controls {
    width: auto;
    flex-wrap: nowrap;
  }

  .listing-sort-button {
    flex: 0 1 auto;
    min-width: 0;
  }
}
