/* ========================================
   TRADING 2D – UI Components
   Buttons, Cards, Forms, Icons
   ======================================== */

/* ---- ANIMATION KEYFRAMES ---- */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn var(--duration-base) var(--easing-ease-out);
}

.fade-in-up {
  animation: fadeInUp var(--duration-base) var(--easing-ease-out);
}

/* ---- BUTTONS ----
   Engraving / premium monochrome – flat graphite, no gradients. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  padding: var(--sp-md) var(--sp-lg);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  border: var(--border-thin) solid transparent;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  text-decoration: none;
  white-space: nowrap;
  text-align: center;
  user-select: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Primary – graphite fill */
.btn-primary {
  background-color: var(--btn-primary);
  color: var(--text-on-dark);
  border-color: transparent;
  transition: background-color 0.2s ease;
}

.btn-primary:hover:not(:disabled),
.btn-primary:focus-visible:not(:disabled) {
  background-color: var(--btn-primary-hover);
  color: var(--text-on-dark);
}

.btn-primary:active:not(:disabled) {
  background-color: var(--btn-primary);
}

/* Secondary – outline */
.btn-secondary {
  background-color: transparent;
  color: var(--btn-primary);
  border: 1px solid var(--btn-primary);
  transition: background-color 0.2s ease;
}

.btn-secondary:hover:not(:disabled),
.btn-secondary:focus-visible:not(:disabled) {
  background-color: var(--border-color);
  color: var(--btn-primary);
}

.btn-secondary:active:not(:disabled) {
  background-color: transparent;
}

/* Ghost – neutral outline for tertiary actions (wishlist, etc.) */
.btn-ghost {
  background-color: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn-ghost:hover:not(:disabled) {
  background-color: var(--border-color);
  border-color: var(--border-color);
  color: var(--text-main);
}

/* Dark – alias of primary for legacy markup */
.btn-dark {
  background-color: var(--btn-primary);
  color: var(--text-on-dark);
  border-color: transparent;
  transition: background-color 0.2s ease;
}

.btn-dark:hover:not(:disabled),
.btn-dark:focus-visible:not(:disabled) {
  background-color: var(--btn-primary-hover);
  color: var(--text-on-dark);
}

/* Disabled – all variants */
.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled,
.btn-dark:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Button Sizes */
.btn-sm {
  padding: var(--sp-sm) var(--sp-md);
  font-size: var(--fs-sm);
}

.btn-lg {
  padding: var(--sp-lg) var(--sp-2xl);
  font-size: var(--fs-lg);
}

/* ---- CONTAINER-AWARE BUTTON SCALING ----
   `vw`-based scaling only reacts to the viewport, not the actual box the
   button sits in – on a wide desktop viewport with a narrow grid column
   (e.g. the component showcase) it never kicks in and the label still
   overflows. Container queries fix this correctly: any ancestor that opts
   in with `container-type: inline-size` (see .demo-item, .card-product)
   makes buttons inside it shrink based on their REAL available width. */
@container (max-width: 360px) {
  .btn-lg {
    padding: var(--sp-md) var(--sp-xl);
    font-size: var(--fs-base);
  }
}

@container (max-width: 280px) {
  .btn-lg {
    padding: var(--sp-md) var(--sp-lg);
    font-size: var(--fs-sm);
    letter-spacing: var(--ls-normal);
  }
}

.btn-block {
  display: flex;
  width: 100%;
}

/* Icon Button – fixed square, centred glyph */
.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn-icon:hover:not(:disabled) {
  background-color: var(--border-color);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.btn-icon-lg {
  width: 48px;
  height: 48px;
}

/* ---- PRODUCT CARDS ---- */

.card {
  background-color: var(--bg-card);
  border: var(--border-thin) solid var(--border-color);
  border-radius: 4px;
  padding: var(--sp-md);
  box-shadow: var(--shadow-subtle);
  overflow: hidden;
  transition: border-color var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out),
    transform var(--duration-base) var(--ease-out);
}

/* RULE-12 hover-контракт: translateY + border + shadow.
   Зображення свідомо НЕ анімується на hover — anti-slop-скіл прямо
   забороняє transform на <img> при hover (design_anti_slop_skill.md). */
@media (hover: hover) and (pointer: fine) {
  .card:hover {
    transform: translateY(-4px);
    border-color: var(--color-border-dark);
    box-shadow: var(--shadow-md);
  }
}

.card-header {
  margin-bottom: var(--sp-md);
}

.card-body {
  margin-bottom: var(--sp-md);
}

.card-footer {
  display: flex;
  gap: var(--sp-md);
  align-items: center;
  justify-content: space-between;
}

/* Product Card Variant */
.card-product {
  display: flex;
  flex-direction: column;
  height: 100%;
  container-type: inline-size; /* lets .btn-lg/.btn inside react to the card's real width */
}

.card-product-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  margin-bottom: var(--sp-md);
  border-radius: var(--border-radius-sm);
}

.card-product-name {
  font-family: var(--font-serif);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--sp-sm);
  line-height: var(--lh-tight);
}

.card-product-name a {
  color: inherit;
  text-decoration: none;
}

.card-product-name a:hover {
  color: var(--color-accent);
}

.card-product-image-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.card-product-price {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--color-price); /* Indigo accent, bold weight for contrast on white */
  margin-bottom: var(--sp-md);
}

.card-product-price-old {
  font-size: var(--fs-base);
  color: var(--color-text-light);
  text-decoration: line-through;
  margin-right: var(--sp-sm);
}

.card-product-info {
  font-size: var(--fs-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--sp-md);
}

.card-product-actions {
  display: flex;
  gap: var(--sp-sm);
  margin-top: auto;
}

.card-add-to-cart-form {
  display: flex;
}

/* CTA takes remaining width, wishlist icon stays a fixed 48px square –
   both share the same height so the row reads as one aligned unit. */
.card-product-actions .btn {
  min-height: 48px;
  min-width: 0;
}

.card-product-actions .btn:not(.btn-ghost) {
  white-space: normal;
  line-height: 1.25;
  padding-block: var(--sp-sm);
  font-size: var(--fs-sm);
  letter-spacing: var(--ls-normal);
}

@container (max-width: 280px) {
  .card-product-actions .btn:not(.btn-ghost) {
    font-size: var(--fs-xs);
    padding-inline: var(--sp-sm);
  }
}

.card-product-actions .flex-1 {
  flex: 1 1 auto;
  min-width: 0; /* allow the ellipsis guard on .btn to work if space is tight */
}

.card-product-actions .btn-ghost {
  width: 48px;
  min-height: 48px;
  padding: 0;
  flex-shrink: 0;
}

/* ---- WISHLIST TOGGLE (сердечко) ---- */

.btn-wishlist-toggle svg {
  width: 20px;
  height: 20px;
  transition: fill 0.2s ease, stroke 0.2s ease, transform 0.2s ease;
}

.btn-wishlist-toggle.is-active {
  color: var(--btn-primary);
  border-color: var(--btn-primary);
}

.btn-wishlist-toggle.is-active svg {
  fill: var(--btn-primary);
  stroke: var(--btn-primary);
}

.btn-wishlist-toggle:active svg {
  transform: scale(0.9);
}

/* ---- BADGES & LABELS ---- */

.badge {
  display: inline-block;
  padding: var(--sp-xs) var(--sp-sm);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  border-radius: var(--border-radius-sm);
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
}

.badge-accent {
  background-color: var(--color-accent);
  color: var(--color-white);
}

.badge-success {
  background-color: var(--color-success);
  color: var(--color-white);
}

.badge-error {
  background-color: var(--color-error);
  color: var(--color-white);
}

.badge-warning {
  background-color: var(--color-warning);
  color: var(--color-white);
}

/* Glassmorphism badge – sits on top of product photos (discount/new labels).
   Uses color-mix() instead of a hardcoded rgba() so it stays tied to the
   --color-white token (No Hardcoded Values). */
.badge-glass {
  display: inline-flex;
  align-items: center;
  background: color-mix(in srgb, var(--color-white) 85%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px); /* iOS Safari */
  color: var(--color-text-primary);
  font-weight: var(--fw-bold);
  font-size: var(--fs-xs);
  text-transform: none;
  letter-spacing: var(--ls-normal);
  border-radius: 999px;
  padding: var(--sp-xs) var(--sp-md);
  box-shadow: var(--shadow-sm);
}

.badge-light {
  background-color: var(--color-border);
  color: var(--color-text-primary);
}

/* ---- FORMS ---- */

.form-group {
  margin-bottom: var(--sp-lg);
}

.form-label {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  margin-bottom: var(--sp-sm);
  color: var(--color-text-primary);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--sp-md);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--border-radius-md);
  background-color: var(--color-white);
  color: var(--color-text-primary);
  transition: border-color var(--duration-base) var(--easing-ease),
    box-shadow var(--duration-base) var(--easing-ease);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-text-light);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 10%, transparent);
  outline: none;
}

.form-input:disabled,
.form-textarea:disabled,
.form-select:disabled {
  background-color: var(--color-border);
  color: var(--color-text-light);
  cursor: not-allowed;
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
}

.form-checkbox,
.form-radio {
  width: 20px;
  height: 20px;
  margin-right: var(--sp-sm);
  cursor: pointer;
  accent-color: var(--color-accent);
}

.form-checkbox-group,
.form-radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}

.form-checkbox-item,
.form-radio-item {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.form-error {
  color: var(--color-error);
  font-size: var(--fs-xs);
  margin-top: var(--sp-xs);
}

.form-success {
  color: var(--color-success);
  font-size: var(--fs-xs);
  margin-top: var(--sp-xs);
}

/* ---- ICONS (Line/Outline style) ---- */

.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.icon-lg {
  width: 32px;
  height: 32px;
}

.icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 1.5;
  stroke: currentColor;
  fill: none;
}

.icon-filled svg {
  fill: currentColor;
  stroke: none;
}

/* ---- TABLES ---- */

.table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--sp-lg);
}

.table th {
  background-color: var(--color-bg-alt);
  font-family: var(--font-sans);
  font-weight: var(--fw-semibold);
  text-align: left;
  padding: var(--sp-md);
  border-bottom: var(--border-thin) solid var(--color-border-dark);
}

.table td {
  padding: var(--sp-md);
  border-bottom: var(--border-thin) solid var(--color-border);
}

.table tbody tr:hover {
  background-color: var(--color-bg-alt);
}

.table-striped tbody tr:nth-child(odd) {
  background-color: var(--color-bg-alt);
}

/* ---- ALERT BOXES ---- */

.alert {
  padding: var(--sp-lg);
  border-radius: var(--border-radius-md);
  border-left: var(--border-medium) solid;
  margin-bottom: var(--sp-lg);
}

/* Backgrounds are derived from the same token via color-mix() instead of a
   separately hardcoded rgba() – one source of truth per color (CSS_Tokens_Handbook). */

.alert-success {
  background-color: color-mix(in srgb, var(--color-success) 8%, transparent);
  color: var(--color-success);
  border-color: var(--color-success);
}

.alert-error {
  background-color: color-mix(in srgb, var(--color-error) 8%, transparent);
  color: var(--color-error);
  border-color: var(--color-error);
}

.alert-warning {
  background-color: color-mix(in srgb, var(--color-warning) 8%, transparent);
  color: var(--color-warning);
  border-color: var(--color-warning);
}

.alert-info {
  background-color: color-mix(in srgb, var(--color-info) 8%, transparent);
  color: var(--color-info);
  border-color: var(--color-info);
}

.alert-close {
  position: absolute;
  top: var(--sp-md);
  right: var(--sp-md);
  background: none;
  border: none;
  font-size: var(--fs-lg);
  color: inherit;
  cursor: pointer;
}

/* ---- PAGINATION ---- */

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  justify-content: center;
  margin-bottom: var(--sp-lg);
}

.pagination-ellipsis {
  border: none;
  cursor: default;
}

.pagination-item {
  min-width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--border-radius-md);
  color: var(--color-text-primary);
  transition: border-color var(--duration-base) var(--easing-ease),
    color var(--duration-base) var(--easing-ease),
    box-shadow var(--duration-base) var(--easing-ease);
  cursor: pointer;
  text-decoration: none;
  padding: 0 var(--sp-sm);
  background: none;
  font: inherit;
}

a.pagination-item:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  box-shadow: var(--shadow-sm);
}

.pagination-item.active {
  background-color: var(--btn-primary);
  color: var(--text-on-dark);
  border-color: var(--btn-primary);
}

.pagination-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
