// ==UserScript==
// @name         GV Desktop-on-Mobile Fix
// @version      4.0
// @match        https://voice.google.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // 1. FORCE CSS (This runs before the page even loads)
    const style = document.createElement('style');
    style.innerHTML = `
        /* Hide specific header items by searching for their containers */
        gv-header-item:has(a[href*="billing"]), 
        gv-header-item:has(div[aria-label*="calls"]),
        .sub-header, .upgrade-link, 
        [aria-label*="Receiving calls"], [aria-label*="Upgrade"] {
            display: none !important;
            width: 0 !important;
            visibility: hidden !important;
        }

        /* The Right Column (Drawer Handle) */
        gv-side-panel, .side-panel, [role="complementary"] {
            min-width: 20px !important;
            width: 20px !important;
            max-width: 20px !important;
            overflow: hidden !important;
            background: #1a73e8 !important; /* Solid Blue Handle */
            transition: width 0.2s !important;
            cursor: pointer !important;
        }

        /* Expand the panel when a specific class is added */
        .drawer-open {
            min-width: 300px !important;
            width: 300px !important;
        }
    `;
    document.head.appendChild(style);

    // 2. LOGIC TO HANDLE CLICKS & KEYPAD
    const runClean = () => {
        // Auto-click the 'Close Keypad' button if it exists
        const closeBtn = document.querySelector('button[aria-label="Close keypad"], button[aria-label="Hide keypad"]');
        if (closeBtn) closeBtn.click();

        // Setup the drawer toggle
        const panel = document.querySelector('gv-side-panel') || document.querySelector('[role="complementary"]');
        if (panel && !panel.onclick) {
            panel.onclick = () => panel.classList.toggle('drawer-open');
        }
    };

    // Run the cleaner constantly to fight Google's updates
    setInterval(runClean, 500);

})();