/* Document Editor Sidebar Styles */

.editor-sidebar {
    width: 200px;
    height: 100%; /* Fill parent height */
    background: var(--bg-primary, white);
    border-right: 1px solid var(--border-color, #e0e0e0);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

/* Sidebar Panel */
.sidebar-panel {
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}

/* Pages panel fills available space */
.sidebar-panel.pages-panel {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Document Info panel - always visible at bottom */
.sidebar-panel:last-child {
    flex: 0 0 auto;
    border-bottom: none;
}

.sidebar-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary, #666);
    background: var(--bg-secondary, #f5f5f5);
    user-select: none;
}

.sidebar-panel-header.collapsible {
    cursor: pointer;
}

.sidebar-panel-header.collapsible:hover {
    background: var(--bg-hover, #eee);
}

.collapse-icon {
    transition: transform 0.2s;
}

.sidebar-panel.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.sidebar-panel.collapsed .sidebar-panel-content {
    display: none;
}

.sidebar-panel-content {
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}

.sidebar-btn {
    position: relative; /* Required for data-tooltip CSS */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary, #666);
    transition:
        background-color 0.15s,
        color 0.15s;
}

.sidebar-btn:hover {
    background: var(--bg-hover, #e0e0e0);
    color: var(--text-primary, #333);
}

/* Pages List */
#pages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.page-thumbnail {
    position: relative;
    /* aspect-ratio set dynamically by JS based on page layout */
    aspect-ratio: 210 / 297; /* fallback: A4 portrait */
    background: white;
    border: 2px solid var(--border-color, #e0e0e0);
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    flex-shrink: 0; /* Don't compress thumbnails - scroll instead */
    transition:
        border-color 0.15s,
        box-shadow 0.15s,
        aspect-ratio 0.2s;
}

.page-thumbnail.landscape {
    /* Landscape pages get visual indicator */
}

.page-thumbnail.portrait {
    /* Portrait pages - default */
}

.page-thumbnail:hover {
    border-color: var(--primary-color, #2196f3);
}

.page-thumbnail.active {
    border-color: var(--primary-color, #2196f3);
    box-shadow: 0 0 0 2px var(--primary-light, rgba(33, 150, 243, 0.2));
}

/* Viewport indicator for pages list */
.viewport-indicator {
    position: absolute;
    left: 4px;
    right: 4px;
    border: 2px solid var(--primary-color, #2196f3);
    background: var(--primary-light, rgba(33, 150, 243, 0.1));
    border-radius: 4px;
    pointer-events: none;
    transition:
        top 0.05s ease-out,
        height 0.1s ease-out;
}

.page-thumbnail canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.page-number {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 8px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 10px;
    border-radius: 2px;
}

.page-thumbnail .page-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: none;
    gap: 2px;
}

.page-thumbnail:hover .page-actions {
    display: flex;
}

.page-action-btn {
    position: relative; /* Required for data-tooltip CSS */
    width: 20px;
    height: 20px;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary, #666);
    transition: background-color 0.15s;
}

.page-action-btn:hover {
    background: white;
    color: var(--text-primary, #333);
}

.page-action-btn.danger:hover {
    color: var(--danger-color, #f44336);
}

/* Document Info */
#document-info {
    padding: 12px 16px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px;
}

.info-row:last-child {
    margin-bottom: 0;
}

.info-label {
    color: var(--text-secondary, #666);
}

.info-value {
    color: var(--text-primary, #333);
    font-weight: 500;
}

/* Users Online (Phase 3) */
.users-online {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-online {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.user-online-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
}

.user-online-name {
    font-size: 12px;
    color: var(--text-primary, #333);
}

/* Comments List (Phase 3) */
.comments-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.comment-item {
    padding: 8px;
    background: #fff9c4;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.comment-item:hover {
    background: #fff59d;
}

.comment-item.resolved {
    opacity: 0.5;
}

.sidebar-empty {
    padding: 12px 8px;
    font-size: 12px;
    color: var(--text-secondary, #999);
    text-align: center;
    font-style: italic;
}

/* Responsive */
@media (max-width: 1024px) {
    .editor-sidebar {
        width: 160px;
    }
}

@media (max-width: 768px) {
    .editor-sidebar {
        position: fixed;
        left: -200px;
        top: 61px; /* Header height (60px + 1px border) */
        height: calc(100vh - 61px);
        z-index: 100;
        transition: left 0.3s;
    }

    .editor-sidebar.open {
        left: 0;
    }

    /* Hide footbar on mobile (no sidebar = no footbar) */
    .footbar,
    .footbar-trigger {
        display: none !important;
    }
}

/* Dark theme */
[data-theme='dark'] .editor-sidebar {
    background: var(--bg-primary);
    border-color: var(--border-color);
}

[data-theme='dark'] .sidebar-panel-header {
    background: var(--bg-secondary);
}

[data-theme='dark'] .page-thumbnail {
    background: white; /* Page thumbnails stay white - they represent paper */
    border-color: var(--border-color);
}

[data-theme='dark'] .sidebar-empty {
    color: var(--text-secondary);
}

/* Sidebar Version History */
.sidebar-version-history {
    margin-top: var(--space-3, 12px);
    padding-top: var(--space-3, 12px);
    border-top: 1px solid var(--border-color, #e0e0e0);
}

.sidebar-version-header {
    margin-bottom: var(--space-2, 8px);
}

.sidebar-version-list {
    max-height: 300px;
    overflow-y: auto;
    padding-right: 4px;
}

.sidebar-version-loading,
.sidebar-version-empty {
    font-size: 12px;
    color: var(--text-secondary, #666);
    text-align: center;
    padding: var(--space-2, 8px);
    font-style: italic;
}

/* Reuse version-history styles but adapt for sidebar */
.sidebar-version-list .version-history-date-group {
    margin-bottom: var(--space-2, 8px);
}

.sidebar-version-list .version-history-date {
    font-size: 10px;
    padding: var(--space-1, 4px) 0;
    margin-bottom: var(--space-1, 4px);
}

.sidebar-version-list .version-history-entry {
    padding: var(--space-1, 4px) 0;
    gap: var(--space-2, 8px);
}

.sidebar-version-list .version-history-timeline {
    width: 16px;
}

.sidebar-version-list .timeline-dot {
    width: 8px;
    height: 8px;
}

.sidebar-version-list .timeline-line {
    min-height: 14px;
}

.sidebar-version-list .version-history-time {
    font-size: 10px;
}

.sidebar-version-list .version-history-action {
    font-size: 10px;
    padding: 1px 4px;
}

.sidebar-version-list .version-history-meta {
    font-size: 10px;
}

.sidebar-version-list .version-history-restore {
    width: 22px;
    height: 22px;
}

.sidebar-version-list .version-history-restore svg {
    width: 12px;
    height: 12px;
}

/* Active version highlight */
.sidebar-version-list .version-history-entry.active {
    background: rgba(33, 150, 243, 0.1);
    border-radius: var(--radius-sm, 4px);
}

.sidebar-version-list .version-history-entry.active .timeline-dot {
    background: var(--accent-color, #2196f3);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
}

/* ==============================================
   Bookmarks Panel Styles
   ============================================== */

.bookmarks-panel .sidebar-panel-header {
    display: flex;
    align-items: center;
    gap: var(--space-2, 8px);
}

.bookmarks-panel .sidebar-panel-header span {
    flex: 1;
}

.bookmarks-panel .sidebar-btn {
    margin-right: var(--space-1, 4px);
}

/* Empty state */
.sidebar-empty-state {
    padding: var(--space-3, 12px);
    text-align: center;
    color: var(--text-tertiary, #999);
    font-size: 12px;
    font-style: italic;
}

/* Bookmark list */
#bookmarks-list {
    max-height: 200px;
    overflow-y: auto;
}

/* Bookmark item */
.bookmark-item {
    display: flex;
    align-items: center;
    gap: var(--space-2, 8px);
    padding: var(--space-2, 8px) var(--space-3, 12px);
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.bookmark-item:last-child {
    border-bottom: none;
}

.bookmark-item:hover {
    background: var(--bg-hover, #f5f5f5);
}

.bookmark-item.active {
    background: rgba(33, 150, 243, 0.1);
}

/* Bookmark icon */
.bookmark-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    color: var(--accent-color, #2196f3);
}

/* Bookmark name */
.bookmark-name {
    flex: 1;
    font-size: 12px;
    color: var(--text-primary, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Bookmark page info */
.bookmark-page {
    font-size: 10px;
    color: var(--text-secondary, #666);
    white-space: nowrap;
}

/* Bookmark actions */
.bookmark-actions {
    display: flex;
    gap: var(--space-1, 4px);
    opacity: 0;
    transition: opacity 0.15s;
}

.bookmark-item:hover .bookmark-actions {
    opacity: 1;
}

.bookmark-action-btn {
    position: relative; /* Required for data-tooltip CSS */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm, 4px);
    color: var(--text-secondary, #666);
    cursor: pointer;
    transition: all 0.15s;
}

.bookmark-action-btn:hover {
    background: var(--bg-tertiary, #eee);
    color: var(--text-primary, #333);
}

.bookmark-action-btn.delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error-color, #ef4444);
}

/* Bookmark marker in text */
.bookmark-marker {
    display: inline-block;
    width: 0;
    height: 1em;
    border-left: 2px solid var(--accent-color, #2196f3);
    margin: 0 1px;
    vertical-align: text-bottom;
    cursor: pointer;
    position: relative;
}

.bookmark-marker::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -4px;
    width: 6px;
    height: 6px;
    background: var(--accent-color, #2196f3);
    border-radius: 50%;
}

.bookmark-marker:hover::after {
    content: attr(data-name);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 6px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: var(--radius-sm, 4px);
    font-size: 11px;
    color: var(--text-primary, #333);
    white-space: nowrap;
    z-index: 10;
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.1));
}

/* Page preview clone in sidebar thumbnails */
.page-preview-clone {
    /* Inherit page-container visual styles without the class */
    background: white;
    box-shadow: none;
}

/* ==============================================
   Footbar (Horizontal Mode Page Navigation)
   ============================================== */

/* Trigger button in bottom-right corner */
.footbar-trigger {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: none; /* Hidden by default, shown in horizontal mode */
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: all 0.2s ease;
}

.footbar-trigger:hover {
    background: var(--bg-secondary, #f5f5f5);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

.footbar-trigger.active {
    background: var(--accent-color, #2196f3);
    border-color: var(--accent-color, #2196f3);
    color: white;
}

.footbar-trigger svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary, #666);
}

.footbar-trigger:hover svg,
.footbar-trigger.active svg {
    color: inherit;
}

/* Show trigger in horizontal mode (trigger is in body, so use body class) */
body.horizontal-view-mode .footbar-trigger {
    display: flex;
}

/* Hide pages panel in sidebar when in horizontal mode */
body.horizontal-view-mode .pages-panel {
    display: none;
}

/* Footbar container */
.footbar {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width, 200px); /* Account for sidebar */
    right: 0;
    height: 80px;
    background: var(--bg-primary, #fff);
    border-top: 1px solid var(--border-color, #e0e0e0);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.1);
    z-index: 99;
    display: none; /* Hidden by default */
    transform: translateY(100%);
    transition:
        transform 0.3s ease,
        left 0.3s ease;
}

.footbar.visible {
    display: block;
    transform: translateY(0);
}

/* Footbar inner layout */
.footbar-inner {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 8px 16px;
    gap: 8px;
}

/* Footbar pages container with horizontal scroll */
.footbar-pages {
    flex: 1;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px;
    position: relative;
    scroll-behavior: smooth;
}

/* Hide scrollbar but keep functionality */
.footbar-pages::-webkit-scrollbar {
    height: 4px;
}

.footbar-pages::-webkit-scrollbar-track {
    background: transparent;
}

.footbar-pages::-webkit-scrollbar-thumb {
    background: var(--border-color, #ccc);
    border-radius: 2px;
}

.footbar-pages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary, #999);
}

/* Footbar thumbnail - smaller than sidebar (half size) */
.footbar-thumbnail {
    flex-shrink: 0;
    width: 45px; /* Half of sidebar thumbnail width */
    height: 60px; /* Proportional height */
    background: white;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: all 0.15s ease;
}

.footbar-thumbnail:hover {
    border-color: var(--accent-color, #2196f3);
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.2);
}

.footbar-navigating .footbar-thumbnail:hover {
    border-color: transparent;
    box-shadow: none;
}

.footbar-thumbnail.active {
    border-color: var(--accent-color, #2196f3);
    border-width: 2px;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

/* Page number badge */
.footbar-thumbnail-number {
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 8px;
    color: var(--text-secondary, #666);
    background: rgba(255, 255, 255, 0.9);
    padding: 1px 3px;
    border-radius: 2px;
    line-height: 1;
}

/* Footbar thumbnail content */
.footbar-thumbnail-content {
    position: relative;
    width: 100%;
    height: 100%;
    transform-origin: top left;
    pointer-events: none;
    overflow: hidden;
}

/* Viewport indicator overlay for footbar */
.footbar-viewport-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.footbar-viewport-indicator {
    position: absolute;
    top: 0;
    bottom: 0;
    background: var(--primary-light, rgba(33, 150, 243, 0.15));
    border-left: 2px solid var(--primary-color, #2196f3);
    border-right: 2px solid var(--primary-color, #2196f3);
    transition:
        left 0.1s ease,
        width 0.1s ease;
}

/* Close button for footbar */
.footbar-close {
    position: relative; /* Required for data-tooltip CSS */
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary, #666);
    transition: all 0.15s;
}

.footbar-close:hover {
    background: var(--bg-secondary, #f5f5f5);
    color: var(--text-primary, #333);
}

/* Dark theme support */
[data-theme='dark'] .footbar-trigger {
    background: var(--bg-secondary, #2d2d2d);
    border-color: var(--border-color, #444);
}

[data-theme='dark'] .footbar-trigger:hover {
    background: var(--bg-tertiary, #3d3d3d);
}

[data-theme='dark'] .footbar {
    background: var(--bg-primary, #1a1a1a);
    border-color: var(--border-color, #444);
}

[data-theme='dark'] .footbar-thumbnail {
    background: white; /* Page thumbnails stay white - they represent paper */
    border-color: var(--border-color, #444);
}

[data-theme='dark'] .footbar-thumbnail-number {
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-secondary, #aaa);
}
