/**
 * QPHistoryDrawer — 0.8.5
 *
 * Lateral drawer for Quick Prompt version history + per-version
 * launch metrics. Pattern + token discipline mirrored from
 * AuditRecapPanel.css (0.8.4 #332/#333) so the same theme switching
 * (dark / light / sakura / matrix / batman) works without revisit.
 *
 * Class prefix `.qph-*`. Sister panel `.arp-*` shares the chrome
 * (overlay + drawer animation + close button) but lives in its own
 * file so future tweaks to one don't accidentally regress the other.
 */

/* ─── CTA button ───────────────────────────────────────────────────── */
.qph-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  font-size: var(--kr-fs-xs, 11px);
  background: var(--kr-bg-elevated);
  border: 1px solid var(--kr-border);
  border-radius: 6px;
  color: var(--kr-text-primary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.qph-cta:hover {
  background: var(--kr-bg-hover);
  border-color: var(--kr-border-medium);
}
.qph-cta:focus-visible {
  outline: 2px solid var(--kr-accent-ink);
  outline-offset: 2px;
}

/* ─── Overlay + drawer chrome ──────────────────────────────────────── */
.qph-overlay {
  position: fixed;
  inset: 0;
  background: var(--kr-bg-overlay, rgba(0, 0, 0, 0.5));
  z-index: 998;
  animation: qph-fade-in 0.15s ease-out;
}
.qph-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 560px;
  max-width: 95vw;
  background: var(--kr-bg-surface);
  border-left: 1px solid var(--kr-border-medium);
  box-shadow: -4px 0 24px var(--kr-bg-scrim, rgba(0, 0, 0, 0.3));
  z-index: 999;
  display: flex;
  flex-direction: column;
  color: var(--kr-text-primary);
  animation: qph-slide-in 0.22s ease-out;
}
@keyframes qph-fade-in {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes qph-slide-in {
  from { transform: translateX(100%); } to { transform: translateX(0); }
}

.qph-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--kr-border);
  background: var(--kr-bg-elevated);
}
.qph-drawer-title {
  margin: 0;
  font-size: var(--kr-fs-md, 14px);
  font-weight: 600;
  color: var(--kr-text-primary);
}
.qph-drawer-title-count {
  margin-left: 8px;
  color: var(--kr-text-dim);
  font-weight: 400;
}
.qph-drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--kr-text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.qph-drawer-close:hover {
  background: var(--kr-bg-hover);
  color: var(--kr-text-primary);
  border-color: var(--kr-border);
}

.qph-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.qph-empty { color: var(--kr-text-dim); font-style: italic; }
.qph-error { color: var(--kr-error); }

/* ─── Version cards ────────────────────────────────────────────────── */
.qph-versions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.qph-version-card {
  background: var(--kr-bg-elevated);
  border: 1px solid var(--kr-border);
  border-radius: 8px;
  padding: 10px 12px;
  transition: border-color 0.15s, background 0.15s;
}
.qph-version-card:hover {
  border-color: var(--kr-border-medium);
}
.qph-version-card[data-active="true"] {
  border-color: var(--kr-accent-ink);
}
.qph-version-card[data-current="true"] {
  /* Subtle accent strip on the left to flag the current version. */
  box-shadow: inset 3px 0 0 0 var(--kr-accent);
}

/* 0.8.5 — wrapper row that hosts the expand button + the delete
   icon side-by-side, so the trash doesn't trigger expand on click. */
.qph-version-card-header-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.qph-version-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--kr-text-primary);
  font-size: var(--kr-fs-sm, 13px);
  text-align: left;
  cursor: pointer;
}
.qph-version-delete {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--kr-text-dim);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.qph-version-delete:hover {
  background: rgba(var(--kr-error-rgb, 200, 80, 80), 0.10);
  border-color: var(--kr-error);
  color: var(--kr-error);
}
.qph-version-delete:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.qph-version-delete:focus-visible {
  outline: 2px solid var(--kr-error);
  outline-offset: 1px;
}
.qph-version-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--kr-bg-raised);
  border: 1px solid var(--kr-border);
  font-size: 11px;
  font-weight: 600;
  color: var(--kr-text-primary);
}
.qph-version-current-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(var(--kr-accent-rgb, 200, 255, 0), 0.16);
  color: var(--kr-accent-ink);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.qph-version-date {
  margin-left: auto;
  font-size: 11px;
  color: var(--kr-text-dim);
}

.qph-version-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--kr-text-dim);
}
.qph-meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  background: var(--kr-bg-raised);
  border: 1px solid var(--kr-border);
  border-radius: 4px;
  color: var(--kr-text-primary);
}
.qph-delta {
  margin-left: 4px;
  font-weight: 600;
}
.qph-delta-good { color: var(--kr-success); }
.qph-delta-bad  { color: var(--kr-warning); }

.qph-version-body {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--kr-border);
}
.qph-version-description {
  margin: 0 0 8px 0;
  font-size: 12px;
  color: var(--kr-text-secondary);
}
.qph-bindings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.qph-binding-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  background: var(--kr-bg-raised);
  border: 1px solid var(--kr-border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--kr-text-primary);
}

.qph-version-template-actions {
  margin-bottom: 6px;
}
.qph-diff-toggle {
  padding: 3px 8px;
  background: var(--kr-bg-raised);
  border: 1px solid var(--kr-border);
  border-radius: 4px;
  color: var(--kr-text-primary);
  font-size: 11px;
  cursor: pointer;
}
.qph-diff-toggle:hover {
  background: var(--kr-bg-hover);
  border-color: var(--kr-border-medium);
}

/* ─── Diff viewer ──────────────────────────────────────────────────── */
.qph-template-preview {
  margin: 0;
  padding: 8px;
  background: var(--kr-bg-raised);
  border: 1px solid var(--kr-border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--kr-text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow: auto;
}

.qph-diff {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  font-size: 11px;
  max-height: 420px;
  overflow: auto;
  background: var(--kr-bg-raised);
  border: 1px solid var(--kr-border);
  border-radius: 4px;
  padding: 6px;
}
.qph-diff-col header {
  position: sticky;
  top: 0;
  padding: 2px 4px;
  background: var(--kr-bg-elevated);
  border-bottom: 1px solid var(--kr-border);
  color: var(--kr-text-dim);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.qph-diff-line {
  padding: 1px 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--kr-text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  /* Border-left used as the diff "gutter" so additions/removals stay
     visible even when the bg-tint is subtle on a light theme. */
  border-left: 2px solid transparent;
}
.qph-diff-line-same    { color: var(--kr-text-dim); }
.qph-diff-line-changed {
  background: rgba(var(--kr-warning-rgb, 255, 200, 60), 0.10);
  border-left-color: var(--kr-warning);
}
.qph-diff-line-added   {
  background: rgba(var(--kr-success-rgb, 60, 200, 100), 0.12);
  border-left-color: var(--kr-success);
}
.qph-diff-line-removed {
  background: rgba(var(--kr-error-rgb, 200, 80, 80), 0.10);
  border-left-color: var(--kr-error);
  text-decoration: line-through;
  opacity: 0.85;
}

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