:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #7c3aed;
  --secondary-hover: #6d28d9;
  --accent: #f59e0b;
  --highlight: #fef3c7;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.login-box {
  background: var(--card);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 90%;
}
.login-box h2 { margin-top: 0; }
.login-box input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  margin: 0.5rem 0 1rem;
}
.error { color: #dc2626; margin: 0.5rem 0 0; min-height: 1.2em; }

.site-header {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  padding: 1.5rem 2rem;
  text-align: center;
}
.site-header h1 { margin: 0; font-size: 1.8rem; }
.subtitle { margin: 0.3rem 0 0; opacity: 0.9; font-size: 0.95rem; }

main {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.search-section { margin-bottom: 1.5rem; }

.search-bar {
  display: flex;
  gap: 0.5rem;
  background: var(--card);
  padding: 0.75rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.search-bar input[type="text"] {
  flex: 1 1 300px;
  min-width: 200px;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
.search-bar input[type="text"]:focus { border-color: var(--primary); }

.buttons { display: flex; gap: 0.5rem; }

.btn {
  padding: 0.7rem 1.1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  text-decoration: none;
  display: inline-block;
  color: white;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.primary { background: var(--primary); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.secondary { background: var(--secondary); }
.btn.secondary:hover:not(:disabled) { background: var(--secondary-hover); }
.btn.small { padding: 0.4rem 0.7rem; font-size: 0.85rem; background: #4b5563; }
.btn.small:hover:not(:disabled) { background: #374151; }

.filters {
  margin-top: 0.6rem;
  padding: 0 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.filters label { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }

.status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.2em;
}
.status.error { color: #dc2626; }
.status.loading { color: var(--primary); }

.llm-info {
  background: linear-gradient(135deg, #f3e8ff, #ede9fe);
  border-left: 4px solid var(--secondary);
  padding: 0.8rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  font-size: 0.92rem;
}
.llm-info .rewrites { margin-top: 0.4rem; }
.llm-info .rewrites-label { color: var(--muted); margin-right: 0.4rem; }
.llm-info .rewrite-tag {
  display: inline-block;
  background: white;
  border: 1px solid var(--secondary);
  color: var(--secondary);
  padding: 0.1rem 0.5rem;
  border-radius: 12px;
  font-size: 0.85rem;
  margin: 0.1rem 0.2rem 0.1rem 0;
}

.results { display: flex; flex-direction: column; gap: 0.75rem; }

.result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.result-card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); }

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.result-title { font-weight: 600; font-size: 1.02rem; }
.result-meta {
  font-size: 0.83rem;
  color: var(--muted);
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}
.result-badge {
  background: var(--highlight);
  color: #92400e;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
}
.score-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0.5rem 0;
  overflow: hidden;
}
.score-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); }

.snippet {
  font-size: 0.9rem;
  color: #374151;
  line-height: 1.5;
  margin: 0.4rem 0;
}
.snippet mark {
  background: var(--highlight);
  padding: 0.05em 0.2em;
  border-radius: 2px;
  font-weight: 600;
}
.llm-reason {
  font-size: 0.85rem;
  color: var(--secondary);
  font-style: italic;
  margin-top: 0.4rem;
}
.result-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.pdf-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 999;
}
.pdf-viewer {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(90vw, 1100px);
  height: min(90vh, 900px);
  background: var(--card);
  box-shadow: var(--shadow-lg);
  border-radius: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pdf-header, .pdf-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.8rem;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
  flex-wrap: wrap;
}
.pdf-header > div { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.pdf-container {
  flex: 1;
  overflow: hidden;
  background: #e5e7eb;
}
.pdf-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.site-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}
