:root {
    --chat-bg: #09090b;
    --chat-card: #18181b;
    --chat-border: #27272a;
    --chat-primary: #2563eb;
    --chat-text: #f4f4f5;
    --chat-muted: #a1a1aa;
}

/* Floating Widget Alignment (Unten Rechts) */
.chat-card {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    height: 660px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 48px);
    background: var(--chat-card);
    border: 1px solid var(--chat-border);
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    z-index: 999999;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    transform-origin: bottom right;
}

/* Versteckter Zustand mit Animation */
.chat-card.chat-widget-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.95) translateY(20px);
}

.chat-header {
    padding: 18px 18px 18px 20px;
    background: #121215;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--chat-text);
    line-height: 1.4;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 8px #22c55e;
    flex-shrink: 0;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-clear-btn,
.chat-close-btn {
    background: transparent;
    border: none;
    color: var(--chat-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}

.chat-clear-btn {
    font-size: 15px;
}

.chat-close-btn {
    font-size: 20px;
}

.chat-clear-btn:hover,
.chat-close-btn:hover {
    color: var(--chat-text);
    background: rgba(255, 255, 255, 0.06);
}

.chat-messages {
    flex: 1;
    padding: 20px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 14.5px;
    line-height: 1.6;
    word-wrap: break-word;
}

.msg.bot {
    background: #27272a;
    color: var(--chat-text);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    max-width: 95%;
}

.msg.bot p {
    margin: 0 0 8px;
}

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

.msg.bot h1,
.msg.bot h2,
.msg.bot h3,
.msg.bot h4,
.msg.bot h5,
.msg.bot h6 {
    margin: 12px 0 6px;
    line-height: 1.3;
}

.msg.bot h1:first-child,
.msg.bot h2:first-child,
.msg.bot h3:first-child {
    margin-top: 0;
}

/* Defensiv gegen Theme-Regeln, die auf beliebige li/ul im Seitenkopf zielen
   (u. a. `.navbar-custom .topbar-menu li { max-height: ... }`). */
.msg.bot ul,
.msg.bot ol {
    margin: 0 0 12px;
    padding-left: 22px;
    max-height: none;
    overflow: visible;
}

.msg.bot ul {
    list-style: disc outside;
}

.msg.bot ol {
    list-style: decimal outside;
}

.msg.bot ul ul {
    list-style: circle outside;
}

.msg.bot ul:last-child,
.msg.bot ol:last-child {
    margin-bottom: 0;
}

.msg.bot li {
    display: list-item;
    float: none;
    max-height: none;
    min-height: 0;
    height: auto;
    overflow: visible;
    line-height: 1.6;
    margin: 0 0 6px;
}

.msg.bot li:last-child {
    margin-bottom: 0;
}

.msg.bot li > p {
    margin: 0;
}

.msg.bot a {
    color: var(--chat-primary);
    text-decoration: underline;
}

.msg.bot code {
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 13px;
    font-family: 'SFMono-Regular', Consolas, monospace;
}

.msg.bot pre {
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    margin: 0 0 8px;
}

.msg.bot pre code {
    background: none;
    border: none;
    padding: 0;
}

.msg.bot table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 0 0 8px;
    font-size: 13px;
}

.msg.bot th,
.msg.bot td {
    border: 1px solid var(--chat-border);
    padding: 6px 8px;
    text-align: left;
    white-space: nowrap;
}

.msg.bot thead {
    display: table-header-group;
}

.msg.bot tbody {
    display: table-row-group;
}

.msg.bot tr {
    display: table-row;
}

.msg.bot th {
    background: #121215;
    font-weight: 600;
}

.msg.user {
    background: var(--chat-primary);
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.chat-input {
    position: relative;
    padding: 14px;
    background: #121215;
    border-top: 1px solid var(--chat-border);
    display: flex;
    align-items: flex-end;
    gap: 10px;
    box-sizing: border-box;
}

/* Während einer laufenden Aufnahme werden die normalen Eingabe-Elemente
   ausgeblendet und die Aufnahme-Leiste nimmt ihren Platz ein. */
.chat-input.is-recording > .chat-file-label,
.chat-input.is-recording > .chat-mic-btn,
.chat-input.is-recording > textarea,
.chat-input.is-recording > #chat-send-btn {
    display: none;
}

.chat-input textarea {
    flex: 1 1 auto;
    min-width: 0;
    background: #09090b;
    border: 1px solid var(--chat-border);
    color: var(--chat-text);
    padding: 10px 14px;
    border-radius: 8px;
    outline: none;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
    max-height: 120px;
    box-sizing: border-box;
}

.chat-input textarea:focus {
    border-color: var(--chat-primary);
}

.chat-input button {
    flex-shrink: 0;
    background: var(--chat-primary);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: opacity 0.2s;
    box-sizing: border-box;
}

.chat-input button:hover {
    opacity: 0.9;
}

.chat-file-label,
.chat-mic-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: #09090b;
    border: 1px solid var(--chat-border);
    color: var(--chat-muted);
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    box-sizing: border-box;
    transition: color 0.2s, border-color 0.2s;
}

.chat-file-label:hover,
.chat-mic-btn:hover {
    color: var(--chat-text);
    border-color: var(--chat-primary);
}

.chat-mic-btn.recording {
    color: #ffffff;
    background: #dc2626;
    border-color: #dc2626;
    animation: chat-mic-pulse 1.4s ease-in-out infinite;
}

@keyframes chat-mic-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(220, 38, 38, 0);
    }
}

/* --- Vorgemerkter Anhang (PDF/Bild/Datei) vor dem Senden --- */
.chat-attachment-preview {
    padding: 0 14px 10px;
    background: #121215;
    box-sizing: border-box;
}

.chat-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    background: #1f1f23;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    padding: 6px 8px 6px 10px;
    color: var(--chat-text);
    font-size: 13px;
}

.chat-attachment-icon {
    color: var(--chat-primary);
    font-size: 16px;
    flex-shrink: 0;
}

.chat-attachment-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.chat-attachment-remove {
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: var(--chat-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 0 0 2px;
}

.chat-attachment-remove:hover {
    color: var(--chat-text);
}

/* --- Sprachaufnahme-Leiste (ersetzt die Eingabe, solange aufgenommen wird) --- */
.chat-recording-bar {
    position: absolute;
    inset: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #1f1f23;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    padding: 0 8px 0 14px;
    box-sizing: border-box;
}

.chat-recording-dot {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #dc2626;
    animation: chat-mic-pulse 1.4s ease-in-out infinite;
}

.chat-recording-text {
    flex: 1 1 auto;
    color: var(--chat-text);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-recording-cancel {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid var(--chat-border);
    color: var(--chat-muted);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.chat-recording-cancel:hover {
    color: var(--chat-text);
    border-color: var(--chat-primary);
}

.chat-recording-stop {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: #dc2626;
    border: none;
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
}

.chat-recording-stop:hover {
    opacity: 0.9;
}
