:root {
  color-scheme: dark;
  --bg: #10141b;
  --text: #e7edf5;
  --muted: #9aa8ba;
  --line: #2b3545;
  --panel: #161c26;
  --panel-soft: #1d2531;
  --primary: #7aa7ff;
  --primary-dark: #5d8fe8;
  --button: #2f6eea;
  --button-hover: #245bc8;
  --success: #173c2a;
  --error: #4a2024;
  --warning: #4a3b18;
  --info: #18354c;
}

body.theme-light {
  color-scheme: light;
  --bg: #f6f7f9;
  --text: #17202a;
  --muted: #627082;
  --line: #d9dee7;
  --panel: #ffffff;
  --panel-soft: #eef3ff;
  --primary: #2457c5;
  --primary-dark: #1f4699;
  --button: #2457c5;
  --button-hover: #1f4699;
  --success: #dff5e7;
  --error: #fde1e1;
  --warning: #fff3cd;
  --info: #e0f0ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

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

nav {
  display: flex;
  align-items: center;
  gap: 14px;
}

nav form {
  margin: 0;
}

.page {
  width: min(1080px, calc(100% - 32px));
  margin: 32px auto;
}

.panel {
  margin-bottom: 20px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.narrow {
  max-width: 460px;
  margin-left: auto;
  margin-right: auto;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

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

.split-actions {
  margin-top: 16px;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
}

.stacked-form {
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.muted,
.section-heading p {
  color: var(--muted);
}

.form,
.search-form {
  display: grid;
  gap: 14px;
}

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

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}

input[type="checkbox"] {
  width: auto;
  min-height: 0;
}

.inline-form label,
.actions label {
  align-items: center;
  display: flex;
  gap: 6px;
}

button {
  min-height: 42px;
  padding: 8px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--button);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

button:hover {
  background: var(--button-hover);
}

.messages {
  margin-bottom: 16px;
}

.message {
  padding: 10px 12px;
  border-radius: 6px;
}

.message.success {
  background: var(--success);
}

.message.error {
  background: var(--error);
}

.result {
  margin-top: 16px;
  padding: 12px;
  background: var(--panel-soft);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

code {
  padding: 2px 5px;
  background: var(--panel-soft);
  border-radius: 4px;
}

.truncate {
  max-width: 280px;
  overflow-wrap: anywhere;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 1.7rem;
  line-height: 1.1;
}

.status {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.detail-block,
.job-panel {
  padding: 14px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.job-panel {
  margin-bottom: 16px;
}

.top-job-panel {
  margin-top: 8px;
}

.job-summary {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.admin-tabs a {
  padding: 5px 9px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.admin-tabs a.active {
  background: var(--button);
  color: #ffffff;
}

.admin-overview {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 12px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
}

.admin-overview h1 {
  margin-bottom: 8px;
  font-size: 1.35rem;
}

.admin-overview .stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.admin-overview .stat {
  min-height: 58px;
  padding: 8px 9px;
}

.admin-overview .stat span {
  font-size: 0.72rem;
  line-height: 1.15;
}

.admin-overview .stat strong {
  margin-top: 2px;
  font-size: 1.25rem;
}

.compact-job-panel {
  margin-bottom: 8px;
  padding: 8px 10px;
}

.job-details summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
}

.job-details summary::-webkit-details-marker {
  display: none;
}

.job-details summary::before {
  content: "+";
  color: var(--muted);
  font-weight: 700;
}

.job-details[open] summary::before {
  content: "-";
}

.job-title {
  font-weight: 700;
}

.job-message {
  color: var(--muted);
  min-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-empty-job {
  margin: 0;
  font-size: 0.9rem;
}

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

.compact-job-row {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.pipe-menu {
  position: relative;
}

.pipe-menu > summary {
  min-height: 42px;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--button);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.pipe-menu > summary::-webkit-details-marker {
  display: none;
}

.pipe-menu[open] .pipe-menu-content {
  display: grid;
}

.pipe-menu-content {
  display: none;
  gap: 10px;
  min-width: min(360px, calc(100vw - 40px));
  padding: 12px;
  margin-top: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
  position: absolute;
  z-index: 20;
}

.compact-worker-panel {
  padding: 10px 12px;
}

.admin-categories {
  display: flex;
  flex-direction: column;
}

.category-matching {
  order: 1;
}

.category-guild {
  order: 2;
}

.category-clusters {
  order: 3;
}

.category-queue {
  order: 4;
}

.category-debug {
  order: 5;
}

.category-scanlogs {
  order: 6;
}

.category-users {
  order: 7;
}

.category-datasources {
  order: 8;
}

.admin-category {
  scroll-margin-top: 18px;
}

.log-view {
  margin-top: 16px;
}

.log-view summary {
  cursor: pointer;
  font-weight: 700;
}

.log-view pre {
  max-height: 420px;
  overflow: auto;
  padding: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  white-space: pre-wrap;
}

.status-badge {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.status-success,
.status-running {
  background: var(--success);
  color: #94f0bb;
}

.theme-light .status-success,
.theme-light .status-running {
  color: #116b37;
}

.status-partial,
.status-queued {
  background: var(--warning);
  color: #ffd56a;
}

.theme-light .status-partial,
.theme-light .status-queued {
  color: #7a5600;
}

.status-empty,
.status-verweigert,
.status-failed,
.status-stopped {
  background: var(--error);
  color: #ffb5bd;
}

.theme-light .status-empty,
.theme-light .status-verweigert,
.theme-light .status-failed,
.theme-light .status-stopped {
  color: #9a2530;
}

.status-not_found,
.status-none {
  background: var(--info);
  color: #9dd4ff;
}

.theme-light .status-not_found,
.theme-light .status-none {
  color: #245273;
}

.compact-list {
  margin: 8px 0 0;
  padding-left: 18px;
}

@media (max-width: 720px) {
  .topbar,
  nav,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .inline-form {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  table {
    display: block;
    overflow-x: auto;
  }
}
