:root {
  --bg: #0d1117; --panel: #161b22; --line: #30363d; --text: #e6edf3;
  --muted: #8b949e; --accent: #2f81f7; --ok: #2ea043; --warn: #d29922; --crit: #f85149;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0 0 .5rem; }
h2 { font-size: 1rem; border-bottom: 1px solid var(--line); padding-bottom: .4rem; }
h3 { font-size: .85rem; color: var(--muted); margin-top: 1rem; }
.muted { color: var(--muted); font-size: .85rem; }
a { color: var(--accent); text-decoration: none; }
.good { color: var(--ok); }
td.good, td.warn { text-align: right; }
.warn { color: var(--warn); }
.src-summary { margin: .2rem 0 .8rem; }
.src-stats { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; font-size: .9rem; }
.src-stats .sep { color: var(--line); }
.src-stats strong { color: var(--text); }

/* Pipeline stage drill-down */
.stage.clickable { cursor: pointer; }
.stage.clickable:hover { outline: 1px solid var(--accent); }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 1rem; z-index: 50; overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  width: min(820px, 100%); max-height: 92vh; overflow-y: auto; padding: 1rem 1.2rem;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.stage-status { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin: .6rem 0; }
.stage-sec { margin-top: 1rem; }
.stage-sec h4 { margin: 0 0 .4rem; font-size: .85rem; color: var(--muted);
  border-bottom: 1px solid var(--line); padding-bottom: .3rem; }
.cfg-tbl { width: 100%; border-collapse: collapse; }
.cfg-tbl td { padding: .25rem .4rem; vertical-align: top; }
.cfg-tbl .cfg-k { font-family: ui-monospace, monospace; white-space: nowrap; color: var(--text); }
.cfg-tbl .cfg-h { font-size: .8rem; }
.cfg-tbl input, .cfg-tbl select {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px; padding: .3rem .4rem;
}
.stage-actions { margin-top: .6rem; display: flex; gap: .6rem; align-items: center; }
.logbox {
  max-height: 220px; overflow-y: auto; background: var(--bg);
  border: 1px solid var(--line); border-radius: 4px; padding: .5rem;
  font-family: ui-monospace, monospace; font-size: .78rem; line-height: 1.5;
  white-space: pre-wrap; word-break: break-all;
}
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: .1rem .6rem; font-size: .8rem; }
.chip.good { color: var(--ok); } .chip.warn { color: var(--warn); }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .75rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 600; font-size: 1.05rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.topnav { display: flex; gap: 1.25rem; }
.topnav a { color: var(--muted); padding: .2rem 0; border-bottom: 2px solid transparent; }
.topnav a.active { color: var(--text); border-bottom-color: var(--accent); }

.source-add { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem; }
.source-add input[type=url] { flex: 1; min-width: 260px; }
.source-add input, .source-add select {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: .45rem .5rem; font-size: .85rem;
}
#bulk-text {
  width: 100%; box-sizing: border-box; margin-bottom: .6rem;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: .5rem; font-size: .85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical;
}

main { padding: 1.25rem; max-width: 1200px; margin: 0 auto; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem 1.25rem; margin-bottom: 1.25rem;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 800px) { .grid { grid-template-columns: 1fr; } }

.pill {
  padding: .2rem .6rem; border-radius: 999px; font-weight: 600; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .03em;
}
.pill.healthy { background: rgba(46,160,67,.15); color: var(--ok); }
.pill.warning { background: rgba(210,153,34,.15); color: var(--warn); }
.pill.critical { background: rgba(248,81,73,.15); color: var(--crit); }

.metric-row { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: .75rem; }
.metric { min-width: 90px; }
.metric .val { font-size: 1.5rem; font-weight: 600; }
.metric .lbl { color: var(--muted); font-size: .75rem; text-transform: uppercase; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }

.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .4rem; }
.dot.running { background: var(--ok); }
.dot.exited, .dot.dead, .dot.missing { background: var(--crit); }
.dot.restarting, .dot.created, .dot.paused { background: var(--warn); }

.alert { padding: .5rem .75rem; border-radius: 6px; margin: .35rem 0; border-left: 3px solid; }
.alert.critical { background: rgba(248,81,73,.1); border-color: var(--crit); }
.alert.warning { background: rgba(210,153,34,.1); border-color: var(--warn); }
.alert.ok { background: rgba(46,160,67,.1); border-color: var(--ok); color: var(--muted); }

.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: .45rem .8rem; font-size: .85rem; cursor: pointer;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.sm { padding: .25rem .55rem; font-size: .78rem; }

.config-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: .75rem; }
.config-grid label { display: flex; flex-direction: column; gap: .25rem; font-size: .8rem; color: var(--muted); }
.config-grid input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: .4rem .5rem; font-size: .85rem;
}
.config-actions { margin-top: 1rem; display: flex; align-items: center; gap: 1rem; }
.actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.action-inline { display: inline-flex; gap: .4rem; }
.action-inline input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: .4rem .5rem;
}
.ep { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--line); }

/* Admiralty 6x6 heatmap */
.adm-grid { border-collapse: separate; border-spacing: 3px; font-size: .8rem; margin-top: .4rem; }
.adm-grid th { color: var(--muted); font-weight: 600; text-align: center; padding: 2px; border: none; }
.adm-grid th.adm-corner { font-size: .65rem; color: #6a737d; }
.adm-grid td.adm-cell {
  width: 40px; height: 34px; text-align: center; color: #fff; font-weight: 600;
  border-radius: 5px; border: 1px solid var(--bg);
}
.adm-legend { display: flex; align-items: center; gap: .4rem; margin-top: .55rem; font-size: .72rem; color: var(--muted); }
.adm-bar { display: inline-block; width: 96px; height: 10px; border-radius: 4px;
  background: linear-gradient(90deg, hsl(210,68%,30%), hsl(150,68%,32%), hsl(90,68%,38%), hsl(30,68%,42%), hsl(0,68%,44%)); }

/* Ingestion pipeline funnel */
.pipeline { display: flex; flex-wrap: wrap; gap: .4rem; align-items: stretch; }
.stage {
  flex: 1 1 130px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: .6rem .7rem; position: relative;
}
.stage .stage-lbl { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .02em; }
.stage .stage-val { font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.stage .stage-sub { color: var(--muted); font-size: .72rem; }
.stage.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.stage-arrow { display: flex; align-items: center; color: var(--muted); font-size: 1.1rem; }
.pill.discovering { background: rgba(47,129,247,.15); color: var(--accent); }
.pill.processing { background: rgba(210,153,34,.15); color: var(--warn); }
.pill.idle { background: rgba(139,148,158,.15); color: var(--muted); }
.pbar { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: .4rem; }
.pbar > span { display: block; height: 100%; background: var(--accent); }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 2rem; width: 320px; display: flex; flex-direction: column; gap: .9rem;
}
.login-card h1 { text-align: center; margin: 0; }
.login-card .subtitle { text-align: center; color: var(--muted); margin: 0 0 .5rem; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
.login-card input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: .55rem;
}
