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

:root {
  --text: #1a1a2e;
  --text-muted: #555;
  --border: #ddd;
  --bg: #fff;
  --bg-subtle: #f7f7f8;
  --accent: #1e64c8;
}

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.container {
  max-width: none;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 1.5em 0 0.5em;
}

h1 {
  font-size: 1.8rem;
  font-weight: 700;
  border-bottom: 2px solid var(--text);
  padding-bottom: 0.3em;
}

h2 {
  font-size: 1.3rem;
  font-weight: 600;
}

h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-muted);
}

p {
  margin: 0.75em 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Tables */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 1rem 0;
}

thead th {
  text-align: left;
  font-weight: 600;
  padding: 0.5em 0.75em;
  border-bottom: 2px solid var(--text);
  white-space: nowrap;
}

tbody td {
  padding: 0.45em 0.75em;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover {
  background: var(--bg-subtle);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Range selector */

.range-selector {
  margin-bottom: .75rem;
}

.range-header {
  margin-bottom: .25rem;
}

.range-label {
  font-size: .8em;
  font-weight: 600;
}

.range-values {
  display: flex;
  justify-content: space-between;
  margin-bottom: .25rem;
}

.range-value-box {
  font-size: .75em;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: .1em .4em;
  min-width: 2.5em;
  text-align: center;
}

.range-track-container {
  position: relative;
  height: 24px;
}

.range-track {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 4px;
  transform: translateY(-50%);
  border-radius: 2px;
  background: var(--border);
}

.range-track-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  transform: translateY(-50%);
  border-radius: 2px;
  background: var(--accent);
}

.range-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  pointer-events: none;
}

.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  cursor: pointer;
}

.range-input::-moz-range-thumb {
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  cursor: pointer;
}

.range-input::-webkit-slider-thumb:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.range-input::-moz-range-thumb:hover {
  background: var(--accent);
  border-color: var(--accent);
}

/* Faceted view: sidebar + content grid */

.faceted-view {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 768px) {
  .faceted-view {
    grid-template-columns: 1fr;
  }
}

.facet-sidebar {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding-right: .5rem;
}

.facet-sidebar-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .25rem;
  font-size: .95rem;
}

.faceted-content {
  min-width: 0; /* prevent grid blowout */
}

.faceted-content table {
  width: max-content;
  min-width: 100%;
}

.faceted-content th {
  white-space: nowrap;
}

/* Toolbar: view toggles + pagination + count + page size in one row */

.faceted-toolbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
  flex-wrap: wrap;
}

.view-toggles {
  display: flex;
  gap: .25rem;
}

/* Facet dropdown */

.facet-dropdown {
  margin-bottom: .75rem;
}

.facet-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: .25rem;
  padding: .4rem .6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: .85em;
  background: var(--bg);
  min-height: 2.2em;
}

.facet-dropdown-trigger:hover {
  border-color: var(--accent);
}

.facet-placeholder {
  color: var(--text-muted);
}

.facet-dropdown-trigger span:first-child {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.facet-clear {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.1em;
  line-height: 1;
  padding: 0 .2rem;
}

.facet-clear:hover {
  color: var(--text);
}

.facet-chevron {
  font-size: .6em;
  color: var(--text-muted);
  flex-shrink: 0;
}

.facet-dropdown-panel {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 4px 4px;
  background: var(--bg);
  max-height: 240px;
  overflow-y: auto;
}

.facet-search {
  width: 100%;
  padding: .35rem .5rem;
  border: none;
  border-bottom: 1px solid var(--border);
  font-size: .8em;
  outline: none;
}

.facet-search:focus {
  background: var(--bg-subtle);
}

.facet-options {
  padding: .25rem 0;
}

.facet-option {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .6rem;
  cursor: pointer;
  font-size: .8em;
}

.facet-option:hover {
  background: var(--bg-subtle);
}

.facet-option-selected {
  background: var(--bg-subtle);
}

.facet-option input[type="checkbox"] {
  margin: 0;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.facet-option-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.facet-option-count {
  color: var(--text-muted);
  font-size: .85em;
  flex-shrink: 0;
}

.facet-option-count::before {
  content: "(";
}

.facet-option-count::after {
  content: ")";
}

/* Compact inline pagination */

.faceted-pagination {
  display: flex;
  align-items: center;
  gap: 2px;
  margin: 0;
}

.faceted-pagination button {
  min-width: 1.6rem;
  padding: .15em .35em;
  font-size: .8em;
  line-height: 1.4;
  border-radius: 3px;
}

.faceted-pagination .pagination-active {
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.faceted-pagination .pagination-ellipsis {
  padding: 0 .15rem;
  color: var(--text-muted);
  font-size: .8em;
}

/* Result count and page size */

.faceted-info {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-left: auto;
}

.faceted-count {
  font-size: .8em;
  color: var(--text-muted);
  white-space: nowrap;
}

.faceted-pagesize {
  width: auto;
  padding: .15rem .35rem;
  font-size: .8em;
  border-radius: 3px;
}

/* Strip PicoCSS article chrome (gradient, shadow) everywhere */

article {
  background: none;
  box-shadow: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem;
  margin: 0;
}

/* Perspective grid */

.perspective-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.perspective-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s;
}

.perspective-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.perspective-card-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.perspective-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* FTS search input */

.fts-search {
    margin-bottom: 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--border);
}

.fts-search-form {
    position: relative;
    display: flex;
    align-items: center;
    margin: 0;
}

.fts-search-input {
    flex: 1;
    width: 100%;
    padding: .4rem .55rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    font-size: .85em;
}

.fts-search-input:focus {
    border-color: var(--accent);
    outline: none;
}

.fts-search-input:disabled {
    background: var(--bg-subtle);
    color: var(--text-muted);
    cursor: not-allowed;
}

.fts-search-clear {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
    padding: 0 .35rem;
}

.fts-search-clear:hover {
    color: var(--text);
}

.fts-error {
    margin: .35rem 0 0;
    font-size: .75em;
    color: #b00020;
}

.fts-help-toggle {
    display: inline-block;
    margin-top: .4rem;
    padding: 0;
    background: none;
    border: none;
    color: var(--accent);
    font-size: .75em;
    cursor: pointer;
    text-decoration: none;
}

.fts-help-toggle:hover {
    text-decoration: underline;
}

.fts-help {
    margin-top: .4rem;
    padding: .5rem .65rem;
    background: var(--bg-subtle);
    border-radius: 4px;
    font-size: .75em;
}

.fts-help ul {
    margin: 0;
    padding-left: 1.1em;
}

.fts-help li {
    margin: .15em 0;
}

.fts-help code {
    background: var(--bg);
    padding: 0 .25em;
    font-size: .95em;
}

/* MapLibre controls — strip Pico's [role="button"] / button styling so the
   library's own SVG markers and zoom controls render unobscured. */

.maplibregl-marker,
.maplibregl-ctrl button {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  color: inherit;
}

.maplibregl-ctrl-group {
  background: var(--bg);
  border-radius: 4px;
}

.maplibregl-ctrl-group button {
  width: 29px;
  height: 29px;
}

/* Utility */

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--bg-subtle);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}
