/* =====================================================================================
   pavex PCI Viewer
   Brand: pavex grey #595959 and pavex red #EA3323 (from the logo). Red is kept for the
   brand and the primary action only, because the PCI scale itself uses oranges and reds.
   Type: Barlow, a typeface drawn from US highway signage.
   ===================================================================================== */

:root {
  --ink: #232527;          /* asphalt */
  --brand-grey: #595959;
  --brand-red: #ea3323;
  --brand-red-dark: #c4241a;
  --paper: #ffffff;
  --mist: #f3f4f4;
  --line: #e1e3e4;
  --muted: #676c70;
  --stage: #17191a;        /* behind videos */
  --focus: #1f6fd1;
  --drawer-w: 460px;
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;
  --shadow: 0 1px 2px rgba(20, 22, 24, .12), 0 6px 20px rgba(20, 22, 24, .10);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 var(--font); color: var(--ink); background: var(--mist); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.btn { border: 1px solid var(--line); background: var(--paper); border-radius: 6px; padding: 7px 14px; font-weight: 600; }
.btn:hover { border-color: #c4c8ca; }
.btn.primary { background: var(--brand-red); border-color: var(--brand-red); color: #fff; }
.btn.primary:hover { background: var(--brand-red-dark); border-color: var(--brand-red-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); font-weight: 500; }
.btn.ghost:hover { color: var(--ink); background: var(--mist); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: var(--muted); flex-shrink: 0; }
.icon-btn:hover { background: var(--mist); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* ------------------------------------------------------------------ sign in */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(180deg, var(--paper) 0 50%, var(--mist) 50%); }
.login-card { width: 100%; max-width: 380px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 32px 28px 24px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-logo { height: 34px; width: auto; justify-self: start; margin-bottom: 6px; }
.login-card h1 { margin: 0; font: 600 24px/1.2 var(--font); letter-spacing: -.005em; }
.login-sub { margin: -6px 0 6px; color: var(--muted); }
.field { display: grid; gap: 5px; font-weight: 600; font-size: 14px; }
.field input { font-weight: 400; padding: 10px 12px; border: 1px solid #cfd3d5; border-radius: 6px; background: var(--paper); }
.field input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px rgba(31, 111, 209, .15); }
.login-card .btn.primary { padding: 11px; margin-top: 4px; font-size: 16px; }
.form-error { min-height: 1.45em; margin: 0; color: #b42318; font-size: 14px; }

/* ------------------------------------------------------------------ app frame */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { height: 56px; flex-shrink: 0; display: flex; align-items: center; gap: 14px; padding: 0 12px 0 18px;
  background: var(--paper); border-bottom: 1px solid var(--line); position: relative; z-index: 1001; }
.topbar-logo { height: 24px; width: auto; display: block; }
.topbar-divider { width: 1px; height: 26px; background: var(--line); }
.project-pick select { appearance: none; border: 1px solid transparent; background: transparent; border-radius: 6px;
  padding: 6px 30px 6px 10px; font-weight: 600; font-size: 16px; max-width: 46vw; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M6 8l4 4 4-4' fill='none' stroke='%23676c70' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; }
.project-pick select:hover:not(:disabled) { border-color: var(--line); }
.project-pick select:disabled { background-image: none; padding-right: 10px; opacity: 1; cursor: default; }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }

.workspace { flex: 1; position: relative; min-height: 0; overflow: hidden; }
.map { position: absolute; inset: 0; background: #e9ebea; }

/* ------------------------------------------------------------------ map details */
.leaflet-container { font-family: var(--font); }
.leaflet-tile-pane { filter: grayscale(1) brightness(1.04) contrast(.88); }
.map-tip { font: 600 13px/1.3 var(--font); color: var(--ink); border: 0; border-radius: 5px; box-shadow: var(--shadow); padding: 5px 9px; }
.leaflet-bottom.leaflet-right { transition: right .25s ease; }
body.drawer-open .leaflet-bottom.leaflet-right { right: var(--drawer-w); }
.leaflet-control-attribution { font-size: 11px; }

/* ------------------------------------------------------------------ summary / legend */
.summary { position: absolute; z-index: 1000; top: 14px; left: 14px; width: 300px; max-height: calc(100% - 28px); overflow: auto;
  background: var(--paper); border-radius: 10px; box-shadow: var(--shadow); padding: 14px 14px 12px 16px; }
.summary-head { display: flex; align-items: flex-start; gap: 8px; }
.summary-head > div { flex: 1; min-width: 0; }
.summary-title { font: 600 17px/1.25 var(--font); }
.summary-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.summary.collapsed .summary-body { display: none; }
.summary.collapsed #summary-toggle svg { transform: rotate(180deg); }
#summary-toggle { margin: -6px -6px 0 0; }

.avg { display: flex; align-items: center; gap: 12px; margin: 14px 0 12px; }
.avg-num { font: 700 48px/0.9 var(--font-num); letter-spacing: -.01em; color: var(--ink);
  padding-left: 12px; border-left: 6px solid var(--cat, var(--line)); font-variant-numeric: tabular-nums; }
.avg-label { font-size: 13px; color: var(--muted); }
.avg-cat { font-weight: 700; color: var(--cat, var(--ink)); filter: brightness(.85); }

/* the network as a strip of road, with a dashed centre line */
.road-bar { display: flex; height: 16px; border-radius: 3px; overflow: hidden; position: relative; margin-bottom: 10px; background: var(--mist); }
.road-bar span { min-width: 2px; transition: opacity .2s; }
.road-bar span.off { opacity: .15; }
.road-bar::after { content: ""; position: absolute; left: 0; right: 0; top: 7px; height: 2px;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.95) 0 10px, transparent 10px 18px); pointer-events: none; }

.cat-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cat-table td { padding: 4px 0; }
.cat-table tr[role="switch"] { cursor: pointer; }
.cat-table tr[role="switch"]:hover td { background: var(--mist); }
.cat-table tr.none { color: #b1b5b8; }
.cat-table tr.off td:not(.sw) { color: #a6aaad; text-decoration: line-through; }
.cat-table tr.off .sw span { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }
.cat-table .sw { width: 22px; }
.cat-table .sw span { display: block; width: 14px; height: 14px; border-radius: 3px; background: var(--c); }
.cat-table tr.none .sw span { opacity: .3; }
.cat-table .ln, .cat-table .pc { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-num); font-weight: 500; }
.cat-table .pc { width: 44px; padding-right: 2px; color: var(--muted); }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 12px; }
.seg-search { display: flex; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.seg-search input { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid #cfd3d5; border-radius: 6px; }

/* ------------------------------------------------------------------ segment drawer */
.drawer { position: absolute; z-index: 1000; top: 0; right: 0; bottom: 0; width: var(--drawer-w);
  background: var(--paper); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(20,22,24,.08);
  display: flex; flex-direction: column; transition: width .25s ease; }
.drawer.expanded { --drawer-w: min(1180px, 80vw); }
body.drawer-open .workspace:has(.drawer.expanded) { --drawer-w: min(1180px, 80vw); }
.workspace:has(.drawer.expanded) .summary { display: none; }
.drawer-head { display: flex; align-items: center; gap: 4px; padding: 12px 10px 10px 18px; border-bottom: 1px solid var(--line); }
.seg-heading { flex: 1; min-width: 0; }
.seg-title { font: 700 22px/1.15 var(--font-num); }
.seg-sub { color: var(--muted); font-size: 13.5px; }
.drawer-scroll { flex: 1; overflow: auto; padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 14px; }

.score-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.score { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: var(--mist);
  border-left: 6px solid var(--cat, var(--line)); }
.score-num { font: 700 40px/0.95 var(--font-num); font-variant-numeric: tabular-nums; min-width: 1.6em; }
.score-label { font-size: 13px; color: var(--muted); }
.score-cat { font-weight: 700; }

.lane-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.lane-tab { display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 8px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--paper); font-size: 14px; }
.lane-tab::before { content: ""; width: 4px; align-self: stretch; border-radius: 2px; background: var(--cat); }
.lane-tab .lt-pci { font: 600 15px/1 var(--font-num); color: var(--muted); font-variant-numeric: tabular-nums; }
.lane-tab:hover { border-color: #c4c8ca; }
.lane-tab.on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 600; }
.lane-tab.on .lt-pci { color: var(--ink); }
.lane-tab[title] { opacity: .7; }

.player { background: var(--stage); border-radius: 8px; padding: 8px; display: grid; gap: 8px; }
.vid { position: relative; background: #000; border-radius: 4px; overflow: hidden; aspect-ratio: 16 / 9; cursor: pointer; }
.vid video { width: 100%; height: 100%; object-fit: contain; display: block; }
.vid-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vid-tag { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; font-weight: 500;
  padding: 1px 7px; border-radius: 3px; pointer-events: none; }
.vid-empty { display: none; position: absolute; inset: 0; place-items: center; color: #8d9296; font-size: 13px; text-align: center; padding: 8px; }
.vid.empty { cursor: default; }
.vid.empty .vid-empty { display: grid; }
.controls { display: flex; align-items: center; gap: 10px; color: #e8eaeb; padding: 2px 2px 0; }
.play-btn { width: 38px; height: 38px; border-radius: 50%; border: 0; background: #fff; color: var(--ink); display: grid; place-items: center; flex-shrink: 0; }
.play-btn svg { width: 18px; height: 18px; }
.play-btn .i-pause, body.is-playing .play-btn .i-play { display: none; }
body.is-playing .play-btn .i-pause { display: block; }
.play-btn:disabled { opacity: .4; cursor: default; }
.controls input[type=range] { flex: 1; min-width: 60px; accent-color: #fff; }
.time { font: 500 14px/1 var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.controls select { background: #2a2d2f; border: 1px solid #3b3f42; color: #eef0f1; border-radius: 6px; padding: 4px 6px; }
.no-video { margin: 0; padding: 14px; border-radius: 8px; background: var(--mist); color: var(--muted); }
.keys { margin: 0; font-size: 12.5px; color: var(--muted); }

/* larger videos: forward view on the left, the two surface views stacked on the right */
.drawer.expanded .player { grid-template-columns: 1.55fr 1fr; grid-template-rows: auto auto; }
.drawer.expanded .vid.gopro { grid-row: 1; grid-column: 1; }
.drawer.expanded .vid-pair { grid-row: 1; grid-column: 2; grid-template-columns: 1fr; align-content: center; }
.drawer.expanded .controls { grid-column: 1 / -1; }
.drawer.expanded .score-row { grid-template-columns: repeat(2, minmax(0, 260px)); }

/* ------------------------------------------------------------------ small screens */
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 0 6px 0 12px; }
  .topbar-logo { height: 20px; }
  .topbar-divider, .who { display: none; }
  .project-pick select { font-size: 15px; max-width: 52vw; }
  .summary { left: 10px; right: 10px; top: 10px; width: auto; max-height: 60%; }
  .drawer, .drawer.expanded { top: auto; left: 0; width: 100%; height: 72%; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 12px 12px 0 0; box-shadow: 0 -8px 24px rgba(20,22,24,.12); }
  #expand-btn { display: none; }
  body.drawer-open .leaflet-bottom.leaflet-right { right: 0; }
  body.drawer-open .summary { display: none; }
  .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
