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

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #1e2130;
    --bg-input: #262938;
    --bg-hover: #2a2e42;
    --border: #2d3148;
    --border-focus: #4a6cf7;
    --text-primary: #e4e6f0;
    --text-secondary: #8b8fa8;
    --text-dim: #555a72;
    --accent: #4a6cf7;
    --accent-hover: #5b7af8;
    --danger: #e74c4c;
    --success: #3ddc84;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* ═══ Screens ═══ */
.screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
}

/* ═══ Card ═══ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.card-wide {
    max-width: 520px;
}

.logo {
    text-align: center;
    margin-bottom: 32px;
    color: var(--accent);
}

.logo-img {
    width: 280px;
    height: auto;
    display: block;
    margin: 0 auto 12px;
    mix-blend-mode: lighten;
}

.logo-img.logo-sm {
    width: 200px;
}

.logo h1 {
    font-size: 24px;
    font-weight: 600;
    margin-top: 12px;
    color: var(--text-primary);
}

.logo .subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ═══ Forms ═══ */
.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus {
    border-color: var(--border-focus);
}

.input-group input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

button[type="submit"] {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

button[type="submit"]:hover { background: var(--accent-hover); }
button[type="submit"]:disabled { opacity: 0.6; cursor: not-allowed; }

.error-msg {
    margin-top: 16px;
    padding: 10px 14px;
    background: rgba(231, 76, 76, 0.1);
    border: 1px solid rgba(231, 76, 76, 0.3);
    border-radius: 8px;
    color: var(--danger);
    font-size: 13px;
    text-align: center;
}

.btn-text {
    display: block;
    margin: 16px auto 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.btn-text:hover { color: var(--text-primary); }
.btn-text.dim { color: var(--text-dim); }

/* ═══ Agent List ═══ */
/* Modal overlay (TOTP prompt) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-overlay .card {
    animation: modal-enter 0.2s ease-out;
}

@keyframes modal-enter {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.agents-list {
    margin-bottom: 8px;
    max-height: 360px;
    overflow-y: auto;
}

.agents-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary);
}

.agents-empty p {
    margin-top: 8px;
    font-size: 14px;
}

.text-dim {
    color: var(--text-dim) !important;
    font-size: 12px !important;
}

.agent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    transition: border-color 0.15s;
}

.agent-item:hover {
    border-color: var(--accent);
}

.agent-info {
    flex: 1;
}

.agent-name {
    font-size: 15px;
    font-weight: 500;
}

.agent-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 3px;
}

.agent-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--success);
}

.agent-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}

.agent-status.busy {
    color: var(--text-dim);
}
.agent-status.busy::before {
    background: var(--text-dim);
}

.agent-connect-btn {
    padding: 7px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.agent-connect-btn:hover { background: var(--accent-hover); }
.agent-connect-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ═══ 2FA / QR Code ═══ */
.qr-container {
    text-align: center;
    margin: 0 0 16px;
    padding: 16px;
    background: #fff;
    border-radius: 12px;
    display: inline-block;
    width: 100%;
}

.qr-container img {
    width: 200px;
    height: 200px;
    display: block;
    margin: 0 auto;
    image-rendering: pixelated;
}

.setup-hint {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 16px;
    line-height: 1.5;
}

.manual-key {
    text-align: center;
    margin-bottom: 20px;
}

.manual-key label {
    display: block;
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.manual-key code {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 2px;
    background: var(--bg-input);
    padding: 6px 12px;
    border-radius: 6px;
    user-select: all;
}

#totp-code {
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 6px;
    font-family: 'Courier New', monospace;
}

/* ═══ Toolbar ═══ */
#toolbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 44px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    user-select: none;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-badge {
    font-size: 12px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-badge::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.status-badge.connected {
    background: rgba(61, 220, 132, 0.15);
    color: var(--success);
}
.status-badge.connected::before { background: var(--success); }

.status-badge.disconnected {
    background: rgba(231, 76, 76, 0.15);
    color: var(--danger);
}
.status-badge.disconnected::before { background: var(--danger); }

.status-badge.reconnecting {
    background: rgba(255, 193, 7, 0.15);
    color: #ffc107;
    animation: pulse-badge 1.5s ease-in-out infinite;
}
.status-badge.reconnecting::before { background: #ffc107; }

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.toolbar-info {
    font-size: 12px;
    color: var(--text-secondary);
}

.toolbar-btn {
    padding: 5px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.toolbar-btn:hover { background: var(--border); }

.toolbar-btn.danger {
    border-color: rgba(231, 76, 76, 0.4);
    color: var(--danger);
}
.toolbar-btn.danger:hover { background: rgba(231, 76, 76, 0.15); }

/* ═══ Canvas ═══ */
#canvas-container {
    position: fixed;
    top: 44px; left: 0; right: 0; bottom: 0;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#remote-canvas {
    display: block;
    outline: none;
    cursor: default;
    image-rendering: auto;
}

body.fullscreen #toolbar { display: none; }
body.fullscreen #canvas-container { top: 0; }

/* ═══ Metrics Overlay ═══ */
#metrics-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.82);
    color: #0f0;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid rgba(0, 255, 0, 0.2);
    pointer-events: none;
    z-index: 50;
    white-space: pre;
    min-width: 280px;
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

#metrics-panel b {
    color: #6f6;
}

.toolbar-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ═══ Clipboard Indicator ═══ */
.clipboard-indicator {
    font-size: 12px;
    color: #3ddc84;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 0 8px;
    white-space: nowrap;
}

.clipboard-indicator.visible {
    opacity: 1;
}

/* ═══ Spinner ═══ */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }
