/* ═══════════════════════════════════════════════════════════════════
   components.css — canonical UI primitives. Loads after tokens.css,
   before page sheets.

   Rules of the layer:
   - New UI uses these classes instead of inventing page-scoped variants
     (the codebase has 100+ *btn* classes; that number only goes down).
   - Everything references tokens.css — no raw hex values here.
   - Logical properties only (margin-inline-*, text-align: start) so RTL
     is correct by construction.
   - Buttons: .btn-primary / .btn-secondary / .btn-danger / .btn-ghost,
     sized with .btn-sm, iconified with .btn-icon.
   - New primitives are ui-prefixed (.ui-input, .ui-card, .ui-badge,
     .ui-empty, .ui-skeleton) to avoid colliding with legacy markup.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Buttons ──
   The canonical trio (.btn-primary / .btn-secondary / .btn-danger) is
   defined in style.css for cascade-order compatibility with legacy
   overrides; it moves here once style.css is dismembered. This sheet
   adds the missing variant and modifiers. */
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.25rem;
  border-radius: 10px;
  padding: 0.5rem 0.875rem;
  border: 1px solid transparent;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  background: transparent;
  color: var(--muted);
}

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

.btn-ghost:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 82%, var(--text));
  outline-offset: 2px;
}

.btn-ghost:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

/* Size / shape modifiers */
.btn-sm {
  min-height: 1.875rem;
  padding: 0.3125rem 0.625rem;
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
}

.btn-icon {
  padding: 0.5rem;
  gap: 0;
}

.btn-icon.btn-sm {
  padding: 0.3125rem;
}

/* ── Text inputs / selects / textareas ── */
.ui-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 2.75rem;
  border-radius: 10px;
  border: 1px solid var(--input-b);
  background: var(--input-bg);
  color: var(--text);
  padding: 0.625rem 0.9rem;
  font-size: var(--text-md);
  font-family: inherit;
  line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s;
}

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

.ui-input:focus-visible {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 78%, white 22%);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

.ui-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ui-input[aria-invalid="true"] {
  border-color: var(--danger);
}

textarea.ui-input {
  min-height: 8.5rem;
  line-height: 1.5;
  resize: vertical;
}

.ui-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  margin-block-end: var(--space-2);
}

.ui-hint {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-block-start: var(--space-1);
}

.ui-error {
  font-size: var(--text-xs);
  color: var(--danger);
  margin-block-start: var(--space-1);
}

/* ── Cards ── */
.ui-card {
  background: var(--card);
  border: 1px solid var(--card-b);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.ui-card--raised {
  box-shadow: var(--shadow-md);
}

/* ── Badges ── */
.ui-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.6;
  background: var(--btn-hover);
  color: var(--muted);
}

.ui-badge--ok     { background: var(--ok-soft);     color: var(--ok); }
.ui-badge--warn   { background: var(--warn-soft);   color: var(--warn); }
.ui-badge--danger { background: var(--danger-soft); color: var(--danger); }
.ui-badge--info   { background: var(--info-soft);   color: var(--info); }
.ui-badge--accent { background: var(--accent-soft); color: var(--accent); }

/* ── Empty state ── */
.ui-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-10) var(--space-5);
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--surface-b);
  border-radius: var(--radius-lg);
}

.ui-empty-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text);
}

/* ── Loading skeleton ── */
.ui-skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--surface-b) 25%,
    color-mix(in srgb, var(--surface-b) 55%, var(--surface)) 50%,
    var(--surface-b) 75%
  );
  background-size: 200% 100%;
  animation: ui-skeleton-shimmer 1.4s ease-in-out infinite;
  color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

@keyframes ui-skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ui-skeleton { animation: none; }
}
