/* ============================================================
   Murm Search — Dark earth-tone theme
   ============================================================ */

:root {
  --bg: #0f1210;
  --bg-surface: #171d19;
  --bg-card: #1c2420;
  --bg-card-hover: #243029;
  --bg-card-active: #2a3a30;
  --border: #2a3630;
  --text: #d4ddd6;
  --text-dim: #7a8f80;
  --text-muted: #4e6055;
  --accent: #4ecb71;
  --accent-dim: #2d7a45;
  --accent-glow: rgba(78, 203, 113, 0.15);
  --tag-bg: #1a2e22;
  --tag-text: #6bc88a;
  --radius: 8px;
  --sidebar-width: 420px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
#header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.header-left h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

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

.tagline {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

/* Mode switch */
.mode-switch {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.mode-btn {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: var(--text-dim);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

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

.mode-btn:hover:not(.active) {
  color: var(--text);
}

/* Search input in header */
.search-wrap {
  flex: 1;
  max-width: 600px;
  position: relative;
}

.search-wrap.hidden { display: none; }

#search-input {
  width: 100%;
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#search-input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.search-hint {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  margin-left: auto;
}

.count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Header nav */
.header-nav {
  display: flex;
  gap: 6px;
}

.nav-link {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
  color: var(--accent);
  background: var(--accent-glow);
}

.nav-link.active {
  color: var(--accent);
}

.logo-link {
  text-decoration: none;
  color: inherit;
}

/* Static pages */
.page-body {
  overflow: auto;
}

.page-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 40px 20px 0;
  align-items: flex-start;
}

.page-inner {
  max-width: 640px;
  width: 100%;
  margin-bottom: 50px;
}

.page-inner h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.page-inner h3 {
  font-size: 16px;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 12px;
  color: var(--accent);
}

.page-inner h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.page-inner p {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  margin-bottom: 14px;
}

.page-inner ul, .page-inner ol {
  margin: 0 0 16px 20px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}

.page-inner li {
  margin-bottom: 6px;
}

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

.page-inner a:hover {
  text-decoration: underline;
}

.page-inner strong {
  color: var(--text);
  font-weight: 600;
}

.page-inner code {
  font-size: 13px;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

.option-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.option-box ol {
  margin-bottom: 0;
}

/* ---- Main layout ---- */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ---- Sidebar ---- */
#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
}

/* ---- Search panel ---- */
#search-panel {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#search-panel::-webkit-scrollbar { width: 6px; }
#search-panel::-webkit-scrollbar-track { background: transparent; }
#search-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

#search-panel.hidden { display: none; }

/* Synthesis box */
.synthesis {
  padding: 14px 16px;
  margin: 12px;
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}

.synthesis.hidden { display: none; }

.synthesis-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
  margin-bottom: 6px;
}

/* Result cards */
#results {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card {
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-dim);
}

.card.active {
  background: var(--bg-card-active);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.card-rank {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.card-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.3;
}

.card-name a {
  color: inherit;
  text-decoration: none;
}

.card-name a:hover { color: var(--accent); }

.card-url, .mini-card-url {
  font-size: 12px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-url a, .mini-card-url a {
  color: var(--accent);
  text-decoration: none;
}
.card-url a:hover, .mini-card-url a:hover {
  text-decoration: underline;
}

.card-location {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 6px;
}

.card-desc {
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 10px;
  white-space: nowrap;
}

/* Relevance bar */
.relevance-bar {
  position: relative;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.relevance-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

.relevance-pct {
  position: absolute;
  right: 0;
  top: -14px;
  font-size: 10px;
  color: var(--text-muted);
}

/* Show more / collapse */
.card.card-overflow,
.mini-card.mini-card-overflow {
  display: none !important;
}

.expanded .card.card-overflow {
  display: block !important;
}

.expanded .mini-card.mini-card-overflow {
  display: flex !important;
}

.show-more-btn {
  width: 100%;
  padding: 8px;
  margin-top: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.show-more-btn:hover {
  background: var(--bg-card-hover);
}

.no-results {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* Empty state */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}

.empty-state p { margin-bottom: 12px; font-size: 14px; line-height: 1.5; }
.empty-state .examples { font-size: 13px; color: var(--text-muted); }
.empty-state em { color: var(--text-dim); }

/* ---- Chat panel ---- */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chat-panel.hidden { display: none; }

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#chat-messages::-webkit-scrollbar { width: 6px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.chat-welcome {
  margin-top: 16px;
}

.chat-welcome .chat-bubble p { margin: 0 0 8px; }
.chat-welcome .chat-bubble p:last-child { margin-bottom: 0; }
.chat-welcome .try-query { font-size: 13px; color: var(--text-muted); }
.chat-welcome .try-query a { color: var(--accent); text-decoration: none; cursor: pointer; }
.chat-welcome .try-query a:hover { text-decoration: underline; }

/* Chat bubbles */
.chat-msg {
  max-width: 92%;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg.user {
  align-self: flex-end;
}

.chat-msg.assistant {
  align-self: flex-start;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
}

.chat-msg.user .chat-bubble {
  background: var(--accent-dim);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.chat-msg.assistant .chat-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 2px;
}

.chat-msg.assistant .chat-bubble.error {
  color: var(--text-muted);
  border-color: #4a2020;
  background: #1e1515;
}

.chat-bubble.thinking {
  padding: 12px 16px;
  display: flex;
  align-items: center;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Mini cards inside chat */
.chat-profiles {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.mini-card {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.mini-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-dim);
}

.mini-card.active {
  border-color: var(--accent);
  background: var(--bg-card-active);
}

.mini-card-num {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}

.mini-card-body {
  flex: 1;
  min-width: 0;
}

.mini-card-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 2px;
}

.mini-card-name a {
  color: inherit;
  text-decoration: none;
}

.mini-card-name a:hover { color: var(--accent); }

.mini-card-loc {
  font-size: 11px;
  color: var(--text);
}

.mini-card-desc {
  font-size: 11px;
  color: var(--text);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mini-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 4px;
}

.mini-card-tags .tag {
  font-size: 10px;
  padding: 1px 6px;
}

.mini-card .relevance-bar {
  margin-top: 4px;
  height: 2px;
}

.mini-card .relevance-pct {
  top: -12px;
  font-size: 9px;
}

/* Chat input */
#chat-input-wrap {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#chat-input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#chat-input::placeholder { color: var(--text-muted); }

#chat-send {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

#chat-send:hover { background: var(--accent); color: var(--bg); }
#chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Map ---- */
#map {
  flex: 1;
  min-width: 0;
}

.maplibregl-ctrl-group {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border) !important;
}

.maplibregl-ctrl-group button {
  background-color: var(--bg-surface) !important;
  border-color: var(--border) !important;
}

.maplibregl-ctrl-group button + button {
  border-top: 1px solid var(--border) !important;
}

.maplibregl-ctrl-group button span {
  filter: invert(1) brightness(0.7);
}

/* ---- Loading indicator ---- */
.loading #search-input,
.loading #chat-input {
  background-image: linear-gradient(90deg, transparent, var(--accent-glow), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ---- MapLibre popup ---- */
.maplibregl-popup-content {
  background: var(--bg-card) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  padding: 10px 14px !important;
  font-size: 13px;
  max-width: 250px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4) !important;
}

.maplibregl-popup-tip {
  border-top-color: var(--bg-card) !important;
}

.maplibregl-popup-close-button {
  color: var(--text-dim) !important;
  font-size: 16px;
}

.popup-name {
  font-weight: 600;
  margin-bottom: 4px;
}

.popup-loc {
  color: var(--text-dim);
  font-size: 12px;
}

.maplibregl-popup-content a {
  color: var(--accent) !important;
  text-decoration: none !important;
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

.maplibregl-popup-content a:focus,
.maplibregl-popup-content a:active {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

/* ---- Report button & modal ---- */
.report-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
  z-index: 1;
}

.card, .mini-card {
  position: relative;
}

.card:hover .report-btn,
.mini-card:hover .report-btn {
  opacity: 1;
}

.report-btn:hover {
  color: #e87070;
  border-color: #e87070;
  background: rgba(232, 112, 112, 0.1);
}

/* Reported card state */
.card.reported,
.mini-card.reported {
  opacity: 0.45;
  pointer-events: none;
}

.card.reported::after,
.mini-card.reported::after {
  content: "Reported";
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 600;
  color: #e87070;
  background: #3a1a1a;
  padding: 2px 8px;
  border-radius: 10px;
}

/* Report modal */
.report-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.report-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.report-modal-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.report-option {
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.report-option:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.report-feedback-wrap {
  display: flex;
  gap: 6px;
}

.report-feedback-wrap.hidden {
  display: none !important;
}

.report-feedback-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.report-feedback-input:focus {
  border-color: var(--accent-dim);
}

.report-feedback-send {
  padding: 8px 14px;
  background: var(--accent-dim);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.report-feedback-send:hover {
  background: var(--accent);
  color: var(--bg);
}

.report-cancel {
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  margin-top: 4px;
}

.report-cancel:hover {
  color: var(--text);
}

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  :root { --sidebar-width: 100%; }
  #main { flex-direction: column; }
  #sidebar { width: 100%; height: 45%; border-right: none; border-bottom: 1px solid var(--border); }
  #map { height: 55%; }
  .header-left .tagline { display: none; }
}
