:root {
  color-scheme: light dark;

  --text-heading: 1.1rem;
  --text-regular: 0.9rem;
  --text-small: 0.8rem;
  --text-xsmall: 0.7rem;

  --color-bg:      light-dark(#ffffff, #16181c);
  --color-text:    light-dark(#1c1e21, #e3e5e8);
  --color-primary: light-dark(#0000ff, #7aa2ff);
  --color-visited: light-dark(#7b3ff2, #c0a6ff);
  --color-muted:   light-dark(#6b7075, #979ca3);
  --color-border:  light-dark(#dddddd, #2c3037);
  --color-hover:   light-dark(#f5f5f5, #22262d);
}

:root:has(body[data-theme="dark"])  { color-scheme: dark; }
:root:has(body[data-theme="light"]) { color-scheme: light; }

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: system-ui, sans-serif;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-text);
}

a {
  text-decoration: none;
  color: var(--color-primary);
  &:visited { color: var(--color-visited); }
  &:hover { color: inherit; }

  &.light {
    color: var(--color-muted);
    &:hover { color: var(--color-primary); }
  }
}

button {
  border-radius: 3px;
}

input[type="checkbox"] {
  appearance: none;
  width: 1em;
  height: 1em;
  border: 1.5px solid var(--color-border);
  border-radius: 2px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  background: transparent;

  &:checked::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--color-primary);
    -webkit-mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 12 12' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 6L5 9.5L10 2.5' stroke='%23000' stroke-width='2.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/80% no-repeat;
            mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 12 12' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 6L5 9.5L10 2.5' stroke='%23000' stroke-width='2.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/80% no-repeat;
  }

  &:focus-visible {
    outline: 1.5px solid var(--color-primary);
    outline-offset: 1px;
  }
}

/* Header */
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);

  & h1 { font-size: var(--text-heading); margin-right: 0.5rem; }
  & p { font-size: var(--text-small); }
}

.header-right {
  margin-left: auto;
  font-size: var(--text-xsmall);
  color: var(--color-muted);
  display: inline-flex;
  align-items: center;
  gap: 1rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  padding: 0;
  background: none;
  border: none;
  line-height: 0;
  cursor: pointer;
  color: var(--color-muted);

  &:hover { color: var(--color-primary); }
  &:focus-visible {
    outline: 1.5px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 2px;
  }
}

/* Three-column layout */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Filters sidebar */
.filters {
  width: 230px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 0.75rem;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  font-size: var(--text-small);
}

.filter-toggle, .map-toggle {
  display: none;
  font: inherit;
  background: none;
  border: 1px solid var(--color-border);
  padding: 0.25rem;
  color: var(--color-primary);
  cursor: pointer;

  &:focus-visible {
    outline: 1.5px solid var(--color-primary);
    outline-offset: 2px;
  }
}

.show-map-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.5rem;
  cursor: pointer;
}

.sidebar-footer {
  font-size: var(--text-xsmall);
  color: var(--color-muted);
  margin-top: auto;
  padding-top: 1rem;

  & p + p { margin-top: 0.5rem; }
}

.search input {
  width: 100%;
  padding: 0.3rem 0.4rem;
  font-size: inherit;
}

.filter-group {
  margin: 0.75rem 0 0;
  border-top: 1px solid var(--color-border);
  padding-top: 0.5rem;

  & summary {
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.1rem 0;
    cursor: pointer;
    user-select: none;
    list-style: none;

    &::-webkit-details-marker { display: none; }

    /* Chevron on accordion */
    &::before {
      content: '';
      width: 0.4em;
      height: 0.4em;
      border-right: 1.5px solid var(--color-muted);
      border-bottom: 1.5px solid var(--color-muted);
      transform: rotate(-45deg);
      transition: transform 0.15s ease;
      flex-shrink: 0;
    }
  }

  &[open] > summary { margin-bottom: 0.5rem; }
  &[open] > summary::before { transform: rotate(45deg); }

  & [data-toggle] {
    margin-left: auto;
    font: inherit;
    font-size: var(--text-xsmall);
    font-weight: normal;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--color-muted);

    &:hover { color: var(--color-primary); }
    &:focus-visible {
      outline: 1.5px solid var(--color-primary);
      outline-offset: 2px;
    }
  }

  & label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.05rem 0;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    & .filter-link {
      margin-left: auto;
      font-size: var(--text-xsmall);
    }
  }
}

/* Results */
.results {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  min-width: 0;
}

.count { padding: 0.25rem; }

[data-space] {
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--color-border);

  & h3 { font-size: var(--text-regular); }

  & .meta, & .address {
    color: var(--color-muted);
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: var(--text-xsmall);
  }

  & p { margin-top: 0.15rem; }
}

[data-space]:hover,
[data-space][aria-selected="true"] {
  background: var(--color-hover);
  cursor: pointer;
}

/* Map */
.map-aside {
  flex: 1;
  min-width: 0;
  border-right: 1px solid var(--color-border);
  display: flex;
}
#map {
  flex: 1;
  width: 100%;
}

.leaflet-container a {
  color: var(--color-primary) !important;
}

.popup-address {
  color: var(--color-muted);
  font-size: var(--text-xsmall);
}

/* Taxonomy listing pages */
.taxonomy-list {
  list-style: none;
  padding: 1rem;
  columns: 3;

  & li { padding: 0.2rem 0; }
}

/* Detail pages */
main.detail {
  max-width: 700px;
  padding: 1rem;
  overflow-y: auto;
}

/* Mobile */
@media (max-width: 750px) {
  html, body { height: auto; overflow: auto; }
  body { display: block; }

  header { flex-direction: column; align-items: flex-start; }
  .header-right { margin-left: 0; }

  .layout { flex-direction: column; flex: none; }

  .filters {
    width: auto;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    gap: 0.5rem;

    & .filter-group[open] { max-height: 220px; overflow-y: auto; }
  }

  .results { overflow-y: visible; }
  .map-aside {
    flex: none;
    min-height: 410px;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .taxonomy-list { columns: 2; }

  .filter-toggle, .map-toggle { display: block; width: 100%; text-align: center; }
  .filters .filter-groups { display: none; }
  .filters .filter-groups.open { display: contents; }
}

@media (max-width: 500px) {
  .taxonomy-list { columns: 1; }
}
