/**
 * Component styles - Buttons, tooltips, stats, filters, badges, loading states, toasts
 */

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
  transform: translateY(-1px);
}

.btn-secondary {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.btn-ghost {
  background: transparent;
  color: var(--gray-600);
}

.btn-ghost:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
}

.btn-destructive {
  color: var(--red-600);
}

.btn-destructive:hover {
  background: var(--red-50);
  color: var(--red-600);
}

/* --------------------------------------------------------------------------
   Custom Tooltips - Greenish transparent theme
   -------------------------------------------------------------------------- */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::before,
[data-tooltip]::after {
  position: absolute;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  pointer-events: none;
  z-index: 9999;
}

[data-tooltip]::before {
  content: attr(data-tooltip);
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.5rem 0.75rem;
  background: rgba(34, 197, 94, 0.95);
  color: white;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

[data-tooltip]::after {
  content: '';
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(34, 197, 94, 0.95);
}

[data-tooltip]:hover::before,
[data-tooltip]:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Left-aligned tooltips for buttons near card edges */
.footer-left [data-tooltip]::before {
  left: 0;
  transform: translateX(0);
}

.footer-left [data-tooltip]::after {
  left: 0.5rem;
  transform: translateX(0);
}

/* Right-aligned tooltips for buttons near right card edges */
.footer-right [data-tooltip]::before {
  left: auto;
  right: 0;
  transform: translateX(0);
}

.footer-right [data-tooltip]::after {
  left: auto;
  right: 0.5rem;
  transform: translateX(0);
}

/* Danger tooltip for delete buttons */
.btn-delete[data-tooltip]::before {
  background: rgba(239, 68, 68, 0.95);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-delete[data-tooltip]::after {
  border-top-color: rgba(239, 68, 68, 0.95);
}

/* --------------------------------------------------------------------------
   Stats Cards
   -------------------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  border: 1px solid var(--gray-200);
  transition: all 0.2s ease;
}

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

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon.green {
  background: var(--primary-100);
  color: var(--primary-600);
}

.stat-icon.amber {
  background: var(--amber-100);
  color: var(--amber-600);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gray-900);
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--gray-500);
  font-weight: 500;
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 0.5rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
}

.stat-change.positive {
  background: var(--primary-100);
  color: var(--primary-700);
}

.stat-change.negative {
  background: var(--red-100);
  color: var(--red-600);
}

.stat-change.neutral {
  background: var(--gray-100);
  color: var(--gray-500);
}

.stat-previous {
  font-size: 0.6875rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

/* --------------------------------------------------------------------------
   Filters
   -------------------------------------------------------------------------- */
.filters-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
  position: sticky;
  top: 81px; /* Below sticky main-header with breathing room */
  background: linear-gradient(135deg, var(--amber-50) 0%, var(--gray-50) 50%, var(--primary-50) 100%);
  padding: 1rem 0;
  z-index: 20; /* Below main-header (z-index: 30) */
}

.filter-group {
  position: relative;
}

.filter-select {
  appearance: none;
  padding: 0.5rem 2.25rem 0.5rem 0.875rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: white;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  min-width: 140px;
}

.filter-select:hover {
  border-color: var(--gray-400);
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.filter-icon {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--gray-400);
}

.search-input {
  padding: 0.5rem 0.875rem 0.5rem 2.5rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: white;
  font-size: 0.875rem;
  width: 280px;
  transition: all 0.15s;
  font-family: inherit;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.search-group {
  position: relative;
}

.search-group .search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
}

.filter-spacer {
  flex: 1;
}

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-success {
  background: var(--primary-100);
  color: var(--primary-700);
}

.badge-success .badge-dot {
  background: var(--primary-500);
}

.badge-warning {
  background: var(--amber-100);
  color: var(--amber-600);
}

.badge-warning .badge-dot {
  background: var(--amber-500);
}

.badge-neutral {
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge-neutral .badge-dot {
  background: var(--gray-400);
}

/* --------------------------------------------------------------------------
   Loading & Empty States
   -------------------------------------------------------------------------- */
.loading-state,
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--gray-500);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

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

.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  color: var(--gray-300);
}

.empty-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--gray-700);
  margin-bottom: 0.25rem;
}

.empty-text {
  font-size: 0.875rem;
  color: var(--gray-500);
}

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 320px;
  max-width: 420px;
  pointer-events: auto;
  animation: toastSlideIn 0.3s ease-out;
  border-left: 4px solid var(--gray-400);
}

.toast.error { border-left-color: var(--red-500); }
.toast.success { border-left-color: var(--primary-500); }
.toast.warning { border-left-color: var(--amber-500); }

.toast.hide {
  animation: toastSlideOut 0.3s ease-in forwards;
}

@keyframes toastSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes toastSlideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

.toast-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-icon svg { width: 20px; height: 20px; }
.toast.error .toast-icon { color: var(--red-500); }
.toast.success .toast-icon { color: var(--primary-500); }
.toast.warning .toast-icon { color: var(--amber-500); }

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

.toast-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 2px;
}

.toast-message {
  font-size: 13px;
  color: var(--gray-600);
  line-height: 1.4;
  word-break: break-word;
}

.toast-close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  border-radius: var(--radius);
  transition: all 0.15s;
  padding: 0;
}

.toast-close:hover {
  color: var(--gray-600);
  background: var(--gray-100);
}

.toast-close svg { width: 16px; height: 16px; }
