/**
 * Nexa WhatsApp Chat - Frontend Styles
 * 
 * @package Nexa_WhatsApp_Chat
 * @since 1.0.0
 */

/* ============================================
   CSS Custom Properties (set via JS from settings)
   ============================================ */
:root {
    --nexa-wa-bubble-color: #25D366;
    --nexa-wa-header-color: #075E54;
    --nexa-wa-bubble-size: 60px;
    --nexa-wa-offset-x: 20px;
    --nexa-wa-offset-y: 20px;
    --nexa-wa-widget-width: 370px;
    --nexa-wa-widget-height: 480px;
    --nexa-wa-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --nexa-wa-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    --nexa-wa-radius: 16px;
    --nexa-wa-z-index: 999999;
}

/* ============================================
   Container
   ============================================ */
.nexa-wa-container {
    position: fixed;
    z-index: var(--nexa-wa-z-index);
    font-family: var(--nexa-wa-font);
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

.nexa-wa-container *,
.nexa-wa-container *::before,
.nexa-wa-container *::after {
    box-sizing: border-box;
}

/* Position variants */
.nexa-wa-container[data-position="bottom-right"] {
    bottom: var(--nexa-wa-offset-y);
    right: var(--nexa-wa-offset-x);
}

.nexa-wa-container[data-position="bottom-left"] {
    bottom: var(--nexa-wa-offset-y);
    left: var(--nexa-wa-offset-x);
}

.nexa-wa-container[data-position="top-right"] {
    top: var(--nexa-wa-offset-y);
    right: var(--nexa-wa-offset-x);
}

.nexa-wa-container[data-position="top-left"] {
    top: var(--nexa-wa-offset-y);
    left: var(--nexa-wa-offset-x);
}

/* ============================================
   Chat Bubble
   ============================================ */
.nexa-wa-bubble {
    width: var(--nexa-wa-bubble-size);
    height: var(--nexa-wa-bubble-size);
    border-radius: 50%;
    background-color: var(--nexa-wa-bubble-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--nexa-wa-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    outline: none;
    padding: 0;
}

.nexa-wa-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.2);
}

.nexa-wa-bubble:active {
    transform: scale(0.95);
}

.nexa-wa-bubble-icon {
    width: 55%;
    height: 55%;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.nexa-wa-bubble-close {
    width: 50%;
    height: 50%;
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* When widget is open */
.nexa-wa-container.nexa-wa-open .nexa-wa-bubble-icon {
    opacity: 0;
    transform: rotate(90deg);
}

.nexa-wa-container.nexa-wa-open .nexa-wa-bubble-close {
    opacity: 1;
    transform: rotate(0deg);
}

/* Notification badge */
.nexa-wa-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ff4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* ============================================
   Bubble Animations
   ============================================ */
.nexa-wa-animation-pulse {
    animation: nexa-wa-pulse 2s ease-in-out infinite;
}

.nexa-wa-animation-bounce {
    animation: nexa-wa-bounce 2s ease infinite;
}

.nexa-wa-animation-shake {
    animation: nexa-wa-shake 6s ease-in-out infinite;
}

/* Stop animation when widget is open */
.nexa-wa-container.nexa-wa-open .nexa-wa-bubble {
    animation: none;
}

@keyframes nexa-wa-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.5); }
    50% { box-shadow: 0 0 0 15px rgba(37, 211, 102, 0); }
}

@keyframes nexa-wa-bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-8px); }
    60% { transform: translateY(-4px); }
}

@keyframes nexa-wa-shake {
    0%, 85%, 100% { transform: rotate(0); }
    87% { transform: rotate(10deg); }
    89% { transform: rotate(-10deg); }
    91% { transform: rotate(8deg); }
    93% { transform: rotate(-6deg); }
    95% { transform: rotate(4deg); }
}

/* ============================================
   Tooltip
   ============================================ */
.nexa-wa-tooltip {
    position: absolute;
    background: white;
    color: #333;
    padding: 10px 36px 10px 14px;
    border-radius: 10px;
    box-shadow: var(--nexa-wa-shadow);
    font-size: 13px;
    white-space: nowrap;
    animation: nexa-wa-fadeIn 0.3s ease;
}

.nexa-wa-container[data-position="bottom-right"] .nexa-wa-tooltip,
.nexa-wa-container[data-position="top-right"] .nexa-wa-tooltip {
    right: calc(var(--nexa-wa-bubble-size) + 12px);
    bottom: calc(var(--nexa-wa-bubble-size) / 2 - 18px);
}

.nexa-wa-container[data-position="bottom-left"] .nexa-wa-tooltip,
.nexa-wa-container[data-position="top-left"] .nexa-wa-tooltip {
    left: calc(var(--nexa-wa-bubble-size) + 12px);
    bottom: calc(var(--nexa-wa-bubble-size) / 2 - 18px);
}

.nexa-wa-tooltip-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: #999;
    padding: 2px 4px;
    line-height: 1;
}

.nexa-wa-tooltip-close:hover {
    color: #333;
}

/* ============================================
   Chat Widget Panel
   ============================================ */
.nexa-wa-widget {
    position: absolute;
    width: var(--nexa-wa-widget-width);
    max-height: var(--nexa-wa-widget-height);
    background: #E5DDD5;
    border-radius: var(--nexa-wa-radius);
    box-shadow: var(--nexa-wa-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: nexa-wa-slideUp 0.3s ease;
}

/* Widget positioning */
.nexa-wa-container[data-position="bottom-right"] .nexa-wa-widget,
.nexa-wa-container[data-position="bottom-left"] .nexa-wa-widget {
    bottom: calc(var(--nexa-wa-bubble-size) + 14px);
}

.nexa-wa-container[data-position="bottom-right"] .nexa-wa-widget {
    right: 0;
}

.nexa-wa-container[data-position="bottom-left"] .nexa-wa-widget {
    left: 0;
}

.nexa-wa-container[data-position="top-right"] .nexa-wa-widget,
.nexa-wa-container[data-position="top-left"] .nexa-wa-widget {
    top: calc(var(--nexa-wa-bubble-size) + 14px);
}

.nexa-wa-container[data-position="top-right"] .nexa-wa-widget {
    right: 0;
}

.nexa-wa-container[data-position="top-left"] .nexa-wa-widget {
    left: 0;
}

@keyframes nexa-wa-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* ============================================
   Widget Header
   ============================================ */
.nexa-wa-widget-header {
    background-color: var(--nexa-wa-header-color);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.nexa-wa-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nexa-wa-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.nexa-wa-header-text {
    display: flex;
    flex-direction: column;
}

.nexa-wa-header-name {
    font-size: 15px;
    font-weight: 600;
}

.nexa-wa-header-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
}

.nexa-wa-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ADE80;
    display: inline-block;
}

.nexa-wa-status-dot.offline {
    background: #FB923C;
}

.nexa-wa-widget-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: white;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.nexa-wa-widget-close:hover {
    opacity: 1;
}

.nexa-wa-widget-close svg {
    width: 20px;
    height: 20px;
}

/* ============================================
   Widget Body (Chat Area)
   ============================================ */
.nexa-wa-widget-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    min-height: 200px;
    max-height: 250px;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c5b9a8' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* Message bubbles */
.nexa-wa-message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.nexa-wa-message-received .nexa-wa-message-content {
    background: white;
    border-radius: 0 12px 12px 12px;
    padding: 10px 14px;
    max-width: 85%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    font-size: 13.5px;
    color: #333;
    line-height: 1.45;
    word-wrap: break-word;
}

.nexa-wa-message-sent .nexa-wa-message-content {
    background: #DCF8C6;
    border-radius: 12px 0 12px 12px;
    padding: 10px 14px;
    max-width: 85%;
    align-self: flex-end;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    font-size: 13.5px;
    color: #333;
    line-height: 1.45;
}

.nexa-wa-message-sent {
    align-items: flex-end;
}

.nexa-wa-message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    padding: 0 4px;
}

/* ============================================
   Widget Footer / Input
   ============================================ */
.nexa-wa-widget-footer {
    background: white;
    padding: 10px 12px;
    flex-shrink: 0;
    border-top: 1px solid #eee;
}

.nexa-wa-visitor-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.nexa-wa-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--nexa-wa-font);
    outline: none;
    transition: border-color 0.2s;
}

.nexa-wa-input:focus {
    border-color: var(--nexa-wa-bubble-color);
}

.nexa-wa-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.nexa-wa-message-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 13px;
    font-family: var(--nexa-wa-font);
    resize: none;
    outline: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.nexa-wa-message-input:focus {
    border-color: var(--nexa-wa-bubble-color);
}

.nexa-wa-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--nexa-wa-bubble-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.2s, transform 0.1s;
    padding: 0;
}

.nexa-wa-send-btn:hover {
    filter: brightness(1.1);
}

.nexa-wa-send-btn:active {
    transform: scale(0.9);
}

.nexa-wa-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* POPIA Consent */
.nexa-wa-consent {
    padding: 8px 0 0;
}

.nexa-wa-consent-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 11px;
    color: #666;
    cursor: pointer;
    line-height: 1.4;
}

.nexa-wa-consent-label input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
}

.nexa-wa-consent-label a {
    color: var(--nexa-wa-header-color);
    text-decoration: underline;
}

/* Powered by */
.nexa-wa-powered-by {
    text-align: center;
    padding: 6px 0 2px;
}

.nexa-wa-powered-by a {
    font-size: 10px;
    color: #aaa;
    text-decoration: none;
}

.nexa-wa-powered-by a:hover {
    color: #777;
}

/* Status bar */
.nexa-wa-status-bar {
    background: #f0f9f0;
    padding: 8px 14px;
    text-align: center;
    font-size: 12px;
    color: #25D366;
    border-top: 1px solid #ddd;
}

.nexa-wa-status-bar.error {
    background: #fef2f2;
    color: #ef4444;
}

/* ============================================
   Mobile Responsive
   ============================================ */
@media (max-width: 480px) {
    .nexa-wa-widget {
        width: calc(100vw - 30px);
        max-height: 85vh;
        position: fixed;
        bottom: 15px !important;
        top: auto !important;
        left: 15px !important;
        right: 15px !important;
        border-radius: 12px;
    }

    .nexa-wa-widget-body {
        max-height: 45vh;
    }

    .nexa-wa-tooltip {
        display: none !important;
    }
}

/* ============================================
   Accessibility
   ============================================ */
.nexa-wa-bubble:focus-visible,
.nexa-wa-send-btn:focus-visible,
.nexa-wa-widget-close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .nexa-wa-bubble,
    .nexa-wa-widget,
    .nexa-wa-tooltip {
        animation: none !important;
        transition: none !important;
    }
}

/* Print: hide widget */
@media print {
    .nexa-wa-container {
        display: none !important;
    }
}
