:root {
  --bg: #eef0f3;
  --fg: #0a0a0a;
  --muted: #6b7280;
  --line: #c0c6cf;
  --card: #ffffff;
  --accent: #0a4dab;
  --good: #0a7a3a;
  --bad: #b00020;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute must always win over our display rules. Without
   this an element with class="stack" hidden would still render because the
   class selector ties with [hidden] on specificity and wins on source order. */
[hidden] { display: none !important; }

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

body {
  font-family: var(--mono);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  font-size: 14px;
}

/* Default link styling — every <a> is hyperlink-blue + underlined.
   Chrome elements (nav tabs, sub-nav, brand wordmark, full-card click targets)
   opt out via the rule below. */
a, a:visited { color: #0000ee; text-decoration: underline; }
a:hover { color: #0000ee; text-decoration: underline; }
.brand .home, .brand .home:visited,
.nav-tab, .nav-tab:visited,
.nav-link, .nav-link:visited,
a.card, a.card:visited,
a.stat-card, a.stat-card:visited,
.pill, .pill:visited {
  color: inherit;
  text-decoration: none;
}

header {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: grid;
  grid-template-columns: max-content max-content 1fr max-content;
  align-items: center;
  gap: 1.25rem;
  background: var(--card);
}
.brand { display: flex; align-items: center; gap: 0.5rem; }
.brand h1 { margin: 0; font-size: 1.1rem; letter-spacing: 0.02em; }
.brand .home { color: inherit; text-decoration: none; }
.brand .home:hover h1 { color: var(--accent); }
.nav-primary {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}
.nav-tab {
  font-size: 0.85rem;
  padding: 0.45rem 0.9rem;
  border-radius: 4px;
  text-decoration: none;
  color: var(--muted);
  border: 1px solid transparent;
}
.nav-tab:hover { color: var(--fg); background: var(--bg); }
.nav-tab-active {
  color: var(--fg);
  background: var(--bg);
  border-color: var(--line);
}
.meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
  justify-self: end;
}
.meta .net, .meta .ver { color: var(--muted); }
.status { color: var(--muted); }
.status.ok { color: var(--good); }
.status.err { color: var(--bad); }
/* .manifest inherits the global <a> styling — hyperlink blue + underlined. */

.nav-secondary {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  gap: 0.25rem;
  align-items: center;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.nav-link {
  font-size: 0.8rem;
  padding: 0.6rem 0.75rem;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.nav-link:hover { color: var(--fg); }
.nav-link-active {
  color: var(--fg);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

.search {
  display: flex;
  gap: 0.4rem;
  flex: 1;
  max-width: 420px;
  margin: 0;
  justify-self: end;
}
.search input {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  color: var(--fg);
  min-width: 0;
}
.search input:focus { outline: none; border-color: var(--accent); }
.search button {
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  cursor: pointer;
  color: var(--muted);
}
.search button:hover { background: #f0f0f0; color: var(--fg); }
@media (max-width: 640px) {
  .search { display: none; }
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1.5rem;
}

.page-head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0;
}
.page-head h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 500;
  letter-spacing: -0.005em;
}
.page-head .page-sub {
  color: var(--muted);
  font-size: 0.85rem;
}

.section-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1.25rem 1.5rem;
}
.section-card > h2:first-child { margin-top: 0; }

/* Vertical stack of cards inside a wrapper div that isn't a direct child of <main>. */
.stack { display: grid; gap: 1.5rem; }

.active-pill {
  font-size: 0.7rem;
  padding: 0.15rem 0.55rem;
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 0.5rem;
  font-weight: normal;
}
h2 .hint { font-size: 0.75rem; color: var(--muted); text-transform: none; letter-spacing: 0; margin-left: 0.5rem; }

.identity dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 1rem;
  margin: 0;
}
.identity dt { color: var(--muted); }
.identity dd { margin: 0; }
.identity code { word-break: break-all; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.85rem 1rem 0.5rem;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 0.1rem;
  position: relative;
  min-height: 96px;
}
.stat-card .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.stat-card .val {
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.stat-card .delta {
  font-size: 0.75rem;
  color: var(--muted);
}
.stat-card .delta.delta-up   { color: var(--good); }
.stat-card .delta.delta-down { color: var(--bad); }
.stat-card .spark {
  align-self: end;
  height: 28px;
  margin: 0.25rem -1rem -0.5rem;
}
.stat-card .spark svg { display: block; width: 100%; height: 100%; }
a.stat-card { color: inherit; text-decoration: none; transition: border-color 80ms, background 80ms; }
a.stat-card:hover { border-color: var(--accent); background: #fdfdff; }
a.stat-card:hover .label { color: var(--accent); }

/* Legacy .card kept for /accounts/ identity etc. */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
}
.card .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.card .val {
  font-size: 1.5rem;
  margin-top: 0.25rem;
}

.chart {
  padding: 0.75rem 1.25rem 1rem;
}
.chart-body {
  height: 160px;
  display: flex;
  align-items: stretch;
}
.chart-body svg { width: 100%; height: 100%; }
.chart-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}
.chart-wrap > svg { display: block; width: 100%; height: 100%; }
.chart-axis {
  position: absolute;
  left: 0.5rem;
  font-size: 10px;
  color: var(--muted);
  font-family: inherit;
  pointer-events: none;
}
.chart-axis-top { top: 0.25rem; }
.chart-axis-bot { bottom: 0.25rem; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
/* Inside a section-card the card already provides bg + border; the table just
   sits inside it without doubling up. */
.section-card table {
  background: transparent;
  border: none;
  border-radius: 0;
  margin-top: 0.25rem;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}
thead th {
  background: var(--bg);
  font-weight: normal;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tr:last-child td { border-bottom: none; }
td.muted { color: var(--muted); text-align: center; }
td code { font-size: 0.85em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.linkrow:hover { background: #f3f6fb; }
/* tr.linkrow links inherit global <a> styling (blue + underline). */
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--fg); }
thead th.sort-asc::after { content: ' ▲'; color: var(--accent); }
thead th.sort-desc::after { content: ' ▼'; color: var(--accent); }
.hint-link { font-size: 0.75rem; text-transform: none; letter-spacing: 0; margin-left: 0.5rem; font-weight: normal; }


.error {
  background: #fdecef;
  border: 1px solid var(--bad);
  color: var(--bad);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1rem;
  margin: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1rem 1.25rem;
}
/* Inside a section-card, .kv inherits the card's bg/border. */
.section-card .kv,
.section-card > dl.kv {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.kv dd code { font-size: 0.95em; }
.kv pre.inline {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.85em;
  white-space: pre-wrap;
  word-break: break-all;
  background: #f4f4f4;
  padding: 0.4rem 0.6rem;
  border-radius: 3px;
}

.raw pre {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.8em;
  margin: 0;
}

.conflict-wrap + .conflict-wrap { margin-top: 1rem; }

.kv-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.kv-form input {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
}
.kv-form button {
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  cursor: pointer;
}
.kv-form button:hover { background: #f0f0f0; }
.raw-pre {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-size: 0.8em;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.info {
  background: #eaf3ea;
  border: 1px solid var(--good);
  color: var(--good);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
}

.actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin: 0.5rem 0;
  flex-wrap: wrap;
}

button {
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  cursor: pointer;
}
button:hover { background: #f0f0f0; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }
button.warn { border-color: var(--bad); color: var(--bad); }
button.warn:hover { background: #fdecef; }

.send-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1rem 1.25rem;
}
.send-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.send-form input, .send-form select {
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg);
  color: var(--fg);
}
.send-form button {
  align-self: start;
  margin-top: 0.5rem;
}

#import-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-top: 0.5rem;
  max-width: 600px;
}
#import-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}
#import-form input {
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
}

details summary { cursor: pointer; color: var(--muted); }
details[open] summary { margin-bottom: 0.5rem; }

.activity {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0.75rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 0.85rem;
}
.activity li {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.6rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--line);
}
.activity li:last-child { border-bottom: none; }
.activity li.muted { color: var(--muted); display: block; }
.activity-ts { color: var(--muted); font-size: 0.8em; }
.activity-msg { word-break: break-word; }
.activity-info .activity-msg { color: var(--fg); }
.activity-success .activity-msg { color: var(--good); }
.activity-error .activity-msg { color: var(--bad); }

.hint-btn {
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  margin-left: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  cursor: pointer;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}
.hint-btn:hover { background: #f0f0f0; color: var(--fg); }
.hint-btn.warn { border-color: var(--bad); color: var(--bad); }
.hint-btn.warn:hover { background: #fdecef; color: var(--bad); }

.passphrase-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1rem 1.25rem;
  max-width: 600px;
  margin-top: 0.5rem;
}
.passphrase-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.passphrase-form input {
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg);
  color: var(--fg);
}
.passphrase-form button {
  align-self: start;
  margin-top: 0.5rem;
}
.passphrase-form.inline-form {
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
}
.passphrase-form.inline-form button { align-self: stretch; margin-top: 0; }

.seed-confirm {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  background: #fff8e1;
  border: 1px solid #f0c14b;
  border-radius: 4px;
}
.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.checkbox-line input { margin: 0; }

.wallet-switcher {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}
.pills { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.pill {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  cursor: pointer;
  color: var(--muted);
}
.pill:hover { background: #f0f0f0; color: var(--fg); }
.pill.pill-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* .reveal-section is now wrapped in .section-card; no extra styling needed. */

.op-row {
  display: grid;
  grid-template-columns: max-content 1fr 2fr max-content;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  align-items: center;
}

.util-table td:last-child { width: 30%; }
.util-bar {
  width: 100%;
  height: 0.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.util-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 200ms linear, background 200ms linear;
}
.util-bar-fill.util-bar-hot { background: #c0392b; }

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.75rem;
  height: 360px;
  overflow-y: auto;
  margin-bottom: 0.5rem;
}
.msg {
  max-width: 80%;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  word-break: break-word;
}
.msg-self {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  flex-direction: row-reverse;
}
.msg-self .msg-ts { color: rgba(255,255,255,0.7); }
.msg-other {
  align-self: flex-start;
  background: #f0f0f0;
  color: var(--fg);
}
.msg-body { font-size: 0.9rem; }
.msg-ts { font-size: 0.75em; color: var(--muted); flex-shrink: 0; }

.pill-badge {
  margin-left: 0.4rem;
  background: var(--bad);
  color: #fff;
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  font-size: 0.7rem;
}
.pill-active .pill-badge { background: #fff; color: var(--accent); }
.op-row select, .op-row input {
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  color: var(--fg);
}
.op-row input:disabled, .op-row select:disabled { opacity: 0.6; background: var(--bg); }
