/* AWIFA Chat Widget — premium support UI (brand: #003366) */

.awifa-chat-widget {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1200;
    font-family: Inter, system-ui, -apple-system, sans-serif;
    --awifa-primary: #003366;
    --awifa-primary-light: #0a4a8a;
    --awifa-surface: rgba(255, 255, 255, 0.92);
    --awifa-border: rgba(203, 213, 225, 0.9);
    --awifa-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
    --awifa-radius: 18px;
}

.awifa-chat-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    background: linear-gradient(135deg, var(--awifa-primary) 0%, var(--awifa-primary-light) 100%);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 0.9rem 1.15rem;
    box-shadow: 0 10px 28px rgba(0, 51, 102, 0.35);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.28s ease;
}

.awifa-chat-toggle:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 14px 32px rgba(0, 51, 102, 0.4);
}

.awifa-chat-toggle:active {
    transform: translateY(-1px) scale(0.98);
}

.awifa-chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 1.3rem;
    height: 1.3rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
    animation: awifa-badge-pop 0.35s ease;
}

@keyframes awifa-badge-pop {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

.awifa-chat-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.85rem);
    width: min(400px, calc(100vw - 2rem));
    max-height: min(680px, calc(100vh - 5rem));
    background: var(--awifa-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--awifa-border);
    border-radius: var(--awifa-radius);
    box-shadow: var(--awifa-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform-origin: bottom right;
    opacity: 0;
    transform: translateY(16px) scale(0.94);
    transition: opacity 0.32s cubic-bezier(0.22, 1, 0.36, 1), transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.awifa-chat-panel--open {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.awifa-chat-panel--closed {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
    pointer-events: none;
}

.awifa-chat-panel[hidden] {
    display: none !important;
}

.awifa-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.1rem;
    background: linear-gradient(135deg, var(--awifa-primary) 0%, #004080 100%);
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 51, 102, 0.2);
}

.awifa-chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.awifa-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.25);
}

.awifa-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.awifa-chat-presence {
    font-size: 0.72rem;
    margin-top: 0.15rem;
    opacity: 0.95;
}

.awifa-chat-presence--online { color: #bbf7d0; }
.awifa-chat-presence--away { color: #fde68a; }
.awifa-chat-presence--offline { color: #fecaca; }

.awifa-chat-hours {
    font-size: 0.68rem;
    opacity: 0.8;
    margin-top: 0.1rem;
}

.awifa-chat-close {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 1rem;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    transition: background 0.2s;
}

.awifa-chat-close:hover {
    background: rgba(255, 255, 255, 0.22);
}

.awifa-chat-messages {
    flex: 1;
    min-height: 300px;
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.awifa-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.awifa-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.35);
    border-radius: 999px;
}

.awifa-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.55);
}

.awifa-chat-date-sep,
.awifa-chat-unread-sep {
    align-self: center;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    background: rgba(255, 255, 255, 0.85);
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    border: 1px solid rgba(203, 213, 225, 0.8);
    position: sticky;
    top: 0;
    z-index: 2;
    backdrop-filter: blur(8px);
    margin: 0.35rem 0;
}

.awifa-chat-unread-sep {
    color: #dc2626;
    border-color: rgba(220, 38, 38, 0.25);
    background: rgba(254, 226, 226, 0.9);
}

.awifa-chat-row {
    display: flex;
    align-items: flex-end;
    gap: 0.45rem;
    max-width: 100%;
}

.awifa-chat-row--user {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.awifa-chat-row--assistant,
.awifa-chat-row--operator,
.awifa-chat-row--system {
    align-self: flex-start;
}

.awifa-chat-row--system {
    justify-content: center;
    width: 100%;
}

.awifa-chat-row--system .awifa-chat-bubble-wrap {
    max-width: 95%;
}

.awifa-chat-row--animate {
    animation: awifa-msg-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes awifa-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.awifa-chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e2e8f0;
    color: var(--awifa-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
    overflow: hidden;
}

.awifa-chat-msg-avatar--user {
    background: var(--awifa-primary);
    color: #fff;
}

.awifa-chat-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.awifa-chat-bubble-wrap {
    max-width: 78%;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.awifa-chat-row--user .awifa-chat-bubble-wrap {
    align-items: flex-end;
}

.awifa-chat-message {
    padding: 0.7rem 0.9rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
    transition: box-shadow 0.2s;
}

.awifa-chat-message:hover {
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
}

.awifa-chat-message.user {
    background: linear-gradient(135deg, var(--awifa-primary) 0%, #004080 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.awifa-chat-message.assistant,
.awifa-chat-message.operator {
    background: #fff;
    border: 1px solid rgba(226, 232, 240, 0.95);
    color: #0f172a;
    border-bottom-left-radius: 4px;
}

.awifa-chat-message.system {
    background: rgba(241, 245, 249, 0.95);
    border: 1px dashed #cbd5e1;
    color: #475569;
    font-size: 0.82rem;
    text-align: center;
    box-shadow: none;
}

.awifa-chat-time {
    font-size: 0.62rem;
    color: #94a3b8;
    padding: 0 0.35rem;
}

.awifa-chat-receipt {
    font-size: 0.62rem;
    color: #94a3b8;
    margin-left: 0.25rem;
}

.awifa-chat-receipt--delivered,
.awifa-chat-receipt--read {
    color: #64748b;
}

.awifa-chat-receipt--read {
    color: #2563eb;
}

.awifa-chat-attachment-preview {
    max-width: min(100%, 240px);
    max-height: 180px;
    border-radius: 10px;
    margin-top: 0.35rem;
    display: block;
    object-fit: cover;
}

.awifa-chat-pdf-preview {
    width: 100%;
    max-width: 280px;
    height: 180px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    margin-top: 0.35rem;
}

.awifa-chat-attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--awifa-primary);
    text-decoration: none;
    margin-top: 0.35rem;
    padding: 0.35rem 0.55rem;
    background: rgba(0, 51, 102, 0.06);
    border-radius: 8px;
    transition: background 0.15s;
}

.awifa-chat-attachment-link:hover {
    background: rgba(0, 51, 102, 0.12);
}

.awifa-chat-welcome {
    padding: 0.25rem 0 0.75rem;
}

.awifa-chat-welcome-headline {
    margin: 0 0 0.5rem;
    font-size: 1.1rem;
    color: #0f172a;
}

.awifa-chat-welcome-desc {
    margin: 0 0 0.5rem;
    font-size: 0.875rem;
    color: #475569;
    white-space: pre-wrap;
    line-height: 1.55;
}

.awifa-chat-welcome-hours {
    margin: 0 0 0.75rem;
    font-size: 0.75rem;
    color: #64748b;
}

.awifa-chat-offline-banner {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 1px solid #fcd34d;
    color: #92400e;
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    font-size: 0.82rem;
    margin-bottom: 0.75rem;
    white-space: pre-wrap;
    line-height: 1.45;
}

.awifa-chat-quick-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.awifa-chat-quick-btn {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    text-align: left;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 0.65rem 0.85rem;
    font: inherit;
    font-size: 0.86rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.awifa-chat-quick-btn:hover {
    border-color: var(--awifa-primary);
    background: #eff6ff;
    transform: translateX(2px);
    box-shadow: 0 4px 12px rgba(0, 51, 102, 0.08);
}

.awifa-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin: 0.25rem 0 0.5rem;
}

.awifa-chat-suggestion-btn {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
    border-radius: 999px;
    padding: 0.4rem 0.75rem;
    font-size: 0.76rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}

.awifa-chat-suggestion-btn:hover {
    background: #dbeafe;
    transform: translateY(-1px);
}

.awifa-chat-typing {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem 0.55rem;
    background: #f8fafc;
}

.awifa-chat-typing-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #e2e8f0;
    color: var(--awifa-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
}

.awifa-chat-typing-dots {
    display: flex;
    gap: 4px;
    padding: 0.45rem 0.65rem;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.awifa-chat-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: awifa-typing 1.2s infinite ease-in-out;
}

.awifa-chat-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.awifa-chat-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes awifa-typing {
    0%, 70%, 100% { transform: translateY(0); opacity: 0.45; }
    35% { transform: translateY(-5px); opacity: 1; }
}

.awifa-chat-skeleton {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0.5rem 0;
}

.awifa-chat-skeleton-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(90deg, #e2e8f0 25%, #f8fafc 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: awifa-shimmer 1.4s infinite;
}

.awifa-chat-skeleton-avatar.right {
    align-self: flex-end;
}

.awifa-chat-skeleton-lines {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-width: 70%;
}

.awifa-chat-skeleton-lines.right {
    align-self: flex-end;
    align-items: flex-end;
}

.awifa-chat-skeleton-line {
    height: 12px;
    border-radius: 8px;
    width: 100%;
    background: linear-gradient(90deg, #e2e8f0 25%, #f8fafc 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: awifa-shimmer 1.4s infinite;
}

.awifa-chat-skeleton-line.short { width: 55%; }
.awifa-chat-skeleton-line.medium { width: 45%; }

@keyframes awifa-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.awifa-chat-form {
    padding: 0.85rem 1rem 1rem;
    border-top: 1px solid rgba(226, 232, 240, 0.95);
    background: rgba(255, 255, 255, 0.95);
    flex-shrink: 0;
}

.awifa-chat-upload-progress {
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    color: #64748b;
}

.awifa-chat-upload-bar {
    height: 4px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.awifa-chat-upload-bar span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--awifa-primary);
    border-radius: 999px;
    transition: width 0.2s;
}

.awifa-chat-form textarea {
    width: 100%;
    resize: vertical;
    min-height: 56px;
    max-height: 120px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 0.7rem 0.85rem;
    font: inherit;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
}

.awifa-chat-form textarea:focus {
    outline: none;
    border-color: var(--awifa-primary);
    box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.12);
}

.awifa-chat-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.65rem;
}

.awifa-chat-actions-left {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.awifa-chat-attach-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #f1f5f9;
    color: #475569;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.awifa-chat-attach-btn:hover {
    background: #e2e8f0;
    color: var(--awifa-primary);
}

.awifa-chat-operator-btn,
.awifa-chat-send-btn {
    border: none;
    border-radius: 10px;
    padding: 0.55rem 0.9rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.82rem;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.awifa-chat-operator-btn {
    background: #f1f5f9;
    color: #334155;
}

.awifa-chat-operator-btn:hover {
    background: #e2e8f0;
}

.awifa-chat-send-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--awifa-primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 51, 102, 0.25);
}

.awifa-chat-send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 51, 102, 0.3);
}

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

.awifa-chat-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1300;
    padding: 1rem;
    animation: awifa-fade-in 0.25s ease;
}

.awifa-chat-modal[hidden] {
    display: none !important;
}

@keyframes awifa-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.awifa-chat-modal-box {
    background: #fff;
    border-radius: 16px;
    padding: 1.35rem;
    max-width: 340px;
    width: 100%;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
    animation: awifa-modal-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes awifa-modal-in {
    from { opacity: 0; transform: scale(0.92) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.awifa-chat-modal-box h3 {
    margin: 0 0 0.5rem;
    font-size: 1.1rem;
    color: #0f172a;
}

.awifa-chat-modal-box p {
    margin: 0 0 1rem;
    font-size: 0.875rem;
    color: #475569;
    line-height: 1.5;
}

.awifa-chat-modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.awifa-chat-stars {
    display: flex;
    gap: 0.35rem;
    justify-content: center;
    margin: 0.75rem 0;
}

.awifa-chat-star {
    background: none;
    border: none;
    font-size: 1.75rem;
    color: #cbd5e1;
    cursor: pointer;
    transition: color 0.15s, transform 0.15s;
    padding: 0.15rem;
}

.awifa-chat-star:hover,
.awifa-chat-star.active {
    color: #f59e0b;
    transform: scale(1.1);
}

.awifa-chat-modal-box textarea {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 0.6rem 0.75rem;
    font: inherit;
    font-size: 0.875rem;
    resize: vertical;
}

body.awifa-chat-mobile-open {
    overflow: hidden;
}

@media (max-width: 768px) {
    .awifa-chat-widget {
        right: 0.75rem;
        bottom: 0.75rem;
        left: auto;
    }

    .awifa-chat-toggle {
        width: 3.25rem;
        height: 3.25rem;
        padding: 0;
        border-radius: 50%;
        justify-content: center;
    }
}

@media (max-width: 640px) {
    .awifa-chat-widget {
        right: 0;
        bottom: 0;
        left: 0;
    }

    .awifa-chat-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        max-height: none;
        border-radius: 0;
        bottom: auto;
        transform-origin: bottom center;
    }

    .awifa-chat-panel--open {
        animation: awifa-mobile-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    }

    @keyframes awifa-mobile-in {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .awifa-chat-messages {
        max-height: none;
        flex: 1;
    }

    .awifa-chat-toggle span:not(.awifa-chat-unread-badge) {
        display: none;
    }
}

.awifa-chat-operator-connected {
    font-size: 0.78rem;
    color: #16a34a;
    margin-top: 0.35rem;
}

.awifa-chat-connection {
    font-size: 0.72rem;
    margin-top: 0.15rem;
}

.awifa-chat-new-messages-btn {
    position: sticky;
    bottom: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    border: none;
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    font-size: 0.75rem;
    background: var(--awifa-primary, #003366);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.awifa-chat-typing-label {
    font-size: 0.75rem;
    color: var(--awifa-text-muted, #64748b);
    margin-left: 0.35rem;
}

@media (prefers-reduced-motion: reduce) {
    .awifa-chat-panel,
    .awifa-chat-row--animate,
    .awifa-chat-toggle,
    .awifa-chat-modal-box {
        animation: none !important;
        transition: none !important;
    }
}
