/**
 * AI Chat Widget Styles
 * 
 * UIKit-compatible styling for the chat widget.
 * Modern, clean design with smooth animations.
 */

/* Widget container */
.ai-chat-widget {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.ai-chat-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.ai-chat-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Floating toggle button */
.ai-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s ease;
    background: #1e87f0;
    color: white;
}

.ai-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.ai-chat-toggle.active {
    background: #0f7ae5;
}

.ai-chat-toggle svg {
    width: 28px;
    height: 28px;
}

/* Notification badge */
.ai-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #f0506e;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

/* Chat panel */
.ai-chat-panel {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    border-radius: 12px;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e87f0;
    color: white;
    padding: 15px 20px;
    border-bottom: none;
}

.ai-chat-header .uk-card-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: white;
}

.ai-chat-close {
    /* Hard-override any global/UiKit button styles so it doesn't render as a big box */
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    background: transparent;

    color: white;
    cursor: pointer;

    width: 34px;
    height: 34px;
    padding: 0;
    margin: -6px -6px -6px 0;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border-radius: 10px;
    line-height: 1;
    min-height: auto;
}

.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.ai-chat-close svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* Messages area */
.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

.ai-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Message bubbles */
.ai-message {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.ai-message-content {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 14px;
}

.ai-message-user .ai-message-content {
    background: #1e87f0;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.ai-message-assistant .ai-message-content {
    background: white;
    color: #333;
    border: 1px solid #e5e5e5;
    border-bottom-left-radius: 4px;
}

/* Markdown styling inside message content */
.ai-message-content--formatted h1,
.ai-message-content--formatted h2,
.ai-message-content--formatted h3 {
    margin: 0.75em 0 0.35em 0;
    font-weight: 600;
    line-height: 1.3;
}

.ai-message-content--formatted h1:first-child,
.ai-message-content--formatted h2:first-child,
.ai-message-content--formatted h3:first-child {
    margin-top: 0;
}

.ai-message-content--formatted h1 {
    font-size: 1.25em;
}

.ai-message-content--formatted h2 {
    font-size: 1.1em;
}

.ai-message-content--formatted h3 {
    font-size: 1em;
}

.ai-message-content--formatted p {
    margin: 0.5em 0;
}

.ai-message-content--formatted p:first-child {
    margin-top: 0;
}

.ai-message-content--formatted p:last-child {
    margin-bottom: 0;
}

.ai-message-content--formatted ul,
.ai-message-content--formatted ol {
    margin: 0.5em 0;
    padding-left: 1.25em;
}

.ai-message-content--formatted li {
    margin: 0.25em 0;
}

.ai-message-content--formatted strong {
    font-weight: 600;
}

.ai-message-system .ai-message-content {
    background: #32d296;
    color: white;
    margin: 0 auto;
    font-size: 13px;
    padding: 8px 12px;
}

.ai-message-error .ai-message-content {
    background: #f0506e;
    color: white;
    margin: 0 auto;
    font-size: 13px;
}

/* Quick actions */
.ai-quick-actions {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e5e5e5;
}

.ai-quick-actions-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
    font-weight: 500;
}

.ai-quick-action {
    display: block;
    width: 100%;
    text-align: left;
    margin-bottom: 6px;
    font-size: 13px;
    padding: 8px 12px;
    background: white;
    border: 1px solid #e5e5e5;
    transition: all 0.2s ease;
}

.ai-quick-action:hover {
    background: #f8f9fa;
    border-color: #1e87f0;
    color: #1e87f0;
}

/* Typing indicator */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.ai-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite;
}

.ai-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.7;
    }

    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Footer / Input area */
.ai-chat-footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #e5e5e5;
}

.ai-chat-form {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.ai-chat-input {
    flex: 1;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
}

.ai-chat-input:focus {
    border-color: #1e87f0;
    outline: none;
}

.ai-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e87f0;
    border: none;
}

.ai-chat-send:hover:not(:disabled) {
    background: #0f7ae5;
}

.ai-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ai-chat-disclaimer {
    font-size: 11px;
    color: #999;
    margin: 0;
    text-align: center;
}

/* Modified element highlight */
.ai-modified {
    animation: pulse 0.5s ease;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .ai-chat-panel {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
        bottom: 80px;
        right: 20px;
    }

    .ai-chat-toggle {
        width: 56px;
        height: 56px;
    }
}

/* Scrollbar styling */
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Pending change messages */
.ai-message-pending-change .ai-message-content {
    background: #fff9e6;
    border: 1px solid #ffd966;
    color: #333;
    max-width: 90%;
    padding: 12px 14px;
}

.ai-change-pending {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-change-description {
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    font-weight: 500;
}

.ai-change-buttons {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.ai-btn-accept,
.ai-btn-reject {
    padding: 6px 16px;
    border-radius: 6px;
    border: none;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
}

.ai-btn-accept {
    background: #32d296;
    color: white;
}

.ai-btn-accept:hover {
    background: #28b57f;
}

.ai-btn-reject {
    background: #f0506e;
    color: white;
}

.ai-btn-reject:hover {
    background: #d93d5a;
}

/* Bulk action buttons */
.ai-message-bulk-actions {
    justify-content: center;
}

.ai-message-bulk-actions .ai-message-content {
    background: #e8f4fd;
    border: 1px solid #1e87f0;
    padding: 10px 14px;
    max-width: 90%;
}

.ai-change-actions-all {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.ai-btn-accept-all,
.ai-btn-reject-all {
    padding: 8px 20px;
    border-radius: 6px;
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
    max-width: 140px;
}

.ai-btn-accept-all {
    background: #32d296;
    color: white;
}

.ai-btn-accept-all:hover {
    background: #28b57f;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(50, 210, 150, 0.3);
}

.ai-btn-reject-all {
    background: #f0506e;
    color: white;
}

.ai-btn-reject-all:hover {
    background: #d93d5a;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(240, 80, 110, 0.3);
}

/* Responsive adjustments for buttons */
@media (max-width: 768px) {
    .ai-change-buttons {
        flex-direction: column;
    }

    .ai-btn-accept,
    .ai-btn-reject {
        width: 100%;
    }

    .ai-change-actions-all {
        flex-direction: column;
    }

    .ai-btn-accept-all,
    .ai-btn-reject-all {
        max-width: 100%;
    }
}