:root {
  color-scheme: light;
  --bg: #f5f4ef;
  --panel: #ffffff;
  --panel-alt: #efede6;
  --ink: #171717;
  --muted: #65615b;
  --line: #d8d3c8;
  --accent: #006d77;
  --accent-strong: #004f57;
  --warm: #b45f06;
  --good: #23764b;
  --shadow: 0 10px 26px rgba(25, 21, 16, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.4;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(245, 244, 239, 0.94);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.8vw, 2.15rem);
  line-height: 1.05;
}

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

.icon-button,
.source-link,
.ghost-button,
.load-more,
.tab-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 1.2rem;
}

.source-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 2.5vw, 30px) 44px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.stat strong {
  font-size: 1.55rem;
  line-height: 1.05;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1.7fr) repeat(7, minmax(116px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

label,
.search-wrap {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(0, 109, 119, 0.22);
  outline-offset: 2px;
}

.ghost-button {
  padding: 0 16px;
  color: var(--accent-strong);
  font-weight: 800;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 10px;
}

.tab-button {
  padding: 0 14px;
  color: var(--muted);
  font-weight: 800;
}

.tab-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.result-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  color: var(--muted);
}

.result-bar strong {
  color: var(--ink);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

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

.product-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.image-link {
  display: block;
  aspect-ratio: 1 / 1;
  background:
    linear-gradient(135deg, rgba(0, 109, 119, 0.08), rgba(180, 95, 6, 0.07)),
    var(--panel-alt);
}

.image-link img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 14px;
  mix-blend-mode: multiply;
}

.image-link img.is-missing {
  opacity: 0.32;
}

.product-content {
  display: grid;
  gap: 10px;
  padding: 13px;
}

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

.price {
  color: var(--accent-strong);
  font-size: 1.05rem;
}

.match-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.product-card h2 {
  min-height: 3.8em;
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.28;
}

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

.chip {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--panel-alt);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.factory {
  border-color: rgba(0, 109, 119, 0.26);
  background: rgba(0, 109, 119, 0.09);
  color: var(--accent-strong);
}

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

.flag-row.muted {
  color: var(--muted);
}

.flag-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flag-badge.best {
  border-color: #d1a326;
  background: #ffe8a3;
  color: #5f4300;
}

.flag-badge.super {
  border-color: #8fbd7f;
  background: #d9edcf;
  color: #1e5a34;
}

.recommendation {
  min-height: 3.1em;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.product-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #ece8dd;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

td {
  font-size: 0.9rem;
}

tbody tr:hover {
  background: rgba(0, 109, 119, 0.05);
}

.table-product {
  display: grid;
  grid-template-columns: 52px minmax(220px, 1fr);
  gap: 10px;
  align-items: start;
}

.table-product img {
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-alt);
  object-fit: contain;
}

.table-product a {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

.subtext {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.score {
  color: var(--good);
  font-weight: 900;
}

.load-more {
  display: block;
  width: min(300px, 100%);
  margin: 18px auto 0;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.load-more[hidden] {
  display: none;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1120px) {
  .toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    padding-top: 14px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .search-wrap,
  .toolbar label:nth-of-type(1),
  .toolbar label:nth-of-type(2),
  .toolbar label:nth-of-type(3),
  .toolbar label:nth-of-type(4),
  .toolbar label:nth-of-type(7),
  .ghost-button {
    grid-column: 1 / -1;
  }

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

@media (max-width: 520px) {
  .app-header {
    position: static;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
  }

  .source-link {
    flex: 1;
  }

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

  .toolbar label:nth-of-type(n),
  .ghost-button {
    grid-column: auto;
  }
}
