:root,
[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface2: #111827;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --accent: #3b82f6;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #eab308;
    --terminal-bg: #0a0a0a;
    --input-bg: #0f172a;
    --shadow: rgba(0,0,0,.3);
}

[data-theme="light"] {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface2: #e2e8f0;
    --border: #cbd5e1;
    --text: #0f172a;
    --text-muted: #475569;
    --text-dim: #64748b;
    --accent: #2563eb;
    --green: #16a34a;
    --red: #dc2626;
    --yellow: #ca8a04;
    --terminal-bg: #fafafa;
    --input-bg: #f8fafc;
    --shadow: rgba(0,0,0,.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    display: flex;
    height: 100vh;
    transition: background .2s, color .2s;
}

.hidden { display: none !important; }

.sidebar {
    width: 220px;
    background: var(--surface2);
    padding: 24px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.logo {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 40px;
    color: var(--text);
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.sidebar a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
}

.sidebar a:hover,
.sidebar a.active {
    background: var(--surface);
    color: var(--text);
}

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
}

.sidebar-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-btn svg { width: 16px; height: 16px; }
.sidebar-btn:hover { color: var(--red); border-color: var(--red); }

.main {
    flex: 1;
    padding: 24px;
    overflow: auto;
    min-width: 0;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.topbar h1 { font-size: 24px; font-weight: 600; }

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

.toggle-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toggle-btn svg { width: 18px; height: 18px; }
.toggle-btn:hover { background: var(--surface2); color: var(--text); }
.toggle-btn.collapsed svg { transform: rotate(180deg); }

.add-btn {
    background: var(--accent);
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 14px;
}

.cards-section {
    overflow: hidden;
    transition: max-height .3s, opacity .3s, margin .3s;
    max-height: 400px;
    opacity: 1;
    margin-bottom: 24px;
}

.cards-section.collapsed {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
    pointer-events: none;
}

.server-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.empty-msg {
    color: var(--text-muted);
    grid-column: 1 / -1;
    padding: 16px;
    font-size: 14px;
}

.server-card {
    background: var(--surface);
    padding: 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    transition: border-color .2s, box-shadow .2s;
}

.server-card.selected { border-color: var(--accent); }
.server-card.connected { box-shadow: 0 0 0 1px var(--green); }
.server-card:hover { border-color: var(--text-dim); }

.card-body {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.server-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.server-header h3 {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-dim);
    flex-shrink: 0;
}

.status.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status.connected { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status.offline { background: var(--red); }
.status.checking { background: var(--yellow); animation: pulse 1s infinite; }

.status-text { font-size: 12px; color: var(--text-dim); }
.status-text.online { color: var(--green); }
.status-text.connected { color: var(--green); }
.status-text.offline { color: var(--red); }
.status-text.checking { color: var(--yellow); }

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

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-btn svg { width: 16px; height: 16px; }
.server-card.connected .terminal-btn { background: var(--red); }

.panel-row {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    min-height: 0;
}

.command-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    flex-shrink: 0;
    transition: width .25s;
    width: 320px;
    overflow: hidden;
}

.command-panel.collapsed {
    width: 56px;
    padding: 10px 6px;
}

.panel-body { padding: 20px; }

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.panel-header h2 { font-size: 16px; font-weight: 600; }

.panel-collapse-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.panel-vertical-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    width: 100%;
    padding: 4px 0 10px;
    margin-bottom: 6px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.panel-vertical-title span {
    display: block;
    line-height: 1;
}

.panel-vertical-title:hover {
    color: var(--text);
}

.panel-icons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 4px 0 8px;
}

.icon-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-dim);
}

.icon-status.online { background: var(--green); }
.icon-status.connected { background: var(--green); }
.icon-status.offline { background: var(--red); }
.icon-status.checking { background: var(--yellow); animation: pulse 1s infinite; }

.icon-indicator {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    border-radius: 6px;
}

.icon-indicator svg { width: 18px; height: 18px; }
.icon-indicator.active { color: var(--green); background: rgba(34,197,94,.15); }

.icon-indicator-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-indicator-btn svg { width: 16px; height: 16px; }
.icon-indicator-btn:hover { color: var(--text); }

.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.terminal-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    flex: 1 1 0;
    height: 420px;
    max-height: 70vh;
    min-width: 280px;
    min-height: 240px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    resize: both;
    overflow: hidden;
    position: relative;
}

.terminal-panel.collapsed {
    height: auto !important;
    max-height: none;
    min-height: unset;
    resize: none;
}

.terminal-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-shrink: 0;
    position: relative;
    z-index: 5;
    background: var(--surface);
}

.terminal-toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.terminal-toolbar-left h2 {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
}

.terminal-font-select {
    padding: 6px 10px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    max-width: 140px;
}

.terminal-toolbar-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.terminal-tool-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.terminal-tool-btn svg { width: 16px; height: 16px; }
.terminal-tool-btn:hover { color: var(--text); border-color: var(--text-dim); }

.terminal-tabs-bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    flex-shrink: 0;
    position: relative;
    z-index: 5;
    background: var(--surface);
}

.terminal-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    max-width: 160px;
}

.terminal-tab.active {
    border-color: var(--accent);
    color: var(--text);
    background: var(--surface);
}

.terminal-tab.connected .tab-dot {
    background: var(--green);
    box-shadow: 0 0 4px var(--green);
}

.terminal-tab.connecting .tab-dot {
    background: var(--yellow);
    animation: pulse 1s infinite;
}

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

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

.tab-close {
    font-size: 14px;
    line-height: 1;
    opacity: .6;
    padding: 0 2px;
}

.tab-close:hover { opacity: 1; color: var(--red); }

.terminal-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.terminal-container {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.terminal-pane {
    position: absolute;
    inset: 0;
    background: var(--terminal-bg);
    border-radius: 8px;
    padding: 6px;
    overflow: hidden;
}

.terminal-pane.hidden { display: none; }

.terminal-pane .xterm {
    height: 100% !important;
    width: 100% !important;
    max-height: 100%;
    overflow: hidden;
}

.terminal-pane .xterm-viewport {
    overflow-y: auto !important;
}

.terminal-pane .xterm-screen,
.terminal-pane .xterm-rows {
    font-family: inherit;
}

.terminal-collapsed-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 4px;
}

.terminal-collapsed-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.terminal-collapsed-count {
    font-size: 12px;
    color: var(--text-dim);
    flex: 1;
}

.field-label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.command-panel select,
.command-panel input[type="text"],
.modal-box input[type="text"],
.modal-box input[type="file"],
.modal-box input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    margin-bottom: 14px;
    font-size: 14px;
}

.server-details {
    background: var(--input-bg);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 14px;
    font-size: 13px;
}

.server-details p {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    color: var(--text-muted);
}

.server-details p:last-child { margin-bottom: 0; }
.server-details strong { color: var(--text); font-weight: 500; }

#detail-status.online { color: var(--green); }
#detail-status.connected { color: var(--green); }
#detail-status.offline { color: var(--red); }
#detail-status.checking { color: var(--yellow); }
#detail-status.unknown { color: var(--text-dim); }

.action-row { display: flex; gap: 8px; }

.btn-icon {
    flex: 1;
    height: 44px;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon svg { width: 18px; height: 18px; }
.btn-icon.btn-primary { background: var(--green); }
.btn-icon.btn-disconnect { background: var(--red); }
.btn-icon.btn-secondary { background: var(--border); color: var(--text); }
.btn-icon.btn-danger { background: #7f1d1d; }
.btn-icon:disabled { opacity: .4; cursor: not-allowed; }

.connected-hint {
    font-size: 12px;
    color: var(--yellow);
    margin-top: 10px;
    text-align: center;
}

.optional-tag { color: var(--text-dim); font-weight: normal; }

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow: auto;
}

.modal-wide { max-width: 620px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions button { flex: 1; }

.btn-primary, .btn-secondary {
    padding: 12px;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 14px;
}

.btn-primary { background: var(--green); }
.btn-secondary { background: var(--border); color: var(--text); }
.full-width { width: 100%; }

#env-content {
    background: var(--input-bg);
    padding: 14px;
    border-radius: 8px;
    font-family: Consolas, monospace;
    font-size: 13px;
    color: var(--green);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow: auto;
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    padding: 24px;
}

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px var(--shadow);
}

.login-box h1 {
    font-size: 26px;
    font-weight: 600;
    margin-bottom: 6px;
    text-align: center;
}

.login-sub {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 28px;
    text-align: center;
}

.login-box .field-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.login-box input[type="text"],
.login-box input[type="password"] {
    width: 100%;
    padding: 11px 14px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    margin-bottom: 16px;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

.login-box input[type="text"]:focus,
.login-box input[type="password"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .15);
}

.login-box input::placeholder {
    color: var(--text-dim);
}

.login-box .btn-primary {
    width: 100%;
    padding: 12px;
    margin-top: 4px;
    font-size: 15px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
}

.login-hint {
    color: var(--text-dim);
    font-size: 12px;
    margin-top: 20px;
    text-align: center;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.login-hint strong {
    color: var(--text-muted);
    font-weight: 500;
}

.login-error {
    color: var(--red);
    font-size: 13px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: rgba(239, 68, 68, .1);
    border-radius: 6px;
}
