#ai-chat-layout-wrapper {
    position: fixed;
    inset: var(--nav_height) 0 0;
    display: flex;
    background: var(--white);
    color: var(--main);
}

#ai-chat-layout-wrapper svg,
#ai-chat-templates svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

#ai-chat-sidebar {
    width: 264px;
    flex-shrink: 0;
    min-height: 0;
    padding: 24px 16px 20px;
    background: var(--secondary_background);
    border-right: 1px solid var(--lightgray);
}

.ai-chat-new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.ai-chat-history-header {
    margin: 30px 12px 12px;
    font-size: 12px;
    font-weight: var(--main_bolder_weight);
    color: var(--secondary);
}

.ai-chat-history-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#ai-chat-history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ai-chat-history-empty {
    margin: 0 12px;
    color: var(--secondary);
    font-size: 13px;
    line-height: 1.6;
}

.ai-chat-history-item {
    position: relative;
}

.history-link {
    display: flex;
    padding: 11px 40px 11px 12px;
    border-radius: 12px;
    color: var(--main);
}

.history-link:hover,
.history-link.active {
    background: var(--secondary_background_2);
    color: var(--main);
}

.history-link.active {
    box-shadow: inset 0 0 0 1px var(--lightgray);
}

.history-item-text {
    min-width: 0;
    flex: 1;
}

.history-title {
    font-size: 14px;
    font-weight: var(--main_bold_weight);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-date {
    margin-top: 4px !important;
    font-size: 11px;
}

.history-delete-btn {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
}

#ai-chat-main {
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 0;
    padding: 0 32px;
}

#obrazavr-ai-chat-container {
    width: 100%;
    max-width: 768px;
    min-height: 0;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    position: relative;
}

.ai-chat-welcome,
.ai-chat-suggestions {
    display: none;
}

#obrazavr-ai-chat-container.is-empty {
    justify-content: center;
    padding: 32px 0 76px;
    overflow-y: auto;
}

.is-empty .ai-chat-welcome {
    display: block;
    text-align: center;
    margin-bottom: 28px;
}

.ai-chat-welcome h1 {
    font-family: var(--main_font);
    font-weight: var(--main_bolder_weight);
    font-size: clamp(28px, 3.2vw, 36px);
    letter-spacing: -.8px;
    margin: 0;
    line-height: 1.25;
}

#obrazavr-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--lightgray) transparent;
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding: 36px 0 32px;
}

.is-empty #obrazavr-chat-messages {
    display: none;
}

.ai-chat-message {
    min-width: 0;
    flex-shrink: 0;
    font-size: 16px;
    font-weight: 400;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.ai-chat-message-user {
    display: flex;
    justify-content: flex-end;
}

.ai-chat-bubble.user-message {
    max-width: 80%;
    background: var(--secondary_background);
    padding: 10px 18px;
    border-radius: 24px;
    line-height: 1.6;
}

.bot-message {
    min-width: 0;
}

.message-text > :first-child { margin-top: 0; }
.message-text > :last-child { margin-bottom: 0; }
.message-text p { margin: 0 0 12px; line-height: inherit; }
.message-text h2, .message-text h3, .message-text h4 {
    margin: 20px 0 8px;
    line-height: 1.4;
    font-size: 1.12em;
}
.message-text h2 { font-size: 1.25em; }
.message-text strong, .message-text b { font-weight: var(--main_bolder_weight); }
.message-text ul, .message-text ol { margin: 8px 0 12px; padding-left: 26px; }
.message-text li { margin: 4px 0; }
.message-text li > p { margin-bottom: 6px; }
.message-text li > :last-child { margin-bottom: 0; }
.message-text li > ul, .message-text li > ol { margin-top: 6px; }
.message-text a { text-decoration: underline; text-underline-offset: 3px; }
.message-text blockquote {
    border-left: 3px solid var(--lightgray);
    padding-left: 18px;
    margin: 12px 0;
    color: var(--secondary);
}
.message-text pre {
    max-width: 100%;
    overflow-x: auto;
    padding: 16px;
    border-radius: 12px;
    background: var(--secondary_background);
    font-size: 14px;
}
.message-text table {
    display: block;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    table-layout: auto;
    overflow-wrap: normal;
    margin: 16px 0;
}
.message-text th, .message-text td { min-width: 120px; padding: 10px 14px; border: 1px solid var(--lightgray); text-align: left; }
.message-text th { background: var(--secondary_background); }
.message-text img { max-width: 100%; height: auto; }
.message-text .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

.ai-chat-message-actions,
.rating-container {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-chat-message-actions { margin-top: 10px; color: var(--secondary); }
#ai-chat-layout-wrapper .ai-chat-message-actions svg { width: 17px; height: 17px; }
.ai-chat-copy-status, .rating-container.rated { font-size: 12px; }

#ai-chat-layout-wrapper .ai-chat-icon-btn,
#ai-chat-layout-wrapper .history-delete-btn,
#mobile_ai_sidebar_opener {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 7px;
    flex-shrink: 0;
    color: var(--secondary);
    background: transparent;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
}

#ai-chat-layout-wrapper .ai-chat-icon-btn:hover:not(:disabled),
#ai-chat-layout-wrapper .history-delete-btn:hover {
    background: var(--secondary_background_2);
    color: var(--main);
}

#ai-chat-layout-wrapper button:focus-visible,
#ai-chat-layout-wrapper a:focus-visible {
    outline: 2px solid var(--secondary);
    outline-offset: 3px;
}

.ai-chat-composer {
    flex-shrink: 0;
    border: 1px solid var(--lightgray);
    border-radius: 26px;
    padding: 6px 12px;
    background: var(--white);
    box-shadow: 0 4px 18px color-mix(in srgb, var(--main) 4%, transparent);
    transition: border-color .15s;
    cursor: text;
}

.ai-chat-composer:focus-within { border-color: var(--secondary); }
.is-empty .ai-chat-composer { padding: 6px 16px; }

#obrazavr-ai-chat-container:not(.is-empty) .ai-chat-composer {
    margin-bottom: max(20px, env(safe-area-inset-bottom, 0px));
}

#obrazavr-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

#obrazavr-chat-user-input {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    max-height: min(200px, 30dvh);
    resize: none;
    overflow-y: auto;
    border: 0;
    outline: none;
    box-shadow: none;
    background: transparent;
    border-radius: 0;
    padding: 8px 0;
    font-size: 16px;
    line-height: 24px;
}

#obrazavr-chat-user-input::placeholder { color: var(--secondary); opacity: 1; }

#ai-chat-layout-wrapper #obrazavr-chat-attach-btn,
#ai-chat-layout-wrapper #obrazavr-chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

#ai-chat-layout-wrapper #obrazavr-chat-send-btn {
    background: var(--accent);
    color: var(--white);
}

#ai-chat-layout-wrapper #obrazavr-chat-send-btn:disabled {
    background: var(--secondary_background_2);
    color: var(--disabled_text);
    transform: none;
    cursor: default;
}

#ai-chat-layout-wrapper #obrazavr-chat-send-btn:hover:not(:disabled) { filter: brightness(1.08); }
#ai-chat-layout-wrapper button:disabled { cursor: default; }

.is-empty .ai-chat-suggestions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}

.ai-chat-suggestion.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 11px;
    padding: 10px 13px;
    --radius: 999px;
}

#ai-chat-layout-wrapper .ai-chat-suggestion svg { width: 17px; height: 17px; }

#obrazavr-chat-image-preview-container {
    position: relative;
    width: fit-content;
    margin: 0 4px 12px;
}

#obrazavr-chat-image-preview {
    display: block;
    width: auto;
    max-width: 100px;
    max-height: 100px;
    border-radius: 12px;
}

#obrazavr-chat-remove-image-btn {
    position: absolute;
    top: -6px;
    right: -8px;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--lightgray);
    border-radius: 50%;
    background: var(--white);
    color: var(--main);
    font-size: 20px;
    cursor: pointer;
}

.message-image-container:not(:last-child) { margin-bottom: 10px; }
.chat-uploaded-image { display: block; max-width: 100%; max-height: 340px; border-radius: 12px; }
#obrazavr-ai-chat-container.drag-over .ai-chat-composer { outline: 2px dashed var(--secondary); outline-offset: 4px; }

.typing-indicator { display: flex; gap: 5px; padding: 8px 0; }
.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--secondary);
    border-radius: 50%;
    animation: ai-chat-thinking 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }
@keyframes ai-chat-thinking { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing-indicator span { animation: none; } }

#mobile_ai_sidebar_opener { display: none; }

@media (max-width: 1000px) and (min-width: 766px) {
    #ai-chat-sidebar { width: 224px; padding-inline: 12px; }
    #ai-chat-main { padding-inline: 24px; }
}

@media (max-width: 765px) {
    #ai-chat-main { padding: 52px 16px 0; }
    #obrazavr-ai-chat-container.is-empty { padding: 8px 0 32px; }
    #ai-chat-sidebar {
        position: absolute;
        inset: 0;
        width: 100%;
        z-index: 3;
        padding: 58px 20px 20px;
        border-right: 0;
    }
    #ai-chat-sidebar:not(.opened) { display: none; }
    #mobile_ai_sidebar_opener {
        display: inline-flex;
        position: absolute;
        top: 10px;
        left: 16px;
        z-index: 4;
        background: var(--secondary_background);
        color: var(--main);
        width: 36px;
        height: 36px;
    }
    .is-empty .ai-chat-welcome { margin-bottom: 24px; }
    #obrazavr-chat-messages { padding: 12px 0 24px; gap: 26px; }
    .ai-chat-bubble.user-message { max-width: 90%; padding: 10px 16px; }
    .ai-chat-composer, .is-empty .ai-chat-composer { padding: 6px 10px; border-radius: 24px; }
    #obrazavr-chat-input-area { gap: 6px; }
    .is-empty .ai-chat-suggestions { gap: 8px; margin-top: 20px; }
    .ai-chat-suggestion.btn { font-size: 10px; padding: 9px 11px; }
}

@media (max-height: 600px) {
    #obrazavr-ai-chat-container.is-empty { justify-content: flex-start; }
}
