:root {
  --bg: #0f1115;
  --card: #171a21;
  --border: #2a2e38;
  --text: #e6e8ec;
  --muted: #9098a8;
  --accent: #4caf50;
  --accent-dark: #3d8b40;
  --error: #f44336;
  --warn: #f5a623;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.logo {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  flex-shrink: 0;
}

.columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.col {
  display: flex;
  flex-direction: column;
}

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

h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge-idle { background: #2a2e38; color: var(--muted); }
.badge-running { background: #1f3a24; color: var(--accent); }
.badge-done { background: #1f3a24; color: var(--accent); }
/* Stopped-on-purpose is neither success nor failure — amber keeps it distinct
   from the green "Finished" and the red "Problem". */
.badge-cancelled { background: #3a331f; color: #e0b950; }
.badge-error { background: #3a1f1f; color: var(--error); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.config-info {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.7;
}
.config-info b { color: var(--text); }
.config-warn { color: var(--warn); }

.sheet-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

input[type="text"], select {
  background: #0a0c10;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.9rem;
  font-family: inherit;
}

#sheet-url-input { flex: 1; min-width: 0; }

#tab-select {
  flex: 1;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239098a8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
#tab-select:disabled { opacity: 0.6; }

button#load-tabs-btn {
  background: #2a2e38;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.85rem;
  cursor: pointer;
}
button#load-tabs-btn:hover { background: #343947; }
button#load-tabs-btn:disabled { color: var(--muted); cursor: not-allowed; }

#column-mapping.hidden { display: none; }
#column-mapping { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

.mapping-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.mapping-field label { font-size: 0.8rem; color: var(--muted); }
.mapping-field .req { color: var(--error); }
.mapping-field-wide { grid-column: 1 / -1; }

.mapping-section { margin-top: 16px; }
.mapping-section h3 { font-size: 0.85rem; margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

.mapping-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 480px) { .mapping-grid { grid-template-columns: 1fr; } }

.mapping-grid-shared { padding-bottom: 4px; }

.mapping-note { font-size: 0.8rem; color: var(--muted); margin: 8px 0 0; font-style: italic; }

.mapping-select, .mapping-field input[type="text"] {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 34px;
}
.mapping-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239098a8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.mapping-field input[type="text"] { padding-right: 10px; }

.stage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.stage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  cursor: pointer;
}
.stage-item input { width: 16px; height: 16px; }

.run-btn-row {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

button#run-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
button#run-btn:hover { background: var(--accent-dark); }
button#run-btn:disabled { background: #2a2e38; color: var(--muted); cursor: not-allowed; }

/* Run-in-progress indicator. The button alone going grey read as "the click
   didn't register", so a moving element sits beside it for the whole job. */
.spinner {
  display: inline-block;
  vertical-align: middle;
  margin-left: 12px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner[hidden] { display: none; }

.run-running-text {
  margin-left: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  vertical-align: middle;
}
.run-running-text[hidden] { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Respect a reduced-motion preference: pulse instead of spin. */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: pulse 1.2s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: 0.25; } }
}

.error-text { color: var(--error); margin-left: 12px; font-size: 0.85rem; }

.current-stage {
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 6px;
}

.progress-counts {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Plain-English activity feed. Deliberately not monospace and not a log box —
   raw log records never reach this page (see CLAUDE.md). */
.activity-feed {
  background: #0a0c10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  height: 260px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.75;
  color: #c8d0da;
  white-space: pre-wrap;
  word-break: break-word;
}

.progress-finished {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: pre-wrap;
  line-height: 1.6;
}

.summaries {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.85rem;
}
.summary-card .row,
.resource-body .row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  padding: 2px 0;
}
.summary-card .row span:last-child,
.resource-body .row span:last-child {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.summary-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.summary-card .stage-name { color: var(--text); font-weight: 600; }
.summary-card .stage-time { color: var(--muted); font-size: 0.8rem; }
.summary-total {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
}
.modal h3 { margin: 0 0 16px; font-size: 1.1rem; }

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}
.modal-row {
  display: flex;
  gap: 10px;
  font-size: 0.9rem;
}
.modal-row-top { align-items: flex-start; }
.modal-label {
  color: var(--muted);
  min-width: 60px;
  flex-shrink: 0;
}
.modal-stage-list {
  margin: 0;
  padding-left: 18px;
}
.modal-stage-list li { margin-bottom: 2px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-secondary {
  background: #2a2e38;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-secondary:hover { background: #343947; }

/* --- This Computer card ------------------------------------------------- */
/* The memory bar is the ONE bar in this app: an explicit exception granted
   for this card only. The Progress panel's "text only, no progress bar, no
   animation" rule is unchanged — don't add bars there.
   Note there is deliberately no CSS transition on the fill: this is a
   measurement, and a smoothly growing bar reads as progress. */
.resource-bar {
  height: 6px;
  background: #0a0c10;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 6px 0 10px;
}
.resource-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
}

/* Only memory changes colour. CPU pegged at 100% is normal during a run and a
   high Chrome count is expected in Stage 3 — colouring those would train the
   operator to ignore colour entirely. */
.resource-level-warn .resource-bar-fill { background: var(--warn); }
.resource-level-critical .resource-bar-fill { background: var(--error); }
.resource-level-warn #res-memory { color: var(--warn); }
.resource-level-critical #res-memory { color: var(--error); }

.resource-stale .resource-body { opacity: 0.45; }

.resource-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.5;
}
.resource-level-critical .resource-note { color: var(--error); }
.resource-note[hidden] { display: none; }
#resources-card.hidden { display: none; }
