:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-dim: #2a5fad;
  --ok: #3dd68c;
  --warn: #f0b429;
  --border: #2e3f56;
  --radius: 10px;
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #152030 0%, var(--bg) 100%);
}

.header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  font-weight: 600;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 52rem;
}

.status {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--muted);
}

.status.ready { color: var(--ok); background: rgba(61, 214, 140, 0.12); }
.status.busy { color: var(--warn); }
.status.err { color: #f87171; background: rgba(248, 113, 113, 0.12); }

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 0;
  min-height: calc(100vh - 120px);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  padding: 1.25rem 1.5rem;
}

.search-panel {
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.results-panel {
  overflow-y: auto;
  max-height: calc(100vh - 120px);
}

h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.hint { font-size: 0.85rem; color: var(--muted); margin: 0 0 1rem; }

.query-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; }

.query-row {
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
}

.query-row textarea {
  flex: 1;
  min-height: 2.5rem;
  resize: vertical;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.query-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.25);
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn.primary {
  width: 100%;
  margin-top: 1rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover { background: var(--accent-dim); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.secondary {
  background: var(--surface2);
  color: var(--text);
  width: 100%;
}

.btn.icon {
  padding: 0.35rem 0.5rem;
  background: transparent;
  color: var(--muted);
  flex-shrink: 0;
}

.btn.icon:hover { color: #f87171; }

.options {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
}

.options label {
  flex: 1;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.options input {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.error {
  color: #f87171;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.hidden { display: none !important; }

.loading {
  color: var(--muted);
  padding: 2rem;
  text-align: center;
}

.schema-block {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.schema-block h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--accent);
}

.hit {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.hit:last-child { border-bottom: none; }

.hit .tag { font-weight: 600; color: var(--text); }
.hit .meta { color: var(--muted); font-size: 0.8rem; }
.hit .desc { color: var(--muted); margin-top: 0.2rem; font-size: 0.8rem; }

.doc-card {
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.doc-card header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.doc-card h3 { margin: 0; font-size: 1rem; }
.doc-card .score {
  font-variant-numeric: tabular-nums;
  color: var(--ok);
  font-weight: 600;
}

.group-line {
  font-size: 0.82rem;
  padding: 0.35rem 0;
  border-left: 3px solid var(--accent);
  padding-left: 0.6rem;
  margin-bottom: 0.35rem;
  background: rgba(61, 139, 253, 0.06);
}

.tags-section { margin-top: 0.75rem; }

.tags-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
}

.tag-chip {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  margin: 0.2rem 0.25rem 0 0;
  border-radius: 4px;
  background: var(--surface2);
  color: var(--muted);
}

.tag-chip.query { border: 1px solid var(--accent); color: var(--accent); }
.tag-chip.best { border: 1px solid var(--ok); color: var(--ok); }

.doc-text {
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: var(--text);
  white-space: pre-wrap;
  max-height: 12rem;
  overflow: hidden;
  position: relative;
}

.doc-text.expanded { max-height: none; }

.doc-text-fade {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3rem;
  background: linear-gradient(transparent, var(--surface));
  pointer-events: none;
}

.doc-text.expanded + .doc-text-fade { display: none; }

.empty {
  color: var(--muted);
  padding: 2rem;
  text-align: center;
}

.summary {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.collapse-toggle {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  margin-bottom: 0.35rem;
}

.collapse-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.collapse-toggle[aria-expanded="true"] {
  border-color: var(--accent);
  margin-bottom: 0.5rem;
}

.collapse-body {
  margin-bottom: 0.75rem;
}

.schema-section > .collapse-toggle {
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.schema-block .collapse-toggle {
  font-size: 0.85rem;
  background: transparent;
  border: none;
  padding: 0.25rem 0;
  margin-bottom: 0.35rem;
}

.schema-block .collapse-toggle:hover {
  background: transparent;
}

.schema-block .collapse-body {
  padding-left: 0.5rem;
  border-left: 2px solid var(--border);
}

.descriptor-list {
  margin-top: 0.35rem;
}

.descriptor-item {
  font-size: 0.82rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}

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

.descriptor-item .d-tag {
  font-weight: 600;
}

.descriptor-item .d-meta {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.15rem;
}

.descriptor-item .d-expl {
  color: var(--muted);
  margin-top: 0.25rem;
  font-size: 0.8rem;
}
