:root {
    --bg-main: #222;
    --bg-sub: #333;
    --text-color: #fff;
    --hover-bg: #444;
    --page-bg: #f0f0f0;
    --transition: 0.4s ease;
}

body.light-mode {
    --bg-main: #fff;
    --bg-sub: #eee;
    --text-color: #000;
    --hover-bg: #ddd;
    --page-bg: #fafafa;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--page-bg) !important;
    color: var(--text-color) !important;
    transition: background-color var(--transition), color var(--transition);
}

    body.light-mode .menu-search {
        background: #ffffff;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    }

        body.light-mode .menu-search input[type="text"] {
            background: #f9f9f9;
            color: #000;
            border-color: #ccc;
        }

        body.light-mode .menu-search button {
            background: #ffffff;
            color: #000;
        }

    body:not(.light-mode) .menu-search {
        background: rgba(75, 73, 73, 0.95);
        box-shadow: 0 2px 6px rgba(255, 255, 255, 0.05);
    }

        body:not(.light-mode) .menu-search button {
            background: rgba(70, 70, 70, 0.85);
            color: #fff;
        }

nav {
    background-color: var(--bg-main);
    transition: background-color 0.4s ease;
}

ul, li {
    list-style: none;
}

    ul.menu {
        font-weight: bold;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        padding: 0 10px;
    }

.menu > li {
    position: relative;
}

    .menu > li > a {
        display: block;
        padding: 12px 18px;
        color: var(--text-color);
        text-decoration: none;
        background: var(--bg-main);
        transition: background var(--transition);
        position: relative;
    }

        .menu > li > a.active,
        nav ul ul li > a.active {
            background: var(--hover-bg);
            color: #ddd;
        }

body.light-mode .menu > li > a.active,
body.light-mode nav ul ul li > a.active {
    background: #ddd;
    color: #000000;
}

.menu > li:hover > a {
    background: var(--hover-bg);
}

nav ul ul {
    position: absolute;
    top: 100%; /* отступ от верха окна */
    left: 0; /* отступ от левого края окна */
    background: var(--bg-sub);
    min-width: 180px;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
}

nav li:hover > ul {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

nav ul ul li {
    position: relative;
}

    nav ul ul li a {
        display: block;
        padding: 12px 16px;
        color: var(--text-color);
        text-decoration: none;
        background: var(--bg-sub);
        transition: background var(--transition);
        position: relative;
    }

    nav ul ul li:hover > a {
        background: var(--hover-bg);
    }

nav ul ul ul {
    left: 100%;
    top: 0;
}

.theme-toggle-btn {
    margin-left: auto;
}

    .theme-toggle-btn > button {
        width: 40px;
        height: 40px;
        font-size: 18px;
        background: var(--bg-main);
        color: var(--text-color);
        border: none;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background var(--transition), color var(--transition);
        outline: none;
    }

        .theme-toggle-btn > button:hover,
        .theme-toggle-btn > button:focus {
            background: var(--bg-main);
            outline: none;
            box-shadow: none;
        }

.menu-search {
    position: absolute;
    top: 6px;
    left: 60%;
    transform: translateX(-50%);
    width: 25%;
    background: var(--page-bg);
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    z-index: 200;
    display: flex;
    align-items: center;
    transition: opacity 0.3s ease;
    overflow: hidden;
    box-sizing: border-box;
}

    .menu-search form {
        display: flex;
        width: 100%;
    }

    .menu-search input[type="text"] {
        flex: 1;
        padding: 4px 8px;
        border: 1px solid #ccc;
        border-radius: 4px 0 0 4px;
        outline: none;
    }

    .menu-search button {
        padding: 4px 8px;
        border: 1px solid #ccc;
        border-left: none;
        background-color: #eee;
        border-radius: 0 4px 4px 0;
        cursor: pointer;
    }

.menu > li > a::after {
    right: 4px;
}

nav ul li > a::after {
    content: '▶';
    display: inline-block;
    margin-left: 6px;
    font-size: 0.7em;
    transition: transform 0.3s ease;
    color: var(--text-color);
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}

.menu > li:not(.has-submenu) > a::after,
nav ul ul li:not(.has-submenu) > a::after {
    content: '';
}

.menu > li:hover > a::after,
nav ul ul li:hover > a::after {
    transform: translateY(-50%) rotate(90deg);
}

.menu > li > a:hover,
nav ul ul li a:hover {
    transition: color 0.3s ease;
}

body.light-mode .menu > li > a:hover,
body.light-mode nav ul ul li a:hover {
    color: #858181;
}

body:not(.light-mode) .menu > li > a:hover,
body:not(.light-mode) nav ul ul li a:hover {
    color: #b4b0b0;
}

.hamburger {
    all: unset;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-main);
    color: var(--text-color);
    border-radius: 6px;
    cursor: pointer;
    position: absolute;
    top: 15px;
    left: 15px;
    position: fixed !important;
    z-index: 200;
    transition: background var(--transition), color var(--transition);
    font-size: 24px; /* чтобы значок был побольше */
    -webkit-user-select: none;
    user-select: none; /* отключаем выделение текста */
    outline: none; /* убираем outline */
    box-shadow: none; /* убираем тень */
}

    .hamburger:focus,
    .hamburger:active {
        outline: none;
        box-shadow: none;
    }

    .hamburger::before {
        content: "☰";
        display: block;
        width: 100%;
        text-align: center;
        font-size: 24px;
        color: var(--text-color);
    }

.hamburger {
    display: none;

    /* остальные стили */
}

.mobile-theme-toggle {
    display: none;
}

.tooltip {
    position: absolute;
    background: transparent;
    font-size: 12px;
    font-weight: bold;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
    white-space: nowrap;
    z-index: 1000;
    color: #807e7e;
    transform: translateZ(0);
    will-change: transform, opacity;
}

    .tooltip.show {
        opacity: 1;
    }

.menu-mobile {
    display: none;
}

@media (max-width: 1024px) {

    .mobile-actions {
        position: fixed;
        top: 15px;
        right: 15px;
        display: flex;
        gap: 10px;
        z-index: 200;
    }

    .mobile-theme-toggle,
    .mobile-search-toggle {
        width: 40px;
        height: 40px;
        background: var(--bg-main);
        color: var(--text-color);
        border: none;
        font-size: 18px;
        border-radius: 6px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background var(--transition), color var(--transition);
        /* Убираем выделение текста и эффект нажатия */
        -webkit-tap-highlight-color: transparent;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        /* Убираем рамку и тень */
        outline: none;
        box-shadow: none;
    }

        .mobile-theme-toggle:focus,
        .mobile-theme-toggle:active,
        .mobile-search-toggle:focus,
        .mobile-search-toggle:active {
            outline: none;
            box-shadow: none;
            background: var(--bg-main);
            color: var(--text-color);
        }

    .tooltip {
        display: none !important;
    }

    .hamburger {
        display: block;
    }

    .theme-toggle-btn {
        display: none;
    }

    nav {
        position: absolute;
        top: 0;
        left: -100%;
        width: 240px;
        height: 100vh;
        background: var(--bg-main);
        transition: left 0.3s ease;
        z-index: 150;
        padding-top: 60px;
    }

        nav.open {
            left: 0;
        }

    ul.menu {
        flex-direction: column;
        align-items: stretch;
        padding: 0;
    }

    .menu-mobile {
        display: block;
    }

    .menu > li > a {
        border-bottom: 1px solid var(--bg-sub);
    }

    nav ul ul {
        position: static;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease, opacity 0.3s ease;
    }

    nav li.open > ul {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        max-height: 1000px;
    }

    nav ul ul ul {
        padding-left: 15px;
    }

    nav ul li > a::after,
    nav ul ul li > a::after {
        transform: translateY(-50%) rotate(90deg);
    }

    nav li.open > a::after {
        transform: translateY(-50%) rotate(270deg);
    }

    .menu-search {
        position: fixed;
        top: 15px;
        left: max(50%);
        transform: translateX(-50%);
        width: 60%;
        background: var(--page-bg);
        padding: 0.25rem 0.5rem;
        border-radius: 6px;
        box-shadow: 0 2px 6px rgba(0,0,0,0.1);
        z-index: 200;
        display: flex;
        align-items: center;
        transition: opacity 0.3s ease;
        overflow: hidden;
        box-sizing: border-box;
    }

        .menu-search.hidden {
            opacity: 0;
            pointer-events: none;
        }

        .menu-search input[type="text"] {
            flex: 1;
            padding: 6px 10px;
            font-size: 14px;
            border-radius: 6px 0 0 6px;
            border: 1px solid #ccc;
            outline: none;
            min-width: 0;
            box-sizing: border-box;
        }

        .menu-search button {
            padding: 6px 10px;
            font-size: 14px;
            border-radius: 0 6px 6px 0;
            border: 1px solid #ccc;
            background: #eee;
            cursor: pointer;
            -webkit-user-select: none;
            user-select: none;
        }
}
