/* SPDX-License-Identifier: Apache-2.0 OR MIT */
:root {
  --bg: #080b10;
  --bg-elev: #0f141d;
  --bg-card: #131a26;
  --bg-input: #0b1018;
  --border: #222e42;
  --border-hi: #334666;
  --text: #e6edf7;
  --text-dim: #94a3b8;
  --text-muted: #64748b;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.14);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.14);
  --radius: 10px;
  --radius-sm: 6px;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 12% 0%, #101a2c 0%, var(--bg) 52%);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 20px 56px;
}

/* Header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: linear-gradient(135deg, #0ea5e9 0%, #22c55e 100%);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-weight: 800;
  font-size: 15px;
  color: #051018;
  flex-shrink: 0;
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.22);
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.02em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.brand p {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 12.5px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border-hi);
  background: var(--bg-card);
  color: var(--text-dim);
  white-space: nowrap;
}

.pill-devnet { border-color: rgba(56, 189, 248, 0.45); color: var(--accent); background: var(--accent-soft); }
.pill-green { border-color: rgba(34, 197, 94, 0.45); color: var(--green); background: var(--green-soft); }
.pill-amber { border-color: rgba(245, 158, 11, 0.45); color: var(--amber); background: var(--amber-soft); }
.pill-red { border-color: rgba(239, 68, 68, 0.45); color: var(--red); background: var(--red-soft); }
.pill-violet { border-color: rgba(167, 139, 250, 0.45); color: var(--violet); background: var(--violet-soft); }

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* RPC Panel */
.rpc-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}

.rpc-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.rpc-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.rpc-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field label {
  font-size: 11px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.field input, .field select {
  width: 100%;
  min-width: 0;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}

.field textarea {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.45;
  resize: vertical;
  outline: none;
}

.wallet-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.wallet-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.stacked-bar {
  display: flex;
  width: 100%;
  height: 16px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-input);
}

.seg-msg { background: #38bdf8; }
.seg-hdr { background: #a78bfa; }
.seg-pad { background: #f59e0b; }
.seg-env { background: #22c55e; }

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 6px;
}

.debug-pre {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: #cbd5e1;
  overflow-x: auto;
  margin: 10px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.rpc-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.rpc-accounts-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hi);
  background: var(--bg-card);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
  white-space: nowrap;
}

.btn:hover { background: #1a2333; border-color: #4a628a; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: #0284c7; border-color: #38bdf8; color: #f8fafc; }
.btn-primary:hover { background: #0369a1; }
.btn-good { background: rgba(34, 197, 94, 0.16); border-color: rgba(34, 197, 94, 0.55); color: #86efac; }
.btn-good:hover { background: rgba(34, 197, 94, 0.25); }
.btn-danger { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.55); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.26); }
.btn-warn { background: rgba(245, 158, 11, 0.16); border-color: rgba(245, 158, 11, 0.55); color: #fcd34d; }
.btn-warn:hover { background: rgba(245, 158, 11, 0.26); }
.btn-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 5px 9px; font-size: 11.5px; }

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

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.tab-btn {
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tab-btn:hover { color: var(--text); border-color: var(--border-hi); }
.tab-btn.active {
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.18), rgba(56, 189, 248, 0.06));
  border-color: var(--accent);
  color: var(--text);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Cards & Grids */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

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

.card + .card, .section-gap { margin-top: 16px; }

.card h2 {
  margin: 0 0 6px;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 13.5px;
  color: var(--text-dim);
  font-weight: 600;
}

.subtitle {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 12.5px;
}

.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-width: 0;
}

.kpi-label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-val {
  font-size: 17px;
  font-weight: 700;
  font-family: var(--mono);
  margin-top: 2px;
  color: var(--text);
  word-break: break-word;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Verdict Banners */
.verdict {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  margin-bottom: 14px;
  font-size: 13px;
}

.verdict-pass {
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.09);
  color: #dcfce7;
}

.verdict-fail {
  border-color: rgba(239, 68, 68, 0.6);
  background: rgba(239, 68, 68, 0.11);
  color: #fee2e2;
}

.verdict-warn {
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.1);
  color: #fef3c7;
}

.verdict-title {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12.5px;
  margin-bottom: 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Progress / CU Bars */
.bar-track {
  width: 100%;
  height: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #0ea5e9, #22c55e);
  transition: width 0.2s ease;
}

.bar-fill.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.bar-fill.danger { background: linear-gradient(90deg, #dc2626, #ef4444); }

/* Stepper pills */
.phase-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.phase-row {
  display: grid;
  grid-template-columns: 110px 1fr 125px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 12px;
}

.phase-row.current {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

.phase-row.done {
  border-color: rgba(34, 197, 94, 0.4);
}

.phase-row.failed {
  border-color: rgba(239, 68, 68, 0.7);
  background: rgba(239, 68, 68, 0.12);
}

/* Code / Hex / Tables */
.mono { font-family: var(--mono); }
.hex {
  font-family: var(--mono);
  font-size: 11.5px;
  color: #bae6fd;
  word-break: break-all;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th, td {
  text-align: left;
  padding: 7px 9px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

td.num, th.num { text-align: right; font-family: var(--mono); }

/* SVG Charts */
.chart-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-top: 10px;
}

.chart-box svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Custodian Toggle Cards */
.custodian-card {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.custodian-card.honest { border-color: rgba(34, 197, 94, 0.45); }
.custodian-card.corrupt { border-color: rgba(239, 68, 68, 0.6); background: rgba(239, 68, 68, 0.08); }

/* Event log */
.log-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.log-ok { color: #86efac; }
.log-err { color: #fca5a5; }
.log-info { color: #93c5fd; }

/* Slider row */
.slider-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 8px 0 12px;
}

.slider-row input[type="range"] {
  flex: 1;
  min-width: 140px;
  accent-color: var(--accent);
}

.footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* Responsive Mobile (390px) */
@media (max-width: 980px) {
  .rpc-grid, .rpc-accounts-grid, .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-2, .grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 600px) {
  .app-shell { padding: 14px 12px 44px; }
  .rpc-grid, .rpc-accounts-grid, .grid-4 {
    grid-template-columns: minmax(0, 1fr);
  }
  .phase-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }
  .tabs { gap: 6px; }
  .tab-btn { flex: 1 1 100%; justify-content: space-between; font-size: 12.5px; }
  .brand h1 { font-size: 17px; }
}
