/* ROOT VARIABLES */
:root {
    /* Colors - White Theme */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #f1f3f4;
    --bg-hover: #e8eaed;
    --bg-active: #e3e5e8;
    
    /* Border colors */
    --border-light: #e5e7eb;
    --border-medium: #d1d5db;
    --border-strong: #9ca3af;
    
    /* Text colors */
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --text-tertiary: #6b7280;
    --text-placeholder: #9ca3af;
    
    /* Accent colors */
    --accent-primary: #4f46e5;
    --accent-primary-hover: #4338ca;
    --accent-secondary: #7c3aed;
    --accent-light: #eef2ff;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.3);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 20px;
    --space-2xl: 24px;
    --space-3xl: 32px;

    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-half: 50%;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
}

:root[data-theme="dark"] {

  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --bg-tertiary: #374151;
  --bg-hover: #4b5563;
  --bg-active: #6b7280;

  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-tertiary: #9ca3af;
  --text-placeholder: #6b7280;

  --border-light: #374151;
  --border-medium: #4b5563;
  --border-strong: #6b7280;

  --accent-primary: #6366f1;
  --accent-primary-hover: #818cf8;
  --accent-secondary: #a78bfa;
  --accent-light: #312e81;

  --shadow-glow: 0 0 20px rgba(99,102,241,0.35);

}


:root[data-theme="claude"] {

  --bg-primary: #faf7f2;
  --bg-secondary: #f4efe6;
  --bg-tertiary: #ede6d8;
  --bg-hover: #e5dccb;
  --bg-active: #ddd2bc;

  --text-primary: #3b2f2f;
  --text-secondary: #5c4a3a;
  --text-tertiary: #7a6856;
  --text-placeholder: #9a8a7a;

  --border-light: #e3d9c7;
  --border-medium: #d6c9b3;
  --border-strong: #c7b89d;

  --accent-primary: #b7791f;
  --accent-primary-hover: #975a16;
  --accent-secondary: #d69e2e;
  --accent-light: #fff8e6;

  --shadow-glow: 0 0 20px rgba(183,121,31,0.25);

}


/* RESET */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}


/* LAYOUT */
.app {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}


/* SIDEBAR */
.sidebar {
    width: 280px;
    height: 100%;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform var(--transition-normal);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border-light);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.logo-text {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-close {
    display: none;
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.sidebar-close:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.new-chat-btn {
    margin: var(--space-lg) var(--space-xl);
    padding: var(--space-md) var(--space-lg);
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    color: white;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.new-chat-btn:active {
    transform: translateY(0);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--space-lg);
}

.chat-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: var(--space-xs);
    position: relative;
}

.chat-item:hover {
    background-color: var(--bg-tertiary);
    transform: translateX(4px);  /* 悬停时轻微右移 */
}

.chat-item.active {
    background-color: var(--accent-light);
    border-left: 3px solid var(--accent-primary);
}

.chat-item-icon {
    width: 32px;
    height: 32px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-tertiary);
}

.chat-item.active .chat-item-icon {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.chat-item-content {
    flex: 1;
    min-width: 0;
}

.chat-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.chat-item-menu {
    opacity: 0;
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}

.chat-item:hover .chat-item-menu {
    opacity: 1;
}

.chat-item-menu:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-light);
    text-align: center;
}

.sidebar-footer span {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 40;
}

.footer-row{
    display:flex;
    align-items:center;
    justify-content:space-between;
}

.logout-btn{
    display:flex;
    align-items:center;
    gap: var(--space-xs);
    padding:var(--space-xs) var(--space-sm);
    border-radius:var(--radius-md);
    font-size:12px;
    color:var(--text-tertiary);
    transition:all var(--transition-fast);
}

.logout-btn:hover{
    background:var(--bg-hover);
    color:var(--text-primary);
}

/* Theme Switcher */
.theme-switcher {
  position: relative;
  display: flex;
  width: calc(100% - 32px);   /* 和 sidebar 内边距对齐 */
  margin: 12px 16px;
  height: 30px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  overflow: hidden;
}

/* 按钮 */
.theme-switcher button {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.theme-switcher button:hover {
  color: var(--text-primary);
}

/* 滑块 */
.theme-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(33.333% - 6px);
  height: 23px;
  background: var(--bg-primary);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-normal);
}

/* 主题位置 */
.theme-switcher[data-theme="light"] .theme-slider {
  transform: translateX(0);
}

.theme-switcher[data-theme="dark"] .theme-slider {
  transform: translateX(110%);
}

.theme-switcher[data-theme="claude"] .theme-slider {
  transform: translateX(220%);
}

/* Main Content */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-primary);
}

/* Mobile Header */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
}

.menu-btn {
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.menu-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.mobile-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.mobile-spacer {
    width: 36px;
}


/* CHAT AREA */
.chat-output {
    flex: 1;
    flex-direction: column;
    gap: var(--space-lg);
    overflow-y: auto;        /* 可滚动 */
    padding: var(--space-lg);
}

.chat-output::-webkit-scrollbar {
    width: 6px;
}

.chat-output::-webkit-scrollbar-track {
    background: transparent;
}

.chat-output::-webkit-scrollbar-thumb {
    background-color: var(--border-medium);
    border-radius: var(--radius-full);
}

.chat-output::-webkit-scrollbar-thumb:hover {
    background-color: var(--border-strong);
}

.messages-container {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.message {
    display: flex;
    gap: var(--space-lg);
    animation: messageEnter 0.3s ease forwards;
}

@keyframes messageEnter {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-avatar.user {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    color: white;
}

.message-avatar.assistant {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    color: var(--accent-primary);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.message-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.message-bubble {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: var(--space-lg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05),0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-bubble.user {
    color: var(--text-primary);
    font-size: 0.8375rem;
    line-height: 1.4;
    word-wrap: break-word;  /* 确保长单词也能换行 */
}

/* 最终回答气泡包装器，保持与步骤块一致的上下间距 */
.final-step-wrapper {
    margin-top: var(--space-lg);
    padding: var(--space-lg) var(--space-xl);
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow:0 6px 18px rgba(20,30,60,0.06);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 0.8375rem;
}

.final-step-wrapper::before {
    display: block;
    font-size: 0.8375rem;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: var(--space-md);
}

.final-placeholder {
    opacity: 0.6;
    font-style: italic;
}


/* TIMELINE */
.timeline-row {
    display: flex;
    align-items: flex-start;
    font-size: 13px;
    user-select: none;
    opacity: 0.85;
    margin-bottom: var(--space-xs);
    margin-left: var(--space-sm);
}

.timeline-tree {
    position: relative;
    display: flex;
    justify-content: center;
}

.timeline-row:not(:last-child) .timeline-tree::after {
    content: "";
    position: absolute;
    top: 16px;
    width: 2px;
    height: calc(100% - 4px);
    background: #e5e7eb;
}

.tree-branch {
    display: block;
    width: 10px;
    height: 10px;
    border-radius: var(--radius-half);
    background: #d1d5db;
    margin-top: 6px;
}

.tree-branch.running {
    background: #f59e0b;
}

.tree-branch.done {
    background: #10b981;
}

.tree-branch.error {
    background: #ef4444;
}

.timeline-main {
    flex: 1;
    padding-bottom: var(--space-xs);
    margin-left: var(--space-xs);
}

.timeline-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.timeline-label-main {
    font-weight: 500;
}

.timeline-label-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: auto;
}

.timeline-label-status.success {
    color: var(--accent-secondary);
    font-size: 12px;
}

.timeline-label-status.error {
    color: var(--accent-primary);
    font-size: 12px;
}

.timeline-label-summary {
    font-size: 11px;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 6px;
}

.timeline-detail {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all var(--transition-normal);
}

.timeline-detail.open {
    max-height: 400px;
    opacity: 1;
    margin-top: var(--space-xs);
}

.timeline-detail pre {
    background: var(--bg-secondary);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
}

@keyframes spin {
    from { transform:rotate(0deg); }
    to { transform:rotate(360deg); }
}

.timeline-row.running .timeline-label {
    color: var(--text-primary);
    font-weight: 500;
}

.timeline-row.running .tree-branch {
    animation: branchPulse 1.2s ease infinite;
}

@keyframes branchPulse {
    0%,100% { opacity:.4 }
    50% { opacity:1 }
}

/* ===== Safe Tool Styling ===== */

.tool-box {
    margin-top: 6px;
    padding: 10px;
    border-radius: 8px;
    background: #f9fafb;
    border: 1px solid var(--border-light);
}

.tool-title {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tool-block {
    margin-top: 6px;
}

.tool-block-title {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-tertiary);
}

.tool-box pre {
    background: var(--bg-tertiary);
    padding: 8px;
    border-radius: 6px;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

.tool-status.success {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--bg-hover);
    color: #166534;
}

.tool-status.error {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: #991b1b;
}

/* Agent Status Bar */
.agent-status-bar {
    width: 100%;
    box-sizing: border-box;
    padding: var(--space-sm) var(--space-sm);
    margin-bottom: var(--space-sm);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    border: 1px solid #ccc;
    border-radius: var(--radius-sm);
}

#agent-status-dot {
    width: 12px;
    height: 12px;
    border-radius: var(--radius-half);
    background-color: #888; /* 默认灰色 */
}

#agent-status-text {
    font-size: 12px;
    color: #333;
}

/* INPUT AREA */
.input-area {
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    padding: var(--space-lg) var(--space-2xl) var(--space-lg);
}

.input-container {
    max-width: 900px;
    margin: 0 auto;
}

.input-wrapper {
    position: relative;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl);
    padding: var(--space-lg);
    transition: all var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1),0 4px 12px rgba(79, 70, 229, 0.15);
}

.chat-input {
    width: 100%;
    min-height: 60px;
    max-height: 200px;
    background: transparent;
    border: none;
    outline: none;
    font-size: 0.8375rem;
    line-height: 1.6;
    color: var(--text-primary);
    resize: none;
    font-family: inherit;
}

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

.input-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: nowrap;          /* 强制不换行 */
    margin-top: var(--space-sm); /* 微调间距，可与边框搭配 */
    border-top: 1px solid var(--border-light); /* 添加分隔线 */
    padding-top: var(--space-sm);
}

.input-actions .send-btn {
    margin-left: auto;
    flex-shrink: 0;
}

.input-btn {
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}

.input-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-secondary);
}

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-half);
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.send-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

.send-btn svg {
    width: 16px;
    height: 16px;
}

.send-btn:active {
    transform: translateY(0);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.input-hint {
    text-align: center;
    margin-top: var(--space-md);
}

.input-hint span {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}


/* UTILITIES */
.hidden {
    display: none !important;
}

#scrollBtn {
    position: absolute;
    right: 24px;
    bottom: 110px;

    z-index: 20;

    padding: 6px 12px;
    border-radius: 20px;
    border: none;

    background: var(--text-primary);
    color: white;
    cursor: pointer;

    opacity: 0;
    transition: opacity 0.2s ease;
    overflow: visible;
}

/* ExecutionBlocks */
.execution-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-lg);
    font-size: 0.8375rem;
    transition: all 0.25s ease;
}

.execution-header {
    padding: var(--space-md) var(--space-lg);
    cursor: pointer;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s ease;
}

.execution-header:hover {
    background: var(--bg-hover);
}

.execution-header.loading {
    color: #b45309;
}

.execution-body {
    border-top: 1px solid var(--border-light);
    max-height: 350px;
    overflow-y: auto;
    transition: all 0.25s ease;
}

.execution-body.collapsed {
    max-height: 0;
    overflow: hidden;
}

.execution-title {
    font-weight: 500;
}

.execution-panel .execution-title {
    display: flex;
    align-items: center;
    gap: 6px;
}

.execution-task-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.execution-task-title {
    font-weight: 600;
    font-size: 14px;
}

.execution-task-meta {
    font-size: 12px;
    display: flex;
    gap: 12px;
    color: var(--text-tertiary);
}

.execution-task-status.running {
    color: #b45309;
}

.execution-task-status.completed {
    color: #059669;
}

.execution-task-status.error {
    color: #dc2626;
}

.arrow {
    transition: transform 0.2s ease;
}

.arrow.rotated {
    transform: rotate(-90deg);
}


/* RESPONSIVE */

@media (max-width: 768px) {
    :root {
        --space-xs: 4px;
        --space-sm: 6px;
        --space-md: 8px;
        --space-lg: 10px;
        --space-xl: 12px;
        --space-2xl: 16px;
        --space-3xl: 20px;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 50;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: flex;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .mobile-header {
        display: flex;
    }

    .chat-output {
        padding: var(--space-lg);
    }

    .messages-container {
        gap: var(--space-lg);
    }

    .message {
        gap: var(--space-md);
    }

    .message-avatar {
        width: 32px;
        height: 32px;
    }

    .input-area {
        padding: var(--space-md);
    }

    .input-wrapper {
        padding: var(--space-md);
    }

    .chat-input {
        min-height: 50px;
        font-size: 0.9375rem;
    }

    .selector-btn {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.8125rem;
    }

    .send-btn {
        padding: var(--space-sm) var(--space-lg);
    }

    .send-btn span {
        display: none;
    }
}