/* =========================================================
   Wanapos N8N Chat Widget — styles auto-injectés.
   Préfixés `.n8nw-` pour éviter toute collision avec la page hôte.
   ========================================================= */

/* ── Reset doux + tokens ─────────────────────────────────── */
.n8nw-root,
.n8nw-root *,
.n8nw-root *::before,
.n8nw-root *::after {
    box-sizing: border-box;
}
/* Anti-focus-ring système (Safari/WebKit notamment) — nuke global sur les
   éléments interactifs du widget. Notre indicateur visuel de focus passe
   par .n8nw-input-form:focus-within (border-color violet) et par
   .n8nw-modal-input:focus (border + box-shadow primary). */
.n8nw-root input,
.n8nw-root textarea,
.n8nw-root button,
.n8nw-root *:focus,
.n8nw-root *:focus-visible {
    -webkit-tap-highlight-color: transparent;
}
.n8nw-root input:focus,
.n8nw-root input:focus-visible,
.n8nw-root textarea:focus,
.n8nw-root textarea:focus-visible,
.n8nw-root button:focus,
.n8nw-root button:focus-visible {
    outline: none !important;
}

.n8nw-root {
    --n8nw-primary:        #604CF3;
    --n8nw-primary-dark:   #4A38D4;
    --n8nw-primary-light:  #EEEAFE;
    --n8nw-bg:             #ffffff;
    --n8nw-surface:        #ffffff;
    --n8nw-surface-2:      #F6F5FB;
    --n8nw-text:           #111827;
    --n8nw-text-muted:     #6B7280;
    --n8nw-border:         #E5E7EB;
    --n8nw-shadow-bubble:  0 12px 30px -8px rgba(0,0,0,.45), 0 4px 10px -4px rgba(0,0,0,.25);
    --n8nw-shadow-panel:   0 30px 80px -20px rgba(20,16,42,.30), 0 10px 25px -10px rgba(20,16,42,.15);

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;  /* au-dessus de tout */
    color: var(--n8nw-text);
}

/* ── Bulle flottante ─────────────────────────────────────── */
.n8nw-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #1f1f1f, #000);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--n8nw-shadow-bubble);
    transition: transform .2s ease, box-shadow .2s ease;
}
.n8nw-bubble:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 16px 38px -8px rgba(0,0,0,.55), 0 6px 12px -4px rgba(0,0,0,.30);
}
.n8nw-bubble:active {
    transform: translateY(0) scale(.98);
}
.n8nw-bubble-icon {
    font-size: 26px;
    line-height: 1;
}
.n8nw-bubble[hidden] {
    display: none;
}

/* ── Panel chat ──────────────────────────────────────────── */
.n8nw-panel {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 48px);
    background: var(--n8nw-bg);
    border-radius: 20px;
    box-shadow: var(--n8nw-shadow-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: n8nw-pop 0.18s ease-out;
}
.n8nw-panel[hidden] {
    display: none;
}
@keyframes n8nw-pop {
    from { opacity: 0; transform: scale(.94) translateY(8px); }
    to   { opacity: 1; transform: scale(1)   translateY(0); }
}

/* ── Header ──────────────────────────────────────────────── */
.n8nw-header {
    background: linear-gradient(135deg, var(--n8nw-primary), var(--n8nw-primary-dark));
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.n8nw-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.n8nw-header-avatar-icon {
    font-size: 20px;
    line-height: 1;
}
.n8nw-header-text {
    flex: 1;
    min-width: 0;
}
.n8nw-header-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
}
.n8nw-header-subtitle {
    font-size: 11px;
    opacity: 0.85;
    margin-top: 2px;
}
.n8nw-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.n8nw-header-btn {
    background: transparent;
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: .85;
    transition: background .15s, opacity .15s;
}
.n8nw-header-btn:hover {
    background: rgba(255,255,255,.15);
    opacity: 1;
}
.n8nw-header-btn-icon {
    font-size: 18px;
    line-height: 1;
}

/* ── Body / messages ─────────────────────────────────────── */
.n8nw-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    background: var(--n8nw-surface-2);
}
.n8nw-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.n8nw-empty {
    text-align: center;
    padding: 20px 12px;
    color: var(--n8nw-text-muted);
}
.n8nw-empty-icon {
    font-size: 38px;
    color: var(--n8nw-primary);
    opacity: .6;
    margin-bottom: 8px;
}
.n8nw-empty-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--n8nw-text);
    margin-bottom: 4px;
}
.n8nw-empty-text {
    font-size: 12px;
    line-height: 1.5;
}
.n8nw-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 14px;
}
.n8nw-suggestion {
    background: var(--n8nw-bg);
    border: 1px solid var(--n8nw-border);
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--n8nw-text);
    cursor: pointer;
    text-align: left;
    transition: border-color .15s, background .15s;
    font-family: inherit;
}
.n8nw-suggestion:hover {
    border-color: var(--n8nw-primary);
    background: var(--n8nw-primary-light);
    color: var(--n8nw-primary);
}

.n8nw-msg {
    display: flex;
}
.n8nw-msg--user {
    justify-content: flex-end;
}
.n8nw-msg--ai {
    flex-direction: column;
    align-items: flex-start;
}
.n8nw-bubble-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.55;
    word-wrap: break-word;
}
.n8nw-msg--user .n8nw-bubble-msg {
    background: var(--n8nw-primary);
    color: #fff;
    white-space: pre-wrap;
}
.n8nw-msg--ai .n8nw-bubble-msg {
    background: var(--n8nw-bg);
    color: var(--n8nw-text);
    width: 100%;
    max-width: 100%;
    line-height: 1.6;
    border: 1px solid rgba(0,0,0,.04);
}

/* Markdown rendu pour les bulles AI */
.n8nw-md p           { margin: 0.55em 0; }
.n8nw-md p:first-child { margin-top: 0; }
.n8nw-md p:last-child  { margin-bottom: 0; }
.n8nw-md ul,
.n8nw-md ol          { margin: 0.6em 0; padding-left: 1.4em; }
.n8nw-md ul          { list-style: disc; }
.n8nw-md ol          { list-style: decimal; }
.n8nw-md li          { margin: 0.25em 0; }
.n8nw-md strong      { font-weight: 600; color: var(--n8nw-text); }
.n8nw-md em          { font-style: italic; }
.n8nw-md code        { background: rgba(0,0,0,0.06); padding: 0.08em 0.3em; border-radius: 4px; font-size: 0.88em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.n8nw-md pre         { background: rgba(0,0,0,0.06); padding: 0.6em; border-radius: 8px; overflow-x: auto; margin: 0.5em 0; }
.n8nw-md pre code    { background: transparent; padding: 0; }
.n8nw-md h1,
.n8nw-md h2,
.n8nw-md h3          { font-weight: 600; margin: 0.7em 0 0.25em; line-height: 1.3; color: var(--n8nw-text); }
.n8nw-md h1          { font-size: 1.05em; }
.n8nw-md h2          { font-size: 1.0em; }
.n8nw-md h3          { font-size: 0.95em; }
.n8nw-md a           { color: var(--n8nw-primary); text-decoration: underline; }
.n8nw-md blockquote  { border-left: 2px solid var(--n8nw-border); padding-left: 0.65em; color: var(--n8nw-text-muted); margin: 0.55em 0; }
.n8nw-md hr          { border: 0; border-top: 1px solid var(--n8nw-border); margin: 0.85em 0; }

/* Loader "typing" */
.n8nw-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: var(--n8nw-bg);
    border-radius: 16px;
    border: 1px solid rgba(0,0,0,.04);
}
.n8nw-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--n8nw-text-muted);
    animation: n8nw-bounce 1.2s ease-in-out infinite;
}
.n8nw-typing-dot:nth-child(2) { animation-delay: .15s; }
.n8nw-typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes n8nw-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* CTA inline escalade */
.n8nw-escalate-cta {
    margin-top: 8px;
    width: 100%;
    background: var(--n8nw-primary-light);
    border: 1px solid rgba(96,76,243,.25);
    border-radius: 14px;
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    font-family: inherit;
    color: var(--n8nw-text);
    transition: border-color .15s, background .15s;
}
.n8nw-escalate-cta:hover {
    border-color: rgba(96,76,243,.5);
    background: rgba(96,76,243,.13);
}
.n8nw-escalate-cta-icon {
    color: var(--n8nw-primary);
    font-size: 18px;
    flex-shrink: 0;
}
.n8nw-escalate-cta-text {
    flex: 1;
    min-width: 0;
}
.n8nw-escalate-cta-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--n8nw-text);
}
.n8nw-escalate-cta-sub {
    font-size: 10px;
    color: var(--n8nw-text-muted);
    margin-top: 1px;
}
.n8nw-escalate-cta-arrow {
    color: var(--n8nw-primary);
    font-size: 16px;
}

/* Erreur réseau / applicative */
.n8nw-err {
    text-align: center;
    color: #DC2626;
    font-size: 12px;
    padding: 6px 0;
}

/* ── Footer / input ──────────────────────────────────────── */
.n8nw-input-wrap {
    flex-shrink: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--n8nw-border);
    background: var(--n8nw-bg);
}
.n8nw-input-form {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    background: var(--n8nw-surface-2);
    border: 1px solid var(--n8nw-border);
    border-radius: 14px;
    padding: 4px 4px 4px 10px;
    transition: border-color .15s, background .15s;
}
.n8nw-input-form:focus-within {
    border-color: rgba(96,76,243,.4);
    background: var(--n8nw-bg);
}
.n8nw-input-textarea {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-family: inherit;
    font-size: 13px;
    color: var(--n8nw-text);
    resize: none;
    line-height: 1.45;
    padding: 7px 0;
    min-height: 32px;
    max-height: 120px;
    -webkit-tap-highlight-color: transparent;
    /* Supprime le styling natif Safari/WebKit (incl. focus ring système). */
    -webkit-appearance: none;
    appearance: none;
}
.n8nw-input-textarea:focus,
.n8nw-input-textarea:focus-visible {
    outline: none !important;
    box-shadow: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}
.n8nw-input-textarea::placeholder {
    color: var(--n8nw-text-muted);
}
.n8nw-input-send {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: none;
    background: var(--n8nw-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s, transform .1s;
}
.n8nw-input-send:hover:not(:disabled) {
    background: var(--n8nw-primary-dark);
}
.n8nw-input-send:active:not(:disabled) {
    transform: scale(.95);
}
.n8nw-input-send:disabled {
    background: #D1D5DB;
    cursor: not-allowed;
}
.n8nw-input-send-icon {
    font-size: 16px;
    line-height: 1;
}

/* ── Modale email d'escalade ─────────────────────────────── */
.n8nw-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 2;
    animation: n8nw-fade .15s ease-out;
}
.n8nw-modal-backdrop[hidden] {
    display: none;
}
@keyframes n8nw-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.n8nw-modal {
    width: 100%;
    background: var(--n8nw-bg);
    border-radius: 16px 16px 0 0;
    padding: 16px 16px 14px;
    animation: n8nw-slide-up .2s ease-out;
}
@keyframes n8nw-slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.n8nw-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}
.n8nw-modal-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--n8nw-text);
    line-height: 1.3;
}
.n8nw-modal-sub {
    font-size: 11px;
    color: var(--n8nw-text-muted);
    margin-top: 3px;
    line-height: 1.4;
}
.n8nw-modal-close {
    background: transparent;
    border: none;
    color: var(--n8nw-text-muted);
    cursor: pointer;
    padding: 2px;
    line-height: 1;
}
.n8nw-modal-close:hover {
    color: var(--n8nw-text);
}
.n8nw-modal-close-icon {
    font-size: 18px;
}
.n8nw-modal-input {
    width: 100%;
    border: 1px solid var(--n8nw-border);
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 13px;
    font-family: inherit;
    color: var(--n8nw-text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.n8nw-modal-input::placeholder {
    color: var(--n8nw-text-muted);
}
.n8nw-modal-input:focus {
    border-color: rgba(96,76,243,.5);
    box-shadow: 0 0 0 3px rgba(96,76,243,.12);
}
.n8nw-modal-err {
    color: #DC2626;
    font-size: 12px;
    margin-top: 6px;
}
.n8nw-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 10px;
}
.n8nw-modal-btn {
    border: none;
    border-radius: 9px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s;
}
.n8nw-modal-btn--secondary {
    background: transparent;
    color: var(--n8nw-text-muted);
}
.n8nw-modal-btn--secondary:hover {
    background: var(--n8nw-surface-2);
    color: var(--n8nw-text);
}
.n8nw-modal-btn--primary {
    background: var(--n8nw-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.n8nw-modal-btn--primary:hover:not(:disabled) {
    background: var(--n8nw-primary-dark);
}
.n8nw-modal-btn--primary:disabled {
    background: #D1D5DB;
    cursor: not-allowed;
}
.n8nw-modal-btn-icon {
    font-size: 14px;
}
.n8nw-modal-success {
    text-align: center;
    padding: 24px 8px 18px;
}
.n8nw-modal-success-icon {
    font-size: 38px;
    color: #10B981;
    margin-bottom: 8px;
}
.n8nw-modal-success-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--n8nw-text);
    margin-bottom: 4px;
}
.n8nw-modal-success-text {
    font-size: 12px;
    color: var(--n8nw-text-muted);
    line-height: 1.5;
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 520px) {
    .n8nw-root {
        bottom: 16px;
        right: 16px;
    }
    .n8nw-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
}
