/* ============================================================
   PRIMITIVE COMPONENTS
   Optional drop-in classes for common UI patterns.
   These reference tokens only—no hardcoded values.
   ============================================================ */

/* --------------------------------------------------------
   Surface / Card
   -------------------------------------------------------- */
.ds-surface {
  background-color: var(--surface-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-base);
}

.ds-card {
  background-color: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--gap-md);
}

.ds-card-flat {
  background-color: var(--surface-default);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-base);
  padding: var(--gap-md);
}

/* --------------------------------------------------------
   Button
   -------------------------------------------------------- */
.ds-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1-5);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-none);
  border-radius: var(--radius-base);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: color var(--duration-fast) var(--ease-out),
              background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.ds-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 var(--focus-ring-offset) var(--surface-default),
              0 0 0 calc(var(--focus-ring-offset) + 2px) var(--focus-ring);
}

.ds-button-primary {
  background-color: var(--accent-primary);
  color: var(--accent-primary-text);
  border-color: var(--accent-primary);
}
.ds-button-primary:hover {
  background-color: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
}
.ds-button-primary:active {
  background-color: var(--accent-primary-active);
  border-color: var(--accent-primary-active);
}

.ds-button-secondary {
  background-color: var(--accent-secondary);
  color: var(--accent-secondary-text);
  border-color: var(--border-default);
}
.ds-button-secondary:hover {
  background-color: var(--accent-secondary-hover);
  border-color: var(--border-hover);
}

.ds-button-danger {
  background-color: var(--accent-danger);
  color: var(--accent-danger-text);
  border-color: var(--accent-danger);
}
.ds-button-danger:hover {
  background-color: var(--accent-danger-hover);
  border-color: var(--accent-danger-hover);
}

.ds-button-ghost {
  background-color: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.ds-button-ghost:hover {
  background-color: var(--surface-hover);
  color: var(--text-primary);
}

.ds-button-sm {
  padding: var(--space-1-5) var(--space-3);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

.ds-button-lg {
  padding: var(--space-2-5) var(--space-5);
  font-size: var(--text-base);
  border-radius: var(--radius-md);
}

.ds-button:disabled,
.ds-button[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* --------------------------------------------------------
   Input
   -------------------------------------------------------- */
.ds-input {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--surface-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-base);
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.ds-input::placeholder {
  color: var(--text-muted);
}

.ds-input:hover {
  border-color: var(--border-hover);
}

.ds-input:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-ring) 15%, transparent);
}

.ds-input:disabled {
  background-color: var(--surface-inset);
  color: var(--text-muted);
  cursor: not-allowed;
}

.ds-input[readonly],
.ds-input.is-readonly {
  background-color: var(--surface-inset);
  color: var(--text-secondary);
  cursor: default;
}

.ds-input-error {
  border-color: var(--border-danger);
}
.ds-input-error:focus {
  border-color: var(--accent-danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-danger) 15%, transparent);
}

/* --------------------------------------------------------
   Badge / Pill
   -------------------------------------------------------- */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0-5) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.ds-badge-default {
  background-color: var(--surface-hover);
  color: var(--text-secondary);
}

.ds-badge-primary {
  background-color: var(--accent-primary);
  color: var(--accent-primary-text);
}

.ds-badge-success {
  background-color: var(--accent-success-bg);
  color: var(--accent-success);
}

.ds-badge-warning {
  background-color: var(--accent-warning-bg);
  color: var(--accent-warning);
}

.ds-badge-danger {
  background-color: color-mix(in srgb, var(--accent-danger) 12%, transparent);
  color: var(--accent-danger);
}

/* --------------------------------------------------------
   Table (data-dense financial style)
   -------------------------------------------------------- */
.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  text-align: left;
}

.ds-table thead {
  border-bottom: 1px solid var(--border-default);
}

.ds-table th {
  padding: var(--space-2) var(--space-3);
  font-weight: var(--weight-semibold);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-muted);
  white-space: nowrap;
}

.ds-table td {
  padding: var(--space-2-5) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.ds-table tbody tr:hover td {
  background-color: var(--surface-hover);
  color: var(--text-primary);
}

.ds-table tbody tr:last-child td {
  border-bottom: none;
}

/* Numeric columns */
.ds-table .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* --------------------------------------------------------
   Modal / Overlay Backdrop
   -------------------------------------------------------- */
.ds-backdrop {
  position: fixed;
  inset: 0;
  background-color: color-mix(in srgb, var(--surface-page) 60%, rgb(0 0 0) 20%);
  backdrop-filter: blur(4px);
  z-index: 40;
  animation: ds-fade-in var(--duration-normal) var(--ease-out);
}

.ds-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: var(--surface-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--gap-lg);
  min-width: 320px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  z-index: 50;
  animation: ds-scale-in var(--duration-normal) var(--ease-spring);
}

/* --------------------------------------------------------
   Tooltip
   -------------------------------------------------------- */
.ds-tooltip {
  position: relative;
}

.ds-tooltip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  padding: var(--space-1) var(--space-2);
  background-color: var(--text-primary);
  color: var(--text-inverted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  z-index: 30;
}

.ds-tooltip:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(-8px);
}

/* --------------------------------------------------------
   Status Dot
   -------------------------------------------------------- */
.ds-status {
  display: inline-block;
  width: 8px;
  height: var(--space-2);
  border-radius: var(--radius-full);
}

.ds-status-success { background-color: var(--accent-success); }
.ds-status-warning { background-color: var(--accent-warning); }
.ds-status-danger  { background-color: var(--accent-danger); }
.ds-status-muted   { background-color: var(--text-muted); }


/* ============================================================
   Skeleton Loading States
   ============================================================ */

.ds-skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-inset) 25%,
    var(--surface-hover) 50%,
    var(--surface-inset) 75%
  );
  background-size: 200% 100%;
  animation: ds-shimmer 1.5s infinite linear;
  border-radius: var(--radius-base);
  pointer-events: none;
  user-select: none;
}

.ds-skeleton-text {
  height: 1em;
  margin-bottom: var(--space-2);
  width: 100%;
}

.ds-skeleton-title {
  height: 1.25em;
  margin-bottom: var(--space-3);
  width: 60%;
}

.ds-skeleton-circle {
  width: var(--space-10);
  height: var(--space-10);
  border-radius: var(--radius-full);
}

.ds-skeleton-avatar {
  width: var(--space-10);
  height: var(--space-10);
  border-radius: var(--radius-full);
}

.ds-skeleton-button {
  height: var(--field-height-base);
  width: 120px;
  border-radius: var(--radius-base);
}

.ds-skeleton-card {
  height: 160px;
  width: 100%;
  border-radius: var(--radius-md);
}

.ds-skeleton-table-row {
  height: var(--space-12);
  width: 100%;
  border-radius: 0;
}

/* Reduced motion: static loading surface */
@media (prefers-reduced-motion: reduce) {
  .ds-skeleton {
    animation: none;
    background: var(--surface-hover);
  }
}

/* ============================================================
   Toast / Notification Stack
   ============================================================ */

.ds-toast-stack {
  position: fixed;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  padding: var(--space-4);
  max-width: 400px;
  width: 100%;
  pointer-events: none;
}

.ds-toast-stack > * {
  pointer-events: auto;
}

.ds-toast-stack-end   { inset-inline-end: 0; inset-block-end: 0; }
.ds-toast-stack-start { inset-inline-start: 0; inset-block-end: 0; }
.ds-toast-stack-top   { inset-inline-end: 0; inset-block-start: 0; flex-direction: column-reverse; }
.ds-toast-stack-bottom { inset-inline-end: 0; inset-block-end: 0; }

.ds-toast {
  position: relative;
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  animation: ds-toast-in var(--duration-normal) var(--ease-out);
}

.ds-toast.exiting {
  animation: ds-toast-out var(--duration-fast) var(--ease-in) forwards;
}

.ds-toast-success {
  border-color: var(--accent-success);
  background: var(--accent-success-bg);
  color: var(--accent-success);
}

.ds-toast-warning {
  border-color: var(--accent-warning);
  background: var(--accent-warning-bg);
  color: var(--accent-warning);
}

.ds-toast-danger {
  border-color: var(--accent-danger);
  background: color-mix(in srgb, var(--accent-danger) 10%, var(--surface-raised));
  color: var(--accent-danger);
}

.ds-toast-info {
  border-color: var(--accent-info);
  background: var(--accent-info-bg);
  color: var(--accent-info);
}

.ds-toast-title {
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.ds-toast-body {
  color: var(--text-secondary);
}

.ds-toast-action {
  margin-top: var(--space-2);
  display: flex;
  gap: var(--gap-sm);
}

.ds-toast-close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  padding: var(--space-1);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-lg);
  line-height: 1;
}

.ds-toast-close:hover {
  color: var(--text-primary);
}

/* Position toast close button relative to toast container */
/* Reduced motion for toasts handled inside the main .ds-toast block above */

@media (prefers-reduced-motion: reduce) {
  .ds-toast {
    animation: none;
  }
  .ds-toast.exiting {
    animation: none;
    opacity: 0;
  }
}

/* ============================================================
   Display State Matrix (for demo/documentation)
   ============================================================
   These classes mirror pseudo-states so they can be shown
   simultaneously in a reference grid.
   -------------------------------------------------------- */

/* Hover state */
.ds-button.is-hover,
.ds-card.is-hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.ds-button-primary.is-hover {
  background-color: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
}

.ds-button-secondary.is-hover {
  background-color: var(--accent-secondary-hover);
  border-color: var(--border-hover);
}

.ds-button-danger.is-hover {
  background-color: var(--accent-danger-hover);
  border-color: var(--accent-danger-hover);
}

.ds-button-ghost.is-hover {
  background-color: var(--surface-hover);
  color: var(--text-primary);
}

/* Active/pressed state */
.ds-button.is-active {
  transform: translateY(0);
}

.ds-button-primary.is-active {
  background-color: var(--accent-primary-active);
  border-color: var(--accent-primary-active);
}

/* Focus state */
.ds-button.is-focus,
.ds-input.is-focus {
  outline: none;
  box-shadow: 0 0 0 var(--focus-ring-offset) var(--surface-default),
              0 0 0 calc(var(--focus-ring-offset) + 2px) var(--focus-ring);
}

.ds-input.is-focus {
  border-color: var(--focus-ring);
}

.ds-input-error.is-focus {
  border-color: var(--accent-danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-danger) 15%, transparent);
}

/* Loading state */
.ds-button.is-loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.ds-button.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1em;
  height: 1em;
  margin-top: -0.5em;
  margin-left: -0.5em;
  border: 2px solid currentcolor;
  border-right-color: transparent;
  border-radius: var(--radius-full);
  animation: ds-spin 1s linear infinite;
  color: inherit;
}

.ds-button-primary.is-loading::after {
  color: var(--accent-primary-text);
}

.ds-button-secondary.is-loading::after {
  color: var(--accent-secondary-text);
}

.ds-button-danger.is-loading::after {
  color: var(--accent-danger-text);
}

.ds-button-ghost.is-loading::after {
  color: var(--text-secondary);
}

@media (prefers-reduced-motion: reduce) {
  .ds-button.is-loading::after {
    animation: none;
    border-right-color: currentcolor;
  }
}

/* Selected state */
.ds-card.is-selected {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 1px var(--accent-primary);
}

.ds-table tbody tr.is-selected td {
  background-color: var(--surface-selected);
  color: var(--text-primary);
}

/* ============================================================
   FORM FIELD
   Wrapper for label, control, help text, and error text.
   No JavaScript required.
   ============================================================ */

.ds-field {
  display: grid;
  gap: var(--space-1);
}

.ds-field-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.ds-field-required {
  color: var(--accent-danger);
  margin-inline-start: var(--space-0-5);
}

.ds-field-help {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: var(--leading-normal);
}

.ds-field-error {
  font-size: var(--text-xs);
  color: var(--accent-danger);
  line-height: var(--leading-normal);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.ds-field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--gap-md);
}

.ds-field.is-invalid .ds-field-label,
.ds-field[aria-invalid="true"] .ds-field-label {
  color: var(--accent-danger);
}

.ds-field.is-disabled .ds-field-label,
.ds-field.is-disabled .ds-field-help {
  color: var(--text-muted);
}

.ds-field.is-readonly .ds-field-label {
  color: var(--text-secondary);
}

/* ============================================================
   SWITCH / TOGGLE
   Binary control backed by a native checkbox.
   No JavaScript required.
   ============================================================ */

.ds-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
}

.ds-switch:has(.ds-switch-input:disabled),
.ds-switch.is-disabled {
  cursor: not-allowed;
}

.ds-switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ds-switch-track {
  position: relative;
  width: 40px;
  height: 24px;
  background: var(--surface-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
}

.ds-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--surface-default);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-fast) var(--ease-out);
}

.ds-switch-input:checked + .ds-switch-track {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.ds-switch-input:checked + .ds-switch-track .ds-switch-thumb {
  transform: translateX(16px);
}

.ds-switch-input:focus-visible + .ds-switch-track {
  outline: none;
  box-shadow: 0 0 0 var(--focus-ring-offset) var(--surface-default),
              0 0 0 calc(var(--focus-ring-offset) + 2px) var(--focus-ring);
}

.ds-switch-input:disabled + .ds-switch-track {
  background: var(--surface-inset);
  border-color: var(--border-subtle);
  opacity: var(--opacity-disabled);
  cursor: not-allowed;
}

.ds-switch-input:disabled + .ds-switch-track .ds-switch-thumb {
  background: var(--border-default);
}

.ds-switch-label {
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.ds-switch-description {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Switch sizes */
.ds-switch-sm .ds-switch-track {
  width: 32px;
  height: 18px;
}

.ds-switch-sm .ds-switch-thumb {
  width: 14px;
  height: 14px;
}

.ds-switch-sm .ds-switch-input:checked + .ds-switch-track .ds-switch-thumb {
  transform: translateX(12px);
}

.ds-switch-lg .ds-switch-track {
  width: 52px;
  height: 30px;
}

.ds-switch-lg .ds-switch-thumb {
  width: 24px;
  height: 24px;
}

.ds-switch-lg .ds-switch-input:checked + .ds-switch-track .ds-switch-thumb {
  transform: translateX(20px);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .ds-switch-track,
  .ds-switch-thumb {
    transition: none;
  }
}

/* ============================================================
   TABS
   Tab list and panels. CSS handles layout and selected state.
   App/framework code must handle panel switching, roving
   tabindex, and ARIA state updates.
   ============================================================ */

.ds-tabs {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
}

.ds-tab-list {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-default);
  position: relative;
}

.ds-tab {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-out),
              background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
  margin-bottom: -1px;
  white-space: nowrap;
}

.ds-tab:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
}

.ds-tab:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.ds-tab.is-active,
.ds-tab[aria-selected="true"] {
  color: var(--text-primary);
  border-bottom-color: var(--accent-primary);
  font-weight: var(--weight-semibold);
}

.ds-tab-panel {
  padding: var(--space-2) 0;
}

.ds-tab-panel[hidden] {
  display: none;
}

/* Compact variant */
.ds-tabs-compact .ds-tab {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .ds-tab {
    transition: none;
  }
}

/* ============================================================
   ACCORDION / DETAILS
   Collapsible content using native <details> where possible.
   No JavaScript required for basic behavior.
   ============================================================ */

.ds-accordion {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.ds-accordion-item {
  border-bottom: 1px solid var(--border-subtle);
}

.ds-accordion-item:last-child {
  border-bottom: none;
}

.ds-accordion-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.ds-accordion-summary::-webkit-details-marker {
  display: none;
}

.ds-accordion-summary:hover {
  background: var(--surface-hover);
}

.ds-accordion-summary:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.ds-accordion-icon {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
}

.ds-accordion-item[open] .ds-accordion-icon {
  transform: rotate(180deg);
}

/* Content reveal animation using grid */
.ds-accordion-content {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--duration-normal) var(--ease-out);
}

.ds-accordion-item[open] .ds-accordion-content {
  grid-template-rows: 1fr;
}

.ds-accordion-content > div {
  overflow: hidden;
  min-height: 0;
}

.ds-accordion-content-inner {
  padding: 0 var(--space-4) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-normal);
}

/* ============================================================
   DROPDOWN / SELECT MENU
   Styled native select and custom menu structure.
   Custom menus require JavaScript for accessibility.
   ============================================================ */

/* Native select wrapper */
.ds-select-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
}

.ds-select-wrapper::after {
  content: '';
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--text-muted);
  pointer-events: none;
}

.ds-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--surface-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  min-height: var(--field-height-base);
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.ds-select:focus-visible {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.ds-select:disabled {
  opacity: var(--opacity-disabled);
  cursor: var(--cursor-disabled);
}

/* Custom menu */
.ds-menu {
  position: relative;
  display: inline-block;
}

.ds-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  background: var(--surface-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
}

.ds-menu-trigger:hover {
  background: var(--surface-hover);
}

.ds-menu-trigger:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.ds-menu-content {
  position: absolute;
  z-index: var(--z-dropdown);
  min-width: 12rem;
  padding: var(--space-1);
  background: var(--surface-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  visibility: hidden;
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  transition: visibility 0s var(--duration-fast),
              opacity var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

.ds-menu-content[data-state="open"] {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.ds-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.ds-menu-item:hover {
  background: var(--surface-hover);
}

.ds-menu-item:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.ds-menu-item[data-disabled] {
  opacity: var(--opacity-disabled);
  cursor: var(--cursor-disabled);
  pointer-events: none;
}

.ds-menu-separator {
  height: 1px;
  margin: var(--space-1) var(--space-2);
  background: var(--border-subtle);
}

.ds-menu-label {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

/* ============================================================
   PROGRESS BAR / SPINNER
   Native progress styling and indeterminate spinner.
   ============================================================ */

.ds-progress {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: var(--space-2);
  border: none;
  border-radius: var(--radius-pill);
  background: var(--surface-inset);
  overflow: hidden;
}

.ds-progress::-webkit-progress-bar {
  background: var(--surface-inset);
  border-radius: var(--radius-pill);
}

.ds-progress::-webkit-progress-value {
  background: var(--accent-primary);
  border-radius: var(--radius-pill);
  transition: width var(--duration-normal) var(--ease-out);
}

.ds-progress::-moz-progress-bar {
  background: var(--accent-primary);
  border-radius: var(--radius-pill);
}

.ds-progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.ds-progress-value {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
}

/* Div-based progress track and bar */
.ds-progress-track {
  width: 100%;
  height: var(--space-2);
  background: var(--surface-inset);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.ds-progress-bar {
  height: 100%;
  background: var(--accent-primary);
  border-radius: var(--radius-pill);
  transition: width var(--duration-normal) var(--ease-out);
}

/* Spinner */
.ds-spinner {
  display: inline-block;
  width: var(--space-6);
  height: var(--space-6);
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-full);
  animation: ds-spin 1s linear infinite;
}

.ds-spinner-sm {
  width: var(--space-4);
  height: var(--space-4);
  border-width: 1.5px;
}

.ds-spinner-lg {
  width: var(--space-8);
  height: var(--space-8);
  border-width: 3px;
}

/* ============================================================
   PAGINATION
   Page navigation for tables, lists, and search results.
   ============================================================ */

.ds-pagination {
  display: flex;
}

.ds-pagination-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  list-style: none;
  padding: 0;
  margin: 0;
}

.ds-pagination-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--space-9);
  height: var(--space-9);
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  background: var(--surface-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
}

.ds-pagination-link:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.ds-pagination-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.ds-pagination-link[aria-current="page"] {
  background: var(--accent-primary);
  color: var(--accent-primary-text);
  border-color: var(--accent-primary);
}

.ds-pagination-link[aria-disabled="true"] {
  opacity: var(--opacity-disabled);
  cursor: var(--cursor-disabled);
  pointer-events: none;
}

.ds-pagination-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--space-9);
  height: var(--space-9);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ============================================================
   BREADCRUMB
   Page hierarchy navigation.
   ============================================================ */

.ds-breadcrumb-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
  padding: 0;
  margin: 0;
}

.ds-breadcrumb-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.ds-breadcrumb-link {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

.ds-breadcrumb-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.ds-breadcrumb-link[aria-current="page"] {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
  text-decoration: none;
  pointer-events: none;
}

.ds-breadcrumb-separator {
  color: var(--text-muted);
  user-select: none;
}

/* ============================================================
   AVATAR
   User/entity image or initials with consistent sizing.
   ============================================================ */

.ds-avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: var(--space-10);
  height: var(--space-10);
  border-radius: var(--radius-full);
  background: var(--surface-inset);
  overflow: hidden;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
}

.ds-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ds-avatar-initials {
  line-height: 1;
  user-select: none;
}

.ds-avatar-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: var(--space-2-5);
  height: var(--space-2-5);
  border-radius: var(--radius-full);
  border: 2px solid var(--surface-default);
  background: var(--text-muted);
}

.ds-avatar-status-online  { background: var(--accent-success); }
.ds-avatar-status-away    { background: var(--accent-warning); }
.ds-avatar-status-busy    { background: var(--accent-danger); }
.ds-avatar-status-offline { background: var(--text-muted); }

.ds-avatar-xs { width: var(--space-6); height: var(--space-6); font-size: var(--text-xs); }
.ds-avatar-xs .ds-avatar-status { width: var(--space-1-5); height: var(--space-1-5); border-width: 1px; }

.ds-avatar-sm { width: var(--space-8); height: var(--space-8); font-size: var(--text-xs); }
.ds-avatar-sm .ds-avatar-status { width: var(--space-2); height: var(--space-2); border-width: 1.5px; }

.ds-avatar-md { width: var(--space-10); height: var(--space-10); }
.ds-avatar-md .ds-avatar-status { width: var(--space-2-5); height: var(--space-2-5); }

.ds-avatar-lg { width: var(--space-12); height: var(--space-12); font-size: var(--text-base); }
.ds-avatar-lg .ds-avatar-status { width: var(--space-3); height: var(--space-3); border-width: 2.5px; }

.ds-avatar-xl { width: var(--space-16); height: var(--space-16); font-size: var(--text-lg); }
.ds-avatar-xl .ds-avatar-status { width: var(--space-3-5); height: var(--space-3-5); border-width: 3px; }

/* ============================================================
   EMPTY STATE
   Consistent no-data, no-results, and first-use states.
   ============================================================ */

.ds-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4);
  color: var(--text-secondary);
}

.ds-empty-icon {
  width: var(--icon-lg);
  height: var(--icon-lg);
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.ds-empty-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin: 0;
}

.ds-empty-description {
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: var(--leading-normal);
  max-width: 320px;
  margin: 0;
}

.ds-empty-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .ds-accordion-content {
    transition: none;
  }
  .ds-accordion-icon {
    transition: none;
  }
  .ds-menu-content {
    transition: none;
  }
  .ds-spinner {
    animation: none;
    border-style: dashed;
    opacity: 0.7;
  }
  .ds-progress-bar,
  .ds-progress::-webkit-progress-value {
    transition: none;
  }
}
