/*!
 * Standalone PDF Export Button Styling
 * Version: 1.2.4
 * Description: Minimal positioning styles for standalone post PDF export
 * Author: Innomis (Dennis Kasper)
 *
 * IMPORTANT: This file provides ONLY positioning and wrapper styles.
 * All button, dropdown, and UI styles are inherited from ktree.css to
 * ensure 100% visual consistency with K-Tree PDF export buttons.
 */

/* ==========================================================================
   ROOT FONT SIZE OVERRIDE FOR STANDALONE POSTS
   ========================================================================== */

/* Override ktree.css root font-size (16px) with 18px for standalone posts
 * Uses same specificity as ktree.css (:root:root) to ensure override works */
:root:root {
    font-size: 18px !important;
}

/* ==========================================================================
   STANDALONE PDF EXPORT WRAPPER (Positioning Only)
   ========================================================================== */

.ktree-standalone-pdf-wrapper {
    /* CRITICAL FIX: Zero-height wrapper with sticky positioning
     * Takes no space in document flow but allows sticky behavior
     * Button is absolutely positioned inside sticky container */
    position: sticky;
    top: 105px; /* Default: TOC disabled - Distance from top when stuck */
    height: 0; /* CRITICAL: Zero height - takes no vertical space */
    width: 100%; /* Full width for positioning context */
    z-index: 9999 !important; /* Very high to ensure it's above TOC and other elements */

    /* Pointer events only on children, not wrapper */
    pointer-events: none;

    /* Smooth appearance */
    animation: ktree-fade-in 0.3s ease;
}

/* Sticky positioning adjustments based on TOC visibility */
body.has-toc-topbar .ktree-standalone-pdf-wrapper {
    top: 173px; /* TOC Top Bar visible */
}

body.has-toc-sidebar .ktree-standalone-pdf-wrapper {
    top: 105px; /* TOC Sidebar visible (will be adjusted via JavaScript if needed) */
}

body.has-toc-none .ktree-standalone-pdf-wrapper,
body:not(.has-toc-topbar):not(.has-toc-sidebar) .ktree-standalone-pdf-wrapper {
    top: 105px; /* TOC disabled or not detected */
}

/* TOC-specific export group positioning adjustments */
body.has-toc-topbar .ktree-standalone-pdf-wrapper .ktree-export-group,
body.has-toc-none .ktree-standalone-pdf-wrapper .ktree-export-group,
body:not(.has-toc-topbar):not(.has-toc-sidebar) .ktree-standalone-pdf-wrapper .ktree-export-group {
    right: 0.85em; /* Increased spacing when top bar TOC is visible or TOC is off */
}

@keyframes ktree-fade-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   EXPORT GROUP (Inherit from ktree.css)
   ========================================================================== */

/* All button, dropdown, and UI styles are inherited from ktree.css */
/* The .ktree-export-group, .ktree-export-btn, .ktree-export-dropdown classes
   use the exact same styles as in K-Tree for perfect visual consistency */

.ktree-standalone-pdf-wrapper .ktree-export-group {
    /* Absolute positioning to remove from document flow
     * Positioned relative to sticky wrapper for scroll behavior */
    position: absolute;
    top: 0;
    right: 0.6em; /* Distance from right edge (default for sidebar) */

    /* Re-enable pointer events on button */
    pointer-events: auto;

    /* Stacking */
    z-index: 10000;
}

/* Make standalone button slightly larger for better visibility */
.ktree-standalone-pdf-wrapper .ktree-btn {
    height: 36px !important; /* Increased from 32px */
    padding: 0 10px !important; /* Base padding */
    display: flex !important;
    align-items: center !important;
}

/* White background for the main export button in standalone context, not dropdown buttons */
.ktree-standalone-pdf-wrapper .ktree-export-group > .ktree-export-btn:not(.active) {
    background: #f3f4f6 !important; /* Light gray background for standalone context when not active */
}

/* When active/clicked, use the normal primary color from K-Tree */
.ktree-standalone-pdf-wrapper .ktree-export-group > .ktree-export-btn.active {
    background: var(--ktree-primary) !important;
    color: white !important;
    border-color: var(--ktree-primary) !important;
}

.ktree-standalone-pdf-wrapper .ktree-btn i {
    width: 18px !important; /* Increased from 16px */
    height: 18px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Export button needs extra right padding for dropdown arrow */
.ktree-standalone-pdf-wrapper .ktree-export-btn {
    padding-right: 32px !important; /* Space for dropdown arrow */
}

/* Direct export mode - reduce padding when no chevron */
.ktree-standalone-pdf-wrapper .ktree-btn.ktree-export-btn.ktree-direct-export {
    padding-right: var(--ktree-space-sm) !important; /* Minimal padding, no chevron space (8px) */
}

/* Adjust dropdown arrow positioning for larger button */
.ktree-standalone-pdf-wrapper .ktree-dropdown-arrow {
    width: 14px !important; /* Slightly larger */
    height: 14px !important;
    right: 9px !important; /* Positioned in the extra padding space */
    top: 50% !important;
    transform: translateY(-50%) !important;
}

/* Ensure dropdown is positioned correctly in standalone context */
.ktree-standalone-pdf-wrapper .ktree-export-dropdown {
    z-index: 10001 !important; /* Above button to ensure visibility */
}

/* Tooltip Z-Index override for standalone buttons */
.ktree-standalone-pdf-wrapper [data-tooltip]::before,
.ktree-standalone-pdf-wrapper [data-tooltip]::after {
    z-index: 9999999 !important; /* Extremely high to ensure tooltip is above Avada header (max 999999) and all other elements */
}

/* Tooltip position override: Main export button opens downwards */
.ktree-standalone-pdf-wrapper .ktree-export-btn[data-tooltip]::before {
    bottom: auto !important;
    top: calc(100% + 8px) !important; /* Position below button */
}

.ktree-standalone-pdf-wrapper .ktree-export-btn[data-tooltip]::after {
    bottom: auto !important;
    top: calc(100% + 3px) !important; /* Arrow below button */
    border-top: none !important;
    border-bottom: 5px solid rgba(0, 0, 0, 0.9) !important; /* Arrow pointing upwards */
}

/* Hide main button tooltip when dropdown is open */
.ktree-standalone-pdf-wrapper .ktree-export-btn[data-tooltip].active::before,
.ktree-standalone-pdf-wrapper .ktree-export-btn[data-tooltip].active::after,
.ktree-standalone-pdf-wrapper .ktree-export-group.active .ktree-export-btn[data-tooltip]::before,
.ktree-standalone-pdf-wrapper .ktree-export-group.active .ktree-export-btn[data-tooltip]::after {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Format options (Portrait/Landscape) keep their tooltips opening upwards (default behavior) */
/* No override needed - they inherit from ktree.css */

/* ==========================================================================
   OVERRIDE: Remove micro-animation on Create PDF button hover
   ========================================================================== */

.ktree-standalone-pdf-wrapper .ktree-generate-pdf-btn:hover,
.ktree-standalone-pdf-wrapper .ktree-generate-pdf-btn:focus,
.ktree-standalone-pdf-wrapper .ktree-generate-pdf-btn:active {
    /* Remove transform animation - keep consistent with K-Tree */
    transform: none !important;
}

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

/* Smartphones - hide PDF export button on very small screens */
@media (max-width: 768px) {
    .ktree-standalone-pdf-wrapper {
        display: none !important;
    }
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
    .ktree-standalone-pdf-wrapper {
        display: none !important;
    }
}

/* ==========================================================================
   RTL (RIGHT-TO-LEFT) SUPPORT
   ========================================================================== */

[dir="rtl"] .ktree-standalone-pdf-wrapper {
    float: left;
    margin: 0 var(--ktree-space-md, 16px) var(--ktree-space-md, 16px) 0;
}
