/* === Base === */
* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin: 0;
  padding: 24px;
  background: #f5f5f7;
  color: #1d1d1f;
}
a { color: #0a58ca; }
code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}
canvas { display: block; background: #fafafa; border-radius: 6px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.err { color: #b00020; padding: 12px; background: #fff; border-radius: 6px; }

/* === Layout === */
/* Fixed 1000px page. On narrow viewports the page scrolls horizontally -
   responsivity is intentionally out of scope. */
.page { width: 1000px; margin: 0 auto; }

.page-header { margin-bottom: 20px; }
.page-header h1 {
  font-size: 28px;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.page-header .hint { margin: 0; }

.hint { color: #6e6e73; font-size: 13px; }

/* === Nav === */
.nav {
  display: flex;
  gap: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid #d2d2d7;
  margin-bottom: 20px;
}
.nav a {
  text-decoration: none;
  color: #424245;
  font-size: 14px;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.nav a:hover { color: #1d1d1f; }
.nav a.active {
  color: #0a58ca;
  border-bottom-color: #0a58ca;
  font-weight: 500;
}

/* === Cards & sections === */
.card {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.card.section { padding: 20px 24px; margin-bottom: 16px; }

.section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6e6e73;
  margin-bottom: 14px;
}
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.section-title-row .section-title { margin-bottom: 0; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #e7f0ff;
  color: #0a58ca;
  margin-left: 6px;
  min-width: 1px;
}
/* Fixed-width meta pill so the title row never reflows as values change. */
.meta-badge {
  font-variant-numeric: tabular-nums;
  display: inline-block;
  min-width: 280px;
  text-align: center;
}

/* === Buttons === */
button {
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid #d2d2d7;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
button:hover:not(:disabled) { background: #f0f0f0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: #0a58ca;
  color: #fff;
  border: 1px solid #0a58ca;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 24px;
}
.btn-primary:hover:not(:disabled) { background: #084aa9; border-color: #084aa9; }
.btn-primary:disabled {
  background: #0a58ca;
  border-color: #0a58ca;
  color: #fff;
  opacity: 0.45;
}

/* === Forms === */
.form-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}
.form-grid.form-grid-4 { grid-template-columns: repeat(4, 1fr); }
.form-grid.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-placeholder { visibility: hidden; }
.field label {
  font-size: 12px;
  color: #6e6e73;
  font-weight: 500;
}
.field input,
.field select {
  height: 34px;
  padding: 0 10px;
  font-size: 14px;
  border: 1px solid #d2d2d7;
  border-radius: 6px;
  background: #fff;
  color: #1d1d1f;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
}
.field select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path fill='none' stroke='%236e6e73' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M3 5l3 3 3-3'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px 12px;
  padding-right: 28px;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: #0a58ca;
  box-shadow: 0 0 0 3px rgba(10, 88, 202, 0.18);
}
.field input:disabled,
.field select:disabled {
  background: #f5f5f7;
  color: #8e8e93;
  cursor: not-allowed;
}

.form-actions {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Fixed-width status pill so nothing else moves when text changes. */
.status-text {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  width: 480px;
  font-size: 13px;
  color: #424245;
  background: #f5f5f7;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Tables === */
table {
  border-collapse: collapse;
  font-size: 13px;
  width: 100%;
  table-layout: fixed;
}
th, td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid #eee;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
th { cursor: pointer; user-select: none; background: #fafafa; position: sticky; top: 0; }
th:hover { background: #f0f0f0; }
tr:hover { background: #f7f7fa; }
tr.selected { background: #e7f0ff; }
.scroll { max-height: 460px; overflow-y: auto; }

/* === Live Run: playback === */
.playback-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.slider-row {
  display: grid;
  grid-template-columns: 140px 1fr 110px;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}
.slider-row label { font-size: 13px; color: #424245; }
.slider-row input[type=range] { width: 100%; margin: 0; }
.slider-value {
  font-size: 12px;
  color: #424245;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* === Live Run: best-route text === */
.best-summary {
  font-size: 13px;
  color: #1d1d1f;
  margin-bottom: 8px;
}
.best-route {
  font-size: 12px;
  color: #424245;
  line-height: 1.5;
  word-break: break-word;
}

/* === Live Run: visualizations === */
.viz-card { padding: 20px 24px; margin-bottom: 16px; }
.viz-grid {
  display: grid;
  grid-template-columns: 480px 440px;
  gap: 24px;
  justify-content: center;
}
.viz-panel { display: flex; flex-direction: column; }

/* === Sweep: heatmap === */
.run-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}
.grid-block { display: flex; flex-direction: column; gap: 6px; }
.grid-block-title {
  font-size: 12px;
  color: #424245;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.grid-cells { display: grid; gap: 3px; }
.grid-cell {
  aspect-ratio: 1 / 1;
  border-radius: 3px;
  background: #e5e5ea;
  cursor: pointer;
  transition: background 120ms linear, box-shadow 120ms linear, opacity 120ms linear;
}
.grid-cell:hover { outline: 1px solid #1d1d1f; }
.grid-axis-x {
  font-size: 10px;
  color: #6e6e73;
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* === Sweep: legend & counters === */
.legend { display: flex; gap: 16px; font-size: 12px; color: #6e6e73; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.06);
}
.swatch-pending { background: #e5e5ea; }
.swatch-running { background: #0a58ca; }
.swatch-done    { background: #34c759; }

/* Fixed-height tooltip slot so hover text doesn't reflow the page. */
.run-tooltip {
  height: 18px;
  line-height: 18px;
  margin-top: 12px;
  font-size: 13px;
  color: #424245;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.run-counters {
  margin-top: 14px;
  font-size: 12px;
  color: #424245;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* === Sweep: best-route + worker activity === */
.sweep-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
  align-items: stretch;
}
.sweep-row > .sweep-panel {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  min-height: 527px;
}
.sweep-row canvas { margin: 0 auto; }

.run-best-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #424245;
  font-variant-numeric: tabular-nums;
  margin: 8px auto 0;
  width: 420px;
}
.run-best-label > div {
  height: 16px;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.worker-list {
  display: grid;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
}
.worker-empty { font-size: 13px; color: #6e6e73; }
.worker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 8px;
  background: #fafafa;
  border-radius: 4px;
  border: 1px solid #ececef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.worker-id { color: #6e6e73; }
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex-shrink: 0;
}
.dot-pending { background: #e5e5ea; }
.dot-running { background: #0a58ca; box-shadow: 0 0 6px rgba(10,88,202,0.55); animation: pulse 1.2s ease-in-out infinite; }
.dot-idle    { background: #34c759; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* === Sweep: results table === */
#runTable .col-label { width: 58%; }
#runTable .col-num   { width: 8.4%; }
#runTable th:first-child,
#runTable td:first-child {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
#runTable .sort-arrow { display: inline-block; width: 10px; }

/* === Overview: prose document === */
.doc { line-height: 1.6; color: #1d1d1f; }
.doc h2 {
  font-size: 22px;
  margin: 32px 0 12px;
  border-bottom: 1px solid #d2d2d7;
  padding-bottom: 4px;
}
.doc h3 { font-size: 17px; margin: 24px 0 8px; }
.doc p  { margin: 12px 0; }
.doc ul, .doc ol { margin: 12px 0; padding-left: 24px; }
.doc li { margin: 4px 0; }
.doc pre {
  background: #1d1d1f;
  color: #f5f5f7;
  padding: 12px 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
  margin: 12px 0;
}
.doc pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}
