/* style.css - с улучшенной адаптивностью и безопасностью */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

.chat-container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
    height: 90vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    text-align: center;
    flex-shrink: 0;
}

.chat-header h2 {
    font-size: 24px;
    margin-bottom: 5px;
    font-weight: 600;
}

.chat-header p {
    opacity: 0.9;
    font-size: 14px;
    font-weight: 300;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    -webkit-overflow-scrolling: touch;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #5a67d8;
}

.message {
    margin-bottom: 15px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.bot-message {
    align-self: flex-start;
}

.user-message {
    align-self: flex-end;
    margin-left: auto;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    background: white;
    border: 1px solid #e0e0e0;
    font-size: 15px;
}

.user-message .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 5px;
    text-align: right;
    font-weight: 300;
}

.bot-message .message-time {
    text-align: left;
}

/* МАЛЕНЬКИЕ КНОПКИ С ИКОНКАМИ */
.quick-buttons {
    padding: 10px 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-top: 1px solid #eee;
    background: white;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.quick-btn-icon {
    width: 45px;
    height: 45px;
    min-width: 45px;
    max-width: 45px;
    padding: 0;
    background: white;
    border: 2px solid #667eea;
    border-radius: 50%;
    color: #667eea;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-sizing: border-box;
    position: relative;
    outline: none;
    touch-action: manipulation;
}

.quick-btn-icon:hover,
.quick-btn-icon:focus {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.quick-btn-icon:active {
    transform: translateY(0);
}

.quick-btn-icon:hover::after {
    content: attr(title);
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
    font-weight: 500;
}

.quick-btn-icon:hover::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    pointer-events: none;
}

/* Большие кнопки для сообщений */
.quick-btn {
    flex: 1 0 30%;
    min-width: 30%;
    max-width: 32%;
    padding: 12px 8px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 12px;
    color: #667eea;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 60px;
    box-sizing: border-box;
    outline: none;
    touch-action: manipulation;
    font-weight: 500;
}

.quick-btn:hover,
.quick-btn:focus {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.quick-btn:active {
    transform: translateY(0);
}

.quick-btn i {
    font-size: 16px;
    margin-bottom: 5px;
}

/* КНОПКИ МЕССЕНДЖЕРОВ */
.contact-section {
    margin-bottom: 15px;
}

.contact-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.contact-link:hover,
.contact-link:focus {
    color: #5a67d8;
    text-decoration: underline;
    outline: none;
}

.messenger-btn {
    flex: 1;
    min-width: 120px;
    padding: 10px 15px;
    border: none;
    border-radius: 10px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 14px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    touch-action: manipulation;
}

.messenger-btn i {
    font-size: 18px;
}

.messenger-btn.whatsapp {
    background: #25D366;
}

.messenger-btn.telegram {
    background: #0088cc;
}

.messenger-btn.messenger {
    background: #006AFF;
}

.messenger-btn:hover,
.messenger-btn:focus {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    opacity: 0.9;
}

.messenger-btn:active {
    transform: translateY(0);
}

.chat-input {
    padding: 20px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    background: white;
    flex-shrink: 0;
}

#messageInput {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.3s;
    min-width: 0;
}

#messageInput:focus {
    border-color: #667eea;
}

#sendButton {
    width: 50px;
    height: 50px;
    background: #667eea;
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    touch-action: manipulation;
}

#sendButton:hover,
#sendButton:focus {
    background: #5a67d8;
    transform: scale(1.05);
}

#sendButton:active {
    transform: scale(0.95);
}

#voiceButton {
    width: 50px;
    height: 50px;
    background: #f8f9fa;
    border: 2px solid #e0e0e0;
    border-radius: 50%;
    color: #667eea;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s;
    display: none;
    align-items: center;
    justify-content: center;
    outline: none;
    touch-action: manipulation;
}

#voiceButton:hover,
#voiceButton:focus {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* КАТЕГОРИИ И УСЛУГИ */
.categories-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(30%, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.category-item {
    padding: 15px 10px;
    background: white;
    border-radius: 12px;
    border: 2px solid #667eea;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 70px;
    outline: none;
    touch-action: manipulation;
}

.category-item:hover,
.category-item:focus {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.category-item:active {
    transform: translateY(0);
}

.category-name {
    font-weight: 600;
    color: #667eea;
    font-size: 15px;
    word-break: break-word;
    line-height: 1.3;
}

.category-item:hover .category-name,
.category-item:focus .category-name {
    color: white;
}

.services-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(30%, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.service-item {
    padding: 12px 10px;
    background: white;
    border-radius: 10px;
    border: 1px solid #e0e0e0;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    min-height: 80px;
    outline: none;
    touch-action: manipulation;
}

.service-item:hover,
.service-item:focus {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.service-item:active {
    transform: translateY(0);
}

.service-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
    font-size: 14px;
    line-height: 1.3;
    word-break: break-word;
    flex-grow: 1;
}

.service-category {
    font-size: 11px;
    color: #666;
    background: #f0f0f0;
    padding: 3px 6px;
    border-radius: 10px;
    display: inline-block;
    align-self: flex-start;
    margin-top: auto;
    font-weight: 500;
}

/* ЗАГОЛОВКИ СУБКАТЕГОРИЙ */
.subcategory-header {
    font-size: 16px;
    font-weight: 600;
    color: #444;
    margin: 20px 0 10px 0;
    padding-bottom: 5px;
    border-bottom: 2px solid #667eea;
    grid-column: 1 / -1;
}

/* МОДАЛЬНЫЕ ОКНА */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}

.modal-header h3 {
    margin: 0;
    color: #333;
    font-weight: 600;
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s;
    outline: none;
}

.modal-close:hover,
.modal-close:focus {
    color: #333;
    background: #f0f0f0;
}

.modal-body {
    padding: 20px;
}

/* ФОРМЫ */
.form-group {
    margin-bottom: 15px;
}

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

.form-control {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.3s;
    font-family: inherit;
}

.form-control:focus {
    border-color: #667eea;
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    outline: none;
    touch-action: manipulation;
}

.btn:hover,
.btn:focus {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover,
.btn-primary:focus {
    background: linear-gradient(135deg, #5a67d8 0%, #6c4d91 100%);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background: #5a6268;
}

/* АНИМАЦИИ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* МОБИЛЬНАЯ АДАПТАЦИЯ */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .chat-container {
        height: 95vh;
        border-radius: 15px;
    }
    
    /* КАТЕГОРИИ - 3 в ряд */
    .categories-list {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    .services-list {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    .category-item {
        min-height: 60px;
        padding: 10px 5px;
        border-radius: 10px;
    }
    
    .service-item {
        min-height: 70px;
        padding: 10px 5px;
    }
    
    .category-name {
        font-size: 13px;
    }
    
    .service-name {
        font-size: 12px;
    }
    
    /* Маленькие кнопки-иконки */
    .quick-btn-icon {
        width: 40px;
        height: 40px;
        min-width: 40px;
        max-width: 40px;
        font-size: 16px;
    }
    
    .quick-buttons {
        padding: 8px 10px;
        gap: 6px;
    }
    
    /* Кнопки мессенджеров */
    .messenger-btn {
        flex: 1 0 48%;
        min-width: 48%;
        margin-bottom: 5px;
        font-size: 13px;
    }
    
    .modal-content {
        width: 95%;
        max-width: 95%;
    }
    
    .chat-header {
        padding: 15px;
    }
    
    .chat-header h2 {
        font-size: 20px;
    }
    
    .chat-messages {
        padding: 15px;
    }
    
    .subcategory-header {
        font-size: 15px;
        margin: 15px 0 8px 0;
    }
}

@media (max-width: 600px) {
    /* На узких экранах - 2 в ряд */
    .categories-list {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .services-list {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .category-item {
        min-height: 65px;
    }
    
    .service-item {
        min-height: 75px;
    }
    
    .quick-btn {
        flex: 1 0 45%;
        min-width: 45%;
        max-width: 48%;
    }
}

@media (max-width: 480px) {
    /* На маленьких экранах */
    .quick-btn-icon {
        width: 38px;
        height: 38px;
        min-width: 38px;
        max-width: 38px;
        font-size: 15px;
    }
    
    .quick-buttons {
        padding: 6px 8px;
        gap: 5px;
    }
    
    /* КАТЕГОРИИ - 3 в ряд */
    .categories-list {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }
    
    .services-list {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }
    
    .category-item {
        min-height: 55px;
        padding: 8px 4px;
    }
    
    .category-name {
        font-size: 12px;
    }
    
    .service-item {
        min-height: 65px;
        padding: 8px 4px;
    }
    
    .service-name {
        font-size: 11px;
    }
    
    .subcategory-header {
        font-size: 14px;
        margin: 12px 0 6px 0;
    }
    
    /* Кнопки мессенджеров по 100% */
    .messenger-btn {
        flex: 1 0 100%;
        min-width: 100%;
        padding: 8px 12px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .message-content {
        padding: 10px 12px;
        font-size: 14px;
    }
}

@media (max-width: 360px) {
    /* На очень маленьких экранах - 2 в ряд */
    .categories-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 5px;
    }
    
    .services-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 5px;
    }
    
    .category-item {
        min-height: 50px;
        padding: 6px 3px;
    }
    
    .category-name {
        font-size: 11px;
    }
    
    .service-item {
        min-height: 60px;
        padding: 6px 3px;
    }
    
    .service-name {
        font-size: 10px;
    }
    
    .subcategory-header {
        font-size: 13px;
        margin: 10px 0 5px 0;
    }
    
    .quick-btn {
        flex: 1 0 100%;
        min-width: 100%;
        max-width: 100%;
    }
}

/* Для устройств без поддержки hover */
@media (hover: none) and (pointer: coarse) {
    .quick-btn-icon:hover::after,
    .quick-btn-icon:hover::before {
        display: none;
    }
    
    .quick-btn:active,
    .category-item:active,
    .service-item:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    .modal-close:active {
        background: #f0f0f0;
    }
}

/* Оптимизация для слабых устройств */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}


/* СТИЛИ ДЛЯ ФОРМЫ ОБРАТНОГО ЗВОНКА */
#callbackForm {
    animation: fadeIn 0.3s ease;
}

#callbackForm .form-control {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.3s;
    font-family: inherit;
}

#callbackForm .form-control:focus {
    border-color: #667eea;
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#callbackForm textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

#callbackForm label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-weight: 500;
    font-size: 14px;
}

#callbackForm .form-error {
    padding: 10px;
    background: #fee;
    border: 1px solid #fcc;
    border-radius: 6px;
    color: #c00;
    font-size: 14px;
    margin-top: 10px;
}

#callbackForm .form-error i {
    margin-right: 8px;
}

/* Адаптивность для формы */
@media (max-width: 768px) {
    #callbackForm {
        gap: 10px;
    }
    
    #callbackForm .form-control {
        padding: 10px 12px;
        font-size: 14px;
    }
    
    #callbackForm textarea.form-control {
        min-height: 90px;
    }
}

@media (max-width: 480px) {
    #callbackForm {
        gap: 8px;
    }
    
    #callbackForm .form-control {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    #callbackForm textarea.form-control {
        min-height: 80px;
    }
}



/* СТИЛИ ДЛЯ ФОРМЫ ОБРАТНОГО ЗВОНКА С СОГЛАШЕНИЕМ */
#callbackForm .agreement-section {
    margin: 10px 0;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
}

#callbackForm .agreement-label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    margin: 0;
}

#callbackForm .agreement-checkbox {
    margin-top: 3px;
    margin-right: 10px;
    flex-shrink: 0;
}

#callbackForm .agreement-text {
    font-size: 13px;
    line-height: 1.4;
}

#callbackForm .agreement-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

#callbackForm .agreement-link:hover {
    text-decoration: underline;
}

/* Адаптивность для соглашения */
@media (max-width: 768px) {
    #callbackForm .agreement-section {
        padding: 8px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    #callbackForm .agreement-section {
        padding: 6px;
        font-size: 11px;
    }
    
    #callbackForm .agreement-text {
        font-size: 11px;
        line-height: 1.3;
    }
}

/* СТИЛИ ДЛЯ КАСТОМНОГО СЕЛЕКТА ВИДА СВЯЗИ */
.contact-type-selector {
    position: relative;
}

.nice-select {
    position: relative;
    cursor: pointer;
}

.nice-select .current {
    display: block;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
    transition: border-color 0.3s;
    position: relative;
}

.nice-select .current::after {
    content: '▼';
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: #666;
}

.nice-select.open .current::after {
    transform: translateY(-50%) rotate(180deg);
}

.nice-select .list {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-top: 5px;
    padding: 0;
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.nice-select.open .list {
    display: block;
}

.nice-select .option {
    padding: 10px 15px;
    cursor: pointer;
    list-style: none;
    transition: background-color 0.2s;
}

.nice-select .option:hover {
    background-color: #f8f9fa;
}

.nice-select .option.selected {
    background-color: #667eea;
    color: white;
}

/* Адаптивность для селекта */
@media (max-width: 768px) {
    .nice-select .current {
        padding: 10px 12px;
        font-size: 14px;
    }
    
    .nice-select .option {
        padding: 8px 12px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .nice-select .current {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .nice-select .option {
        padding: 6px 10px;
        font-size: 13px;
    }
}