:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #697585;
  --line: #d7dde5;
  --panel: #ffffff;
  --bg: #f4f6f8;
  --green: #15803d;
  --green-soft: #e8f5ee;
  --red: #b42318;
  --red-soft: #fdecea;
  --blue: #2563eb;
  --blue-soft: #e8efff;
  --amber: #b7791f;
  --amber-soft: #fff7e6;
  --shadow: 0 12px 28px rgba(23, 33, 43, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  background: #18202a;
  color: #f8fafc;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #f4c95d;
  color: #17212b;
  font-weight: 800;
}

.brand-mark.large {
  width: 54px;
  height: 54px;
  margin: 0 auto 10px;
  font-size: 18px;
}

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

.brand-block h1 {
  font-size: 17px;
}

.brand-block p {
  color: #bcc6d2;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #dbe4ef;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: #273241;
  border-color: #36465a;
  color: #ffffff;
}

.status-box {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #dbe4ef;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--red);
}

.status-dot.ok {
  background: var(--green);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

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

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.topbar h2 {
  margin-top: 2px;
  font-size: 26px;
}

.tab {
  display: none;
}

.tab.active {
  display: grid;
  gap: 16px;
}

.panel,
.table-wrap,
.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.query-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) minmax(180px, 1fr) 150px 150px 130px 110px;
  align-items: end;
  gap: 12px;
}

.batch-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 160px 150px 140px;
  align-items: end;
  gap: 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
}

.settings-toggle {
  align-self: end;
}

.settings-primary {
  max-width: 320px;
}

.templates {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cfd6df;
  border-radius: 8px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--ink);
}

input[type="checkbox"] {
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--blue-soft);
  border-color: var(--blue);
}

.primary,
.ghost,
.download,
.seg {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  text-decoration: none;
}

.primary {
  border: 1px solid #1f4fd1;
  background: var(--blue);
  color: #ffffff;
  font-weight: 700;
}

.primary:disabled {
  opacity: 0.55;
  cursor: progress;
}

.ghost {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.download {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.result-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
}

.summary-card {
  min-height: 220px;
  padding: 18px;
}

.summary-card .state {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-weight: 700;
}

.state.candidate {
  color: var(--green);
  background: var(--green-soft);
}

.state.eliminated {
  color: var(--red);
  background: var(--red-soft);
}

.metric {
  margin-top: 18px;
}

.metric strong {
  display: block;
  font-size: 34px;
  line-height: 1.1;
}

.metric span,
.muted {
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid #edf0f3;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f9fafb;
  color: #536273;
  font-size: 12px;
  z-index: 1;
}

td.number {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.section-head,
.pool-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.jobs-list {
  display: grid;
  gap: 10px;
}

.api-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.api-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 120px 120px minmax(160px, 0.8fr) 200px;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid #edf0f3;
  border-radius: 8px;
}

.api-row strong {
  display: block;
}

.api-meta {
  color: var(--muted);
  font-size: 12px;
}

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

.danger {
  min-height: 32px;
  border: 1px solid #f4c7c1;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  padding: 0 10px;
}

.mini {
  min-height: 32px;
  border-radius: 8px;
  padding: 0 10px;
}

.api-form {
  display: grid;
  gap: 14px;
}

.api-form[hidden] {
  display: none !important;
}

.api-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(170px, 1fr));
  gap: 12px;
}

.api-form-grid .wide {
  grid-column: 1 / -1;
}

.job-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 180px 160px 90px;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid #edf0f3;
  border-radius: 8px;
}

.progress {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #e6eaf0;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--blue);
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
}

.tag.completed {
  background: var(--green-soft);
  color: var(--green);
}

.tag.failed,
.tag.error {
  background: var(--red-soft);
  color: var(--red);
}

.pool-toolbar {
  flex-wrap: wrap;
}

.pool-toolbar label {
  min-width: 280px;
  max-width: 520px;
  flex: 1;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.seg {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.seg.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(23, 33, 43, 0.12);
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-card h1 {
  text-align: center;
  font-size: 24px;
}

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

.error {
  min-height: 20px;
  color: var(--red);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #17212b;
  color: #ffffff;
  box-shadow: var(--shadow);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .nav {
    grid-template-columns: repeat(5, 1fr);
  }

  .nav-item {
    text-align: center;
  }

  .query-grid,
  .batch-grid,
  .settings-grid,
  .api-form-grid,
  .result-layout {
    grid-template-columns: 1fr;
  }

  .job-row,
  .api-row {
    grid-template-columns: 1fr;
  }

  .api-form-grid .wide {
    grid-column: auto;
  }
}
