/* LegacyLens — Dark Theme */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --bg-input: #21262d;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --error: #f85149;
  --success: #3fb950;
  --warning: #d29922;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --radius: 6px;
}

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

body {
  font-family: var(--font-ui);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

header h1 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.health-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
  transition: background 0.3s;
}

.health-indicator.connected {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.health-indicator.degraded {
  background: var(--warning);
  box-shadow: 0 0 6px var(--warning);
}

.header-right {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* --- Query Bar --- */

.query-bar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

#query-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

#query-input:focus {
  border-color: var(--accent);
}

.query-controls {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

#language-filter {
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
}

#send-btn, #clear-btn {
  padding: 6px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

#send-btn {
  background: var(--accent);
  color: var(--bg-primary);
}

#send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#clear-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

#clear-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

/* --- Split View --- */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.split-view {
  flex: 1;
  display: flex;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sources-panel {
  flex: 0 0 40%;
  border-right: 1px solid var(--border);
}

.answer-panel {
  flex: 0 0 60%;
  position: relative;
}

#sources-list {
  overflow-y: auto;
  padding: 12px;
  flex: 1;
  scroll-behavior: smooth;
}

#answer-content {
  overflow-y: auto;
  padding: 16px;
  flex: 1;
  font-size: 0.95rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  scroll-behavior: smooth;
}

#answer-content.error {
  color: var(--error);
}

/* --- Source Cards --- */

.source-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.source-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.source-path {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.copy-btn, .collapse-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 2px 8px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.copy-btn:hover, .collapse-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.source-code {
  overflow: hidden;
  transition: max-height 0.3s ease;
  max-height: 400px;
}

.source-code.collapsed {
  max-height: 0;
}

.source-code pre {
  margin: 0;
  padding: 12px;
  font-size: 0.82rem;
  overflow-x: auto;
  background: var(--bg-primary) !important;
}

.source-code code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

/* --- Loading Spinner --- */

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.spinner.hidden {
  display: none;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* --- Footer --- */

footer {
  padding: 8px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 0.78rem;
  color: var(--text-muted);
  min-height: 32px;
}

/* --- Responsive --- */

@media (max-width: 768px) {
  .split-view {
    flex-direction: column;
  }

  .sources-panel {
    flex: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }

  .answer-panel {
    flex: 1;
  }

  .query-controls {
    flex-wrap: wrap;
  }

  header {
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
  }
}
