:root {
  --text-heading: 1.1rem;
  --text-regular: 0.9rem;
  --text-small: 0.8rem;
  --text-xsmall: 0.7rem;
  --color-primary: blue;
  --color-muted: #888;
  --color-border: #ddd;
  --color-hover: #f5f5f5;
}

*, *::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;
}

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

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

input[type="checkbox"] {
  appearance: none;
  width: 0.9em;
  height: 0.9em;
  border: 1.5px solid #999;
  border-radius: 2px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  background: #fff;

  &:checked {
    background: var(--color-primary);
    border-color: var(--color-primary);
  }

  &:checked::after {
    content: '';
    position: absolute;
    inset: 0;
    background: 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='white' 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: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);

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

.header-mail {
  margin-left: auto;
  font-size: var(--text-xsmall);
  color: var(--color-muted);
}

/* 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 { display: none; }

.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;
}

fieldset {
  border: none;
  padding: 0;
  margin: 1rem 0 0;

  & legend {
    font-weight: 700;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0;
    margin-bottom: 0.5rem;
  }

  & [data-toggle] {
    font-size: var(--text-xsmall);
    font-weight: normal;
    cursor: pointer;
  }

  & 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 {
      display: none;
      margin-left: auto;
      font-size: var(--text-xsmall);
    }

    &:hover .filter-link { display: inline; }
  }
}

/* Results */
.results {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  border-right: 1px solid var(--color-border);
  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;
}
#map {
  width: 100%;
  height: 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-mail { 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;

    & fieldset { max-height: 200px; overflow-y: auto; }
  }

  .results { border-right: none; overflow-y: visible; }
  .map-aside { height: 300px; }
  .taxonomy-list { columns: 2; }

  .filter-toggle { display: block; text-align: center; }
  .filters .filter-groups { display: none; }
  .filters .filter-groups.open { display: contents; }
}

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