/* Main Container */
#jinx-chat-container {
    --jinx-widget-offset-x: 20px;
    --jinx-widget-offset-y: 20px;
    position: fixed;
    bottom: calc(var(--jinx-widget-offset-y) + 70px);
    right: var(--jinx-widget-offset-x);
    width: 350px;
    max-width: 90%;
    height: 450px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    z-index: 999998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    transform-origin: bottom right;
    border: 1px solid #eee;
}

#jinx-chat-container[style*="--jinx-widget-side: left"] {
    right: auto;
    left: var(--jinx-widget-offset-x);
    transform-origin: bottom left;
}

#jinx-chat-container.jinx-hidden {
    transform: translateY(15px) scale(0.98);
    opacity: 0;
    pointer-events: none;
}

/* Header */
#jinx-chat-header {
    background: var(--jinx-accent-color);
    color: var(--jinx-accent-contrast);
    padding: 14px 18px;
    font-weight: 500;
    display: flex;
}

.jinx-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.jinx-header-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%; /* circular */
    object-fit: cover;
    display: block;
}

/* Body & Messages */
#jinx-chat-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden; /* Ensure messages don't push outside */
}

#jinx-chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.jinx-msg {
    padding: 10px 15px;
    border-radius: 14px;
    max-width: 85%;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.jinx-msg-user {
    align-self: flex-end;
    background: var(--jinx-accent-color);
    color: var(--jinx-accent-contrast);
    border-bottom-right-radius: 2px;
}

.jinx-msg-ai {
    align-self: flex-start;
    background: #f1f3f5;
    color: #333;
    border-bottom-left-radius: 2px;
}

/* Bot Choice Buttons */
.jinx-bot-choices {
    background: transparent !important;
    padding: 0 !important;
    width: 100%;
    max-width: 100% !important;
}

.jinx-bot-choices p {
    margin: 0 0 10px 0;
    font-size: 13px;
    color: #666;
}

.jinx-bot-choice-btn {
    border: 1px solid var(--jinx-accent-color) !important;
    color: var(--jinx-accent-color) !important;
    font-weight: 500;
}

.jinx-bot-choice-btn:hover {
    background: var(--jinx-accent-color) !important;
    color: var(--jinx-accent-contrast) !important;
}


/* Input Area */
#jinx-chat-input-area {
    padding: 15px;
    background: #fff;
    border-top: 1px solid #f1f1f1;
    display: flex;
    gap: 10px;
}

#jinx-chat-input {
    flex-grow: 1;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 10px 14px;
    outline: none;
    font-size: 14px;
    color: #333;
    background: #f8f9fa;
    transition: border-color 0.2s, background 0.2s;
}

#jinx-chat-input:focus {
    border-color: var(--jinx-accent-color);
    background: #fff;
}

#jinx-chat-send {
    background: var(--jinx-accent-color);
    color: var(--jinx-accent-contrast);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: filter 0.2s;
}

#jinx-chat-send:hover {
    filter: brightness(0.9);
}

#jinx-chat-send svg {
    width: 20px;
    height: 20px;
}

/* Floating Toggle Button */
#jinx-chat-toggle {
    --jinx-accent-color: #007cba;
    --jinx-widget-offset-x: 20px;
    --jinx-widget-offset-y: 20px;
    position: fixed;
    bottom: var(--jinx-widget-offset-y);
    right: var(--jinx-widget-offset-x);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--jinx-accent-color);
    color: var(--jinx-accent-contrast);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: hidden;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#jinx-chat-toggle[style*="--jinx-widget-side: left"] {
    right: auto;
    left: var(--jinx-widget-offset-x);
}

#jinx-chat-toggle:hover {
    transform: scale(1.05);
}

#jinx-chat-toggle .jinx-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#jinx-chat-toggle svg {
    width: 24px;
    height: 24px;
    stroke: var(--jinx-accent-contrast);
}

.jinx-icon-close {
    display: none;
}

#jinx-chat-toggle.jinx-chat-open {
    background: #343a40;
}

#jinx-chat-toggle.jinx-chat-open .jinx-icon-open {
    display: none;
}

#jinx-chat-toggle.jinx-chat-open .jinx-icon-close {
    display: block;
}

/* Tooltip / Welcome Bubble */
#jinx-chat-tooltip {
    --jinx-tooltip-offset-x: calc(var(--jinx-widget-offset-x) + 65px);
    position: fixed;
    bottom: calc(var(--jinx-widget-offset-y) + 8px); /* Center slightly relative to 56px toggle */
    right: var(--jinx-tooltip-offset-x);
    background: #fff;
    padding: 10px 30px 10px 14px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 999999;
    max-width: 240px;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    pointer-events: auto;
    border: 1px solid #eee;
    animation: jinxPopIn 0.4s ease-out forwards;
}

#jinx-chat-tooltip.jinx-hidden {
    display: none;
}

#jinx-chat-tooltip[style*="--jinx-widget-side: left"] {
    right: auto;
    left: var(--jinx-tooltip-offset-x);
}

#jinx-chat-tooltip[style*="--jinx-widget-side: left"]::after {
    right: auto;
    left: -7px;
    border-left: none;
    border-right: 7px solid #fff;
}

#jinx-chat-tooltip::after {
    content: "";
    position: absolute;
    right: -7px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 7px solid #fff;
}

.jinx-tooltip-close {
    position: absolute;
    top: 2px;
    right: 6px;
    font-size: 16px;
    cursor: pointer;
    color: #adb5bd;
}

.jinx-tooltip-close:hover {
    color: #495057;
}

/* Animations */
@keyframes jinxPopIn {
    0% { transform: scale(0.9) translateX(10px); opacity: 0; }
    100% { transform: scale(1) translateX(0); opacity: 1; }
}

/* Fallback Widget */
.jinx-chat-fallback-widget {
    margin-top: 10px;
    padding: 12px;
    background-color: #f8f9fa;
    border-left: 3px solid var(--jinx-accent-color);
    border-radius: 4px;
    font-size: 13px;
    line-height: 1.5;
}

.jinx-chat-fallback-widget a {
    color: var(--jinx-accent-color);
    text-decoration: none;
    font-weight: 500;
}

/* Markdown Styles */
.jinx-msg p {
    margin: 0 0 8px 0;
}

.jinx-msg p:last-child {
    margin-bottom: 0;
}

.jinx-msg ul, .jinx-msg ol {
    margin: 8px 0;
    padding-left: 20px;
}

.jinx-msg li {
    margin-bottom: 4px;
}

.jinx-msg code {
    background: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.jinx-msg-user code {
    background: rgba(255,255,255,0.2);
}

.jinx-msg pre {
    background: rgba(0,0,0,0.05);
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.jinx-msg-user pre {
    background: rgba(255,255,255,0.1);
}

.jinx-msg pre code {
    background: none;
    padding: 0;
}

.jinx-msg strong {
    font-weight: 600;
}

.jinx-msg blockquote {
    border-left: 3px solid #ddd;
    margin: 8px 0;
    padding-left: 10px;
    color: #666;
}


/* Overlay / Confirm Dialog */
.jinx-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.jinx-overlay.jinx-hidden {
    display: none;
    opacity: 0;
}

.jinx-overlay-content {
    background: #fff;
    padding: 25px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    max-width: 80%;
    animation: jinxPopIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.jinx-overlay-icon {
    margin-bottom: 15px;
    color: var(--jinx-accent-color);
}

.jinx-overlay p {
    margin: 0 0 20px 0;
    font-weight: 600;
    font-size: 16px;
    color: #333;
}

.jinx-overlay-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.jinx-overlay-buttons button {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
    border: none;
}

.jinx-overlay-buttons button:active {
    transform: scale(0.98);
}

.jinx-btn-confirm {
    background: var(--jinx-accent-color);
    color: var(--jinx-accent-contrast);
}

.jinx-btn-cancel {
    background: #f1f3f5;
    color: #495057;
}

.jinx-btn-cancel:hover {
    background: #e9ecef;
}

/* Bot Avatar in Chat Bubble */
.jinx-header-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-style: normal;
    vertical-align: middle;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
