:root {
  --bg: #f7f7f4;
  --panel: #ffffff;
  --ink: #1f2421;
  --muted: #5c655f;
  --line: #d9ded8;
  --soft: #eef2ed;
  --teal: #197a75;
  --teal-dark: #0f5c58;
  --amber: #d9911b;
  --red: #c4493d;
  --violet: #6b5fb5;
  --marker: #7c867f;
  --shadow: 0 1px 2px rgba(31, 36, 33, 0.06), 0 8px 24px rgba(31, 36, 33, 0.06);
  --radius: 10px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  appearance: none;
  -webkit-appearance: none;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

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

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Shell ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
}

/* ---------- Header ---------- */
.app-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.eyebrow {
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.reset-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--teal-dark);
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease;
}

.reset-button:hover {
  border-color: var(--teal);
  background: var(--soft);
}

.reset-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.search-field input {
  height: 42px;
  width: min(38vw, 300px);
  min-width: 200px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

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

.select-field select {
  height: 42px;
  width: 134px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  outline: none;
}

.select-field-wide select {
  width: 170px;
}

.search-field input:focus,
.select-field select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(25, 122, 117, 0.14);
}

.header-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* ---------- Filter chips (merged metrics + filter) ---------- */
.filter-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.chip:hover {
  border-color: var(--teal);
}

.chip-label {
  font-size: 13px;
  font-weight: 800;
}

.chip-count {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chip.is-active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.chip.is-active .chip-count {
  color: rgba(255, 255, 255, 0.82);
}

.context-line {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.summary-card {
  display: grid;
  gap: 4px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.summary-card span {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 800;
}

.summary-card strong {
  font-size: 17px;
  font-weight: 900;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

/* ---------- Workspace ---------- */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(340px, 384px) minmax(0, 1fr);
}

/* ---------- Rail (list + detail) ---------- */
.rail {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.sheet-handle {
  display: none;
}

.rail-view {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.rail-view[hidden] {
  display: none;
}

.rail-head {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.rail-head-count strong {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.rail-head-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.sort-field {
  flex: 0 0 auto;
}

.sort-field select {
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  outline: none;
}

.sort-field select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(25, 122, 117, 0.14);
}

.story-panel {
  flex: 0 0 auto;
  display: grid;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.story-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.story-head strong {
  font-size: 13px;
}

.story-field select {
  height: 30px;
  width: 112px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  outline: none;
}

.story-field select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(25, 122, 117, 0.14);
}

.story-list {
  display: grid;
  gap: 6px;
}

.story-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.story-item:hover,
.story-item.is-selected {
  border-color: rgba(25, 122, 117, 0.55);
  background: #eef6f0;
}

.story-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--soft);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.story-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.story-main strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.story-main small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.story-value {
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.story-empty {
  padding: 8px 0;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
}

.place-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ---------- Place card ---------- */
.place-card {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease;
}

.place-card:hover {
  background: #f3f8f4;
}

.place-card.is-selected {
  background: #eef6f0;
  border-left-color: var(--teal);
}

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.card-rank {
  flex: 0 0 auto;
  min-width: 16px;
  padding-top: 1px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.card-name {
  flex: 1 1 auto;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.card-loc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.card-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.card-stats .stat-strong {
  color: var(--ink);
  font-weight: 800;
}

.sep {
  color: var(--line);
}

/* ---------- Tag pill (shared by card + detail) ---------- */
.tag {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--soft);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
}

.tag.both {
  background: rgba(107, 95, 181, 0.14);
  color: #51469a;
}

.tag.official {
  background: rgba(196, 73, 61, 0.12);
  color: #9d3128;
}

.tag.frequent {
  background: rgba(217, 145, 27, 0.18);
  color: #875708;
}

.empty-results {
  display: grid;
  gap: 6px;
  align-content: center;
  justify-items: center;
  flex: 1 1 auto;
  padding: 40px 24px;
  text-align: center;
}

.empty-results[hidden] {
  display: none;
}

.empty-results strong {
  font-size: 15px;
}

.empty-results span {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Detail subview ---------- */
.rail-detail {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.detail-back {
  position: sticky;
  top: 0;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  text-align: left;
}

.detail-back:hover {
  background: var(--soft);
}

.detail-back svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.place-detail {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.detail-kicker {
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
}

.place-detail h3 {
  margin: 4px 0 0;
  font-size: 22px;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.detail-place {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.detail-insights {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.insight-chip {
  display: grid;
  gap: 3px;
  min-height: 52px;
  padding: 10px;
  border-radius: 8px;
  background: var(--soft);
}

.insight-chip span {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 800;
}

.insight-chip strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detail-stat {
  display: grid;
  gap: 4px;
  min-height: 64px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.detail-stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-stat strong {
  font-size: 17px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.detail-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.map-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  transition: background 160ms ease;
}

.map-link:hover {
  background: var(--teal-dark);
}

.share-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
}

.share-link:hover {
  background: var(--soft);
}

.detail-list {
  display: grid;
  gap: 8px;
}

.detail-list h4 {
  font-size: 13px;
}

.detail-list ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

/* Real-expense record list (transaction-style rows) */
.record-list {
  gap: 0 !important;
}

.record {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.record:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.record-main {
  min-width: 0;
}

.record-top {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.record-desc {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.record-amount {
  flex: 0 0 auto;
  text-align: right;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.record-amount small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.record-note {
  margin-left: 4px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.record-empty {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Map panel ---------- */
.map-panel {
  position: relative;
  min-height: 0;
  background: #e8ede9;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.place-marker {
  cursor: pointer;
  opacity: 0.86;
  stroke: #fff;
  stroke-width: 0.55;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  transform-origin: center;
}

.place-marker:hover,
.place-marker.is-selected {
  opacity: 1;
  stroke: #1f2421;
  stroke-width: 0.85;
}

.place-marker.normal {
  fill: var(--marker);
}
.place-marker.frequent {
  fill: var(--amber);
}
.place-marker.official {
  fill: var(--red);
}
.place-marker.both {
  fill: var(--violet);
}

.leaflet-tooltip {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: 800 12px/1.35 Inter, ui-sans-serif, system-ui, sans-serif;
}

/* Marker cluster bubbles */
.cluster-wrap {
  background: transparent;
}

.cluster-bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(25, 122, 117, 0.92);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(31, 36, 33, 0.32);
}

.cluster-bubble.md {
  font-size: 14px;
  background: rgba(18, 104, 99, 0.94);
}

.cluster-bubble.lg {
  font-size: 14px;
  background: rgba(15, 92, 88, 0.96);
}

/* Legend overlay on the map */
.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.both {
  background: var(--violet);
}
.legend-dot.official {
  background: var(--red);
}
.legend-dot.frequent {
  background: var(--amber);
}
.legend-dot.normal {
  background: var(--marker);
}

/* ---------- Loading overlay ---------- */
.app-loading {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.app-loading[hidden] {
  display: none;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes sheetContentIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Tablet / small desktop ---------- */
@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: minmax(300px, 340px) minmax(0, 1fr);
  }
}

/* ---------- Mobile: map-first with bottom sheet ---------- */
@media (max-width: 768px) {
  .app-header {
    padding: 8px 10px;
    gap: 6px;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 17px;
    line-height: 1.15;
  }

  .header-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    width: 100%;
  }

  .header-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 94px 116px 38px;
    align-items: stretch;
    gap: 6px;
    width: 100%;
  }

  .search-field {
    min-width: 0;
  }

  .search-field input {
    height: 38px;
    width: 100%;
    min-width: 0;
  }

  .select-field {
    min-width: 0;
  }

  .select-field select,
  .select-field-wide select {
    height: 38px;
    width: 100%;
    min-width: 0;
    padding: 0 8px;
    font-size: 12.5px;
  }

  .reset-button {
    width: 38px;
    height: 38px;
  }

  .header-bottom {
    align-items: stretch;
    gap: 0;
    min-width: 0;
  }

  .filter-chips {
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .filter-chips::-webkit-scrollbar {
    display: none;
  }

  .chip {
    flex: 0 0 auto;
    min-height: 34px;
    gap: 6px;
    padding: 0 6px;
  }

  .context-line {
    display: none;
  }

  .summary-strip {
    display: none;
  }

  .workspace {
    display: block;
    position: relative;
    min-height: 0;
  }

  .map-panel {
    position: absolute;
    inset: 0;
    overflow: hidden;
  }

  /* Rail becomes a bottom sheet over the map */
  .rail {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    height: clamp(216px, 38%, 280px);
    max-height: calc(100% - 8px);
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 28px rgba(31, 36, 33, 0.16);
    transition: height 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: height;
  }

  .rail[data-sheet-mode="mid"] {
    height: min(66%, 480px);
  }

  .rail[data-sheet-mode="full"],
  .rail.is-expanded {
    height: calc(100% - 8px);
  }

  .rail:not([data-sheet-mode="full"]) .story-panel {
    display: none;
  }

  .rail-list:not([hidden]),
  .rail-detail:not([hidden]) {
    animation: sheetContentIn 180ms ease-out;
  }

  .place-list,
  .rail-detail {
    scrollbar-width: none;
  }

  .place-list::-webkit-scrollbar,
  .rail-detail::-webkit-scrollbar {
    display: none;
  }

  .rail-head {
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
  }

  .sort-field select,
  .story-field select {
    height: 36px;
  }

  .sheet-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex: 0 0 auto;
    padding: 8px 12px 6px;
    cursor: pointer;
    border-radius: 16px 16px 0 0;
    touch-action: manipulation;
  }

  .sheet-grip {
    position: absolute;
    top: 8px;
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
  }

  .sheet-handle-text {
    display: flex;
    justify-content: center;
    gap: 2px;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    padding-top: 6px;
  }

  .sheet-handle-text strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
  }

  .story-panel {
    gap: 8px;
    padding: 10px 12px;
  }

  .story-item {
    min-height: 44px;
  }

  .place-card {
    padding: 10px 12px;
  }

  .detail-back {
    min-height: 44px;
    padding: 0 16px;
  }

  .map-legend {
    left: auto;
    right: 10px;
    top: 10px;
    bottom: auto;
    padding: 6px 10px;
    font-size: 11px;
    gap: 4px 10px;
  }

  .detail-stats {
    grid-template-columns: 1fr 1fr;
  }

  .detail-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .header-controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 38px;
  }

  .search-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 360px) {
  .chip {
    gap: 5px;
    padding: 0 6px;
  }

  .rail {
    height: clamp(208px, 40%, 260px);
  }

  .rail[data-sheet-mode="mid"] {
    height: min(68%, 420px);
  }
}

@media (max-width: 768px) and (orientation: landscape) {
  .rail {
    height: min(54%, 240px);
  }
}

@media (max-width: 900px) and (max-height: 480px) {
  .app-header {
    padding: 10px 16px;
    gap: 8px;
  }

  .header-top {
    gap: 12px;
  }

  h1 {
    font-size: 18px;
  }

  .summary-strip {
    display: none;
  }

  .story-panel {
    display: none;
  }

  .sort-field select,
  .story-field select {
    height: 38px;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .spinner {
    border-top-color: var(--teal);
  }
}
