body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eef2f5;
  color: #111827;
}

.card {
  width: 100%;
  max-width: 1080px;
  margin: 32px;
  padding: 32px;
  background: white;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, 0.12);
}

h1 {
  margin-top: 0;
  font-size: 32px;
}

input,
button,
select,
textarea {
  width: 100%;
  box-sizing: border-box;
  margin-top: 12px;
  padding: 14px;
  font: inherit;
}

input,
select,
textarea {
  min-height: 44px;
  color: #111827;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #2563eb;
  outline: 3px solid rgba(37, 99, 235, 0.15);
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

button {
  cursor: pointer;
  min-height: 44px;
  background: #1d4ed8;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 650;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.secondary-btn {
  width: auto;
  padding: 10px 18px;
  font-size: 15px;
  background: #e8edf3;
  color: #172033;
  border: 1px solid #cbd5e1;
}

#login-status {
  margin-top: 16px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

#admin-email {
  color: #047857;
  margin-top: -12px;
}

.tool-list {
  margin-top: 32px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.tool-tab {
  background: #e8edf3;
  color: #172033;
  border: 1px solid #cbd5e1;
}

.tool-tab.active {
  background: #172033;
  color: #ffffff;
  border-color: #172033;
}

.query-tool {
  margin-top: 28px;
  padding-top: 28px;
  border-top: 1px solid #d9e1e8;
}

.section-header,
.results-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}

.section-header h2,
.results-header h3 {
  margin: 0;
}

.section-header p {
  margin: 6px 0 0;
  color: #58677a;
}

.readonly-badge,
#result-count {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  background: #e7f7ee;
  color: #047857;
  font-size: 13px;
  font-weight: 700;
}

.query-form {
  margin-top: 20px;
}

.form-grid,
.filter-row,
.order-row,
.passage-search-grid {
  display: grid;
  gap: 14px;
}

.form-grid {
  grid-template-columns: 170px minmax(260px, 1fr) 130px;
}

.filter-row {
  grid-template-columns: minmax(160px, 1fr) 170px 150px minmax(220px, 1fr);
}

.order-row {
  grid-template-columns: minmax(220px, 1fr) 180px;
  margin-top: 14px;
}

.passage-search-panel {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: #f8fafc;
}

.passage-search-grid {
  grid-template-columns: 180px 180px;
}

.path-field {
  min-width: 0;
}

label span {
  display: block;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

details {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: #f8fafc;
}

summary {
  cursor: pointer;
  color: #172033;
  font-weight: 750;
}

.query-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 20px;
}

.audit-controls {
  display: grid;
  grid-template-columns: 160px 180px minmax(240px, 1fr);
  gap: 14px;
  align-items: end;
  margin-top: 20px;
}

.checkbox-label {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  margin-top: 12px;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
}

.checkbox-label input {
  width: auto;
  min-height: 0;
  margin: 0;
}

.checkbox-label span {
  color: #172033;
}

.audit-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.audit-summary div {
  padding: 14px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: #f8fafc;
}

.audit-summary span,
.audit-summary small {
  display: block;
}

.audit-summary span {
  font-size: 24px;
  font-weight: 800;
}

.audit-summary small {
  margin-top: 4px;
  color: #58677a;
  font-weight: 700;
}

.table-wrap {
  max-height: 560px;
  margin-top: 14px;
  overflow: auto;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
}

.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.audit-table th,
.audit-table td {
  padding: 11px 12px;
  border-bottom: 1px solid #e5ebf1;
  text-align: left;
  vertical-align: top;
}

.audit-table th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
  text-transform: uppercase;
}

.audit-table tr:last-child td {
  border-bottom: none;
}

.duplicate-row {
  background: #fff7ed;
}

.pid-cell {
  width: 90px;
  font-weight: 800;
}

.path-cell {
  overflow-wrap: anywhere;
}

.number-cell {
  width: 70px;
  text-align: right;
}

.scope-cell {
  width: 170px;
  color: #92400e;
  font-weight: 750;
}

.empty-cell {
  color: #58677a;
  text-align: center;
}

.query-actions button:first-child {
  width: auto;
  min-width: 150px;
}

.status-line {
  min-height: 22px;
  margin-top: 16px;
  color: #58677a;
  font-weight: 600;
}

.status-line.error {
  color: #b91c1c;
}

.query-results {
  margin-top: 22px;
}

.document-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.document-item,
.passage-match-item {
  padding: 14px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: #ffffff;
}

.document-item h4,
.passage-match-item h4 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.document-item p,
.passage-match-item p {
  margin: 6px 0 0;
  color: #58677a;
  font-size: 13px;
}

.passage-match-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.passage-match-item blockquote {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-left: 4px solid #1d4ed8;
  background: #f8fafc;
  color: #172033;
  line-height: 1.45;
}

#json-output {
  max-height: 420px;
  margin: 16px 0 0;
  padding: 16px;
  overflow: auto;
  border-radius: 8px;
  background: #101827;
  color: #d6e4ff;
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 820px) {
  body {
    align-items: flex-start;
  }

  .card {
    margin: 0;
    min-height: 100vh;
    border-radius: 0;
  }

  .admin-header,
  .section-header,
  .results-header,
  .query-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .tool-list,
  .form-grid,
  .filter-row,
  .order-row,
  .passage-search-grid,
  .audit-controls,
  .audit-summary {
    grid-template-columns: 1fr;
  }

  .secondary-btn,
  .query-actions button:first-child {
    width: 100%;
  }
}
