:root {
  --bg: oklch(0.985 0.006 95);
  --surface: oklch(1 0 0);
  --surface-soft: oklch(0.965 0.008 100);
  --text: oklch(0.23 0.018 255);
  --muted: oklch(0.49 0.022 255);
  --line: oklch(0.9 0.012 255);
  --primary: oklch(0.48 0.115 205);
  --primary-strong: oklch(0.39 0.105 205);
  --primary-soft: oklch(0.94 0.035 205);
  --success: oklch(0.56 0.12 155);
  --warning: oklch(0.64 0.14 72);
  --danger: oklch(0.58 0.16 25);
  --radius: 8px;
  --shadow: 0 10px 28px oklch(0.35 0.02 255 / 0.08);
  --font: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
}

a {
  color: var(--primary);
  text-decoration: none;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: oklch(1 0 0 / 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.header-inner,
.page-title,
.page-shell {
  max-width: 1240px;
  margin: 0 auto;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 24px 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  color: var(--text);
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 9px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

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

.top-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.top-nav a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 13px;
  color: var(--muted);
  transition: background 160ms ease, color 160ms ease;
}

.top-nav a:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.top-nav a.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 700;
}

.page-title {
  padding: 2px 24px 14px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.25;
}

h1 {
  font-size: 24px;
  font-weight: 760;
}

h2 {
  font-size: 17px;
}

.page-shell {
  padding: 18px 24px 40px;
}

.toolbar-card,
.panel,
.candidate {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar-card {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(180px, 0.55fr) minmax(0, 2fr);
  gap: 20px;
  align-items: end;
  padding: 18px;
  margin-bottom: 16px;
}

.toolbar-card p,
.section-head p,
.muted {
  color: var(--muted);
}

.toolbar-card p,
.section-head p {
  margin: 6px 0 0;
}

form {
  margin: 0;
}

.filters,
.edit-form,
.action-form {
  display: grid;
  gap: 12px;
}

.filters {
  grid-template-columns: minmax(120px, 0.6fr) minmax(180px, 1.2fr) minmax(150px, 0.8fr) minmax(120px, 0.6fr) minmax(120px, 0.6fr) auto;
  align-items: end;
}

.rules-toolbar,
.default-floor-form,
.threshold-bulk-form {
  display: grid;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.rules-toolbar {
  grid-template-columns: minmax(240px, 1fr) 120px auto auto;
}

.default-floor-form {
  grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(130px, 0.5fr)) auto minmax(160px, 0.6fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.threshold-bulk-form {
  grid-template-columns: minmax(220px, 1fr) repeat(2, minmax(140px, 0.55fr)) repeat(3, minmax(78px, 0.35fr)) auto minmax(160px, 0.6fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.default-floor-form p,
.threshold-bulk-form p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.edit-form {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.assistant-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-weight: 650;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

select,
input {
  min-height: 38px;
  padding: 0 11px;
}

textarea {
  min-height: 118px;
  padding: 10px 11px;
  resize: vertical;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px oklch(0.48 0.115 205 / 0.14);
}

button,
.open-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--primary);
  border-radius: 7px;
  padding: 0 14px;
  background: var(--primary);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  transition: transform 120ms ease, background 150ms ease, border-color 150ms ease;
}

button:hover,
.open-link:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

button:active,
.open-link:active {
  transform: scale(0.98);
}

button.secondary,
.row-actions button:nth-child(2),
.secondary-link {
  background: #ffffff;
  color: var(--primary-strong);
}

button.secondary:hover,
.row-actions button:nth-child(2):hover,
.secondary-link:hover {
  background: var(--primary-soft);
}

.wide-field {
  grid-column: span 2;
}

.checkbox-field {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: end;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  background: var(--surface-soft);
  color: var(--text);
}

.checkbox-field input {
  width: auto;
  min-height: auto;
}

.preview-switch {
  display: grid;
  gap: 6px;
  align-self: stretch;
}

.preview-switch p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.form-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.candidate-list {
  display: grid;
  gap: 14px;
}

.candidate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  padding: 18px;
}

.candidate-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.account-line,
.time-line,
.reason-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.account-line strong {
  font-size: 16px;
}

.account-line span,
.time-line,
.pill,
.tag,
.status-pill {
  color: var(--muted);
}

.account-line span,
.pill,
.tag,
.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--surface-soft);
  font-size: 12px;
}

.time-line {
  margin-top: 7px;
  font-size: 13px;
}

.score-box {
  min-width: 86px;
  border: 1px solid oklch(0.88 0.06 72);
  border-radius: 8px;
  padding: 8px 10px;
  background: oklch(0.97 0.035 72);
  text-align: right;
}

.score-box span {
  display: block;
  color: oklch(0.46 0.08 72);
  font-size: 12px;
}

.score-box strong {
  display: block;
  color: oklch(0.42 0.1 72);
  font-size: 22px;
  line-height: 1.15;
}

.candidate-text {
  margin: 14px 0;
  white-space: pre-wrap;
  color: oklch(0.29 0.018 255);
  font-size: 15px;
}

.reason-row {
  gap: 7px;
}

.reason-row .pill {
  background: var(--primary-soft);
  border-color: oklch(0.86 0.04 205);
  color: var(--primary-strong);
}

.pill.warn {
  background: #fff7ed;
  border-color: #fdba74;
  color: #c2410c;
}

.ai-review {
  border: 1px solid oklch(0.88 0.04 155);
  border-radius: 8px;
  padding: 12px;
  margin-top: 14px;
  background: oklch(0.97 0.026 155);
}

.ai-review.skip {
  border-color: oklch(0.88 0.055 55);
  background: oklch(0.975 0.026 55);
}

.ai-review.neutral {
  border-color: var(--line);
  background: var(--surface-soft);
}

.ai-review-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: oklch(0.35 0.07 155);
}

.ai-review p {
  margin: 8px 0 0;
}

.assistant-output {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.assistant-summary,
.assistant-answer {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-soft);
}

.assistant-summary {
  color: var(--text);
  font-weight: 700;
}

.assistant-answer {
  min-height: 120px;
  white-space: pre-wrap;
}

.assistant-results {
  display: grid;
  gap: 12px;
}

.assistant-result-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.assistant-result-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.assistant-result-head h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.assistant-result-head span {
  flex: 0 0 auto;
  color: oklch(0.42 0.1 72);
  font-weight: 800;
}

.assistant-result-text {
  max-height: 96px;
  overflow: auto;
  margin: 10px 0;
  color: oklch(0.29 0.018 255);
  white-space: pre-wrap;
}

.assistant-result-note {
  display: grid;
  gap: 6px;
  border-left: 3px solid var(--primary);
  padding-left: 10px;
}

.assistant-result-note p {
  margin: 0;
}

.assistant-result-side {
  display: grid;
  align-content: start;
  gap: 10px;
}

.candidate-side {
  display: grid;
  align-content: start;
  gap: 12px;
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: var(--surface-soft);
}

.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-grid strong {
  display: block;
  margin-top: 2px;
  font-size: 17px;
}

.action-form {
  grid-template-columns: 1fr;
}

.post-preview-slot {
  display: grid;
  gap: 8px;
  margin: 12px 0 14px;
}

.post-preview-frame {
  width: 100%;
  height: min(430px, 58vh);
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.preview-empty {
  min-height: 360px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

.preview-empty strong {
  color: var(--text);
  font-size: 15px;
}

.preview-empty span {
  max-width: 360px;
  padding: 0 14px;
  font-size: 12px;
}

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

/* Twitter widgets.js blockquote 容器 */
.twitter-tweet {
  margin: 0 !important;
  max-width: 100% !important;
}

/* Twitter 嵌入包装器 - 高度由 JS inline max-height 控制 */

.twitter-preview-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
}

.twitter-preview-loading .loading-hint {
  font-size: 14px;
  color: var(--muted);
}

/* Twitter 降级本地卡片 */
.twitter-fallback-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 16px;
  min-height: 200px;
}

.tfc-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.tfc-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #1d1d1d;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  flex-shrink: 0;
}

.tfc-name {
  font-weight: 600;
  font-size: 15px;
}

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

.tfc-text {
  line-height: 1.65;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.tfc-metrics {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}

.tfc-link {
  display: inline-block;
  color: oklch(0.5 0.08 205);
  text-decoration: none;
  border: 1px solid oklch(0.7 0.06 205);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}

.tfc-link:hover {
  background: oklch(0.5 0.08 205);
  color: #ffffff;
}

.panel {
  padding: 18px;
  margin-bottom: 16px;
}

.section-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.notice-box {
  border: 1px solid oklch(0.88 0.04 205);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--primary-soft);
  color: oklch(0.34 0.06 205);
}

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

.rules-table-wrap {
  max-height: 64vh;
  overflow: auto;
}

.rules-table-wrap table {
  min-width: 1080px;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  background: #ffffff;
}

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

tbody tr:hover {
  background: oklch(0.985 0.004 255);
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

td input,
td select {
  min-width: 110px;
}

.rules-table-wrap td input,
.rules-table-wrap td select {
  min-width: 88px;
}

.rules-table-wrap td:nth-child(9) input {
  min-width: 100px;
}

.rules-table-wrap td:last-child {
  min-width: 86px;
}

code {
  font-family: var(--mono);
  font-size: 12px;
}

.url-cell {
  display: inline-block;
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  gap: 8px;
  min-width: 150px;
}

.row-actions button {
  min-height: 32px;
  padding: 0 10px;
}

.save-status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
}

.pagination a {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  background: #ffffff;
  color: var(--text);
}

.pagination a.disabled {
  pointer-events: none;
  color: oklch(0.68 0.016 255);
  background: var(--surface-soft);
}

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

.config-status div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.config-status span,
.config-status strong {
  display: block;
}

.config-status span {
  color: var(--muted);
  font-size: 12px;
}

.config-status strong {
  margin-top: 4px;
  font-weight: 700;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 34px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

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

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

.login-brand {
  margin-bottom: 18px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.login-error {
  border: 1px solid oklch(0.84 0.08 25);
  border-radius: 8px;
  padding: 10px 12px;
  background: oklch(0.97 0.03 25);
  color: oklch(0.45 0.12 25);
}

.collector-alerts {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.collector-alert {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 12px 14px;
}

.collector-alert.error {
  border-color: oklch(0.78 0.14 25);
  background: oklch(0.97 0.03 25);
  color: oklch(0.42 0.15 25);
}

.collector-alert.warning {
  border-color: oklch(0.82 0.12 75);
  background: oklch(0.98 0.04 75);
  color: oklch(0.38 0.1 75);
}

.collector-alert small {
  color: inherit;
  opacity: 0.82;
}

.status-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 9px;
}

.status-pill.error {
  background: oklch(0.95 0.04 25);
  color: oklch(0.43 0.14 25);
}

.status-pill.warning {
  background: oklch(0.96 0.05 75);
  color: oklch(0.4 0.1 75);
}

.status-pill.ok {
  background: oklch(0.95 0.05 160);
  color: oklch(0.36 0.1 160);
}

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

@media (max-width: 980px) {
  .toolbar-card,
  .candidate {
    grid-template-columns: 1fr;
  }

  .filters,
  .edit-form,
  .assistant-form,
  .rules-toolbar,
  .default-floor-form,
  .threshold-bulk-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .candidate-side {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 14px;
  }

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

@media (max-width: 680px) {
  .header-inner,
  .page-title,
  .page-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .header-inner {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand {
    min-width: 0;
  }

  .top-nav {
    justify-content: flex-start;
    width: 100%;
  }

  .top-nav a {
    min-height: 34px;
    padding: 0 10px;
  }

  .page-shell {
    padding-top: 14px;
  }

  .toolbar-card,
  .panel,
  .candidate {
    padding: 14px;
  }

  .filters,
  .edit-form,
  .assistant-form,
  .rules-toolbar,
  .default-floor-form,
  .threshold-bulk-form,
  .config-status {
    grid-template-columns: 1fr;
  }

  .wide-field {
    grid-column: auto;
  }

  .form-actions,
  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .candidate-head {
    flex-direction: column;
  }

  .score-box {
    width: 100%;
    text-align: left;
  }

  .post-preview-frame,
  .preview-empty {
    min-height: 320px;
  }
}
