/* ---------- Saved page (#/saved, js/saved-page.js). Prefix sv-. ----------
   Layout follows the width the page really has (container queries on .sv-page), not the window, like the Profile page:
   the app sidebar takes room from 860px and the ad rails from 1300px.
   - Narrow page: one column of tiles. The Map button swaps the list for the map (.sv-map-open).
   - From 600px of page: tiles in an auto-fill grid; the labelled Sort select replaces the icon button.
   - From 820px of page content (a 1200px window with the sidebar, the same line as the Market, Store and Place wide layout): the map
     panel sits beside the list and the Map button is hidden. */

.sv-page { container-type: inline-size; container-name: sv; padding: 16px 16px 32px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- Header and tools ---------- */
.sv-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.sv-title-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.sv-h1 { margin: 0; }
.sv-count { font-size: 14px; color: var(--text-muted); white-space: nowrap; }
.sv-map-toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--brand-text);
  font: 600 14px/1 inherit; font-family: inherit; cursor: pointer;
}
.sv-map-toggle[aria-pressed="true"] { background: var(--brand-tint); border-color: var(--brand-text); }
.sv-tools { flex: 1 1 100%; display: flex; gap: 8px; min-width: 0; }
.sv-search {
  flex: 1; min-width: 0; height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text-muted);
}
.sv-search svg { flex: none; }
.sv-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; }
.sv-search:focus-within { border-color: var(--focus-ring); box-shadow: 0 0 0 2px var(--focus-ring); }

/* Sort: on a narrow page an icon button (the real select is stretched invisibly over it, so the native picker opens); on a
   wider page the word "Sort" and the visible select. */
.sv-sort {
  position: relative; flex: none; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text);
}
.sv-sort-text { display: none; font-size: 14px; color: var(--text-muted); }
.sv-sort select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font: inherit; font-size: 16px; }
.sv-sort:focus-within { border-color: var(--focus-ring); box-shadow: 0 0 0 2px var(--focus-ring); }

/* Type chips: one row; on a narrow page it scrolls sideways inside itself, never the page. */
.sv-chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 4px; }
.sv-chips::-webkit-scrollbar { display: none; }
.sv-chips .chip { flex: none; min-height: 44px; padding: 0 14px; font-size: 14px; font-weight: 600; background: var(--surface); }
.sv-chips .chip.active { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.sv-chip-count { font-weight: 500; opacity: 0.8; }

/* ---------- List ---------- */
.sv-layout { display: flex; gap: 24px; align-items: flex-start; }
.sv-list { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.sv-group-title { margin: 8px 0 0; font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.sv-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }

.sv-tile-wrap { position: relative; }
.sv-tile {
  display: flex; align-items: center; gap: 12px; min-height: 76px; box-sizing: border-box; height: 100%;
  padding: 10px 56px 10px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  color: var(--text); text-decoration: none;
}
.sv-tile:hover { border-color: var(--brand-text); }
.sv-tile:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.sv-thumb {
  flex: none; width: 52px; height: 52px; border-radius: 10px; color: #fff;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.sv-thumb svg { width: 24px; height: 24px; }
.sv-thumb-initials { font-weight: 700; font-size: 17px; }
.sv-tile-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sv-type-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.sv-tile-name { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.sv-tile-sub { margin: 0; font-size: 14px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sv-tile-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.sv-pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--brand-tint); color: var(--brand-text); }
.sv-pin-num {
  flex: none; width: 26px; height: 26px; border-radius: 999px; background: var(--brand); color: var(--on-brand);
  font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
/* The bookmark sits at the right, vertically centred (its 44px hit area comes from mobile-sizing.css). */
.sv-tile-wrap .save-toggle { top: 50%; right: 12px; transform: translateY(-50%); width: 36px; height: 36px; }
.sv-tile-wrap .save-toggle svg { width: 18px; height: 18px; }

.sv-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 24px 16px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-lg); }
.sv-empty p { margin: 0; font-size: 15px; color: var(--text); line-height: 1.45; }

/* ---------- Map ---------- */
.sv-map-panel { display: none; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.sv-map-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.sv-map-title { margin: 0; font-size: 16px; font-weight: 600; }
.sv-map-note { font-size: 14px; color: var(--text-muted); }
.sv-map { height: 60vh; min-height: 320px; max-height: 560px; }
.sv-map-none { margin: 0; padding: 16px; font-size: 14px; color: var(--text-muted); line-height: 1.45; }
.sv-map-pin {
  display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; box-sizing: border-box;
  border-radius: 999px 999px 999px 4px; transform: rotate(-45deg); background: var(--brand); border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); color: #fff; font-size: 13px; font-weight: 700;
}
.sv-map-pin > span { transform: rotate(45deg); line-height: 1; }

/* Narrow page with the Map button pressed: the map replaces the list. */
.sv-map-open .sv-list { display: none; }
.sv-map-open .sv-map-panel { display: flex; flex: 1 1 auto; min-width: 0; }

@container sv (min-width: 600px) {
  .sv-tools { flex: 0 1 auto; }
  .sv-search { width: 280px; flex: none; }
  .sv-sort { width: auto; padding: 0 4px 0 12px; }
  .sv-sort-text { display: inline; }
  .sv-sort-icon { display: none; }
  .sv-sort select { position: static; opacity: 1; width: auto; height: 100%; border: 0; background: transparent; color: var(--text); font-size: 14px; font-weight: 600; padding-right: 8px; }
  .sv-head { flex-wrap: nowrap; }
  .sv-title-row { flex: 1; }
  .sv-chips { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
  .sv-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
}

@container sv (min-width: 820px) {
  .sv-map-toggle { display: none; }
  .sv-map-open .sv-list { display: flex; }
  .sv-map-panel, .sv-map-open .sv-map-panel { display: flex; flex: 0 0 320px; position: sticky; top: calc(var(--topbar-h, 96px) + 12px); } /* below the header at its real height, as on Settings */
}
