/*
 * ILS Chat Widget - WCAG 2.2 AAA Compliant
 */

/* Custom properties */
.ils-chat {
    --chat-bg: #ffffff;
    --chat-text: #1a1a1a;
    --chat-border: #666666;
    --chat-accent: #363636;
    --chat-owner-bg: #f0f0f0;
    --chat-visitor-bg: #363636;
    --chat-visitor-text: #ffffff;
    --chat-muted: #666666;
    --chat-focus: 3px solid #000000;
    --chat-radius: 8px;
    --chat-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* Position fixed in bottom right */
.ils-chat {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

/* Toggle button - 44px minimum for AAA */
.ils-chat-toggle {
    width: 60px;
    height: 60px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    border: none;
    background-color: var(--chat-accent);
    color: var(--chat-visitor-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chat-shadow);
    transition: transform 0.2s ease;
    position: relative;
}

.ils-chat-toggle:hover {
    transform: scale(1.05);
}

.ils-chat-toggle:focus {
    outline: var(--chat-focus);
    outline-offset: 2px;
}

.ils-chat-toggle[aria-expanded="true"] {
    display: none;
}

/* Chat icon SVG */
.ils-chat-icon svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* Unread badge */
.ils-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background-color: #dc3545;
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Chat panel */
.ils-chat-panel {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 100px);
    background-color: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ils-chat-panel[hidden] {
    display: none;
}

/* Header */
.ils-chat-header {
    padding: 16px;
    background-color: var(--chat-accent);
    color: var(--chat-visitor-text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ils-chat-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.ils-chat-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: transparent;
    color: var(--chat-visitor-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    border-radius: 4px;
    margin: -8px -8px -8px 0;
}

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

.ils-chat-close:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* Messages area */
.ils-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ils-chat-messages:focus {
    outline: var(--chat-focus);
    outline-offset: -3px;
}

/* Individual message */
.ils-chat-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--chat-radius);
    word-wrap: break-word;
}

.ils-chat-message--visitor {
    align-self: flex-end;
    background-color: var(--chat-visitor-bg);
    color: var(--chat-visitor-text);
}

.ils-chat-message--owner {
    align-self: flex-start;
    background-color: var(--chat-owner-bg);
    color: var(--chat-text);
}

.ils-chat-message-time {
    font-size: 11px;
    color: var(--chat-muted);
    margin-top: 4px;
    display: block;
}

.ils-chat-message--visitor .ils-chat-message-time {
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
}

/* Welcome message */
.ils-chat-welcome {
    text-align: center;
    color: var(--chat-muted);
    padding: 20px;
}

/* Input area */
.ils-chat-form {
    padding: 12px;
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background-color: var(--chat-bg);
}

.ils-chat-input {
    flex: 1;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);
    font-size: 16px;
    font-family: inherit;
    resize: none;
    color: var(--chat-text);
    background-color: var(--chat-bg);
}

.ils-chat-input:focus {
    outline: var(--chat-focus);
    outline-offset: 0;
    border-color: var(--chat-accent);
}

.ils-chat-input::placeholder {
    color: var(--chat-muted);
}

.ils-chat-send {
    min-width: 44px;
    min-height: 44px;
    padding: 0 16px;
    border: none;
    border-radius: var(--chat-radius);
    background-color: var(--chat-accent);
    color: var(--chat-visitor-text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.ils-chat-send:hover {
    opacity: 0.9;
}

.ils-chat-send:focus {
    outline: var(--chat-focus);
    outline-offset: 2px;
}

.ils-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Status bar */
.ils-chat-status {
    padding: 8px 12px;
    font-size: 12px;
    color: var(--chat-muted);
    text-align: center;
    border-top: 1px solid var(--chat-border);
    background-color: var(--chat-bg);
    flex-shrink: 0;
}

.ils-chat-status:empty {
    display: none;
}

/* Loading state */
.ils-chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 20px;
}

.ils-chat-loading-dot {
    width: 8px;
    height: 8px;
    background-color: var(--chat-muted);
    border-radius: 50%;
    animation: ils-chat-bounce 1.4s ease-in-out infinite both;
}

.ils-chat-loading-dot:nth-child(1) { animation-delay: -0.32s; }
.ils-chat-loading-dot:nth-child(2) { animation-delay: -0.16s; }

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

/* Visually hidden (for screen readers) */
.ils-chat .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ils-chat,
    .ils-chat * {
        animation: none !important;
        transition: none !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: more) {
    .ils-chat {
        --chat-border: #000000;
        --chat-muted: #000000;
    }

    .ils-chat-message--owner {
        border: 2px solid var(--chat-text);
    }
}

/* Dark color scheme - match site */
@media (prefers-color-scheme: dark) {
    .ils-chat {
        --chat-bg: #2a2a2a;
        --chat-text: #ffffff;
        --chat-border: #555555;
        --chat-owner-bg: #3a3a3a;
        --chat-muted: #aaaaaa;
        --chat-focus: 3px solid #ffffff;
    }
}

/* Mobile adjustments */
@media (max-width: 400px) {
    .ils-chat {
        bottom: 10px;
        right: 10px;
    }

    .ils-chat-panel {
        width: calc(100vw - 20px);
        height: calc(100vh - 80px);
        max-height: none;
    }
}
