/* Reusable pieces, mobile-first. Desktop overrides at 768px. Measurements from docs/DESIGN.md. */
@layer components {
  /* ---------- Header ---------- */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .site-header__inner {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 52px;
  }

  .logo img {
    height: 30px;
    width: auto;
  }

  .main-nav {
    display: none;
  }

  .search {
    display: none;
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
  }

  .icon-btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-pill);
    color: var(--ink);
    transition: background-color 0.15s;
  }

  .icon-btn:hover {
    background: var(--surface-2);
  }

  .icon-btn .icon {
    width: 22px;
    height: 22px;
  }

  .icon-btn .count {
    position: absolute;
    top: 3px;
    right: 1px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-pill);
    background: var(--red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
  }

  /* ---------- Buttons ---------- */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    border-radius: 10px;
    font-size: var(--fs-s);
    line-height: 1.3;
    white-space: nowrap;
    transition: background-color 0.15s, transform 0.15s;
  }

  .btn .icon {
    width: 16px;
    height: 16px;
  }

  .btn--primary {
    background: var(--red);
    color: #fff;
  }

  .btn--primary:hover {
    background: var(--red-hover);
  }

  .btn--primary:active {
    transform: translateY(1px);
  }

  /* ---------- Hero ---------- */
  .hero {
    background: var(--bg-hero);
    overflow: hidden;
  }

  .hero__inner {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    align-items: center;
    gap: 8px;
    height: 158px;
  }

  .hero__title {
    font-size: 1.6rem;
    line-height: 1.1;
  }

  .hero__accent {
    display: block;
    color: var(--red);
  }

  .hero__sub {
    margin-top: 8px;
    font-size: var(--fs-xs);
    color: var(--text);
  }

  .hero .btn {
    margin-top: 14px;
  }

  .hero__img {
    width: 100%;
    max-width: 186px;
    height: auto;
    justify-self: end;
    align-self: end;
    margin-right: -8px;
    margin-bottom: -26px; /* phones cropped by the band, as in the mockup */
  }

  /* ---------- Brand strip ---------- */
  .brands {
    background: var(--surface);
    border-block: 1px solid var(--border);
  }

  .brands__list {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 44px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .brands__list::-webkit-scrollbar {
    display: none;
  }

  .brands__list li {
    flex: none;
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-s);
    color: var(--text-2);
    font-size: var(--fs-s);
    white-space: nowrap;
  }

  .brand:hover {
    background: var(--surface-2);
    color: var(--ink);
  }

  .brand__logo {
    width: 20px;
    height: 20px;
    color: var(--ink);
  }

  .brand__name {
    display: none;
  }

  .brand--samsung .brand__logo {
    display: none;
  }

  .brand--samsung .brand__name {
    display: inline;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #1428a0;
  }

  .brand--google .brand__logo {
    color: #4285f4;
  }

  /* ---------- Features ---------- */
  .features {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 12px;
  }

  .features li {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    text-align: center;
    font-size: 0.65rem;
    line-height: 1.35;
    color: var(--text-2);
  }

  .features .icon {
    width: 24px;
    height: 24px;
    color: var(--ink);
  }

  /* ---------- Sections ---------- */
  .section {
    margin-top: 22px;
  }

  .section__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
  }

  .section__head h2 {
    font-size: 1.0625rem;
  }

  .more {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--red);
    font-size: var(--fs-s);
    white-space: nowrap;
  }

  .more .icon {
    width: 16px;
    height: 16px;
  }

  .grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  /* ---------- Product card ---------- */
  .card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 10px;
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow-card);
    transition: box-shadow 0.2s, transform 0.2s;
  }

  .card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-2px);
  }

  .card__media {
    position: relative;
    display: block;
    height: 128px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface);
  }

  .card__media img {
    width: 100%;
    height: 100%;
    padding: 4px;
    object-fit: contain;
  }

  .card__noimage {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--surface-2);
  }

  .badge {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 1;
    padding: 3px 8px;
    border-radius: 7px;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1.3;
  }

  .badge--new {
    background: var(--red);
    color: #fff;
  }

  .badge--dark {
    background: var(--badge-dark);
    color: #fff;
  }

  .badge--light {
    background: var(--badge-light);
    color: var(--ink);
  }

  .wish {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-pill);
    color: var(--text-2);
    background: var(--surface);
  }

  .wish .icon {
    width: 18px;
    height: 18px;
  }

  .wish:hover {
    color: var(--red);
  }

  .card__body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 8px;
  }

  .card__title {
    font-size: var(--fs-s);
    font-weight: 700;
    color: var(--ink);
  }

  .card__title a::after {
    /* whole card clickable without nesting interactive elements */
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: inherit;
  }

  .card__meta {
    font-size: var(--fs-xs);
    color: var(--muted);
  }

  .card__price {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
    margin-top: 5px;
  }

  .card__price strong {
    font-size: var(--fs-m);
    font-weight: 700;
    color: var(--red);
  }

  .card__price s {
    font-size: var(--fs-xs);
    color: var(--muted-2);
  }

  .card__installment {
    margin-top: 7px;
    padding: 5px 9px;
    border-radius: 8px;
    background: var(--surface-2);
    font-size: var(--fs-xs);
    color: var(--text-2);
  }

  /* Horizontal card (image left) */
  .card--row {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 8px;
    align-items: start;
  }

  .card--row .card__media {
    width: 64px;
    height: 64px;
  }

  .card--row .card__installment {
    width: max-content;
    max-width: 100%;
    white-space: nowrap;
  }

  .card--row .card__body {
    margin-top: 0;
  }

  .card--row .card__title {
    font-size: var(--fs-xs);
    padding-right: 24px;
  }

  .card--row .card__meta {
    font-size: 0.65rem;
  }

  .card--row .card__price strong {
    font-size: var(--fs-s);
  }

  .card--row .card__price s {
    font-size: 0.65rem;
  }

  .card--row .card__installment {
    font-size: 0.65rem;
    padding: 4px 7px;
  }

  .card--row .wish {
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
  }

  .card--row .badge {
    top: 4px;
    left: 4px;
    padding: 2px 6px;
    font-size: 0.6rem;
  }

  /* ---------- Footer ---------- */
  .site-footer {
    margin-top: 28px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-top: 24px;
  }

  .site-footer__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px 16px;
  }

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

  .site-footer__brand img {
    height: 36px;
    width: auto;
  }

  .site-footer__tagline {
    margin-top: 10px;
    font-size: var(--fs-s);
    color: var(--muted);
  }

  .site-footer__contact {
    display: grid;
    gap: 6px;
    margin-top: 12px;
    font-size: var(--fs-s);
    color: var(--text-2);
  }

  .site-footer__contact li {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .site-footer__contact .icon {
    width: 16px;
    height: 16px;
    color: var(--muted);
  }

  .site-footer__contact a:hover {
    color: var(--red);
  }

  .social {
    display: flex;
    gap: 12px;
    margin-top: 14px;
  }

  .social a {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    color: var(--ink);
  }

  .social .icon {
    width: 24px;
    height: 24px;
  }

  .site-footer__col h2 {
    font-size: var(--fs-s);
    margin-bottom: 8px;
  }

  .site-footer__col li {
    line-height: 1.9;
  }

  .site-footer__col a {
    font-size: var(--fs-s);
    color: var(--muted);
  }

  .site-footer__col a:hover {
    color: var(--ink);
  }

  .site-footer__chat {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--surface-2);
    font-size: var(--fs-s);
    color: var(--text-2);
  }

  .chat-btn .icon {
    width: 18px;
    height: 18px;
  }

  .site-footer__bottom {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 22px;
    padding: 14px 0 18px;
    border-top: 1px solid var(--border);
    font-size: var(--fs-xs);
    color: var(--muted-3);
  }

  .payments {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .payments__visa {
    width: 48px;
    height: 24px;
    color: #1a1f71;
  }

  .payments__mc {
    width: 34px;
    height: 22px;
    color: #eb001b;
  }

  .payments__word {
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  .payments__tbc {
    color: #00a3e0;
  }

  .payments__bog {
    color: #ff5b00;
  }

  .site-footer__delivery {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .flag {
    width: 20px;
    height: 14px;
    border: 1px solid var(--border);
    border-radius: 2px;
  }

  /* ---------- Mobile tab bar ---------- */
  .tabbar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  .tabbar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 0.65rem;
    color: var(--text-2);
  }

  .tabbar__item .icon {
    width: 22px;
    height: 22px;
  }

  .tabbar__item.is-active {
    color: var(--red);
  }

  body {
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  }

  /* ---------- Desktop ---------- */
  @media (min-width: 768px) {
    :root {
      --gutter: 24px;
    }

    body {
      padding-bottom: 0;
    }

    .site-header__inner {
      gap: 26px;
      height: 56px;
    }

    .logo img {
      height: 36px;
    }

    .main-nav {
      display: flex;
      align-items: center;
      gap: 22px;
      font-size: var(--fs-s);
      color: var(--text-2);
    }

    .main-nav a:hover {
      color: var(--ink);
    }

    .main-nav a.is-active {
      color: var(--red);
    }

    .search {
      display: flex;
      align-items: center;
      flex: 1;
      max-width: 300px;
      height: 38px;
      margin-left: auto;
      padding: 0 6px 0 16px;
      border-radius: var(--radius-pill);
      background: var(--surface-2);
    }

    .search input {
      flex: 1;
      min-width: 0;
      border: 0;
      background: none;
      font-size: var(--fs-s);
      outline: none;
    }

    .search input::placeholder {
      color: var(--muted-2);
    }

    .search button {
      display: grid;
      place-items: center;
      width: 30px;
      height: 30px;
      color: var(--text-2);
    }

    .search .icon {
      width: 18px;
      height: 18px;
    }

    .header-actions {
      margin-left: 0;
      gap: 6px;
    }

    .icon-btn--mobile {
      display: none;
    }

    .hero__inner {
      grid-template-columns: 1fr 1fr;
      gap: 24px;
      height: clamp(262px, 17vw, 320px);
    }

    .hero__title {
      font-size: var(--fs-hero);
    }

    .hero__sub {
      margin-top: 12px;
      font-size: var(--fs-m);
    }

    .hero .btn {
      margin-top: 22px;
      padding: 11px 22px;
      font-size: var(--fs-s);
    }

    .hero__img {
      max-width: min(100%, 560px);
      margin-right: 0;
      margin-bottom: clamp(-80px, -5vw, -60px);
    }

    .brands__list {
      justify-content: space-between;
      gap: 0;
      height: 48px;
      overflow: visible;
    }

    .brands__list li {
      flex: 1;
      display: flex;
      justify-content: center;
    }

    .brands__list li + li {
      border-left: 1px solid var(--border);
    }

    .brand__name {
      display: inline;
    }

    .features {
      gap: 0;
      margin-top: 14px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 14px;
    }

    .features li {
      flex-direction: row;
      gap: 12px;
      padding: 14px 18px;
      background: none;
      border: 0;
      border-radius: 0;
      text-align: left;
      font-size: var(--fs-xs);
    }

    .features li + li {
      border-left: 1px solid var(--border);
    }

    .features .icon {
      width: 26px;
      height: 26px;
    }

    .section {
      margin-top: 26px;
    }

    .section__head {
      margin-bottom: 12px;
    }

    .section__head h2 {
      font-size: 1.125rem;
    }

    .grid {
      grid-template-columns: repeat(4, 1fr);
      gap: 14px;
    }

    .card {
      padding: 12px;
    }

    .badge {
      top: 8px;
      left: 8px;
    }

    .card__body {
      margin-top: 10px;
    }

    .card__title {
      font-size: 0.875rem;
    }

    .card__price strong {
      font-size: 1.0625rem;
    }

    .card__media {
      height: auto;
      aspect-ratio: 1.5; /* scales with the column width */
    }

    .card--row {
      grid-template-columns: 80px 1fr;
      gap: 10px;
    }

    .card--row .card__media {
      width: 80px;
      height: 80px;
    }

    .card--row .card__title {
      font-size: var(--fs-s);
    }

    .card--row .card__meta {
      font-size: var(--fs-xs);
    }

    .card--row .card__price strong {
      font-size: var(--fs-m);
    }

    .card--row .card__price s,
    .card--row .card__installment {
      font-size: var(--fs-xs);
    }

    .site-footer {
      margin-top: 32px;
    }

    .site-footer__grid {
      grid-template-columns: 1.5fr 1fr 1fr 1.4fr 1fr;
      gap: 24px;
    }

    .site-footer__brand,
    .site-footer__chat {
      grid-column: auto;
    }

    .site-footer__bottom {
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
    }

    .tabbar {
      display: none;
    }
  }

  /* Wide screens: the 68% container fits five mockup-sized cards (D-036). */
  @media (min-width: 1200px) {
    .grid {
      grid-template-columns: repeat(5, 1fr);
    }
  }
}
