:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2129;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e3e6eb;
  --chip: #f1f3f6;
  --ink: #1d2129;
  --ink-hover: #343a46;
  --focus: #2f6fed;
  --dk: #e1243c;
  --dk-soft: #fde9ec;
  --tl: #1554c0;
  --tl-soft: #e6eefc;
  --tr: #d9480f;
  --tr-soft: #fdede4;
  --ok: #0c8460;
  --ok-soft: #e4f4ed;
  --warn: #a35a06;
  --warn-soft: #fdf2e1;
  --star: #e6a011;
  --sale: #d92d20;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-family: "Segoe UI", Tahoma, system-ui, -apple-system, Roboto, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.ico, [data-icon] { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.rtl { direction: rtl; font-family: Tahoma, "Segoe UI", sans-serif; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; }

.store-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.store-dot.dk { background: var(--dk); }
.store-dot.tl { background: var(--tl); }
.store-dot.tr { background: var(--tr); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { font-weight: 650; font-size: 16px; white-space: nowrap; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--ink); color: #fff; }
.brand-stores {
  display: inline-flex; align-items: center; gap: 6px; margin-left: 4px;
  color: var(--muted); font-size: 12.5px; white-space: nowrap;
}
.brand-stores .store-dot.tl, .brand-stores .store-dot.tr { margin-left: 6px; }
.engine {
  display: flex; align-items: center; gap: 8px; flex: none;
  height: 28px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.engine .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.engine.ready .dot { background: var(--ok); }
.engine.starting .dot { background: var(--star); animation: pulse 1.1s ease-in-out infinite; }
.engine.error { color: var(--sale); border-color: #f6c5cc; }
.engine.error .dot { background: var(--sale); }

main { padding-top: 24px; padding-bottom: 56px; }

/* Search */
.search {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 6px 6px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15); }
.search-icon { color: var(--muted); }
.search input {
  flex: 1; min-width: 0; height: 42px;
  border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 16px; color: inherit;
}
.search input::-webkit-search-cancel-button { display: none; }

.primary {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  height: 42px; padding: 0 20px;
  border: 0; border-radius: 6px;
  background: var(--ink); color: #fff; font-weight: 600;
}
.primary:hover { background: var(--ink-hover); }
.primary:disabled { cursor: progress; opacity: 0.85; }
.primary:focus-visible, .icon-btn:focus-visible, .segmented button:focus-visible, .chip:focus-visible,
.link-btn:focus-visible, .title:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--text); text-decoration: none;
}
.icon-btn:hover { background: var(--chip); }
.icon-btn:disabled { opacity: 0.5; cursor: progress; }
.icon-btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn.ghost:hover { background: var(--chip); color: var(--text); }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.copied { color: var(--ok); border-color: #a9dcc6; }

/* Controls */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 12px; }
.spacer { flex: 1; }
.segmented {
  display: inline-flex; gap: 2px; padding: 3px; max-width: 100%;
  background: #e8eaee; border-radius: 8px;
  overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  display: inline-flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 12px;
  border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); font-size: 13px; white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] {
  background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow);
}

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track {
  position: relative; width: 34px; height: 20px; flex: none;
  border-radius: 999px; background: #cfd4dc; transition: background 0.15s;
}
.toggle .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s;
}
.toggle input:checked + .track { background: var(--ok); }
.toggle input:checked + .track::after { transform: translateX(14px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Recent searches */
.recent { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: var(--muted); }
.recent-list { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.recent-list::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; flex: none;
  height: 30px; max-width: 220px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--text); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { border-color: var(--ink); }

/* Results header */
.results-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 26px 0 12px; }
.results-title { min-width: 0; }
.results-head h2 { margin: 0; font-size: 18px; font-weight: 650; overflow-wrap: anywhere; }
.results-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* Best price verdict */
.verdict {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px;
  margin-bottom: 16px; padding: 14px 16px;
  background: var(--surface); border: 1px solid #a9dcc6; border-radius: var(--radius); box-shadow: var(--shadow);
}
.verdict-main { display: flex; align-items: center; gap: 14px; min-width: 0; }
.verdict-icon {
  width: 40px; height: 40px; border-radius: 8px; flex: none;
  display: grid; place-items: center; background: var(--ok-soft); color: var(--ok);
}
.verdict-text { min-width: 0; display: grid; gap: 2px; }
.verdict-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.verdict-label strong { color: var(--text); }
.verdict-price { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.verdict-title {
  color: var(--text); font-size: 13px; text-decoration: none; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.verdict-title:hover { text-decoration: underline; }
.verdict-compare { display: grid; gap: 6px; align-content: center; border-left: 1px solid var(--line); padding-left: 16px; }
.compare-row { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; }
.compare-row .name { width: 84px; flex: none; color: var(--muted); }
.compare-row .value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.compare-row .diff { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compare-row.win .value { color: var(--ok); }

/* Store columns */
.columns { display: grid; gap: 20px; align-items: start; }
.columns.dual { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.columns.triple { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.columns.triple .link-btn .label-text { display: none; }
.columns.triple .link-btn { width: 36px; padding: 0; justify-content: center; }
.column { display: grid; gap: 10px; min-width: 0; }
.col-head { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.store-badge {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  height: 28px; padding: 0 11px; border-radius: 999px;
  font-size: 13px; font-weight: 650;
}
.store-badge.dk { background: var(--dk-soft); color: #b3172c; }
.store-badge.tl { background: var(--tl-soft); color: var(--tl); }
.store-badge.tr { background: var(--tr-soft); color: #b23c0b; }
.col-meta { flex: 1; min-width: 0; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.col-meta .rtl { font-size: 12px; }

/* Product card (compact by default) */
.product {
  position: relative;
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  grid-template-areas: "thumb info" "price price";
  gap: 10px 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.product.cheapest { border-color: #a9dcc6; }
.rank {
  position: absolute; top: 8px; left: 8px; z-index: 1;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 11px; font-weight: 650;
}
.thumb {
  grid-area: thumb;
  width: 84px; height: 84px;
  display: grid; place-items: center; overflow: hidden;
  border: 1px solid #eef0f3; border-radius: 6px;
  background: #fff; color: #c3c8d0;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.info { grid-area: info; min-width: 0; display: grid; gap: 6px; align-content: start; }
.title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 13.5px; font-weight: 600; line-height: 1.75;
  color: var(--text); text-decoration: none; text-align: right;
}
.title:hover { color: var(--focus); }
.subtitle { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; }
.fact {
  display: inline-flex; align-items: center; gap: 5px;
  max-width: 100%; height: 24px; padding: 0 8px;
  border-radius: 999px; background: var(--chip); color: #344054;
  font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fact .label { overflow: hidden; text-overflow: ellipsis; }
.fact.star .ico { color: var(--star); }
.fact.ok { background: var(--ok-soft); color: var(--ok); }
.fact.warn { background: var(--warn-soft); color: var(--warn); }
.swatches { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 2px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.18); }

.pricing {
  grid-area: price;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: 10px; border-top: 1px solid var(--line); min-width: 0;
}
.price-block { display: grid; gap: 2px; min-width: 0; }
.price-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 20px; }
.price-top:empty { display: none; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px;
  border-radius: 999px; background: var(--sale); color: #fff;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.badge.best { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.rrp { color: var(--faint); font-size: 12px; text-decoration: line-through; font-variant-numeric: tabular-nums; }
.price { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.unit { margin-left: 4px; font-size: 12px; font-weight: 500; color: var(--muted); }
.product.unavailable .price { font-size: 15px; color: var(--faint); }
.product.unavailable .thumb img { filter: grayscale(1); opacity: 0.6; }
.actions { display: flex; gap: 6px; flex: none; }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--text);
  font-size: 13px; text-decoration: none; white-space: nowrap;
}
.link-btn:hover { border-color: var(--ink); }

/* Wide card when a single store is shown */
.columns.single .product {
  grid-template-columns: 112px minmax(0, 1fr) 250px;
  grid-template-areas: "thumb info price";
  align-items: center; gap: 16px; padding: 14px 16px;
}
.columns.single .thumb { width: 112px; height: 112px; }
.columns.single .title { font-size: 14px; }
.columns.single .pricing {
  flex-direction: column; align-items: flex-end; justify-content: center;
  padding-top: 0; border-top: 0;
}
.columns.single .price-block { justify-items: end; text-align: right; }
.columns.single .price-top { justify-content: flex-end; }
.columns.single .price { font-size: 21px; }

/* Column states */
.col-message {
  display: grid; justify-items: center; gap: 8px; padding: 28px 16px; text-align: center;
  border: 1px dashed #d5d9e0; border-radius: var(--radius); color: var(--muted);
}
.col-message strong { color: var(--text); font-size: 14px; }
.col-message p { margin: 0; max-width: 380px; font-size: 13px; overflow-wrap: anywhere; }
.col-message .ico { color: var(--faint); }
.col-message.error .ico { color: var(--sale); }

/* Loading skeleton */
.skeleton .sk {
  border-radius: 6px;
  background: linear-gradient(90deg, #eef0f3 25%, #f6f7f9 50%, #eef0f3 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.skeleton .thumb { border: 0; }
.sk.line { height: 13px; }
.sk.w90 { width: 90%; } .sk.w60 { width: 60%; } .sk.w40 { width: 40%; }
.sk.price-sk { width: 140px; height: 24px; }
.sk.btn-sk { width: 80px; height: 34px; }

/* Empty and intro states */
.state {
  display: grid; justify-items: center; gap: 10px;
  margin-top: 56px; padding: 0 12px; text-align: center; color: var(--muted);
}
.state:empty { display: none; }
.state-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
}
.state h3 { margin: 4px 0 0; color: var(--text); font-size: 17px; font-weight: 650; }
.state .chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 8px;
  background: #1d2129; color: #fff; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); z-index: 20;
}

.spin { animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 1100px) {
  .columns.dual .link-btn .label-text { display: none; }
  .columns.dual .link-btn { width: 36px; padding: 0; justify-content: center; }
  .columns.triple { grid-template-columns: minmax(0, 1fr); }
  .columns.triple .link-btn .label-text { display: inline; }
  .columns.triple .link-btn { width: auto; padding: 0 12px; }
}

@media (max-width: 900px) {
  .columns.dual { grid-template-columns: minmax(0, 1fr); }
  .columns.dual .link-btn .label-text { display: inline; }
  .columns.dual .link-btn { width: auto; padding: 0 12px; }
  .verdict { grid-template-columns: minmax(0, 1fr); }
  .verdict-compare { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 10px; }
  .brand-stores { display: none; }
}

@media (max-width: 760px) {
  .wrap { padding: 0 14px; }
  .primary .label-text { display: none; }
  .primary { padding: 0 14px; }
  .spacer { display: none; }
  .columns.single .product {
    grid-template-columns: 84px minmax(0, 1fr);
    grid-template-areas: "thumb info" "price price";
    gap: 10px 14px; padding: 12px 14px;
  }
  .columns.single .thumb { width: 84px; height: 84px; }
  .columns.single .pricing {
    flex-direction: row; align-items: center; justify-content: space-between;
    padding-top: 10px; border-top: 1px solid var(--line);
  }
  .columns.single .price-block { justify-items: start; text-align: left; }
  .columns.single .price-top { justify-content: flex-start; }
  .columns .link-btn .label-text, .columns.dual .link-btn .label-text { display: none; }
  .columns .link-btn, .columns.dual .link-btn { width: 36px; padding: 0; justify-content: center; }
}

@media (max-width: 420px) {
  .engine #engine-text { display: none; }
  .engine { padding: 0 9px; }
  .price, .columns.single .price { font-size: 17px; }
  .verdict-price { font-size: 19px; }
}
