/*
  © 2025 Milos Saric. All rights reserved.
*/

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --text-primary: #0d0d0d;
  --text-secondary: #676767;
  --border-color: #e5e5e5;
  --input-bg: #ffffff;
  --input-border: #d1d1d1;
  --input-focus: #10a37f;
  --button-primary: #10a37f;
  --button-hover: #0d8c6d;
  --button-disabled: #d1d1d1;
  --dropdown-bg: #ffffff;
  --dropdown-hover: #f7f7f8;
  --dropdown-selected: #ececf1;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --primary-gradient: linear-gradient(135deg, #10a37f 0%, #0d8c6d 100%);
  --success-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.dark-mode {
  --bg-primary: #0d0d0d;
  --bg-secondary: #1a1a1a;
  --text-primary: #ececec;
  --text-secondary: #a0a0a0;
  --border-color: #2f2f2f;
  --input-bg: #1a1a1a;
  --input-border: #3f3f3f;
  --input-focus: #19c37d;
  --button-primary: #19c37d;
  --button-hover: #15a569;
  --button-disabled: #3f3f3f;
  --dropdown-bg: #1a1a1a;
  --dropdown-hover: #2f2f2f;
  --dropdown-selected: #2f2f2f;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* ChatGPT-Style Main Section */
.chatgpt-section {
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  background: var(--bg-primary);
}

.chatgpt-container {
  max-width: 768px;
  width: 100%;
  margin: 0 auto;
}

/* Minimal Header */
.minimal-header {
  text-align: center;
  margin-bottom: 2rem;
  animation: fadeIn 0.6s ease-out;
}

.minimal-header h1 {
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin: 0;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Search Box - ChatGPT Style */
.search-box-wrapper {
  position: relative;
  width: 100%;
  animation: fadeIn 0.6s ease-out 0.2s backwards;
}

.search-input-container {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.search-input-container:focus-within {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.1);
}

.minimal-search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 1rem;
  color: var(--text-primary);
  padding: 0.5rem 0;
  font-family: inherit;
}

.minimal-search-input::placeholder {
  color: var(--text-secondary);
}

.send-button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--button-disabled);
  color: #ffffff;
  cursor: not-allowed;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.send-button:not(:disabled) {
  background: var(--button-primary);
  cursor: pointer;
}

.send-button:not(:disabled):hover {
  background: var(--button-hover);
  transform: scale(1.05);
}

.send-button:not(:disabled):active {
  transform: scale(0.95);
}

.send-button svg {
  transition: transform 0.2s ease;
}

.send-button:not(:disabled):hover svg {
  transform: translateX(2px);
}

/* Dropdown - Minimal & Clean */
.minimal-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--dropdown-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-height: 400px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  animation: dropdownSlide 0.2s ease-out;
}

@keyframes dropdownSlide {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.minimal-dropdown::-webkit-scrollbar {
  width: 6px;
}

.minimal-dropdown::-webkit-scrollbar-track {
  background: transparent;
}

.minimal-dropdown::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.minimal-dropdown::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

.autocomplete-item {
  padding: 0.875rem 1rem;
  cursor: pointer;
  transition: background 0.15s ease;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9375rem;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--dropdown-hover);
}

.autocomplete-item mark {
  background: rgba(16, 163, 127, 0.15);
  color: var(--text-primary);
  font-weight: 600;
  padding: 1px 2px;
  border-radius: 3px;
}

/* Loading State - Minimal */
.minimal-loading {
  text-align: center;
  padding: 3rem 0;
  animation: fadeIn 0.3s ease-out;
}

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

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

.minimal-loading p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin: 0;
}

/* Error State - Minimal */
.minimal-error {
  text-align: center;
  padding: 3rem 2rem;
  animation: fadeIn 0.3s ease-out;
}

.minimal-error svg {
  color: #ef4444;
  margin-bottom: 1rem;
}

.minimal-error h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.5rem 0;
}

.minimal-error p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin: 0 0 1.5rem 0;
}

.retry-button {
  background: var(--button-primary);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.retry-button:hover {
  background: var(--button-hover);
  transform: translateY(-1px);
}

.retry-button:active {
  transform: translateY(0);
}

/* Results Section - FULL SCREEN TAKEOVER (Keep existing styles) */
#resultsSection {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg-primary);
  z-index: 10000;
  overflow-y: auto;
  animation: explosiveReveal 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  padding: 2rem;
}

@keyframes explosiveReveal {
  0% {
    opacity: 0;
    transform: scale(0.3) rotate(-5deg);
    clip-path: circle(0% at 50% 50%);
  }
  50% {
    clip-path: circle(50% at 50% 50%);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    clip-path: circle(100% at 50% 50%);
  }
}

.results-header-cell {
  text-align: center;
  padding: 3rem 2rem;
  background: transparent;
  border: none;
  box-shadow: none;
  margin-bottom: 2rem;
  animation: fadeInUp 0.8s ease-out 0.4s backwards;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.results-header-cell h2 {
  font-size: 4rem;
  font-weight: 900;
  background: var(--success-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 1rem;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  animation: textBounce 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.5s backwards;
}

@keyframes textBounce {
  0% {
    transform: scale(0.5) translateY(-50px);
    opacity: 0;
  }
  60% {
    transform: scale(1.1) translateY(0);
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

.results-subtitle {
  font-size: 1.5rem;
  color: var(--text-secondary);
  margin: 0;
  font-weight: 600;
  animation: fadeInUp 0.8s ease-out 0.6s backwards;
}

#recommendationsList {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  padding: 2rem 0;
}

/* Book Card - Modern Card Design */
.book-card {
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  animation: cardPop 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) backwards;
  animation-delay: calc(var(--index, 0) * 0.1s);
}

@keyframes cardPop {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(30px) rotate(-5deg);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0) rotate(0deg);
  }
}

.book-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: var(--primary-gradient);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

.book-card:hover::before {
  transform: scaleX(1);
}

.book-card:hover {
  border-color: var(--button-primary);
  box-shadow: var(--shadow-lg);
  transform: translateY(-10px) scale(1.02);
}

.book-rank {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  width: 60px;
  height: 60px;
  background: var(--primary-gradient);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(16, 163, 127, 0.4);
  animation: rankSpin 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) backwards;
  animation-delay: calc(var(--index, 0) * 0.1s + 0.2s);
}

@keyframes rankSpin {
  from {
    transform: rotate(-360deg) scale(0);
  }
  to {
    transform: rotate(0deg) scale(1);
  }
}

.book-info {
  padding-right: 4rem;
}

.book-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1rem;
  line-height: 1.4;
}

.similarity-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(16, 163, 127, 0.1);
  color: var(--button-primary);
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid rgba(16, 163, 127, 0.2);
}

.similarity-badge svg {
  width: 18px;
  height: 18px;
  animation: starPulse 2s ease-in-out infinite;
}

@keyframes starPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* Close Button for Results */
.close-results-btn {
  position: fixed;
  top: 2rem;
  right: 2rem;
  width: 60px;
  height: 60px;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.4);
  transition: all 0.3s ease;
  z-index: 10001;
  animation: fadeInUp 0.6s ease-out 0.8s backwards;
}

.close-results-btn:hover {
  background: #dc2626;
  transform: scale(1.1) rotate(90deg);
  box-shadow: 0 12px 32px rgba(239, 68, 68, 0.6);
}

.close-results-btn svg {
  width: 28px;
  height: 28px;
}

/* Author Section */
/* Author Section - Minimalistic Floating Card */
.author-section {
  position: fixed;
  top: 6rem;
  right: 2rem;
  z-index: 9999;
  animation: slideInRight 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.5s backwards;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100px) rotate(10deg);
  }
  to {
    opacity: 1;
    transform: translateX(0) rotate(0deg);
  }
}

.author-card {
  background: var(--input-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 180px;
  position: relative;
  overflow: hidden;
}

/* Dark mode enhancement */
.dark-mode .author-card {
  background: rgba(26, 26, 26, 0.95);
  border-color: var(--input-border);
}

.author-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--primary-gradient);
  transform: scaleX(0);
  transition: transform 0.4s ease;
}

.author-card:hover::before {
  transform: scaleX(1);
}

.author-card:hover {
  border-color: var(--button-primary);
  box-shadow: var(--shadow-lg), 0 0 30px rgba(16, 163, 127, 0.2);
  transform: translateY(-8px) scale(1.05);
}

.author-image {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  position: relative;
}

.author-image::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--primary-gradient);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.author-card:hover .author-image::before {
  opacity: 1;
  animation: rotateBorder 3s linear infinite;
}

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

.author-image img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--bg-primary);
  display: block;
  transition: all 0.3s ease;
  background: var(--bg-secondary);
}

.dark-mode .author-image img {
  border-color: var(--bg-secondary);
}

.author-card:hover .author-image img {
  transform: scale(1.1);
}

.author-info {
  text-align: center;
  width: 100%;
}

.author-info h3 {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 0.25rem 0;
}

.author-info h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.25rem 0;
  line-height: 1.2;
}

.author-title {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin: 0 0 1rem 0;
  line-height: 1.3;
}

.author-socials {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  width: 100%;
}

.author-socials a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  text-decoration: none;
  position: relative;
}

.author-socials a::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-sm);
  background: var(--primary-gradient);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.author-socials a:hover::before {
  opacity: 1;
}

.author-socials a:hover {
  color: white;
  transform: translateY(-4px) rotate(360deg);
  box-shadow: 0 8px 16px rgba(16, 163, 127, 0.4);
}

.author-socials svg {
  width: 16px;
  height: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .minimal-header h1 {
    font-size: 1.5rem;
  }

  .chatgpt-section {
    padding: 2rem 1rem;
  }

  .results-header-cell h2 {
    font-size: 2.5rem;
  }

  .results-subtitle {
    font-size: 1.25rem;
  }

  #recommendationsList {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding: 1rem 0;
  }

  .book-card {
    padding: 1.5rem;
  }

  .book-rank {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
  }

  .book-title {
    font-size: 1.25rem;
  }

  .author-card {
    flex-direction: column;
    text-align: center;
    padding: 2rem 1.5rem;
  }

  .author-image {
    width: 120px;
    height: 120px;
  }

  .author-info h2 {
    font-size: 1.5rem;
  }

  .author-socials {
    justify-content: center;
  }

  .close-results-btn {
    top: 1rem;
    right: 1rem;
    width: 50px;
    height: 50px;
  }
}

@media (max-width: 480px) {
  .minimal-header h1 {
    font-size: 1.25rem;
  }

  .results-header-cell h2 {
    font-size: 2rem;
  }

  #resultsSection {
    padding: 1rem;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Add this to the end of your book-recommender.css file */

/* Mobile Fix for Author Section */
@media (max-width: 768px) {
  .author-section {
    position: static; /* Remove fixed positioning on mobile */
    top: auto;
    right: auto;
    width: 100%;
    padding: 2rem 1rem;
    margin-top: 2rem;
    animation: none; /* Remove slide animation on mobile */
  }

  .author-card {
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .author-section {
    padding: 1.5rem 1rem;
  }
  
  .author-card {
    padding: 1.5rem;
  }
  
  .author-image {
    width: 100px !important;
    height: 100px !important;
  }
  
  .author-info h2 {
    font-size: 1.25rem !important;
  }
  
  .author-title {
    font-size: 0.8rem !important;
  }
}

/* 
  Z-Index Fix for Author Section
  Add this to your book-recommender.css file
  This ensures the mega menu appears above the author card
*/

/* Update the author section z-index - DESKTOP ONLY */
.author-section {
  z-index: 100; /* Reduced from 9999 - should be below mega menu */
}

/* Keep the fixed positioning only on desktop */
@media (min-width: 769px) {
  .author-section {
    position: fixed;
    top: 6rem;
    right: 2rem;
    animation: slideInRight 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.5s backwards;
  }
}

/* Mobile: Author section at bottom (static positioning) */
@media (max-width: 768px) {
  .author-section {
    position: static;
    top: auto;
    right: auto;
    width: 100%;
    padding: 2rem 1rem;
    margin-top: 2rem;
    animation: none;
  }

  .author-card {
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .author-section {
    padding: 1.5rem 1rem;
  }
  
  .author-card {
    padding: 1.5rem;
  }
  
  .author-image {
    width: 100px !important;
    height: 100px !important;
  }
  
  .author-info h2 {
    font-size: 1.25rem !important;
  }
  
  .author-title {
    font-size: 0.8rem !important;
  }
}

/* Ensure results section is highest when visible */
#resultsSection {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg-primary);
  z-index: 10000; /* Keep this high as it's a full-screen overlay */
  overflow-y: auto;
  animation: explosiveReveal 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  padding: 2rem;
}

/* Close button should be above results */
.close-results-btn {
  position: fixed;
  top: 2rem;
  right: 2rem;
  width: 60px;
  height: 60px;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.4);
  transition: all 0.3s ease;
  z-index: 10001; /* Above results section */
  animation: fadeInUp 0.6s ease-out 0.8s backwards;
}

/* 
  Z-Index Hierarchy for reference:
  - Mega Menu: typically 1000-9999 (check your header.php/global CSS)
  - Author Section: 100 (below mega menu)
  - Results Section: 10000 (full-screen overlay)
  - Close Button: 10001 (above results)
*/

/* Add this to your book-recommender.css file */

/* Fix pull-to-refresh on mobile devices */
#resultsSection {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg-primary);
  z-index: 10000;
  overflow-y: auto;
  animation: explosiveReveal 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  padding: 2rem;
  
  /* CRITICAL FIX: Enable pull-to-refresh on mobile */
  overscroll-behavior-y: contain; /* Prevents parent scroll but allows pull-to-refresh */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Alternative fix if the above doesn't work on all devices */
@supports (-webkit-touch-callout: none) {
  /* iOS-specific fix */
  #resultsSection {
    overscroll-behavior-y: auto;
  }
}

/* Ensure the main content doesn't interfere when results are shown */
body.results-active {
  overflow: hidden;
  overscroll-behavior-y: none; /* Disable pull-to-refresh on main body when results are open */
}

/* When results are NOT showing, allow normal pull-to-refresh */
body:not(.results-active) {
  overscroll-behavior-y: auto;
}