:root {
  --navy: #00215e;
  --navy-hover: #001a4d;
  --red-alert: #c41e3a;
  --red-muted: #fef2f2;
  --text: #1e293b;
  --text-muted: #64748b;
  --label-caps: #94a3b8;
  --border: #e2e8f0;
  --shell-bg: #ffffff;
  --card-shadow: 0 1px 3px rgba(0, 33, 94, 0.08);
}
* { box-sizing: border-box; }
body.app-shell {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--shell-bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.25rem 1.5rem;
}
.app-header {
  margin-bottom: 1rem;
}
.portal-title {
  margin: 0 0 0.2rem;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.02em;
}
.portal-tagline {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.header-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}
.header-tabs .tab-trigger {
  padding: 0.55rem 1.1rem;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.header-tabs .tab-trigger:hover { color: var(--text); }
.header-tabs .tab-trigger.active {
  color: var(--navy);
  font-weight: 700;
  border-bottom-color: var(--navy);
}

.content-card {
  background: #fafbfc;
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  padding: 1.5rem 1.5rem 1.75rem;
  flex: 1;
}

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

.form-row {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.form-row label { font-size: 0.8rem; font-weight: 600; color: var(--navy); }
.form-row input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}
.form-row input[type="number"] {
  width: 100px;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.btn-primary {
  padding: 0.55rem 1.1rem;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn-primary:hover { background: var(--navy-hover); }
.hint-inline {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 42rem;
  line-height: 1.45;
}

#result, #result-recent { margin-top: 0.35rem; font-size: 0.85rem; }
.error { color: var(--red-alert); font-weight: 500; }

.metrics-section { margin-top: 0.5rem; }
.metrics-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.metrics-eyebrow {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--label-caps);
  margin: 0 0 0.2rem;
}
.metrics-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--navy);
}
.alert-pill {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  white-space: nowrap;
}
.alert-pill.neutral {
  background: #f1f5f9;
  color: var(--text-muted);
}
.alert-pill.high {
  background: var(--red-muted);
  color: var(--red-alert);
}
.alert-pill.warn {
  background: #fffbeb;
  color: #b45309;
}

#risk-summary-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1rem;
  padding: 0.65rem 0.85rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1.35fr 1fr;
  gap: 1.1rem;
  margin-bottom: 1.1rem;
}
@media (max-width: 960px) {
  .metrics-grid { grid-template-columns: 1fr; }
}
.metric-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  box-shadow: var(--card-shadow);
}
.metric-card .card-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--label-caps);
  margin-bottom: 0.5rem;
}
.metric-card .card-value-lg {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--navy);
}
.metric-card .card-value-lg.critical { color: var(--red-alert); }
.severity-badge {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
}
.severity-badge.ok { background: #ecfdf5; color: #047857; }
.severity-badge.warn { background: #fffbeb; color: #b45309; }
.severity-badge.critical { background: var(--red-muted); color: var(--red-alert); }

.metric-card.card-volume-hero {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}
.metric-card.card-volume-hero .card-label { color: rgba(255,255,255,0.7); }
.metric-card.card-volume-hero .card-value-lg {
  color: #fff;
  font-size: clamp(1.5rem, 4vw, 2.35rem);
}
.metric-card.card-volume-hero .volume-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(255,255,255,0.2);
  font-size: 0.75rem;
  color: rgba(255,255,255,0.85);
}
.metric-card.card-volume-hero .volume-foot strong { color: #fff; }

.topology-list { margin: 0; padding: 0; list-style: none; font-size: 0.85rem; }
.topology-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}
.topology-list li:last-child { border-bottom: none; }
.topology-list span:first-child { color: var(--text-muted); }
.topology-list strong { color: var(--navy); font-size: 1.05rem; }

.metrics-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.1rem;
  align-items: stretch;
}
@media (max-width: 960px) {
  .metrics-row2 { grid-template-columns: 1fr; }
}
.cluster-pair {
  display: flex;
  gap: 1.25rem;
}
.cluster-pair > div { flex: 1; }
.cluster-pair .n { font-size: 1.5rem; font-weight: 800; color: var(--navy); }
.cluster-pair .lbl {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--label-caps);
}
.mule-pass-lines { font-size: 0.85rem; line-height: 1.65; }
.mule-pass-lines strong { color: var(--navy); font-size: 1.1rem; }

.flagged-mules-box { margin-top: 1.1rem; }
.flagged-mules-list { margin-top: 0.5rem; max-height: 12rem; overflow-y: auto; }
.flagged-mule-addr {
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  word-break: break-all;
  line-height: 1.4;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.flagged-mule-addr:last-child { border-bottom: none; }
.flagged-mules-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0.6rem 0 0;
  line-height: 1.4;
}

.history-tab-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.history-tab-head .hint-inline { margin: 0; flex: 1; min-width: 12rem; }
.btn-secondary {
  padding: 0.5rem 1rem;
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-secondary:hover { background: #f1f5f9; }
#global-flagged-status {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.global-flagged-list {
  margin-top: 0.35rem;
  max-height: min(70vh, 28rem);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.65rem;
  background: #fff;
}
.global-flagged-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 1rem;
}
.global-flagged-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.global-flagged-row a.global-flagged-arkm {
  color: #0369a1;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.global-flagged-row a.global-flagged-arkm:hover {
  color: var(--navy);
}
.btn-export {
  margin-top: 1.1rem;
  width: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.btn-export:hover:not(:disabled) { background: var(--navy-hover); }
.btn-export:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.panel { margin-bottom: 1.5rem; }
.panel-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--navy);
  margin-bottom: 0.65rem;
}

.flow-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.flow-toolbar {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
}
.flow-toolbar .icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
}
.flow-toolbar .icon-btn:hover {
  background: #f8fafc;
  color: var(--navy);
}
.flow-toolbar .text-btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.flow-toolbar .text-btn:hover { background: #f1f5f9; }
.flow-toolbar .text-btn.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
#flow-view {
  width: 100%;
  height: 380px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.flow-summary {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  line-height: 1.45;
}

.timeline {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 0.35rem;
}
.timeline-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.6rem;
  font-size: 0.8rem;
  border-bottom: 1px solid #f1f5f9;
}
.timeline-item:last-child { border-bottom: none; }
.timeline-time { color: var(--text-muted); min-width: 138px; font-family: ui-monospace, monospace; font-size: 0.76rem; }
.timeline-flow { flex: 1; font-family: ui-monospace, monospace; font-size: 0.72rem; color: var(--text); }
.timeline-amount { font-weight: 700; color: var(--navy); font-size: 0.8rem; }
.addr-dune-banned {
  display: inline-block;
  padding: 0.08rem 0.28rem;
  border-radius: 4px;
  background: #fff1f2;
  color: #9f1239;
  border: 1px solid #fda4af;
  font-weight: 600;
}

.empty-state { text-align: center; color: var(--text-muted); padding: 2rem; font-size: 0.9rem; }

.loading-recent {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2.5rem 2rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.loading-recent .spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
