/**
 * Đồng Thuận — Core components
 * Depends on: tokens.css, base.css
 * Existing class names preserved for migration (.btn, .chip, .product-card, …)
 */

/* ——— Button ——— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height-lg);
  padding: 0.7rem 1.35rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: var(--font-body);
  font-size: var(--text-body-sm-size);
  font-weight: 600;
  letter-spacing: 0.01em;
  text-align: center;
  cursor: pointer;
  transition:
    transform var(--duration-sheet) var(--ease-standard),
    background var(--duration-sheet) ease,
    border-color var(--duration-sheet) ease,
    color var(--duration-sheet) ease,
    box-shadow var(--duration-sheet) ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.btn:disabled,
.btn.is-disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
  pointer-events: none;
}

.btn--sm,
.btn-sm {
  min-height: var(--control-height-sm);
  padding: 0.4rem 0.9rem;
  font-size: var(--text-caption-size);
}

.btn--md,
.btn-md {
  min-height: var(--control-height-md);
  padding: 0.55rem 1.1rem;
}

.btn--lg,
.btn-lg {
  min-height: var(--control-height-lg);
  padding: 0.7rem 1.35rem;
}

.btn-primary,
.btn--primary {
  background: var(--color-brand);
  color: var(--color-brand-ink);
}

.btn-primary:hover:not(:disabled),
.btn--primary:hover:not(:disabled) {
  background: var(--color-brand-hover);
}

.btn-secondary,
.btn--secondary {
  background: var(--color-success);
  color: var(--color-on-inverse);
}

.btn-secondary:hover:not(:disabled),
.btn--secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-success) 88%, black);
}

.btn-outline,
.btn--outline,
.btn-ghost-ink {
  background: transparent;
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.btn-outline:hover:not(:disabled),
.btn--outline:hover:not(:disabled),
.btn-ghost-ink:hover:not(:disabled) {
  border-color: var(--color-text);
  background: color-mix(in srgb, var(--color-text) 4%, transparent);
}

.btn-ghost,
.btn--ghost {
  background: transparent;
  border-color: color-mix(in srgb, var(--color-on-inverse) 55%, transparent);
  color: var(--color-on-inverse);
}

.btn-ghost:hover:not(:disabled),
.btn--ghost:hover:not(:disabled) {
  border-color: var(--color-on-inverse);
  background: color-mix(in srgb, var(--color-on-inverse) 10%, transparent);
}

.btn-text,
.btn--text {
  min-height: auto;
  padding: 0.25rem 0;
  border: 0;
  background: transparent;
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.btn-text:hover:not(:disabled),
.btn--text:hover:not(:disabled) {
  transform: none;
  color: var(--color-text);
}

/* ——— Chip / filter ——— */
.chip-row {
  display: flex;
  gap: var(--space-control-gap);
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: var(--space-1);
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.chip {
  flex: 0 0 auto;
  min-height: var(--touch-min);
  padding: 0.55rem 1rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-body-sm-size);
  font-weight: 500;
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease,
    transform var(--duration-fast) var(--ease-standard);
}

.chip:active:not(:disabled) {
  transform: scale(0.97);
}

.chip:hover:not(:disabled),
.chip:focus-visible {
  border-color: var(--color-accent);
}

.chip:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.chip.is-active,
.chip[aria-pressed="true"] {
  background: var(--color-text);
  border-color: var(--color-text);
  color: var(--color-on-inverse);
}

.chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ——— Badge ——— */
.badge,
.product-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-xs);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.badge--neutral,
.product-badge {
  background: color-mix(in srgb, var(--color-text) 78%, transparent);
  color: var(--color-on-inverse);
}

.badge--accent,
.product-badge--accent {
  background: var(--color-accent);
  color: var(--color-on-inverse);
}

.badge--preorder,
.product-badge--preorder {
  background: color-mix(in srgb, var(--color-festive) 88%, var(--color-text));
  color: var(--color-on-inverse);
}

.badge--availability,
.product-badge--availability {
  background: var(--color-success);
  color: var(--color-on-inverse);
}

.product-badges {
  position: absolute;
  inset: 0.65rem auto auto 0.65rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-width: calc(100% - 1.3rem);
}

/* ——— Product card ——— */
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-grid-gap);
}

.product-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: box-shadow var(--duration-normal) var(--ease-standard);
}

.product-card:has(.product-card-hit:hover),
.product-card:has(.product-card-hit:focus-visible) {
  box-shadow: var(--shadow-hover);
}

.product-card-hit {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
  border-radius: inherit;
}

.product-card-hit:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.product-card-media {
  position: relative;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background: var(--color-media-fallback);
}

.product-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform var(--duration-slow) var(--ease-standard);
}

.product-grid--with-lead .product-card--featured {
  grid-column: 1 / -1;
}

@media (min-width: 720px) {
  .product-grid--with-lead .product-card--featured {
    grid-column: span 2;
  }

  .product-grid--with-lead .product-card--featured .product-card-hit {
    display: grid;
    grid-template-columns: 1fr 1.1fr;
    align-items: stretch;
  }

  .product-grid--with-lead .product-card--featured .product-card-media {
    aspect-ratio: auto;
    min-height: 16rem;
    height: 100%;
  }
}

@media (max-width: 719px) {
  .product-grid--with-lead .product-card--featured {
    grid-column: 1 / -1;
  }
}

.drawer-thumbs {
  display: flex;
  gap: var(--space-2);
  padding: 0 var(--space-4) var(--space-2);
  overflow-x: auto;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.drawer-thumb {
  flex: 0 0 auto;
  width: 4.75rem;
  height: var(--touch-min);
  min-width: var(--touch-min);
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--color-media-fallback);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--duration-fast) ease, transform var(--duration-fast) var(--ease-standard);
}

.drawer-thumb:active {
  transform: scale(0.97);
}

.drawer-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.drawer-thumb.is-selected,
.drawer-thumb[aria-pressed="true"] {
  border-color: var(--color-accent);
  box-shadow: inset 0 0 0 1px var(--color-surface-raised);
}

.drawer-thumb:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.product-card-hit:hover .product-card-media img,
.product-card-hit:active .product-card-media img {
  transform: scale(1.02);
}

.product-card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.35rem;
  padding: var(--space-card-padding);
}

.product-category {
  margin: 0;
  font-size: var(--text-caption-size);
  font-weight: var(--text-label-weight);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-accent);
}

.product-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-h3-size);
  font-weight: var(--text-h3-weight);
  line-height: var(--text-h3-lh);
  color: var(--color-text);
}

.product-meta {
  margin: 0;
  flex: 1;
  font-size: var(--text-body-sm-size);
  color: var(--color-text-muted);
}

.product-card-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: 0.55rem;
}

.product-price {
  font-weight: var(--text-price-weight);
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

.product-price-note {
  font-size: 0.72em;
  font-weight: 500;
  color: var(--color-text-muted);
}

.product-price--contact {
  color: var(--color-success);
}

.product-cta {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

/* ——— Editorial card (foundation only) ——— */
.editorial-card {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.editorial-card__media {
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--color-media-fallback);
}

.editorial-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.editorial-card__eyebrow {
  margin: 0 0 var(--space-2);
  font-size: var(--text-label-size);
  font-weight: var(--text-label-weight);
  letter-spacing: var(--text-label-tracking);
  text-transform: uppercase;
  color: var(--color-accent);
}

.editorial-card__title {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-h3-size);
  font-weight: var(--text-h3-weight);
  line-height: var(--text-h3-lh);
}

.editorial-card__body {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-body-sm-size);
  line-height: var(--text-body-sm-lh);
}

@media (min-width: 640px) {
  .editorial-card--split {
    grid-template-columns: 1fr 1.2fr;
    align-items: center;
  }
}

/* ——— Form foundation ——— */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field__label,
.form-label {
  font-size: var(--text-body-sm-size);
  font-weight: 600;
  color: var(--color-text);
}

.field__hint,
.form-hint {
  margin: 0;
  font-size: var(--text-caption-size);
  color: var(--color-text-muted);
}

.field__error,
.form-error {
  margin: 0;
  font-size: var(--text-caption-size);
  color: var(--color-danger);
}

.input,
.textarea,
.select,
.sort-select {
  min-height: var(--control-height-md);
  width: 100%;
  max-width: 100%;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 1rem; /* avoid iOS zoom */
  line-height: 1.4;
}

.textarea {
  min-height: 6.5rem;
  resize: vertical;
}

.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible,
.sort-select:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
  border-color: var(--color-accent);
}

.input.is-invalid,
.textarea.is-invalid,
.select.is-invalid {
  border-color: var(--color-danger);
}

.sort-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  font-size: var(--text-body-sm-size);
  color: var(--color-text-muted);
}

.sort-select {
  width: auto;
  min-width: 9rem;
  min-height: var(--touch-min);
}

/* ——— Empty state ——— */
.empty-state,
.collection-empty {
  padding: var(--space-10) var(--space-4);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  text-align: center;
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
}

.empty-state__title,
.collection-empty__title {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-h3-size);
  font-weight: var(--text-h3-weight);
  color: var(--color-text);
}

.empty-state__desc,
.collection-empty .empty-state__desc {
  margin: 0 0 var(--space-4);
  color: var(--color-text-muted);
}

/* ——— Navigation / header (TASK-932) ——— */
.site-header {
  --header-fg: var(--color-on-inverse);
  --header-fg-muted: color-mix(in srgb, var(--color-on-inverse) 78%, transparent);
  --header-pad-y: 0.15rem;
  position: fixed;
  inset: 0 0 auto;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: calc(var(--header-pad-y) + env(safe-area-inset-top, 0px))
    max(var(--space-container-inline), env(safe-area-inset-right, 0px))
    var(--header-pad-y)
    max(var(--space-container-inline), env(safe-area-inset-left, 0px));
  color: var(--header-fg);
  background: transparent;
  border-bottom: 1px solid transparent;
  box-shadow: none;
  pointer-events: none;
  transition:
    background-color var(--duration-sheet) var(--ease-standard),
    border-color var(--duration-sheet) var(--ease-standard),
    box-shadow var(--duration-sheet) var(--ease-standard),
    color var(--duration-sheet) var(--ease-standard);
}

.site-header a {
  pointer-events: auto;
  color: inherit;
  text-decoration: none;
}

.site-header.is-scrolled {
  --header-fg: var(--color-text);
  --header-fg-muted: var(--color-text-muted);
  background: color-mix(in srgb, var(--palette-paper-raised) 88%, var(--palette-cream));
  border-bottom-color: color-mix(in srgb, var(--palette-ink) 14%, transparent);
  box-shadow:
    0 1px 0 rgba(28, 20, 16, 0.05),
    0 10px 24px rgba(28, 20, 16, 0.06);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  font-family: var(--font-display);
  font-size: 1.28rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  /* Optical: serif caps feel heavy on the left — slight nudge */
  transform: translateY(0.02em);
}

.wordmark:hover {
  color: var(--header-fg);
  opacity: 0.92;
}

.wordmark:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: var(--radius-xs);
}

.nav {
  display: flex;
  align-items: center;
  gap: clamp(1.1rem, 2.2vw, 1.75rem);
  font-family: var(--font-body);
  font-size: var(--text-body-sm-size);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.nav a {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.2rem 0;
  color: var(--header-fg-muted);
  border-bottom: 1px solid transparent;
  transition:
    color 180ms var(--ease-standard),
    border-color 180ms var(--ease-standard),
    opacity 180ms var(--ease-standard);
}

.nav a:hover {
  color: var(--header-fg);
}

.nav a:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: var(--radius-xs);
  color: var(--header-fg);
}

.nav a.is-current,
.nav a[aria-current="true"] {
  color: var(--header-fg);
  border-bottom-color: currentColor;
}

.nav a.nav-cta {
  font-weight: 600;
  color: var(--header-fg);
  letter-spacing: 0.015em;
}

.nav a.nav-cta:hover,
.nav a.nav-cta:focus-visible {
  border-bottom-color: currentColor;
}

.nav a.nav-cta.is-current,
.nav a.nav-cta[aria-current="true"] {
  border-bottom-color: currentColor;
}

@media (prefers-reduced-motion: reduce) {
  .site-header,
  .nav a {
    transition: none;
  }
}

/* ——— Drawer (mobile sheet / desktop modal) ——— */
body.drawer-open {
  overflow: hidden;
  overscroll-behavior: none;
}

body.drawer-open.is-scroll-locked {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
}

.product-drawer {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) 0
    env(safe-area-inset-left, 0px);
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: var(--z-overlay);
  border: 0;
  background: var(--color-overlay);
  cursor: pointer;
  animation: drawer-backdrop-in var(--duration-sheet) var(--ease-exit) both;
}

.drawer-panel {
  position: absolute;
  inset: auto 0 0;
  z-index: calc(var(--z-drawer) + 1);
  max-height: min(92dvh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: contain;
  background: var(--color-bg);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-drawer);
  animation: drawer-up var(--duration-sheet) var(--ease-entrance);
}

.drawer-grabber {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 0.28rem;
  margin: 0.55rem auto 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-text) 22%, transparent);
}

.drawer-toolbar {
  display: flex;
  justify-content: flex-end;
  flex: 0 0 auto;
  padding: var(--space-2) var(--space-4) 0;
}

.drawer-close {
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    transform var(--duration-fast) var(--ease-standard);
}

.drawer-close:active {
  transform: scale(0.97);
  background: color-mix(in srgb, var(--color-text) 5%, transparent);
}

.drawer-close:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.drawer-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.drawer-media {
  aspect-ratio: 4 / 3;
  max-height: min(38vh, 280px);
  background: var(--color-media-fallback);
}

.drawer-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.drawer-body {
  padding: 1.15rem 1.25rem 1.25rem;
}

.drawer-meta {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--color-accent);
  font-weight: 600;
}

.drawer-title {
  margin: 0 0 0.65rem;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  line-height: 1.2;
}

.drawer-price {
  margin-bottom: 0.85rem;
  font-size: 1.15rem;
}

.drawer-specs {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

.drawer-specs li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.92rem;
}

.drawer-specs span {
  color: var(--color-text-muted);
}

.drawer-desc {
  margin: 0;
  color: var(--color-text-muted);
}

.drawer-foot {
  flex: 0 0 auto;
  padding: 0.75rem 1.25rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-bg) 92%, white);
  box-shadow: 0 -8px 20px rgba(28, 20, 16, 0.04);
}

.drawer-cta {
  width: 100%;
  min-height: var(--touch-min);
}

@keyframes drawer-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes drawer-backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes drawer-fade {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 0.5rem));
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

@media (min-width: 720px) {
  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-grid-gap-md);
  }

  .product-drawer {
    padding: 0;
  }

  .drawer-grabber {
    display: none;
  }

  .drawer-panel {
    inset: 50% auto auto 50%;
    width: min(34rem, calc(100vw - 2rem));
    max-height: min(88vh, 860px);
    transform: translate(-50%, -50%);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-floating);
    animation: drawer-fade var(--duration-sheet) var(--ease-entrance);
  }

  .drawer-foot {
    box-shadow: none;
    padding-bottom: 1rem;
  }
}

@media (min-width: 1100px) {
  .product-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 419px) {
  .product-grid {
    grid-template-columns: 1fr;
  }

  .sort-label {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }
}

@media (prefers-reduced-motion: reduce) {
  .drawer-panel,
  .drawer-backdrop {
    animation: none;
  }

  .product-card-hit:hover .product-card-media img,
  .product-card-hit:active .product-card-media img {
    transform: none;
  }

  .btn:hover:not(:disabled),
  .btn:active:not(:disabled),
  .chip:active:not(:disabled),
  .drawer-close:active,
  .drawer-thumb:active {
    transform: none;
  }
}
