/**
 * AI 球样式（水晶悬浮球 + 面板 + 工具大窗）
 * 变量与组件样式沿用 tool.alexer.cc 悬浮球（cw-* 前缀），保证视觉一致；
 * 末尾 ab-toolframe 为博客侧新增的全屏工具窗。
 */

.cw-root {
    --cw-primary: #059669;
    --cw-primary-hover: #10b981;
    --cw-on-primary: #fff;
    --cw-bg: #fff;
    --cw-bg-muted: #f9fafb;
    --cw-surface: #fff;
    --cw-border: #e5e7eb;
    --cw-border-light: #f3f4f6;
    --cw-text: #1f2937;
    --cw-text-secondary: #4b5563;
    --cw-text-muted: #6b7280;
    --cw-text-faint: #9ca3af;
    --cw-bubble: #fff;
    --cw-on-bubble: #1f2937;
    --cw-radius-sm: 6px;
    --cw-radius: 10px;
    --cw-radius-lg: 14px;
    --cw-radius-full: 9999px;
    --cw-shadow-sm: 0 1px 2px #1f23290a;
    --cw-shadow-panel: 0 12px 40px #00000038;
    --cw-transition: .15s cubic-bezier(.4, 0, .2, 1);
    --cw-font-size-lg: 16px;
    --cw-font-size: 14px;
    --cw-font-size-sm: 12px;
    font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Noto Sans, Arial, sans-serif;
}

:root.dark .cw-root {
    --cw-primary: #10b981;
    --cw-primary-hover: #059669;
    --cw-bg: #1a1b1e;
    --cw-bg-muted: #212226;
    --cw-surface: #25262a;
    --cw-border: #3a3b3f;
    --cw-border-light: #2a2b2e;
    --cw-text: #e5e7eb;
    --cw-text-secondary: #b0b3b8;
    --cw-text-muted: #8b8e93;
    --cw-text-faint: #6b6e73;
    --cw-bubble: #1f2937;
    --cw-on-bubble: #e5e7eb;
    --cw-shadow-panel: 0 12px 40px #00000080;
}

/* ---------------- 悬浮球 ---------------- */
.cw-launcher {
    z-index: 9999;
    will-change: transform;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    width: 48px;
    height: 48px;
    transition: left .45s cubic-bezier(.34, 1.56, .64, 1), top .22s cubic-bezier(.4, 0, .2, 1);
    position: fixed;
    transform: translateZ(0);
}

.cw-launcher--dragging { transition: none; }

.cw-launcher-btn {
    border-radius: var(--cw-radius-full);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    cursor: grab;
    background: 0 0;
    border: none;
    justify-content: center;
    align-items: center;
    width: 48px;
    height: 48px;
    padding: 0;
    transition: opacity .2s, transform .2s cubic-bezier(.4, 0, .2, 1);
    display: flex;
    position: relative;
}

.cw-launcher-btn:hover { transform: scale(1.08); }
.cw-launcher-btn:active { cursor: grabbing; }
.cw-launcher-icon { justify-content: center; align-items: center; width: 100%; height: 100%; display: flex; }
.cw-launcher-icon svg { width: 100%; height: 100%; }
.cw-ball-svg { filter: drop-shadow(0 6px 16px #00000040); display: block; }

/* 停靠把手：球缩进右缘后仅露把手，点按弹出 */
.cw-launcher--docked .cw-launcher-btn { opacity: 0; pointer-events: none; }
.cw-launcher--docked .cw-dock-bar { opacity: 1; pointer-events: auto; }

.cw-dock-bar {
    color: #fff;
    cursor: grab;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    opacity: 0;
    pointer-events: none;
    z-index: 4;
    background: linear-gradient(#059669, #10b981);
    border-radius: 18px 0 0 18px;
    justify-content: center;
    align-items: center;
    width: 32px;
    height: 36px;
    transition: opacity .2s;
    display: flex;
    position: absolute;
    top: 50%;
    left: -2px;
    transform: translateY(-50%);
    box-shadow: -2px 0 10px #0000002e;
}

.cw-dock-bar:hover { background: linear-gradient(#10b981, #059669); }
.cw-dock-bar:active { cursor: grabbing; }
.cw-dock-bar svg { width: 14px; height: 14px; }

/* ---------------- 面板 ---------------- */
.cw-panel {
    z-index: 9998;
    background: var(--cw-bg);
    border-radius: var(--cw-radius-lg);
    width: 400px;
    max-width: calc(100vw - 3rem);
    height: 620px;
    max-height: calc(100dvh - 3rem);
    box-shadow: var(--cw-shadow-panel);
    flex-direction: column;
    animation: .25s cw-fade-slide-in;
    display: none;
    position: fixed;
    overflow: hidden;
}

.cw-root--open .cw-panel { display: flex; }

@keyframes cw-fade-slide-in {
    0% { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.cw-header {
    background: var(--cw-bg);
    color: var(--cw-text);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    border-bottom: 1px solid var(--cw-border-light);
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    display: flex;
}

.cw-header-left { align-items: center; gap: 8px; min-width: 0; display: flex; }

.cw-header-logo {
    color: #fff;
    background: linear-gradient(135deg, #059669, #10b981);
    border-radius: 50%;
    flex-shrink: 0;
    justify-content: center;
    align-items: center;
    width: 26px;
    height: 26px;
    display: flex;
}

.cw-header-title {
    font-size: var(--cw-font-size-lg);
    white-space: nowrap;
    text-overflow: ellipsis;
    font-weight: 600;
    overflow: hidden;
}

.cw-header-actions { flex-shrink: 0; align-items: center; gap: 2px; display: flex; }

.cw-header-btn {
    border-radius: var(--cw-radius-sm);
    width: 30px;
    height: 30px;
    color: var(--cw-text-secondary);
    cursor: pointer;
    transition: background-color var(--cw-transition), color var(--cw-transition);
    background: 0 0;
    border: none;
    justify-content: center;
    align-items: center;
    display: inline-flex;
}

.cw-header-btn:hover { color: var(--cw-text); background: #0000000d; }
:root.dark .cw-header-btn:hover { background: #ffffff14; }
.cw-header-btn svg { width: 16px; height: 16px; }

/* ---------------- 消息区 ---------------- */
.cw-messages {
    min-height: 0;
    font-size: var(--cw-font-size);
    color: var(--cw-text);
    background: var(--cw-bg-muted);
    flex-direction: column;
    flex: 1;
    gap: 12px;
    padding: 16px;
    line-height: 1.5;
    display: flex;
    overflow-y: auto;
}

.cw-messages::-webkit-scrollbar { width: .25em; }
.cw-messages::-webkit-scrollbar-thumb { background-color: var(--cw-border); border-radius: 5px; }

.cw-welcome {
    text-align: center;
    max-width: 300px;
    color: var(--cw-text-muted);
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: auto;
    display: flex;
}

.cw-welcome-text { font-size: var(--cw-font-size-sm); line-height: 1.6; }

.cw-msg { flex-direction: column; display: flex; }
.cw-msg-user { align-items: flex-end; }
.cw-msg-assistant { align-items: flex-start; gap: 12px; }

.cw-msg-bubble {
    border-radius: var(--cw-radius);
    max-width: 85%;
    font-size: var(--cw-font-size);
    word-break: break-word;
    white-space: pre-wrap;
    padding: 10px 14px;
    line-height: 1.7;
}

.cw-msg-user .cw-msg-bubble {
    background: var(--cw-bubble);
    color: var(--cw-on-bubble);
    border: 1px solid var(--cw-border);
    border-bottom-right-radius: 4px;
}

.cw-msg-assistant .cw-msg-bubble {
    background: var(--cw-surface);
    color: var(--cw-text);
    border: 1px solid var(--cw-border-light);
    border-bottom-left-radius: 4px;
}

.cw-text { white-space: pre-wrap; word-break: break-word; }

.cw-cursor {
    vertical-align: text-bottom;
    background: var(--cw-primary);
    width: 2px;
    height: 1em;
    margin-left: 1px;
    animation: .9s step-end infinite cw-blink;
    display: inline-block;
}

@keyframes cw-blink { 0%, to { opacity: 1; } 50% { opacity: 0; } }

/* ---------------- 工具 / 文章卡片 ---------------- */
.cw-tools { flex-direction: column; gap: 8px; margin-top: 10px; display: flex; }

.cw-tool-card {
    border: 1px solid var(--cw-border);
    border-radius: var(--cw-radius);
    background: var(--cw-surface);
    transition: border-color var(--cw-transition), box-shadow var(--cw-transition);
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    text-decoration: none;
    display: flex;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.cw-tool-card:hover { border-color: var(--cw-primary); box-shadow: 0 2px 8px #00000014; }

.cw-tool-icon {
    border-radius: var(--cw-radius-sm);
    color: #fff;
    flex-shrink: 0;
    justify-content: center;
    align-items: center;
    width: 30px;
    height: 30px;
    display: flex;
    font-size: 13px;
    font-weight: 700;
}

.cw-tool-body { flex-direction: column; gap: 2px; min-width: 0; display: flex; }

.cw-tool-title {
    font-size: var(--cw-font-size-sm);
    color: var(--cw-text);
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.cw-tool-desc {
    font-size: var(--cw-font-size-sm);
    color: var(--cw-text-muted);
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4;
    display: -webkit-box;
    overflow: hidden;
}

.cw-result-note {
    font-size: var(--cw-font-size-sm);
    color: var(--cw-text-muted);
    padding: 2px 2px 0;
}

/* 搜索模式结果容器 */
.cw-search-results { flex-direction: column; gap: 8px; display: flex; }

/* ---------------- 历史会话（仅 AI 模式） ---------------- */
.cw-history { background: var(--cw-bg-muted); flex-direction: column; flex: 1; min-height: 0; display: none; overflow: hidden; }
.cw-root--history .cw-history { display: flex; }
.cw-root--history .cw-messages,
.cw-root--history .cw-input-area { display: none; }

.cw-history-header {
    border-bottom: 1px solid var(--cw-border-light);
    font-size: var(--cw-font-size-sm);
    color: var(--cw-text);
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-weight: 600;
    display: flex;
}

.cw-history-back {
    color: var(--cw-text-secondary);
    font-size: var(--cw-font-size-sm);
    cursor: pointer;
    border-radius: var(--cw-radius-sm);
    transition: background-color var(--cw-transition), color var(--cw-transition);
    background: 0 0;
    border: none;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    display: inline-flex;
}

.cw-history-back:hover { color: var(--cw-text); background: #0000000d; }

.cw-history-list { flex-direction: column; flex: 1; gap: 6px; min-height: 0; padding: 8px; display: flex; overflow-y: auto; }

.cw-history-item {
    border: 1px solid var(--cw-border);
    border-radius: var(--cw-radius);
    background: var(--cw-surface);
    cursor: pointer;
    transition: border-color var(--cw-transition), box-shadow var(--cw-transition);
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    display: flex;
}

.cw-history-item:hover { border-color: var(--cw-primary); box-shadow: 0 2px 8px #0000000f; }

.cw-history-item-title {
    min-width: 0;
    font-size: var(--cw-font-size);
    color: var(--cw-text);
    white-space: nowrap;
    text-overflow: ellipsis;
    flex: 1;
    overflow: hidden;
}

.cw-history-item-time { font-size: var(--cw-font-size-sm); color: var(--cw-text-faint); flex-shrink: 0; }

.cw-history-empty {
    text-align: center;
    color: var(--cw-text-muted);
    font-size: var(--cw-font-size-sm);
    margin: auto;
    padding: 24px;
}

/* ---------------- 输入区 ---------------- */
.cw-input-area {
    border-top: 1px solid var(--cw-border-light);
    background: var(--cw-bg);
    flex-direction: column;
    gap: 6px;
    padding: 10px 16px;
    display: flex;
}

.cw-input-box {
    border: 1px solid var(--cw-border);
    border-radius: var(--cw-radius);
    background: var(--cw-bg-muted);
    transition: border-color var(--cw-transition), box-shadow var(--cw-transition);
    flex-direction: column;
    padding: 10px 10px 8px 12px;
    display: flex;
}

.cw-input-box:focus-within { border-color: var(--cw-primary); box-shadow: 0 0 0 2px #0596691f; }

.cw-input {
    min-height: 60px;
    max-height: 160px;
    color: var(--cw-text);
    font-size: var(--cw-font-size);
    resize: none;
    background: 0 0;
    border: none;
    outline: none;
    flex: 1;
    font-family: inherit;
    line-height: 1.6;
    overflow-y: auto;
}

.cw-input::placeholder { color: var(--cw-text-faint); }

.cw-input-actions { justify-content: flex-end; align-items: center; gap: 6px; padding-top: 6px; display: flex; }

.cw-mic-btn {
    border-radius: var(--cw-radius-sm);
    width: 34px;
    height: 34px;
    color: var(--cw-text-muted);
    cursor: pointer;
    transition: background-color var(--cw-transition), color var(--cw-transition);
    background: 0 0;
    border: none;
    flex-shrink: 0;
    justify-content: center;
    align-items: center;
    display: flex;
}

.cw-mic-btn:hover { color: var(--cw-text); background: #0000000d; }
.cw-mic-btn svg { width: 16px; height: 16px; }

.cw-mic-btn--active { color: #fff; background: #dc2626; animation: 1.2s ease-in-out infinite cw-mic-pulse; }

@keyframes cw-mic-pulse {
    0%, to { box-shadow: 0 0 #dc262673; }
    50% { box-shadow: 0 0 0 6px #dc262600; }
}

.cw-send-btn {
    border-radius: var(--cw-radius-sm);
    background: var(--cw-primary);
    width: 34px;
    height: 34px;
    color: var(--cw-on-primary);
    cursor: pointer;
    transition: background-color var(--cw-transition), opacity var(--cw-transition);
    border: none;
    flex-shrink: 0;
    justify-content: center;
    align-items: center;
    display: flex;
}

.cw-send-btn svg { width: 16px; height: 16px; }
.cw-send-btn:hover:not(:disabled) { background: var(--cw-primary-hover); }
.cw-send-btn:disabled { opacity: .4; cursor: not-allowed; }

.cw-footer { text-align: center; color: var(--cw-text-faint); padding-bottom: 2px; font-size: 11px; }

/* ---------------- 全屏工具大窗（博客侧新增） ---------------- */
.cw-toolframe {
    z-index: 10000;
    background: var(--cw-bg);
    flex-direction: column;
    display: none;
    position: fixed;
    inset: 0;
}

.cw-root--tool .cw-toolframe { display: flex; }
.cw-root--tool .cw-panel,
.cw-root--tool .cw-launcher { display: none; }

.cw-toolframe-bar {
    background: var(--cw-bg);
    color: var(--cw-text);
    border-bottom: 1px solid var(--cw-border-light);
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    padding-top: calc(7px + env(safe-area-inset-top));
    display: flex;
    flex-shrink: 0;
}

.cw-toolframe-back {
    border-radius: var(--cw-radius-sm);
    color: var(--cw-text-secondary);
    cursor: pointer;
    transition: background-color var(--cw-transition), color var(--cw-transition);
    background: 0 0;
    border: none;
    align-items: center;
    gap: 4px;
    padding: 6px 10px 6px 6px;
    display: inline-flex;
    font-size: var(--cw-font-size);
}

.cw-toolframe-back:hover { color: var(--cw-text); background: #0000000d; }
.cw-toolframe-back svg { width: 16px; height: 16px; }

.cw-toolframe-name {
    font-size: var(--cw-font-size);
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.cw-toolframe-cat {
    font-size: 11px;
    color: var(--cw-text-muted);
    border: 1px solid var(--cw-border);
    border-radius: var(--cw-radius-full);
    padding: 2px 8px;
    flex-shrink: 0;
}

/* 裁掉工具站自带 64px 顶部导航，仅露工具本体 */
.cw-toolframe-body { position: relative; flex: 1; overflow: hidden; background: var(--cw-bg); }

.cw-toolframe-iframe {
    position: absolute;
    top: -64px;
    left: 0;
    width: 100%;
    height: calc(100% + 64px);
    border: none;
}

.cw-toolframe-loading {
    position: absolute;
    inset: 0;
    background: var(--cw-bg);
    color: var(--cw-text-faint);
    font-size: var(--cw-font-size-sm);
    justify-content: center;
    align-items: center;
    display: flex;
    z-index: 2;
    transition: opacity .2s;
}

.cw-toolframe-loading.is-hidden { opacity: 0; pointer-events: none; }

/* ---------------- 移动端：面板与大窗全屏 ---------------- */
@media (width<=768px) {
    .cw-root--open .cw-launcher { display: none; }

    .cw-panel {
        border-radius: 0;
        max-width: none;
        max-height: none;
        animation: none;
        width: 100vw !important;
        height: 100dvh !important;
        position: fixed !important;
        inset: 0 !important;
    }

    .cw-header { padding-top: calc(10px + env(safe-area-inset-top)); }
    .cw-messages { padding: 12px; }
    .cw-input-area { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}
