/**
 * Tiny Wire — components.css
 * Requires: lib/globals.css (tokens + reset + base)
 *
 * Convention:
 *   .btn-*       buttons         .input         input field
 *   .card        card container  .select        select field
 *   .tag-*       tag             .checkbox      checkbox
 *   .badge       muted badge     .radio         radio
 *   .chip-*      status chip     .switch        toggle switch
 *   .dot-*       status dot      .slider        slider
 *   .alert-*     inline alert    .progress      progress bar
 *   .banner-*    full-width
 */

/* ─── Button ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-6); white-space: nowrap;
  height: var(--size-control-md); padding: 0 var(--space-14);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: var(--text-base);
  font-weight: var(--weight-medium); letter-spacing: var(--tracking-slight);
  cursor: pointer; user-select: none;
  transition:
    background    var(--duration-fast) var(--ease-standard),
    border-color  var(--duration-fast) var(--ease-standard),
    color         var(--duration-fast) var(--ease-standard),
    opacity       var(--duration-fast) var(--ease-standard),
    box-shadow    var(--duration-fast) var(--ease-standard),
    transform     var(--duration-fast) var(--ease-standard);
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { cursor: not-allowed; opacity: 0.45; pointer-events: none; }

.btn-sm { height: var(--size-control-sm); padding: 0 var(--space-10); font-size: var(--text-md); }
.btn-lg { height: var(--size-control-lg); padding: 0 var(--space-20); font-size: var(--text-lg); }

.btn-primary {
  background: var(--text-primary); color: var(--text-inverse);
}
.btn-primary:hover { background: color-mix(in srgb, var(--text-primary) 85%, var(--text-secondary)); }

.btn-secondary {
  background: var(--surface-muted); color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-inset); border-color: var(--border-strong); }

.btn-outline {
  background: transparent; color: var(--text-primary);
  border-color: var(--border);
}
.btn-outline:hover { background: var(--surface-muted); border-color: var(--border-strong); }

.btn-ghost {
  background: transparent; color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--surface-muted); color: var(--text-primary); }

.btn-danger {
  background: var(--danger); color: var(--danger-fg);
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 88%, black); }

.btn-brand {
  background: var(--brand); color: var(--brand-fg);
}
.btn-brand:hover { background: color-mix(in srgb, var(--brand) 88%, black); }

.btn-link {
  background: transparent; color: var(--info); padding: 0;
  height: auto; text-decoration: underline; text-underline-offset: 2px;
  border-radius: var(--radius-xs);
}
.btn-link:hover { color: var(--text-primary); text-decoration-thickness: 2px; }
/* v1.1 — was --text-tertiary (3.85:1, fails AA + looked disabled).
   Switched to --info which carries link semantics and passes contrast. */

.btn-stop {
  display: inline-flex; align-items: center; gap: var(--space-8);
  height: 36px; padding: 0 var(--space-12);
  background: color-mix(in srgb, var(--danger) 7%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent);
  border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: var(--text-base); font-weight: var(--weight-medium);
  color: var(--danger); cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard);
}
.btn-stop:hover { background: color-mix(in srgb, var(--danger) 13%, var(--surface)); }

.btn-rollback {
  height: 26px; padding: 0 var(--space-10);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-family: var(--font-body); font-size: var(--text-md);
  color: var(--text-secondary); cursor: pointer; white-space: nowrap;
  transition: background var(--duration-fast), border-color var(--duration-fast);
}
.btn-rollback:hover { background: var(--surface-muted); border-color: var(--border-dashed); }

/* Icon button — square */
.btn-icon {
  width: var(--size-control-md); height: var(--size-control-md);
  padding: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent;
  transition: background var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast);
}
.btn-icon:hover { background: var(--surface-muted); color: var(--text-primary); }
.btn-icon.btn-icon-outline { border-color: var(--border); }
.btn-icon.btn-sm { width: var(--size-control-sm); height: var(--size-control-sm); }
.btn-icon.btn-lg { width: var(--size-control-lg); height: var(--size-control-lg); }

/* Button group */
.btn-group {
  display: inline-flex; align-items: stretch;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface);
}
.btn-group .btn {
  border-radius: 0; border: 0;
  border-right: 1px solid var(--border-light);
  background: var(--surface); color: var(--text-secondary);
}
.btn-group .btn:last-child { border-right: 0; }
.btn-group .btn:hover { background: var(--surface-muted); color: var(--text-primary); }
.btn-group .btn[aria-pressed="true"],
.btn-group .btn.active { background: var(--surface-muted); color: var(--text-primary); font-weight: var(--weight-semibold); }

/* ─── Input ─────────────────────────────────────────────────────────────── */
.input, .textarea, .select {
  display: block; width: 100%;
  height: var(--size-control-md);
  padding: 0 var(--space-10);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: var(--text-base);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--duration-fast), background var(--duration-fast), box-shadow var(--duration-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .textarea:focus, .select:focus { border-color: var(--brand); box-shadow: var(--shadow-focus); }
.input:disabled, .textarea:disabled, .select:disabled {
  background: var(--surface-muted); color: var(--text-disabled);
  cursor: not-allowed; opacity: 1;
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select[aria-invalid="true"] {
  border-color: var(--danger);
}
.input[aria-invalid="true"]:focus, .textarea[aria-invalid="true"]:focus, .select[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent);
}

.input-sm { height: var(--size-control-sm); font-size: var(--text-md); padding: 0 var(--space-8); }
.input-lg { height: var(--size-control-lg); font-size: var(--text-lg); padding: 0 var(--space-12); }

.textarea {
  height: auto; min-height: 72px;
  padding: var(--space-8) var(--space-10);
  line-height: var(--leading-compact); resize: vertical;
}

.select {
  cursor: pointer; padding-right: var(--space-24);
  /* warm-500 mid-neutral — legible on both light and dark inputs (replaced a
     stale hardcoded grey that read low-contrast in dark mode). */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%23A89E99' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--space-10) center;
  appearance: none; -webkit-appearance: none;
}

.input-group {
  display: flex; align-items: stretch; width: 100%;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.input-group:focus-within { border-color: var(--brand); box-shadow: var(--shadow-focus); }
.input-group .input { border: 0; height: calc(var(--size-control-md) - 2px); background: transparent; }
.input-group .input:focus { box-shadow: none; }
.input-group-addon {
  display: flex; align-items: center; gap: var(--space-6);
  padding: 0 var(--space-10);
  color: var(--text-tertiary); font-size: var(--text-md);
  background: var(--surface-subtle);
  border-right: 1px solid var(--border);
}
.input-group-addon:last-child { border-right: 0; border-left: 1px solid var(--border); }

/* ─── Label, helper, hint ───────────────────────────────────────────────── */
.label {
  display: block; font-size: var(--text-md); font-weight: var(--weight-medium);
  color: var(--text-secondary); margin-bottom: var(--space-5);
}
.label-required::after {
  content: '*'; color: var(--danger); margin-left: 2px;
}
.helper {
  font-size: var(--text-md); color: var(--text-tertiary);
  line-height: var(--leading-compact); margin-top: var(--space-5);
}
.field-error {
  font-size: var(--text-md); color: var(--danger);
  line-height: var(--leading-compact); margin-top: var(--space-5);
}
.field-group { display: flex; flex-direction: column; gap: 0; }

/* ─── Checkbox & Radio ──────────────────────────────────────────────────── */
.checkbox, .radio {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  cursor: pointer; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--duration-fast), border-color var(--duration-fast);
  position: relative;
}
.checkbox { border-radius: var(--radius-xs); }
.radio    { border-radius: var(--radius-full); }
.checkbox:hover, .radio:hover { border-color: var(--text-tertiary); }

.checkbox:checked, .radio:checked {
  background: var(--brand); border-color: var(--brand);
}
.checkbox:checked::after {
  content: ''; width: 10px; height: 10px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10' fill='none'%3E%3Cpath d='M2 5.5L4 7.5L8 2.5' stroke='white' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
}
.radio:checked::after {
  content: ''; width: 6px; height: 6px; border-radius: var(--radius-full); background: var(--brand-fg);
}
/* v1.1 — indeterminate state (e.g. "some, not all" multi-select header). */
.checkbox:indeterminate {
  background: var(--brand); border-color: var(--brand);
}
.checkbox:indeterminate::after {
  content: ''; width: 8px; height: 2px; background: var(--brand-fg); border-radius: 1px;
}

.checkbox:disabled, .radio:disabled {
  opacity: 0.45; cursor: not-allowed; background: var(--surface-muted);
}
.checkbox[aria-invalid="true"], .radio[aria-invalid="true"] { border-color: var(--danger); }

.field-check {
  display: inline-flex; align-items: center; gap: var(--space-8); cursor: pointer;
}
.field-check-label { font-size: var(--text-base); color: var(--text-primary); }

/* ─── Switch ────────────────────────────────────────────────────────────── */
.switch {
  appearance: none; -webkit-appearance: none;
  width: 32px; height: 18px; border-radius: var(--radius-full);
  background: var(--border); position: relative; cursor: pointer; flex-shrink: 0;
  border: 0;
  transition: background var(--duration-fast);
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: var(--radius-full);
  background: var(--surface); box-shadow: var(--shadow-toggle);
  transition: transform var(--duration-fast) var(--ease-spring);
}
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(14px); }
.switch:disabled { opacity: 0.45; cursor: not-allowed; }
/* v1.1 — the global :focus-visible box-shadow was being clipped by the
   pill's own background; switch now carries its own offset focus ring. */
.switch:focus-visible {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 5px var(--ring);
}

/* ─── Slider ────────────────────────────────────────────────────────────── */
.slider {
  width: 100%; height: 5px; appearance: none;
  background: var(--border); border-radius: var(--radius-full);
  outline: none; cursor: pointer;
}
.slider::-webkit-slider-thumb {
  appearance: none; width: 16px; height: 16px; border-radius: var(--radius-full);
  background: var(--text-primary); cursor: grab; box-shadow: var(--shadow-toggle);
  border: 2px solid var(--surface);
}
.slider::-webkit-slider-thumb:active { cursor: grabbing; }
.slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: var(--radius-full);
  background: var(--text-primary); cursor: grab; box-shadow: var(--shadow-toggle);
  border: 2px solid var(--surface);
}
.slider:disabled { opacity: 0.45; cursor: not-allowed; }
/* v1.1 — focus ring on the thumb; both engines need their own selector. */
.slider:focus-visible { box-shadow: none; }
.slider:focus-visible::-webkit-slider-thumb {
  box-shadow: var(--shadow-toggle), 0 0 0 4px var(--ring);
}
.slider:focus-visible::-moz-range-thumb {
  box-shadow: var(--shadow-toggle), 0 0 0 4px var(--ring);
}
.slider-wrap { display: flex; align-items: center; gap: var(--space-12); }
.slider-val {
  font-size: var(--text-xl); font-weight: var(--weight-semibold);
  font-family: var(--font-heading); color: var(--text-primary);
  letter-spacing: var(--tracking-snug); min-width: 30px; text-align: right;
  font-feature-settings: var(--numeric-tabular); font-variant-numeric: tabular-nums lining-nums;
}

/* ─── Tag ───────────────────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: var(--space-4);
  font-size: var(--text-2xs); font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps); text-transform: uppercase;
  padding: 2px 6px; border-radius: var(--radius-xs);
  background: var(--surface-muted); color: var(--text-secondary);
  border: 1px solid transparent;
}
.tag-danger { background: var(--danger-light); color: var(--danger); }
/* v1.5 — green is now reserved for trust states; the success tag is green via
   --success. .tag-brand kept as a back-compat alias (was always success-tinted). */
.tag-success,
.tag-brand  { background: var(--success-light); color: var(--success-dark); }
.tag-info   { background: var(--info-light); color: var(--info); }
.tag-warn   { background: var(--warning-light); color: var(--warning); }
.tag-accent { background: var(--accent-light); color: var(--accent); }

.badge {
  display: inline-block; font-size: var(--text-2xs);
  font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; color: var(--text-tertiary);
  background: var(--surface-muted); border: 1px solid var(--border);
  border-radius: var(--radius-xs); padding: 1px 5px; vertical-align: middle;
}

/* ─── Status chip ───────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: var(--space-6);
  height: 26px; padding: 0 var(--space-10); border-radius: var(--radius-full);
  font-size: var(--text-md); font-weight: var(--weight-medium);
  border: 1px solid transparent;
  background: var(--surface-muted); color: var(--text-secondary);
}
.chip-dot {
  width: 6px; height: 6px; border-radius: var(--radius-full);
  background: currentColor; flex-shrink: 0;
}
.chip-ok       { background: color-mix(in srgb, var(--success) 10%, transparent); border-color: color-mix(in srgb, var(--success) 25%, transparent); color: var(--success); }
.chip-warn     { background: color-mix(in srgb, var(--warning) 10%, transparent); border-color: color-mix(in srgb, var(--warning) 25%, transparent); color: var(--warning); }
.chip-critical { background: color-mix(in srgb, var(--danger)  10%, transparent); border-color: color-mix(in srgb, var(--danger)  25%, transparent); color: var(--danger); }
.chip-info     { background: color-mix(in srgb, var(--info)    10%, transparent); border-color: color-mix(in srgb, var(--info)    25%, transparent); color: var(--info); }
.chip-stopped  { background: var(--surface-muted); border-color: var(--border); color: var(--text-secondary); }

/* ─── Dots ──────────────────────────────────────────────────────────────── */
.dot {
  width: var(--size-status-dot-base);
  height: var(--size-status-dot-base);
  border-radius: var(--radius-full);
  display: inline-block; flex-shrink: 0;
}
.dot-green  { background: var(--success); }
/* v1.1 — .dot-warn added; .dot-amber rerouted to its actual chart amber.
   The old .dot-amber pointed at the warning brown — a misleading name. */
.dot-warn   { background: var(--warning); }
.dot-amber  { background: var(--chart-amber); }
.dot-red    { background: var(--danger); }
.dot-blue   { background: var(--info); }
.dot-muted  { background: var(--text-tertiary); }

.monitoring-dot {
  position: relative; width: 7px; height: 7px;
  border-radius: var(--radius-full); background: var(--success); flex-shrink: 0;
  animation: pulse-dot 2.8s ease-in-out infinite;
}
.monitoring-dot::after {
  content: ''; position: absolute; inset: 0;
  border-radius: var(--radius-full);
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--success) 55%, transparent);
  animation: ripple-ring 2.8s ease-in-out infinite;
}

/* ─── Avatar ────────────────────────────────────────────────────────────── */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--size-avatar-md); height: var(--size-avatar-md);
  border-radius: var(--radius-full);
  background: var(--surface-muted); color: var(--text-secondary);
  font-size: var(--text-md); font-weight: var(--weight-semibold);
  overflow: hidden; flex-shrink: 0; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: var(--size-avatar-sm); height: var(--size-avatar-sm); font-size: var(--text-xs); }
.avatar-lg { width: var(--size-avatar-lg); height: var(--size-avatar-lg); font-size: var(--text-base); }
.avatar-xl { width: 48px; height: 48px; font-size: var(--text-lg); }

.avatar-group { display: inline-flex; }
.avatar-group .avatar {
  border: 2px solid var(--surface); margin-left: -8px;
}
.avatar-group .avatar:first-child { margin-left: 0; }

/* ─── Separator ─────────────────────────────────────────────────────────── */
.separator {
  border: 0; height: 1px; background: var(--border-light); width: 100%;
}
.separator-strong { background: var(--border); }
.separator-v { width: 1px; height: 16px; background: var(--border); display: inline-block; }

/* ─── Skeleton ──────────────────────────────────────────────────────────── */
.skeleton {
  display: block; background:
    linear-gradient(90deg,
      var(--surface-muted) 0%,
      var(--surface-inset) 50%,
      var(--surface-muted) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.6s linear infinite;
  border-radius: var(--radius-xs);
}

/* ─── Progress ──────────────────────────────────────────────────────────── */
.progress {
  display: block; width: 100%; height: 6px;
  background: var(--surface-muted); border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-bar {
  display: block; height: 100%;
  background: var(--brand); border-radius: var(--radius-full);
  transition: width var(--duration-moderate) var(--ease-spring);
}
.progress-bar-danger { background: var(--danger); }
.progress-bar-warning{ background: var(--warning); }

/* ─── Spinner ───────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--brand);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.spinner-sm { width: 12px; height: 12px; border-width: 1.5px; }
.spinner-lg { width: 22px; height: 22px; border-width: 2.5px; }

/* ─── Card ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--space-16);
}
.card-disabled { opacity: 0.45; pointer-events: none; user-select: none; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-12);
}
.card-title {
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  color: var(--text-primary);
  display: flex; align-items: center; gap: var(--space-8);
}
.card-desc {
  font-size: var(--text-md); color: var(--text-tertiary);
  line-height: var(--leading-compact);
}
.card-footer {
  margin-top: var(--space-12);
  padding-top: var(--space-12);
  border-top: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: flex-end;
  gap: var(--space-8);
}
.section-heading {
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  color: var(--text-primary); margin-bottom: var(--space-14);
  display: flex; align-items: center; gap: var(--space-8);
}

/* ─── Alert ─────────────────────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: var(--space-10);
  padding: var(--space-10) var(--space-12); border-radius: var(--radius-sm);
  font-size: var(--text-md); line-height: var(--leading-compact);
  border: 1px solid transparent;
}
.alert-icon { flex-shrink: 0; margin-top: 1px; }
.alert-body { flex: 1; min-width: 0; }
.alert-title {
  font-weight: var(--weight-semibold); margin-bottom: 2px;
}
.alert-danger  { color: var(--danger);  background: color-mix(in srgb, var(--danger)  8%, transparent); border-color: color-mix(in srgb, var(--danger)  22%, transparent); }
.alert-warn    { color: var(--warning); background: color-mix(in srgb, var(--warning) 8%, transparent); border-color: color-mix(in srgb, var(--warning) 22%, transparent); }
.alert-success,
.alert-brand   { color: var(--success-dark); background: color-mix(in srgb, var(--success) 8%, transparent); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.alert-info    { color: var(--info);    background: color-mix(in srgb, var(--info)    8%, transparent); border-color: color-mix(in srgb, var(--info)    22%, transparent); }

/* ─── Banner ────────────────────────────────────────────────────────────── */
.banner {
  display: flex; align-items: center; gap: var(--space-12);
  padding: var(--space-8) var(--space-16);
  font-size: var(--text-md); font-weight: var(--weight-medium);
  border-radius: var(--radius-sm);
  border-top: 1px solid transparent; border-bottom: 1px solid transparent;
}
.banner-danger {
  background: color-mix(in srgb, var(--danger) 7%, transparent);
  border-color: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger);
}
.banner-success,
.banner-brand {
  background: color-mix(in srgb, var(--success) 8%, transparent);
  border-color: color-mix(in srgb, var(--success) 22%, transparent); color: var(--success-dark);
}
.banner-info {
  background: color-mix(in srgb, var(--info) 7%, transparent);
  border-color: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info);
}
/* v1.1 — added .banner-warn for parity with .alert-warn and .chip-warn. */
.banner-warn {
  background: color-mix(in srgb, var(--warning) 8%, transparent);
  border-color: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning);
}
.banner-dot {
  width: 7px; height: 7px; border-radius: var(--radius-full);
  background: currentColor; flex-shrink: 0;
  animation: pulse-dot 1.4s ease-in-out infinite;
}

/* ─── Tooltip ───────────────────────────────────────────────────────────── */
.tooltip {
  position: absolute;
  background: var(--text-primary); color: var(--text-inverse);
  font-family: var(--font-body); font-size: var(--text-sm);
  font-weight: var(--weight-semibold); white-space: nowrap;
  padding: 5px 9px; border-radius: var(--radius-sm);
  pointer-events: none; opacity: 0;
  transition: opacity 0.12s ease;
  z-index: var(--z-tooltip);
}
.tooltip[data-open="true"] { opacity: 1; transition-delay: 200ms; }
.tooltip::before {
  content: ''; position: absolute;
  border: 5px solid transparent;
}
.tooltip[data-side="top"]::before    { top: 100%; left: 50%; transform: translateX(-50%); border-top-color: var(--text-primary); }
.tooltip[data-side="bottom"]::before { bottom: 100%; left: 50%; transform: translateX(-50%); border-bottom-color: var(--text-primary); }
.tooltip[data-side="left"]::before   { left: 100%; top: 50%; transform: translateY(-50%); border-left-color: var(--text-primary); }
.tooltip[data-side="right"]::before  { right: 100%; top: 50%; transform: translateY(-50%); border-right-color: var(--text-primary); }

/* Trigger wrapper for click-and-hover demos */
.tooltip-wrap { position: relative; display: inline-flex; }
.tooltip-wrap:hover > .tooltip { opacity: 1; transition-delay: 400ms; }

/* ─── Popover ───────────────────────────────────────────────────────────── */
.popover {
  position: absolute;
  background: var(--surface); border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md); box-shadow: var(--shadow-dropdown);
  padding: var(--space-12); min-width: 200px;
  z-index: var(--z-dropdown);
  animation: filterIn var(--duration-base) var(--ease-spring) both;
}
.popover-header {
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  color: var(--text-primary); margin-bottom: var(--space-8);
}

/* ─── Dropdown menu ─────────────────────────────────────────────────────── */
.menu {
  background: var(--surface); border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md); box-shadow: var(--shadow-dropdown);
  padding: var(--space-4); min-width: 180px;
  z-index: var(--z-dropdown);
}
.menu-item {
  display: flex; align-items: center; gap: var(--space-8);
  padding: var(--space-6) var(--space-8);
  font-size: var(--text-base); color: var(--text-primary);
  border-radius: var(--radius-xs); cursor: pointer;
  width: 100%; text-align: left;
}
.menu-item:hover, .menu-item:focus { background: var(--surface-muted); outline: none; }
.menu-item-icon { color: var(--text-tertiary); flex-shrink: 0; }
.menu-item-shortcut {
  margin-left: auto; font-size: var(--text-xs); color: var(--text-tertiary);
  font-family: var(--font-mono);
}
.menu-item-danger { color: var(--danger); }
.menu-item-danger:hover { background: var(--danger-light); }
.menu-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--text-tertiary); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; padding: var(--space-6) var(--space-8) var(--space-4);
}
.menu-separator {
  height: 1px; background: var(--border-light); margin: var(--space-4) 0;
}

/* ─── Dialog (modal) ────────────────────────────────────────────────────── */
.dialog-overlay {
  position: fixed; inset: 0;
  background: color-mix(in srgb, var(--text-primary) 60%, transparent);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  z-index: var(--z-overlay);
  animation: fadeIn var(--duration-base) var(--ease-standard) both;
}
.dialog {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface); border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-modal);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 64px); overflow: auto;
  z-index: var(--z-modal);
  animation: modalIn var(--duration-moderate) var(--ease-spring) both;
}
.dialog-header {
  padding: var(--space-20) var(--space-20) var(--space-12);
  border-bottom: 1px solid var(--border-light);
}
.dialog-title {
  font-family: var(--font-heading); font-size: var(--text-xl);
  font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug);
  color: var(--text-primary); margin-bottom: var(--space-4);
}
.dialog-desc {
  font-size: var(--text-md); color: var(--text-tertiary);
  line-height: var(--leading-compact);
}
.dialog-body { padding: var(--space-16) var(--space-20); }
.dialog-footer {
  padding: var(--space-12) var(--space-20);
  border-top: 1px solid var(--border-light);
  display: flex; gap: var(--space-8); justify-content: flex-end;
}
.dialog-close {
  position: absolute; top: var(--space-12); right: var(--space-12);
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); cursor: pointer;
}
.dialog-close:hover { background: var(--surface-muted); color: var(--text-primary); }

/* ─── Sheet (side drawer) ───────────────────────────────────────────────── */
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(380px, 90vw);
  background: var(--surface); border-left: 1px solid var(--border-hairline);
  box-shadow: var(--shadow-modal);
  z-index: var(--z-modal);
  display: flex; flex-direction: column;
  animation: sheetIn var(--duration-moderate) var(--ease-spring) both;
}
@keyframes sheetIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.sheet-header {
  padding: var(--space-20) var(--space-20) var(--space-12);
  border-bottom: 1px solid var(--border-light);
}
.sheet-body { padding: var(--space-16) var(--space-20); flex: 1; overflow: auto; }
.sheet-footer {
  padding: var(--space-12) var(--space-20);
  border-top: 1px solid var(--border-light);
  display: flex; gap: var(--space-8); justify-content: flex-end;
}

/* ─── Tabs ──────────────────────────────────────────────────────────────── */
.tabs-list {
  display: flex; align-items: stretch; gap: var(--space-2);
  border-bottom: 1px solid var(--border-light);
}
.tab {
  display: inline-flex; align-items: center; gap: var(--space-6);
  padding: var(--space-8) var(--space-12);
  font-size: var(--text-md); font-weight: var(--weight-medium);
  color: var(--text-tertiary); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--duration-fast), border-color var(--duration-fast);
}
.tab:hover { color: var(--text-secondary); }
.tab[aria-selected="true"], .tab.active {
  color: var(--text-primary); border-bottom-color: var(--text-primary);
}
.tab:disabled, .tab[aria-disabled="true"] {
  color: var(--text-disabled); cursor: not-allowed; pointer-events: none;
}
.tab-panel { padding: var(--space-16) 0; }

/* Pill tabs variant */
.tabs-list-pill {
  display: inline-flex; background: var(--surface-muted);
  border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 2px; gap: 0;
}
.tabs-list-pill .tab {
  padding: var(--space-5) var(--space-12); border: 0;
  border-radius: var(--radius-xs); margin: 0;
}
.tabs-list-pill .tab[aria-selected="true"], .tabs-list-pill .tab.active {
  background: var(--surface); color: var(--text-primary);
  box-shadow: var(--shadow-toggle);
}

/* ─── Accordion ─────────────────────────────────────────────────────────── */
.accordion {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); overflow: hidden;
}
.accordion-item { border-bottom: 1px solid var(--border-light); }
.accordion-item:last-child { border-bottom: 0; }
.accordion-trigger {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: var(--space-12) var(--space-16);
  font-size: var(--text-base); font-weight: var(--weight-medium);
  color: var(--text-primary); cursor: pointer;
  background: transparent; border: 0; text-align: left;
}
.accordion-trigger:hover { background: var(--surface-muted); }
.accordion-trigger-icon {
  color: var(--text-tertiary); transition: transform var(--duration-fast) var(--ease-spring);
}
.accordion-item[data-state="open"] .accordion-trigger-icon { transform: rotate(180deg); }
.accordion-content {
  padding: 0 var(--space-16) var(--space-12);
  font-size: var(--text-md); color: var(--text-secondary);
  line-height: var(--leading-normal);
}
.accordion-item[data-state="closed"] .accordion-content { display: none; }

/* ─── Breadcrumb ────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: var(--space-6);
  font-size: var(--text-md);
  flex-wrap: wrap;
}
.breadcrumb-item { color: var(--text-tertiary); }
.breadcrumb-item:hover { color: var(--text-secondary); }
.breadcrumb-item[aria-current="page"] {
  color: var(--text-primary); font-weight: var(--weight-medium);
}
.breadcrumb-sep { color: var(--text-tertiary); user-select: none; }

/* ─── Pagination ────────────────────────────────────────────────────────── */
.pagination {
  display: inline-flex; align-items: center; gap: var(--space-4);
}
.pagination .btn-icon { width: 28px; height: 28px; }
.pagination-item {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px; padding: 0 8px;
  border-radius: var(--radius-xs);
  font-size: var(--text-md); font-weight: var(--weight-medium);
  font-feature-settings: var(--numeric-tabular); font-variant-numeric: tabular-nums lining-nums;
  color: var(--text-secondary); cursor: pointer;
  border: 1px solid transparent;
}
.pagination-item:hover { background: var(--surface-muted); }
.pagination-item[aria-current="page"], .pagination-item.active {
  background: var(--surface); border-color: var(--border);
  color: var(--text-primary);
}
.pagination-item:disabled, .pagination-item[aria-disabled="true"] {
  color: var(--text-disabled); cursor: not-allowed; pointer-events: none;
}
.pagination-ellipsis { color: var(--text-tertiary); padding: 0 4px; }

/* ─── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  display: flex; align-items: flex-start; gap: var(--space-10);
  padding: var(--space-12) var(--space-14);
  background: var(--surface); border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md); box-shadow: var(--shadow-modal);
  min-width: 280px; max-width: 380px;
  animation: toastIn 0.32s var(--ease-spring) both;
}
.toast-icon { flex-shrink: 0; margin-top: 1px; color: var(--success); }
.toast-danger .toast-icon  { color: var(--danger); }
.toast-warn .toast-icon    { color: var(--warning); }
.toast-info .toast-icon    { color: var(--info); }
.toast-body { flex: 1; min-width: 0; }
.toast-title {
  font-size: var(--text-base); font-weight: var(--weight-semibold);
  color: var(--text-primary); margin-bottom: 2px;
}
.toast-desc { font-size: var(--text-md); color: var(--text-tertiary); line-height: var(--leading-compact); }
.toast-close {
  color: var(--text-tertiary); padding: 0; width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.toast-close:hover { color: var(--text-primary); }

/* ─── Command (cmd+k) ───────────────────────────────────────────────────── */
.command {
  background: var(--surface); border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md); box-shadow: var(--shadow-modal);
  width: 480px; max-width: 90vw; overflow: hidden;
  display: flex; flex-direction: column;
}
.command-input-wrap {
  display: flex; align-items: center; gap: var(--space-10);
  padding: var(--space-12) var(--space-14);
  border-bottom: 1px solid var(--border-light);
}
.command-input {
  flex: 1; border: 0; outline: none; background: transparent;
  font-size: var(--text-lg); color: var(--text-primary);
  font-family: var(--font-body);
}
.command-input::placeholder { color: var(--text-tertiary); }
.command-list { max-height: 320px; overflow-y: auto; padding: var(--space-4); }
.command-group-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--text-tertiary); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; padding: var(--space-8) var(--space-8) var(--space-4);
}

/* ─── Table ─────────────────────────────────────────────────────────────── */
.table {
  width: 100%; border-collapse: collapse;
  font-size: var(--text-md);
}
.table thead tr { border-bottom: 1px solid var(--border); }
.table th {
  text-align: left; padding: var(--space-8);
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  color: var(--text-tertiary); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; white-space: nowrap;
  background: transparent;
}
.table tbody tr { border-bottom: 1px solid var(--border-light); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-subtle); }
.table td {
  padding: var(--space-10) var(--space-8); vertical-align: middle;
  color: var(--text-secondary);
}
.table td strong, .table td.td-primary { color: var(--text-primary); font-weight: var(--weight-medium); }
.table .td-num { font-feature-settings: var(--numeric-tabular); font-variant-numeric: tabular-nums lining-nums; text-align: right; }
.table .td-actions { text-align: right; white-space: nowrap; }
.table-bordered {
  border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden;
}
.table-bordered th { background: var(--surface-subtle); }

/* ─── Sidebar (app) ─────────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  width: 240px; height: 100%;
}
.sidebar-header {
  padding: var(--space-16) var(--space-16) var(--space-12);
  border-bottom: 1px solid var(--border-light);
}
.sidebar-group { padding: var(--space-12) var(--space-8); }
.sidebar-group-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--text-tertiary); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; padding: 0 var(--space-8) var(--space-6);
}
.sidebar-link {
  display: flex; align-items: center; gap: var(--space-10);
  padding: var(--space-6) var(--space-10);
  font-size: var(--text-md); color: var(--text-secondary);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
}
.sidebar-link:hover { background: var(--surface-muted); color: var(--text-primary); }
.sidebar-link.active {
  background: var(--surface-muted); color: var(--text-primary);
  font-weight: var(--weight-medium);
}
.sidebar-link-icon { color: var(--text-tertiary); flex-shrink: 0; width: 16px; height: 16px; }
.sidebar-link.active .sidebar-link-icon { color: var(--text-primary); }

/* Rail (collapsed) — icon-only sidebar at --sidebar-w. Reuses every .sidebar* rule;
   hide labels, center icons. Add .sidebar--rail to .sidebar. */
.sidebar--rail { width: var(--sidebar-w); }
.sidebar--rail .sidebar-header { display: flex; align-items: center; justify-content: center; padding: var(--space-12) var(--space-8); }
.sidebar--rail .sidebar-group { display: flex; flex-direction: column; align-items: center; gap: var(--space-6); }
.sidebar--rail .sidebar-link { justify-content: center; gap: 0; padding: var(--space-10); width: 100%; }
.sidebar--rail .sidebar-link-label { display: none; }
.sidebar--rail .sidebar-link-icon { width: 20px; height: 20px; }

/* ─── Status bar (operational) ──────────────────────────────────────────── */
.status-bar {
  display: flex; align-items: center; gap: var(--space-16);
  padding: var(--space-8) var(--space-16); flex-shrink: 0;
}
.status-bar-rule { width: 1px; height: 16px; background: var(--border); flex-shrink: 0; }
.status-stat { display: flex; align-items: center; gap: var(--space-6); }
.status-stat-label { font-size: var(--text-md); color: var(--text-tertiary); }
.status-stat-value {
  display: inline-flex; align-items: center; gap: var(--space-5);
  font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--text-primary);
  font-feature-settings: var(--numeric-tabular); font-variant-numeric: tabular-nums lining-nums;
}
.status-stat-context { font-size: var(--text-md); color: var(--text-tertiary); }

/* ─── Empty state ───────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--space-48) var(--space-24);
  text-align: center; gap: var(--space-8);
}
.empty-state-icon {
  width: 48px; height: 48px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-muted); border-radius: var(--radius-full);
  color: var(--text-tertiary); margin-bottom: var(--space-8);
}
.empty-state-title {
  font-family: var(--font-heading); font-size: var(--text-lg);
  font-weight: var(--weight-semibold); color: var(--text-primary);
  letter-spacing: var(--tracking-snug);
}
.empty-state-desc {
  font-size: var(--text-md); color: var(--text-tertiary);
  max-width: 320px; line-height: var(--leading-compact);
}
.empty-state-actions {
  display: flex; gap: var(--space-8); margin-top: var(--space-12);
}

/* ─── KBD ───────────────────────────────────────────────────────────────── */
kbd, .kbd {
  display: inline-flex; align-items: center; justify-content: center;
  height: 18px; min-width: 18px; padding: 0 4px;
  font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--text-secondary); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  box-shadow: 0 1px 0 var(--border-light);
}
