/* ============================================
   COMPONENTS.CSS — UI Kit
   Crosra Research Analysis Tool
   
   Reusable components built on design tokens.
   All colors auto-adapt to dark mode.
   
   Structure:
   1. Buttons
   2. Cards
   3. Forms (inputs, selects, checkboxes, radios, textareas)
   4. Badges & Tags
   5. Alerts & Status Bars
   6. Modals & Dialogs
   7. Dropdowns
   8. Tabs
   9. Tables
   10. Tooltips
   11. Avatars & Icons
   12. Dividers & Spacers
   13. Progress & Loading
   ============================================ */

/* ============================================
   1. BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
  transition: 
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.btn:hover {
  background: var(--bg-muted);
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn:disabled,
.btn[disabled],
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Button sizes */
.btn-sm {
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
  border-radius: var(--radius-lg);
}

.btn-xl {
  padding: var(--space-4) var(--space-8);
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-lg);
}

/* Primary button */
.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-primary:active {
  background: var(--primary-active);
}

/* Secondary button */
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg-muted);
  border-color: var(--primary);
  color: var(--primary);
}

/* Ghost button */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--bg-muted);
  color: var(--text);
}

/* Outline button */
.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: var(--text-inverse);
}

/* Danger button */
.btn-danger {
  background: var(--error);
  color: var(--text-inverse);
  border-color: var(--error);
  box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
  background: var(--error-dark);
  border-color: var(--error-dark);
  box-shadow: var(--shadow-md);
}

.btn-danger:focus-visible {
  box-shadow: var(--focus-ring-error);
}

/* Success button */
.btn-success {
  background: var(--success);
  color: var(--text-inverse);
  border-color: var(--success);
}

.btn-success:hover {
  background: var(--success-dark);
  border-color: var(--success-dark);
}

/* Icon button (square) */
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-icon.btn-sm {
  width: 28px;
  height: 28px;
}

.btn-icon.btn-lg {
  width: 44px;
  height: 44px;
}

/* Button group */
.btn-group {
  display: inline-flex;
  gap: 0;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:first-child {
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.btn-group .btn:last-child {
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

.btn-group .btn + .btn {
  margin-left: -1px;
}

/* Loading button */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn-loading::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  color: var(--text-inverse);
}

.btn-secondary.btn-loading::after,
.btn-ghost.btn-loading::after,
.btn-outline.btn-loading::after {
  color: var(--text);
}

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

/* ============================================
   2. CARDS
   ============================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  transition: 
    box-shadow var(--transition-base),
    transform var(--transition-base),
    border-color var(--transition-base);
}

.card-hover:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--primary);
}

.card-interactive:active {
  transform: translateY(0);
}

.card-elevated {
  box-shadow: var(--shadow-md);
  border-color: transparent;
}

.card-flat {
  box-shadow: none;
  border-color: var(--border-subtle);
}

.card-header {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.card-header-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text);
  margin: 0;
}

.card-header-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.card-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.card-body {
  padding: var(--space-6);
}

.card-body-compact {
  padding: var(--space-4);
}

.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}

/* Accent card (left border) */
.card-accent {
  border-left: 4px solid var(--primary);
}

.card-accent-warning {
  border-left: 4px solid var(--warning);
}

.card-accent-error {
  border-left: 4px solid var(--error);
}

.card-accent-success {
  border-left: 4px solid var(--success);
}

.card-accent-info {
  border-left: 4px solid var(--info);
}

/* ============================================
   3. FORMS
   ============================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text);
}

.form-label-required::after {
  content: ' *';
  color: var(--error);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--error);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* Text input */
.input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: 
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

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

.input:hover:not(:disabled):not(:focus) {
  border-color: var(--text-subtle);
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

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

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

.input-error:focus {
  border-color: var(--error);
  box-shadow: var(--focus-ring-error);
}

/* Input sizes */
.input-sm {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
}

.input-lg {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
}

/* Textarea */
.textarea {
  width: 100%;
  padding: var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  resize: vertical;
  min-height: 80px;
  transition: 
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

/* Select */
.select {
  width: 100%;
  padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text);
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  appearance: none;
  cursor: pointer;
  transition: 
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

.select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.select:disabled {
  background-color: var(--bg-muted);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Checkbox */
.checkbox-wrapper {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
}

.checkbox {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.checkbox:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.checkbox-label {
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
}

/* Radio */
.radio-wrapper {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
}

.radio {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.radio:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.radio-label {
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
}

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.switch-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.switch input:checked + .switch-slider {
  background: var(--primary);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-slider {
  box-shadow: var(--focus-ring);
}

.switch input:disabled + .switch-slider {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Input group (with addon) */
.input-group {
  display: flex;
  align-items: stretch;
}

.input-group .input {
  border-radius: 0;
  flex: 1;
}

.input-group .input:first-child,
.input-group .input-addon:first-child {
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.input-group .input:last-child,
.input-group .input-addon:last-child {
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

.input-addon {
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  background: var(--bg-muted);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.input-group .input + .input {
  margin-left: -1px;
}

/* ============================================
   4. BADGES & TAGS
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  line-height: 1.4;
  color: var(--text);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-sm {
  padding: 1px var(--space-1-5);
  font-size: 10px;
}

.badge-lg {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
}

/* Status badges */
.badge-success {
  background: var(--success-light);
  color: var(--success-dark);
  border-color: transparent;
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning-dark);
  border-color: transparent;
}

.badge-error,
.badge-danger {
  background: var(--error-light);
  color: var(--error-dark);
  border-color: transparent;
}

.badge-info {
  background: var(--info-light);
  color: var(--info-dark);
  border-color: transparent;
}

.badge-primary {
  background: var(--primary-light);
  color: var(--primary);
  border-color: transparent;
}

.badge-accent {
  background: var(--accent-light);
  color: var(--accent-dark);
  border-color: transparent;
}

/* Dot badge (status indicator) */
.badge-dot {
  padding-left: var(--space-2);
}

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-dot.badge-success::before { background: var(--success); }
.badge-dot.badge-warning::before { background: var(--warning); }
.badge-dot.badge-error::before { background: var(--error); }
.badge-dot.badge-info::before { background: var(--info); }

/* Tag (removable) */
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--text);
}

.tag-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  transition: 
    background-color var(--transition-fast),
    color var(--transition-fast);
}

.tag-remove:hover {
  background: var(--error-light);
  color: var(--error);
}

/* ============================================
   5. ALERTS & STATUS BARS
   ============================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text);
}

.alert-icon {
  flex-shrink: 0;
  font-size: var(--text-lg);
  line-height: 1;
}

.alert-content {
  flex: 1;
  min-width: 0;
}

.alert-title {
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-1);
}

.alert-dismiss {
  flex-shrink: 0;
  padding: var(--space-1);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: 
    background-color var(--transition-fast),
    color var(--transition-fast);
}

.alert-dismiss:hover {
  background: var(--bg-muted);
  color: var(--text);
}

.alert-success {
  background: var(--success-light);
  border-left-color: var(--success);
  color: var(--success-dark);
}

.alert-warning {
  background: var(--warning-light);
  border-left-color: var(--warning);
  color: var(--warning-dark);
}

.alert-error {
  background: var(--error-light);
  border-left-color: var(--error);
  color: var(--error-dark);
}

.alert-info {
  background: var(--info-light);
  border-left-color: var(--info);
  color: var(--info-dark);
}

/* Status bar (compact) */
.status-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-muted);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.status-bar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-bar.success .status-bar-dot { background: var(--success); }
.status-bar.warning .status-bar-dot { background: var(--warning); }
.status-bar.error .status-bar-dot { background: var(--error); }

/* ============================================
   6. MODALS & DIALOGS
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: var(--z-modal-backdrop);
  animation: modal-fade-in var(--transition-base);
}

[data-theme="dark"] .modal-overlay {
  background: rgba(2, 6, 23, 0.8);
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modal-slide-up var(--transition-base);
}

@keyframes modal-slide-up {
  from { 
    opacity: 0; 
    transform: translateY(10px) scale(0.98); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0) scale(1); 
  }
}

.modal-sm { max-width: 400px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }
.modal-full { max-width: calc(100vw - var(--space-8)); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}

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

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: 
    background-color var(--transition-fast),
    color var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-muted);
  color: var(--text);
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ============================================
   7. DROPDOWNS
   ============================================ */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  z-index: var(--z-dropdown);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: 
    opacity var(--transition-fast),
    transform var(--transition-fast),
    visibility var(--transition-fast);
}

.dropdown.open .dropdown-menu,
.dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-menu-right {
  left: auto;
  right: 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
  transition: 
    background-color var(--transition-fast),
    color var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--bg-muted);
  color: var(--primary);
}

.dropdown-item-icon {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  color: var(--text-muted);
}

.dropdown-item:hover .dropdown-item-icon {
  color: var(--primary);
}

.dropdown-item-shortcut {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-subtle);
}

.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-1) 0;
}

.dropdown-header {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

/* ============================================
   8. TABS
   ============================================ */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

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

.tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: 
    color var(--transition-fast),
    border-color var(--transition-fast),
    background-color var(--transition-fast);
}

.tab:hover {
  color: var(--text);
  background: var(--bg-subtle);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Pill tabs (alternative style) */
.tabs-pills {
  display: inline-flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--bg-muted);
  border-radius: var(--radius-md);
  border: none;
}

.tabs-pills .tab {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border-bottom: none;
}

.tabs-pills .tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
}

/* Tab panel */
.tab-panel {
  display: none;
  animation: tab-fade-in var(--transition-base);
}

.tab-panel.active {
  display: block;
}

@keyframes tab-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================
   9. TABLES
   ============================================ */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table thead {
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}

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

.table td {
  padding: var(--space-3) var(--space-4);
  color: var(--text);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

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

.table tbody tr:hover {
  background: var(--bg-subtle);
}

/* Striped table */
.table-striped tbody tr:nth-child(even) {
  background: var(--bg-subtle);
}

/* Compact table */
.table-compact th,
.table-compact td {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}

/* Clickable rows */
.table-clickable tbody tr {
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.table-clickable tbody tr:hover {
  background: var(--primary-lighter);
}

.table-empty {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--text-muted);
}

.table-empty-icon {
  font-size: 3rem;
  margin-bottom: var(--space-3);
  opacity: 0.5;
}

/* ============================================
   10. TOOLTIPS
   ============================================ */
.tooltip {
  position: relative;
  display: inline-block;
}

.tooltip-content {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-1-5) var(--space-2);
  background: var(--neutral-900);
  color: var(--text-inverse);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  border-radius: var(--radius-md);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: 
    opacity var(--transition-fast),
    visibility var(--transition-fast);
  z-index: var(--z-tooltip);
  box-shadow: var(--shadow-lg);
}

[data-theme="dark"] .tooltip-content {
  background: var(--neutral-100);
  color: var(--neutral-900);
}

.tooltip-content::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--neutral-900);
}

[data-theme="dark"] .tooltip-content::after {
  border-top-color: var(--neutral-100);
}

.tooltip:hover .tooltip-content {
  opacity: 1;
  visibility: visible;
}

/* ============================================
   11. AVATARS & ICONS
   ============================================ */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--accent-light) 100%);
  color: var(--primary);
  border-radius: 50%;
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
  overflow: hidden;
}

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

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: var(--text-xs);
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: var(--text-lg);
}

.avatar-xl {
  width: 80px;
  height: 80px;
  font-size: var(--text-2xl);
}

/* Icon wrapper */
.icon-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--bg-muted);
  color: var(--primary);
  border-radius: var(--radius-md);
  font-size: var(--text-lg);
  flex-shrink: 0;
}

.icon-wrapper-sm {
  width: 28px;
  height: 28px;
  font-size: var(--text-sm);
}

.icon-wrapper-lg {
  width: 56px;
  height: 56px;
  font-size: var(--text-2xl);
}

.icon-wrapper-primary {
  background: var(--primary-light);
  color: var(--primary);
}

.icon-wrapper-accent {
  background: var(--accent-light);
  color: var(--accent-dark);
}

.icon-wrapper-success {
  background: var(--success-light);
  color: var(--success-dark);
}

.icon-wrapper-warning {
  background: var(--warning-light);
  color: var(--warning-dark);
}

.icon-wrapper-error {
  background: var(--error-light);
  color: var(--error-dark);
}

.icon-wrapper-info {
  background: var(--info-light);
  color: var(--info-dark);
}

/* ============================================
   12. DIVIDERS & SPACERS
   ============================================ */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-4) 0;
  border: none;
}

.divider-vertical {
  width: 1px;
  height: 100%;
  background: var(--border);
  margin: 0 var(--space-4);
  border: none;
  display: inline-block;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin: var(--space-6) 0;
}

.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Spacer */
.spacer {
  flex: 1;
}

.spacer-sm { height: var(--space-2); }
.spacer-md { height: var(--space-4); }
.spacer-lg { height: var(--space-8); }
.spacer-xl { height: var(--space-12); }

/* ============================================
   13. PROGRESS & LOADING
   ============================================ */
/* Progress bar */
.progress {
  width: 100%;
  height: 8px;
  background: var(--bg-muted);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

.progress-bar-success { background: var(--success); }
.progress-bar-warning { background: var(--warning); }
.progress-bar-error { background: var(--error); }

.progress-sm { height: 4px; }
.progress-lg { height: 12px; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spinner-rotate 0.6s linear infinite;
}

.spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 1.5px;
}

.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

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

/* Skeleton loader */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-muted) 0%,
    var(--bg-subtle) 50%,
    var(--bg-muted) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

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

.skeleton-text {
  height: 14px;
  margin-bottom: var(--space-2);
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: var(--space-3);
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.skeleton-button {
  height: 36px;
  width: 120px;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text);
  margin-bottom: var(--space-2);
}

.empty-state-description {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 400px;
  margin-bottom: var(--space-6);
}

/* ============================================
   14. CONTAINER & LAYOUT HELPERS
   ============================================ */
.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.container-sm { max-width: 640px; }
.container-md { max-width: 768px; }
.container-lg { max-width: 1024px; }
.container-xl { max-width: 1280px; }
.container-2xl { max-width: 1536px; }

/* Stack (vertical flex with gap) */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack-sm { gap: var(--space-2); }
.stack-lg { gap: var(--space-6); }
.stack-xl { gap: var(--space-8); }

/* Cluster (horizontal flex with gap) */
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.cluster-sm { gap: var(--space-2); }
.cluster-lg { gap: var(--space-4); }

/* Grid */
.grid {
  display: grid;
  gap: var(--space-4);
}

.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* Responsive grid */
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

@media (max-width: 768px) {
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   15. ANIMATIONS
   ============================================ */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-in-up {
  from { 
    opacity: 0; 
    transform: translateY(10px); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0); 
  }
}

@keyframes scale-in {
  from { 
    opacity: 0; 
    transform: scale(0.95); 
  }
  to { 
    opacity: 1; 
    transform: scale(1); 
  }
}

.animate-fade-in { animation: fade-in var(--transition-base); }
.animate-fade-in-up { animation: fade-in-up var(--transition-base); }
.animate-scale-in { animation: scale-in var(--transition-base); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}