/* ============================================================
   固居小帮手 · AI 助手 —— 品牌风格（水蓝绿 + 金）
   与工地系统主色系统一：#1a6b7c / #2a93a8 / #5bc0d4 + #c9a227
   ============================================================ */

#guju-helper-root {
    /* 品牌色（与 base.css 的"水"主题一致） */
    --water-deep: #0a2e38;
    --water-dark: #0f4c5c;
    --water-primary: #1a6b7c;
    --water-mid: #2a93a8;
    --water-light: #5bc0d4;
    --water-glow: #8ed7e6;
    --water-bg-soft: #e8f4f8;

    --gold-dark: #8b6914;
    --gold-primary: #c9a227;
    --gold-light: #f0d878;
    --gold-soft: #fbf4dc;

    --ink-black: #1a2332;
    --ink-dark: #2d3e50;
    --ink-mid: #4a6274;
    --ink-light: #6b8299;

    --paper: #ffffff;
    --paper-cool: #f0f4f7;
    --surface: #ffffff;

    --line: #e4ebef;
    --line-strong: #d3dde3;

    --danger: #d64541;
    --danger-soft: #fdecea;
    --success: #2f9e6b;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --shadow-pop: 0 12px 40px rgba(15, 76, 92, 0.16);
    --shadow-soft: 0 4px 16px rgba(15, 76, 92, 0.12);

    --font: -apple-system, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;

    position: fixed;
    z-index: 999999;
    pointer-events: none;
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
}

:where(#guju-helper-root) * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: inherit;
}

/* ==================== 悬浮按钮 ==================== */
.helper-fab {
    opacity: 0;
    visibility: hidden;
    position: fixed;
    right: 20px;
    bottom: 84px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0f4c5c 0%, #1a6b7c 45%, #2a93a8 100%);
    box-shadow: 0 6px 20px rgba(26, 107, 124, 0.34);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

#guju-helper-root.helper-ready .helper-fab {
    opacity: 1;
    visibility: visible;
}

.helper-fab:hover {
    transform: scale(1.06);
    box-shadow: 0 8px 26px rgba(26, 107, 124, 0.42);
}

.helper-fab:active {
    transform: scale(0.96);
}

.helper-fab.dragging {
    opacity: 0.92;
    cursor: grabbing;
    transition: none;
}

.helper-fab-icon {
    width: 26px;
    height: 26px;
    color: #fff;
    pointer-events: none;
}

.helper-fab-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

/* 呼吸光圈 */
.helper-fab::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--water-mid);
    opacity: 0.18;
    animation: helper-pulse 3s ease-in-out infinite;
    z-index: -1;
}

@keyframes helper-pulse {
    0%, 100% { transform: scale(1); opacity: 0.18; }
    50% { transform: scale(1.28); opacity: 0; }
}

/* ==================== 对话窗口 ==================== */
.helper-window {
    position: fixed;
    right: 20px;
    bottom: 152px;
    width: 408px;
    height: 640px;
    max-height: calc(100vh - 110px);
    background: var(--paper);
    border-radius: 18px;
    box-shadow: var(--shadow-pop);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(16px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.22s cubic-bezier(.2,.8,.2,1), transform 0.22s cubic-bezier(.2,.8,.2,1);
    pointer-events: none;
    border: 1px solid var(--line);
}

.helper-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ==================== 顶部 Header ==================== */
.helper-header {
    height: 60px;
    background: linear-gradient(135deg, #0f4c5c 0%, #1a6b7c 60%, #2a93a8 100%);
    color: #fff;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 11px;
    user-select: none;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* 顶部金色点缀 */
.helper-header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--gold-primary), var(--gold-light), var(--gold-primary));
    opacity: 0.85;
}

.helper-header-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.helper-header-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.helper-header-status {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.94);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.helper-header-status-dot {
    width: 7px;
    height: 7px;
    background: #7ee2a8;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(126, 226, 168, 0.22);
}

.helper-header-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.helper-header-btn {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    padding: 0;
}

.helper-header-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

.helper-header-btn svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

/* ==================== 消息区域 ==================== */
.helper-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 16px;
    background: linear-gradient(180deg, #f7fbfc 0%, #f2f7f9 100%);
    display: flex;
    flex-direction: column;
    gap: 16px;
    -webkit-overflow-scrolling: touch;
}

.helper-messages::-webkit-scrollbar { width: 6px; }
.helper-messages::-webkit-scrollbar-track { background: transparent; }
.helper-messages::-webkit-scrollbar-thumb { background: rgba(15, 76, 92, 0.16); border-radius: 3px; }
.helper-messages::-webkit-scrollbar-thumb:hover { background: rgba(15, 76, 92, 0.28); }

/* ==================== 消息气泡 ==================== */
.helper-msg {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    max-width: 100%;
    animation: helper-msg-in 0.22s ease-out;
}

@keyframes helper-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* AI 消息：左头像 + 白色卡片气泡（占满整行，避免文字溢出/挤压） */
.helper-msg.ai {
    width: 100%;
}

.helper-ai-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0f4c5c, #2a93a8);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(26, 107, 124, 0.28);
}

.helper-ai-content {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 40px);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 4px 14px 14px 14px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.72;
    color: var(--ink-dark);
    word-break: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 1px 3px rgba(15, 76, 92, 0.05);
}

/* 用户消息：右侧品牌蓝渐变气泡 */
.helper-msg.user {
    align-self: flex-end;
    justify-content: flex-end;
}

.helper-user-bubble {
    max-width: 82%;
    padding: 11px 14px;
    border-radius: 14px 4px 14px 14px;
    font-size: 14px;
    line-height: 1.6;
    background: linear-gradient(135deg, #1a6b7c, #2a93a8);
    color: #fff;
    word-break: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 2px 8px rgba(26, 107, 124, 0.22);
}

/* ==================== Markdown / 富文本 ==================== */
.helper-ai-content strong {
    font-weight: 700;
    color: var(--water-dark);
}

.helper-ai-content .ai-quote {
    border-left: 3px solid var(--water-mid);
    padding: 7px 12px;
    margin: 8px 0;
    background: var(--water-bg-soft);
    border-radius: 0 8px 8px 0;
    color: var(--ink-dark);
}

.helper-ai-content .ai-warning {
    background: var(--danger-soft);
    border-left: 3px solid var(--danger);
    color: #b23b37;
    padding: 8px 12px;
    margin: 8px 0;
    border-radius: 0 8px 8px 0;
    font-weight: 600;
}

.helper-ai-content .ai-highlight {
    background: var(--gold-soft);
    border-left: 3px solid var(--gold-primary);
    color: var(--ink-dark);
    padding: 8px 12px;
    margin: 8px 0;
    border-radius: 0 8px 8px 0;
    font-weight: 600;
}

/* 列表 */
.helper-ai-content .ai-ol, .helper-ai-content .ai-ul {
    margin: 6px 0;
    padding-left: 6px;
}
.helper-ai-content .ai-li {
    display: flex;
    gap: 6px;
    margin: 3px 0;
}
.helper-ai-content .ai-li .ai-li-num {
    color: var(--water-primary);
    font-weight: 600;
    min-width: 20px;
}
.helper-ai-content .ai-li .ai-li-dot {
    color: var(--water-mid);
}

/* ==================== 来源标签 ==================== */
.helper-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 9px;
}

.helper-source-tag {
    font-size: 11px;
    line-height: 1;
    padding: 3px 8px;
    border-radius: 7px;
    white-space: nowrap;
    font-weight: 500;
}

.helper-source-kb { color: #1a6b7c; background: rgba(42, 147, 168, 0.12); }
.helper-source-auth { color: #2f7d32; background: rgba(47, 125, 50, 0.10); }
.helper-source-web { color: #b26a00; background: rgba(201, 162, 39, 0.14); }
.helper-source-faq { color: #8b6914; background: rgba(201, 162, 39, 0.18); border: 1px solid rgba(201, 162, 39, 0.3); }

/* ==================== 反馈按钮 ==================== */
.helper-feedback {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    align-items: center;
}

.helper-feedback-btn {
    width: 28px;
    height: 26px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink-light);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.15s ease;
}

.helper-feedback-btn:hover {
    background: var(--water-bg-soft);
    color: var(--water-primary);
}

.helper-feedback-btn.active-up {
    background: rgba(47, 158, 107, 0.12);
    color: var(--success);
    border-color: rgba(47, 158, 107, 0.3);
}

.helper-feedback-btn.active-down {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: rgba(214, 69, 65, 0.3);
}

.helper-feedback-btn svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
}

.helper-feedback-tip {
    font-size: 11px;
    color: var(--ink-light);
}

/* ==================== 加载动画 ==================== */
.helper-loading {
    display: flex;
    gap: 5px;
    padding: 2px 0;
    align-items: center;
}

.helper-loading span {
    width: 7px;
    height: 7px;
    background: var(--water-mid);
    border-radius: 50%;
    opacity: 0.55;
    animation: helper-loading-bounce 1.3s infinite ease-in-out both;
}

.helper-loading span:nth-child(1) { animation-delay: -0.32s; }
.helper-loading span:nth-child(2) { animation-delay: -0.16s; }
.helper-loading span:nth-child(3) { animation-delay: 0s; }

@keyframes helper-loading-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.35; }
    40% { transform: scale(1); opacity: 1; }
}

.helper-loading-tip {
    font-size: 12px;
    color: var(--ink-light);
    margin-bottom: 7px;
}

/* 流式输出打字光标 */
.helper-cursor {
    display: inline-block;
    width: 2px;
    height: 14px;
    margin-left: 2px;
    vertical-align: -2px;
    background: var(--water-mid);
    animation: helper-cursor-blink 0.8s steps(1) infinite;
}

@keyframes helper-cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ==================== 空状态 · 快捷提问卡片 ==================== */
.helper-empty {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.helper-greeting {
    font-size: 13px;
    color: var(--ink-mid);
    line-height: 1.7;
}

.helper-greeting .helper-greeting-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--water-dark);
    margin-bottom: 4px;
}

.helper-quick-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.helper-quick-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--water-dark);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    flex: 0 0 auto;
    max-width: 100%;
}

.helper-quick-pill:hover {
    border-color: var(--water-mid);
    color: var(--water-primary);
    background: var(--water-bg-soft);
}

.helper-quick-pill-icon {
    width: 16px;
    height: 16px;
    color: var(--water-primary);
    display: inline-flex;
    flex: 0 0 auto;
}

.helper-quick-pill-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.helper-quick-pill-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==================== 底部输入区 ==================== */
.helper-input-area {
    padding: 16px 20px 18px;
    border-top: 1px solid var(--line);
    background: #f2f7f9;
    flex-shrink: 0;
    margin-top: auto;
    width: 100%;
    min-width: 0;
}

.helper-input-box {
    background: #fff;
    border: 1px solid #e4e4e7;
    border-radius: 18px;
    padding: 8px 10px 4px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    box-shadow: 0 1px 2px rgba(15, 76, 92, 0.06);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.helper-input-box:focus-within {
    border-color: var(--water-mid);
    box-shadow: 0 0 0 3px rgba(42, 147, 168, 0.14);
}

.helper-input {
    display: block;
    width: 100%;
    min-height: 40px;
    max-height: 120px;
    padding: 8px 8px;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--ink-black);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
    overflow-y: auto;
    min-width: 0;
    word-break: break-word;
    caret-color: var(--water-primary);
    box-sizing: border-box;
}

.helper-input::placeholder {
    color: var(--ink-light);
    opacity: 1;
}

.helper-input-toolbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-width: 0;
    padding: 0 2px 2px;
}

.helper-tool-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--ink-light);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex: 0 0 auto;
    transition: background 0.15s ease, color 0.15s ease;
}

.helper-tool-btn:hover {
    background: var(--water-bg-soft);
    color: var(--water-primary);
}

.helper-tool-btn svg {
    width: 19px;
    height: 19px;
    fill: currentColor;
}

.helper-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #1a6b7c, #2a93a8);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex: 0 0 auto;
    box-shadow: 0 3px 10px rgba(26, 107, 124, 0.26);
    transition: opacity 0.15s ease, filter 0.15s ease;
}

.helper-send-btn:not(:disabled):hover {
    filter: brightness(1.08);
}

.helper-send-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    box-shadow: none;
}

.helper-send-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* ==================== 待发送图片 ==================== */
.helper-pending-images {
    padding: 0 14px 8px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    background: #f2f7f9;
    flex-shrink: 0;
}

.helper-pending-img-wrap {
    position: relative;
}

.helper-pending-img {
    width: 56px;
    height: 56px;
    border-radius: 10px;
    object-fit: cover;
    border: 1px solid var(--line);
}

.helper-pending-img-remove {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: 2px solid #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.helper-pending-img-remove svg {
    width: 8px;
    height: 8px;
    fill: currentColor;
}

/* ==================== 消息内图片 ==================== */
.helper-msg-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.helper-msg-image {
    max-width: 72%;
    max-height: 180px;
    border-radius: 10px;
    border: 1px solid var(--line);
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.helper-msg-image:hover {
    transform: scale(1.02);
}

/* ==================== 移动端适配 ==================== */
@media (max-width: 520px) {
    .helper-fab {
        right: 16px;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        width: 50px;
        height: 50px;
    }

    .helper-window {
        right: 0;
        left: 0;
        top: env(safe-area-inset-top, 0px);
        bottom: 0;
        width: 100%;
        height: auto;
        max-height: none;
        border-radius: 18px 18px 0 0;
        transform-origin: bottom center;
        transform: translateY(100%);
        margin: 0;
        border: none;
    }

    .helper-window.open {
        transform: translateY(0);
    }

    .helper-header {
        padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 12px;
        height: auto;
        min-height: 60px;
        cursor: default;
        touch-action: none;
    }

    .helper-header::before {
        display: block;
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.4);
        border-radius: 2px;
    }

    .helper-messages {
        padding: 16px 13px;
        gap: 16px;
    }

    .helper-ai-content,
    .helper-user-bubble {
        font-size: 15px;
    }

    .helper-user-bubble {
        max-width: 84%;
    }

    .helper-msg-image {
        max-height: 160px;
    }

    .helper-input-area {
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .helper-input {
        font-size: 16px !important;
        padding: 8px 8px;
    }

    .helper-send-btn {
        width: 38px;
        height: 38px;
    }
}
