/* Bonding dashboard. Colours are roles; the dark values are the default, light is opt-in. */
:root {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, .10); --border-strong: rgba(255, 255, 255, .18);
  --text: #f0efec; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
  --accent: #3987e5; --accent-track: rgba(57, 135, 229, .22); --on-accent: #ffffff;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .35);
  --radius: 12px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f4f3ef; --surface: #fcfcfb; --surface-2: #f3f2ee; --surface-3: #e9e8e2;
  --border: rgba(11, 11, 11, .10); --border-strong: rgba(11, 11, 11, .20);
  --text: #0b0b0b; --text-2: #52514e; --muted: #77756f; --grid: #e1e0d9; --axis: #c3c2b7;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --accent: #2a78d6; --accent-track: rgba(42, 120, 214, .18);
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 6px 18px rgba(11, 11, 11, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3, p { margin: 0; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
h3 { font-size: 14px; font-weight: 600; }
button, select, input { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sec { color: var(--text-2); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ header */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 20px; background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; letter-spacing: .01em; }
.brand svg { width: 26px; height: 26px; }
.health {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px 5px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-weight: 600;
}
.top-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; }
.top-actions { display: flex; gap: 8px; align-items: center; position: relative; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.ico {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; flex: none;
  font-size: 10px; font-weight: 800; line-height: 1; color: #fff; background: var(--muted);
}
.ico.good { background: var(--good); }
.ico.warn { background: var(--warn); color: #0b0b0b; }
.ico.bad { background: var(--crit); }
.ico.info { background: var(--accent); }
.ico.idle { background: var(--surface-3); color: var(--text-2); }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border-strong); color: var(--text-2);
}
.tag.master { border-color: var(--accent); color: var(--text); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); font-weight: 550;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:focus-visible, select:focus-visible, input:focus-visible, .chart-plot:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.ghost { background: transparent; }
select.sel {
  padding: 4px 8px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface-2); cursor: pointer;
}
select.sel:disabled { opacity: .45; cursor: not-allowed; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; padding: 6px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow); display: grid; gap: 2px;
}
.menu button { text-align: left; padding: 8px 10px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; }
.menu button:hover { background: var(--surface-3); }

/* ------------------------------------------------------------------ layout */
main { max-width: 1480px; margin: 0 auto; padding: 18px 20px 60px; display: grid; gap: 18px; }
section { display: grid; gap: 10px; min-width: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.card > h3 { margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.banner {
  display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--crit); background: color-mix(in srgb, var(--crit) 12%, var(--surface));
}
.stale .live { opacity: .5; }

/* -------------------------------------------------------------------- path */
.path { display: flex; align-items: stretch; gap: 0; overflow-x: auto; padding: 18px 16px; }
.node {
  flex: 1 1 0; min-width: 130px; display: grid; gap: 4px; align-content: center; justify-items: center; text-align: center;
  padding: 12px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border);
}
.node .glyph { width: 28px; height: 28px; color: var(--text-2); }
.node .t { font-weight: 600; }
.node .s { color: var(--text-2); font-size: 12.5px; }
.node.wans { flex: 1.7 1 0; min-width: 230px; justify-items: stretch; text-align: left; gap: 6px; }
.wan-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.wan-row .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.wan-row .rt { color: var(--text-2); font-size: 12.5px; }
.hop { flex: 0 0 34px; align-self: center; height: 3px; border-radius: 2px; background: var(--surface-3); position: relative; }
.hop.good { background: var(--good); }
.hop.bad { background: var(--crit); }
.hop.bad::after {
  content: "✕"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center;
  background: var(--crit); color: #fff; font-size: 10px; font-weight: 800;
}
.key { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--muted); }
.key.line { width: 14px; height: 3px; border-radius: 2px; }

/* ------------------------------------------------------------------- tiles */
.tiles { grid-template-columns: 1.5fr 1.1fr .8fr .9fr 1.5fr 1.5fr; gap: 18px; }
.tile { display: grid; gap: 6px; align-content: start; }
.tile .label { color: var(--text-2); font-weight: 550; }
.tile .value { font-size: 30px; font-weight: 650; line-height: 1.1; letter-spacing: -.01em; }
.tile.hero .value { font-size: 52px; }
.tile .unit { font-size: 15px; font-weight: 550; color: var(--text-2); margin-left: 6px; letter-spacing: 0; }
.tile .sub { color: var(--text-2); font-size: 12.5px; }
.spark { width: 100%; height: 40px; display: block; }
.rings { display: flex; gap: 14px; justify-content: space-between; }
.ring { display: grid; justify-items: center; gap: 2px; flex: 1; }
.ring svg { width: 68px; height: 68px; }
.ring .rl { color: var(--text-2); font-size: 12.5px; }
.ring-track { fill: none; stroke: var(--accent-track); stroke-width: 6; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset .5s; }
.ring-fill.warn { stroke: var(--warn); }
.ring-fill.bad { stroke: var(--crit); }
.ring-text { fill: var(--text); font-size: 15px; font-weight: 650; text-anchor: middle; dominant-baseline: central; }

/* --------------------------------------------------------------- wan cards */
.wan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 18px; }
.wan { display: grid; gap: 12px; }
.wan-head { display: flex; align-items: center; gap: 10px; }
.wan-head .ttl { font-weight: 650; font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wan-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.wan-rates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rate .l { color: var(--text-2); font-size: 12.5px; }
.rate .v { font-size: 24px; font-weight: 650; line-height: 1.15; }
.rate .u { font-size: 13px; color: var(--text-2); margin-left: 4px; font-weight: 550; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; }
.kv > div { min-width: 0; }
.kv .span2 { grid-column: span 2; }
.kv .span3 { grid-column: 1 / -1; }
.kv .span3 .v { white-space: normal; }
.kv .l { color: var(--muted); font-size: 12px; }
.kv .v { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wan-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 12px; }
.wan-actions label { color: var(--text-2); }

/* ------------------------------------------------------------------ charts */
.range { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.range button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 550; }
.range button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.chart-grid.loading .chart-plot { opacity: .55; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head .u { color: var(--muted); font-weight: 400; margin-left: 6px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--text-2); font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-plot { display: block; width: 100%; border-radius: 6px; }
.chart-plot svg { display: block; width: 100%; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { stroke: var(--surface); stroke-width: 2; }
.cross { stroke: var(--axis); stroke-width: 1; }
.empty { fill: var(--muted); font-size: 13px; text-anchor: middle; }
.c0 { stroke: var(--muted); } .c1 { stroke: var(--s1); } .c2 { stroke: var(--s2); } .c3 { stroke: var(--s3); } .c4 { stroke: var(--s4); }
.c5 { stroke: var(--s5); } .c6 { stroke: var(--s6); } .c7 { stroke: var(--s7); } .c8 { stroke: var(--s8); }
.f0 { fill: var(--muted); } .f1 { fill: var(--s1); } .f2 { fill: var(--s2); } .f3 { fill: var(--s3); } .f4 { fill: var(--s4); }
.f5 { fill: var(--s5); } .f6 { fill: var(--s6); } .f7 { fill: var(--s7); } .f8 { fill: var(--s8); }
.b0 { background: var(--muted); } .b1 { background: var(--s1); } .b2 { background: var(--s2); } .b3 { background: var(--s3); } .b4 { background: var(--s4); }
.b5 { background: var(--s5); } .b6 { background: var(--s6); } .b7 { background: var(--s7); } .b8 { background: var(--s8); }
.area { stroke: none; opacity: .10; }
details.tbl { margin-top: 8px; }
details.tbl summary { cursor: pointer; color: var(--text-2); font-size: 12.5px; width: fit-content; border-radius: 4px; }
.scroll { overflow: auto; max-height: 280px; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; min-width: 150px; padding: 8px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-size: 12.5px;
}
.tooltip .th { color: var(--text-2); margin-bottom: 4px; }
.tooltip .tr { display: grid; grid-template-columns: auto auto 1fr; gap: 8px; align-items: center; }
.tooltip .tr b { font-variant-numeric: tabular-nums; }
.tooltip .tr span:last-child { color: var(--text-2); }

/* ------------------------------------------------------------------ tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 550; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.rows { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.rows dt { color: var(--muted); }
.rows dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.svc { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.sub-h { margin: 14px 0 8px; color: var(--text-2); font-weight: 600; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.events { display: grid; gap: 0; max-height: 420px; overflow: auto; }
.ev { display: grid; grid-template-columns: auto auto 1fr; gap: 10px; padding: 8px 2px; border-bottom: 1px solid var(--border); align-items: start; }
.ev:last-child { border-bottom: 0; }
.ev time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12.5px; padding-top: 1px; }
.none { color: var(--muted); padding: 6px 0; }

/* ----------------------------------------------------------------- dialogs */
dialog {
  border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 20px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h3 { font-size: 17px; margin-bottom: 8px; }
dialog p { color: var(--text-2); margin-bottom: 14px; }
dialog .field { display: grid; gap: 4px; margin-bottom: 12px; }
dialog .field span { color: var(--text-2); font-size: 13px; }
dialog input[type="text"], dialog input[type="password"], .login input {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface-2);
}
dialog .opts { display: grid; gap: 8px; margin-bottom: 14px; }
dialog .opts label { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.err { color: var(--text); background: color-mix(in srgb, var(--crit) 16%, var(--surface)); border: 1px solid var(--crit); border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; padding: 10px 16px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* ------------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(380px, 100%); display: grid; gap: 14px; }
.login .brand { justify-content: center; font-size: 18px; margin-bottom: 4px; }
.login label { display: grid; gap: 5px; color: var(--text-2); font-size: 13px; }
.login .btn { justify-content: center; padding: 10px; }
.login .hint { color: var(--muted); font-size: 12.5px; text-align: center; }

/* -------------------------------------------------------------- responsive */
@media (max-width: 1250px) {
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tiles .tile.hero { grid-column: span 2; }
  .tiles .tile.wide { grid-column: span 2; }
}
@media (max-width: 900px) {
  .two, .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-meta { margin-left: 0; order: 3; width: 100%; }
  .top-actions { margin-left: auto; }
}
@media (max-width: 560px) {
  main { padding: 14px 16px 50px; }
  .top { padding: 10px 16px; }
  .tiles { grid-template-columns: minmax(0, 1fr); }
  .tiles .tile.hero, .tiles .tile.wide { grid-column: auto; }
  .tile.hero .value { font-size: 44px; }
  .wan-grid { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .kv .span2 { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { .ring-fill { transition: none; } }
