:root {
  --c-deep-purple:  #29003e;
  --c-core-purple:  #990ae3;
  --c-light-purple: #f4e0ff;
  --c-light-beige:  #f8eee8;
  --c-white:        #ffffff;

  --c-text:         var(--c-deep-purple);
  --c-muted:        #6f6675;
  --c-divider:      rgba(41, 0, 62, 0.10);
  --c-shadow:       rgba(41, 0, 62, 0.18);
  --c-shadow-soft:  rgba(41, 0, 62, 0.08);
  --c-backdrop:     rgba(41, 0, 62, 0.45);

  --font-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-base);
  color: var(--c-text);
}

.app {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

#viewDiv {
  position: absolute;
  inset: 0;
}

.esri-ui {
  opacity: 0;
  transition: opacity 200ms ease;
}
.esri-ui.ready { opacity: 1; }

.ui-top {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
  z-index: 5;
}

.search-container {
  position: relative;
  pointer-events: auto;
  flex: 0 1 360px;
  max-width: 360px;
  height: 48px;
  background: var(--c-white) !important;
  border: 1px solid rgba(0, 0, 0, 0.33) !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.10) !important;
  overflow: visible !important;
}

.search-container .esri-search__submit-button,
.search-container .esri-search__clear-button,
.search-container .esri-search__warning-menu {
  display: none !important;
}

.search-container .esri-search__container,
.search-container .esri-search__form {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  height: 100% !important;
  width: 100% !important;
  padding: 0 !important;
}

.search-container calcite-autocomplete {
  width: 100% !important;

  --calcite-font-size-0: 14px;
  --calcite-font-size--1: 14px;

  --calcite-autocomplete-input-background-color: var(--c-white);
  --calcite-autocomplete-input-border-color: transparent;
  --calcite-autocomplete-input-corner-radius: 8px;
  --calcite-autocomplete-input-text-color: rgba(0, 0, 0, 0.80);
  --calcite-autocomplete-input-placeholder-text-color: rgba(0, 0, 0, 0.62);
  --calcite-autocomplete-input-icon-color: rgba(0, 0, 0, 0.80);
  --calcite-autocomplete-input-shadow: none;

  --calcite-autocomplete-input-actions-icon-color: rgba(0, 0, 0, 0.80);
  --calcite-autocomplete-input-actions-icon-color-hover: rgba(0, 0, 0, 0.80);
  --calcite-autocomplete-input-actions-icon-color-press: rgba(0, 0, 0, 0.80);
  --calcite-autocomplete-input-actions-background-color: var(--c-white);
  --calcite-autocomplete-input-actions-background-color-hover: #f2f2f2;
  --calcite-autocomplete-input-actions-background-color-press: #ebebeb;

  --calcite-autocomplete-background-color: var(--c-white);
  --calcite-autocomplete-corner-radius: 8px;
  --calcite-autocomplete-text-color: var(--c-deep-purple);
  --calcite-autocomplete-description-text-color: rgba(0, 0, 0, 0.62);
  --calcite-autocomplete-heading-text-color: var(--c-deep-purple);

  --calcite-color-foreground-2: var(--c-light-purple);

  --calcite-color-focus: transparent;
  --calcite-ui-focus-color: transparent;
  --calcite-internal-color-focus: transparent;
  --calcite-color-brand: transparent;
}

.search-container calcite-autocomplete-item {
  --calcite-autocomplete-text-color: var(--c-deep-purple);
  --calcite-autocomplete-description-text-color: rgba(0, 0, 0, 0.62);
  --calcite-color-foreground-2: var(--c-light-purple);
  --calcite-color-brand: var(--c-core-purple);
}

.duk-button {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--c-white);
  color: var(--c-deep-purple);
  border: 1px solid rgba(41, 0, 62, 0.15);
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--c-shadow-soft);
  flex: 0 0 auto;
  transition: background 120ms ease;
}

.duk-button:hover  { background: var(--c-light-purple); }
.duk-button:active { transform: translateY(1px); }
.duk-button:focus-visible {
  outline: 2px solid var(--c-core-purple);
  outline-offset: 2px;
}

.duk-button__icon {
  width: 18px; height: 18px;
  display: inline-flex;
  align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--c-core-purple);
  color: var(--c-white);
  font-size: 12px;
  font-weight: 700;
}

.custom-popup {
  position: absolute;
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--c-light-beige);
  border-radius: 12px;
  box-shadow: 0 10px 28px var(--c-shadow);
  font-size: 14px;
  line-height: 1.45;
  z-index: 6;
  pointer-events: auto;
  transform: translate(-50%, calc(-100% - 42px));
}

.custom-popup__title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 16px 14px;
  background: var(--c-white);
  color: var(--c-deep-purple);
}

.custom-popup__title-text {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.custom-popup__close {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  color: var(--c-deep-purple);
  padding: 0 2px;
  border-radius: 4px;
}
.custom-popup__close:hover { background: var(--c-light-purple); }
.custom-popup__close:focus-visible {
  outline: 2px solid var(--c-core-purple);
  outline-offset: 2px;
}

.popup__section { padding: 16px; }
.popup__section + .popup__section {
  border-top: 1px solid var(--c-divider);
}

.popup__section + .popup__section--joined {
  border-top: 0;
  padding-top: 0;
}

.custom-popup__empty {
  position: relative;
  padding: 36px 20px 32px;
  text-align: center;
}

.custom-popup__empty .custom-popup__close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.custom-popup__empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--c-white);
  border: 2px solid var(--c-deep-purple);
  color: var(--c-deep-purple);
  font-size: 18px;
  font-weight: 700;
}

.custom-popup__empty-text {
  color: var(--c-deep-purple);
  font-size: 14px;
  font-weight: 600;
}

.popup__section-title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--c-deep-purple);
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.row:last-child { margin-bottom: 0; }

.row__icon {
  flex: 0 0 22px;
  width: 22px; height: 22px;
  color: var(--c-deep-purple);
  margin-top: 1px;
}

.row__body { flex: 1; }
.row__label { font-weight: 700; color: var(--c-deep-purple); }
.row__values { margin-top: 2px; }
.row__value-line { display: block; color: var(--c-deep-purple); }

.loading {
  padding: 28px 16px;
  text-align: center;
  color: var(--c-muted);
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--c-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 10;
}

.modal-backdrop[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--c-white);
  border-radius: 14px;
  box-shadow: 0 20px 48px var(--c-shadow);
  overflow: hidden;
  transform: translateY(8px);
  transition: transform 160ms ease;
}

.modal-backdrop[data-open="true"] .modal { transform: translateY(0); }

.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 12px;
}

.modal__title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--c-deep-purple);
  line-height: 1.3;
}

.modal__close {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  color: var(--c-deep-purple);
  padding: 0 4px;
  border-radius: 4px;
}
.modal__close:hover { background: var(--c-light-purple); }
.modal__close:focus-visible {
  outline: 2px solid var(--c-core-purple);
  outline-offset: 2px;
}

.faq-list {
  list-style: none;
  margin: 0;
  padding: 0 0 8px;
}

.faq-list li { border-top: 1px solid var(--c-divider); }

.faq-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  color: var(--c-core-purple);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.faq-list a:hover {
  background: var(--c-light-purple);
  color: var(--c-deep-purple);
}

.faq-list a:focus-visible {
  outline: 2px solid var(--c-core-purple);
  outline-offset: -2px;
}

.faq-list__arrow {
  flex: 0 0 auto;
  width: 16px; height: 16px;
}

.boot-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--c-light-beige);
  color: var(--c-deep-purple);
  text-align: center;
  font-size: 14px;
  z-index: 20;
}

[hidden] { display: none !important; }

/* Pin the map attribution to the actual bottom of the map container
   regardless of view.padding.bottom. We intentionally leave view.padding
   set after the popup closes to prevent the map re-centering (jumping),
   but Esri's default attribution respects view.padding and floats up
   into the middle of the screen on mobile. z-index below .custom-popup
   (which is 6) so the popup covers it when open — matching "popup above
   attribution" behavior. */
#viewDiv .esri-ui {
  contain: none !important;
}

#viewDiv .esri-attribution {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  top: auto !important;
  z-index: 1 !important;
}

@media (max-width: 720px) {
  .ui-top { flex-wrap: nowrap; }
  .search-container { flex: 1 1 auto; }
  .duk-button { padding: 9px 12px; font-size: 13px; }

  .custom-popup {
    position: fixed;
    inset: auto 0 0 0;
    top: auto;
    left: 0;
    width: 100%;
    max-width: 100%;
    max-height: 70vh;
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    transform: none;
  }
}
