:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #20242c;
  --muted: #667085;
  --line: #d8dde6;
  --good: #16794c;
  --warn: #a05a00;
  --bad: #b42318;
  --run: #175cd3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 15px;
  font-weight: 700;
}

.topbar p,
.hint,
.panel-head span {
  color: var(--muted);
}

.layout {
  display: grid;
  align-items: start;
  grid-template-columns: minmax(280px, 360px) minmax(420px, 1fr);
  gap: 16px;
  padding: 16px;
}

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

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

.controls,
.runs {
  grid-column: 1;
}

.controls {
  grid-row: 1 / span 2;
}

.runs {
  grid-row: 3;
}

.current,
.detail {
  grid-column: 2;
}

.current {
  grid-row: 1;
}

.detail {
  grid-row: 2;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge.success,
.status-pill.success {
  border-color: #abefc6;
  background: #ecfdf3;
  color: var(--good);
}

.badge.running,
.status-pill.running,
.badge.queued {
  border-color: #b2ccff;
  background: #eff4ff;
  color: var(--run);
}

.badge.error,
.status-pill.error {
  border-color: #fecdca;
  background: #fef3f2;
  color: var(--bad);
}

.badge.duplicate {
  border-color: #fedf89;
  background: #fffaeb;
  color: var(--warn);
}

.badge.stopped,
.status-pill.stopped {
  border-color: #d0d5dd;
  background: #f2f4f7;
  color: #475467;
}

.toggle-row,
.field,
.sources label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field {
  align-items: stretch;
  flex-direction: column;
  margin-top: 14px;
}

input[type="number"],
input[type="password"],
input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  font: inherit;
}

input[type="number"],
input[type="password"],
input[type="text"] {
  min-height: 38px;
}

textarea {
  min-height: 72px;
  resize: vertical;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.actions {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 8px 12px;
}

button.primary {
  background: #20242c;
  color: #fff;
  border-color: #20242c;
}

button.danger {
  border-color: #fecdca;
  background: #fff;
  color: var(--bad);
}

button.ghost {
  min-height: 30px;
  padding: 5px 9px;
  color: var(--muted);
}

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

.sources {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.platform-settings {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.platform-card {
  margin: 0;
  border: 1px solid #eef1f5;
  border-radius: 8px;
  padding: 10px;
}

.platform-card legend {
  padding: 0 5px;
  font-weight: 700;
}

.platform-card .field {
  margin-top: 8px;
}

.toggle-row.compact {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.cookie-state {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 600;
}

.cookie-state.configured {
  color: var(--good);
}

.empty {
  color: var(--muted);
  min-height: 48px;
  display: flex;
  align-items: center;
}

.current {
  align-self: start;
}

.current .source-statuses {
  margin-bottom: 8px;
}

.current .source-row {
  padding: 6px 0;
}

.source-statuses {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.source-row {
  display: grid;
  grid-template-columns: minmax(80px, 140px) 110px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid #eef1f5;
}

.source-row:last-child {
  border-bottom: 0;
}

.source-row .file,
.source-row .error {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-row .error {
  color: var(--bad);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid #eef1f5;
  padding: 9px 7px;
  text-align: left;
  white-space: nowrap;
}

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

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f8fafc;
}

.logs {
  width: 100%;
  min-height: 340px;
  max-height: 520px;
  overflow: auto;
  margin: 0;
  border-radius: 6px;
  background: #111827;
  color: #d1d5db;
  padding: 12px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
}

.login-page {
  min-height: 100vh;
}

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

.login-panel {
  display: grid;
  width: min(100%, 360px);
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.login-panel p {
  margin-top: 4px;
  color: var(--muted);
}

.login-error {
  padding: 8px 10px;
  border: 1px solid #fecdca;
  border-radius: 6px;
  background: #fef3f2;
  color: var(--bad) !important;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .controls,
  .runs,
  .current,
  .detail {
    grid-column: 1;
  }

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