/* ==========================================================================
   Component recipes. Requires tokens.css. Implements §6 of DESIGN-SYSTEM.md.
   Naming: .ds-<component>[--<variant>] and .ds-<component>__<part>.
   Every class here is documented in §6; ds self-tests fail otherwise.
   Colours, type, radii, shadows and motion come only from var(--ds-*) tokens.
   ========================================================================== */

/* ---- 1. Typography ---- */
.ds-display {
  font-family: var(--ds-font-display); font-weight: var(--ds-fw-semibold);
  font-size: var(--ds-text-3xl); line-height: var(--ds-text-3xl-lh);
  letter-spacing: var(--ds-tracking-display); color: var(--ds-ink);
}
.ds-title {
  font-family: var(--ds-font-display); font-weight: var(--ds-fw-semibold);
  font-size: var(--ds-text-xl); line-height: var(--ds-text-xl-lh);
  letter-spacing: var(--ds-tracking-display); color: var(--ds-ink);
}
.ds-heading {
  font-weight: var(--ds-fw-semibold); font-size: var(--ds-text-md);
  line-height: var(--ds-text-md-lh); letter-spacing: var(--ds-tracking-tight); color: var(--ds-ink);
}
.ds-body {
  font-weight: var(--ds-fw-regular); font-size: var(--ds-text-base);
  line-height: var(--ds-text-base-lh); letter-spacing: var(--ds-tracking-tight); color: var(--ds-ink-2);
}
.ds-label {
  font-weight: var(--ds-fw-medium); font-size: var(--ds-text-sm);
  line-height: var(--ds-text-sm-lh); color: var(--ds-ink);
}
.ds-caption {
  font-weight: var(--ds-fw-regular); font-size: var(--ds-text-xs);
  line-height: var(--ds-text-xs-lh); color: var(--ds-ink-3);
}
.ds-mono { font-family: var(--ds-font-mono); font-size: var(--ds-text-sm); }

/* ---- 2. Button ---- */
.ds-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--ds-space-2);
  height: var(--ds-control); padding: 0 var(--ds-space-3);
  border: 0; border-radius: var(--ds-radius-control);
  font: inherit; font-size: var(--ds-text-base); font-weight: var(--ds-fw-medium);
  line-height: 1; white-space: nowrap; cursor: pointer;
  background: var(--ds-surface); color: var(--ds-ink); box-shadow: var(--ds-ring), var(--ds-shadow-sm);
  transition: background-color var(--ds-duration-fast) var(--ds-ease-out),
    box-shadow var(--ds-duration-fast) var(--ds-ease-out);
}
.ds-btn:hover { background-image: linear-gradient(var(--ds-hover), var(--ds-hover)); }
.ds-btn:active { background-image: linear-gradient(var(--ds-active), var(--ds-active)); }
.ds-btn:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }
.ds-btn:disabled, .ds-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; background-image: none; }
.ds-btn--primary { background: var(--ds-accent); color: var(--ds-on-accent); box-shadow: var(--ds-shadow-sm); }
.ds-btn--primary:hover { background: var(--ds-accent-hover); background-image: none; }
.ds-btn--ghost { background: transparent; box-shadow: none; color: var(--ds-ink-2); }
.ds-btn--ghost:hover { color: var(--ds-ink); }
.ds-btn--danger { background: var(--ds-danger); color: var(--ds-on-accent); box-shadow: var(--ds-shadow-sm); }
.ds-btn--sm { height: var(--ds-control-sm); padding: 0 var(--ds-space-2); font-size: var(--ds-text-sm); }
.ds-btn--lg { height: var(--ds-control-lg); padding: 0 var(--ds-space-4); }
.ds-btn--icon { width: var(--ds-control); padding: 0; }

/* ---- 3. Form fields ---- */
.ds-field { display: flex; flex-direction: column; gap: var(--ds-space-1); }
.ds-input {
  height: var(--ds-control); width: 100%; padding: 0 var(--ds-space-3);
  border: 0; border-radius: var(--ds-radius-control);
  background: var(--ds-surface); color: var(--ds-ink); box-shadow: var(--ds-ring);
  font: inherit; font-size: var(--ds-text-base); font-weight: var(--ds-fw-medium);
  transition: box-shadow var(--ds-duration-fast) var(--ds-ease-out);
}
.ds-input::placeholder { color: var(--ds-ink-3); font-weight: var(--ds-fw-regular); }
.ds-input:hover { box-shadow: var(--ds-ring-strong); }
.ds-input:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }
.ds-input[aria-invalid="true"] { box-shadow: 0 0 0 1px var(--ds-danger); }
.ds-input--area { height: auto; min-height: calc(var(--ds-control) * 3); padding: var(--ds-space-2) var(--ds-space-3); resize: vertical; }
.ds-field__hint { font-size: var(--ds-text-xs); line-height: var(--ds-text-xs-lh); color: var(--ds-ink-3); }
.ds-field__error { font-size: var(--ds-text-xs); line-height: var(--ds-text-xs-lh); color: var(--ds-danger); }

/* ---- 4. Card ---- */
.ds-card {
  background: var(--ds-surface); border-radius: var(--ds-radius-card);
  box-shadow: var(--ds-ring), var(--ds-shadow-sm); padding: var(--ds-space-4);
}
.ds-card__header { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-3); margin-bottom: var(--ds-space-3); }

/* ---- 5. Badge ---- */
.ds-badge {
  display: inline-flex; align-items: center; gap: var(--ds-space-1);
  height: 20px; padding: 0 var(--ds-space-2); border-radius: var(--ds-radius-full);
  font-size: var(--ds-text-xs); font-weight: var(--ds-fw-medium); line-height: 1;
  background: var(--ds-surface-2); color: var(--ds-ink-2);
}
.ds-badge--success { background: var(--ds-success-soft); color: var(--ds-success); }
.ds-badge--warning { background: var(--ds-warning-soft); color: var(--ds-warning); }
.ds-badge--danger { background: var(--ds-danger-soft); color: var(--ds-danger); }
.ds-badge--info { background: var(--ds-info-soft); color: var(--ds-info); }

/* ---- 6. Table: the one place the border property is legal (§1.3) ---- */
.ds-table { width: 100%; border-collapse: collapse; font-size: var(--ds-text-base); color: var(--ds-ink); }
.ds-table th {
  height: var(--ds-control); padding: 0 var(--ds-space-3); text-align: left;
  font-size: var(--ds-text-xs); font-weight: var(--ds-fw-medium); color: var(--ds-ink-3);
  border-bottom: 1px solid var(--ds-line);
}
.ds-table td {
  height: var(--ds-control-lg); padding: 0 var(--ds-space-3); font-weight: var(--ds-fw-medium);
  border-bottom: 1px solid var(--ds-line);
}
.ds-table tbody tr:hover { background: var(--ds-hover); }

/* ---- 7. Skeleton loading ---- */
.ds-skeleton {
  position: relative; overflow: hidden; display: block;
  background: var(--ds-skeleton); border-radius: var(--ds-radius-sm);
}
.ds-skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--ds-skeleton-shine), transparent);
  animation: ds-shimmer 1.4s var(--ds-ease-out) infinite;
}
.ds-skeleton--text { height: var(--ds-text-base-lh); border-radius: var(--ds-radius-sm); }
.ds-skeleton--circle { border-radius: var(--ds-radius-full); }
.ds-skeleton--block { border-radius: var(--ds-radius-card); }
@keyframes ds-shimmer { to { transform: translateX(100%); } }

/* ---- 8. Popups: overlay, dialog, menu, toast ---- */
.ds-overlay {
  position: fixed; inset: 0; z-index: var(--ds-z-overlay); background: var(--ds-overlay);
  display: grid; place-items: center; padding: var(--ds-space-4);
  animation: ds-fade-in var(--ds-duration) var(--ds-ease-out);
}
.ds-dialog {
  z-index: var(--ds-z-dialog); width: min(100%, 440px); max-height: calc(100vh - var(--ds-space-16));
  overflow: auto; background: var(--ds-surface); color: var(--ds-ink);
  border-radius: var(--ds-radius-panel); box-shadow: var(--ds-ring), var(--ds-shadow-lg);
  animation: ds-pop-in var(--ds-duration) var(--ds-ease-out);
}
.ds-dialog--wide { width: min(100%, 640px); }
.ds-dialog__header { padding: var(--ds-space-5) var(--ds-space-5) var(--ds-space-2); }
.ds-dialog__title { font-size: var(--ds-text-md); line-height: var(--ds-text-md-lh); font-weight: var(--ds-fw-semibold); }
.ds-dialog__body { padding: 0 var(--ds-space-5) var(--ds-space-5); color: var(--ds-ink-2); font-size: var(--ds-text-base); line-height: var(--ds-text-base-lh); }
.ds-dialog__footer {
  display: flex; justify-content: flex-end; gap: var(--ds-space-2);
  padding: var(--ds-space-3) var(--ds-space-5); background: var(--ds-surface-2);
}
.ds-menu {
  z-index: var(--ds-z-dropdown); min-width: 180px; padding: var(--ds-space-1);
  background: var(--ds-surface); border-radius: var(--ds-radius-card);
  box-shadow: var(--ds-ring), var(--ds-shadow-md);
  animation: ds-pop-in var(--ds-duration-fast) var(--ds-ease-out);
}
.ds-menu__item {
  display: flex; align-items: center; gap: var(--ds-space-2); width: 100%;
  height: var(--ds-control-sm); padding: 0 var(--ds-space-2); border: 0; border-radius: var(--ds-radius-control);
  background: transparent; color: var(--ds-ink); font: inherit;
  font-size: var(--ds-text-base); font-weight: var(--ds-fw-medium); text-align: left; cursor: pointer;
}
.ds-menu__item:hover, .ds-menu__item[data-active="true"] { background: var(--ds-hover); }
.ds-menu__item--danger { color: var(--ds-danger); }
.ds-toast {
  z-index: var(--ds-z-toast); display: flex; align-items: center; gap: var(--ds-space-3);
  min-height: var(--ds-control-lg); padding: var(--ds-space-2) var(--ds-space-4);
  background: var(--ds-surface-inverse); color: var(--ds-ink-inverse);
  border-radius: var(--ds-radius-card); box-shadow: var(--ds-shadow-lg);
  font-size: var(--ds-text-base); font-weight: var(--ds-fw-medium);
  animation: ds-pop-in var(--ds-duration) var(--ds-ease-out);
}
@keyframes ds-fade-in { from { opacity: 0; } }
@keyframes ds-pop-in { from { opacity: 0; transform: translateY(4px) scale(0.98); } }

/* ---- 9. Icon ---- */
.ds-icon { width: var(--ds-icon); height: var(--ds-icon); flex: none; stroke-width: 1.75; }
.ds-icon--sm { width: var(--ds-icon-sm); height: var(--ds-icon-sm); }
.ds-icon--lg { width: var(--ds-icon-lg); height: var(--ds-icon-lg); }

/* ---- Reduced motion applies to every recipe above ---- */
@media (prefers-reduced-motion: reduce) {
  .ds-skeleton::after { animation: none; }
  .ds-overlay, .ds-dialog, .ds-menu, .ds-toast { animation: none; }
  .ds-btn, .ds-input { transition: none; }
}
