/**
 * saveButton.css - Save Button Component Styling
 * The Stoic Wire
 * 
 * Complete version including toast notifications for JWT expiry handling
 */

/* ========================================= */
/* CSS VARIABLES                             */
/* ========================================= */

:root {
  /* Button Colors */
  --save-btn-accent: #a67c52;
  --save-btn-accent-hover: #8b6644;
  --save-btn-dark: #2a2a2a;
  --save-btn-dark-hover: #3a3a3a;
  --save-btn-light: #ffffff;
  --save-btn-light-hover: #f0f0f0;
  --save-btn-border-light: rgba(0, 0, 0, 0.1);
  
  /* Icon colors */
  --save-icon-dark: #2a2a2a;
  --save-icon-light: #ffffff;
  
  /* Toast colors */
  --toast-info: #17a2b8;
  --toast-success: #28a745;
  --toast-error: #dc3545;
  --toast-warning: #ffc107;
  --toast-dark: #33302e;
  --toast-action-bg: rgba(255, 255, 255, 0.2);
  --toast-action-bg-hover: rgba(255, 255, 255, 0.3);
  
  /* Typography */
  --font-primary: 'EB Garamond', Georgia, serif;
  
  /* Shadows */
  --save-btn-shadow: 0 4px 12px rgba(166, 124, 82, 0.3);
  --toast-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  
  /* Animations */
  --animation-duration: 0.6s;
  --animation-timing: cubic-bezier(0.4, 0, 0.2, 1);
  --transition-speed: 0.2s;
}

/* ========================================= */
/* TOAST CONTAINER & NOTIFICATIONS           */
/* ========================================= */

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

.toast {
  background: var(--toast-dark);
  color: white;
  padding: 14px 20px;
  border-radius: 8px;
  box-shadow: var(--toast-shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  max-width: 420px;
  pointer-events: auto;
  animation: slideIn 0.3s ease-out;
  transition: transform 0.3s ease, opacity 0.3s ease;
  font-family: var(--font-primary);
  font-size: 1rem;
  line-height: 1.4;
  position: relative;
  margin-bottom: 10px;
}

.toast.success {
  background: var(--toast-success);
}

.toast.error {
  background: var(--toast-error);
}

.toast.info {
  background: var(--toast-info);
}

.toast.warning {
  background: var(--toast-warning);
  color: #333;
}

/* Toast Icon */
.toast-icon {
  font-size: 1.2rem;
  font-weight: bold;
  flex-shrink: 0;
}

/* Toast Message */
.toast-message {
  flex-grow: 1;
  font-family: var(--font-primary);
}

/* Toast Action Button */
.toast-action {
  margin-left: auto;
  padding: 6px 14px;
  background: var(--toast-action-bg);
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--transition-speed) ease;
  font-family: var(--font-primary);
}

.toast-action:hover {
  background: var(--toast-action-bg-hover);
  color: white;
  text-decoration: none;
}

.toast.warning .toast-action {
  background: rgba(0, 0, 0, 0.1);
  color: #333;
}

.toast.warning .toast-action:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* Login prompt specific */
.toast-login-prompt {
  min-width: 320px;
}

/* Toast exit animation */
.toast-exit {
  animation: slideOut 0.3s ease-out forwards;
}

/* ========================================= */
/* BASE SAVE BUTTON STYLES                   */
/* ========================================= */

.save-btn {
  position: relative;
  transition: all var(--transition-speed) ease;
}

/* Ensure proper spacing */
.share-buttons-top .save-btn {
  margin-left: 0;
}

/* ========================================= */
/* SAVED STATE                               */
/* ========================================= */

.save-btn.saved {
  background: var(--save-btn-accent) !important;
  border-color: var(--save-btn-accent) !important;
}

.save-btn.saved:hover {
  background: var(--save-btn-accent-hover) !important;
  transform: translateY(-2px);
  box-shadow: var(--save-btn-shadow);
}

.save-btn.saved .share-icon svg {
  fill: var(--save-icon-light);
  stroke: var(--save-icon-light);
}

/* ========================================= */
/* LOADING STATE                             */
/* ========================================= */

.save-loading {
  display: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.save-loading .spinner {
  width: 20px;
  height: 20px;
  animation: spin 1s linear infinite;
}

.save-loading .spinner circle {
  stroke: currentColor;
}

/* ========================================= */
/* ANIMATIONS                                */
/* ========================================= */

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

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

.save-btn.animate-save {
  animation: saveAnimation var(--animation-duration) var(--animation-timing);
}

@keyframes saveAnimation {
  0% {
    transform: scale(1) rotate(0deg);
  }
  50% {
    transform: scale(1.2) rotate(180deg);
  }
  100% {
    transform: scale(1) rotate(360deg);
  }
}

/* ========================================= */
/* DESKTOP STYLES (1024px+)                  */
/* ========================================= */

@media (min-width: 1024px) {
  .share-buttons-top .save-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    background: var(--save-btn-dark);
    border: 1px solid var(--save-btn-dark);
  }
  
  .share-buttons-top .save-btn:hover {
    background: var(--save-btn-accent);
    border-color: var(--save-btn-accent);
  }
  
  .share-buttons-top .save-btn .share-icon svg {
    stroke: var(--save-icon-light);
  }
  
  /* Unsaved state on desktop */
  .share-buttons-top .save-btn:not(.saved) {
    background: var(--save-btn-dark);
    border-color: var(--save-btn-dark);
  }
  
  .share-buttons-top .save-btn:not(.saved):hover {
    background: var(--save-btn-accent);
    border-color: var(--save-btn-accent);
  }
  
  .share-buttons-top .save-btn:not(.saved) .share-icon svg {
    stroke: var(--save-icon-light);
    fill: none;
  }
}

/* ========================================= */
/* TABLET STYLES (769px - 1023px)            */
/* ========================================= */

@media (min-width: 769px) and (max-width: 1023px) {
  .share-buttons-top .save-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    background: var(--save-btn-light);
    border: 1px solid var(--save-btn-border-light);
  }
  
  .share-buttons-top .save-btn:hover,
  .share-buttons-top .save-btn:active {
    background: var(--save-btn-light-hover);
    border-color: var(--save-btn-border-light);
  }
  
  .share-buttons-top .save-btn .share-icon svg {
    stroke: var(--save-icon-dark);
  }
  
  /* Unsaved state on tablet */
  .share-buttons-top .save-btn:not(.saved) {
    background: var(--save-btn-light);
    border-color: var(--save-btn-border-light);
  }
  
  .share-buttons-top .save-btn:not(.saved) .share-icon svg {
    stroke: var(--save-icon-dark);
    fill: none;
  }
}

/* ========================================= */
/* MOBILE STYLES (max-width: 768px)          */
/* ========================================= */

@media (max-width: 768px) {
  /* Toast container adjustments for mobile */
  .toast-container {
    left: 10px;
    right: 10px;
    top: 10px;
  }
  
  .toast {
    width: calc(100% - 20px);
    max-width: none;
    min-width: auto;
    font-size: 0.9rem;
    padding: 12px 16px;
  }
  
  .toast-action {
    padding: 4px 10px;
    font-size: 0.8rem;
  }
  
  /* Save button styles for mobile */
  .share-buttons-top .save-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    background: var(--save-btn-light);
    border: 1px solid var(--save-btn-border-light);
  }
  
  .share-buttons-top .save-btn:hover,
  .share-buttons-top .save-btn:active {
    background: var(--save-btn-light-hover);
    border-color: var(--save-btn-border-light);
  }
  
  .share-buttons-top .save-btn .share-icon svg {
    stroke: var(--save-icon-dark);
  }
  
  /* Unsaved state on mobile */
  .share-buttons-top .save-btn:not(.saved) {
    background: var(--save-btn-light) !important;
    border-color: var(--save-btn-border-light) !important;
  }
  
  .share-buttons-top .save-btn:not(.saved) .share-icon svg {
    stroke: var(--save-icon-dark) !important;
    fill: none !important;
  }
  
  /* Ensure saved state overrides */
  .share-buttons-top .save-btn.saved {
    background: var(--save-btn-accent) !important;
    border-color: var(--save-btn-accent) !important;
  }
  
  .share-buttons-top .save-btn.saved .share-icon svg {
    stroke: var(--save-icon-light) !important;
    fill: var(--save-icon-light) !important;
  }
}

/* ========================================= */
/* UTILITY CLASSES                           */
/* ========================================= */

/* Ensure loading state works across all breakpoints */
.save-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

/* Focus states for accessibility */
.save-btn:focus-visible {
  outline: 2px solid var(--save-btn-accent);
  outline-offset: 2px;
}

/* Remove focus outline for mouse users */
.save-btn:focus:not(:focus-visible) {
  outline: none;
}

/* Share tooltip positioning fix */
.share-buttons-top .save-btn .share-tooltip {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.share-buttons-top .save-btn:hover .share-tooltip {
  opacity: 1;
}