/* Block History Panel Styles */

/* Panel Container */
.block-history-panel {
  position: fixed;
  top: 0;
  right: -400px;
  width: 400px;
  height: 100vh;
  background: var(--bs-body-bg, #fff);
  border-left: 1px solid var(--bs-border-color, #dee2e6);
  box-shadow: -4px 0 15px rgba(0, 0, 0, 0.1);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease;
  overflow: hidden;
}

.block-history-panel.visible {
  right: 0;
}

/* Panel Header */
.history-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--bs-tertiary-bg, #f8f9fa);
}

.history-panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--bs-body-color, #212529);
}

.history-panel-title i {
  color: var(--bs-primary, #0d6efd);
}

.history-panel-close {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--bs-secondary, #6c757d);
  border-radius: 4px;
  transition: background-color 0.2s;
}

.history-panel-close:hover {
  background: var(--bs-secondary-bg, #e9ecef);
  color: var(--bs-body-color, #212529);
}

/* Attribution Section */
.history-panel-attribution {
  padding: 1rem;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--bs-tertiary-bg, #f8f9fa);
}

.attribution-summary {
  margin-bottom: 0.75rem;
}

.attribution-bar {
  height: 8px;
  background: var(--bs-secondary-bg, #e9ecef);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  margin-bottom: 0.5rem;
}

.attribution-human {
  background: linear-gradient(135deg, #28a745, #20c997);
  transition: width 0.3s ease;
}

.attribution-ai {
  background: linear-gradient(135deg, #6f42c1, #0d6efd);
  transition: width 0.3s ease;
}

.attribution-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.attribution-label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.attribution-label.human {
  color: #28a745;
}

.attribution-label.ai {
  color: #6f42c1;
}

.attribution-total {
  font-size: 0.8rem;
  color: var(--bs-secondary, #6c757d);
  text-align: center;
  margin-top: 0.25rem;
}

/* Filter Buttons */
.history-filters {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.history-filter-btn {
  flex: 1;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  border: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--bs-body-bg, #fff);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.history-filter-btn:hover {
  background: var(--bs-secondary-bg, #e9ecef);
}

.history-filter-btn.active {
  background: var(--bs-primary, #0d6efd);
  color: #fff;
  border-color: var(--bs-primary, #0d6efd);
}

/* Panel Content */
.history-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* Loading State */
.history-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--bs-secondary, #6c757d);
  gap: 0.75rem;
}

.history-loading i {
  font-size: 1.5rem;
  color: var(--bs-primary, #0d6efd);
}

/* Spinning animation for loading icon */
.spinning {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Error State */
.history-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--bs-danger, #dc3545);
  gap: 0.75rem;
  text-align: center;
}

/* Empty State */
.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--bs-secondary, #6c757d);
  text-align: center;
}

.history-empty i {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

.history-empty p {
  font-size: 0.85rem;
  margin: 0.5rem 0 0 0;
}

/* History Entries */
.history-entries {
  padding: 0;
}

.history-entry {
  padding: 1rem;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
  transition: background-color 0.2s;
}

.history-entry:hover {
  background: var(--bs-tertiary-bg, #f8f9fa);
}

.history-entry.human {
  border-left: 3px solid #28a745;
}

.history-entry.ai {
  border-left: 3px solid #6f42c1;
}

.history-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.history-author {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.history-author.human {
  color: #28a745;
}

.history-author.ai {
  color: #6f42c1;
}

.history-timestamp {
  font-size: 0.8rem;
  color: var(--bs-secondary, #6c757d);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Current badge for most recent entry */
.history-current-badge {
  background: var(--bs-primary, #0d6efd);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Subtle styling for the current/most recent entry */
.history-entry.is-current {
  background: var(--bs-primary-bg-subtle, #e7f1ff);
}

.history-entry.is-current:hover {
  background: var(--bs-primary-bg-subtle, #e7f1ff);
}

.history-entry-type {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--bs-body-color, #212529);
  margin-bottom: 0.5rem;
}

.history-entry-type i {
  font-size: 0.75rem;
  color: var(--bs-secondary, #6c757d);
}

/* Changes List */
.history-entry-changes {
  margin-bottom: 0.5rem;
}

.history-change {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  padding: 0.25rem 0;
}

.history-change-field {
  font-weight: 500;
  color: var(--bs-primary, #0d6efd);
}

.history-change-arrow {
  color: var(--bs-secondary, #6c757d);
  font-size: 0.7rem;
}

.history-change-value {
  color: var(--bs-body-color, #212529);
  font-family: monospace;
  font-size: 0.75rem;
  background: var(--bs-secondary-bg, #e9ecef);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-no-changes {
  font-size: 0.8rem;
  color: var(--bs-secondary, #6c757d);
  font-style: italic;
}

.history-more {
  font-size: 0.75rem;
  color: var(--bs-secondary, #6c757d);
}

/* Action Buttons */
.history-entry-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.history-preview-btn,
.history-rollback-btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  border: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--bs-body-bg, #fff);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--bs-secondary, #6c757d);
}

.history-preview-btn:hover {
  background: var(--bs-info-bg-subtle, #cff4fc);
  border-color: var(--bs-info, #0dcaf0);
  color: var(--bs-info, #0dcaf0);
}

.history-rollback-btn:hover {
  background: var(--bs-warning-bg-subtle, #fff3cd);
  border-color: var(--bs-warning, #ffc107);
  color: #856404;
}

/* Rollback Preview Modal */
.rollback-preview {
  padding: 1rem 0;
}

.preview-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--bs-warning, #ffc107);
  margin-bottom: 1rem;
}

.preview-header i {
  font-size: 1.25rem;
}

.preview-description {
  color: var(--bs-secondary, #6c757d);
  margin-bottom: 1rem;
}

.preview-type-change {
  background: var(--bs-warning-bg-subtle, #fff3cd);
  border: 1px solid var(--bs-warning, #ffc107);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #856404;
}

.preview-changes {
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 1.5rem;
}

.preview-change {
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 6px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.preview-change-field {
  background: var(--bs-tertiary-bg, #f8f9fa);
  padding: 0.5rem 0.75rem;
  font-weight: 500;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.preview-change-values {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--bs-border-color, #dee2e6);
}

.preview-current,
.preview-restored {
  background: var(--bs-body-bg, #fff);
  padding: 0.75rem;
}

.preview-current label,
.preview-restored label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--bs-secondary, #6c757d);
  margin-bottom: 0.35rem;
}

.preview-current pre,
.preview-restored pre {
  margin: 0;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 100px;
  overflow-y: auto;
  background: var(--bs-tertiary-bg, #f8f9fa);
  padding: 0.5rem;
  border-radius: 4px;
}

.preview-current {
  background: #fff5f5;
}

.preview-current pre {
  background: #ffe6e6;
}

.preview-restored {
  background: #f0fff4;
}

.preview-restored pre {
  background: #d4edda;
}

.preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--bs-border-color, #dee2e6);
}

/* Dark Mode Support - Bootstrap 5 */
[data-bs-theme="dark"] .block-history-panel {
  background: #1e1e1e;
  border-color: #333;
  color: #e9ecef;
}

[data-bs-theme="dark"] .history-panel-header,
[data-bs-theme="dark"] .history-panel-attribution {
  background: #2d2d2d;
  border-color: #333;
}

[data-bs-theme="dark"] .history-panel-title {
  color: #e9ecef;
}

[data-bs-theme="dark"] .history-entry {
  border-bottom-color: #333;
}

[data-bs-theme="dark"] .history-entry:hover {
  background: #2d2d2d;
}

[data-bs-theme="dark"] .history-entry-type {
  color: #e9ecef;
}

[data-bs-theme="dark"] .history-change-value {
  background: #333;
  color: #e9ecef;
}

[data-bs-theme="dark"] .history-no-changes {
  color: #adb5bd;
}

[data-bs-theme="dark"] .history-timestamp,
[data-bs-theme="dark"] .history-more {
  color: #adb5bd;
}

[data-bs-theme="dark"] .history-current-badge {
  background: #4a90e2;
}

[data-bs-theme="dark"] .history-entry.is-current {
  background: #1a2a3a;
}

[data-bs-theme="dark"] .history-entry.is-current:hover {
  background: #1a2a3a;
}

[data-bs-theme="dark"] .history-empty,
[data-bs-theme="dark"] .history-loading {
  color: #adb5bd;
}

[data-bs-theme="dark"] .history-filter-btn {
  background: #2d2d2d;
  border-color: #444;
  color: #e9ecef;
}

[data-bs-theme="dark"] .history-filter-btn:hover {
  background: #3d3d3d;
}

[data-bs-theme="dark"] .history-panel-close {
  color: #adb5bd;
}

[data-bs-theme="dark"] .history-panel-close:hover {
  background: #3d3d3d;
  color: #fff;
}

[data-bs-theme="dark"] .history-preview-btn,
[data-bs-theme="dark"] .history-rollback-btn {
  background: #2d2d2d;
  border-color: #444;
  color: #adb5bd;
}

[data-bs-theme="dark"] .history-preview-btn:hover {
  background: #1a3a4a;
  border-color: #0dcaf0;
  color: #0dcaf0;
}

[data-bs-theme="dark"] .history-rollback-btn:hover {
  background: #3d3520;
  border-color: #ffc107;
  color: #ffc107;
}

[data-bs-theme="dark"] .preview-current {
  background: #2d1a1a;
}

[data-bs-theme="dark"] .preview-current pre {
  background: #3d2a2a;
  color: #e9ecef;
}

[data-bs-theme="dark"] .preview-restored {
  background: #1a2d1e;
}

[data-bs-theme="dark"] .preview-restored pre {
  background: #2a3d2e;
  color: #e9ecef;
}

[data-bs-theme="dark"] .preview-change-field {
  background: #2d2d2d;
  color: #e9ecef;
  border-bottom-color: #444;
}

[data-bs-theme="dark"] .preview-description {
  color: #adb5bd;
}

/* Grid Diff Styles */
.grid-diff-summary {
  padding: 0.75rem;
}

.diff-stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.diff-stat {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
}

.diff-stat.diff-added {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.diff-stat.diff-removed {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.diff-stat.diff-modified {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

.diff-details {
  font-size: 0.85rem;
}

.diff-details h6 {
  font-size: 0.8rem;
  font-weight: 600;
  margin: 0.75rem 0 0.5rem 0;
  color: var(--bs-secondary, #6c757d);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.diff-details ul {
  margin: 0;
  padding-left: 1.25rem;
}

.diff-details li {
  margin-bottom: 0.25rem;
  line-height: 1.4;
}

.diff-details li.diff-added {
  color: #155724;
}

.diff-details li.diff-removed {
  color: #721c24;
}

.diff-details li.diff-modified {
  color: #856404;
}

/* Dark mode grid diff styles */
[data-bs-theme="dark"] .diff-stat.diff-added {
  background: #1e3a29;
  color: #75d99a;
  border-color: #2d5a3e;
}

[data-bs-theme="dark"] .diff-stat.diff-removed {
  background: #3a1e22;
  color: #e87a85;
  border-color: #5a2d32;
}

[data-bs-theme="dark"] .diff-stat.diff-modified {
  background: #3a3420;
  color: #f0c75e;
  border-color: #5a4d2d;
}

[data-bs-theme="dark"] .diff-details h6 {
  color: #adb5bd;
}

[data-bs-theme="dark"] .diff-details li.diff-added {
  color: #75d99a;
}

[data-bs-theme="dark"] .diff-details li.diff-removed {
  color: #e87a85;
}

[data-bs-theme="dark"] .diff-details li.diff-modified {
  color: #f0c75e;
}

/* Text Diff Styles */
.text-diff-container {
  padding: 0.75rem;
}

.text-diff-content {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.85rem;
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 6px;
  overflow: hidden;
  max-height: 400px;
  overflow-y: auto;
}

.diff-line {
  padding: 0.25rem 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.diff-line:last-child {
  border-bottom: none;
}

.diff-marker {
  display: inline-block;
  width: 1.5em;
  font-weight: 600;
  user-select: none;
}

.diff-line.diff-same {
  background: var(--bs-body-bg, #fff);
  color: var(--bs-secondary, #6c757d);
}

.diff-line.diff-add {
  background: #d4edda;
  color: #155724;
}

.diff-line.diff-add .diff-marker {
  color: #28a745;
}

.diff-line.diff-remove {
  background: #f8d7da;
  color: #721c24;
}

.diff-line.diff-remove .diff-marker {
  color: #dc3545;
}

.diff-line.diff-collapsed {
  background: var(--bs-tertiary-bg, #f8f9fa);
  color: var(--bs-secondary, #6c757d);
  font-style: italic;
  text-align: center;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* Dark mode text diff */
[data-bs-theme="dark"] .text-diff-content {
  border-color: #444;
}

[data-bs-theme="dark"] .diff-line {
  border-bottom-color: #444;
}

[data-bs-theme="dark"] .diff-line.diff-same {
  background: #1e1e1e;
  color: #adb5bd;
}

[data-bs-theme="dark"] .diff-line.diff-add {
  background: #1e3a29;
  color: #75d99a;
}

[data-bs-theme="dark"] .diff-line.diff-add .diff-marker {
  color: #28a745;
}

[data-bs-theme="dark"] .diff-line.diff-remove {
  background: #3a1e22;
  color: #e87a85;
}

[data-bs-theme="dark"] .diff-line.diff-remove .diff-marker {
  color: #dc3545;
}

[data-bs-theme="dark"] .diff-line.diff-collapsed {
  background: #2d2d2d;
  color: #adb5bd;
}

/* Responsive */
@media (max-width: 768px) {
  .block-history-panel {
    width: 100%;
    right: -100%;
  }

  .preview-change-values {
    grid-template-columns: 1fr;
  }
}
