/* Hyggefisk application shell.
 *
 * One layout switch, at 48rem: map above list on a phone, side by side on a
 * wider screen. Colours follow the system scheme, because most fishing
 * happens at dawn and dusk and the phone will be in dark mode. */

:root {
  color-scheme: light dark;
  --bg: #f6f4ef;
  --fg: #1d2530;
  --muted: #5b6672;
  --line: #d8d3c8;
  --accent: #1f6f8b;
  --panel: #ffffff;
  --header-height: 3.5rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171d;
    --fg: #e6e9ec;
    --muted: #9aa5b1;
    --line: #2a333d;
    --accent: #6fb7d1;
    --panel: #1a2129;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Keep the header clear of a notch or a home indicator. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--header-height);
  padding: 0 0.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

#top h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  white-space: nowrap;
}

#search {
  display: flex;
  flex: 1;
  gap: 0.5rem;
  min-width: 0;
}

#search input,
#search select {
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--fg);
  /* 16px keeps iOS from zooming the page when the field takes focus. */
  font-size: 1rem;
}

#search input { flex: 1; }

#admin-link {
  margin-left: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  text-decoration: none;
}
#admin-link:hover { color: var(--accent); }

#app {
  display: grid;
  flex: 1;
  min-height: 0;
  grid-template-rows: minmax(40vh, 1fr) minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
}

/* An explicit height is not optional: a MapLibre container with no height
 * renders nothing and reports no error. */
#map {
  min-height: 40vh;
  height: 100%;
}

#list {
  overflow-y: auto;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

#status {
  margin: 0;
  padding: 0.75rem;
  color: var(--muted);
}

#spots {
  list-style: none;
  margin: 0;
  padding: 0;
}

#spots li {
  border-bottom: 1px solid var(--line);
}

.spot-row {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.spot-name { font-weight: 600; }

.spot-kind {
  font-size: 0.85rem;
  color: var(--muted);
}

#spots li:hover,
#spots li:focus-within {
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}

#detail {
  position: fixed;
  inset: auto 0 0 0;
  max-height: 70vh;
  overflow-y: auto;
  padding: 1rem;
  border-top: 1px solid var(--line);
  border-radius: 1rem 1rem 0 0;
  background: var(--panel);
  box-shadow: 0 -0.5rem 1.5rem rgba(0, 0, 0, 0.2);
}

#detail[hidden] { display: none; }

a { color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (min-width: 48rem) {
  #app {
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr) 22rem;
  }

  #map { min-height: 0; }

  #list {
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  #detail {
    inset: var(--header-height) 0 0 auto;
    width: 26rem;
    max-height: none;
    border-radius: 0;
    border-top: 0;
    border-left: 1px solid var(--line);
  }
}

/* Detail panel contents */

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.detail-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.detail-close {
  flex: none;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.95rem;
  cursor: pointer;
}

.detail-facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 0.75rem;
  margin: 0.75rem 0 0;
}

.detail-facts dt { color: var(--muted); }
.detail-facts dd { margin: 0; }

#detail h3 {
  margin: 1rem 0 0.35rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.detail-species,
.detail-tags,
.detail-sources {
  margin: 0;
  padding: 0;
  list-style: none;
}

.detail-tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.detail-tags li {
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  font-size: 0.85rem;
}

.detail-sources li {
  padding: 0.5rem 0;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.source-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  margin-top: 0.2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.source-type { font-weight: 600; }

#map { position: relative; }

#map-offline {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 0.75rem;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--fg);
  font-size: 0.9rem;
  box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

#map-offline[hidden] { display: none; }

#update-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
}

#update-bar[hidden] { display: none; }

#update-bar button {
  padding: 0.3rem 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 0.5rem;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

#locate {
  flex: none;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.95rem;
  white-space: nowrap;
  cursor: pointer;
}

#locate:disabled { opacity: 0.6; cursor: wait; }

#sort[hidden] { display: none; }

.detail-copy {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.copy-button {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.9rem;
  cursor: pointer;
}

.detail-links {
  margin: 0;
  padding: 0;
  list-style: none;
}

.detail-links li { padding: 0.3rem 0; }

.detail-note {
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

@media (max-width: 47.99rem) {
  /* On a phone the header runs out of width; the selects wrap under the
   * search field. */
  #top { height: auto; padding: 0.5rem 0.75rem; }
  #search { flex-wrap: wrap; }
  #search input { flex-basis: 100%; }
}
