/* hexports application styles */
* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--page);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.shell {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(var(--blur-panel));
  -webkit-backdrop-filter: blur(var(--blur-panel));
}

.sidebar {
  padding: 16px;
  order: 2;
}

.content {
  padding: 0;
  order: 1;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
  margin-bottom: 4px;
}

h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

.section {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.section:first-child {
  border-top: 0;
  padding-top: 0;
}

.dropzone {
  border: 1px dashed var(--accent);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  background: var(--accent-soft);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
}

.dropzone:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.dropzone.over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

input[type="file"],
select,
input[type="date"],
input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  border: 1px solid transparent;
  background: var(--surface-sunk);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  transition: all 0.15s;
}

input:focus,
select:focus,
textarea:focus,
input:hover,
select:hover,
textarea:hover {
  background: var(--surface);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.smooth-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-muted);
  padding: 0 2px;
  margin-top: 4px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

label span {
  display: flex;
  justify-content: space-between;
}

.hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.meta-kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1px 10px;
  font-size: 11px;
  margin: 6px 0 8px;
}

.meta-kv .hint {
  line-height: 1.7;
}

.series-list,
.marker-list,
.stats {
  display: grid;
  gap: 8px;
}

.series-item,
.marker-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 12px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.series-item:hover,
.marker-item:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--line-strong);
}

.series-item {
  display: grid;
  gap: 10px;
}

.series-top,
.marker-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  background: var(--surface-sunk);
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-pill);
  display: inline-block;
  flex: none;
}

.chart-card {
  position: relative;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 12px;
  box-shadow: var(--shadow-md);
}

.toolbar {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 12px;
  align-items: center;
}

.toolbar-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.toolbar-group--secondary {
  justify-content: flex-end;
}

.toolbar-group--secondary #summaryChip {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-group--secondary .btn-pair {
  flex: none;
}

.canvas-wrap {
  position: relative;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  min-height: clamp(280px, 45dvh, 500px);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: clamp(280px, 45dvh, 500px);
  cursor: grab;
  touch-action: none;
}

canvas.dragging {
  cursor: grabbing;
}

canvas:focus-visible {
  outline: 3px solid var(--accent-ring);
  outline-offset: -3px;
}

.canvas-wrap.range-mode canvas {
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 16px;
}

.tooltip {
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-width: 160px;
  box-shadow: var(--shadow-hover);
  backdrop-filter: blur(var(--blur-panel));
  -webkit-backdrop-filter: blur(var(--blur-panel));
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
  font-size: 11px;
  line-height: 1.6;
  pointer-events: none;
}

.tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
}

.inline {
  display: flex;
  gap: 10px;
  align-items: center;
}

.inline>* {
  flex: 1;
  min-width: 0;
}

.marker-list button {
  width: auto;
  justify-self: start;
}

.series-controls {
  display: grid;
  gap: 10px;
}

.series-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 6px;
}

.series-grid input[type="range"] {
  margin: 0;
}

.series-control-row,
.series-width-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.series-width {
  display: grid;
  gap: 8px;
}

.palette {
  display: grid;
  grid-template-columns: repeat(8, 18px);
  justify-content: start;
  gap: 6px;
}

.palette-block {
  display: grid;
  gap: 8px;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  padding: 0;
  min-width: 18px;
  background: transparent;
  box-shadow: none;
  display: inline-grid;
  place-items: center;
}

.swatch.selected {
  border-color: var(--text);
  transform: scale(1.15);
  z-index: 1;
}

.swatch span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--swatch-color);
  border-radius: var(--radius-pill);
}

.marker-item {
  display: grid;
  gap: 4px;
}

.annotation-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.range-list {
  display: grid;
  gap: 8px;
}

.range-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.range-stats {
  display: grid;
  gap: 5px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.range-stat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  color: var(--text-muted);
  font-size: 11px;
}

.range-stat strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.annotation-mode .segmented__btn {
  min-width: 64px;
}

.unit-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text-muted);
}

.marker-list {
  margin-top: 8px;
}

.marker-help {
  margin-bottom: var(--space-2);
}

.agg-section {
  margin-top: 20px;
  display: none;
}

.agg-section.visible {
  display: block;
}

.agg-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.agg-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  max-height: 340px;
  overflow-y: auto;
}

.agg-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.agg-wrap thead th {
  text-align: right;
  padding: 8px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}

.agg-wrap thead th:first-child {
  text-align: left;
}

.agg-wrap td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.agg-wrap tr:last-child td {
  border-bottom: none;
}

.agg-wrap tr:hover td {
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.agg-wrap td:first-child {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
}

/* Slot items */
.slot-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--surface);
  margin-bottom: 8px;
}

.slot-item:last-of-type {
  margin-bottom: 0;
}

.slot-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.slot-axis-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
  flex: none;
  padding: 2px 5px;
  background: var(--surface-sunk);
  border-radius: var(--radius-xs);
}

.slot-header select {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  padding: 5px 8px;
}

.slot-remove-btn {
  flex: none;
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1;
}

/* Annotation popups stay visible even when their chart card is off-screen. */
.marker-popup-wrap {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.marker-popup {
  position: fixed;
  pointer-events: all;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 12px;
  width: 220px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: var(--shadow-hover);
  display: none;
  z-index: 1100;
}

.marker-popup.visible {
  display: block;
}

.range-popup {
  width: 260px;
}

.marker-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.marker-popup-header strong {
  font-size: 12px;
}

.marker-popup-form {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.marker-popup-form > *,
.marker-popup-form input,
.popup-buttons > button {
  min-width: 0;
}

.marker-popup-form label {
  gap: 4px;
}

.popup-buttons {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.popup-buttons button:first-child {
  flex: 1;
}

@media (min-width: 1080px) {
  .shell {
    flex-direction: row;
    gap: 20px;
    align-items: flex-start;
  }

  .sidebar {
    flex: 0 0 300px;
    position: sticky;
    top: 24px;
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
    padding: 20px;
  }

  .content {
    flex: 1;
    min-width: 0;
  }

  .chart-card {
    padding: 20px;
  }
}

@media (max-width: 1079px) {
  .shell {
    padding: 12px;
    gap: 12px;
  }

  .sidebar {
    padding: 16px;
  }

  .chart-card {
    padding: 12px;
    border-radius: var(--radius-lg);
  }

  canvas,
  .empty,
  .canvas-wrap {
    min-height: 280px;
    height: 40dvh;
  }
}

/* Donation Widget */
.kofi-floater {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 52px;
  height: 52px;
  background: var(--glass);
  backdrop-filter: blur(var(--blur-panel));
  -webkit-backdrop-filter: blur(var(--blur-panel));
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10000;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--text-muted);
}

.kofi-floater:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: var(--shadow-hover);
  color: var(--accent);
  border-color: var(--accent);
}

.kofi-floater svg {
  width: 28px;
  height: 28px;
}

.kofi-panel {
  position: fixed;
  bottom: 84px;
  left: 24px;
  width: 400px;
  height: 660px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 120px);
  background: var(--glass);
  backdrop-filter: blur(var(--blur-panel));
  -webkit-backdrop-filter: blur(var(--blur-panel));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-hover);
  z-index: 9999;
  overflow: hidden;
  animation: kofiAppear 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.kofi-frame {
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
}

@keyframes kofiAppear {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.kofi-trigger.hidden, .kofi-floater.hidden, .kofi-panel.hidden { display: none; }

.brand-icon {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
}

#sourceName {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  min-height: 0;
}

.stage {
  overflow-y: auto;
}

.chart-card {
  min-height: 100%;
  padding: var(--space-4);
}

.toolbar {
  min-height: 32px;
  margin-bottom: var(--space-3);
}

.toolbar-group {
  flex-wrap: nowrap;
}

.add-dataset {
  width: 100%;
  margin-top: var(--space-2);
}

.add-dataset[hidden] {
  display: none;
}

.tooltip {
  border: 1px solid var(--tooltip-line);
}

.tooltip-date {
  margin-bottom: var(--space-1);
  opacity: 0.7;
}

.series-color-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  vertical-align: middle;
  background: var(--series-color);
  border-radius: var(--radius-pill);
}

.table-color-dot {
  width: 7px;
  height: 7px;
  margin-right: var(--space-1);
}

.mobile-readout {
  display: none;
  margin-top: var(--space-2);
  padding: var(--space-3);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.5;
}

@media (max-width: 900px) {
  .chart-card {
    min-height: auto;
  }
}

@media (max-width: 760px) {
  .toolbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .toolbar-group--secondary {
    justify-content: space-between;
  }
}

@media (max-width: 640px) {
  .appbar__sep,
  #sourceName {
    display: none;
  }

  .chart-card {
    padding: var(--space-2);
  }

  .toolbar {
    margin-inline: calc(-1 * var(--space-2));
    padding-inline: var(--space-2);
  }

  .toolbar-group {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toolbar-group::-webkit-scrollbar {
    display: none;
  }

  .toolbar-group--secondary {
    justify-content: flex-start;
  }

  .toolbar-group--secondary #summaryChip {
    flex: none;
  }

  .tooltip {
    display: none;
  }

  .mobile-readout {
    display: block;
  }

  .kofi-floater {
    left: var(--space-3);
    bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  }

  .kofi-panel {
    left: var(--space-3);
    bottom: calc(76px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 2 * var(--space-3));
  }
}

@media (hover: none) and (pointer: coarse) {
  .palette {
    grid-template-columns: repeat(8, 44px);
    overflow-x: auto;
  }

  .swatch {
    width: 44px;
    height: 44px;
    padding: 10px;
  }
}
