/* 登录页 */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #11111b 0%, #1e1e2e 50%, #181825 100%);
}

.login-card {
    background: #181825;
    border: 1px solid #313244;
    border-radius: 12px;
    padding: 40px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.login-card h1 {
    font-size: 20px;
    color: #cba6f7;
    text-align: center;
    margin-bottom: 4px;
}

.login-card .subtitle {
    font-size: 12px;
    color: #6c7086;
    text-align: center;
    margin-bottom: 24px;
}

.login-card label {
    display: block;
    font-size: 11px;
    color: #a6adc8;
    margin-bottom: 4px;
}

.login-card input {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 16px;
    background: #1e1e2e;
    border: 1px solid #45475a;
    border-radius: 8px;
    color: #cdd6f4;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.login-card input:focus {
    border-color: #cba6f7;
}

.login-card button {
    width: 100%;
    padding: 10px;
    background: #cba6f7;
    color: #1e1e2e;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.login-card button:hover { background: #b4befe; }
.login-card button:disabled { background: #45475a; cursor: not-allowed; }

.login-card .error {
    color: #f38ba8;
    font-size: 11px;
    text-align: center;
    margin-top: 8px;
    min-height: 16px;
}

.login-card .footer {
    margin-top: 16px;
    font-size: 10px;
    color: #585b70;
    text-align: center;
}

/* 导航栏 */
.navbar {
    background: #181825;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #313244;
    flex-shrink: 0;
}

.navbar h1 { font-size: 14px; color: #cba6f7; }
.navbar .nav-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.navbar .nav-right span { font-size: 11px; color: #6c7086; }
.navbar button {
    padding: 4px 10px;
    background: #45475a;
    color: #cdd6f4;
    border: none;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
}
.navbar button:hover { background: #585b70; }
.navbar button.primary { background: #cba6f7; color: #1e1e2e; font-weight: bold; }
.navbar button.primary:hover { background: #b4befe; }

.nav-workspace-label {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    background: #1e1e2e;
    border: 1px solid #313244;
    border-radius: 5px;
    cursor: pointer;
    font-size: 11px;
    color: #89b4fa;
    transition: background 0.15s, border-color 0.15s;
    user-select: none;
}
.nav-workspace-label:hover { background: #25253a; border-color: #45475a; }
.nav-workspace-icon { font-size: 10px; line-height: 1; }
.nav-workspace-name { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-workspace-caret { font-size: 7px; color: #6c7086; margin-left: 2px; }
.nav-workspace-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #181825;
    border: 1px solid #313244;
    border-radius: 6px;
    min-width: 160px;
    max-width: 240px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    max-height: 240px;
    overflow-y: auto;
    padding: 3px;
}
.nav-workspace-header {
    padding: 4px 8px;
    font-size: 9px;
    color: #6c7086;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #313244;
    margin-bottom: 2px;
}
.nav-workspace-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    font-size: 11px;
    cursor: pointer;
    color: #cdd6f4;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-workspace-item:hover { background: #1e1e2e; color: #89b4fa; }
.nav-workspace-item.active { background: #1e1e2e; color: #a6e3a1; }
.nav-workspace-check { width: 12px; text-align: center; font-size: 10px; flex-shrink: 0; }
.nav-workspace-id { overflow: hidden; text-overflow: ellipsis; }
.nav-username { font-size: 11px; color: #6c7086; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 通用卡片 */
.card {
    background: #181825;
    border: 1px solid #313244;
    border-radius: 10px;
    padding: 16px;
}

.card h2 { font-size: 14px; color: #89b4fa; margin-bottom: 12px; }

/* 表格 */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th {
    text-align: left;
    padding: 8px;
    border-bottom: 1px solid #313244;
    color: #89b4fa;
    font-weight: normal;
}

td {
    padding: 6px 8px;
    border-bottom: 1px solid #1e1e2e;
    color: #cdd6f4;
}

tr:hover td { background: #1e1e2e; }

/* 状态标 */
.badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
}

.badge.ok { background: #a6e3a1; color: #1e1e2e; }
.badge.err { background: #f38ba8; color: #1e1e2e; }
.badge.warn { background: #f9e2af; color: #1e1e2e; }

/* 表单行 */
.form-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.form-row label {
    font-size: 11px;
    color: #a6adc8;
    display: block;
    margin-bottom: 2px;
}

.form-row input, .form-row select {
    padding: 6px 10px;
    background: #1e1e2e;
    border: 1px solid #45475a;
    border-radius: 6px;
    color: #cdd6f4;
    font-size: 12px;
    outline: none;
}

.form-row input:focus, .form-row select:focus { border-color: #cba6f7; }

/* 动作按钮 */
.action-btn {
    padding: 4px 10px;
    background: #45475a;
    color: #cdd6f4;
    border: none;
    border-radius: 4px;
    font-size: 10px;
    cursor: pointer;
}

.action-btn:hover { background: #585b70; }
.action-btn.primary { background: #89b4fa; color: #1e1e2e; font-weight: bold; }
.action-btn.danger { background: #f38ba8; color: #1e1e2e; }

/* Toast */
.toast {
    position: fixed; top: 10px; right: 10px; padding: 8px 16px;
    border-radius: 6px; font-size: 12px; z-index: 1000;
    animation: fadeIn 0.2s;
}

.toast.ok { background: #a6e3a1; color: #1e1e2e; }
.toast.err { background: #f38ba8; color: #1e1e2e; }

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

/* 页面容器 */
.page-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* 实例卡片 */
.instance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.instance-card {
    background: #1e1e2e;
    border: 1px solid #313244;
    border-radius: 8px;
    padding: 14px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.instance-card:hover { border-color: #89b4fa; }

.instance-card .name {
    font-size: 14px;
    color: #89b4fa;
    margin-bottom: 4px;
}

.instance-card .id {
    font-size: 10px;
    color: #6c7086;
    font-family: monospace;
}

.instance-card .meta {
    font-size: 10px;
    color: #a6adc8;
    margin-top: 6px;
}

.instance-card .status {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
}

.instance-card .status.online { background: #a6e3a1; }
.instance-card .status.offline { background: #6c7086; }

/* 下载中心 */
.download-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.download-card {
    background: #1e1e2e;
    border: 1px solid #313244;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.download-card .icon { font-size: 32px; margin-bottom: 8px; }

.download-card .name {
    font-size: 12px;
    color: #cdd6f4;
    margin-bottom: 4px;
}

.download-card .size {
    font-size: 10px;
    color: #6c7086;
    margin-bottom: 10px;
}

.download-card button {
    padding: 5px 16px;
    background: #89b4fa;
    color: #1e1e2e;
    border: none;
    border-radius: 6px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
}

.download-card button:hover { background: #b4befe; }

/* 工作区拖拽手柄 */
.ws-resize-handle {
    background: transparent;
    transition: background 0.15s;
}
.ws-resize-handle:hover { background: #313244; }

/* 水平拖拽手柄（底部布局） */
.ws-resize-handle-h {
    background: transparent;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ws-resize-handle-h:hover { background: #313244; }
.ws-resize-handle-h::before {
    content: '';
    width: 24px;
    height: 2px;
    background: #45475a;
    border-radius: 1px;
}
.ws-resize-handle-h:hover::before { background: #585b70; }

/* 面板全屏 */
.panel.fullscreen {
    position: fixed !important;
    inset: 0 !important;
    z-index: 99 !important;
    width: 100% !important;
    border-radius: 0 !important;
    border: none !important;
}

/* 右键菜单 */
.context-menu {
    background: #181825;
    border: 1px solid #313244;
    border-radius: 6px;
    padding: 4px 0;
    z-index: 100;
    min-width: 120px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.context-menu-item {
    padding: 4px 12px;
    font-size: 11px;
    cursor: pointer;
    color: #cdd6f4;
}
.context-menu-item:hover { background: #313244; }

/* ==================== 移动端响应式 ==================== */

@media (max-width: 768px) {
    /* 导航栏缩小 */
    .navbar { padding: 6px 8px; gap: 4px; flex-wrap: wrap; }
    .navbar h1 { font-size: 13px; }
    .navbar button { font-size: 10px; padding: 3px 8px; }

    /* 页面容器 */
    .page-container { padding: 6px; }

    /* 表格横滚 */
    table { font-size: 10px; }
    th, td { padding: 4px 6px; }

    /* 表单行堆叠 */
    .form-row { flex-direction: column; gap: 6px; }
    .form-row input, .form-row select { width: 100% !important; }

    /* 卡片 */
    .card { padding: 10px; border-radius: 6px; }

    /* 实例网格单列 */
    .instance-grid { grid-template-columns: 1fr; }

    /* 下载网格单列 */
    .download-grid { grid-template-columns: 1fr 1fr; }

    /* 登录卡 */
    .login-card { padding: 24px; width: 100%; max-width: 100%; }
}

/* ==================== workspace 移动端 ==================== */

/* 移动端 tab 切换栏（默认隐藏） */
.ws-mobile-tabs {
    display: none;
    flex-shrink: 0;
    background: #11111b;
    border-bottom: 1px solid #313244;
    padding: 0 4px;
}
.ws-mobile-tabs button {
    flex: 1;
    padding: 8px 4px;
    background: transparent;
    color: #6c7086;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 12px;
    cursor: pointer;
}
.ws-mobile-tabs button.active {
    color: #89b4fa;
    border-bottom-color: #89b4fa;
}

/* 虚拟键盘：桌面端隐藏 */
#wsVkb { display: none; }

@media (max-width: 768px) {
    /* 显示移动端 tab 栏 */
    .ws-mobile-tabs { display: flex; }

    /* 主区域纵排 */
    #wsMainArea {
        flex-direction: column !important;
        flex: 1 1 0 !important;
        min-height: 0 !important;
    }

    /* 所有面板：默认隐藏，激活时显示 */
    #wsFilePanel, #wsEditorPanel, #wsTermPanel {
        display: none !important;
        width: 100% !important;
        flex: 1 !important;
        min-width: auto !important;
        min-height: 0 !important;
        border-right: none !important;
        border-left: none !important;
    }
    #wsFilePanel.ws-mobile-active,
    #wsEditorPanel.ws-mobile-active,
    #wsTermPanel.ws-mobile-active {
        display: flex !important;
        flex: 1 1 0 !important;
        overflow: hidden !important;
    }

    /* 隐藏拖拽手柄 */
    .ws-resize-handle, .ws-resize-handle-h { display: none !important; }

    /* 终端面板在底部布局时 */
    #wsTermSideSlot { width: 100% !important; }
    #wsBottomRow { flex: 1 !important; min-height: 200px !important; }
    #wsTopRow { flex: 0 0 auto !important; }

    /* 编辑器面板：flex 填满 */
    #wsEditorPanel.ws-mobile-active {
        flex: 1 1 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
    #wsEditorPanel textarea { flex: 1 1 0 !important; }

    /* 编辑器行号缩小 */
    #wsLineGutter { min-width: 24px !important; font-size: 10px !important; padding: 4px 2px !important; }
    #wsCodeEditor { font-size: 11px !important; padding: 4px !important; }

    /* 状态栏 */
    #wsStatusBar { font-size: 9px !important; gap: 8px !important; padding: 2px 6px !important; }

    /* 文件面板：确保高度被正确分配 */
    #wsFilePanel.ws-mobile-active {
        flex: 1 1 0 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        min-height: 0 !important;
    }

    /* 文件列表占满剩余空间 */
    #wsFileList {
        flex: 1 1 0 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
    }

    /* 文件列表增大触摸区域 */
    .panel-body .entry { padding: 5px 6px; font-size: 12px; }

    /* 面板标题栏 */
    .panel-header { font-size: 11px; padding: 6px 8px; }

    /* 终端操作按钮缩小 */
    #wsTermPanel .btn-sm { font-size: 9px; padding: 2px 4px; }

    /* xterm 容器高度自适应 */
    #ws-xterm-container { min-height: 0; }

    /* ===== 虚拟键盘 (VKB) ===== */
    #wsVkb {
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
        background: #11111b;
        border-top: 1px solid #313244;
        padding: 4px 2px 6px;
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
    }
    #wsVkb .vkb-row {
        display: flex;
        gap: 3px;
        justify-content: center;
        padding: 2px 0;
    }
    #wsVkb .vkb-btn {
        min-width: 36px;
        height: 36px;
        font-size: 11px;
        font-family: monospace;
        background: #313244;
        color: #cdd6f4;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
    }
    #wsVkb .vkb-btn:active {
        background: #585b70;
    }
    #wsVkb .vkb-btn.active {
        background: #89b4fa;
        color: #1e1e2e;
    }
    #wsVkb .vkb-page {
        display: none;
    }
    #wsVkb .vkb-page.active {
        display: block;
    }
    #wsVkb .vkb-page-toggle {
        min-width: 50px;
        height: 26px;
        font-size: 10px;
        font-family: inherit;
        background: transparent;
        color: #6c7086;
        border: 1px solid #313244;
        border-radius: 3px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    #wsVkb .vkb-page-toggle.active {
        background: #313244;
        color: #cdd6f4;
        border-color: #585b70;
    }
    #wsVkb .vkb-page-row {
        margin-top: 2px;
        padding-top: 4px;
        border-top: 1px solid #1e1e2e;
    }
}
