/* ========================================
   Workspace Dock (Collapsible Left Sidebar)

   Three states:
   - Collapsed (default): 60px wide, centered icons only
   - Stage1 (1st click):  140px wide, short labels visible
   - Stage2 (2nd click): 200px wide, full labels visible

   Z-index is set BELOW the header nav.
   ======================================== */

.workspace-dock {
    position: fixed;
    top: var(--header-height, 60px);
    left: 0;
    width: 60px;
    height: calc(100vh - var(--header-height, 60px));
    background-color: #ffffff;
    z-index: 99;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.06);
    transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* Stage 1: partially expanded */
.workspace-dock.stage1 {
    width: 140px;
}

/* Stage 2: fully expanded */
.workspace-dock.stage2 {
    width: 200px;
}

[data-theme="dark"] .workspace-dock,
.dark .workspace-dock {
    background-color: #1e1e2e;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.25);
}

/* Toggle button */
.dock-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 48px;
    background: none;
    border: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.dock-toggle:hover {
    background-color: rgba(0, 0, 0, 0.04);
    color: #222;
}
.dock-toggle svg {
    flex-shrink: 0;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Rotate icon at stage2 */
.workspace-dock.stage2 .dock-toggle svg {
    transform: rotate(180deg);
}

[data-theme="dark"] .dock-toggle,
.dark .dock-toggle {
    border-bottom-color: rgba(255, 255, 255, 0.08);
    color: #cdd6f4;
}
[data-theme="dark"] .dock-toggle:hover,
.dark .dock-toggle:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: #fff;
}

/* Navigation area */
.dock-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
/* At stage1 and stage2, align items to start */
.workspace-dock.stage1 .dock-nav,
.workspace-dock.stage2 .dock-nav {
    align-items: stretch;
}

/* Nav item */
.dock-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 44px;
    padding: 0;
    color: #555;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.18s ease;
    white-space: nowrap;
    position: relative;
    gap: 0;
}
.dock-item svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    stroke-width: 1.8;
    transition: stroke 0.15s;
}

/* Labels - both hidden by default (collapsed) */
.dock-label {
    display: none;
    font-size: 14px;
    font-weight: 400;
    pointer-events: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Stage1: show short labels, hide full labels */
.workspace-dock.stage1 .dock-item {
    justify-content: flex-start;
    width: 100%;
    padding: 0 14px;
    gap: 10px;
}
.workspace-dock.stage1 .dock-label-short {
    display: inline;
    max-width: 66px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.workspace-dock.stage1 .dock-label-full {
    display: none;
}

/* Stage2: show full labels */
.workspace-dock.stage2 .dock-item {
    justify-content: flex-start;
    width: 100%;
    padding: 0 16px;
    gap: 12px;
}
.workspace-dock.stage2 .dock-label-short {
    display: none;
}
.workspace-dock.stage2 .dock-label-full {
    display: inline;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hover / Active state */
.dock-item:hover {
    background-color: rgba(145, 53, 0, 0.06);
    color: #913500;
}
.dock-item:hover svg {
    stroke: #913500;
}
.dock-item.active {
    background-color: rgba(145, 53, 0, 0.1);
    color: #913500;
    font-weight: 500;
}
.dock-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 22px;
    background-color: #913500;
    border-radius: 0 3px 3px 0;
}

/* Dark mode item colors */
[data-theme="dark"] .dock-item,
.dark .dock-item {
    color: #a6adc8;
}
[data-theme="dark"] .dock-item:hover,
.dark .dock-item:hover {
    background-color: rgba(137, 180, 250, 0.1);
    color: #89b4fa;
}
[data-theme="dark"] .dock-item:hover svg,
.dark .dock-item:hover svg {
    stroke: #89b4fa;
}
[data-theme="dark"] .dock-item.active,
.dark .dock-item.active {
    background-color: rgba(137, 180, 250, 0.15);
    color: #89b4fa;
}
[data-theme="dark"] .dock-item.active::before,
.dark .dock-item.active::before {
    background-color: #89b4fa;
}

/* Main content offset */
.main-content {
    margin-left: 60px !important;
    transition: margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Apply margin dynamically via JS (inline style), these are fallbacks */
body.dock-stage1 .main-content {
    margin-left: 140px !important;
}
body.dock-stage2 .main-content {
    margin-left: 200px !important;
}

/* Responsive: small screens */
@media (max-width: 768px) {
    .workspace-dock {
        width: 52px;
    }
    .workspace-dock.stage1 {
        width: 120px;
    }
    .workspace-dock.stage2 {
        width: 180px;
    }
    .dock-item {
        width: 52px;
    }
    .main-content {
        margin-left: 52px !important;
    }
}
@media (max-width: 480px) {
    .workspace-dock {
        width: 0;
        overflow: hidden;
    }
    .workspace-dock.stage1,
    .workspace-dock.stage2 {
        width: 160px;
    }
    .main-content {
        margin-left: 0 !important;
    }
}

/* ========================================
   Page Sidebar (Right Column)
   
   Used on article/encyclopedia/library list pages
   ======================================== */

/* Layout: main content + sidebar */
.page-with-sidebar {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.page-main {
    flex: 1;
    min-width: 0;
}

/* Sidebar container */
.page-sidebar {
    width: 300px;
    flex-shrink: 0;
}

.sidebar-inner {
    display: flex;
    flex-direction: column;
    gap: 24px;
    position: sticky;
    top: calc(var(--header-height, 60px) + 20px);
}

/* Widget card */
.sidebar-widget {
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid var(--color-border);
    overflow: hidden;
    transition: box-shadow 0.3s ease;
}

.sidebar-widget:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

/* Widget title */
.widget-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    color: var(--color-text);
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--color-border);
    letter-spacing: -0.01em;
}

.widget-title svg {
    color: var(--color-primary);
    flex-shrink: 0;
}

/* Widget list base */
.widget-list {
    list-style: none;
    margin: 0;
    padding: 8px 14px;
}

.widget-list-item {
    padding: 10px 4px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    transition: background-color 0.2s ease;
}

.widget-list-item:last-child {
    border-bottom: none;
}

/* --- Article list style (with cover) --- */
.widget-list-article .widget-list-item {
    gap: 12px;
    align-items: flex-start;
}

.wla-cover {
    display: block;
    flex-shrink: 0;
    width: 72px;
    height: 50px;
    border-radius: 6px;
    overflow: hidden;
}

.wla-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.wla-cover:hover img {
    transform: scale(1.05);
}

.wla-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wla-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    transition: color 0.2s ease;
}

.wla-title:hover {
    color: var(--color-primary);
}

.wla-views {
    font-size: 11px;
    color: var(--color-text-muted);
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.wla-views svg {
    opacity: 0.6;
}

/* --- Text list style (encyclopedia rank) --- */
.widget-list-text {
    padding: 8px 14px;
}

.widget-list-text .widget-list-item {
    padding: 9px 4px;
    gap: 10px;
    align-items: center;
}

.wlt-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    background: var(--color-bg-secondary);
    color: var(--color-text-muted);
    transition: all 0.2s ease;
}

/* Top 3 highlight */
.widget-list-text .widget-list-item:nth-child(1) .wlt-rank,
.widget-list-text .widget-list-item:nth-child(2) .wlt-rank,
.widget-list-text .widget-list-item:nth-child(3) .wlt-rank {
    background: linear-gradient(135deg, #913500, #b45a1a);
    color: #ffffff;
}

.wlt-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
    text-decoration: none;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.2s ease;
    flex: 1;
    min-width: 0;
}

.wlt-title:hover {
    color: var(--color-primary);
}

/* --- Book list style --- */
.widget-list-book .widget-list-item {
    gap: 12px;
    align-items: flex-start;
}

.wlb-cover {
    display: block;
    flex-shrink: 0;
    width: 48px;
    height: 64px;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.wlb-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.wlb-cover:hover img {
    transform: scale(1.05);
}

.wlb-cover-placeholder {
    width: 48px;
    height: 64px;
    background: linear-gradient(135deg, #f0e8dc, #e0d4c4);
    border-radius: 4px;
    flex-shrink: 0;
}

.wlb-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wlb-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    transition: color 0.2s ease;
}

.wlb-title:hover {
    color: var(--color-primary);
}

.wlb-author {
    font-size: 12px;
    color: var(--color-text-muted);
}

/* --- Tags cloud --- */
.widget-tags {
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.widget-tag {
    display: inline-block;
    padding: 5px 12px;
    font-size: 12px;
    color: var(--color-text-secondary);
    background: var(--color-bg-secondary);
    border-radius: 20px;
    text-decoration: none;
    transition: all 0.25s ease;
    border: 1px solid transparent;
    white-space: nowrap;
}

.widget-tag:hover {
    background: var(--color-primary);
    color: #ffffff;
    border-color: var(--color-primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(145, 53, 0, 0.2);
}

/* ========================================
   Responsive - Page Sidebar
   ======================================== */

@media (max-width: 992px) {
    .page-with-sidebar {
        gap: 20px;
    }
    
    .page-sidebar {
        width: 260px;
    }
    
    .sidebar-inner {
        top: calc(var(--header-height, 60px) + 12px);
    }
}

@media (max-width: 768px) {
    .page-with-sidebar {
        flex-direction: column;
        gap: 24px;
    }
    
    .page-sidebar {
        width: 100%;
    }
    
    .sidebar-inner {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 16px;
    }
    
    .sidebar-widget {
        flex: 1 1 calc(50% - 8px);
        min-width: 240px;
    }
}

@media (max-width: 480px) {
    .sidebar-inner {
        flex-direction: column;
    }
    
    .sidebar-widget {
        flex: 1 1 100%;
        min-width: 0;
    }
}

/* ========================================
 * Footer adjustment for left workspace-dock
 * Footer is outside </main> so it needs its own margin-left
 * ======================================== */

.footer {
    margin-left: 60px;
    transition: margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    width: calc(100% - 60px);
}

body.dock-stage1 .footer {
    margin-left: 140px;
    width: calc(100% - 140px);
}

body.dock-stage2 .footer {
    margin-left: 200px;
    width: calc(100% - 200px);
}

/* ========================================
 * Footer adjustment when right page-sidebar exists
 * Reduce width further so footer stays within viewport
 * ======================================== */

.footer--with-sidebar {
    margin-right: 350px;
    width: calc(100% - 60px - 350px);
}

body.dock-stage1 .footer--with-sidebar {
    width: calc(100% - 140px - 350px);
}

body.dock-stage2 .footer--with-sidebar {
    width: calc(100% - 200px - 350px);
}

@media (max-width: 992px) {
    .footer--with-sidebar {
        margin-right: 310px;
        width: calc(100% - 60px - 310px);
    }
    body.dock-stage1 .footer--with-sidebar {
        width: calc(100% - 140px - 310px);
    }
    body.dock-stage2 .footer--with-sidebar {
        width: calc(100% - 200px - 310px);
    }
}

@media (max-width: 768px) {
    .footer--with-sidebar {
        margin-right: 0;
        width: calc(100% - 52px);
    }
}

/* Responsive: footer left margin matches dock */
@media (max-width: 768px) {
    .footer {
        margin-left: 52px;
        width: calc(100% - 52px);
    }
    .footer--with-sidebar {
        margin-right: 0;
        width: calc(100% - 52px);
    }
}

@media (max-width: 480px) {
    .footer {
        margin-left: 0;
        width: 100%;
    }
    .footer--with-sidebar {
        width: 100%;
    }
}
