/* ============================================
   CureMap — Styles
   Clinical trial discovery for patients
   ============================================ */

/* --- Reset & Variables --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fafaf8;
  --text: #1a1a1a;
  --text-muted: #5a5a56;
  --accent: #2d6a9f;
  --accent-hover: #1a4f7a;
  --accent-light: #e3f0f9;
  --warm: #c4842d;
  --green: #2e7d32;
  --green-light: #e8f5e9;
  --orange: #e65100;
  --orange-light: #fff3e0;
  --border: #e0ddd8;
  --card-bg: #ffffff;
  --shadow: rgba(0,0,0,0.06);
  --shadow-lg: rgba(0,0,0,0.1);
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --header-height: 56px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

/* --- Layout --- */
.container { max-width: 720px; margin: 0 auto; padding: 0 2rem; }
.container-wide { max-width: 1280px; margin: 0 auto; padding: 0 1.5rem; }

/* --- Header --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: rgba(250, 250, 248, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

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

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

.logo:hover { color: var(--accent); }

.header-nav { display: flex; gap: 1.5rem; }

.header-nav a {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.header-nav a:hover { color: var(--text); }

.nav-fav { position: relative; }

.fav-badge {
  font-size: 0.5rem;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  min-width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  vertical-align: super;
  margin-left: 2px;
}

/* --- Hero / Search --- */
.hero {
  padding: 4rem 0 3rem;
  text-align: center;
}

.hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.75rem;
}

.hero .tagline {
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 520px;
  margin: 0 auto 2.5rem;
}

/* Search box */
.search-box {
  text-align: left;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.search-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.search-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.search-field-main { flex: 1.5; }

.search-field label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.search-field input {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  padding: 0.875rem 0.875rem;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.search-field input:focus {
  border-color: var(--accent);
}

.search-field input::placeholder {
  color: #b0ada6;
}

/* Location input with locate button */
.location-input-wrap {
  display: flex;
  position: relative;
}

.location-input-wrap input {
  flex: 1;
  border-radius: 4px 0 0 4px;
}

.btn-locate {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.75rem;
  height: 48px;
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 4px 4px 0;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.btn-locate:hover { color: var(--accent); border-color: var(--accent); }

.btn-locate.locating {
  color: var(--warm);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Autocomplete */
.search-field { position: relative; }
.location-input-wrap { position: relative; }

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 4px 12px var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  display: none;
}

.autocomplete-list.open { display: block; }

.autocomplete-item {
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.1s;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

.btn-search {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.875rem 1.5rem;
  height: 48px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.search-submit {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

.btn-search:hover { background: var(--accent-hover); }

/* Filters */
.search-filters {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-group label {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.filter-group select {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  padding: 0.875rem 0.875rem;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--text);
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.filter-group select:focus { border-color: var(--accent); }

/* --- Results --- */
.results-section {
  padding: 0 0 3rem;
  min-height: 60vh;
}

.results-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.results-summary span {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.results-actions { display: flex; align-items: center; gap: 0.75rem; }

.btn-share {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-share:hover { border-color: var(--accent); color: var(--accent); }

.view-toggle { display: flex; gap: 0.25rem; }

.view-btn {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.view-btn:hover { border-color: var(--accent); color: var(--accent); }

.view-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Result filters */
.result-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.rf-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.rf-group label {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.rf-group select {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  padding: 0.5rem 0.625rem;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--text);
  outline: none;
  cursor: pointer;
  max-width: 200px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.rf-group select:focus { border-color: var(--accent); }

.rf-clear {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem 0;
  transition: color 0.15s;
}

.rf-clear:hover { color: var(--accent); }

/* Split view */
.results-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  height: calc(100vh - 280px);
  min-height: 500px;
}

.results-split.view-map {
  grid-template-columns: 1fr;
}

.results-split.view-map .list-pane { display: none; }

.results-split.view-list {
  grid-template-columns: 1fr;
}

.results-split.view-list .map-pane { display: none; }

.results-split.view-list .list-pane {
  max-width: 800px;
  margin: 0 auto;
}

/* Map */
.map-pane {
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

#map { width: 100%; height: 100%; min-height: 400px; }

/* Trial list */
.list-pane {
  overflow-y: auto;
  padding-right: 0.5rem;
}

/* Trial card */
.trial-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.trial-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px var(--shadow);
}

.trial-card-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-fav {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.125rem;
  color: var(--border);
  transition: color 0.15s;
  padding: 0;
  line-height: 1;
}

.btn-fav:hover { color: var(--warm); }
.btn-fav.fav-active { color: var(--warm); }

.trial-card.highlighted {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light), 0 2px 8px var(--shadow);
  transition: border-color 0.2s, box-shadow 0.3s;
}

.trial-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.trial-card h3 {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.4;
  flex: 1;
}

.trial-card .nct-id {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.trial-card .trial-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
}

.trial-badge {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
}

.badge-recruiting { background: var(--green-light); color: var(--green); }
.badge-active { background: var(--accent-light); color: var(--accent); }
.badge-completed { background: #f5f5f5; color: #666; }
.badge-phase { background: var(--orange-light); color: var(--orange); }
.badge-condition { background: #f3e8ff; color: #6b21a8; }

.trial-card .trial-summary {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.625rem;
}

.trial-card .trial-locations {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.btn-load-more {
  display: block;
  width: 100%;
  padding: 0.75rem;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-load-more:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

/* --- Loading --- */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-bottom: 0.5rem;
}

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

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal-content {
  position: relative;
  background: var(--card-bg);
  border-radius: 8px;
  max-width: 680px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#modal-body {
  overflow-y: auto;
  padding: 2rem 2.5rem 2.5rem;
  flex: 1;
}

.modal-close {
  font-size: 1.5rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
  flex-shrink: 0;
  margin-left: 1rem;
}

.modal-close:hover { color: var(--text); }

/* Modal content */
.detail-header { margin-bottom: 1.5rem; }

.detail-header h2 {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}

.detail-header .nct-id {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.detail-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.detail-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.detail-section h3 {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--warm);
  margin-bottom: 0.75rem;
}

.detail-section p,
.detail-section li {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text);
}

.detail-section ul {
  list-style: none;
  padding: 0;
}

.detail-section ul li {
  padding: 0.25rem 0;
  padding-left: 1rem;
  position: relative;
}

.detail-section ul li::before {
  content: '\2014';
  position: absolute;
  left: 0;
  color: var(--border);
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.detail-meta-item label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.detail-meta-item span {
  font-size: 0.875rem;
  color: var(--text);
}

.detail-locations {
  list-style: none;
  padding: 0;
}

.detail-locations li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.detail-locations li:last-child { border-bottom: none; }

.detail-location-status {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--green);
  margin-left: 0.5rem;
}

.btn-ct-gov {
  display: inline-block;
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.5rem 1rem;
  transition: all 0.2s;
}

.btn-ct-gov:hover {
  background: var(--accent);
  color: #fff;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  background: var(--text);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.625rem 1.25rem;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 2000;
  pointer-events: none;
}

.toast.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Saved list */
.saved-list {
  list-style: none;
  padding: 0;
}

.saved-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

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

.saved-item-link {
  flex: 1;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
}

.saved-item-link:hover { color: var(--accent); }

.saved-item-meta {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.saved-item-meta span {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* Detail favorite button */
.btn-fav-detail { font-size: 0.75rem; }
.btn-fav-detail.fav-active { border-color: var(--warm); color: var(--warm); }

/* --- About --- */
.about-section {
  padding: 4rem 0;
  border-top: 1px solid var(--border);
}

.about-section h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.about-section p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  max-width: 560px;
}

.about-principles {
  display: flex;
  gap: 2rem;
  margin: 1.5rem 0;
}

.principle {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.principle strong {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.principle span {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.about-link a {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

/* --- Footer --- */
footer {
  padding: 2rem 0;
  text-align: center;
  border-top: 1px solid var(--border);
}

footer p {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-muted);
}

footer a { color: var(--text-muted); }
footer a:hover { color: var(--accent); }

footer .disclaimer {
  margin-top: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.625rem;
  color: #9a9790;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

/* --- No results --- */
.no-results {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
}

.no-results h3 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.no-results p {
  font-size: 0.875rem;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .hero { padding: 3rem 0 2rem; }
  .hero h1 { font-size: 1.5rem; }

  .search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .search-filters { flex-direction: column; gap: 0.5rem; }

  .results-split {
    grid-template-columns: 1fr;
    height: auto;
  }

  .map-pane { height: 300px; }

  .list-pane { padding-right: 0; }

  .about-principles {
    flex-direction: column;
    gap: 1rem;
  }

  .detail-meta-grid { grid-template-columns: 1fr; }

  .modal-header { padding: 0.75rem 1.5rem; }
  #modal-body { padding: 1.25rem 1.5rem 1.5rem; }
  .modal-actions { gap: 0.375rem; }
  .modal-actions .btn-ct-gov { font-size: 0.625rem; padding: 0.375rem 0.625rem; }

  .view-toggle { display: none; }
}

@media (max-width: 480px) {
  .container { padding: 0 1rem; }
  .container-wide { padding: 0 0.75rem; }
  .header-nav { gap: 1rem; }
}

/* --- Print --- */
@media print {
  .site-header, .map-pane, .view-toggle, .btn-load-more, .modal { display: none; }
  .results-split { grid-template-columns: 1fr; height: auto; }
  .trial-card { break-inside: avoid; }
}
