/* chartai Canvas Demo — Dark mode only */

:root {
  --bg: #08080c;
  --bg-warm: #0c0c12;
  --surface: #14141e;
  --surface-hover: #1a1a28;
  --surface-active: #222234;
  --border: #262638;
  --border-light: #2e2e44;
  --text: #e0e0ec;
  --text-dim: #8888a0;
  --text-muted: #555570;
  --accent: #6c8aff;
  --accent-hover: #8aa4ff;
  --accent-dim: rgba(108, 138, 255, 0.15);
  --danger: #ff5566;
  --danger-dim: rgba(255, 85, 102, 0.12);
  --success: #44cc88;
  --warning: #ffbb44;
  --chart-bg: #0e0e16;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ============================================
   Toolbar
   ============================================ */

.toolbar {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  z-index: 200;
  position: relative;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.logo-sub {
  font-weight: 400;
  color: var(--text-dim);
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.toolbar-spacer {
  flex: 1;
}

.toolbar-stats {
  display: flex;
  gap: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.stat-value {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.toolbar-btn {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
  white-space: nowrap;
}

.toolbar-btn:hover {
  background: var(--surface-active);
  border-color: var(--border-light);
}

.toolbar-btn:active {
  transform: scale(0.97);
}

.toolbar-btn.danger {
  color: var(--danger);
}

.toolbar-btn.danger:hover {
  background: var(--danger-dim);
}

/* Toggle */
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.toggle input {
  display: none;
}

.toggle-slider {
  width: 36px;
  height: 20px;
  background: var(--surface-active);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--text-dim);
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition:
    transform 0.2s,
    background 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(16px);
  background: white;
}

.toggle-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

/* Dropdown */
.dropdown {
  position: relative;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 300;
  min-width: 140px;
  padding: 4px;
  flex-direction: column;
}

.dropdown-menu.open {
  display: flex;
}

.dropdown-menu button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}

.dropdown-menu button:hover {
  background: var(--surface-hover);
}

/* ============================================
   Viewport & Canvas
   ============================================ */

.viewport {
  position: relative;
  width: 100%;
  height: calc(100vh - 48px);
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.07) 1px,
    transparent 1px
  );
  background-size: 24px 24px;
  cursor: grab;
}

.viewport.grabbing {
  cursor: grabbing;
}

.canvas {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  /* No size needed — children are absolute */
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  background: radial-gradient(
    ellipse 70% 65% at 50% 50%,
    transparent 0%,
    rgba(8, 8, 12, 0.18) 55%,
    rgba(8, 8, 12, 0.38) 75%,
    rgba(8, 8, 12, 0.98) 100%
  );
}

.zoom-indicator {
  position: absolute;
  bottom: 16px;
  right: 16px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.zoom-indicator.visible {
  opacity: 1;
}

/* ============================================
   Chart Tile
   ============================================ */

.chart-tile {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: visible;
  transition: box-shadow 0.2s;
}

.chart-tile:hover {
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.6);
}

.chart-tile.dragging {
  z-index: 50;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.7);
  opacity: 0.92;
}

.chart-tile.resizing {
  z-index: 50;
}

/* Tile Header */
.tile-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  cursor: grab;
  min-height: 36px;
  flex-shrink: 0;
}

.tile-header:active {
  cursor: grabbing;
}

.tile-name {
  flex: 0 0 auto;
  width: 60px; /* auto-sized by JS */
  min-width: 20px;
  max-width: 200px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.tile-name:hover {
  border-color: var(--border);
  background: var(--surface-hover);
}

.tile-name:focus {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.tile-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.tile-type {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.tile-points {
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 7px;
  border-radius: 3px;
  flex-shrink: 0;
}

.tile-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
  transition:
    background 0.12s,
    color 0.12s;
  flex-shrink: 0;
}

.tile-btn:hover {
  background: var(--surface-active);
  color: var(--text);
}

.tile-btn.danger:hover {
  background: var(--danger-dim);
  color: var(--danger);
}

.tile-btn svg {
  width: 14px;
  height: 14px;
}

/* Point Size Slider (scatter charts) */
.tile-point-size {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.point-size-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 48px;
  height: 3px;
  background: var(--surface-active);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.point-size-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.1s;
}

.point-size-slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
}

.point-size-slider::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.point-size-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 22px;
  font-variant-numeric: tabular-nums;
}

/* Tile Body (chart container) */
.tile-body {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Resize Handles */
.resize-handle {
  position: absolute;
  z-index: 5;
}

.resize-n {
  top: -4px;
  left: 12px;
  right: 12px;
  height: 8px;
  cursor: n-resize;
}

.resize-s {
  bottom: -4px;
  left: 12px;
  right: 12px;
  height: 8px;
  cursor: s-resize;
}

.resize-e {
  right: -4px;
  top: 12px;
  bottom: 12px;
  width: 8px;
  cursor: e-resize;
}

.resize-w {
  left: -4px;
  top: 12px;
  bottom: 12px;
  width: 8px;
  cursor: w-resize;
}

.resize-ne {
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  cursor: ne-resize;
}

.resize-nw {
  top: -4px;
  left: -4px;
  width: 14px;
  height: 14px;
  cursor: nw-resize;
}

.resize-se {
  bottom: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  cursor: se-resize;
}

.resize-sw {
  bottom: -4px;
  left: -4px;
  width: 14px;
  height: 14px;
  cursor: sw-resize;
}

/* ============================================
   GPU Chart Styles (from chart library)
   ============================================ */

.gpu-chart {
  width: 100%;
  height: 100%;
  position: relative;
}

.gpu-chart-canvas-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  touch-action: none;
  cursor: grab;
  background: var(--chart-bg);
  overflow: hidden;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.gpu-chart-canvas-wrap:active {
  cursor: grabbing;
}

.gpu-chart-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.gpu-chart-axis-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* ============================================
   Context Menu
   ============================================ */

.context-menu {
  display: none;
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 500;
  min-width: 160px;
  padding: 4px;
  flex-direction: column;
}

.context-menu.open {
  display: flex;
}

.context-menu button {
  display: block;
  width: 100%;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}

.context-menu button:hover {
  background: var(--surface-hover);
}

/* ============================================
   Modal (Data Source Dialog)
   ============================================ */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 600;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 560px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s;
}

.modal-close:hover {
  background: var(--surface-active);
  color: var(--text);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* Presets — scrollable with sticky category headers */
.presets {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.presets::-webkit-scrollbar {
  width: 5px;
}
.presets::-webkit-scrollbar-track {
  background: transparent;
}
.presets::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.preset-category {
  /* nothing special — just groups header + items */
}

.preset-category-header {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.preset-category-items {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px 10px;
}

.preset-btn {
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-dim);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background 0.12s,
    color 0.12s,
    border-color 0.12s;
  white-space: nowrap;
}

.preset-btn:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

.preset-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.field-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

.field-hint code {
  font-size: 11px;
  background: var(--surface-active);
  padding: 1px 5px;
  border-radius: 3px;
}

.field-input {
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.field-input:focus {
  border-color: var(--accent);
}

.field-textarea {
  padding: 10px 12px;
  font-size: 12px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  line-height: 1.5;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.15s;
  tab-size: 2;
}

.field-textarea:focus {
  border-color: var(--accent);
}

.modal-error {
  font-size: 12px;
  color: var(--danger);
  background: var(--danger-dim);
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 85, 102, 0.2);
  word-break: break-word;
}

/* Buttons */
.btn {
  height: 34px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-accent {
  background: var(--accent);
  color: white;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-active);
}

/* ============================================
   Toast
   ============================================ */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--danger);
  color: white;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1000;
  transition: opacity 0.3s;
}

.toast.hidden {
  display: none;
}

/* ============================================
   Utility
   ============================================ */

.hidden {
  display: none !important;
}

/* Scrollbar styling for modal */
.modal::-webkit-scrollbar {
  width: 6px;
}

.modal::-webkit-scrollbar-track {
  background: transparent;
}

.modal::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.modal::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}
