:root {
  --results-row-border: #ebeae1;
}

body.dark-mode {
  --results-row-border: #1f2933;
}

/* ===== Dark mode toggle (isolated, non-invasive) ===== */

.dark-toggle {
  grid-column: 3;
  justify-self: end;
  /* SAME RIGHT EDGE */
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin: 0;
  gap: 8px;
  align-self: center;
}

.dark-label {
  font-size: 12px;
  color: #707070;
}

.switch {
  position: relative;
  width: 46px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background-color: #cfcfcf;
  border-radius: 999px;
  transition: 0.3s;
}

.slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: 0.3s;
}

.switch input:checked+.slider {
  background-color: #eba265;
}

.switch input:checked+.slider::before {
  transform: translateX(24px);
}

/* ===== Dark mode styles (scoped, safe) ===== */

body.dark-mode {
  background-color: #1f2933;
}

body.dark-mode #sortSelect {
  background-color: #314355;
}

body {
  transition: background-color 0.25s ease;
}

#sortSelect {
  transition: background-color 0.25s ease;
}

#resultsTable tbody td {
  border-top: 3px solid #1f2933 !important;
}


/* =====================================
   Scroll to top button
   ===================================== */
#scrollToTopBtn {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: #343434;
  color: #ffffff;
  font-size: 22px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(20px);

  /* hidden by default */
  z-index: 9999;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease,
    background-color 0.25s ease;
}

#scrollToTopBtn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

#scrollToTopBtn:hover {
  background: #343434;
}

/* ---------- Sort-bar styling ---------- */

.sort-bar {
  justify-self: end;
  gap: 6px;
  display: flex;
  align-items: center;
  padding: 15px;
  color: #707070;
  font-size: 12px;
  align-self: center;
}

#sortSelect {
  background-color: #cfcfcf;
  border-radius: 4px;
  color: #ffffff;
  padding: 5px;
  font-size: 12px;
  border: none;
  max-width: 120px;
}

/* ---------- Confidence indicator styling ---------- */

.confidence {
  font-size: 11px;
  margin-top: 2px;
}

.confidence.high {
  color: #2e7d32;
}

.confidence.low {
  color: #f57c00;
}

.confidence.learning {
  color: #999;
  font-style: italic;
}

/* ---------- Market info styling ---------- */

.market-info {
  font-size: 12px;
  color: #444;
  margin-top: 4px;
}

.market-info strong {
  color: #2e7d32;
}

.market-info.muted {
  color: #999;
}

/* ---------- Tagline styilng ---------- */
.tagline {
  color: #a7cce2;
  font-size: 14px;
  font-weight: 500;
  padding-left: 16px;
  margin-top: -8px;
}

/* ---------- Disable dealLegend ---------- */
#dealLegend {
  display: none;
}

/* ---------- Global reset ---------- */
* {
  box-sizing: border-box;
}

/* ---------- Page ---------- */
body {
  margin: 0;
  background: #ebeae1;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #1f2933;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  padding: 16px;
}

/* Logo styling */
.logo {
  height: 40px;
  width: auto;
  display: block;
}

/* ---------- Table (desktop-safe) ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px !important;
}

thead {
  background: #e8f5e9;
}

thead th {
  padding: 10px;
  text-align: left;
  color: #c4c4c4;
  font-weight: 600;
  font-size: 11px;
  background: #343434;
  text-transform: uppercase;
}

tbody td {
  padding: 10px;
  border-bottom: 1px solid #e5e7eb;
}

th {
  border: 1px solid #707070 !important;
}

#resultsTable tbody td {
  border-top: 3px solid var(--results-row-border) !important;
}

#resultsTable thead th:nth-child(1) {
  font-weight: 600;
}

/* =====================================
   Stabilize table layout (no shifting)
   ===================================== */

#resultsTable {
  table-layout: fixed;
  width: 100%;
}

/* ---------- Images (EXCLUDING logo) ---------- */
img:not(.logo) {
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
}

/* ================================
   Search result table adjustments
   ================================ */
@media (min-width: 769px) {
  #resultsTable img {
    max-width: 140px;
    max-height: 140px;
    width: auto;
    height: auto;
    object-fit: contain;
  }

  #resultsTable tbody tr {
    height: auto;
  }
}

/* Fixed image column width */
#resultsTable th:nth-child(2),
#resultsTable td:nth-child(2) {
  width: 160px;
  text-align: center;
}

/* Shift Image + Item columns slightly to the right */
#resultsTable th:nth-child(2),
#resultsTable td:nth-child(2),
#resultsTable th:nth-child(3),
#resultsTable td:nth-child(3) {
  padding-left: 22px;
}

#resultsTable td:nth-child(2) img {
  max-width: 140px;
  max-height: 140px;
  width: auto;
  height: auto;
  display: block;
  margin: 0 auto;
}

#resultsTable th:nth-child(3),
#resultsTable td:nth-child(3) {
  width: auto;
}

#resultsTable th:nth-child(4),
#resultsTable td:nth-child(4),
#resultsTable th:nth-child(5),
#resultsTable td:nth-child(5),
#resultsTable th:nth-child(6),
#resultsTable td:nth-child(6),
#resultsTable th:nth-child(7),
#resultsTable td:nth-child(7) {
  width: 140px;
}

/* ================================
   Reults table hover
   ================================ */

#resultsTable thead th {
  cursor: pointer;
}

#resultsTable thead th:hover {
  text-decoration: underline;
}


/* ================================
   Center Marketplace column (desktop)
   ================================ */
@media (min-width: 769px) {

  #resultsTable th:nth-child(1),
  #resultsTable td:nth-child(1) {
    width: 130px;
    text-align: center;
    white-space: nowrap;
    font-weight: 500;
  }
}

/* ---------- Controls ---------- */
#searchInput {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #7fb8df;
  background-color: #cadfed;
  font-size: 16px;
  outline: none;
  flex: 1;
  min-width: 0;
}

#searchInput:focus {
  background-color: #a9d2ee;
  border-color: #5fa7d6;
  outline: none;
}

#searchInput:-webkit-autofill,
#searchInput:-webkit-autofill:hover,
#searchInput:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0px 1000px #a9d2ee inset;
  -webkit-text-fill-color: #1f2933;
}

#runAnalysis {
  padding: 12px 18px;
  border-radius: 10px;
  border: none;
  background: #b8d677;
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.25s ease;
}

#runAnalysis:hover {
  background: #b8d677cc;
}

#search-wrapper.scrolled #runAnalysis:hover {
  background-color: #323232;
}

#runAnalysis:active {
  transform: scale(0.98);
}

/* ---------- Loading Bar ---------- */
#loadingContainer {
  margin-bottom: 10px;
  background-color: transparent !important;
}

#loadingBar {
  width: 0%;
  height: 20px;
  background: #ff9c9c;
  color: #ffffff;
  text-align: center;
  line-height: 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}

/* ---------- Search + button container ---------- */
.controls-gap {
  grid-column: 2;
}

.listings-button {
  grid-column: 3;
  justify-self: end;
  /* RIGHT align */
}

.controls-wrapper {
  display: grid;
  grid-template-columns: 1fr 15px auto;
  /* F | G | H */
  grid-template-rows: auto auto;
  gap: 6px 0;
  width: 100%;
  max-width: 760px;
  /* matches your existing content width */
  align-items: center;
}

/* Sticky container */
#search-wrapper {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: transparent;
  width: 100%;
}

.search-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  background: transparent;
  width: 100%;
  box-sizing: border-box;
  /* ADD */
}

/* Button style when scrolled */
#search-wrapper.scrolled #runAnalysis {
  background-color: #343434;
  color: #fff;
}

/* ---------- Time badge ---------- */
.time-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  background: #f5f5f5;
  color: #1f2933;
  font-size: 12px;
  white-space: nowrap;
}

/* ---------- Mobile & Tablet ---------- */
@media (max-width: 768px) {

  .time-badge {
    width: fit-content;
    max-width: max-content;
  }

  #searchInput {
    width: 100%;
    padding: 12px 14px;
  }

  table {
    font-size: 14px;
  }

  thead {
    display: none;
  }

  tbody tr,
  tbody td {
    display: table-row;
    display: table-cell;
  }

  #resultsTable {
    display: none;
  }

  /* ======================================================
   MOBILE CARDS
   ====================================================== */
  #mobileResults {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .mobile-card {
    display: grid;
    grid-template-columns: 30% 70%;
    gap: 16px;
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    overflow: hidden;
  }

  .mobile-left img {
    width: 100%;
    max-width: none !important;
    max-height: none !important;
    height: auto;
    border-radius: 8px;
  }

  .mobile-right {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8%;
    padding-left: 10%;
  }

  .mobile-marketplace {
    padding: 5%;
  }

  /* fixed selector typo */
  .mobile-left,
  .mobile-right {
    background-color: inherit;
  }
}

/* ======================================================
   HOMEPAGE DEAL GRID
   ====================================================== */
/* ---------- Flip card base ---------- */

.homepage-deal-card {
  perspective: 1000px;
}

.deal-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

/* front + back */
.deal-card-front,
.deal-card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 10px;
  overflow: hidden;
}

.deal-card-front {
  display: flex;
  align-items: flex-end;
}

/* back side */
.deal-card-back {
  background: #343434;
  color: #ffffff;
  transform: rotateY(180deg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
}

/* back text styling */
.deal-back-marketplace {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 12px;
  color: rgba(244, 162, 85, 0.85);
  margin-bottom: 4px;
}

/* Marketplace-specific colors */

.deal-back-marketplace.marketplace-auctionet {
  color: #f3527e;
}

.deal-back-marketplace.marketplace-tradera {
  color: #fcae70;
}

.deal-back-marketplace.marketplace-blocket {
  color: #91d667;
}

.deal-back-marketplace.marketplace-olsens {
  color: #92d4f4;
}

.deal-back-marketplace.marketplace-karljohan {
  color: #b38adb;
}

.deal-back-marketplace.marketplace-budi {
  color: #ece781;
}

.deal-back-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
}

.deal-back-meta {
  font-size: 12px;
  opacity: 0.7;
}

/* ======================================================
   Homepage deal card marketplace backgrounds
   ====================================================== */

/* Tradera */
.homepage-deal-card.marketplace-tradera .deal-card-front,
.homepage-deal-card.marketplace-tradera .deal-card-back {
  background-color: rgba(252, 174, 112, 0.25);
}

/* Auctionet */
.homepage-deal-card.marketplace-auctionet .deal-card-front,
.homepage-deal-card.marketplace-auctionet .deal-card-back {
  background-color: rgba(243, 82, 126, 0.25);
}

/* Blocket */
.homepage-deal-card.marketplace-blocket .deal-card-front,
.homepage-deal-card.marketplace-blocket .deal-card-back {
  background-color: rgba(145, 214, 103, 0.25);
}

/* Olsens */
.homepage-deal-card.marketplace-olsens .deal-card-front,
.homepage-deal-card.marketplace-olsens .deal-card-back {
  background-color: rgba(146, 212, 244, 0.25);
}

/* Karljohan */
.homepage-deal-card.marketplace-karljohan .deal-card-front,
.homepage-deal-card.marketplace-karljohan .deal-card-back {
  background-color: rgba(179, 138, 219, 0.25);
}

/* Budi */
.homepage-deal-card.marketplace-budi .deal-card-front,
.homepage-deal-card.marketplace-budi .deal-card-back {
  background-color: rgba(236, 231, 129, 0.25);
}


/* ---------- Desktop hover flip only ---------- */
@media (hover: hover) and (pointer: fine) {
  .homepage-deal-card:hover .deal-card-inner {
    transform: rotateY(180deg);
  }
}

.homepage-deals {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-top: 24px;
}

/* Individual deal card */
.homepage-deal-card {
  position: relative;
  background: transparent;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  aspect-ratio: 1 / 1;
  cursor: pointer;
}

/* Base card shadow with delayed return */
.homepage-deal-card {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: box-shadow 0.2s ease 0.6s;
  /* delay matches flip duration */
}

/* Remove shadow immediately on hover (before flip starts) */
@media (hover: hover) and (pointer: fine) {
  .homepage-deal-card:hover {
    box-shadow: none;
    transition-delay: 0s;
  }
}

/* ======================================================
   Mobile: non-animated flip (show back side only)
   Exact same styling as desktop back
   ====================================================== */
@media (hover: none) and (pointer: coarse) {

  /* Disable all 3D behavior on mobile */
  .deal-card-inner {
    transform: none !important;
    transform-style: flat;
    width: 100%;
    height: 100%;
    position: relative;
  }

  /* Back face must face camera */
  .deal-card-back {
    transform: none !important;
  }

  /* Faces fill card */
  .deal-card-front,
  .deal-card-back {
    width: 100%;
    height: 100%;
  }

  /* Default: front visible */
  .deal-card-front {
    display: flex;
  }

  .deal-card-back {
    display: none;
  }

  /* Flipped: show back */
  .homepage-deal-card.flipped .deal-card-front {
    display: none;
  }

  .homepage-deal-card.flipped .deal-card-back {
    display: flex;
  }

  /* Mobile: reduce back-side content size */
  .deal-card-back {
    font-size: 0.8em;
    /* ~20% smaller */
    gap: 6px;
    justify-content: flex-start;
  }

  /* Marketplace name: always fully visible */
  .deal-back-marketplace {
    flex-shrink: 0;
    white-space: nowrap;
    overflow: visible;
  }

  /* Title: clip instead of marketplace */
  .deal-back-title {
    font-size: 0.85em;
    line-height: 1.1;

    overflow: hidden;
    text-overflow: ellipsis;

    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }

  /* Meta can shrink first if space is tight */
  .deal-back-meta {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

/* Image placeholder (image wiring later if desired) */
.homepage-deal-card .deal-image {
  position: absolute;
  inset: 0;
  background: #f2f2f2;
}

/* Price */
.homepage-deal-card .deal-price {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 2;
  background: rgba(0, 0, 0, 0.75);
  color: #ffffff;
  font-weight: bold;
  font-size: 14px;
  padding: 6px 8px;
  border-radius: 0 8px 0 0;
}

/* Deal badge */
.homepage-deal-card .deal-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #b8d677;
  color: #1f1f1f;
  font-size: 12px;
  font-weight: bold;
  padding: 4px 6px;
  border-radius: 6px;
}

.price-active-bidding {
  color: #cfcfcf;          /* neutral grey */
  font-style: italic;
  font-weight: normal;
  font-size: 14px;
}

/* ======================================================
   MOBILE HOMEPAGE GRID (DISCOVERY MODE)
   ====================================================== */
@media (max-width: 600px) {
  .homepage-deals {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 1100px) {
  .homepage-deals {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 768px) {
  .homepage-deals {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .homepage-deal-card {
    border-radius: 8px;
  }

  .homepage-deal-card .deal-price {
    font-size: 12px;
    padding: 4px 6px;
  }

  .homepage-deal-card .deal-badge {
    font-size: 11px;
    padding: 3px 5px;
  }
}

/* ======================================================
   Generic styling
   ====================================================== */