:root {
  color-scheme: light dark;
  --bg: #f5f6f3;
  --surface: #fffefa;
  --surface-2: #edf1e9;
  --text: #1e261f;
  --muted: #6a7368;
  --accent: #2f7d57;
  --danger: #b44432;
  --line: rgba(30, 38, 31, 0.14);
  --shadow: 0 16px 42px rgba(32, 49, 37, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171b18;
    --surface: #202820;
    --surface-2: #263126;
    --text: #f0f5ef;
    --muted: #aeb8ad;
    --accent: #85c79f;
    --danger: #ed8977;
    --line: rgba(240, 245, 239, 0.14);
    --shadow: 0 16px 42px rgba(0, 0, 0, 0.25);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.admin-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px 18px 40px;
}

.login-shell {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 18px;
}

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

.login-card h1 {
  margin-bottom: 0;
}

.login-error {
  border: 1px solid var(--danger);
  border-radius: 12px;
  padding: 12px;
  color: var(--danger);
  background: transparent;
  line-height: 1.6;
}

.admin-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  padding: 16px 0 24px;
}

.back-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.logout-link {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  color: var(--muted);
  background: var(--surface);
  text-decoration: none;
}

h1 {
  margin: 12px 0 8px;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.05;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

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

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

.stat-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-card span,
.stat-card small {
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 34px;
  line-height: 1;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 18px;
  font-size: 22px;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-2);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check input {
  width: 18px;
  min-height: 18px;
}

button {
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 0 16px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

button.secondary,
.list-head button {
  color: var(--text);
  background: transparent;
  border-color: var(--line);
}

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

.list-panel {
  margin-top: 18px;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.cleanup-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 0.8fr) minmax(150px, 0.8fr) auto;
  align-items: end;
  gap: 12px;
}

.cleanup-form button {
  white-space: nowrap;
}

.cleanup-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.cleanup-preview[hidden] {
  display: none;
}

.cleanup-preview div {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
  background: var(--surface-2);
}

.cleanup-preview span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.cleanup-preview strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
  line-height: 1;
}

.cleanup-confirm {
  margin-top: 12px;
}

.modal {
  width: min(560px, calc(100% - 28px));
  max-height: calc(100dvh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.28);
}

.modal::backdrop {
  background: rgba(12, 16, 13, 0.42);
}

.modal form {
  padding: 20px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
}

.icon-close {
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-color: var(--line);
  color: var(--muted);
  background: transparent;
  font-size: 24px;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.config-list {
  display: grid;
  gap: 12px;
}

.channel-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: var(--surface-2);
}

.channel-top,
.model-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.channel-top strong,
.model-row strong {
  display: block;
}

.meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.models {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.model-row {
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.badge {
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.status {
  min-height: 24px;
  margin-top: 14px;
}

.popular-list {
  display: grid;
  gap: 8px;
}

.popular-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-2);
}

.popular-row span {
  color: var(--muted);
  white-space: nowrap;
}

@media (max-width: 820px) {
  .grid,
  .stats-grid,
  .channel-top,
  .model-row {
    grid-template-columns: 1fr;
  }

  .grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .channel-top,
  .model-row {
    display: grid;
  }

  .popular-row {
    align-items: start;
    display: grid;
  }

  .list-head,
  .toolbar,
  .cleanup-form,
  .cleanup-preview,
  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar button,
  .modal-actions button {
    width: 100%;
  }
}
