:root {
    --chat-ink: #1c1228;
    --chat-muted: #6f5b86;
    --chat-surface: #f7f1ff;
    --chat-surface-strong: #eadcff;
    --chat-accent: #7c4dff;
    --chat-accent-strong: #6a3ff2;
    --chat-border: #d9c7f5;
    --chat-shadow: rgba(28, 18, 40, 0.25);
    --chat-wrapper-size: 52px;
    --chat-gap: 16px;
    --chat-panel-width: min(450px, calc(100vw - 40px));
    --chat-panel-offset: calc(20px + var(--chat-wrapper-size) + var(--chat-gap));
}

#chatWrapper {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    height: var(--chat-wrapper-size);
    width: var(--chat-wrapper-size);
    background: radial-gradient(circle at 30% 30%, #ffffff 0%, #eadcff 70%);
    border-radius: 100%;
    border: 1px solid var(--chat-border);
    box-shadow: 0 0 10px var(--pro-main-color);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#chatWrapper:hover,
#chatWrapper.isOpen {
    transform: translateY(-2px);
    box-shadow: 0 16px 30px rgba(31, 26, 23, 0.25);
}

#chatgptLogo,
#geminiLogo {
    width: 28px;
}

#chatPanel {
    display: none;
    position: fixed;
    right: 20px;
    bottom: var(--chat-panel-offset);
    z-index: 1000;
    width: var(--chat-panel-width);
    height: min(calc(100vh - 200px), 700px);
    flex-direction: column;
    border-radius: 8px;
    border: 1px solid var(--chat-border);
    background: radial-gradient(circle at top left, #f4ecff 0%, #f7f1ff 50%, #e7dbff 100%);
    box-shadow: 0 18px 40px var(--chat-shadow);
    transition: opacity 0.2s ease, transform 0.2s ease;
    font-family: "Space Grotesk", "Avenir Next", "Helvetica Neue", sans-serif;
    color: var(--chat-ink);
}

#chatPanel.isOpen {
    display: flex;
}

#chatHeader {
    padding: 12px 14px 10px;
    background: linear-gradient(135deg, #f5edff 0%, #f9f4ff 45%, #e7dbff 100%);
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chatHeaderTop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chatHeaderActions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.chatTitle {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.chatHeaderIconButton {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    color: var(--chat-muted);
    border-radius: 2px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    outline: none;
}

.chatHeaderIconButton:hover,
.chatHeaderIconButton:focus {
    color: var(--chat-ink);
    border-color: var(--chat-border);
    background: #ffffff;
}   

.chatTooltip {
    position: absolute;
    right: 0;
    bottom: calc(100% + 6px);
    padding: 4px 8px;
    border-radius: 100px;
    white-space: nowrap;
    background: #ffffff;
    border: 1px solid var(--chat-border);
    box-shadow: 0 4px 12px rgba(28, 18, 40, 0.12);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--chat-muted);
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.chatHeaderIconButton:hover .chatTooltip,
.chatHeaderIconButton:focus .chatTooltip {
    opacity: 1;
    transform: translateY(0);
}

.chatCloseIcon {
    font-size: 1.2rem;
    border-radius: 2px;
    font-weight: 700;
}

.chatClearIcon {
    width: 16px;
    height: 16px;
}

#chatFooter {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--chat-border);
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    background: #f9f4ff;
}

.chatModels {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 2px;
    border: 1px solid var(--chat-border);
    border-radius: 100px;
    background: #efe6ff;
}

.chatModelSlider {
    position: absolute;
    top: 2px;
    bottom: 2px;
    left: 2px;
    width: calc(50% - 2px);
    border-radius: 100px;
    background: #ffffff;
    box-shadow: 0 4px 10px rgba(28, 18, 40, 0.12);
    transition: transform 0.2s ease;
    z-index: 0;
}

.chatModels[data-active="gemini"] .chatModelSlider {
    transform: translateX(100%);
}

.chatModelToggle,
.chatModelToggle:hover,
.chatModelToggle:focus,
.chatModelToggle:active {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    background: transparent;
    color: var(--chat-muted);
    border-radius: 100px;
    padding: 6px 8px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    transition: color 0.2s ease;
}

.chatModelToggle:hover,
.chatModelToggle:focus,
.chatModelToggle:active {
    color: var(--chat-ink);
}

.chatModelToggle.isActive {
    color: var(--chat-ink);
}

.chatModelIcon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0.65;
    transition: opacity 0.2s ease;
}

.chatModelToggle.isActive .chatModelIcon {
    opacity: 1;
}

.chatModelIcon path {
    fill: currentColor;
}

#chatBody {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    min-height: 100px;
    overflow: hidden;
    flex: 1;
    background: white;
}

#chatMessages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 6px;
}

.chatBubble {
    max-width: 85%;
    padding: 10px 12px;
    border-radius: 18px;
    background: #ffffff;
    border: 1px solid var(--chat-border);
    font-size: 0.9rem;
    line-height: 1.35;
    white-space: pre-wrap;
    box-shadow: 0 0 5px lightgray;
    animation: chat-pop 0.18s ease-out;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word; 
}

.chatBubble:nth-last-child(1) {
    margin-bottom: min(calc(100vh - 200px), 700px);
}

.chatBubble a {
    color: var(--chat-accent-strong);
    text-decoration: underline;
}

.chatBubble a:hover {
    color: var(--chat-accent);
}

.chatBubble code {
    font-family: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.85rem;
    background: #f7f7f7;
    border: 1px solid #e1d3ff;
    border-radius: 4px;
    padding: 2px 4px;
    color: var(--pro-main-color);
}

.chatBubble pre {
    margin: 8px 0;
    padding: 10px 12px;
    background: #f7f7f7;
    border: 1px solid #e1d3ff;
    border-radius: 4px;
    white-space: pre-wrap;
}

.chatBubble pre code {
    background: transparent;
    border: none;
    padding: 0;
    font-size: 0.85rem;
}

.chatBubble h1,
.chatBubble h2,
.chatBubble h3 {
    margin: 6px 0 4px;
    font-weight: bold;
    line-height: 1.2;
}

.chatBubble h1 {
    font-size: 1.2rem;
}

.chatBubble h2 {
    font-size: 1.1rem;
}

.chatBubble h3 {
    font-size: 1rem;
}

.chatBubble ul {
    margin: 6px 0 6px 18px;
    padding: 0;
}

.chatBubble li {
    margin: 2px 0;
}

.chatBubble.isUser {
    align-self: flex-end;
    background: linear-gradient(135deg, #eadbff 0%, #ddc8ff 100%);
    color: #241236;
}

.chatBubble.isAssistant {
    align-self: flex-start;
    border: none;
    box-shadow: none;
}

.chatBubble.isLoading {
    color: var(--chat-muted);
    font-style: italic;
}

.chatBubble.isError {
    color: #000000;
    background: #ffebeb;
    border: solid 1px red;
}

#chatUpgradeNotice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: #f5edff;
    border: 1px solid #cdb0ff;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--chat-muted);
}

#chatUpgradeNotice[hidden] {
    display: none;
}

#chatUpgradeNotice a {
    color: var(--chat-accent-strong);
    font-weight: 600;
    text-decoration: none;
}

#chatUpgradeNotice a:hover {
    text-decoration: underline;
}

#chatComposer {
    display: flex;
    gap: 8px;
    padding: 0;
    border-top: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

#chatComposer.isDisabled {
    opacity: 0.6;
}

#chatInput {
    flex: 1;
    border: 1px solid var(--chat-border);
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
}

#chatInput:focus {
    border-color: var(--chat-accent);
    box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.18);
}

#chatSend {
    border: none;
    background: var(--chat-accent);
    color: #ffffff;
    padding: 10px 14px;
    border-radius: 4px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.85rem;
}

#chatSend:disabled {
    background: #c9b0ff;
    cursor: not-allowed;
}

@keyframes chat-pop {
    from {
        transform: translateY(4px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}
