/* Website-Chat. Farben wie mechmeister.css und die Chat-Ansicht im App-Mockup:
   Nutzerblasen und Senden in Mechmeister-Blau, alles andere zurückhaltend. */
.mm-chat {
    --mm-chat-blue: #1d6bf3;
    --mm-chat-blue-hover: #1557c9;
    --mm-chat-blue-tint: #edf3fe;
    --mm-chat-ink: #0f172a;
    --mm-chat-text: #3e4859;
    --mm-chat-muted: #646e80;
    --mm-chat-faint: #8f99a8;
    --mm-chat-bubble: #f1f3f6;
    --mm-chat-field: #f2f4f7;
    --mm-chat-hairline: rgba(15, 23, 42, .08);
    --mm-chat-title-font: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mm-chat-ease: cubic-bezier(.2, .9, .25, 1);
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1050;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--mm-chat-ink);
    -webkit-font-smoothing: antialiased;
}
/* Grundwerte in :where(), damit jede Bausteinregel sie ohne !important überschreibt. */
.mm-chat :where(*, *::before, *::after) { box-sizing: border-box; }
.mm-chat [hidden], .mm-chat[hidden] { display: none !important; }
.mm-chat :where(p) { margin: 0; font-size: inherit; line-height: inherit; color: inherit; }
.mm-chat :where(button, textarea) { font: inherit; }
.mm-chat :where(button) { cursor: pointer; transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .15s ease; }
.mm-chat button:disabled { cursor: not-allowed; }
.mm-chat button:focus-visible, .mm-chat a:focus-visible, .mm-chat input:focus-visible { outline: 2px solid var(--mm-chat-blue); outline-offset: 2px; }
.mm-chat-messages:focus-visible { outline: 2px solid var(--mm-chat-blue); outline-offset: -2px; }

/* Startknopf */
.mm-chat-launcher {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    height: 52px;
    padding: 0 20px 0 9px;
    border: 0;
    border-radius: 26px;
    background: var(--mm-chat-ink);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1), 0 2px 4px rgba(15, 23, 42, .12), 0 14px 32px -10px rgba(15, 23, 42, .5);
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: -.01em;
    white-space: nowrap;
}
.mm-chat-launcher:hover { background: #1b2436; transform: translateY(-1px); }
.mm-chat-launcher:active { transform: scale(.97); }
.mm-chat-launcher-logo {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #fff;
}
.mm-chat-launcher-logo img { display: block; width: 22px; height: 22px; object-fit: contain; }
.mm-chat-launcher-close { display: none; }
.mm-chat-launcher[aria-expanded="true"] {
    width: 52px;
    padding: 0;
    justify-content: center;
    background: #fff;
    color: var(--mm-chat-ink);
    box-shadow: 0 0 0 1px var(--mm-chat-hairline), 0 2px 4px rgba(15, 23, 42, .06), 0 12px 28px -10px rgba(15, 23, 42, .3);
}
.mm-chat-launcher[aria-expanded="true"]:hover { background: #f6f7f9; }
.mm-chat-launcher[aria-expanded="true"] .mm-chat-launcher-logo,
.mm-chat-launcher[aria-expanded="true"] .mm-chat-launcher-text { display: none; }
.mm-chat-launcher[aria-expanded="true"] .mm-chat-launcher-close { display: block; }

/* Fenster */
.mm-chat-panel {
    position: absolute;
    right: 0;
    bottom: 68px;
    width: 384px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 116px);
    max-height: calc(100dvh - 116px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, .06), 0 2px 6px rgba(15, 23, 42, .04), 0 16px 40px -12px rgba(15, 23, 42, .2), 0 40px 80px -32px rgba(15, 23, 42, .24);
    transform-origin: 100% 100%;
    animation: mm-chat-in .26s var(--mm-chat-ease);
}
.mm-chat-panel:focus { outline: none; }
@keyframes mm-chat-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }

.mm-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 12px 12px 18px;
    flex-shrink: 0;
}
.mm-chat-avatar { display: block; width: 32px; height: 32px; object-fit: contain; flex-shrink: 0; }
.mm-chat-title { min-width: 0; flex: 1; }
.mm-chat-header h2 {
    margin: 0;
    color: var(--mm-chat-ink);
    font-family: var(--mm-chat-title-font);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -.01em;
}
.mm-chat-title a {
    display: inline-block;
    margin-top: 1px;
    color: var(--mm-chat-muted);
    font-size: 12.5px;
    line-height: 1.35;
    text-decoration: underline;
    text-decoration-color: rgba(100, 110, 128, .35);
    text-underline-offset: 3px;
    transition: color .15s ease, text-decoration-color .15s ease;
}
.mm-chat-title a:hover { color: var(--mm-chat-blue); text-decoration-color: currentColor; }
.mm-chat-header-actions { display: flex; gap: 2px; }
.mm-chat-icon-button {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--mm-chat-muted);
}
.mm-chat-icon-button:hover:not(:disabled) { background: var(--mm-chat-bubble); color: var(--mm-chat-ink); }
.mm-chat-icon-button:disabled { opacity: .4; }

/* Verlauf: unten verankert wie im Messenger. Die Schatten oben und unten
   erscheinen nur, wenn wirklich gescrollt werden kann. */
.mm-chat-content { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.mm-chat-messages {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px 16px 16px;
    scrollbar-width: thin;
    scrollbar-color: #d3d8df transparent;
    background:
        linear-gradient(#fff 40%, rgba(255, 255, 255, 0)) top / 100% 32px no-repeat local,
        linear-gradient(rgba(255, 255, 255, 0), #fff 60%) bottom / 100% 32px no-repeat local,
        linear-gradient(rgba(15, 23, 42, .07), rgba(15, 23, 42, 0)) top / 100% 8px no-repeat scroll,
        linear-gradient(rgba(15, 23, 42, 0), rgba(15, 23, 42, .07)) bottom / 100% 8px no-repeat scroll,
        #fff;
}
.mm-chat-messages > :first-child { margin-top: auto; }
.mm-chat-messages::-webkit-scrollbar { width: 6px; }
.mm-chat-messages::-webkit-scrollbar-thumb { background: #d3d8df; border-radius: 3px; }

.mm-chat-message {
    width: fit-content;
    max-width: 84%;
    margin: 0 0 4px;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    text-align: start;
    animation: mm-chat-rise .26s var(--mm-chat-ease) backwards;
}
@keyframes mm-chat-rise { from { opacity: 0; transform: translateY(6px); } }
.mm-chat-assistant { background: var(--mm-chat-bubble); color: var(--mm-chat-ink); border-bottom-left-radius: 6px; }
.mm-chat-assistant + .mm-chat-assistant { border-top-left-radius: 6px; }
.mm-chat-user { max-width: 80%; margin-left: auto; background: var(--mm-chat-blue); color: #fff; border-bottom-right-radius: 6px; }
.mm-chat-user + .mm-chat-assistant,
.mm-chat-assistant + .mm-chat-user,
.mm-chat-welcome + .mm-chat-user { margin-top: 10px; }

.mm-chat-welcome .mm-chat-message { white-space: normal; }
.mm-chat-welcome .mm-chat-message + .mm-chat-message { animation-delay: .1s; }

/* Kontaktknopf in einer Antwort */
.mm-chat-message a {
    display: flex;
    align-items: center;
    gap: 6px;
    width: fit-content;
    margin-top: 10px;
    padding: 7px 13px 7px 14px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .06);
    color: var(--mm-chat-blue);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    text-decoration: none;
    white-space: normal;
    transition: background-color .15s ease, color .15s ease;
}
.mm-chat-message a::after { content: '→'; font-weight: 500; transition: transform .15s ease; }
.mm-chat-message a:hover { background: var(--mm-chat-blue); color: #fff; }
.mm-chat-message a:hover::after { transform: translateX(2px); }

/* Antwortvorschläge: stehen dort, wo die eigene Nachricht erscheinen würde. */
.mm-chat-suggestions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    padding: 4px 16px 14px;
    flex-shrink: 0;
}
.mm-chat-suggestions button {
    max-width: 88%;
    padding: 8px 14px;
    border: 1px solid rgba(29, 107, 243, .3);
    border-radius: 18px;
    background: #fff;
    color: var(--mm-chat-blue);
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1.35;
    text-align: start;
    animation: mm-chat-rise .26s var(--mm-chat-ease) backwards;
}
.mm-chat-suggestions button:nth-child(2) { animation-delay: .05s; }
.mm-chat-suggestions button:nth-child(3) { animation-delay: .1s; }
.mm-chat-suggestions button:hover:not(:disabled) { background: var(--mm-chat-blue-tint); border-color: rgba(29, 107, 243, .55); color: var(--mm-chat-blue-hover); }
.mm-chat-suggestions button:active:not(:disabled) { transform: scale(.98); }
.mm-chat-suggestions button:disabled { opacity: .45; }

/* Eingabe */
.mm-chat-footer { flex-shrink: 0; padding: 4px 14px 12px; }

.mm-chat-consent {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin: 0 0 10px;
    padding: 0 4px;
    color: var(--mm-chat-text);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.45;
    cursor: pointer;
}
.mm-chat-consent input {
    -webkit-appearance: none;
    appearance: none;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin: 1px 0 0;
    border: 1.5px solid #8a94a4;
    border-radius: 5px;
    background: #fff center / 10px 10px no-repeat;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease;
}
.mm-chat-consent input:hover:not(:disabled) { border-color: var(--mm-chat-blue); }
.mm-chat-consent input:checked {
    border-color: var(--mm-chat-blue);
    background-color: var(--mm-chat-blue);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.6 6.3 5 8.6l4.4-5' fill='none' stroke='%23fff' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.mm-chat-consent input:disabled { opacity: .5; cursor: not-allowed; }
.mm-chat-consent a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: rgba(62, 72, 89, .35);
    text-underline-offset: 2px;
    white-space: nowrap;
    transition: color .15s ease;
}
.mm-chat-consent a:hover { color: var(--mm-chat-blue); text-decoration-color: currentColor; }
.mm-chat-consent-short { display: none; }

/* Nach der Zustimmung schrumpft der Hinweis auf eine Zeile. */
.mm-chat-consent:has(input:checked) { align-items: center; margin-bottom: 8px; color: var(--mm-chat-muted); font-size: 11.5px; }
.mm-chat-consent:has(input:checked) input { width: 14px; height: 14px; margin: 0; border-radius: 4px; background-size: 9px 9px; }
.mm-chat-consent:has(input:checked) a { text-decoration-color: rgba(100, 110, 128, .4); }
.mm-chat-consent:has(input:checked) .mm-chat-consent-long { display: none; }
.mm-chat-consent:has(input:checked) .mm-chat-consent-short { display: inline; }

.mm-chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 16px;
    border: 1px solid transparent;
    border-radius: 24px;
    background: var(--mm-chat-field);
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.mm-chat-composer:focus-within { border-color: rgba(29, 107, 243, .45); background: #fff; box-shadow: 0 0 0 4px rgba(29, 107, 243, .1); }
.mm-chat-composer textarea {
    display: block;
    flex: 1;
    width: 100%;
    min-width: 0;
    min-height: 20px;
    max-height: 120px;
    margin: 0 0 7px;
    padding: 0;
    border: 0;
    background: transparent;
    resize: none;
    field-sizing: content;
    color: var(--mm-chat-ink);
    font-size: 14px;
    line-height: 20px;
    outline: none;
}
.mm-chat-composer textarea::placeholder { color: var(--mm-chat-muted); opacity: 1; }
.mm-chat-composer textarea:disabled { background: transparent; color: var(--mm-chat-muted); -webkit-text-fill-color: var(--mm-chat-muted); }
.mm-chat-composer button {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--mm-chat-blue);
    color: #fff;
}
.mm-chat-composer button svg { transform: translateX(1px); }
.mm-chat-composer button:hover:not(:disabled) { background: var(--mm-chat-blue-hover); }
.mm-chat-composer button:active:not(:disabled) { transform: scale(.94); }
.mm-chat-composer button:disabled { background: #dce1e8; color: #fff; }

.mm-chat-note { margin-top: 9px; padding: 0 4px; color: var(--mm-chat-muted); font-size: 11px; line-height: 1.45; text-align: center; text-wrap: balance; }

/* Status und Fehler */
.mm-chat-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 4px 10px;
    color: var(--mm-chat-muted);
    font-size: 12.5px;
    line-height: 1.45;
}
/* Tippanzeige: drei Punkte, die nacheinander aufleuchten */
.mm-chat-status[data-error="false"]::before {
    --mm-chat-dot: no-repeat radial-gradient(circle closest-side, var(--mm-chat-faint) 92%, transparent);
    content: '';
    flex-shrink: 0;
    width: 22px;
    height: 7px;
    background: var(--mm-chat-dot) 0 50%, var(--mm-chat-dot) 50% 50%, var(--mm-chat-dot) 100% 50%;
    background-size: 5px 5px;
    animation: mm-chat-dots 1.1s infinite ease-in-out;
}
@keyframes mm-chat-dots {
    0%, 75%, 100% { background-size: 5px 5px, 5px 5px, 5px 5px; }
    15% { background-size: 7px 7px, 5px 5px, 5px 5px; }
    35% { background-size: 5px 5px, 7px 7px, 5px 5px; }
    55% { background-size: 5px 5px, 5px 5px, 7px 7px; }
}
.mm-chat-status[data-error="true"] { margin: 0 0 10px; padding: 9px 12px; border-radius: 12px; background: #fdf1f1; color: #a8231c; }
.mm-chat-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

/* Niedrige Fenster, etwa Handys im Querformat */
@media (max-height: 700px) {
    .mm-chat-suggestions { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }
    .mm-chat-suggestions button { padding: 6px 12px; font-size: 13px; }
}
@media (max-height: 540px) {
    .mm-chat-panel { position: fixed; inset: 8px 8px max(8px, env(safe-area-inset-bottom)) auto; width: min(384px, calc(100vw - 16px)); max-width: none; height: auto; max-height: none; }
    .mm-chat-suggestions { display: none; }
    .mm-chat-header { padding: 10px 10px 8px 14px; }
    .mm-chat-footer { max-height: 60%; overflow-y: auto; }
}
/* Handy: Chat als Vollbild, der Startknopf tritt so lange zurück.
   Steht nach den Höhenregeln, damit es auch auf sehr kleinen Handys gilt. */
@media (max-width: 480px) {
    html:has(#mm-chat-panel:not([hidden])) { overflow: hidden; }
    .mm-chat { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
    .mm-chat-launcher { height: 48px; padding: 0 16px 0 7px; font-size: 14px; }
    .mm-chat-launcher[aria-expanded="true"] { display: none; }
    .mm-chat-panel {
        position: fixed;
        inset: 0;
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
        animation-name: mm-chat-sheet;
    }
    .mm-chat-header { padding: max(14px, env(safe-area-inset-top)) 10px 10px 16px; box-shadow: 0 1px 0 var(--mm-chat-hairline); }
    .mm-chat-messages { padding: 16px 14px 14px; }
    .mm-chat-suggestions { padding: 4px 14px 14px; }
    .mm-chat-footer { padding: 4px 12px max(12px, env(safe-area-inset-bottom)); }
    .mm-chat-composer textarea { font-size: 16px; line-height: 22px; margin-bottom: 6px; }
}
@keyframes mm-chat-sheet { from { opacity: 0; transform: translateY(24px); } }
@media (prefers-reduced-motion: reduce) {
    .mm-chat :where(button), .mm-chat-composer, .mm-chat-consent input, .mm-chat-message a, .mm-chat-message a::after { transition: none; }
    .mm-chat-panel, .mm-chat-message, .mm-chat-suggestions button, .mm-chat-status::before { animation: none; }
    .mm-chat-launcher:hover, .mm-chat-launcher:active, .mm-chat button:active:not(:disabled) { transform: none; }
}
