/* AI assistant widget. AiAssistant mounts on every route through SiteShell;
   loads after site-shell.css so it can reposition the back-to-top control. */
body[data-page] {
    --ai-blue: #075fd8;
    --ai-blue-deep: #064aa4;
    --ai-ink: #102238;
    --ai-bar: #172a3d;
    --ai-border: #d7e4f2;
    --ai-soft: #f4f8fc;
    --ai-soft-deep: #edf5ff;
    --ai-font: "MiSans", "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
}

/* back-to-top moves up to make room for the assistant launcher below it. */
body[data-page] .back-to-top {
    bottom: max(102px, env(safe-area-inset-bottom));
}

body[data-page] .ai-launcher {
    position: fixed;
    right: max(24px, env(safe-area-inset-right));
    bottom: max(24px, env(safe-area-inset-bottom));
    z-index: 950;
    display: inline-grid;
    place-items: center;
    width: 54px;
    height: 54px;
    margin: 0;
    padding: 0;
    background: #ffffff;
    border: 1px solid rgba(7, 95, 216, 0.25);
    border-radius: 50%;
    color: var(--ai-blue);
    box-shadow: 0 8px 24px rgba(7, 74, 164, 0.24), 0 2px 6px rgba(16, 34, 56, 0.08);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(7, 95, 216, 0.12);
    transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

body[data-page] .ai-launcher:hover {
    border-color: rgba(7, 95, 216, 0.55);
    box-shadow: 0 12px 30px rgba(7, 74, 164, 0.3), 0 3px 8px rgba(16, 34, 56, 0.1);
    transform: translateY(-2px);
}

body[data-page] .ai-launcher:active {
    transform: translateY(0);
}

body[data-page] .ai-launcher svg {
    display: block;
    width: 26px;
    height: 26px;
}

body[data-page] .ai-launcher:focus-visible,
body[data-page] .ai-panel-close:focus-visible,
body[data-page] .ai-panel-send:focus-visible,
body[data-page] .ai-note-questions button:focus-visible,
body[data-page] .ai-note-link:focus-visible {
    outline: 2px solid #6fa6f4;
    outline-offset: 2px;
    box-shadow: none;
}

body[data-page].nav-open .ai-launcher {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

body[data-page] .ai-panel {
    position: fixed;
    right: max(24px, env(safe-area-inset-right));
    bottom: 102px;
    z-index: 950;
    width: min(384px, calc(100vw - 32px));
    height: min(560px, calc(100dvh - 140px));
    min-height: 420px;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid var(--ai-border);
    border-radius: 2px;
    box-shadow: 0 24px 60px rgba(16, 34, 56, 0.18);
    overflow: hidden;
    font-family: var(--ai-font);
    animation: ai-panel-in 200ms ease both;
}

@keyframes ai-panel-in {
    from {
        opacity: 0;
        transform: translateY(14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

body[data-page] .ai-panel-head {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 12px;
    padding: 13px 10px 13px 14px;
    color: var(--ai-ink);
    background: #ffffff;
    border-bottom: 1px solid var(--ai-border);
    box-shadow: inset 0 2px 0 var(--ai-blue);
}

body[data-page] .ai-panel-avatar {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    color: var(--ai-blue);
    background: var(--ai-soft-deep);
    border: 1px solid #c9ddf5;
    border-radius: 2px;
}

body[data-page] .ai-panel-avatar svg {
    display: block;
    width: 20px;
    height: 20px;
}

body[data-page] .ai-panel-title {
    display: grid;
    gap: 2px;
    min-width: 0;
    margin-right: auto;
}

body[data-page] .ai-panel-title strong {
    color: var(--ai-ink);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
}

body[data-page] .ai-panel-title small {
    color: #8aa0b5;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
}

body[data-page] .ai-panel-close {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    margin: 0;
    padding: 0;
    color: #8aa0b5;
    background: transparent;
    border: 0;
    border-radius: 2px;
    cursor: pointer;
    transition: color 180ms ease, background-color 180ms ease;
}

body[data-page] .ai-panel-close:hover {
    color: var(--ai-ink);
    background: #eef4fb;
}

body[data-page] .ai-panel-close svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

body[data-page] .ai-panel-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 14px;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    background: var(--ai-soft);
}

body[data-page] .ai-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

body[data-page] .ai-note {
    max-width: 92%;
    padding: 11px 13px;
    font-size: 14px;
    line-height: 1.75;
    text-wrap: pretty;
}

body[data-page] .ai-note p {
    margin: 0 0 8px;
}

body[data-page] .ai-note p:last-of-type {
    margin-bottom: 0;
}

body[data-page] .ai-note-user {
    align-self: flex-end;
    max-width: 85%;
    color: #ffffff;
    background: var(--ai-blue);
    border-radius: 2px;
    font-weight: 550;
}

body[data-page] .ai-note-assistant {
    align-self: flex-start;
    color: var(--ai-ink);
    background: #ffffff;
    border: 1px solid var(--ai-border);
    border-radius: 2px;
}

body[data-page] .ai-note-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

body[data-page] .ai-note-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin: 0;
    padding: 6px 10px;
    color: var(--ai-blue-deep);
    background: var(--ai-soft-deep);
    border: 1px solid #c9ddf5;
    border-radius: 2px;
    font-size: 13px;
    font-weight: 620;
    line-height: 1.4;
    text-decoration: none;
    white-space: nowrap;
    transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

body[data-page] .ai-note-link:hover,
body[data-page] .ai-note-link:focus-visible {
    color: #ffffff;
    background: var(--ai-blue);
    border-color: var(--ai-blue);
}

body[data-page] .ai-note-link svg {
    width: 13px;
    height: 13px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    transition: transform 180ms ease;
}

body[data-page] .ai-note-link:hover svg,
body[data-page] .ai-note-link:focus-visible svg {
    transform: translateX(2px);
}

body[data-page] .ai-note-questions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 10px 0 0;
}

body[data-page] .ai-note-questions button {
    margin: 0;
    padding: 8px 11px;
    color: #253448;
    background: #f6f9fd;
    border: 1px solid var(--ai-border);
    border-radius: 2px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 560;
    line-height: 1.5;
    text-align: left;
    cursor: pointer;
    transition: color 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

body[data-page] .ai-note-questions button:hover {
    color: var(--ai-blue-deep);
    background: var(--ai-soft-deep);
    border-color: #9cc3f2;
}

body[data-page] .ai-typing {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    position: relative;
    padding: 14px 15px;
    background: #ffffff;
    border: 1px solid var(--ai-border);
    border-radius: 2px;
}

body[data-page] .ai-typing i {
    width: 6px;
    height: 6px;
    background: #9db4ca;
    border-radius: 50%;
    animation: ai-typing-dot 1s ease-in-out infinite;
}

body[data-page] .ai-typing i:nth-child(2) {
    animation-delay: 160ms;
}

body[data-page] .ai-typing i:nth-child(3) {
    animation-delay: 320ms;
}

@keyframes ai-typing-dot {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.55;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

body[data-page] .ai-panel-foot {
    display: grid;
    flex: 0 0 auto;
    gap: 7px;
    margin: 0;
    padding: 12px;
    background: #ffffff;
    border-top: 1px solid var(--ai-border);
}

body[data-page] .ai-panel-field {
    display: flex;
    gap: 8px;
}

body[data-page] .ai-panel-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 42px;
    margin: 0;
    padding: 0 12px;
    color: var(--ai-ink);
    background: #f6f9fd;
    border: 1px solid var(--ai-border);
    border-radius: 2px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    transition: border-color 180ms ease, box-shadow 180ms ease;
}

body[data-page] .ai-panel-input::placeholder {
    color: #8aa0b5;
}

body[data-page] .ai-panel-input:focus {
    background: #ffffff;
    border-color: var(--ai-blue);
    outline: none;
    box-shadow: 0 0 0 1px var(--ai-blue);
}

body[data-page] .ai-panel-send {
    flex: 0 0 auto;
    height: 42px;
    margin: 0;
    padding: 0 17px;
    color: #ffffff;
    background: var(--ai-blue);
    border: 0;
    border-radius: 2px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 650;
    line-height: 1;
    cursor: pointer;
    transition: background-color 180ms ease;
}

body[data-page] .ai-panel-send:hover:not(:disabled) {
    background: var(--ai-blue-deep);
}

body[data-page] .ai-panel-send:disabled {
    opacity: 0.45;
    cursor: default;
}

body[data-page] .ai-panel-hint {
    margin: 0;
    color: #8aa0b5;
    font-size: 11.5px;
    line-height: 1.5;
}

@media (max-width: 720px) {
    body[data-page] .ai-launcher {
        right: max(16px, env(safe-area-inset-right));
        bottom: max(16px, env(safe-area-inset-bottom));
        width: 48px;
        height: 48px;
    }

    body[data-page] .ai-launcher svg {
        width: 24px;
        height: 24px;
    }

    body[data-page] .back-to-top {
        bottom: max(88px, env(safe-area-inset-bottom));
    }

    body[data-page] .ai-panel {
        right: max(16px, env(safe-area-inset-right));
        bottom: 88px;
        left: max(16px, env(safe-area-inset-left));
        width: auto;
        max-width: 420px;
        height: min(560px, calc(100dvh - 124px));
        min-height: 400px;
        margin-left: auto;
    }
}

@media (max-width: 640px) {
    /* 16px 输入字号，避免 iOS 聚焦时页面缩放。 */
    body[data-page] .ai-panel-input {
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    body[data-page] .ai-launcher,
    body[data-page] .ai-panel,
    body[data-page] .ai-panel-close,
    body[data-page] .ai-note-link,
    body[data-page] .ai-note-link svg,
    body[data-page] .ai-note-questions button,
    body[data-page] .ai-panel-input,
    body[data-page] .ai-panel-send {
        transition: none;
        animation: none;
    }

    body[data-page] .ai-typing i {
        animation: none;
    }
}
