@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary: #6366f1;       
    --primary-light: #eef2ff; 
    --primary-hover: #4f46e5;
    --bg-body: #f3f4f6;       
    --bg-sidebar: #ffffff;    
    --bg-card: #ffffff;
    --text-main: #1f2937;     
    --text-sub: #9ca3af;      
    --border: #f3f4f6;
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --radius-l: 16px;
    --radius-m: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

/* 登录页面专用样式 */
.login-wrapper { height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); position: relative; }
.login-card { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(20px); width: 90%; max-width: 400px; padding: 40px; border-radius: 20px; box-shadow: 0 15px 35px rgba(0,0,0,0.1); text-align: center; }
.login-logo { font-size: 3.5rem; margin-bottom: 10px; background: linear-gradient(to right, #6366f1, #8b5cf6); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; display: inline-block; }
.login-title { font-size: 1.5rem; font-weight: bold; margin-bottom: 5px; color: #333; }
.login-subtitle { color: #888; font-size: 0.9rem; margin-bottom: 30px; }
.login-form-group { margin-bottom: 20px; text-align: left; }
.login-label { display: block; margin-bottom: 8px; font-weight: 600; font-size: 0.9rem; color: #555; }
.login-input { width: 100%; padding: 14px; border: 2px solid #eee; border-radius: 10px; background: #f9f9f9; font-size: 1rem; transition: 0.3s; }
.login-input:focus { border-color: var(--primary); background: #fff; outline: none; }
.login-btn { width: 100%; padding: 14px; background: var(--primary); color: white; border: none; border-radius: 10px; font-size: 1rem; font-weight: bold; cursor: pointer; box-shadow: 0 5px 15px rgba(99, 102, 241, 0.3); transition: transform 0.2s; }
.login-btn:active { transform: scale(0.98); }

/* 主界面布局 */
.app-container { display: flex; height: 100vh; width: 100vw; }

.sidebar {
    width: 250px; background: var(--bg-sidebar); display: flex; flex-direction: column;
    border-right: 1px solid var(--border); z-index: 50; transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.brand { padding: 30px 24px 20px; display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 32px; height: 32px; background: linear-gradient(135deg, #6366f1, #8b5cf6); border-radius: 10px; color: white; font-weight: 800; font-size: 1.1rem; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3); }
.brand-text { font-size: 1.15rem; font-weight: 700; color: #111827; letter-spacing: -0.5px; }

#sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 12px; scrollbar-width: none; }
#sidebar-nav::-webkit-scrollbar { display: none; }

/* 分类标题 */
.nav-category { font-size: 0.7rem; color: var(--text-sub); margin: 24px 0 8px 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.nav-category:first-child { margin-top: 10px; }

/* 菜单项 */
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; margin-bottom: 4px;
    border-radius: var(--radius-m); cursor: pointer;
    transition: all 0.2s ease; color: #4b5563; font-weight: 500; font-size: 0.9rem;
    border: 1px solid transparent;
}

/* === ★★★ 修复：Emoji 保持原色，不加滤镜 ★★★ === */
.nav-icon-emoji {
    font-size: 1.2rem;
    width: 24px; text-align: center;
    /* 移除 grayscale 滤镜，让颜色始终显示 */
    transition: transform 0.2s ease;
}

.nav-item:hover { background-color: #f9fafb; color: #111827; }
.nav-item:hover .nav-icon-emoji { transform: scale(1.1); }

/* 选中状态 */
.nav-item.active { background-color: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 底部栏 */
.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); background: #ffffff; }
.logout-btn {
    width: 100%; padding: 10px; border: 1px solid #e5e7eb; background: white; color: #6b7280;
    border-radius: var(--radius-m); cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 0.9rem; font-weight: 500;
}
.logout-btn:hover { background: #fef2f2; border-color: #fee2e2; color: #ef4444; }

/* 内容区 */
.main-content { flex: 1; display: flex; flex-direction: column; background: var(--bg-body); position: relative; width: 100%; }
.top-bar {
    height: 64px; padding: 0 32px; display: flex; justify-content: space-between; align-items: center;
    background: rgba(255,255,255,0.8); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 40;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    gap: 16px;
}
.page-title { font-size: 1.25rem; font-weight: 700; color: #111827; flex: 1; }
.top-bar-right {
    display: flex; align-items: center; gap: 12px;
}

/* 搜索框 */
.search-wrapper {
    position: relative;
}
.search-input {
    width: 280px; padding: 8px 12px 8px 36px; border: 1px solid #e5e7eb; border-radius: var(--radius-m);
    font-size: 0.9rem; background: #f9fafb; transition: all 0.2s; color: #1f2937;
}
.search-input:focus {
    background: white; border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-light);
    width: 320px;
}
.search-input::placeholder {
    color: #9ca3af;
}

/* 完成度指示器 */
.completion-indicator {
    min-width: 60px; padding: 6px 12px; border-radius: var(--radius-m);
    background: linear-gradient(135deg, #10b981, #059669); color: white;
    font-size: 0.85rem; font-weight: 600; text-align: center;
    cursor: default; box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.save-btn {
    background: var(--primary); color: white; border: none; padding: 10px 24px; border-radius: var(--radius-m);
    font-weight: 600; font-size: 0.9rem; cursor: pointer; box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
    transition: all 0.2s; display: flex; align-items: center; gap: 6px;
}
.save-btn:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35); }
.save-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.content-area { flex: 1; overflow-y: auto; padding: 32px; max-width: 1000px; margin: 0 auto; width: 100%; }

/* 配置卡片 */
.config-group {
    background: var(--bg-card); border-radius: var(--radius-l); padding: 32px;
    box-shadow: var(--shadow-card); margin-bottom: 24px; display: none;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.config-group.active { display: block; }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.form-item { margin-bottom: 28px; }
.form-header { margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.form-label { font-weight: 600; font-size: 0.95rem; color: #374151; }
.required-tag { background: #fff1f2; color: #e11d48; font-size: 0.7rem; padding: 2px 8px; border-radius: 99px; font-weight: 700; border: 1px solid #ffe4e6; }
.form-desc { font-size: 0.85rem; color: #6b7280; margin-bottom: 10px; line-height: 1.5; }
.form-input {
    width: 100%; padding: 12px 16px; border: 1px solid #e5e7eb; border-radius: var(--radius-m);
    font-size: 0.95rem; background: #f9fafb; transition: all 0.2s; color: #1f2937;
}
.form-input:focus { background: white; border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-light); }

/* 卡片式配置项 - 关键词:目录ID */
.key-value-wrapper {
    display: flex; flex-direction: column; gap: 10px; margin-top: 8px;
}
.key-value-card-list {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 10px; align-items: start;
}
.key-value-card-list.single-column {
    grid-template-columns: 1fr;
}
.key-value-card {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    background: #f9fafb; border: 1px solid #e5e7eb; border-radius: var(--radius-m);
    transition: all 0.2s; min-width: 0;
}
.key-value-card:hover {
    border-color: #d1d5db; background: #f3f4f6;
}
.kv-key-input {
    flex: 1; min-width: 0; padding: 8px 12px; border: 1px solid #e5e7eb;
    border-radius: var(--radius-m); background: white; font-size: 0.9rem;
    transition: all 0.2s;
}
.kv-key-input:focus {
    border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-light);
}
.kv-separator {
    font-size: 1rem; font-weight: 600; color: #6b7280; user-select: none;
    flex-shrink: 0;
}
.kv-value-input {
    flex: 1; min-width: 0; padding: 8px 12px; border: 1px solid #e5e7eb;
    border-radius: var(--radius-m); background: white; font-size: 0.9rem;
    transition: all 0.2s;
}
.kv-value-input:focus {
    border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-light);
}
.kv-delete-btn {
    width: 28px; height: 28px; border: none; background: #fee2e2; color: #dc2626;
    border-radius: 50%; cursor: pointer; font-size: 1.3rem; line-height: 1;
    display: flex; align-items: center; justify-content: center; transition: all 0.2s;
    flex-shrink: 0;
}
.kv-delete-btn:hover {
    background: #fecaca; transform: scale(1.1);
}
.kv-add-btn {
    padding: 10px 16px; border: 2px dashed #d1d5db; background: transparent;
    color: var(--primary); border-radius: var(--radius-m); cursor: pointer;
    font-size: 0.9rem; font-weight: 600; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    width: fit-content; margin-top: 4px;
}
.kv-add-btn:hover {
    border-color: var(--primary); background: var(--primary-light);
}

/* 卡片式配置项 - 简单值列表（用 | 或逗号分隔） */
.value-list-wrapper {
    display: flex; flex-direction: column; gap: 10px; margin-top: 8px;
}
.value-list-card-list {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 10px; align-items: start;
}
.value-list-card {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    background: #f9fafb; border: 1px solid #e5e7eb; border-radius: var(--radius-m);
    transition: all 0.2s; min-width: 0;
}
.value-list-card:hover {
    border-color: #d1d5db; background: #f3f4f6;
}
.vl-input {
    flex: 1; min-width: 0; padding: 8px 12px; border: 1px solid #e5e7eb;
    border-radius: var(--radius-m); background: white; font-size: 0.9rem;
    transition: all 0.2s;
}
.vl-input:focus {
    border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-light);
}
.vl-delete-btn {
    width: 28px; height: 28px; border: none; background: #fee2e2; color: #dc2626;
    border-radius: 50%; cursor: pointer; font-size: 1.3rem; line-height: 1;
    display: flex; align-items: center; justify-content: center; transition: all 0.2s;
    flex-shrink: 0;
}
.vl-delete-btn:hover {
    background: #fecaca; transform: scale(1.1);
}
.vl-add-btn {
    padding: 10px 16px; border: 2px dashed #d1d5db; background: transparent;
    color: var(--primary); border-radius: var(--radius-m); cursor: pointer;
    font-size: 0.9rem; font-weight: 600; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    width: fit-content; margin-top: 4px;
}
.vl-add-btn:hover {
    border-color: var(--primary); background: var(--primary-light);
}

/* 开关控件 */
.switch-wrapper {
    display: flex; align-items: center; justify-content: space-between; padding: 14px 18px;
    background: #f9fafb; border: 1px solid #f3f4f6; border-radius: var(--radius-m); cursor: pointer; transition: border-color 0.2s;
}
.switch-wrapper:hover { border-color: #e5e7eb; background: #f3f4f6; }
.switch-label { font-size: 0.95rem; font-weight: 500; color: #4b5563; }
.switch-label.on { color: var(--primary); font-weight: 600; }
.switch-box { position: relative; width: 44px; height: 24px; }
.switch-box input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #d1d5db; border-radius: 34px; transition: .3s; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: .3s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }

/* 移动端 */
.menu-toggle { display: none; border: none; background: none; font-size: 1.5rem; color: #374151; padding: 4px; }
.overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); backdrop-filter: blur(3px); z-index: 45; opacity: 0; visibility: hidden; transition: 0.3s; }
.overlay.active { opacity: 1; visibility: visible; }
@media (max-width: 768px) {
    .sidebar { position: fixed; left: -250px; height: 100%; box-shadow: 0 0 20px rgba(0,0,0,0.1); }
    .sidebar.open { transform: translateX(250px); }
    .menu-toggle { display: block; }
    .top-bar { 
        padding: 8px 16px; 
        height: auto; 
        min-height: 56px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .page-title { 
        width: 100%; 
        order: 1;
        margin-bottom: 0;
    }
    .top-bar-right { 
        width: 100%; 
        order: 2;
        display: flex; 
        gap: 8px; 
        align-items: center;
        flex-wrap: nowrap;
    }
    .search-wrapper {
        flex: 1;
        min-width: 0;
    }
    .search-input { 
        width: 100%; 
        max-width: none; 
        padding: 8px 12px 8px 36px;
    }
    .search-input:focus { 
        width: 100%; 
    }
    .completion-indicator { 
        font-size: 0.75rem; 
        padding: 4px 8px;
        min-width: 50px;
        flex-shrink: 0;
    }
    .save-btn { 
        padding: 8px 16px;
        font-size: 0.85rem;
        flex-shrink: 0;
        white-space: nowrap;
    }
    .content-area { padding: 16px; }
    .config-group { padding: 20px; }
    /* 移动端卡片网格单列显示 */
    .key-value-card-list, .value-list-card-list {
        grid-template-columns: 1fr;
    }
}
/* 日志查看器样式 */
.log-viewer-container {
    background: #ffffff;
    border-radius: var(--radius-l);
    padding: 24px;
    box-shadow: var(--shadow-card);
}

.log-loading, .log-error {
    padding: 20px;
    text-align: center;
    color: var(--text-sub);
    font-size: 0.9rem;
}

.log-error {
    color: #dc2626;
}

.log-content {
    background: #1f2937;
    color: #e5e7eb;
    padding: 20px;
    border-radius: var(--radius-m);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    /* 优化移动端滚动体验 */
    -webkit-overflow-scrolling: touch;
    /* 自定义滚动条样式（WebKit浏览器） */
    scrollbar-width: thick; /* Firefox */
    scrollbar-color: #4b5563 #374151; /* Firefox */
}

/* WebKit浏览器（Chrome、Safari、Edge）滚动条样式 */
.log-content::-webkit-scrollbar {
    width: 12px; /* 滚动条宽度 */
    height: 12px; /* 水平滚动条高度 */
}

.log-content::-webkit-scrollbar-track {
    background: #374151; /* 滚动条轨道背景 */
    border-radius: 6px;
}

.log-content::-webkit-scrollbar-thumb {
    background: #6b7280; /* 滚动条滑块颜色 */
    border-radius: 6px;
    border: 2px solid #374151; /* 增加视觉边界 */
    min-height: 40px; /* 最小高度，便于拖动 */
}

.log-content::-webkit-scrollbar-thumb:hover {
    background: #9ca3af; /* 悬停时颜色 */
}

/* Toast */
.toast-container { position: fixed; top: 24px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2937; color: white; padding: 10px 24px; border-radius: 99px; font-size: 0.9rem; font-weight: 500; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); animation: fadeDown 0.3s; }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* SSH 终端容器 */
.ssh-terminal-container {
    background: #000000;
    padding: 10px;
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    height: 500px; /* 固定高度，或者根据需要调整 */
    position: relative;
}

/* 隐藏 xterm 的滚动条，使用容器的 */
.xterm-viewport {
    overflow-y: auto !important;
}

/* ====== SSH 头部美化 ====== */
.ssh-header {
    display: flex;
    justify-content: space-between; /* 左右对齐 */
    align-items: center; /* 垂直居中 */
    margin-bottom: 20px; /* 增加底部间距 */
    padding: 0 4px;
    flex-wrap: wrap; /* 手机端自动换行 */
    gap: 12px;
}

/* 左侧标题区域 - 修复对齐问题 */
.ssh-header-main {
    display: flex;
    align-items: center; /* 垂直居中核心代码 */
    gap: 10px;
}

.ssh-header-icon {
    font-size: 1.6rem;
    line-height: 1; /* 关键：强制行高为 1，消除上下间隙 */
    
    /* 额外技巧：让 Emoji 自身也居中，并微调位置 */
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* 微调：Emoji 视觉上通常偏高，往下压 1-2px 会更协调 */
    transform: translateY(2px); 
    
    /* 阴影增加立体感 */
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.1));
}

.ssh-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: #111827;
    letter-spacing: -0.5px;
    line-height: 1; /* 保持标题行高紧凑 */
    
    /* 渐变色文字效果（可选，不喜欢可以删掉 background 相关属性） */
    background: linear-gradient(135deg, #1f2937 0%, #4b5563 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* 右侧（或下方）的安全提示胶囊 */
.ssh-tip-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: #ecfdf5; /* 淡绿色背景 (安全感) */
    border: 1px solid #d1fae5;
    padding: 6px 12px;
    border-radius: 99px; /* 胶囊形状 */
    font-size: 0.8rem;
    color: #047857; /* 深绿色文字 */
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
    max-width: 100%;
}

.ssh-tip-icon {
    font-size: 1rem;
}

.ssh-tip-text b {
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-decoration-color: #10b981;
}

/* 移动端适配：变为垂直排列 */
@media (max-width: 600px) {
    .ssh-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .ssh-tip-box {
        width: 100%;
        border-radius: 8px; /* 手机上改圆角矩形 */
        justify-content: center;
    }
}

/* =========================================
   SSH 配置栏样式优化 (Flex 布局)
   ========================================= */
.ssh-config {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-card);
    padding: 20px;
    
    /* 改用 Flex 布局，自动换行，对齐底部 */
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end; /* 让按钮和输入框底部对齐 */
    
    margin-bottom: 16px;
}

.ssh-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1; /* 自动撑开宽度 */
    min-width: 140px; /* 防止太窄 */
}

/* 针对端口号输入框，让它窄一点，看起来更协调 */
.ssh-field:nth-child(2) {
    flex: 0.4;
    min-width: 80px;
}

.ssh-label {
    font-size: 13px;
    color: #4b5563;
    font-weight: 600;
    margin-left: 2px;
}

.ssh-input {
    width: 100%;
    height: 40px; /* 固定高度 */
    padding: 0 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    outline: none;
    font-size: 14px;
    font-family: 'Inter', monospace; /* 数字显示更好看 */
    transition: all 0.2s;
}

.ssh-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* 按钮样式优化 */
.ssh-save, .ssh-connect {
    height: 40px; /* 与输入框高度一致 */
    padding: 0 20px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 80px;
}

.ssh-save {
    background: #eff6ff;
    color: var(--primary);
    border: 1px solid transparent;
}
.ssh-save:hover {
    background: #dbeafe;
    border-color: #bfdbfe;
}

.ssh-connect {
    background: #10b981;
    color: #fff;
    box-shadow: 0 2px 5px rgba(16, 185, 129, 0.2);
}
.ssh-connect:hover {
    background: #059669;
    transform: translateY(-1px);
}
.ssh-connect:active {
    transform: translateY(0);
}
.ssh-connect:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 连接成功后的状态 */
.ssh-connect.connected {
    background: #ef4444; /* 变成红色断开按钮 */
    box-shadow: none;
}
.ssh-connect.connected:hover {
    background: #dc2626;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .ssh-config {
        flex-direction: column; /* 手机上垂直排列 */
        align-items: stretch;
        gap: 12px;
    }
    .ssh-field, .ssh-field:nth-child(2) {
        width: 100%;
        flex: none;
    }
    .ssh-save, .ssh-connect {
        width: 100%;
        margin-top: 4px;
    }
}