/* ===========================================
   Page Layout Styles for Individual Pages
   =========================================== */

/* Page Layout - Two Column: Sidebar + Content */
.page-layout {
    display: flex;
    min-height: calc(100vh - 80px);
    padding-top: 80px;
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
    /* Ensure above background elements */
}

/* Sidebar Styles */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 2rem 1.5rem;
    position: sticky;
    top: 80px;
    height: calc(100vh - 80px);
    overflow-y: auto;
}

.sidebar-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav li {
    margin-bottom: 0.25rem;
}

.sidebar-link {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.sidebar-link:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-link.active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Sidebar with Topics and Subtopics */
.sidebar-topic {
    margin-bottom: 1.5rem;
}

.sidebar-topic-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
    padding-left: 0.5rem;
}

.sidebar-subtopics {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-subtopics li {
    margin-bottom: 0.15rem;
}

.sidebar-subtopics .sidebar-link {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    padding: 2rem 3rem;
    max-width: 900px;
    position: relative;
    /* Context for absolute children if any */
}

.content-header {
    margin-bottom: 2rem;
    /* Reduced from 3rem */
    padding-bottom: 1.5rem;
    /* Reduced from 2rem */
    border-bottom: 1px solid var(--border-color);
}

.page-title {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.page-description {
    font-size: 1.1rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

/* Breadcrumb */
.breadcrumb {
    margin-bottom: 1rem;
    /* Reduced from 1.5rem */
    font-size: 0.9rem;
}

.breadcrumb a {
    color: var(--accent-primary);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.breadcrumb span {
    color: var(--text-tertiary);
    margin: 0 0.5rem;
}

/* Content Sections */
.content-sections {
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

.content-section {
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.content-section:last-child {
    border-bottom: none;
}

.section-heading {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

.section-content {
    color: var(--text-secondary);
    line-height: 1.8;
    font-size: 1rem;
}

.section-content p {
    margin-bottom: 1rem;
}

.section-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 1.5rem 0 1rem;
}

.section-content ul,
.section-content ol {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.section-content li {
    margin-bottom: 0.5rem;
}

.section-content code {
    background: var(--bg-tertiary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
    color: var(--accent-primary);
}

.section-content pre {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 1.5rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
}

.section-content pre code {
    background: none;
    padding: 0;
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* Code blocks with syntax highlighting */
.code-block {
    background: var(--code-bg);
    /* Always Dark Background for Better Contrast */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin: 1.5rem 0;
    overflow: hidden;
}

.code-block-header {
    background: rgba(0, 0, 0, 0.2);
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-family: 'Fira Code', monospace;
}

.code-block pre {
    margin: 0;
    padding: 1.5rem;
    border: none;
    background: none;
    color: var(--code-text);
    /* Force White Text */
    text-shadow: none;
    /* remove any default shadow that might blur it */
    overflow-x: auto;
    white-space: pre;
}

/* Make tables scrollable on mobile */
/* Table Styles */
.section-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.95rem;
}

.section-content th,
.section-content td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.section-content th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
}

.section-content tr:hover td {
    background: rgba(99, 102, 241, 0.05);
}

/* Make tables scrollable on mobile */
@media (max-width: 768px) {
    .section-content table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
}

/* Force Prism to respect our color */
:not(pre)>code[class*="language-"],
pre[class*="language-"],
pre code {
    background: transparent !important;
    text-shadow: none !important;
    color: inherit;
}

code[class*="language-"],
pre[class*="language-"] {
    color: #e2e8f0 !important;
    /* Force Light Text */
}

/* Navigation Pagination */
.content-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.content-nav a {
    display: flex;
    flex-direction: column;
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s ease;
    max-width: 45%;
}

.content-nav a:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.content-nav .nav-label {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.content-nav .nav-title {
    color: var(--text-primary);
    font-weight: 600;
}

.content-nav .prev-link {
    text-align: left;
}

.content-nav .next-link {
    text-align: right;
    margin-left: auto;
}

/* Dropdown Navigation Styles */
.nav-item.has-dropdown {
    position: relative;
}

.nav-item.has-dropdown>.nav-link {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-item.has-dropdown>.nav-link::after {
    content: '▼';
    font-size: 0.6rem;
    margin-left: 0.25rem;
    transition: transform 0.2s ease;
}

.nav-item.has-dropdown:hover>.nav-link::after {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    z-index: 1000;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.nav-item.has-dropdown:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-menu a {
    display: block;
    padding: 0.75rem 1.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.dropdown-menu a:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 0;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .page-layout {
        flex-direction: column;
    }

    /* FIX: Show Content FIRST, Sidebar SECOND */
    .main-content {
        order: 1;
    }

    .sidebar {
        order: 2;
        width: 100%;
        min-width: 100%;
        height: auto;
        position: relative;
        top: 0;
        border-right: none;
        border-top: 1px solid var(--border-color);
        /* Separator on top now */
        border-bottom: 1px solid var(--border-color);
        margin-top: 2rem;
    }

    .sidebar-nav {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .sidebar-nav li {
        margin-bottom: 0;
    }

    .sidebar-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .main-content {
        padding: 2rem 1.5rem;
    }

    .page-title {
        font-size: 2rem;
    }

    .dropdown-menu {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        display: none;
    }

    .nav-item.has-dropdown.active .dropdown-menu {
        display: block;
    }
}

@media (max-width: 768px) {
    .page-layout {
        padding-top: 70px;
    }

    .sidebar {
        padding: 1.5rem 1rem;
    }

    .main-content {
        padding: 1.5rem 1rem;
    }

    .page-title {
        font-size: 1.75rem;
    }

    .section-heading {
        font-size: 1.5rem;
    }

    .content-nav {
        flex-direction: column;
        gap: 1rem;
    }

    .content-nav a {
        max-width: 100%;
    }
}

/* Simplified Footer for subpages */
.footer {
    margin-top: auto;
}

.footer .footer-bottom {
    padding: 1.5rem 0;
}

/* ===================================
   ADVERTISING LAYOUT STYLES
   =================================== */

.ad-rail-left,
.ad-rail-right {
    position: fixed;
    top: 90px;
    width: 160px;
    height: calc(100vh - 90px);
    z-index: 5;
    display: none;
    /* Hidden by default until we confirm overlap space */
}

@media (min-width: 1850px) {

    /* Only show rails on very wide screens where they won't overlap content */
    .ad-rail-left {
        display: block;
        left: 20px;
    }

    .ad-rail-right {
        display: block;
        right: 20px;
    }
}

.ad-banner-top {
    width: 100%;
    min-height: 0px;
    /* Collapse if empty */
    margin-bottom: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.ad-banner-top.has-ad {
    min-height: 90px;
    margin-bottom: 2rem;
}

/* ===================================
   Minimalistic Hero Section for Homepage
   =================================== */
.hero-minimal {
    min-height: calc(100vh - 80px);
    padding-top: 120px;
    padding-bottom: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hero-minimal-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 2rem;
    text-align: center;
}

.hero-minimal-title {
    font-size: 3rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 2rem;
    line-height: 1.2;
}

.hero-minimal-description {
    font-size: 1.2rem;
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 3rem;
}

.hero-minimal-features {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.feature-icon {
    font-size: 1.25rem;
}

.hero-minimal-cta {
    color: var(--text-tertiary);
    font-size: 1rem;
}

@media (max-width: 768px) {
    .hero-minimal {
        padding-top: 100px;
    }

    .hero-minimal-title {
        font-size: 2rem;
    }

    .hero-minimal-description {
        font-size: 1rem;
    }

    .feature-item {
        width: 100%;
        justify-content: center;
    }
}

/* ===================================
   Ad Placeholder Styles (AdSense Ready)
   =================================== */

/* Sidebar Ad Placeholder */
.ad-placeholder-sidebar {
    margin-top: 2rem;
    padding: 1rem;
    min-height: 250px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    text-align: center;
}

/* Content Ad Placeholder - Between sections */
.ad-placeholder-content {
    margin: 2rem 0;
    padding: 1.5rem;
    min-height: 100px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    text-align: center;
}

/* Footer Ad Placeholder */
.ad-placeholder-footer {
    margin: 2rem auto;
    padding: 1.5rem;
    max-width: 728px;
    min-height: 90px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    text-align: center;
}

/* Hide ad placeholder text when ads are active */
.ad-placeholder-sidebar.ad-active,
.ad-placeholder-content.ad-active,
.ad-placeholder-footer.ad-active {
    background: transparent;
    border: none;
    padding: 0;
    min-height: auto;
}

/* Responsive ad adjustments */
@media (max-width: 768px) {
    .ad-placeholder-sidebar {
        min-height: 100px;
    }

    .ad-placeholder-footer {
        max-width: 100%;
        margin: 1rem;
    }
}

/* ===================================
   MOBILE STABILITY FIXES (PREVENT GLITCHING)
   =================================== */
@media (max-width: 768px) {

    html,
    body {
        overflow-x: hidden;
        /* Stop horizontal scroll */
        width: 100%;
        position: relative;
    }

    .page-layout {
        width: 100%;
        overflow-x: hidden;
    }

    .sidebar {
        max-width: 100%;
        box-sizing: border-box;
        /* Make sidebar collapsible or smaller if needed, for now ensure no overflow */
    }

    .main-content {
        max-width: 100vw;
        /* Ensure content doesn't stretch page */
        box-sizing: border-box;
        overflow-x: hidden;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .code-block,
    pre {
        max-width: 100%;
        width: 100%;
        overflow-x: auto;
        /* Allow code to scroll internally */
    }

    /* Ad Containment */
    .ad-placeholder-sidebar,
    .ad-banner-top,
    ins.adsbygoogle {
        max-width: 100% !important;
        overflow: hidden;
        box-sizing: border-box;
    }
}

/* ===================================
   Enhanced Beginner-Friendly Styles
   =================================== */

/* Info boxes for key concepts */
.info-box {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(6, 182, 212, 0.1) 100%);
    border-left: 4px solid var(--primary);
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0 8px 8px 0;
}

.info-box h4 {
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.info-box p {
    margin: 0;
    color: var(--text-secondary);
}

/* Tip boxes */
.tip-box {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(52, 211, 153, 0.1) 100%);
    border-left: 4px solid #10b981;
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0 8px 8px 0;
}

.tip-box h4 {
    color: #10b981;
    margin-bottom: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.tip-box p {
    margin: 0;
    color: var(--text-secondary);
}

/* Warning boxes */
.warning-box {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1) 0%, rgba(251, 191, 36, 0.1) 100%);
    border-left: 4px solid #f59e0b;
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0 8px 8px 0;
}

.warning-box h4 {
    color: #f59e0b;
    margin-bottom: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.warning-box p {
    margin: 0;
    color: var(--text-secondary);
}

/* Simple analogy styling */
.analogy {
    font-style: italic;
    color: var(--text-secondary);
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin: 1rem 0;
}

.analogy::before {
    content: '💡 ';
}

/* Key terms highlighting */
.key-term {
    font-weight: 600;
    color: var(--primary);
}

/* Comparison Table Styles */
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.95rem;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.comparison-table thead {
    background-color: var(--bg-tertiary);
    border-bottom: 2px solid var(--border-color);
}

.comparison-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.comparison-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.comparison-table tr:last-child td {
    border-bottom: none;
}

.comparison-table tr:hover {
    background-color: var(--bg-card);
}

/* ===================================
   INTERVIEW Q&A STYLES (STRUCTURED)
   =================================== */

.qa-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: all 0.3s ease;
}

.qa-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.qa-question {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.qa-question::before {
    content: "Q";
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.qa-answer {
    color: var(--text-secondary);
    padding-left: 2rem;
    line-height: 1.7;
}

/* Clean Answer Code Blocks */
.qa-answer :not(pre)>code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    color: var(--accent-primary);
}

.qa-answer pre code {
    background: none;
    padding: 0;
}

.difficulty-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.difficulty-beginner {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.difficulty-intermediate {
    background: rgba(234, 179, 8, 0.15);
    color: #eab308;
}

.difficulty-advanced {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.topic-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 2rem 0 1rem 0;
}

.topic-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.topic-header .difficulty-badge {
    margin-left: 0;
    /* Reset for header */
}