/* Morpho Observatory — dense research dashboard.
   Risk is always communicated by a text label as well as colour. */

:root {
  --bg: #0d1117;
  --bg-raised: #151b23;
  --bg-inset: #10161d;
  --border: #262d38;
  --border-strong: #3a4453;
  --text: #e4e8ee;
  --text-muted: #8b96a5;
  --text-dim: #616d7e;
  --accent: #4c8dff;
  --accent-dim: #1f3557;
  --accent-text: #cfe0ff;
  --row-hover: #182029;
  color-scheme: dark;

  --normal: #3fb950;
  --watch: #d6a41e;
  --high: #e08640;
  --extreme: #f0663f;
  --critical: #f4534e;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f6f8fa;
  --bg-raised: #ffffff;
  --bg-inset: #eef2f6;
  --border: #d8dee6;
  --border-strong: #afb8c5;
  --text: #1f2328;
  --text-muted: #57606a;
  --text-dim: #6e7781;
  --accent: #0969da;
  --accent-dim: #dbeafe;
  --accent-text: #064a9b;
  --row-hover: #f0f4f8;
  --normal: #16752a;
  --watch: #8a6200;
  --high: #a44800;
  --extreme: #c23912;
  --critical: #cf222e;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { font-size: 15px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

code, .mono, td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.6rem 1.25rem;
  flex-wrap: wrap;
}

.brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .version {
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 400;
  margin-left: 0.35rem;
}

.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav a {
  padding: 0.3rem 0.7rem;
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.nav a:hover { background: var(--bg-inset); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-dim); color: var(--accent-text); }

.content { padding: 1.25rem; max-width: 1800px; margin: 0 auto; }

/* ---------- freshness strip ---------- */

.freshness {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
  padding: 0.45rem 1.25rem;
  background: var(--bg-inset);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--mono);
}
.freshness .item { white-space: nowrap; }
.freshness .item b { color: var(--text); font-weight: 550; }
.freshness .item.stale b { color: var(--extreme); }
.freshness .item.stale::after { content: " stale"; color: var(--extreme); }
.freshness .spacer { flex: 1; }

/* ---------- headings ---------- */

h1 { font-size: 1.4rem; margin: 0 0 0.25rem; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 1.75rem 0 0.6rem; font-weight: 600; }
h3 { font-size: 0.92rem; margin: 1.25rem 0 0.5rem; font-weight: 600; color: var(--text-muted); }

.page-head { margin-bottom: 1rem; }
.page-head .subtitle { color: var(--text-muted); font-size: 0.85rem; }

.section-note {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin: 0 0 0.6rem;
}

/* ---------- KPI cards ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 0.6rem;
}

.kpi {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.7rem 0.8rem;
}
.kpi .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}
.kpi .value {
  font-family: var(--mono);
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.kpi .sub { font-size: 0.72rem; color: var(--text-dim); margin-top: 0.2rem; }

.kpi.watch .value { color: var(--watch); }
.kpi.high .value { color: var(--high); }
.kpi.extreme .value { color: var(--extreme); }
.kpi.critical .value { color: var(--critical); }

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

.table-wrap {
  overflow-x: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 7px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--bg-inset);
  text-align: left;
  padding: 0.5rem 0.65rem;
  font-weight: 550;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
thead th.num { text-align: right; }
thead th a { color: inherit; }
thead th a:hover { color: var(--text); text-decoration: none; }
thead th a.sorted { color: var(--accent); }

tbody td {
  padding: 0.42rem 0.65rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td.num { text-align: right; font-size: 0.8rem; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--row-hover); }

td.wrap, th.wrap { white-space: normal; }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* Copy affordance next to abbreviated addresses and hashes. */
.copy {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0 0.15rem;
  opacity: 0;
  transition: opacity 0.1s;
}
tr:hover .copy, .facts .fact:hover .copy, .page-head .copy { opacity: 1; }
.copy:hover { color: var(--accent); }
.copy.copied { color: var(--normal); opacity: 1; }

/* ---------- risk labels ---------- */

.hf {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.hf .tag {
  font-family: var(--sans);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  border: 1px solid currentColor;
  opacity: 0.9;
}

.risk-normal { color: var(--normal); }
.risk-watch { color: var(--watch); }
.risk-high { color: var(--high); }
.risk-extreme { color: var(--extreme); }
.risk-critical { color: var(--critical); font-weight: 600; }
.risk-unknown, .risk-no-debt { color: var(--text-dim); }

.pos { color: var(--normal); }
.neg { color: var(--critical); }

/* ---------- filters ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.7rem 0.8rem;
  margin-bottom: 0.8rem;
}
.field { display: flex; flex-direction: column; gap: 0.2rem; }
.field label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
input[type="text"], input[type="number"], input[type="date"], select {
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text);
  padding: 0.3rem 0.45rem;
  font-size: 0.82rem;
  font-family: var(--sans);
  min-width: 8rem;
}
input:focus, select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

.checkbox { flex-direction: row; align-items: center; gap: 0.4rem; padding-bottom: 0.3rem; }
.checkbox label { text-transform: none; letter-spacing: 0; font-size: 0.8rem; color: var(--text-muted); }

button, .btn {
  background: var(--accent-dim);
  border: 1px solid var(--border-strong);
  color: var(--accent-text);
  border-radius: 5px;
  padding: 0.32rem 0.8rem;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: var(--sans);
}
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--text-muted); }

/* ---------- pills / period selector ---------- */

.pills { display: inline-flex; gap: 0.25rem; flex-wrap: wrap; }
.pills a {
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.pills a:hover { text-decoration: none; color: var(--text); }
.pills a.active { background: var(--accent-dim); color: var(--accent-text); border-color: var(--accent); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
}
.theme-toggle:hover { color: var(--text); }

/* ---------- network picker and badges ---------- */

.chainbar {
  padding: 0.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.chainbar:empty { display: none; }

.chip {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}
/* Networks are told apart by their name; the tint is a secondary cue only,
   never the sole carrier of meaning. */
.chip.chain-1 { border-color: #5b7cfa; color: #a8bcff; }
.chip.chain-8453 { border-color: #3d7bff; color: #9fc0ff; }
.chip.chain-137 { border-color: #8e6cf0; color: #c4b0ff; }
.chip.chain-42161 { border-color: #3f9bd6; color: #a3d4ef; }
.chip.chain-10 { border-color: #d6564f; color: #f0a5a1; }
.chip.chain-130 { border-color: #d357a8; color: #f0a9d8; }
.chip.chain-747474 { border-color: #4fb28a; color: #a5dcc5; }

/* ---------- pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--mono);
}
.pagination .spacer { flex: 1; }

/* ---------- definition grids ---------- */

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.1rem 1.5rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.85rem 1rem;
}
.fact { padding: 0.3rem 0; border-bottom: 1px solid var(--border); }
.fact .k {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.fact .v { font-family: var(--mono); font-size: 0.86rem; word-break: break-all; }

/* ---------- charts ---------- */

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(430px, 1fr));
  gap: 0.75rem;
}
.chart {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.6rem;
  min-height: 300px;
}
.chart .chart-title {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0 0 0.3rem 0.35rem;
}
.chart-empty { color: var(--text-dim); font-size: 0.82rem; padding: 4rem 1rem; text-align: center; }

/* ---------- timeline ---------- */

.timeline { list-style: none; margin: 0; padding: 0 0 0 1.1rem; border-left: 1px solid var(--border-strong); }
.timeline li { position: relative; padding: 0.35rem 0 0.35rem 0.4rem; font-size: 0.84rem; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -1.52rem;
  top: 0.72rem;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}
.timeline li.kind-watch::before { background: var(--watch); }
.timeline li.kind-high::before { background: var(--high); }
.timeline li.kind-extreme::before { background: var(--extreme); }
.timeline li.kind-critical::before { background: var(--critical); }
.timeline li.kind-start::before { background: var(--accent); }
.timeline li.kind-liquidation::before { background: var(--critical); box-shadow: 0 0 0 3px rgba(244, 83, 78, 0.2); }
.timeline li.kind-end::before { background: var(--text-muted); }
.timeline .when { font-family: var(--mono); font-size: 0.76rem; color: var(--text-dim); margin-right: 0.5rem; }
.timeline .detail { color: var(--text-muted); font-size: 0.78rem; }

/* ---------- callouts ---------- */

.callout {
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--watch);
  background: var(--bg-raised);
  border-radius: 5px;
  padding: 0.7rem 0.9rem;
  font-size: 0.84rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
}
.callout strong { color: var(--text); }
.callout.info { border-left-color: var(--accent); }

/* ---------- misc ---------- */

.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.small { font-size: 0.78rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.stack { display: flex; flex-direction: column; gap: 0.1rem; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

.badge {
  display: inline-block;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.08rem 0.35rem;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}
.badge.ok { color: var(--normal); border-color: currentColor; }
.badge.bad { color: var(--critical); border-color: currentColor; }
.badge.pending { color: var(--watch); border-color: currentColor; }

.methodology { max-width: 62rem; }
.methodology p, .methodology li { color: var(--text-muted); font-size: 0.9rem; }
.methodology h2 { color: var(--text); }
.methodology pre {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  overflow-x: auto;
  font-size: 0.8rem;
  color: var(--text);
}
.methodology code { font-size: 0.85em; }

.htmx-request .table-wrap { opacity: 0.55; transition: opacity 0.1s; }

/* ---------- login ---------- */

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.login {
  width: 100%;
  max-width: 22rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}
.login h1 { font-size: 1.05rem; margin: 0 0 0.2rem; }
.login p { margin: 0 0 1.2rem; }
.login label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}
.login input {
  width: 100%;
  margin-bottom: 0.9rem;
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.45rem 0.55rem;
}
.login input:focus { outline: none; border-color: var(--accent); }
.login button {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.5rem;
}
.login button:hover { filter: brightness(1.1); }

.login-error {
  border: 1px solid var(--critical);
  border-radius: 4px;
  color: var(--critical);
  font-size: 0.8rem;
  padding: 0.45rem 0.6rem;
  margin-bottom: 1rem;
}

/* ---------- connection health ---------- */

.dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  margin-right: 0.4rem;
  background: var(--text-dim);
  vertical-align: baseline;
}
.dot.ok { background: var(--normal); }
.dot.error { background: var(--critical); }
.dot.disabled { background: var(--text-dim); }
.dot.stale { background: var(--watch); }

.banner {
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  margin: 0 0 1rem;
}
.banner.ok { border: 1px solid var(--normal); color: var(--normal); }
.banner.bad { border: 1px solid var(--critical); color: var(--critical); }
.banner strong { color: inherit; }
