/**
 * AI Chat Assistant - Frontend Chat Widget Styles
 * Uses CSS custom properties (set via PHP) for full customization
 */

/* =============================================
   CHAT WIDGET CONTAINER
   ============================================= */
#aca-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: var(--aca-font-size, 14px);
    line-height: 1.5;
    box-sizing: border-box;
}

#aca-chat-widget *,
#aca-chat-widget *::before,
#aca-chat-widget *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Position variants */
#aca-chat-widget.aca-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

#aca-chat-widget.aca-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* =============================================
   CHAT BUBBLE (FAB)
   ============================================= */
.aca-chat-bubble {
    width: var(--aca-bubble-size, 60px);
    height: var(--aca-bubble-size, 60px);
    border-radius: 50%;
    background: var(--aca-primary, #2563eb);
    color: var(--aca-text, #ffffff);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    opacity: 0;
    transform: scale(0.5);
}

.aca-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
}

.aca-chat-bubble:active {
    transform: scale(0.95);
}

.aca-chat-bubble svg {
    fill: none;
    stroke: currentColor;
}

.aca-chat-bubble img {
    width: 60%;
    height: 60%;
    object-fit: contain;
    border-radius: 50%;
}

/* Bubble entrance animation */
.aca-bubble-visible {
    opacity: 1 !important;
    transform: scale(1) !important;
    animation: aca-bubble-bounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.aca-bubble-hidden {
    opacity: 0 !important;
    transform: scale(0.5) !important;
    pointer-events: none;
}

@keyframes aca-bubble-bounce {
    0% { opacity: 0; transform: scale(0.3); }
    50% { opacity: 1; transform: scale(1.1); }
    100% { opacity: 1; transform: scale(1); }
}

/* Pulse ring animation */
.aca-chat-bubble::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--aca-primary, #2563eb);
    opacity: 0;
    animation: aca-pulse-ring 2s ease-out infinite;
    animation-delay: 3s;
}

@keyframes aca-pulse-ring {
    0% { opacity: 0.6; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.4); }
}

/* =============================================
   CHAT WINDOW
   ============================================= */
.aca-chat-window {
    position: absolute;
    bottom: 0;
    width: var(--aca-width, 380px);
    height: var(--aca-height, 520px);
    max-height: calc(100vh - 100px);
    background: var(--aca-bg, #ffffff);
    border-radius: var(--aca-radius, 16px);
    box-shadow: 0 10px 60px rgba(0, 0, 0, 0.12), 0 4px 20px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.aca-position-bottom-right .aca-chat-window {
    right: 0;
}

.aca-position-bottom-left .aca-chat-window {
    left: 0;
}

.aca-chat-window.aca-chat-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* =============================================
   CHAT HEADER
   ============================================= */
.aca-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #ffffff;
    color: #111827;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.aca-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.aca-header-avatar,
.aca-header-avatar-default {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.aca-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.aca-header-avatar-default {
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #e5e7eb;
}

.aca-header-title {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
}

.aca-header-subtitle {
    font-size: 11px;
    color: #6b7280;
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 4px;
}

.aca-header-subtitle::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
    flex-shrink: 0;
}

.aca-chat-header-actions {
    display: flex;
    gap: 4px;
}

.aca-header-btn {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: transparent;
    color: #6b7280;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.aca-header-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

.aca-header-btn svg {
    fill: none;
    stroke: currentColor;
}

/* =============================================
   MESSAGES CONTAINER
   ============================================= */
.aca-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--aca-bg, #ffffff);
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.aca-chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

.aca-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

/* =============================================
   MESSAGE STYLES
   ============================================= */
.aca-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: aca-msg-appear 0.3s ease;
}

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

.aca-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.aca-message-bot {
    align-self: flex-start;
}

.aca-message-system {
    align-self: center;
    max-width: 90%;
    padding: 8px 16px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 12px;
    font-size: 12px;
    text-align: center;
}

/* Message avatar */
.aca-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--aca-bot-bubble, #f1f5f9);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.aca-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.aca-message-avatar svg {
    width: 16px;
    height: 16px;
    color: var(--aca-bot-text, #1e293b);
    opacity: 0.6;
}

/* Message bubbles */
.aca-message-bubble {
    padding: 10px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.aca-bubble-user {
    background: var(--aca-user-bubble, #2563eb);
    color: var(--aca-user-text, #ffffff);
    border-bottom-right-radius: 4px;
}

.aca-bubble-bot {
    background: var(--aca-bot-bubble, #f1f5f9);
    color: var(--aca-bot-text, #1e293b);
    border-bottom-left-radius: 4px;
}

.aca-bubble-bot a {
    color: var(--aca-primary, #2563eb);
    text-decoration: underline;
}

.aca-bubble-bot a:hover {
    opacity: 0.8;
}

.aca-bubble-bot code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.aca-bubble-bot ul,
.aca-bubble-bot ol {
    padding-left: 16px;
    margin: 4px 0;
}

.aca-bubble-bot li {
    margin: 2px 0;
}

.aca-bubble-bot strong {
    font-weight: 600;
}

/* =============================================
   TYPING INDICATOR
   ============================================= */
.aca-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 18px !important;
}

.aca-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--aca-bot-text, #1e293b);
    opacity: 0.3;
    animation: aca-typing-bounce 1.2s ease-in-out infinite;
}

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

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

@keyframes aca-typing-bounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* =============================================
   INPUT AREA
   ============================================= */
.aca-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: var(--aca-bg, #ffffff);
    flex-shrink: 0;
}

.aca-chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.aca-chat-input-wrapper:focus-within {
    border-color: var(--aca-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#aca-chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: var(--aca-font-size, 14px);
    line-height: 1.5;
    color: #1e293b;
    padding: 8px 0;
    max-height: 120px;
    overflow-y: auto;
}

#aca-chat-input::placeholder {
    color: #94a3b8;
}

.aca-chat-send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: var(--aca-primary, #2563eb);
    color: var(--aca-text, #ffffff);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.aca-chat-send-btn:hover:not(:disabled) {
    background: var(--aca-secondary, #1e40af);
    transform: scale(1.05);
}

.aca-chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.aca-chat-send-btn svg {
    fill: none;
    stroke: currentColor;
}

/* Powered by */
.aca-powered-by {
    text-align: center;
    font-size: 10px;
    color: #94a3b8;
    margin-top: 8px;
}

/* =============================================
   HUMAN HANDOFF CARD
   ============================================= */
.aca-handoff-card {
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 16px;
    padding: 16px;
    margin: 4px 0;
    align-self: flex-start;
    max-width: 92%;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    animation: aca-msg-appear 0.3s ease;
}

.aca-handoff-title {
    font-weight: 700;
    font-size: 14px;
    color: #1e293b;
    margin-bottom: 4px;
}

.aca-handoff-subtitle {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 12px;
}

.aca-handoff-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

.aca-handoff-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: none;
    transition: all 0.2s ease;
}

.aca-btn-call {
    background: #dcfce7;
    color: #166534;
}
.aca-btn-call:hover { background: #bbf7d0; }

.aca-btn-email {
    background: #eff6ff;
    color: #1e40af;
}
.aca-btn-email:hover { background: #dbeafe; }

.aca-btn-notify {
    background: #fefce8;
    color: #854d0e;
}
.aca-btn-notify:hover { background: #fef08a; }

.aca-handoff-form {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.aca-handoff-form input {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    color: #1e293b;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}

.aca-handoff-form input:focus {
    border-color: var(--aca-primary, #2563eb);
}

.aca-handoff-send-btn {
    background: var(--aca-primary, #2563eb);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    font-family: inherit;
}

.aca-handoff-send-btn:hover { opacity: 0.85; }
.aca-handoff-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.aca-handoff-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 500;
}

/* =============================================
   MOBILE RESPONSIVE
   ============================================= */
@media (max-width: 480px) {
    #aca-chat-widget {
        bottom: 12px;
        right: 12px;
        left: 12px;
    }

    #aca-chat-widget.aca-position-bottom-left {
        left: 12px;
        right: 12px;
    }

    .aca-chat-window {
        width: calc(100vw - 24px) !important;
        height: calc(100vh - 80px) !important;
        max-height: calc(100vh - 80px);
        border-radius: 16px;
    }

    .aca-position-bottom-right .aca-chat-window,
    .aca-position-bottom-left .aca-chat-window {
        right: 0;
        left: 0;
    }

    .aca-chat-bubble {
        position: fixed;
        bottom: 12px;
        right: 12px;
    }

    .aca-position-bottom-left .aca-chat-bubble {
        right: auto;
        left: 12px;
    }
}