/**
 * FileViewer - Enhanced dual-pane file browser styles
 * Uses CSS variables from Chainlit's theme
 */

/* ============================================================================
   PANEL STRUCTURE
   ============================================================================ */

.file-browser-panel {
  position: fixed;
  right: 0;
  top: 0;
  height: 100vh;
  width: 45%;
  min-width: 400px;
  max-width: 800px;
  background: hsl(var(--card));
  border-left: 1px solid hsl(var(--border));
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.file-browser-panel.open {
  transform: translateX(0);
}

/* Header */
.file-browser-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  flex-shrink: 0;
}

.file-browser-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
}

.file-browser-close-btn {
  padding: 0.375rem;
  border-radius: 0.375rem;
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: all 0.15s ease;
}

.file-browser-close-btn:hover {
  background: hsl(var(--accent));
  color: hsl(var(--foreground));
}

/* Main content area */
.file-browser-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: hsl(var(--background));
}

/* ============================================================================
   SECTIONS (Outputs/Inputs)
   ============================================================================ */

.file-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  transition: flex 0.2s ease;
}

.file-section.collapsed .section-body {
  display: none;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: hsl(var(--muted) / 0.5);
  border-bottom: 1px solid hsl(var(--border));
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.section-header:hover {
  background: hsl(var(--muted));
}

.section-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.collapse-icon {
  font-size: 0.625rem;
  color: hsl(var(--muted-foreground));
  transition: transform 0.2s ease;
  width: 1rem;
  text-align: center;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: hsl(var(--foreground));
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.file-count {
  font-size: 0.625rem;
  color: hsl(var(--muted-foreground));
  font-weight: 400;
}

.section-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Section resizer */
.section-resizer {
  height: 4px;
  background: hsl(var(--border));
  cursor: row-resize;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.section-resizer:hover {
  background: hsl(var(--primary) / 0.5);
}

/* ============================================================================
   FILE TABS (compact, inline with toolbar)
   ============================================================================ */

.file-tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  align-items: flex-end;
}

.file-tabs:empty::before {
  content: 'No files';
  color: hsl(var(--muted-foreground));
  font-size: 0.6875rem;
  font-style: italic;
  display: flex;
  align-items: center;
  padding: 0.375rem 0.5rem;
}

.file-tabs::-webkit-scrollbar {
  height: 3px;
}

.file-tabs::-webkit-scrollbar-track {
  background: transparent;
}

.file-tabs::-webkit-scrollbar-thumb {
  background: hsl(var(--muted-foreground) / 0.3);
  border-radius: 2px;
}

.file-tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem 0.625rem;
  border: 1px solid hsl(var(--border));
  border-bottom: none;
  border-radius: 0.375rem 0.375rem 0 0;
  background: hsl(var(--muted) / 0.5);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  margin-right: -6px;
  margin-bottom: -1px;
  z-index: 0;
}

.file-tab:hover {
  background: hsl(var(--muted) / 0.8);
  z-index: 2;
}

/* Selected tab - connects to content below */
.file-tab--selected {
  background: hsl(var(--background));
  border-color: hsl(var(--border));
  z-index: 3;
  transform: translateY(-1px);
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.05);
}

.file-tab--selected:hover {
  background: hsl(var(--background));
  z-index: 3;
}

/* File tab icon (compact) */
.file-tab-icon {
  position: relative;
  width: 18px;
  height: 22px;
  color: var(--file-color, hsl(var(--muted-foreground)));
  flex-shrink: 0;
}

.file-icon-svg {
  width: 100%;
  height: 100%;
}

.file-ext {
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.375rem;
  font-weight: 700;
  color: var(--file-color, hsl(var(--muted-foreground)));
  text-transform: lowercase;
  white-space: nowrap;
}

.file-tab-name {
  font-size: 0.6875rem;
  color: hsl(var(--muted-foreground));
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-tab--selected .file-tab-name {
  color: hsl(var(--foreground));
  font-weight: 500;
}

/* New file indicator */
.new-indicator {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 5px;
  height: 5px;
  background: hsl(var(--primary));
  border-radius: 50%;
}

/* Blinking animation for new/changed files */
.file-tab--new {
  animation: subtle-blink 2s ease-in-out infinite;
}

@keyframes subtle-blink {
  0%, 100% {
    opacity: 1;
    background: hsl(var(--muted) / 0.3);
  }
  50% {
    opacity: 0.7;
    background: hsl(var(--primary) / 0.15);
  }
}

.file-tab--new .new-indicator {
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.3);
    opacity: 0.7;
  }
}

/* ============================================================================
   PREVIEW AREA
   ============================================================================ */

.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem 0;
  background: hsl(var(--muted) / 0.3);
  border-bottom: 1px solid hsl(var(--border));
  min-height: 42px;
  flex-shrink: 0;
  position: relative;
}

.preview-toolbar:empty {
  display: none;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  flex-shrink: 0;
  margin-left: auto;
  padding-bottom: 0.25rem;
}

.toolbar-actions:empty {
  display: none;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem;
  border-radius: 0.25rem;
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.toolbar-btn:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.toolbar-btn.active {
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--primary));
}

/* Version navigation */
.version-nav {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.125rem;
  background: hsl(var(--muted) / 0.5);
  border-radius: 0.25rem;
}

/* Hide version-nav if it has no visible content */
.version-nav:empty {
  display: none;
}

.version-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.125rem;
  border-radius: 0.125rem;
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: all 0.15s ease;
}

.version-btn:hover:not(:disabled) {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
}

.version-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.version-info {
  font-size: 0.5625rem;
  color: hsl(var(--muted-foreground));
  padding: 0 0.25rem;
  min-width: 2.5rem;
  text-align: center;
}

/* Copy toast notification */
.copy-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 100;
}

.copy-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.copy-toast--error {
  background: hsl(0 84% 60%);
  color: white;
}

.copy-toast svg {
  flex-shrink: 0;
}

/* Preview content - background matches selected tab */
.preview-content {
  flex: 1;
  overflow: auto;
  background: hsl(var(--background));
  border-top: none;
}

/* Subtle fade animation when switching tabs */
.preview-content.switching {
  animation: content-fade 0.15s ease-out;
}

@keyframes content-fade {
  0% {
    opacity: 0.7;
  }
  100% {
    opacity: 1;
  }
}

/* ============================================================================
   EMPTY & LOADING STATES
   ============================================================================ */

.empty-state,
.loading-state,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 0.75rem;
  padding: 2rem;
  color: hsl(var(--muted-foreground));
}

.empty-state svg,
.error-state svg {
  opacity: 0.5;
}

.empty-state p,
.loading-state span,
.error-state p {
  font-size: 0.75rem;
  text-align: center;
}

/* Spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid hsl(var(--muted));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============================================================================
   DIFF VIEW
   ============================================================================ */

.diff-view {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.diff-header-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.5rem;
  background: hsl(var(--muted) / 0.3);
  border-bottom: 1px solid hsl(var(--border));
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.diff-old {
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  background: hsl(0 84% 60% / 0.15);
  color: hsl(0 84% 40%);
  font-weight: 500;
}

.diff-new {
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  background: hsl(142 76% 36% / 0.15);
  color: hsl(142 76% 30%);
  font-weight: 500;
}

.diff-content {
  flex: 1;
  margin: 0;
  padding: 1rem;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
  background: hsl(var(--background));
}

.diff-line-add {
  display: block;
  background: hsl(142 76% 36% / 0.15);
  color: hsl(142 76% 30%);
  margin: 0 -1rem;
  padding: 0 1rem;
}

.dark .diff-line-add {
  background: hsl(142 76% 36% / 0.2);
  color: hsl(142 76% 60%);
}

.diff-line-remove {
  display: block;
  background: hsl(0 84% 60% / 0.15);
  color: hsl(0 84% 40%);
  margin: 0 -1rem;
  padding: 0 1rem;
}

.dark .diff-line-remove {
  background: hsl(0 84% 60% / 0.2);
  color: hsl(0 72% 65%);
}

.diff-line-info {
  display: block;
  color: hsl(var(--primary));
  font-weight: 500;
  margin: 0.5rem -1rem;
  padding: 0.25rem 1rem;
  background: hsl(var(--primary) / 0.05);
}

.diff-file-header {
  display: block;
  color: hsl(var(--muted-foreground));
  font-weight: 600;
}

/* Side-by-side diff fallback */
.diff-simple {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: hsl(var(--border));
  flex: 1;
  overflow: hidden;
}

.diff-column {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.diff-column-header {
  padding: 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-align: center;
  flex-shrink: 0;
}

.diff-old-column .diff-column-header {
  background: hsl(0 84% 60% / 0.1);
  color: hsl(0 84% 40%);
}

.diff-new-column .diff-column-header {
  background: hsl(142 76% 36% / 0.1);
  color: hsl(142 76% 30%);
}

.diff-column pre {
  flex: 1;
  margin: 0;
  padding: 0.75rem;
  overflow: auto;
  font-size: 0.75rem;
  line-height: 1.5;
  background: hsl(var(--background));
}

/* ============================================================================
   CODE PREVIEW
   ============================================================================ */

.code-preview {
  height: 100%;
  overflow: auto;
}

.code-preview pre {
  margin: 0;
  padding: 1rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
  background: hsl(var(--muted) / 0.3);
  min-height: 100%;
}

.code-preview code {
  font-family: inherit;
}

/* ============================================================================
   UNKNOWN FILE STATE
   ============================================================================ */

.unknown-file-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
}

.unknown-file-state svg {
  color: hsl(var(--muted-foreground));
  opacity: 0.5;
}

.unknown-file-state .filename {
  font-weight: 500;
  color: hsl(var(--foreground));
  margin: 0;
}

.unknown-file-state .content-type {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  margin: 0;
}

.unknown-file-state .download-btn {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  border: none;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.unknown-file-state .download-btn:hover {
  background: hsl(var(--primary) / 0.9);
}

/* ============================================================================
   HEADER BUTTON
   ============================================================================ */

.files-browser-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: 0.375rem;
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: all 0.15s ease;
}

.files-browser-btn:hover {
  background: hsl(var(--accent));
  color: hsl(var(--foreground));
}

/* ============================================================================
   LEGACY FILE LINK STYLES
   ============================================================================ */

.file-link {
  cursor: pointer;
  text-decoration: none !important;
  border: 1px solid hsl(var(--border));
}

.file-link:hover {
  border-color: hsl(var(--primary) / 0.5);
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
  .file-browser-panel {
    width: 100% !important;
    min-width: unset !important;
    max-width: unset !important;
  }

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

/* ============================================================================
   SCROLLBARS
   ============================================================================ */

.preview-content::-webkit-scrollbar,
.diff-content::-webkit-scrollbar,
.code-preview::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.preview-content::-webkit-scrollbar-track,
.diff-content::-webkit-scrollbar-track,
.code-preview::-webkit-scrollbar-track {
  background: hsl(var(--muted) / 0.5);
}

.preview-content::-webkit-scrollbar-thumb,
.diff-content::-webkit-scrollbar-thumb,
.code-preview::-webkit-scrollbar-thumb {
  background: hsl(var(--muted-foreground) / 0.3);
  border-radius: 4px;
}

.preview-content::-webkit-scrollbar-thumb:hover,
.diff-content::-webkit-scrollbar-thumb:hover,
.code-preview::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--muted-foreground) / 0.5);
}

/* ============================================================================
   ICONS SIZE HELPER
   ============================================================================ */

.w-4 { width: 1rem; }
.h-4 { height: 1rem; }
.w-5 { width: 1.25rem; }
.h-5 { height: 1.25rem; }
.w-12 { width: 3rem; }
.h-12 { height: 3rem; }
.w-16 { width: 4rem; }
.h-16 { height: 4rem; }

/* ============================================================================
   INLINE FILE PREVIEW WIDGET (for presentations in chat)
   ============================================================================ */

/* Container for inline presentations */
.presentation-gallery {
  margin: 1rem 0;
  border-radius: 0.5rem;
  overflow: hidden;
}

/* The file preview widget */
.file-preview-widget {
  display: flex;
  flex-direction: column;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  overflow: hidden;
}

/* Inline variant - constrained height */
.file-preview-widget--inline {
  max-width: 100%;
  border: 1px solid hsl(var(--border) / 0.8);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.04),
    0 1px 2px rgba(0, 0, 0, 0.06);
}

.dark .file-preview-widget--inline {
  border-color: hsl(var(--border) / 0.6);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.15),
    0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Wrapper for presentation widgets in chat messages */
.presentation-widget-wrapper {
  margin: 0.75rem 0;
  width: 100%;
  padding: 0.75rem;
  background: hsl(var(--muted) / 0.3);
  border-radius: 0.75rem;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 4px 12px rgba(0, 0, 0, 0.04);
}

.dark .presentation-widget-wrapper {
  background: hsl(var(--muted) / 0.2);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.2),
    0 4px 12px rgba(0, 0, 0, 0.15);
}

.presentation-widget-wrapper .file-preview-widget {
  max-width: 100%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Widget header (title/description) */
.file-preview-widget .widget-header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  background: hsl(var(--muted) / 0.3);
  border-bottom: 1px solid hsl(var(--border));
}

.file-preview-widget .widget-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: hsl(var(--foreground));
}

.file-preview-widget .widget-description {
  font-size: 0.8rem;
  color: hsl(var(--muted-foreground));
}

/* Widget toolbar */
.file-preview-widget .widget-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 0.75rem;
  background: hsl(var(--muted) / 0.2);
  border-bottom: 1px solid hsl(var(--border));
  min-height: 42px;
}

.file-preview-widget .file-tabs {
  display: flex;
  align-items: flex-end;
  gap: 0;
  flex-wrap: wrap;
  padding-top: 0.5rem;
}

.file-preview-widget .toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding-bottom: 0.5rem;
}

.file-preview-widget .toolbar-actions:empty {
  display: none;
}

/* Reuse same tab styles */
.file-preview-widget .file-tab {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem 0.625rem;
  border: 1px solid hsl(var(--border));
  border-bottom: none;
  border-radius: 0.375rem 0.375rem 0 0;
  background: hsl(var(--muted) / 0.5);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  margin-right: -6px;
  margin-bottom: -1px;
  z-index: 0;
}

.file-preview-widget .file-tab:hover {
  background: hsl(var(--muted) / 0.8);
  z-index: 2;
}

.file-preview-widget .file-tab--selected {
  background: hsl(var(--background));
  border-color: hsl(var(--border));
  z-index: 3;
  transform: translateY(-1px);
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.05);
}

.file-preview-widget .file-tab--selected:hover {
  background: hsl(var(--background));
  z-index: 3;
}

/* Reuse tab icon styles */
.file-preview-widget .file-tab-icon {
  position: relative;
  width: 18px;
  height: 22px;
  color: var(--file-color, hsl(var(--muted-foreground)));
}

.file-preview-widget .file-icon-svg {
  width: 100%;
  height: 100%;
}

.file-preview-widget .file-ext {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 6px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--file-color, hsl(var(--muted-foreground)));
}

.file-preview-widget .file-tab-name {
  font-size: 0.75rem;
  font-weight: 500;
  color: hsl(var(--foreground));
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Preview content area */
.file-preview-widget .widget-preview-content {
  flex: 1;
  overflow: auto;
  background: hsl(var(--background));
  min-height: 200px;
}

.file-preview-widget--inline .widget-preview-content {
  max-height: 400px;
}

/* Reuse toolbar button styles */
.file-preview-widget .toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 0.25rem;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.file-preview-widget .toolbar-btn:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

/* Reuse empty/loading/error states */
.file-preview-widget .empty-state,
.file-preview-widget .loading-state,
.file-preview-widget .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  color: hsl(var(--muted-foreground));
  text-align: center;
  min-height: 200px;
}

.file-preview-widget .loading-state .spinner {
  width: 24px;
  height: 24px;
  border: 2px solid hsl(var(--muted));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.file-preview-widget .unknown-file-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  text-align: center;
  color: hsl(var(--muted-foreground));
}

.file-preview-widget .unknown-file-state .filename {
  font-weight: 500;
  color: hsl(var(--foreground));
}

.file-preview-widget .unknown-file-state .content-type {
  font-size: 0.75rem;
}

.file-preview-widget .download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease;
}

.file-preview-widget .download-btn:hover {
  background: hsl(var(--primary) / 0.9);
}

/* Switching animation */
.file-preview-widget .widget-preview-content.switching {
  animation: content-fade 0.15s ease-out;
}

/* Image preview in widget */
.file-preview-widget .image-preview {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: auto;
}

.file-preview-widget .image-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 0.375rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Code preview in widget */
.file-preview-widget .code-preview {
  height: 100%;
  overflow: auto;
}

.file-preview-widget .code-preview pre {
  margin: 0;
  padding: 1rem;
  min-height: 100%;
}

/* Text preview in widget */
.file-preview-widget .text-preview {
  height: 100%;
  overflow: auto;
}

.file-preview-widget .text-preview pre {
  margin: 0;
  padding: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* CSV preview in widget */
.file-preview-widget .csv-preview {
  height: 100%;
  overflow: auto;
  padding: 1rem;
}

.file-preview-widget .csv-preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.file-preview-widget .csv-preview th,
.file-preview-widget .csv-preview td {
  border: 1px solid hsl(var(--border));
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.file-preview-widget .csv-preview th {
  background: hsl(var(--muted));
  font-weight: 500;
}

.file-preview-widget .csv-preview tr:hover {
  background: hsl(var(--muted) / 0.5);
}

/* ============================================================================
   VERSION HISTORY PANEL
   ============================================================================ */

.version-history-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.2s ease;
}

.version-history-panel.closing {
  animation: fade-out 0.2s ease forwards;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.version-history-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.version-history-content {
  position: relative;
  width: 90%;
  max-width: 1200px;
  height: 85vh;
  max-height: 800px;
  background: hsl(var(--card));
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-up 0.2s ease;
}

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.version-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.3);
}

.version-history-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 1rem;
  color: hsl(var(--foreground));
}

.version-history-title svg {
  color: hsl(var(--primary));
}

.version-count {
  font-size: 0.75rem;
  font-weight: 400;
  color: hsl(var(--muted-foreground));
  padding: 0.25rem 0.5rem;
  background: hsl(var(--muted));
  border-radius: 9999px;
}

.version-history-close {
  padding: 0.5rem;
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  border-radius: 0.375rem;
  transition: all 0.15s ease;
}

.version-history-close:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.version-history-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Sidebar */
.version-sidebar {
  width: 280px;
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
  background: hsl(var(--muted) / 0.2);
}

.version-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  font-size: 0.75rem;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.compare-mode-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: hsl(var(--muted));
  border-radius: 9999px;
  transition: 0.2s;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: hsl(var(--primary));
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(14px);
}

.version-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

/* Version item */
.version-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-bottom: 0.25rem;
}

.version-item:hover {
  background: hsl(var(--muted) / 0.5);
}

.version-item.selected {
  background: hsl(var(--primary) / 0.1);
  border: 1px solid hsl(var(--primary) / 0.3);
}

.version-item-radio {
  display: none;
  flex-direction: column;
  gap: 0.25rem;
  padding-top: 0.25rem;
}

.compare-mode .version-item-radio {
  display: flex;
}

.version-radio-from,
.version-radio-to {
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.version-radio-from {
  accent-color: hsl(0 84% 60%);
}

.version-radio-to {
  accent-color: hsl(142 76% 36%);
}

.version-item-info {
  flex: 1;
  min-width: 0;
}

.version-item-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.version-number {
  font-weight: 600;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
}

.version-badge {
  font-size: 0.625rem;
  font-weight: 500;
  padding: 0.125rem 0.375rem;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-radius: 9999px;
  text-transform: uppercase;
}

.version-item-meta {
  display: flex;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  margin-bottom: 0.25rem;
}

.version-item-hash {
  font-size: 0.6875rem;
  font-family: ui-monospace, monospace;
  color: hsl(var(--muted-foreground));
  opacity: 0.7;
}

.version-item-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.version-item:hover .version-item-actions {
  opacity: 1;
}

.version-action-btn {
  padding: 0.375rem;
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  border-radius: 0.25rem;
  transition: all 0.15s ease;
}

.version-action-btn:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.version-action-btn.restore-btn:hover {
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--primary));
}

/* Main content area */
.version-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.version-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.2);
}

.version-view-tabs {
  display: flex;
  gap: 0.25rem;
  background: hsl(var(--muted) / 0.5);
  padding: 0.25rem;
  border-radius: 0.375rem;
}

.version-view-tab {
  padding: 0.375rem 0.75rem;
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground));
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 0.25rem;
  transition: all 0.15s ease;
}

.version-view-tab:hover {
  color: hsl(var(--foreground));
}

.version-view-tab.active {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.version-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.viewing-version {
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}

.current-version-badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  background: hsl(142 76% 36% / 0.15);
  color: hsl(142 76% 36%);
  border-radius: 0.25rem;
}

.restore-version-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border: none;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 0.375rem;
  transition: all 0.15s ease;
}

.restore-version-btn:hover {
  background: hsl(var(--primary) / 0.9);
}

.version-preview {
  flex: 1;
  overflow: auto;
  background: hsl(var(--background));
}

/* Version content view */
.version-content-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.version-content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: hsl(var(--muted) / 0.3);
  border-bottom: 1px solid hsl(var(--border));
}

.version-content-info {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.copy-content-btn {
  padding: 0.375rem;
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  border-radius: 0.25rem;
  transition: all 0.15s ease;
}

.copy-content-btn:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.version-code-preview {
  flex: 1;
  margin: 0;
  padding: 1rem;
  overflow: auto;
  font-size: 0.8125rem;
  line-height: 1.6;
  background: hsl(var(--muted) / 0.2);
}

.version-code-preview .line-number {
  display: inline-block;
  width: 3.5rem;
  padding-right: 1rem;
  text-align: right;
  color: hsl(var(--muted-foreground));
  opacity: 0.5;
  user-select: none;
}

/* Git-style diff view */
.git-diff-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.diff-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: hsl(var(--muted) / 0.3);
  border-bottom: 1px solid hsl(var(--border));
}

.diff-file-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--foreground));
}

.diff-version-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.diff-from-version {
  padding: 0.25rem 0.5rem;
  background: hsl(0 84% 60% / 0.15);
  color: hsl(0 84% 40%);
  border-radius: 0.25rem;
  font-weight: 500;
}

.dark .diff-from-version {
  color: hsl(0 72% 65%);
}

.diff-to-version {
  padding: 0.25rem 0.5rem;
  background: hsl(142 76% 36% / 0.15);
  color: hsl(142 76% 30%);
  border-radius: 0.25rem;
  font-weight: 500;
}

.dark .diff-to-version {
  color: hsl(142 76% 50%);
}

.diff-stats {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: hsl(var(--muted) / 0.2);
  border-bottom: 1px solid hsl(var(--border));
  font-size: 0.8125rem;
}

.diff-stat-additions {
  color: hsl(142 76% 36%);
  font-weight: 500;
}

.diff-stat-deletions {
  color: hsl(0 84% 60%);
  font-weight: 500;
}

.diff-stat-summary {
  color: hsl(var(--muted-foreground));
}

.diff-content-wrapper {
  flex: 1;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.5;
}

.diff-hunk {
  margin-bottom: 1rem;
}

.diff-hunk-header {
  padding: 0.5rem 1rem;
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--primary));
  font-weight: 500;
}

.diff-line {
  display: flex;
  min-height: 1.5em;
}

.diff-line-num {
  width: 3.5rem;
  padding: 0 0.5rem;
  text-align: right;
  color: hsl(var(--muted-foreground));
  opacity: 0.5;
  user-select: none;
  flex-shrink: 0;
}

.diff-line-num-old {
  background: hsl(var(--muted) / 0.3);
}

.diff-line-num-new {
  background: hsl(var(--muted) / 0.2);
}

.diff-line-prefix {
  width: 1.5rem;
  text-align: center;
  flex-shrink: 0;
  font-weight: 600;
}

.diff-line-content {
  flex: 1;
  padding-right: 1rem;
  white-space: pre-wrap;
  word-break: break-all;
}

.diff-line-add {
  background: hsl(142 76% 36% / 0.15);
}

.diff-line-add .diff-line-num-new {
  background: hsl(142 76% 36% / 0.2);
}

.diff-line-add .diff-line-prefix {
  color: hsl(142 76% 36%);
}

.dark .diff-line-add {
  background: hsl(142 76% 36% / 0.1);
}

.diff-line-del {
  background: hsl(0 84% 60% / 0.15);
}

.diff-line-del .diff-line-num-old {
  background: hsl(0 84% 60% / 0.2);
}

.diff-line-del .diff-line-prefix {
  color: hsl(0 84% 60%);
}

.dark .diff-line-del {
  background: hsl(0 84% 60% / 0.1);
}

.diff-line-context {
  background: transparent;
}

.diff-no-changes {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 1rem;
  color: hsl(var(--muted-foreground));
}

.diff-no-changes svg {
  color: hsl(142 76% 36%);
}

/* Simple side-by-side diff fallback */
.diff-simple-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100%;
}

.diff-column {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.diff-column-old {
  border-right: 1px solid hsl(var(--border));
}

.diff-column-header {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  border-bottom: 1px solid hsl(var(--border));
}

.diff-column-old .diff-column-header {
  background: hsl(0 84% 60% / 0.1);
  color: hsl(0 84% 40%);
}

.diff-column-new .diff-column-header {
  background: hsl(142 76% 36% / 0.1);
  color: hsl(142 76% 30%);
}

.diff-column-content {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 0;
}

.diff-column-content .diff-line {
  padding: 0 0.5rem;
}

.diff-column-content .diff-line-num {
  width: 3rem;
}

/* Version history button in toolbar */
.version-history-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border: none;
  background: hsl(var(--muted) / 0.5);
  color: hsl(var(--muted-foreground));
  font-size: 0.6875rem;
  cursor: pointer;
  border-radius: 0.25rem;
  transition: all 0.15s ease;
}

.version-history-btn:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.version-history-btn .version-badge-count {
  padding: 0.125rem 0.375rem;
  background: hsl(var(--primary) / 0.2);
  color: hsl(var(--primary));
  border-radius: 9999px;
  font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
  .version-history-content {
    width: 95%;
    height: 90vh;
  }

  .version-sidebar {
    width: 220px;
  }

  .diff-simple-view {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
   DARK MODE STARTER ICONS FIX
   ============================================================================ */

/*
 * Starter button icons use external SVG files loaded via <img>, so they don't
 * inherit currentColor. We use CSS filter to invert them in dark mode.
 */
.dark [id^="starter-"] img,
.dark button[id^="starter-"] img {
  filter: invert(1) brightness(2);
}
