:root {
  color-scheme: dark;
  --bg: #0f1216;
  --sidebar: #12161b;
  --panel: #171b21;
  --panel-strong: #1c2129;
  --field: #0f1216;
  --ink: #e6e9ee;
  --ink-soft: #aeb7c4;
  --muted: #8a94a3;
  --line: #262c35;
  --accent: #3ecf9e;
  --accent-ink: #0f1216;
  --accent-soft: rgba(62, 207, 158, 0.14);
  --warn: #e0a64a;
  --warn-soft: rgba(224, 166, 74, 0.14);
  --danger: #f0866f;
  --danger-soft: rgba(240, 134, 111, 0.14);
  --ok: #3ecf9e;
  --ok-soft: rgba(62, 207, 158, 0.14);
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 1.6rem;
  font-weight: 600;
}

code {
  font-family: var(--mono);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

/* ---- shell ---- */

.app {
  display: flex;
  flex-wrap: wrap;
  min-height: 100vh;
}

.sidebar {
  flex: 1 1 220px;
  max-width: 260px;
  min-width: 200px;
  padding: 24px 16px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand {
  padding: 0 12px 20px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--ink-soft);
}

.nav a:hover {
  color: #fff;
}

.nav a.active {
  background: #1f262f;
  color: #fff;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 24px;
  display: grid;
  gap: 10px;
  justify-items: start;
}

.content {
  flex: 999 1 560px;
  min-width: 0;
  padding: 32px;
}

.view[hidden] {
  display: none;
}

.view {
  display: grid;
  gap: 24px;
  align-content: start;
}

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.view-head .subtext {
  margin: 4px 0 0;
}

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

.block-head h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

.text-link {
  color: var(--accent);
  font-size: 0.9rem;
}

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

/* ---- forms ---- */

.control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.control-field {
  display: grid;
  gap: 6px;
}

.control-field.grow {
  flex: 1 1 280px;
}

.control-field label {
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

input,
select {
  min-height: 44px;
  min-width: 110px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
  color: var(--ink);
  background: var(--field);
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button,
a.secondary,
a.compact {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 18px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  cursor: pointer;
}

button:hover,
a.secondary:hover,
a.compact:hover {
  filter: brightness(1.1);
}

:is(button, a).secondary {
  color: var(--ink);
  background: transparent;
  border-color: var(--line);
  font-weight: 500;
}

:is(button, a).secondary:hover {
  background: #1f262f;
  filter: none;
}

:is(button, a).danger {
  color: var(--danger);
  background: transparent;
  border-color: rgba(240, 134, 111, 0.4);
}

:is(button, a).danger:hover {
  background: var(--danger-soft);
  filter: none;
}

:is(button, a).compact {
  padding: 0 14px;
  font-size: 0.86rem;
}

button[hidden] {
  display: none;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.form-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 14px;
}

.form-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

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

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.checkbox-field input {
  min-width: 0;
  min-height: 0;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.condition-rows {
  margin-bottom: 8px;
}

.condition-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr 1fr auto;
  align-items: end;
  margin-bottom: 8px;
}

/* ---- panels ---- */

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

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

.panel-body {
  padding: 18px 20px 20px;
}

.subtext {
  color: var(--muted);
  font-size: 0.92rem;
}

.layout {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

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

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

.stat-label {
  margin: 0 0 6px;
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.stat-value {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.9rem;
  font-weight: 500;
}

.stack {
  display: grid;
  gap: 12px;
}

.client-card,
.queue-card,
.filter-card,
.source-card,
.snapshot-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  background: var(--panel-strong);
  min-width: 0;
}

.client-card h3,
.queue-card h3,
.filter-card h3,
.source-card h3,
.snapshot-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}

.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.empty {
  padding: 24px 16px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  text-align: center;
  color: var(--muted);
}

.title {
  font-weight: 600;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.detail {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

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

th {
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

td code {
  word-break: break-all;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  background: var(--muted);
}

.status-submitted .status-dot,
.status-succeeded .status-dot,
.status-selected .status-dot {
  background: var(--ok);
}

.status-dry-run .status-dot,
.status-dry_run .status-dot,
.status-preferred .status-dot,
.status-running .status-dot,
.status-queued .status-dot {
  background: var(--accent);
}

.status-skipped .status-dot,
.status-ignored .status-dot {
  background: var(--warn);
}

.status-failed .status-dot,
.status-discarded .status-dot {
  background: var(--danger);
}

.error-banner {
  display: none;
  margin-bottom: 18px;
  padding: 14px 18px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(240, 134, 111, 0.35);
}

.error-banner.visible {
  display: block;
}

.auth-gate {
  max-width: 560px;
  margin: 8vh auto 0;
}

.auth-gate[hidden] {
  display: none;
}

.auth-gate .panel-body {
  display: grid;
  gap: 14px;
}

.auth-copy {
  color: var(--muted);
  line-height: 1.5;
}

/* ---- home ---- */

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 0.88rem;
}

.status-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status-chip.ok::before {
  background: var(--ok);
}

.status-chip.warn::before {
  background: var(--warn);
}

.status-chip.danger::before {
  background: var(--danger);
}

.attention {
  border-color: rgba(240, 134, 111, 0.4);
  background: #1b1614;
}

.attention[hidden] {
  display: none;
}

.show-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.show-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.show-card .show-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

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

.progress-track {
  position: relative;
  flex: 1 1 40px;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

/* Widths are set from script (CSSOM); inline style attributes are blocked by the CSP. */
.progress-aired,
.progress-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
}

.progress-aired {
  background: rgba(62, 207, 158, 0.28);
}

.progress-fill {
  background: var(--accent);
}

.progress-label {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.show-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--muted);
}

.show-status::before {
  content: "";
  flex: 0 0 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.show-status.ok {
  color: var(--ok);
}

.show-status.ok::before {
  background: var(--ok);
}

.show-status.warn {
  color: var(--warn);
}

.show-status.warn::before {
  background: var(--warn);
}

.show-status.danger {
  color: var(--danger);
}

.show-status.danger::before {
  background: var(--danger);
}

.list-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 14px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.list-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.list-row .grow {
  flex: 1 1 260px;
  min-width: 0;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.86rem;
}

.status-strip strong {
  font-family: var(--mono);
  font-weight: 400;
  color: var(--ink-soft);
}

/* ---- narrow screens ---- */

@media (max-width: 980px) {
  .sidebar {
    flex: 1 1 100%;
    max-width: none;
    padding: 16px;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-foot {
    margin-top: 0;
    padding-top: 12px;
    grid-auto-flow: column;
    justify-content: start;
    align-items: center;
    gap: 10px;
  }

  .content {
    padding: 20px 16px;
  }

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

  .condition-row {
    grid-template-columns: 1fr;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }

  td {
    border-bottom: 0;
    padding: 6px 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    font-size: 0.74rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
  }
}

.mt-12 {
  margin-top: 12px;
}

.mt-16 {
  margin-top: 16px;
}

/* ---- library tabs and sortable table ---- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 14px 0;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  color: var(--ink-soft);
  background: transparent;
  font-weight: 500;
}

.tab:hover {
  color: #fff;
  background: #1f262f;
  filter: none;
}

.tab[aria-selected="true"] {
  color: #fff;
  border-bottom-color: var(--accent);
}

.tab .count {
  margin-left: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.library-table td {
  padding: 8px 10px;
  vertical-align: middle;
}

.library-table .col-progress {
  min-width: 190px;
}

.sort-button {
  min-height: 32px;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  box-shadow: none;
}

.sort-button:hover {
  color: #fff;
  filter: none;
}

.sort-button[data-dir="asc"]::after {
  content: " \25B2";
  font-size: 0.7em;
}

.sort-button[data-dir="desc"]::after {
  content: " \25BC";
  font-size: 0.7em;
}

.library-table .col-score {
  text-align: center;
  font-family: var(--mono);
}
