:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-muted: #eef2f6;
  --border: #d9e1ea;
  --text: #17212f;
  --muted: #657386;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --blue: #2563eb;
  --green: #15803d;
  --red: #b91c1c;
  --amber: #b45309;
  --shadow: 0 1px 2px rgba(23, 33, 47, 0.06);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 0 14px;
  white-space: nowrap;
}

button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

button[aria-pressed="false"] {
  background: var(--surface);
  color: var(--accent);
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  outline-offset: 1px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  padding: 16px 24px;
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

main {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 20px 24px 32px;
}

.controls {
  display: grid;
  grid-template-columns: minmax(240px, 1.8fr) repeat(5, minmax(120px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.controls label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.controls button {
  width: 72px;
}

.error-banner {
  border: 1px solid rgba(185, 28, 28, 0.28);
  border-radius: 6px;
  background: #fff1f2;
  color: var(--red);
  margin-bottom: 16px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
}

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

.metric-tile {
  min-height: 82px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric-tile span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-tile strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
}

.metric-tile.is-running strong {
  color: var(--blue);
}

.metric-tile.is-completed strong {
  color: var(--green);
}

.metric-tile.is-failed strong,
.metric-tile.is-stuck strong {
  color: var(--red);
}

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

.bottom-grid {
  grid-template-columns: minmax(300px, 0.7fr) minmax(0, 1.3fr);
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
}

.panel-header h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

.panel-header span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--surface-muted);
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
}

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

td {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr.is-selected {
  background: #ecfdf5;
}

.runs-panel th:nth-child(1),
.runs-panel td:nth-child(1) {
  width: 72px;
}

.runs-panel th:nth-child(4),
.runs-panel td:nth-child(4) {
  width: 104px;
}

.runs-panel th:nth-child(5),
.runs-panel td:nth-child(5) {
  width: 112px;
}

.runs-panel th:nth-child(6),
.runs-panel td:nth-child(6),
.runs-panel th:nth-child(7),
.runs-panel td:nth-child(7) {
  width: 154px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-width: 78px;
  height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.status-pending {
  background: #f1f5f9;
  color: #475569;
}

.status-running,
.status-claimed {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-completed {
  background: #dcfce7;
  color: #166534;
}

.status-failed,
.status-dead {
  background: #fee2e2;
  color: #991b1b;
}

.detail-panel {
  min-height: 420px;
}

.detail-empty,
.empty-row {
  color: var(--muted);
  padding: 16px;
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding: 14px;
}

.detail-field {
  min-width: 0;
}

.detail-field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.detail-field strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-list {
  max-height: 520px;
  overflow: auto;
}

.task-item {
  border-bottom: 1px solid var(--surface-muted);
  padding: 12px 14px;
}

.task-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}

.task-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.task-meta,
.task-error {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.task-error {
  margin-top: 6px;
  color: var(--red);
}

.queue-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.queue-item {
  min-height: 76px;
  border: 1px solid var(--surface-muted);
  border-radius: 6px;
  padding: 12px;
}

.queue-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.queue-item strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1;
}

@media (max-width: 1180px) {
  .controls,
  .content-grid,
  .bottom-grid {
    grid-template-columns: 1fr;
  }

  .controls button {
    width: 100%;
  }

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

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 16px;
  }

  .topbar-actions,
  .topbar-actions button {
    width: 100%;
  }

  main {
    padding: 16px;
  }

  .metrics,
  .queue-grid,
  .detail-summary {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 760px;
  }
}
