# -*- coding: utf-8 -*-
# gui/styles/buttons.py
"""Стили для всех видов кнопок"""
from pathlib import Path
import re

LIGHT_TEXT_PRIMARY = "#172B4D"
LIGHT_TEXT_SECONDARY = "#5E6C84"
LIGHT_TEXT_DISABLED = "#A5ADBA"
LIGHT_PANEL = "#FFFFFF"
LIGHT_BORDER = "#DFE1E6"
LIGHT_HOVER = "#EBECF0"
LIGHT_PRESSED = "#DFE1E6"
LIGHT_ACCENT_SOFT = "#DEEBFF"
LIGHT_ACCENT_BORDER = "#85B8FF"

BUTTONS = {

    "BUTTON_PRIMARY": """
        QPushButton {
            background-color: palette(highlight);
            color: #ffffff;
            border: 1px solid palette(highlight);
            border-radius: 0px;
            padding: 8px 14px;
            font-size: 14px;
            font-weight: 600;
        }
        QPushButton:hover {
            background-color: #0747A6;
            border-color: #0747A6;
        }
        QPushButton:pressed {
            background-color: #043A7D;
            border-color: #043A7D;
        }
        QPushButton:disabled {
            background-color: palette(mid);
            color: #42526E;
            border-color: palette(mid);
        }
    """,

    "BUTTON_SECONDARY": """
        QPushButton {
            background-color: palette(button);
            color: palette(button-text);
            border: 1px solid palette(mid);
            border-radius: 0px;
            padding: 4px 8px;
            font-size: 12px;
            min-width: 100px;
            min-height: 30px;
        }
        QPushButton:hover {
            background-color: #EBECF0;
        }
        QPushButton:pressed {
            background-color: #DFE1E6;
        }
    """,

    "BUTTON_SMALL": """
        QPushButton {
            background-color: palette(button);
            color: palette(button-text);
            border: 1px solid palette(mid);
            border-radius: 0px;
            padding: 6px 12px;
            font-size: 12px;
            min-width: 80px;
            min-height: 30px;
        }
        QPushButton:hover {
            background-color: #EBECF0;
        }
        QPushButton:pressed {
            background-color: #DFE1E6;
        }
        QPushButton:checked {
            background-color: palette(highlight);
            color: #ffffff;
            border-color: palette(highlight);
        }
    """,

    "MEASURE_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/measure_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "MEASURE_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/measure_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,
    "MEASURE_TEXT_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 0px;
            qproperty-toolButtonStyle: ToolButtonTextOnly;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "MEASURE_TEXT_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 0px;
            qproperty-toolButtonStyle: ToolButtonTextOnly;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "CREATE_ZONE_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/create_zone_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "CREATE_ZONE_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/create_zone_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "DELETE_ZONE_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/delete_zone_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "DELETE_ZONE_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/delete_zone_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "SELECT_ZONE_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/select_zone_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "SELECT_ZONE_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/select_zone_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,
    "EDIT_ZONE_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/edit_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "EDIT_ZONE_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/edit_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "CREATE_NEW_MESH_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/create_mesh_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "CREATE_NEW_MESH_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/create_mesh_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "USE_CURRENT_MESH_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/use_current_mesh_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "USE_CURRENT_MESH_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/use_current_mesh_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "START_POINT_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/start_point_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "START_POINT_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/start_point_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "CREATE_MESH_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/create_mesh_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "CREATE_MESH_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/create_mesh_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,
    "REMEMBER_POINT_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/remember_point_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "REMEMBER_POINT_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/remember_point_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "SET_GRID_STEP_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/set_step_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "SET_GRID_STEP_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/set_step_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "CREATE_VOLUME_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/create_volume_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "CREATE_VOLUME_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/create_volume_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,

    "REMEMBER_VOLUME_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/accept_wolume_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "REMEMBER_VOLUME_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 16px;
            padding-left: 6px;
            qproperty-icon: url("gui/components/icons/accept_wolume_white.png");
            qproperty-iconSize: 18px 18px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,
    "MODEL_TOGGLE": """
        QToolButton {
            background-color: transparent;
            color: white;
            border: 1px solid #555555;
            font-size: 14px;
            padding-left: 6px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:disabled {
            background-color: #1f1f1f;
            color: #7a7a7a;
            border: 1px solid #2a2a2a;
        }
        QToolButton:hover { background-color: #4a4a4a; }
        QToolButton:pressed { background-color: #5a5a5a; }
    """,

    "MODEL_TOGGLE_ACTIVE": """
        QToolButton {
            background-color: rgba(255, 255, 255, 0.3);
            color: white;
            border: 1px solid #cfcfcf;
            font-size: 14px;
            padding-left: 6px;
            qproperty-toolButtonStyle: ToolButtonTextBesideIcon;
        }
        QToolButton:hover { background-color: #6a6a6a; }
        QToolButton:pressed { background-color: #7a7a7a; }
    """,
    "STANDARD_BUTTON_DARK_THEME": """
        QPushButton {
            background-color: #3c3c3c;
            color: white;
            border: none;
            font-size: 16px;
            text-align: left;
            border-radius: 0px;
            padding-left: 10px;
        }
        QPushButton:hover { background-color: #4a4a4a; }
        QPushButton:pressed { background-color: #5a5a5a; }
        QPushButton:disabled {
            background-color: #2e2e2e;
            color: #606060;
            border: none;
        }
    """,

    "STANDARD_BUTTON_DARK_THEME_ACTIVE": """
        QPushButton {
            background-color: #5a5a5a;
            color: white;
            border: none;
            font-size: 16px;
            text-align: left;
            border-radius: 0px;
            padding-left: 10px;
        }
        QPushButton:hover { background-color: #6a6a6a; }
        QPushButton:pressed { background-color: #7a7a7a; }
        QPushButton:disabled {
            background-color: #2e2e2e;
            color: #606060;
            border: none;
        }
    """,

    "STANDARD_BUTTON_LIGHT_THEME": """
        QPushButton {
            background-color: #FFFFFF;
            color: #172B4D;
            border: 1px solid #DFE1E6;
            font-size: 16px;
            border-radius: 0px;
            text-align: left;
            padding-left: 10px;
        }
        QPushButton:hover {
            background-color: #EBECF0;
            border-color: #DFE1E6;
        }
        QPushButton:pressed { background-color: #DFE1E6; }
        QPushButton:disabled {
            background-color: #F4F5F7;
            color: #B3BAC5;
            border: 1px solid #EBECF0;
        }
    """,

    "STANDARD_BUTTON_LIGHT_THEME_ACTIVE": """
        QPushButton {
            background-color: #FFFFFF;
            color: #0C66E4;
            border: 1px solid #85B8FF;
            font-size: 16px;
            border-radius: 0px;
            font-weight: 600;
            text-align: left;
            padding-left: 10px;
        }
        QPushButton:hover { background-color: #EBECF0; }
        QPushButton:pressed { background-color: #DFE1E6; }
        QPushButton:disabled {
            background-color: #F4F5F7;
            color: #B3BAC5;
            border: 1px solid #EBECF0;
            font-weight: normal;
        }
    """,

    "TAB_BUTTON_ACTIVE": """
        QPushButton {
            background-color: #5a5a5a;
            color: white;
            border: 1px solid #6A6A6A;
            font-size: 16px;
            font-weight: bold;
            text-align: center;
            border-radius: 0px;
            margin 10px;
        }
        QPushButton:hover {
            background-color: #6a6a6a;
        }
        QPushButton:pressed {
            background-color: #7a7a7a;
        }
        QPushButton:disabled {
            background-color: #2e2e2e;
            color: #606060;
            border: 1px solid #333333;
        }
    """,

    "TAB_BUTTON_NORMAL": """
        QPushButton {
            background-color: #3c3c3c;
            color: #DCDCDC;
            border: 1px solid #3A3A3A;
            font-size: 16px;
            text-align: center;
            border-radius: 0px;
            margin 10px;
        }
        QPushButton:hover {
            background-color: #4a4a4a;
        }
        QPushButton:pressed {
            background-color: #5a5a5a;
        }
        QPushButton:disabled {
            background-color: #2e2e2e;
            color: #606060;
            border: 1px solid #333333;
        }
    """,

    "VISUALIZATION_BUTTON_ACTIVE": """
        QPushButton {
            background-color: #0078d4;
            color: #ffffff;
            border: 1px solid #0078d4;
            border-radius: 0px;
            padding: 4px 8px;
            font-size: 14px;
            font-weight: bold;
        }
        QPushButton:hover {
            background-color: #106ebe;
            border-color: #106ebe;
        }
        QPushButton:pressed {
            background-color: #005a9e;
        }
    """,

    "VISUALIZATION_BUTTON_FILL": """
        QPushButton {
            background-color: palette(button);
            color: palette(button-text);
            border: 1px solid palette(mid);
            border-radius: 0px;
            padding: 4px 8px;
            font-size: 14px;
            font-weight: 600;
        }
        QPushButton:hover {
            border-color: palette(highlight);
        }
        QPushButton:pressed {
            background-color: palette(light);
        }
    """,
    "TAB_BUTTON_ACTIVE_LIGHT": """
        QPushButton {
            background-color: #FFFFFF;
            color: #0C66E4;
            border: 1px solid #85B8FF;
            font-size: 16px;
            font-weight: 600;
            text-align: center;
            border-radius: 0px;
            margin 10px;
        }
        QPushButton:hover {
            background-color: #EBECF0;
        }
        QPushButton:pressed {
            background-color: #DFE1E6;
        }
        QPushButton:disabled {
            background-color: #F4F5F7;
            color: #B3BAC5;
            border: 1px solid #EBECF0;
        }
    """,

    "TAB_BUTTON_NORMAL_LIGHT": """
        QPushButton {
            background-color: #FFFFFF;
            color: #172B4D;
            border: 1px solid #DFE1E6;
            font-size: 16px;
            text-align: center;
            border-radius: 0px;
            margin 10px;
        }
        QPushButton:hover {
            background-color: #EBECF0;
        }
        QPushButton:pressed {
            background-color: #DFE1E6;
        }
        QPushButton:disabled {
            background-color: #F4F5F7;
            color: #B3BAC5;
            border: 1px solid #EBECF0;
        }
    """,

    "RACK_TAB_BUTTON_ACTIVE": """
        QPushButton {
            background-color: #5F738A;
            color: #FFFFFF;
            border: 1px solid #6F8298;
            border-radius: 3px;
            padding: 2px 8px;
            font-size: 13px;
            font-weight: 600;
            text-align: center;
        }
        QPushButton:hover {
            background-color: #6A7F97;
            border-color: #7A8FA6;
        }
        QPushButton:pressed {
            background-color: #52657A;
            border-color: #62778D;
        }
    """,

    "RACK_TAB_BUTTON_NORMAL": """
        QPushButton {
            background-color: #3A3F45;
            color: #D9DEE3;
            border: 1px solid #4A5058;
            border-radius: 3px;
            padding: 2px 8px;
            font-size: 13px;
            font-weight: 500;
            text-align: center;
        }
        QPushButton:hover {
            background-color: #434A53;
            border-color: #5A616A;
        }
        QPushButton:pressed {
            background-color: #4D5661;
            border-color: #636D78;
        }
    """,

    "RACK_TAB_BUTTON_ACTIVE_LIGHT": """
        QPushButton {
            background-color: #DCEBFF;
            color: #0C66E4;
            border: 1px solid #85B8FF;
            border-radius: 3px;
            padding: 2px 8px;
            font-size: 13px;
            font-weight: 600;
            text-align: center;
        }
        QPushButton:hover {
            background-color: #CFE1FF;
            border-color: #6FA8FF;
        }
        QPushButton:pressed {
            background-color: #BFD6FF;
            border-color: #5D9BFF;
        }
    """,

    "RACK_TAB_BUTTON_NORMAL_LIGHT": """
        QPushButton {
            background-color: #FFFFFF;
            color: #172B4D;
            border: 1px solid #DFE1E6;
            border-radius: 3px;
            padding: 2px 8px;
            font-size: 13px;
            font-weight: 500;
            text-align: center;
        }
        QPushButton:hover {
            background-color: #F4F5F7;
            border-color: #CDD4DD;
        }
        QPushButton:pressed {
            background-color: #EBECF0;
            border-color: #C1C7D0;
        }
    """,
}

_ICONS_DIR = Path(__file__).resolve().parents[1] / "components" / "icons"


def _replace_white_icons_with_black(style_text: str) -> str:
    """Заменить *_white.png на *_black.png, только если файл чёрной иконки существует."""
    pattern = re.compile(r'([a-z0-9_]+)_white\.png', re.IGNORECASE)

    def _swap(match):
        icon_base = match.group(1)
        black_name = f"{icon_base}_black.png"
        if (_ICONS_DIR / black_name).exists():
            return black_name
        return match.group(0)

    return pattern.sub(_swap, style_text)


def _make_light_toggle_style(style_text: str, is_active: bool = False) -> str:
    """Построить читаемый вариант светлой темы для стилей QToolButton панели инструментов зон."""
    result = _replace_white_icons_with_black(style_text)
    replacements = [
        ("color: white;", f"color: {LIGHT_TEXT_PRIMARY};"),
        ("color: #ffffff;", f"color: {LIGHT_TEXT_PRIMARY};"),
        ("border: 1px solid #555555;", f"border: 1px solid {LIGHT_BORDER};"),
        ("QToolButton:hover { background-color: #4a4a4a; }", f"QToolButton:hover {{ background-color: {LIGHT_HOVER}; }}"),
        ("QToolButton:pressed { background-color: #5a5a5a; }", f"QToolButton:pressed {{ background-color: {LIGHT_PRESSED}; }}"),
        ("background-color: #1f1f1f;", f"background-color: {LIGHT_PANEL};"),
        ("color: #7a7a7a;", f"color: {LIGHT_TEXT_SECONDARY};"),
        ("border: 1px solid #2a2a2a;", f"border: 1px solid {LIGHT_BORDER};"),
    ]
    for old, new in replacements:
        result = result.replace(old, new)

    if is_active:
        result = result.replace(
            "background-color: rgba(255, 255, 255, 0.3);",
            f"background-color: {LIGHT_ACCENT_SOFT};",
        )
        result = result.replace("border: 1px solid #cfcfcf;", f"border: 1px solid {LIGHT_ACCENT_BORDER};")
        result = result.replace("QToolButton:hover { background-color: #6a6a6a; }", "QToolButton:hover { background-color: #CFE1FF; }")
        result = result.replace("QToolButton:pressed { background-color: #7a7a7a; }", "QToolButton:pressed { background-color: #B3D4FF; }")
    else:
        result = result.replace("background-color: transparent;", f"background-color: {LIGHT_PANEL};")
    result = result.replace("color: #9a9a9a;", f"color: {LIGHT_TEXT_DISABLED};")
    result = result.replace("color: #1a1a1a;", f"color: {LIGHT_TEXT_PRIMARY};")
    return result


_ZONE_TOOL_TOGGLE_KEYS = (
    "MEASURE_TEXT_TOGGLE",
    "MEASURE_TEXT_TOGGLE_ACTIVE",
    "CREATE_ZONE_TOGGLE",
    "CREATE_ZONE_TOGGLE_ACTIVE",
    "DELETE_ZONE_TOGGLE",
    "DELETE_ZONE_TOGGLE_ACTIVE",
    "SELECT_ZONE_TOGGLE",
    "SELECT_ZONE_TOGGLE_ACTIVE",
    "EDIT_ZONE_TOGGLE",
    "EDIT_ZONE_TOGGLE_ACTIVE",
    "CREATE_NEW_MESH_TOGGLE",
    "CREATE_NEW_MESH_TOGGLE_ACTIVE",
    "USE_CURRENT_MESH_TOGGLE",
    "USE_CURRENT_MESH_TOGGLE_ACTIVE",
    "START_POINT_TOGGLE",
    "START_POINT_TOGGLE_ACTIVE",
    "REMEMBER_POINT_TOGGLE",
    "REMEMBER_POINT_TOGGLE_ACTIVE",
    "SET_GRID_STEP_TOGGLE",
    "SET_GRID_STEP_TOGGLE_ACTIVE",
    "CREATE_VOLUME_TOGGLE",
    "CREATE_VOLUME_TOGGLE_ACTIVE",
    "REMEMBER_VOLUME_TOGGLE",
    "REMEMBER_VOLUME_TOGGLE_ACTIVE",
    "MODEL_TOGGLE",
    "MODEL_TOGGLE_ACTIVE",
)

for _key in _ZONE_TOOL_TOGGLE_KEYS:
    _style = BUTTONS.get(_key)
    if _style:
        BUTTONS[f"{_key}_LIGHT"] = _make_light_toggle_style(
            _style,
            is_active=_key.endswith("_ACTIVE"),
        )


# ---------------------------------------------------------------------------
# Module workflow notes
# ---------------------------------------------------------------------------
#
# 1) Назначение модуля:
#    Определение всех стилей (QSS) для кнопок приложения: primary, secondary,
#    standard, tab, visualization, toggle-кнопки инструментов (measure, zone,
#    mesh, volume, model и др.) в тёмной и светлой темах. Содержит автогенерацию
#    светлых вариантов toggle-стилей через _make_light_toggle_style().
#
# 2) Зависимости модуля:
#    Импорты: Path (pathlib), re
#    Хост/базовый класс: нет (модуль-словарь)
#    Внешние библиотеки: нет (стандартная библиотека)
#
# 3) Экспорт:
#    Словарь BUTTONS: dict[str, str] — ключ → QSS-строка.
#    Константы цветов светлой темы: LIGHT_TEXT_PRIMARY, LIGHT_TEXT_SECONDARY,
#    LIGHT_TEXT_DISABLED, LIGHT_PANEL, LIGHT_BORDER, LIGHT_HOVER,
#    LIGHT_PRESSED, LIGHT_ACCENT_SOFT, LIGHT_ACCENT_BORDER.
#
# 4) Состояние (поля):
#    BUTTONS      : dict[str, str] — основной реестр стилей кнопок.
#    _ICONS_DIR   : Path — путь к gui/components/icons/ (для подстановки иконок).
#    _ZONE_TOOL_TOGGLE_KEYS: tuple[str] — ключи toggle-стилей для автогенерации.
#
# 5) Последовательность действий и вызовов:
#    1. Определение словаря BUTTONS с тёмными стилями.
#    2. _ICONS_DIR = Path → gui/components/icons/
#    3. _replace_white_icons_with_black(style_text) — regex-замена *_white.png
#       на *_black.png, если файл существует.
#    4. _make_light_toggle_style(style_text, is_active) — построение светлого
#       варианта toggle-стилей: замена цветов, бордюров, hover/pressed.
#    5. Цикл по _ZONE_TOOL_TOGGLE_KEYS: для каждого ключа создаётся
#       BUTTONS["{key}_LIGHT"] через _make_light_toggle_style().
#
# 6) Побочные эффекты:
#    Мутирует словарь BUTTONS при импорте модуля — добавляет *_LIGHT ключи.
#    Проверяет наличие файлов иконок через Path.exists() на этапе импорта.
#
# 7) Границы ответственности:
#    НЕ применяет стили к виджетам — только хранит QSS-строки.
#    НЕ взаимодействует с theme_bus — переключение темы в StylableMixin.
#    НЕ содержит стили для не-кнопочных виджетов.
#
# 8) Обработка ошибок:
#    _replace_white_icons_with_black: если чёрная иконка не найдена —
#    оригинальное имя сохраняется (fallback).
#    Нет исключений при отсутствии ключей в BUTTONS.get().
#
# 9) Инварианты и контракты:
#    - Каждый toggle-стиль имеет пару: KEY и KEY_ACTIVE.
#    - Автогенерированные светлые стили имеют суффикс _LIGHT.
#    - Все QSS-строки — валидный Qt StyleSheet синтаксис.
#
# 10) Правило сопровождения:
#     Новые toggle-стили добавлять в BUTTONS + в _ZONE_TOOL_TOGGLE_KEYS
#     для автогенерации светлого варианта. Иконки _white.png и _black.png
#     должны существовать парами в gui/components/icons/. При добавлении
#     non-toggle стилей — добавлять *_LIGHT вариант вручную.
