/* Grafana dark, reproduced from its actual token values: the greys are
   #111217 canvas / #181b1f panel / #2c3235 border, text is #ccccdc primary and
   rgba(204,204,220,0.65) secondary, and the series palette is Grafana's classic
   one. Nothing here is loaded from the network — no webfont, no CDN — because a
   dashboard that blocks on a font request is not a fast dashboard. */

:root {
  --canvas: #111217;
  --panel: #181b1f;
  --border: #2c3235;
  --border-weak: #22252b;
  --text: #ccccdc;
  --text-weak: rgba(204, 204, 220, 0.65);
  --text-faint: rgba(204, 204, 220, 0.4);
  --hover: #22252b;
  --blue: #3d71d9;
  --grid: rgba(204, 204, 220, 0.07);

  --c1: #73bf69;
  --c2: #f2cc0c;
  --c3: #8ab8ff;
  --c4: #ff9830;
  --c5: #f2495c;
  --c6: #b877d9;
  --c7: #ffa6b0;
  --c8: #5794f2;

  --font: Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- navbar */

.navbar {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.nav-left { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.nav-logo { display: flex; align-items: center; }
.crumb { color: var(--text); }
.crumb.muted, .crumb-sep { color: var(--text-weak); }
.nav-right { display: flex; align-items: center; gap: 4px; }

.time-picker { position: relative; display: flex; gap: 4px; }

.tbtn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
}
.tbtn:hover { background: var(--hover); border-color: #3f444b; }
.tbtn.icon { padding: 0 7px; }

.time-menu {
  position: absolute;
  right: 0;
  top: 32px;
  width: 200px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 2px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
  padding: 4px 0;
  z-index: 40;
}
.time-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 12px;
  background: none;
  border: 0;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
}
.time-menu button:hover { background: var(--hover); }
.time-menu button.active { color: var(--c4); }

/* ---------------------------------------------------------------- layout */

.dash { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.loading { padding: 40px; color: var(--text-weak); }

.row { display: grid; gap: 8px; }
.row.stats  { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.row.one    { grid-template-columns: 1fr; }
.row.two    { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.row.three  { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.section {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}
.section::after { content: ""; flex: 1; height: 1px; background: var(--border-weak); }

/* ---------------------------------------------------------------- panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-head {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  flex: 0 0 auto;
}
.panel-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panel-desc { color: var(--text-faint); font-size: 11px; margin-left: 8px; white-space: nowrap; }
/* The body is a flex column so a legend takes its own space instead of being
   appended underneath a canvas that already claims the full height -- which
   pushed it out of the panel and into the one below. */
.panel-body {
  flex: 1 1 auto;
  padding: 0 10px 8px;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.panel.tall .panel-body { height: 290px; }
.panel.mid .panel-body  { height: 200px; }
.panel-body > canvas { display: block; width: 100%; flex: 1 1 auto; min-height: 0; }

/* ------------------------------------------------------------ stat panel */

.stat { padding: 2px 10px 12px; }
.stat-value {
  font-size: 34px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}
.stat-sub { color: var(--text-weak); font-size: 12px; margin-top: 3px; }

/* ------------------------------------------------------------- bar gauge */

.bars { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; flex: 1 1 auto; min-height: 0; padding-right: 2px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr auto; align-items: center; gap: 8px; font-size: 12px; }
.bar-label { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: rgba(204, 204, 220, 0.05); height: 16px; border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 2px; }
.bar-value { color: var(--text-weak); font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.bar-row:hover .bar-label { color: #fff; }

/* ----------------------------------------------------------------- table */

table.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
table.tbl th {
  text-align: left;
  color: var(--text-weak);
  font-weight: 500;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
}
table.tbl td { padding: 3px 8px; border-bottom: 1px solid var(--border-weak); font-variant-numeric: tabular-nums; }
table.tbl tr:hover td { background: var(--hover); }
table.tbl td.num { text-align: right; }
table.tbl a { color: var(--c3); text-decoration: none; }
table.tbl a:hover { text-decoration: underline; }
.scroll { overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.skin-thumb {
  width: 20px; height: 20px; vertical-align: middle; margin-right: 6px;
  image-rendering: pixelated;
  background: rgba(204, 204, 220, 0.08);
  border-radius: 2px;
}

/* --------------------------------------------------------------- legends */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding: 4px 2px 0;
  font-size: 12px;
  flex: 0 0 auto;      /* never squeezed, never overflowing into the next panel */
  max-height: 42px;
  overflow-y: auto;
  line-height: 1.35;
}
.legend-item { display: flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text-weak); }
.legend-item.on { color: var(--text); }
.legend-swatch { width: 12px; height: 3px; border-radius: 2px; }

/* --------------------------------------------------------------- tooltip */

.tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: #1f2226;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 6px 8px;
  font-size: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}
.tooltip .tt-title { color: var(--text-weak); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-dot { width: 8px; height: 8px; border-radius: 50%; }
.tooltip .tt-val { margin-left: auto; padding-left: 14px; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ misc */

.footer { color: var(--text-faint); font-size: 11px; padding: 4px 2px 20px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 12px; }
.kv dt { color: var(--text-weak); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.note { color: var(--text-weak); font-size: 12px; line-height: 1.5; }
.note b { color: var(--text); font-weight: 500; }

/* ------------------------------------------------------- pickers/dropdowns */

.picker { position: relative; }
.qstat { color: var(--text-faint); font-size: 11px; margin-left: 12px; font-variant-numeric: tabular-nums; }

.dropdown {
  position: absolute;
  right: 0;
  top: 32px;
  min-width: 130px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 2px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  padding: 4px 0;
  z-index: 40;
}
.dropdown.wide { width: 440px; padding: 12px; }
.dropdown button {
  display: block; width: 100%; text-align: left; padding: 6px 12px;
  background: none; border: 0; color: var(--text);
  font-family: var(--font); font-size: 13px; cursor: pointer;
}
.dropdown button:hover { background: var(--hover); }
.dropdown button.active { color: var(--c4); }

.dd-cols { display: grid; grid-template-columns: 1fr 160px; gap: 16px; }
.dd-head { font-size: 12px; color: var(--text-weak); margin-bottom: 8px; }
.dd-field { display: block; margin-bottom: 8px; font-size: 12px; color: var(--text-weak); }
.dd-field span { display: block; margin-bottom: 3px; }
.dd-field input {
  width: 100%; height: 30px; padding: 0 8px;
  background: var(--canvas); border: 1px solid var(--border); border-radius: 2px;
  color: var(--text); font-family: var(--font); font-size: 13px;
}
.dd-field input:focus { outline: none; border-color: var(--blue); }
.btn-primary {
  width: 100%; height: 30px; margin-top: 2px;
  background: var(--blue); border: 0; border-radius: 2px;
  color: #fff; font-family: var(--font); font-size: 13px; cursor: pointer;
}
.btn-primary:hover { background: #4c7fe0; }
.dd-hint { color: var(--text-faint); font-size: 11px; margin-top: 8px; line-height: 1.4; }
.quick { max-height: 220px; overflow-y: auto; }
.quick button { padding: 5px 10px; font-size: 12px; }

.panel-body canvas { cursor: crosshair; }

/* ---------------------------------------------------------------- responsive
   The desktop grid uses minmax(420px) / minmax(300px) tracks, which on a phone
   are wider than the viewport — the page scrolled sideways and every panel was
   clipped. Below these breakpoints the rows collapse to one column and the
   chrome shrinks with them. */

.panel-body > canvas { touch-action: pan-y; }   /* vertical swipe scrolls, horizontal drag zooms */

@media (max-width: 1100px) {
  .row.three { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}

@media (max-width: 820px) {
  .row.two, .row.three { grid-template-columns: 1fr; }
  .row.stats { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .stat-value { font-size: 26px; }
}

@media (max-width: 700px) {
  body { font-size: 13px; }
  .dash { padding: 6px; gap: 6px; }
  .row { gap: 6px; }

  /* Two rows of chrome beat one row that overflows. */
  .navbar {
    height: auto;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 8px;
    position: static;          /* a sticky two-line bar eats too much of a short screen */
  }
  .nav-left { flex: 1 1 100%; font-size: 13px; }
  .nav-right { flex: 1 1 100%; justify-content: space-between; }
  .crumb.muted, .crumb-sep { display: none; }
  .qstat { margin-left: 0; flex-basis: 100%; }

  .tbtn { height: 32px; padding: 0 8px; font-size: 12px; }   /* 32px: touch target */
  #timeLabel { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* A fixed 440px dropdown is wider than the screen. */
  .dropdown { position: fixed; left: 6px; right: 6px; top: auto; width: auto; max-height: 70vh; overflow-y: auto; }
  .dropdown.wide { width: auto; }
  .dd-cols { grid-template-columns: 1fr; gap: 10px; }
  .dd-field input, .btn-primary { height: 36px; }

  .panel.tall .panel-body { height: 230px; }
  .panel.mid .panel-body { height: 190px; }
  .panel-head { height: auto; min-height: 28px; padding: 4px 8px; flex-wrap: wrap; }
  .panel-title { white-space: normal; font-size: 12px; line-height: 1.3; }
  .panel-desc { margin-left: 0; }
  .panel-body { padding: 0 8px 6px; }

  /* Wide tables scroll inside their panel instead of stretching the page. */
  .scroll { overflow-x: auto; }
  table.tbl { font-size: 11px; }
  table.tbl th, table.tbl td { padding: 3px 6px; white-space: nowrap; }

  .bar-row { grid-template-columns: 82px 1fr auto; gap: 6px; font-size: 11px; }
  .bar-value { min-width: 48px; }
  .legend { font-size: 11px; max-height: 54px; }

  .tooltip { max-width: 80vw; white-space: normal; }
}

@media (max-width: 420px) {
  .row.stats { grid-template-columns: repeat(2, 1fr); }
  .bar-row { grid-template-columns: 70px 1fr auto; }
  .panel.tall .panel-body { height: 200px; }
}

/* Caveat line under a table title, for panels whose numbers need context. */
.panel-note {
  color: var(--text-weak);
  font-size: 11px;
  line-height: 1.45;
  padding: 0 0 6px;
  max-width: 78ch;
}
