/*
  Copyright (c) 2021-2026 Littleton Robotics
  http://github.com/Mechanical-Advantage

  Use of this source code is governed by a BSD
  license that can be found in the LICENSE file
  at the root directory of this project.
*/

/* Documentation */

div.documentation-container {
  position: absolute;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

div.documentation-container > * {
  position: absolute;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  border: none;
}

/* Line graph */

canvas.line-graph-canvas {
  position: absolute;
  top: 0%;
  left: 0%;
  width: 100%;
  height: 100%;
}

div.line-graph-scroll {
  position: absolute;
  z-index: 9;
  left: 0px;
  right: 0px;
  top: 8px;
  bottom: 35px;
  overflow: scroll;
  scrollbar-width: none; /* Required for Firefox */
}

div.line-graph-scroll::-webkit-scrollbar {
  display: none;
}

div.line-graph-scroll-content {
  width: 1000000px;
  height: 1000000px;
}

div.line-graph-help {
  position: absolute;
  z-index: 10;
  left: 0px;
  right: 0px;
  top: 8px;
  bottom: 35px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  user-select: none;
}

div.line-graph-help-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  opacity: 0.45;
  transition: opacity 0.4s ease-out;
  animation: help-fade-in 0.4s ease-out;
}

div.line-graph-help.fading-out div.line-graph-help-container {
  opacity: 0;
}

div.line-graph-help-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.3px;
  color: #000;
}

@media (prefers-color-scheme: dark) {
  div.line-graph-help-row {
    color: #fff;
  }
}

img.line-graph-help-icon {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

@media (prefers-color-scheme: dark) {
  img.line-graph-help-icon {
    filter: invert(1);
  }
}

@keyframes help-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 0.45;
  }
}

/* 2D Field */

div.field-2d-canvas-container {
  position: absolute;
  bottom: 0%;
  left: 0%;
  width: 100%;
  height: calc(100% + 26px);
  overflow: hidden;
}

body.satellite div.field-2d-canvas-container {
  height: 100%;
}

canvas.field-2d-canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

div.field-2d-scroll {
  position: absolute;
  left: 0px;
  right: 0px;
  bottom: 0px;
  height: calc(100% + 26px);
  overflow: scroll;
  scrollbar-width: none; /* Required for Firefox */
}

body.satellite div.field-2d-scroll {
  height: 100%;
}

div.field-2d-scroll::-webkit-scrollbar {
  display: none;
}

div.field-2d-scroll-content {
  width: 1000000px;
  height: 1000000px;
}

/* 3D Field */

@media (prefers-color-scheme: dark) {
}

/* Source: https://freecodez.com/post/7pt17rk */

/* Table & Console */

img.large-table-hand-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100px;
}

@media (prefers-color-scheme: dark) {
  img.large-table-hand-icon {
    filter: invert(100%);
  }
}

/* Table */

div.data-table-container {
  position: absolute;
  top: 0px;
  bottom: 0px;
  left: 0px;
  right: 0px;
  overflow: auto;
}

table.data-table {
  text-align: left;
  white-space: nowrap;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;

  border-style: hidden;
}

table.data-table th {
  position: sticky;
  top: 0px;
  height: 30px;
  padding: 0px;
  border-right: 1px solid #eee;
  border-bottom: 1px solid #222;

  background-color: #fff;
  z-index: 8;
}

table.data-table th:first-child {
  left: 0px;
  min-width: 97px;
  z-index: 10;
}

table.data-table th:first-child input {
  position: absolute;
  left: 4px;
  top: 4.5px;
  height: 15px;
  width: 56px;
}

table.data-table th:first-child button {
  position: absolute;
  left: 70px;
  top: 2.5px;
  height: 25px;
  width: 25px;
}

table.data-table th:not(:first-child) {
  min-width: 175px;
}

div.data-table-key-container {
  position: absolute;
  left: 6px;
  right: 6px;
  top: 0px;
  height: 30px;
  line-height: 30px;

  direction: rtl;
  overflow: hidden;
  text-overflow: ellipsis;
}

div.data-table-key-container.has-close-button {
  right: 30px;
}

div.data-table-key-container span {
  unicode-bidi: plaintext;
}

button.data-table-key-delete {
  position: absolute;
  height: 25px;
  width: 25px;
  top: 2.5px;
  right: 2px;
}

table.data-table th:last-child {
  border-right: none;
}

table.data-table td {
  height: 16px;
  line-height: 16px;
  padding: 4px;
  font-family: Courier, monospace;
  user-select: text;
  border-right: 1px solid #eee;
  border-bottom: 1px solid #eee;
}

table.data-table td:first-child {
  position: sticky;
  left: 0px;
  text-align: right;
  font-weight: bold;

  background-color: #fff;
}

table.data-table td:last-child {
  border-right: none;
}

table.data-table tr:last-child td {
  border-bottom: none;
}

table.data-table tr.hovered td {
  background-color: #ddd;
}

table.data-table tr.selected td {
  background-color: #aaa;
}

@media (prefers-color-scheme: dark) {
  table.data-table th {
    border-right: 1px solid #333;
    border-bottom: 1px solid #eee;
    background-color: #222;
  }

  table.data-table td {
    border-right: 1px solid #333;
    border-bottom: 1px solid #333;
  }

  table.data-table td:first-child {
    background-color: #222;
  }

  table.data-table tr.hovered td {
    background-color: #444;
  }

  table.data-table tr.selected td {
    background-color: #777;
  }
}

div.data-table-drag-highlight {
  position: absolute;
  z-index: 11;
  width: 25px;
  top: 0px;
  bottom: 0px;
  background-color: lightgreen;
  opacity: 25%;
}

/* Console */

div.console-table-drag-highlight {
  position: absolute;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  z-index: 11;
  background-color: lightgreen;
  opacity: 25%;
}

div.console-table-container {
  position: absolute;
  top: 0px;
  bottom: 0px;
  left: 0px;
  right: 0px;
  overflow-x: hidden;
  overflow-y: auto;
}

table.console-table {
  width: 100%;
  table-layout: fixed;

  border-collapse: separate;
  border-spacing: 0;
  border-style: hidden;
  margin-bottom: 6px;
}

table.console-table th {
  position: sticky;
  top: 0px;
  height: 30px;
  padding: 0px;
  border-right: 1px solid #eee;
  border-bottom: 1px solid #222;
  font-size: 14px;

  background-color: #fff;
  z-index: 8;
}

table.console-table th:first-child {
  width: 97px;
  z-index: 10;
}

table.console-table th:first-child input {
  position: absolute;
  left: 4px;
  top: 4.5px;
  height: 15px;
  width: 56px;
}

table.console-table th:first-child button {
  position: absolute;
  left: 70px;
  top: 2.5px;
  height: 25px;
  width: 25px;
}

button.console-table-key-delete {
  position: absolute;
  height: 25px;
  width: 25px;
  top: 2.5px;
  margin-left: 5px;
}

table.console-table th:not(:first-child) {
  border-right: none;
}

table.console-table th:not(:first-child) div {
  position: absolute;
  left: 0px;
  top: 0px;
  height: 30px;
  right: 246px;
  padding-left: 5px;
  overflow: hidden;
  font-size: 14px;
  line-height: 30px;
  text-align: left;
  white-space: nowrap;
}

table.console-table th:not(:first-child) div.wide {
  right: 218px;
}

table.console-table button.export-button {
  position: absolute;
  top: 50%;
  right: 216px;
  height: 25px;
  width: 25px;
  padding-top: 9px;
  padding-bottom: 9px;
  transform: translateY(-50%);
}

table.console-table button.highlight-button {
  position: absolute;
  top: 50%;
  right: 188px;
  height: 25px;
  width: 25px;
  padding-top: 9px;
  padding-bottom: 9px;
  transform: translateY(-50%);
}

table.console-table button.highlight-button.active img {
  /* https://codepen.io/sosuke/pen/Pjoqqp */
  filter: invert(84%) sepia(28%) saturate(6635%) hue-rotate(354deg) brightness(96%) contrast(112%);
}

table.console-table input.filter {
  position: absolute;
  top: 50%;
  right: 5px;
  height: 15px;
  width: 180px;
  padding-top: 9px;
  padding-bottom: 9px;
  transform: translateY(-50%);
}

table.console-table th:not(:first-child) input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  height: 1em;
  width: 1em;
  background: url("symbols/cancel.svg") no-repeat 50% 50%;
  background-size: contain;
}

table.console-table td {
  padding: 0px 6px 0px 6px;
  user-select: text;
  vertical-align: top;
  font-family: Courier, monospace;
  font-size: 12px;
  line-height: 16px;
  overflow-wrap: break-word;
  word-break: break-all;
  white-space: break-spaces;
  tab-size: 4;
}

table.console-table td span.highlight {
  background-color: #ffff00;
}

table.console-table td:first-child {
  text-align: right;
  font-weight: bold;
  user-select: none;
}

table.console-table td:last-child {
  border-right: none;
}

table.console-table tr.hovered td {
  background-color: #eee;
}

table.console-table tr.selected td {
  background-color: #e3e3e3;
}

table.console-table tr.warning td {
  background-color: #ffaa0055;
}

table.console-table tr.warning.hovered td {
  background-color: #ffaa0088;
}

table.console-table tr.warning.selected td {
  background-color: #ffaa00aa;
}

table.console-table tr.error td {
  background-color: #ff000055;
}

table.console-table tr.error.hovered td {
  background-color: #ff000088;
}

table.console-table tr.error.selected td {
  background-color: #ff0000aa;
}

@media (prefers-color-scheme: dark) {
  table.console-table th {
    border-right: 1px solid #333;
    border-bottom: 1px solid #eee;
    background-color: #222;
  }

  table.console-table td span.highlight {
    color: black;
  }

  table.console-table td:first-child {
    background-color: #222;
  }

  table.console-table tr.hovered td {
    background-color: #333;
  }

  table.console-table tr.selected td {
    background-color: #3e3e3e;
  }
}

/* Statistics */

div.stats-values-container {
  position: absolute;
  left: 0px;
  top: 0px;
  bottom: 0px;
  max-width: 50%;
  overflow-y: auto;
}

table.stats-values {
  width: calc(100% - 20px);
  margin: 10px;

  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #555;
}

table.stats-values td {
  word-wrap: break-word;
  padding: 2px 6px 2px 6px;
  border: 1px solid #eee;
  overflow: hidden;
}

table.stats-values tr.section td {
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}

table.stats-values tr.section:not(:first-child) td {
  border-top: 1px solid #555;
}

@media (prefers-color-scheme: dark) {
  table.stats-values {
    border: 1px solid #999;
  }

  table.stats-values td {
    border: 1px solid #333;
  }

  table.stats-values tr.section td {
    border-top: 1px solid #999;
  }
}

table.stats-values tr.values td:first-child {
  text-align: right;
  font-size: 12px;
  width: 100px;
}

table.stats-values tr.values td:not(:first-child) {
  user-select: text;
  font-family: Courier, monospace;
  font-size: 14px;
}

div.stats-histogram-container {
  position: absolute;
  right: 10px;
  top: 0px;
  bottom: 10px;
  overflow: hidden;
}

/* Video */

div.video-container {
  position: absolute;
  top: 0%;
  height: 100%;
  left: 0%;
  width: 100%;
  overflow: hidden;
}

div.video-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Driver Inputs */

canvas.driver-inputs-canvas {
  position: absolute;
  left: 0%;
  top: 0%;
  width: 100%;
  height: 100%;
}

/* Car Dynamics */

div.car-dynamics-canvas-container {
  position: absolute;
  bottom: 0%;
  height: calc(100% + 10px);
  left: 0px;
  width: 100%;
}

body.satellite div.car-dynamics-canvas-container {
  height: 100%;
}

canvas.car-dynamics-canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

  background-color: #f4f4f4;
  border: 1px solid #555;
}

@media (prefers-color-scheme: dark) {
  canvas.car-dynamics-canvas {
    background-color: #292929;
    border: 1px solid #999;
  }
}

/* Points */

div.points-background-container {
  position: absolute;
  bottom: 0%;
  height: calc(100% + 10px);
  left: 0px;
  width: 100%;
}

body.satellite div.points-background-container {
  height: 100%;
}

div.points-background {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

  background-color: #f4f4f4;
  border: 1px solid #555;
}

@media (prefers-color-scheme: dark) {
  div.points-background {
    background-color: #292929;
    border: 1px solid #999;
  }
}

div.points-background svg {
  position: absolute;
  stroke-width: 5px;
}

/* Metadata */

div.metadata-table-container {
  height: 100%;
  width: 100%;
  overflow: auto;
}

table.metadata-table {
  width: 100%;
  table-layout: fixed;
  text-align: left;
  word-wrap: break-word;
  border-collapse: separate;
  border-spacing: 0;
}

table.metadata-table th:first-child {
  width: 150px;
}

table.metadata-table th {
  padding: 6px;
  position: sticky;
  top: 0px;
  border-bottom: 1px solid #222;
  background-color: #fff;
}

table.metadata-table td:first-child {
  padding: 6px;
  text-align: right;
  font-weight: bold;
  border-right: 1px solid #222;
}

table.metadata-table td:not(:first-child) {
  padding: 6px;
  font-family: Courier, monospace;
  font-size: 14px;
  user-select: text;
}

table.metadata-table td.no-data {
  font-style: italic;
}

@media (prefers-color-scheme: dark) {
  table.metadata-table th {
    border-bottom: 1px solid #eee;
    background-color: #222;
  }

  table.metadata-table td:first-child {
    border-right: 1px solid #eee;
  }
}

/* Lap analysis shares the workbench's flat, compact controls. */
.lap-view:not([hidden]) {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.lap-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px 6px;
  background: var(--background-color);
  border-bottom: 1px solid #8884;
  font-size: 13px;
}
.lap-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
}
.lap-header-title {
  font-weight: 600;
}
.lap-header-end {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}
.lap-summary {
  font-size: 12px;
  opacity: 0.75;
  white-space: normal;
}
.lap-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  padding: 8px 12px;
  background: var(--background-color);
  font-size: 13px;
}
.lap-header button,
.lap-toolbar button,
.lap-setup button {
  min-height: 22px;
  padding: 2px 8px;
  font: inherit;
  font-size: 12px;
  color: var(--mv-control-fg);
  background: var(--mv-control-bg);
  border: 1px solid var(--mv-control-border);
  border-radius: 4px;
  cursor: pointer;
}
.lap-body {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}
.lap-body.lap-stacked {
  /* The table comes first in the page, so reversing puts the map on top. */
  flex-direction: column-reverse;
}
.lap-pane {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}
.lap-pane[hidden],
.lap-split-handle[hidden] {
  display: none;
}
/* These match SPLIT_MIN in LapRenderer.ts. */
.lap-split .lap-table-pane {
  min-width: 480px;
}
.lap-split .lap-map-pane {
  min-width: 320px;
  /* The same edge as the stock tab controls divider */
  box-shadow: 0px 0px 3px 2px #00000022;
}
.lap-stacked .lap-table-pane,
.lap-stacked .lap-map-pane {
  min-width: 0;
}
.lap-stacked .lap-table-pane {
  min-height: 140px;
}
.lap-stacked .lap-map-pane {
  min-height: 160px;
}
/* Like the sidebar and controls handles, the divider is an invisible strip 10 px wide over the pane edge. */
.lap-split-handle {
  flex: 0 0 0;
  position: relative;
  z-index: 3;
}
.lap-split-handle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -5px;
  width: 10px;
  cursor: col-resize;
}
.lap-stacked .lap-split-handle::before {
  top: -5px;
  bottom: auto;
  left: 0;
  right: 0;
  width: auto;
  height: 10px;
  cursor: row-resize;
}
.lap-readonly .lap-split-handle::before {
  cursor: default;
}
.lap-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  position: relative;
}
.lap-map {
  position: absolute;
  inset: 0;
}
.lap-map div.field-2d-canvas-container,
.lap-map div.field-2d-scroll {
  height: 100%;
}
.lap-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.lap-table td {
  padding: 7px 10px;
  text-align: right;
  border-bottom: 1px solid #8884;
}
.lap-table td:nth-child(3),
.lap-table td.lap-source {
  text-align: left;
}
.lap-table td.lap-source {
  min-width: 240px;
}
.lap-table tr {
  cursor: pointer;
}
.lap-table tr:hover,
.lap-selected {
  background: #8882;
}
.lap-heading {
  position: sticky;
  top: 0;
  background: #eee;
  font-weight: 600;
}
.lap-best {
  color: #8430ae;
  font-weight: 600;
}
.lap-personal {
  color: #187b43;
  font-weight: 600;
}
.lap-hint,
.lap-empty {
  padding: 12px;
  font-size: 13px;
}
.lap-hint {
  /* Footer stays pinned inside the scroll area, with room so scrollbars never cover its text */
  position: sticky;
  left: 0;
  bottom: 0;
  box-sizing: border-box;
  padding: 8px 20px 18px 12px;
  background: #eee;
  border-top: 1px solid #8884;
}
.lap-empty {
  position: absolute;
  top: 40%;
  left: 10%;
  right: 10%;
  text-align: center;
  pointer-events: none;
}
@media (prefers-color-scheme: dark) {
  .lap-split .lap-map-pane {
    box-shadow: 0px 0px 0px 0.7px #000;
  }
  .lap-heading {
    background: #222;
  }
  .lap-hint {
    background: #222;
  }
  .lap-best {
    color: #d49bff;
  }
  .lap-personal {
    color: #72d6a0;
  }
}

.graph-inline-controls {
  position: absolute;
  right: 8px;
  bottom: 6px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.85);
  font-size: 12px;
  opacity: 1;
}
.graph-inline-controls:hover,
.graph-inline-controls:focus-within {
  opacity: 1;
}
.graph-inline-controls label {
  display: flex;
  align-items: center;
  gap: 3px;
}
.graph-inline-controls label.lap-axis-label {
  gap: 5px;
  font-weight: 600;
}
.lap-axis-mode {
  max-width: 240px;
  height: 20px;
  font-size: 12px;
  color: inherit;
  background: transparent;
  border: 1px solid rgba(128, 128, 128, 0.5);
  border-radius: 4px;
  padding: 0 4px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  .graph-inline-controls {
    background: rgba(34, 34, 34, 0.85);
  }
  .lap-axis-mode option {
    background: #333;
  }
}

/* Lap setup uses the 2D Field controller's settings column. */
.lap-setup button {
  display: block;
  width: calc(100% - 20px);
  margin: 5px 10px;
}
.lap-setup .title .full {
  font-size: 13px;
}

/* Keep scrolling available without permanent bars, as in the sidebar. */
.lap-content,
.field-2d-settings[aria-label="Lap setup"] {
  scrollbar-width: none;
}
.lap-content::-webkit-scrollbar,
.field-2d-settings[aria-label="Lap setup"]::-webkit-scrollbar {
  display: none;
}
.lap-table input.mv-checkbox,
.lap-table input.mv-radio {
  position: relative;
  inset: auto;
}

:root {
  --trackside-critical: #b3261e;
  --trackside-warn: #8a5a00;
  --trackside-background: #fff;
  --trackside-border: #ddd;
  --trackside-muted: #666;
}
@media (prefers-color-scheme: dark) {
  :root {
    --trackside-critical: #ff7b72;
    --trackside-warn: #ffb938;
    --trackside-background: #222;
    --trackside-border: #444;
    --trackside-muted: #aaa;
  }
}
.trackside-grid {
  position: absolute;
  inset: 0;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  grid-auto-rows: minmax(150px, 1fr);
  gap: 12px;
  overflow: auto;
}
.trackside-tile {
  container-type: inline-size;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 24px;
  border: 1px solid var(--trackside-border);
}
.trackside-label {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trackside-reading {
  font-size: clamp(28px, 16cqw, 64px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trackside-state {
  height: 22px;
  font-size: 16px;
}
.trackside-tile[data-severity="critical"] {
  color: var(--trackside-critical);
  border-color: var(--trackside-critical);
}
.trackside-tile[data-severity="warn"] {
  color: var(--trackside-warn);
  border-color: var(--trackside-warn);
}
.trackside-tile[data-freshness="stale"] .trackside-reading {
  opacity: 0.55;
}
.trackside-tile[data-freshness="offline"] {
  color: var(--trackside-muted);
  border-style: dashed;
}

.trackside-unit {
  font-size: 0.5em;
  font-weight: 400;
}

.trackside-grid.with-graph {
  bottom: 60%;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  grid-auto-rows: minmax(120px, 1fr);
}
.trackside-graph {
  position: absolute;
  inset: 40% 0 0;
  pointer-events: none;
}
.trackside-graph .line-graph-help {
  display: none !important;
}
