/* =========================================================
   Tutorial Studio · Page Panel
   左侧「页面」面板：卡片、操作条、右键菜单、拖拽排序

   说明：
   1. 本文件只作用于页面面板，不影响其他侧边栏。
   2. 加载顺序在 sidebar.css / sidebar_activity.css 之后，
      用于覆盖旧版页面列表样式。
   3. 所有交互态都提供 :focus-visible，保证键盘可用。
   ========================================================= */

:root {
    --pp-ink: #0f172a;
    --pp-ink-soft: #475569;
    --pp-muted: #94a3b8;
    --pp-line: #e6eaf1;
    --pp-line-strong: #d5dbe6;
    --pp-surface: #ffffff;
    --pp-surface-soft: #f8fafc;
    --pp-accent: #2563eb;
    --pp-accent-soft: #eff4ff;
    --pp-danger: #dc2626;
    --pp-radius-lg: 12px;
    --pp-radius-md: 8px;
    --pp-radius-sm: 6px;
    --pp-shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --pp-shadow-md: 0 6px 18px rgba(15, 23, 42, .08);
    --pp-shadow-lg: 0 16px 40px rgba(15, 23, 42, .16);
}


/* =========================================================
   1. 面板头部
   ========================================================= */

.sidebar-panel[data-panel="pages"] .panel-head {
    min-height: 46px;
    padding: 0 10px 0 14px;
    gap: 8px;
    background: linear-gradient(180deg, #ffffff, #fcfdff);
}

.sidebar-panel[data-panel="pages"] .panel-title {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;

    font-size: 12px;
    font-weight: 700;
    letter-spacing: .02em;
    color: var(--pp-ink);
}

.sidebar-panel[data-panel="pages"] .panel-title::before {
    content: "";
    display: block;
    width: 3px;
    height: 12px;
    border-radius: 2px;
    background: var(--pp-accent);
}

.sidebar-panel[data-panel="pages"] .panel-head-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-count {
    min-width: 22px;
    padding: 2px 7px;

    border-radius: 999px;
    background: var(--pp-accent-soft);
    color: var(--pp-accent);

    font-size: 10.5px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: center;
    letter-spacing: 0;
}

.panel-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 26px;
    height: 26px;
    padding: 0;

    border: 1px solid transparent;
    border-radius: var(--pp-radius-sm);
    background: transparent;
    color: var(--pp-ink-soft);

    cursor: pointer;
    transition: background-color .16s ease, color .16s ease, border-color .16s ease;
}

.panel-icon-btn:hover {
    background: var(--pp-surface-soft);
    border-color: var(--pp-line);
    color: var(--pp-ink);
}

.panel-icon-btn:active {
    background: #eef2f7;
}

.panel-icon-btn:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: 1px;
}


/* =========================================================
   2. 列表容器
   ========================================================= */

.sidebar-panel[data-panel="pages"] .page-list {
    display: flex;
    flex-direction: column;
    gap: 12px;

    padding: 12px;
    margin: 0;

    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-panel[data-panel="pages"] .page-list::-webkit-scrollbar {
    width: 6px;
}

.sidebar-panel[data-panel="pages"] .page-list::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #d7dee9;
}

.sidebar-panel[data-panel="pages"] .page-list::-webkit-scrollbar-thumb:hover {
    background: #c2ccdb;
}

.sidebar-panel[data-panel="pages"] .page-list:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: -2px;
    border-radius: var(--pp-radius-md);
}


/* =========================================================
   3. 页面卡片
   ========================================================= */

.sidebar-panel[data-panel="pages"] .page-item {
    position: relative;

    padding: 8px;

    border: 1px solid var(--pp-line);
    border-radius: var(--pp-radius-lg);
    background: var(--pp-surface);
    box-shadow: var(--pp-shadow-sm);

    cursor: pointer;

    transition:
        border-color .18s ease,
        box-shadow .18s ease,
        transform .18s ease,
        background-color .18s ease;
}

.sidebar-panel[data-panel="pages"] .page-item:hover {
    border-color: var(--pp-line-strong);
    box-shadow: var(--pp-shadow-md);
    transform: translateY(-1px);
}

.sidebar-panel[data-panel="pages"] .page-item:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: 2px;
}

.sidebar-panel[data-panel="pages"] .page-item.active {
    border-color: rgba(37, 99, 235, .55);
    background: var(--pp-accent-soft);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12), var(--pp-shadow-md);
    transform: none;
}

.sidebar-panel[data-panel="pages"] .page-item.active::before {
    content: "";
    position: absolute;
    left: -1px;
    top: 12px;
    bottom: 12px;

    width: 3px;

    border-radius: 0 3px 3px 0;
    background: var(--pp-accent);
}

.sidebar-panel[data-panel="pages"] .page-item.is-dragging {
    opacity: .45;
    border-style: dashed;
    transform: none;
    box-shadow: none;
}

.sidebar-panel[data-panel="pages"] .page-item.is-drop-before::after,
.sidebar-panel[data-panel="pages"] .page-item.is-drop-after::after {
    content: "";
    position: absolute;
    left: 4px;
    right: 4px;

    height: 2px;

    border-radius: 2px;
    background: var(--pp-accent);
}

.sidebar-panel[data-panel="pages"] .page-item.is-drop-before::after {
    top: -6px;
}

.sidebar-panel[data-panel="pages"] .page-item.is-drop-after::after {
    bottom: -6px;
}


/* =========================================================
   4. 缩略图
   ========================================================= */

.sidebar-panel[data-panel="pages"] .thumb {
    position: relative;
    overflow: hidden;

    width: 100%;
    height: clamp(116px, 15vh, 140px);

    margin: 0;

    border: 1px solid #edf1f7;
    border-radius: var(--pp-radius-md);
    background:
        linear-gradient(180deg, #fbfcfe, #f4f7fb);

    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .6);
}

.sidebar-panel[data-panel="pages"] .page-item.active .thumb {
    border-color: rgba(37, 99, 235, .35);
    background: #ffffff;
}

.sidebar-panel[data-panel="pages"] .thumb iframe {
    pointer-events: none;
    border: 0;
    background: #ffffff;
}


/* ---------------------------------------------------------
   缩略图占位骨架
   --------------------------------------------------------- */

.thumb-skeleton {
    position: absolute;
    inset: 0;

    background:
        linear-gradient(100deg,
            #f2f5fa 20%,
            #f8fafc 38%,
            #f2f5fa 56%);

    background-size: 220% 100%;

    animation: thumb-shimmer 1.5s ease-in-out infinite;
}

.thumb.is-loading::after {
    content: "";

    position: absolute;
    inset: 0;

    background:
        linear-gradient(100deg,
            rgba(255, 255, 255, 0) 20%,
            rgba(255, 255, 255, .55) 50%,
            rgba(255, 255, 255, 0) 80%);

    background-size: 220% 100%;

    animation: thumb-shimmer 1.2s linear infinite;

    pointer-events: none;
}

@keyframes thumb-shimmer {

    from {
        background-position: 140% 0;
    }

    to {
        background-position: -40% 0;
    }
}

@media (prefers-reduced-motion: reduce) {

    .thumb-skeleton,
    .thumb.is-loading::after {
        animation: none;
    }
}


/* =========================================================
   5. 页面标题：缩略图底部透明悬浮条
   ========================================================= */

.sidebar-panel[data-panel="pages"] .page-name {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    z-index: 3;

    box-sizing: border-box;

    margin: 0;
    padding: 18px 10px 8px;

    border-radius: 0 0 var(--pp-radius-md) var(--pp-radius-md);

    background:
        linear-gradient(180deg,
            rgba(15, 23, 42, 0) 0%,
            rgba(15, 23, 42, .18) 35%,
            rgba(15, 23, 42, .68) 100%);

    color: #ffffff;

    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    text-align: left;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .45);

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;

    transition:
        opacity .16s ease,
        transform .16s ease;
}

.sidebar-panel[data-panel="pages"] .page-item:hover .page-name,
.sidebar-panel[data-panel="pages"] .page-item:focus-visible .page-name,
.sidebar-panel[data-panel="pages"] .page-name[data-editing="1"] {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.page-name-input {
    width: 100%;
    box-sizing: border-box;
    padding: 3px 6px;

    border: 1px solid var(--pp-accent);
    border-radius: var(--pp-radius-sm);
    background: #ffffff;
    color: var(--pp-ink);

    font: inherit;
    font-size: 11.5px;
    font-weight: 600;

    box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
    outline: none;
}


/* =========================================================
   6. 悬停操作条
   ========================================================= */

.sidebar-panel[data-panel="pages"] .page-item-actions {
    position: absolute;
    top: 14px;
    right: 14px;

    display: flex;
    gap: 4px;

    opacity: 0;
    transform: translateY(-2px);
    pointer-events: none;

    transition: opacity .16s ease, transform .16s ease;
}

.sidebar-panel[data-panel="pages"] .page-item:hover .page-item-actions,
.sidebar-panel[data-panel="pages"] .page-item:focus-within .page-item-actions,
.sidebar-panel[data-panel="pages"] .page-item.active .page-item-actions {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.page-item-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 24px;
    height: 24px;
    padding: 0;

    border: 1px solid rgba(255, 255, 255, .9);
    border-radius: var(--pp-radius-sm);
    background: rgba(255, 255, 255, .92);
    color: var(--pp-ink-soft);

    cursor: pointer;
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 6px rgba(15, 23, 42, .12);

    transition: background-color .14s ease, color .14s ease, border-color .14s ease;
}

.page-item-action:hover {
    background: #ffffff;
    color: var(--pp-ink);
}

.page-item-action[data-page-action="delete"]:hover,
.page-item-action.is-armed {
    border-color: rgba(220, 38, 38, .35);
    background: #fef2f2;
    color: var(--pp-danger);
}

.page-item-action:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: 1px;
}


/* =========================================================
   7. 拖拽手柄
   ========================================================= */

.sidebar-panel[data-panel="pages"] .page-drag-handle {
    position: absolute;
    top: 14px;
    left: 14px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 20px;
    height: 20px;

    border-radius: var(--pp-radius-sm);
    background: rgba(255, 255, 255, .9);
    color: var(--pp-muted);

    opacity: 0;
    cursor: grab;
    box-shadow: 0 1px 4px rgba(15, 23, 42, .1);

    transition: opacity .16s ease, color .16s ease;
}

.sidebar-panel[data-panel="pages"] .page-item:hover .page-drag-handle,
.sidebar-panel[data-panel="pages"] .page-item:focus-within .page-drag-handle {
    opacity: 1;
}

.sidebar-panel[data-panel="pages"] .page-drag-handle:hover {
    color: var(--pp-ink);
}

.sidebar-panel[data-panel="pages"] .page-drag-handle:active {
    cursor: grabbing;
}


/* =========================================================
   8. 底部「添加页面」
   ========================================================= */

.sidebar-panel[data-panel="pages"] .add-page {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;

    margin: 0 12px 12px;
    padding: 10px 12px;

    border: 1px dashed var(--pp-line-strong);
    border-radius: var(--pp-radius-md);
    background: var(--pp-surface-soft);

    color: var(--pp-ink-soft);

    font-size: 12px;
    font-weight: 600;

    cursor: pointer;
    transition: border-color .16s ease, background-color .16s ease, color .16s ease;
}

.sidebar-panel[data-panel="pages"] .add-page:hover {
    border-color: var(--pp-accent);
    background: var(--pp-accent-soft);
    color: var(--pp-accent);
}

.sidebar-panel[data-panel="pages"] .add-page:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: 2px;
}


/* =========================================================
   9. 右键菜单
   ========================================================= */

.page-context-menu {
    position: fixed;
    z-index: 4000;

    min-width: 176px;
    padding: 6px;

    border: 1px solid var(--pp-line);
    border-radius: 10px;
    background: #ffffff;
    box-shadow: var(--pp-shadow-lg);

    animation: page-menu-in .12s ease-out;
}

@keyframes page-menu-in {

    from {
        opacity: 0;
        transform: translateY(-4px) scale(.98);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.page-context-item {
    display: flex;
    align-items: center;
    gap: 9px;

    width: 100%;
    padding: 7px 9px;

    border: 0;
    border-radius: var(--pp-radius-sm);
    background: transparent;

    color: var(--pp-ink);
    font-size: 12px;
    font-weight: 500;
    text-align: left;

    cursor: pointer;
    transition: background-color .12s ease, color .12s ease;
}

.page-context-item:hover:not(:disabled) {
    background: var(--pp-surface-soft);
}

.page-context-item:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: -2px;
}

.page-context-item:disabled {
    color: #b8c2d1;
    cursor: not-allowed;
}

.page-context-item.is-danger {
    color: var(--pp-danger);
}

.page-context-item.is-danger:hover:not(:disabled) {
    background: #fef2f2;
}

.page-context-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 16px;

    color: currentColor;
    opacity: .8;
}

.page-context-divider {
    height: 1px;
    margin: 5px 4px;

    background: var(--pp-line);
}


/* =========================================================
   10. 窄屏适配
   ========================================================= */

@media (max-width: 720px) {

    .sidebar-panel[data-panel="pages"] .page-list {
        gap: 8px;
        padding: 10px;
    }

    .sidebar-panel[data-panel="pages"] .thumb {
        height: 96px;
    }

    .sidebar-panel[data-panel="pages"] .page-item {
        padding: 7px 7px 8px;
    }

    /* 触摸设备没有 hover，操作条常显。 */

    .sidebar-panel[data-panel="pages"] .page-item-actions,
    .sidebar-panel[data-panel="pages"] .page-drag-handle {
        opacity: 1;
        transform: none;
        pointer-events: auto;
    }
}
