/**
 * AI Form Assistant Styles
 * Collapsible sidebar with chat interface and diff highlighting
 *
 * @version 1.0.0
 */

/* =============================================================================
   SIDEBAR CONTAINER
   ============================================================================= */

.ai-assistant-sidebar {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100vh;
    background: #ffffff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 2100; /* Above modal overlay */
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease-in-out;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.ai-assistant-sidebar.ai-assistant-open {
    right: 0;
}

/* When in modal context - adjust positioning */
.modal-open .ai-assistant-sidebar,
.um-container .ai-assistant-sidebar {
    position: fixed;
}

/* =============================================================================
   SIDEBAR HEADER
   ============================================================================= */

.ai-assistant-header {
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.ai-assistant-header h5 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-assistant-header h5 i {
    font-size: 1.25rem;
}

.ai-assistant-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: 0.375rem;
    opacity: 0.9;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-assistant-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.3);
}

/* =============================================================================
   CHAT AREA
   ============================================================================= */

.ai-assistant-chat {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Custom scrollbar */
.ai-assistant-chat::-webkit-scrollbar {
    width: 6px;
}

.ai-assistant-chat::-webkit-scrollbar-track {
    background: transparent;
}

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

.ai-assistant-chat::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* =============================================================================
   MESSAGES
   ============================================================================= */

.ai-message {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    position: relative;
    animation: messageSlideIn 0.2s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.ai-message-assistant {
    align-self: flex-start;
    background: white;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 0.25rem;
}

.ai-message-assistant-question {
    align-self: flex-start;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
    border-bottom-left-radius: 0.25rem;
}

.ai-message-error {
    align-self: center;
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #fca5a5;
    max-width: 95%;
}

.ai-message-success {
    align-self: center;
    background: #d1fae5;
    color: #059669;
    border: 1px solid #6ee7b7;
}

.ai-message-info {
    align-self: center;
    background: #e0e7ff;
    color: #4338ca;
    border: 1px solid #a5b4fc;
}

.ai-message-clarification {
    align-self: flex-start;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    padding: 0.75rem 1rem;
    max-width: 90%;
}

.clarification-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.clarification-option-btn {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    color: #334155;
    cursor: pointer;
    transition: all 0.2s;
}

.clarification-option-btn:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

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

.ai-message-content {
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.ai-message-time {
    font-size: 0.7rem;
    opacity: 0.6;
    margin-top: 0.35rem;
    text-align: right;
}

/* =============================================================================
   TYPING INDICATOR
   ============================================================================= */

.ai-typing-indicator {
    display: flex;
    gap: 0.3rem;
    padding: 0.75rem 1rem;
    align-self: flex-start;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    border-bottom-left-radius: 0.25rem;
}

.ai-typing-indicator span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.ai-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.ai-typing-indicator span:nth-child(3) { animation-delay: 0s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* =============================================================================
   INPUT AREA
   ============================================================================= */

.ai-assistant-input-area {
    padding: 1rem;
    background: white;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    flex-shrink: 0;
}

.ai-assistant-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 1.25rem;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
    resize: none;
    min-height: 2.5rem;
    max-height: 6rem;
    line-height: 1.4;
    font-family: inherit;
}

.ai-assistant-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.ai-assistant-input::placeholder {
    color: #9ca3af;
}

.ai-assistant-send {
    width: 2.5rem;
    height: 2.5rem;
    min-width: 2.5rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1rem;
}

.ai-assistant-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.ai-assistant-send:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    transform: none;
}

.ai-assistant-send:active:not(:disabled) {
    transform: scale(0.95);
}

/* =============================================================================
   PROPOSED CHANGES PANEL
   ============================================================================= */

.ai-assistant-proposed-changes {
    background: white;
    border-top: 1px solid #e5e7eb;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
    flex-shrink: 0;
}

.ai-assistant-proposed-changes.has-changes {
    max-height: 50vh;
    overflow-y: auto;
}

.proposed-changes-header {
    padding: 0.75rem 1rem;
    background: linear-gradient(to right, #f0fdf4, #ecfdf5);
    border-bottom: 1px solid #bbf7d0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1;
}

.proposed-changes-header h6 {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: #166534;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.proposed-changes-header h6 i {
    color: #22c55e;
}

.proposed-changes-actions {
    display: flex;
    gap: 0.5rem;
}

.proposed-changes-actions .btn {
    font-size: 0.75rem;
    padding: 0.35rem 0.65rem;
}

/* =============================================================================
   CHANGE ITEM
   ============================================================================= */

.proposed-change-item {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    transition: all 0.3s ease;
}

.proposed-change-item:last-child {
    border-bottom: none;
}

.proposed-change-item:hover {
    background: #f9fafb;
}

.proposed-change-item.applied {
    background: #d1fae5;
    opacity: 0;
    transform: translateX(20px);
}

.proposed-change-item.rejected {
    background: #fee2e2;
    opacity: 0;
    transform: translateX(-20px);
}

.change-field-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: #374151;
    margin-bottom: 0.5rem;
}

.change-diff {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.change-current, .change-proposed {
    flex: 1;
    padding: 0.5rem 0.65rem;
    border-radius: 0.375rem;
    min-height: 3rem;
    display: flex;
    flex-direction: column;
}

.change-current {
    background: #fef2f2;
    border: 1px solid #fecaca;
}

.change-proposed {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
}

.diff-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.diff-value {
    display: block;
    word-break: break-word;
    font-size: 0.8rem;
}

.diff-removed {
    color: #dc2626;
    text-decoration: line-through;
    text-decoration-color: rgba(220, 38, 38, 0.5);
}

.diff-added {
    color: #16a34a;
    font-weight: 500;
}

.change-arrow {
    color: #9ca3af;
    display: flex;
    align-items: center;
    font-size: 0.9rem;
}

.change-reason {
    font-size: 0.75rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
    font-style: italic;
}

.change-actions {
    display: flex;
    gap: 0.35rem;
    justify-content: flex-end;
}

.btn-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1.2;
}

.btn-xs i {
    font-size: 0.8rem;
}

/* =============================================================================
   TOGGLE BUTTON (Floating)
   ============================================================================= */

.ai-assistant-toggle:not(.ai-assistant-close) {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    z-index: 2050;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all 0.2s;
}

.ai-assistant-toggle:not(.ai-assistant-close):hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.ai-assistant-toggle:not(.ai-assistant-close):active {
    transform: scale(1.05);
}

/* Hide toggle when sidebar is open */
.ai-assistant-sidebar.ai-assistant-open ~ .ai-assistant-toggle:not(.ai-assistant-close),
.ai-assistant-open + .ai-assistant-toggle:not(.ai-assistant-close) {
    opacity: 0;
    pointer-events: none;
}

/* =============================================================================
   WELCOME MESSAGE STYLING
   ============================================================================= */

.ai-assistant-chat .ai-message-assistant ul {
    margin: 0.5rem 0 0 1rem;
    padding: 0;
    list-style-type: disc;
}

.ai-assistant-chat .ai-message-assistant li {
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

/* =============================================================================
   RESPONSIVE DESIGN
   ============================================================================= */

@media (max-width: 768px) {
    .ai-assistant-sidebar {
        width: 100%;
        right: -100%;
    }

    .ai-assistant-toggle:not(.ai-assistant-close) {
        right: 1rem;
        bottom: 1rem;
        width: 3rem;
        height: 3rem;
        font-size: 1.25rem;
    }

    .change-diff {
        flex-direction: column;
        gap: 0.35rem;
    }

    .change-arrow {
        transform: rotate(90deg);
        justify-content: center;
        padding: 0.25rem 0;
    }

    .proposed-changes-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }

    .proposed-changes-actions {
        justify-content: stretch;
    }

    .proposed-changes-actions .btn {
        flex: 1;
    }
}

/* =============================================================================
   DARK MODE SUPPORT (Optional)
   ============================================================================= */

@media (prefers-color-scheme: dark) {
    /* Uncomment to enable dark mode support
    .ai-assistant-sidebar {
        background: #1f2937;
        color: #f9fafb;
    }

    .ai-assistant-chat {
        background: #111827;
    }

    .ai-message-assistant {
        background: #374151;
        color: #f9fafb;
        border-color: #4b5563;
    }

    .ai-assistant-input-area {
        background: #1f2937;
        border-color: #374151;
    }

    .ai-assistant-input {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }

    .proposed-change-item {
        border-color: #374151;
    }

    .proposed-change-item:hover {
        background: #374151;
    }
    */
}

/* =============================================================================
   PRINT STYLES
   ============================================================================= */

@media print {
    .ai-assistant-sidebar,
    .ai-assistant-toggle:not(.ai-assistant-close) {
        display: none !important;
    }
}

/* =============================================================================
   SAVING OVERLAY
   ============================================================================= */

#ai-saving-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

#ai-saving-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.ai-saving-content {
    background: white;
    padding: 2rem 3rem;
    border-radius: 0.75rem;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.ai-saving-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: ai-saving-spin 1s linear infinite;
}

.ai-saving-text {
    font-size: 1.1rem;
    color: #374151;
    font-weight: 500;
}

@keyframes ai-saving-spin {
    to { transform: rotate(360deg); }
}
