/* ==============================================
   GETINFORSEARCH - REFACTORED STYLESHEET V5.4
============================================== */

/* === 1. DESIGN TOKENS & BASE STYLES === */
:root {
  /* Colors */
  --bg-start: #f4f7f9;
  --bg-end: #e6eaf0;
  --surface: #ffffff;
  --text-primary: #1a202c;
  --text-secondary: #5a6474;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --border-color: #d1d8e0;
  --shadow-color: rgba(45, 55, 72, 0.1);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Sizing & Radius */
  --header-height: 76px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Effects */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-image: linear-gradient(135deg, var(--bg-start), var(--bg-end));
  color: var(--text-primary);
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main {
  flex-grow: 1;
}

/* === 2. HEADER & NAVIGATION === */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 4px 12px var(--shadow-color);
  position: sticky;
  top: 0;
  z-index: 1000;
  min-height: var(--header-height);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
}

.header-logo {
  height: 50px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

nav {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-grow: 1;
  justify-content: center;
}

.nav-link {
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  box-shadow: 0 1px 2px var(--shadow-color);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.nav-link:hover {
  color: var(--primary);
  background-color: var(--surface);
  border-color: var(--border-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--shadow-color);
}

.nav-link.active {
  color: #fff;
  background-color: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.4);
  transform: translateY(0);
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: 5px;
  left: 20%;
  right: 20%;
  height: 2px;
  background-color: #fff;
  animation: expand-underline 0.4s ease forwards;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.mobile-menu-toggle {
  display: none;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.mobile-menu-toggle:hover {
  background-color: var(--bg-start);
}

/* Consolidated UI Icon Buttons */
#theme-toggle,
#history-toggle-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  font-size: 1.2rem;
}

#theme-toggle:hover,
#history-toggle-button:hover {
  color: var(--primary);
  background-color: var(--bg-start);
  transform: scale(1.1);
}

/* Desktop-only hover effect */
@media (min-width: 769px) and (hover: hover) {
  .site-header {
    transform: translateY(-80%);
    opacity: 0.8;
  }
  .site-header:hover,
  .site-header:focus-within {
    transform: translateY(0);
    opacity: 1;
  }
}

/* === 3. HISTORY DROPDOWN === */
#history-container {
  position: fixed;
  top: 5rem;
  right: 1.5rem;
  width: 350px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 24px var(--shadow-color);
  z-index: 2000;
  padding: 0;
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
  visibility: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

#history-container.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--surface);
  position: sticky;
  top: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.clear-history-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.85rem;
  transition: var(--transition);
}

.clear-history-btn:hover {
  background-color: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.history-item {
  padding: 0.75rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.2s ease;
  margin: 0 0.5rem 0.5rem;
}

.history-item:hover {
  background-color: var(--bg-start);
}

.history-item p {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .question {
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.history-item .answer {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* === 4. LAYOUT & CONTENT SECTIONS === */
.content-section {
  display: none;
}

.content-section.active {
  display: block;
}

#home .main-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4vh 2vw;
  min-height: calc(100vh - var(--header-height));
}

#home .container {
  width: 100%;
  max-width: 720px;
  text-align: center;
}

#home .logo {
  width: 350px;
  max-width: 80%;
  height: auto;
  margin-bottom: 2rem;
  opacity: 0.9;
}

.page-container {
  max-width: 800px;
  margin: 2rem auto;
  padding: 2rem;
  background-color: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 6px 16px var(--shadow-color);
  text-align: left;
}

.page-container h1 {
  margin-top: 0;
  color: var(--text-primary);
  font-size: clamp(1.5rem, 4vw, 2.5rem);
}

.page-container p {
  line-height: 1.7;
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 1.2rem;
}

/* === 5. SEARCH FORM === */
#search-form {
  display: flex;
  width: 100%;
  margin: 0 auto 1.5rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-full);
  background: var(--surface);
  box-shadow: 0 4px 12px var(--shadow-color);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

#search-form:hover,
#search-form:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2), 0 8px 20px var(--shadow-color);
  transform: translateY(-2px);
}

#search-input {
  flex-grow: 1;
  padding: 1rem 1.5rem;
  border: none;
  font-size: 1.1rem;
  background-color: transparent;
  color: var(--text-primary);
  border-radius: var(--radius-full) 0 0 var(--radius-full);
  outline: none;
  min-width: 0;
}

#search-input::placeholder {
  color: #9ca3af;
  transition: opacity 0.3s ease;
}

#search-form button {
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

#search-form button[type="submit"] {
  padding: 0 1.5rem;
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
  background: var(--primary);
  color: #fff;
  font-weight: 500;
  gap: 0.5rem;
  min-width: 60px;
}

#search-form button[type="submit"]:hover {
  background: var(--primary-hover);
}

#mic-button {
  background: transparent;
  padding: 0 1rem;
  color: var(--text-secondary);
  min-width: 44px;
}

#mic-button:hover {
  color: var(--primary);
}

#mic-button.listening {
  color: #ef4444;
  animation: pulse 1.5s infinite;
}

/* === 6. RESPONSE CONTAINER === */
#response-container {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: left;
  position: relative;
  box-shadow: 0 6px 16px var(--shadow-color);
  display: none;
  animation: fadeIn 0.5s;
  width: 100%;
  margin-top: 1rem;
}

#response-text {
  line-height: 1.7;
  font-size: 1.1rem;
  color: var(--text-primary);
}

#response-text p:not(:last-child) {
  margin-bottom: 1em;
}

#response-text strong {
  color: var(--primary);
  font-weight: 600;
}

.citations-container {
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg-start);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

#copy-button {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.5rem;
  background: #f1f5f9;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  transition: var(--transition);
}

#copy-button.copied {
  background: #10b981;
  color: white;
}

#copy-button:not(.copied):hover {
  background: #e2e8f0;
}

/* === 7. LOADING & FOOTER === */
#loading-indicator {
  display: none;
  padding: 2rem 0;
}

.typing-indicator {
  display: flex;
  justify-content: center;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  margin: 0 3px;
  background-color: var(--primary);
  border-radius: 50%;
  animation: typing 1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

.site-footer {
  margin-top: auto;
  padding: 2rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
  opacity: 0.8;
  border-top: 1px solid var(--border-color);
}

/* === 8. DARK MODE === */
[data-theme="dark"] {
  --bg-start: #1a202c;
  --bg-end: #2d3748;
  --surface: #2d3748;
  --text-primary: #f7fafc;
  --text-secondary: #a0aec0;
  --primary: #4299e1;
  --primary-hover: #2b6cb0;
  --border-color: #4a5568;
  --shadow-color: rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .history-item:hover {
  background-color: #4a5568;
}

[data-theme="dark"] #copy-button {
  background: #4a5568;
  color: var(--text-primary);
  border-color: #718096;
}

[data-theme="dark"] #copy-button:hover:not(.copied) {
  background: #718096;
}

[data-theme="dark"] .page-container {
  background-color: #1a202c;
}

[data-theme="dark"] #home .logo,
[data-theme="dark"] .header-logo {
  filter: invert(0.8) sepia(0.5) hue-rotate(180deg) saturate(1.5) brightness(1.1) contrast(1.2);
  opacity: 1;
}

[data-theme="dark"] .nav-link {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .nav-link:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .nav-link.active {
  background-color: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 4px 10px rgba(66, 153, 225, 0.4);
}

[data-theme="dark"] .clear-history-btn {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-secondary);
}

[data-theme="dark"] .clear-history-btn:hover {
  background-color: var(--primary);
  color: #1a202c;
  border-color: var(--primary);
}

[data-theme="dark"] .mobile-menu-toggle {
  color: var(--text-primary);
}

/* === 9. KEYFRAMES === */
@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@keyframes typing {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes expand-underline {
  from {
    width: 0;
    left: 50%;
  }
  to {
    width: 60%;
    left: 20%;
  }
}

/* === 10. RESPONSIVE & ACCESSIBILITY === */

/* Tablet styles */
@media (max-width: 1024px) {
  .page-container {
    margin: 1.5rem;
    padding: 1.5rem;
  }
  #home .logo {
    width: 300px;
  }
  #history-container {
    width: 320px;
    right: 1rem;
  }
  .nav-link {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
  }
}

/* Mobile styles */
@media (max-width: 768px) {
  .site-header {
    padding: 0.5rem 1rem;
    min-height: auto;
    /* !important is used to override the desktop hover effect on mobile */
    transform: translateY(0) !important;
    opacity: 1 !important;
  }
  .header-logo {
    height: 40px;
  }
  .mobile-menu-toggle {
    display: block;
    order: 2;
  }
  nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    box-shadow: 0 4px 12px var(--shadow-color);
    z-index: 1001;
  }
  nav.mobile-nav-open {
    display: flex;
  }
  .nav-link {
    margin: 0.25rem 1rem;
    text-align: center;
    border-radius: var(--radius-md);
  }
  .header-actions {
    order: 3;
    gap: 0.5rem;
  }
  #theme-toggle,
  #history-toggle-button {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
  #history-container {
    top: 65px;
    bottom: auto;
    right: 1rem;
    left: auto;
    width: 320px;
    max-height: 60vh;
  }
  #home .main-wrapper {
    padding: 2vh 1rem;
  }
  #home .logo {
    width: 250px;
    margin-bottom: 1.5rem;
  }
  #search-form {
    margin-bottom: 1rem;
  }
  #search-input {
    font-size: 1rem;
    padding: 0.875rem 1rem;
  }
  #search-form button[type="submit"] {
    padding: 0 1rem;
  }
  #mic-button {
    padding: 0 0.75rem;
  }
  #response-container {
    padding: 1.5rem;
    margin-top: 1rem;
  }
  #response-text {
    font-size: 1rem;
  }
  #copy-button {
    position: static;
    margin-top: 1rem;
    align-self: flex-start;
  }
  .page-container {
    margin: 1rem;
    padding: 1.5rem;
  }
  .citations-container {
    margin-top: 1rem;
    padding: 0.5rem 0.75rem;
  }
}

/* Small mobile styles */
@media (max-width: 480px) {
  .site-header {
    padding: 0.5rem;
  }
  #home .logo {
    width: 200px;
  }
  #search-input {
    font-size: 0.95rem;
    padding: 0.75rem;
  }
  .page-container {
    margin: 0.5rem;
    padding: 1rem;
  }
  .nav-link {
    font-size: 0.9rem;
    padding: 0.65rem 1rem;
  }
  /* NOTE: Removed a conflicting #history-container rule here for consistent UI. */
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print styles */
@media print {
  body {
    background: white !important;
    color: black !important;
  }
  .site-header,
  .site-footer,
  #search-form,
  #copy-button,
  .mobile-menu-toggle,
  #theme-toggle,
  #history-toggle-button {
    display: none !important;
  }
  .page-container,
  #response-container {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
  }
}