/*
 * NetworkDiscovery UI.
 *
 * Colour roles come from the validated reference palette. The eight
 * categorical slots are only ever used where a text label sits beside the
 * swatch; the graph itself is deliberately neutral, because a node-link
 * diagram compares every colour against every other and eight hues cannot
 * clear that bar (red and orange in particular).
 */

:root {
  color-scheme: light;

  --surface-0: #f6f5f2;
  --surface-1: #fcfcfb;
  --surface-2: #efeeea;
  --border:    #dcdad4;
  --border-strong: #c3c0b8;

  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #75736d;

  --series-1: #2a78d6;

  --cat-1: #2a78d6; /* database */
  --cat-2: #eb6834; /* cache */
  --cat-3: #1baf7a; /* web */
  --cat-4: #eda100; /* voip */
  --cat-5: #e87ba4; /* queue */
  --cat-6: #008300; /* mail */
  --cat-7: #4a3aa7; /* monitoring */
  --cat-8: #e34948; /* remote */
  --cat-other: #8a8880;

  --good:     #008300;
  --warning:  #eda100;
  --critical: #e34948;

  --graph-edge: #b4b1a9;
  --graph-node: #6d6b64;

  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;

    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border:    #35342f;
    --border-strong: #4b4a44;

    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #94928a;

    --series-1: #3987e5;

    --cat-1: #3987e5;
    --cat-2: #d95926;
    --cat-3: #199e70;
    --cat-4: #c98500;
    --cat-5: #d55181;
    --cat-6: #008300;
    --cat-7: #9085e9;
    --cat-8: #e66767;
    --cat-other: #8a8880;

    --graph-edge: #4f4e48;
    --graph-node: #9a978e;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border:    #35342f;
  --border-strong: #4b4a44;

  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #94928a;

  --series-1: #3987e5;

  --cat-1: #3987e5;
  --cat-2: #d95926;
  --cat-3: #199e70;
  --cat-4: #c98500;
  --cat-5: #d55181;
  --cat-6: #008300;
  --cat-7: #9085e9;
  --cat-8: #e66767;
  --cat-other: #8a8880;

  --graph-edge: #4f4e48;
  --graph-node: #9a978e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--surface-0);
}

a { color: var(--series-1); }
a:hover { text-decoration: underline; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: -999px; top: 0; padding: 8px 12px;
  background: var(--surface-1); z-index: 10;
}
.skip:focus { left: 8px; }

/* ---------- chrome ---------- */

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 16px; height: 52px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
  flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 650; color: var(--text-primary); text-decoration: none;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a {
  padding: 6px 10px; border-radius: var(--radius);
  color: var(--text-secondary); text-decoration: none; font-weight: 500;
}
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; }
.topbar nav a[aria-current="page"] { background: var(--surface-2); color: var(--text-primary); }
.topbar-right { display: flex; align-items: center; gap: 8px; }

select, input[type="search"], input[type="text"], button {
  font: inherit; color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 5px 9px;
}
button { cursor: pointer; }
button:hover { background: var(--surface-2); }
.theme-toggle { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; color: var(--text-secondary); }

main { padding: 20px 16px 40px; max-width: 1400px; margin: 0 auto; }

.foot {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 1400px; margin: 0 auto; padding: 16px;
  color: var(--text-muted); font-size: 12px;
  border-top: 1px solid var(--border);
}

/* ---------- headings & cards ---------- */

h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: -0.005em; }
.page-head { margin-bottom: 16px; }
.page-head p { margin: 0; color: var(--text-secondary); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .hint { color: var(--text-muted); font-size: 12px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

/* ---------- stat tiles ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.tile .label { color: var(--text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.tile .value { font-size: 26px; font-weight: 600; line-height: 1.2; margin-top: 2px; letter-spacing: -0.02em; }
.tile .sub { color: var(--text-muted); font-size: 12px; }

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

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--text-muted); }

/* ---------- chips ---------- */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 1px 8px 1px 6px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary); white-space: nowrap;
}
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cat-other); flex: none; }
.cat-1 .chip-dot { background: var(--cat-1); }
.cat-2 .chip-dot { background: var(--cat-2); }
.cat-3 .chip-dot { background: var(--cat-3); }
.cat-4 .chip-dot { background: var(--cat-4); }
.cat-5 .chip-dot { background: var(--cat-5); }
.cat-6 .chip-dot { background: var(--cat-6); }
.cat-7 .chip-dot { background: var(--cat-7); }
.cat-8 .chip-dot { background: var(--cat-8); }

.pill { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border-strong); color: var(--text-secondary); }
.pill.good { color: var(--good); border-color: var(--good); }
.pill.warn { color: var(--warning); border-color: var(--warning); }
.pill.bad  { color: var(--critical); border-color: var(--critical); }

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

.chart { width: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; font-family: var(--sans); }
.chart .area { fill: var(--series-1); opacity: 0.14; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .marker { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 20;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 7px 10px; font-size: 12px; line-height: 1.45;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.14);
  max-width: 280px; opacity: 0; transition: opacity .08s;
}
.tooltip[data-show] { opacity: 1; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
.tooltip .tt-row { color: var(--text-secondary); }

/* ---------- graph ---------- */

.graph-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 16px; align-items: start; }
.graph-frame { position: relative; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); }
#graph { width: 100%; height: 640px; display: block; touch-action: none; }
#graph .edge { stroke: var(--graph-edge); stroke-width: 1.5; fill: none; }
#graph .edge.hot { stroke: var(--series-1); stroke-width: 2.5; }
#graph .edge.dim { opacity: 0.15; }
#graph .edge-label { fill: var(--text-muted); font-size: 10px; font-family: var(--mono); pointer-events: none; }
#graph .edge-label.hot { fill: var(--text-primary); }
#graph .node circle { fill: var(--surface-1); stroke: var(--graph-node); stroke-width: 2; }
#graph .node.agent circle { stroke: var(--series-1); stroke-width: 2.5; }
#graph .node.dim { opacity: 0.2; }
#graph .node text { fill: var(--text-secondary); font-size: 11px; font-family: var(--sans); pointer-events: none; }
#graph .node.hot text { fill: var(--text-primary); font-weight: 600; }
#graph .node { cursor: grab; }
#graph .node:active { cursor: grabbing; }

.graph-side .legend { display: grid; gap: 7px; }
.legend-item { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 12px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--graph-node); background: var(--surface-1); flex: none; }
.legend-swatch.agent { border-color: var(--series-1); }
.legend-line { width: 16px; height: 0; border-top: 2px solid var(--graph-edge); flex: none; }
.legend-line.hot { border-color: var(--series-1); }

.graph-controls { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.graph-empty { display: grid; place-items: center; height: 640px; color: var(--text-muted); text-align: center; padding: 20px; }

.empty-page { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.empty { color: var(--text-muted); padding: 12px 0; }

.bar { height: 6px; border-radius: 3px; background: var(--series-1); min-width: 2px; }
.bar-cell { width: 120px; }
.bar-track { background: var(--surface-2); border-radius: 3px; }

@media (max-width: 900px) {
  .graph-layout { grid-template-columns: 1fr; }
  #graph { height: 460px; }
}
