/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Dark mode scrollbar */
.dark ::-webkit-scrollbar-thumb {
    background: #4b5563;
}
.dark ::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Smooth transitions - optimized for Safari */
:root {
    color-scheme: light dark;
}

.dark {
    color-scheme: dark;
}

/* Apply transitions only to specific elements instead of * */
body,
.bg-white,
.dark\:bg-gray-800,
nav,
aside,
article,
.prose {
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    will-change: auto;
}

/* Remove transition from all other elements for better Safari performance */
*, *::before, *::after {
    transition: none;
}

code:not(pre code) {
    background-color: rgba(59, 130, 246, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace !important;
}

.dark code:not(pre code) {
    background-color: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
}

/* Search highlight */
.search-highlight {
    background-color: #fef3c7;
    padding: 2px 4px;
    border-radius: 2px;
}

.md-level-1, .md-level-2 {
    margin-left: 0px;
    font-size: 0.95rem;
}

.md-level-3 {
    margin-left: 8px;
    font-size: 0.85rem;
}

.md-level-4 {
    margin-left: 12px;
    font-size: 0.8rem;
}

.md-level-5 {
    margin-left: 16px;
    font-size: 0.75rem;
}

.md-level-6 {
    margin-left: 20px;
    font-size: 0.7rem;
}

/* Active TOC item */
.toc-active {
    color: #0066ff !important;
    background-color: rgba(243, 244, 246, 1) !important;
    border-left-color: #0066ff !important;
}

.dark .toc-active {
    color: #42c1ed !important;
    background-color: rgba(55, 65, 81, 0.5) !important;
    border-left-color: #42c1ed !important;
}

/* Responsive prose elements */
article pre {
    max-width: 100%;
    overflow-x: auto;
}

article table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

article img {
    max-width: 100%;
    height: auto;
}

.md-index-active {
    font-weight: 600 !important;
    color: #2563eb !important;
    border-left: 3px solid #3b82f6 !important;
    background-color: rgba(59, 130, 246, 0.1) !important;
    margin-left: -3px !important;
}

/* Prevent layout breaking on small screens */
@media (max-width: 640px) {
    article {
        font-size: 0.875rem;
    }
    
    article h1 {
        font-size: 1.5rem;
    }
    
    article h2 {
        font-size: 1.25rem;
    }
    
    article h3 {
        font-size: 1.125rem;
    }
}

/* Prism.js Code Block Styling */
div.code-toolbar {
    position: relative;
    margin: 1.5em 0;
}

div.code-toolbar > .toolbar {
    position: absolute;
    top: 0.5em;
    right: 0.5em;
    transition: opacity 0.3s ease-in-out;
    opacity: 0;
}

div.code-toolbar:hover > .toolbar {
    opacity: 1;
}

div.code-toolbar > .toolbar .toolbar-item {
    display: inline-block;
}

div.code-toolbar > .toolbar button {
    background: rgba(59, 130, 246, 0.9);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

div.code-toolbar > .toolbar button:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

div.code-toolbar > .toolbar button:active {
    transform: translateY(0);
}

/* Dark mode adjustments for copy button */
.dark div.code-toolbar > .toolbar button {
    background: rgba(96, 165, 250, 0.9);
}

.dark div.code-toolbar > .toolbar button:hover {
    background: #60a5fa;
    box-shadow: 0 2px 8px rgba(96, 165, 250, 0.3);
}

/* Code block container */
pre[class*="language-"] {
    border-radius: 8px;
    margin: 1.5em 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.dark pre[class*="language-"] {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Header Copy Link Button */
.header-copy-link {
    padding: 4px 8px;
    border-radius: 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    vertical-align: middle;
    font-size: 0.875em;
}

.header-copy-link:hover {
    background: rgba(59, 130, 246, 0.1);
}

.dark .header-copy-link:hover {
    background: rgba(96, 165, 250, 0.1);
}

/* Ensure headers can show the button on hover */
.md-header-tag {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.md-header-tag:hover .header-copy-link {
    opacity: 1 !important;
}

/* Search popup blur background */
.search-blur-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    background-color: rgba(0, 0, 0, 0.2);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.search-blur-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.dark .search-blur-backdrop {
    background-color: rgba(0, 0, 0, 0.4);
}

/* Spinner Animation */
.spinner-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(59, 130, 246, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.dark .spinner {
    border: 4px solid rgba(96, 165, 250, 0.2);
    border-top-color: #60a5fa;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* ============================================
   MODERN ENHANCEMENTS
   ============================================ */

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

/* Skip to content link */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.focus\:not-sr-only:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Fade in animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* Improved code block styling */
.doc-content pre {
    position: relative;
}

.doc-content pre:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Header anchor links */
.doc-content h1, .doc-content h2, .doc-content h3, .doc-content h4, .doc-content h5, .doc-content h6 {
    position: relative;
    scroll-margin-top: 5rem;
}

.header-copy-button {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.group:hover .header-copy-button {
    opacity: 1;
}

/* Better focus styles for accessibility */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
    border-radius: 0.25rem;
}

.dark a:focus-visible, .dark button:focus-visible, .dark input:focus-visible, .dark textarea:focus-visible {
    outline-color: #60a5fa;
}

/* Prose enhancements */
.prose {
    max-width: none;
}

.prose img {
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.prose a {
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: all 0.2s ease;
}

.prose a:hover {
    text-decoration-thickness: 2px;
}

/* Table styling */
.prose table {
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 0.5rem;
    overflow: hidden;
}

.prose th {
    background-color: #f3f4f6;
}

.dark .prose th {
    background-color: #374151;
}

/* Callout boxes */
.prose blockquote {
    border-left-width: 4px;
    border-radius: 0.25rem;
    background-color: #f3f4f6;
    padding: 1rem 1.5rem;
}

.dark .prose blockquote {
    background-color: #1f2937;
}

/* Button hover effects */
button, .button {
    transition: all 0.2s ease;
}

button:hover, .button:hover {
    transform: translateY(-1px);
}

button:active, .button:active {
    transform: translateY(0);
}

/* Card hover effects */
.card-hover {
    transition: all 0.3s ease;
}

.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Gradient text */
.gradient-text {
    background: linear-gradient(to right, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.dark .gradient-text {
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Loading skeleton */
.skeleton {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

.dark .skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Tooltip */
[data-tooltip] {
    position: relative;
}

[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 0.75rem;
    background-color: #1f2937;
    color: white;
    font-size: 0.875rem;
    border-radius: 0.375rem;
    white-space: nowrap;
    z-index: 50;
    margin-bottom: 0.5rem;
}

/* Print styles */
@media print {
    nav, aside, footer, .no-print {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
    
    a {
        text-decoration: underline;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
}

/* Responsive utilities */
@media (max-width: 640px) {
    .prose {
        font-size: 0.875rem;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    * {
        border-color: currentColor !important;
    }
}
