/* Tomdiesel chat: isolated from the site's page and navigation styles. */
.td-chat-widget {
    --td-blue: #0066cc;
    --td-blue-dark: #004d99;
    --td-orange: #ff6600;
    --td-ink: #172b42;
    --td-muted: #526478;
    --td-border: #dce5ef;
    position: fixed;
    bottom: max(22px, env(safe-area-inset-bottom, 0px));
    left: max(22px, env(safe-area-inset-left, 0px));
    z-index: 10000;
    color: var(--td-ink);
    font-family: 'Roboto', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    text-align: left;
    color-scheme: light;
}

.td-chat-widget,
.td-chat-widget * {
    box-sizing: border-box;
}

.td-chat-widget [hidden] {
    display: none !important;
}

.td-chat-widget button,
.td-chat-widget textarea {
    font: inherit;
}

.td-chat-widget button {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.td-chat-widget button:focus-visible,
.td-chat-widget a:focus-visible,
.td-chat-widget textarea:focus-visible {
    outline: 3px solid var(--td-orange);
    outline-offset: 3px;
}

.td-chat-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 54px;
    max-width: calc(100vw - 44px);
    padding: 13px 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 999px;
    background: var(--td-blue-dark);
    color: #fff;
    box-shadow: 0 8px 28px rgba(0, 48, 102, 0.25);
    font-weight: 700 !important;
    line-height: 1.3;
    transition: background-color 160ms ease, box-shadow 160ms ease;
}

.td-chat-toggle:hover {
    background: #003e7d;
    box-shadow: 0 10px 32px rgba(0, 48, 102, 0.32);
}

.td-chat-toggle svg {
    flex: 0 0 23px;
    width: 23px;
    height: 23px;
}

.td-chat-toggle-label {
    overflow-wrap: anywhere;
}

.td-chat-panel {
    position: fixed;
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
    left: max(22px, env(safe-area-inset-left, 0px));
    display: flex;
    flex-direction: column;
    width: 400px;
    max-width: calc(100vw - 44px - env(safe-area-inset-left, 0px));
    height: min(650px, 85vh, calc(100vh - 114px - env(safe-area-inset-bottom, 0px)));
    height: min(650px, 85dvh, calc(100dvh - 114px - env(safe-area-inset-bottom, 0px)));
    min-height: 0;
    overflow: hidden;
    border: 1px solid #cddbe9;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 20px 64px rgba(13, 38, 66, 0.23), 0 3px 12px rgba(13, 38, 66, 0.1);
}

.td-chat-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    flex: 0 0 auto;
    align-items: center;
    gap: 2px 12px;
    padding: 17px 16px 17px 20px;
    background: var(--td-blue-dark);
    color: #fff;
    border-bottom: 3px solid var(--td-orange);
}

.td-chat-header h2 {
    grid-column: 1;
    margin: 0;
    color: #fff;
    font-family: 'Montserrat', Arial, sans-serif;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

.td-chat-status {
    grid-column: 1;
    margin: 3px 0 0;
    color: #e2efff;
    font-size: 12px;
    line-height: 1.4;
}

.td-chat-close {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 12px;
    background: transparent;
    color: #fff;
    font-size: 25px !important;
    line-height: 1;
}

.td-chat-close:hover {
    background: rgba(255, 255, 255, 0.13);
}

.td-chat-close svg {
    width: 20px;
    height: 20px;
}

.td-chat-notice {
    flex: 0 0 auto;
    margin: 0;
    padding: 10px 18px;
    border-bottom: 1px solid var(--td-border);
    background: #f3f7fc;
    color: #425870;
    font-size: 12px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.td-chat-quick-actions {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 7px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--td-border);
    background: #fff;
}

.td-chat-quick-actions button {
    min-height: 38px;
    max-width: 100%;
    padding: 8px 11px;
    border: 1px solid #cadced;
    border-radius: 999px;
    background: #f5f9ff;
    color: #164d80;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    text-align: left;
    overflow-wrap: anywhere;
}

.td-chat-quick-actions button:hover:not(:disabled) {
    border-color: var(--td-blue);
    background: #e7f1ff;
}

.td-chat-messages {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    padding: 18px 16px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #b5c5d7 #f6f8fb;
    background: #f6f8fb;
    -webkit-overflow-scrolling: touch;
}

.td-chat-message {
    flex: 0 0 auto;
    width: fit-content;
    max-width: 95%;
    padding: 12px 14px;
    border: 1px solid var(--td-border);
    border-radius: 15px;
    overflow-wrap: anywhere;
    word-break: normal;
}

.td-chat-message.assistant {
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    background: #fff;
    color: var(--td-ink);
}

.td-chat-message.user {
    align-self: flex-end;
    border-color: var(--td-blue-dark);
    border-bottom-right-radius: 5px;
    background: var(--td-blue-dark);
    color: #fff;
}

.td-chat-reply {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.td-chat-reply + .td-chat-reply {
    margin-top: 9px;
}

.td-chat-mode-label {
    display: block;
    margin: 8px 0 0;
    color: var(--td-muted);
    font-size: 11px;
    line-height: 1.4;
}

.td-chat-message.user .td-chat-mode-label {
    color: #e2efff;
}

.td-chat-handoff {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--td-border);
}

.td-chat-handoff-reason {
    margin: 0 0 9px;
    color: var(--td-muted);
    font-size: 13px;
    line-height: 1.5;
}

.td-chat-contact-link {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 48px;
    margin-top: 7px;
    padding: 10px 12px;
    border: 1px solid #c3d8ee;
    border-left: 3px solid var(--td-orange);
    border-radius: 9px;
    background: #f1f7ff;
    color: var(--td-blue-dark);
    text-decoration: none;
    overflow-wrap: anywhere;
}

.td-chat-contact-link:hover {
    border-color: var(--td-blue);
    border-left-color: var(--td-orange);
    background: #e6f0ff;
}

.td-chat-contact-link strong {
    font-size: 13px;
    font-weight: 700;
}

.td-chat-contact-link span {
    font-size: 13px;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.td-chat-typing {
    flex: 0 0 auto;
    align-self: flex-start;
    padding: 6px 1px;
    color: var(--td-muted);
    font-size: 12px;
    font-style: italic;
    line-height: 1.45;
}

.td-chat-form {
    display: flex;
    flex: 0 0 auto;
    align-items: flex-end;
    gap: 9px;
    margin: 0;
    padding: 12px 14px 8px;
    border-top: 1px solid var(--td-border);
    background: #fff;
}

.td-chat-input {
    display: block;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 46px;
    max-height: 110px;
    margin: 0;
    padding: 11px 12px;
    resize: none;
    overflow-y: auto;
    border: 1px solid #b8cadc;
    border-radius: 11px;
    background: #fff;
    color: var(--td-ink);
    font-size: 16px !important;
    line-height: 1.45;
    box-shadow: none;
}

.td-chat-input::placeholder {
    color: #607287;
    opacity: 1;
}

.td-chat-input:focus {
    border-color: var(--td-blue);
}

.td-chat-submit {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    min-width: 46px;
    min-height: 46px;
    padding: 11px 13px;
    border: 1px solid var(--td-blue-dark);
    border-radius: 11px;
    background: var(--td-blue-dark);
    color: #fff;
    font-weight: 700 !important;
    line-height: 1.3;
}

.td-chat-submit:hover:not(:disabled) {
    background: #003e7d;
}

.td-chat-submit svg {
    width: 20px;
    height: 20px;
}

.td-chat-submit:disabled,
.td-chat-quick-actions button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.td-chat-footer {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 10px;
    padding: 0 14px 9px;
    background: #fff;
}

.td-chat-clear {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 6px 3px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--td-blue-dark);
    font-size: 12px !important;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.td-chat-clear:hover {
    color: #00346b;
}

.td-chat-privacy {
    min-width: 0;
    margin: 0;
    color: var(--td-muted);
    font-size: 11px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.td-chat-widget .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 600px) {
    .td-chat-widget {
        left: max(14px, env(safe-area-inset-left, 0px));
        bottom: max(14px, env(safe-area-inset-bottom, 0px));
    }

    .td-chat-toggle {
        min-height: 50px;
        padding: 12px 17px;
    }

    .td-chat-panel {
        top: max(12px, env(safe-area-inset-top, 0px));
        right: max(12px, env(safe-area-inset-right, 0px));
        bottom: max(12px, env(safe-area-inset-bottom, 0px));
        left: max(12px, env(safe-area-inset-left, 0px));
        width: auto;
        max-width: none;
        height: calc(100vh - max(12px, env(safe-area-inset-top, 0px)) - max(12px, env(safe-area-inset-bottom, 0px)));
        height: calc(100dvh - max(12px, env(safe-area-inset-top, 0px)) - max(12px, env(safe-area-inset-bottom, 0px)));
        max-height: 100%;
        border-radius: 16px;
    }

    .td-chat-widget.is-open .td-chat-toggle,
    .td-chat-widget:has(.td-chat-panel:not([hidden])) .td-chat-toggle {
        display: none;
    }

    .td-chat-header {
        padding: 12px 12px 12px 15px;
    }

    .td-chat-header h2 {
        font-size: 16px;
    }

    .td-chat-notice {
        padding: 8px 14px;
    }

    .td-chat-quick-actions {
        gap: 6px;
        padding: 9px 12px;
    }

    .td-chat-messages {
        gap: 10px;
        padding: 14px 12px;
    }

    .td-chat-message {
        max-width: 97%;
        padding: 11px 12px;
    }

    .td-chat-form {
        gap: 7px;
        padding: 10px 11px 5px;
    }

    .td-chat-footer {
        gap: 8px;
        padding: 0 11px 6px;
    }
}

/* Keep the composer and conversation usable when a mobile keyboard is open. */
@media (max-width: 600px) and (max-height: 450px) {
    .td-chat-header {
        padding: 5px 10px 5px 13px;
    }

    .td-chat-status {
        display: none;
    }

    .td-chat-notice {
        max-height: 42px;
        padding: 5px 12px;
        overflow-y: auto;
    }

    .td-chat-quick-actions {
        flex-wrap: nowrap;
        padding: 6px 10px;
        overflow-x: auto;
    }

    .td-chat-quick-actions button {
        flex: 0 0 auto;
        white-space: nowrap;
    }

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

    .td-chat-input {
        max-height: 68px;
    }

    .td-chat-footer {
        padding-bottom: 3px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .td-chat-widget *,
    .td-chat-widget *::before,
    .td-chat-widget *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}

@media (forced-colors: active) {
    .td-chat-toggle,
    .td-chat-panel,
    .td-chat-message,
    .td-chat-contact-link,
    .td-chat-submit,
    .td-chat-close {
        border: 1px solid ButtonText;
    }
}
