/* ── 全局重置 & 变量 ── */
:root {
    --bg-primary: #1a1b26;
    --bg-secondary: #24253a;
    --bg-tertiary: #2f3049;
    --bg-hover: #3b3d5c;
    --text-primary: #e0e0e8;
    --text-secondary: #9a9bb4;
    --text-muted: #6a6b82;
    --accent: #7aa2f7;
    --accent-hover: #89b4fa;
    --danger: #f7768e;
    --success: #9ece6a;
    --border: #3b3d5c;
    --shadow: rgba(0, 0, 0, 0.4);
    --radius: 8px;
    --radius-sm: 4px;
    --sidebar-width: 320px;
    --transition: 0.2s ease;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

button {
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    border: none;
    outline: none;
    transition: all var(--transition);
}

input, select, textarea {
    font-family: inherit;
    font-size: 13px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    outline: none;
    transition: border-color var(--transition);
    width: 100%;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
}

textarea {
    resize: vertical;
    min-height: 60px;
}

.hidden { display: none !important; }

/* ── 认证页面 ── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    background: var(--bg-primary);
}

.auth-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 380px;
    max-width: 90vw;
    text-align: center;
    box-shadow: 0 20px 60px var(--shadow);
}

.auth-icon {
    font-size: 48px;
    margin-bottom: 8px;
    opacity: 0.5;
}

.auth-box h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.auth-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    text-align: left;
}

.auth-form .form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.auth-form .error-msg {
    text-align: center;
    padding: 0;
}

.btn-full {
    width: 100%;
    padding: 10px;
    font-size: 14px;
}

.auth-switch {
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.auth-switch a:hover {
    color: var(--accent-hover);
}
/* ── 布局 ── */
#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ── 侧边栏 ── */
#sidebar {
    width: var(--sidebar-width, 320px);
        min-width: 80px;
        max-width: 600px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.sidebar-header h1 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
}

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

.sidebar-username {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
}

/* 极窄侧栏时隐藏文字 */
#sidebar.narrow .sidebar-username,
#sidebar.narrow #btn-new-connection {
    font-size: 0;
    width: auto;
    padding: 8px 10px;
}

#sidebar.narrow #btn-new-connection::before {
    content: '+';
    font-size: 16px;
    font-weight: bold;
}

#sidebar.narrow .sidebar-header h1 {
    font-size: 0;
}

#sidebar.narrow .section-header h2 {
    font-size: 0;
}

#sidebar.narrow .sidebar-footer-btns .btn-footer {
    font-size: 0;
    padding: 6px;
}

#sidebar.narrow .sidebar-footer-btns #btn-close-all::before {
    content: '✕';
    font-size: 14px;
}

#sidebar.narrow .sidebar-footer-btns #btn-logout::before {
    content: '⇥';
    font-size: 14px;
}
.btn-primary {
    background: var(--accent);
    color: var(--bg-primary);
    padding: 8px 16px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 13px;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-small {
    background: transparent;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 14px;
}

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

.btn-cancel {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: var(--radius);
}

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

/* ── 会话标签 ── */
.sidebar-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
}

.section-header h2 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 8px 12px;
}

.sidebar-footer-btns {
    display: flex;
    gap: 4px;
}

.btn-footer {
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    flex: 1;
    text-align: center;
    transition: all var(--transition);
}

.btn-footer:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    }
    
    #btn-close-all:hover {
        color: var(--accent);
    }
    
    #btn-logout:hover {
    color: var(--danger);
}
#session-tabs {
    overflow-y: auto;
    padding: 4px 8px;
    max-height: 50%;
}

.session-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
    font-size: 13px;
    color: var(--text-secondary);
}

.session-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.session-tab.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-left: 3px solid var(--accent);
    padding-left: 9px;
}

.session-tab .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
}

.session-tab .status-dot.connecting {
    background: #e0af68;
    animation: pulse 1s infinite;
}

.session-tab .status-dot.disconnected {
    background: var(--danger);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.session-tab .tab-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-tab .tab-close {
    background: none;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    padding: 0 4px;
    border-radius: 2px;
    opacity: 0.4;
        transition: opacity var(--transition), color var(--transition), background var(--transition);
}

.session-tab:hover .tab-close {
    opacity: 1;
}

.session-tab .tab-close:hover {
    color: var(--danger);
    background: rgba(247, 118, 142, 0.15);
}

.session-tab.active .tab-close {
    opacity: 0.7;
}
/* ── 连接历史 ── */
#connection-history {
    overflow-y: auto;
    flex: 1;
    padding: 4px 8px;
}

.empty-hint {
    color: var(--text-muted);
    font-size: 12px;
    padding: 12px;
    text-align: center;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.history-item:hover {
    background: var(--bg-hover);
}

.history-item .hi-info {
    flex: 1;
    overflow: hidden;
    display: flex;
        flex-direction: column;
        min-width: 0;
        gap: 2px;
}

.history-item .hi-primary {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

.history-item .hi-host {
    font-size: 11px;
    color: var(--text-secondary);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 1.2;
    }
    
    .history-item .hi-time {
        font-size: 10px;
    color: var(--text-muted);
    overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 1.2;
}

.history-item .hi-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--transition);
}

.history-item:hover .hi-actions {
    opacity: 1;
}

.history-item .hi-edit,
.history-item .hi-delete {
    background: none;
    color: var(--text-muted);
    font-size: 13px;
    padding: 2px 5px;
    border-radius: 2px;
    line-height: 1;
}

.history-item .hi-edit:hover {
    color: var(--accent);
    background: rgba(122, 162, 247, 0.15);
}

.history-item .hi-delete:hover {
    color: var(--danger);
    background: rgba(247, 118, 142, 0.15);
}

/* ── 侧栏拉伸手柄 ── */
.resize-handle {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background 0.15s;
    position: relative;
    z-index: 10;
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--accent);
}
/* ── 主内容区 ── */
#main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-width: 0;
}

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 16px;
}

.welcome-icon {
    font-size: 64px;
    opacity: 0.3;
}

.welcome h2 {
    font-size: 20px;
    color: var(--text-secondary);
}

.welcome p {
    font-size: 14px;
}

/* ── 终端 ── */
#terminal-container {
    height: 100%;
}

#terminals {
    height: 100%;
}

.terminal-wrapper {
    height: 100%;
    display: none;
}

.terminal-wrapper.active {
    display: block;
}

.terminal-wrapper .xterm {
    height: 100%;
    padding: 4px;
}

.terminal-wrapper .xterm-viewport {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-hover) transparent;
}

/* ── 对话框 ── */
.dialog-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.dialog {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 440px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px var(--shadow);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.dialog-close {
    background: none;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    padding: 0 4px;
}

.dialog-close:hover {
    color: var(--text-primary);
}

/* ── 快速粘贴 ── */
.quick-paste {
    padding: 12px 20px 4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.quick-paste-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.quick-paste-row {
    display: flex;
    gap: 6px;
}

.quick-paste-input {
    font-size: 12px;
    padding: 6px 10px;
    color: var(--text-secondary);
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
}

.quick-paste-input:focus {
    color: var(--text-primary);
}

.quick-paste-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0;
}

.quick-paste-divider::before,
.quick-paste-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.quick-paste-divider span {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
#connect-form {
    padding: 8px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.error-msg {
    color: var(--danger);
    font-size: 13px;
    padding: 0 20px 16px;
}

/* ── 连接状态栏 ── */
#connection-status {
    position: fixed;
    bottom: 16px;
    right: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-secondary);
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 100;
    display: none;
}

#connection-status.visible {
    display: block;
}

/* ── 滚动条 ── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
