/* src/taskpane/taskpane.css */
/* Version: v20.0 (Cleaned & Merged: Production Ready) */

:root {
    /* --- Design Tokens --- */
    
    /* 颜色：黑白灰主调 */
    --color-black: #242424;
    --color-text-sub: #605e5c;
    --color-border: #d1d1d1;
    --color-border-hover: #a1a1a1;
    
    /* 颜色：功能色 */
    --color-primary: #0078d4;      /* 选中高亮 */
    --color-danger: #d13438;       /* 警示红 */
    --color-success: #107c10;      /* 成功绿 */

    /* 背景色 */
    --bg-body: #ffffff;
    --bg-toolbar: rgb(244, 244, 244); 
    --bg-hover: #f5f5f5;
    --bg-active: rgb(197, 198, 198); /* 点击深灰 */
    --bg-disabled: #e6e6e6;          /* 禁用背景 */
    --bg-selected: #eff6fc;          /* 列表选中 */
    --bg-current: #f0fdf4;           /* 当前运行中 */

    /* 尺寸 */
    --radius-sm: 2px;  /* 原有的小圆角 */
    --radius-md: 4px;  /* 中等圆角 (Footer/Input) */
}

/* ==========================================================================
   1. Reset & Global Layout
   ========================================================================== */
* { box-sizing: border-box; }

body {
    height: 100vh;
    margin: 0; padding: 0;
    display: flex; flex-direction: column;
    overflow: hidden;
    font-family: "Segoe UI", "Helvetica Neue", sans-serif;
    font-size: 12px;
    color: var(--color-black);
    background: var(--bg-body);
}

/* ==========================================================================
   2. Structural Layout
   ========================================================================== */
.layout-header {
    flex-shrink: 0;
    background: var(--bg-body);
    border-bottom: 1px solid var(--color-border);
    z-index: 10;
}

.layout-content {
    flex-grow: 1;
    overflow-y: auto;
    display: flex; flex-direction: column;
    position: relative;
    background: var(--bg-body);
}

.layout-footer {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid var(--color-border);
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 20;
}

.disclaimer-text {
    font-size: 10px; /* 最小可读字号 */
    color: #828282; /* 辅助性颜色 */
    padding: 2px 10px;
    background-color: #f8f8f8;
    border-top: 1px solid #edebe9; /* 与上方操作区隔离 */
    text-align: center;
    font-style: italic;
}

.footer-row {
    display: flex;
    align-items: center;
    width: 100%;
}
.footer-row.input-row { gap: 6px; }

/* ==========================================================================
   3. Base Components (Atoms)
   ========================================================================== */

/* --- Buttons Base --- */
button {
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 12px;
    transition: all 0.1s ease-in-out; 
    display: flex; align-items: center; justify-content: center;
    font-family: inherit;
    background-color: transparent; 
    border: 1px solid transparent; 
}

/* 1. Generic Buttons (Minimal/Black/Outline) */
.btn-minimal, .btn-black, .btn-outline {
    flex: 1;
    height: 32px;
    background: #ffffff;
    color: var(--color-black);
    border: 1px solid var(--color-border);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.btn-minimal:hover, .btn-black:hover, .btn-outline:hover {
    background: var(--bg-hover);
    border-color: var(--color-border-hover);
}
.btn-minimal:active, .btn-black:active, .btn-outline:active {
    background: var(--bg-active);
    border-color: var(--color-border-hover);
    transform: translateY(1px);
}

/* 2. Danger Buttons */
.btn-outline-danger {
    flex: 1;
    height: 32px;
    background: #ffffff;
    color: var(--color-danger);
    border: 1px solid var(--color-border);
}
.btn-outline-danger:hover { background-color: var(--color-danger); color: #ffffff; border-color: var(--color-danger); }
.btn-outline-danger:active { background-color: #a82b2f; border-color: #a82b2f; color: #ffffff; }

/* 成功状态：用于按钮操作成功后的视觉反馈 */
.btn-status-success {
    background-color: var(--color-success) !important;
    border-color: var(--color-success) !important;
    color: #ffffff !important;
    cursor: default !important; /* 防止用户以为还能点 */
    box-shadow: none !important;
    opacity: 1 !important; /* 覆盖可能存在的 disabled 透明度 */
}

/* 成功状态下的图标颜色修正 (强制变白) */
.btn-status-success svg {
    fill: currentColor; /* 让 SVG 跟随文字颜色 */
}

/* 简单的淡入淡出动画过渡 */
.btn-status-success {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* Group 3: Ghost Buttons (Transparent Background) */

/* 3.1. Base Ghost Style (共享交互逻辑：透明底 + 悬停变灰) */
.btn-menu, .btn-ghost {
    background: transparent; 
    border: none; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.1s;
}

/* 3.2. Icon Button (用于设置齿轮、Header图标) -> 锁定方形尺寸 */
.btn-menu {
    color: var(--color-black);
    width: 28px; 
    height: 28px; 
}

/* 3.3. Text Action Button (用于“智能提炼”) -> 自适应宽度 + 蓝色强调 */
.btn-ghost {
    color: var(--color-primary); /* 使用主色调，强调这是个功能入口 */
    width: auto;                 /* 关键修复：允许文字撑开宽度 */
    padding: 0 6px;              /* 给文字留点呼吸空间 */
    height: 24px;                /* 比图标稍微矮一点，显得精致 */
    font-size: 11px;
}

/* Shared Interaction States */
/* 悬停时：两者都变灰底，文字变深色 */
.btn-menu:hover, .btn-ghost:hover { 
    background: var(--bg-hover); 
    color: #000; 
}
.btn-menu:active, .btn-ghost:active { 
    background: var(--bg-active); 
}
/* 4. Special Buttons (Clean/Purge) */
.btn-icon-ghost-danger {
    color: #999;
    width: 28px; height: 28px;
    transition: all 0.2s;
}
.btn-icon-ghost-danger:hover { color: var(--color-danger); background-color: #fde7e9; }
.btn-icon-ghost-danger:active { background-color: #f8d7da; }
.btn-icon-ghost-danger.confirm-state {
    color: #fff !important;
    background-color: var(--color-danger) !important;
    width: auto !important;
    padding: 0 8px; font-size: 11px;
}

/* 5. Footer Buttons */
.btn-primary-full {
    width: 100%; height: 34px;
    background-color: var(--color-black); color: #ffffff;
    border-radius: var(--radius-md);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.btn-primary-full:hover { background-color: #000000; }

.btn-icon-action { /* Footer Send Button */
    width: 34px; height: 34px; flex-shrink: 0;
    background: #f3f2f1; color: var(--color-primary);
    border-radius: var(--radius-md); font-size: 14px;
}
.btn-icon-action:hover { background: #e1dfdd; color: #005a9e; }
.btn-icon-action:active { background: #d0d0d0; }

/* 发送按钮运行状态样式 */
.btn-icon.is-running {
    position: relative;
    transition: all 0.2s ease;
}

.btn-icon.is-running svg {
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* 外环旋转动画 (Gemini风格) */
.btn-icon.is-running::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 2px solid transparent;
    border-top: 2px solid #333; /* 主色调深灰 */
    border-radius: 50%;
    animation: rotate 1s linear infinite;
    z-index: 1;
}

/* 内部停止方块 (保持呼吸感) */
.btn-icon.is-running::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background-color: #333; /* 深灰色，符合商务配色 */
    border-radius: 2px; /* 2px圆角，符合商务审美 */
    opacity: 1;
    transition: opacity 0.2s ease;
    animation: breath 1.5s ease-in-out infinite;
    /* 使用ICONS.STOP中的SVG作为背景图像 */
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 16 16" fill="%23333"><rect x="2" y="2" width="12" height="12" rx="2"/></svg>');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    z-index: 2;
}

/* 呼吸感动画 */
@keyframes breath {
    0%, 100% {
        opacity: 0.7;
        transform: translate(-50%, -50%) scale(0.95);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* 外环旋转动画 */
@keyframes rotate {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }
    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Disabled State */
button:disabled,
.btn-minimal:disabled, .btn-black:disabled, .btn-outline:disabled,
.btn-outline-danger:disabled, .btn-primary-full:disabled,
.btn-icon-action:disabled, .async-btn:disabled {
    background-color: var(--bg-disabled);
    color: #a6a6a6;
    border-color: #e1dfdd;
    cursor: not-allowed;
    box-shadow: none; pointer-events: none;
}

/* --- Inputs --- */
input[type="text"], input[type="password"], textarea, select {
    width: 100%; padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 12px; font-family: inherit;
    background: #fff; outline: none; margin-bottom: 4px;
}
input:focus, textarea:focus, select:focus { border-color: var(--color-primary); }

/* Footer Compact Input */
.compact-input {
    width: 100%; height: 32px;
    line-height: 30px; /* Center text vertically */
    padding: 0 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 12px;
    background-color: #f3f2f1;
    margin-bottom: 0 !important;
    transition: all 0.2s;
    outline: none;
}
.compact-input:focus {
    background-color: #ffffff;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 1px var(--color-primary);
}

textarea.config-editor {
    min-height: 140px;
    font-size: 12px; line-height: 1.5;
    background-color: #f9f9f9; resize: vertical;
    padding: 8px;
}

/* ==========================================================================
   4. Header & Toolbar
   ========================================================================== */
.header-top-row {
    display: flex; align-items: center;
    height: 45px; padding-left: 12px; padding-right: 40px; gap: 8px;
}

/* Model Selector */
.model-select-wrapper { flex: 1; min-width: 0; position: relative; display: flex; align-items: center; }
.dropdown-trigger { 
    display: inline-flex; align-items: center; justify-content: space-between;
    width: auto !important; max-width: 100%;
    cursor: pointer; padding: 6px 10px; border-radius: 6px; 
    transition: background 0.1s; 
}
.dropdown-trigger:hover { background-color: var(--bg-hover); }
.dropdown-trigger:active { background-color: var(--bg-active); }
.model-text { 
    font-weight: 600; font-size: 13px; margin-right: 6px; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}
.dropdown-trigger span:last-of-type { display: inline-block; transition: transform 0.2s ease; font-size: 10px; color: #666; }
.dropdown-trigger.active span:last-of-type { transform: rotate(180deg); }

.dropdown-menu {
    display: none; position: absolute; top: 100%; left: 0; width: 100%; min-width: 180px;
    background: #fff; border: 1px solid var(--color-black);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1); z-index: 100; margin-top: 4px;
}
.dropdown-menu.show { display: block; }
.dropdown-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f3f3f3; }
.dropdown-item:hover { background: #f3f3f3; }
.dropdown-item.selected { font-weight: bold; background: #eee; }

/* Toolbar Area */
.toolbar-container {
    background-color: var(--bg-toolbar);
    padding: 12px;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}
.action-btn-group { display: flex; gap: 8px; }

/* Breadcrumb (Capsule Style) */
.breadcrumb-row {
    margin-bottom: 12px; display: flex; align-items: center;
    height: 24px; overflow: hidden; border-bottom: 1px solid transparent;
}
.breadcrumb-scrollable {
    flex: 1; display: flex; align-items: center;
    white-space: nowrap; overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none; -ms-overflow-style: none;
    mask-image: linear-gradient(to right, black 90%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 90%, transparent 100%);
    cursor: default; user-select: none;
}
.breadcrumb-scrollable::-webkit-scrollbar { display: none; }
.crumb-text {
    font-size: 11px; color: #605e5c; max-width: 160px; 
    overflow: hidden; text-overflow: ellipsis;
}
.crumb-text.current { color: #0078d4; font-weight: 600; }
.crumb-badge {
    display: inline-block; padding: 0 5px; margin-right: 4px;
    border-radius: 4px; font-size: 9px; font-weight: 700;
    line-height: 16px; height: 16px;
    background-color: #f3f2f1; color: #605e5c; border: 1px solid #e1dfdd;
    font-family: Consolas, monospace;
}
.crumb-badge.lvl-1 { background-color: #eff6fc; color: #0078d4; border-color: #c7e0f4; }
.crumb-badge.lvl-2 { background-color: #f0fdf4; color: #107c10; border-color: #bcebd5; }
.crumb-badge.lvl-3 { background-color: #fff4ce; color: #795e00; border-color: #fde7d9; }

/* ==========================================================================
   5. Content & Tab Area (Reverted & Optimized)
   ========================================================================== */
.tab-header { 
    display: flex; 
    border-bottom: 1px solid var(--color-border); 
    background: #fff; 
}

.tab-item {
    flex: 1; text-align: center; padding: 12px 0;
    cursor: pointer; color: #666; 
    border-bottom: 2px solid transparent; 
    font-weight: 600;
    transition: all 0.2s;
}

.tab-item.active { 
    color: var(--color-black); 
    border-bottom: 2px solid var(--color-black); 
}

/* --- 大纲模式专属样式 (Purple Theme) --- */

/* 1. 激活状态：深紫文字 + 浅紫底 + 紫色下划线 */
.tab-item.active.mode-outline {
    color: #5c2d91;            /* Deep Purple */
    border-bottom-color: #5c2d91;
    background-color: #f3f0f9; /* Pale Purple */
}

/* 2. 非激活状态：保留淡紫色文字，避免回退到灰色 */
.tab-item.mode-outline:not(.active) {
    color: #9e7cc1;            /* Light Purple Text */
}

.tab-content-wrapper { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    position: relative; 
}

/* --- 新增：大纲模式下的按钮样式 (覆盖默认黑色) --- */
.btn-primary-full.mode-outline {
    background-color: #5c2d91; /* 与你的 Tab 激活色一致 (Deep Purple) */
    border-color: #5c2d91;
    color: #ffffff;
}

.btn-primary-full.mode-outline:hover {
    background-color: #4a2475; /* 悬停时稍微加深 */
}

.btn-primary-full.mode-outline:active {
    background-color: #321850; /* 点击时更深 */
}

/* --- Editor --- */
.full-height-editor {
    flex: 1; 
    width: 100%; 
    border: none; 
    resize: none; 
    padding: 16px; 
    font-family: inherit; 
    line-height: 1.6; 
    outline: none; 
    font-size: 13px; 
    color: var(--color-black);
    transition: background-color 0.3s ease; /* 背景色平滑过渡 */
}

/* [New] 大纲模式下的编辑器背景：极淡紫色 */
.full-height-editor.mode-outline {
    background-color: #fcfaff; /* Very very pale purple */
}

/* ==========================================================================
   6. Settings Overlay (优化后的固定页脚架构 + 表单修复)
   ========================================================================== */
.settings-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: #fff; z-index: 9999; 
    display: none;      /* 由 taskpane.ts 控制显隐 */
    flex-direction: column; /* 纵向排列：Header -> Modal(滚动) -> Footer(固定) */
}

/* 顶部标题栏：禁止压缩 */
.settings-header {
    flex-shrink: 0; 
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0; padding: 14px 16px; 
    font-size: 16px; font-weight: bold;
    border-bottom: 1px solid var(--color-border);
}

/* 中间内容滚动区：占据剩余空间 */
.settings-modal { 
    flex: 1; 
    overflow-y: auto; 
    padding: 12px 16px; 
}

/* 每一个设置卡片 */
.setting-card { 
    border: 1px solid var(--color-border); border-radius: 2px; margin-bottom: 8px; 
    padding: 0; overflow: hidden; 
}

.section-header {
    display: flex; justify-content: space-between; align-items: center;
    font-weight: 600; user-select: none;
    transition: background-color 0.1s; padding: 14px 12px;     
}
.section-header:hover { background-color: var(--bg-hover); }

#apiArea, #promptSettingsArea, #taskArea { padding: 12px; display: flex; flex-direction: column; }

/* 通用标签样式 */
.settings-modal label { 
    display: block; margin-top: 10px; margin-bottom: 4px; 
    font-weight: 600; color: var(--color-text-sub); font-size: 11px; 
}

/* 列表与配置项样式 */
.list-scrollable {
    max-height: 140px; overflow-y: auto;
    border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    margin-bottom: 8px; background-color: #fff;
}

.profile-item {
    padding: 10px; border-bottom: 1px solid #f0f0f0; cursor: pointer;
    display: flex; justify-content: space-between; align-items: center; font-size: 13px;
}
.profile-item:hover { background-color: var(--bg-hover); }

.profile-item.active {
    background-color: var(--bg-selected); color: var(--color-primary);
    border-left: 3px solid var(--color-primary); padding-left: 7px; font-weight: 600;
}

/* 当前使用中状态：背景变绿，文字加粗 */
.profile-item.current { 
    background-color: var(--bg-current); 
    color: var(--color-success); 
    font-weight: 600; 
}

/* --------------------------------------------------------------------------
   [核心修复] Profile Form Component Context (解决输入框宽度不一致的根本原因)
   -------------------------------------------------------------------------- */
/* 1. 定义表单容器为 Flex 列布局，强制子元素拉伸 */
#profileForm {
    display: flex;        
    flex-direction: column; 
    width: 100%;
    /* Flex 容器默认 align-items: stretch，这会强制 Input 填满宽度 */
}

/* 2. 强制覆盖所有输入框样式 (Text & Password) */
#profileForm input {
    display: block !important;       /* 覆盖 inline-block 默认值 */
    width: 100% !important;          /* 强制 100% 宽度 */
    box-sizing: border-box !important; /* 确保 padding 不撑破容器 */
    
    margin-bottom: 12px;
    height: 32px;                    /* 固定高度，保证整齐 */
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
}
/* [新增] 取消选中时的蓝色高亮，改为深灰色 */
#profileForm input:focus {
    border-color: #a1a1a1 !important;  /* 覆盖全局的蓝色，改为深灰 */
    outline: none !important;          /* 确保移除浏览器默认的光圈 */
    box-shadow: none !important;       /* 移除可能存在的阴影 */
}

/* 3. 表单专用标签样式 */
#profileForm label {
    font-weight: 600;
    color: var(--color-text-sub);
    margin-top: 8px;
    margin-bottom: 4px;
}
/* -------------------------------------------------------------------------- */

/* 固定页脚区：位于 overlay 最底部，不随内容滚动 */
.settings-footer {
    flex-shrink: 0;
    padding: 8px 16px 16px 16px; 
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 日志按钮行：紧贴下方虚线 */
.footer-btn-row {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    margin-bottom: 6px; 
}

.footer-btn-row .btn-ghost {
    color: #999;
    font-size: 10px;
    padding: 0;
}

/* 法律链接行 */
.settings-footer-links {
    width: 100%; 
    padding-top: 10px;
    margin-top: 0;
    border-top: 1px dashed var(--color-border); 
    text-align: center;
    font-size: 11px;
    color: var(--color-text-sub);
}

.settings-footer-links a {
    color: var(--color-text-sub);
    text-decoration: none;
    padding: 4px 8px;
}

.settings-footer-links a:hover {
    color: var(--color-primary);
    text-decoration: underline;
}

.settings-footer-links .separator {
    color: var(--color-border);
    margin: 0 2px;
}

/* 设置内的反馈文字 (测试成功/失败) */
.api-feedback {
    font-size: 11px; margin-top: 4px;
    text-align: right; width: 100%; align-self: stretch;
    min-height: 16px;
    display: flex; 
    align-items: center; 
    justify-content: flex-end; 
    gap: 4px;
}
.api-success { color: var(--color-success); }
.api-error { color: var(--color-danger); }
.api-feedback svg { fill: currentColor; display: inline-block; }
/* ==========================================================================
   7. Utilities & Status Bar
   ========================================================================== */
#status, .status-bar-slim {
    font-size: 10px; color: #999;
    width: 100%; height: 16px; margin-top: -2px;
    display: flex; align-items: center; justify-content: flex-end; 
    overflow: hidden;
}
#status.api-error, .status-bar-slim.api-error { color: var(--color-danger); }
#status.api-success, .status-bar-slim.api-success { color: var(--color-success); }

.flex { display: flex; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-1 { gap: 4px; }
.hidden { display: none !important; }

/* 强制禁用状态 (Watchdog/Loading时使用) */
.force-disabled {
    background-color: #f0f0f0 !important; color: #a6a6a6 !important;
    border-color: #e1dfdd !important; cursor: wait !important;
    pointer-events: none !important; box-shadow: none !important;
    transform: none !important;
}

/* [核心] 防闪烁斗篷：初始完全透明 */
body.cloak {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-in;
}
