:root {
  color-scheme: light dark;
  --bg: #f7f8fb;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #708090;
  --accent: #2563eb;
  --success: #16a34a;
  --warn: #dc2626;
  --border: #d9e2ec;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101522;
    --card: #152238;
    --text: #e3e8ef;
    --muted: #94a3b8;
    --accent: #60a5fa;
    --success: #4ade80;
    --warn: #f87171;
    --border: #27364a;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header,
footer {
  padding: 2rem clamp(1rem, 3vw, 3rem);
}

header h1 {
  margin-bottom: 0.25rem;
}

header .meta {
  margin: 0;
  color: var(--muted);
}

header .hint {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

header .actions {
  margin-top: 1rem;
}

header .actions .button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

header .actions .button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
}

.help-fab {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.2rem;
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.25);
  z-index: 20;
}

.help-fab:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

main {
  display: grid;
  gap: 1.5rem;
  padding: 0 clamp(1rem, 3vw, 3rem) 3rem;
}

.card {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: clamp(1rem, 2.5vw, 2rem);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.stat {
  background: rgba(37, 99, 235, 0.08);
  border-radius: 10px;
  padding: 1rem;
}

.stat .label {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.stat .value {
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--text);
}

.stat .value.success {
  color: var(--success);
}

.stat .value.warn {
  color: var(--warn);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.filters label {
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
  color: var(--muted);
}

.filters select,
.filters input {
  margin-top: 0.35rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 1rem;
  min-width: 160px;
  background: transparent;
  color: inherit;
}

.filters button {
  padding: 0.55rem 1rem;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 0.95rem;
}

.filters button:hover {
  opacity: 0.93;
}

.collapsible {
  border: none;
  padding: 0;
}

.collapsible summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  padding: 0;
}

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

.summary-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.collapsible summary h2 {
  margin: 0;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.15);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
}

.chevron {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.collapsible[open] .chevron {
  transform: rotate(45deg);
  border-color: var(--accent);
}

.chevron.small {
  width: 0.6rem;
  height: 0.6rem;
}

.site-entry .chevron {
  margin-left: auto;
}

.site-entry[open] .chevron {
  transform: rotate(45deg);
  border-color: var(--accent);
}

.collapsible-body {
  margin-top: 1rem;
}

.job-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.job-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  background: rgba(37, 99, 235, 0.05);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.job-card h3 {
  margin: 0;
  font-size: 1.05rem;
}

.job-card .job-meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.job-progress {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.18);
  overflow: hidden;
}

.job-progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s ease;
}

.job-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}

.job-stats li {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  background: rgb(85 100 157 / 50%);
}

.job-stats .label {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.job-stats .value {
  font-weight: 600;
  font-size: 1rem;
}

.job-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.table-container {
  max-height: 480px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

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

thead {
  position: sticky;
  top: 0;
  background: var(--card);
  box-shadow: 0 1px 0 var(--border);
}

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

tbody tr:hover {
  background: rgba(37, 99, 235, 0.06);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
}

.status-chip.error {
  background: rgba(220, 38, 38, 0.12);
  color: var(--warn);
}

.status-chip.ok {
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
}

.snapshot-link a {
  color: var(--accent);
  text-decoration: none;
}

.snapshot-link a:hover {
  text-decoration: underline;
}

.save-error {
  color: var(--warn);
  font-size: 0.85rem;
  white-space: pre-wrap;
}

.loading {
  text-align: center;
  color: var(--muted);
}

.muted-link {
  color: var(--muted);
  font-size: 0.85rem;
}

#root-links {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  padding-left: 0;
  list-style: none;
}

#root-links > li {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  background: rgba(37, 99, 235, 0.05);
}

#root-links > li h3 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

#root-links .site-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

#root-links .site-entry {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

#root-links .site-entry summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  padding: 0.75rem 1rem;
}

#root-links .site-entry summary::-webkit-details-marker {
  display: none;
}

#root-links .site-entry .link-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

#root-links .site-summary-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

#root-links .site-entry .link-count {
  font-size: 0.8rem;
  color: var(--muted);
}

.site-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
}

.type-badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(37, 99, 235, 0.15);
  color: var(--accent);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
}

#root-links .link-heading .muted-link {
  font-size: 0.8rem;
}

.site-notes {
  margin: 0.2rem 0 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.root-link-list {
  list-style: disc;
  margin: 0.4rem 0 0 1.1rem;
  padding: 0;
}

.root-link-list li {
  margin-bottom: 0.2rem;
}

#root-links a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95rem;
  word-break: break-all;
}

#root-links a:hover {
  text-decoration: underline;
}

footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

code {
  background: rgba(15, 23, 42, 0.08);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9rem;
}
