/*!
 * Commerce Link Builder — front-end card / grid styles.
 *
 * Design goals:
 *
 *   - "溶け込む" with arbitrary WordPress themes: avoid resetting
 *     theme typography or colors at the root; pin everything inside
 *     a single `.clb-card` / `.clb-grid` boundary, and use CSS
 *     custom properties so a theme can override any token without
 *     touching this file.
 *
 *   - Modern affiliate-card layout (Rinker-inspired): horizontal
 *     image + body on desktop (image left, ~140 px wide), stacks
 *     vertically below 480 px. Provider buttons sit at the bottom
 *     of the body and pick up the upstream brand color
 *     (Amazon / Rakuten / Yahoo!ショッピング).
 *
 *   - No external font, no SVG icon set, no JS dependency. The
 *     stylesheet is the only asset enqueued for the front-end.
 *
 * CSS custom properties (override at :root or on `.clb-card`):
 *
 *   --clb-card-bg              card background
 *   --clb-card-border          card border (1 px solid)
 *   --clb-card-radius          card border-radius
 *   --clb-card-shadow          card box-shadow
 *   --clb-card-padding         card inner padding
 *   --clb-card-gap             space between image and body
 *   --clb-card-image-size      image column width (desktop)
 *   --clb-text-strong          title color
 *   --clb-text-muted           brand / footer color
 *   --clb-text-default         body / description color
 *   --clb-button-radius        button border-radius
 *   --clb-color-amazon         Amazon button background
 *   --clb-color-amazon-text    Amazon button text
 *   --clb-color-rakuten        Rakuten button background
 *   --clb-color-rakuten-text   Rakuten button text
 *   --clb-color-yahoo          Yahoo!ショッピング button background
 *   --clb-color-yahoo-text     Yahoo!ショッピング button text
 *
 * @package CommerceLinkBuilder
 */

/* -----------------------------------------------------------------
 * Tokens.
 * Defined on :where(.clb-card, .clb-grid) so they cascade into
 * every plugin-rendered element without leaking globally.
 * -------------------------------------------------------------- */

:where(.clb-card, .clb-grid) {
  --clb-card-bg: #ffffff;
  --clb-card-border: 1px solid #e5e7eb;
  --clb-card-radius: 8px;
  --clb-card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04),
    0 1px 3px rgba(0, 0, 0, 0.06);
  --clb-card-padding: 16px;
  --clb-card-gap: 16px;
  --clb-card-image-size: 140px;

  --clb-text-strong: #111827;
  --clb-text-muted: #6b7280;
  --clb-text-default: #374151;

  --clb-button-radius: 6px;

  --clb-color-amazon: #ff9900;
  --clb-color-amazon-text: #ffffff;
  --clb-color-rakuten: #bf0000;
  --clb-color-rakuten-text: #ffffff;
  --clb-color-yahoo: #ff0033;
  --clb-color-yahoo-text: #ffffff;
}

/* -----------------------------------------------------------------
 * Card container.
 * -------------------------------------------------------------- */

.clb-card {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: var(--clb-card-gap);
  padding: var(--clb-card-padding);
  margin: 1.5em 0;
  background: var(--clb-card-bg);
  border: var(--clb-card-border);
  border-radius: var(--clb-card-radius);
  box-shadow: var(--clb-card-shadow);
  box-sizing: border-box;
}

/* Variant: compact card narrows the image. */
.clb-card.clb-card-single-compact-card {
  --clb-card-image-size: 100px;
  --clb-card-padding: 12px;
  --clb-card-gap: 12px;
}

/* Variant: minimal CTA stacks everything and emphasizes buttons. */
.clb-card.clb-card-single-minimal-cta {
  --clb-card-image-size: 80px;
  --clb-card-padding: 12px;
  --clb-card-gap: 12px;
}

/* Image column. */
.clb-card__image {
  flex: 0 0 var(--clb-card-image-size);
  margin: 0;
  align-self: flex-start;
}

.clb-card__image a {
  display: block;
  line-height: 0;
}

.clb-card__image img {
  display: block;
  width: 100%;
  height: auto;
  max-width: var(--clb-card-image-size);
  border-radius: calc(var(--clb-card-radius) - 2px);
  background: #f3f4f6;
  object-fit: contain;
}

/* Body column. */
.clb-card__body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.clb-card__header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.clb-card__provider {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.01em;
  color: var(--clb-text-muted);
  background: #f3f4f6;
  border-radius: 999px;
}

/* Provider-specific provider-badge tints (subtle). */
.clb-card__provider.clb-provider-amazon {
  color: #b35a00;
  background: #fff3e0;
}
.clb-card__provider.clb-provider-rakuten {
  color: #8a0000;
  background: #ffe7e7;
}
.clb-card__provider.clb-provider-yahoo_shopping {
  color: #a00021;
  background: #ffe5ea;
}

.clb-card__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--clb-text-strong);
  word-break: break-word;
}

.clb-card__title a {
  color: inherit;
  text-decoration: none;
}

.clb-card__title a:hover,
.clb-card__title a:focus-visible {
  text-decoration: underline;
}

.clb-card__brand {
  margin: 0;
  font-size: 12px;
  color: var(--clb-text-muted);
}

.clb-card__description {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--clb-text-default);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.clb-card__price {
  margin: 0;
  font-size: 14px;
  color: var(--clb-text-strong);
}

.clb-card__price-amount {
  font-weight: 700;
}

.clb-card__price-observed-at {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 400;
  color: var(--clb-text-muted);
}

.clb-card__availability {
  margin: 0;
  font-size: 12px;
  color: var(--clb-text-muted);
}

.clb-card__availability--out_of_stock,
.clb-card__availability--unavailable {
  color: #b91c1c;
}

/* Buttons row. */
.clb-card__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.clb-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  min-width: 120px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  text-decoration: none;
  text-align: center;
  border-radius: var(--clb-button-radius);
  border: 0;
  cursor: pointer;
  transition:
    filter 120ms ease,
    transform 120ms ease;
}

.clb-button:hover,
.clb-button:focus-visible {
  filter: brightness(0.92);
  text-decoration: none;
}

.clb-button:active {
  transform: translateY(1px);
}

.clb-button:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* Provider-specific button colors. */
.clb-button.clb-button-amazon {
  background: var(--clb-color-amazon);
  color: var(--clb-color-amazon-text);
}
.clb-button.clb-button-rakuten {
  background: var(--clb-color-rakuten);
  color: var(--clb-color-rakuten-text);
}
.clb-button.clb-button-yahoo_shopping {
  background: var(--clb-color-yahoo);
  color: var(--clb-color-yahoo-text);
}

/* Footer. */
.clb-card__disclaimers {
  margin-top: 10px;
  border-top: 1px solid #f3f4f6;
  padding-top: 8px;
}

.clb-card__disclaimers-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 11px;
  color: var(--clb-text-muted);
  line-height: 1.5;
}

.clb-card__disclaimer + .clb-card__disclaimer {
  margin-top: 2px;
}

.clb-card__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.clb-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--clb-text-muted);
  background: #f3f4f6;
  border-radius: 999px;
}

/* Admin-only fallback warning emitted by ProductCardBlockRenderer. */
.clb-card.clb-card--admin-warning {
  display: block;
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
  font-size: 13px;
  padding: 12px 14px;
}

/* -----------------------------------------------------------------
 * Grid container.
 *
 * Visual model: the grid is a SINGLE card-shaped box and each
 * item renders as a horizontal row (image on the left, body on
 * the right) stacked vertically inside the box. The legacy
 * column-grid layout is intentionally not used; the layout
 * matches the request to keep the grid "カードと同様のシェイプ一つに収まる".
 * -------------------------------------------------------------- */

.clb-grid {
  display: flex;
  flex-direction: column;
  gap: var(--clb-grid-gap, 0);
  margin: 1.5em 0;
  padding: var(--clb-card-padding);
  background: var(--clb-card-bg);
  border: var(--clb-card-border);
  border-radius: var(--clb-card-radius);
  box-shadow: var(--clb-card-shadow);
  list-style: none;
}

.clb-grid.clb-grid--gap-none {
  --clb-grid-gap: 0;
}
.clb-grid.clb-grid--gap-small {
  --clb-grid-gap: 8px;
}
.clb-grid.clb-grid--gap-medium {
  --clb-grid-gap: 16px;
}
.clb-grid.clb-grid--gap-large {
  --clb-grid-gap: 24px;
}

.clb-grid-item {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid #f0f1f3;
}

.clb-grid-item:first-child {
  border-top: 0;
}

.clb-grid-item__card {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: var(--clb-card-gap);
  padding: 12px 0;
}

.clb-grid-item__image {
  flex: 0 0 var(--clb-card-image-size, 96px);
  margin: 0;
}

.clb-grid-item__image a {
  display: block;
  line-height: 0;
}

.clb-grid-item__image img {
  display: block;
  width: 100%;
  height: auto;
  max-width: var(--clb-card-image-size, 96px);
  border-radius: calc(var(--clb-card-radius) - 2px);
  background: #f3f4f6;
  object-fit: contain;
}

.clb-grid-item__body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.clb-grid-item__provider {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--clb-text-muted);
  background: #f3f4f6;
  border-radius: 999px;
}

.clb-grid-item__provider.clb-provider-amazon {
  color: #b35a00;
  background: #fff3e0;
}
.clb-grid-item__provider.clb-provider-rakuten {
  color: #8a0000;
  background: #ffe7e7;
}
.clb-grid-item__provider.clb-provider-yahoo_shopping {
  color: #a00021;
  background: #ffe5ea;
}

.clb-grid-item__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--clb-text-strong);
  word-break: break-word;
}

.clb-grid-item__title a {
  color: inherit;
  text-decoration: none;
}

.clb-grid-item__title a:hover,
.clb-grid-item__title a:focus-visible {
  text-decoration: underline;
}

.clb-grid-item__brand {
  margin: 0;
  font-size: 12px;
  color: var(--clb-text-muted);
}

.clb-grid-item__price {
  margin: 0;
  font-size: 14px;
  color: var(--clb-text-strong);
}

.clb-grid-item__price-amount {
  font-weight: 700;
}

.clb-grid-item__price-observed-at {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 400;
  color: var(--clb-text-muted);
}

.clb-grid-item__disclaimers {
  margin-top: 8px;
  border-top: 1px solid #f3f4f6;
  padding-top: 6px;
}

.clb-grid-item__disclaimers-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 11px;
  color: var(--clb-text-muted);
  line-height: 1.5;
}

.clb-grid-item__disclaimer + .clb-grid-item__disclaimer {
  margin-top: 2px;
}

.clb-grid-item__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

/* -----------------------------------------------------------------
 * Responsive: stack image above body below 480 px.
 * -------------------------------------------------------------- */

@media (max-width: 480px) {
  .clb-card {
    flex-direction: column;
  }
  .clb-card__image {
    flex: 0 0 auto;
    align-self: center;
  }
  .clb-card__image img {
    max-width: 200px;
  }
  .clb-grid-item__card {
    flex-direction: column;
  }
  .clb-grid-item__image {
    flex: 0 0 auto;
    align-self: center;
  }
  .clb-grid-item__image img {
    max-width: 200px;
  }
}
