:root {
  font-size: 14px;
  --paper: #f6faf7;
  --panel: #ffffff;
  --line: #dce8df;
  --line-soft: #eef5f0;
  --text: #1f2933;
  --muted: #6f7d74;
  --accent: #15915f;
  --accent-strong: #0f7a4f;
  --accent-soft: #e8f7ef;
  --green: #16935f;
  --green-soft: #e8f7ef;
  --purple: #2e8f68;
  --purple-soft: #eaf8f1;
  --danger: #b42318;
  --header: #ffffff;
  --input: #ffffff;
  --input-border: #cfd3cb;
  --table-head: #eef7f1;
  --row-even: #fafbfd;
  --chip: #f2f5fa;
  --button-panel: #ffffff;
  --skeleton-mid: #f4f7fb;
  --hover-border: #bfd8d1;
  --hover-border-strong: #9bc8b6;
  --shadow: 0 8px 22px rgba(22, 97, 63, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0d1511;
  --panel: #14211a;
  --line: #294438;
  --line-soft: #20352b;
  --text: #e6f0ea;
  --muted: #93a89d;
  --accent: #42c986;
  --accent-strong: #67d69e;
  --accent-soft: #173b29;
  --green: #42c986;
  --green-soft: #173b29;
  --purple: #42c986;
  --purple-soft: #173b29;
  --danger: #ff8a80;
  --header: #111b16;
  --input: #0f1a15;
  --input-border: #355246;
  --table-head: #182c22;
  --row-even: #111d18;
  --chip: #1b2d24;
  --button-panel: #14211a;
  --skeleton-mid: #18261f;
  --hover-border: #3b6a55;
  --hover-border-strong: #4f8a70;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

.app-container {
  width: min(1480px, calc(100vw - 48px));
  margin: 0 auto;
}

.app-header {
  border-bottom: 1px solid var(--line);
  background: var(--header);
  box-shadow: 0 1px 4px rgba(22, 97, 63, 0.04);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
}

.brand {
  color: var(--text);
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.header-tools {
  display: flex;
  gap: 22px;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
}

.header-tools b {
  color: var(--text);
}

.source-link,
.status-item {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.source-link {
  color: var(--muted);
  text-decoration: none;
}

.source-link:hover,
.source-link:focus {
  color: var(--accent);
  text-decoration: none;
}

.nav-icon {
  flex: none;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle {
  display: inline-grid;
  width: 32px;
  min-width: 32px;
  height: 32px;
  min-height: 32px;
  place-items: center;
  padding: 0;
  border-color: var(--line);
  border-radius: 50%;
  background: var(--button-panel);
  color: var(--text);
  line-height: 1;
}

.theme-toggle:hover,
.theme-toggle:focus {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.theme-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-icon-sun {
  display: none;
}

html[data-theme="dark"] .theme-icon-moon {
  display: none;
}

html[data-theme="dark"] .theme-icon-sun {
  display: block;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.divider {
  width: 1px;
  height: 18px;
  background: var(--line);
}

.shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  height: calc(100vh - 52px);
  min-height: 0;
  padding: 14px 0;
  overflow: hidden;
}

.query-block,
.panel,
.stat-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.query-block {
  padding: 12px 14px;
  margin-bottom: 0;
}

.query-form {
  display: grid;
  grid-template-columns: minmax(0, 760px) 128px;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin: 0;
}

.query-form input,
.query-form button {
  width: 100%;
  height: 40px;
  min-height: 40px;
  padding-top: 0;
  padding-bottom: 0;
  line-height: 40px;
}

.query-form input {
  line-height: normal;
}

input,
select,
button {
  display: block;
  box-sizing: border-box;
  min-height: 40px;
  height: 40px;
  margin: 0;
  font-size: 0.94rem;
  line-height: 1.2;
  transform: none;
  transition:
    background-color 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease;
}

input,
select {
  width: 100%;
  border-color: var(--input-border);
  border-radius: 7px;
  background: var(--input);
  color: var(--text);
}

button {
  border-width: 1px;
  border-style: solid;
  border-radius: 7px;
  font-weight: 750;
  box-shadow: none;
}

button:hover,
button:focus,
button:active {
  transform: none;
  box-shadow: none;
}

.query-form button,
.pager button:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.query-form button:hover,
.pager button:not(:disabled):hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.query-result {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  text-align: center;
}

.query-result:empty {
  display: none;
}

.query-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

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

.stat-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 76px;
  padding: 14px 16px;
}

.stat-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.15rem;
  font-weight: 900;
}

.tone-green .stat-icon,
.tone-primary .stat-icon,
.tone-purple .stat-icon {
  background: var(--green-soft);
  color: var(--green);
}

.stat-label {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.stat-value {
  overflow: hidden;
  color: var(--text);
  font-size: 1.38rem;
  font-weight: 900;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.skeleton {
  min-height: 76px;
  background: linear-gradient(90deg, var(--panel), var(--skeleton-mid), var(--panel));
}

.content-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  min-height: 0;
}

.panel {
  min-width: 0;
}

.group-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  padding: 10px;
}

.detail-panel {
  height: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 26px;
  margin-bottom: 8px;
}

h1,
h2 {
  margin: 0;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: 0;
}

h1 {
  font-size: 1rem;
}

h2 {
  overflow: hidden;
  font-size: 1.08rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-filter {
  height: 32px;
  min-height: 32px;
  margin-bottom: 6px;
  border-radius: 7px;
  font-size: 0.86rem;
}

.groups {
  display: grid;
  grid-auto-rows: min-content;
  gap: 1px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.group-meta,
.detail-meta,
.muted,
.empty-state {
  color: var(--muted);
}

.group-meta {
  padding: 0 7px 4px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.78rem;
}

.group-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 6px;
  align-items: center;
  width: 100%;
  min-height: 28px;
  height: 28px;
  padding: 3px 7px;
  border: 1px solid var(--panel);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.group-row:hover,
.group-row:focus {
  border-color: var(--hover-border);
  background: var(--accent-soft);
}

.group-row.is-active,
.group-row[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.group-row.is-active .group-name,
.group-row[aria-current="true"] .group-name {
  font-weight: 850;
}

.group-row.is-active .group-count,
.group-row[aria-current="true"] .group-count {
  color: var(--accent);
}

.group-name {
  overflow: hidden;
  font-size: 0.86rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.details {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
}

.detail-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, auto);
  gap: 12px;
  align-items: center;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--line-soft);
}

.detail-title {
  min-width: 0;
}

.title-line {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.copy-group {
  display: inline-grid;
  flex: none;
  width: 28px;
  min-width: 28px;
  height: 28px;
  min-height: 28px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--button-panel);
  color: var(--muted);
  cursor: pointer;
}

.copy-group:hover,
.copy-group:focus {
  border-color: var(--hover-border);
  background: var(--accent-soft);
  color: var(--accent);
}

.copy-group svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.detail-chip {
  flex: none;
  border-radius: 6px;
  padding: 4px 8px;
  background: var(--chip);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.detail-meta {
  margin-top: 3px;
  font-size: 0.84rem;
}

.detail-tools {
  display: grid;
  grid-template-columns: minmax(180px, 280px) auto;
  gap: 10px;
  align-items: center;
}

.detail-filter {
  width: 100%;
  height: 34px;
  min-height: 34px;
  font-size: 0.86rem;
}

.page-size {
  display: grid;
  grid-template-columns: auto 88px;
  gap: 8px;
  align-items: center;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.page-size select {
  width: 88px;
  min-width: 88px;
  height: 34px;
  min-height: 34px;
  padding-right: 26px;
}

.table-wrap {
  width: 100%;
  min-height: 0;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 760px;
  margin: 0;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--panel);
  font-size: 0.9rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

th {
  height: 34px;
  background: var(--table-head);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 800;
  text-align: left;
}

td,
th {
  padding: 6px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

tbody tr:nth-child(even) {
  background: var(--row-even);
}

tbody tr:hover {
  background: var(--accent-soft);
}

th:nth-child(1),
td:nth-child(1) {
  width: 52%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 130px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 170px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 170px;
}

.rule-value {
  overflow-wrap: anywhere;
  font-family: Consolas, "SFMono-Regular", monospace;
}

.type {
  display: inline-flex;
  min-width: 70px;
  justify-content: center;
  border-radius: 999px;
  padding: 1px 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
}

.attrs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.attr {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border-radius: 999px;
  padding: 1px 7px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
}

.pager {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding: 7px 14px;
  border-top: 1px solid var(--line-soft);
  background: var(--panel);
}

.pager button {
  min-width: 54px;
  height: 30px;
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.pager .pseudo {
  min-width: 100px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.result-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.domain {
  font-weight: 800;
}

.site-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
  margin-top: 8px;
}

.query-result .site-tags {
  margin-top: 0;
}

.site-tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  height: 30px;
  padding: 4px 9px;
  border: 1px solid var(--hover-border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  transform: none;
  box-shadow: none;
}

.site-tag:hover,
.site-tag:focus,
.site-tag:active {
  border-color: var(--hover-border-strong);
  background: var(--accent-soft);
  transform: none;
  box-shadow: none;
}

.error {
  color: var(--danger);
  font-weight: 700;
}

.empty-state {
  display: grid;
  height: 100%;
  min-height: 320px;
  place-items: center;
}

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline;
}

@media (max-width: 920px) {
  .app-container {
    width: min(100vw - 24px, 1440px);
  }

  .query-form,
  .content-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .header-tools {
    display: none;
  }

  .group-panel,
  .detail-panel {
    height: auto;
    min-height: 0;
  }

  body {
    overflow: auto;
  }

  .groups {
    max-height: 320px;
  }

  .detail-head,
  .pager {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .detail-tools {
    grid-template-columns: 1fr;
  }

  .pager {
    flex-direction: column;
  }
}
