/*
 * 顶部置顶公告栏（top alert）
 *
 * 独立于 app.css / 公告弹窗：固定在视口最顶部，导航栏 (.jx-nav) 通过
 * --jx-top-alert-h 让出与公告栏等高的偏移，避免被遮住。
 * 高度由 top-alert.js 实时测量并写回 :root；未启用 JS 时退回 2.5rem 的近似值。
 */

.jx-top-alert {
    --jx-ta-bg-a: #1e3a8a;
    --jx-ta-bg-b: #1d4ed8;
    --jx-ta-border: rgba(15, 23, 42, 0.35);
    --jx-ta-badge: rgba(255, 255, 255, 0.16);

    position: sticky;
    top: 0;
    z-index: 101;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-height: 2.5rem;
    padding: 0.375rem 0.75rem;
    color: #f8fafc;
    background: linear-gradient(90deg, var(--jx-ta-bg-a), var(--jx-ta-bg-b));
    border-bottom: 1px solid var(--jx-ta-border);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18);
    font-size: 0.8125rem;
    line-height: 1.4;
    isolation: isolate;
}

/* 配色等级：固定深色底 + 浅色字，明暗主题下都保证对比度 */
.jx-top-alert--info {
    --jx-ta-bg-a: #1e3a8a;
    --jx-ta-bg-b: #1d4ed8;
}

.jx-top-alert--success {
    --jx-ta-bg-a: #14532d;
    --jx-ta-bg-b: #15803d;
}

.jx-top-alert--warning {
    --jx-ta-bg-a: #7c2d12;
    --jx-ta-bg-b: #b45309;
}

.jx-top-alert--danger {
    --jx-ta-bg-a: #7f1d1d;
    --jx-ta-bg-b: #b91c1c;
}

.jx-top-alert__badge {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    background: var(--jx-ta-badge);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.jx-top-alert__badge-icon {
    width: 0.875rem;
    height: 0.875rem;
}

.jx-top-alert__viewport {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.jx-top-alert__viewport::-webkit-scrollbar {
    display: none;
}

.jx-top-alert__track {
    display: flex;
    align-items: center;
    width: max-content;
    min-width: 100%;
    will-change: transform;
}

.jx-top-alert__group {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
}

.jx-top-alert__item {
    color: inherit;
    font-size: 0.8125rem;
    white-space: nowrap;
    text-decoration: none;
}

a.jx-top-alert__item {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    text-decoration-color: rgba(248, 250, 252, 0.45);
}

a.jx-top-alert__item:hover {
    text-decoration-color: #f8fafc;
}

a.jx-top-alert__item:focus-visible {
    outline: 2px solid #f8fafc;
    outline-offset: 2px;
    border-radius: 3px;
}

.jx-top-alert__sep {
    padding: 0 0.875rem;
    font-size: 0.625rem;
    opacity: 0.5;
}

.jx-top-alert__close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: inherit;
    opacity: 0.8;
    cursor: pointer;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}

.jx-top-alert__close:hover {
    background: rgba(255, 255, 255, 0.16);
    opacity: 1;
}

.jx-top-alert__close:focus-visible {
    outline: 2px solid #f8fafc;
    outline-offset: 2px;
}

.jx-top-alert__close svg {
    width: 0.875rem;
    height: 0.875rem;
}

/* 导航栏跟随公告栏高度下移：.jx-nav 自身是 top:0 的 sticky，这里用更高特异性覆盖 */
.jx-top-alert ~ .jx-nav {
    top: var(--jx-top-alert-h, 2.5rem);
}

/* 滚动播放：轨道内由 JS 追加一份等宽副本，位移一份宽度后无缝衔接 */
.jx-top-alert.is-scrolling .jx-top-alert__viewport {
    overflow: hidden;
}

.jx-top-alert.is-scrolling .jx-top-alert__track {
    animation: jx-top-alert-marquee var(--jx-top-alert-duration, 30s) linear infinite;
}

.jx-top-alert.is-scrolling:hover .jx-top-alert__track,
.jx-top-alert.is-scrolling:focus-within .jx-top-alert__track,
.jx-top-alert.is-paused .jx-top-alert__track {
    animation-play-state: paused;
}

@keyframes jx-top-alert-marquee {
    from {
        transform: translate3d(0, 0, 0);
    }
    to {
        transform: translate3d(calc(-1 * var(--jx-top-alert-shift, 0px)), 0, 0);
    }
}

/* 减弱动态效果：不滚动，改为可手动横向滚动 */
@media (prefers-reduced-motion: reduce) {
    .jx-top-alert.is-scrolling .jx-top-alert__track {
        animation: none;
    }
}

@media (max-width: 480px) {
    .jx-top-alert {
        gap: 0.5rem;
        padding: 0.375rem 0.5rem;
    }

    .jx-top-alert__badge {
        padding: 0.125rem 0.375rem;
    }

    .jx-top-alert__label {
        display: none;
    }
}

@media print {
    .jx-top-alert {
        display: none !important;
    }
}
