@import url('components/header.css');
@import url('components/articles.css');
@import url('components/sidebar.css');

/* ==========================================================================
   ServerSideLabs - Enhanced Responsive Stylesheet
   ========================================================================== */

/* CSS Reset & Base Styles
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent horizontal scrolling on all elements */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* CSS Variables
   ========================================================================== */
:root {
    /* Perfect aged newspaper colors */
    --paper-white: #f2ede6;
    --ink-black: #1a1a1a;
    --subtle-gray: #666666;
    --accent-gray: #888888;
    --border-gray: #c9c0b5;
    --hover-bg: rgba(139,116,95,0.06);
    --card-bg: rgba(139,116,95,0.12);
    --code-bg: #ebe4da;
    --code-bg-hover: #e4ddd2;
    
    /* Responsive spacing variables */
    --container-padding: 20px;
    --section-gap: 40px;
    --content-gap: 20px;
}

/* Dark theme variables */
[data-theme="dark"] {
    --paper-white: #0d1117;
    --ink-black: #e6e6e6;
    --subtle-gray: #b3b3b3;
    --accent-gray: #8d8d8d;
    --border-gray: #30363d;
    --hover-bg: rgba(255,255,255,0.05);
    --card-bg: rgba(255,255,255,0.02);
}

/* Base Typography & Layout
   ========================================================================== */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--paper-white);
    color: var(--ink-black);
    line-height: 1.6;
    background-image: 
        radial-gradient(circle at 1px 1px, rgba(139,116,95,0.08) 1px, transparent 0);
    background-size: 20px 20px;
    min-height: 100vh;
    /* Improved text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

[data-theme="dark"] body {
    background-image: 
        radial-gradient(circle at 1px 1px, rgba(255,255,255,0.03) 1px, transparent 0);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--container-padding);
    width: 100%;
}

/* Improved Content Overflow Prevention
   ========================================================================== */
.featured-article .content,
.article-detail .content,
.content-preview {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Long URLs and code should break appropriately */
.featured-article .content a,
.article-detail .content a {
    word-break: break-all;
    overflow-wrap: break-word;
}

/* Layout Grid - Restored Original with Responsive Improvements
   ========================================================================== */
.main-content {
    display: flex;
    gap: var(--section-gap);
    margin-bottom: 40px;
    align-items: start;
    /* Ensure content doesn't overflow */
    min-width: 0;
}

#content-area {
    flex: 2;
    min-width: 0; /* Prevents flex item from overflowing */
    /* Ensure content breaks properly */
    overflow-wrap: break-word;
}


/* Improved Code Blocks - Better Mobile Handling
   ========================================================================== */
.code-block,
.article-detail .content pre {
    background: var(--code-bg);
    border: 1px solid var(--border-gray);
    padding: 20px;
    margin: 20px 0;
    font-family: "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", "Courier New", monospace;
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    line-height: 1.4;
    cursor: pointer;
    break-inside: avoid;
    color: var(--ink-black);
    transition: background-color 0.2s ease;
    /* Prevent horizontal overflow */
    overflow-x: auto;
    white-space: pre;
    word-wrap: normal;
    /* Smooth scrolling on mobile */
    -webkit-overflow-scrolling: touch;
}

.code-block:hover {
    background: var(--code-bg-hover);
}

/* Dark theme code blocks */
[data-theme="dark"] .code-block {
    background: #161b22;
    border: 1px solid #30363d;
    color: #e6e6e6;
}

[data-theme="dark"] .code-block:hover {
    background: #1c2128;
}

.code-block .code-header {
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--subtle-gray);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Interactive Elements
   ========================================================================== */
.htmx-loading {
    opacity: 0.7;
}

.expandable {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.expandable:hover {
    background: var(--hover-bg);
}

.expanded-content {
    margin-top: 15px;
    padding: 15px;
    border-left: 3px solid var(--ink-black);
    background: var(--card-bg);
}

/* HTMX Loading States
   ========================================================================== */
.htmx-request .nav-link {
    opacity: 0.7;
}

.htmx-indicator {
    display: none;
}

.htmx-indicator.htmx-request {
    display: block;
}

/* Prevent layout shifts during HTMX swaps */
.htmx-swapping {
    opacity: 1;
}

.htmx-settling {
    opacity: 1;
}

/* Article Dividers */
.article-divider {
    border-bottom: 1px dotted var(--border-gray);
    padding: var(--content-gap) 0;
    margin-bottom: var(--content-gap);
}

/* Mobile-First Responsive Design
   ========================================================================== */

/* Large Mobile / Small Tablet: 576px - 767px */
@media (max-width: 767px) {
    :root {
        --container-padding: 15px;
        --section-gap: 20px;
        --content-gap: 15px;
    }
    
    /* Switch to stacked layout */
    .main-content {
        flex-direction: column;
        gap: var(--content-gap);
    }
}

/* Small Mobile: 480px and below */
@media (max-width: 480px) {
    :root {
        --container-padding: 10px;
        --section-gap: 15px;
        --content-gap: 10px;
    }
    
    .container {
        padding: 10px;
    }
}

/* Large Desktop: 1200px and above */
@media (min-width: 1200px) {
    .container {
        padding: 30px;
    }
    
    .main-content {
        gap: 50px;
    }
}

/* Landscape Phone Specific */
@media (max-height: 500px) and (orientation: landscape) {
    .main-content {
        margin-bottom: 20px;
    }
}

/* High DPI / Retina Display Optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Optimize text rendering for high DPI screens */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print Styles */
@media print {
    .theme-toggle,
    .nav-bar,
    .sidebar,
    .footer {
        display: none !important;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .article-detail {
        max-width: none;
    }
    
    .container {
        max-width: none;
        padding: 0;
    }
    
    /* Ensure good print typography */
    body {
        font-size: 12pt;
        line-height: 1.4;
    }
    
    .article-detail .content {
        font-size: 11pt;
    }
    
    .featured-article h2,
    .article-detail .article-title {
        font-size: 18pt;
        margin-bottom: 10pt;
    }
}

/* Focus Management for Accessibility */
a:focus,
button:focus,
[tabindex]:focus {
    outline: 2px solid var(--ink-black);
    outline-offset: 2px;
    /* Ensure focus is visible on all backgrounds */
    background: rgba(255, 255, 255, 0.1);
}

/* Skip Link - Accessible Navigation */
.skip-link {
    position: absolute !important;
    top: -100px !important;
    left: 6px !important;
    background: var(--ink-black) !important;
    color: var(--paper-white) !important;
    padding: 8px 12px !important;
    text-decoration: none !important;
    z-index: 10000 !important;
    transition: top 0.2s ease !important;
    border-radius: 4px !important;
    font-size: 0.9rem !important;
    font-weight: bold !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.skip-link:focus {
    top: 6px !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Additional responsive utilities */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Smooth transitions for theme changes */
* {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

/* Loading states for better UX */
.htmx-loading {
    opacity: 0.7;
    pointer-events: none;
}

.htmx-indicator {
    display: none;
    text-align: center;
    padding: 20px;
    color: var(--subtle-gray);
    font-style: italic;
}

.htmx-indicator.htmx-request {
    display: block;
}

/* Footer responsive adjustments */
.footer {
    border-top: 2px double var(--ink-black);
    padding-top: 20px;
    margin-top: 40px;
    text-align: center;
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    color: var(--accent-gray);
}

/* Infinite scroll improvements */
.article-divider {
    border-bottom: 1px dotted var(--border-gray);
    padding: var(--content-gap) 0;
    margin-bottom: var(--content-gap);
}

/* Animation for loading indicators */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
