:root {
    --brand: #4f7cff;
    --panel: #ffffff;
    --text: #1f2a44;
    --sub-text: #6d7b99;
    --border: #dbe4ff;
    --bg: #f8faff;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    overflow: hidden;
    font-family: "Microsoft YaHei", "SimHei", sans-serif;
    font-size: 14px;
}

.widget-root {
    width: 100%;
    height: 100%;
    position: relative;
}

/* 兼容旧脚本：仅切 class 时也能正确显示/隐藏 */
.widget-root.is-open .chat-panel {
    display: flex !important;
}

.widget-root.is-open .fab-ball {
    display: none !important;
}

.widget-root.is-open .fab-hint {
    display: none !important;
}

/* --- 悬浮球 --- */
.fab-ball {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(140deg, #5c88ff 0%, #6a6cff 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    box-shadow: 0 10px 24px rgba(74, 106, 232, 0.35);
    position: absolute;
    left: 0;
    right: auto;
    bottom: 0;
}

.fab-hint {
    position: absolute;
    left: 66px;
    bottom: 10px;
    background: rgba(255, 255, 255, 0.96);
    color: #35508f;
    border: 1px solid #d7e3ff;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
    box-shadow: 0 6px 16px rgba(70, 96, 170, 0.2);
    white-space: nowrap;
    pointer-events: none;
    animation: fabHintPulse 1.8s ease-in-out infinite;
}

@keyframes fabHintPulse {
    0%, 100% { transform: translateY(0); opacity: 0.9; }
    50% { transform: translateY(-2px); opacity: 1; }
}

/* --- 聊天面板 --- */
.chat-panel {
    width: 100%;
    height: 100%;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    /* 关键修复：使用 flex 布局来分配空间 */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(44, 76, 154, 0.18);
}

.chat-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* 固定高度，不参与 flex 伸缩 */
    flex-shrink: 0;
    cursor: default;
    user-select: none;
}

.chat-header.dragging {
    cursor: default;
}

.confirm-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(18, 28, 55, 0.35);
    backdrop-filter: blur(2px);
}

.confirm-dialog {
    width: min(300px, calc(100% - 24px));
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(42, 66, 128, 0.22);
    padding: 14px;
}

.confirm-title {
    margin: 0;
    font-size: 15px;
    color: var(--text);
}

.confirm-text {
    margin: 8px 0 14px;
    font-size: 13px;
    color: var(--sub-text);
}

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.confirm-btn {
    border: 1px solid var(--border);
    border-radius: 9px;
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
    cursor: pointer;
}

.confirm-btn.secondary {
    background: #fff;
    color: var(--sub-text);
}

.confirm-btn.primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

/* 让聊天框占据所有剩余空间 */
.chat-box {
    flex-grow: 1;
    padding: 12px;
    overflow-y: auto;
    background: var(--bg);
}

.chat-input-row, .chat-status {
    /* 固定高度，不参与 flex 伸缩 */
    flex-shrink: 0;
}

/* --- 内部组件样式 (基本不变) --- */
.chat-title { font-size: 1rem; font-weight: 700; color: var(--brand); }
.chat-header-btn { background: #fff; border: 1px solid var(--border); width: 28px; height: 28px; border-radius: 8px; padding: 0; cursor: pointer; color: var(--sub-text); }
.chat-item { margin-bottom: 10px; max-width: 88%; padding: 8px 12px; border-radius: 12px; word-break: break-word; white-space: pre-wrap; }
.chat-ai { background: #ffffff; color: var(--text); border: 1px solid #e6edff; border-bottom-left-radius: 4px; }
.chat-user { background: linear-gradient(145deg, #5f83ff 0%, #4f6fff 100%); color: #fff; border-bottom-right-radius: 4px; margin-left: auto; }
.chat-input-row { padding: 10px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; background: #fff; }
.chat-input { flex-grow: 1; min-width: 0; border-radius: 20px; border: 1px solid var(--border); background: #f7faff; color: var(--text); padding: 8px 14px; font-size: 14px; }
.chat-send { width: 36px; height: 36px; border: none; border-radius: 50%; color: #fff; background: var(--brand); cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chat-status { padding: 4px 12px 8px; display: flex; justify-content: space-between; color: var(--sub-text); font-size: 11px; background: #fff; border-top: 1px solid #edf2ff; }
