:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #e0e4e9;
  --line-strong: #c9d0d8;
  --text: #14181f;
  --text-muted: #5c6673;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-weak: #eef3ff;
  --ok: #157347;
  --ok-weak: #e8f5ee;
  --warn: #9a5b06;
  --warn-weak: #fdf2e0;
  --bad: #b42318;
  --bad-weak: #fdecea;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

/* `hidden` must win over the layout rules below (flex/grid would override it). */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--accent-weak);
  color: var(--accent);
}

.brand-mark .icon {
  width: 15px;
  height: 15px;
}

.brand-name {
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
}

.statuses {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
}

.pill.is-ok {
  color: var(--ok);
  border-color: #bfe0cd;
  background: var(--ok-weak);
}

.pill.is-ok .dot {
  background: var(--ok);
}

.pill.is-warn {
  color: var(--warn);
  border-color: #ecd2a6;
  background: var(--warn-weak);
}

.pill.is-warn .dot {
  background: var(--warn);
}

.pill.is-bad {
  color: var(--bad);
  border-color: #f0c2bd;
  background: var(--bad-weak);
}

.pill.is-bad .dot {
  background: var(--bad);
}

/* ------------------------------------------------------------------ layout */

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  align-items: start;
  min-height: calc(100vh - 56px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  min-height: calc(100vh - 56px);
}

.layout.is-lobby {
  grid-template-columns: minmax(0, 1fr);
}

.content {
  min-width: 0;
  padding-bottom: 48px;
}

.lobby-slot {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 8px 0 0;
}

.lobby-slot .section {
  border-bottom: 0;
}

.section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.sidebar .section:last-child,
.content .section:last-child {
  border-bottom: 0;
}

.section-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

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

.section-head .section-title {
  margin: 0;
}

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

/* ----------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.btn:hover:not(:disabled) {
  background: #f7f8fa;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn-quiet {
  border-color: var(--line);
  color: var(--text-muted);
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 34px;
  padding: 0;
  flex: none;
}

.btn-small {
  min-height: 26px;
  padding: 0 9px;
  font-size: 12px;
}

.chevron {
  transition: transform 150ms ease;
}

[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.field-label:not(:first-child) {
  margin-top: 14px;
}

.input {
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

select.input {
  cursor: pointer;
}

.input:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#input-link {
  font-family: var(--mono);
  font-size: 12px;
}

.input-row {
  display: flex;
  gap: 8px;
}

#btn-run {
  margin-top: 18px;
}

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

.hint.is-error {
  color: var(--bad);
}

.alert {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #f0c2bd;
  border-radius: var(--radius);
  background: var(--bad-weak);
  color: var(--bad);
  font-size: 13px;
}

.alert p {
  margin: 0 0 8px;
}

.alert .btn {
  background: var(--surface);
  color: var(--bad);
  border-color: #f0c2bd;
}

/* ------------------------------------------------------------- key/value */

.kv {
  display: grid;
  gap: 0;
  margin: 0;
}

.kv > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}

.kv > div:last-child {
  border-bottom: 0;
}

.kv dt {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.kv dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
  overflow-wrap: anywhere;
}

.kv-wide dd,
.kv-wide dt {
  font-size: 12.5px;
}

/* ---------------------------------------------------------------- phases */

.phases {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.phases li {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-muted);
}

.phases li:last-child {
  border-bottom: 0;
}

.phase-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
}

.phases li[data-state="active"] {
  color: var(--text);
  font-weight: 500;
}

.phases li[data-state="active"] .phase-dot {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.phases li[data-state="done"] {
  color: var(--text);
}

.phases li[data-state="done"] .phase-dot {
  border-color: var(--ok);
  background: var(--ok);
}

.phases li[data-state="failed"] .phase-dot {
  border-color: var(--bad);
  background: var(--bad);
}

.phase-meta {
  overflow: hidden;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phase-name {
  white-space: nowrap;
}

/* ----------------------------------------------------------------- meters */

.meters {
  display: grid;
  gap: 0;
}

.meter {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.meter:first-child {
  padding-top: 0;
}

.meter:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.meter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.meter-title {
  font-weight: 500;
}

.meter-value {
  font-family: var(--mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.meter-value .unit {
  margin-left: 3px;
  font-size: 11px;
  color: var(--text-muted);
}

.bar {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: #eceff3;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--accent);
  transition: width 140ms linear;
}

.meter-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 7px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------- verdict */

.verdict {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--surface);
}

.verdict.is-ok {
  border-color: #bfe0cd;
  border-left-color: var(--ok);
  background: var(--ok-weak);
}

.verdict.is-warn {
  border-color: #ecd2a6;
  border-left-color: var(--warn);
  background: var(--warn-weak);
}

.verdict.is-fail {
  border-color: #f0c2bd;
  border-left-color: var(--bad);
  background: var(--bad-weak);
}

.verdict-badge {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line-strong);
  font-size: 11.5px;
  font-weight: 600;
}

.verdict.is-ok .verdict-badge {
  color: var(--ok);
  border-color: #bfe0cd;
}

.verdict.is-warn .verdict-badge {
  color: var(--warn);
  border-color: #ecd2a6;
}

.verdict.is-fail .verdict-badge {
  color: var(--bad);
  border-color: #f0c2bd;
}

.verdict-title {
  margin: 0 0 4px;
  font-weight: 600;
}

.verdict-detail {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ----------------------------------------------------------------- tables */

.result-block {
  margin-top: 22px;
}

.result-block h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 13px;
}

table.data th,
table.data td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

table.data th:first-child,
table.data td:first-child {
  text-align: left;
  white-space: normal;
}

table.data thead th {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: #fafbfc;
  border-top: 1px solid var(--line);
}

table.data tbody tr:last-child td {
  border-bottom: 0;
}

table.data td.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.cell-level-ok {
  color: var(--ok);
}

.cell-level-warn {
  color: var(--warn);
}

.cell-level-fail {
  color: var(--bad);
  font-weight: 600;
}

.table-note {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* -------------------------------------------------------------------- log */

.log {
  max-height: 220px;
  margin: 12px 0 0;
  padding: 10px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-muted);
  white-space: pre-wrap;
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #1f242c;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(16, 20, 26, 0.18);
}

.toast.is-error {
  background: var(--bad);
  border-color: var(--bad);
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    min-height: 0;
  }

  .topbar {
    height: auto;
    padding: 10px 16px;
    flex-wrap: wrap;
  }

  .content .section,
  .sidebar .section {
    padding: 16px;
  }
}

@media (max-width: 560px) {
  table.data th,
  table.data td {
    padding: 8px 6px;
    font-size: 12.5px;
  }

  .meter-value {
    font-size: 14px;
  }
}
