/* ========================================
   AFFILIATE LINK MANAGER - B4GLASS
   Multi-link tracking system with stats
   ======================================== */

/* ========================================
   LINK MANAGER CONTAINER
   ======================================== */

.ref-links-manager {
  padding: 32px;
  margin-bottom: 32px;
  scroll-margin-top: calc(var(--topbar-height) + 24px); /* Dynamic space for sticky header */
}

.ref-links-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.ref-links-header__actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.ref-links-header .ref-section-title {
  margin: 0;
}

/* Use in ref-table as well */
.ref-table .ref-links-header {
  margin-bottom: 24px;
}

.ref-table .ref-links-header .ref-section-title {
  margin: 0;
}

/* ========================================
   BUTTONS
   ======================================== */

.ref-btn {
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ref-btn--primary {
  background: linear-gradient(135deg, #8b5cf6 0%, #d946ef 100%);
  color: white;
}

.ref-btn--primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.4);
}

.ref-btn--dashboard {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
}

.ref-btn--dashboard:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
}

.ref-btn--qr {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 13px;
}

.ref-btn--qr:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(139, 92, 246, 0.3);
}

.ref-btn--secondary {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.ref-btn--secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.ref-btn--small {
  padding: 8px 16px;
  font-size: 13px;
}

.ref-btn--danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.ref-btn--danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* ========================================
   LINKS LIST
   ======================================== */

.ref-links-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ref-link-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px;
  transition: all 0.3s ease;
}

.ref-link-card:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(139, 92, 246, 0.3);
  transform: translateY(-2px);
}

.ref-link-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.ref-link-card__title {
  font-size: 18px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  margin-bottom: 8px;
}

.ref-link-card__meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
}

.ref-link-card__badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.ref-link-card__status {
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}

.ref-link-card__status--active {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.ref-link-card__status--inactive {
  background: rgba(107, 114, 128, 0.15);
  color: #9ca3af;
  border: 1px solid rgba(107, 114, 128, 0.3);
}

/* Tags */
.ref-link-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.ref-tag {
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

/* URL Display */
.ref-link-card__url {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ref-link-card__url-text,
.ref-link-card__url-input {
  flex: 1;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ref-link-card__url-input {
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
  cursor: text;
}

.ref-link-card__copy-btn {
  padding: 6px 12px;
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 8px;
  color: #a78bfa;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ref-link-card__copy-btn:hover {
  background: rgba(139, 92, 246, 0.25);
}

.ref-link-card__copy-btn.copied {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
  color: #22c55e;
}

/* Stats Grid */
.ref-link-card__stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.ref-stat-item {
  text-align: center;
}

.ref-stat-item__value {
  font-size: 24px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  margin-bottom: 4px;
}

.ref-stat-item__label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ref-stat-item--highlight {
  background: rgba(16, 185, 129, 0.1);
  padding: 12px 8px;
  border-radius: 8px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.ref-stat-item--highlight .ref-stat-item__value {
  color: #10b981;
}

/* Actions */
.ref-link-card__actions {
  display: flex;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.ref-action-btn {
  flex: 1;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.ref-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.95);
}

.ref-action-btn--danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #ef4444;
}

.ref-action-btn--danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* Empty State */
.ref-links-empty {
  text-align: center;
  padding: 64px 32px;
}

.ref-links-empty svg {
  opacity: 0.3;
  margin-bottom: 16px;
}

.ref-links-empty p {
  color: rgba(255, 255, 255, 0.6);
  font-size: 16px;
}

/* Loading State */
.ref-links-loading {
  text-align: center;
  padding: 48px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(139, 92, 246, 0.2);
  border-top-color: #8b5cf6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========================================
   MODAL
   ======================================== */

.ref-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.ref-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.ref-modal__content {
  position: relative;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  animation: slideUp 0.3s ease;
}

.ref-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.ref-modal__header h3 {
  font-size: 24px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  margin: 0;
}

.ref-modal__close {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: rgba(255, 255, 255, 0.6);
}

.ref-modal__close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   FORM
   ======================================== */

.ref-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.ref-form__group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ref-form__group label {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
}

.ref-form__group input,
.ref-form__group select,
.ref-form__group textarea {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px 16px;
  color: rgba(255, 255, 255, 0.95);
  font-size: 14px;
  transition: all 0.2s ease;
}

.ref-form__group input:focus,
.ref-form__group select:focus,
.ref-form__group textarea:focus {
  outline: none;
  border-color: rgba(139, 92, 246, 0.5);
  background: rgba(0, 0, 0, 0.4);
}

.ref-form__group small {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.ref-form__actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.ref-form__actions .ref-btn {
  flex: 1;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
  .ref-links-manager {
    padding: 20px 16px;
    scroll-margin-top: calc(var(--topbar-height) + 32px); /* Dynamic space for mobile header */
  }

  .ref-links-header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }
  
  .ref-create-btn {
    width: 100%;
    justify-content: center;
  }

  .ref-link-card {
    padding: 16px;
  }

  .ref-link-card__header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .ref-link-card__stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
  
  .ref-stat-item__value {
    font-size: 18px;
  }
  
  .ref-stat-item__label {
    font-size: 10px;
  }

  .ref-link-card__url {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }
  
  .ref-link-card__url-input {
    font-size: 12px;
    text-align: center;
    padding: 8px 0;
  }
  
  .ref-link-card__copy-btn {
    width: 100%;
    justify-content: center;
  }

  .ref-link-card__actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .ref-action-btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 140px;
    justify-content: center;
  }

  .ref-modal__content {
    padding: 24px 20px;
    width: 95%;
    max-width: none;
  }
  
  .ref-qr-modal__content {
    width: 95%;
    max-width: none;
  }
}

@media (max-width: 480px) {
  .ref-links-manager {
    padding: 16px 12px;
    scroll-margin-top: calc(var(--topbar-height) + 40px); /* Dynamic space for small mobile screens */
  }

  .ref-link-card {
    padding: 14px;
  }

  .ref-link-card__stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .ref-stat-item__value {
    font-size: 16px;
  }
  
  .ref-stat-item__label {
    font-size: 9px;
  }
  
  .ref-link-card__actions {
    flex-direction: column;
  }
  
  .ref-action-btn {
    width: 100%;
    min-width: auto;
  }
  
  .ref-modal__content {
    padding: 20px 16px;
  }
  
  .ref-modal__header h3 {
    font-size: 18px;
  }
  
  .ref-form-group label {
    font-size: 13px;
  }
  
  .ref-form-input,
  .ref-form-select {
    padding: 10px 12px;
    font-size: 14px;
  }
  
  .ref-qr-modal__content {
    padding: 20px 16px;
  }
  
  .ref-qr-actions {
    flex-direction: column;
    gap: 10px;
  }
  
  .ref-qr-actions .ref-btn {
    width: 100%;
  }
}

/* ========================================
   QR CODE MODAL
   ======================================== */

.ref-qr-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s ease;
}

.ref-qr-modal__content {
  background: rgba(30, 30, 46, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 32px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s ease;
}

.ref-qr-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.ref-qr-modal__header h3 {
  font-size: 24px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  margin: 0;
}

.ref-qr-modal__close {
  background: none;
  border: none;
  font-size: 32px;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.3s ease;
}

.ref-qr-modal__close:hover {
  color: rgba(255, 255, 255, 0.95);
}

.ref-qr-modal__body {
  text-align: center;
}

.ref-qr-image-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;
}

.ref-qr-image {
  width: 100%;
  max-width: 300px;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.ref-qr-error {
  text-align: center;
  padding: 40px 20px;
}

.ref-qr-error i {
  font-size: 48px;
  color: #ef4444;
  margin-bottom: 16px;
}

.ref-qr-error p {
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 20px;
}

.ref-qr-url {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
  word-break: break-all;
  margin: 0 0 24px 0;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.ref-qr-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
