:root,
:host,
.embed-mode {
    --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;
    --launcher-size: 80px;
}

* {
    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;
}

.demo__embed {
    margin-top: 28px;
    text-align: left;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: var(--shadow);
}

.demo__embed summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}

.demo__embed-note {
    margin: 10px 0 0;
    font-size: 14px;
    color: var(--text-muted);
}

.demo__embed-code {
    margin: 12px 0 0;
    padding: 12px;
    border-radius: 8px;
    background: #1f2023;
    color: #f3f3f5;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}

.demo__embed-code code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre;
}

/* Animierter Pfeil, der auf das Widget unten rechts zeigt */
.demo__pointer {
    position: fixed;
    right: calc(var(--widget-offset-right, 20px) + 34px);
    bottom: calc(var(--widget-offset-bottom, 20px) + var(--launcher-size, 80px) + 8px);
    z-index: 2147482000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--accent, #c0140c);
    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,
:host(.chat-open) .demo__pointer,
.chat-open .demo__pointer {
    opacity: 0;
    visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .demo__pointer { animation: none; }
}

/* ---------------------------------------------------------------
   Embed-Modus (Shadow DOM auf fremden Webseiten)
   --------------------------------------------------------------- */
.hauptmann-widget-host {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 2147483647;
}

.embed-mode {
    --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;
    --launcher-size: 80px;
    --widget-offset-right: 20px;
    --widget-offset-bottom: 20px;
    background: transparent;
    overflow: visible;
    height: auto;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    line-height: 1.55;
}

body.embed-mode {
    background: transparent;
    overflow: visible;
    height: auto;
    margin: 0;
}

.embed-mode .chat-widget,
body.embed-mode .chat-widget {
    position: fixed;
    right: var(--widget-offset-right, 20px);
    bottom: var(--widget-offset-bottom, 20px);
    pointer-events: auto;
    z-index: 2147483647;
}

.embed-mode .chat-panel,
body.embed-mode .chat-panel {
    position: absolute;
    right: 0;
    bottom: calc(var(--launcher-size) + 16px);
    top: auto;
}

@media (max-width: 480px) {
    .embed-mode .chat-widget,
    body.embed-mode .chat-widget {
        right: max(16px, var(--widget-offset-right, 20px));
        bottom: max(16px, var(--widget-offset-bottom, 20px));
    }
}

/* ---------------------------------------------------------------
   Widget (unten rechts, aufklappbar)
   --------------------------------------------------------------- */
.chat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2147483000;
}

.chat-launcher {
    position: absolute;
    right: 0;
    bottom: 0;
    width: var(--launcher-size);
    height: var(--launcher-size);
    padding: 0;
    border: none;
    border-radius: 0;
    cursor: pointer;
    background: transparent;
    box-shadow: none;
    color: var(--accent);
    transition: transform .15s ease, width .15s ease, height .15s ease, border-radius .15s ease, background .15s ease, box-shadow .15s ease;
}

.chat-launcher:hover {
    transform: translateY(-2px);
}

.chat-launcher__icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transition: opacity .15s ease, transform .15s ease;
}

.chat-launcher__icon--open {
    width: var(--launcher-size);
    height: auto;
    max-width: var(--launcher-size);
    max-height: var(--launcher-size);
    object-fit: contain;
    transform: translate(-50%, -50%);
}

/* Schließen-Button, wenn Widget geöffnet */
.chat-widget.open .chat-launcher {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.chat-widget.open .chat-launcher:hover {
    background: var(--accent-hover);
}

/* Icon-Wechsel je nach Zustand */
.chat-launcher__icon--close {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(-90deg);
}

.chat-widget.open .chat-launcher__icon--open {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(90deg);
    pointer-events: none;
}

.chat-widget.open .chat-launcher__icon--close {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0);
}

/* Panel */
.chat-panel {
    position: absolute;
    right: 0;
    bottom: calc(var(--launcher-size) + 16px);
    width: 45vw;
    height: 70dvh;
    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-panel[hidden] {
    display: none !important;
}

.chat-widget.open .chat-panel {
    display: flex !important;
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
}

@media (max-width: 800px) {
    .chat-panel {
        width: calc(100vw - (var(--widget-offset-right, 20px) * 2));
        max-width: none;
    }
}

/* 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: 14px;
    margin: 0;
    font-weight: 600;
    line-height: 1.25;
}

.app__brand > div {
    min-width: 0;
}

.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;
}

/* Ergebnis-Karten */
.cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.card {
    display: flex;
    flex-direction: column;
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: var(--text);
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

a.card:hover {
    border-color: var(--accent);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .10);
    transform: translateY(-2px);
}

.card__media {
    width: 100%;
    aspect-ratio: 16 / 10;
    background: var(--surface-alt);
    overflow: hidden;
}

.card__media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card__body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
}

.card__badge {
    align-self: flex-start;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--accent);
    background: rgba(192, 20, 12, .08);
    padding: 2px 8px;
    border-radius: 999px;
}

.card__title {
    margin: 0;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.3;
}

.card__desc {
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card__more {
    margin-top: 2px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
}

@media (max-width: 420px) {
    .cards { grid-template-columns: 1fr; }
}

/* 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%; }
}

@media (max-width: 480px) {
    .chat-widget {
        right: 16px;
        bottom: 16px;
    }
}
