/* global styles */

:root {
  /* Chrome-only for now but this will allow smooth size transitions */
  interpolate-size: allow-keywords;

  --accent-color: #2ec6fe;
}

html {
  box-sizing: border-box;
}

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

body {
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0;
  background-color: #f0f0f0;
  color: #303030;

  font-family: Futura, "Trebuchet MS", Arial, sans-serif;
  font-style: normal;
  font-variant: normal;
}

/* Dynamic viewport (mobile URL bar); falls back to 100vh in .u-fill-height */
@supports (height: 100dvh) {
  body.u-fill-height {
    height: 100dvh;
    min-height: 100dvh;
  }
}

footer,
header {
  flex: 0;
  min-height: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  background: #3d2914;
  color: #f5e6d3;

  img {
    max-height: 40px;
    margin: 0 0.5em;
  }

  h1 {
    flex: 1;
    margin-right: 50px;
    text-align: center;
  }

  a,
  a:visited {
    color: #f0c96a;
    text-decoration: underline;
  }
}

header#main-head {
  justify-content: space-between;
  align-items: center;
  padding: 0 max(8px, env(safe-area-inset-left, 0px)) 0
    max(8px, env(safe-area-inset-right, 0px));
  padding-top: max(0px, env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--accent-color);
}

#main-head h1 {
  margin-right: 0;
}

#main-head burger-menu {
  flex: 0 0 auto;
  margin-left: auto;
}

h1,
h2,
h3,
h4 {
  font-family:
    Futura, "Century Gothic", "Trebuchet MS", "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-weight: 700;
  font-variant: normal;
}

/* Exclude img so `header > img { display: none }` can hide #logo on small screens */
#main-head > :not(img) {
  display: flex;
  flex-direction: row;
  align-items: center;
}

#logo {
  height: 40px;
  margin: 0 10px 0 5px;
}

#main-foot {
  border-top: 1px solid var(--accent-color);
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  padding-left: max(8px, env(safe-area-inset-left, 0px));
  padding-right: max(8px, env(safe-area-inset-right, 0px));
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  min-height: calc(50px + env(safe-area-inset-bottom, 0px));
  height: auto;
  text-align: center;
  font-size: clamp(0.8125rem, 2.8vw, 1rem);
}

main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 80vh;
  max-width: 100vw;
  overflow: hidden;

  padding: 8px;
  overflow-y: auto;
  background-color: #fafafa;
}

@supports (height: 100dvh) {
  main {
    min-height: 80dvh;
  }
}

/* Stand Your Grounds — map shell */
.map-app {
  position: relative;
  flex: 1 1 auto;
  min-height: min(70vh, 560px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
}

@supports (height: 100dvh) {
  .map-app {
    min-height: min(70dvh, 560px);
  }
}

.map-app__error {
  flex: 0 0 auto;
  margin: 0 0 8px;
  padding: 10px 12px;
  border-radius: 6px;
  background: #ffe8e8;
  color: #5c1010;
  font-size: 0.9rem;
  line-height: 1.4;
  text-align: left;
}

.map-app__canvas {
  flex: 1 1 auto;
  min-height: min(65vh, 520px);
  width: 100%;
  border-radius: 8px;
  border: 1px solid #ccc;
  overflow: hidden;
  background: #e8e8e8;
}

@supports (height: 100dvh) {
  .map-app__canvas {
    min-height: min(58dvh, 520px);
  }
}

.map-app__map-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: min(65vh, 520px);
  width: 100%;
  display: flex;
  flex-direction: column;
}

@supports (height: 100dvh) {
  .map-app__map-shell {
    min-height: min(58dvh, 520px);
  }
}

.map-app__map-shell > .map-app__canvas {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.map-app__nearby-wrap {
  position: absolute;
  z-index: 15;
  top: max(12px, env(safe-area-inset-top, 0px));
  left: max(12px, env(safe-area-inset-left, 0px));
  display: flex;
  max-width: min(280px, calc(100% - 24px));
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}

.map-app__nearby-wrap .map-app__nearby-btn,
.map-app__nearby-wrap .map-app__geo-status {
  pointer-events: auto;
}

.map-app__nearby-btn.btn {
  padding: 0.45em 1.1em;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  font-variant: normal;
  font-weight: 600;
  font-size: 0.9rem;

  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    background-color: #f0e0e4;
  }
}

.map-app__geo-status {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: rgba(250, 250, 250, 0.96);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  font-size: 0.85rem;
  line-height: 1.35;
  color: #303030;
}

/* Shop detail popup (light DOM, above map) */
.shop-popup {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.shop-popup:not(.u-hidden) {
  pointer-events: auto;
}

.shop-popup__inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.shop-popup__backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.shop-popup__panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  max-height: min(72vh, 520px);
  overflow-y: auto;
  margin: 0 8px max(12px, env(safe-area-inset-bottom, 0px));
  padding: 12px 16px 16px;
  border-radius: 12px 12px 0 0;
  border-top: 3px solid var(--accent-color);
  background: #fafafa;
  color: #303030;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
  text-align: left;
}

.shop-popup__close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  color: #303030;
}

.shop-popup__close:focus-visible {
  outline: var(--accent-color) auto 2px;
  outline-offset: 2px;
}

.shop-popup__title-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 44px 8px 0;
}

.shop-popup__title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.75;
}

.shop-popup__favorite {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 6px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #6b4c30;
  cursor: pointer;
  transition:
    color 0.15s ease,
    transform 0.1s ease;
}

.shop-popup__favorite:hover {
  color: #e53935;
  transform: scale(1.1);
}

.shop-popup__favorite:focus-visible {
  outline: var(--accent-color) auto 2px;
  outline-offset: 2px;
}

.shop-popup__favorite--active {
  color: #e53935;
}

.shop-popup__favorite-icon {
  width: 100%;
  height: 100%;
}

.shop-popup__summary {
  margin: 0 0 10px;
  font-size: 0.95rem;
  line-height: 1.45;
  font-family: Futura, "Trebuchet MS", Arial, sans-serif;
  font-variant: normal;
}

.shop-popup__values {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 10px;
  font-size: 0.8125rem;
}

.shop-popup__value-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.shop-popup__value {
  padding: 2px 8px;
  border-radius: 4px;
  border-left: 3px solid var(--clr-accent-bg, #f0ebe3);
  background: var(--clr-accent-bg, #f0ebe3);
  white-space: nowrap;
}

.shop-popup__value[data-category="ownership"] {
  border-left-color: #c8872a;
}

.shop-popup__value[data-category="safety"] {
  border-left-color: #2a9d8f;
}

.shop-popup__value[data-category="ethics"] {
  border-left-color: #457b9d;
}

.shop-popup__value[data-category="dietary"] {
  border-left-color: #9b5de5;
}

.shop-popup__links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.shop-popup__link {
  font-size: 0.875rem;
  color: #3d2914;
  text-decoration: underline;
}

.shop-popup__link:visited {
  color: #5a3e28;
}

.shop-popup__link:hover,
.shop-popup__link:focus-visible {
  color: #2ec6fe;
}

.shop-popup__subhead {
  margin: 12px 0 6px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b4c30;
}

.shop-popup__google-body {
  font-size: 0.9rem;
  line-height: 1.45;
}

.shop-popup__google-body a {
  color: #3d2914;
  text-decoration: underline;
}

.shop-popup__google-body a:hover,
.shop-popup__google-body a:focus-visible {
  color: #2ec6fe;
}

.shop-popup__google-body p {
  margin: 0 0 6px;
}

.shop-popup__google-body ul {
  margin: 4px 0 0;
  padding-left: 1.2rem;
}

.shop-popup__hours-today {
  margin: 0 0 6px;
  font-size: 0.9rem;
}

.shop-popup__hours-next {
  margin: 2px 0 6px;
  font-size: 0.82rem;
  color: #6b4c30;
  font-style: italic;
}

.shop-popup__status {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: baseline;
}

.shop-popup__status--open {
  background: #d4edda;
  color: #1b5e20;
}

.shop-popup__status--closed {
  background: #f0d0d0;
  color: #8b1a1a;
}

.shop-popup__status--opening-soon {
  background: #fff3cd;
  color: #7a5d00;
}

.shop-popup__status--closing-soon {
  background: #fff3cd;
  color: #7a5d00;
}

.shop-popup__loading,
.shop-popup__muted {
  color: #666;
  font-style: italic;
  margin: 0;
}

.shop-popup__error {
  color: #8b1a1a;
  margin: 0;
}

.shop-popup__attribution {
  margin: 14px 0 0;
  padding-top: 10px;
  border-top: 1px solid #d4c4b0;
  font-size: 0.75rem;
  color: #6b4c30;
  line-height: 1.4;
}

.shop-popup__attribution a {
  color: #3d2914;
}

.shop-popup__attribution a:hover,
.shop-popup__attribution a:focus-visible {
  color: #2ec6fe;
}

@media (min-width: 768px) {
  .shop-popup__inner {
    align-items: center;
    padding: 16px;
  }

  .shop-popup__panel {
    margin: 0;
    border-radius: 12px;
    max-height: min(80vh, 600px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .shop-popup__backdrop {
    transition: none;
  }
}

.btn,
button.image-btn,
input[type="file"]::file-selector-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25em;
  padding: 0.25em 1em;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  font-variant: common-ligatures small-caps;
  text-decoration: none;

  img {
    height: 2em;
    width: 2em;
    margin: 0;
  }

  &:disabled {
    cursor: not-allowed;

    img {
      opacity: 0.5;
    }
  }

  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    outline: var(--accent-color) auto 1px;
    background-color: #ddbfc67a;
  }
}

input[type="file"] {
  border-radius: 5px;
  border: 1px solid #ccc;
  cursor: pointer;

  &::file-selector-button {
    display: inline-flex;
  }

  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    outline: var(--accent-color) auto 1px;

    &::file-selector-button {
      background-color: #ddbfc67a;
    }
  }
}

a.btn {
  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    text-decoration: underline;
  }
}

/* Map header menu: suggest link (panel matches header brown; gold link reads clearly) */
burger-menu .burger-menu__list a.btn {
  justify-content: flex-start;
  width: 100%;
  color: #f0c96a;
  text-align: left;
}

burger-menu .burger-menu__list a.btn:hover,
burger-menu .burger-menu__list a.btn:focus-visible {
  outline: 2px solid rgba(245, 230, 211, 0.55);
  outline-offset: 2px;
  background-color: rgba(240, 201, 106, 0.15);
}

.map-app__favorites-filter {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.35em 0.8em;
  margin-right: max(8px, env(safe-area-inset-right, 0px));
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #f5e6d3;
  font-size: 0.875rem;
  font-variant: common-ligatures small-caps;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.map-app__favorites-filter:hover {
  background: rgba(255, 255, 255, 0.2);
}

.map-app__favorites-filter input[type="checkbox"] {
  width: 1em;
  height: 1em;
  margin: 0;
  accent-color: var(--accent-color);
  cursor: pointer;
}

a:focus-visible {
  outline: var(--accent-color) auto 1px;
}

/* util classes */

.u-hidden {
  display: none !important;
}

.u-flex {
  display: flex;
}

.u-flex-column {
  flex-direction: column;
}

.u-flex-1 {
  flex: 1;
}

.u-left {
  text-align: left;
}

.u-center {
  text-align: center;
}

.u-fill-width {
  width: -webkit-fill-available;
  width: 100%;
}

.u-fill-height {
  height: -webkit-fill-available;
  height: 100vh;
}

.u-stretch-height {
  height: -webkit-fill-available;
  height: 100%;
  flex: 1;
}

/* background scroll fix for dialogs */
dialog {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

/* responsive design tweaks (breakpoints adopted from Bootstrap) */

@media (max-width: 767px) {
  header#main-head {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 8px;
    height: auto;
    min-height: auto;
    padding-top: max(6px, env(safe-area-inset-top, 0px));
    padding-bottom: 8px;
  }

  #main-head h1 {
    display: block;
    flex: 1 1 auto;
    margin-right: 0;
    min-width: 0;
    font-size: clamp(0.95rem, 4.2vw, 1.2rem);
    line-height: 1.2;
    padding: 0 4px;
    text-align: center;
  }

  burger-menu .burger-menu__list a.btn {
    padding: 0.45em 0.65em;
    font-size: 0.8125rem;
    line-height: 1.25;
    white-space: normal;
    word-break: break-word;
  }

  burger-menu .burger-menu__list .map-app__favorites-filter {
    padding: 0.35em 0.55em;
    font-size: 0.8125rem;
    white-space: normal;
  }

  main.map-app {
    padding: 6px;
  }

  .map-app__canvas {
    border-radius: 6px;
  }
}

@media (min-width: 768px) {
  #main-head > img {
    display: block;
  }
}

/* web component placeholders */
update-notification {
  display: none;
}

/* view transitions */

@view-transition {
  navigation: auto;
  types: slide, forwards;
}
