/* ==========================================================
   EXPERT TAX — CHAT WIDGET  |  v2 Design System
   Navy: #000a1f  |  Blue: #0266f2  |  White: #ffffff
   ========================================================== */

/* ── Toggle Button ─────────────────────────────────────── */
#chat-toggle-btn {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 99999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(145deg, #0266f2 0%, #014cb8 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 28px rgba(2, 102, 242, 0.45), 0 2px 8px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
#chat-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 36px rgba(2, 102, 242, 0.55);
}
#chat-toggle-btn:active { transform: scale(0.95); }

#chat-toggle-btn .chat-icon,
#chat-toggle-btn .close-icon {
    position: absolute;
    transition: opacity 0.22s ease, transform 0.22s ease;
    color: #fff;
}
#chat-toggle-btn .close-icon { opacity: 0; transform: rotate(-90deg) scale(0.7); }
#chat-toggle-btn.is-open .chat-icon { opacity: 0; transform: rotate(90deg) scale(0.7); }
#chat-toggle-btn.is-open .close-icon { opacity: 1; transform: rotate(0) scale(1); }

/* Notification dot */
#chat-notif-dot {
    position: absolute;
    top: 0px;
    right: 0px;
    width: 16px;
    height: 16px;
    background: #22c55e;
    border: 2.5px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
    animation: notif-pulse 2.2s ease-in-out infinite;
}
@keyframes notif-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
    70%  { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ── Chat Window ────────────────────────────────────────── */
#chat-window {
    position: fixed;
    bottom: 102px;
    right: 28px;
    z-index: 99998;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 130px);
    background: #ffffff;
    border-radius: 20px;
    box-shadow:
        0 40px 80px rgba(0, 10, 31, 0.18),
        0 8px 24px rgba(0, 10, 31, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
    border: 1px solid rgba(2, 102, 242, 0.12);
}
#chat-window.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────── */
#chat-header {
    background: linear-gradient(135deg, #000a1f 0%, #001240 100%);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
#chat-header::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, #0266f2, #6bb0ff, #0266f2);
    background-size: 200% 100%;
    animation: header-shimmer 3s linear infinite;
}
@keyframes header-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.cw-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0266f2, #6bb0ff);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(2, 102, 242, 0.4);
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
}
.cw-header-text { flex: 1; min-width: 0; }
.cw-name {
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    margin: 0;
    line-height: 1.2;
}
.cw-status {
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 11.5px;
    color: rgba(255,255,255,0.6);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}
.cw-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34,197,94,0.8);
    animation: dot-blink 2.5s ease infinite;
    flex-shrink: 0;
}
@keyframes dot-blink {
    0%,100% { opacity: 1; } 50% { opacity: 0.3; }
}
#cw-minimize {
    background: rgba(255,255,255,0.08);
    border: none;
    color: rgba(255,255,255,0.6);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}
#cw-minimize:hover { background: rgba(2,102,242,0.4); color: #fff; }

/* ── Messages ────────────────────────────────────────────── */
#cw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
#cw-messages::-webkit-scrollbar { width: 3px; }
#cw-messages::-webkit-scrollbar-track { background: transparent; }
#cw-messages::-webkit-scrollbar-thumb { background: rgba(2,102,242,0.15); border-radius: 4px; }

/* Date label */
.cw-date-label {
    text-align: center;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 11px;
    color: #9ca3af;
    font-weight: 500;
    margin: 4px 0;
}

/* Message row */
.cw-msg {
    display: flex;
    gap: 7px;
    align-items: flex-end;
    animation: cw-appear 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes cw-appear {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.cw-msg.bot  { flex-direction: row; }
.cw-msg.user { flex-direction: row-reverse; }

/* Bot mini avatar */
.cw-msg-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0266f2, #6bb0ff);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
    margin-bottom: 2px;
}

/* Bubble */
.cw-bubble {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 16px;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 13.5px;
    line-height: 1.55;
    position: relative;
}
.cw-msg.bot .cw-bubble {
    background: #f1f5ff;
    color: #111827;
    border-bottom-left-radius: 4px;
    border: 1px solid #e0e9ff;
}
.cw-msg.user .cw-bubble {
    background: linear-gradient(135deg, #0266f2, #014cb8);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 14px rgba(2,102,242,0.25);
}
.cw-bubble a { color: #0266f2; font-weight: 600; text-decoration: none; border-bottom: 1px solid rgba(2,102,242,0.3); }
.cw-msg.user .cw-bubble a { color: #a8ccff; border-bottom-color: rgba(168,204,255,0.4); }

/* Structured list inside bubble */
.cw-list {
    margin: 6px 0 2px;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cw-list li {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 13px;
}
.cw-list li .cw-li-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #0266f2;
    margin-top: 5px;
    flex-shrink: 0;
}

/* Typing indicator */
.cw-typing {
    display: flex;
    gap: 7px;
    align-items: flex-end;
}
.cw-typing .cw-bubble { padding: 12px 14px; }
.cw-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #cbd5e1;
    display: inline-block;
    animation: cw-bounce 1.2s ease-in-out infinite;
}
.cw-dot:nth-child(2) { animation-delay: 0.15s; }
.cw-dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes cw-bounce {
    0%,60%,100% { transform: translateY(0); background: #cbd5e1; }
    30% { transform: translateY(-5px); background: #0266f2; }
}

/* ── Quick Reply Chips ───────────────────────────────────── */
#cw-chips {
    padding: 6px 14px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
    flex-shrink: 0;
}
.cw-chip {
    background: #fff;
    color: #0266f2;
    border: 1.5px solid #0266f2;
    border-radius: 99px;
    padding: 6px 14px;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.cw-chip:hover {
    background: #0266f2;
    color: #fff;
    transform: translateY(-1.5px);
    box-shadow: 0 4px 12px rgba(2, 102, 242, 0.2);
}
.cw-chip:active {
    transform: translateY(0);
}

/* ── Inline Booking Form inside Bubble ───────────────────── */
.cw-bubble--form {
    max-width: 90% !important;
    width: 100%;
    background: #f8faff !important;
    border: 1px solid #dbeafe !important;
    padding: 14px !important;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}
.cw-form-title {
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: #000a1f;
    margin: 0 0 10px 0;
}
.cw-inline-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}
.cw-inline-form .cw-field {
    display: flex;
    flex-direction: column;
    width: 100%;
}
.cw-inline-form .cw-form-input {
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    padding: 7px 10px;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 12.5px;
    color: #111827;
    background: #fff;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    box-sizing: border-box;
}
.cw-inline-form .cw-form-input:focus {
    border-color: #0266f2;
    box-shadow: 0 0 0 3px rgba(2,102,242,0.1);
}
.cw-inline-form textarea.cw-form-input {
    resize: none;
    height: 48px;
}
.cw-inline-form select.cw-form-input {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234b5563' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
    padding-right: 30px;
    cursor: pointer;
}
.cw-inline-form .cw-form-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}
.cw-inline-form .cw-submit-booking {
    flex: 1;
    padding: 8px 12px;
    background: linear-gradient(135deg, #0266f2, #014cb8);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cw-inline-form .cw-submit-booking:hover {
    box-shadow: 0 4px 10px rgba(2,102,242,0.25);
}
.cw-inline-form .cw-submit-booking:active {
    transform: translateY(1px);
}
.cw-inline-form .cw-cancel-booking {
    padding: 8px 12px;
    background: transparent;
    color: #6b7280;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.cw-inline-form .cw-cancel-booking:hover {
    border-color: #cbd5e1;
    color: #374151;
}
.cw-inline-form .cw-form-note {
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 10px;
    color: #9ca3af;
    margin: 2px 0 0 0;
    text-align: center;
}

/* ── Input Bar ───────────────────────────────────────────── */
#cw-input-bar {
    border-top: 1px solid #f1f5f9;
    padding: 10px 12px;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
    background: #fff;
}
#cw-input {
    flex: 1;
    border: 1.5px solid #e5e7eb;
    border-radius: 20px;
    padding: 9px 14px;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 13.5px;
    color: #111827;
    background: #f9fafb;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
#cw-input::placeholder { color: #9ca3af; }
#cw-input:focus {
    border-color: #0266f2;
    box-shadow: 0 0 0 3px rgba(2,102,242,0.08);
    background: #fff;
}
#cw-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0266f2, #014cb8);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(2,102,242,0.3);
    transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
    color: #fff;
}
#cw-send:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 18px rgba(2,102,242,0.4);
}
#cw-send:active { transform: scale(0.94); }

/* ── Footer ─────────────────────────────────────────────── */
#cw-footer {
    text-align: center;
    padding: 5px 0 9px;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 10.5px;
    color: #d1d5db;
    flex-shrink: 0;
    background: #fff;
}
#cw-footer strong { color: #0266f2; font-weight: 700; }

/* ── Success state ───────────────────────────────────────── */
.cw-success-msg {
    text-align: center;
    padding: 16px 10px;
}
.cw-success-msg .cw-success-icon {
    font-size: 36px;
    display: block;
    margin-bottom: 8px;
}
.cw-success-msg p {
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    margin: 0;
}
.cw-success-msg span {
    font-size: 12px;
    color: #6b7280;
    font-weight: 400;
}

/* Custom Select Dropdown */
.cw-custom-select-wrapper {
    position: relative;
    width: 100%;
}
.cw-custom-select-trigger {
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    padding: 7px 10px;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 12.5px;
    color: #111827;
    background: #fff;
    outline: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: border-color 0.2s, box-shadow 0.2s;
    user-select: none;
}
.cw-custom-select-wrapper:focus-within .cw-custom-select-trigger,
.cw-custom-select-wrapper.open .cw-custom-select-trigger {
    border-color: #0266f2;
    box-shadow: 0 0 0 3px rgba(2,102,242,0.1);
}
.cw-custom-select-trigger svg {
    transition: transform 0.2s ease;
    color: #4b5563;
    flex-shrink: 0;
}
.cw-custom-select-wrapper.open .cw-custom-select-trigger svg {
    transform: rotate(180deg);
}

.cw-custom-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #dbeafe;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 10, 31, 0.12);
    z-index: 999;
    max-height: 180px;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
}
.cw-custom-select-wrapper.open .cw-custom-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.cw-custom-option {
    padding: 8px 12px;
    font-family: 'Satoshi', -apple-system, sans-serif;
    font-size: 12.5px;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-align: left;
}
.cw-custom-option:hover {
    background: #f1f5ff;
    color: #0266f2;
}
.cw-custom-option.selected {
    background: #e0e9ff;
    color: #0266f2;
    font-weight: 600;
}

/* Custom scrollbar for options menu */
.cw-custom-options::-webkit-scrollbar {
    width: 4px;
}
.cw-custom-options::-webkit-scrollbar-track {
    background: transparent;
}
.cw-custom-options::-webkit-scrollbar-thumb {
    background: rgba(2, 102, 242, 0.2);
    border-radius: 4px;
}

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 480px) {
    #chat-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }
    #chat-toggle-btn {
        bottom: 18px;
        right: 18px;
        width: 54px;
        height: 54px;
    }
    .cw-form-grid { grid-template-columns: 1fr; }
}
