/* Button base styles */
.btn { 
  border: 1px solid #cbd5e1; 
  background: white; 
  color: #0f172a; 
  border-radius: 8px; 
  padding: 8px 12px; 
  cursor: pointer; 
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn.primary { 
  background: var(--primary); 
  border-color: var(--primary); 
  color: white; 
}

.btn.primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.btn.cta { 
  background: linear-gradient(135deg, #10b981, #059669); 
  border-color: #047857; 
  color: #ffffff; 
  font-weight: 700; 
  box-shadow: 0 2px 6px rgba(16, 185, 129, .35); 
}

.btn.cta:hover { 
  filter: brightness(1.05); 
  transform: translateY(-1px);
}

.btn.lg { 
  padding: 12px 16px; 
  font-size: 16px; 
}

.btn.small { 
  padding: 4px 8px; 
  font-size: 12px; 
}

/* Icon-only buttons (used in sermons actions) */
.btn.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  line-height: 1;
  font-size: 16px;
  border-color: transparent;
  background: transparent;
}

.btn.icon > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 18px;
  line-height: 1;
}

.btn.icon:hover {
  background: #f1f5f9;
  border-color: #e2e8f0;
}

.btn.icon.download { color: var(--primary); }
.btn.icon.edit { color: var(--warning); }
.btn.icon.delete { color: var(--danger); }

.btn.danger { 
  background: var(--danger); 
  border-color: var(--danger); 
  color: #fff; 
}

.btn.danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

.btn:disabled { 
  opacity: .6; 
  cursor: not-allowed; 
  transform: none !important;
  box-shadow: none !important;
}

/* Enhanced loading state for buttons */
.btn.loading { 
  position: relative; 
  color: transparent !important; 
  pointer-events: none;
  opacity: 0.8;
  transform: none !important;
  box-shadow: none !important;
}

.btn.loading::after { 
  content: ''; 
  position: absolute; 
  top: 50%; 
  left: 50%; 
  transform: translate(-50%, -50%); 
  width: 20px; 
  height: 20px; 
  border: 2px solid rgba(255, 255, 255, 0.3); 
  border-top: 2px solid #ffffff; 
  border-radius: 50%; 
  animation: spin 0.8s linear infinite; 
}

/* Special loading state for primary buttons */
.btn.primary.loading::after {
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #ffffff;
}

/* Loading state for form submit buttons - more prominent */
.form-grid .btn.loading {
  background: #6b7280 !important;
  border-color: #6b7280 !important;
  cursor: not-allowed;
  transform: none !important;
}

.form-grid .btn.primary.loading {
  background: #3b82f6 !important;
  opacity: 0.7;
}

.form-grid .btn.loading::before {
  content: 'Đang lưu...';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  opacity: 0.9;
  z-index: 1;
  animation: pulse 1.5s ease-in-out infinite;
}

.form-grid .btn.loading::after { 
  width: 16px;
  height: 16px;
  right: 16px;
  left: auto;
  top: 50%;
  transform: translateY(-50%);
  border: 2px solid rgba(255, 255, 255, 0.4); 
  border-top: 2px solid #ffffff; 
  z-index: 2;
}

/* Additional loading states for better UX */
.btn.loading-text {
  position: relative;
  padding-right: 48px !important;
}

.btn.loading-text::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top: 2px solid #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Success button loading state */
.success-btn.loading {
  opacity: 0.8;
  pointer-events: none;
}

.success-btn.loading::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Button animations */
@keyframes pulse {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.6; }
}

/* Button focus states for accessibility */
.btn:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Haptic feedback simulation with subtle animations */
.btn:active {
  transform: scale(0.98);
}

/* Mobile touch improvements */
@media (max-width: 480px) {
  .btn {
    min-height: 44px; /* Touch target size */
    padding: 12px 16px;
  }
  
  .btn.small {
    min-height: 36px;
    padding: 8px 12px;
  }
}