:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #f2f6f4;
  --ink: #17211d;
  --muted: #65716b;
  --line: #dce3df;
  --teal: #16756f;
  --teal-dark: #0f5954;
  --amber: #b56a22;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(21, 35, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Segoe UI",
    Arial,
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  font-size: 20px;
  font-weight: 700;
}

.subline {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.nav-link {
  color: var(--ink);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 6px;
}

.nav-link.active,
.nav-link:hover {
  background: var(--surface-2);
}

.copy-btn,
.primary-btn,
.ghost-btn {
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 7px 12px;
  font-weight: 600;
}

.copy-btn,
.primary-btn {
  background: var(--teal);
  color: #ffffff;
}

.copy-btn {
  animation: wechatPulse 1.8s ease-in-out infinite;
  border-color: rgba(22, 117, 111, 0.28);
}

.copy-btn:hover,
.primary-btn:hover {
  background: var(--teal-dark);
}

@keyframes wechatPulse {
  0%,
  100% {
    background: #16756f;
    box-shadow: 0 0 0 0 rgba(22, 117, 111, 0.42);
    transform: translateY(0);
  }
  50% {
    background: #d97706;
    box-shadow: 0 0 0 8px rgba(217, 119, 6, 0);
    transform: translateY(-1px);
  }
}

.ghost-btn {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-btn:hover {
  border-color: #b8c5bf;
  background: var(--surface-2);
}

.view {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 24px 32px;
}

.hidden {
  display: none !important;
}

.filter-panel,
.tool-panel,
.login-panel,
.editor-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.filter-panel {
  position: sticky;
  top: 86px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
}

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

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.version-hint {
  color: #c1121f;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.update-alert {
  color: #c1121f;
  font-weight: 800;
}

.wechat-hint {
  margin-left: 8px;
  color: #111111;
  font-weight: 700;
}

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

.category-btn {
  min-height: 36px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  text-align: center;
}

.category-btn.active {
  background: #e5f2ef;
  border-color: var(--teal);
  color: var(--teal-dark);
  font-weight: 700;
}

select,
input[type="search"],
input[type="text"],
input[type="password"],
input:not([type]) {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
}

select:disabled {
  background: #f0f3f1;
  color: #8a948e;
  cursor: not-allowed;
}

input:focus,
select:focus {
  outline: 2px solid rgba(22, 117, 111, 0.18);
  border-color: var(--teal);
}

.answer-workspace {
  min-width: 0;
}

.workspace-head,
.admin-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 16px;
  margin-bottom: 12px;
}

#currentMeta,
#adminStatus {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.quick-jumps {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.jump-btn {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 6px;
  padding: 6px 9px;
  color: var(--muted);
}

.jump-btn:hover {
  color: var(--teal-dark);
  border-color: var(--teal);
}

.watermark-surface {
  position: relative;
  min-height: 420px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.watermark-grid {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: var(--watermark-opacity, 0.12);
  color: var(--teal-dark);
  font-weight: 700;
  overflow: hidden;
}

.watermark-grid span {
  position: absolute;
  font-size: var(--watermark-size, 18px);
  line-height: 1.25;
  white-space: nowrap;
  transform: translate(-50%, -50%) rotate(-18deg);
  transform-origin: center;
}

#answerContent {
  position: relative;
  z-index: 2;
  padding: 16px;
}

.public-lock,
.public-lock #publicView,
.public-lock .topbar,
.public-lock .answer-item,
.public-lock .section-block {
  -webkit-user-select: none;
  user-select: none;
}

.public-lock input,
.public-lock textarea,
.public-lock select {
  -webkit-user-select: text;
  user-select: text;
}

.public-lock img,
.public-lock a,
.public-lock button {
  -webkit-user-drag: none;
}

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

.section-block {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  overflow: hidden;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: #edf5f2;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.section-title small {
  color: var(--muted);
  font-weight: 600;
}

.answer-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  gap: 8px;
  padding: 10px;
}

.answer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #e5ece8;
  border-radius: 6px;
  background: #ffffff;
}

.answer-item .q {
  color: var(--muted);
  font-size: 12px;
}

.answer-item .a {
  font-weight: 800;
  color: var(--amber);
  overflow-wrap: anywhere;
}

.admin-view {
  display: block;
  padding: 18px 24px 32px;
}

.login-panel {
  max-width: 420px;
  margin: 42px auto;
  padding: 18px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.admin-console {
  display: grid;
  gap: 16px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.admin-tabs button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.admin-tabs button.active {
  border-color: rgba(22, 117, 111, 0.45);
  background: var(--teal);
  color: #ffffff;
}

.admin-panel {
  display: grid;
  gap: 16px;
}

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

.tool-panel,
.editor-panel {
  padding: 14px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin-bottom: 0;
}

.panel-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.context-pill {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.compact-btn {
  min-height: 30px;
  padding: 4px 9px;
}

.date-filter {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}

.date-filter label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.date-filter input {
  min-height: 34px;
}

.small-log {
  margin-top: 8px;
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.connection-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(22px, 1fr);
  align-items: end;
  gap: 8px;
  min-height: 160px;
  margin: 10px 0;
  padding: 12px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow-x: auto;
}

.chart-bar {
  display: grid;
  align-content: end;
  justify-items: center;
  min-width: 24px;
  height: 132px;
  gap: 5px;
}

.chart-bar-value {
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 800;
}

.chart-bar-fill {
  width: 100%;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--teal);
}

.chart-bar-date {
  writing-mode: vertical-rl;
  color: var(--muted);
  font-size: 10px;
}

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

.mini-table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  font-size: 12px;
}

.mini-table th,
.mini-table td {
  border-bottom: 1px solid #e6ece9;
  padding: 7px 8px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.mini-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #edf5f2;
  color: #173b37;
}

.editor-filters,
.inline-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.inline-form {
  grid-template-columns: 1.2fr 0.8fr auto;
}

.management-form {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.9fr) minmax(80px, 0.4fr) auto;
}

#groupForm {
  grid-template-columns: 1fr minmax(90px, 0.35fr) auto;
}

#newGroupForm {
  grid-template-columns: 1fr minmax(120px, 0.4fr) auto;
}

#addAnswerForm {
  grid-template-columns: 1.2fr 0.6fr 0.8fr auto;
}

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

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

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

.answers-table th,
.answers-table td {
  border-bottom: 1px solid #e6ece9;
  padding: 8px;
  text-align: left;
  vertical-align: middle;
}

.answers-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #edf5f2;
  color: #173b37;
  font-size: 12px;
}

.answers-table input {
  width: 100%;
  min-height: 34px;
}

.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.danger-btn {
  min-height: 34px;
  border: 1px solid #f2b8b5;
  border-radius: 6px;
  background: #fff5f5;
  color: var(--danger);
}

.backup-table-wrap {
  max-height: 420px;
}

.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 50;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 14px 20px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 12px;
  background: rgba(23, 33, 29, 0.94);
  color: #ffffff;
  box-shadow:
    0 18px 48px rgba(12, 22, 18, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -46%) scale(0.96);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  pointer-events: none;
  backdrop-filter: blur(12px);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .view {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .filter-panel {
    position: static;
  }

  .admin-grid,
  .editor-filters,
  .inline-form,
  .date-filter,
  #addAnswerForm {
    grid-template-columns: 1fr;
  }

  .workspace-head,
  .admin-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}
