:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --accent2: #533483;
  --text: #eee;
  --text-dim: #999;
  --text-bright: #fff;
  --border: #2a2a4e;
  --success: #4ecca3;
  --warning: #ffc107;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: var(--surface);
  padding: 1rem 2rem;
  border-bottom: 2px solid var(--accent);
  display: flex; align-items: center; gap: 2rem; flex-wrap: wrap;
}
header h1 { font-size: 1.3rem; color: var(--accent); }
nav { display: flex; gap: 0.5rem; }
nav button {
  background: transparent; color: var(--text-dim); border: 1px solid var(--border);
  padding: 0.4rem 1rem; border-radius: 4px; cursor: pointer;
}
nav button.active { background: var(--accent2); color: var(--text-bright); border-color: var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.view { display: none; }
.view.active { display: block; }

.search-box { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.search-box input[type="text"] {
  flex: 1; min-width: 250px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 0.7rem 1rem; border-radius: 6px; font-size: 1rem;
}
.search-box input:focus { outline: none; border-color: var(--accent); }
.search-box button {
  background: var(--accent); color: #fff; border: none;
  padding: 0.7rem 1.5rem; border-radius: 6px; cursor: pointer; font-size: 1rem;
}
.search-options { display: flex; gap: 1rem; align-items: center; width: 100%; }
.search-options select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 0.3rem 0.5rem; border-radius: 4px;
}
.search-options label { font-size: 0.85rem; color: var(--text-dim); cursor: pointer; }

.results { display: flex; flex-direction: column; gap: 0.5rem; }
.result-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.8rem; cursor: pointer; transition: border-color 0.2s;
}
.result-item:hover { border-color: var(--accent); }
.result-item .name { font-size: 1rem; font-weight: 600; color: var(--text-bright); }
.result-item .meta { font-size: 0.8rem; color: var(--text-dim); margin: 0.2rem 0; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.result-item .meta .type { color: var(--accent); }
.result-item .meta .source { color: var(--success); }
.result-item .meta .score { color: var(--warning); }
.result-item .preview { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.3rem; line-height: 1.4; }
.result-item .terms { font-size: 0.75rem; color: var(--accent2); margin-top: 0.2rem; }

.browse-categories { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.browse-categories button {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer;
}
.browse-categories button:hover { border-color: var(--accent); }
.browse-categories button.active { background: var(--accent2); border-color: var(--accent); }

.chat-messages { max-height: 60vh; overflow-y: auto; margin-bottom: 1rem; }
.message { background: var(--surface); border-radius: 8px; padding: 1rem; margin-bottom: 0.5rem; line-height: 1.5; }
.message.system { opacity: 0.7; }
.message.user { background: var(--surface2); }
.message.assistant { border-left: 3px solid var(--accent); }
.message .chat-help { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.5rem; }
.chat-input-area { display: flex; gap: 0.5rem; }
.chat-input-area textarea {
  flex: 1; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 0.7rem; border-radius: 6px; font-size: 0.95rem; resize: vertical; min-height: 50px;
}
.chat-input-area button {
  background: var(--accent); color: #fff; border: none;
  padding: 0.7rem 1.5rem; border-radius: 6px; cursor: pointer;
}
.llm-status { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.3rem; text-align: center; }

.modal {
  display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
}
.modal.active { display: flex; align-items: center; justify-content: center; }
.modal-content {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 2rem; max-width: 800px; width: 90%; max-height: 80vh; overflow-y: auto; position: relative;
}
.close { position: absolute; right: 1rem; top: 0.5rem; font-size: 1.5rem; cursor: pointer; color: var(--text-dim); }
.close:hover { color: var(--accent); }

.error-banner {
  position: fixed; top: 0; left: 0; right: 0; background: var(--accent);
  color: #fff; padding: 0.8rem 2rem; text-align: center; z-index: 2000;
  display: flex; justify-content: space-between; align-items: center;
}
.error-banner .dismiss { background: none; border: none; color: #fff; cursor: pointer; font-size: 1.2rem; }
.error-banner.hidden { display: none; }

@media (max-width: 600px) {
  header { flex-direction: column; align-items: flex-start; gap: 1rem; }
  .search-box input { min-width: 100%; }
}
