/* ============================================================
   词小龙 V3 — 侧边栏布局系统
   依赖：app.css 中的 :root 变量和组件样式
   保留所有现有组件 class，只新增布局框架
   ============================================================ */

/* === 布局容器 === */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* === 侧边栏 === */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--line);
    transition: width 0.2s ease, transform 0.25s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar[data-collapsed="true"] {
    width: 64px;
}

/* 品牌区 */
.sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 56px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--ink);
    min-width: 0;
}

.sidebar__brand img {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    flex-shrink: 0;
}

.sidebar__brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar[data-collapsed="true"] .sidebar__brand-text {
    display: none;
}

.sidebar__brand-text strong {
    font-size: 16px;
    font-weight: 700;
    color: var(--brand-dark);
}

.sidebar__brand-text small {
    font-size: 9px;
    color: var(--muted);
    letter-spacing: 0.5px;
}

.sidebar__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

.sidebar__toggle:hover {
    background: var(--brand-soft);
    color: var(--brand);
}

/* === 导航区 === */
.sidebar__nav {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
}

/* 分组 */
.sidebar-group {
    margin-bottom: 8px;
}

.sidebar-group__header {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: #435b54;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-align: left;
    gap: 8px;
}

.sidebar-group__header:hover {
    background: var(--surface-soft);
    color: var(--ink);
}

.sidebar-group__header svg {
    flex-shrink: 0;
    opacity: 0.72;
}

.sidebar-group__header span {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-group__chevron {
    margin-left: auto;
    transition: transform 0.2s;
    opacity: 0.5;
}

.sidebar-group.is-expanded .sidebar-group__chevron {
    transform: rotate(180deg);
}

.sidebar[data-collapsed="true"] .sidebar-group__header span,
.sidebar[data-collapsed="true"] .sidebar-group__chevron {
    display: none;
}

.sidebar[data-collapsed="true"] .sidebar-group__header {
    justify-content: center;
    padding: 10px;
}

/* 菜单项 */
.sidebar-group__items {
    padding-left: 30px;
    margin-bottom: 4px;
}

.sidebar[data-collapsed="true"] .sidebar-group__items {
    display: none !important;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
    text-decoration: none;
    transition: background 0.12s, color 0.12s;
    position: relative;
}

.sidebar-item:hover {
    background: var(--surface-soft);
}

.sidebar-item.is-active {
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-weight: 600;
}

.sidebar-item.is-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--brand);
    border-radius: 0 2px 2px 0;
}

.sidebar-item__badge {
    min-width: 20px;
    height: 20px;
    margin-left: auto;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: #e8edf2;
    color: #334155;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

.sidebar-item__badge--warning {
    background: #fff1c2;
    color: #7a5200;
}

.sidebar-item__badge--danger {
    background: #fee2e2;
    color: #a32121;
}

.sidebar-group--premium {
    margin-top: 10px;
    padding: 6px 0;
    border-top: 1px solid rgba(184, 131, 40, .22);
    border-bottom: 1px solid rgba(184, 131, 40, .22);
}

.sidebar-group--premium .sidebar-group__header {
    color: #765316;
}

.sidebar-group--premium .sidebar-group__header svg {
    color: var(--gold);
    opacity: 1;
}

.sidebar-group--premium .sidebar-item.is-active {
    color: #68450d;
    background: #fbf0d9;
}

.sidebar-group--premium .sidebar-item.is-active::before {
    background: var(--gold);
}

/* === 用户区 === */
.sidebar__user {
    padding: 12px;
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

.sidebar__user-info {
    margin-bottom: 8px;
}

.sidebar__user-info strong {
    display: block;
    font-size: 13px;
    line-height: 1.3;
}

.sidebar__user-info small {
    display: block;
    font-size: 11px;
    color: var(--muted);
    line-height: 1.4;
}

.sidebar__user-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.sidebar__profile-link,
.sidebar__logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.sidebar__profile-link:hover,
.sidebar__logout:hover {
    background: var(--surface-soft);
    color: var(--danger);
}

.sidebar[data-collapsed="true"] .sidebar__user-info {
    display: none;
}

.sidebar[data-collapsed="true"] .sidebar__user-actions {
    flex-direction: column;
}

/* === 顶部栏 === */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 16px;
    height: 56px;
    padding: 0 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.topbar__hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    flex-shrink: 0;
}

.topbar__hamburger:hover {
    background: var(--surface-soft);
}

/* 面包屑 */
.topbar__breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    flex-shrink: 0;
}

.topbar__breadcrumb a {
    color: var(--muted);
    text-decoration: none;
}

.topbar__breadcrumb a:hover {
    color: var(--brand);
}

.topbar__breadcrumb-sep {
    color: var(--line);
}

.topbar__breadcrumb-current {
    color: var(--ink);
    font-weight: 500;
}

.topbar__title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === 内容区 === */
.app-content {
    margin-left: 240px;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.2s ease;
}

.sidebar[data-collapsed="true"] ~ .app-content {
    margin-left: 64px;
}

/* 用于兼容，page-main 现在是内容区内的主区域 */
.app-content .page-main {
    flex: 1;
}

/* === 移动端响应式 === */
@media (max-width: 767px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: var(--shadow);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar[data-collapsed="true"] {
        width: 280px;
    }

    .app-content {
        margin-left: 0 !important;
    }

    .topbar__hamburger {
        display: flex;
    }

    .topbar {
        padding: 0 12px;
    }

    .topbar__breadcrumb {
        display: none;
    }

    /* 移动端侧边栏遮罩 */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 99;
        background: rgba(0, 0, 0, 0.3);
        opacity: 0;
        transition: opacity 0.25s;
        pointer-events: none;
    }

    .sidebar-overlay.is-visible {
        opacity: 1;
        pointer-events: auto;
    }
}

/* 平板端：收起侧边栏 */
@media (min-width: 768px) and (max-width: 1080px) {
    .sidebar:not(.is-open) {
        width: 64px;
    }

    .sidebar:not(.is-open) .sidebar__brand-text,
    .sidebar:not(.is-open) .sidebar-group__header span,
    .sidebar:not(.is-open) .sidebar-group__chevron,
    .sidebar:not(.is-open) .sidebar-group__items,
    .sidebar:not(.is-open) .sidebar__user-info {
        display: none;
    }

    .app-content {
        margin-left: 64px;
    }
}

/* === 折叠状态下的 Hover 展开（平板端） === */
@media (min-width: 768px) and (max-width: 1080px) {
    .sidebar:not(.is-open):hover {
        width: 240px;
        box-shadow: var(--shadow);
    }

    .sidebar:not(.is-open):hover .sidebar__brand-text,
    .sidebar:not(.is-open):hover .sidebar-group__header span,
    .sidebar:not(.is-open):hover .sidebar-group__chevron,
    .sidebar:not(.is-open):hover .sidebar-group__items,
    .sidebar:not(.is-open):hover .sidebar__user-info {
        display: flex;
    }
}
