:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #eef3f1;
  --text: #172126;
  --muted: #627179;
  --line: #d8e1df;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #dff3ef;
  --gold: #9f6a05;
  --warn: #9a3412;
  --shadow: 0 12px 30px rgba(14, 28, 35, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

button {
  cursor: pointer;
  min-height: 38px;
  padding: 0 12px;
}

button:hover,
select:hover,
input:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(180px, auto) minmax(260px, 520px) auto;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

.brand {
  display: inline-flex;
  margin-right: 12px;
  color: var(--text);
  font-size: 24px;
  font-weight: 750;
  text-decoration: none;
}

.summary {
  color: var(--muted);
  font-size: 14px;
}

.search {
  display: flex;
  gap: 8px;
}

.search input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
}

.search button,
.primary-action {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.top-actions button,
.filters button {
  background: #fff;
}

#savedCount {
  display: inline-grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  align-items: start;
  min-height: calc(100vh - 64px);
}

.filters {
  position: sticky;
  top: 64px;
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 64px);
  overflow: auto;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: var(--surface-soft);
}

.filters select,
.filters button,
.filters input {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.multi-filter {
  display: grid;
  gap: 6px;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  max-width: 100%;
  padding: 0 8px;
  border-color: var(--accent-soft);
  border-radius: 999px;
  background: #fff;
  color: var(--accent-dark);
  font-size: 12px;
}

.chip span {
  color: var(--muted);
  font-weight: 700;
}

.option-menu {
  display: grid;
  max-height: 218px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.option-menu button {
  min-height: 34px;
  padding: 6px 10px;
  border: 0;
  border-radius: 0;
  color: var(--text);
  font-size: 13px;
  text-align: left;
}

.option-menu button + button {
  border-top: 1px solid #edf2f1;
}

.option-menu button:hover {
  background: var(--accent-soft);
}

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

.content {
  padding: 18px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
  margin-bottom: 12px;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.pet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.pet-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(10, 20, 25, 0.05);
}

.pet-card-compact {
  min-width: 0;
}

.pet-open {
  display: grid;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  text-align: left;
}

.image-wrap {
  display: block;
  background: #dfe8eb;
}

.pet-image,
.placeholder {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #dfe8eb;
}

.placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.detail-placeholder {
  aspect-ratio: 16 / 8;
  border-radius: 8px;
}

.pet-info {
  display: grid;
  gap: 6px;
  padding: 12px;
}

.pet-topline {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.pet-name {
  min-width: 0;
  font-size: 18px;
  font-weight: 750;
  line-height: 1.2;
}

.fee {
  flex: 0 0 auto;
  color: var(--gold);
  font-size: 14px;
  font-weight: 750;
}

.pet-meta,
.freshness {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.freshness {
  font-size: 12px;
}

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

.tag {
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  padding: 3px 8px;
}

.save-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 32px;
  border-color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.94);
  font-size: 13px;
}

.save-toggle.is-saved,
.primary-action.is-saved {
  border-color: #9f6a05;
  background: #fff7df;
  color: #6f4a04;
}

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 22px 0;
  color: var(--muted);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  justify-items: end;
  background: rgba(18, 28, 34, 0.48);
}

.detail {
  position: relative;
  width: min(940px, 100vw);
  height: 100vh;
  overflow: auto;
  background: var(--surface);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.18);
}

.close {
  position: sticky;
  top: 12px;
  left: calc(100% - 52px);
  z-index: 5;
  width: 40px;
  height: 40px;
  margin: 12px;
  background: #fff;
  font-size: 22px;
  line-height: 1;
}

.detail-body {
  display: grid;
  gap: 22px;
  padding: 0 24px 28px;
}

.gallery {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
}

.gallery img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: #dfe8eb;
}

.gallery img:first-child {
  grid-row: span 2;
}

.detail-hero {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.detail h1 {
  margin: 0 0 10px;
  font-size: 34px;
  line-height: 1.08;
}

.detail-section {
  display: grid;
  gap: 10px;
}

.detail-section h2,
.panel-head h2 {
  margin: 0;
  font-size: 18px;
}

.detail-text {
  white-space: pre-wrap;
  color: #344148;
  line-height: 1.55;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.fact-grid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
}

.fact-grid dt {
  color: var(--muted);
  font-size: 12px;
}

.fact-grid dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-weight: 650;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions a,
.actions button,
.primary-action {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 6px;
}

.actions a {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.rescue-block {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
}

.similar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}

.side-panel,
.compare-panel {
  position: fixed;
  z-index: 60;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.side-panel {
  top: 0;
  right: 0;
  width: min(430px, 100vw);
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--line);
}

.compare-panel {
  left: 18px;
  right: 18px;
  bottom: 18px;
  max-height: min(72vh, 720px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.saved-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.saved-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.saved-item img,
.saved-thumb {
  width: 72px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #dfe8eb;
}

.saved-thumb {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.saved-item button {
  text-align: left;
}

.saved-item button:first-of-type {
  display: grid;
  gap: 3px;
  padding: 0;
  border: 0;
}

.saved-item span {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compare-body {
  padding: 14px;
}

.compare-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  font-size: 14px;
}

.compare-table th,
.compare-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.compare-table th {
  position: sticky;
  top: 57px;
  background: #f9fbfb;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.compare-table button {
  padding: 0;
  border: 0;
  color: var(--accent-dark);
  font-weight: 700;
  text-align: left;
}

.empty,
.error {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.error {
  color: var(--warn);
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }

  .shell {
    grid-template-columns: 1fr;
  }

  .filters {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content {
    padding: 12px;
  }

  .gallery {
    grid-template-columns: 1fr;
  }

  .detail-body {
    padding-inline: 16px;
  }

  .fact-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .filters,
  .range-row,
  .fact-grid {
    grid-template-columns: 1fr;
  }

  .pet-grid {
    grid-template-columns: 1fr;
  }

  .detail-hero {
    display: grid;
  }

  .saved-item {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .saved-item img,
  .saved-thumb {
    width: 56px;
  }

  .saved-item button:last-child {
    grid-column: 1 / -1;
  }
}
