/* Editor tab styles. Tokens come from style.css :root. */

.ed-wrapper {
  --ed-strip: 36px;
  display: flex;
  flex-direction: row;
  flex: 1;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.ed-wrapper > #chart-container {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

/* ── Toolbar ── */
.ed-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--secondary);
  flex-shrink: 0;
}

.ed-btn {
  border: 1px solid transparent;
  color: #fff;
  padding: 6px 14px;
  min-height: 32px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: bold;
  transition: opacity 0.2s;
}

.ed-btn:hover:not(:disabled) { opacity: 0.85; }
.ed-btn:disabled { opacity: 0.6; cursor: default; }

.ed-btn--primary { background: var(--accent-strong); }
.ed-btn--secondary { background: var(--secondary); border-color: var(--accent); }

.ed-status {
  font-size: 13px;
  margin-left: 4px;
  color: var(--text-muted);
}
.ed-status.is-ok { color: var(--status-ok); }
.ed-status.is-error { color: var(--status-error); }

/* ── Settings panel ── */
.ed-panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--secondary);
  overflow: hidden;
  flex-shrink: 0;
  width: 280px;
  transition: width 0.2s;
}

.ed-panel.is-collapsed { width: var(--ed-strip); }
.ed-panel.is-collapsed .ed-panel-content { display: none; }

.ed-panel-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  background: var(--secondary);
  border: none;
  border-bottom: 1px solid var(--secondary);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  min-width: 24px;
  min-height: 36px;
  padding: 8px 10px;
  flex-shrink: 0;
  white-space: nowrap;
}

.ed-panel.is-collapsed .ed-panel-toggle { justify-content: center; padding-left: 0; padding-right: 0; }
.ed-panel.is-collapsed .ed-panel-toggle .ed-icon:first-child { display: none; }

.ed-icon { flex-shrink: 0; display: block; }

.ed-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ed-section-label {
  font-size: 11px;
  font-weight: bold;
  color: var(--accent-text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--secondary);
  margin-top: 4px;
}

/* ── Toggle switch ── */
.ed-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  padding: 2px 0;
}

.ed-toggle-label { flex: 1; line-height: 1.3; }

.ed-toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

/* visually hidden but focusable and exposed to assistive tech */
.ed-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.ed-toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  background: var(--control-off);
  transition: background 0.2s;
}

.ed-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  pointer-events: none;
}

.ed-toggle input:checked + .ed-toggle-track { background: var(--accent); }
.ed-toggle input:checked + .ed-toggle-track .ed-toggle-thumb { transform: translateX(18px); }
.ed-toggle input:focus-visible + .ed-toggle-track {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

/* ── Slider / number ── */
.ed-slider-row { display: flex; flex-direction: column; gap: 3px; }

.ed-slider-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text);
}

.ed-slider-value { color: var(--accent-text); }

.ed-control-label { font-size: 12px; color: var(--text); flex: 1; }

.ed-slider { width: 100%; accent-color: var(--accent); }

.ed-number-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ed-input-number {
  width: 70px;
  flex-shrink: 0;
  background: var(--secondary);
  border: 1px solid var(--control-off);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
  font: inherit;
  font-size: 12px;
}

/* ── Fields section ── */
.ed-fields { display: flex; flex-direction: column; gap: 12px; }

.ed-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ed-subhead-label { font-size: 12px; font-weight: bold; color: var(--text); }

.ed-well {
  background: var(--well);
  border-radius: 4px;
  padding: 10px;
}

.ed-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-fields > .ed-chips { min-height: 48px; }

.ed-rows { display: flex; flex-direction: column; gap: 8px; }

.ed-row-card { position: relative; }

.ed-row-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.ed-row-label { font-size: 11px; color: var(--text-muted); }

.ed-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--secondary);
  color: var(--text);
  border: 1px solid var(--hairline);
  font-size: 13px;
  padding: 3px 4px 3px 10px;
  border-radius: 20px;
}

.ed-chip-text { overflow-wrap: anywhere; }

.ed-icon-btn,
.ed-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  min-width: 24px;
  min-height: 24px;
  border-radius: 4px;
  flex-shrink: 0;
}

.ed-chip-remove { border-radius: 50%; position: relative; }

.ed-icon-btn:hover,
.ed-chip-remove:hover { color: var(--text); background: var(--hairline); }

.ed-btn-micro,
.ed-btn-add-row {
  background: var(--secondary);
  border: 1px solid var(--hairline);
  color: var(--text);
  font: inherit;
  font-weight: bold;
  letter-spacing: 0.04em;
  cursor: pointer;
  min-height: 24px;
}

.ed-btn-micro { font-size: 10px; padding: 4px 8px; border-radius: 12px; }
.ed-btn-add-row { font-size: 11px; padding: 6px 14px; border-radius: 4px; align-self: flex-start; }

.ed-btn-micro:hover,
.ed-btn-add-row:hover { border-color: var(--accent); }

.ed-input-text {
  background: var(--well);
  border: 1px solid var(--control-off);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 12px;
  width: 100px;
  max-width: 100%;
}

/* ── Focus: every editor control ── */
.ed-btn:focus-visible,
.ed-panel-toggle:focus-visible,
.ed-icon-btn:focus-visible,
.ed-chip-remove:focus-visible,
.ed-btn-micro:focus-visible,
.ed-btn-add-row:focus-visible,
.ed-input-number:focus-visible,
.ed-input-text:focus-visible,
.ed-slider:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

.ed-panel-toggle:focus-visible { outline-offset: -2px; }

/* ── Narrow viewports: panel overlays the chart ── */
@media (max-width: 719px) {
  .ed-wrapper > #chart-container { margin-left: var(--ed-strip); }

  .ed-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 5;
    width: min(280px, 85vw);
  }

  .ed-panel.is-collapsed { width: var(--ed-strip); }
}

/* ── Touch: 44px targets ── */
@media (pointer: coarse) {
  .ed-wrapper { --ed-strip: 44px; }

  .ed-btn { min-height: 44px; padding: 8px 16px; }
  .ed-panel-toggle { min-height: 44px; min-width: 44px; }
  .ed-icon-btn { min-width: 44px; min-height: 44px; }
  .ed-btn-micro,
  .ed-btn-add-row { min-height: 44px; padding-left: 14px; padding-right: 14px; }
  .ed-toggle-row { min-height: 44px; }
  .ed-input-number { min-height: 44px; font-size: 16px; }
  .ed-input-text { min-height: 44px; font-size: 16px; }

  /* keep the chip compact; expand only the hit area */
  .ed-chip-remove::after {
    content: '';
    position: absolute;
    inset: -10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ed-panel,
  .ed-btn,
  .ed-toggle-track,
  .ed-toggle-thumb {
    transition-duration: 0.01ms;
  }
}
