/* GruntSearch - Vagibond Search Engine */

:root {
  --primary: #ff00ff;
  --secondary: #00ffff;
  --bg-dark: #0f0f14;
  --bg-card: #1a1a24;
  --bg-input: #252530;
  --border: #333344;
  --text-primary: #ffffff;
  --text-secondary: #888899;
  --text-muted: #555566;
  --gradient: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  --promoted-bg: #1c1c28;
  --promoted-border: #4a4a5a;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================
   HOMEPAGE STYLES
   ============================================ */

.homepage {
  min-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  padding-top: calc(40px + 36px);
}

.homepage-content {
  width: 100%;
  max-width: 600px;
  text-align: center;
}

.logo-container {
  margin-bottom: 24px;
}

.logo {
  width: 120px;
  height: 120px;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 20px rgba(255, 0, 255, 0.3));
  animation: logo-pulse 3s ease-in-out infinite;
}

@keyframes logo-pulse {
  0%, 100% { filter: drop-shadow(0 0 20px rgba(255, 0, 255, 0.3)); }
  50% { filter: drop-shadow(0 0 40px rgba(255, 0, 255, 0.5)); }
}

.logo-text {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -2px;
}

.logo-grunt {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-search {
  color: var(--text-primary);
}

.tagline {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 32px;
}

/* Search Box */
.search-container {
  width: 100%;
}

.search-box {
  position: relative;
  margin-bottom: 20px;
}

.search-box .search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 16px 100px 16px 48px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: 40px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 0, 255, 0.1);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.voice-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}

.voice-btn:hover {
  color: var(--primary);
  background: rgba(255, 0, 255, 0.1);
}

.voice-btn svg {
  width: 20px;
  height: 20px;
}

/* Search Dropdown */
.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-top: none;
  border-radius: 0 0 20px 20px;
  overflow: hidden;
  display: none;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.search-dropdown.open {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}

.dropdown-item:hover {
  background: rgba(255, 0, 255, 0.1);
}

.dropdown-item svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.dropdown-item-text {
  flex: 1;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-powered {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.dropdown-powered a {
  color: var(--primary);
  text-decoration: none;
}

/* Search Buttons */
.search-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.search-btn {
  padding: 12px 24px;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.search-btn.primary {
  background: var(--gradient);
  color: #000;
}

.search-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(255, 0, 255, 0.4);
}

.search-btn.secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.search-btn.secondary:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Homepage Footer */
.homepage-footer {
  margin-top: 60px;
}

.powered-by {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.powered-by a {
  color: var(--primary);
  text-decoration: none;
}

.powered-by a:hover {
  text-decoration: underline;
}

/* ============================================
   RESULTS PAGE STYLES
   ============================================ */

.results-page {
  min-height: calc(100vh - 36px);
  padding-top: 36px;
}

.results-header {
  position: sticky;
  top: 36px;
  z-index: 50;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.results-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}

.results-logo img {
  width: 40px;
  height: 40px;
}

.results-logo span {
  font-size: 1.2rem;
  font-weight: 700;
}

.results-search-box {
  position: relative;
  flex: 1;
  min-width: 0; /* Allow shrinking */
}

.results-search-box .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

.results-search-box input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.results-search-box input:focus {
  border-color: var(--primary);
}

.results-search-box .search-dropdown {
  border-radius: 0 0 16px 16px;
}

/* Header User Avatar */
.header-user {
  flex-shrink: 0;
  margin-left: auto; /* Push to right */
  padding-left: 16px;
}

.user-avatar-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--gradient);
  padding: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.user-avatar-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 0 16px rgba(255, 0, 255, 0.5);
}

.user-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: none;
}

.user-avatar.loaded {
  display: block;
}

.user-avatar-fallback {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar-fallback svg {
  width: 22px;
  height: 22px;
  fill: var(--text-secondary);
}

.user-avatar.loaded + .user-avatar-fallback {
  display: none;
}

/* Results Content */
.results-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* AI Overview */
.ai-overview {
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.05) 0%, rgba(0, 255, 255, 0.05) 100%);
  border: 1px solid rgba(255, 0, 255, 0.2);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 24px;
  position: relative;
}

.ai-overview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-right: 50px; /* Make room for the speak button */
}

.ai-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--gradient);
  color: #000;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.ai-badge svg {
  width: 16px;
  height: 16px;
}

.ai-powered-by {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.ai-overview-content {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.ai-overview-content p {
  margin-bottom: 12px;
}

.ai-overview-content p:last-child {
  margin-bottom: 0;
}

.ai-speak-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--gradient);
  color: #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.ai-speak-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(255, 0, 255, 0.4);
}

.ai-speak-btn svg {
  width: 18px;
  height: 18px;
}

.ai-speak-btn.speaking {
  animation: speak-pulse 0.5s ease-in-out infinite;
}

@keyframes speak-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Results Meta */
.results-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* Results List */
.results-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Result Card */
.result-card {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.result-card:last-child {
  border-bottom: none;
}

.result-card.promoted {
  background: var(--promoted-bg);
  border: 1px solid var(--promoted-border);
  border-radius: 12px;
  padding: 16px;
  margin: 8px 0;
}

.result-card.promoted .result-promoted-badge {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Adjust grid rows when promoted badge is present */
.result-card.promoted {
  grid-template-rows: auto auto auto auto;
}

.result-card.promoted .result-logo {
  grid-row: 2;
}

.result-card.promoted .result-header {
  grid-row: 2;
}

.result-card.promoted .result-body {
  grid-row: 3;
}

.result-card.promoted .result-actions {
  grid-row: 4;
}

.result-card.promoted .result-promoted-badge svg {
  width: 12px;
  height: 12px;
}

/* Result card layout */
.result-card {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto auto;
  gap: 8px 12px;
}

.result-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.1);
  grid-column: 1;
  grid-row: 1;
  align-self: center;
}

.result-header {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.result-url {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}

.result-title {
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--secondary);
  cursor: pointer;
  display: block;
  text-decoration: none;
}

.result-title:hover {
  text-decoration: underline;
}

.result-card.promoted .result-title {
  color: var(--primary);
}

/* Result body - spans full width, description and thumbnail side by side */
.result-body {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 16px;
  align-items: start;
}

.result-card:not(.has-thumbnail) .result-body {
  grid-template-columns: 1fr;
}

.result-description {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
}

.result-thumbnail {
  width: 180px;
  height: 110px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.result-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

/* Result Actions */
.result-actions {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  gap: 8px;
}

.result-action-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.result-action-btn:hover {
  background: var(--gradient);
  color: #000;
}

.result-action-btn svg {
  width: 16px;
  height: 16px;
}

.result-action-btn.speaking {
  background: var(--gradient);
  color: #000;
  animation: speak-pulse 0.5s ease-in-out infinite;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.page-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 500;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.page-btn:not(:disabled):hover {
  background: var(--bg-card);
  color: var(--primary);
  border-color: var(--primary);
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-btn svg {
  width: 16px;
  height: 16px;
}

.page-numbers {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-number {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  background: transparent;
  border: none;
  color: var(--text-secondary);
}

.page-number:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.page-number.active {
  background: var(--gradient);
  color: #000;
}

.page-number.ellipsis {
  cursor: default;
}

/* Related Searches */
.related-searches {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.related-searches h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.related-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.related-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
}

.related-item:hover {
  background: var(--bg-card);
  border-color: var(--primary);
  color: var(--primary);
}

.related-item svg {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */

@media (max-width: 768px) {
  .homepage {
    padding-top: calc(20px + 36px);
  }

  .logo {
    width: 80px;
    height: 80px;
  }

  .logo-text {
    font-size: 2rem;
  }

  .search-box input {
    padding: 14px 80px 14px 44px;
    font-size: 0.95rem;
  }

  .search-buttons {
    flex-direction: column;
  }

  .search-btn {
    width: 100%;
  }

  .results-header {
    flex-wrap: wrap;
    gap: 12px;
  }

  .results-logo {
    flex: 0 0 auto;
  }

  .results-search-box {
    flex: 1 1 200px;
    order: 2;
  }

  .header-user {
    order: 1;
    margin-left: auto;
    padding-left: 0;
  }

  .result-card {
    grid-template-columns: 36px 1fr;
    gap: 8px 10px;
  }

  .result-logo {
    width: 36px;
    height: 36px;
  }

  .result-body {
    grid-template-columns: 1fr;
  }

  .result-thumbnail {
    width: 100%;
    height: 140px;
  }

  .pagination {
    flex-wrap: wrap;
  }

  .page-numbers {
    order: -1;
    width: 100%;
    justify-content: center;
    margin-bottom: 12px;
  }
}

@media (max-width: 480px) {
  .ai-overview-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .ai-speak-btn {
    top: auto;
    bottom: 16px;
    right: 16px;
  }
}

/* Gruntslate spinner animation */
@keyframes gruntslate-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
