/* Latency tab (latency-app.js). Self-contained; uses the dashboard's font and base colours. */

/* Variables live on :root because the drawer, popover and tooltip are attached to <body>. */
:root {
  --lt-ink: #152535;
  --lt-text: #2b4058;
  --lt-muted: #6d7884;
  --lt-line: #e3e9ef;
  --lt-soft: #f5f8fb;
  --lt-blue: #1f5e9c;
  --lt-green: #2f8a66;
  --lt-amber: #c9861a;
  --lt-red: #c64b5b;
  --lt-radius: 12px;
}
.lt-root, .lt-drawer, .lt-popover { font-variant-numeric: tabular-nums; }
.lt-root {
  color: var(--lt-text);
  display: grid;
  gap: 14px;
  font-variant-numeric: tabular-nums;
}

.lt-root button, .lt-root input, .lt-root select { font: inherit; }

/* toolbar ------------------------------------------------------------------------------------ */
.lt-toolbar {
  align-items: end;
  background: #fff;
  border: 1px solid var(--lt-line);
  border-radius: var(--lt-radius);
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  justify-content: space-between;
  padding: 12px 14px;
  position: sticky;
  top: 8px;
  z-index: 5;
  box-shadow: 0 6px 18px rgba(21, 37, 53, 0.05);
}
.lt-toolbar-fields { align-items: end; display: flex; flex-wrap: wrap; gap: 10px 14px; }
.lt-field { display: inline-flex; flex-direction: column; gap: 4px; }
.lt-field-label { color: var(--lt-muted); font-size: .7rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.lt-select, .lt-input-unit, .lt-search {
  background: #fff;
  border: 1px solid #d5dee8;
  border-radius: 8px;
  color: var(--lt-ink);
  height: 34px;
  padding: 0 10px;
}
.lt-select { cursor: pointer; padding-right: 6px; }
.lt-select:focus, .lt-input-unit:focus-within, .lt-search:focus { border-color: var(--lt-blue); outline: 2px solid rgba(31, 94, 156, .15); }
.lt-input-unit { align-items: center; display: inline-flex; gap: 4px; }
.lt-input-unit input { background: transparent; border: 0; color: var(--lt-ink); height: 100%; outline: none; padding: 0; text-align: right; }
.lt-input-unit em { color: var(--lt-muted); font-style: normal; }
.lt-search { min-width: 180px; }

.lt-segmented { background: var(--lt-soft); border: 1px solid var(--lt-line); border-radius: 9px; display: inline-flex; padding: 3px; }
.lt-segmented button { background: transparent; border: 0; border-radius: 7px; color: var(--lt-muted); cursor: pointer; font-weight: 600; padding: 6px 12px; }
.lt-segmented button.active { background: #fff; box-shadow: 0 1px 3px rgba(21, 37, 53, .12); color: var(--lt-ink); }
.lt-segmented.small button { font-size: .8rem; padding: 4px 10px; }

.lt-icon-button { background: var(--lt-soft); border: 1px solid #d5dee8; border-radius: 8px; color: var(--lt-text); cursor: pointer; font-size: 1rem; height: 34px; width: 34px; }
.lt-popover { background: #fff; border: 1px solid var(--lt-line); border-radius: var(--lt-radius); box-shadow: 0 16px 40px rgba(21, 37, 53, .16); display: grid; gap: 10px; max-width: 320px; padding: 14px; position: absolute; z-index: 30; }
.lt-popover h4 { color: var(--lt-ink); margin: 0; }
.lt-popover-actions { align-items: center; display: flex; justify-content: space-between; }

.lt-tabs { border-bottom: 1px solid var(--lt-line); display: flex; flex-wrap: wrap; gap: 4px; }
.lt-tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--lt-muted); cursor: pointer; font-weight: 600; margin-bottom: -1px; padding: 10px 14px; }
.lt-tabs button:hover { color: var(--lt-ink); }
.lt-tabs button.active { border-bottom-color: var(--lt-blue); color: var(--lt-blue); }

.lt-view { display: grid; gap: 14px; }
.lt-view > * { min-width: 0; }
.lt-banner { background: #fff7e8; border: 1px solid #f0d39d; border-radius: 10px; color: #7a5410; padding: 10px 14px; }
.lt-subhead { border-top: 1px solid var(--lt-line); color: var(--lt-ink); font-size: 1.1rem; margin: 8px 0 0; padding-top: 16px; }

/* tiles -------------------------------------------------------------------------------------- */
.lt-tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.lt-tile { background: #fff; border: 1px solid var(--lt-line); border-left: 4px solid var(--lt-line); border-radius: var(--lt-radius); display: grid; gap: 4px; padding: 14px 14px 10px; }
.lt-tile.clickable { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.lt-tile.clickable:hover { box-shadow: 0 8px 20px rgba(21, 37, 53, .08); transform: translateY(-1px); }
.lt-tile.tone-good { border-left-color: var(--lt-green); }
.lt-tile.tone-warn { border-left-color: var(--lt-amber); }
.lt-tile.tone-bad { border-left-color: var(--lt-red); }
.lt-tile-label { align-items: center; color: var(--lt-muted); display: flex; font-size: .72rem; font-weight: 600; gap: 6px; letter-spacing: .04em; margin: 0; text-transform: uppercase; }
.lt-tile-value { align-items: baseline; color: var(--lt-ink); display: flex; flex-wrap: wrap; font-size: 1.65rem; font-weight: 600; gap: 8px; margin: 2px 0 0; }
.lt-tile-sub { color: var(--lt-muted); font-size: .78rem; line-height: 1.4; margin: 0; }
.lt-help { border: 1px solid #b8c4d0; border-radius: 50%; cursor: help; display: inline-grid; font-size: .62rem; height: 14px; place-items: center; width: 14px; }
.lt-delta { border-radius: 999px; font-size: .72rem; font-weight: 600; padding: 2px 7px; }
.lt-delta.good { background: #e6f4ee; color: #1f7352; }
.lt-delta.bad { background: #fbe9ec; color: #a63446; }
.lt-delta.neutral { background: var(--lt-soft); color: var(--lt-muted); }
.lt-spark-wrap { height: 28px; margin-top: 4px; }
.lt-spark { display: block; height: 28px; width: 100%; }

/* cards ---------------------------------------------------------------------------------------- */
.lt-card { background: #fff; border: 1px solid var(--lt-line); border-radius: var(--lt-radius); min-width: 0; padding: 14px 16px; }
.lt-card-head { align-items: flex-start; display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; margin-bottom: 10px; }
.lt-card-head h3 { color: var(--lt-ink); font-size: .98rem; margin: 0; }
.lt-card-sub { color: var(--lt-muted); font-size: .8rem; line-height: 1.45; margin: 3px 0 0; max-width: 560px; }
.lt-card-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; }
.lt-grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.lt-row { align-items: end; display: flex; flex-wrap: wrap; gap: 10px 14px; }
.lt-hint { color: var(--lt-muted); font-size: .76rem; margin: 6px 0 0; }
.lt-muted { color: var(--lt-muted); }
.lt-strong { color: var(--lt-ink); font-weight: 600; }
.lt-empty { color: var(--lt-muted); margin: 12px 0; text-align: center; }
.lt-link-button { background: none; border: 0; color: var(--lt-blue); cursor: pointer; font-weight: 600; padding: 4px 2px; }
.lt-link-button:hover { text-decoration: underline; }
.lt-button { background: var(--lt-blue); border: 0; border-radius: 8px; color: #fff; cursor: pointer; display: inline-block; font-weight: 600; padding: 8px 14px; text-decoration: none; }
.lt-link { color: var(--lt-blue); font-weight: 600; text-decoration: none; }
.lt-link:hover { text-decoration: underline; }
.lt-copy { background: var(--lt-soft); border: 1px solid var(--lt-line); border-radius: 6px; color: var(--lt-text); cursor: copy; font-family: ui-monospace, monospace; font-size: .75rem; padding: 2px 6px; }

.lt-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.lt-legend-item { align-items: center; color: var(--lt-muted); display: inline-flex; font-size: .76rem; gap: 6px; }
.lt-legend-item i { border-radius: 3px; display: inline-block; height: 10px; width: 10px; }

.lt-loading { align-items: center; color: var(--lt-muted); display: flex; gap: 10px; justify-content: center; padding: 28px; }
.lt-spinner { animation: lt-spin .8s linear infinite; border: 2px solid #d5dee8; border-radius: 50%; border-top-color: var(--lt-blue); height: 16px; width: 16px; }
@keyframes lt-spin { to { transform: rotate(360deg); } }

/* charts --------------------------------------------------------------------------------------- */
.lt-svg svg { display: block; height: auto; width: 100%; }
.lt-svg .grid { stroke: #edf1f5; }
.lt-svg .axis { fill: #7b8896; font-size: 11px; }
.lt-svg .target { stroke: var(--lt-red); stroke-dasharray: 5 4; stroke-width: 1.3; }
.lt-svg .target-label { fill: var(--lt-red); font-size: 11px; font-weight: 600; }
.lt-svg .cursor { stroke: #a8b5c2; stroke-dasharray: 3 3; }
.lt-line-chart.clickable .hit, .lt-histogram.clickable rect[data-index], .lt-heatmap.clickable rect[data-key] { cursor: pointer; }
.lt-histogram rect[data-index]:hover, .lt-heatmap rect[data-key]:hover { opacity: .8; }
.lt-heat-scale { align-items: center; color: var(--lt-muted); display: flex; flex-wrap: wrap; font-size: .74rem; gap: 8px; margin-top: 6px; }
.lt-heat-scale i { background: linear-gradient(90deg, rgb(234, 242, 250), rgb(31, 94, 156)); border-radius: 3px; display: inline-block; height: 8px; width: 90px; }
.lt-heat-over { margin-left: auto; }

.lt-tooltip { background: #172a3d; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); color: #fff; font-size: .76rem; line-height: 1.55; max-width: 280px; padding: 8px 11px; pointer-events: none; position: fixed; z-index: 60; }
.lt-tooltip em { color: #aac3dc; font-style: normal; }
.lt-tooltip .lt-muted { color: #aab7c4; }
.lt-swatch { border-radius: 2px; display: inline-block; height: 8px; margin-right: 5px; width: 8px; }

.lt-hbars { display: grid; gap: 8px; }
.lt-hbar { align-items: center; border-radius: 8px; display: grid; gap: 12px; grid-template-columns: minmax(110px, 190px) 1fr minmax(84px, auto); padding: 3px 6px; }
.lt-hbar.clickable { cursor: pointer; }
.lt-hbar.clickable:hover, .lt-hbar.active { background: var(--lt-soft); }
.lt-hbar-label { color: var(--lt-ink); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lt-hbar-track { background: #f1f4f7; border-radius: 5px; display: flex; height: 16px; position: relative; }
.lt-hbar-fill { border-radius: 5px; display: block; height: 100%; }
.lt-hbar-whisker { border-top: 2px solid #8fa4b8; position: absolute; top: 7px; }
.lt-hbar-target { border-left: 2px dashed var(--lt-red); bottom: -3px; position: absolute; top: -3px; }
.lt-hbar-seg { display: block; height: 100%; }
.lt-hbar-seg:first-child { border-radius: 5px 0 0 5px; }
.lt-hbar-seg:last-child { border-radius: 0 5px 5px 0; }
.lt-hbar-value { color: var(--lt-ink); font-size: .84rem; font-weight: 600; text-align: right; }
.lt-hbar-value small { color: var(--lt-muted); display: block; font-size: .72rem; font-weight: 400; }

.lt-waterfall .label { fill: var(--lt-text); font-size: 12px; }
.lt-waterfall .label.strong { fill: var(--lt-ink); font-weight: 600; }
.lt-waterfall .value { fill: var(--lt-muted); font-size: 11px; }
.lt-waterfall .marker { stroke-dasharray: 4 3; stroke-width: 1.5; }
.lt-waterfall .marker-label { font-size: 11px; font-weight: 600; }
.lt-waterfall g.clickable { cursor: pointer; }
.lt-waterfall g.row:hover rect { filter: brightness(.94); }

.lt-highlights { display: grid; gap: 8px; list-style: none; margin: 0; padding: 0; }
.lt-highlights li { align-items: center; background: var(--lt-soft); border-left: 3px solid #9aa9b8; border-radius: 6px; display: flex; gap: 12px; justify-content: space-between; padding: 8px 12px; }
.lt-highlights li.bad { border-left-color: var(--lt-red); }
.lt-highlights li.warn { border-left-color: var(--lt-amber); }
.lt-highlights li.good { border-left-color: var(--lt-green); }
.lt-highlights .lt-link-button { flex-shrink: 0; }

/* agents --------------------------------------------------------------------------------------- */
.lt-agent-strip { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); }
.lt-agent-strip button { background: #fff; border: 1px solid var(--lt-line); border-radius: 10px; cursor: pointer; display: grid; gap: 2px; padding: 10px 12px; text-align: left; }
.lt-agent-strip button:hover { border-color: #b9c9d9; }
.lt-agent-strip button.active { border-color: var(--lt-blue); box-shadow: inset 0 0 0 1px var(--lt-blue); }
.lt-agent-name { color: var(--lt-muted); font-size: .76rem; font-weight: 600; }
.lt-agent-value { color: var(--lt-ink); font-size: 1.15rem; font-weight: 600; }
.lt-agent-meta { color: var(--lt-muted); font-size: .72rem; }
.lt-dot-bad { color: var(--lt-red); font-weight: 600; }

/* tables --------------------------------------------------------------------------------------- */
.lt-table-wrap { overflow-x: auto; }
.lt-table { border-collapse: collapse; font-size: .84rem; width: 100%; }
.lt-table th, .lt-table td { border-bottom: 1px solid #eef2f5; padding: 9px 10px; text-align: left; white-space: nowrap; }
.lt-table th { color: var(--lt-muted); font-size: .7rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }
.lt-table th.sortable { cursor: pointer; user-select: none; }
.lt-table th.sortable:hover { color: var(--lt-ink); }
.lt-table .num { text-align: right; }
.lt-table tr.clickable { cursor: pointer; }
.lt-table tr.clickable:hover td { background: #f6f9fc; }
.lt-tree td:first-child { color: var(--lt-text); }
.lt-caret { background: none; border: 0; color: var(--lt-blue); cursor: pointer; padding: 0 6px 0 0; width: 20px; }
.lt-caret-space { display: inline-block; width: 20px; }
.lt-box { display: inline-block; height: 12px; position: relative; vertical-align: middle; width: 140px; }
.lt-box::before { background: #eef2f5; content: ""; height: 2px; left: 0; position: absolute; right: 0; top: 5px; }
.lt-box-body { background: rgba(31, 94, 156, .28); border: 1px solid rgba(31, 94, 156, .55); border-radius: 3px; height: 10px; position: absolute; top: 0; }
.lt-box-whisker { border-top: 2px solid #9fb2c5; position: absolute; top: 5px; }
.lt-box-median { background: var(--lt-blue); height: 12px; position: absolute; top: -1px; width: 2px; }
.lt-pill { border-radius: 999px; display: inline-block; font-weight: 600; padding: 2px 8px; }
.lt-pill.good { background: #e6f4ee; color: #1f7352; }
.lt-pill.warn { background: #fdf3e2; color: #8a5b0e; }
.lt-pill.bad { background: #fbe9ec; color: #a63446; }
.lt-pager { align-items: center; color: var(--lt-muted); display: flex; font-size: .8rem; gap: 12px; justify-content: flex-end; margin-top: 10px; }
.lt-pager button { background: var(--lt-soft); border: 1px solid var(--lt-line); border-radius: 7px; color: var(--lt-text); cursor: pointer; padding: 5px 10px; }
.lt-pager button:disabled { cursor: default; opacity: .45; }

.lt-columns { position: relative; }
.lt-columns summary { background: #fff; border: 1px solid #d5dee8; border-radius: 8px; cursor: pointer; height: 34px; line-height: 32px; list-style: none; padding: 0 12px; }
.lt-columns-menu { background: #fff; border: 1px solid var(--lt-line); border-radius: 10px; box-shadow: 0 12px 28px rgba(21, 37, 53, .14); display: grid; gap: 6px; padding: 10px 12px; position: absolute; right: 0; top: 40px; z-index: 6; }
.lt-columns-menu label { align-items: center; display: flex; gap: 8px; white-space: nowrap; }

/* turns ------------------------------------------------------------------------------------------ */
.lt-filters { display: grid; gap: 12px; }
.lt-filters form.lt-field { display: inline-flex; }
.lt-chip { background: #fff; border: 1px solid #d5dee8; border-radius: 999px; color: var(--lt-text); cursor: pointer; padding: 5px 12px; }
.lt-chip.active { background: #e8f0f9; border-color: var(--lt-blue); color: var(--lt-blue); font-weight: 600; }

/* drawer ------------------------------------------------------------------------------------------ */
.lt-drawer-backdrop { background: rgba(21, 37, 53, .28); inset: 0; position: fixed; z-index: 40; }
.lt-drawer { animation: lt-slide .18s ease-out; background: #fff; bottom: 0; box-shadow: -12px 0 32px rgba(21, 37, 53, .18); display: flex; flex-direction: column; max-width: 100%; position: absolute; right: 0; top: 0; width: min(860px, 92vw); }
@keyframes lt-slide { from { transform: translateX(24px); opacity: .6; } }
.lt-drawer-head { align-items: flex-start; border-bottom: 1px solid var(--lt-line); display: flex; justify-content: space-between; padding: 16px 20px; }
.lt-drawer-head h3 { color: var(--lt-ink); margin: 0; }
.lt-drawer-close { background: none; border: 0; color: var(--lt-muted); cursor: pointer; font-size: 1.6rem; line-height: 1; }
.lt-drawer-body { display: grid; gap: 16px; overflow-y: auto; padding: 16px 20px 28px; }
/* Grid items default to min-width: auto, so a wide table would stretch the whole drawer; let tables scroll instead. */
.lt-drawer-body > * { min-width: 0; }
.lt-drawer-title { color: var(--lt-ink); font-size: .9rem; margin: 6px 0; }
.lt-facts { display: grid; gap: 10px 18px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); margin: 0; }
.lt-facts dt { color: var(--lt-muted); font-size: .72rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }
.lt-facts dd { color: var(--lt-ink); font-weight: 600; margin: 3px 0 0; }

@media (max-width: 760px) {
  .lt-toolbar { position: static; }
  .lt-hbar { grid-template-columns: 100px 1fr 70px; }
  .lt-grid-2 { grid-template-columns: minmax(0, 1fr); }
}
