/* Sauron: a watchtower for hosts. Dark only, one type family (Archivo,
   variable width) whose width axis does the expressive work. */

@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  color-scheme: dark;
  /* ground & ink */
  --ground: #161b20;      /* basalt */
  --raised: #1d242b;      /* slate, for dialogs/menus */
  --sunk: #12171b;
  --line: #2a333c;        /* hairline */
  --line-strong: #3a4550;
  --ink: #e9e5db;         /* bone */
  --ink-2: #a3aaa4;       /* lichen */
  --ink-3: #7f8781;
  /* signal (UI accent + latency series) */
  --signal: #3987e5;
  --signal-ink: #9cc3f2;
  --loss: #9085e9;
  /* reserved status palette: always paired with a shape and a label */
  --good: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  --none: #262e36;

  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --s-1: 0.8125rem;  /* 13 */
  --s0: 0.9375rem;   /* 15 */
  --s1: 1.125rem;    /* 18 */
  --s2: 1.5rem;      /* 24 */
  --s3: 2.125rem;    /* 34 */
  --s4: clamp(2.25rem, 5.2vw, 3.75rem);
  --rail: 15rem;
  --r-sm: 3px;
  --r-md: 6px;
}

* { box-sizing: border-box; }
html { background: var(--ground); }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--s0);
  line-height: 1.5;
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--signal-ink); text-underline-offset: 0.18em; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: var(--r-sm); }
h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.15; }
h1 { font-size: var(--s3); font-stretch: 118%; font-weight: 760; letter-spacing: -0.01em; }
h2 { font-size: var(--s1); font-stretch: 110%; }
h3 { font-size: var(--s0); font-stretch: 105%; }
p { margin: 0 0 0.75em; max-width: 68ch; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 1.75rem;
  padding: 1.5rem 1.25rem;
  border-right: 1px solid var(--line);
}
.wordmark {
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 1.6rem; font-weight: 850; font-stretch: 125%; letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none;
}
.wordmark svg { flex: none; }
.nav { display: flex; flex-direction: column; gap: 0.1rem; }
.nav-sep { height: 1px; background: var(--line); margin: 0.6rem 0; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.45rem 0.6rem; border-radius: var(--r-md);
  color: var(--ink-2); text-decoration: none;
}
.nav a:hover { color: var(--ink); background: var(--sunk); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--raised); box-shadow: inset 2px 0 0 var(--signal); }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.5rem; font-size: var(--s-1); }
.rail-foot .who { color: var(--ink-2); }
.rail-foot .who strong { color: var(--ink); font-weight: 600; }
.main { min-width: 0; padding: 2.5rem clamp(1rem, 4vw, 3.5rem) 4rem; }
.topbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; inset: 0 auto 0 0; width: min(18rem, 85vw); z-index: 30;
    background: var(--ground); transform: translateX(-100%); transition: transform 0.2s ease;
    padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
  }
  .rail.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55); }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 20; padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
    background: var(--ground); border-bottom: 1px solid var(--line);
  }
  .topbar .wordmark { font-size: 1.25rem; }
  .main { padding-top: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font: inherit; font-weight: 600; font-size: var(--s-1); line-height: 1;
  padding: 0.6rem 0.9rem; border-radius: var(--r-md);
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); background: var(--sunk); color: var(--ink); }
.btn.primary { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn.primary:hover { background: #4b93e8; }
.btn.danger { color: #f1a3a3; border-color: #5a2a2c; }
.btn.danger:hover { background: #2a1719; }
.btn.link { border: 0; padding: 0.3rem 0.2rem; color: var(--signal-ink); background: none; }
.btn.link:hover { color: var(--ink); text-decoration: underline; }
.btn[disabled] { opacity: 0.5; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

label.field, .field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > span:first-child { font-weight: 600; font-size: var(--s-1); }
.field small, .hint { color: var(--ink-3); font-size: var(--s-1); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=url],
input[type=search], input[type=datetime-local], select, textarea {
  font: inherit; color: var(--ink); background: var(--sunk);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  padding: 0.55rem 0.7rem; width: 100%; min-width: 0;
}
textarea { min-height: 7rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--signal); outline-offset: 0; border-color: transparent; }
input[type=checkbox], input[type=radio] { accent-color: var(--signal); width: 1rem; height: 1rem; margin: 0; }
.check { display: flex; align-items: center; gap: 0.55rem; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem 1.25rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.error-box { border-left: 3px solid var(--crit); background: #241517; padding: 0.6rem 0.8rem; border-radius: var(--r-sm); }
.ok-box { border-left: 3px solid var(--good); background: #13221a; padding: 0.6rem 0.8rem; border-radius: var(--r-sm); }
.inline-num { width: 5rem !important; display: inline-block; padding: 0.3rem 0.5rem !important; text-align: right; }

/* segmented radio */
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line-strong); border-radius: var(--r-md); overflow: hidden; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; padding: 0.5rem 0.9rem; font-size: var(--s-1); font-weight: 600; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--raised); color: var(--ink); box-shadow: inset 0 -2px 0 var(--signal); }
.seg input:focus-visible + span { outline: 2px solid var(--signal); outline-offset: -2px; }

/* ---------- form page ---------- */
.form-page { max-width: 46rem; }
.form-section { padding: 1.5rem 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 1rem; }
.form-section:first-of-type { border-top: 0; }
.form-section > h2 { margin-bottom: 0.1rem; }
.rule-opt { display: flex; gap: 0.7rem; align-items: baseline; padding: 0.7rem 0.8rem; border: 1px solid var(--line); border-radius: var(--r-md); cursor: pointer; }
.rule-opt:has(input:checked) { border-color: var(--signal); background: var(--sunk); }
.rule-opt input[type=radio] { transform: translateY(0.15rem); }
.rule-opt .rule-text { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.pair { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: 0.5rem; }
.choice-list { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; }

/* ---------- page heads ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.75rem; }
.page-head p { margin: 0.4rem 0 0; color: var(--ink-2); }
.crumb { font-size: var(--s-1); color: var(--ink-2); margin-bottom: 0.6rem; display: inline-block; text-decoration: none; }
.crumb:hover { color: var(--ink); }

/* ---------- overview hero ---------- */
.hero { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.25rem; align-items: start; margin: 0.5rem 0 2.25rem; }
.hero-glyph { margin-top: 0.45rem; }
.hero h1 {
  font-size: var(--s4); font-weight: 820; font-stretch: 125%; letter-spacing: -0.025em; line-height: 1.02;
  max-width: 18ch; text-wrap: balance;
}
.hero .sub { margin-top: 0.85rem; color: var(--ink-2); font-size: var(--s1); max-width: 60ch; }
.hero .sub strong { color: var(--ink); font-weight: 600; }
.banner { display: flex; gap: 0.6rem; align-items: baseline; margin-bottom: 1.5rem; }

/* filter row */
.filters { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 0.75rem; }
.filters input[type=search] { width: 15rem; }
.filters select { width: auto; }
.filters .spacer { flex: 1; }

/* ---------- watch list ---------- */
.watch { border-top: 1px solid var(--line); }
.watch-head, .watch-row {
  display: grid;
  grid-template-columns: 8.5rem minmax(10rem, 1.6fr) minmax(0, 1fr) 9.5rem 6.5rem 4.5rem 4.5rem;
  gap: 1rem; align-items: center; padding: 0.65rem 0.5rem;
}
.watch-head { font-size: var(--s-1); color: var(--ink-3); font-weight: 600; border-bottom: 1px solid var(--line); }
.watch-head .r, .watch-row .r { text-align: right; }
.watch-row { border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.watch-row:hover { background: var(--sunk); color: inherit; }
.watch-row .name { font-weight: 600; font-stretch: 104%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-row .target { font-size: var(--s-1); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-row .why { font-size: var(--s-1); color: var(--ink-2); margin-top: 0.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-group { padding: 1.4rem 0.5rem 0.4rem; font-size: var(--s-1); color: var(--ink-2); font-weight: 600; border-bottom: 1px solid var(--line); }
.empty { padding: 3rem 0.5rem; color: var(--ink-2); }
.empty h2 { color: var(--ink); margin-bottom: 0.5rem; }
@media (max-width: 1100px) {
  .watch-head { display: none; }
  .watch-row { grid-template-columns: 8rem minmax(0, 1fr) auto; grid-template-areas: "st nm lt" "st tg strip"; row-gap: 0.4rem; }
  .watch-row > :nth-child(1) { grid-area: st; align-self: start; }
  .watch-row > :nth-child(2) { grid-area: nm; }
  .watch-row > :nth-child(3) { grid-area: tg; }
  .watch-row > :nth-child(4) { grid-area: strip; }
  .watch-row > :nth-child(5), .watch-row > :nth-child(7) { display: none; }
  .watch-row > :nth-child(6) { grid-area: lt; }
}
@media (max-width: 560px) {
  .watch-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "nm lt" "st st" "tg strip"; }
}

/* status label */
.status { display: inline-flex; align-items: center; gap: 0.45rem; font-size: var(--s-1); font-weight: 600; white-space: nowrap; }
.status svg { flex: none; }

/* tags */
.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.75rem; color: var(--ink-2); padding: 0.1rem 0.45rem 0.1rem 0.35rem; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.tag i { width: 0.5rem; height: 0.5rem; border-radius: 50%; display: inline-block; }

/* ---------- detail ---------- */
.detail-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem 2rem; align-items: end; margin-bottom: 2rem; }
.detail-head h1 { font-size: clamp(1.9rem, 4vw, 2.9rem); font-weight: 800; font-stretch: 122%; overflow-wrap: anywhere; }
.detail-head .state-line { margin-top: 0.7rem; display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; align-items: baseline; color: var(--ink-2); }
@media (max-width: 760px) { .detail-head { grid-template-columns: minmax(0, 1fr); } }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1.25rem 2rem; padding: 1.25rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 2rem; }
.fact dt { font-size: var(--s-1); color: var(--ink-3); }
.fact dd { margin: 0.15rem 0 0; font-size: var(--s1); font-weight: 600; font-stretch: 106%; }
.fact dd.small { font-size: var(--s0); font-weight: 500; }
.section { margin: 2.5rem 0; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.5rem 1rem; margin-bottom: 0.9rem; }
.section-head p { margin: 0; color: var(--ink-2); font-size: var(--s-1); }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; transition: opacity 0.15s; }
.chart.loading { opacity: 0.45; }
.chart svg { display: block; overflow: visible; }
.chart svg:focus-visible { outline: 2px solid var(--signal); outline-offset: 4px; }
.axis text { fill: var(--ink-3); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.grid line { stroke: var(--line); stroke-width: 1; }
.baseline { stroke: var(--line-strong); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; margin-top: 0.6rem; font-size: var(--s-1); color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.key-line { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.key-box { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 9rem;
  background: var(--raised); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  padding: 0.5rem 0.65rem; font-size: var(--s-1); line-height: 1.35; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.tip .t { color: var(--ink-3); margin-bottom: 0.3rem; }
.tip .row { display: flex; align-items: center; gap: 0.45rem; }
.tip .v { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.tip .l { color: var(--ink-2); }
.no-data { padding: 2.5rem 0; color: var(--ink-3); border: 1px dashed var(--line); border-radius: var(--r-md); text-align: center; }
.scroll-x { overflow-x: auto; padding-bottom: 0.25rem; }
.ranges { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 1.5rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: var(--s-1); }
th { text-align: left; color: var(--ink-3); font-weight: 600; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
td.tnum { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .btn-row { justify-content: flex-end; flex-wrap: nowrap; }
details > summary { cursor: pointer; color: var(--signal-ink); font-size: var(--s-1); margin: 0.6rem 0; }

/* ---------- list pages ---------- */
.list { border-top: 1px solid var(--line); }
.list-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem; align-items: center; padding: 0.9rem 0.25rem; border-bottom: 1px solid var(--line); }
.list-row .title { font-weight: 600; font-stretch: 104%; }
.list-row .meta { font-size: var(--s-1); color: var(--ink-2); margin-top: 0.15rem; overflow-wrap: anywhere; }
@media (max-width: 560px) { .list-row { grid-template-columns: minmax(0, 1fr); } }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card { width: min(25rem, 100%); }
.auth-card .wordmark { font-size: 2.6rem; margin-bottom: 0.4rem; }
.auth-card .lede { color: var(--ink-2); margin-bottom: 1.75rem; }
.auth-card form { display: flex; flex-direction: column; gap: 1rem; }
.auth-card .btn.primary { justify-content: center; padding: 0.75rem; font-size: var(--s0); }
.auth-card .foot { margin-top: 1.25rem; font-size: var(--s-1); }

/* ---------- dialog & toast ---------- */
dialog {
  background: var(--raised); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 10px;
  padding: 0; width: min(34rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem);
}
dialog::backdrop { background: rgba(5, 8, 10, 0.7); }
dialog form { display: flex; flex-direction: column; gap: 1rem; padding: 1.5rem; }
dialog h2 { font-size: var(--s2); font-stretch: 115%; }
dialog .btn-row { justify-content: flex-end; margin-top: 0.5rem; }
dialog .checklist { max-height: 14rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.45rem; padding: 0.6rem; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sunk); }
.toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--ground); font-weight: 600; font-size: var(--s-1);
  padding: 0.65rem 1rem; border-radius: var(--r-md); z-index: 50; max-width: calc(100vw - 2rem);
}
.toast.bad { background: #f1a3a3; color: #2a1112; }
.qr { background: #fff; padding: 0.6rem; border-radius: var(--r-md); width: 12.5rem; height: 12.5rem; }
code.secret { font-size: var(--s-1); letter-spacing: 0.08em; overflow-wrap: anywhere; color: var(--ink); }
