/* ============================================================
   Apricot AI Chat — Tawk.to-inspired Widget Styles
   ============================================================ */

/* ── CSS Variables ───────────────────────────────────────── */
:root {
    --aac-primary:       #ffbb84;   /* apricot orange */
    --aac-primary-dark:  #f0a060;
    --aac-primary-light: #fff4ec;
    --aac-primary-text:  #7a3b00;   /* dark text on light orange bg */
    --aac-bg:            #ffffff;
    --aac-msg-bg:        #f1f1f1;
    --aac-text:          #1a1a1a;
    --aac-text-muted:    #8a8a8a;
    --aac-border:        #e5e5e5;
    --aac-shadow:        0 8px 48px rgba(0,0,0,0.18);
    --aac-radius:        16px;
}

/* ── Base widget container ───────────────────────────────── */
.aac-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--aac-text);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* ── Toggle button ───────────────────────────────────────── */
.aac-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--aac-primary);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(255, 187, 132, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    outline: none;
    flex-shrink: 0;
    position: relative;
}
.aac-toggle:hover {
    background: var(--aac-primary-dark);
    transform: scale(1.06);
    box-shadow: 0 6px 26px rgba(255, 187, 132, 0.65);
}
.aac-toggle:focus-visible {
    box-shadow: 0 0 0 3px rgba(255, 187, 132, 0.45);
}

/* Tawk-style chat icon inside button */
.aac-toggle-icon {
    font-size: 26px;
    line-height: 1;
    transition: opacity 0.15s, transform 0.2s;
    color: #7a3b00;
}
.aac-toggle .aac-icon-close {
    font-size: 20px;
    font-weight: 700;
}

/* Notification badge */
.aac-toggle::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff4757;
    border: 2px solid #fff;
    display: none;
}
.aac-has-unread .aac-toggle::after { display: block; }

/* ── Chat box ────────────────────────────────────────────── */
.aac-chat-box {
    width: 370px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 100px);
    background: var(--aac-bg);
    border-radius: var(--aac-radius);
    box-shadow: var(--aac-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 14px;
    animation: aac-slide-up 0.25s cubic-bezier(.4,0,.2,1);
    transform-origin: bottom right;
    border: 1px solid rgba(0,0,0,0.08);
}
.aac-chat-box[hidden] { display: none; }

@keyframes aac-slide-up {
    from { opacity: 0; transform: translateY(16px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ── Header ──────────────────────────────────────────────── */
.aac-header {
    background: var(--aac-primary);
    color: #7a3b00;
    padding: 16px 18px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}
/* Subtle pattern overlay like tawk */
.aac-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='20' cy='20' r='1' fill='rgba(255,255,255,0.06)'/%3E%3C/svg%3E") repeat;
    pointer-events: none;
}

.aac-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    border: 2px solid var(--aac-primary);
}
/* Online dot on avatar */
.aac-header-avatar::after {
    content: '';
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff3e0;
    border: 2px solid var(--aac-primary);
}

.aac-header-info {
    flex: 1;
    min-width: 0;
}
.aac-title {
    font-weight: 700;
    font-size: 15px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.01em;
}
.aac-subtitle {
    font-size: 12px;
    opacity: 0.88;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}
.aac-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fff3e0;
    display: inline-block;
    animation: aac-pulse 2s infinite;
}
@keyframes aac-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.35; }
}

/* Close button in header (optional — uses existing toggle) */
.aac-header-close {
    background: transparent;
    border: none;
    color: rgba(122, 59, 0, 0.7);
    font-size: 20px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
    flex-shrink: 0;
}
.aac-header-close:hover {
    background: rgba(122, 59, 0, 0.12);
    color: #7a3b00;
}

/* ── Greeting banner (below header) ─────────────────────── */
.aac-greeting {
    background: var(--aac-primary-light);
    padding: 10px 18px;
    font-size: 13px;
    color: var(--aac-primary-text);
    border-bottom: 1px solid rgba(255,187,132,0.25);
    flex-shrink: 0;
}

/* ── Messages area ───────────────────────────────────────── */
.aac-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    background: #f7f7f7;
}
.aac-messages::-webkit-scrollbar { width: 4px; }
.aac-messages::-webkit-scrollbar-track { background: transparent; }
.aac-messages::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 4px; }

/* ── Date/time separator ─────────────────────────────────── */
.aac-date-sep {
    text-align: center;
    font-size: 11px;
    color: var(--aac-text-muted);
    margin: 4px 0;
    position: relative;
}
.aac-date-sep::before, .aac-date-sep::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 28%;
    height: 1px;
    background: var(--aac-border);
}
.aac-date-sep::before { left: 0; }
.aac-date-sep::after  { right: 0; }

/* ── Message bubbles ─────────────────────────────────────── */
.aac-msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: aac-msg-in 0.2s ease;
}
@keyframes aac-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.aac-msg--bot  { align-self: flex-start; }
.aac-msg--user { align-self: flex-end;   }

/* Tawk: bot message has a small avatar on the left */
.aac-msg--bot {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    max-width: 86%;
}
.aac-msg--bot .aac-msg-inner {
    display: flex;
    flex-direction: column;
}
.aac-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--aac-primary);
    color: #7a3b00;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.aac-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.6;
}
.aac-msg--bot .aac-bubble {
    background: #ffffff;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
    color: var(--aac-text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}
.aac-msg--user .aac-bubble {
    background: var(--aac-primary);
    color: #7a3b00;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(255,187,132,0.40);
}

.aac-msg-time {
    font-size: 10.5px;
    color: var(--aac-text-muted);
    margin-top: 4px;
    padding: 0 4px;
}
.aac-msg--user .aac-msg-time { text-align: right; }

/* read tick for user messages (tawk-style) */
.aac-msg--user .aac-msg-time::after {
    content: ' ✓✓';
    color: #f0a060;
    font-size: 10px;
}

/* ── Typing indicator ────────────────────────────────────── */
.aac-typing .aac-bubble {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #e8e8e8;
}
.aac-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c0c0c0;
    animation: aac-bounce 1.3s infinite ease-in-out;
}
.aac-typing-dot:nth-child(2) { animation-delay: 0.18s; }
.aac-typing-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes aac-bounce {
    0%, 80%, 100% { transform: translateY(0);   opacity: 0.5; }
    40%            { transform: translateY(-6px); opacity: 1;   }
}

/* ── WhatsApp fallback banner ────────────────────────────── */
.aac-fallback {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin: 0 12px 6px;
    background: #fff4ec;
    border: 1px solid #ffd4aa;
    border-radius: 12px;
    font-size: 13px;
    color: #7a3b00;
    animation: aac-msg-in 0.2s ease;
}
.aac-fallback-text { flex: 1; line-height: 1.4; }
.aac-fallback-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #25d366;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 7px 13px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s, transform 0.15s;
    box-shadow: 0 2px 6px rgba(37,211,102,0.35);
}
.aac-fallback-btn:hover {
    background: #1da851;
    color: #fff;
    transform: translateY(-1px);
}
.aac-fallback-btn svg { flex-shrink: 0; }

/* ── Input area ──────────────────────────────────────────── */
.aac-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--aac-border);
    background: #fff;
    flex-shrink: 0;
}
.aac-input {
    flex: 1;
    resize: none;
    border: 1px solid #ddd;
    border-radius: 22px;
    padding: 9px 16px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    max-height: 110px;
    overflow-y: auto;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f7f7f7;
    color: var(--aac-text);
}
.aac-input::placeholder { color: #b0b0b0; }
.aac-input:focus {
    border-color: var(--aac-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255,187,132,0.28);
}

.aac-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--aac-primary);
    border: none;
    cursor: pointer;
    color: #7a3b00;
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.15s, background 0.2s;
    outline: none;
    box-shadow: 0 2px 8px rgba(255,187,132,0.50);
}
.aac-send:hover    { background: var(--aac-primary-dark); transform: scale(1.08); }
.aac-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

/* Powered-by footer (tawk shows "Powered by tawk") */
.aac-powered {
    text-align: center;
    font-size: 10.5px;
    color: #bbb;
    padding: 5px 0 7px;
    background: #fff;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    border-top: 1px solid #f0f0f0;
}
.aac-powered a {
    color: var(--aac-primary-dark);
    text-decoration: none;
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 480px) {
    .aac-widget {
        bottom: 14px;
        right: 14px;
    }
    .aac-chat-box {
        width: calc(100vw - 28px);
        height: calc(100vh - 80px);
        border-radius: 14px;
    }
}
