#n8n-chat-widget,
#n8n-chat-widget * {
    box-sizing: border-box !important;
}

#n8n-chat-widget {
    position: fixed !important;
    right: 20px !important;
    bottom: 20px !important;
    z-index: 999999 !important;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    font-family: Arial, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.35;
    isolation: isolate;
}

#n8n-chat-widget button,
#n8n-chat-widget input,
#n8n-chat-widget [contenteditable="true"] {
    margin: 0;
    box-shadow: none;
    text-indent: 0;
    text-transform: none;
    letter-spacing: normal;
    font-family: inherit;
    line-height: normal;
}

#n8n-chat-widget button::before,
#n8n-chat-widget button::after {
    content: none !important;
}

#n8n-chat-widget [hidden] {
    display: none !important;
}

#n8n-chat-widget .ttc-window,
#n8n-chat-widget .ttc-header,
#n8n-chat-widget .ttc-footer,
#n8n-chat-widget .ttc-content,
#n8n-chat-widget .ttc-toolbar,
#n8n-chat-widget .ttc-input-wrapper,
#n8n-chat-widget .ttc-group {
    margin: 0;
}

/* ==========================================================================
   ICON MỞ CHAT
   - Bình thường: nhịp thở nhẹ.
   - Có .has-unread: nổi bật và rung nhẹ theo chu kỳ.
   ========================================================================== */

#n8n-chat-widget .ttc-toggle {
    position: relative;
    width: 64px;
    min-width: 64px;
    max-width: 64px;
    height: 64px;
    min-height: 64px;
    max-height: 64px;
    margin-left: auto;
    padding: 0;
    display: grid;
    place-items: center;
    overflow: visible;
    border: 3px solid #fff;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, #159cff 0%, #0787f8 48%, #006ed4 100%);
    cursor: pointer;
    box-shadow:
        0 9px 28px rgba(0, 132, 255, .42),
        0 3px 9px rgba(0, 0, 0, .18);
    animation: ttc-focus-pulse 3.8s ease-in-out infinite;
    transform-origin: center;
    will-change: transform, box-shadow, filter;
    transition:
        transform .18s ease,
        box-shadow .18s ease,
        filter .18s ease;
    appearance: none;
}

#n8n-chat-widget .ttc-toggle-icon,
#n8n-chat-widget .ttc-toggle-icon svg {
    display: block;
    width: 34px;
    height: 34px;
}

#n8n-chat-widget .ttc-toggle-icon {
    position: relative;
    z-index: 2;
    transform-origin: center;
    will-change: transform;
}

#n8n-chat-widget .ttc-toggle.has-unread {
    animation: ttc-unread-attention 2.8s ease-in-out infinite;
}

#n8n-chat-widget .ttc-toggle.has-unread .ttc-toggle-icon {
    animation: ttc-icon-attention 2.8s ease-in-out infinite;
}

#n8n-chat-widget .ttc-toggle:hover {
    animation: none;
    filter: brightness(1.08) saturate(1.06);
    transform: translateY(-3px) scale(1.06);
    box-shadow:
        0 14px 36px rgba(0, 132, 255, .52),
        0 5px 13px rgba(0, 0, 0, .2);
}

#n8n-chat-widget .ttc-toggle:hover .ttc-toggle-icon {
    animation: none;
}

#n8n-chat-widget .ttc-toggle:active {
    animation: none;
    transform: translateY(0) scale(.95);
}

#n8n-chat-widget .ttc-toggle:focus-visible {
    outline: 4px solid rgba(255, 166, 33, .48);
    outline-offset: 4px;
}

#n8n-chat-widget .ttc-toggle[aria-expanded="true"],
#n8n-chat-widget .ttc-toggle[aria-expanded="true"] .ttc-toggle-icon {
    animation: none;
}

#n8n-chat-widget .ttc-unread-badge {
    position: absolute;
    z-index: 5;
    top: -5px;
    right: -5px;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    display: grid;
    place-items: center;
    border: 2px solid #fff;
    border-radius: 999px;
    background: #f02821;
    color: #fff;
    box-shadow:
        0 3px 10px rgba(240, 40, 33, .52),
        0 0 0 3px rgba(240, 40, 33, .12);
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    animation: ttc-unread-badge-pulse 1.4s ease-in-out infinite;
}

/* ==========================================================================
   CỬA SỔ CHAT
   ========================================================================== */

#n8n-chat-widget .ttc-window {
    width: 370px;
    height: 540px;
    max-width: calc(100vw - 30px);
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #dce2e8;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .22);
    transition: width .2s ease, height .2s ease;
}

#n8n-chat-widget .ttc-window.is-expanded {
    width: min(720px, calc(100vw - 40px));
    height: min(780px, calc(100vh - 40px));
}

/* ==========================================================================
   HEADER
   ========================================================================== */

#n8n-chat-widget .ttc-header {
    width: 100%;
    min-height: 40px;
    padding: 4px 6px 4px 11px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 0;
    background: #0787f8;
    color: #fff;
}

#n8n-chat-widget .ttc-header-title {
    margin: 0;
    padding: 0;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
}

#n8n-chat-widget .ttc-header-actions {
    position: relative;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 1px;
}

#n8n-chat-widget .ttc-header-btn {
    position: relative;
    z-index: 3;
    width: 30px;
    min-width: 30px;
    max-width: 30px;
    height: 30px;
    min-height: 30px;
    max-height: 30px;
    padding: 5px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    appearance: none;
}

#n8n-chat-widget .ttc-header-btn:hover {
    background: rgba(255, 255, 255, .16);
}

#n8n-chat-widget .ttc-header-btn svg {
    display: block;
    width: 18px;
    height: 18px;
}

/* ==========================================================================
   NỘI DUNG HỘI THOẠI
   ========================================================================== */

#n8n-chat-widget .ttc-content {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px;
    border: 0;
    background: #f7f8fa;
    color: #25282b;
    font-size: 14px;
    scrollbar-width: thin;
}

#n8n-chat-widget .ttc-msg-row {
    display: flex;
    width: 100%;
    margin: 5px 0;
    padding: 0;
}

#n8n-chat-widget .ttc-msg-row-user {
    justify-content: flex-end;
}

#n8n-chat-widget .ttc-msg-row-bot {
    justify-content: flex-start;
}

#n8n-chat-widget .ttc-msg-box {
    max-width: 82%;
    margin: 0;
    padding: 7px 10px;
    border: 0;
    border-radius: 13px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#n8n-chat-widget .ttc-msg-user {
    background: #0787f8;
    color: #fff;
    border-bottom-right-radius: 5px;
}

#n8n-chat-widget .ttc-msg-bot {
    background: #e8eaed;
    color: #25282b;
    border-bottom-left-radius: 5px;
}

#n8n-chat-widget .ttc-msg-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin: 0 0 2px;
    padding: 0;
}

#n8n-chat-widget .ttc-msg-meta strong {
    margin: 0;
    color: inherit;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
}

#n8n-chat-widget .ttc-msg-bot .ttc-msg-meta strong {
    color: #0074d9;
}

#n8n-chat-widget .ttc-msg-meta small {
    flex: 0 0 auto;
    margin: 0;
    color: inherit;
    opacity: .68;
    font-size: 9px;
    line-height: 1.2;
}

#n8n-chat-widget .ttc-msg-body {
    margin: 0;
    padding: 0;
    white-space: pre-wrap;
    line-height: 1.4;
}

/* ==========================================================================
   FOOTER + TOOLBAR
   ========================================================================== */

#n8n-chat-widget .ttc-footer {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: #fff;
}

#n8n-chat-widget .ttc-toolbar {
    width: 100%;
    min-width: 0;
    min-height: 32px;
    padding: 2px 5px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 3px;
    overflow: hidden;
    border-top: 1px solid #eceff2;
    border-bottom: 1px solid #eceff2;
    background: #fff;
}

#n8n-chat-widget .ttc-group {
    min-width: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0;
    padding: 0;
    overflow: hidden;
}

#n8n-chat-widget .ttc-group:last-child {
    justify-content: flex-end;
    overflow: visible;
}

#n8n-chat-widget .ttc-btn,
#n8n-chat-widget .ttc-emoji {
    position: static;
    flex: 0 0 25px;
    width: 25px;
    min-width: 25px;
    max-width: 25px;
    height: 27px;
    min-height: 27px;
    max-height: 27px;
    padding: 3px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #3f454b;
    cursor: pointer;
    font-size: 13px;
    appearance: none;
}

#n8n-chat-widget .ttc-btn:hover,
#n8n-chat-widget .ttc-emoji:hover {
    background: #e7eaee;
}

#n8n-chat-widget .ttc-btn svg {
    display: block;
    width: 17px;
    height: 17px;
}

#n8n-chat-widget .ttc-format-btn,
#n8n-chat-widget .ttc-size-btn {
    font-size: 13px;
    line-height: 1;
}

#n8n-chat-widget .ttc-emoji {
    font-size: 18px;
    line-height: 1;
}

#n8n-chat-widget #ttc-color-picker {
    position: static;
    flex: 0 0 24px;
    width: 24px;
    min-width: 24px;
    max-width: 24px;
    height: 24px;
    min-height: 24px;
    max-height: 24px;
    margin: 0;
    padding: 3px;
    overflow: hidden;
    border: 0;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    appearance: none;
}

#n8n-chat-widget .ttc-more-emoji {
    flex-basis: 24px;
    width: 24px;
    min-width: 24px;
    max-width: 24px;
    border-left: 1px solid #e2e6ea;
    border-radius: 0 6px 6px 0;
}

#n8n-chat-widget .ttc-more-emoji svg {
    width: 15px;
    height: 15px;
    transition: transform .18s ease;
}

#n8n-chat-widget .ttc-icon-list {
    width: 100%;
    max-height: 82px;
    margin: 0;
    padding: 4px 6px;
    flex-wrap: wrap;
    gap: 2px;
    overflow-y: auto;
    border: 0;
    border-bottom: 1px solid #eceff2;
    background: #fff;
}

#n8n-chat-widget .ttc-icon-list[hidden] {
    display: none !important;
}

#n8n-chat-widget .ttc-icon-list:not([hidden]) {
    display: flex;
}

#n8n-chat-widget .ttc-more-emoji.is-open svg {
    transform: rotate(180deg);
}

/* ==========================================================================
   EDITOR + NÚT GỬI
   ========================================================================== */

#n8n-chat-widget .ttc-input-wrapper {
    position: relative;
    width: 100%;
    min-width: 0;
    min-height: 50px;
    margin: 0;
    padding: 5px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 6px;
    overflow: visible;
    border: 0;
    background: #fff;
}

#n8n-chat-widget .ttc-editor {
    position: static;
    width: 100%;
    min-width: 0;
    max-width: none;
    min-height: 40px;
    max-height: 112px;
    margin: 0;
    padding: 8px 9px;
    overflow-y: auto;
    outline: none;
    border: 1px solid #cfe0f2;
    border-radius: 10px;
    background: #fff;
    color: #25282b;
    font-size: 14px;
    line-height: 1.35;
}

#n8n-chat-widget .ttc-editor:focus {
    border-color: #86bfff;
    box-shadow: 0 0 0 2px rgba(0, 132, 255, .09);
    background: #fbfdff;
}

#n8n-chat-widget .ttc-editor:empty::before {
    content: attr(data-placeholder);
    color: #a3a9b0;
    pointer-events: none;
}

#n8n-chat-widget .ttc-btn-send {
    position: static;
    align-self: stretch;
    width: auto;
    min-width: 55px;
    max-width: 70px;
    min-height: 40px;
    height: auto;
    margin: 0;
    padding: 0 12px;
    display: inline-grid;
    place-items: center;
    border: 0;
    border-radius: 10px;
    background: #0787f8;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    appearance: none;
}

#n8n-chat-widget .ttc-btn-send:hover {
    background: #0074e4;
}

#n8n-chat-widget .ttc-btn-send:disabled {
    opacity: .55;
    cursor: wait;
}

/* ==========================================================================
   PREVIEW + ẢNH CHAT
   ========================================================================== */

#n8n-chat-widget .ttc-file-preview {
    position: absolute;
    left: 7px;
    bottom: calc(100% + 4px);
    z-index: 5;
    margin: 0;
    padding: 7px;
    border: 1px solid #dfe3e8;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 -5px 18px rgba(0, 0, 0, .12);
}

#n8n-chat-widget .ttc-file-preview img {
    display: block;
    width: auto;
    height: 70px;
    max-width: 160px;
    margin: 0;
    object-fit: cover;
    border: 0;
    border-radius: 7px;
}

#n8n-chat-widget .ttc-remove-file {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 23px;
    min-width: 23px;
    max-width: 23px;
    height: 23px;
    min-height: 23px;
    max-height: 23px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #e53935;
    color: #fff;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}

#n8n-chat-widget .ttc-chat-img {
    display: block;
    max-width: 230px;
    max-height: 230px;
    margin: 6px 0 0;
    border: 1px solid rgba(0, 0, 0, .12);
    border-radius: 9px;
    object-fit: cover;
}

#n8n-chat-widget .ttc-chat-link,
#n8n-chat-widget .ttc-chat-file {
    color: inherit;
    text-decoration: underline;
    overflow-wrap: anywhere;
}

#n8n-chat-widget .ttc-msg-user .ttc-chat-link,
#n8n-chat-widget .ttc-msg-user .ttc-chat-file {
    color: #fff;
}

#n8n-chat-widget .ttc-send-error {
    margin: 5px 0 0;
    font-size: 11px;
    font-weight: 600;
    color: #ffe3e1;
}

/* ==========================================================================
   TYPING
   ========================================================================== */

#n8n-chat-widget .ttc-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 2px;
}

#n8n-chat-widget .ttc-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #8b9198;
    animation: ttc-bounce 1.2s infinite ease-in-out;
}

#n8n-chat-widget .ttc-typing span:nth-child(2) {
    animation-delay: .15s;
}

#n8n-chat-widget .ttc-typing span:nth-child(3) {
    animation-delay: .3s;
}

/* ==========================================================================
   ANIMATION
   ========================================================================== */

@keyframes ttc-bounce {
    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-4px);
    }
}

@keyframes ttc-focus-pulse {
    0%,
    100% {
        box-shadow:
            0 0 0 0 rgba(0, 132, 255, .32),
            0 9px 28px rgba(0, 132, 255, .42),
            0 3px 9px rgba(0, 0, 0, .18);
        filter: brightness(1);
        transform: translateY(0) scale(1);
    }

    45% {
        box-shadow:
            0 0 0 10px rgba(0, 132, 255, 0),
            0 11px 31px rgba(0, 132, 255, .48),
            0 4px 10px rgba(0, 0, 0, .17);
        filter: brightness(1.04);
        transform: translateY(-1px) scale(1.015);
    }
}

@keyframes ttc-unread-attention {
    0%,
    62%,
    100% {
        box-shadow:
            0 0 0 0 rgba(255, 152, 24, .5),
            0 10px 30px rgba(0, 132, 255, .46),
            0 3px 9px rgba(0, 0, 0, .18);
        filter: brightness(1);
        transform: translateY(0) scale(1) rotate(0deg);
    }

    70% {
        box-shadow:
            0 0 0 14px rgba(255, 152, 24, 0),
            0 15px 36px rgba(0, 132, 255, .55),
            0 5px 12px rgba(0, 0, 0, .18);
        filter: brightness(1.08);
        transform: translateY(-5px) scale(1.07) rotate(0deg);
    }

    77% {
        transform: translateY(-2px) scale(1.04) rotate(-4deg);
    }

    84% {
        transform: translateY(-3px) scale(1.05) rotate(4deg);
    }

    91% {
        transform: translateY(-1px) scale(1.02) rotate(-2deg);
    }
}

@keyframes ttc-icon-attention {
    0%,
    62%,
    100% {
        transform: scale(1) rotate(0deg);
    }

    70% {
        transform: scale(1.14);
    }

    77% {
        transform: scale(1.12) rotate(-6deg);
    }

    84% {
        transform: scale(1.12) rotate(6deg);
    }

    91% {
        transform: scale(1.06) rotate(-3deg);
    }
}

@keyframes ttc-unread-badge-pulse {
    0%,
    100% {
        transform: scale(1);
        box-shadow:
            0 3px 10px rgba(240, 40, 33, .52),
            0 0 0 0 rgba(240, 40, 33, .34);
    }

    50% {
        transform: scale(1.15);
        box-shadow:
            0 4px 13px rgba(240, 40, 33, .58),
            0 0 0 6px rgba(240, 40, 33, 0);
    }
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    #n8n-chat-widget .ttc-toggle,
    #n8n-chat-widget .ttc-toggle-icon,
    #n8n-chat-widget .ttc-unread-badge {
        animation: none;
    }
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
    #n8n-chat-widget {
        right: 10px !important;
        bottom: 84px !important;
    }

    #n8n-chat-widget .ttc-toggle {
        width: 61px;
        min-width: 61px;
        max-width: 61px;
        height: 61px;
        min-height: 61px;
        max-height: 61px;
    }

    #n8n-chat-widget .ttc-toggle-icon,
    #n8n-chat-widget .ttc-toggle-icon svg {
        width: 32px;
        height: 32px;
    }

    #n8n-chat-widget .ttc-window {
        width: min(370px, calc(100vw - 20px));
        height: min(560px, calc(100vh - 105px));
        max-width: none;
        max-height: none;
    }

    #n8n-chat-widget .ttc-window.is-expanded {
        width: calc(100vw - 20px);
        height: calc(100vh - 105px);
    }

    #n8n-chat-widget .ttc-msg-box {
        max-width: 88%;
    }
}

@media (max-width: 390px) {
    #n8n-chat-widget {
        right: 8px !important;
    }

    #n8n-chat-widget .ttc-toggle {
        width: 59px;
        min-width: 59px;
        max-width: 59px;
        height: 59px;
        min-height: 59px;
        max-height: 59px;
    }

    #n8n-chat-widget .ttc-toggle-icon,
    #n8n-chat-widget .ttc-toggle-icon svg {
        width: 31px;
        height: 31px;
    }

    #n8n-chat-widget .ttc-window,
    #n8n-chat-widget .ttc-window.is-expanded {
        width: calc(100vw - 16px);
        height: calc(100vh - 100px);
    }

    #n8n-chat-widget .ttc-btn,
    #n8n-chat-widget .ttc-emoji {
        flex-basis: 24px;
        width: 24px;
        min-width: 24px;
        max-width: 24px;
    }

    #n8n-chat-widget .ttc-input-wrapper {
        padding: 4px;
        gap: 4px;
    }

    #n8n-chat-widget .ttc-btn-send {
        min-width: 52px;
        padding: 0 9px;
    }
}

/* ==========================================================================
   BẢO VỆ CLICK/TOUCH
   ========================================================================== */

#n8n-chat-widget #chat-toggle,
#n8n-chat-widget #ttc-close,
#n8n-chat-widget #ttc-expand,
#n8n-chat-widget #ttc-attach,
#n8n-chat-widget #ttc-send {
    pointer-events: auto !important;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}