:root {
  color-scheme: light;
  --paper: #ffffff;
  --ink: #2c3038;
  --muted: #7a8089;
  --line: rgba(44, 48, 56, 0.1);
  --shadow: 0 -18px 50px rgba(44, 48, 56, 0.16);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --sheet-collapsed-height: 46vh;
  /* Expanded, the sheet takes the whole screen; the map stays behind it. */
  --sheet-expanded-height: 100dvh;
  /* The expanded sheet's content starts under the floating topbar. */
  --sheet-top-clear: 84px;
  --map-edge-gap: 12px;
  /* The sheet is flush with the screen; the legend, map controls and sheet content line up on this side. */
  --sheet-side: max(32px, calc((100vw - 1296px) / 2));
  --sheet-inset: 0px;
  --sheet-radius: 24px;
  --tint-1: rgba(44, 48, 56, 0.05);
  --tint-2: rgba(44, 48, 56, 0.08);
  --tint-3: rgba(44, 48, 56, 0.16);
  --float-shadow: 0 1px 3px rgba(44, 48, 56, 0.08), 0 8px 26px rgba(44, 48, 56, 0.14);
  --legend-bottom: calc(var(--sheet-collapsed-height) + var(--sheet-inset) + var(--map-edge-gap));
  --legend-bottom-expanded: calc(var(--sheet-expanded-height) + var(--sheet-inset) + var(--map-edge-gap));
}

* { box-sizing: border-box; }

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #eef0f3;
  color: var(--ink);
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
}

button,
input,
select { font: inherit; }

button,
select { color: inherit; }

#map {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: #eef0f3;
}

.topbar {
  position: fixed;
  z-index: 20;
  top: 16px;
  left: 20px;
  right: 20px;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(320px, 520px) minmax(190px, 1fr);
  align-items: center;
  gap: 18px;
  pointer-events: none;
}

.topbar > * { pointer-events: auto; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  padding: 5px 14px 5px 5px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--float-shadow);
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.015em;
  text-decoration: none;
  backdrop-filter: blur(14px);
}

.brand-text b { font-weight: 800; }

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  font-size: 17px;
}

.search-wrap { position: relative; }

.search-pill {
  display: flex;
  height: 46px;
  align-items: center;
  gap: 10px;
  padding: 0 8px 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--float-shadow);
  backdrop-filter: blur(15px);
}

.search-pill:focus-within {
  outline: 3px solid rgba(91, 130, 255, 0.22);
  border-color: rgba(91, 130, 255, 0.45);
}

.search-pill svg {
  width: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-width: 2;
}

.search-pill input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
}

.search-pill input::placeholder { color: var(--muted); }

kbd {
  padding: 5px 8px;
  border: 0;
  border-radius: 999px;
  background: var(--tint-2);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 650;
}

.search-results {
  position: absolute;
  top: 54px;
  right: 0;
  left: 0;
  overflow: hidden;
  max-height: min(440px, 55vh);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 18px 55px rgba(44, 48, 56, 0.22);
}

/* A plain serif link, underlined; a paper-coloured halo keeps it readable over the map. */
.topbar-button {
  justify-self: end;
  min-height: 42px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 400;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  text-shadow: 0 0 6px var(--paper), 0 0 2px var(--paper), 0 0 1px var(--paper);
}

.topbar-button:hover { text-decoration-thickness: 2px; }
.topbar-button:focus-visible { border-radius: 6px; outline: 3px solid rgba(91, 130, 255, 0.35); outline-offset: 2px; }

.sheet {
  position: fixed;
  z-index: 15;
  right: 0;
  bottom: 0;
  left: 0;
  height: var(--sheet-collapsed-height);
  overflow: hidden;
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  background: var(--paper);
  box-shadow: var(--shadow), 0 -1px 0 rgba(44, 48, 56, 0.05);
  transition: height 360ms cubic-bezier(0.22, 1, 0.36, 1), padding-top 360ms cubic-bezier(0.22, 1, 0.36, 1),
    border-radius 360ms cubic-bezier(0.22, 1, 0.36, 1);
}

.sheet.is-expanded {
  height: var(--sheet-expanded-height);
  padding-top: var(--sheet-top-clear);
  border-radius: 0;
}

.sheet-handle {
  display: grid;
  width: 100%;
  height: 24px;
  padding: 0;
  place-items: center;
  border: 0;
  background: transparent;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}

/* While the handle is dragged the sheet follows the pointer 1:1; snapping re-enables the transitions. */
.is-sheet-dragging .sheet,
.is-sheet-dragging .map-legend,
.is-sheet-dragging .maplibregl-ctrl-bottom-right { transition: none; }
.is-sheet-dragging .sheet-handle { cursor: grabbing; }

.sheet-handle span {
  width: 44px;
  height: 5px;
  border-radius: 99px;
  background: var(--tint-3);
}

.sheet-scroll {
  height: calc(100% - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.sheet-header,
.sheet-body {
  width: calc(100% - 64px);
  max-width: calc(1360px - 64px);
  margin: 0 auto;
}

.sheet-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 14px 40px;
  padding: 8px 0 20px;
  border-bottom: 1px solid var(--line);
}

.sheet-heading { min-width: 0; }

h1 {
  max-width: 820px;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(34px, 3.1vw, 48px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1;
}

.sheet-subtitle {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.sheet-controls,
.region-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sheet-controls { justify-content: flex-end; }

.region-controls label { display: block; }

.control-label,
.roast-control legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

select {
  min-width: 170px;
  max-width: 240px;
  height: 38px;
  padding: 0 32px 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--tint-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%236f6a61' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='m1 1 4 4 4-4'/%3E%3C/svg%3E") no-repeat right 13px center;
  appearance: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

select:hover { background-color: var(--tint-2); }
select:focus-visible { outline: 2px solid #5b82ff; outline-offset: 1px; }

.roast-control {
  margin: 0;
  padding: 0;
  border: 0;
}

.segments {
  display: grid;
  grid-template-columns: repeat(3, auto);
  padding: 3px;
  border-radius: 999px;
  background: var(--tint-1);
}

.segments input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segments label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 15px;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.segments label:hover { color: var(--ink); }

.segments input:focus-visible + label { outline: 2px solid #5b82ff; }

.segments input:checked + label {
  background: #fff;
  box-shadow: 0 1px 2px rgba(44, 48, 56, 0.08), 0 2px 8px rgba(44, 48, 56, 0.08);
  color: var(--ink);
}

.segments input:checked + label::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5b82ff;
  box-shadow: 0 0 0 3px rgba(91, 130, 255, 0.16);
}

.sheet-body { padding: 20px 0 80px; }

/* Detail view: the card owns the sheet. The headline and region pickers step aside so the locality
   name opens at the top; the roast control stays, floating at the top-right while the card scrolls. */
.sheet.is-detail .sheet-header {
  position: sticky;
  z-index: 3;
  top: 0;
  display: block;
  height: 0;
  padding: 0;
  border: 0;
}

.sheet.is-detail .sheet-heading,
.sheet.is-detail .region-controls { display: none; }

.sheet.is-detail .sheet-controls {
  position: absolute;
  top: 6px;
  right: 0;
  flex-direction: row;
}

.sheet.is-detail .segments {
  background: var(--paper);
  box-shadow: inset 0 0 0 100px var(--tint-1), var(--float-shadow);
}

.sheet.is-detail .sheet-body { padding-top: 6px; }

.table-empty {
  display: grid;
  min-height: 180px;
  place-content: center;
  text-align: center;
}

.table-empty h2 {
  margin: 2px 0 6px;
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 500;
}

.table-empty p {
  max-width: 540px;
  margin: 3px auto;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.eyebrow,
.sort-hint {
  font-size: 10px !important;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sort-hint { margin-top: 16px !important; }

.skeleton {
  display: grid;
  gap: 10px;
  padding: 12px 0;
}

.skeleton span {
  display: block;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(90deg, #f3f4f6 25%, #f7f8fa 50%, #f3f4f6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

@keyframes shimmer { to { background-position: -200% 0; } }

.map-legend {
  position: fixed;
  z-index: 10;
  bottom: var(--legend-bottom);
  left: var(--sheet-side);
  max-width: min(650px, calc(100vw - 60px));
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--float-shadow);
  backdrop-filter: blur(12px);
  pointer-events: none;
  transition: bottom 360ms cubic-bezier(0.22, 1, 0.36, 1);
}

#app:has(.sheet.is-expanded) .map-legend { bottom: var(--legend-bottom-expanded); }

.legend-bands {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  gap: 7px 13px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 650;
}

.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.95), 0 0 0 2px var(--tint-2);
}

.legend-notes {
  margin: 7px 0 0;
  white-space: nowrap;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.35;
}

.maplibregl-ctrl-bottom-right {
  right: var(--sheet-side);
  bottom: var(--legend-bottom);
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 6px;
  transition: bottom 360ms cubic-bezier(0.22, 1, 0.36, 1);
}

#app:has(.sheet.is-expanded) .maplibregl-ctrl-bottom-right { bottom: var(--legend-bottom-expanded); }

.maplibregl-ctrl-bottom-right .maplibregl-ctrl { margin: 0; }

.maplibregl-ctrl-group:not(:empty) {
  overflow: hidden;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--float-shadow);
}

.map-tooltip {
  min-width: 170px;
  font-family: var(--sans);
  line-height: 1.35;
}

.map-tooltip strong {
  display: block;
  margin-bottom: 2px;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.map-tooltip span { display: block; color: #6b7078; font-size: 11px; }
.map-tooltip b { display: block; margin-top: 7px; font-size: 12px; }

.maplibregl-popup-content {
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 10px 30px rgba(44, 48, 56, 0.2);
}

.maplibregl-popup-tip { border-top-color: var(--paper) !important; }

.modal-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  padding: 24px;
  place-items: center;
  background: rgba(44, 48, 56, 0.42);
  backdrop-filter: blur(5px);
}

.modal-panel {
  width: min(620px, 100%);
  max-height: min(720px, calc(100vh - 48px));
  overflow: auto;
  padding: 28px;
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(44, 48, 56, 0.3);
}

.modal-panel h2 { margin: 0 0 8px; font: 500 30px/1.1 var(--serif); }
.modal-panel p { color: var(--muted); font-size: 14px; line-height: 1.55; }
.modal-close { float: right; border: 0; background: none; cursor: pointer; font-size: 23px; }

.dev-chip {
  position: fixed;
  z-index: 100;
  right: 12px;
  bottom: 10px;
  padding: 5px 8px;
  border: 1px solid #b47b18;
  border-radius: 999px;
  background: #fff0bf;
  color: #754b00;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1099px) {
  .sheet-header { grid-template-columns: minmax(0, 1fr); }
  .sheet-controls { justify-content: space-between; }
}

@media (max-width: 899px) {
  :root {
    --sheet-collapsed-height: 66vh;
    --sheet-top-clear: 108px;
    --map-edge-gap: 8px;
    --sheet-side: 8px;
    --sheet-radius: 22px;
  }

  .topbar {
    top: 10px;
    right: 12px;
    left: 12px;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .search-wrap { grid-column: 1 / -1; grid-row: 2; }
  .topbar-button { grid-column: 2; grid-row: 1; min-height: 38px; }
  .brand { grid-column: 1; grid-row: 1; padding: 3px 12px 3px 3px; }
  .brand-mark { width: 32px; height: 32px; font-size: 15px; }

  .sheet-header,
  .sheet-body { width: calc(100% - 32px); }

  .sheet-header { padding-top: 4px; gap: 12px; }
  h1 { font-size: 30px; }
  .sheet-subtitle { font-size: 12px; }

  .sheet-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .region-controls { align-items: stretch; }
  .region-controls label { min-width: 0; flex: 1; }
  select { width: 100%; min-width: 0; max-width: none; }
  .segments { grid-template-columns: repeat(3, 1fr); }
  .sheet.is-detail .segments label { min-height: 30px; padding: 0 10px; }

  .map-legend {
    left: 12px;
    max-width: calc(100vw - 72px);
    padding: 8px 10px;
  }

  .maplibregl-ctrl-bottom-right { right: 12px; }
  .legend-bands { gap: 5px 9px; }
  .legend-item { font-size: 9px; }
}

@media (max-width: 520px) {
  .brand { font-size: 13px; }
  .topbar-button { font-size: 14px; }
  .search-pill { height: 44px; }
  .legend-bands { grid-template-columns: repeat(2, max-content); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
