/* ============================================================
   SnagPulse Layout System
   ============================================================
   Main layout, grid, responsive structure.
   ============================================================ */

/* === Reset & Base === */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  max-width: 100vw;
  overflow-x: hidden;
}

html::-webkit-scrollbar {
  width: var(--scrollbar-w);
}

html::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

html::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Skip link for accessibility */
.sp-skip-link {
  position: absolute;
  top: -100%;
  left: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: var(--accent-coral);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: var(--fw-semibold);
  z-index: 9999;
  text-decoration: none;
}

.sp-skip-link:focus {
  top: var(--sp-4);
}

/* === Main Layout === */

.sp-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
}

.sp-main {
  flex: 1;
}

/* Content container */
.sp-container {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--content-pad);
}

/* Main + Sidebar layout */
.sp-layout {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  gap: var(--sp-8);
  padding: var(--sp-8) 0;
}

.sp-layout__main {
  min-width: 0;
}

.sp-layout__sidebar {
  position: sticky;
  top: calc(var(--header-h) + var(--sp-8));
  align-self: start;
  max-height: calc(100vh - var(--header-h) - var(--sp-16));
  overflow-y: auto;
  scrollbar-width: none;
}

.sp-layout__sidebar::-webkit-scrollbar {
  display: none;
}

/* === Deal Grid === */

.sp-deal-grid {
  display: flex;
  flex-direction: column;
  gap: var(--card-gap);
}

/* Grid mode (togglable) */
.sp-deal-grid--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  gap: var(--card-gap);
}

/* === Section Headers === */

.sp-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
}

.sp-section-title {
  font-family: var(--ff-display);
  font-size: var(--fs-display-md);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-tight);
}

.sp-section-link {
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  color: var(--accent-ice);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.sp-section-link:hover {
  color: var(--accent-ice-hover);
}

/* === Category Page Header === */

.sp-category-header {
  padding: var(--sp-10) 0 var(--sp-6);
}

.sp-category-header__title {
  font-size: var(--fs-display-lg);
  font-family: var(--ff-display);
  font-weight: var(--fw-bold);
  margin-bottom: var(--sp-3);
}

.sp-category-header__desc {
  font-size: var(--fs-body);
  color: var(--text-secondary);
  max-width: 640px;
  line-height: var(--lh-relaxed);
}

/* Subcategory pills — wrap to show all */
.sp-subcategory-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-4) 0;
  margin-bottom: var(--sp-2);
}

/* === Deal Detail Layout === */

.sp-detail-layout {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  gap: var(--sp-8);
  padding: var(--sp-6) 0 var(--sp-16);
}

.sp-detail-layout__main {
  max-width: 720px;
  min-width: 0;
}

.sp-detail-layout__sidebar {
  position: sticky;
  top: calc(var(--header-h) + var(--sp-8));
  align-self: start;
}

/* Detail page: product hero */
.sp-deal-hero {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  margin-bottom: var(--sp-6);
}

.sp-deal-hero__image {
  width: 100%;
  aspect-ratio: 1200 / 630;
  object-fit: cover;
  border-radius: var(--radius-lg);
}

.sp-deal-hero__info {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.sp-deal-hero__title {
  font-size: var(--fs-display-lg);
  font-family: var(--ff-display);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
}

.sp-deal-hero__store-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-small);
}

.sp-deal-hero__price-block {
  display: flex;
  align-items: baseline;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-top: var(--sp-2);
}

.sp-deal-hero__context {
  font-size: var(--fs-small);
  color: var(--accent-mint);
  font-weight: var(--fw-medium);
}

/* === Blog Layout === */

.sp-blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--card-gap);
}

/* Blog article: single column, editorial */
.sp-article-layout {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--sp-8) var(--content-pad) var(--sp-16);
}

.sp-article-header {
  margin-bottom: var(--sp-8);
}

.sp-article-header__tag {
  display: inline-block;
  font-size: var(--fs-micro);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  color: var(--accent-coral);
  margin-bottom: var(--sp-3);
}

.sp-article-header__title {
  font-size: var(--fs-display-xl);
  margin-bottom: var(--sp-4);
}

.sp-article-header__meta {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-small);
  color: var(--text-secondary);
}

.sp-article-header__image {
  width: 100%;
  border-radius: var(--radius-xl);
  margin: var(--sp-8) 0;
}

/* === Search Results Layout === */

.sp-search-layout {
  padding: var(--sp-8) 0;
}

.sp-search-header {
  margin-bottom: var(--sp-6);
}

.sp-search-header__title {
  font-size: var(--fs-display-lg);
  margin-bottom: var(--sp-2);
}

.sp-search-header__count {
  font-size: var(--fs-body);
  color: var(--text-secondary);
}

/* === Error Page === */

.sp-error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: var(--sp-16) var(--content-pad);
}

.sp-error-page__code {
  font-family: var(--ff-mono);
  font-size: clamp(4rem, 10vw, 8rem);
  font-weight: var(--fw-bold);
  color: var(--border-emphasis);
  line-height: 1;
  margin-bottom: var(--sp-4);
}

.sp-error-page__title {
  font-size: var(--fs-display-lg);
  margin-bottom: var(--sp-3);
}

.sp-error-page__desc {
  font-size: var(--fs-body);
  color: var(--text-secondary);
  max-width: 400px;
  margin-bottom: var(--sp-8);
}

/* === Disclosure Bar (top of page) === */

.sp-disclosure-bar {
  background: var(--bg-deep);
  padding: var(--sp-1) var(--content-pad);
  text-align: center;
  font-size: var(--fs-small);
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--border-subtle);
}

.sp-disclosure-bar a {
  color: var(--text-tertiary);
  text-decoration: underline;
  text-decoration-color: var(--border-default);
  text-underline-offset: 2px;
}

.sp-disclosure-bar a:hover {
  color: var(--text-secondary);
}

/* === Mobile Bottom Navigation === */

.sp-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-sticky);
  background: var(--surface-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border-subtle);
  padding: var(--sp-2) 0;
  padding-bottom: max(var(--sp-2), env(safe-area-inset-bottom));
}

.sp-bottom-nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.sp-bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--sp-1) var(--sp-3);
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 10px;
  font-weight: var(--fw-medium);
  transition: color var(--dur-fast) ease;
  -webkit-tap-highlight-color: transparent;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.sp-bottom-nav__item.is-active {
  color: var(--accent-coral);
}

.sp-bottom-nav__item:active {
  color: var(--text-primary);
}

.sp-bottom-nav__icon {
  width: 22px;
  height: 22px;
}

/* === Responsive === */

/* === Filter panel: desktop dropdown (not bottom sheet) === */
@media (min-width: 769px) {
  .sp-filter-panel {
    align-items: flex-start;
    justify-content: center;
  }

  .sp-filter-panel__backdrop {
    background: rgba(0, 0, 0, 0.15);
  }

  .sp-filter-panel__sheet {
    max-width: 420px;
    max-height: 70vh;
    margin-top: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    transform: translateY(-8px);
    opacity: 0;
    transition: transform var(--dur-base) var(--ease-out), opacity var(--dur-base) ease;
  }

  .sp-filter-panel.is-open .sp-filter-panel__sheet {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 1024px) {
  /* Header: reduce gap to prevent overflow */
  .sp-header__inner {
    gap: var(--sp-3);
  }

  /* Push actions + hamburger to far right when nav is hidden */
  .sp-header__actions {
    margin-left: auto;
  }

  /* Hide Sign In button — accessible via Account in bottom nav */
  .sp-header__actions .sp-btn-ghost {
    display: none;
  }

  .sp-layout {
    grid-template-columns: 1fr;
  }

  .sp-layout__sidebar {
    position: static;
    max-height: none;
  }

  /* Sidebar: fill full width on mobile (not fixed 340px) */
  .sp-sidebar {
    width: 100%;
  }

  .sp-detail-layout {
    grid-template-columns: 1fr;
  }

  .sp-detail-layout__sidebar {
    position: static;
  }

  .sp-nav {
    display: none;
  }

  /* Mobile nav: fullscreen overlay when hamburger is open */
  .sp-nav.is-mobile-open {
    display: flex;
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(100vh - var(--header-h));
    height: calc(100dvh - var(--header-h));
    background: var(--bg-primary);
    flex-direction: column;
    align-items: stretch;
    padding: var(--sp-6);
    z-index: var(--z-overlay);
    overflow-y: auto;
    flex: none;
  }

  .sp-nav.is-mobile-open .sp-nav__item {
    padding: var(--sp-3) var(--sp-4);
    font-size: var(--fs-body);
    width: 100%;
    text-align: left;
  }

  .sp-nav.is-mobile-open .sp-dropdown {
    position: static;
    box-shadow: none;
    border: none;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    margin-top: var(--sp-2);
  }

  .sp-nav.is-mobile-open .sp-dropdown--mega.is-open {
    display: flex;
    flex-direction: column;
    min-width: auto;
  }

  .sp-hamburger {
    display: flex;
  }

  .sp-hero__inner {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .sp-hero__image-wrap {
    order: -1;
  }

  .sp-hero__image {
    max-width: 260px;
  }

  .sp-hero__cta-row {
    justify-content: center;
  }

  .sp-deal-card {
    grid-template-columns: 48px 100px 1fr;
  }

  .sp-deal-card__image-wrap {
    width: 100px;
    height: 100px;
  }

  .sp-deal-card__price-block {
    grid-column: 1 / -1;
    grid-row: auto;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
  }

  .sp-deal-hero__image {
    border-radius: var(--radius-md);
  }

  .sp-footer__grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-8);
  }

  .sp-footer__brand {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  .sp-bottom-nav {
    display: block;
  }

  /* Add bottom padding for bottom nav */
  .sp-page {
    padding-bottom: 72px;
  }

  /* --- Filter bar: two-row mobile layout --- */
  .sp-filters {
    padding: var(--sp-2) var(--content-pad);
  }

  .sp-filters__inner {
    flex-wrap: wrap;
    gap: var(--sp-2) var(--sp-3);
  }

  /* Hide vertical dividers on mobile */
  .sp-filter-divider {
    display: none;
  }

  /* Sort pills stay inline, toggle pushed right */
  .sp-filter-pills {
    flex-shrink: 0;
  }

  .sp-filter-trigger {
    width: 32px;
    height: 32px;
  }

  .sp-filters__inner > .sp-toggle {
    margin-left: auto;
  }

  /* Smaller filter pill text on mobile */
  .sp-filter-pill {
    padding: var(--sp-1) var(--sp-3);
    font-size: var(--fs-micro);
  }

  /* --- Deal card: stacked mobile layout --- */
  .sp-deal-card {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
  }

  /* Score ring overlays image top-left */
  .sp-deal-card__score {
    position: absolute;
    top: calc(var(--sp-5) + var(--sp-2));
    left: calc(var(--sp-5) + var(--sp-2));
    z-index: 2;
  }

  /* Image first */
  .sp-deal-card__image-wrap {
    order: 1;
    width: 100%;
    height: 180px;
    min-height: 180px;
  }

  /* Content below image */
  .sp-deal-card__content {
    order: 2;
  }

  .sp-deal-card__excerpt {
    order: 3;
  }

  .sp-deal-card__price-block {
    order: 4;
    flex-direction: row;
    align-items: center;
    min-width: auto;
    text-align: left;
  }

  .sp-deal-card__status {
    z-index: 3;
  }

  /* Deal card actions: wrap GET DEAL to its own row */
  .sp-deal-card__actions {
    order: 6;
    flex-wrap: wrap;
    gap: var(--sp-2);
  }

  .sp-deal-card__actions-spacer {
    display: none;
  }

  .sp-deal-card__actions .sp-btn-cta {
    flex-basis: 100%;
    justify-content: center;
    order: 10;
  }

  .sp-deal-grid--grid {
    grid-template-columns: 1fr;
  }

  /* --- Hero mobile --- */
  .sp-hero {
    padding: var(--sp-8) var(--content-pad) var(--sp-10);
  }

  .sp-hero__price-block {
    justify-content: center;
  }

  /* Keep hero score ring within image bounds */
  .sp-hero__score-ring {
    top: var(--sp-2);
    right: var(--sp-2);
  }

  /* --- Footer mobile --- */
  .sp-footer__grid {
    grid-template-columns: 1fr;
    gap: var(--sp-6);
  }

  .sp-footer__bottom {
    flex-direction: column;
    text-align: center;
  }

  .sp-blog-grid {
    grid-template-columns: 1fr;
  }

  .sp-dropdown--mega.is-open {
    grid-template-columns: 1fr 1fr;
    min-width: auto;
  }

  /* --- Prevent any child overflow --- */
  .sp-container,
  .sp-filters,
  .sp-hero,
  .sp-footer {
    max-width: 100vw;
    overflow-x: hidden;
  }
}

@media (max-width: 480px) {
  .sp-deal-card__image-wrap {
    height: 160px;
    min-height: 160px;
  }

  .sp-hero__image {
    max-width: 200px;
  }

  .sp-newsletter__form {
    flex-direction: column;
  }

  .sp-alert-form__row {
    flex-direction: column;
  }

  .sp-dropdown--mega.is-open {
    grid-template-columns: 1fr;
  }

  /* Even smaller filter pills on tiny screens */
  .sp-filter-pill {
    padding: 3px var(--sp-2);
    font-size: 10px;
  }

  .sp-toggle {
    font-size: var(--fs-micro);
  }
}

/* === Hide Ghost Portal floating button (we use our own CTA) === */

.gh-portal-triggerbtn-container,
.gh-portal-triggerbtn-iframe {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* === Focus styles (keyboard only) === */

:focus-visible {
  outline: 2px solid var(--accent-ice);
  outline-offset: 2px;
  border-radius: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Prevent sticky header from obscuring focused/targeted elements (G-12) */
:target,
*:focus {
  scroll-margin-top: calc(var(--header-h) + 1rem);
}

.sp-article-body h2[id],
.sp-article-body h3[id] {
  scroll-margin-top: calc(var(--header-h) + 2rem);
}

/* === Utility: visually hidden but screen reader accessible === */

.sp-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* === Print styles === */

@media print {
  .sp-header,
  .sp-footer,
  .sp-filters,
  .sp-bottom-nav,
  .sp-noise,
  .sp-sidebar {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }
}
