/* Rangeway Research - Brand Aligned CSS
   Based on Rangeway Brand Guidelines v1.0
   Colors: Sunset Coral, Golden Highway, Mountain Charcoal, Coastal Cream, Ocean Deep, Fog Gray
   Typography: Montserrat for headlines, Source Sans Pro for body
*/

/* Import Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800&family=Source+Sans+Pro:wght@300;400;600&display=swap');

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

html {
  scroll-behavior: smooth;
}

/* CSS Variables - Light Mode (Default) */
:root {
  /* Brand Primary Colors */
  --sunset-coral: #F09060;
  --golden-highway: #FFB366;
  --mountain-charcoal: #4A4A4A;

  /* Brand Supporting Colors */
  --coastal-cream: #F5DEB3;
  --ocean-deep: #2C5F7C;
  --fog-gray: #B8B8B8;

  /* Application Colors - Light Mode */
  --bg-primary: #FFFFFF;
  --bg-secondary: #FAFAFA;
  --text-primary: #2C3E50;
  --text-secondary: #666666;
  --text-heading: #4A4A4A;
  --card-bg: #FFFFFF;
  --border-color: #E6E6E6;
  --shadow-light: rgba(0,0,0,0.08);
  --shadow-medium: rgba(0,0,0,0.12);
  --accent: #F09060;
  --accent-hover: #e07a48;

  /* Category Colors */
  --category-trends: #2C5F7C;
  --category-contrarian: #F09060;
  --category-case-study: #4A9C6D;
  --category-misconception: #8B5CF6;
  --category-metrics: #EC4899;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #252525;
    --text-primary: #e8e8e8;
    --text-secondary: #b0b0b0;
    --text-heading: #f5f5f5;
    --card-bg: #252525;
    --border-color: #3a3a3a;
    --shadow-light: rgba(0,0,0,0.3);
    --shadow-medium: rgba(0,0,0,0.4);
    --accent-hover: #FFB366;
  }
}

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

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
}

.logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.logo-icon {
  width: 56px;
  height: 56px;
}

.header h1 {
  font-family: 'Montserrat', -apple-system, sans-serif;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--text-heading);
  margin: 0;
}

.header p {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-top: 0.5rem;
}

/* Search Section */
.search-section {
  margin-bottom: 2rem;
}

.search-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search-input {
  flex: 1;
  padding: 1rem 1.5rem;
  font-size: 1rem;
  font-family: 'Source Sans Pro', sans-serif;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-bg);
  color: var(--text-primary);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 144, 96, 0.2);
}

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

.search-button {
  padding: 1rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: 'Montserrat', sans-serif;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--golden-highway);
  color: var(--mountain-charcoal);
  cursor: pointer;
  transition: all 0.3s ease;
}

.search-button:hover {
  background: var(--accent);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(240, 144, 96, 0.3);
}

.search-button:active {
  transform: scale(0.98);
}

.search-button:disabled {
  background: var(--border-color);
  color: var(--text-secondary);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Quick Search Tags */
.quick-searches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.quick-search-tag {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-family: 'Source Sans Pro', sans-serif;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
}

.quick-search-tag:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(240, 144, 96, 0.1);
}

/* Loading State */
.loading {
  display: none;
  text-align: center;
  padding: 3rem;
}

.loading.active {
  display: block;
}

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

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--text-secondary);
}

/* Results Section */
.results {
  display: none;
}

.results.active {
  display: block;
}

/* Summary Card */
.summary-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 4px 20px var(--shadow-light);
}

.summary-card h2 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--accent);
}

.summary-card p {
  color: var(--text-primary);
  line-height: 1.8;
}

/* Sources Grid */
.sources-section {
  margin-bottom: 2rem;
}

.sources-section h2 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-heading);
}

.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.source-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  text-decoration: none;
  transition: border-color 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

.source-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--shadow-medium);
}

.source-card .source-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 50%;
  flex-shrink: 0;
}

.source-card .source-title {
  flex: 1;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-card .source-domain {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.source-card:hover .source-title {
  color: var(--accent);
}

/* Insights Section */
.insights-section {
  margin-bottom: 2rem;
}

.insights-section h2 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-heading);
}

.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1.5rem;
}

.insight-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 4px 20px var(--shadow-light);
}

.insight-card h3 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.insight-card h3.trends { color: var(--category-trends); }
.insight-card h3.contrarian { color: var(--category-contrarian); }
.insight-card h3.case_study { color: var(--category-case-study); }
.insight-card h3.misconception { color: var(--category-misconception); }
.insight-card h3.metrics { color: var(--category-metrics); }

.insight-card ul {
  list-style: none;
}

.insight-card li {
  padding: 0.5rem 0;
  padding-left: 1.25rem;
  position: relative;
  color: var(--text-secondary);
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-color);
}

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

.insight-card li::before {
  content: "\2192";
  position: absolute;
  left: 0;
  color: var(--accent);
}

/* Rangeway Implications */
.implications-card {
  background: linear-gradient(135deg, var(--card-bg) 0%, rgba(240, 144, 96, 0.08) 100%);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 1.5rem;
  margin-top: 2rem;
  box-shadow: 0 4px 20px var(--shadow-light);
}

.implications-card h2 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--accent);
}

.implications-card ul {
  list-style: none;
}

.implications-card li {
  padding: 0.75rem 0;
  padding-left: 1.5rem;
  position: relative;
  color: var(--text-primary);
}

.implications-card li::before {
  content: "\2726";
  position: absolute;
  left: 0;
  color: var(--accent);
}

/* Error State */
.error {
  display: none;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  color: #dc2626;
}

@media (prefers-color-scheme: dark) {
  .error {
    color: #fca5a5;
  }
}

.error.active {
  display: block;
}

/* Footer */
.footer {
  text-align: center;
  padding-top: 2rem;
  margin-top: 3rem;
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  .logo-container {
    flex-direction: column;
    gap: 0.75rem;
  }

  .logo-icon {
    width: 48px;
    height: 48px;
  }

  .header h1 {
    font-size: 1.5rem;
  }

  .header p {
    font-size: 1rem;
  }

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

  .search-button {
    width: 100%;
  }

  .sources-grid,
  .insights-grid {
    grid-template-columns: 1fr;
  }
}

/* Inline Source Links */
.inline-source {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85em;
  font-weight: 500;
  transition: color 0.2s ease;
}

.inline-source:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Markdown Tables */
.markdown-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
  background: var(--card-bg);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.markdown-table thead {
  background: rgba(240, 144, 96, 0.1);
}

.markdown-table th {
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
  text-align: left;
  padding: 0.75rem 1rem;
  color: var(--text-heading);
  border-bottom: 2px solid var(--border-color);
}

.markdown-table td {
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
}

.markdown-table tbody tr:last-child td {
  border-bottom: none;
}

.markdown-table tbody tr:hover {
  background: rgba(240, 144, 96, 0.05);
}

/* Citation superscripts */
.citation {
  color: var(--accent);
  font-weight: 500;
  cursor: default;
}

/* Clickable citation links */
.citation-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85em;
  vertical-align: super;
  transition: color 0.2s ease;
}

.citation-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Insight card content formatting */
.insight-content p {
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

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

.insight-content a {
  color: var(--accent);
  text-decoration: none;
}

.insight-content a:hover {
  text-decoration: underline;
}

.insight-content strong {
  color: var(--text-primary);
  font-weight: 600;
}
