/* ============================================
   Grace Fields Chat Interface - WCAG AA Compliant
   ============================================ */

:root {
    /* Light Mode Chat Variables */
    --chat-bg: #f8f9fa;
    --message-user-bg: #31B2E0;
    --message-assistant-bg: #ffffff;
    --message-user-text: #ffffff;
    --message-assistant-text: #1a1a1a;      /* WCAG AA compliant */
    --input-bg: #ffffff;
    --input-border: #e2e8f0;
    --input-text: #1a1a1a;                  /* WCAG AA compliant */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --grace-icon-color: #9B59B6;            /* Darker lavender for better contrast */
}

/* Dark mode variables - WCAG AA compliant */
body.dark-mode {
    --chat-bg: #1a1d23;
    --message-assistant-bg: #252930;
    --message-assistant-text: #f7fafc;      /* WCAG AA compliant on dark bg */
    --input-bg: #252930;
    --input-border: #3a3f47;
    --input-text: #f7fafc;                  /* WCAG AA compliant on dark bg */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
    --grace-icon-color: #B19CD9;            /* Lighter lavender for dark mode */
}

/* Note: Legacy @media (prefers-color-scheme: dark) removed.
   Theme is controlled via body.dark-mode class for consistent user preference.
   See ui-enhancements.js for theme toggle logic. */

/* Chat Container - Improved Spacing */
.chat-container {
    max-width: 900px;
    margin: 2rem auto;
    height: calc(100vh - 150px);
    display: flex;
    flex-direction: column;
    background: var(--input-bg);
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

/* Chat Header - Better Spacing */
.chat-header {
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, #31B2E0 0%, #4ECDC4 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.grace-avatar {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

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

.chat-actions button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.chat-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.chat-actions button:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Chat Messages Area - Improved Spacing */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--chat-bg);
    scroll-behavior: smooth;
    transition: background-color 0.3s ease;
}

/* Message Styles */
.message {
    display: flex;
    margin-bottom: 1.5rem;
    animation: messageSlideIn 0.3s ease;
    gap: 0.75rem;
}

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

.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: linear-gradient(135deg, #31B2E0 0%, #4ECDC4 100%);
    color: white;
}

.grace-message .message-avatar,
.assistant-message .message-avatar {
    background: rgba(177, 156, 217, 0.1);
    color: #B19CD9;
}

.message-content {
    max-width: 70%;
    margin: 0 1rem;
}

.message-text {
    padding: 1rem 1.25rem;
    border-radius: 16px;
    line-height: 1.6;
    word-wrap: break-word;
    border: 1px solid transparent;
    transition: all 0.3s ease;
}

.user-message .message-text {
    background: var(--message-user-bg);
    color: var(--message-user-text);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(49, 178, 224, 0.2);
}

.assistant-message .message-text {
    background: var(--message-assistant-bg);
    color: var(--message-assistant-text);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
    border-color: rgba(177, 156, 217, 0.1);
}

/* Light mode - WCAG AA compliant contrast */
body:not(.dark-mode) .assistant-message .message-text {
    background: #ffffff;
    color: #1a1a1a;                         /* WCAG AA compliant */
    border-color: #e2e8f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Dark mode - WCAG AA compliant contrast */
body.dark-mode .assistant-message .message-text {
    background: #252930;
    color: #f7fafc;                         /* WCAG AA compliant */
    border-color: #3a3f47;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.message-time {
    font-size: 0.75rem;
    color: #718096;                         /* WCAG AA compliant */
    margin-top: 0.5rem;
    padding: 0 0.5rem;
}

/* Dark mode message time */
body.dark-mode .message-time {
    color: #a0aec0;                         /* WCAG AA compliant on dark bg */
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 0 2rem 1rem;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 0.75rem 1rem;
    background: var(--message-assistant-bg);
    border-radius: 16px;
    margin: 0 1rem;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: typingBounce 1.4s infinite;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

.typing-text {
    font-size: 0.875rem;
    color: #6c757d;
    font-style: italic;
}

/* Quick Suggestions */
.quick-suggestions {
    padding: 1rem 2rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    background: var(--chat-bg);
    border-top: 1px solid var(--input-border);
}

.suggestion-chip {
    padding: 0.5rem 1rem;
    border: 1px solid var(--input-border);
    border-radius: 20px;
    background: var(--input-bg);
    color: #31B2E0;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.suggestion-chip:hover {
    background: #31B2E0;
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

/* Chat Input Container - Improved Spacing & Accessibility */
.chat-input-container {
    padding: 1.25rem 1.5rem;
    background: var(--input-bg);
    border-top: 1px solid var(--input-border);
    display: flex;
    align-items: flex-end;
    gap: 1rem;
}

.input-wrapper {
    flex: 1;
}

.input-wrapper textarea {
    width: 100%;
    border: 2px solid var(--input-border);
    border-radius: 0.75rem;
    padding: 0.875rem 1rem;
    resize: none;
    max-height: 150px;
    min-height: 44px;
    font-size: 1rem;
    line-height: 1.5;
    transition: all 0.3s ease;
    background: var(--input-bg);
    color: var(--input-text);
}

.input-wrapper textarea:focus {
    border-color: #31B2E0;
    box-shadow: 0 0 0 3px rgba(49, 178, 224, 0.15);
    outline: none;
}

.input-wrapper textarea::placeholder {
    color: #a0aec0;
}

body.dark-mode .input-wrapper textarea::placeholder {
    color: #718096;
}

.btn-icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--input-border);
    background: var(--input-bg);
    color: #31B2E0;
    font-size: 0.875rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.btn-icon:hover {
    background: #31B2E0;
    color: white;
    transform: scale(1.05);
    border-color: #31B2E0;
}

.btn-icon:focus {
    outline: 2px solid #31B2E0;
    outline-offset: 2px;
}

.btn-send {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #31B2E0 0%, #4ECDC4 100%);
    border: none;
    color: white;
    font-size: 0.875rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.btn-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(49, 178, 224, 0.4);
}

.btn-send:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Voice Recording */
.voice-recording {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 1.5rem 2rem;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.recording-animation {
    position: relative;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pulse-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid #dc3545;
    border-radius: 50%;
    animation: pulse 1.5s ease-out infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

.recording-animation i {
    color: #dc3545;
    font-size: 1.5rem;
    z-index: 1;
}

/* Microphone Recording State */
.btn-icon.recording {
    background: #dc3545;
    border-color: #dc3545;
    color: white;
    animation: micPulse 1s ease-in-out infinite;
}

.btn-icon.recording i {
    color: white;
}

@keyframes micPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(220, 53, 69, 0);
    }
}

/* Dark mode voice recording */
body.dark-mode .voice-recording {
    background: var(--terminal-surface, #161b22);
    border: 1px solid var(--terminal-border, #30363d);
    color: var(--terminal-text, #c9d1d9);
}

/* Scrollbar Styles */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.5);
}

/* Mobile Responsive - Enhanced Accessibility */
@media (max-width: 768px) {
    .chat-container {
        margin: 0;
        height: 100vh;
        border-radius: 0;
    }

    .chat-header {
        padding: 1rem 1.25rem;
    }

    .chat-messages {
        padding: 1rem;
    }

    .message-content {
        max-width: 85%;
    }

    .message-text {
        padding: 0.875rem 1rem;
        font-size: 0.9375rem;
    }

    .quick-suggestions {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding: 0.875rem 1rem;
    }

    .suggestion-chip {
        min-height: 44px;
        padding: 0.75rem 1.25rem;
        white-space: nowrap;
    }

    .chat-input-container {
        padding: 1rem;
    }

    .input-wrapper textarea {
        font-size: 1rem;
        padding: 0.75rem 1rem;
    }

    /* Ensure all interactive elements meet 44x44px minimum */
    .btn-icon,
    .btn-send,
    .chat-actions button {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ================================================
   Reduced Motion Support (WCAG 2.1 Level AAA)
   ================================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Remove message slide-in animations */
    .message {
        animation: none !important;
    }

    /* Remove typing indicator animation */
    .typing-indicator span {
        animation: none !important;
    }

    /* Remove hover transforms */
    .suggestion-chip:hover,
    .btn-icon:hover,
    .btn-send:hover,
    .chat-actions button:hover {
        transform: none !important;
    }

    /* Disable backdrop blur for performance */
    .grace-avatar {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
}

/* File Upload Preview */
.file-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.file-preview i {
    color: #667eea;
}

.file-preview button {
    margin-left: auto;
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
}

/* Message Actions */
.message-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-actions button {
    background: none;
    border: none;
    color: #6c757d;
    font-size: 0.875rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.message-actions button:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

