:root {
  color-scheme: dark;
  --bg: #08090f;
  --card: #141620;
  --card-2: #10121b;
  --line: #ffffff1a;
  --line-strong: #ffffff2b;
  --text: #f7f7fb;
  --muted: #b8bbc8;
  --a: #ff3d6e;
  --ok: #3ddc97;
  --warn: #f8c14a;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

header,
main {
  width: min(100% - 2rem, 1420px);
  margin: auto;
}

header {
  padding: 2rem 0 1rem;
}

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

h1 {
  margin-bottom: .45rem;
  font-size: clamp(1.8rem, 4vw, 3rem);
}

h2 {
  font-size: 1.28rem;
}

h3 {
  font-size: 1rem;
  margin: 1rem 0 .5rem;
}

p {
  color: var(--muted);
  line-height: 1.5;
}

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

a:hover {
  color: var(--a);
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1rem 0;
}

.admin-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
  padding-bottom: 2rem;
}

.admin-content {
  display: grid;
  gap: .85rem;
  min-width: 0;
}

.admin-content > * {
  min-width: 0;
}

.admin-section {
  scroll-margin-top: 1rem;
}

.side-nav {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--card-2);
  padding: .75rem;
}

.side-title {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: 0;
  margin: .15rem .25rem .65rem;
}

.side-nav nav {
  display: grid;
  gap: .35rem;
}

.nav-link {
  display: flex;
  align-items: center;
  min-height: 2.45rem;
  border: 1px solid transparent;
  border-radius: .4rem;
  color: var(--muted);
  font-weight: 800;
  padding: 0 .8rem;
}

.nav-link:hover,
.nav-link.active {
  border-color: #ff3d6e66;
  background: #ff3d6e1f;
  color: var(--text);
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .8rem;
  margin: 1rem 0 0;
}

.card,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--card);
  padding: 1rem;
}

.card small {
  display: block;
  color: var(--muted);
  margin-bottom: .35rem;
}

.card strong {
  display: block;
  font-size: 1.2rem;
  overflow-wrap: anywhere;
}

.toolbar,
.inline,
.checkline,
.topbar,
.section-head {
  display: flex;
  gap: .7rem;
  align-items: center;
}

.toolbar,
.inline,
.checkline {
  margin: 1rem 0;
}

.topbar,
.section-head {
  justify-content: space-between;
}

.section-title-row {
  margin-bottom: -.2rem;
}

.inline,
.checkline {
  flex-wrap: wrap;
}

.compact {
  margin-bottom: 0;
}

.stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .7rem;
  margin: 1rem 0;
}

.stack label {
  grid-column: 1/-1;
  display: flex;
  align-items: center;
  gap: .55rem;
  font-weight: 700;
}

.stack button {
  justify-self: start;
}

.checkline label {
  display: flex;
  align-items: center;
  gap: .55rem;
  color: var(--text);
  font-weight: 700;
}

.crawl-form {
  display: grid;
  gap: .85rem;
  margin: 1rem 0;
}

.source-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .7rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.source-options legend {
  grid-column: 1 / -1;
  margin-bottom: .1rem;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 900;
}

.source-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .7rem;
  align-items: start;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: #ffffff08;
  padding: .85rem;
  cursor: pointer;
}

.source-option:has(input:checked) {
  border-color: #ff3d6e99;
  background: #ff3d6e17;
}

.source-option strong,
.source-option small {
  display: block;
}

.source-option small {
  margin-top: .28rem;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 500;
  line-height: 1.4;
}

.llm-form {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 1rem 0;
  padding: .2rem 0;
}

.llm-form .inline {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
}

.llm-form .inline input {
  width: 100%;
  min-width: 0;
}

#llmLimit {
  grid-column: span 2;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: #ffffff12;
  color: var(--text);
  padding: 0 .8rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #ff3d6eaa;
  outline: 2px solid #ff3d6e2e;
}

input,
select {
  min-height: 2.7rem;
}

textarea {
  width: 100%;
  min-height: 7rem;
  padding: .8rem;
  resize: vertical;
  line-height: 1.45;
}

input {
  flex: 1;
  min-width: 0;
}

.inline input {
  min-width: min(22rem, 100%);
}

.small-input {
  max-width: 5.5rem;
  min-width: 4.5rem;
}

input[type=checkbox] {
  flex: 0 0 auto;
  min-height: auto;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
}

input[type=radio] {
  flex: 0 0 auto;
  min-height: auto;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  margin-top: .18rem;
}

button {
  min-height: 2.7rem;
  border: 0;
  border-radius: .5rem;
  background: var(--a);
  color: #fff;
  font-weight: 700;
  padding: 0 1rem;
  cursor: pointer;
  white-space: nowrap;
}

button:disabled {
  opacity: .55;
  cursor: wait;
}

.ghost {
  background: #ffffff14;
}

.danger {
  background: #8f2038;
}

.badge,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 1.8rem;
  border-radius: 999px;
  background: #ffffff14;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
  padding: 0 .7rem;
  white-space: nowrap;
}

.hint {
  font-size: .9rem;
}

pre {
  white-space: pre-wrap;
  max-height: 18rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: #0006;
  padding: .75rem;
}

.import-form {
  margin-top: .75rem;
}

.queue-list {
  display: grid;
  gap: .5rem;
  margin-top: .75rem;
}

.queue-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .7rem;
  align-items: start;
  border-top: 1px solid var(--line);
  padding-top: .65rem;
}

.queue-item strong,
.queue-item small {
  display: block;
  overflow-wrap: anywhere;
}

.queue-item small {
  color: var(--muted);
  margin-top: .18rem;
}

.status.done,
.status.published {
  color: var(--ok);
}

.status.failed {
  color: #ff8c9f;
}

.status.queued,
.status.draft {
  color: var(--warn);
}

.status.archived {
  color: #9da3b7;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: .5rem;
  overflow: hidden;
}

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

th {
  color: var(--muted);
  font-weight: 700;
}

.summary {
  display: block;
  color: var(--muted);
  font-size: .86rem;
  margin-top: .35rem;
  line-height: 1.4;
}

.actions {
  display: flex;
  gap: .55rem;
  align-items: center;
  flex-wrap: wrap;
}

.table-scroll {
  overflow: auto;
}

.table-scroll table {
  min-width: 980px;
}

.row-actions {
  display: flex;
  gap: .45rem;
  align-items: center;
}

.row-actions button {
  min-height: 2.2rem;
  padding: 0 .7rem;
}

.page-toolbar {
  display: grid;
  grid-template-columns: minmax(18rem, 1fr) repeat(3, minmax(10rem, .25fr));
  align-items: stretch;
}

.page-summary {
  display: grid;
  gap: .85rem;
  margin: 1.25rem 0 1.45rem;
}

.summary-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .7rem;
}

.summary-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: #ffffff08;
  padding: .85rem;
}

.summary-card small,
.summary-card span {
  display: block;
  color: var(--muted);
}

.summary-card small {
  margin-bottom: .4rem;
  font-size: .82rem;
  font-weight: 800;
}

.summary-card strong {
  display: block;
  font-size: 1.38rem;
  margin-bottom: .25rem;
  overflow-wrap: anywhere;
}

.summary-card span {
  min-height: 2.6em;
  font-size: .86rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.summary-breakdowns {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .7rem;
}

.page-form {
  display: grid;
  gap: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .75rem;
}

.page-form label {
  display: grid;
  gap: .35rem;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 800;
}

.page-form input,
.page-form select,
.page-form textarea {
  width: 100%;
  color: var(--text);
}

.editor {
  border-color: var(--line-strong);
}

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

.analytics-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 1rem;
  margin-top: .5rem;
}

.mini-list {
  display: grid;
  gap: .7rem;
}

.mini-group {
  border: 1px solid var(--line);
  border-radius: .5rem;
  padding: .75rem;
  background: #ffffff08;
}

.mini-group strong {
  display: block;
  margin-bottom: .55rem;
}

.mini-group span {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  border-top: 1px solid var(--line);
  padding: .45rem 0;
  color: var(--muted);
}

.mini-group span:first-of-type {
  border-top: 0;
}

.mini-group em {
  font-style: normal;
  overflow-wrap: anywhere;
}

.mini-group b {
  color: var(--text);
}

.mini-table {
  font-size: .9rem;
}

.mini-table th,
.mini-table td {
  padding: .55rem;
}

.mini-table td:last-child {
  max-width: 24rem;
  overflow-wrap: anywhere;
}

@media (max-width: 1120px) {
  .admin-layout {
    grid-template-columns: 188px minmax(0, 1fr);
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .stack {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .inline {
    flex-direction: column;
    align-items: stretch;
  }

  .inline input {
    min-width: 0;
  }

  .page-toolbar,
  .summary-kpis,
  .summary-breakdowns,
  .source-options,
  .form-grid,
  .analytics-layout {
    grid-template-columns: 1fr;
  }

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

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

  #llmLimit {
    grid-column: auto;
  }
}

@media (max-width: 820px) {
  header,
  main {
    width: min(100% - 1rem, 1420px);
  }

  header {
    padding-top: 1rem;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .side-nav {
    top: .5rem;
    z-index: 5;
    max-height: none;
  }

  .side-nav nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: .1rem;
  }

  .nav-link {
    flex: 0 0 auto;
  }
}

@media (max-width: 560px) {
  .stats,
  .compact-stats {
    grid-template-columns: 1fr;
  }

  .card,
  .panel {
    padding: .85rem;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .checkline {
    align-items: flex-start;
    flex-direction: column;
  }
}
