/* --- Загальні стилі та змінні --- */
:root {
    --aib-primary: #006666;
    --aib-secondary: #03b3a8;
    --aib-accent: #34B2D0;
    --aib-grey: #6c757d;
    --aib-dark-grey: #343a40;
}

/* =================================================================== */
/* --- СТИЛІ ДЛЯ СТОРІНКИ АВТОРА (UI КОНСТРУКТОРА) --- */
/* =================================================================== */
.ai-bot-container { max-width: 100%; margin: 0px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; font-size: 15px; }
.aib-card { background: #fff; border: 1px solid #e0e0e0; padding: 20px 25px; margin-bottom: 25px; border-radius: 0; box-shadow: none; }

.aib-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
    margin-bottom: 20px;
}
.aib-card-header h3 {
    margin: 0;
    border: none;
    padding: 0;
    color: var(--aib-primary);
    font-size: 20px;
}
.aib-card-header h3 i { color: var(--aib-accent); margin-right: 10px; }
.bot-count-indicator {
    font-size: 14px;
    font-weight: 500;
    color: var(--aib-grey);
    background-color: #f0f4f8;
    padding: 5px 10px;
    border-radius: 4px;
}

.aib-card-centered-action { text-align: center; padding: 30px; }

#ai-bot-form .form-group { margin-bottom: 18px; }
#ai-bot-form .form-group label { display: block; margin-bottom: 8px; font-weight: 500; }
#ai-bot-form .form-group .form-subtitle { font-size: 13px; color: #777; margin-top: 5px; margin-bottom: 8px; }
#ai-bot-form input[type=text], 
#ai-bot-form input[type=number], 
#ai-bot-form textarea,
#ai-bot-form .aib-select { 
    width: 100%; 
    padding: 12px 15px; 
    border: none; 
    background-color: #efefef; 
    box-sizing: border-box; 
    transition: all .2s; 
    border-radius: 0; 
    font-size: 15px;
}
#ai-bot-form .aib-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 16px 12px;
}
#ai-bot-form input[type=text]:focus, 
#ai-bot-form input[type=number]:focus, 
#ai-bot-form textarea:focus,
#ai-bot-form .aib-select:focus { 
    background-color: #e5e5e5; 
    box-shadow: none; 
    outline: 0; 
}
#ai-bot-form input[type="color"] {
    width: 100%;
    height: 49px;
    padding: 5px;
    border: none;
    background-color: #efefef;
    cursor: pointer;
    box-sizing: border-box;
}

.form-buttons { display: flex; gap: 10px; align-items: center; margin-top: 20px; }
.aib-button-prominent, .aib-button-secondary { border: none; cursor: pointer; padding: 10px 20px; font-size: 15px; font-weight: 700; transition: all .3s; color: #fff; border-radius: 0; display: inline-flex; align-items: center; justify-content: center; }
.aib-button-prominent { background-color: var(--aib-accent); }
.aib-button-prominent:hover { background-color: #2a9ab4; }
.aib-button-secondary { background-color: var(--aib-grey); }
.aib-button-secondary:hover { background-color: #5a6268; }
.aib-button-disabled, .aib-button-prominent:disabled {
    background-color: #ccc !important;
    cursor: not-allowed !important;
    opacity: 0.8;
}

.aib-button-prominent i, .aib-button-secondary i { margin-right: 8px; }
label.aib-button-secondary { font-size: 14px; padding: 8px 15px; }
.aib-button-as-link { background: transparent; border: none; color: var(--aib-grey); cursor: pointer; padding: 0; font-size: 14px; font-weight: normal; text-decoration: underline; transition: color 0.2s; }
.aib-button-as-link:hover { color: var(--aib-dark-grey); }
.avatar-upload-wrapper { display: flex; align-items: center; gap: 15px; }
.avatar-preview { width: 80px; height: 80px; background-color: #efefef; border: 2px dashed #ccc; border-radius: 50%; background-size: cover; background-position: center; display: flex; align-items: center; justify-content: center; text-align: center; color: #888; font-size: 12px; flex-shrink: 0; }
.avatar-upload-actions { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
#saved-bots-list ul { list-style: none; padding: 0; margin: 0; }
.saved-bot-item { display: flex; justify-content: space-between; align-items: flex-start; padding: 15px 5px; border-bottom: 1px solid #eee; flex-wrap: wrap; gap: 10px; }
.saved-bot-item:last-child { border-bottom: none; }
.saved-bot-main-info { display: flex; flex-direction: column; gap: 8px; flex-grow: 1; }
.saved-bot-name { font-weight: 500; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.bot-role-icon {
    font-size: 16px;
    color: var(--aib-primary);
    cursor: help;
    width: 20px;
    text-align: center;
}
.saved-bot-stats { display: flex; align-items: center; gap: 15px; font-size: 12px; color: #777; flex-wrap: wrap;}
.saved-bot-stats i { color: var(--aib-accent); margin-right: -10px; }
.saved-bot-controls { display: flex; align-items: center; gap: 15px; flex-shrink: 0; }
.saved-bot-actions { display: flex; gap: 5px; }
.saved-bot-actions .action-btn { background: 0 0; border: 1px solid #ccc; cursor: pointer; padding: 5px 8px; color: #555; transition: all .2s; display: inline-block; line-height: 1; border-radius: 0; }
.saved-bot-actions .action-btn:hover { background-color: #e9e9e9; color: #000; }
.saved-bot-actions .action-btn:disabled i { color: var(--aib-secondary); }
.saved-bots-loader { color: #777; }
.access-toggle { display: flex; align-items: center; gap: 8px; }
.access-label { font-size: 13px; color: #666; width: 60px; }
.aib-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.aib-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; }
input:checked + .slider { background-color: var(--aib-secondary); }
input:checked + .slider:before { transform: translateX(20px); }
.slider.round { border-radius: 24px; }
.slider.round:before { border-radius: 50%; }
.limit-box-wrapper { margin-bottom: 25px; }
.limit-info-box { border: 1px solid var(--aib-secondary); background-color: rgba(3,179,168,.05); padding: 15px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 15px; font-size: 15px; border-radius: 0; }
.limit-info-box strong { font-weight: 500; }
.limit-info-box small { color: #777; font-size: 13px; }
.limit-info-box a#increase-limit-link { color: var(--aib-primary); text-decoration: underline; cursor: pointer; font-weight: 500; margin-left: auto; }
.aib-info-details { background: #f8f9fa; border: 1px solid #e0e0e0; border-top: none; padding: 15px; margin-top: 0; border-radius: 0; }
.limit-exceeded-notice { background-color: rgba(220,53,69,.1); color: #721c24; border-left: 3px solid #dc3545; padding: 15px; margin-bottom: 20px; font-weight: 700; text-align: center; border-radius: 0; }

.aib-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: end;
}
.aib-form-row + .form-subtitle {
    margin-top: 0;
}
.aib-form-row .form-group {
    margin-bottom: 0;
}

@media (max-width: 600px) {
    .limit-info-box { flex-direction: column; align-items: flex-start; gap: 8px; }
    .limit-info-box a#increase-limit-link { margin-left: 0; margin-top: 5px; }
    .aib-form-row {
        grid-template-columns: 1fr;
        gap: 18px;
    }
}
.loader-container { display: flex; align-items: center; gap: 10px; color: var(--aib-primary); font-size: 14px; }
.loader-spinner { border: 3px solid rgba(0,102,102,.2); border-top-color: var(--aib-primary); border-radius: 50%; width: 20px; height: 20px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- СТИЛІ ДЛЯ СТОРІНКИ ЧАТУ --- */
html.aib-html-active,
body.aib-chat-page-active {
    overflow: hidden;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}
#ai-bot-chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    margin: 0;
    background-color: var(--aib-bg-color);
}
body.admin-bar #ai-bot-chat-container {
    height: calc(100vh - 32px);
    height: calc(100dvh - 32px);
}
@media screen and (max-width: 782px) {
    body.admin-bar #ai-bot-chat-container {
        height: calc(100vh - 46px);
        height: calc(100dvh - 46px);
    }
}
.chat-header {
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background-color: var(--aib-header-bg);
    color: #fff;
    gap: 15px;
}
#chat-body {
    flex-grow: 1;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
#chat-messages {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px;
}
.chat-footer {
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    border-top: 1px solid rgba(0,0,0,0.1);
    padding: 10px 15px;
    background-color: var(--aib-bg-color);
}
.chat-bot-info { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.chat-header .chat-avatar { width: 62px; height: 62px; flex-shrink: 0; background-color: var(--aib-accent); display: flex; align-items: center; justify-content: center; border-radius: 50%; overflow: hidden; border: 2px solid #fff; }
.chat-header .chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-header .chat-avatar i { font-size: 30px; color: #fff; }
.chat-header h1 { font-size: 18px; line-height: 1.3; margin: 0; padding: 0px; font-weight: 600; text-align: left; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chat-actions { display: flex; gap: 12px; }
.chat-action-btn { background: transparent; border: none; color: rgba(255,255,255,0.7); font-size: 18px; cursor: pointer; transition: color 0.2s; padding: 5px; }
.chat-action-btn:hover { color: #fff; background: transparent;  }
.chat-action-btn:disabled { color: var(--aib-secondary); cursor: default; }
.chat-message-wrapper { display: flex; gap: 10px; max-width: 80%; align-items: flex-end; }
.message-bubble { padding: 12px 18px; border-radius: 20px; line-height: 1.5; border: 1px solid rgba(0,0,0,0.05); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.message-content { word-wrap: break-word; }
.message-content code { background: rgba(0,0,0,0.07); padding: 2px 5px; border-radius: 4px; font-family: monospace; }
.message-from-model { align-self: flex-start; }
.message-from-model .message-bubble { background-color: var(--aib-bot-bubble-bg); color: var(--aib-bot-text-color); border-bottom-left-radius: 5px; }
.message-from-user { align-self: flex-end; flex-direction: row-reverse; }
.message-from-user .message-bubble { background-color: var(--aib-user-bubble-bg); color: var(--aib-user-text-color); border-bottom-right-radius: 5px; }
.message-avatar { width: 40px; height: 40px; background-color: var(--aib-accent); display: flex; align-items: center; justify-content: center; border-radius: 50%; overflow: hidden; flex-shrink: 0; }
.message-avatar img { width: 100%; height: 100%; object-fit: cover; }
.message-avatar i { font-size: 20px; color: #fff; }
.message-from-user .message-avatar { background-color: var(--aib-grey); }
.message-from-system-error {width: 100%; max-width: 100%; }
.message-from-system-error .message-bubble { background-color: #ffebee; color: #c62828; text-align: center; width: 100%; }
.user-limit-counter {
    text-align: center;
    font-size: 12px;
    color: #666;
    padding-bottom: 8px;
}
#chat-form { display: flex; align-items: flex-end; gap: 10px; }
#chat-input {
    flex-grow: 1;
    padding: 12px 18px;
    border: 1px solid #ccc;
    border-radius: 24px;
    resize: none;
    font-size: 16px;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: hidden;
    background-color: #fff;
}
#send-btn, #voice-input-btn { width: 48px; height: 48px; border-radius: 50%; border: none; background-color: var(--aib-accent); color: #fff; cursor: pointer; transition: all .2s; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; }
#send-btn:hover, #voice-input-btn:hover { background-color: #2a9ab4; }
#send-btn:disabled { background-color: #ccc; cursor: not-allowed; }
#voice-input-btn.is-listening { background-color: #f27a10; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(242, 122, 16, .7); } 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
#typing-indicator .typing-dots span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background-color: grey; margin: 0 2px; animation: typing-bounce 1.4s infinite ease-in-out both; }
#typing-indicator .typing-dots span:nth-child(1) { animation-delay: -.32s; }
#typing-indicator .typing-dots span:nth-child(2) { animation-delay: -.16s; }
@keyframes typing-bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }
.aib-error-msg-wrapper { max-width: 100%; margin: 0; text-align: center; background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; padding: 40px 20px; border-radius: 0; box-shadow: none; }
.aib-error-icon { font-size: 50px; margin-bottom: 20px; }
.aib-error-msg-wrapper h3 { font-size: 24px; color: #721c24; margin: 0 0 10px 0; }
.aib-error-msg-wrapper p { color: #721c24; font-size: 16px; line-height: 1.6; }
.mobile-avatar-banner { display: none; }
@media (max-width: 600px) {
    .mobile-avatar-banner { display: block; text-align: center; flex-shrink: 0; transition: all 0.3s ease-in-out; }
    .mobile-avatar-banner-img {
        width: 50%;
        max-width: 200px;
        height: auto;
        aspect-ratio: 1 / 1;
        object-fit: cover;
        border-radius: 50%;
        border: 4px solid var(--aib-header-bg);
        box-shadow: 0 4px 15px rgba(0,0,0,0.15);
        transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
        cursor: pointer;
    }
    .mobile-avatar-banner-img.zoomed {
        width: 95%;
        max-width: 95%;
        border-radius: 24px;
        box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    }
    #ai-bot-chat-container:not(.chat-is-active) .mobile-avatar-banner { padding-bottom: 20px; }
    #ai-bot-chat-container:not(.chat-is-active) #chat-body { justify-content: center; }
    #ai-bot-chat-container:not(.chat-is-active) #chat-messages { padding-top: 0; }
    #ai-bot-chat-container.chat-is-active .mobile-avatar-banner { padding: 20px 0 10px 0; }
    #ai-bot-chat-container.chat-is-active .mobile-avatar-banner-img {
        width: 35%;
        max-width: 120px;
    }
     #ai-bot-chat-container.chat-is-active .mobile-avatar-banner-img.zoomed {
        width: 95%;
        max-width: 95%;
    }
    .chat-header .chat-avatar { display: none; }
    .chat-header { padding: 10px 15px; }
    .chat-header h1 { font-size: 16px; }
    #chat-input { max-height: 90px; }
    .chat-message-wrapper { max-width: 90%; }
}
.aib-qr-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 15px; box-sizing: border-box; }
.aib-qr-modal.show { display: flex; }
.aib-qr-modal-content { background: #fff; padding: 25px; border-radius: 8px; text-align: center; position: relative; box-shadow: 0 5px 15px rgba(0,0,0,0.3); max-width: 320px; width: 100%; box-sizing: border-box; }
.aib-qr-modal-close { position: absolute; top: 5px; right: 12px; font-size: 28px; font-weight: bold; color: #999; cursor: pointer; line-height: 1; transition: color 0.2s; }
.aib-qr-modal-close:hover { color: #333; }
.aib-qr-modal-content img { display: block; width: 100%; max-width: 250px; height: auto; margin: 10px auto 20px auto; border-radius: 4px; background: #f1f1f1; }
.aib-qr-modal-content p { margin: 0 0 10px 0; font-size: 15px; color: #333; }
.aib-qr-modal-link { font-size: 12px; color: #777; word-break: break-all; background-color: #f0f0f0; padding: 5px 8px; border-radius: 4px; display: block; }