#ai-gw {
    position: fixed;
    bottom: 52px;
    right: 12px;
    z-index: 9999;
    width: 40px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#ai-gw-toggle-wrap {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(22, 32, 48, 0.95);
    border: 1px solid rgba(102, 192, 244, 0.18);
    border-radius: 24px;
    padding: 10px 0 12px;
    cursor: pointer;
    user-select: none;
    width: 40px;
    box-shadow: -3px 0 16px rgba(0, 0, 0, 0.35);
    gap: 6px;
    transition: background 0.2s, border-color 0.2s;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#ai-gw-toggle-wrap:hover {
    background: rgba(30, 48, 72, 0.98);
    border-color: rgba(102, 192, 244, 0.35);
}

#ai-gw-toggle {
    background: linear-gradient(135deg, #6e8efb 0%, #4a6cf7 100%);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(74, 108, 247, 0.5);
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

#ai-gw-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(74, 108, 247, 0.65);
}

#ai-gw-label {
    color: #c7d5e0;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    line-height: 1.8;
    white-space: pre-line;
    cursor: pointer;
    transition: color 0.2s;
    letter-spacing: 0.05em;
}

#ai-gw-toggle-wrap:hover #ai-gw-label {
    color: #66c0f4;
}

#ai-gw-panel {
    display: none;
    position: absolute;
    right: 52px;
    bottom: 0;
    flex-direction: column;
    width: 360px;
    height: 460px;
    background: linear-gradient(180deg, #1a2633 0%, #141d27 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 60px rgba(0, 0, 0, 0.3);
    margin: 0;
    overflow: hidden;
}

#ai-gw-panel.open {
    display: flex;
}

#ai-gw-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(102, 192, 244, 0.15) 0%, rgba(74, 144, 226, 0.1) 100%);
    border-bottom: 1px solid rgba(102, 192, 244, 0.2);
    color: #ffffff;
    font-weight: 600;
    font-size: 15px;
}

#ai-gw-header-btns {
    display: flex;
    align-items: center;
    gap: 4px;
}

#ai-gw-close,
#ai-gw-clear {
    background: transparent;
    border: none;
    color: #9aa7b4;
    font-size: 15px;
    cursor: pointer;
    opacity: 0.8;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

#ai-gw-close:hover,
#ai-gw-clear:hover {
    opacity: 1;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

#ai-gw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(0, 0, 0, 0.15);
}

#ai-gw-messages::-webkit-scrollbar {
    width: 6px;
}

#ai-gw-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

#ai-gw-messages::-webkit-scrollbar-thumb {
    background: #2a475e;
    border-radius: 3px;
}

#ai-gw-messages::-webkit-scrollbar-thumb:hover {
    background: #3c5a78;
}

.ai-gw-msg {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.55;
    max-width: 85%;
    word-break: break-word;
    white-space: pre-wrap;
}

.ai-gw-msg.user {
    background: linear-gradient(135deg, #3a78b4 0%, #2a5a8f 100%);
    align-self: flex-end;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(58, 120, 180, 0.3);
}

.ai-gw-msg.ai {
    background: linear-gradient(135deg, rgba(58, 120, 180, 0.12) 0%, rgba(10, 15, 20, 0) 100%);
    border: 1px solid rgba(58, 120, 180, 0.2);
    align-self: flex-start;
    color: #c7d5e0;
}

.ai-gw-sources {
    margin-top: 8px;
    font-size: 12px;
    color: #9aa7b4;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.ai-gw-sources a {
    color: #66c0f4;
    text-decoration: none;
}

.ai-gw-sources a:hover {
    text-decoration: underline;
}

#ai-gw-footer {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.2);
}

#ai-gw-input {
    flex: 1;
    border: 1px solid rgba(58, 120, 180, 0.25);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 14px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(0, 0, 0, 0.1));
    color: #c7d5e0;
    outline: none;
    transition: all 0.2s;
}

#ai-gw-input:focus {
    border-color: rgba(102, 192, 244, 0.5);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.15));
    box-shadow: 0 0 12px rgba(102, 192, 244, 0.15);
}

#ai-gw-input::placeholder {
    color: #7a8fa3;
}

#ai-gw-send {
    background: linear-gradient(90deg, #66c0f4 0%, #4a90e2 100%);
    color: #1b2838;
    border: none;
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(102, 192, 244, 0.25);
}

#ai-gw-send:hover {
    background: linear-gradient(90deg, #5aadf0 0%, #3a80d2 100%);
    box-shadow: 0 4px 12px rgba(102, 192, 244, 0.35);
}

#ai-gw-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}

.ai-gw-msg.ai-gw-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #9aa7b4;
    font-style: italic;
    white-space: normal;
    background: transparent;
    border: none;
}

.ai-gw-status-text {
    color: #66c0f4;
}

.ai-gw-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

.ai-gw-dots span {
    width: 6px;
    height: 6px;
    background: #66c0f4;
    border-radius: 50%;
    animation: ai-gw-bounce 1.2s infinite ease-in-out;
}

.ai-gw-dots span:nth-child(1) {
    animation-delay: 0s;
}

.ai-gw-dots span:nth-child(2) {
    animation-delay: 0.18s;
}

.ai-gw-dots span:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes ai-gw-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.ai-gw-msg.ai-gw-tool-call {
    background: linear-gradient(135deg, rgba(102, 192, 244, 0.08) 0%, rgba(74, 144, 226, 0.05) 100%);
    border: 1px solid rgba(102, 192, 244, 0.3);
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
    padding: 0;
    overflow: hidden;
}

.tool-call-header {
    padding: 10px 14px 6px;
    font-size: 13px;
    color: #66c0f4;
    border-bottom: 1px solid rgba(102, 192, 244, 0.15);
}

.tool-call-header strong {
    color: #ffffff;
}

.tool-call-args {
    margin: 0;
    padding: 10px 14px 12px;
    font-size: 12px;
    color: #9aa7b4;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 8px 8px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.ai-gw-msg.ai-gw-tool-result {
    background: linear-gradient(135deg, rgba(46, 160, 67, 0.08) 0%, rgba(35, 120, 55, 0.05) 100%);
    border: 1px solid rgba(46, 160, 67, 0.25);
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
    padding: 0;
    overflow: hidden;
}

.tool-result-header {
    padding: 8px 14px 6px;
    font-size: 13px;
    color: #2ea043;
    border-bottom: 1px solid rgba(46, 160, 67, 0.15);
}

.tool-result-header strong {
    color: #ffffff;
}

.tool-result-content {
    padding: 10px 14px 12px;
    font-size: 12px;
    color: #9aa7b4;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-gw-msg.ai-gw-thinking {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #9aa7b4;
    font-style: italic;
    white-space: normal;
    background: transparent;
    border: none;
}

.thinking-text {
    color: #66c0f4;
}