:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #18202f;
  --muted: #657084;
  --line: #dbe2ec;
  --primary: #1d5fd1;
  --primary-dark: #174aa1;
  --ok: #0f8a5f;
  --shadow: 0 8px 20px rgba(35, 50, 80, 0.07);
  --card-shadow: 0 6px 16px rgba(35, 50, 80, 0.05);
  --chart-pad: 12px;
  --icon-blue: #8FC5FF; /* lighter action icon color */
  --chart-side-pad: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.upload-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 24px;
  align-items: stretch;
  padding: 28px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

button.header-language-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 28px;
  margin-bottom: 14px;
  border: 1px solid #b9cceb;
  border-radius: 4px;
  background: #fff;
  color: var(--primary);
  box-shadow: none;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  padding: 0 10px;
}

button.header-language-button:hover {
  border-color: var(--primary);
  background: #f3f7ff;
  color: var(--primary-dark);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.summary {
  max-width: 720px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.65;
}

.resource-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.resource-links a {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
  padding: 7px 10px;
  text-decoration: none;
}

.resource-links a:hover {
  border-color: var(--primary);
  background: #f3f7ff;
}

.file-source-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding-top: 12px;
}

.drop-zone,
.import-zone {
  display: grid;
  place-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 190px;
  padding: 24px 14px;
  border: 2px dashed #9eb6dd;
  border-radius: 8px;
  background: #f3f7ff;
  color: var(--primary-dark);
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    transform 0.18s ease;
}

.import-zone {
  width: 100%;
  font: inherit;
}

.drop-zone:hover,
.import-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: #e9f1ff;
  transform: translateY(-1px);
}

.drop-zone input {
  display: none;
}

.drop-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.25;
  max-width: calc(100% - 4px);
  overflow-wrap: anywhere;
  white-space: normal;
}

.drop-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  max-width: calc(100% - 4px);
  overflow-wrap: anywhere;
}

.js-plotly-plot .legend .legendlines path {
  stroke-width: 1.4px !important;
}

.status-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.status-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--card-shadow);
}

.status-card {
  min-width: 0;
  padding: 16px;
}

.status-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.status-card strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-card-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-card-body {
  flex: 1 1 auto;
  min-width: 0;
}

.status-card-file .status-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-card-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-card-main strong {
  flex: 1 1 auto;
  min-width: 0;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr);
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  padding: 18px;
}

.app-shell > section.panel + section.panel {
  margin-top: 18px;
}

.panel-header {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.meta-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.meta-list div {
  display: grid;
  grid-template-columns: 105px minmax(0, 1fr);
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.meta-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

dt {
  color: var(--muted);
  font-size: 13px;
  padding-top: 2px; /* nudge label slightly down without full vertical centering */
}

dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.bus-table {
  table-layout: fixed;
}

.bus-col-id,
.bus-col-fields {
  width: 18%;
}

.bus-col-name {
  width: 30%;
}

.bus-col-payload {
  width: 20%;
}

.bus-col-frames {
  width: 14%;
}

.bus-table th,
.bus-table td {
  padding: 7px 8px;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.param-groups {
  display: grid;
  gap: 8px;
}

.param-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  overflow: hidden;
}

.param-group summary {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
}

.param-group summary::-webkit-details-marker {
  display: none;
}

.param-group summary::before {
  content: "▸";
  color: var(--muted);
  flex: 0 0 auto;
}

.param-group[open] summary::before {
  content: "▾";
}

/* Make the triangle marker larger and better aligned */
.param-group summary::before {
  font-size: 22px;
  line-height: 1;
  margin-right: 0px;
  transform-origin: center;
}

.param-group[open] summary::before {
  font-size: 22px;
}

.param-group-name {
  min-width: 0;
  color: var(--text);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}

.param-group-count {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.param-grid {
  border-top: 1px solid var(--line);
}

.param-grid-head,
.param-grid-row {
  display: grid;
  grid-template-columns: minmax(130px, 230px) minmax(100px, 180px) 84px minmax(0, 1fr);
  column-gap: 22px;
  padding: 6px 10px 6px 40px; /* left padding increased to align with summary title */
  align-items: center;
}

.param-grid-head {
  color: var(--muted);
  font-size: 12px;
  background: #f5f8fc;
}

.param-grid-row {
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.param-grid-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chart-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chart-module {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--card-shadow);
}

.chart-module-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px 14px 8px;
  background: #f8fafc;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.chart-module-header:hover {
  background: #eef4fb;
}

.chart-module-header h3 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
}

.chart-module-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chart-module-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 22px;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  transform-origin: center;
}

.chart-module-chevron::before {
  content: "▾";
}

.chart-module.is-collapsed .chart-module-chevron {
  transform: rotate(-90deg);
}

.chart-stack[hidden] {
  display: none;
}

.chart-stack {
  display: grid;
  grid-template-columns: 1fr;
  /* match chart-stack spacing to button/button spacing for visual consistency */
  gap: var(--chart-pad);
  padding: var(--chart-pad);
}

.custom-chart-builder {
  display: grid;
  gap: var(--chart-pad);
}

.custom-chart-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  align-items: end;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.custom-chart-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.custom-chart-form select,
.custom-chart-form input {
  min-width: 0;
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.custom-chart-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  justify-self: start;
  border: 1px solid #b9cceb;
  background: #fff;
  color: var(--primary);
  line-height: 1;
  padding: 0 16px;
  white-space: nowrap;
}

.custom-chart-form button:hover {
  border-color: var(--primary);
  background: #f3f7ff;
  color: var(--primary-dark);
}

.custom-chart-results {
  display: grid;
  gap: var(--chart-pad);
}
.chart-module-empty {
  padding: 22px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.chart-module-loading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 72px;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcff;
  color: var(--muted);
  font-size: 13px;
}

.chart-module-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid #d8e1ef;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: chart-spin 0.9s linear infinite;
}

.chart-module-loading strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 14px;
}

.chart-module-progress {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7edf6;
}

.chart-module-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 160ms ease;
}

.chart-render-content.is-preparing {
  position: absolute;
  left: -100000px;
  top: 0;
  width: min(1180px, calc(100vw - 48px));
  visibility: hidden;
  pointer-events: none;
}

.chart-render-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--chart-pad);
}

@keyframes chart-spin {
  to {
    transform: rotate(360deg);
  }
}

.chart-figure {
  display: grid;
  /* main column stretches, actions column sized to content to avoid unused whitespace */
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--chart-pad);
  align-items: stretch;
  width: 100%;
}

.chart-figure-main {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.chart-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--chart-pad);
  padding: var(--chart-pad) var(--chart-side-pad);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 800;
}

.chart-title span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-title small {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.chart-actions {
  display: flex;
  flex-direction: column;
  gap: var(--chart-pad);
  align-items: flex-end; /* align buttons to right edge so right margin equals side padding */
  justify-content: flex-start;
  width: auto;
  min-width: 0; /* allow column to shrink to content */
  /* make first button flush with the top of the actions column */
  padding-top: 0;
  /* remove right padding so buttons sit flush with the actions column edge */
  padding-right: 0;
  padding-left: 0px;
}

.chart-actions button {
  width: 100%;
  border: 1px solid #d8e1ef;
  background: #f7f9fc;
  color: #516074;
  text-align: left;
}

.chart-actions button:hover:not(:disabled) {
  border-color: #b9c9df;
  background: #eef4fb;
  color: var(--primary-dark);
}

.chart-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.plotly-chart {
  width: 100%;
  height: min(75vh, 820px);
  min-height: 520px;
  background: #fbfcff;
  margin: 0;
  padding: 0;
  display: block;
  overflow: hidden;
  border-radius: inherit;
}

.plotly-chart-compact {
  aspect-ratio: 3.5 / 1;
  height: auto;
  min-height: 240px;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 38px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 11px;
}

button:hover {
  background: var(--primary-dark);
}

button.subtle-button {
  flex: 0 0 auto;
  border: 1px solid #d8e1ef;
  background: #f7f9fc;
  color: #6b778c;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 3px 8px;
}

button.subtle-button:hover {
  border-color: #c8d4e6;
  background: #eef3f9;
  color: #516074;
}

/* Connected state for flight controller button */
button.connected {
  background: #d9534f;
}

button.connected:hover {
  background: #c9302c;
}

button.cancel-transfer {
  background: #d9534f;
}

button.cancel-transfer:hover {
  background: #c9302c;
}

.fc-dialog {
  width: min(720px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(35, 50, 80, 0.24);
}

.chart-dialog {
  width: calc(100vw - 24px);
  max-width: none;
  height: calc(100vh - 24px);
  max-height: none;
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(35, 50, 80, 0.24);
}

.fc-dialog::backdrop {
  background: rgba(24, 32, 47, 0.36);
}

.chart-dialog::backdrop {
  background: rgba(24, 32, 47, 0.36);
}

.fc-dialog-panel {
  margin: 0;
  padding: 22px;
}

.chart-dialog-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  margin: 0;
  padding: 22px;
}

.chart-dialog-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px;
  gap: 14px;
  align-items: stretch;
  min-height: 0;
}

.chart-dialog-plot {
  min-width: 0;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fbfcff;
}

.chart-dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

.chart-dialog-actions .icon-button svg,
.chart-dialog-actions .icon-button img {
  width: 78%;
  height: 78%;
  display: block;
  color: var(--icon-blue);
}

.chart-dialog-actions .icon-button[hidden] {
  display: none !important;
}

.fc-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 18px;
  font-weight: 500;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover {
  background: #f3f7ff;
  color: var(--primary-dark);
}

.chart-actions .icon-button img {
  display: block;
  width: 74%;
  height: 74%;
  object-fit: contain;
}

/* tint inline SVG icons (those inserted as <svg>) to the theme icon color */
.chart-actions .icon-button svg {
  width: 74%;
  height: 74%;
  display: block;
  color: var(--icon-blue);
}

/* enlarge the 2D/3D mode and interaction icons slightly */
.chart-actions button[data-chart-action="toggle-trajectory-mode"] svg,
.chart-actions button[data-chart-action="toggle-trajectory-mode"] img,
.chart-actions button[data-chart-action="toggle-interaction-mode"] svg,
.chart-actions button[data-chart-action="toggle-interaction-mode"] img {
  width: 86%;
  height: 86%;
}

/* apply icon color to inline SVG by making the button's color the icon color */
.chart-actions .icon-button {
  color: var(--icon-blue);
}

/* Reduce horizontal whitespace around icon buttons */
.chart-actions .icon-button {
  margin: 0; /* no left/right gap */
  /* ensure no implicit right margin from user agent */
  margin-right: 0;
}

/* ensure the very first icon button sits flush at the top */
.chart-actions .icon-button:first-child {
  margin-top: 0;
}

/* Ensure icon buttons in the action bar are fixed-size squares and not full-width */
.chart-actions .icon-button {
  width: 44px !important;
  height: 44px !important;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  flex: none !important;
}

.chart-actions .delete-custom-chart-button svg,
.chart-actions .delete-custom-chart-button img {
  width: 74%;
  height: 74%;
}

.fc-controls {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.fc-controls label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.fc-controls select,
.fc-controls input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
}

.fc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.fc-action-group {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.fc-transfer {
  display: grid;
  gap: 8px;
  margin: -4px 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.fc-transfer[hidden] {
  display: none;
}

.fc-transfer-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.fc-transfer-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fc-transfer-row strong {
  color: var(--primary-dark);
  font-size: 12px;
  white-space: nowrap;
}

.fc-transfer progress {
  width: 100%;
  height: 10px;
  accent-color: var(--primary);
}

.fc-session-hint {
  margin: -4px 0 12px;
  padding: 9px 12px;
  border: 1px solid #b9cceb;
  border-radius: 8px;
  background: #f3f7ff;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
}

.fc-session-hint[hidden] {
  display: none;
}

.flight-log-table .name-header {
  padding-left: 48px;
}

.flight-log-table .name-cell input[type="checkbox"] {
  margin-right: 8px;
}

.dir-checkbox {
  margin-right: 8px;
  vertical-align: middle;
  cursor: pointer;
}

.dir-toggle,
.file-toggle {
  position: relative;
  display: inline-flex;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #eef4ff;
  cursor: pointer;
  padding: 0;
  appearance: none;
  flex: 0 0 auto;
  vertical-align: middle;
  bottom: 1px;
  transition:
    border-color 0.12s ease,
    box-shadow 0.12s ease,
    background 0.12s ease;
}

.dir-toggle:hover,
.file-toggle:hover {
  border-color: var(--primary);
  background: #e5efff;
}

.dir-toggle:focus,
.file-toggle:focus {
  outline: none;
  border-color: var(--primary);
  background: #e5efff;
  /* box-shadow: 0 0 0 3px rgba(29, 95, 209, 0.18); */
}

.dir-toggle::after,
.file-toggle::after {
  content: '';
  position: absolute;
  inset: 2px;
  display: block;
  border-radius: 2px;
  background: transparent;
  transition: background 0.12s ease;
}

.dir-toggle.checked,
.file-toggle.checked {
  background: #fff;
  border-color: var(--primary);
}

.dir-toggle.checked::after,
.file-toggle.checked::after {
  background: var(--primary);
}

.fc-actions button:disabled {
  background: #c9d3e2;
  cursor: not-allowed;
}

.fc-file-list {
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.fc-dialog-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.ok {
  color: var(--ok);
}

.error {
  color: #b42318;
}

@media (max-width: 860px) {
  .upload-panel,
  .content-grid,
  .status-panel,
  .file-source-grid {
    grid-template-columns: 1fr;
  }

  .chart-figure {
    grid-template-columns: 1fr;
  }

  .chart-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-dialog-body {
    grid-template-columns: 1fr;
  }

  .chart-dialog-actions {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    justify-content: end;
  }

  .chart-dialog-plot {
    height: 100%;
    min-height: 0;
  }

  .fc-controls {
    grid-template-columns: 1fr;
  }
}
