/* ==========================================================================
   rivus360.center — AI Chat widget (CSP-safe; external styles only)
   ========================================================================== */

.rv-helpdesk {
    --c-bg: #0c0e1a;
    --c-surface: #141833;
    --c-border: rgba(255, 255, 255, 0.12);
    --c-text: #e9ebf5;
    --c-muted: #9aa1bd;
    --c-cyan: #22d3ee;
    --c-violet: #2f5bff;
    /* Eingabefelder und flache Flaechen. Vorher waren die Werte fest verdrahtet
       und blieben im hellen Modus dunkel — mit dunklem Text darauf. */
    --c-feld: rgba(7, 8, 15, 0.6);
    --c-flaeche: rgba(255, 255, 255, 0.08);
    --c-flaeche-sanft: rgba(255, 255, 255, 0.06);
    position: fixed;
    right: clamp(1rem, 3vw, 2rem);
    bottom: clamp(1rem, 3vw, 2rem);
    z-index: 1100;
    font-family: var(--font-family, "Roboto", system-ui, sans-serif);
}

/* Light theme for the RIVUS360 Helpdesk widget */
html[data-theme="light"] .rv-helpdesk {
    --c-bg: #ffffff;
    --c-surface: #eef1f8;
    --c-border: rgba(0, 0, 0, 0.14);
    --c-text: #0f1222;
    --c-muted: #4a5170;
    --c-cyan: #0a93b0; /* darker for readable links/icons on light */
    --c-feld: #ffffff;
    --c-flaeche: rgba(0, 0, 0, 0.05);
    --c-flaeche-sanft: rgba(0, 0, 0, 0.035);
}

/* Launcher button */
.rv-helpdesk__launcher {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.8rem 1.2rem;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    background: #004efe;
    box-shadow: 0 10px 28px -10px rgba(0, 78, 254, 0.55);
    transition: transform 0.2s ease, background 0.2s ease;
}

/* Stronger glow on hover via an opacity fade (composited) instead of
   transitioning box-shadow, which the compositor can't animate. */
.rv-helpdesk__launcher::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: 0 16px 38px -10px rgba(0, 78, 254, 0.6);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.rv-helpdesk__launcher:hover {
    transform: translateY(-2px);
    background: #003ad1;
}

.rv-helpdesk__launcher:hover::after {
    opacity: 1;
}

.rv-helpdesk__launcher i {
    font-size: 1.2rem;
}

/* Panel */
.rv-helpdesk__panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.75rem);
    width: min(92vw, 380px);
    height: min(70vh, 540px);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border-radius: 18px;
    border: 1px solid var(--c-border);
    background: var(--c-bg);
    box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.7);
}

.rv-helpdesk.is-open .rv-helpdesk__panel {
    display: flex;
    animation: rv-helpdesk-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.rv-helpdesk.is-open .rv-helpdesk__launcher {
    display: none;
}

@keyframes rv-helpdesk-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.rv-helpdesk__header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.9rem 1rem;
    background: linear-gradient(120deg, rgba(34, 211, 238, 0.16), rgba(47, 91, 255, 0.16));
    border-bottom: 1px solid var(--c-border);
}

.rv-helpdesk__avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--c-flaeche);
    overflow: hidden;
    flex-shrink: 0;
}

.rv-helpdesk__avatar img {
    width: 36px;
    height: 36px;
    display: block;
}

.rv-helpdesk__launcher-img {
    display: block;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
    animation: bitty-bob 2.6s ease-in-out infinite;
}

@keyframes bitty-bob {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-2px) rotate(-4deg); }
}

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

.rv-helpdesk__title {
    font-weight: 700;
    color: var(--c-text);
    font-size: 0.95rem;
    line-height: 1.1;
}

.rv-helpdesk__subtitle {
    font-size: 0.75rem;
    color: var(--c-muted);
}

.rv-helpdesk__close {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--c-muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 8px;
}

.rv-helpdesk__close:hover {
    color: var(--c-text);
    background: var(--c-flaeche-sanft);
}

/* Welcome / hero greeting */
.rv-helpdesk__welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    padding: 0.5rem 0.5rem 0.25rem;
}

.rv-helpdesk__hero {
    width: 104px;
    height: 104px;
    display: block;
    animation: bitty-walk-in 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.rv-helpdesk__welcome-text {
    color: var(--c-text);
    font-size: 0.95rem;
    line-height: 1.5;
    max-width: 28ch;
    animation: bitty-fade-up 0.5s ease 0.25s both;
}

@keyframes bitty-walk-in {
    0%   { opacity: 0; transform: translateX(-48px) rotate(-6deg); }
    60%  { opacity: 1; transform: translateX(6px) rotate(2deg); }
    100% { opacity: 1; transform: translateX(0) rotate(0); }
}

@keyframes bitty-fade-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .rv-helpdesk__hero,
    .rv-helpdesk__welcome-text { animation: none; }
}

/* Messages */
.rv-helpdesk__messages {
    flex: 1;
    min-height: 0; /* let the flex child actually scroll instead of growing */
    overflow-y: auto;
    overscroll-behavior: contain; /* don't chain scroll to the page behind */
    -webkit-overflow-scrolling: touch;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.rv-helpdesk__msg {
    max-width: 85%;
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.rv-helpdesk__msg--bot {
    align-self: flex-start;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    color: var(--c-text);
    border-bottom-left-radius: 4px;
}

.rv-helpdesk__msg--user {
    align-self: flex-end;
    color: #fff;
    background: var(--primary, #007bff);
    border-bottom-right-radius: 4px;
}

.rv-helpdesk__msg--bot a {
    color: var(--c-cyan);
    font-weight: 600;
    text-decoration: underline;
    word-break: break-word;
}

.rv-helpdesk__msg--bot a:hover {
    color: #67e8f9;
}

/* Direct-contact links shown with the fallback message */
.rv-helpdesk__contact-wrap {
    padding: 0.5rem;
    max-width: 85%;
}

.rv-helpdesk__contact {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.rv-helpdesk__contact a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--c-border);
    border-radius: 10px;
    background: var(--c-surface);
    color: var(--c-text);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s;
}

.rv-helpdesk__contact a:hover {
    border-color: var(--c-cyan);
    color: var(--c-cyan);
}

.rv-helpdesk__contact i {
    font-size: 1.1rem;
    color: var(--c-cyan);
    flex-shrink: 0;
}

/* Typing indicator */
.rv-helpdesk__typing {
    align-self: flex-start;
    display: inline-flex;
    gap: 4px;
    padding: 0.7rem 0.9rem;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 14px;
}

.rv-helpdesk__typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--c-muted);
    animation: rv-helpdesk-bounce 1.2s infinite ease-in-out;
}

.rv-helpdesk__typing span:nth-child(2) { animation-delay: 0.15s; }
.rv-helpdesk__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes rv-helpdesk-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-5px); opacity: 1; }
}

/* Input */
.rv-helpdesk__form {
    display: flex;
    align-items: flex-end; /* send button stays put as the textarea grows */
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--c-border);
    background: var(--c-bg);
}

.rv-helpdesk__input {
    /* Gleiche Hoehe wie der Senden-Knopf, damit die Zeile ruhig wirkt */
    min-height: 52px;
    flex: 1;
    min-width: 0; /* allow the textarea to shrink so the row never overflows */
    resize: none;
    max-height: 110px;
    padding: 0.65rem 0.85rem;
    border-radius: 12px;
    border: 1px solid var(--c-border);
    background: var(--c-feld);
    color: var(--c-text);
    font: inherit;
    font-size: 0.9rem;
}

.rv-helpdesk__input::placeholder {
    /* Ohne eigene Regel nimmt der Browser sein Standardgrau — im hellen Modus
       auf hellem Feld kaum lesbar. */
    color: var(--c-muted);
    opacity: 1;
}

.rv-helpdesk__input:focus {
    outline: none;
    border-color: var(--c-cyan);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.18);
}

.rv-helpdesk__send {
    flex-shrink: 0;
    /* War 42px breit und ohne feste Hoehe — auf dem Handy kaum zu treffen.
       52px entspricht der ueblichen Mindestgroesse fuer Bedienelemente. */
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    color: #fff;
    /* Farbe aus dem Projekt statt dem Blau aus nbit.center */
    background: var(--primary, #c5023c);
    font-size: 1.35rem;
    transition: background 0.2s ease, transform 0.15s ease;
}

.rv-helpdesk__send:hover {
    background: var(--primary-dark, #9e0230);
    transform: scale(1.06);
}

.rv-helpdesk__send:active { transform: scale(0.96); }

.rv-helpdesk__send:disabled {
    opacity: 0.5;
    cursor: default;
}

.rv-helpdesk__disclaimer {
    padding: 0 0.75rem 0.6rem;
    font-size: 0.68rem;
    color: var(--c-muted);
    text-align: center;
}

@media (prefers-reduced-motion: reduce) {
    .rv-helpdesk.is-open .rv-helpdesk__panel { animation: none; }
    .rv-helpdesk__typing span { animation: none; }
}

/* Per-message character counter (cost/abuse limit, user-friendly) */
.rv-helpdesk__counter {
    font-size: 0.72rem;
    color: var(--c-muted, #9aa1bd);
    text-align: right;
    padding: 0 14px 8px;
    min-height: 1em;
}

.rv-helpdesk__counter.is-near {
    color: #f59e0b;
}

/* ---------- Mobile: full-screen chat overlay ----------
   Fixes the mobile bugs: window no longer jumps with the URL bar (100dvh),
   the conversation scrolls instead of the page behind it, and the input row
   can't push the send button off-screen. */
@media (max-width: 600px) {
    .rv-helpdesk__panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100vh;     /* fallback */
        height: 100dvh;    /* stable across mobile URL-bar show/hide */
        max-height: none;
        border: none;
        border-radius: 0;
        z-index: 1200;
    }

    /* Lock the page behind the full-screen chat so touch-scroll stays inside it. */
    body.rv-helpdesk-open {
        overflow: hidden;
    }

    /* iOS Safari auto-zooms when a focused field has font-size < 16px, and
       leaves the page zoomed after the keyboard closes — making the panel look
       enlarged and pushing the send button off-screen. 16px prevents the zoom. */
    .rv-helpdesk__input {
        font-size: 16px;
    }
}


/* =============================================================================
   Rivy — Maskottchen des Helpdesks
   =============================================================================
   Kleine Lebenszeichen, damit der Knopf auffaellt, ohne zu nerven: Rivy wippt
   in langen Abstaenden kurz und nickt, wenn man mit der Maus draufgeht.
   ============================================================================= */
.rv-helpdesk__launcher-img {
    display: block;
    /* Alle 9 Sekunden ein kurzes Wippen — lang genug, um nicht zu stoeren */
    animation: rivy-wippen 9s ease-in-out infinite;
    transform-origin: 50% 85%;
}

@keyframes rivy-wippen {
    0%, 86%, 100% { transform: rotate(0deg) translateY(0); }
    89%           { transform: rotate(-9deg) translateY(-2px); }
    92%           { transform: rotate(7deg)  translateY(-1px); }
    95%           { transform: rotate(-4deg) translateY(0); }
}

.rv-helpdesk__launcher:hover .rv-helpdesk__launcher-img,
.rv-helpdesk__launcher:focus-visible .rv-helpdesk__launcher-img {
    animation: rivy-nicken 0.6s ease-in-out;
}

@keyframes rivy-nicken {
    0%, 100% { transform: rotate(0deg); }
    30%      { transform: rotate(-12deg) scale(1.08); }
    65%      { transform: rotate(8deg)   scale(1.04); }
}

/* Rivy in der Begruessung: taucht sanft auf */
.rv-helpdesk__hero {
    width: 84px;
    height: 84px;
    display: block;
    margin: 0 auto 0.75rem;
    animation: rivy-auftauchen 0.5s ease-out both;
}

@keyframes rivy-auftauchen {
    from { opacity: 0; transform: translateY(10px) scale(0.9); }
    to   { opacity: 1; transform: none; }
}

/* Avatar in der Kopfzeile */
.rv-helpdesk__avatar img { display: block; border-radius: 50%; }

@media (prefers-reduced-motion: reduce) {
    .rv-helpdesk__launcher-img,
    .rv-helpdesk__hero {
        animation: none !important;
    }
}


/* Ladezustand des Senden-Knopfs -------------------------------------------- */
.rv-helpdesk__send.is-busy i { visibility: hidden; }

.rv-helpdesk__send.is-busy::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: senden-dreht 0.7s linear infinite;
}

.rv-helpdesk__send { position: relative; }

@keyframes senden-dreht {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .rv-helpdesk__send.is-busy::after { animation-duration: 2s; }
}
