/* =============================================================================
   KI-Chat Streaming UI – /ai/chat
   ============================================================================= */

.ki-chat {
    height: 100%;
    overflow: hidden;
    min-height: 0;
}

/* Hauptbereich und Sidebar füllen die volle Höhe des Chats */
.ki-chat > * {
    min-height: 0;
}

/* Chat-Seite: Body auf exakte Viewport-Höhe fixieren, kein eigener Scroll */
body:has(.ki-chat--seite) .oo-wdb-body {
    height: calc(100vh - var(--oo-wdb-header-height));
    min-height: unset;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body:has(.ki-chat--seite) .oo-wdb-body > * {
    flex: 1;
    min-height: 0;
}

/* ── Sidebar ── */

.ki-chat-sidebar {
    width: 18rem;
    min-width: 200px;
    border-right: 1px solid var(--oo-color-border, #e0e0e0);
    background: var(--oo-color-surface, #f5f5f5);
}

.ki-chat-sidebar-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--oo-color-border, #e0e0e0);
    font-weight: 600;
    background: var(--oo-primary);
    color: #fff;
}

.ki-chat-sidebar-liste {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.ki-chat-sidebar-eintrag {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 0.5rem 0.75rem;
    margin-bottom: 2px;
    border: none;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.ki-chat-sidebar-eintrag:hover {
    background: var(--oo-color-surface-hover, #eeeeee);
}

.ki-chat-sidebar-eintrag.aktiv {
    background: var(--oo-color-primary-light, #e3f2fd);
    font-weight: 500;
}

.ki-chat-sidebar-eintrag-inhalt {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.ki-chat-sidebar-eintrag-inhalt .ki-chat-sidebar-eintrag-titel {
    flex: 1;
    min-width: 0;
}

.ki-chat-sidebar-eintrag-loeschen {
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.ki-chat-sidebar-eintrag:hover .ki-chat-sidebar-eintrag-loeschen {
    opacity: 1;
}

.ki-chat-sidebar-eintrag-titel {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Main Area ── */

.ki-chat-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* Schwebendes Scroll-nach-unten-Icon */
.ki-chat-scroll-down-btn {
    position: absolute;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--oo-color-border, #ccc);
    border-radius: 50%;
    background: var(--oo-color-background, #fff);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    color: var(--oo-color-text-secondary, #555);
    font-size: 1.1rem;
    z-index: 10;
    margin-bottom: 0.5rem;
}

.ki-chat-scroll-down-btn.aktiv,
.ki-chat-scroll-down-btn.sichtbar {
    display: flex;
}

/* ── Nachrichten ── */

.ki-chat-nachrichten {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overscroll-behavior: contain;
}

.ki-chat-willkommen {
    flex: 1;
    color: var(--oo-color-text-secondary, #666);
    text-align: center;
}

.ki-chat-willkommen h2 {
    margin: 0 0 0.5rem;
    font-size: 1.4rem;
}

.ki-chat-willkommen p {
    margin: 0;
}

.ki-chat-nachricht {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    line-height: 1.5;
}

.ki-chat-nachricht.benutzer {
    align-self: flex-end;
    background: var(--oo-color-primary-light, #e3f2fd);
    border-bottom-right-radius: 2px;
}

.ki-chat-nachricht.assistent {
    align-self: flex-start;
    background: var(--oo-color-surface, #f0f0f0);
    border-bottom-left-radius: 2px;
}

.ki-chat-text {
    word-break: break-word;
}

.ki-chat-status {
    font-style: italic;
    color: var(--oo-color-text-secondary, #888);
}

/* ── Eingabe ── */

.ki-chat-eingabe {
    border-top: 1px solid var(--oo-color-border, #e0e0e0);
    padding: 0.75rem 1.5rem;
    background: var(--oo-color-background, #fff);
    position: relative;
    flex-shrink: 0;
}

/* AutoGrow Textarea */
.AutoGrowTextarea {
    flex: 1;
    min-width: 0;
    display: grid;
}

.AutoGrowTextarea::after {
    content: attr(data-replicated-value) " ";
    white-space: pre-wrap;
    visibility: hidden;
    font-family: inherit;
    line-height: 1.5;
    padding: 0.45rem 0.75rem;
    border: 1px solid transparent;
    grid-area: 1 / 1 / 2 / 2;
}

.AutoGrowTextarea textarea {
    grid-area: 1 / 1 / 2 / 2;
    overflow: hidden;
    width: 100%;
    resize: none;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--oo-color-border, #ccc);
    border-radius: 8px;
    font-family: inherit;
    line-height: 1.5;
    min-height: 2rem;
    max-height: 10rem;
    overflow-y: auto;
    box-sizing: border-box;
}

.AutoGrowTextarea textarea:focus {
    outline: none;
    border-color: var(--oo-color-primary, #1976d2);
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.15);
}

/* ── Responsive ── */

@media (max-width: 768px) {
    .ki-chat-sidebar {
        display: none;
    }

    .ki-chat-nachricht {
        max-width: 95%;
    }
}


/* =============================================================================
   StreamingPanel – SidePanel-Integration
   ============================================================================= */

/* ── Globales rechtes SidePanel (SectionOutlet: SidePanel) ── */

:root {
    --oo-sidepanel-width: 35rem;
}

.layout-sidepanel-host {
    position: fixed;
    top: var(--oo-wdb-header-height);
    right: 0;
    width: var(--oo-sidepanel-width);
    height: calc(100vh - var(--oo-wdb-header-height));
    z-index: 1200;
    pointer-events: none;
}

.layout-sidepanel-host > * {
    pointer-events: auto;
}

/* Mobile: Panel als Full-Screen-Overlay */
@media (max-width: 1024px) {
    .layout-sidepanel-host {
        width: 100vw;
        top: 3.5rem;
        height: calc(100vh - 3.5rem);
    }
}


/* IstInContent: Body weicht rechts aus, Panel bleibt fixed daneben */
body:has(.SidePanel-ai-chat.IstInContent) .oo-wdb-body {
    margin-right: var(--oo-sidepanel-width);
}

/* IstUeberContent: Panel breiter, Body weicht aus, rechte Seiten-Sidebar verstecken */
body:has(.SidePanel-ai-chat.IstUeberContent) .layout-sidepanel-host {
    width: 50vw;
}

body:has(.SidePanel-ai-chat.IstUeberContent) .oo-wdb-body {
    margin-right: 50vw;
}

body:has(.SidePanel-ai-chat.IstUeberContent) .artikel-details-sidebar {
    display: none;
}

/* Panel-Wrapper: volle Höhe & Breite des Hosts */
.zusammenfassung--wrapper.SidePanel-ai-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.SidePanel-ai-chat .zusammenfassung--infobox {
    display: flex;
    flex-direction: column;
    height: 100%;
    border-left: 1px solid #e0e0e0;
    background: #fff;
    overflow: hidden;
}

.SidePanel-ai-chat.IstUeberContent .zusammenfassung--infobox {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.SidePanel-ai-chat .zusammenfassung--infobox-header {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #e0e0e0;
    background: var(--oo-primary);
    gap: 0.5rem;
    flex-shrink: 0;
}

.SidePanel-ai-chat .zusammenfassung--infobox-header .h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

.SidePanel-ai-chat .zusammenfassung--infobox-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.SidePanel-ai-chat .StreamingPanel--history {
    display: flex;
    flex-direction: column;
    height: 100%;
    border-right: 1px solid #e0e0e0;
    background: #f5f5f5;
}

.SidePanel-ai-chat .StreamingPanel--history-content {
    flex: 1;
    overflow-y: auto;
}
.SidePanel-ai-chat.IstInContent .ki-chat-nachrichten {
    padding: 0.5rem;
}

.SidePanel-ai-chat.IstInContent .ki-chat-nachricht {
  padding: 0.1rem 0.35rem;
}

/* Mobile: margin-right zurücksetzen */
@media (max-width: 1024px) {
    body:has(.SidePanel-ai-chat.IstInContent) .oo-wdb-body,
    body:has(.SidePanel-ai-chat.IstUeberContent) .oo-wdb-body {
        margin-right: 0;
    }
}
