body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f5f5f5;
}

/* Chat window must always be above the backdrop */
.chat-container { z-index: 2147483647 !important; position: fixed; }
/* Extra specificity for the main site chat container */
#supportChat { z-index: 2147483647 !important; position: fixed !important; }

/* Mobile-only backdrop for support chat */
.chat-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2147483646; /* just below chat */
    opacity: 0;
    visibility: hidden;
    transition: opacity 200ms ease, visibility 0s linear 200ms;
    display: none; /* hidden on desktop */
    /* Do not intercept clicks unless explicitly opened */
    pointer-events: none;
    mix-blend-mode: normal;
}

@media (max-width: 768px) {
    .chat-backdrop { display: block; }
    body.chat-open { overflow: hidden; }
    /* Ensure chat window is not dimmed on mobile */
    .chat-container.open { opacity: 1 !important; filter: none !important; backdrop-filter: none !important; transform: none !important; }
    /* Cart icon and other floating UI: hide while chat is open to avoid overlap/taps */
    body.chat-open #cartIcon { z-index: 100 !important; display: none !important; }
    /* Extra guard: ensure the concrete instance is always on top */
    body.chat-open #supportChat { z-index: 999999999 !important; position: fixed !important; }
}

/* Keep chat above any site modal/backdrop (e.g., cart) and fully bright */
body.modal-open #supportChat,
body.modal-open .chat-container {
    position: fixed !important;
    z-index: 2147483647 !important;
    opacity: 1 !important;
    filter: none !important;
    backdrop-filter: none !important;
}

.chat-backdrop.open {
    opacity: 1;
    visibility: visible;
    transition: opacity 200ms ease, visibility 0s;
    /* Now backdrop becomes interactive to allow outside-tap-to-close */
    pointer-events: auto;
}

/* Visual-only dimming: show backdrop but do NOT capture clicks */
.chat-backdrop.dim {
    opacity: 1;
    visibility: visible;
    transition: opacity 200ms ease, visibility 0s;
    pointer-events: none;
}

.chat-container {
    max-width: 600px;
    margin: 20px auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    opacity: 0;
    transform: translateY(10px) scale(0.98);
    visibility: hidden;
    pointer-events: none;
    transition: opacity 220ms ease, transform 260ms ease, visibility 0s linear 260ms;
    /* Create a new stacking context that stays above most site UI */
    position: fixed;
    z-index: 2147483647;
}

.chat-container.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
    pointer-events: auto;
    transition: opacity 220ms ease, transform 260ms ease, visibility 0s;
    position: fixed !important; /* prevent any parent rules from overriding */
    z-index: 2147483647 !important; /* guarantee over the backdrop */
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #eee;
    background-color: #4a4a4a;
    color: white;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.chat-header h2 {
    margin: 0;
    font-size: 1.2em;
}

#closeChat {
    background: none;
    border: none;
    color: white;
    font-size: 1.5em;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#closeChat:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
}

.chat-messages {
    height: 400px;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.message {
    max-width: 80%;
    padding: 10px 15px;
    margin-bottom: 10px;
    border-radius: 18px;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background-color: #4a4a4a;
    color: white;
}

.message.admin {
    align-self: flex-start;
    background-color: #f1f1f1;
    color: #333;
}

.message-info {
    font-size: 0.8em;
    opacity: 0.7;
    margin-top: 5px;
}

.chat-input {
    display: flex;
    padding: 15px;
    border-top: 1px solid #eee;
}

#messageInput {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 18px;
    resize: none;
    height: 40px;
    box-sizing: border-box;
}

#sendMessage {
    margin-left: 10px;
    padding: 10px 20px;
    background-color: #4a4a4a;
    color: white;
    border: none;
    border-radius: 18px;
    cursor: pointer;
}

#sendMessage:hover {
    background-color: #333;
}

#sendMessage:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* Плавающая кнопка поддержки */
.support-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #b9825a;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    user-select: none;
    animation: float 4s ease-in-out infinite;
}

.support-button:hover {
    background-color: #a67449;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.support-button svg {
    width: 24px;
    height: 24px;
}

/* Красный бейдж со счётчиком */
.support-button .support-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #ff3b30;
    color: #fff;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 0 0 2px #fff;
    font-weight: 700;
}

/* Пульсация при непрочитанных */
.support-button.has-unread {
    animation: float 4s ease-in-out infinite, pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(185, 130, 90, 0.45); }
    70% { box-shadow: 0 0 0 14px rgba(185, 130, 90, 0); }
    100% { box-shadow: 0 0 0 0 rgba(185, 130, 90, 0); }
}

@keyframes float {
    0% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
    100% { transform: translateY(0); }
}

/* Адаптация чата для интеграции */
.chat-container {
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.chat-container .chat-header {
    background-color: #b9825a;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.chat-container .chat-header:hover {
    background-color: #a67449;
}

/* Форма регистрации */
.registration-form {
    font-family: 'Open Sans', sans-serif;
}

.registration-form h2 {
    margin-top: 0;
    color: #333;
    text-align: center;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}

.form-group input:focus {
    outline: none;
    border-color: #b9825a;
    box-shadow: 0 0 0 2px rgba(185, 130, 90, 0.2);
}

.registration-form button {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s;
}

.registration-form button[type="submit"] {
    background-color: #b9825a;
    color: white;
}

.registration-form button[type="submit"]:hover {
    background-color: #a67449;
}

.registration-form button[type="button"] {
    background-color: #f0f0f0;
    color: #333;
}

.registration-form button[type="button"]:hover {
    background-color: #e0e0e0;
}
