#tool-menu {
    position: absolute;
    left: 0;
    top: 0;
    width: 46px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 0;
    background: var(--tv-elevated-bg);
    border-right: 1px solid var(--tv-border);
}

#tool-menu button {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 4px;
    margin: 0;
    padding: 0;
    background: transparent;
    color: var(--tv-text);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

#tool-menu button:hover {
    background: var(--tv-hover);
}

#tool-menu button.active {
    background: var(--tv-active);
    color: var(--tv-blue);
}

#chart-container.drawing-mode #tool-menu button.active {
    background: var(--tv-active);
    box-shadow: inset 0 0 0 1px rgba(41, 98, 255, 0.18);
}

#tool-menu button:disabled {
    color: var(--tv-muted);
    cursor: default;
}

#tool-menu button:disabled:hover {
    background: transparent;
}

#tool-menu svg {
    display: block;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#tool-line circle {
    fill: var(--tv-control-bg);
    stroke: currentColor;
}

.tool-text {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0;
}

#line-toolbar {
    position: absolute;
    left: 58px;
    top: 10px;
    z-index: 20;
    height: 42px;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 9px;
    background: var(--tv-elevated-bg);
    border: 1px solid var(--tv-border);
    border-radius: 8px;
    box-shadow: 0 8px 22px var(--tv-shadow);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

#chart-container.line-selected-mode #line-toolbar {
    border-color: rgba(41, 98, 255, 0.28);
}

#chart-container.line-dragging-mode #line-toolbar {
    border-color: rgba(41, 98, 255, 0.45);
    box-shadow: 0 8px 22px rgba(41, 98, 255, 0.16);
}

#line-toolbar[hidden] {
    display: none;
}

#line-toolbar.paste-only-mode > :not(.more-control) {
    display: none !important;
}

#line-toolbar button {
    width: 30px;
    height: 28px;
    border: 0;
    border-radius: 4px;
    padding: 0;
    background: transparent;
    color: var(--tv-text);
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#line-toolbar button:hover,
#line-toolbar button.active {
    background: var(--tv-hover);
    color: var(--tv-blue);
}

#line-toolbar button:disabled {
    color: var(--tv-muted);
    cursor: default;
    opacity: 0.55;
}

#line-toolbar button:disabled:hover {
    background: transparent;
    color: var(--tv-muted);
}

#line-toolbar svg {
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.line-toolbar-divider {
    width: 1px;
    height: 22px;
    flex: 0 0 1px;
    margin: 0 2px;
    background: var(--tv-border);
}

.toolbar-color {
    height: 30px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    color: var(--tv-muted);
    font-size: 12px;
}

.color-control {
    position: relative;
    padding: 0;
}

.color-button {
    width: 34px !important;
    min-width: 34px;
    height: 32px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    color: var(--tv-text) !important;
    position: relative;
}

.color-button:hover,
.style-button:hover,
.choice-button:hover,
#line-text-bold:hover {
    background: var(--tv-hover) !important;
}

.toolbar-swatch {
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 1px;
    height: 4px;
    border: 0;
    border-radius: 999px;
    background: var(--tv-blue);
}

.color-menu {
    position: absolute;
    left: 0;
    top: 34px;
    z-index: 40;
    width: 154px;
    display: grid;
    grid-template-columns: repeat(6, 18px);
    gap: 6px;
    padding: 9px;
    background: var(--tv-control-bg);
    border: 1px solid var(--tv-border);
    border-radius: 6px;
    box-shadow: 0 8px 22px var(--tv-shadow);
}

.color-menu[hidden] {
    display: none;
}

.color-menu button {
    width: 18px !important;
    height: 18px !important;
    border: 1px solid var(--tv-border) !important;
    border-radius: 50% !important;
    background: var(--color-value) !important;
    padding: 0 !important;
}

.color-menu button.active {
    outline: 2px solid var(--tv-blue);
    outline-offset: 2px;
}

.style-control,
.choice-control {
    position: relative;
}

.more-control {
    position: relative;
}

.style-button {
    width: 42px !important;
    height: 32px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    background: transparent !important;
}

.style-preview {
    width: 26px;
    height: 0;
    display: inline-block;
    border-top: 2px solid currentColor;
}

[data-style="dashed"] .style-preview {
    border-top-style: dashed;
}

[data-style="dotted"] .style-preview {
    border-top-style: dotted;
    border-top-width: 3px;
}

.style-menu {
    position: absolute;
    left: 0;
    top: 36px;
    z-index: 40;
    width: 168px;
    padding: 0;
    overflow: hidden;
    background: var(--tv-control-bg);
    border: 1px solid var(--tv-border);
    border-radius: 8px;
    box-shadow: 0 8px 22px var(--tv-shadow);
}

.style-menu[hidden] {
    display: none;
}

.style-menu button {
    width: 100% !important;
    height: 42px !important;
    display: flex !important;
    align-items: center;
    justify-content: flex-start !important;
    gap: 14px;
    padding: 0 16px !important;
    border-radius: 0 !important;
    color: var(--tv-text) !important;
    font-size: 14px !important;
    text-align: center;
}

.style-menu button.active {
    background: var(--tv-text) !important;
    color: var(--tv-control-bg) !important;
}

.style-menu .style-preview {
    width: 34px;
    flex: 0 0 34px;
}

.choice-button {
    width: auto !important;
    min-width: 42px;
    height: 32px !important;
    gap: 4px;
    padding: 0 9px !important;
    background: transparent !important;
}

.width-button {
    font-size: 13px !important;
    font-weight: 500;
}

.choice-menu {
    position: absolute;
    left: 0;
    top: 36px;
    z-index: 40;
    width: 78px;
    padding: 0;
    overflow: hidden;
    background: var(--tv-control-bg);
    border: 1px solid var(--tv-border);
    border-radius: 8px;
    box-shadow: 0 8px 22px var(--tv-shadow);
}

.more-menu {
    position: absolute;
    right: 0;
    top: 36px;
    z-index: 40;
    width: 112px;
    padding: 4px 0;
    background: var(--tv-control-bg);
    border: 1px solid var(--tv-border);
    border-radius: 8px;
    box-shadow: 0 8px 22px var(--tv-shadow);
}

.more-menu[hidden] {
    display: none;
}

.more-menu button {
    width: 100% !important;
    height: 34px !important;
    justify-content: flex-start !important;
    padding: 0 12px !important;
    border-radius: 0 !important;
    color: var(--tv-text) !important;
    font-size: 13px !important;
}

.more-menu button.active,
.more-menu button:hover {
    background: var(--tv-hover) !important;
}

.choice-menu[hidden] {
    display: none;
}

.choice-menu button {
    width: 100% !important;
    height: 38px !important;
    display: flex !important;
    align-items: center;
    justify-content: flex-start !important;
    gap: 0;
    padding: 0 14px !important;
    border-radius: 0 !important;
    color: var(--tv-text) !important;
    font-size: 13px !important;
    text-align: left;
}

.choice-menu button span {
    width: 100%;
    text-align: center;
}

.choice-menu button.active {
    background: var(--tv-text) !important;
    color: var(--tv-control-bg) !important;
}

.text-size-button {
    min-width: 52px;
}

.text-size-icon {
    width: auto;
    display: inline-block;
    text-align: center;
    font-weight: 500;
    line-height: 1;
    font-size: 18px;
    transform: translateY(-1px);
}

#line-text-size-label {
    min-width: 14px;
    color: var(--tv-muted);
    font-size: 11px;
    font-weight: 600;
    transform: translateY(3px);
}

.bold-icon {
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

.text-color-icon {
    display: inline-block;
    font-size: 19px;
    font-weight: 500;
    line-height: 1;
    transform: translateY(-1px);
}

.mobile-only-tool {
    display: none !important;
}

.toolbar-text-icon {
    display: inline-block;
    font-size: 17px;
    font-weight: 500;
    line-height: 1;
}

#line-text-editor {
    position: absolute;
    z-index: 35;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--tv-text);
    font: 12px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 18px;
    text-align: left;
    outline: none;
    color: transparent;
    caret-color: transparent;
    opacity: 0.01;
    transform-origin: left top;
}

#line-text-editor::placeholder {
    color: transparent;
    opacity: 1;
}

#line-text-editor[hidden] {
    display: none;
}

@media (max-width: 720px) {
    #tool-menu {
        left: 8px;
        top: 8px;
        width: auto;
        max-width: calc(100% - 16px);
        flex-direction: row;
        padding: 4px;
        border: 1px solid var(--tv-border);
        border-radius: 8px;
        box-shadow: 0 6px 16px var(--tv-shadow);
    }

    #tool-menu button {
        width: 34px;
        height: 34px;
    }

    #line-toolbar {
        left: 8px;
        right: auto;
        top: 52px;
        bottom: auto;
        width: max-content;
        max-width: calc(100% - 16px);
        height: auto;
        min-height: 40px;
        max-height: none;
        flex-wrap: nowrap;
        align-content: center;
        justify-content: flex-start;
        gap: 4px;
        padding: 4px;
        overflow: visible;
        scrollbar-width: none;
        border-radius: 8px;
    }

    #line-toolbar::-webkit-scrollbar {
        display: none;
    }

    #line-toolbar button {
        flex: 0 0 auto;
        width: 34px;
        height: 34px;
        border-radius: 4px;
    }

    #line-toolbar button:hover {
        background: transparent !important;
        color: var(--tv-text) !important;
    }

    #line-toolbar button.active,
    #line-toolbar button.active:hover {
        background: var(--tv-hover) !important;
        color: var(--tv-blue) !important;
    }

    #line-toolbar button:disabled,
    #line-toolbar button:disabled:hover {
        color: var(--tv-muted);
        background: transparent;
    }

    .line-toolbar-divider {
        height: 22px;
        margin: 0;
    }

    .color-button {
        width: 34px !important;
        min-width: 34px;
        height: 34px !important;
        display: inline-grid !important;
        place-items: center;
        gap: 0;
    }

    .color-button svg,
    .color-button .text-color-icon {
        transform: translateY(-2px);
    }

    .style-button {
        width: 40px !important;
        height: 34px !important;
    }

    .choice-button {
        min-width: 42px;
        height: 34px !important;
        padding: 0 8px !important;
    }

    .text-size-button {
        min-width: 50px;
    }

    .style-preview {
        width: 22px;
    }

    .toolbar-swatch {
        left: 6px;
        right: 6px;
    }

    #line-width-label {
        font-size: 13px;
    }

    #line-text-size-label {
        min-width: 14px;
        font-size: 11px;
    }

    @media (max-width: 390px) {
        #line-toolbar {
            gap: 3px;
            padding: 4px;
        }

        #line-toolbar button {
            width: 32px;
            height: 32px;
        }

        .color-button {
            width: 32px !important;
            min-width: 32px;
            height: 32px !important;
        }

        .style-button {
            width: 36px !important;
            height: 32px !important;
        }

        .choice-button {
            min-width: 38px;
            height: 32px !important;
            padding-left: 6px !important;
            padding-right: 6px !important;
        }

        .text-size-button {
            min-width: 44px;
        }
    }

    .mobile-only-tool {
        display: inline-flex !important;
    }

    #line-copy,
    #line-paste,
    #line-lock,
    #line-delete {
        display: none !important;
    }

    .color-menu,
    .style-menu,
    .choice-menu,
    .more-menu {
        position: fixed;
        z-index: 90;
    }

    .color-menu {
        width: 204px;
        grid-template-columns: repeat(6, 22px);
        gap: 8px;
        padding: 14px;
        box-sizing: border-box;
    }

    .color-menu button {
        width: 22px !important;
        height: 22px !important;
    }

    #line-text-editor {
        font-size: 16px !important;
        line-height: 18px;
        -webkit-text-size-adjust: 100%;
    }
}
