:root {
    --btg-primary: #1e6091;
    --btg-primary-light: #5fa8d3;
    --btg-secondary: #f7ede2;
    --btg-surface: #ffffff;
    --btg-border: #d8e2dc;
    --btg-shadow: 0 14px 35px rgba(30, 96, 145, 0.18);
    --btg-text: #2b2d42;
    --btg-text-muted: #4a4e69;
    --btg-success: #38a169;
    --btg-error: #d64550;
}

.btg-chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 12px;
}

.btg-chat-launcher button {
    appearance: none;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--btg-primary), var(--btg-primary-light));
    color: #fff;
    box-shadow: var(--btg-shadow);
    padding: 14px 22px;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btg-chat-launcher button:hover,
.btg-chat-launcher button:focus {
    transform: translateY(-2px);
    box-shadow: 0 20px 40px rgba(30, 96, 145, 0.22);
    outline: none;
}

.btg-chat-bubble {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 360px;
    max-width: calc(100vw - 32px);
    max-height: 70vh;
    z-index: 9999;
    background: var(--btg-surface);
    border-radius: 18px;
    border: 1px solid var(--btg-border);
    box-shadow: var(--btg-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.btg-chat-bubble.is-open {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}

.btg-chat-header {
    background: linear-gradient(135deg, var(--btg-primary), var(--btg-primary-light));
    color: #fff;
    padding: 18px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.btg-chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.btg-chat-title {
    font-weight: 700;
    font-size: 16px;
}

.btg-chat-subtitle {
    font-size: 12px;
    opacity: 0.85;
}

.btg-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btg-chat-close:hover,
.btg-chat-close:focus {
    background: rgba(255, 255, 255, 0.3);
    outline: none;
}

.btg-chat-messages {
    flex: 1;
    padding: 18px;
    background: #f8f9fb;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.btg-message {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.btg-message-user {
    flex-direction: row-reverse;
}

.btg-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--btg-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.btg-message-user .btg-message-avatar {
    background: var(--btg-primary-light);
}

.btg-message-content {
    background: var(--btg-surface);
    border-radius: 16px;
    padding: 12px 15px;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
    color: var(--btg-text);
    line-height: 1.5;
    white-space: pre-line;
    max-width: 80%;
    font-size: 15px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.btg-message-user .btg-message-content {
    background: linear-gradient(135deg, var(--btg-primary), var(--btg-primary-light));
    color: #fff;
}

.btg-message-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.btg-card {
    background: var(--btg-surface);
    border-radius: 12px;
    border: 1px solid var(--btg-border);
    padding: 12px 14px;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
}

.btg-card-title {
    font-weight: 700;
    color: var(--btg-primary);
    margin-bottom: 4px;
}

.btg-card-subtitle {
    font-size: 13px;
    color: var(--btg-text-muted);
    margin-bottom: 6px;
}

.btg-card-description {
    font-size: 14px;
    color: var(--btg-text);
}

.btg-card-meta {
    margin-top: 8px;
    font-size: 12px;
    color: var(--btg-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.btg-card-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.btg-card-buttons a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 999px;
    border: none;
    background: linear-gradient(135deg, var(--btg-primary), var(--btg-primary-light));
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btg-card-buttons a:hover,
.btg-card-buttons a:focus {
    transform: translateY(-1px);
    box-shadow: 0 12px 30px rgba(30, 96, 145, 0.18);
    outline: none;
}

.btg-chat-footer {
    padding: 16px;
    border-top: 1px solid var(--btg-border);
    background: var(--btg-surface);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btg-chat-actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.btg-location-btn {
    flex: 1;
    background: rgba(30, 96, 145, 0.08);
    color: var(--btg-primary);
    border: 1px solid rgba(30, 96, 145, 0.15);
    border-radius: 999px;
    padding: 10px 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.2s ease, border 0.2s ease;
}

.btg-location-btn:hover,
.btg-location-btn:focus {
    background: rgba(30, 96, 145, 0.12);
    border-color: rgba(30, 96, 145, 0.35);
    outline: none;
}

.btg-chat-input {
    display: flex;
    gap: 10px;
}

.btg-chat-input textarea {
    flex: 1;
    border: 1px solid var(--btg-border);
    border-radius: 14px;
    padding: 10px 12px;
    resize: none;
    min-height: 50px;
    max-height: 100px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.btg-chat-input textarea:focus {
    outline: none;
    border-color: rgba(30, 96, 145, 0.35);
    box-shadow: 0 0 0 3px rgba(30, 96, 145, 0.12);
}

.btg-send-btn {
    background: linear-gradient(135deg, var(--btg-primary), var(--btg-primary-light));
    border: none;
    color: #fff;
    border-radius: 12px;
    padding: 0 18px;
    font-size: 15px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btg-send-btn:hover,
.btg-send-btn:focus {
    transform: translateY(-1px);
    box-shadow: 0 12px 30px rgba(30, 96, 145, 0.18);
    outline: none;
}

.btg-typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--btg-text-muted);
}

.btg-typing-indicator span {
    height: 8px;
    width: 8px;
    background: var(--btg-primary-light);
    border-radius: 50%;
    animation: btg-typing 1s infinite ease-in-out;
}

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

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

@keyframes btg-typing {
    0%, 80%, 100% {
        opacity: 0.2;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

.btg-alert {
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
}

.btg-alert-success {
    background: rgba(56, 161, 105, 0.1);
    color: var(--btg-success);
}

.btg-alert-error {
    background: rgba(214, 69, 80, 0.12);
    color: var(--btg-error);
}

.btg-alert-info {
    background: rgba(30, 96, 145, 0.12);
    color: var(--btg-primary);
}

@media (max-width: 600px) {
    .btg-chat-launcher {
        right: 16px;
        bottom: 16px;
    }

    .btg-chat-bubble {
        right: 16px;
        left: 16px;
        bottom: 16px;
        width: auto;
        max-height: calc(100vh - 120px);
    }

    .btg-chat-header,
    .btg-chat-footer {
        padding: 14px;
    }

    .btg-chat-messages {
        padding: 16px;
    }
}

@media (max-width: 420px) {
    .btg-message-content {
        max-width: 85%;
    }

    .btg-chat-messages {
        padding: 12px;
    }

    .btg-message {
        max-width: 100%;
    }
}

/* Better box-sizing for all chat elements */
.btg-chat-bubble,
.btg-chat-bubble * {
    box-sizing: border-box;
}

/* iPhone 12 and similar devices (390px width) */
@media (max-width: 390px) {
    .btg-message-content {
        max-width: 82%;
        padding: 10px 12px;
    }

    .btg-chat-messages {
        padding: 10px;
    }

    .btg-chat-bubble-fullscreen .btg-chat-messages {
        padding: 10px;
    }

    /* Prevent iOS auto-zoom when typing (requires min 16px font) */
    .btg-chat-input textarea {
        font-size: 16px;
    }
}

/* Prevent auto-zoom on all mobile devices */
@media (max-width: 600px) {
    .btg-chat-input textarea {
        font-size: 16px;
    }
}
.btg-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btg-accessibility-btn {
    background: rgba(255, 255, 255, 0.25);
    border: none;
    color: #fff;
    border-radius: 999px;
    width: 36px;
    height: 36px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.btg-accessibility-btn:hover,
.btg-accessibility-btn:focus {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-1px);
    outline: none;
}

.btg-accessibility-btn[aria-pressed="true"] {
    background: rgba(255, 255, 255, 0.45);
}

.btg-chat-header-actions .btg-chat-close {
    margin-left: 4px;
}

body.btg-chat-fullscreen-active {
    background: #f9fafb;
    min-height: 100vh;
    overflow: hidden;
}

.btg-chat-bubble-fullscreen {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    background: var(--btg-surface);
    box-sizing: border-box;
}

.btg-chat-bubble-fullscreen .btg-chat-header,
.btg-chat-bubble-fullscreen .btg-chat-footer,
.btg-chat-bubble-fullscreen .btg-chat-messages {
    width: 100%;
    max-width: min(600px, 100%);
    margin: 0 auto;
    box-sizing: border-box;
}

.btg-chat-bubble-fullscreen .btg-chat-messages {
    flex: 1;
    overflow-y: auto;
    max-height: none;
    padding: clamp(12px, 5vw, 24px);
}

.btg-chat-bubble-fullscreen .btg-chat-footer,
.btg-chat-bubble-fullscreen .btg-chat-header {
    padding: clamp(14px, 5vw, 24px);
}

body.btg-chat-fullscreen-active .btg-chat-launcher {
    display: none;
}

.btg-message {
    animation: btg-fade-in 0.2s ease;
}

@keyframes btg-fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

body.btg-hope-large-text .btg-chat-messages,
body.btg-hope-large-text .btg-chat-input textarea {
    font-size: 18px;
}

body.btg-hope-large-text .btg-message-content {
    font-size: 17px;
}

body.btg-hope-large-text .btg-chat-title {
    font-size: 18px;
}

body.btg-hope-high-contrast {
    --btg-primary: #0f172a;
    --btg-primary-light: #1e3a8a;
    --btg-secondary: #0f172a;
    --btg-surface: #0f172a;
    --btg-border: #1e293b;
    --btg-text: #f8fafc;
    --btg-text-muted: #cbd5f5;
}

body.btg-hope-high-contrast .btg-message-user .btg-message-content {
    background: var(--btg-primary-light);
}

body.btg-hope-high-contrast .btg-chat-bubble {
    background: var(--btg-surface);
    color: var(--btg-text);
}

body.btg-hope-high-contrast .btg-chat-messages {
    background: #0b1120;
}

body.btg-hope-high-contrast .btg-chat-footer {
    background: #111827;
}

body.btg-chat-fullscreen-active .btg-chat-bubble .btg-chat-footer {
    border-top: 1px solid var(--btg-border);
}

.btg-chat-bubble-fullscreen .btg-chat-input textarea {
    min-height: 60px;
}

.btg-location-btn.is-hidden {
    display: none !important;
}

/* Clickable links in chat messages */
.btg-message-content a.btg-chat-link {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
    display: inline;
}

.btg-message-user .btg-message-content a.btg-chat-link {
    color: #fff;
}

.btg-message-content a.btg-chat-link:hover {
    opacity: 0.8;
}


/* Fix for fullscreen chat - ensure footer always visible */
.btg-chat-bubble-fullscreen .btg-chat-footer {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.btg-chat-bubble-fullscreen .btg-chat-messages {
    flex: 1;
    overflow-y: auto;
    max-height: calc(100vh - 180px); /* Account for header + footer */
    min-height: 0; /* Allow flex shrinking */
}

