/* ═══════════════════════════════════════════════════
   SN AI Assistant – Chatbot & Voice Widget Styles
   Brand: SN Plumbing Solutions
   Colors: Primary #113B62, Secondary #40A0D9, Accent #FCB511
   ═══════════════════════════════════════════════════ */

/* CSS Custom Properties – configurable from admin */
:root {
    --sn-primary: #113B62;
    --sn-secondary: #40A0D9;
    --sn-accent: #FCB511;
    --sn-bg: #f4fafd;
    --sn-card: #ffffff;
    --sn-text: #1a2b3d;
    --sn-text-light: #5a6f83;
    --sn-border: #cfe2ee;
    --sn-shadow: rgba(17, 59, 98, 0.15);
    --sn-radius: 16px;
    --sn-font: 'Poppins', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ── Toggle Button ── */
#sn-ai-toggle {
    position: fixed;
    z-index: 999998;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sn-primary), var(--sn-secondary));
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--sn-shadow), 0 0 0 0 rgba(64, 160, 217, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: sn-pulse 3s infinite;
}

#sn-ai-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px var(--sn-shadow);
}

#sn-ai-toggle.active {
    animation: none;
    background: linear-gradient(135deg, #d63638, #ff6b6b);
}

#sn-ai-toggle svg {
    width: 28px;
    height: 28px;
    fill: #fff;
    transition: transform 0.3s ease;
}

#sn-ai-toggle.active svg.sn-icon-chat { display: none; }
#sn-ai-toggle:not(.active) svg.sn-icon-close { display: none; }
#sn-ai-toggle.active svg.sn-icon-close { display: block; }

/* Position variants */
.sn-pos-bottom-right #sn-ai-toggle { bottom: 24px; right: 24px; }
.sn-pos-bottom-left #sn-ai-toggle { bottom: 24px; left: 24px; }
.sn-pos-middle-right #sn-ai-toggle { bottom: 50%; right: 24px; transform: translateY(50%); }

@keyframes sn-pulse {
    0% { box-shadow: 0 4px 20px var(--sn-shadow), 0 0 0 0 rgba(64, 160, 217, 0.5); }
    50% { box-shadow: 0 4px 20px var(--sn-shadow), 0 0 0 12px rgba(64, 160, 217, 0); }
    100% { box-shadow: 0 4px 20px var(--sn-shadow), 0 0 0 0 rgba(64, 160, 217, 0); }
}

/* ── Chat Window (Desktop) ── */
#sn-ai-window {
    position: fixed;
    z-index: 999999;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 100px);
    border-radius: var(--sn-radius);
    background: var(--sn-bg);
    box-shadow: 0 12px 48px rgba(17, 59, 98, 0.25), 0 0 0 1px rgba(17, 59, 98, 0.08);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--sn-font);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#sn-ai-window.visible {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Position variants for window */
.sn-pos-bottom-right #sn-ai-window { bottom: 96px; right: 24px; }
.sn-pos-bottom-left #sn-ai-window { bottom: 96px; left: 24px; }
.sn-pos-middle-right #sn-ai-window { bottom: calc(50% - 220px); right: 24px; }

/* ── Header ── */
.sn-ai-header {
    background: linear-gradient(135deg, var(--sn-primary), var(--sn-secondary));
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sn-ai-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.3);
}

.sn-ai-avatar svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}

.sn-ai-header-info {
    flex: 1;
}

.sn-ai-header-title {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.sn-ai-header-subtitle {
    color: rgba(255,255,255,0.7);
    font-size: 12px;
    margin: 2px 0 0;
    line-height: 1.3;
}

.sn-header-call {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #FCB511;
    color: #113B62;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.sn-header-call:hover {
    background: #fff;
    color: #113B62;
    transform: scale(1.05);
}

.sn-header-call svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.sn-ai-online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    margin-right: 4px;
    animation: sn-blink 2s infinite;
}

@keyframes sn-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Messages Area ── */
.sn-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.sn-ai-messages::-webkit-scrollbar {
    width: 5px;
}

.sn-ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.sn-ai-messages::-webkit-scrollbar-thumb {
    background: var(--sn-border);
    border-radius: 10px;
}

/* ── Message Bubbles ── */
.sn-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: sn-fadeIn 0.3s ease;
}

@keyframes sn-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.sn-msg-bot {
    align-self: flex-start;
    background: var(--sn-card);
    color: var(--sn-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.sn-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--sn-primary), var(--sn-secondary));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.sn-msg-bot strong, .sn-msg-bot b {
    color: var(--sn-primary);
}

.sn-msg-emergency {
    border-left: 3px solid #d63638;
    background: #fef2f2;
}

.sn-msg-bot a {
    color: var(--sn-secondary);
    text-decoration: underline;
}

/* ── Typing Indicator ── */
.sn-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 14px 20px;
    background: var(--sn-card);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.sn-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sn-secondary);
    animation: sn-typingAnim 1.4s ease-in-out infinite;
}

.sn-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.sn-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes sn-typingAnim {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1.1); }
}

/* ── TTS Play Button on Bot Messages ── */
.sn-tts-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 5px 12px;
    background: #f1f7fa;
    border: 1px solid #c9e2ef;
    border-radius: 20px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    color: #113B62;
    transition: all 0.2s ease;
    user-select: none;
}

.sn-tts-btn:hover {
    background: #40A0D9;
    color: #fff;
    border-color: #40A0D9;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(64,160,217,0.25);
}

.sn-tts-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
    flex-shrink: 0;
}

.sn-tts-btn.playing {
    background: #e74c3c !important;
    color: #ffffff !important;
    border-color: #e74c3c !important;
    animation: sn-audioPulse 1.5s infinite;
}

@keyframes sn-audioPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(231, 76, 60, 0); }
}

/* ── Input Area ── */
.sn-ai-input-area {
    padding: 12px 14px;
    background: var(--sn-card);
    border-top: 1px solid var(--sn-border);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.sn-ai-input-wrap {
    flex: 1;
    position: relative;
}

#sn-ai-input {
    width: 100%;
    border: 1.5px solid var(--sn-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--sn-font);
    background: var(--sn-bg);
    color: var(--sn-text);
    resize: none;
    min-height: 42px;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s ease;
    line-height: 1.4;
    box-sizing: border-box;
}

#sn-ai-input:focus {
    border-color: var(--sn-secondary);
    box-shadow: 0 0 0 3px rgba(64, 160, 217, 0.15);
}

#sn-ai-input::placeholder {
    color: var(--sn-text-light);
    opacity: 0.7;
}

/* Action buttons */
.sn-ai-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.sn-ai-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

#sn-ai-send {
    background: linear-gradient(135deg, var(--sn-primary), var(--sn-secondary));
    color: #fff;
}

#sn-ai-send:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 12px rgba(17, 59, 98, 0.3);
}

#sn-ai-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#sn-ai-voice {
    background: var(--sn-bg);
    color: var(--sn-text-light);
    border: 1.5px solid var(--sn-border);
}

#sn-ai-voice:hover {
    border-color: var(--sn-secondary);
    color: var(--sn-secondary);
}

#sn-ai-voice.listening {
    background: #fef2f2;
    border-color: #d63638;
    color: #d63638;
    animation: sn-voicePulse 1.5s infinite;
}

@keyframes sn-voicePulse {
    0% { box-shadow: 0 0 0 0 rgba(214, 54, 56, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(214, 54, 56, 0); }
    100% { box-shadow: 0 0 0 0 rgba(214, 54, 56, 0); }
}

/* ── Quick Actions Bar (Single horizontal scrollable row) ── */
.sn-ai-quick-actions {
    padding: 8px 12px;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    background: var(--sn-card);
    border-top: 1px solid var(--sn-border);
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sn-ai-quick-actions::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.sn-quick-btn {
    flex: 0 0 auto;
    padding: 6px 13px;
    border-radius: 20px;
    border: 1px solid var(--sn-border);
    background: var(--sn-bg);
    color: var(--sn-text);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--sn-font);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.sn-quick-btn:hover {
    background: var(--sn-secondary);
    color: #fff;
    border-color: var(--sn-secondary);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(64,160,217,0.25);
}

/* ── Service Request Form ── */
.sn-lead-form {
    padding: 16px;
    background: var(--sn-card);
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    margin: 4px 0;
    animation: sn-fadeIn 0.3s ease;
}

.sn-lead-form h4 {
    color: var(--sn-primary);
    font-size: 15px;
    font-weight: 700;
    margin: 0 0 12px;
}

.sn-lead-form label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--sn-text);
    margin-bottom: 4px;
}

.sn-lead-form label .required {
    color: #d63638;
}

.sn-lead-form input,
.sn-lead-form select,
.sn-lead-form textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid var(--sn-border);
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--sn-font);
    background: var(--sn-bg);
    color: var(--sn-text);
    margin-bottom: 10px;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s ease;
}

.sn-lead-form input:focus,
.sn-lead-form select:focus,
.sn-lead-form textarea:focus {
    border-color: var(--sn-secondary);
}

.sn-lead-form textarea {
    min-height: 60px;
    resize: vertical;
}

.sn-lead-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.sn-lead-submit {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, var(--sn-primary), var(--sn-secondary));
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--sn-font);
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 4px;
}

.sn-lead-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--sn-shadow);
}

.sn-lead-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ── Confirmation Review ── */
.sn-lead-review {
    padding: 14px;
    background: #f0f9ff;
    border: 1px solid var(--sn-border);
    border-radius: 10px;
    margin: 4px 0;
    animation: sn-fadeIn 0.3s ease;
}

.sn-lead-review h4 {
    color: var(--sn-primary);
    font-size: 14px;
    margin: 0 0 10px;
}

.sn-lead-review p {
    font-size: 13px;
    margin: 4px 0;
    color: var(--sn-text);
}

.sn-lead-review p strong {
    color: var(--sn-primary);
}

.sn-review-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.sn-review-confirm {
    flex: 1;
    padding: 8px;
    background: var(--sn-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--sn-font);
}

.sn-review-edit {
    flex: 1;
    padding: 8px;
    background: transparent;
    color: var(--sn-text-light);
    border: 1px solid var(--sn-border);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    font-family: var(--sn-font);
}

/* ── Powered By Footer ── */
.sn-ai-footer {
    padding: 6px 14px;
    text-align: center;
    font-size: 10px;
    color: var(--sn-text-light);
    background: var(--sn-card);
    border-top: 1px solid var(--sn-border);
    flex-shrink: 0;
}

.sn-ai-footer a {
    color: var(--sn-secondary);
    text-decoration: none;
}

/* ═══════════════════════════════════
   MOBILE STYLES (Bottom Sheet)
   ═══════════════════════════════════ */
@media (max-width: 480px) {
    #sn-ai-toggle {
        width: 54px;
        height: 54px;
        bottom: 16px !important;
        right: 16px !important;
        left: auto !important;
    }

    #sn-ai-window {
        width: 100vw;
        max-width: 100vw;
        height: calc(100vh - 60px);
        max-height: calc(100vh - 60px);
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        border-radius: var(--sn-radius) var(--sn-radius) 0 0;
        transform: translateY(100%);
    }

    #sn-ai-window.visible {
        transform: translateY(0);
    }

    .sn-ai-header {
        padding: 14px 16px;
    }

    /* Bottom sheet drag handle */
    .sn-ai-header::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: rgba(255,255,255,0.3);
    }

    .sn-ai-messages {
        padding: 12px;
    }

    .sn-msg {
        max-width: 90%;
        font-size: 15px;
    }

    #sn-ai-input {
        font-size: 16px; /* Prevents iOS zoom */
    }

    .sn-lead-row {
        grid-template-columns: 1fr;
    }
}

/* ── Hide voice button when not supported ── */
.sn-no-voice #sn-ai-voice {
    display: none;
}

/* ── Loading spinner ── */
.sn-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: sn-spin 0.6s linear infinite;
}

@keyframes sn-spin {
    to { transform: rotate(360deg); }
}

/* ── Audio Playback Banner & Stop Control ── */
.sn-ai-audio-bar {
    background: #113B62;
    color: #fff;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    animation: sn-fadeIn 0.2s ease;
    flex-shrink: 0;
}

.sn-audio-bar-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sn-audio-wave {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    height: 14px;
}

.sn-audio-wave span {
    width: 3px;
    height: 100%;
    background: #FCB511;
    border-radius: 2px;
    animation: sn-wave 0.8s ease-in-out infinite alternate;
}

.sn-audio-wave span:nth-child(2) { animation-delay: 0.2s; }
.sn-audio-wave span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sn-wave {
    0% { height: 4px; }
    100% { height: 14px; }
}

.sn-btn-stop-audio {
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 14px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sn-btn-stop-audio:hover {
    background: #c0392b;
    transform: scale(1.04);
}

.sn-tts-btn.playing {
    background: #e74c3c !important;
    color: #fff !important;
    border-color: #e74c3c !important;
    font-weight: 600;
}

/* ── Appointment Booking Card ── */
.sn-appointment-card {
    background: #ffffff;
    border: 1.5px solid #cfe2ee;
    border-radius: 14px;
    padding: 16px;
    margin: 8px 0;
    box-shadow: 0 4px 16px rgba(17, 59, 98, 0.08);
    animation: sn-fadeIn 0.3s ease;
}

.sn-appointment-card .sn-form-header {
    border-bottom: 1px solid #eef4f8;
    padding-bottom: 8px;
    margin-bottom: 12px;
}

.sn-appointment-card .sn-form-header h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #113B62;
}

.sn-appointment-card .sn-form-header p {
    margin: 2px 0 0 0;
    font-size: 11px;
    color: #64748b;
}

.sn-appt-fields .sn-form-group {
    margin-bottom: 10px;
}

.sn-appt-fields label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 4px;
}

.sn-appt-fields label .required {
    color: #e74c3c;
}

.sn-appt-fields input,
.sn-appt-fields select,
.sn-appt-fields textarea {
    width: 100%;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    border: 1px solid #cfe2ee;
    border-radius: 8px;
    background: #f8fafc;
    box-sizing: border-box;
    outline: none;
    transition: all 0.2s ease;
}

.sn-appt-fields input:focus,
.sn-appt-fields select:focus,
.sn-appt-fields textarea:focus {
    border-color: #40A0D9;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(64, 160, 217, 0.15);
}

.sn-appt-fields .sn-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.sn-btn-book-submit {
    width: 100%;
    background: linear-gradient(135deg, #113B62, #40A0D9);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 4px;
}

.sn-btn-book-submit:hover {
    box-shadow: 0 4px 12px rgba(17, 59, 98, 0.25);
    transform: translateY(-1px);
}

.sn-booking-success {
    text-align: center;
    padding: 12px 6px;
}

.sn-booking-success .sn-success-icon {
    font-size: 32px;
    margin-bottom: 6px;
}

.sn-booking-success h4 {
    margin: 0 0 6px 0;
    color: #113B62;
    font-size: 16px;
}

.sn-booking-success p {
    font-size: 13px;
    color: #334155;
    margin: 4px 0;
    line-height: 1.4;
}

.sn-summary-box {
    background: #f0f7fc;
    border: 1px solid #cfe2ee;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 10px 0;
    text-align: left;
    font-size: 12px;
    color: #113B62;
    line-height: 1.6;
}

.sn-urgent-note {
    font-size: 12px;
    background: #fff3cd;
    border: 1px solid #ffeeba;
    padding: 8px;
    border-radius: 6px;
    color: #856404;
    margin-top: 8px;
}

.sn-urgent-note a {
    color: #856404;
    font-weight: bold;
}

