/**
 * Theme T&B — UI component library.
 *
 * @package Theme_TB
 * @since 1.0.0
 */

/* Buttons */
.tb-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--tb-touch-min);
  padding: 0.65rem 1.15rem;
  border-radius: var(--tb-radius-md);
  border: 1px solid transparent;
  font-family: var(--tb-font-sans);
  font-size: var(--tb-text-sm);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--tb-transition), color var(--tb-transition), border-color var(--tb-transition), box-shadow var(--tb-transition), transform var(--tb-transition);
}

.tb-button:focus-visible {
  outline: 2px solid var(--tb-color-focus);
  outline-offset: 2px;
}

.tb-button:disabled,
.tb-button.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.tb-button--primary {
  background: linear-gradient(135deg, var(--tb-color-primary), var(--tb-color-primary-light));
  color: var(--tb-color-text-inverse);
  box-shadow: var(--tb-shadow-low);
}

.tb-button--primary:hover,
.tb-button--primary:focus {
  background: var(--tb-color-primary-dark);
  color: var(--tb-color-text-inverse);
  box-shadow: var(--tb-shadow-md);
}

.tb-button--secondary {
  background: var(--tb-color-surface);
  color: var(--tb-color-primary);
  border-color: var(--tb-color-border-strong);
}

.tb-button--outline {
  background: transparent;
  color: var(--tb-color-primary);
  border-color: var(--tb-color-primary);
}

.tb-button--ghost {
  background: transparent;
  color: var(--tb-color-text);
  border-color: transparent;
}

.tb-button--ghost:hover {
  background: var(--tb-color-surface);
}

.tb-button--success { background: var(--tb-color-success); color: #fff; }
.tb-button--warning { background: var(--tb-color-warning); color: #0f172a; }
.tb-button--danger { background: var(--tb-color-danger); color: #fff; }

.tb-button--icon {
  width: var(--tb-touch-min);
  height: var(--tb-touch-min);
  padding: 0;
  border-radius: var(--tb-radius-pill);
}

.tb-button--loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.tb-button--loading::after {
  content: "";
  position: absolute;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: tb-spin 0.7s linear infinite;
}

@keyframes tb-spin {
  to { transform: rotate(360deg); }
}

/* Forms */
.tb-field {
  display: flex;
  flex-direction: column;
  gap: var(--tb-space-xs);
  margin-bottom: var(--tb-space-md);
}

.tb-field__label {
  font-size: var(--tb-text-sm);
  font-weight: 600;
  color: var(--tb-color-text);
}

.tb-input,
.tb-select,
.tb-textarea {
  width: 100%;
  min-height: var(--tb-touch-min);
  padding: 0.75rem 1rem;
  border: 1px solid var(--tb-color-border);
  border-radius: var(--tb-radius-md);
  background: var(--tb-color-bg);
  color: var(--tb-color-text);
  font-family: inherit;
  font-size: var(--tb-text-base);
  transition: border-color var(--tb-transition), box-shadow var(--tb-transition);
}

.tb-input:focus,
.tb-select:focus,
.tb-textarea:focus {
  outline: none;
  border-color: var(--tb-color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.tb-checkbox,
.tb-radio {
  display: flex;
  align-items: center;
  gap: var(--tb-space-sm);
  min-height: var(--tb-touch-min);
}

.tb-toggle {
  position: relative;
  width: 48px;
  height: 26px;
  background: var(--tb-color-border);
  border-radius: var(--tb-radius-pill);
  cursor: pointer;
  transition: background var(--tb-transition);
}

.tb-toggle.is-on {
  background: var(--tb-color-primary);
}

/* Alerts */
.tb-alert {
  padding: var(--tb-space-md);
  border-radius: var(--tb-radius-md);
  border: 1px solid var(--tb-color-border);
  margin-bottom: var(--tb-space-md);
}

.tb-alert--success { background: rgba(34, 197, 94, 0.1); border-color: var(--tb-color-success); }
.tb-alert--warning { background: rgba(245, 158, 11, 0.1); border-color: var(--tb-color-warning); }
.tb-alert--danger { background: rgba(239, 68, 68, 0.1); border-color: var(--tb-color-danger); }
.tb-alert--info { background: rgba(14, 165, 233, 0.1); border-color: var(--tb-color-info); }

/* Breadcrumbs */
.tb-breadcrumbs {
  margin-bottom: var(--tb-space-lg);
}

.tb-breadcrumbs__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tb-space-xs);
  align-items: center;
  font-size: var(--tb-text-sm);
  color: var(--tb-color-text-muted);
  list-style: none;
  padding: 0;
  margin: 0;
}

.tb-breadcrumbs__item::after {
  content: "/";
  margin-left: var(--tb-space-xs);
  opacity: 0.5;
}

.tb-breadcrumbs__item:last-child::after {
  content: none;
}

.tb-breadcrumbs a {
  color: var(--tb-color-text-muted);
  text-decoration: none;
}

.tb-breadcrumbs a:hover {
  color: var(--tb-color-link);
}

/* Pagination */
.tb-pagination {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tb-space-xs);
  justify-content: center;
  margin-top: var(--tb-space-xl);
  list-style: none;
  padding: 0;
}

.tb-pagination a,
.tb-pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tb-touch-min);
  min-height: var(--tb-touch-min);
  padding: 0 var(--tb-space-sm);
  border: 1px solid var(--tb-color-border);
  border-radius: var(--tb-radius-md);
  text-decoration: none;
  color: var(--tb-color-text);
  font-weight: 500;
}

.tb-pagination .current {
  background: var(--tb-color-primary);
  border-color: var(--tb-color-primary);
  color: #fff;
}

/* Empty state */
.tb-empty-state {
  text-align: center;
  padding: var(--tb-space-2xl) var(--tb-space-lg);
  background: var(--tb-color-surface);
  border: 1px dashed var(--tb-color-border);
  border-radius: var(--tb-radius-lg);
}

.tb-empty-state__title {
  margin: 0 0 var(--tb-space-sm);
  font-size: var(--tb-text-xl);
}

.tb-empty-state__text {
  margin: 0 0 var(--tb-space-lg);
  color: var(--tb-color-text-muted);
}

/* Skeleton loader */
.tb-skeleton {
  background: linear-gradient(90deg, var(--tb-color-surface) 25%, var(--tb-color-border) 50%, var(--tb-color-surface) 75%);
  background-size: 200% 100%;
  animation: tb-shimmer 1.4s ease infinite;
  border-radius: var(--tb-radius-sm);
}

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

/* Modal */
.tb-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--tb-space-md);
}

.tb-modal[hidden] {
  display: none;
}

.tb-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.tb-modal__dialog {
  position: relative;
  width: min(100%, 520px);
  background: var(--tb-color-card);
  border-radius: var(--tb-radius-lg);
  box-shadow: var(--tb-shadow-float);
  padding: var(--tb-space-xl);
}

/* Filter chips */
.tb-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tb-space-sm);
  margin-bottom: var(--tb-space-lg);
}

.tb-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.85rem;
  border-radius: var(--tb-radius-pill);
  border: 1px solid var(--tb-color-border);
  background: var(--tb-color-bg);
  font-size: var(--tb-text-sm);
  text-decoration: none;
  color: var(--tb-color-text);
  transition: all var(--tb-transition);
}

.tb-chip:hover,
.tb-chip.is-active {
  background: var(--tb-color-primary);
  border-color: var(--tb-color-primary);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .tb-skeleton { animation: none; }
  .tb-button--loading::after { animation: none; }
}