/*
 * Zoe Chat Drawer Component
 * A modular chat drawer that can be included on any page
 *
 * Usage:
 * 1. Include this CSS: <link rel="stylesheet" href="/public/css/zoe-chat.css">
 * 2. Include the HTML partial (see zoe-chat.html or copy the markup)
 * 3. Include the JS: <script src="/public/js/zoe-chat.js"></script>
 */

/* ============================================
   Fixed Help Button
   ============================================ */
.zoe-help-btn {
    position: fixed;
    bottom: 15px;
    right: 15px;
    z-index: 3000;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--accent);
    color: white;
    font-size: 18px;
    font-weight: 600;
    padding: 16px 32px;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 14px rgba(243, 112, 33, 0.3);
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
}

.zoe-help-btn:hover {
    background: var(--accent-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(243, 112, 33, 0.4);
}

.zoe-help-btn.hidden {
    display: none;
}

/* Scroll-aware: when a primary CTA marked .zoe-fab-shy is in the lower
   viewport, fade and lift the FAB out of the way so it never overlaps
   the conversion-critical button (HF-1 / P-8 from the website
   first-week audit). Mark CTAs with class="zoe-fab-shy" and the
   IntersectionObserver in zoe-chat.js will toggle .zoe-help-btn--shy. */
.zoe-help-btn--shy {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.zoe-help-btn svg {
    width: 24px;
    height: 24px;
}

/* ============================================
   Chat Drawer Backdrop
   ============================================ */
.zoe-chat-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.zoe-chat-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   Chat Drawer Panel
   ============================================ */
.zoe-chat-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 450px;
    z-index: 3002;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    background: var(--card, white);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.zoe-chat-drawer.active {
    transform: translateX(0);
}

/* ============================================
   Chat Header
   ============================================ */
.zoe-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--card, white);
    flex-shrink: 0;
}

.zoe-chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.zoe-chat-back {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 50%;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoe-chat-back:hover {
    background: var(--bg);
}

.zoe-chat-back svg {
    width: 24px;
    height: 24px;
}

.zoe-chat-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.zoe-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-family: 'Fjalla One', sans-serif;
    font-size: 20px;
}

.zoe-chat-title-text h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    font-family: 'Montserrat', sans-serif;
    margin: 0;
}

.zoe-chat-title-text span {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================
   Chat Messages
   ============================================ */
.zoe-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

/* Spacer pushes messages to bottom when few messages */
.zoe-chat-spacer {
    flex: 1 1 auto;
    min-height: 0;
}

.zoe-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.5;
}

.zoe-message.zoe {
    background: var(--bg);
    color: var(--text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.zoe-message.user {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.zoe-action-group {
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 85%;
}

.zoe-action-btn {
    appearance: none;
    border: 1px solid var(--primary);
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    padding: 10px 12px;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.zoe-action-btn.primary {
    background: var(--primary);
    color: white;
}

.zoe-action-btn.secondary {
    background: var(--card, white);
    color: var(--primary);
}

.zoe-action-btn:hover:not(:disabled) {
    border-color: var(--primary-dark);
}

.zoe-action-btn.primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.zoe-action-btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

/* Links in Zoe's messages */
.zoe-message.zoe a {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 600;
}

.zoe-message.zoe a:hover {
    color: var(--primary-dark);
}

/* ============================================
   Typing Indicator
   ============================================ */
.zoe-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 60px;
}

.zoe-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: zoe-typing 1.4s infinite;
}

.zoe-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.zoe-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

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

/* ============================================
   Chat Input
   ============================================ */
.zoe-chat-input-container {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    background: var(--card, white);
    flex-shrink: 0;
}

.zoe-chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}

.zoe-chat-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.zoe-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: background 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.zoe-chat-send:hover {
    background: var(--accent-dark);
}

.zoe-chat-send:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.zoe-chat-send svg {
    width: 20px;
    height: 20px;
}

/* ============================================
   Mobile Responsive
   ============================================ */
@media (max-width: 768px) {
    .zoe-chat-drawer {
        max-width: 100%;
    }

    .zoe-help-btn {
        bottom: 15px;
        right: 12px;
        font-size: 14px;
        padding: 10px 18px;
        background: var(--accent);
    }

    .zoe-help-need {
        display: none;
    }
}

/* ============================================
   Dark Mode
   ============================================ */
html[data-theme="dark"] .zoe-chat-input {
    background: var(--card);
    color: var(--text);
    border-color: var(--border);
}

html[data-theme="dark"] .zoe-chat-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(74, 158, 255, 0.2);
}

/* ============================================
   Payment Modal (Phase 4)
   ============================================ */
.zoe-payment-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 3003;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}
.zoe-payment-overlay.active {
    display: flex;
}
.zoe-payment-modal {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    margin: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}
.zoe-payment-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #e5e7eb;
}
.zoe-payment-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #111;
}
.zoe-payment-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    line-height: 1;
}
.zoe-payment-body {
    padding: 20px 24px;
}
.zoe-payment-summary {
    font-size: 14px;
    color: #555;
    margin-bottom: 8px;
    line-height: 1.5;
}
.zoe-payment-amount {
    font-size: 28px;
    font-weight: 700;
    color: #111;
    margin-bottom: 20px;
}
#zoe-square-card-container {
    min-height: 44px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    transition: border-color 0.2s;
}
#zoe-square-card-container:focus-within {
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.zoe-payment-error {
    color: #dc2626;
    font-size: 13px;
    min-height: 20px;
    margin-bottom: 4px;
}
.zoe-payment-footer {
    padding: 0 24px 16px;
    display: flex;
    gap: 12px;
}
.zoe-payment-btn {
    flex: 1;
    padding: 14px 24px;
    background: var(--accent, #3b82f6);
    color: white;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: opacity 0.2s;
}
.zoe-payment-btn:hover {
    opacity: 0.9;
}
.zoe-payment-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.zoe-payment-cancel {
    padding: 14px 20px;
    background: none;
    border: 1px solid #d1d5db;
    color: #555;
    font-size: 14px;
    border-radius: 10px;
    cursor: pointer;
}
.zoe-payment-cancel:hover {
    background: #f3f4f6;
}
.zoe-payment-secure {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    font-size: 12px;
    color: #888;
    border-top: 1px solid #e5e7eb;
}

/* Dark mode payment modal */
html[data-theme="dark"] .zoe-payment-modal {
    background: var(--card, #1e1e2e);
}
html[data-theme="dark"] .zoe-payment-header {
    border-color: var(--border, #333);
}
html[data-theme="dark"] .zoe-payment-header h3 {
    color: var(--text, #eee);
}
html[data-theme="dark"] .zoe-payment-amount {
    color: var(--text, #eee);
}
html[data-theme="dark"] .zoe-payment-summary {
    color: var(--text-muted, #999);
}
html[data-theme="dark"] #zoe-square-card-container {
    border-color: var(--border, #444);
    background: var(--bg, #111);
}
html[data-theme="dark"] .zoe-payment-secure {
    border-color: var(--border, #333);
}

@media (max-width: 480px) {
    .zoe-payment-modal {
        margin: 10px;
        max-width: none;
    }
}
