/* ===========================================
   UDM KI-Assistent Styles
   =========================================== */

/* Floating Bubble */
.udm-ai-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--bs-primary, #0d6efd), #0056b3);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    z-index: 9999;
    border: none;
}

.udm-ai-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.udm-ai-bubble.active {
    background: linear-gradient(135deg, var(--bs-danger, #dc3545), #a71d2a);
}

.udm-ai-bubble span {
    font-size: 1.5em;
}

/* Chat Panel */
.udm-ai-panel {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: 9998;
    overflow: hidden;
}

/* Panel Header */
.udm-ai-panel-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--bs-primary, #0d6efd), #0056b3);
    color: white;
    font-weight: bold;
    flex-shrink: 0;
}

.udm-ai-panel-header .btn-link {
    color: white;
    padding: 4px 8px;
    text-decoration: none;
}

.udm-ai-panel-header .btn-link:hover {
    opacity: 0.8;
}

/* Status Banner */
.udm-ai-status-banner {
    padding: 8px 16px;
    background: var(--bs-warning-bg-subtle, #fff3cd);
    color: var(--bs-warning-text-emphasis, #664d03);
    font-size: 0.85em;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
    flex-shrink: 0;
}

/* Session Header - Konversationsauswahl */
.udm-ai-session-header {
    padding: 10px 16px;
    background: var(--bs-body-bg, #fff);
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
    flex-shrink: 0;
}

.udm-ai-session-header .dxbl-combobox {
    min-width: 200px;
}

.udm-ai-session-header .btn-sm {
    padding: 6px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Messages Container */
.udm-ai-panel-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--bs-tertiary-bg);
    display: flex;
    flex-direction: column;
}

/* Sticky Dialoge am unteren Rand des Scroll-Bereichs */
.udm-ai-sticky-dialogs {
    position: sticky;
    bottom: -16px;
    margin-top: auto;
    margin-left: -16px;
    margin-right: -16px;
    z-index: 10;
    max-height: 60%;
    display: flex;
    flex-direction: column;
}

/* Welcome Message */
.udm-ai-welcome {
    text-align: center;
    padding: 32px 16px;
    color: var(--bs-secondary, #6c757d);
}

.udm-ai-welcome-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--bs-primary, #0d6efd), #0056b3);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 1.75em;
}

.udm-ai-welcome h5 {
    color: var(--bs-body-color, #212529);
    margin-bottom: 8px;
}

.udm-ai-welcome p {
    margin-bottom: 8px;
}

/* Chat Messages */
.udm-ai-message {
    display: flex;
    margin-bottom: 16px;
    animation: udm-ai-fadeInUp 0.3s ease;
}

@keyframes udm-ai-fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.udm-ai-message.user {
    flex-direction: row-reverse;
}

.udm-ai-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bs-secondary, #6c757d);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.875em;
}

.udm-ai-message.user .udm-ai-message-avatar {
    background: var(--bs-primary, #0d6efd);
}

.udm-ai-message.assistant .udm-ai-message-avatar {
    background: var(--bs-success, #198754);
}

.udm-ai-message-content {
    max-width: 75%;
    margin: 0 10px;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9em;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    word-wrap: break-word;
}

.udm-ai-message.user .udm-ai-message-content {
    background: var(--bs-primary, #0d6efd);
    color: white;
}

.udm-ai-message-text {
    line-height: 1.3;
    font-size: 0.9em;
}

/* ===========================================
   Markdown-Rendering (Markdig)
   =========================================== */

/* Tabellen */
.udm-ai-message-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5em 0;
    font-size: 0.9em;
}

.udm-ai-message-text th,
.udm-ai-message-text td {
    border: 1px solid var(--bs-border-color, #dee2e6);
    padding: 0.35em 0.6em;
    text-align: left;
}

.udm-ai-message-text th {
    background: var(--bs-tertiary-bg, #f8f9fa);
    font-weight: 600;
    white-space: nowrap;
}

.udm-ai-message-text tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

/* Listen */
.udm-ai-message-text ul,
.udm-ai-message-text ol {
    margin: 0.3em 0;
    padding-left: 1.5em;
}

.udm-ai-message-text li {
    margin-bottom: 0.15em;
}

/* Ueberschriften */
.udm-ai-message-text h1,
.udm-ai-message-text h2,
.udm-ai-message-text h3,
.udm-ai-message-text h4 {
    margin: 0.6em 0 0.3em 0;
    line-height: 1.3;
}

.udm-ai-message-text h1 { font-size: 1.3em; }
.udm-ai-message-text h2 { font-size: 1.15em; }
.udm-ai-message-text h3 { font-size: 1.05em; }
.udm-ai-message-text h4 { font-size: 1em; }

/* Inline-Code */
.udm-ai-message-text code {
    background: var(--bs-dark-bg-subtle, #e9ecef);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

/* Code-Bloecke */
.udm-ai-message-text pre {
    background: var(--bs-dark-bg-subtle, #e9ecef);
    padding: 0.6em 0.8em;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.udm-ai-message-text pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
}

/* Blockquotes */
.udm-ai-message-text blockquote {
    border-left: 3px solid var(--bs-primary, #0d6efd);
    margin: 0.5em 0;
    padding: 0.3em 0.8em;
    color: var(--bs-secondary, #6c757d);
}

/* Horizontale Linie */
.udm-ai-message-text hr {
    border: none;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    margin: 0.6em 0;
}

/* Absaetze — kompakter im Chat */
.udm-ai-message-text p {
    margin: 0.3em 0;
}

.udm-ai-message-time {
    font-size: 0.75em;
    color: var(--bs-secondary, #6c757d);
    margin-top: 4px;
}

.udm-ai-message.user .udm-ai-message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* Code Block */
.udm-ai-code-block {
    margin-top: 10px;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 8px;
    overflow: hidden;
}

.udm-ai-code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bs-dark, #212529);
    color: white;
    font-size: 0.8em;
}

.udm-ai-code-block pre {
    margin: 0;
    padding: 12px;
    background: var(--bs-dark-bg-subtle);
    color: var(--bs-body-color);
    font-size: 0.85em;
    overflow-x: auto;
    max-height: 200px;
}

.udm-ai-code-block code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* Code Preview (Execution Confirmation) */
.udm-ai-code-preview {
    border-top: 2px solid var(--bs-warning, #ffc107);
    padding: 12px;
    background: rgba(255, 193, 7, 0.1);
    flex-shrink: 0;
}

.udm-ai-code-preview-header {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.udm-ai-code-preview-info {
    margin-bottom: 8px;
}

.udm-ai-code-preview-code {
    margin: 10px 0;
    max-height: 150px;
    overflow-y: auto;
}

.udm-ai-code-preview-code pre {
    margin: 0;
    padding: 10px;
    background: var(--bs-dark-bg-subtle);
    color: var(--bs-body-color);
    border-radius: 6px;
    font-size: 0.8em;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.udm-ai-code-preview-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 10px;
}

.udm-ai-code-preview-warning {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
}

/* Input Area */
.udm-ai-panel-input {
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    background: var(--bs-body-bg, #fff);
    flex-shrink: 0;
    gap: 6px;
}

.udm-ai-input-row {
    display: flex;
    align-items: center;
}

.udm-ai-input-row input {
    flex: 1;
}

.udm-ai-input-row .btn {
    padding: 8px 16px;
}

.udm-ai-options-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.udm-ai-options-row .btn-sm {
    font-size: 0.75em;
    padding: 3px 8px;
}

/* Responsive */
@media (max-width: 480px) {
    .udm-ai-panel {
        width: calc(100vw - 40px);
        right: 20px;
        left: 20px;
        height: calc(100vh - 160px);
    }

    .udm-ai-message-content {
        max-width: 85%;
    }
}

/* Dark Mode wird automatisch durch Bootstrap CSS-Variablen unterstuetzt */

/* Scrollbar Styling */
.udm-ai-panel-messages::-webkit-scrollbar {
    width: 6px;
}

.udm-ai-panel-messages::-webkit-scrollbar-track {
    background: transparent;
}

.udm-ai-panel-messages::-webkit-scrollbar-thumb {
    background: var(--bs-secondary, #6c757d);
    border-radius: 3px;
}

.udm-ai-panel-messages::-webkit-scrollbar-thumb:hover {
    background: var(--bs-primary, #0d6efd);
}

/* ===========================================
   Streaming Styles
   =========================================== */

/* Streaming Message */
.udm-ai-message.streaming .udm-ai-message-content {
    background: linear-gradient(90deg, var(--bs-body-bg), var(--bs-tertiary-bg));
}

/* Blinking Cursor */
.udm-ai-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--bs-primary, #0d6efd);
    margin-left: 2px;
    animation: udm-ai-blink 1s infinite;
    vertical-align: text-bottom;
}

@keyframes udm-ai-blink {
    0%, 50% {
        opacity: 1;
    }
    51%, 100% {
        opacity: 0;
    }
}

/* Streaming Toggle */
.udm-ai-streaming-toggle {
    color: var(--bs-secondary, #6c757d);
}

.udm-ai-streaming-toggle .form-check-input {
    margin-right: 0.5rem;
}

/* ===========================================
   Clarification Dialog
   =========================================== */

.udm-ai-clarification-dialog {
    border-top: 2px solid var(--bs-info);
    padding: 16px;
    background: var(--bs-info-bg-subtle);
    flex-shrink: 1;
    min-height: 0;
    overflow-y: auto;
    animation: udm-ai-slideUp 0.3s ease;
}

@keyframes udm-ai-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.udm-ai-clarification-header {
    font-weight: 600;
    color: var(--bs-info, #0dcaf0);
    margin-bottom: 12px;
    font-size: 0.9em;
}

.udm-ai-clarification-content {
    margin-bottom: 12px;
}

.udm-ai-clarification-context {
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    margin-bottom: 10px;
}

.udm-ai-clarification-question {
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--bs-body-color, #212529);
}

.udm-ai-clarification-hint {
    margin-top: 4px;
    margin-bottom: 12px;
}

.udm-ai-clarification-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.udm-ai-option-btn {
    transition: all 0.2s ease;
}

.udm-ai-option-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.udm-ai-clarification-input .input-group {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    overflow: hidden;
}

.udm-ai-clarification-footer {
    text-align: right;
}

/* ===========================================
   Confirmation Dialog
   =========================================== */

.udm-ai-confirmation-dialog {
    border-top: 2px solid var(--bs-success);
    padding: 16px;
    background: var(--bs-success-bg-subtle);
    flex-shrink: 1;
    min-height: 0;
    overflow-y: auto;
    animation: udm-ai-slideUp 0.3s ease;
}

.udm-ai-confirmation-header {
    font-weight: 600;
    color: var(--bs-success, #198754);
    margin-bottom: 12px;
    font-size: 0.9em;
}

.udm-ai-confirmation-summary {
    font-size: 1em;
    margin-bottom: 8px;
}

.udm-ai-confirmation-description {
    font-size: 0.9em;
    margin-bottom: 12px;
}

.udm-ai-confirmation-changes {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.udm-ai-change-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
}

.udm-ai-change-icon {
    font-weight: bold;
    font-family: monospace;
    width: 20px;
    text-align: center;
}

.udm-ai-change-type {
    font-weight: 500;
}

.udm-ai-change-name {
    font-family: 'Consolas', 'Monaco', monospace;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
}

.udm-ai-confirmation-warnings {
    margin-bottom: 12px;
}

.udm-ai-confirmation-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ===========================================
   Tool Call Preview
   =========================================== */

.udm-ai-tool-call-preview {
    border-top: 2px solid var(--bs-purple);
    padding: 16px;
    background: var(--bs-body-bg);
    flex-shrink: 1;
    min-height: 0;
    overflow-y: auto;
    animation: udm-ai-slideUp 0.3s ease;
}

.udm-ai-tool-call-header {
    font-weight: 600;
    color: var(--bs-purple, #6f42c1);
    margin-bottom: 12px;
    font-size: 0.9em;
}

.udm-ai-tool-call-content {
    margin-bottom: 12px;
}

.udm-ai-tool-call-content pre {
    margin: 0;
    padding: 12px;
    background: var(--bs-dark-bg-subtle);
    color: var(--bs-body-color);
    border-radius: 6px;
    font-size: 0.8em;
    max-height: 200px;
    overflow: auto;
}

.udm-ai-tool-call-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ===========================================
   Additional Message Styles
   =========================================== */

/* Message with Tool Calls indicator */
.udm-ai-message .udm-ai-tool-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--bs-purple, #6f42c1);
    color: white;
    border-radius: 12px;
    font-size: 0.75em;
    margin-top: 8px;
}

/* Message loading state */
.udm-ai-message.loading .udm-ai-message-content {
    min-height: 40px;
    display: flex;
    align-items: center;
}

/* Error message style */
.udm-ai-message.error .udm-ai-message-content {
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid rgba(220, 53, 69, 0.3);
}

/* Success message style */
.udm-ai-message.success .udm-ai-message-content {
    background: rgba(25, 135, 84, 0.1);
    border: 1px solid rgba(25, 135, 84, 0.3);
}

/* ===========================================
   Stop Button for Streaming
   =========================================== */

.udm-ai-panel-input .btn-outline-danger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    flex-shrink: 0;
}

/* ===========================================
   Knowledge Mode Badge
   =========================================== */

.udm-ai-mode-badge {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    font-size: 0.75em;
    border-radius: 4px;
    flex-shrink: 0;
    white-space: nowrap;
    margin-left: auto;
    cursor: default;
}

.udm-ai-mode-badge.vector {
    background: var(--bs-success-bg-subtle, #d1e7dd);
    color: var(--bs-success-text-emphasis, #0a3622);
}

.udm-ai-mode-badge.text {
    background: var(--bs-warning-bg-subtle, #fff3cd);
    color: var(--bs-warning-text-emphasis, #664d03);
}

/* ===========================================
   Tab Layout
   =========================================== */

.udm-ai-tabs {
    display: flex;
    flex-direction: column;
}

.udm-ai-tabs > .dxbl-tabs-content {
    flex: 1;
    overflow: hidden;
}

.udm-ai-tabpage {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===========================================
   Zeitprotokoll (Timing Log)
   =========================================== */

.udm-ai-timing-log {
    flex: 1;
    overflow-y: auto;
    padding: 1em;
}

.udm-ai-timing-empty {
    text-align: center;
    padding: 2em 1em;
    color: var(--bs-secondary, #6c757d);
    font-size: 0.9em;
}

.udm-ai-timing-table {
    font-size: 0.85em;
}

.udm-ai-timing-table th {
    font-size: 0.85em;
    white-space: nowrap;
    background: var(--bs-tertiary-bg, #f8f9fa);
    position: sticky;
    top: 0;
    z-index: 1;
}

.udm-ai-timing-table td {
    vertical-align: middle;
}

.udm-ai-timing-slow td {
    color: var(--bs-danger-text-emphasis, #842029);
    background: var(--bs-danger-bg-subtle, #f8d7da);
}
