:root {
  --green: #1D9E75;
  --green-tint: #E6F5F0;
  --amber: #BA7517;
  --amber-tint: #FBF0E1;
  --red: #A32D2D;
  --red-tint: #F9E9E9;
  --blue-tint: #EAF1FB;
  --blue: #2E5FA3;
  --surface: #FFFFFF;
  --surface-muted: #F7F7F8;
  --border: #DADCE0;
  --text: #1A1D21;
  --text-muted: #6B7076;
  --radius: 8px;
  /* Fixed dark chip for the log box -- deliberately not tied to --text, which
     flips between themes. */
  --code-bg: #1A1D21;
  --code-fg: #D5D8DC;
}

/* Dark theme: applied when the OS prefers it (and the user hasn't explicitly
   chosen light), or always once the toggle button sets data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: #1E2126;
    --surface-muted: #16181C;
    --border: #33373D;
    --text: #ECEDEE;
    --text-muted: #9BA1A6;
  }
}
:root[data-theme="dark"] {
  --surface: #1E2126;
  --surface-muted: #16181C;
  --border: #33373D;
  --text: #ECEDEE;
  --text-muted: #9BA1A6;
}

* { box-sizing: border-box; }

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

button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius);
  border: 0.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
}
button:hover { background: var(--surface-muted); }

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 500;
}
.btn-primary:hover { background: #178563; }

.btn-text {
  border: none;
  background: none;
  color: var(--text-muted);
  padding: 4px 0;
  font-size: 13px;
}
.btn-text:hover { color: var(--text); background: none; }

/* Nav bar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: 10px 24px;
}
.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 500;
}
.wordmark-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}
.navtabs { display: flex; gap: 4px; }
.navtabs a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 0.5px solid transparent;
}
.navtabs a.active {
  background: var(--surface-muted);
  border-color: var(--border);
  color: var(--text);
}

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-title { font-size: 18px; font-weight: 500; margin: 0; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* Cards */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 16px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title { font-size: 14px; font-weight: 500; margin: 0; }
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 0.5px solid var(--border);
}

/* Metrics strip */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.metric-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.metric-value { font-size: 24px; font-weight: 500; }
.metric-value.green { color: var(--green); }
.metric-value.amber { color: var(--amber); }
.metric-value.blue { color: var(--blue); }

.markets-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 700px) { .markets-grid { grid-template-columns: 1fr; } }

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--green-tint);
  color: var(--green);
  font-weight: 500;
}

.audit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 0.5px solid var(--border);
}
.audit-row:last-child { border-bottom: none; }
.audit-row-name { font-size: 13px; }
.audit-row-status { display: flex; align-items: center; gap: 8px; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.complete { background: var(--green); }
.status-dot.attention { background: var(--amber); }
.status-dot.none { background: #C6C9CD; }

.pill {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}
.pill.high { background: var(--red-tint); color: var(--red); }
.pill.medium { background: var(--amber-tint); color: var(--amber); }
.pill.low { background: var(--green-tint); color: var(--green); }

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

/* Priority list */
.priority-list { list-style: none; margin: 0; padding: 0; }
.priority-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
}
.priority-item:last-child { border-bottom: none; }
.priority-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-muted);
  border: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}
.priority-text { flex: 1; font-size: 13px; }
.priority-effort { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* Accordion */
.accordion { border: 0.5px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.accordion + .accordion { margin-top: 10px; }
.accordion-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--surface);
}
.accordion-header:hover { background: var(--surface-muted); }
.accordion-name { font-size: 13px; font-weight: 500; flex: 1; }
.accordion-chevron { transition: transform 0.15s ease; color: var(--text-muted); }
.accordion.open .accordion-chevron { transform: rotate(180deg); }
.accordion-body { display: none; padding: 4px 14px 14px; }
.accordion.open .accordion-body { display: block; }

.finding {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 0.5px solid var(--border);
}
.finding:last-child { border-bottom: none; }
.finding-icon { flex-shrink: 0; margin-top: 2px; }
.finding-icon.good { color: var(--green); }
.finding-icon.attention { color: var(--amber); }
.finding-icon.info { color: var(--blue); }
.finding-title { font-weight: 500; font-size: 13px; }
.finding-text { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.copy-block {
  position: relative;
  background: var(--surface-muted);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 40px 12px 12px;
  font-size: 13px;
  margin: 8px 0;
  white-space: pre-wrap;
}
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
  padding: 3px 8px;
}

/* Live status page */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 0.5px solid var(--border);
  margin-bottom: 12px;
  font-size: 13px;
}
.banner.complete { background: var(--green-tint); border-color: var(--green); }
.banner.running { background: var(--amber-tint); border-color: var(--amber); }
.banner-dot { width: 9px; height: 9px; border-radius: 50%; }
.banner.complete .banner-dot { background: var(--green); }
.banner.running .banner-dot { background: var(--amber); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.info-strip {
  background: var(--blue-tint);
  color: var(--blue);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  margin-bottom: 16px;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px 10px;
  border-bottom: 0.5px solid var(--border);
}
td { padding: 10px; border-bottom: 0.5px solid var(--border); }
tr:hover td { background: var(--surface-muted); }

/* Sortable table headers */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable::after { content: ""; margin-left: 4px; }
th.sort-asc::after { content: "\2191"; }
th.sort-desc::after { content: "\2193"; }

button.small { font-size: 12px; padding: 4px 10px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 10px;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.chip.complete { background: var(--green-tint); color: var(--green); }
.chip.complete .dot { background: var(--green); }
.chip.running { background: var(--amber-tint); color: var(--amber); }
.chip.running .dot { background: var(--amber); }
.chip.queued { background: var(--surface-muted); color: var(--text-muted); }
.chip.queued .dot { background: #C6C9CD; }
.chip.failed { background: var(--red-tint); color: var(--red); }
.chip.failed .dot { background: var(--red); }

.log-box {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: var(--radius);
  padding: 12px;
  max-height: 180px;
  overflow-y: auto;
}
.log-line { padding: 2px 0; white-space: pre-wrap; word-break: break-word; }
.log-line.success { color: #6FD8AE; }
.log-line.warn { color: #E8B368; }
.log-line.error { color: #E38A8A; }

/* Forms */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 14px;
}
@media (max-width: 700px) { .form-row { grid-template-columns: 1fr; } }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.field input, .field textarea, .field select {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  background: var(--surface-muted);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text);
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--green);
}
.field textarea { min-height: 64px; resize: vertical; }
.section-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: none;
  margin: 18px 0 10px;
  padding-top: 14px;
  border-top: 0.5px solid var(--border);
}
.section-label:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.empty-state { color: var(--text-muted); font-size: 13px; padding: 20px 0; text-align: center; }
