/**
 * NO-KI Chat Widget - Styles
 * NOVVIA Corporate Design (Gold/Schwarz/Weiß)
 */

:root {
    /* NOVVIA Brand-Gold (matcht NO-KI Standalone-App) */
    --noki-gold: #D4AF37;
    --noki-gold-dark: #B8860B;

    /* Onyx-Theme — passend zum Premium-Look der Standalone-App */
    --noki-dark: #F5EFE0;          /* "dark" wird hier als TEXT-Farbe verwendet → warm-weiß */
    --noki-light: #1C1A16;         /* Sidebar / Header / Sub-Container */
    --noki-white: #0F0E0C;         /* Haupt-Hintergrund (Chat-Container) */
    --noki-gray: #A39E92;          /* Sekundär-Text, deaktivierte Elemente */
    --noki-border: #2A2620;        /* Dunkle Border, deutlich sichtbar auf #0F0E0C */

    /* Bubbles: User = Gold-Akzent, Assistant = warmes Anthrazit */
    --noki-user-bg: #D4AF37;
    --noki-user-text: #0F0E0C;
    --noki-assistant-bg: #26221B;
    --noki-assistant-text: #F5EFE0;

    --noki-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
    --noki-shadow-hover: 0 6px 28px rgba(0, 0, 0, 0.6);
}

/* =============================================================================
 * CHAT BUBBLE (Toggle Button)
 * ========================================================================== */
#noki-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    /* Münze ist selbst goldfarben — Background nur für Hover/Focus-Wirkung */
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--noki-shadow);
    z-index: 999998;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
    user-select: none;
    border-radius: 50%;
}

#noki-chat-bubble img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: block;
}

#noki-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: var(--noki-shadow-hover);
    filter: brightness(1.08);
}

#noki-chat-bubble:focus {
    outline: 3px solid var(--noki-gold);
    outline-offset: 3px;
}

#noki-chat-bubble.noki-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.6);
}

/* =============================================================================
 * CHAT CONTAINER
 * ========================================================================== */
#noki-chat-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 48px);
    background: var(--noki-white);
    border-radius: 16px;
    box-shadow: var(--noki-shadow);
    display: flex;
    flex-direction: column;  /* Header oben, Messages mitte, Form unten */
    overflow: hidden;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--noki-dark);
    animation: noki-slide-up 0.25s ease-out;
}

/* Main-Fuellbereich (Header/Messages/Form vertikal) */
#noki-chat-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header-Linke Seite (Hautanalyse-Button) + Rechte Seite (Empfehlungen / Trainer / X) */
#noki-chat-header-left,
#noki-chat-header-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
}
#noki-chat-header-left { margin-right: 8px; }
#noki-chat-header-right { margin-left: 8px; }

/* User-Meta (B2B/B2C · Rolle · Kundengruppe) unter dem Header-Titel */
#noki-chat-user-meta {
    display: block;
    margin-top: 2px;
}

/* hidden-Attribut muss die ID-Regel oben schlagen (Specificity 110 > 100), sonst ist der
   Container dauerhaft sichtbar und closeChat() kann ihn per c.hidden=true nicht ausblenden. */
#noki-chat-container[hidden] {
    display: none;
}

/* Gleiches Problem bei .noki-skin-preview und .noki-correction-form:
   display:flex der Klasse ueberschreibt [hidden]{display:none} -> leerer Rahmen ueber dem
   Input, obwohl hidden=true. Mit !important erzwingen. */
.noki-skin-preview[hidden],
.noki-correction-form[hidden] {
    display: none !important;
}

@keyframes noki-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================================================
 * HEADER
 * ========================================================================== */
/* Header-Logo: kleine Münze links neben dem Titel */
#noki-chat-header-logo {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 8px;
    display: block;
}

#noki-chat-header {
    background: var(--noki-dark);
    color: var(--noki-white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--noki-gold);
    flex-shrink: 0;
}

#noki-chat-title {
    font-weight: 600;
    font-size: 16px;
    letter-spacing: 0.3px;
}

#noki-chat-close {
    background: transparent;
    border: none;
    color: var(--noki-white);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

#noki-chat-close:hover {
    background: rgba(255, 255, 255, 0.12);
}

.noki-header-btn {
    background: transparent;
    border: 0;
    color: var(--noki-white);
    width: 34px;
    height: 34px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    padding: 0;
}
.noki-header-btn:hover,
.noki-header-btn:focus-visible {
    background: rgba(255, 255, 255, 0.15);
    outline: none;
}

/* =============================================================================
 * MESSAGES
 * ========================================================================== */
#noki-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--noki-light);
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#noki-chat-messages::-webkit-scrollbar {
    width: 6px;
}
#noki-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
#noki-chat-messages::-webkit-scrollbar-thumb {
    background: var(--noki-border);
    border-radius: 3px;
}
#noki-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--noki-gray);
}

.noki-msg {
    display: flex;
    max-width: 85%;
}

.noki-msg-user {
    align-self: flex-end;
    justify-content: flex-end;
}

.noki-msg-assistant {
    align-self: flex-start;
}

.noki-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14.5px;
    line-height: 1.45;
}

.noki-msg-user .noki-msg-bubble {
    background: var(--noki-user-bg);
    color: var(--noki-user-text);
    border-bottom-right-radius: 4px;
}

.noki-msg-assistant .noki-msg-bubble {
    background: var(--noki-assistant-bg);
    color: var(--noki-assistant-text);
    border: 1px solid var(--noki-border);
    border-bottom-left-radius: 4px;
}

.noki-msg-bubble a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--noki-gold);
    text-underline-offset: 2px;
}

.noki-msg-user .noki-msg-bubble a {
    color: var(--noki-white);
    text-decoration-color: rgba(255, 255, 255, 0.6);
}

/* Markdown-gerenderte Elemente */
.noki-msg-bubble strong { font-weight: 700; }
.noki-msg-bubble em { font-style: italic; }
.noki-msg-bubble code {
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 0.88em;
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    white-space: normal;
}
.noki-msg-user .noki-msg-bubble code { background: rgba(255, 255, 255, 0.18); }
.noki-msg-bubble pre.noki-code {
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 0.85em;
    background: rgba(0, 0, 0, 0.08);
    padding: 8px 10px;
    border-radius: 6px;
    margin: 6px 0;
    overflow-x: auto;
    white-space: pre;
}
.noki-msg-user .noki-msg-bubble pre.noki-code { background: rgba(255, 255, 255, 0.15); }
.noki-msg-bubble ul {
    padding-left: 18px;
    margin: 4px 0;
}
.noki-msg-bubble li { margin: 2px 0; }

/* =============================================================================
 * SELFIE-UPLOAD / HAUTANALYSE-PREVIEW
 * ========================================================================== */
.noki-skin-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin: 0;
    background: rgba(201, 169, 97, 0.08);
    border-top: 1px solid var(--noki-border);
    border-bottom: 1px solid var(--noki-border);
    flex-shrink: 0;
}
.noki-skin-preview img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--noki-border);
    flex-shrink: 0;
}
.noki-skin-preview-actions {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}
.noki-skin-preview-name {
    font-size: 12px;
    color: var(--noki-gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#noki-skin-preview-cancel {
    background: transparent;
    border: 0;
    color: var(--noki-gray);
    font-size: 22px;
    line-height: 1;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}
#noki-skin-preview-cancel:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--noki-dark);
}

/* =============================================================================
 * TRAINER-KORREKTUR-FORMULAR
 * ========================================================================== */
.noki-correction-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    background: var(--noki-light);
    border-top: 1px solid var(--noki-border);
    flex-shrink: 0;
    max-height: 65%;
    overflow-y: auto;
}
.noki-correction-title {
    font-weight: 700;
    font-size: 13px;
    color: var(--noki-dark);
    margin-bottom: 2px;
}
.noki-correction-form label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--noki-gray);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.noki-correction-form input[type="text"],
.noki-correction-form textarea {
    font: inherit;
    text-transform: none;
    font-weight: 400;
    color: var(--noki-dark);
    background: var(--noki-white);
    border: 1px solid var(--noki-border);
    border-radius: 6px;
    padding: 7px 9px;
    font-size: 13.5px;
    line-height: 1.4;
    resize: vertical;
}
.noki-correction-form input[type="text"]:focus,
.noki-correction-form textarea:focus {
    outline: none;
    border-color: var(--noki-gold);
    box-shadow: 0 0 0 2px rgba(201, 169, 97, 0.15);
}
.noki-correction-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.noki-correction-form .noki-btn-primary,
.noki-correction-form .noki-btn-secondary {
    padding: 7px 14px;
    border-radius: 6px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 0;
    transition: background 0.15s ease;
}
.noki-correction-form .noki-btn-primary {
    background: var(--noki-gold);
    color: var(--noki-white);
}
.noki-correction-form .noki-btn-primary:hover:not(:disabled) {
    background: var(--noki-gold-dark);
}
.noki-correction-form .noki-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.noki-correction-form .noki-btn-secondary {
    background: transparent;
    color: var(--noki-gray);
    border: 1px solid var(--noki-border);
}
.noki-correction-form .noki-btn-secondary:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--noki-dark);
}
.noki-correction-status {
    font-size: 12.5px;
    padding: 6px 10px;
    border-radius: 5px;
    text-align: center;
}
.noki-correction-status.is-info  { background: rgba(0, 0, 0, 0.06); color: var(--noki-gray); }
.noki-correction-status.is-ok    { background: rgba(45, 180, 90, 0.15); color: #1b7a3e; }
.noki-correction-status.is-error { background: rgba(200, 50, 50, 0.12); color: #a81e1e; }

/* Produktkontext-Banner oben im Messages-Container */
.noki-product-context {
    align-self: stretch;
    margin: 0 -16px 8px;
    padding: 8px 16px;
    background: rgba(201, 169, 97, 0.12);
    border-bottom: 1px solid rgba(201, 169, 97, 0.35);
    color: var(--noki-dark);
    font-size: 12.5px;
    line-height: 1.3;
}
.noki-product-context strong {
    font-weight: 700;
    color: var(--noki-gold-dark);
}

/* Medien in Chat-Bubbles */
.noki-msg-bubble .noki-img,
.noki-msg-bubble .noki-video {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 6px 0;
    background: rgba(0, 0, 0, 0.04);
}
.noki-msg-bubble .noki-embed {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    margin: 6px 0;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}
.noki-msg-bubble .noki-embed iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* =============================================================================
 * ATTACHMENTS: Produktbilder-Grid + Video-Clips unter der Assistant-Bubble
 * ========================================================================== */
.noki-attachments {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.noki-product-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
    gap: 8px;
}
.noki-product-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid var(--noki-border);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.noki-product-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    text-decoration: none;
}
.noki-product-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    border-radius: 4px;
    background: #fff;
    display: block;
}
.noki-product-card span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.3;
    text-align: center;
    color: var(--noki-dark);
    font-weight: 500;
}

.noki-video-clip {
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    border: 1px solid var(--noki-border);
}
.noki-video-clip video {
    width: 100%;
    height: auto;
    display: block;
}
.noki-video-clip iframe {
    width: 100%;
    aspect-ratio: 16 / 9;
    display: block;
    border: 0;
}
.noki-video-title {
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    background: var(--noki-white);
    color: var(--noki-dark);
    border-top: 1px solid var(--noki-border);
}

/* =============================================================================
 * TYPING INDICATOR
 * ========================================================================== */
.noki-typing .noki-msg-bubble {
    display: inline-flex;
    gap: 4px;
    padding: 14px 16px;
}

.noki-typing .noki-msg-bubble span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--noki-gold);
    animation: noki-bounce 1.3s infinite ease-in-out both;
}

.noki-typing .noki-msg-bubble span:nth-child(1) { animation-delay: -0.32s; }
.noki-typing .noki-msg-bubble span:nth-child(2) { animation-delay: -0.16s; }

@keyframes noki-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* =============================================================================
 * FORM / INPUT
 * ========================================================================== */
#noki-chat-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--noki-border);
    background: var(--noki-white);
    flex-shrink: 0;
    align-items: flex-end;
}

#noki-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--noki-border);
    border-radius: 20px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14.5px;
    line-height: 1.4;
    outline: none;
    max-height: 120px;
    min-height: 40px;
    transition: border-color 0.2s ease;
    background: var(--noki-white);
    color: var(--noki-dark);
}

#noki-chat-input:focus {
    border-color: var(--noki-gold);
    box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.15);
}

#noki-chat-input:disabled {
    opacity: 0.6;
    background: var(--noki-light);
}

#noki-chat-form button[type="submit"] {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--noki-gold);
    color: var(--noki-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.1s ease;
}

/* Mic-Button fuer Spracheingabe, links neben Textarea */
.noki-mic-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--noki-border);
    background: var(--noki-white);
    color: var(--noki-gray);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    padding: 0;
}
.noki-mic-btn:hover:not(:disabled) {
    background: var(--noki-light);
    color: var(--noki-dark);
    border-color: var(--noki-gold);
}
.noki-mic-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.noki-mic-btn.is-recording {
    background: #d93a3a;
    color: #fff;
    border-color: #d93a3a;
    animation: noki-mic-pulse 1.2s infinite ease-in-out;
}
@keyframes noki-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(217, 58, 58, 0.55); }
    50%      { box-shadow: 0 0 0 10px rgba(217, 58, 58, 0); }
}
.noki-mic-btn[hidden] { display: none !important; }

#noki-chat-form button[type="submit"]:hover:not(:disabled) {
    background: var(--noki-gold-dark);
    transform: scale(1.05);
}

#noki-chat-form button[type="submit"]:active:not(:disabled) {
    transform: scale(0.95);
}

#noki-chat-form button[type="submit"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =============================================================================
 * MOBILE / RESPONSIVE
 * Greift nur wenn der Container die Klasse .noki-mobile-fullsize hat —
 * Admin-Option steuert das. Ohne die Klasse wird auf Mobile die konfigurierte
 * Pixel-Groesse beibehalten (evtl. zu gross fuer schmale Handys).
 * ========================================================================== */
@media (max-width: 768px) {
    #noki-chat-container.noki-mobile-fullsize {
        /* Echter Vollbild-Modus: kein Rand, kein Rund, deckt auch einen klebenden Site-Header ab.
           svh/dvh unterstuetzen iOS-Safari (dynamische UI-Leisten). */
        width: 100vw !important;
        height: 100vh !important;
        height: 100svh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100svh !important;
        max-height: 100dvh !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        transform: none !important;
        border-radius: 0 !important;
    }

    #noki-chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }

    .noki-inline-trigger {
        padding: 6px 10px;
        font-size: 12px;
    }

    /* Header-Buttons auf Mobile einen Tick kompakter */
    .noki-header-btn {
        width: 32px;
        height: 32px;
    }
}

/* =============================================================================
 * Hinweis: Dark-Mode-Auto-Switch wurde entfernt — wir sind permanent
 * im Onyx-Theme (siehe :root am Anfang der Datei).
 * ========================================================================== */
