/*!
 * affilun — 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 `.afl-card` / `.afl-grid` boundary, and use CSS
 *     custom properties so a theme can override any token without
 *     touching this file.
 *
 *   - Modern affiliate-card layout: 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 `.afl-card`):
 *
 *   --afl-card-bg              card background
 *   --afl-card-border          card border (1 px solid)
 *   --afl-card-radius          card border-radius
 *   --afl-card-shadow          card box-shadow
 *   --afl-card-padding         card inner padding
 *   --afl-card-gap             space between image and body
 *   --afl-card-image-size      image column width (desktop)
 *   --afl-text-strong          title color
 *   --afl-text-muted           brand / footer color
 *   --afl-text-default         body / description color
 *   --afl-button-radius        button border-radius
 *   --afl-color-amazon         Amazon button background
 *   --afl-color-amazon-text    Amazon button text
 *   --afl-color-rakuten        Rakuten button background
 *   --afl-color-rakuten-text   Rakuten button text
 *   --afl-color-yahoo          Yahoo!ショッピング button background
 *   --afl-color-yahoo-text     Yahoo!ショッピング button text
 *
 * @package Affilun
 */

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

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

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

  --afl-button-radius: 6px;

  --afl-color-amazon: #f6a306;
  --afl-color-amazon-text: #111827;
  --afl-color-rakuten: #cf4944;
  --afl-color-rakuten-text: #111827;
  --afl-color-yahoo: #51a7e8;
  --afl-color-yahoo-text: #111827;
  --afl-color-mercari: #f2a1a1;
  --afl-color-mercari-text: #5f1111;
}

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

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

/* Design presets shared by cards and grids. */
:where(.afl-card, .afl-grid).afl-design-flat {
  --afl-card-border: 1px solid #e5e7eb;
  --afl-card-shadow: none;
}

:where(.afl-card, .afl-grid).afl-design-outlined {
  --afl-card-bg: transparent;
  --afl-card-border: 2px solid #d1d5db;
  --afl-card-shadow: none;
}

:where(.afl-card, .afl-grid).afl-design-soft {
  --afl-card-bg: #f8fafc;
  --afl-card-border: 1px solid #e2e8f0;
  --afl-card-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

:where(.afl-card, .afl-grid).afl-design-soft .afl-button {
  --afl-button-radius: 999px;
}

:where(.afl-card, .afl-grid).afl-button-shape-square {
  --afl-button-radius: 0;
}

:where(.afl-card, .afl-grid).afl-button-shape-pill {
  --afl-button-radius: 999px;
}

:where(.afl-card, .afl-grid).afl-buttons-stacked
  :where(.afl-card__buttons, .afl-grid-item__buttons),
:where(.afl-card, .afl-grid).afl-buttons-full
  :where(.afl-card__buttons, .afl-grid-item__buttons) {
  flex-direction: column;
  align-items: stretch;
}

:where(.afl-card, .afl-grid).afl-buttons-full .afl-button {
  width: 100%;
}

:where(.afl-card, .afl-grid).afl-button-tone-muted {
  --afl-color-amazon: #f3f4f6;
  --afl-color-amazon-text: #374151;
  --afl-color-rakuten: #f3f4f6;
  --afl-color-rakuten-text: #374151;
  --afl-color-yahoo: #f3f4f6;
  --afl-color-yahoo-text: #374151;
  --afl-color-mercari: #f3f4f6;
  --afl-color-mercari-text: #374151;
}

:where(.afl-card, .afl-grid).afl-button-tone-monochrome {
  --afl-color-amazon: #111827;
  --afl-color-amazon-text: #ffffff;
  --afl-color-rakuten: #111827;
  --afl-color-rakuten-text: #ffffff;
  --afl-color-yahoo: #111827;
  --afl-color-yahoo-text: #ffffff;
  --afl-color-mercari: #111827;
  --afl-color-mercari-text: #ffffff;
}

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

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

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

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

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

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

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

.afl-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(--afl-text-muted);
  background: #f3f4f6;
  border-radius: 999px;
}

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

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

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

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

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

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

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

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

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

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

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

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

.afl-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(--afl-button-radius);
  border: 0;
  cursor: pointer;
  transition:
    filter 120ms ease,
    transform 120ms ease;
}

:where(.afl-card, .afl-grid) .afl-button {
  padding: 8px 16px !important;
  min-width: 120px !important;
  min-height: 0 !important;
  font-size: 13px !important;
  line-height: 1.4 !important;
  border-radius: var(--afl-button-radius) !important;
  box-shadow: none !important;
}

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

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

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

/* Provider-specific button colors. */
.afl-button.afl-button-amazon {
  background: var(--afl-color-amazon);
  color: var(--afl-color-amazon-text);
}
.afl-button.afl-button-rakuten {
  background: var(--afl-color-rakuten);
  color: var(--afl-color-rakuten-text);
}
.afl-button.afl-button-yahoo_shopping {
  background: var(--afl-color-yahoo);
  color: var(--afl-color-yahoo-text);
}
.afl-button.afl-button-mercari {
  background: var(--afl-color-mercari);
  color: var(--afl-color-mercari-text);
}
.afl-button.afl-button-custom {
  background: var(--afl-text-strong);
  color: #ffffff;
}

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

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

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

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

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

.afl-badge-sale,
.afl-badge--sale {
  color: #7c2d12;
  background: #ffedd5;
  font-weight: 700;
}

.afl-grid-item__badges {
  margin-top: 4px;
}

/* Link-only / degraded fallback cards. */
.afl-card.afl-card--fallback {
  display: block;
  border-color: #fde68a;
  background: linear-gradient(180deg, #fffbeb 0%, #ffffff 100%);
}

.afl-card.afl-card--fallback .afl-card__title {
  margin-bottom: 8px;
}

.afl-card__fallback-copy {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--afl-text-default);
}

.afl-card.afl-card--fallback .afl-card__buttons {
  margin-top: 12px;
}

.afl-card.afl-card--fallback .afl-button-amazon {
  min-width: 180px;
  padding: 10px 20px;
  box-shadow: 0 2px 6px rgba(255, 153, 0, 0.24);
}

.afl-card__fallback-disclosure {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--afl-text-muted);
}

/* Admin-only fallback warning emitted by ProductCardBlockRenderer. */
.afl-card.afl-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 "カードと同様のシェイプ一つに収まる".
 * -------------------------------------------------------------- */

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

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

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

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

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

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

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

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

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

.afl-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(--afl-text-muted);
  background: #f3f4f6;
  border-radius: 999px;
}

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

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

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

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

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

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

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

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

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

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

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

.afl-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) {
  .afl-card {
    flex-direction: column;
  }
  .afl-card__image {
    flex: 0 0 auto;
    align-self: center;
  }
  .afl-card__image img {
    max-width: 200px;
  }
  .afl-grid-item__card {
    flex-direction: column;
  }
  .afl-grid-item__image {
    flex: 0 0 auto;
    align-self: center;
  }
  .afl-grid-item__image img {
    max-width: 200px;
  }
}
