/* === 全局变量 === */
:root {
    /* 亮色模式 */
    --light-bg: #ffffff;
    --light-sidebar-bg: #f5f7f9;
    --light-text: #333333;
    --light-accent: #4285f4;
    --light-accent-hover: #2a75f3;
    --light-border: #e0e0e0;
    --light-code-bg: #f6f8fa;
    --light-hover: #e0e7ff;
    --light-active: #d2e3fc;
    --light-header: #ffffff;
    --light-shadow: rgba(0, 0, 0, 0.1);
    
    /* 暗色模式 */
    --dark-bg: #1e1e1e;
    --dark-sidebar-bg: #252526;
    --dark-text: #e0e0e0;
    --dark-accent: #4285f4;
    --dark-accent-hover: #5a95ff;
    --dark-border: #3c3c3c;
    --dark-code-bg: #2d2d2d;
    --dark-hover: #383b42;
    --dark-active: #3a3d45;
    --dark-header: #252526;
    --dark-shadow: rgba(0, 0, 0, 0.3);
    
    /* 通用变量 */
    --sidebar-width: 300px;
    --header-height: 70px;
    --transition-speed: 0.3s;
}

/* === 基本样式 === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

body.light-mode {
    background-color: var(--light-bg);
    color: var(--light-text);
}

body.dark-mode {
    background-color: var(--dark-bg);
    color: var(--dark-text);
}

/* === 主题过渡动画 === */
.theme-transition {
    transition: background-color 0.5s cubic-bezier(0.4, 0, 0.2, 1), 
                color 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-transition * {
    transition: background-color 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                color 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === 头部样式 === */
#main-header {
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 100;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

.light-mode #main-header {
    background-color: var(--light-header);
    border-bottom: 1px solid var(--light-border);
}

.dark-mode #main-header {
    background-color: var(--dark-header);
    border-bottom: 1px solid var(--dark-border);
}

.brand {
    display: flex;
    align-items: center;
}

#logo {
    width: 40px;
    height: 40px;
    margin-right: 15px;
    object-fit: contain;
    transition: transform 0.3s ease;
}

#logo:hover {
    transform: scale(1.1) rotate(5deg);
}

.titles {
    display: flex;
    flex-direction: column;
}

.titles h1 {
    font-size: 1.5rem;
    margin: 0;
}

.titles h2 {
    font-size: 0.9rem;
    font-weight: normal;
    margin: 0;
    opacity: 0.8;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.official-link {
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
    padding: 8px 12px;
    border-radius: 4px;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    overflow: hidden;
}

.light-mode .official-link {
    color: var(--light-accent);
    background-color: rgba(66, 133, 244, 0.1);
}

.dark-mode .official-link {
    color: var(--dark-accent);
    background-color: rgba(66, 133, 244, 0.2);
}

.official-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.official-link:after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: -100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: 0.4s;
}

.official-link:hover:after {
    left: 100%;
}

#theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.light-mode #theme-toggle {
    color: var(--light-text);
    background-color: var(--light-sidebar-bg);
}

.dark-mode #theme-toggle {
    color: var(--dark-text);
    background-color: var(--dark-sidebar-bg);
}

.theme-toggle-animate {
    transition: transform 0.3s ease, background-color 0.3s ease;
}

.theme-toggle-animate:hover {
    transform: rotate(30deg);
}

.theme-toggle-spin {
    animation: spin-toggle 0.6s ease;
}

@keyframes spin-toggle {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* === 主容器 === */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* === 侧边栏样式 === */
#sidebar {
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
    position: relative;
}

.light-mode #sidebar {
    background-color: var(--light-sidebar-bg);
    border-right: 1px solid var(--light-border);
}

.dark-mode #sidebar {
    background-color: var(--dark-sidebar-bg);
    border-right: 1px solid var(--dark-border);
}

.search-container {
    padding: 20px;
    position: relative;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 10px;
    font-size: 14px;
    opacity: 0.6;
    transition: opacity 0.3s;
}

#search-box:focus + .search-icon {
    opacity: 1;
    color: var(--light-accent);
}

.dark-mode #search-box:focus + .search-icon {
    color: var(--dark-accent);
}

#search-box {
    width: 100%;
    padding: 10px 36px;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.light-mode #search-box {
    border: 1px solid var(--light-border);
    background-color: var(--light-bg);
    color: var(--light-text);
}

.dark-mode #search-box {
    border: 1px solid var(--dark-border);
    background-color: var(--dark-bg);
    color: var(--dark-text);
}

#search-box:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.3);
    transform: translateY(-1px);
}

.clear-search {
    position: absolute;
    right: 10px;
    font-size: 14px;
    opacity: 0;
    cursor: pointer;
    transition: opacity 0.3s, transform 0.2s;
}

.clear-search.visible {
    opacity: 0.6;
}

.clear-search:hover {
    opacity: 1;
    transform: scale(1.2);
}

#search-suggestions {
    position: absolute;
    left: 20px;
    right: 20px;
    background-color: white;
    border-radius: 6px;
    max-height: 350px;
    overflow-y: auto;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: top center;
}

.light-mode #search-suggestions {
    background-color: var(--light-bg);
    border: 1px solid var(--light-border);
}

.dark-mode #search-suggestions {
    background-color: var(--dark-bg);
    border: 1px solid var(--dark-border);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

#search-suggestions.hidden {
    opacity: 0;
    transform: scaleY(0.8);
    pointer-events: none;
}

.suggestion-item {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s, transform 0.2s;
}

.light-mode .suggestion-item {
    border-bottom: 1px solid var(--light-border);
}

.dark-mode .suggestion-item {
    border-bottom: 1px solid var(--dark-border);
}

.suggestion-item:last-child {
    border-bottom: none;
    border-radius: 0 0 6px 6px;
}

.suggestion-item:first-child {
    border-radius: 6px 6px 0 0;
}

.light-mode .suggestion-item:hover {
    background-color: var(--light-hover);
    transform: translateX(2px);
}

.dark-mode .suggestion-item:hover {
    background-color: var(--dark-hover);
    transform: translateX(2px);
}

.suggestion-animate {
    animation: slideInFromTop 0.3s ease forwards;
    opacity: 0;
}

.suggestion-name {
    font-weight: bold;
}

.suggestion-description {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 加载更多按钮 */
.load-more-button {
    padding: 12px 15px;
    background-color: rgba(66, 133, 244, 0.1);
    color: var(--light-accent);
    cursor: pointer;
    text-align: center;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
    border-radius: 0 0 6px 6px;
}

.dark-mode .load-more-button {
    background-color: rgba(66, 133, 244, 0.2);
    color: var(--dark-accent);
}

.load-more-button:hover {
    background-color: rgba(66, 133, 244, 0.2);
    transform: translateY(-2px);
}

.dark-mode .load-more-button:hover {
    background-color: rgba(66, 133, 244, 0.3);
}

.load-more-button i {
    animation: pulse 1.5s infinite;
}

/* 搜索无结果 */
.no-results {
    text-align: center;
    font-style: italic;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.load-all-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 0.9rem;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    background-color: rgba(66, 133, 244, 0.1);
    color: var(--light-accent);
    font-style: normal;
    font-weight: bold;
    margin-top: 5px;
    transition: all 0.3s;
}

.dark-mode .load-all-button {
    background-color: rgba(66, 133, 244, 0.2);
    color: var(--dark-accent);
}

.load-all-button:hover {
    background-color: rgba(66, 133, 244, 0.2);
    transform: translateY(-2px);
}

.dark-mode .load-all-button:hover {
    background-color: rgba(66, 133, 244, 0.3);
}

/* 搜索加载中 */
.search-loading {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.spinner-small {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(66, 133, 244, 0.2);
    border-top: 3px solid var(--light-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.dark-mode .spinner-small {
    border-top: 3px solid var(--dark-accent);
}

/* 搜索结果计数 */
.results-count {
    padding: 8px 15px;
    background-color: rgba(66, 133, 244, 0.05);
    font-size: 0.9rem;
    text-align: center;
    border-bottom: 1px solid;
}

.light-mode .results-count {
    border-color: var(--light-border);
}

.dark-mode .results-count {
    border-color: var(--dark-border);
}

.results-count span {
    font-weight: bold;
    color: var(--light-accent);
}

.dark-mode .results-count span {
    color: var(--dark-accent);
}

/* 函数列表包装器 */
.function-list-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 0 0 20px 0;
}

#function-list {
    list-style-type: none;
}

#function-list li {
    padding: 10px 20px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.light-mode #function-list li:hover {
    background-color: var(--light-hover);
    transform: translateX(5px);
}

.dark-mode #function-list li:hover {
    background-color: var(--dark-hover);
    transform: translateX(5px);
}

.light-mode #function-list li.active {
    background-color: var(--light-active);
    border-left-color: var(--light-accent);
}

.dark-mode #function-list li.active {
    background-color: var(--dark-active);
    border-left-color: var(--dark-accent);
}

.function-item-animate {
    animation: slideInFromLeft 0.4s forwards;
    animation-fill-mode: both;
}

/* === 内容区样式 === */
#content-area {
    flex: 1;
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    padding: 30px 40px;
    transition: background-color var(--transition-speed);
}

.light-mode #content-area {
    background-color: var(--light-bg);
}

.dark-mode #content-area {
    background-color: var(--dark-bg);
}

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

.welcome-screen {
    text-align: center;
    padding: 60px 0;
    animation: fadeInScale 0.7s ease-out;
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 30px;
    color: var(--light-accent);
}

.dark-mode .welcome-icon {
    color: var(--dark-accent);
}

.bounce-animation {
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.function-title {
    font-size: 2.2rem;
    margin-bottom: 0.5em;
    color: var(--light-text);
    animation: slideInFromTop 0.5s ease-out;
}

.dark-mode .function-title {
    color: var(--dark-text);
}

/* 内容淡入淡出效果 */
.content-fade-in {
    animation: fadeInScale 0.5s ease-out forwards;
}

.content-fade-out {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s, transform 0.3s;
}

/* 函数文档样式 */
.function-section {
    margin-bottom: 30px;
}

.content-section-animate {
    animation: fadeIn 0.6s ease-out forwards;
    opacity: 0;
}

h2 {
    font-size: 1.5rem;
    margin: 1.5em 0 0.7em;
    padding-bottom: 8px;
    border-bottom: 1px solid;
    transition: border-color var(--transition-speed);
}

.light-mode h2 {
    color: #555;
    border-color: var(--light-border);
}

.dark-mode h2 {
    color: #ccc;
    border-color: var(--dark-border);
}

pre {
    margin: 15px 0;
    border-radius: 6px;
    overflow-x: auto;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.light-mode pre {
    background-color: var(--light-code-bg);
    border: 1px solid var(--light-border);
}

.dark-mode pre {
    background-color: var(--dark-code-bg);
    border: 1px solid var(--dark-border);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

code {
    font-family: 'Fira Code', 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

code.r {
    display: block;
    padding: 16px;
}

ul {
    padding-left: 20px;
    margin: 15px 0;
}

li {
    margin-bottom: 8px;
    line-height: 1.5;
}

.parameters li strong {
    color: #c7254e;
}

.dark-mode .parameters li strong {
    color: #ff7b93;
}

/* 错误状态样式 */
.error-content {
    text-align: center;
    padding: 40px 20px;
    animation: fadeInScale 0.5s ease-out;
}

.error-content i {
    font-size: 3.5rem;
    color: #f44336;
    margin-bottom: 20px;
}

.dark-mode .error-content i {
    color: #ff5252;
}

.pulse-error {
    animation: pulseError 2s infinite;
}

@keyframes pulseError {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

.retry-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background-color: var(--light-accent);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 20px;
    transition: all 0.3s;
}

.dark-mode .retry-button {
    background-color: var(--dark-accent);
}

.retry-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* 搜索结果中的高亮文本 */
mark {
    background-color: rgba(66, 133, 244, 0.2);
    color: inherit;
    padding: 0 3px;
    border-radius: 3px;
    font-weight: bold;
}

.dark-mode mark {
    background-color: rgba(66, 133, 244, 0.3);
}

/* === 加载状态 === */
#loading {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    transition: background-color var(--transition-speed);
}

.light-mode #loading {
    background: rgba(255, 255, 255, 0.8);
}

.dark-mode #loading {
    background: rgba(30, 30, 30, 0.8);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(66, 133, 244, 0.2);
    border-top: 5px solid var(--light-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

.dark-mode .spinner {
    border-top: 5px solid var(--dark-accent);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading p {
    font-size: 1.2rem;
    position: relative;
}

#loading.fade-in {
    animation: fadeIn 0.3s forwards;
}

#loading.fade-out {
    animation: fadeOut 0.3s forwards;
}

/* === 动画效果 === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes slideInFromLeft {
    from { transform: translateX(-30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideInFromTop {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeInScale {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* === 响应式设计 === */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
    }
    
    #sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
    }
    
    #content-area {
        padding: 20px;
    }
    
    .titles h1 {
        font-size: 1.2rem;
    }
    
    .titles h2 {
        font-size: 0.8rem;
    }
    
    .header-actions {
        gap: 10px;
    }
    
    #logo {
        width: 30px;
        height: 30px;
    }
}