.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 6px 12px;
  min-height: 34px;
  line-height: 22px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: var(--font-sm);
  text-decoration: none;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}

.btn-sm {
  padding: 4px 10px;
  min-height: 28px;
  line-height: 18px;
}

.btn-lg {
  padding: 14px 32px;
  font-size: var(--font-lg);
  min-height: 44px;
  border-radius: var(--radius-lg);
}

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

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

.btn-danger {
  background: var(--danger);
  color: var(--bg);
}

.btn-danger:hover {
  background: #c82333;
}

.btn-success {
  background: var(--success);
  color: var(--bg);
}

.btn-success:hover {
  background: #218838;
}

.btn-secondary {
  background: #6c757d;
  color: var(--bg);
}

.btn-secondary:hover {
  background: #5a6268;
}

.icon-inline {
  vertical-align: text-bottom;
  margin-right: 4px;
}

.icon-muted {
  opacity: 0.5;
}

.btn-connect {
  background: var(--purple);
  color: var(--bg);
}

.btn-connect:hover {
  background: #6a1fc9;
}

.btn-outline-primary {
  background: var(--bg);
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline-primary:hover {
  background: #e6f2ff;
}

.btn-outline-secondary {
  background: var(--bg);
  color: #4b5563;
  border-color: #6c757d;
}

.btn-outline-secondary:hover {
  background: #f3f4f6;
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--danger);
  text-decoration: underline;
  font-weight: 600;
  cursor: pointer;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  justify-content: center;
  font-size: 16px;
}

.btn-sync {
  position: relative;
}

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

.spinner-indicator {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--bg);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

.sync-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.75);
  z-index: 9999;
  color: #fff;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sync-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.sync-overlay-spinner {
  font-size: 64px;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

.sync-overlay-message {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.sync-overlay-elapsed {
  font-size: 14px;
  color: #d1d5db;
  margin-top: 10px;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.htmx-request {
  opacity: 0.5;
  pointer-events: none;
}

.htmx-request .spinner-indicator {
  visibility: visible;
  opacity: 1;
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85em;
  font-weight: 600;
}

.badge-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.badge-warning {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

.badge-danger {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.badge-strong {
  background: #e6f2ff;
  color: var(--primary);
  border: 1px solid #cfe4ff;
}

.pill {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: var(--font-sm);
  font-weight: 600;
  background: var(--primary);
  color: var(--bg);
}

.pill-warning {
  background: var(--warning);
}

.form-label {
  display: block;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-xs);
  font-size: var(--font-sm);
}

.form-control,
.form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  font-size: var(--font-base);
  background: var(--bg);
}

.form-control-center {
  text-align: center;
  font-weight: 600;
}

.form-control:disabled,
.form-select:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: #f3f4f6;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary);
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(0, 102, 204, 0.25);
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.card-header {
  margin-bottom: var(--space-md);
  font-weight: 600;
}

.card-title {
  margin: 0 0 var(--space-xs) 0;
  font-size: var(--font-lg);
  font-weight: 600;
}

.card-subtitle {
  margin: 0;
  color: var(--text-light);
  font-size: var(--font-sm);
}

.card-grid {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.feature-card {
  padding: var(--space-md);
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left-width: 3px;
}

.accent-success {
  border-left-color: var(--success);
}

.accent-primary {
  border-left-color: var(--primary);
}

.accent-purple {
  border-left-color: var(--purple);
}

.accent-warning {
  border-left-color: #fd7e14;
}

.accent-danger {
  border-left-color: var(--danger);
}

.accent-gold {
  border-left-color: #ffd700;
}

.accent-neutral {
  border-left-color: #6b7280;
}

.details-info {
  background: #e7f3ff;
  border-left: 3px solid var(--primary);
}

.details-info summary {
  color: var(--primary);
}

.callout {
  padding: var(--space-md);
  border-radius: var(--radius);
  border-left: 4px solid var(--primary);
  background: #f0f7ff;
  color: var(--text);
}

.callout-info {
  border-left-color: var(--primary);
  background: #e7f3ff;
}

.callout-warning {
  border-left-color: #ffc107;
  background: #fff3cd;
}

.callout-success {
  border-left-color: var(--success);
  background: #f0fff4;
}

.callout-danger {
  border-left-color: var(--danger);
  background: #fff5f5;
}

.callout-purple {
  border-left-color: var(--purple);
  background: #f0e7ff;
  color: #4a148c;
}

.note {
  margin-bottom: var(--space-sm);
  padding: var(--space-md);
  background: #f5f5f5;
  border-radius: var(--radius);
  font-size: var(--font-sm);
}

.context-note {
  font-size: 11px;
  color: #888;
  margin-top: var(--space-sm);
  padding: var(--space-sm);
  background: var(--bg);
  border-radius: var(--radius);
}

.loading-text {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
}

.loading-panel {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.loading-title {
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text-dark);
  margin: var(--space-sm) 0 var(--space-xs) 0;
}

.loading-subtitle {
  font-size: var(--font-sm);
  color: var(--text-light);
  margin: 0;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-state-title {
  font-size: var(--font-lg);
  margin-bottom: var(--space-sm);
}

.empty-state-subtitle {
  font-size: var(--font-sm);
  margin: 0;
}

.league-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.league-list li {
  margin: 0;
}

.league-row {
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.league-meta {
  font-size: var(--font-sm);
  color: var(--text-dark);
}

.league-meta small {
  color: var(--text-light);
}

.league-actions {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.tabs {
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--space-lg);
}

.tab-list {
  display: flex;
  gap: 0;
}

.tab-button {
  padding: 12px 24px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  border-left: 3px solid transparent;
  color: var(--text-light);
  font-weight: 600;
  cursor: pointer;
  font-size: var(--font-base);
  transition: color var(--transition), border-color var(--transition);
}

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

.tab-content {
  display: block;
}

.tab-content.is-hidden {
  display: none;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}

.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table th {
  background: #f5f5f5;
  font-weight: 600;
}

.table-striped tbody tr:nth-child(even) {
  background: #f8f9fa;
}

.table-hover tbody tr:hover {
  background: #f9f9f9;
}

.table-sticky th {
  position: sticky;
  top: 0;
  z-index: 10;
}

.table-right th:nth-child(n + 3),
.table-right td:nth-child(n + 3) {
  text-align: right;
}

.table-compact th,
.table-compact td {
  padding: 8px 10px;
}

.details-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-md);
  background: var(--bg);
}

.details-card summary {
  cursor: pointer;
  font-weight: 600;
  user-select: none;
}

.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  background: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  border-left: 4px solid var(--primary);
  pointer-events: auto;
  animation: toast-slide-in 0.3s ease-out;
  min-width: 300px;
}

.toast-error {
  border-left-color: var(--danger);
}

.toast-success {
  border-left-color: var(--success);
}

.toast-info {
  border-left-color: var(--primary);
}

.toast-warning {
  border-left-color: #ffc107;
}

.toast-icon {
  flex-shrink: 0;
  font-size: 20px;
  line-height: 1;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  margin: 0 0 4px 0;
  font-size: var(--font-sm);
  color: var(--text-dark);
}

.toast-message {
  margin: 0;
  font-size: var(--font-sm);
  color: var(--text-light);
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
  transition: color var(--transition);
}

.toast-close:hover {
  color: var(--text);
}

@keyframes toast-slide-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast-fade-out {
  animation: toast-fade-out 0.3s ease-out forwards;
}

@keyframes toast-fade-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  min-height: 200px;
}

.loading-state p {
  color: var(--text-light);
  font-size: var(--font-sm);
  margin: 0;
}

.loading-label {
  color: var(--primary);
  font-weight: 600;
}

.loading-muted {
  color: #999;
  font-style: italic;
}

.trade-impact {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  margin-top: var(--space-sm);
}

.impact-row {
  padding: var(--space-sm);
  border-radius: var(--radius);
  background: #f8f9fa;
}

.impact-label {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 600;
}

.impact-value {
  font-weight: 600;
  font-size: var(--font-lg);
}

.impact-value.positive {
  color: #2e7d32;
}

.impact-value.negative {
  color: #e65100;
}

/* Fairness badges used in trade suggestions */
.fairness-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85em;
  font-weight: 600;
  margin-bottom: 8px;
}

.fairness-Excellent {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.fairness-Fair {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

.fairness-Lopsided,
.fairness-Very\ Lopsided {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.fairness-Very\ Lopsided {
  border-width: 2px;
}

.advantage-indicator {
  margin-left: var(--space-sm);
  color: var(--text-light);
  font-size: 0.9em;
}

.fairness-score {
  margin-left: 4px;
  opacity: 0.8;
}

.progress {
  background: var(--border);
  height: 8px;
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: var(--space-xs);
}

.progress-bar {
  height: 100%;
  background: var(--primary);
}

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

.impact-row.positive {
  background: #e8f5e9;
  border-left: 3px solid #4caf50;
}

.impact-row.negative {
  background: #fff3e0;
  border-left: 3px solid #ff9800;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
  background-color: var(--bg);
  margin: 5% auto;
  padding: 30px;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-close {
  float: right;
  font-size: 28px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}

.alert {
  padding: var(--space-md);
  border-radius: var(--radius);
}

.alert-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.alert-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.alert-info {
  background: #e7f3ff;
  color: #004085;
  border: 1px solid #b6d4fe;
}

.export-buttons {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.export-btn-wrapper {
  position: relative;
}

.export-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

.export-tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  background: #333;
  color: var(--bg);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius);
  font-size: 12px;
  white-space: nowrap;
  margin-bottom: var(--space-sm);
  z-index: 1000;
}

.export-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 20px;
  border: 6px solid transparent;
  border-top-color: #333;
}

.export-btn-wrapper:hover .export-tooltip {
  display: block;
}

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

@media (max-width: 576px) {
  .export-buttons {
    flex-direction: column;
    width: 100%;
  }

  .export-btn {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 576px) {
  .btn {
    min-height: 44px;
    font-size: 15px;
    padding: 12px 16px;
  }

  .toast-container {
    right: 10px;
    left: 10px;
    max-width: none;
  }

  .toast {
    min-width: auto;
    width: 100%;
  }

  .loading-state {
    padding: 40px 20px;
    min-height: 150px;
  }
}

@media (max-width: 768px) {
  .tab-list {
    flex-direction: column;
    gap: 0;
  }

  .tab-button {
    width: 100%;
    text-align: left;
    border-bottom-color: transparent;
    border-left: 3px solid transparent;
    padding: 14px 20px;
  }

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