:root {
  color-scheme: light;
  --ink: #17201b;
  --muted: #66716c;
  --line: #d8ded8;
  --paper: #fbfcfa;
  --panel: #ffffff;
  --mint: #dff3e5;
  --mint-strong: #1f7a4d;
  --amber: #f4c25f;
  --rose: #d85858;
  --blue: #2f6db5;
  --shadow: 0 10px 28px rgba(31, 45, 37, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 8px 12px;
}

button:hover {
  border-color: #aeb9b1;
}

button.primary {
  border-color: var(--mint-strong);
  background: var(--mint-strong);
  color: white;
}

button.danger {
  border-color: #f0c1c1;
  color: #a43131;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.brand {
  font-weight: 750;
}

nav {
  display: flex;
  gap: 6px;
}

nav a {
  border-radius: 7px;
  padding: 8px 11px;
  color: var(--muted);
}

nav a[aria-current="page"] {
  background: var(--mint);
  color: var(--ink);
}

.admin-layout,
.label-layout {
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto 60px;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 24px;
}

.admin-form-panel,
.query-list-panel,
.query-text-panel,
.editor-toolbar,
.markup-editor,
.search-preview {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.admin-form-panel,
.query-list-panel,
.query-text-panel,
.markup-editor,
.search-preview {
  border-radius: 8px;
}

.admin-form-panel,
.query-list-panel {
  padding: 20px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 2vw, 2rem);
}

h2 {
  font-size: 1.05rem;
}

h3 {
  margin: 0;
  font-size: 0.95rem;
}

.query-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

label {
  color: var(--muted);
  font-size: 0.92rem;
}

textarea,
.bullet-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
  padding: 12px;
}

.button-row,
.section-heading,
.editor-toolbar,
.query-context,
.status-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button-row {
  flex-wrap: wrap;
}

.section-heading,
.query-context,
.editor-toolbar {
  justify-content: space-between;
}

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

.message {
  min-height: 24px;
  color: var(--blue);
  margin: 10px 0;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 650;
  font-size: 0.85rem;
}

.query-preview {
  max-width: 480px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.82rem;
  background: #edf4ff;
  color: #244f84;
}

.status.unlabelled {
  background: #fff5de;
  color: #76521a;
}

.label-layout {
  display: grid;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--mint-strong);
  font-size: 0.8rem;
  font-weight: 760;
  text-transform: uppercase;
}

.query-text-panel {
  padding: 18px;
  border-left: 5px solid var(--amber);
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  line-height: 1.5;
}

.editor-toolbar {
  border-radius: 8px;
  padding: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--mint);
  color: var(--ink);
  font-size: 0.88rem;
}

.markup-editor {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.rerun-search-banner {
  display: block;
  width: 100%;
  padding: 10px 16px;
  background: var(--accent, #2563eb);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.rerun-search-banner:hover {
  opacity: 0.88;
}

.search-preview {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.search-preview:empty {
  display: none;
}

.line {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.line.must-have {
  border-color: #9bd4ad;
  background: #f3fbf5;
}

.line.dragging {
  opacity: 0.45;
}

.line.drop-reorder {
  border-left: 7px solid var(--blue);
  padding-left: 4px;
}

.line.drop-join {
  border-color: var(--mint-strong);
  box-shadow: inset 0 0 0 2px rgba(31, 122, 77, 0.18);
}

.drag-handle {
  width: 24px;
  min-height: 44px;
  border-radius: 6px;
  background: linear-gradient(90deg, #d9e6ff 0 4px, transparent 4px);
}

.bullet-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.bullet {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  max-width: 100%;
  border: 1px solid #e3e8e3;
  border-radius: 7px;
  background: #fff;
  padding: 6px;
  cursor: grab;
}

.filter-editor {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.filter-input {
  max-width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f6f8f6;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
}

.filter-input.invalid {
  border-color: var(--rose);
  background: #fff7f7;
  color: #8c2b2b;
}

.result-card {
  display: grid;
  grid-template-columns: minmax(240px, 0.85fr) minmax(520px, 1.35fr);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
}

.result-profile {
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
}

.result-description {
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.requirement-stats {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
}

.requirement-table {
  min-width: 720px;
  font-size: 0.88rem;
}

.requirement-table .must-have-row td:first-child {
  font-weight: 750;
}

.match-cell {
  border-radius: 6px;
  font-weight: 650;
}

.match-full {
  background: #dff3e5;
  color: #215b3e;
}

.match-partial {
  background: #fff2c7;
  color: #6d5416;
}

.match-no {
  background: #f8dada;
  color: #7a2e2e;
}

.match-stack {
  display: flex;
  width: 100%;
  height: 24px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f6f8f6;
}

.match-stack-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  font-size: 0.72rem;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
}

.requirement-table.stats-table td:nth-child(2) {
  width: 420px;
}

.requirement-table td:nth-child(2),
.requirement-table td:nth-child(3),
.requirement-table td:nth-child(4) {
  width: 120px;
}

.result-requirement-table {
  table-layout: fixed;
}

.result-requirement-table th:nth-child(1),
.result-requirement-table td:nth-child(1),
.result-requirement-table th:nth-child(3),
.result-requirement-table td:nth-child(3) {
  width: calc((100% - 120px) / 2);
}

.result-requirement-table th:nth-child(2),
.result-requirement-table td:nth-child(2) {
  width: 120px;
}

.result-card a {
  color: var(--blue);
  text-decoration: underline;
}

.search-error {
  margin: 0;
  color: #a43131;
}

.bullet.dragging {
  cursor: grabbing;
  opacity: 0.18;
}

.bullet-grip {
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  color: #89958f;
  cursor: grab;
  font-weight: 700;
  letter-spacing: 0;
  user-select: none;
}

.drag-ghost {
  position: fixed;
  z-index: 1000;
  max-width: min(720px, calc(100vw - 32px));
  pointer-events: none;
  box-shadow: 0 16px 32px rgba(23, 32, 27, 0.18);
  opacity: 0.96;
  transform: rotate(-1.5deg);
}

.drag-ghost .bullet-input {
  background: #fff;
}

.bullet-input {
  min-height: 38px;
  width: auto;
  max-width: min(720px, 100%);
  padding: 8px 10px;
}

.must-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  white-space: nowrap;
  color: var(--muted);
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.empty-state {
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

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

  .query-context,
  .editor-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .line {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .bullet {
    width: 100%;
    flex-wrap: wrap;
  }

  .must-toggle {
    width: max-content;
  }

  .result-card {
    grid-template-columns: 1fr;
  }
}
