:root {
  color-scheme: light;
  --bg: #f7f8f4;
  --surface: #ffffff;
  --surface-strong: #eef4ef;
  --text: #17201a;
  --muted: #5f6f66;
  --border: #d9e1db;
  --accent: #246b52;
  --accent-strong: #174a39;
  --danger: #a73737;
  --shadow: 0 16px 40px rgba(23, 32, 26, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card p {
  margin: 4px 0 0;
  color: var(--muted);
}

.login-status {
  min-height: 24px;
  color: var(--muted);
  font-size: 14px;
}

.app-shell {
  display: none;
}

body[data-auth="logged-in"] .login-screen {
  display: none;
}

body[data-auth="logged-in"] .app-shell {
  display: block;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(36, 107, 82, 0.25);
  outline-offset: 2px;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary:hover {
  background: var(--accent-strong);
}

.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(247, 248, 244, 0.94);
  backdrop-filter: blur(12px);
}

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

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
}

.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.tabs {
  display: flex;
  gap: 8px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

body:not([data-role="admin"]) .admin-only {
  display: none;
}

.tab {
  background: transparent;
}

.tab.is-active {
  background: var(--text);
  color: #ffffff;
  border-color: var(--text);
}

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

.panel {
  display: none;
}

.panel.is-active {
  display: block;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 20px;
  align-items: start;
}

.qa-board,
.answer-area,
.admin-card,
.results,
.hit-details {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.qa-board,
.answer-area,
.admin-card {
  padding: 20px;
}

.results {
  overflow: hidden;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 600;
}

label small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.4;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-stack {
  display: grid;
  gap: 22px;
}

.settings-section {
  display: grid;
  gap: 14px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.section-title span {
  color: var(--muted);
  font-size: 14px;
}

.section-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.user-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

.user-table th,
.user-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.user-table th {
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 14px;
}

.user-table tr:last-child td {
  border-bottom: 0;
}

.user-table td:first-child {
  font-weight: 700;
  white-space: nowrap;
}

.user-table input {
  min-width: 180px;
}

.user-table select {
  min-width: 120px;
}

.row-delete {
  min-height: 38px;
  padding: 8px 12px;
}

.wide {
  grid-column: 1 / -1;
}

.form-row,
.actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.form-row {
  margin-top: 14px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.actions {
  margin-top: 16px;
  justify-content: flex-end;
}

.qa-board {
  display: grid;
  gap: 14px;
}

.checkbox {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--text);
  margin-right: auto;
}

.checkbox input {
  width: 18px;
  height: 18px;
}

.compact-field {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.compact-field input {
  width: 78px;
}

.answer-area {
  margin-top: 20px;
}

.admin-layout .answer-area {
  margin-top: 0;
}

.answer {
  min-height: 220px;
  margin-top: 14px;
  padding: 16px;
  border-radius: 8px;
  background: var(--surface-strong);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.answer-large {
  min-height: 300px;
}

.hit-details {
  margin-top: 18px;
  overflow: hidden;
}

.hit-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 700;
}

.compact-results {
  border-top: 1px solid var(--border);
  max-height: 360px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.section-head span,
.status {
  color: var(--muted);
  font-size: 14px;
}

.result-list {
  display: grid;
  gap: 12px;
  max-height: 640px;
  overflow: auto;
  padding: 14px;
}

.item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.item-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
}

.item-path,
.item-meta,
.item-summary {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--text);
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .tabs,
  .top-actions,
  .form-row,
  .actions {
    width: 100%;
  }

  .tab,
  .actions button {
    flex: 1;
  }

  .admin-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .section-title {
    display: grid;
  }
}
