/* ShopSmart buyer foundation. Layered on purpose: page styles still win.
   Anything that must beat a page rule belongs in responsive-fix.css. */
@layer ss.tokens, ss.reset, ss.base, ss.components, ss.utils;

@layer ss.tokens {
  :root {
    /* Brand */
    --ss-navy:        #0D2B55;
    --ss-navy-700:    #143A6B;
    --ss-navy-900:    #061226;
    --ss-cyan:        #1B9BDB;
    --ss-cyan-tint:   #E8F4FC;
    --ss-sale:        #B3261E;

    /* Action. Navy on white text, 14.1:1. The accent contract is untouched. */
    --ss-action:       var(--ss-navy, #0D2B55);
    --ss-action-hover: var(--ss-navy-700, #143A6B);
    --ss-on-action:    #FFFFFF;
    --ss-accent:       var(--accent, #1B9BDB);
    --ss-on-accent:    var(--on-accent, #061226);

    /* Surfaces */
    --ss-page:       #F5F7FA;
    --ss-surface:    #FFFFFF;
    --ss-surface-2:  #FAFBFD;
    --ss-line:       #E3E8EF;
    --ss-line-2:     #CBD4E1;

    /* Text. Nothing lighter than --ss-ink-3 is ever used on text. */
    --ss-ink:    #10203A;
    --ss-ink-2:  #46586F;
    --ss-ink-3:  #5B6B84;

    /* Type */
    --ss-font-ui:   "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --ss-font-text: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --ss-t-12: .75rem;   --ss-t-14: .875rem;  --ss-t-16: 1rem;
    --ss-t-17: 1.0625rem;--ss-t-18: 1.125rem; --ss-t-20: 1.25rem;
    --ss-t-24: 1.5rem;   --ss-t-30: 1.875rem;

    /* Space */
    --ss-1: 4px;  --ss-2: 8px;  --ss-3: 12px; --ss-4: 16px;
    --ss-5: 20px; --ss-6: 24px; --ss-8: 32px; --ss-12: 48px; --ss-16: 64px;

    /* Shape. A hierarchy, not one value. */
    --ss-r-input: 10px;
    --ss-r-card:  12px;
    --ss-r-media: 8px;
    --ss-r-sheet: 16px;
    --ss-r-pill:  999px;

    /* Depth. Only for things that float. */
    --ss-shadow-pop:   0 4px 12px rgba(16,32,58,.08);
    --ss-shadow-float: 0 12px 32px rgba(16,32,58,.14);

    /* Layout */
    --ss-container: 1280px;
    --ss-gutter: 16px;
    --ss-tap: 44px;
    --ss-header-h: 104px;   /* phone sticky budget, enforced */
    --ss-bottomnav-h: 56px;

    /* Motion */
    --ss-dur: 180ms;
    --ss-dur-fast: 120ms;
    --ss-ease: cubic-bezier(.2,.6,.2,1);

    /* Z */
    --ss-z-header: 100; --ss-z-bottomnav: 90; --ss-z-scrim: 200;
    --ss-z-sheet: 210;  --ss-z-drawer: 220;   --ss-z-toast: 300;
  }
  @media (min-width: 768px)  { :root { --ss-gutter: 24px; } }
  @media (min-width: 1280px) { :root { --ss-gutter: 32px; } }
}

/* Page metrics are opt-in with <body class="ss-page">. A layer loses to page
   rules, but it still fills in whatever a page never set: measured on
   2026-09-14, the body font-size/line-height below pushed product's first image
   149px down on a phone and the control font moved category 51px. Pages get the
   class as they adopt the shared components (Phase 2); until then only the rules
   that measured no change apply everywhere. :where() keeps these selectors at the
   specificity of a bare element, so a component class inside ss.components
   (.ss-btn--primary's white text) is never beaten by `.ss-page a`. */
@layer ss.reset {
  *, *::before, *::after { box-sizing: border-box; }
  body { margin: 0; }                       /* fixes the 8px body margin on suppliers-all */
  img, svg, video, canvas { display: block; max-width: 100%; }
  img { height: auto; }
  :where(.ss-page) :is(button, input, select, textarea) { font: inherit; color: inherit; }
  [hidden] { display: none !important; }    /* fixes ACC-04 and the empty pagination bar */
}

@layer ss.base {
  html { -webkit-text-size-adjust: 100%; }
  body:where(.ss-page) {
    background: var(--ss-page, #F5F7FA);
    color: var(--ss-ink, #10203A);
    font-family: var(--ss-font-text, system-ui);
    font-size: var(--ss-t-16, 1rem);
    line-height: 1.55;
  }
  :where(.ss-page) :is(h1, h2, h3, h4), .ss-h { font-family: var(--ss-font-ui, system-ui); line-height: 1.25; }
  :where(.ss-page) a { color: var(--ss-navy, #0D2B55); }
  :focus-visible {
    outline: 2px solid var(--ss-cyan, #1B9BDB);
    outline-offset: 2px;
    border-radius: 4px;
  }
  ::selection { background: var(--ss-cyan-tint, #E8F4FC); }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: .001ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: .001ms !important;
      scroll-behavior: auto !important;
    }
  }
}

@layer ss.components {

  /* ---- Container: one alignment for bar, header, nav, content, footer ---- */
  .ss-container {
    width: 100%;
    max-width: calc(var(--ss-container, 1280px) + (var(--ss-gutter, 16px) * 2));
    margin-inline: auto;
    padding-inline: var(--ss-gutter, 16px);
  }

  /* ---- Buttons ---- */
  .ss-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: var(--ss-2, 8px);
    min-height: var(--ss-tap, 44px);
    padding-inline: var(--ss-4, 16px);
    border: 1.5px solid transparent;
    border-radius: var(--ss-r-input, 10px);
    font-family: var(--ss-font-ui, system-ui);
    font-size: var(--ss-t-16, 1rem); font-weight: 600; line-height: 1;
    text-decoration: none; cursor: pointer;
    transition: background var(--ss-dur-fast, 120ms) var(--ss-ease, ease);
  }
  .ss-btn--primary   { background: var(--ss-action, #0D2B55); color: var(--ss-on-action, #fff); }
  .ss-btn--primary:hover { background: var(--ss-action-hover, #143A6B); }
  .ss-btn--secondary { background: var(--ss-surface, #fff); color: var(--ss-navy, #0D2B55);
                       border-color: var(--ss-navy, #0D2B55); }
  .ss-btn--accent    { background: var(--ss-accent, #1B9BDB); color: var(--ss-on-accent, #061226); }
  .ss-btn--quiet     { background: transparent; color: var(--ss-navy, #0D2B55); }
  .ss-btn--block     { width: 100%; }
  .ss-btn[disabled], .ss-btn[aria-disabled="true"] {
    background: var(--ss-line, #E3E8EF); color: var(--ss-ink-3, #5B6B84);
    border-color: transparent; cursor: not-allowed;
  }
  /* A disabled button must be accompanied by .ss-btn-reason explaining why. */
  .ss-btn-reason { font-size: var(--ss-t-12, .75rem); color: var(--ss-ink-3, #5B6B84);
                   margin-top: var(--ss-1, 4px); }

  /* ---- Fields ---- */
  .ss-field {
    width: 100%; min-height: var(--ss-tap, 44px);
    padding: 10px var(--ss-3, 12px);
    background: var(--ss-surface, #fff);
    border: 1px solid var(--ss-line-2, #CBD4E1);
    border-radius: var(--ss-r-input, 10px);
    font-size: var(--ss-t-16, 1rem);   /* enforced again in responsive-fix.css */
  }
  .ss-field::placeholder { color: var(--ss-ink-3, #5B6B84); }
  textarea.ss-field { resize: vertical; min-height: 96px; }

  /* ---- Chips ---- */
  .ss-chip {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: var(--ss-tap, 44px); padding-inline: var(--ss-3, 12px);
    background: var(--ss-surface, #fff);
    border: 1px solid var(--ss-line-2, #CBD4E1);
    border-radius: var(--ss-r-pill, 999px);
    font-size: var(--ss-t-14, .875rem); color: var(--ss-ink-2, #46586F);
    white-space: nowrap; cursor: pointer;
  }
  .ss-chip[aria-pressed="true"], .ss-chip.is-on {
    background: var(--ss-cyan-tint, #E8F4FC);
    border-color: var(--ss-cyan, #1B9BDB);
    color: var(--ss-navy, #0D2B55); font-weight: 600;
  }

  /* ---- Badges. One per card, maximum. ---- */
  .ss-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px var(--ss-2, 8px); border-radius: 6px;
    font-family: var(--ss-font-ui, system-ui);
    font-size: var(--ss-t-12, .75rem); font-weight: 700; line-height: 1.4;
  }
  .ss-badge--sale     { background: var(--ss-sale, #B3261E); color: #fff; }
  .ss-badge--verified { background: var(--ss-cyan-tint, #E8F4FC); color: var(--ss-navy, #0D2B55); }

  /* ---- Card ---- */
  .ss-card {
    background: var(--ss-surface, #fff);
    border: 1px solid var(--ss-line, #E3E8EF);
    border-radius: var(--ss-r-card, 12px);
  }
  /* On phones, section wrappers flatten so cards get the width (SYS-06). */
  @media (max-width: 767px) {
    .ss-flat-on-phone { border: 0; border-radius: 0; padding-inline: 0; background: transparent; }
  }

  /* ---- Product grid: auto-fill, never fixed columns (DSK-02) ---- */
  .ss-grid-products {
    display: grid; gap: var(--ss-3, 12px);
    grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  }
  @media (min-width: 600px) { .ss-grid-products { gap: var(--ss-4, 16px);
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }
  @media (min-width: 900px) { .ss-grid-products {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }
  /* Beside a filter sidebar, keep the same minimum so cards never fall to 158px at 1920. */
  .ss-with-sidebar .ss-grid-products {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }

  /* ---- Product card. Reserved row heights stop neighbours misaligning. ---- */
  .ss-pcard { display: flex; flex-direction: column; overflow: hidden;
              background: var(--ss-surface, #fff);
              border: 1px solid var(--ss-line, #E3E8EF);
              border-radius: var(--ss-r-card, 12px); }
  .ss-pcard-media { position: relative; aspect-ratio: 1 / 1; background: #fff;
                    display: grid; place-items: center; padding: var(--ss-2, 8px);
                    border-bottom: 1px solid var(--ss-line, #E3E8EF); }
  .ss-pcard-media img { width: 100%; height: 100%; object-fit: contain;
                        border-radius: var(--ss-r-media, 8px); }
  .ss-pcard-media img[data-fit="cover"] { object-fit: cover; }
  .ss-pcard-badge { position: absolute; left: var(--ss-2, 8px); bottom: var(--ss-2, 8px); }
  .ss-pcard-save  { position: absolute; right: 4px; top: 4px;
                    width: var(--ss-tap, 44px); height: var(--ss-tap, 44px);
                    display: grid; place-items: center; background: none; border: 0;
                    color: var(--ss-ink-3, #5B6B84); cursor: pointer; }
  .ss-pcard-save[aria-pressed="true"] { color: var(--ss-sale, #B3261E); }
  .ss-pcard-body  { display: grid; gap: var(--ss-1, 4px); padding: 10px 10px 12px; }
  .ss-pcard-name  { font-family: var(--ss-font-ui, system-ui);
                    font-size: var(--ss-t-14, .875rem); font-weight: 500; line-height: 1.35;
                    min-height: calc(2 * 1.35em);
                    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
                    overflow: hidden; }
  .ss-pcard-price { font-family: var(--ss-font-ui, system-ui);
                    font-size: var(--ss-t-17, 1.0625rem); font-weight: 700;
                    font-variant-numeric: tabular-nums; color: var(--ss-navy, #0D2B55); }
  .ss-pcard-was   { min-height: 1.4em;                 /* reserved even when empty */
                    font-size: var(--ss-t-12, .75rem); color: var(--ss-ink-3, #5B6B84);
                    text-decoration: line-through; font-variant-numeric: tabular-nums; }
  .ss-pcard-meta  { min-height: 1.4em;                 /* reserved even when empty */
                    font-size: var(--ss-t-12, .75rem); color: var(--ss-ink-3, #5B6B84);
                    display: flex; gap: var(--ss-2, 8px); }

  /* ---- Rail: a carousel that reads as scrollable, not as clipped ---- */
  .ss-rail {
    display: grid; grid-auto-flow: column;
    grid-auto-columns: minmax(var(--ss-rail-item, 158px), 1fr);
    gap: var(--ss-3, 12px);
    overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x proximity; scrollbar-width: none;
    /* full-bleed so the last card is deliberately half-visible at the screen edge */
    padding-inline: var(--ss-gutter, 16px);
    margin-inline: calc(var(--ss-gutter, 16px) * -1);
  }
  .ss-rail::-webkit-scrollbar { display: none; }
  .ss-rail > * { scroll-snap-align: start; }
  @media (min-width: 1024px) {
    .ss-rail { mask-image: linear-gradient(90deg, #000 calc(100% - 48px), transparent 100%); }
  }
  .ss-rail-nav { display: none; }
  @media (hover: hover) and (min-width: 1024px) { .ss-rail-nav { display: inline-flex; } }
  /* A rail with fewer items than fit is rendered as a plain grid instead. */

  /* ---- Tab row: same treatment, plus the active tab scrolled into view in JS ---- */
  .ss-tabs { display: flex; gap: var(--ss-1, 4px); overflow-x: auto; scrollbar-width: none;
             border-bottom: 1px solid var(--ss-line, #E3E8EF);
             padding-inline: var(--ss-gutter, 16px);
             margin-inline: calc(var(--ss-gutter, 16px) * -1); }
  .ss-tabs::-webkit-scrollbar { display: none; }
  .ss-tab  { flex: 0 0 auto; min-height: var(--ss-tap, 44px); padding-inline: var(--ss-3, 12px);
             display: inline-flex; align-items: center;
             font-family: var(--ss-font-ui, system-ui); font-size: var(--ss-t-14, .875rem);
             color: var(--ss-ink-2, #46586F); border-bottom: 2px solid transparent;
             background: none; border-top: 0; border-inline: 0; white-space: nowrap; }
  .ss-tab[aria-selected="true"] { color: var(--ss-navy, #0D2B55); font-weight: 700;
                                  border-bottom-color: var(--ss-cyan, #1B9BDB); }

  /* ---- Empty state: one pattern everywhere ---- */
  .ss-empty { display: grid; justify-items: center; gap: var(--ss-3, 12px);
              text-align: center; padding: var(--ss-12, 48px) var(--ss-4, 16px);
              background: var(--ss-surface, #fff);
              border: 1px solid var(--ss-line, #E3E8EF);
              border-radius: var(--ss-r-card, 12px); }
  .ss-empty svg { width: 40px; height: 40px; color: var(--ss-ink-3, #5B6B84); }
  .ss-empty p   { margin: 0; color: var(--ss-ink-2, #46586F); max-width: 36ch; }

  /* ---- Sheet and scrim ---- */
  .ss-scrim { position: fixed; inset: 0; z-index: var(--ss-z-scrim, 200);
              background: rgba(6,18,38,.48); opacity: 0;
              transition: opacity var(--ss-dur, 180ms) var(--ss-ease, ease); }
  .ss-scrim.is-open { opacity: 1; }
  .ss-sheet { position: fixed; inset: auto 0 0 0; z-index: var(--ss-z-sheet, 210);
              max-height: min(86dvh, 720px); display: flex; flex-direction: column;
              background: var(--ss-surface, #fff);
              border-radius: var(--ss-r-sheet, 16px) var(--ss-r-sheet, 16px) 0 0;
              box-shadow: var(--ss-shadow-float, 0 12px 32px rgba(16,32,58,.14));
              padding-bottom: env(safe-area-inset-bottom, 0px);
              transform: translateY(100%);
              transition: transform var(--ss-dur, 180ms) var(--ss-ease, ease); }
  .ss-sheet.is-open { transform: translateY(0); }
  .ss-sheet-body { overflow-y: auto; overscroll-behavior: contain;
                   padding: var(--ss-4, 16px); }
  .ss-sheet-foot { border-top: 1px solid var(--ss-line, #E3E8EF);
                   padding: var(--ss-3, 12px) var(--ss-4, 16px);
                   display: grid; grid-template-columns: 1fr 1fr; gap: var(--ss-2, 8px); }
  @media (min-width: 768px) {
    /* above 768 the same component centres as a dialog */
    .ss-sheet { inset: 50% auto auto 50%; translate: -50% -50%; transform: none;
                width: min(560px, calc(100vw - 48px));
                border-radius: var(--ss-r-sheet, 16px); }
  }

  /* ---- Bottom navigation, phones only ---- */
  .ss-bottomnav { position: fixed; inset: auto 0 0 0; z-index: var(--ss-z-bottomnav, 90);
                  display: grid; grid-template-columns: repeat(4, 1fr);
                  background: var(--ss-surface, #fff);
                  border-top: 1px solid var(--ss-line, #E3E8EF);
                  padding-bottom: env(safe-area-inset-bottom, 0px); }
  .ss-bottomnav a { display: grid; justify-items: center; align-content: center; gap: 2px;
                    min-height: var(--ss-bottomnav-h, 56px);
                    font-size: var(--ss-t-12, .75rem); color: var(--ss-ink-3, #5B6B84);
                    text-decoration: none; }
  .ss-bottomnav a[aria-current="page"] { color: var(--ss-navy, #0D2B55); font-weight: 600; }
  @media (min-width: 768px) { .ss-bottomnav { display: none; } }
  body.has-bottomnav { padding-bottom: calc(var(--ss-bottomnav-h, 56px) + env(safe-area-inset-bottom, 0px)); }
  @media (min-width: 768px) { body.has-bottomnav { padding-bottom: 0; } }

  /* ---- Skeletons: shown instead of empty flashes while data loads ---- */
  .ss-skel { background: linear-gradient(90deg, #EEF2F7 25%, #F7F9FC 37%, #EEF2F7 63%);
             background-size: 400% 100%; border-radius: var(--ss-r-media, 8px);
             animation: ss-shimmer 1.4s ease infinite; }
  @keyframes ss-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

  /* ---- Toast ---- */
  .ss-toast { position: fixed; z-index: var(--ss-z-toast, 300);
              left: 50%; translate: -50% 0;
              bottom: calc(var(--ss-bottomnav-h, 56px) + 12px + env(safe-area-inset-bottom, 0px));
              display: flex; align-items: center; gap: var(--ss-2, 8px);
              padding: var(--ss-3, 12px) var(--ss-4, 16px);
              background: var(--ss-navy, #0D2B55); color: #fff;
              border-radius: var(--ss-r-pill, 999px);
              box-shadow: var(--ss-shadow-float, 0 12px 32px rgba(16,32,58,.14));
              font-size: var(--ss-t-14, .875rem); }
  @media (min-width: 768px) { .ss-toast { bottom: 24px; } }
}

@layer ss.utils {
  /* Expand a small control's hit area without changing how it looks. */
  .ss-tap { position: relative; }
  .ss-tap::after { content: ""; position: absolute; inset: 50% auto auto 50%;
                   translate: -50% -50%;
                   width: max(100%, var(--ss-tap, 44px));
                   height: max(100%, var(--ss-tap, 44px)); }
  .ss-tabular { font-variant-numeric: tabular-nums; }
  .ss-measure { max-width: 68ch; }
  .ss-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
           overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .ss-nowrap { white-space: nowrap; }
}
