* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --accent: #8b5cf6;
    --bg-dark: #0a0a1a;
    --bg-card: rgba(15, 15, 35, 0.85);
    --bg-panel: rgba(12, 12, 28, 0.9);
    --bg-input: rgba(255, 255, 255, 0.05);
    --bg-input-focus: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(99, 102, 241, 0.5);
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --success: #22c55e;
    --radius: 12px;
    --radius-sm: 8px;
}

html,
body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    overflow: hidden;
}

/* ─── Background Particles ──────────────────────────────── */
.bg-particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
}

.bg-particles::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 30%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 70% 70%, rgba(139, 92, 246, 0.10) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.05) 0%, transparent 70%);
    animation: bgFloat 20s ease-in-out infinite;
}

@keyframes bgFloat {

    0%,
    100% {
        transform: translate(0, 0) rotate(0deg);
    }

    25% {
        transform: translate(2%, -2%) rotate(1deg);
    }

    50% {
        transform: translate(-1%, 3%) rotate(-0.5deg);
    }

    75% {
        transform: translate(1.5%, -1%) rotate(0.5deg);
    }
}

.particle {
    position: absolute;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.3);
    animation: particleFloat linear infinite;
    pointer-events: none;
}

@keyframes particleFloat {
    0% {
        transform: translateY(100vh) scale(0);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        transform: translateY(-100vh) scale(1);
        opacity: 0;
    }
}

/* ─── Login Container (Two Column) ──────────────────────── */
.login-container {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    min-height: 100vh;
    padding: 20px;
}

/* ─── Saved Hosts Panel ─────────────────────────────────── */
.saved-hosts-panel {
    width: 280px;
    max-height: 560px;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
    animation: panelAppear 0.6s ease-out 0.15s both;
}

@keyframes panelAppear {
    0% {
        opacity: 0;
        transform: translateX(-20px) scale(0.95);
    }

    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

.panel-header h2 svg {
    width: 18px;
    height: 18px;
    color: var(--primary-light);
}

.host-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-light);
}

.saved-hosts-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.saved-hosts-list::-webkit-scrollbar {
    width: 4px;
}

.saved-hosts-list::-webkit-scrollbar-track {
    background: transparent;
}

.saved-hosts-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* ─── Empty State ───────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 16px;
    color: var(--text-dim);
}

.empty-state svg {
    width: 40px;
    height: 40px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.empty-state span {
    font-size: 0.75rem;
    line-height: 1.4;
}

/* ─── Panel Footer (Export/Import) ──────────────────────── */
.panel-footer {
    display: flex;
    gap: 6px;
    padding: 12px;
    border-top: 1px solid var(--border);
}

.panel-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.panel-action-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.panel-action-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--primary-light);
}

/* ─── Host Card ─────────────────────────────────────────── */
.host-card {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border-radius: 12px;
    margin-bottom: 6px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.host-card:hover {
    background: rgba(255, 255, 255, 0.04);
}

.host-card.active {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.25);
}

.host-card-main {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    padding: 8px;
    cursor: pointer;
    border-radius: 8px;
    min-width: 0;
}

.host-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.host-info {
    min-width: 0;
    flex: 1;
}

.host-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.host-detail {
    font-size: 0.72rem;
    color: var(--text-dim);
    font-family: 'JetBrains Mono', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.host-delete {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    opacity: 0;
}

.host-card:hover .host-delete {
    opacity: 1;
}

.host-delete:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error);
}

.host-delete svg {
    width: 15px;
    height: 15px;
}

/* ─── Login Card ────────────────────────────────────────── */
.login-card {
    width: 100%;
    max-width: 440px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.03) inset;
    animation: cardAppear 0.6s ease-out;
}

@keyframes cardAppear {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ─── Card Header ───────────────────────────────────────── */
.card-header {
    text-align: center;
    margin-bottom: 28px;
}

.logo {
    margin-bottom: 16px;
    display: inline-block;
    animation: logoGlow 3s ease-in-out infinite alternate;
}

@keyframes logoGlow {
    0% {
        filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.3));
    }

    100% {
        filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.5));
    }
}

.card-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text) 0%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ─── Form ──────────────────────────────────────────────── */
.form-row {
    display: flex;
    gap: 12px;
}

.flex-grow {
    flex: 1;
}

.port-group {
    width: 90px;
    flex-shrink: 0;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    width: 18px;
    height: 18px;
    color: var(--text-dim);
    pointer-events: none;
    transition: color 0.2s;
}

.input-wrapper input {
    width: 100%;
    padding: 12px 14px 12px 42px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    transition: all 0.25s ease;
    outline: none;
}

.port-group .input-wrapper input {
    padding-left: 14px;
    text-align: center;
}

.input-wrapper input:focus {
    background: var(--bg-input-focus);
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.input-wrapper input:focus+.input-icon,
.input-wrapper input:focus~.input-icon {
    color: var(--primary-light);
}

.input-wrapper input::placeholder {
    color: var(--text-dim);
}

/* ─── Save Host Checkbox ────────────────────────────────── */
.save-host-row {
    margin-bottom: 18px;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.checkbox-wrapper input[type="checkbox"] {
    display: none;
}

.checkbox-custom {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 5px;
    background: var(--bg-input);
    position: relative;
    transition: all 0.2s;
    flex-shrink: 0;
}

.checkbox-wrapper input[type="checkbox"]:checked+.checkbox-custom {
    background: var(--primary);
    border-color: var(--primary);
}

.checkbox-wrapper input[type="checkbox"]:checked+.checkbox-custom::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 6px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-label {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ─── Password Toggle ───────────────────────────────────── */
.toggle-password {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    transition: color 0.2s;
}

.toggle-password:hover {
    color: var(--text-muted);
}

.toggle-password svg {
    width: 18px;
    height: 18px;
}

/* ─── Error Message ─────────────────────────────────────── */
.error-message {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--error-bg);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-sm);
    color: #fca5a5;
    font-size: 0.85rem;
    margin-bottom: 18px;
    animation: shakeIn 0.4s ease;
}

.error-message svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--error);
}

@keyframes shakeIn {
    0% {
        transform: translateX(-10px);
        opacity: 0;
    }

    25% {
        transform: translateX(5px);
    }

    50% {
        transform: translateX(-3px);
    }

    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ─── Connect Button ────────────────────────────────────── */
.btn-connect {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.btn-connect::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
    transition: left 0.5s ease;
}

.btn-connect:hover::before {
    left: 100%;
}

.btn-connect:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.35);
}

.btn-connect:active {
    transform: translateY(0);
}

.btn-connect:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.btn-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.spinner {
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* ─── Card Footer ───────────────────────────────────────── */
.card-footer {
    margin-top: 20px;
    text-align: center;
}

.security-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-dim);
    font-size: 0.78rem;
}

.security-badge svg {
    width: 14px;
    height: 14px;
    color: var(--success);
}

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 780px) {
    .login-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .saved-hosts-panel {
        width: 100%;
        max-width: 440px;
        max-height: 200px;
    }

    .login-card {
        padding: 28px 24px;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 24px 20px;
        border-radius: 16px;
    }

    .saved-hosts-panel {
        border-radius: 16px;
    }

    .card-header h1 {
        font-size: 1.35rem;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .port-group {
        width: 100%;
    }
}

/* ─── Auth Tabs ─────────────────────────────────────────── */
.auth-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    border: 1px solid var(--border);
}

.auth-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 16px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-dim);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
}

.auth-tab svg {
    width: 16px;
    height: 16px;
}

.auth-tab:hover {
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.04);
}

.auth-tab.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-light);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.1);
}

/* ─── Auth Sections ─────────────────────────────────────── */
.auth-section {
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    0% {
        opacity: 0;
        transform: translateY(-5px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Key Textarea ──────────────────────────────────────── */
.key-input-area {
    position: relative;
}

.key-input-area textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    line-height: 1.4;
    resize: vertical;
    min-height: 100px;
    max-height: 200px;
    outline: none;
    transition: all 0.25s ease;
}

.key-input-area textarea:focus {
    background: var(--bg-input-focus);
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.key-input-area textarea::placeholder {
    color: var(--text-dim);
}

.key-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

.btn-upload-key {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-upload-key:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--primary-light);
}

.btn-upload-key svg {
    width: 14px;
    height: 14px;
}

/* ─── Auth Badge in host card ───────────────────────────── */
.auth-badge {
    font-size: 0.7rem;
    vertical-align: middle;
}