/* ============================================================
   Version History (F5)
   Per-prompt timeline dialog: rail + diff main pane, named
   versions (Pro), manual snapshots. Tokens only — no hardcoded
   colors; diff tints via color-mix over semantic tokens.
   ============================================================ */

/* ---------- Dialog shell ---------- */

.vh-modal .vh-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: min(64rem, 94vw);
  max-width: 64rem;
  padding: var(--space-4);
}

.vh-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.vh-heading {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.vh-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.vh-subtitle {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vh-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.vh-snapshot-btn {
  white-space: nowrap;
}

.vh-close {
  line-height: 1;
}

.vh-loading {
  margin: 0;
  padding: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ---------- Layout: timeline rail + main pane ---------- */

.vh-layout {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: var(--space-3);
  min-height: 18rem;
}

.vh-rail {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow-y: auto;
  max-height: min(60vh, 32rem);
  padding-inline-end: var(--space-1);
  border-inline-end: 1px solid var(--border-primary);
}

.vh-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

/* ---------- Timeline entries ---------- */

.vh-rail-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  width: 100%;
  padding: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  text-align: start;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.vh-rail-item:hover {
  background: var(--surface-secondary);
}

.vh-rail-item:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 1px;
}

.vh-rail-item.is-selected {
  background: var(--surface-secondary);
  border-color: var(--brand-500);
}

.vh-rail-time-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
}

.vh-rail-relative {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.vh-rail-item.is-current .vh-rail-relative {
  color: var(--text-brand);
}

.vh-current-marker {
  display: inline-block;
  padding: 0 var(--space-2);
  border-radius: var(--radius-full, 999px);
  background: color-mix(in srgb, var(--brand-500) 14%, var(--surface-primary));
  border: 1px solid color-mix(in srgb, var(--brand-500) 40%, var(--border-primary));
  color: var(--text-brand);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.vh-rail-absolute {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.vh-name-badge {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 var(--space-2);
  border-radius: var(--radius-full, 999px);
  background: var(--surface-tertiary);
  color: var(--text-primary);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

.vh-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.vh-chip {
  display: inline-block;
  padding: 0 var(--space-1);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  background: var(--surface-secondary);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

/* ---------- Toolbar ---------- */

.vh-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.vh-tabs {
  display: inline-flex;
  gap: var(--space-1);
  padding: var(--space-1);
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
}

.vh-tab {
  padding: var(--space-1) var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.vh-tab:hover {
  color: var(--text-primary);
}

.vh-tab:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 1px;
}

.vh-tab.is-active {
  background: var(--surface-primary);
  border-color: var(--border-primary);
  color: var(--text-primary);
  font-weight: var(--font-medium);
}

.vh-compare {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-inline-start: auto;
}

.vh-compare-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.vh-compare-select {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--surface-primary);
  color: var(--text-primary);
  font-size: var(--text-sm);
}

.vh-compare-select:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 1px;
}

.vh-layout-toggle {
  flex-shrink: 0;
}

/* ---------- Diff rendering ---------- */

.vh-diff-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 8rem;
}

.vh-diff-note {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.vh-version-text,
.vh-diff {
  margin: 0;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.5;
  overflow: auto;
  max-height: min(46vh, 26rem);
}

.vh-version-text {
  padding: var(--space-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-primary);
}

.vh-diff--unified {
  padding: var(--space-1) 0;
}

.vh-diff--split {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.vh-diff-col {
  min-width: 0;
  padding: var(--space-1) 0;
}

.vh-diff-col--old {
  border-inline-end: 1px solid var(--border-primary);
}

.vh-line {
  padding: 0 var(--space-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-primary);
}

.vh-line--add {
  background: color-mix(in srgb, var(--success-500) 12%, var(--surface-secondary));
}

.vh-line--del {
  background: color-mix(in srgb, var(--danger-500) 10%, var(--surface-secondary));
}

.vh-line--spacer {
  background: var(--surface-tertiary);
  opacity: 0.5;
}

.vh-word {
  background: transparent;
  color: inherit;
  border-radius: var(--radius-sm);
}

.vh-word--add {
  background: color-mix(in srgb, var(--success-500) 32%, var(--surface-secondary));
  font-weight: var(--font-medium);
}

.vh-word--del {
  background: color-mix(in srgb, var(--danger-500) 28%, var(--surface-secondary));
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

/* ---------- Name / note editor (Pro) ---------- */

.vh-meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
}

.vh-meta-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.vh-meta-label {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.vh-pro-badge {
  flex-shrink: 0;
}

.vh-meta-locked {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.vh-upgrade-btn {
  align-self: flex-start;
}

.vh-meta-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) auto;
  align-items: start;
  gap: var(--space-2);
}

.vh-meta-name,
.vh-meta-note {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--surface-primary);
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
}

.vh-meta-note {
  resize: vertical;
  min-height: 2.4rem;
}

.vh-meta-name:focus-visible,
.vh-meta-note:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 1px;
}

.vh-meta-save {
  align-self: start;
  white-space: nowrap;
}

.vh-restore-btn,
.vh-copy-btn {
  flex-shrink: 0;
}

/* ---------- Actions / empty state ---------- */

.vh-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.vh-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  text-align: center;
}

.vh-empty-icon {
  font-size: var(--text-2xl);
}

.vh-empty-title {
  margin: 0;
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.vh-empty-help {
  margin: 0;
  max-width: 32rem;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .vh-layout {
    grid-template-columns: 1fr;
  }

  .vh-rail {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    padding-block-end: var(--space-1);
    border-inline-end: none;
    border-block-end: 1px solid var(--border-primary);
  }

  .vh-rail-item {
    min-width: 12rem;
    flex-shrink: 0;
  }

  .vh-diff--split {
    grid-template-columns: 1fr;
  }

  .vh-diff-col--old {
    border-inline-end: none;
    border-block-end: 1px solid var(--border-primary);
  }

  .vh-meta-row {
    grid-template-columns: 1fr;
  }

  .vh-compare {
    margin-inline-start: 0;
  }
}

/* ---------- Dark mode ----------
   All colors above are semantic tokens remapped by the dark theme;
   diff tints mix over --surface-secondary, so they track the theme.
   Word-level emphasis gets a slightly stronger mix for contrast. */

:root[data-theme="dark"] .vh-word--add {
  background: color-mix(in srgb, var(--success-500) 38%, var(--surface-secondary));
}

:root[data-theme="dark"] .vh-word--del {
  background: color-mix(in srgb, var(--danger-500) 34%, var(--surface-secondary));
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .vh-rail-item,
  .vh-tab {
    transition: none;
  }
}
