:root {
    --bg: #f7f7f8;
    --surface: #ffffff;
    --surface-alt: #f0f0f2;
    --border: #e3e3e8;
    --text: #1f2023;
    --text-muted: #6b6f76;
    --accent: #c0140c;
    --accent-hover: #a01109;
    --user-bubble: #c0140c;
    --user-text: #ffffff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --radius: 14px;
    --max-width: 820px;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    line-height: 1.55;
    background: transparent;
}

/* ---------------------------------------------------------------
   Demo-Seite (Hintergrund + Hinweis auf das Widget)
   --------------------------------------------------------------- */
.demo {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    text-align: center;
    background:
        radial-gradient(1200px 600px at 100% 100%, rgba(192, 20, 12, 0.10), transparent 60%),
        radial-gradient(900px 500px at 0% 0%, rgba(192, 20, 12, 0.06), transparent 55%),
        #f7f7f8;
}

.demo__inner {
    max-width: 640px;
}

.demo__badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    margin-bottom: 20px;
}

.demo__title {
    font-size: clamp(28px, 5vw, 44px);
    line-height: 1.15;
    margin: 0 0 16px;
    color: #1f2023;
}

.demo__text {
    font-size: clamp(16px, 2.4vw, 19px);
    color: #55585f;
    margin: 0 0 28px;
}

.demo__cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--accent);
    margin: 0;
}

/* Animierter Pfeil, der auf das Widget unten rechts zeigt */
.demo__pointer {
    position: fixed;
    right: 50px;
    bottom: 65px;
    z-index: 2147482000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--accent);
    animation: pointer-bounce 1.4s ease-in-out infinite;
    transition: opacity .2s ease, visibility .2s ease;
    pointer-events: none;
}

.demo__pointer-text {
    font-weight: 700;
    font-size: 14px;
    background: #fff;
    padding: 4px 10px;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}

.demo__pointer-arrow {
    transform: rotate(30deg);
    margin-top: 10px;
}

@keyframes pointer-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(8px); }
}

/* Hinweis ausblenden, sobald der Chat geöffnet ist */
body.chat-open .demo__pointer {
    opacity: 0;
    visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .demo__pointer { animation: none; }
}

/* ---------------------------------------------------------------
   Widget (unten rechts, aufklappbar)
   --------------------------------------------------------------- */
.chat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2147483000;
}

.chat-launcher {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    display: grid;
    place-items: center;
    transition: transform .15s ease, background .15s ease;
}

.chat-launcher:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.chat-launcher__icon {
    grid-area: 1 / 1;
    transition: opacity .15s ease, transform .15s ease;
}

.chat-launcher__icon--open {
    width: 34px;
    height: 34px;
    object-fit: contain;
    border-radius: 8px;
}

/* Icon-Wechsel je nach Zustand */
.chat-launcher__icon--close { opacity: 0; transform: rotate(-90deg); }
.chat-widget.open .chat-launcher__icon--open { opacity: 0; transform: rotate(90deg); }
.chat-widget.open .chat-launcher__icon--close { opacity: 1; transform: rotate(0); }

/* Panel */
.chat-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 380px;
    height: min(600px, calc(100dvh - 120px));
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
    transform-origin: bottom right;
    opacity: 0;
    transform: translateY(12px) scale(.98);
    pointer-events: none;
    visibility: hidden;
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
}

.chat-widget.open .chat-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
}

/* Header */
.app__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
}

.app__brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app__logo {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    overflow: hidden;
}

.app__logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.app__title {
    font-size: 16px;
    margin: 0;
    font-weight: 600;
}

.app__subtitle {
    font-size: 12px;
    margin: 0;
    color: var(--text-muted);
}

.app__actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Buttons */
.btn {
    font: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 8px 12px;
    transition: background .15s ease, border-color .15s ease, opacity .15s ease;
    color: var(--text);
}

.btn--ghost {
    background: transparent;
    border-color: var(--border);
    font-size: 13px;
}

.btn--ghost:hover {
    background: var(--surface-alt);
}

.btn--icon {
    background: transparent;
    padding: 6px;
    line-height: 1;
    display: grid;
    place-items: center;
    color: var(--text-muted);
}

.btn--icon:hover {
    background: var(--surface-alt);
    color: var(--text);
}

.btn--send {
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    flex: 0 0 auto;
}

.btn--send:hover {
    background: var(--accent-hover);
}

.btn--send:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
}

.msg {
    display: flex;
    gap: 12px;
    max-width: 100%;
    animation: fade-in .2s ease;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.msg__avatar {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
}

.msg--user {
    flex-direction: row-reverse;
}

.msg--user .msg__avatar {
    background: var(--user-bubble);
}

.msg--bot .msg__avatar {
    background: var(--accent);
}

.msg__body {
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    max-width: min(80%, 640px);
    overflow-wrap: anywhere;
}

.msg--user .msg__body {
    background: var(--user-bubble);
    color: var(--user-text);
    border-color: transparent;
}

.msg__body p { margin: 0 0 .6em; }
.msg__body p:last-child { margin-bottom: 0; }
.msg__body ul, .msg__body ol { margin: .3em 0 .6em; padding-left: 1.3em; }
.msg__body a { color: var(--accent); }
.msg--user .msg__body a { color: #fff; text-decoration: underline; }
.msg__body pre {
    background: var(--surface-alt);
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
}
.msg__body code {
    background: var(--surface-alt);
    padding: .1em .35em;
    border-radius: 5px;
    font-size: .9em;
}
.msg__body pre code { background: none; padding: 0; }

/* Quellen */
.sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}

.sources__title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    margin: 0 0 6px;
}

.sources__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sources__item a,
.sources__item span {
    display: inline-block;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-alt);
    color: var(--text);
    text-decoration: none;
    border: 1px solid var(--border);
}

.sources__item a:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Typing-Indikator */
.typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: blink 1.2s infinite ease-in-out both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
    0%, 80%, 100% { opacity: .25; transform: scale(.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Empty state */
.empty {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    max-width: 420px;
    padding: 24px;
}
.empty h2 {
    color: var(--text);
    font-size: 20px;
    margin: 0 0 8px;
}

/* Composer */
.composer {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.composer__form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 8px 8px 8px 14px;
}

.composer__form:focus-within {
    border-color: var(--accent);
}

.composer__input {
    flex: 1;
    resize: none;
    border: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    max-height: 160px;
    outline: none;
    padding: 6px 0;
}

.error-text {
    color: #d64545;
}

@media (max-width: 600px) {
    .msg__body { max-width: 88%; }
}

/* Auf kleinen Bildschirmen füllt das Panel nahezu den ganzen Viewport */
@media (max-width: 480px) {
    .chat-widget {
        right: 16px;
        bottom: 16px;
    }

    .chat-panel {
        position: fixed;
        right: 12px;
        left: 12px;
        bottom: 84px;
        width: auto;
        height: min(70dvh, calc(100dvh - 100px));
    }
}
