:root {
  --black: #111;
  --accent: #E70565;
  --grey-mid: #767676;
  --grey-light: #d4d4d4;
  --grey-bg: #f5f5f5;
  --grid-line: #efefef;
  --white: #fff;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --panel-width: 336px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  color: var(--black);
  background: var(--white);
}

/* ── Layout ─────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
}

.app__header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--grey-light);
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.app__title {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0;
  color: var(--accent);
}

.app__description {
  color: var(--grey-mid);
  font-size: 0.875rem;
  margin: 0;
}

.app__file {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.app__filename {
  font-size: 1rem;
  color: var(--black);
  font-weight: 600;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app__body {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}

/* ── Dropzone (empty state) ─────────────────────────── */

.dropzone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  cursor: pointer;
  transition: background 0.15s;
}

.dropzone--drag-over {
  background: #fef0f5;
}

.dropzone__title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 0.5rem;
}

.dropzone__icon {
  width: 64px;
  height: 64px;
  color: var(--grey-mid);
}

.dropzone__text {
  font-size: 1rem;
  color: var(--grey-mid);
  text-align: center;
  margin: 0;
}

.dropzone__hint {
  font-size: 0.9375rem;
  color: var(--grey-mid);
}

.dropzone__input {
  display: none;
}

.dropzone__example-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.25em 0.5em;
}

.dropzone__example-btn:hover {
  color: #c40454;
}

/* ── Workspace (loaded state) ──────────────────────── */

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}

.workspace__chart-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.workspace__chart {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.workspace__chart .uplot {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  right: 0.5rem;
  bottom: 0.5rem;
}

/* ── Side panel ────────────────────────────────────── */

.panel {
  width: var(--panel-width);
  border-left: 1px solid var(--grey-light);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 0 0.75rem 0.75rem;
  font-size: 1rem;
  transition: width 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
}

.panel--collapsed {
  width: 0;
  padding: 0;
  opacity: 0;
  overflow: hidden;
  border-left: none;
}

/* ── Series list ───────────────────────────────────── */

.series-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.series-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  cursor: pointer;
  border-radius: 4px;
  position: relative;
  min-height: 2rem;
}

.series-item:hover {
  background: var(--grey-bg);
}

.series-item--hidden .series-item__colour,
.series-item--hidden .series-item__name,
.series-item--hidden .series-item__value,
.series-item--hidden .series-item__pct {
  opacity: 0.35;
}

.series-item__colour {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.series-item__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
}

.series-item__trailing {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.375rem;
  margin-left: auto;
  padding-right: 0.25rem;
}

.series-item__value {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--grey-mid);
  text-align: right;
}

.series-item__pct {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--grey-mid);
  min-width: 3.25rem;
  text-align: right;
}

.series-item__pct:empty {
  display: none;
}

.series-item__value:empty {
  min-width: 0;
}

.series-item__value--active {
  color: var(--black);
}

.series-item__btn {
  position: absolute;
  right: 1.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 3px;
  color: var(--grey-mid);
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.series-item__btn svg {
  width: 14px;
  height: 14px;
}

.series-item:hover .series-item__btn {
  opacity: 1;
  pointer-events: auto;
}

.series-list--hovering .series-item__btn {
  opacity: 0 !important;
  pointer-events: none !important;
}

.series-item__btn:hover {
  background: var(--grey-bg);
  color: var(--accent);
}

.series-item__drag {
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  cursor: grab;
  color: var(--grey-light);
  font-size: 1.125rem;
  line-height: 1;
  user-select: none;
  opacity: 0;
  transition: opacity 0.1s;
}

.series-item:hover .series-item__drag {
  opacity: 1;
  color: var(--grey-mid);
}

.series-list--hovering .series-item__drag {
  opacity: 0 !important;
}

.series-item--dragging {
  opacity: 0.5;
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

.series-item--drag-before::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

.series-item--drag-after::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

.series-item--total {
  border-radius: 0;
}

.series-list__divider {
  height: 1px;
  background: var(--grey-light);
  margin: 0.375rem 0.5rem;
}

/* ── Cursor tooltip ────────────────────────────────── */

.cursor-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(17, 17, 17, 0.9);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.1s;
}

.cursor-tooltip--visible {
  opacity: 1;
}

.panel__cursor-time {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--grey-mid);
  padding: 0 0.5rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
}

.panel__actions {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--grey-light);
  margin-bottom: 0.5rem;
}

.panel__config {
  border-top: 1px solid var(--grey-light);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
}

.panel__config-label {
  font-size: 0.875rem;
  color: var(--grey-mid);
  margin-bottom: 0.25rem;
  margin-top: 0.5rem;
}

.panel__config-label:first-child {
  margin-top: 0;
}

.panel__config-select {
  width: 100%;
}

#interpolation-wrap {
  margin-top: 0.75rem;
}

#fill-missing-wrap {
  margin-top: 0.5rem;
}

.panel__config-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.panel__config-checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 1.125rem;
  height: 1.125rem;
  border: 2px solid var(--grey-mid);
  border-radius: 3px;
  background: var(--white);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.panel__config-checkbox input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.panel__config-checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 45%;
  width: 5px;
  height: 9px;
  border: solid var(--white);
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -55%) rotate(45deg);
}

.series-item__value--interpolated {
  font-style: italic;
  opacity: 0.6;
}

.series-item__value--interpolated::before {
  content: '~';
}

.panel__warning {
  background: #fff0f5;
  border-left: 3px solid var(--accent);
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  color: var(--accent);
  margin: 0.5rem 0;
  border-radius: 0 3px 3px 0;
}

.button--small {
  font-size: 0.8125rem;
  padding: 0.3em 0.6em;
}

.button--active {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
}

.button--active:hover {
  background: #c70456;
}

/* ── Series config modal ───────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--white);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  width: min(420px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.modal__title {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0;
  flex: 1;
}

.modal__close {
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 4px;
  font-size: 1.5rem;
  color: var(--grey-mid);
}

.modal__close:hover {
  background: var(--grey-bg);
  color: var(--black);
}

.modal__field {
  margin-bottom: 1rem;
}

.modal__label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--grey-mid);
  margin-bottom: 0.3rem;
  letter-spacing: 0.01em;
}

.modal__input {
  width: 100%;
  padding: 0.5em 0.7em;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  border: 1.5px solid var(--grey-light);
  border-radius: 4px;
}

.modal__input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.modal__row {
  display: flex;
  gap: 1rem;
}

.modal__row .modal__field {
  flex: 1;
}

/* ── Custom checkbox ───────────────────────────────── */

.modal input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--grey-mid);
  border-radius: 4px;
  background: var(--white);
  cursor: pointer;
  position: relative;
  vertical-align: middle;
}

.modal input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.modal input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 45%;
  width: 6px;
  height: 10px;
  border: solid var(--white);
  border-width: 0 2.5px 2.5px 0;
  transform: translate(-50%, -55%) rotate(45deg);
}

.modal input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Status bar ────────────────────────────────────── */

.status-bar {
  border-top: 1px solid var(--grey-light);
  padding: 0.5rem 1.5rem;
  font-size: 0.8125rem;
  color: var(--grey-mid);
  display: flex;
  gap: 1.5rem;
  flex-shrink: 0;
}

/* ── Buttons ───────────────────────────────────────── */

.button {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.4em 0.8em;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid var(--grey-light);
  background: var(--white);
  color: var(--black);
  border-radius: 4px;
}

.button:hover { background: var(--grey-bg); }
.button:active { background: var(--grey-light); }
.button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ── Error ─────────────────────────────────────────── */

.error {
  color: var(--accent);
  background: #fff0f5;
  border-left: 4px solid var(--accent);
  padding: 0.6rem 0.875rem;
  margin: 0.75rem 1.25rem;
  font-size: 0.875rem;
}

/* ── Loading ───────────────────────────────────────── */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex: 1;
  color: var(--grey-mid);
}

.loading__spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--grey-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Drop overlay ──────────────────────────────────── */

.drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(231, 5, 101, 0.08);
  border: 3px dashed var(--accent);
  border-radius: 8px;
  z-index: 100;
  pointer-events: none;
}

.drop-overlay__label {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
}

/* ── Toolbar ───────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--grey-light);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  flex-shrink: 0;
  margin: 0 0.75rem;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}

.toolbar__spacer {
  flex: 1;
}

.toolbar__select {
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 0.4em 0.7em;
  border: 1.5px solid var(--grey-light);
  border-radius: 4px;
  background: var(--white);
  cursor: pointer;
}

.toolbar__select:hover {
  background: var(--grey-bg);
}

.toolbar__select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toolbar__separator {
  width: 1px;
  height: 1.5rem;
  background: var(--grey-light);
  flex-shrink: 0;
}

.toolbar__icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 4px;
  color: var(--grey-mid);
  flex-shrink: 0;
  padding: 0;
}

.toolbar__icon-btn:hover {
  background: var(--grey-bg);
  color: var(--accent);
}

.toolbar__icon-btn:active {
  background: var(--grey-light);
}

.toolbar__icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toolbar__icon-btn svg {
  width: 20px;
  height: 20px;
}

.toolbar__filename {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--black);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ── Responsive ────────────────────────────────────── */

@media (max-width: 700px) {
  .panel:not(.panel--collapsed) {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    background: var(--white);
    box-shadow: -4px 0 12px rgba(0,0,0,0.1);
    z-index: 10;
  }
}
