/* ============================================
   Experiment Viewer - Professional Dark Theme
   ============================================ */

/* CSS Custom Properties */
/* Changes: 
   - Updated accent colors to a more professional blue palette for consistency and sophistication.
   - Removed gradient accents to avoid visual clutter; using solid colors for a cleaner look.
   - Adjusted text colors slightly for better readability and contrast.
   - Kept glassmorphic effects but toned down opacities for a subtler appearance.
   - Unified miscellaneous color references (e.g., #0284c7) to match new accents.
*/
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a25;
  --glass-bg: rgba(255,
      255,
      255,
      0.02);
  /* Slightly reduced opacity for subtlety */
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-hover: rgba(255, 255, 255, 0.04);

  --text-primary: #f0f0f5;
  /* Slightly brighter for better contrast */
  --text-secondary: #b0b0c0;
  --text-muted: #707085;

  --accent-primary: #3b82f6;
  /* Professional blue */
  --accent-secondary: #60a5fa;
  /* Lighter blue for secondary elements */

  --sidebar-width: 320px;
  --header-height: 56px;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
}

/* App Layout */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
#header {
  height: var(--header-height);
  background: var(--glass-bg);
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.logo {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-primary);
}

.logo-link {
  text-decoration: none;
  transition: opacity var(--transition-fast);
}

.logo-link:hover {
  opacity: 0.8;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toolbar {
  display: flex;
  gap: 12px;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.toolbar-btn:hover {
  background: var(--glass-hover);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

.toolbar-btn.active {
  background: var(--accent-primary);
  border-color: transparent;
  color: white;
}

.toolbar-btn .icon {
  width: 16px;
  height: 16px;
}

/* Viewer Layout */
#viewer {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Panes */
.pane {
  display: flex;
  flex: 1;
  min-width: 0;
}

.pane.secondary {
  display: none;
  border-left: 1px solid var(--glass-border);
}

#viewer.compare-mode .pane.secondary {
  display: flex;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--glass-border);
}

.sidebar-header h2 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.external-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  transition: all var(--transition-fast);
}

.external-link:hover {
  background: var(--glass-hover);
  color: var(--text-primary);
}

.external-link .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Custom Scrollbar */
.sidebar-content::-webkit-scrollbar,
.content-body::-webkit-scrollbar {
  width: 8px;
}

.sidebar-content::-webkit-scrollbar-track,
.content-body::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb,
.content-body::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 4px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover,
.content-body::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* File Tree */
#tree-primary,
#tree-secondary {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar ul ul {
  padding-left: 16px;
}

.sidebar ul.collapsed {
  display: none;
}

.sidebar li {
  margin: 2px 0;
}

.folder,
.file-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.folder:hover,
.file-link:hover {
  background: var(--glass-hover);
  color: var(--text-primary);
}

.folder {
  font-weight: 500;
  color: var(--text-primary);
}

.file-link.active {
  background: var(--accent-primary);
  color: white;
}

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.folder .icon {
  color: var(--accent-secondary);
  opacity: 1;
}

.file-link .icon {
  color: var(--accent-primary);
}

.file-link.active .icon {
  color: white;
}

.name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Content Area */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

.content-header {
  height: 48px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--glass-border);
  background: var(--glass-bg);
  flex-shrink: 0;
}

.file-path,
.file-path-slot {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-family: "SF Mono", "Fira Code", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Per-pane navigation button - hidden by default, shown on mobile compare mode */
.pane-nav-btn {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.pane-nav-btn:hover,
.pane-nav-btn:active {
  background: var(--glass-hover);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

.pane-nav-btn .icon {
  width: 14px;
  height: 14px;
  color: var(--accent-primary);
}

.pane.primary .pane-nav-btn .icon {
  color: var(--accent-primary);
}

.pane.secondary .pane-nav-btn .icon {
  color: var(--accent-secondary);
}

.content-body {
  flex: 1;
  overflow-y: auto;
  padding: 32px 48px;
}

/* Markdown Content */
.markdown-body {
  max-width: 900px;
  color: var(--text-primary);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  color: var(--text-primary);
  margin-top: 2em;
  margin-bottom: 0.5em;
  font-weight: 600;
}

.markdown-body h1 {
  font-size: 2rem;
  margin-top: 0;
}

.markdown-body h2 {
  font-size: 1.5rem;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 0.3em;
}

.markdown-body h3 {
  font-size: 1.25rem;
}

.markdown-body p {
  margin: 1em 0;
  color: var(--text-secondary);
}

.markdown-body a {
  color: var(--accent-secondary);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.9em;
  color: var(--accent-primary);
}

.markdown-body pre {
  background: var(--bg-tertiary);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  border: 1px solid var(--glass-border);
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: var(--text-primary);
}

.markdown-body blockquote {
  margin: 1em 0;
  padding: 12px 20px;
  border-left: 3px solid var(--accent-primary);
  background: var(--glass-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 24px;
  color: var(--text-secondary);
}

.markdown-body li {
  margin: 0.5em 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
}

.markdown-body th,
.markdown-body td {
  padding: 10px 14px;
  border: 1px solid var(--glass-border);
  text-align: left;
}

.markdown-body th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--glass-border);
  margin: 2em 0;
}

/* PDF Viewer */
.pdf-viewer {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
  border-radius: var(--radius-md);
}

/* Intro Section */
.intro {
  max-width: 700px;
  padding: 40px 0;
}

.intro h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent-primary);
  /* Updated to match new accent */
  margin: 0 0 24px 0;
}

.intro p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin: 0 0 16px 0;
}

.intro strong {
  color: var(--text-primary);
}

.stats {
  display: flex;
  gap: 32px;
  margin-top: 40px;
  padding-top: 32px;
  border-top: 1px solid var(--glass-border);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent-primary);
  /* Updated to match new accent */
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Loading & Error States */
.loading,
.error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
}

.error {
  color: #ef4444;
}

/* Responsive */
@media (max-width: 1200px) {
  :root {
    --sidebar-width: 280px;
  }
}

/* Mobile Styles */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 85vw;
    --header-height: 52px;
  }

  /* Header adjustments */
  #header {
    padding: 0 16px;
  }

  .logo {
    font-size: 1rem;
  }

  /* Hamburger Menu Button */
  .menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
  }

  .menu-btn:hover,
  .menu-btn:active {
    background: var(--glass-hover);
    color: var(--text-primary);
    border-color: var(--accent-primary);
  }

  .menu-btn .icon {
    width: 20px;
    height: 20px;
    pointer-events: none;
  }

  /* Toolbar adjustments */
  .toolbar {
    gap: 8px;
  }

  .toolbar-btn {
    padding: 10px 12px;
    min-height: 40px;
  }

  .toolbar-btn span {
    display: none;
  }

  /* Sidebar as slide-out drawer */
  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    max-width: 320px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Sidebar overlay */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-overlay.visible {
    display: block;
  }

  /* Improve touch targets in sidebar */
  .folder,
  .file-link,
  .external-link {
    padding: 12px 16px;
    min-height: 44px;
  }

  /* Content body adjustments */
  .content-body {
    padding: 20px 16px;
  }

  .content-header {
    padding: 0 16px;
    height: 44px;
  }

  .file-path {
    font-size: 0.8rem;
  }

  /* Markdown adjustments for mobile */
  .markdown-body {
    max-width: 100%;
  }

  .markdown-body h1 {
    font-size: 1.5rem;
  }

  .markdown-body h2 {
    font-size: 1.25rem;
  }

  .markdown-body h3 {
    font-size: 1.1rem;
  }

  .markdown-body pre {
    padding: 12px;
    font-size: 0.85rem;
  }

  .markdown-body table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  /* Intro section mobile */
  .intro {
    padding: 24px 0;
  }

  .intro h1 {
    font-size: 1.75rem;
  }

  .intro p {
    font-size: 1rem;
  }

  .stats {
    flex-wrap: wrap;
    gap: 24px;
    margin-top: 24px;
    padding-top: 24px;
  }

  .stat-value {
    font-size: 2rem;
  }

  /* Compare mode on mobile - stack vertically */
  #viewer.compare-mode {
    flex-direction: column;
  }

  #viewer.compare-mode .pane {
    flex: none;
    height: 50vh;
    min-height: 300px;
  }

  #viewer.compare-mode .pane.secondary {
    display: flex;
    border-left: none;
    border-top: 2px solid var(--accent-primary);
  }

  /* In compare mode, both sidebars become slide-out drawers */
  #viewer.compare-mode .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    max-width: 320px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    /* Safari fix: ensure proper overflow containment */
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #viewer.compare-mode .sidebar.open {
    transform: translateX(0);
  }

  /* Safari fix: ensure sidebar-content scrolls properly within fixed container */
  #viewer.compare-mode .sidebar-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Show per-pane nav buttons in mobile compare mode */
  #viewer.compare-mode .pane-nav-btn {
    display: flex;
  }

  /* Hide main hamburger in mobile compare mode - per-pane buttons replace it */
  #viewer.compare-mode~#header .menu-btn,
  body:has(#viewer.compare-mode) .menu-btn {
    display: none;
  }

  /* Adjust content-header for mobile compare */
  #viewer.compare-mode .content-header {
    padding: 0 12px;
    gap: 8px;
  }
}

/* Hide hamburger on desktop */
@media (min-width: 769px) {
  .menu-btn {
    display: none;
  }

  .sidebar-overlay {
    display: none !important;
  }
}

/* Extra small devices */
@media (max-width: 480px) {
  .logo {
    font-size: 0.9rem;
  }

  .content-body {
    padding: 16px 12px;
  }

  .intro h1 {
    font-size: 1.5rem;
  }

  .stats {
    gap: 16px;
  }

  .stat-value {
    font-size: 1.75rem;
  }

  .stat-label {
    font-size: 0.75rem;
  }
}