/* ==========================================================================
 * XUI Component Library — v1.0
 * Strictly consumes variables from tokens.css. Zero external dependencies.
 * State priority: disabled > loading > active > focus-visible > hover > default.
 * ========================================================================== */

/* ---------- 1. Buttons ---------- */
.xui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: var(--btn-h);
  padding: var(--s-0) var(--s-3-5);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text-1);
  font-size: var(--t-small-size);
  font-weight: var(--t-weight-medium);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition:
    background var(--d-fast) var(--ease),
    border-color var(--d-fast) var(--ease),
    color var(--d-fast) var(--ease),
    transform var(--d-instant) var(--ease);
}

.xui-btn:not(:disabled):not([data-state="loading"]):hover {
  background: var(--bg-elev-3);
  border-color: var(--line-strong);
  transform: translateY(var(--hover-lift));
}

.xui-btn:not(:disabled):not([data-state="loading"]):active {
  background: var(--bg-elev-4);
  transform: translateY(1px) scale(var(--press-scale));
}

.xui-btn.is-sm {
  height: var(--btn-h-sm);
  padding: var(--s-0) var(--s-2-5);
  font-size: var(--t-caption-size);
}

.xui-btn.is-lg {
  height: var(--btn-h-lg);
  padding: var(--s-0) var(--s-4-5);
  font-size: var(--t-body-size);
}

.xui-btn.is-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
  font-weight: var(--t-weight-semibold);
}

.xui-btn.is-primary:not(:disabled):not([data-state="loading"]):hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.xui-btn.is-primary:not(:disabled):not([data-state="loading"]):active {
  background: var(--accent-active);
  border-color: var(--accent-active);
}

.xui-btn.is-soft {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-on-soft);
}

.xui-btn.is-soft:not(:disabled):not([data-state="loading"]):hover {
  border-color: var(--accent-ring);
}

.xui-btn.is-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.xui-btn.is-ghost:not(:disabled):not([data-state="loading"]):hover {
  background: var(--bg-elev-3);
  color: var(--text-1);
}

.xui-btn.is-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--text-pure);
  font-weight: var(--t-weight-semibold);
}

.xui-btn.is-danger:not(:disabled):not([data-state="loading"]):hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.xui-btn.is-danger-soft {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

.xui-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.xui-btn[data-state="loading"] {
  cursor: progress;
  opacity: 0.78;
}

.xui-spinner {
  width: 14px;
  height: 14px;
  border-radius: var(--r-pill);
  border: 2px solid currentColor;
  border-right-color: transparent;
  display: inline-block;
  animation: xui-spin 720ms linear infinite;
}

/* Icon Button */
.xui-icon-btn {
  flex: none;
  width: var(--icon-btn-size);
  height: var(--icon-btn-size);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease), transform var(--d-instant) var(--ease);
}

.xui-icon-btn.is-sm {
  width: var(--icon-btn-sm);
  height: var(--icon-btn-sm);
}

.xui-icon-btn:not(:disabled):hover {
  background: var(--bg-elev-3);
  color: var(--text-1);
}

.xui-icon-btn:not(:disabled):active {
  transform: scale(var(--press-scale));
}

.xui-icon-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent-on-soft);
}

.xui-icon-btn.is-active:not(:disabled):hover {
  background: var(--accent-ring);
}

.xui-icon-btn.is-danger:not(:disabled):hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.xui-icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- 2. Segmented Control (Signature XPlayer Pattern) ---------- */
.xui-seg {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s-0-5);
  padding: 2px;
  background: var(--bg-base);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  user-select: none;
}

/* Sliding pill injected by XUI.ui.initIndicators() — animates via transform + width only.
 * Without JS (no [data-xui-indicator]) the per-item .is-active background below stands in. */
.xui-seg-indicator {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: var(--r-xs);
  background: var(--bg-elev-3);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line-strong);
  pointer-events: none;
  transition:
    transform var(--d-switch) var(--ease-out),
    width var(--d-switch) var(--ease-out),
    height var(--d-switch) var(--ease-out),
    opacity var(--d-fast) var(--ease);
}

.xui-seg-indicator.is-accent {
  background: var(--accent);
  box-shadow: none;
}

.xui-seg[data-xui-indicator] .xui-seg-item.is-active {
  background: transparent;
  box-shadow: none;
}

.xui-seg-item {
  height: calc(var(--btn-h-sm) - 2px);
  padding: var(--s-0) var(--s-2-5);
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-2);
  font-size: var(--t-caption-size);
  font-weight: var(--t-weight-medium);
  display: inline-flex;
  align-items: center;
  gap: var(--s-1-5);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}

.xui-seg-item:hover {
  background: var(--bg-elev-3);
  color: var(--text-1);
}

.xui-seg-item.is-active {
  background: var(--bg-elev-3);
  color: var(--text-1);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line-strong);
}

.xui-seg-item.is-active:hover {
  background: var(--bg-elev-4);
}

.xui-seg-item.is-accent.is-active {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: none;
}

.xui-seg-item.is-accent.is-active:hover {
  background: var(--accent-hover);
}

/* ---------- 3. Form Controls ---------- */
.xui-field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1-5);
}

.xui-field-label {
  font-size: var(--t-caption-size);
  font-weight: var(--t-weight-medium);
  color: var(--text-2);
}

.xui-field-hint {
  font-size: var(--t-micro-size);
  color: var(--text-3);
}

.xui-field[data-state="error"] .xui-field-hint {
  color: var(--danger);
}

.xui-input,
.xui-select,
.xui-textarea {
  width: 100%;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev-1);
  color: var(--text-1);
  font-size: var(--t-small-size);
  transition: border-color var(--d-fast) var(--ease), background var(--d-fast) var(--ease);
}

.xui-input,
.xui-select {
  height: var(--input-h);
  padding: var(--s-0) var(--s-3);
}

.xui-textarea {
  padding: var(--s-2-5) var(--s-3);
  min-height: 84px;
  resize: vertical;
  line-height: var(--t-body-lh);
}

.xui-input::placeholder,
.xui-textarea::placeholder {
  color: var(--text-3);
}

.xui-input:not(:disabled):not([readonly]):hover,
.xui-select:not(:disabled):hover,
.xui-textarea:not(:disabled):not([readonly]):hover {
  border-color: var(--line-strong);
}

.xui-input:focus,
.xui-select:focus,
.xui-textarea:focus {
  border-color: var(--accent);
  /* Keep a real outline alongside the soft glow: R-FOCUS-02 forbids box-shadow-only
   * rings because they vanish in Windows High Contrast / forced-colors mode. */
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: -1px;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.xui-field[data-state="error"] .xui-input,
.xui-field[data-state="error"] .xui-select,
.xui-field[data-state="error"] .xui-textarea {
  border-color: var(--danger);
}

.xui-input:disabled,
.xui-select:disabled,
.xui-textarea:disabled {
  background: var(--bg-base);
  color: var(--text-3);
  cursor: not-allowed;
}

/* Input with leading icon / trailing kbd */
.xui-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.xui-input-wrap > .xui-input-icon {
  position: absolute;
  left: var(--s-2-5);
  color: var(--text-3);
  pointer-events: none;
  display: inline-flex;
}

.xui-input-wrap.has-icon > .xui-input {
  padding-left: calc(var(--s-3) + 20px);
}

.xui-input-wrap > .xui-input-trail {
  position: absolute;
  right: var(--s-2);
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
}

/* Toggle Switch */
.xui-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2-5);
  cursor: pointer;
  user-select: none;
}

.xui-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.xui-toggle-track {
  width: var(--toggle-w);
  height: var(--toggle-h);
  border-radius: var(--r-pill);
  background: var(--bg-elev-4);
  border: 1px solid var(--line);
  padding: 2px;
  display: inline-flex;
  align-items: center;
  transition: background var(--d-switch) var(--ease), border-color var(--d-switch) var(--ease);
}

.xui-toggle-knob {
  width: var(--toggle-knob);
  height: var(--toggle-knob);
  border-radius: var(--r-pill);
  background: var(--text-1);
  transition: transform var(--d-switch) var(--ease-spring), background var(--d-switch) var(--ease);
}

.xui-toggle input:checked + .xui-toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}

.xui-toggle input:checked + .xui-toggle-track .xui-toggle-knob {
  transform: translateX(calc(var(--toggle-w) - var(--toggle-knob) - 6px));
  background: var(--text-on-accent);
}

.xui-toggle input:focus-visible + .xui-toggle-track {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

/* Checkbox */
.xui-check {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--t-small-size);
  cursor: pointer;
  user-select: none;
}

.xui-check input[type="checkbox"],
.xui-check input[type="radio"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* Range Slider (Video scrub, volume, zoom, opacity) */
.xui-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--bg-elev-4);
  outline: none;
  cursor: pointer;
}

.xui-slider:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: 3px;
}

.xui-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: var(--r-pill);
  background: var(--accent);
  border: 2px solid var(--bg-elev-1);
  box-shadow: var(--shadow-sm);
  transition: transform var(--d-fast) var(--ease);
}

.xui-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* ---------- 4. Badges, Dots, Kbd, Avatars ---------- */
.xui-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  height: 22px;
  padding: var(--s-0) var(--s-2);
  border-radius: var(--r-pill);
  background: var(--bg-elev-3);
  color: var(--text-2);
  font-size: var(--t-micro-size);
  font-weight: var(--t-weight-medium);
  white-space: nowrap;
}

.xui-badge.is-accent { background: var(--accent-soft); color: var(--accent-on-soft); }
.xui-badge.is-info { background: var(--info-soft); color: var(--info); }
.xui-badge.is-success { background: var(--success-soft); color: var(--success); }
.xui-badge.is-warn { background: var(--warn-soft); color: var(--warn); }
.xui-badge.is-danger { background: var(--danger-soft); color: var(--danger); }

.xui-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--r-pill);
  background: var(--text-3);
  display: inline-block;
  flex: none;
}

.xui-dot.is-accent { background: var(--accent); }
.xui-dot.is-success { background: var(--success); }
.xui-dot.is-warn { background: var(--warn); }
.xui-dot.is-danger { background: var(--danger); }
.xui-dot.is-pulse { animation: xui-pulse-dot 1.8s ease-in-out infinite; }

.xui-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: var(--s-0) var(--s-1-5);
  border-radius: var(--r-xs);
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: var(--t-micro-size);
  line-height: 1;
}

.xui-avatar {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  background: var(--tone-grad-0);
  color: var(--text-pure);
  font-size: var(--t-caption-size);
  font-weight: var(--t-weight-semibold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  user-select: none;
}

.xui-avatar.is-sm { width: 24px; height: 24px; font-size: var(--t-micro-size); }
.xui-avatar.is-lg { width: 42px; height: 42px; font-size: var(--t-body-size); }
.xui-avatar.is-square { border-radius: var(--r-sm); }
.xui-avatar[data-tone="0"] { background: var(--tone-grad-0); }
.xui-avatar[data-tone="1"] { background: var(--tone-grad-1); }
.xui-avatar[data-tone="2"] { background: var(--tone-grad-2); }
.xui-avatar[data-tone="3"] { background: var(--tone-grad-3); }
.xui-avatar[data-tone="4"] { background: var(--tone-grad-4); }
.xui-avatar[data-tone="5"] { background: var(--tone-grad-5); }

.xui-avatar-status {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: var(--r-pill);
  background: var(--success);
  border: 2px solid var(--bg-elev-1);
}

/* ---------- 5. Tabs (Underline & Editor Tab Strip) ---------- */
.xui-tabs-list {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-1);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.xui-tabs-list::-webkit-scrollbar { display: none; }

/* Sliding underline injected by XUI.ui.initIndicators() (transform + width only). */
.xui-tab-indicator {
  position: absolute;
  left: 0;
  top: 0;
  height: 2px;
  border-radius: var(--r-pill);
  background: var(--accent);
  pointer-events: none;
  transition:
    transform var(--d-switch) var(--ease-out),
    width var(--d-switch) var(--ease-out),
    opacity var(--d-fast) var(--ease);
}

.xui-tab-indicator.is-editor {
  border-radius: 0;
}

.xui-tabs-list[data-xui-indicator] .xui-tab.is-active::after {
  display: none;
}

.xui-tab {
  position: relative;
  height: 36px;
  padding: var(--s-0) var(--s-3);
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: var(--t-small-size);
  font-weight: var(--t-weight-medium);
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--d-fast) var(--ease), background var(--d-fast) var(--ease);
}

.xui-tab:hover {
  color: var(--text-1);
}

.xui-tab.is-active {
  color: var(--accent);
}

.xui-tab.is-active::after {
  content: "";
  position: absolute;
  left: var(--s-2);
  right: var(--s-2);
  bottom: 0;
  height: 2px;
  border-radius: var(--r-pill);
  background: var(--accent);
}

/* Editor / Document File Tabs */
.xui-tabs-list.is-editor {
  background: var(--bg-base);
  gap: var(--s-0);
}

.xui-tabs-list.is-editor .xui-tab {
  height: 34px;
  border-right: 1px solid var(--line-subtle);
  font-size: var(--t-caption-size);
  padding: var(--s-0) var(--s-3);
}

.xui-tabs-list.is-editor .xui-tab.is-active {
  background: var(--bg-elev-1);
  color: var(--text-1);
}

.xui-tabs-list.is-editor .xui-tab.is-active::after {
  left: 0;
  right: 0;
  top: 0;
  bottom: auto;
  border-radius: 0;
}

.xui-tab-panel {
  display: none;
}

.xui-tab-panel.is-active {
  display: block;
  animation: xui-fade-in var(--d-fast) var(--ease-out);
}

/* ---------- 6. Cards & Property Grid ---------- */
.xui-card {
  background: var(--bg-elev-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--card-pad);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  transition: border-color var(--d-fast) var(--ease), background var(--d-fast) var(--ease), transform var(--d-fast) var(--ease);
}

.xui-card.is-interactive {
  cursor: pointer;
}

.xui-card.is-interactive:hover {
  border-color: var(--line-strong);
  background: var(--bg-elev-2);
}

.xui-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.xui-prop-grid {
  display: grid;
  grid-template-columns: minmax(84px, auto) 1fr;
  gap: var(--s-2) var(--s-3);
  font-size: var(--t-caption-size);
}

.xui-prop-key {
  color: var(--text-3);
}

.xui-prop-val {
  color: var(--text-1);
  word-break: break-word;
}

/* ---------- 7. Breadcrumb (Cloud Drive / IDE) ---------- */
.xui-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  font-size: var(--t-small-size);
  color: var(--text-2);
  overflow: hidden;
}

.xui-crumb {
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-xs);
  border: 0;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}

.xui-crumb:hover {
  background: var(--bg-elev-3);
  color: var(--text-1);
}

.xui-crumb.is-current {
  color: var(--text-1);
  font-weight: var(--t-weight-semibold);
}

.xui-crumb-sep {
  color: var(--text-3);
  user-select: none;
}

/* ---------- 8. Tree View (IDE / Cloud Drive) ---------- */
.xui-tree {
  display: flex;
  flex-direction: column;
  gap: 1px;
  user-select: none;
}

.xui-tree-row {
  display: flex;
  align-items: center;
  gap: var(--s-1-5);
  height: var(--row-h-compact);
  padding: var(--s-0) var(--s-2);
  padding-left: calc(var(--s-2) + var(--depth, 0) * 14px);
  border-radius: var(--r-xs);
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: var(--t-caption-size);
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}

.xui-tree-row:hover {
  background: var(--bg-elev-3);
  color: var(--text-1);
}

.xui-tree-row.is-active {
  background: var(--accent-soft);
  color: var(--accent-on-soft);
  font-weight: var(--t-weight-medium);
}

.xui-tree-row.is-active:hover {
  background: var(--accent-ring);
}

.xui-tree-chevron {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  transition: transform var(--d-fast) var(--ease);
}

.xui-tree-row[aria-expanded="true"] .xui-tree-chevron {
  transform: rotate(90deg);
}

/* Collapse animates grid-template-rows 0fr -> 1fr (the modern "auto height" technique);
 * the inner wrapper (injected by XUI.ui.initTrees) supplies the overflow clip. */
.xui-tree-children {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--d-base) var(--ease-out);
}

.xui-tree-children.is-open {
  grid-template-rows: 1fr;
}

.xui-tree-children-inner {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* ---------- 9. Data Table & Virtual List ---------- */
.xui-table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-elev-1);
}

.xui-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-small-size);
}

.xui-table th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--row-h-compact);
  padding: var(--s-0) var(--s-3);
  text-align: left;
  font-size: var(--t-micro-size);
  font-weight: var(--t-weight-semibold);
  color: var(--text-3);
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.xui-table td {
  height: var(--row-h);
  padding: var(--s-0) var(--s-3);
  border-bottom: 1px solid var(--line-subtle);
  color: var(--text-1);
  vertical-align: middle;
}

.xui-table tbody tr {
  transition: background var(--d-fast) var(--ease);
}

.xui-table tbody tr:hover {
  background: var(--bg-elev-3);
}

.xui-table tbody tr.is-selected {
  background: var(--accent-soft);
}

/* Virtual List Container */
.xui-vlist {
  position: relative;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-elev-1);
}

.xui-vlist-spacer {
  position: relative;
  width: 100%;
}

.xui-vlist-row {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-0) var(--s-3);
  border-bottom: 1px solid var(--line-subtle);
  font-size: var(--t-small-size);
  cursor: pointer;
  transition: background var(--d-fast) var(--ease);
}

.xui-vlist-row:hover {
  background: var(--bg-elev-3);
}

.xui-vlist-row.is-active {
  background: var(--accent-soft);
  color: var(--accent-on-soft);
}

.xui-vlist-row.is-active:hover {
  background: var(--accent-ring);
}

/* ---------- 10. Progress Bar ---------- */
.xui-progress {
  position: relative;
  width: 100%;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--bg-elev-3);
  overflow: hidden;
}

.xui-progress-fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--accent);
  transition: width var(--d-base) var(--ease);
}

.xui-progress.is-success .xui-progress-fill { background: var(--success); }
.xui-progress.is-warn .xui-progress-fill { background: var(--warn); }
.xui-progress.is-danger .xui-progress-fill { background: var(--danger); }

.xui-progress.is-indeterminate .xui-progress-fill {
  width: 45%;
  animation: xui-progress-indeterminate 1.4s var(--ease) infinite;
}

/* ---------- 11. Timeline Tracks (Video Editor / Audio DAW) ---------- */
.xui-timeline {
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  user-select: none;
}

.xui-timeline-ruler {
  height: 24px;
  display: flex;
  align-items: center;
  padding-left: 112px;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--t-micro-size);
  color: var(--text-3);
}

.xui-timeline-track {
  display: flex;
  align-items: stretch;
  height: 40px;
  border-bottom: 1px solid var(--line-subtle);
}

.xui-timeline-head {
  width: 112px;
  flex: none;
  padding: var(--s-0) var(--s-2-5);
  background: var(--bg-elev-1);
  border-right: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--t-micro-size);
  color: var(--text-2);
}

.xui-timeline-lane {
  position: relative;
  flex: 1;
  background: var(--bg-base);
  overflow: hidden;
}

.xui-clip {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: var(--r-xs);
  padding: var(--s-0) var(--s-2);
  display: flex;
  align-items: center;
  font-size: var(--t-micro-size);
  font-weight: var(--t-weight-medium);
  color: var(--text-pure);
  background: var(--tone-grad-3);
  border: 1px solid var(--line-strong);
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
}

.xui-clip.is-video { background: var(--tone-grad-1); border-color: var(--tone-1); }
.xui-clip.is-audio { background: var(--tone-grad-0); border-color: var(--tone-0); }
.xui-clip.is-fx { background: var(--tone-grad-4); border-color: var(--tone-4); }
.xui-clip.is-selected { outline: 2px solid var(--accent); outline-offset: -1px; }

.xui-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  pointer-events: none;
  z-index: 4;
}

/* ---------- 12. Chat Message Primitives (IM / AI Chat) ---------- */
.xui-chat-msg {
  display: flex;
  gap: var(--s-2-5);
  align-items: flex-start;
  max-width: 82%;
}

.xui-chat-msg.is-self {
  margin-left: auto;
  flex-direction: row-reverse;
}

.xui-chat-bubble {
  padding: var(--s-2-5) var(--s-3-5);
  border-radius: var(--r-md);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  font-size: var(--t-small-size);
  line-height: var(--t-body-lh);
  color: var(--text-1);
}

.xui-chat-msg.is-self .xui-chat-bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

.xui-chat-meta {
  font-size: var(--t-micro-size);
  color: var(--text-3);
  margin-bottom: var(--s-1);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.xui-chat-msg.is-self .xui-chat-meta {
  justify-content: flex-end;
}

/* ---------- 13. Toolbar ---------- */
.xui-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s-1-5);
  padding: var(--s-1-5) var(--s-2-5);
  background: var(--bg-elev-1);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

/* ---------- 14. Context & Dropdown Menu ---------- */
.xui-menu {
  position: fixed;
  min-width: var(--menu-min-w);
  padding: var(--s-1-5);
  border-radius: var(--r-md);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-menu);
  z-index: var(--z-menu);
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform-origin: top left;
  transform: translateY(calc(-4px * var(--motion-scale))) scale(0.97);
  /* Leave state carries the faster --d-exit; JS toggles .is-open and waits for it. */
  transition:
    opacity var(--d-exit) var(--ease-out),
    transform var(--d-exit) var(--ease-out),
    visibility 0s linear var(--d-exit);
}

.xui-menu.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition:
    opacity var(--d-base) var(--ease-out),
    transform var(--d-base) var(--ease-out),
    visibility 0s linear 0s;
}

.xui-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-1-5) var(--s-2-5);
  border-radius: var(--r-sm);
  border: 0;
  background: transparent;
  color: var(--text-1);
  font-size: var(--t-small-size);
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}

.xui-menu-item:hover,
.xui-menu-item.is-focused {
  background: var(--bg-elev-3);
}

.xui-menu-item.is-active {
  color: var(--accent-on-soft);
}

.xui-menu-item.is-active:hover,
.xui-menu-item.is-active.is-focused {
  background: var(--accent-soft);
}

.xui-menu-item.is-danger {
  color: var(--danger);
}

.xui-menu-item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.xui-menu-sep {
  height: 1px;
  background: var(--line);
  margin: var(--s-1) var(--s-1);
}

.xui-menu-label {
  padding: var(--s-1) var(--s-2-5);
  font-size: var(--t-micro-size);
  font-weight: var(--t-weight-semibold);
  color: var(--text-3);
}

/* ---------- 15. Dialog Modal ---------- */
.xui-dialog-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: var(--z-dialog);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-5);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--d-exit) var(--ease-out), visibility 0s linear var(--d-exit);
}

.xui-dialog-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity var(--d-base) var(--ease-out), visibility 0s linear 0s;
}

.xui-dialog {
  width: 100%;
  max-width: var(--dialog-w);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-dialog);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(calc(8px * var(--motion-scale))) scale(0.98);
  transition: opacity var(--d-exit) var(--ease-out), transform var(--d-exit) var(--ease-out);
}

.xui-dialog-backdrop.is-open .xui-dialog {
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity var(--d-base) var(--ease-out), transform var(--d-base) var(--ease-out);
}

.xui-dialog.is-lg { max-width: var(--dialog-w-lg); }

.xui-dialog-head {
  padding: var(--s-3-5) var(--s-5);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.xui-dialog-title {
  margin: 0;
  font-size: var(--t-h2-size);
  font-weight: var(--t-h2-w);
}

.xui-dialog-body {
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-3-5);
  max-height: 70vh;
  overflow-y: auto;
}

.xui-dialog-foot {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
}

/* ---------- 16. Drawer ---------- */
.xui-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: var(--z-drawer);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--d-exit) var(--ease);
}

.xui-drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
  transition: opacity var(--d-base) var(--ease);
}

.xui-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(var(--drawer-w), 92vw);
  background: var(--bg-elev-1);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-dialog);
  z-index: calc(var(--z-drawer) + 1);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--d-exit) var(--ease-drawer);
}

.xui-drawer[data-side="left"] {
  right: auto;
  left: 0;
  border-left: 0;
  border-right: 1px solid var(--line);
  transform: translateX(-100%);
}

.xui-drawer.is-open {
  transform: translateX(0);
  transition: transform var(--d-base) var(--ease-drawer);
}

.xui-drawer-head {
  height: var(--topbar-h);
  padding: var(--s-0) var(--s-4);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
}

.xui-drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s-4);
}

/* ---------- 17. Command Palette (Ctrl+K) ---------- */
.xui-cmdk-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: var(--z-cmdk);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh var(--s-4) var(--s-5);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--d-exit) var(--ease-out), visibility 0s linear var(--d-exit);
}

.xui-cmdk-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity var(--d-base) var(--ease-out), visibility 0s linear 0s;
}

.xui-cmdk {
  width: 100%;
  max-width: var(--cmdk-w);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-dialog);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(calc(8px * var(--motion-scale))) scale(0.98);
  transition: opacity var(--d-exit) var(--ease-out), transform var(--d-exit) var(--ease-out);
}

.xui-cmdk-backdrop.is-open .xui-cmdk {
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity var(--d-base) var(--ease-out), transform var(--d-base) var(--ease-out);
}

.xui-cmdk-input-row {
  display: flex;
  align-items: center;
  gap: var(--s-2-5);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
}

.xui-cmdk-input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-1);
  font-size: var(--t-body-size);
  outline: none;
}

.xui-cmdk-list {
  max-height: 320px;
  overflow-y: auto;
  padding: var(--s-1-5);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.xui-cmdk-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  border: 0;
  background: transparent;
  color: var(--text-1);
  font-size: var(--t-small-size);
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.xui-cmdk-item:hover,
.xui-cmdk-item.is-selected {
  background: var(--accent-soft);
  color: var(--accent-on-soft);
}

.xui-cmdk-foot {
  padding: var(--s-2) var(--s-4);
  border-top: 1px solid var(--line-subtle);
  background: var(--bg-elev-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--t-micro-size);
  color: var(--text-3);
}

/* ---------- 18. Toast Stack ---------- */
.xui-toast-stack {
  position: fixed;
  right: var(--s-4);
  bottom: var(--s-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  pointer-events: none;
}

.xui-toast {
  position: relative;
  overflow: hidden;
  pointer-events: auto;
  max-width: var(--toast-max-w);
  padding: var(--s-2-5) var(--s-3-5);
  border-radius: var(--r-md);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-left: var(--border-accent-w) solid var(--accent);
  box-shadow: var(--shadow-toast);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  font-size: var(--t-small-size);
  color: var(--text-1);
  animation: xui-toast-in var(--d-base) var(--ease-out);
}

.xui-toast.is-leaving { animation: xui-toast-out var(--d-exit) var(--ease-out) forwards; }
.xui-toast.is-success { border-left-color: var(--success); }
.xui-toast.is-warn { border-left-color: var(--warn); }
.xui-toast.is-error { border-left-color: var(--danger); }
.xui-toast.is-info { border-left-color: var(--info); }

.xui-toast-msg {
  flex: 1;
  min-width: 0;
}

.xui-toast-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  color: var(--text-2);
}

.xui-toast.is-success .xui-toast-icon { color: var(--success); }
.xui-toast.is-warn .xui-toast-icon { color: var(--warn); }
.xui-toast.is-error .xui-toast-icon { color: var(--danger); }
.xui-toast.is-info .xui-toast-icon { color: var(--info); }

/* Lifetime meter: a composited bar that drains via transform; JS sets the duration
 * inline and pauses it (animation-play-state) while the pointer rests on the toast. */
.xui-toast-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  opacity: 0.4;
  transform-origin: left center;
  animation: xui-toast-countdown var(--d-slow) linear forwards;
  pointer-events: none;
}

.xui-toast.is-success .xui-toast-progress { background: var(--success); }
.xui-toast.is-warn .xui-toast-progress { background: var(--warn); }
.xui-toast.is-error .xui-toast-progress { background: var(--danger); }
.xui-toast.is-info .xui-toast-progress { background: var(--info); }

/* ---------- 19. Tooltip ----------
 * XUI.ui.initTooltips() upgrades every [data-tooltip] host to a single floating
 * .xui-tooltip node with viewport clamping, edge flipping and transform-origin
 * anchoring. The pure-CSS fallback below only remains for keyboard focus and for
 * consumers who never load the JS layer.
 */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-xs);
  background: var(--bg-elev-4);
  color: var(--text-1);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  font-size: var(--t-micro-size);
  white-space: nowrap;
  pointer-events: none;
  z-index: var(--z-tooltip);
  animation: xui-fade-in var(--d-fast) var(--ease-out);
}

/* Once the JS layer owns hover tooltips, silence the CSS hover pseudo only
 * (focus-visible keeps working for keyboard users). */
html.xui-tooltip-js [data-tooltip]:hover::after {
  content: none;
}

.xui-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  max-width: 280px;
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-xs);
  background: var(--bg-elev-4);
  color: var(--text-1);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  font-size: var(--t-micro-size);
  white-space: nowrap;
  pointer-events: none;
  z-index: var(--z-tooltip);
  opacity: 0;
  transform: scale(0.94);
  transition: opacity var(--d-fast) var(--ease-out), transform var(--d-fast) var(--ease-out);
}

.xui-tooltip.is-open {
  opacity: 1;
  transform: scale(1);
}

/* ---------- 20. Skeleton & Empty State ----------
 * Base surface is flat; the highlight is a composited pseudo-element swept with
 * transform (see xui-skeleton-sweep) so the animation never triggers repaint.
 */
.xui-skeleton {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-sm);
  background: var(--skeleton-a);
}

.xui-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 25%, var(--skeleton-b) 50%, transparent 75%);
  animation: xui-skeleton-sweep var(--d-skeleton) var(--ease) infinite;
}

.xui-empty {
  padding: var(--s-7) var(--s-5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--s-2-5);
  color: var(--text-2);
}

.xui-empty-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--r-md);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------- 21. Skin Swatch Pill ---------- */
.xui-swatch {
  width: 22px;
  height: 22px;
  border-radius: var(--r-pill);
  border: 2px solid transparent;
  padding: 2px;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease);
}

.xui-swatch:hover { transform: scale(1.12); }
.xui-swatch.is-active { border-color: var(--text-1); }

.xui-swatch-dot {
  width: 14px;
  height: 14px;
  border-radius: var(--r-pill);
  display: block;
}

/* ---------- 22. Popover (Anchored Floating Panel) ----------
 * XUI.ui.popover(anchor, opts) floats a single .xui-popover node next to its
 * trigger: viewport clamped, transform-origin anchored to the growth edge, and
 * an interruptible leave driven by the shared afterTransition() helper.
 */
.xui-popover {
  position: fixed;
  min-width: var(--popover-min-w);
  padding: var(--s-3);
  border-radius: var(--r-md);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-menu);
  color: var(--text-1);
  z-index: var(--z-popover);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform-origin: top left;
  transform: translateY(calc(-4px * var(--motion-scale))) scale(0.97);
  transition:
    opacity var(--d-exit) var(--ease-out),
    transform var(--d-exit) var(--ease-out),
    visibility 0s linear var(--d-exit);
}

.xui-popover.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition:
    opacity var(--d-base) var(--ease-out),
    transform var(--d-base) var(--ease-out),
    visibility 0s linear 0s;
}

.xui-popover-title {
  font-size: var(--t-small-size);
  font-weight: var(--t-weight-semibold);
  color: var(--text-1);
  margin-bottom: var(--s-2);
}

.xui-popover-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  color: var(--text-2);
  font-size: var(--t-caption-size);
  line-height: 1.6;
}

.xui-popover-foot {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  margin-top: var(--s-3);
}

/* ---------- 23. Accordion (grid-template-rows fold, single-open optional) ---------- */
.xui-accordion {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg-elev-1);
}

.xui-accordion-item + .xui-accordion-item {
  border-top: 1px solid var(--line);
}

.xui-accordion-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-2-5) var(--s-3);
  border: 0;
  background: transparent;
  color: var(--text-1);
  font-size: var(--t-small-size);
  font-weight: var(--t-weight-medium);
  text-align: left;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease);
}

.xui-accordion-head:hover {
  background: var(--bg-elev-2);
}

.xui-accordion-chevron {
  flex: none;
  display: inline-flex;
  color: var(--text-3);
  transition: transform var(--d-switch) var(--ease-out);
}

.xui-accordion-item.is-open .xui-accordion-chevron {
  transform: rotate(180deg);
}

/* Folded with a composited grid track (0fr -> 1fr) instead of a guessed max-height. */
.xui-accordion-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--d-base) var(--ease-out);
}

.xui-accordion-item.is-open .xui-accordion-panel {
  grid-template-rows: 1fr;
}

.xui-accordion-inner {
  min-height: 0;
  overflow: hidden;
}

.xui-accordion-body {
  padding: var(--s-0) var(--s-3) var(--s-3);
  color: var(--text-2);
  font-size: var(--t-caption-size);
  line-height: 1.65;
}

/* ---------- 24. Combobox (filterable input + floating listbox) ---------- */
.xui-combobox {
  position: relative;
}

.xui-combobox-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + var(--s-1));
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s-1);
  border-radius: var(--r-md);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-menu);
  z-index: var(--z-popover);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(calc(-4px * var(--motion-scale))) scale(0.98);
  transform-origin: top center;
  transition:
    opacity var(--d-exit) var(--ease-out),
    transform var(--d-exit) var(--ease-out),
    visibility 0s linear var(--d-exit);
}

.xui-combobox.is-open .xui-combobox-list {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition:
    opacity var(--d-base) var(--ease-out),
    transform var(--d-base) var(--ease-out),
    visibility 0s linear 0s;
}

.xui-combobox-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: var(--s-1-5) var(--s-2-5);
  border-radius: var(--r-sm);
  color: var(--text-1);
  font-size: var(--t-small-size);
  cursor: pointer;
}

.xui-combobox-opt.is-hidden {
  display: none;
}

.xui-combobox-opt.is-focused,
.xui-combobox-opt:hover {
  background: var(--bg-elev-3);
}

.xui-combobox-opt.is-selected {
  color: var(--accent);
}

.xui-combobox-opt-meta {
  flex: none;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: var(--t-micro-size);
}

/* ---------- 25. Scrubbable Number (drag / keys / dblclick to edit) ---------- */
.xui-scrub {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: var(--bg-elev-2);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: var(--t-caption-size);
  font-variant-numeric: tabular-nums;
  cursor: ew-resize;
  user-select: none;
  touch-action: none;
  transition: background var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}

.xui-scrub:hover {
  background: var(--bg-elev-3);
}

.xui-scrub.is-scrubbing {
  background: var(--accent-soft);
  border-color: var(--accent-ring);
  color: var(--accent-on-soft);
}

.xui-scrub:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

.xui-scrub-input {
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: center;
  outline: none;
}

/* ---------- 26. Hold to Confirm (press-and-hold progress) ---------- */
.xui-hold {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.xui-hold-fill {
  position: absolute;
  inset: 0;
  transform: scaleX(0);
  transform-origin: left center;
  background: currentColor;
  opacity: 0.2;
  pointer-events: none;
  z-index: 0;
}

.xui-hold > *:not(.xui-hold-fill) {
  position: relative;
  z-index: 1;
}

.xui-hold.is-complete {
  border-color: var(--success);
}

/* ---------- 27. Drag Sortable ----------
 * Pointer reordering. The dragged row is lifted out of flow (position: fixed)
 * while a placeholder holds its slot; siblings re-settle with a FLIP transform,
 * so layout never repaints — only transform does (see initSortables).
 */
.xui-sortable {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.xui-sortable-item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev-1);
  color: var(--text-1);
  font-size: var(--t-small-size);
  touch-action: none;
}

.xui-sortable-item:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

.xui-sortable-item.is-dragging {
  z-index: var(--z-drag);
  cursor: grabbing;
  background: var(--bg-elev-2);
  border-color: var(--accent-ring);
  box-shadow: var(--shadow-menu);
}

.xui-sortable-placeholder {
  border-radius: var(--r-sm);
  border: 1px dashed var(--line-strong);
  background: var(--accent-soft);
}

.xui-sort-grip {
  flex: none;
  display: inline-flex;
  color: var(--text-3);
  cursor: grab;
}

/* ---------- 28. Swipe to Dismiss (momentum) ----------
 * The surface slides over a static action strip; past the threshold — or on a
 * fast fling — it commits and leaves, otherwise it springs back. Only transform
 * and opacity animate (see initSwipeables).
 */
.xui-swipe-wrap {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-sm);
}

.xui-swipe-action {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: 0 var(--s-4);
  background: var(--danger);
  color: var(--text-pure);
  font-size: var(--t-small-size);
  font-weight: var(--t-weight-medium);
  pointer-events: none;
}

.xui-swipe-item {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev-1);
  color: var(--text-1);
  font-size: var(--t-small-size);
  touch-action: pan-y;
  user-select: none;
  will-change: transform;
}

.xui-swipe-item:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: calc(-1 * var(--focus-ring-w));
}

/* ---------- 29. Color Picker (popover-embedded HSV) ---------- */
.xui-cpk {
  width: 224px;
  display: flex;
  flex-direction: column;
  gap: var(--s-2-5);
}

.xui-cpk-sv {
  position: relative;
  height: 132px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  cursor: crosshair;
  touch-action: none;
}

.xui-cpk-thumb {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: var(--r-pill);
  border: 2px solid var(--text-pure);
  box-shadow: var(--shadow-sm);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.xui-cpk-hue {
  position: relative;
  height: 12px;
  border-radius: var(--r-pill);
  cursor: pointer;
  touch-action: none;
  background: linear-gradient(to right, red, yellow, lime, cyan, blue, magenta, red);
}

.xui-cpk-hue-thumb {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: var(--r-pill);
  border: 2px solid var(--text-pure);
  box-shadow: var(--shadow-sm);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.xui-cpk-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.xui-cpk-preview {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
}

.xui-cpk-hex {
  width: 100%;
  height: 28px;
  padding: 0 var(--s-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-elev-1);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: var(--t-caption-size);
  text-transform: uppercase;
}

.xui-cpk-hex:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
  border-color: var(--accent-ring);
}

.xui-cpk-presets {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1-5);
}

.xui-cpk-preset {
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: var(--r-xs);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform var(--d-fast) var(--ease);
}

.xui-cpk-preset:hover {
  transform: scale(1.12);
}

.xui-cpk-preset:focus-visible {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}
