/**
 * Outline Panel Styles
 *
 * Right sidebar showing table of contents / outline
 * for navigating long HTML and Markdown notes.
 */

/* OUTLINE PANEL */

#outline-panel {
    width: var(--outline-width, 280px);
    min-width: 0;
    max-width: 500px;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0px 16px 16px 16px;
    box-sizing: border-box;
    background: #f8f9fa;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #dee2e6;
    /* Hide scrollbars but keep scroll functionality */
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none; /* Firefox */
    transition: width 0.3s ease, padding 0.3s ease;
}

/* Hide scrollbar for Chrome, Safari and Opera */
#outline-panel::-webkit-scrollbar {
    display: none;
}

/* Outline header */
.outline-header {
    position: sticky;
    top: 0;
    z-index: 1;
    margin: -16px -16px 16px;
    padding: 16px 16px 12px;
    background: #f8f9fa;
    /* border-bottom: 1px solid #dee2e6; */
}

.outline-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    text-align: center;
}

.outline-close-btn {
    position: absolute;
    top: 12px;
    right: 15px;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: #6c757d;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.outline-close-btn:hover,
.outline-close-btn:focus {
    background: rgba(0, 125, 184, 0.1);
    color: #007DB8;
}

.outline-close-btn i {
    width: 14px;
    height: 14px;
}

/* Outline navigation list */
.outline-nav {
    list-style: none;
    padding: 0;
    margin: 0;
    /* Reserve room so the last items can scroll clear of the sticky header above */
    padding-bottom: 45px;
}

.outline-nav-item {
    margin: 0;
    padding: 0;
}

.outline-nav-link {
    display: block;
    padding: 6px 12px;
    color: #495057;
    text-decoration: none;
    border-radius: 4px;
    font-size: 0.875rem;
    line-height: 1.4;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.outline-nav-link:hover {
    background: rgba(0, 125, 184, 0.1);
    color: #007DB8;
}

.outline-nav-link.active {
    background: rgba(0, 125, 184, 0.15);
    color: #007DB8;
    font-weight: 500;
}

/* Heading levels - indentation */
.outline-nav-link[data-level="1"] {
    font-weight: 600;
    padding-left: 12px;
    font-size: 0.9rem;
}

.outline-nav-link[data-level="2"] {
    padding-left: 24px;
}

.outline-nav-link[data-level="3"] {
    padding-left: 36px;
    font-size: 0.85rem;
}

.outline-nav-link[data-level="4"] {
    padding-left: 48px;
    font-size: 0.85rem;
}

.outline-nav-link[data-level="5"] {
    padding-left: 60px;
    font-size: 0.825rem;
}

.outline-nav-link[data-level="6"] {
    padding-left: 72px;
    font-size: 0.825rem;
}

/* Empty state */
.outline-empty {
    padding: 32px 12px;
    text-align: center;
    color: #adb5bd;
    font-size: 0.875rem;
}

.outline-empty-icon {
    font-size: 2rem;
    margin-bottom: 8px;
    opacity: 0.5;
}

.outline-empty-text {
    margin: 0;
}

/* Outline resize handle */
.outline-resize-handle {
    height: 100vh;
    background: #f8f9fa;
    cursor: col-resize;
    position: relative;
    flex-shrink: 0;
    border-left: 1px solid #dee2e6;
}

/* Extend hover area for easier button access */
.outline-resize-handle::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    right: -8px;
    bottom: 0;
    z-index: 1;
}

/* Toggle outline button */
.toggle-outline-btn {
    position: absolute;
    top: 50%;
    right: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 25px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px 0 0 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-size: 0.875rem;
    padding: 0;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    opacity: 1;
    pointer-events: auto;
}

body:not(.outline-collapsed) .toggle-outline-btn {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.outline-resize-handle:hover .toggle-outline-btn,
.toggle-outline-btn:focus {
    opacity: 1;
    pointer-events: auto;
}

.toggle-outline-btn:hover {
    background: #f8f9fa;
    color: #007DB8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.toggle-outline-btn:disabled,
.toggle-outline-btn[aria-disabled="true"],
html.outline-collapsed .toggle-outline-btn:disabled,
body.outline-collapsed .toggle-outline-btn:disabled {
    background: #f1f3f5;
    color: #adb5bd;
    border-color: #dee2e6;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.65;
}

.toggle-outline-btn:disabled:hover,
.toggle-outline-btn[aria-disabled="true"]:hover {
    background: #f1f3f5;
    color: #adb5bd;
    box-shadow: none;
}

.toggle-outline-btn i {
    transition: transform 0.3s ease;
    width: 12px;
    height: 12px;
}

.toggle-outline-btn .lucide,
.toggle-outline-btn [class*="lucide-"] {
    display: inline-block;
    width: 12px;
    height: 12px;
    background-color: currentColor;
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    filter: none !important;
}

/* Collapsed state */
html.outline-collapsed #outline-panel,
body.outline-collapsed #outline-panel {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0;
    overflow: hidden;
}

html.outline-collapsed .outline-resize-handle,
body.outline-collapsed .outline-resize-handle {
    cursor: default;
}

html.outline-collapsed .toggle-outline-btn,
body.outline-collapsed .toggle-outline-btn {
    right: 3px;
    border-radius: 4px 0 0 4px;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

html.outline-collapsed .toggle-outline-btn i,
body.outline-collapsed .toggle-outline-btn i {
    transform: rotate(180deg);
}

/* Mobile: Hide resize handle and toggle button, but keep panel accessible via swipe */
@media (max-width: 800px) {
    .outline-resize-handle {
        display: none !important;
    }

    .toggle-outline-btn {
        display: none !important;
    }

    /* On mobile, add smooth transitions */
    #outline-panel {
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    /* On mobile, outline is collapsed by default */
    body:not(.outline-mobile-open) #outline-panel {
        position: fixed;
        right: 0;
        top: 0;
        z-index: 2147483003;
        width: 80% !important;
        max-width: 320px !important;
        transform: translateX(100%);
        opacity: 0;
        pointer-events: none;
    }

    /* When open on mobile, make it overlay the content.
       Padding/overflow are restated because a stale desktop
       .outline-collapsed class (e.g. after a landscape->portrait
       rotation) would otherwise leave the panel with padding: 0. */
    body.outline-mobile-open #outline-panel {
        position: fixed;
        right: 0;
        top: 0;
        z-index: 2147483003;
        box-shadow: -4px 0 8px rgba(0, 0, 0, 0.2);
        width: 80% !important;
        max-width: 320px !important;
        padding: 0px 16px 16px 16px;
        overflow-y: auto;
        overflow-x: hidden;
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
    }
}

/* Overlay backdrop for mobile */
.outline-mobile-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2147483002;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

body.outline-mobile-open .outline-mobile-backdrop {
    opacity: 1;
    pointer-events: auto;
}

/* Hide outline panel, resize handle and toggle button in Kanban view */
.kanban-page #outline-panel,
.kanban-page .outline-resize-handle,
.kanban-page .toggle-outline-btn,
body.kanban-active #outline-panel,
body.kanban-active .outline-resize-handle,
body.kanban-active .toggle-outline-btn {
    display: none !important;
}

/* DARK MODE SUPPORT */

body.dark-mode #outline-panel,
html[data-theme='dark'] #outline-panel {
    background: var(--dm-sidebar-bg);
    border-left-color: var(--dm-border);
}

body.dark-mode .outline-header,
html[data-theme='dark'] .outline-header {
    background: var(--dm-sidebar-bg);
    border-bottom-color: var(--dm-border);
}

body.dark-mode .outline-title,
html[data-theme='dark'] .outline-title {
    color: #999;
}

body.dark-mode .outline-nav-link,
html[data-theme='dark'] .outline-nav-link {
    color: #ccc;
}

html.theme-black[data-theme='dark'] .outline-nav-link,
body.black-mode .outline-nav-link {
    color: #66778f;
}

body.dark-mode .outline-nav-link:hover,
html[data-theme='dark'] .outline-nav-link:hover {
    background: var(--dm-sidebar-surface);
    color: #4db8ff;
}

body.dark-mode .outline-nav-link.active,
html[data-theme='dark'] .outline-nav-link.active {
    background: var(--dm-active);
    color: #4db8ff;
}

body.dark-mode .outline-empty,
html[data-theme='dark'] .outline-empty {
    color: #666;
}

body.dark-mode .outline-resize-handle,
html[data-theme='dark'] .outline-resize-handle {
    background: var(--dm-sidebar-bg);
    border-left-color: var(--dm-border);
}

body.dark-mode .toggle-outline-btn,
html[data-theme='dark'] .toggle-outline-btn {
    background: var(--dm-sidebar-surface);
    border-color: var(--dm-border);
    color: #999;
}

body.dark-mode .toggle-outline-btn:hover,
html[data-theme='dark'] .toggle-outline-btn:hover {
    background: var(--dm-surface-hover);
    color: #4db8ff;
}

body.dark-mode .toggle-outline-btn:disabled,
body.dark-mode .toggle-outline-btn[aria-disabled="true"],
html[data-theme='dark'] .toggle-outline-btn:disabled,
html[data-theme='dark'] .toggle-outline-btn[aria-disabled="true"] {
    background: var(--dm-sidebar-surface);
    border-color: var(--dm-border);
    color: #666;
}

body.dark-mode .toggle-outline-btn:disabled:hover,
body.dark-mode .toggle-outline-btn[aria-disabled="true"]:hover,
html[data-theme='dark'] .toggle-outline-btn:disabled:hover,
html[data-theme='dark'] .toggle-outline-btn[aria-disabled="true"]:hover {
    background: var(--dm-sidebar-surface);
    color: #666;
}

.heading-anchor--floating {
    position: absolute;
    z-index: 1000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    padding: 0;
    font-size: 12px;
    line-height: 1;
    text-decoration: none;
    opacity: 0.5;
    transform: translateY(-50%);
    transition: opacity 0.15s;
    cursor: pointer;
}

.heading-anchor--floating:hover {
    opacity: 1;
}

.heading-anchor--floating[hidden] {
    display: none !important;
}

.heading-anchor--floating svg {
    width: 12px;
    height: 12px;
    fill: currentColor;
    pointer-events: none;
}

/* Heading anchor copy toast */
#heading-copy-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(0.5rem);
    background: #333;
    color: #fff;
    font-size: 0.82rem;
    padding: 0.4em 0.9em;
    border-radius: 6px;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    white-space: nowrap;
}

#heading-copy-toast.heading-copy-toast--visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#heading-copy-toast.heading-copy-toast--hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(0.5rem);
}

body.dark-mode #heading-copy-toast,
html[data-theme='dark'] #heading-copy-toast {
    background: #555;
    color: #f0f0f0;
}
