:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f9fbfb;
  --text: #172026;
  --muted: #66747d;
  --border: #d9e1e5;
  --border-strong: #c4ced4;
  --accent: #0f766e;
  --accent-soft: #dff5f1;
  --blue: #2563eb;
  --green: #168a4a;
  --amber: #a16207;
  --red: #b42318;
  --gray: #697780;
  --shadow: 0 16px 40px rgba(23, 32, 38, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  min-height: 36px;
  padding: 0 14px;
}

button:hover {
  background: #0b625c;
}

button.ghost,
button.row-action {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--text);
}

button.row-action {
  min-height: 30px;
  padding: 0 8px;
}

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

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #101820;
  color: #e8eef2;
  padding: 22px 18px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  align-items: center;
  background: #dff5f1;
  border-radius: 6px;
  color: #0f4f49;
  display: flex;
  font-size: 13px;
  font-weight: 800;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 14px;
}

.brand span {
  color: #9eb0bc;
  font-size: 12px;
  margin-top: 2px;
}

nav {
  display: grid;
  gap: 4px;
}

nav a {
  border-radius: 6px;
  color: #b9c7d0;
  font-size: 13px;
  padding: 10px 12px;
  text-decoration: none;
}

nav a.active,
nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  align-items: flex-start;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  letter-spacing: 0;
  line-height: 1.25;
}

h2 {
  font-size: 15px;
  letter-spacing: 0;
  line-height: 1.3;
}

p,
.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.topbar p {
  margin-top: 5px;
}

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

.env-chip,
.status-chip {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  min-height: 24px;
  padding: 0 9px;
  white-space: nowrap;
}

.env-chip {
  background: var(--accent-soft);
  color: #0f4f49;
}

.auth-panel,
.panel,
.summary-grid article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 14px;
}

.token-form {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(220px, 320px) auto auto;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.summary-grid article {
  padding: 14px;
}

.summary-grid span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.summary-grid strong {
  display: block;
  font-size: 22px;
  line-height: 1.2;
}

.content-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) 360px;
  margin-bottom: 16px;
}

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

.panel {
  min-width: 0;
  padding: 16px;
}

.panel-heading {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 680px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  padding: 9px 8px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-soft);
  color: #4b5b64;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.status-healthy {
  background: #e7f7ed;
  color: var(--green);
}

.control-cell {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.status-backfilling,
.status-running {
  background: #fff3d6;
  color: var(--amber);
}

.status-failed {
  background: #fde8e5;
  color: var(--red);
}

.status-stale,
.status-unknown,
.status-skipped,
.status-paused {
  background: #eef2f4;
  color: var(--gray);
}

.request-form,
.list {
  display: grid;
  gap: 12px;
}

.request-form label,
fieldset {
  color: #3c4a52;
  display: grid;
  font-size: 12px;
  font-weight: 750;
  gap: 7px;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

legend {
  margin-bottom: 7px;
}

.segments {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px;
}

.segments label {
  align-items: center;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  font-size: 12px;
  gap: 6px;
  justify-content: center;
  padding: 7px 4px;
}

.segments label:has(input:checked) {
  background: #fff;
  box-shadow: 0 1px 3px rgba(23, 32, 38, 0.12);
  color: var(--accent);
}

.segments input {
  height: 13px;
  width: 13px;
}

.toggle {
  align-items: center;
  display: flex !important;
  gap: 8px !important;
}

.toggle input {
  width: auto;
}

.list-item {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px;
}

.list-title {
  display: block;
  font-size: 13px;
  font-weight: 800;
}

.list-meta {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

.list-error {
  color: var(--red);
  display: block;
  font-size: 12px;
  margin-top: 2px;
  word-break: break-word;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 14px;
}

.hidden {
  display: none !important;
}

.toast {
  background: #101820;
  border-radius: 6px;
  bottom: 18px;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  padding: 10px 12px;
  pointer-events: none;
  position: fixed;
  right: 18px;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    align-items: center;
    display: flex;
    justify-content: space-between;
  }

  nav {
    display: flex;
    flex-wrap: wrap;
  }

  .content-grid,
  .lower-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  main {
    padding: 16px;
  }

  .topbar,
  .auth-panel {
    align-items: stretch;
    flex-direction: column;
  }

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

.screen.hidden { display: none; }
.source-group { margin-bottom: 18px; }
.source-group > h3 {
  color: var(--muted); font-size: 11px; font-weight: 800;
  letter-spacing: 0.04em; margin: 0 0 8px; text-transform: uppercase;
}
.split-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { font-size: 22px; font-weight: 800; line-height: 1.1; }
.kpi.broken { color: var(--red); }
.kpi.attention { color: var(--amber); }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 40px; }
.spark > i { background: var(--accent); border-radius: 1px; display: block; flex: 1 1 auto; min-width: 2px; }
.spark > i.failed { background: var(--red); }
.linkish { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 0; text-decoration: underline; }
.modal {
  background: rgba(16, 24, 32, 0.5); inset: 0; position: fixed;
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 10;
}
.modal.hidden { display: none; }
.modal .card {
  background: var(--surface); border-radius: 8px; box-shadow: var(--shadow);
  max-height: 80vh; max-width: 720px; overflow: auto; padding: 20px; width: 100%;
}
.modal pre {
  background: var(--surface-soft); border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; overflow-x: auto; padding: 10px; white-space: pre-wrap; word-break: break-word;
}
.deferred {
  background: #fff8e6; border: 1px dashed var(--border-strong); border-radius: 8px;
  color: var(--amber); font-size: 13px; padding: 16px;
}
.filter-row { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filter-row select, .filter-row input { width: auto; min-width: 160px; }
.control-cell { align-items: center; display: flex; gap: 8px; }
.row-action {
  background: var(--surface-soft); border: 1px solid var(--border-strong); border-radius: 6px;
  color: var(--text); cursor: pointer; font-size: 12px; padding: 5px 10px;
}
.row-action[disabled] { cursor: not-allowed; opacity: 0.5; }
.login-screen {
  align-items: center; display: flex; inset: 0; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); display: grid; gap: 14px; max-width: 380px; padding: 28px; width: 100%;
}
.login-card h1 { font-size: 20px; }
.login-card .brand { margin-bottom: 4px; }
.login-divider {
  align-items: center; color: var(--muted); display: flex; font-size: 12px; gap: 10px; margin: 4px 0;
}
.login-divider::before, .login-divider::after {
  background: var(--border); content: ""; flex: 1 1 auto; height: 1px;
}
.login-form { display: grid; gap: 12px; }
.login-form label { color: #3c4a52; display: grid; font-size: 12px; font-weight: 750; gap: 6px; }
.login-error { color: var(--red); font-size: 13px; margin: 0; min-height: 18px; }