/* The region map. Kept beside the viewer rather than in the site's Sass
   because the whole map is a self-contained static app, and the page that
   hosts it is the only thing that loads this.

   Layout contract: nothing here may ever cause horizontal page scroll. Every
   grid child carries min-width: 0, tables wrap their content, and the panel
   scrolls vertically inside its own track. */

/* One scroll container: the page. The map sticks beside the panel rather
   than the panel scrolling inside a fixed frame, because two scrollbars
   side by side leaves a reader guessing which one owns the wheel.
   main.mjs measures the real site header and sets --site-header-h; the
   value here is only the fallback. */
.region-app-wrap {
  --app-height: calc(100dvh - var(--site-header-h, 4.5rem));
}

.region-appbar {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  padding: 0.65rem 1rem 0.6rem;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.region-appbar h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
}

.region-appbar p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.region-app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(20rem, 30vw, 24rem);
  align-items: start;
}

.region-map-pane {
  position: sticky;
  top: var(--site-header-h, 4.5rem);
  height: var(--app-height);
  min-width: 0;
}

.region-map {
  position: absolute;
  inset: 0;
}

.map-status {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  margin: 0;
  max-width: calc(100% - 1.5rem);
  padding: 0.4rem 0.7rem;
  border-radius: 0.35rem;
  font-size: 0.85rem;
  background: rgb(15 22 33 / 0.9);
  color: #e8edf5;
  z-index: 5;
}

.map-status[data-kind="warn"] { background: rgb(120 60 20 / 0.95); }

/* ── The panel ──────────────────────────────────────────────────────── */

.region-panel {
  min-width: 0;
  /* At least a screen tall so the sticky map has something to stick
     against even when the panel holds nothing but its empty controls. */
  min-height: var(--app-height);
  border-left: 1px solid var(--border);
  background: var(--surface);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.panel-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.8rem 0.9rem;
  min-width: 0;
}

.panel-card h2,
.panel-card summary h2 {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.panel-card--details summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.panel-card--details summary h2 { margin: 0; }

.panel-card--details summary::before {
  content: "";
  border: 0.28rem solid transparent;
  border-left-color: var(--ink-muted);
  translate: 0 -0.05rem;
  transition: rotate 120ms ease;
}

.panel-card--details[open] summary::before { rotate: 90deg; }
.panel-card--details[open] summary { margin-bottom: 0.55rem; }

.panel-hint {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-muted);
}

/* ── Look up ────────────────────────────────────────────────────────── */

.coordinate-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.5rem;
  align-items: end;
}

.coordinate-form label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--ink-muted);
  min-width: 0;
}

.coordinate-form input,
.region-search-input,
#region-search {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 0.42rem 0.5rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.35rem;
}

.coordinate-form button {
  grid-column: 1 / -1;
  padding: 0.45rem 0.6rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: #fff;
  background: var(--orange);
  border: 0;
  border-radius: 0.35rem;
  cursor: pointer;
}

.coordinate-form button:hover { background: var(--orange-deep); }

/* ── Result ─────────────────────────────────────────────────────────── */

.lookup-result { margin-top: 0.7rem; }

.lookup-result h3 {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.region-table {
  width: 100%;
  /* The site's article tables carry a 34rem floor for prose readability;
     a panel table shrinks with its card instead. */
  min-width: 0;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.region-table th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
}

.region-table th,
.region-table td {
  padding: 0.24rem 0.45rem 0.24rem 0;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.region-table tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border); }

/* ── Search ─────────────────────────────────────────────────────────── */

.search-results {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
}

.search-results li:not(:last-child) { border-bottom: 1px solid var(--border); }

.search-results button {
  width: 100%;
  text-align: left;
  padding: 0.38rem 0.5rem;
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.search-results button:hover { background: var(--surface-2); }

.search-results .search-name { font-weight: 600; }

.search-results .search-namespace {
  font-size: 0.7rem;
  color: var(--ink-muted);
  margin-left: 0.35rem;
}

/* ── Layers ─────────────────────────────────────────────────────────── */

.layer-toggles { display: grid; gap: 0.35rem; }

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
}

.swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 0.2rem;
  flex: none;
}

/* ── Database ───────────────────────────────────────────────────────── */

.kv {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.15rem 0.6rem;
  font-size: 0.8rem;
  margin: 0.6rem 0 0;
}

.kv dt { font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.database-meta h3 {
  margin: 0.7rem 0 0.3rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.sources {
  font-size: 0.75rem;
  color: var(--ink-muted);
  padding-left: 1.05rem;
  margin: 0.3rem 0 0;
}

.sources a { color: var(--link); }

.database-picker {
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  display: grid;
  gap: 0.35rem;
}

.database-picker input { font-size: 0.8rem; max-width: 100%; }

/* ── Narrow windows: stack, never squeeze ───────────────────────────── */

@media (max-width: 56rem) {
  .region-app { display: block; }

  .region-map-pane {
    /* Relative, not static: the map inside is absolutely positioned and
       would otherwise escape its pane and cover the panel. */
    position: relative;
    top: auto;
    height: 58dvh;
    min-height: 22rem;
  }

  .region-panel {
    min-height: 0;
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .region-appbar p { white-space: normal; }
}

/* ── Match rows: one region per row, two lines, no table to fight ──── */

.match-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.match-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0;
}

.match-row:not(:last-child) { border-bottom: 1px solid var(--border); }

.match-row .swatch { translate: 0 0.05rem; }

.match-main {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 0.1rem;
}

.match-primary {
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.match-namespace code {
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.match-membership {
  flex: none;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.match-membership--expanded { color: var(--orange); }
