/**
 * AI Summary Plugin Styles
 * Version: 1.0.0
 */

/* AI Summary Button in TOC */
.ai-summary-btn-toc {
  font-size: 16px !important;
  padding: 12px 24px !important;
  font-weight: 600 !important;
  border-radius: 8px !important;
  transition: all 0.3s ease !important;
  box-shadow: 0 2px 8px rgba(58, 83, 126, 0.3) !important;
}

.ai-summary-btn-toc .ai-icon {
  font-size: 18px !important;
}

/* TOC Header Layout - Side by side on desktop */
@media (min-width: 768px) {
  .elementor-toc__header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 15px !important;
  }
  
  .elementor-toc__header-title {
    flex: 1 !important;
    margin: 0 !important;
  }
  
  .ai-summary-btn-toc {
    width: auto !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }
}

/* Mobile responsiveness */
@media (max-width: 767px) {
  .elementor-toc__header {
    flex-direction: column !important;
    gap: 10px !important;
  }
  
  .ai-summary-btn-toc {
    width: 100% !important;
    margin-top: 10px !important;
  }
}

.ai-summary-btn:hover {
  background: #2d3f5f;
}

/* Generated button state - clickable to scroll to summary */
.ai-summary-btn-generated {
  background: #2d5e3f !important; /* Green tint to show it's complete */
  cursor: pointer !important;
}

.ai-summary-btn-generated:hover {
  background: #245431 !important;
}

.ai-summary-container {
  margin: 15px 0 30px 0;
  padding: 0;
  clear: both;
}

.ai-summary-container .buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ai-summary-btn {
  background: #3a537e;
  color: white;
  border: none;
  padding: 12px 28px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.ai-summary-saved-btn {
  background: #059669;
}

.ai-summary-saved-btn:hover {
  background: #047857;
}

.ai-summary-btn:hover {
  background: #2d3f5f;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(58, 83, 126, 0.4);
}

.ai-summary-regenerate-btn {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
  margin-left: 10px;
  display: none !important; /* Hidden by default, uncomment for debugging */
}

.ai-summary-regenerate-btn:hover {
  background: linear-gradient(135deg, #495057 0%, #343a40 100%);
}

.ai-summary-btn:disabled,
.ai-summary-regenerate-btn:disabled {
  background: #9ca3af !important;
  cursor: not-allowed !important;
  transform: none !important;
  box-shadow: none !important;
  opacity: 0.6 !important;
  pointer-events: none !important;
}

.ai-summary-btn .ai-icon {
  font-size: 16px;
  display: inline-block;
  line-height: 1;
}

.ai-summary-header .ai-icon {
  font-size: 18px;
}

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

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.6s linear infinite;
}

.ai-summary-btn .spinner {
  margin-right: 5px;
}

@media (max-width: 600px) {
  .ai-summary-container .buttons {
    flex-direction: column;
  }
  
  .ai-summary-btn,
  .ai-summary-regenerate-btn {
    width: 100%;
    justify-content: center;
  }
}

.ai-summary-content {
  display: none;
  margin-top: 20px;
  margin-bottom: 30px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  overflow: hidden;
  background: white;
}

/* Responsive max-width */
@media (max-width: 768px) {
  .ai-summary-content {
    margin-left: 0;
    margin-right: 0;
  }
  
  .ai-summary-text {
    padding: 20px;
  }
}

.ai-summary-header {
  background-color: #273754;
  color: white;
  padding: 15px 20px;
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.ai-summary-text {
  background: #f8f9fa;
  padding: 30px;
  border-radius: 0 0 6px 6px;
  font-size: 15px;
  line-height: 1.7;
  color: #2d3748;
}

/* Relative positioning to contain Speechify widget */
.ai-summary-content {
  position: relative;
}

/* Contain and center Speechify widget in summary */
.ai-summary-text > div:first-child,
.ai-summary-text [class*="speechify"],
.ai-summary-text iframe[src*="speechify"] {
  max-width: 600px !important;
  margin-left: auto !important;
  margin-right: auto !important;
  display: block !important;
}

/* Specific styling for speechify-root inside AI summary */
.ai-summary-content #speechify-root,
.ai-summary-text #speechify-root {
  max-width: 50% !important;
  width: 50% !important;
  display: block !important;
  margin-left: auto !important;
  margin-right: auto !important;
  position: relative !important;
}

/* Position the Speechify floating widget within the AI summary container */
.ai-summary-content #speechify-root > div,
.ai-summary-content #speechify-root iframe {
  position: absolute !important;
  bottom: 20px !important;
  right: 20px !important;
  left: auto !important;
  top: auto !important;
  z-index: 100 !important;
  pointer-events: all !important;
}

/* Keep the inline player centered */
.ai-summary-text > div[class*="speechify"]:first-child {
  position: static !important;
  margin: 0 auto 20px !important;
}

.ai-summary-text p {
  margin: 0 0 16px 0;
  line-height: 1.8;
}

.ai-summary-text p:last-child {
  margin-bottom: 0;
}

.ai-summary-text h3 {
  color: #1a202c;
  font-size: 18px;
  font-weight: 600;
  margin: 30px 0 16px 0;
  padding-bottom: 8px;
  border-bottom: 2px solid #e2e8f0;
}

.ai-summary-text h3:first-child {
  margin-top: 0;
}

.ai-summary-text h4 {
  color: #2d3748;
  font-size: 16px;
  font-weight: 600;
  margin: 20px 0 10px 0;
}

.ai-summary-text ul {
  margin: 16px 0;
  padding-left: 0;
  list-style: none;
}

.ai-summary-text ul li {
  margin-bottom: 12px;
  padding-left: 28px;
  position: relative;
  line-height: 1.7;
}

.ai-summary-text ul li:before {
  content: "•";
  color: #4F46E5;
  font-weight: bold;
  font-size: 20px;
  position: absolute;
  left: 8px;
}

.ai-summary-text ol {
  margin: 16px 0;
  padding-left: 28px;
  counter-reset: item;
}

.ai-summary-text ol li {
  margin-bottom: 12px;
  line-height: 1.7;
}

.ai-summary-text strong,
.ai-summary-text b {
  color: #1a202c;
  font-weight: 600;
}

.ai-summary-text em,
.ai-summary-text i {
  font-style: italic;
  color: #4a5568;
}

/* AI Anchor Links in Summary */
.ai-summary-link {
  color: #667eea;
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px dashed #667eea;
  transition: all 0.2s ease;
  cursor: pointer;
}

.ai-summary-link:hover {
  color: #764ba2;
  border-bottom-color: #764ba2;
  background: rgba(102, 126, 234, 0.1);
  border-radius: 3px;
  padding: 2px 4px;
  margin: -2px -4px;
}

/* Highlighted anchor target in content */
.ai-anchor-target {
  position: relative;
  scroll-margin-top: 100px;
}

.ai-anchor-highlight {
  background: linear-gradient(120deg, rgba(255, 230, 109, 0.6) 0%, rgba(255, 242, 161, 0.5) 100%);
  box-shadow: 0 0 0 8px rgba(255, 230, 109, 0.3);
  border-radius: 4px;
  padding: 4px;
  margin: -4px;
  transition: all 0.3s ease;
  animation: highlightPulse 2s ease-in-out;
}

@keyframes highlightPulse {
  0%, 100% { 
    box-shadow: 0 0 0 8px rgba(255, 230, 109, 0.3); 
  }
  50% { 
    box-shadow: 0 0 0 12px rgba(255, 230, 109, 0.5),
                0 0 20px rgba(255, 230, 109, 0.3); 
    transform: scale(1.01);
  }
}

.ai-summary-link:after {
  content: "↗";
  font-size: 11px;
  margin-left: 3px;
  opacity: 0.7;
}

/* Section Reference Links (# links) */
.section-ref-link {
  color: #a0aec0;
  text-decoration: none;
  font-size: 12px;
  font-weight: bold;
  margin-right: 6px;
  opacity: 0;
  transition: opacity 0.2s ease, color 0.2s ease;
  cursor: pointer;
}

li:hover .section-ref-link {
  opacity: 1;
}

.section-ref-link:hover {
  color: #667eea;
  text-decoration: none;
}

@media (max-width: 768px) {
  .section-ref-link {
    opacity: 0.5;
  }
  
  li:hover .section-ref-link {
    opacity: 1;
  }
}

.ai-summary-error {
  background: #f8d7da;
  color: #721c24;
  padding: 15px 20px;
  border-radius: 6px;
  margin: 15px 0;
  font-size: 14px;
}

.ai-summary-status {
  background: #cce5ff;
  color: #004085;
  padding: 15px 20px;
  border-radius: 6px;
  margin: 15px 0;
  font-size: 14px;
  text-align: center;
}

.ai-summary-status .spinner {
  display: inline-block;
  margin-right: 8px;
  vertical-align: middle;
}

/* Responsive styles */
@media (max-width: 768px) {
  .ai-summary-btn {
    padding: 10px 20px;
    font-size: 13px;
  }
  
  .ai-summary-text {
    padding: 20px;
    font-size: 14px;
  }
  
  .ai-summary-header {
    padding: 12px 15px;
    font-size: 15px;
  }
}
