.mh-dify-chat {
    --mh-dify-blue: #2e9cdb;
    --mh-dify-blue-dark: #2586c0;
    --mh-dify-bg: #eef6fb;
    border: 1px solid #c5dde9;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.mh-dify-chat__header {
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--mh-dify-blue) 0%, var(--mh-dify-blue-dark) 100%);
    color: #fff;
}

.mh-dify-chat__header h2 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.4;
}

.mh-dify-chat__header p {
    margin: 6px 0 0;
    font-size: 0.8125rem;
    opacity: 0.95;
}

.mh-dify-chat__messages {
    min-height: 220px;
    max-height: min(520px, 55vh);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: var(--mh-dify-bg);
}

.mh-dify-chat__message {
    margin-bottom: 12px;
    display: flex;
}

.mh-dify-chat__message--bot {
    align-items: flex-start;
    gap: 8px;
}

.mh-dify-chat__avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.mh-dify-chat__message--user {
    justify-content: flex-end;
}

.mh-dify-chat__bubble {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9375rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.mh-dify-chat__message--bot .mh-dify-chat__bubble {
    background: #fff;
    color: #333;
    border: 1px solid #d8e8f0;
    border-top-left-radius: 4px;
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 44px);
    overflow: visible;
}

.mh-dify-chat__message--user .mh-dify-chat__bubble {
    background: var(--mh-dify-blue);
    color: #fff;
    border-top-right-radius: 4px;
}

.mh-dify-chat__message--loading .mh-dify-chat__bubble {
    font-style: normal;
}

.mh-dify-chat__bubble--dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-width: 52px;
    min-height: 24px;
    padding: 12px 16px;
}

.mh-dify-chat__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #8aa8b8;
    animation: mh-dify-chat-dot 1.2s infinite ease-in-out both;
}

.mh-dify-chat__dot:nth-child(1) {
    animation-delay: 0s;
}

.mh-dify-chat__dot:nth-child(2) {
    animation-delay: 0.15s;
}

.mh-dify-chat__dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes mh-dify-chat-dot {
    0%,
    80%,
    100% {
        opacity: 0.25;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

.mh-dify-chat__bubble--md {
    white-space: normal;
}

.mh-dify-chat__bubble--md > :first-child {
    margin-top: 0;
}

.mh-dify-chat__bubble--md > :last-child {
    margin-bottom: 0;
}

.mh-dify-chat__bubble--md p {
    margin: 0 0 0.65em;
}

.mh-dify-chat__bubble--md h1,
.mh-dify-chat__bubble--md h2,
.mh-dify-chat__bubble--md h3,
.mh-dify-chat__bubble--md h4 {
    margin: 0.75em 0 0.4em;
    font-size: 1em;
    font-weight: 700;
    line-height: 1.4;
}

.mh-dify-chat__bubble--md ul,
.mh-dify-chat__bubble--md ol {
    margin: 0.4em 0 0.65em;
    padding-left: 1.35em;
}

.mh-dify-chat__bubble--md li {
    margin: 0.2em 0;
}

.mh-dify-chat__bubble--md li > ul,
.mh-dify-chat__bubble--md li > ol {
    margin-bottom: 0;
}

.mh-dify-chat__bubble--md a {
    color: var(--mh-dify-blue);
    text-decoration: underline;
}

.mh-dify-chat__bubble--md a:hover {
    color: var(--mh-dify-blue-dark);
}

.mh-dify-chat__bubble--md code {
    padding: 0.1em 0.35em;
    border-radius: 4px;
    background: #eef4f8;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 0.88em;
}

.mh-dify-chat__bubble--md pre {
    margin: 0.5em 0 0.75em;
    padding: 10px 12px;
    border-radius: 8px;
    background: #eef4f8;
    overflow-x: auto;
}

.mh-dify-chat__bubble--md pre code {
    padding: 0;
    background: none;
    font-size: 0.85em;
}

.mh-dify-chat__bubble--md blockquote {
    margin: 0.5em 0;
    padding-left: 10px;
    border-left: 3px solid #c5dde9;
    color: #555;
}

.mh-dify-chat__bubble--md table {
    display: block;
    width: 100%;
    margin: 0.5em 0 0.75em;
    border-collapse: collapse;
    font-size: 0.875rem;
    overflow-x: auto;
}

.mh-dify-chat__bubble--md th,
.mh-dify-chat__bubble--md td {
    padding: 6px 8px;
    border: 1px solid #d8e8f0;
    text-align: left;
}

.mh-dify-chat__bubble--md th {
    background: #f5fafc;
    font-weight: 700;
}

.mh-dify-chat__bubble--md hr {
    margin: 0.75em 0;
    border: 0;
    border-top: 1px solid #d8e8f0;
}

.mh-dify-chat__bubble--md strong {
    font-weight: 700;
}

.mh-dify-chat__composer {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: #fff;
    border-top: 1px solid #d8e8f0;
}

.mh-dify-chat__input {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 10px 12px;
    border: 1px solid #c5dde9;
    border-radius: 8px;
    font-size: 0.9375rem;
    line-height: 1.5;
    resize: vertical;
    font-family: inherit;
}

.mh-dify-chat__input:focus {
    outline: none;
    border-color: var(--mh-dify-blue);
    box-shadow: 0 0 0 2px rgba(46, 156, 219, 0.2);
}

.mh-dify-chat__send {
    flex-shrink: 0;
    align-self: flex-end;
    min-width: 72px;
    height: 44px;
    padding: 0 16px;
    border: none;
    border-radius: 8px;
    background: var(--mh-dify-blue);
    color: #fff;
    font-size: 0.9375rem;
    font-weight: 700;
    cursor: pointer;
}

.mh-dify-chat__send:hover:not(:disabled) {
    background: var(--mh-dify-blue-dark);
}

.mh-dify-chat__send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.mh-dify-chat__error {
    margin: 0 12px 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #fff0f0;
    color: #c0392b;
    font-size: 0.875rem;
    display: none;
}

.mh-dify-chat__error.is-visible {
    display: block;
}

.mh-dify-chat__notice {
    padding: 12px 16px;
    background: #fff8e6;
    color: #7a5d00;
    font-size: 0.875rem;
    border: 1px dashed #e6c200;
    border-radius: 8px;
}

@media screen and (max-width: 599px) {
    .mh-dify-chat__messages {
        max-height: min(360px, 50vh);
    }
}
