/**
 * Bootstrap Grafana - Buttons
 * Complete restyle of .btn* to match grafana.com + Grafana UI buttons
 *
 * Primary CTA: solid brand orange with gradient options
 * Secondary: subtle filled or outline
 * Ghost / text buttons common in product UI
 */

.btn {
  --bs-btn-font-family: var(--gf-font-sans);
  --bs-btn-font-size: var(--gf-font-size-sm);
  --bs-btn-font-weight: var(--gf-font-weight-medium);
  --bs-btn-line-height: 1.4;
  --bs-btn-padding-x: 1rem;
  --bs-btn-padding-y: 0.5rem;
  --bs-btn-border-radius: var(--gf-radius);
  --bs-btn-box-shadow: none;
  --bs-btn-focus-box-shadow: 0 0 0 3px var(--gf-action-focus);
  --bs-btn-active-box-shadow: none;
  --bs-btn-transition: all 0.15s ease;
  font-family: var(--gf-font-sans);
  font-weight: var(--gf-font-weight-medium);
  border-radius: var(--gf-radius);
  padding: 0.5rem 1rem;
  font-size: var(--gf-font-size-sm);
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  position: relative;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--gf-action-focus);
}

.btn:active {
  transform: translateY(0);
}

/* Primary - the signature Grafana orange button */
.btn-primary,
.btn.btn-primary {
  background-color: var(--gf-brand);
  border-color: var(--gf-brand);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background-color: var(--gf-brand-hover);
  border-color: var(--gf-brand-hover);
  color: #ffffff;
}

.btn-primary:active {
  background-color: var(--gf-brand-active);
  border-color: var(--gf-brand-active);
}

/* Gradient primary variant (very common on grafana.com CTAs) */
.btn-primary.gf-gradient,
.btn.gf-gradient-primary {
  background: var(--gf-gradient-brand);
  border-color: transparent;
  color: #ffffff;
  position: relative;
  overflow: hidden;
}

.btn-primary.gf-gradient:hover,
.btn.gf-gradient-primary:hover {
  filter: brightness(1.05);
  box-shadow: 0 2px 8px rgba(245, 95, 62, 0.4);
}

/* Secondary */
.btn-secondary {
  background-color: var(--gf-bg-secondary);
  border-color: var(--gf-border-medium);
  color: var(--gf-text-primary);
}

.btn-secondary:hover,
.btn-secondary:focus {
  background-color: var(--gf-bg-hover);
  border-color: var(--gf-border-strong);
  color: var(--gf-text-primary);
}

/* Outline / ghost variants */
.btn-outline-primary {
  color: var(--gf-brand);
  border-color: var(--gf-brand);
  background-color: transparent;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
  background-color: var(--gf-brand);
  border-color: var(--gf-brand);
  color: #ffffff;
}

.btn-outline-secondary {
  color: var(--gf-text-secondary);
  border-color: var(--gf-border-medium);
  background-color: transparent;
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
  background-color: var(--gf-bg-secondary);
  border-color: var(--gf-border-strong);
  color: var(--gf-text-primary);
}

/* Ghost / text button (very Grafana) */
.btn-ghost,
.btn-link.btn-ghost,
.btn.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--gf-text-secondary);
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.btn-ghost:hover,
.btn-ghost:focus {
  background-color: var(--gf-action-hover);
  color: var(--gf-text-primary);
  text-decoration: none;
}

/* Danger / destructive */
.btn-danger {
  background-color: var(--gf-danger);
  border-color: var(--gf-danger);
  color: #ffffff;
}

.btn-danger:hover {
  background-color: #b80c4f;
  border-color: #b80c4f;
}

/* Success */
.btn-success {
  background-color: var(--gf-success);
  border-color: var(--gf-success);
  color: #ffffff;
}

/* Sizes - match Grafana */
.btn-lg,
.btn-group-lg > .btn {
  --bs-btn-padding-x: 1.25rem;
  --bs-btn-padding-y: 0.625rem;
  font-size: var(--gf-font-size-base);
  border-radius: var(--gf-radius-md);
}

.btn-sm,
.btn-group-sm > .btn {
  --bs-btn-padding-x: 0.625rem;
  --bs-btn-padding-y: 0.3125rem;
  font-size: 12px;
  border-radius: var(--gf-radius-sm);
}

/* Block */
.btn-block {
  display: block;
  width: 100%;
}

/* Icon button (square-ish) */
.btn-icon {
  padding: 0.5rem;
  width: 2.25rem;
  height: 2.25rem;
  justify-content: center;
}

.btn-icon.btn-lg {
  width: 2.75rem;
  height: 2.75rem;
}

.btn-icon.btn-sm {
  width: 1.875rem;
  height: 1.875rem;
}

/* Disabled state */
.btn:disabled,
.btn.disabled {
  opacity: 0.55;
  pointer-events: none;
  box-shadow: none;
}

/* Loading state helper (add .btn-loading + spinner inside if wanted) */
.btn-loading {
  color: transparent !important;
  pointer-events: none;
}

.btn-loading::after {
  content: '';
  position: absolute;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: gf-spin 0.6s linear infinite;
  color: inherit;
}

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

/* Button groups */
.btn-group .btn {
  border-radius: 0;
}

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

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

.btn-group-vertical .btn:first-child {
  border-radius: var(--gf-radius) var(--gf-radius) 0 0;
}

.btn-group-vertical .btn:last-child {
  border-radius: 0 0 var(--gf-radius) var(--gf-radius);
}

/* Close button (for modals, alerts) */
.btn-close {
  background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ccccccdc'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat;
  opacity: 0.7;
}

.btn-close:hover {
  opacity: 1;
}

[data-theme="dark"],
[data-theme="green-dark"] .btn-close {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ccccccdc'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e");
}
