.chat-widget-button {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 9999;
    width: 64px;
    height: 64px;
    border: 1px solid rgba(255, 255, 255, 0.38);
    border-radius: 50%;
    background: linear-gradient(145deg, #ffffff 0%, #eef6ff 100%);
    box-shadow: 0 18px 42px rgba(13, 93, 178, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    cursor: pointer;
    user-select: none;
    touch-action: none;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.chat-widget-button::after {
    content: "";
    position: absolute;
    inset: 7px;
    border-radius: inherit;
    border: 1px solid rgba(255, 255, 255, 0.26);
    pointer-events: none;
}

.chat-widget-button:hover {
    transform: translateY(-2px);
    background: linear-gradient(145deg, #ffffff 0%, #e4f2ff 100%);
    box-shadow: 0 22px 52px rgba(13, 93, 178, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

.chat-widget-button:active {
    transform: translateY(0) scale(0.97);
}

.chat-widget-button-inner {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.chat-widget-logo-image {
    width: 82%;
    height: 82%;
    display: block;
    object-fit: contain;
}

.chat-widget-window {
    position: fixed;
    right: 22px;
    bottom: 96px;
    z-index: 9998;
    width: min(480px, calc(100vw - 36px));
    height: min(680px, calc(100vh - 122px));
    min-height: 480px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(25, 118, 210, 0.16);
    border-radius: 10px;
    background: #f8fbff;
    box-shadow: 0 24px 72px rgba(8, 31, 68, 0.28);
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.18s ease, visibility 0.18s ease, transform 0.18s ease;
}

.chat-widget-window-show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.chat-widget-window-fullscreen {
    top: 16px !important;
    left: 16px !important;
    right: 16px !important;
    bottom: 16px !important;
    width: calc(100vw - 32px) !important;
    height: calc(100vh - 32px) !important;
    max-width: none;
    min-height: 0;
    border-radius: 10px;
}

.chat-widget-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: 12px 14px 12px 16px;
    color: #fff;
    background: linear-gradient(135deg, #1778d7 0%, #29a5ee 100%);
}

.chat-widget-header-title {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 12px;
}

.chat-widget-header-logo {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.chat-widget-header-logo .chat-widget-logo-image {
    width: 31px;
    height: 31px;
}

.chat-widget-title-text {
    min-width: 0;
}

.chat-widget-header h3 {
    margin: 0;
    font-size: 17px;
    line-height: 1.2;
    font-weight: 700;
    letter-spacing: 0;
}

.chat-widget-subtitle {
    margin-top: 3px;
    font-size: 12px;
    line-height: 1.2;
    color: rgba(255, 255, 255, 0.78);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-widget-header-buttons {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-widget-close,
.chat-widget-fullscreen {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 8px;
    color: #fff;
    background: transparent;
    cursor: pointer;
    transition: background 0.16s ease, transform 0.16s ease;
}

.chat-widget-close {
    font-size: 25px;
    line-height: 1;
}

.chat-widget-close:hover,
.chat-widget-fullscreen:hover {
    background: rgba(255, 255, 255, 0.18);
}

.chat-widget-close:active,
.chat-widget-fullscreen:active {
    transform: scale(0.95);
}

.chat-widget-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 16px;
    background:
        linear-gradient(180deg, rgba(239, 247, 255, 0.94) 0%, rgba(250, 252, 255, 0.98) 100%);
}

.chat-widget-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-widget-messages::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(78, 119, 166, 0.28);
}

.chat-widget-message {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 0 14px;
}

.chat-widget-message-user {
    justify-content: flex-end;
}

.chat-widget-message-bot {
    justify-content: flex-start;
}

.chat-widget-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 50%;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 27px 27px;
}

.chat-widget-avatar-user {
    order: 2;
    background-color: #f08a22;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4Zm0 2c-2.67 0-8 1.34-8 4v1.4c0 .33.27.6.6.6h14.8c.33 0 .6-.27.6-.6V18c0-2.66-5.33-4-8-4Z'/%3E%3C/svg%3E");
}

.chat-widget-avatar-bot {
    background-color: #fff;
    background-image: url("/chat-gear-logo-centered.png");
    box-shadow: 0 8px 18px rgba(173, 35, 28, 0.18);
}

.chat-widget-message-content {
    max-width: min(78%, 360px);
    min-width: 0;
    padding: 10px 13px;
    border-radius: 13px;
    font-size: 14px;
    line-height: 1.65;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.chat-widget-message-user .chat-widget-message-content {
    order: 1;
    color: #172033;
    background: #ffffff;
    border: 1px solid rgba(15, 71, 130, 0.08);
    border-top-right-radius: 4px;
    box-shadow: 0 8px 22px rgba(33, 60, 95, 0.08);
}

.chat-widget-message-bot .chat-widget-message-content {
    color: #162033;
    background: #e8f4ff;
    border: 1px solid rgba(41, 150, 232, 0.18);
    border-top-left-radius: 4px;
}

.chat-widget-input {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px;
    border-top: 1px solid rgba(30, 100, 170, 0.1);
    background: rgba(255, 255, 255, 0.96);
}

.chat-widget-input textarea {
    flex: 1 1 auto;
    height: 44px;
    max-height: 116px;
    min-width: 0;
    padding: 11px 13px;
    border: 1px solid rgba(56, 112, 170, 0.18);
    border-radius: 10px;
    outline: none;
    resize: none;
    color: #162033;
    background: #fff;
    font: inherit;
    line-height: 1.45;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.chat-widget-input textarea:focus {
    border-color: #2b91df;
    box-shadow: 0 0 0 3px rgba(43, 145, 223, 0.12);
}

.chat-widget-input textarea:disabled {
    color: #8a97a8;
    background: #f4f7fa;
    cursor: not-allowed;
}

.chat-widget-send {
    flex: 0 0 auto;
    min-width: 78px;
    height: 44px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    color: #fff;
    background: linear-gradient(135deg, #2799eb 0%, #1175cf 100%);
    box-shadow: 0 10px 22px rgba(17, 117, 207, 0.24);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}

.chat-widget-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 26px rgba(17, 117, 207, 0.3);
}

.chat-widget-send:active {
    transform: translateY(0);
}

.chat-widget-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.chat-widget-loading {
    width: fit-content;
    max-width: 78%;
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0 0 14px 44px;
    padding: 10px 13px;
    border: 1px solid rgba(41, 150, 232, 0.18);
    border-radius: 13px;
    border-top-left-radius: 4px;
    color: #526173;
    background: #e8f4ff;
    font-size: 13px;
}

.chat-widget-message-loading .chat-widget-loading {
    margin: 0;
}

.chat-widget-loading-dots {
    display: flex;
    gap: 4px;
}

.chat-widget-loading-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #1d86df;
    animation: chat-widget-loading 1.1s infinite ease-in-out;
}

.chat-widget-loading-dot:nth-child(2) {
    animation-delay: 0.16s;
}

.chat-widget-loading-dot:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes chat-widget-loading {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.45;
    }
    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.chat-widget-message-content p {
    margin: 0 0 8px;
}

.chat-widget-message-content p:last-child,
.chat-widget-message-content ul:last-child,
.chat-widget-message-content ol:last-child,
.chat-widget-message-content pre:last-child,
.chat-widget-message-content table:last-child {
    margin-bottom: 0;
}

.chat-widget-message-content h1,
.chat-widget-message-content h2,
.chat-widget-message-content h3,
.chat-widget-message-content h4 {
    margin: 12px 0 8px;
    color: #0e335f;
    line-height: 1.35;
    letter-spacing: 0;
}

.chat-widget-message-content h1 {
    font-size: 18px;
}

.chat-widget-message-content h2 {
    font-size: 17px;
}

.chat-widget-message-content h3,
.chat-widget-message-content h4 {
    font-size: 15px;
}

.chat-widget-message-content ul,
.chat-widget-message-content ol {
    margin: 6px 0 10px 20px;
    padding: 0;
}

.chat-widget-message-content li {
    margin: 3px 0;
}

.chat-widget-message-content strong {
    color: #0e335f;
    font-weight: 700;
}

.chat-widget-message-content code {
    padding: 2px 5px;
    border-radius: 5px;
    color: #0a4f94;
    background: rgba(15, 112, 194, 0.1);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
}

.chat-widget-message-content pre {
    max-width: 100%;
    margin: 8px 0 10px;
    padding: 10px 12px;
    overflow-x: auto;
    border-radius: 8px;
    color: #e8f2ff;
    background: #10233d;
    font-size: 12px;
    line-height: 1.55;
}

.chat-widget-message-content pre code {
    padding: 0;
    color: inherit;
    background: transparent;
    font-size: inherit;
}

.chat-widget-message-content blockquote {
    margin: 8px 0;
    padding: 7px 10px;
    border-left: 3px solid #238ee3;
    border-radius: 0 7px 7px 0;
    background: rgba(35, 142, 227, 0.08);
    color: #44576b;
}

.chat-widget-message-content table {
    display: block;
    width: max-content;
    max-width: 100%;
    margin: 8px 0 10px;
    overflow-x: auto;
    border-collapse: collapse;
    border-radius: 8px;
    background: #fff;
}

.chat-widget-message-content th,
.chat-widget-message-content td {
    padding: 7px 9px;
    border: 1px solid rgba(34, 89, 145, 0.16);
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.chat-widget-message-content th {
    color: #0e335f;
    background: #eef7ff;
    font-weight: 700;
}

.chat-widget-think-container {
    margin-bottom: 10px;
    overflow: hidden;
    border: 1px solid rgba(34, 89, 145, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
}

.chat-widget-think-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    color: #36506a;
    background: rgba(35, 142, 227, 0.08);
    cursor: pointer;
    user-select: none;
    font-size: 13px;
}

.chat-widget-think-arrow {
    display: inline-block;
    transition: transform 0.16s ease;
}

.chat-widget-think-arrow.expanded {
    transform: rotate(90deg);
}

.chat-widget-think-content {
    max-height: 0;
    overflow: hidden;
    padding: 0 10px;
    color: #405367;
    transition: max-height 0.2s ease, padding 0.2s ease;
}

.chat-widget-think-content.expanded {
    max-height: 420px;
    padding: 10px;
    overflow-y: auto;
}

@media (max-width: 640px) {
    .chat-widget-button {
        right: 16px;
        bottom: 16px;
        width: 58px;
        height: 58px;
    }

    .chat-widget-window {
        right: 10px !important;
        left: 10px !important;
        bottom: 84px !important;
        top: auto !important;
        width: calc(100vw - 20px) !important;
        height: min(640px, calc(100vh - 104px));
        min-height: 420px;
    }

    .chat-widget-window-fullscreen {
        top: 8px !important;
        right: 8px !important;
        bottom: 8px !important;
        left: 8px !important;
        width: calc(100vw - 16px) !important;
        height: calc(100vh - 16px) !important;
    }

    .chat-widget-message-content {
        max-width: calc(100% - 46px);
    }
}
