/* ── Plot Grid (Feature 9) ──────────────────────────────────────────────── */

/* Outer wrapper — full height flex column */
.plot-grid-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
  font-family: var(--font-ui);
}

/* Toolbar row */
.plot-grid-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Add Thread button */
.plot-add-thread {
  padding: 0.3rem 0.75rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius, 6px);
  font-size: var(--font-sm, 0.85rem);
  font-family: var(--font-ui);
  cursor: pointer;
  transition: opacity 0.15s;
}
.plot-add-thread:hover {
  opacity: 0.85;
}
.plot-add-thread:active {
  opacity: 0.7;
}

/* Scrollable table area */
.plot-grid-scroll {
  flex: 1;
  overflow: auto;
  overflow-x: auto;
  overflow-y: auto;
}

/* Empty state message */
.plot-grid-empty {
  padding: 2rem 1.5rem;
  color: var(--muted);
  font-size: var(--font-sm, 0.85rem);
  text-align: center;
}

/* ── Table ── */
.plot-grid-table {
  border-collapse: collapse;
  min-width: max-content;
  width: 100%;
  table-layout: fixed;
}

.plot-grid-table th,
.plot-grid-table td {
  border: 1px solid var(--border);
  min-width: 160px;
  vertical-align: top;
}

/* Sticky column header (Thread label) */
.plot-thread-header-cell {
  width: 200px;
  min-width: 200px;
  position: sticky;
  left: 0;
  background: var(--bg);
  z-index: 2;
}

/* All thead th — sticky top */
.plot-grid-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Thread-header intersection: both sticky left AND sticky top */
.plot-grid-table thead .plot-thread-header-cell {
  z-index: 3;
}

/* ── Thread row ── */
.plot-thread-row {
  transition: background 0.1s;
}
.plot-thread-row:hover {
  background: rgba(255, 255, 255, 0.015);
}

/* Drop indicator when dragging over a row */
.plot-thread-row.plot-drop-indicator {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Row being dragged */
.plot-thread-row.plot-dragging {
  opacity: 0.45;
}

/* ── Thread label cell ── */
.plot-thread-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.5rem;
  cursor: grab;
  background: var(--surface);
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 200px;
  width: 200px;
}
.plot-thread-label:active {
  cursor: grabbing;
}

/* Drag handle icon */
.plot-thread-drag-handle {
  color: var(--muted);
  font-size: 1.1rem;
  cursor: grab;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
}
.plot-thread-drag-handle:active {
  cursor: grabbing;
}

/* Color swatch */
.plot-thread-color-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
}
.plot-thread-color-swatch:hover {
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.15);
}

/* Thread title input */
.plot-thread-title-input {
  border: none;
  background: transparent;
  font-size: 0.85rem;
  font-family: var(--font-ui);
  flex: 1;
  color: var(--text);
  outline: none;
  min-width: 0;
  padding: 0.1rem 0.2rem;
  border-radius: 3px;
  transition: outline 0.1s;
}
.plot-thread-title-input:focus {
  outline: 1px solid var(--accent);
}

/* Delete thread button — hidden until row hover */
.plot-thread-delete {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--error, #ef4444);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
  border-radius: 3px;
  flex-shrink: 0;
  transition: opacity 0.15s, background 0.15s;
}
.plot-thread-row:hover .plot-thread-delete {
  opacity: 1;
}
.plot-thread-delete:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* ── Plot cells ── */
.plot-cell {
  padding: 0.3rem 0.4rem;
  min-height: 80px;
  position: relative;
  vertical-align: top;
}
.plot-cell:focus-within {
  background: var(--surface-2, rgba(255, 255, 255, 0.03));
}

/* Editable cell content */
.plot-cell-content {
  min-height: 60px;
  font-size: 0.82rem;
  line-height: 1.4;
  outline: none;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}
.plot-cell-content:focus {
  background: var(--surface-2, rgba(255, 255, 255, 0.03));
}
.plot-cell-content:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

/* Link button — hidden until cell hover */
.plot-cell-link-btn {
  position: absolute;
  bottom: 0.2rem;
  right: 0.2rem;
  opacity: 0;
  font-size: 0.8rem;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
  border-radius: 3px;
  line-height: 1;
  transition: opacity 0.15s, background 0.1s;
  color: var(--muted);
}
.plot-cell:hover .plot-cell-link-btn {
  opacity: 1;
}
.plot-cell-link-btn:hover {
  background: var(--surface);
  color: var(--accent);
}

/* Linked scene chips container */
.plot-cell-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  margin-top: 0.25rem;
}

/* Individual scene chip */
.plot-scene-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  background: var(--accent-light, rgba(99, 149, 237, 0.15));
  color: var(--accent);
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 99px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}
.plot-scene-chip-remove {
  cursor: pointer;
  font-style: normal;
  opacity: 0.65;
  flex-shrink: 0;
  line-height: 1;
  padding: 0 0.1rem;
  border-radius: 50%;
  transition: opacity 0.1s, background 0.1s;
}
.plot-scene-chip-remove:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

/* ── Scene picker floating panel ── */
.plot-scene-picker {
  position: fixed;
  z-index: 500;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  padding: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
  min-width: 200px;
  font-family: var(--font-ui);
}

.plot-scene-picker-item {
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.82rem;
  color: var(--text);
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plot-scene-picker-item:hover {
  background: var(--surface);
}
.plot-scene-picker-item.is-linked {
  color: var(--accent);
  font-weight: 600;
}
.plot-scene-picker-item.is-linked::after {
  content: ' ✓';
  opacity: 0.75;
}
.plot-scene-picker-empty {
  color: var(--muted);
  cursor: default;
  font-style: italic;
}
.plot-scene-picker-empty:hover {
  background: transparent;
}

/* ── Color picker popover ── */
.plot-color-picker-popover {
  position: absolute;
  z-index: 501;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.4rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 120px;
}

.plot-color-option {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.1s, transform 0.1s;
  flex-shrink: 0;
}
.plot-color-option:hover {
  border-color: #fff;
  transform: scale(1.15);
}
