:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #dfe4ec;
  --border-strong: #c9d1de;
  --text: #1c2430;
  --muted: #64708a;
  --accent: #1f6feb;
  --accent-soft: #e8f0ff;
  --ok: #17803d;
  --warn: #a15c00;
  --warn-soft: #fff5e2;
  --err: #b42318;
  --err-soft: #fdecea;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.logo {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
}

.brand-sub {
  font-size: 15px;
  color: var(--muted);
}

.meta {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.logout-btn {
  flex: none;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.logout-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---------- 布局 ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-areas:
    "query history"
    "result history";
  align-items: start;
  gap: 16px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 16px 24px 48px;
}

.query-panel {
  grid-area: query;
}

.result-panel {
  grid-area: result;
}

.history-panel {
  grid-area: history;
  position: sticky;
  top: 76px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: 0 1px 2px rgba(20, 30, 50, 0.04);
}

/* ---------- 输入 ---------- */

.mode-tabs {
  display: inline-flex;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}

.mode-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 16px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}

.mode-tab.active {
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(20, 30, 50, 0.1);
}

.query-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 12px;
  color: var(--muted);
}

input[type="text"],
input[type="date"],
input[type="number"],
input:not([type]),
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.14);
}

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

.inline-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
}

.field.compact {
  max-width: 220px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  padding-bottom: 6px;
  cursor: pointer;
  user-select: none;
}

.checkbox.tall {
  align-self: end;
  padding-bottom: 9px;
}

.checkbox input:disabled + span {
  opacity: 0.55;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- 操作 ---------- */

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

button.primary {
  border: 0;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 9px 22px;
  border-radius: 8px;
  cursor: pointer;
}

button.primary:hover:not(:disabled) {
  background: #185aba;
}

button.primary:disabled {
  background: #9db7e2;
  cursor: not-allowed;
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

.ghost {
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 4px 11px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}

.ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.ghost:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- 状态 ---------- */

.status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 8px;
}

.spinner {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status-text {
  font-size: 13px;
}

.status-sub {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.form-error {
  margin-top: 14px;
  padding: 10px 14px;
  border: 1px solid #f3c3be;
  background: var(--err-soft);
  color: var(--err);
  border-radius: 8px;
  font-size: 13px;
  white-space: pre-wrap;
}

/* ---------- 结果 ---------- */

.result-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.verdict {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 14px 16px;
  background: #fbfcfe;
}

.verdict-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #c8dbff;
  padding: 2px 8px;
  border-radius: 5px;
}

.confidence {
  font-size: 12px;
  color: var(--muted);
}

.conclusion {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.5;
}

.owners {
  margin-top: 8px;
  font-size: 13px;
}

.owners-label {
  color: var(--muted);
  margin-right: 6px;
}

.owner {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  background: #eef6ee;
  color: var(--ok);
  border: 1px solid #cfe6d4;
  padding: 1px 8px;
  border-radius: 999px;
  margin-right: 6px;
}

.alt {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.alt-chip {
  font-family: var(--mono);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 8px;
  border-radius: 999px;
}

.sentence-box {
  border: 1px solid #cfe0ff;
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 10px 14px;
}

.sentence-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.sentence-box code {
  font-family: var(--mono);
  font-size: 13px;
  color: #123a78;
  word-break: break-all;
  white-space: pre-wrap;
}

.warnings {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.warning-row {
  display: flex;
  gap: 8px;
  font-size: 12px;
  background: var(--warn-soft);
  border: 1px solid #f2dcb8;
  color: var(--warn);
  border-radius: 6px;
  padding: 6px 10px;
}

.warning-tag {
  flex: 0 0 auto;
  font-weight: 600;
}

.result-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.result-tab {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  padding: 8px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.result-tab.active {
  color: var(--accent);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.view {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fbfcfe;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  max-height: 520px;
  overflow: auto;
}

div.view {
  background: transparent;
  border: 0;
  padding: 0;
  max-height: none;
}

.evidence-block + .evidence-block {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}

.evidence-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.evidence-title {
  font-size: 13px;
  color: var(--muted);
}

.evidence-row {
  display: grid;
  grid-template-columns: 92px 200px minmax(0, 1fr);
  gap: 10px;
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
}

.evidence-row:nth-child(odd) {
  background: #f8fafc;
}

.evidence-row.anchor {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

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

.evidence-where {
  color: #3d4a63;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.evidence-msg {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.result-meta {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

/* ---------- 历史 ---------- */

.history-panel h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 10px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: calc(100vh - 180px);
  overflow: auto;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

.history-item:hover {
  background: var(--bg);
}

.history-item.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.history-item.unmatched .history-title::after {
  content: " · 未命中";
  color: var(--warn);
  font-size: 11px;
}

.history-title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

.empty {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 0;
}

/* ---------- 响应式 ---------- */

@media (max-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "query"
      "result"
      "history";
    padding: 12px 14px 40px;
  }

  .history-panel {
    position: static;
  }

  .history-list {
    max-height: none;
  }

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

  .inline-row {
    flex-direction: column;
    align-items: stretch;
  }

  .field.compact {
    max-width: none;
  }

  .evidence-row {
    grid-template-columns: 80px minmax(0, 1fr);
  }

  .evidence-msg {
    grid-column: 1 / -1;
    white-space: normal;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 10px 14px;
  }

  .meta {
    text-align: left;
  }
}

/* ---------- 批量结果 ---------- */

.batch-summary {
  font-weight: 600;
  margin-bottom: 12px;
}

.batch-table-wrap {
  overflow-x: auto;
  margin-bottom: 12px;
}

.batch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.batch-table th,
.batch-table td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  white-space: nowrap;
}

.batch-table th {
  color: var(--muted);
  font-weight: 600;
  background: #fafbfd;
}

.batch-table td:nth-child(6) {
  font-family: var(--mono);
}

.batch-status.ok {
  color: var(--ok);
  font-weight: 600;
}

.batch-status.warn {
  color: var(--warn);
  font-weight: 600;
}

.batch-status.err {
  color: var(--err);
  font-weight: 600;
}

.batch-detail td {
  background: #fafbfd;
  padding: 8px 12px;
  white-space: normal;
}

.batch-detail pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 12px;
  max-height: 420px;
  overflow: auto;
}

.batch-errors {
  margin-top: 8px;
  color: var(--err);
  font-size: 12px;
}
