/* ============================================================
   TENGO CENTER – WIDGET CHAT UTILISATEUR
   Fichier : public/assets/chat/chat-widget.css
   v2.1 – Fix : mobile height / Chrome position / Safari
   ============================================================ */

:root {
    --tc-primary:       #1a73e8;
    --tc-primary-dark:  #1557b0;
    --tc-primary-light: #e8f0fe;
    --tc-danger:        #ea4335;
    --tc-warning:       #fbbc04;
    --tc-white:         #ffffff;
    --tc-gray-50:       #f8f9fa;
    --tc-gray-100:      #f1f3f4;
    --tc-gray-200:      #e8eaed;
    --tc-gray-400:      #9aa0a6;
    --tc-gray-600:      #5f6368;
    --tc-gray-800:      #3c4043;
    --tc-shadow:        0 8px 32px rgba(0,0,0,0.18);
    --tc-radius:        14px;
    --tc-radius-sm:     8px;
    --tc-font:          'Segoe UI', system-ui, -apple-system, sans-serif;
    --tc-z:             999999;
}

/* ============================================================
   WRAPPER – flex column, aligne tout à droite
   FIX CHROME : align-items:flex-end empêche la fenêtre
   de déborder vers la gauche
   ============================================================ */
#tc-chat-wrapper {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: var(--tc-z);
    font-family: var(--tc-font);
    font-size: 14px;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-align-items: flex-end;
    align-items: flex-end;
}

/* ============================================================
   BOUTON FLOTTANT
   ============================================================ */
.tc-chat-toggle {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--tc-primary);
    color: var(--tc-white);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(26,115,232,0.45);
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    outline: none;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    margin-top: 10px;
}
.tc-chat-toggle:hover {
    -webkit-transform: scale(1.08);
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(26,115,232,0.55);
    background: var(--tc-primary-dark);
}
.tc-chat-toggle svg { width: 24px; height: 24px; }

.tc-unread-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    background: var(--tc-danger);
    color: var(--tc-white);
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    padding: 0 4px;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    border: 2px solid var(--tc-white);
}

/* ============================================================
   FENÊTRE DE CHAT (DESKTOP)
   ============================================================ */
.tc-chat-window {
    width: 320px;
    height: 420px;
    background: var(--tc-white);
    border-radius: var(--tc-radius);
    box-shadow: var(--tc-shadow);
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 10px;
    -webkit-animation: tc-slide-up 0.22s ease;
    animation: tc-slide-up 0.22s ease;
}

@-webkit-keyframes tc-slide-up {
    from { opacity: 0; -webkit-transform: translateY(14px) scale(0.97); transform: translateY(14px) scale(0.97); }
    to   { opacity: 1; -webkit-transform: translateY(0) scale(1); transform: translateY(0) scale(1); }
}
@keyframes tc-slide-up {
    from { opacity: 0; transform: translateY(14px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   HEADER – toujours flex-shrink:0 pour ne jamais disparaître
   ============================================================ */
.tc-chat-header {
    background: var(--tc-primary);
    color: var(--tc-white);
    padding: 12px 14px;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 10px;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    min-height: 58px;
}
.tc-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}
.tc-header-info { -webkit-flex: 1; flex: 1; min-width: 0; }
.tc-header-title { font-weight: 700; font-size: 14px; line-height: 1.2; }
.tc-header-status {
    font-size: 11px;
    opacity: 0.9;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}
.tc-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; -webkit-flex-shrink: 0; flex-shrink: 0; }
.tc-dot-green  { background: #4caf50; }
.tc-dot-orange { background: var(--tc-warning); }
.tc-dot-gray   { background: var(--tc-gray-400); }

.tc-btn-header-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: var(--tc-white);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-transition: background 0.15s;
    transition: background 0.15s;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}
.tc-btn-header-close:hover { background: rgba(255,255,255,0.3); }

/* ============================================================
   ÉTAPES
   ============================================================ */
.tc-step {
    -webkit-flex: 1;
    flex: 1;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* ============================================================
   FORMULAIRE
   ============================================================ */
.tc-form-intro {
    padding: 14px 16px 0;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}
.tc-form-intro p {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    background: var(--tc-primary-light);
    padding: 10px 12px;
    border-radius: var(--tc-radius-sm);
    border-left: 3px solid var(--tc-primary);
    color: var(--tc-gray-800);
}

.tc-form-body {
    padding: 12px 16px 14px;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    -webkit-flex: 1;
    flex: 1;
    min-height: 0;
}

.tc-form-group {
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    gap: 4px;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}
.tc-form-group label { font-size: 12px; font-weight: 600; color: var(--tc-gray-600); }

.tc-input {
    width: 100%;
    padding: 9px 11px;
    border: 1.5px solid var(--tc-gray-200);
    border-radius: var(--tc-radius-sm);
    font-size: 14px;
    font-family: var(--tc-font);
    color: var(--tc-gray-800);
    -webkit-transition: border-color 0.15s, box-shadow 0.15s;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
.tc-input:focus {
    border-color: var(--tc-primary);
    box-shadow: 0 0 0 3px rgba(26,115,232,0.12);
}
.tc-input::-webkit-input-placeholder { color: var(--tc-gray-400); }
.tc-input::placeholder { color: var(--tc-gray-400); }

.tc-form-error {
    color: var(--tc-danger);
    font-size: 12px;
    background: #fce8e6;
    padding: 7px 10px;
    border-radius: var(--tc-radius-sm);
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}

.tc-btn-primary {
    width: 100%;
    padding: 11px;
    background: var(--tc-primary);
    color: var(--tc-white);
    border: none;
    border-radius: var(--tc-radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    gap: 8px;
    -webkit-transition: background 0.15s;
    transition: background 0.15s;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}
.tc-btn-primary:hover  { background: var(--tc-primary-dark); }
.tc-btn-primary:active { opacity: 0.88; }

/* ============================================================
   INTERFACE CHAT
   ============================================================ */
.tc-agent-info {
    padding: 7px 12px;
    background: var(--tc-primary-light);
    font-size: 12px;
    color: var(--tc-primary);
    font-weight: 600;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 6px;
    border-bottom: 1px solid var(--tc-gray-200);
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}

.tc-messages-container {
    -webkit-flex: 1;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
    min-height: 0;
}
.tc-messages-container::-webkit-scrollbar { width: 4px; }
.tc-messages-container::-webkit-scrollbar-thumb { background: var(--tc-gray-200); border-radius: 2px; }

.tc-msg {
    max-width: 82%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
}
.tc-msg-user   { -webkit-align-self: flex-end;   align-self: flex-end;   background: var(--tc-primary); color: var(--tc-white); border-bottom-right-radius: 3px; }
.tc-msg-agent  { -webkit-align-self: flex-start;  align-self: flex-start;  background: var(--tc-gray-100); color: var(--tc-gray-800); border-bottom-left-radius: 3px; }
.tc-msg-system { -webkit-align-self: center; align-self: center; background: transparent; color: var(--tc-gray-400); font-size: 11px; font-style: italic; text-align: center; padding: 2px 6px; max-width: 100%; }

.tc-msg-meta { font-size: 10px; opacity: 0.6; margin-top: 3px; text-align: right; }
.tc-msg-agent .tc-msg-meta { text-align: left; }

.tc-waiting-msg {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 12px;
    color: var(--tc-gray-400);
    border-top: 1px solid var(--tc-gray-100);
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}
.tc-dots-loader { display: -webkit-flex; display: flex; gap: 3px; }
.tc-dots-loader span {
    width: 5px; height: 5px;
    background: var(--tc-gray-400);
    border-radius: 50%;
    -webkit-animation: tc-dot-pulse 1.4s infinite ease-in-out;
    animation: tc-dot-pulse 1.4s infinite ease-in-out;
}
.tc-dots-loader span:nth-child(2) { -webkit-animation-delay:.2s; animation-delay:.2s; }
.tc-dots-loader span:nth-child(3) { -webkit-animation-delay:.4s; animation-delay:.4s; }
@-webkit-keyframes tc-dot-pulse {
    0%,80%,100% { -webkit-transform:scale(0.7); transform:scale(0.7); opacity:.5; }
    40% { -webkit-transform:scale(1); transform:scale(1); opacity:1; }
}
@keyframes tc-dot-pulse {
    0%,80%,100% { transform:scale(0.7); opacity:.5; }
    40% { transform:scale(1); opacity:1; }
}

.tc-input-area {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: flex-end;
    align-items: flex-end;
    gap: 7px;
    padding: 8px 10px;
    border-top: 1px solid var(--tc-gray-200);
    background: var(--tc-white);
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}
.tc-textarea {
    -webkit-flex: 1;
    flex: 1;
    resize: none;
    border: 1.5px solid var(--tc-gray-200);
    border-radius: 18px;
    padding: 7px 12px;
    font-size: 13px;
    font-family: var(--tc-font);
    color: var(--tc-gray-800);
    max-height: 72px;
    min-height: 34px;
    overflow-y: auto;
    outline: none;
    -webkit-transition: border-color 0.15s;
    transition: border-color 0.15s;
    line-height: 1.4;
    -webkit-appearance: none;
    appearance: none;
}
.tc-textarea:focus { border-color: var(--tc-primary); }
.tc-textarea:disabled { background: var(--tc-gray-50); cursor: not-allowed; }

.tc-btn-send {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--tc-primary);
    color: var(--tc-white);
    border: none;
    cursor: pointer;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    -webkit-transition: background 0.15s;
    transition: background 0.15s;
}
.tc-btn-send:hover:not(:disabled)  { background: var(--tc-primary-dark); }
.tc-btn-send:active:not(:disabled) { opacity: 0.85; }
.tc-btn-send:disabled { background: var(--tc-gray-200); cursor: not-allowed; }

.tc-chat-footer {
    padding: 6px 10px 10px;
    border-top: 1px solid var(--tc-gray-100);
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    text-align: center;
}
.tc-btn-end {
    background: none; border: none;
    color: var(--tc-danger); font-size: 12px; cursor: pointer;
    padding: 4px 8px; border-radius: 4px;
    -webkit-transition: background 0.15s; transition: background 0.15s;
}
.tc-btn-end:hover { background: #fce8e6; }

.tc-closed-msg {
    display: -webkit-flex; display: flex;
    -webkit-flex-direction: column; flex-direction: column;
    -webkit-align-items: center; align-items: center;
    -webkit-justify-content: center; justify-content: center;
    padding: 30px 20px; text-align: center; gap: 10px;
    -webkit-flex: 1; flex: 1;
}
.tc-closed-msg h4 { margin:0; font-size:16px; color:var(--tc-gray-800); font-weight:700; }
.tc-closed-msg p  { margin:0; color:var(--tc-gray-600); font-size:13px; line-height:1.5; }

.tc-spinner {
    width:13px; height:13px;
    border:2px solid rgba(255,255,255,0.3);
    border-top-color:var(--tc-white);
    border-radius:50%;
    -webkit-animation:tc-spin .6s linear infinite;
    animation:tc-spin .6s linear infinite;
    display:inline-block; vertical-align:middle;
}
@-webkit-keyframes tc-spin { to { -webkit-transform:rotate(360deg); transform:rotate(360deg); } }
@keyframes tc-spin { to { transform:rotate(360deg); } }

/* ============================================================
   RESPONSIVE MOBILE (≤ 520px)
   La fenêtre passe en position FIXED indépendante du wrapper
   → le header est TOUJOURS visible (fenêtre part du bas)
   → aucun débordement vers le haut
   ============================================================ */
@media (max-width: 520px) {

    /* Wrapper : bouton reste en bas à droite */
    #tc-chat-wrapper {
        bottom: 14px;
        right: 14px;
    }

    .tc-chat-toggle {
        width: 52px;
        height: 52px;
        margin-top: 0;
    }

    /*
     * Fenêtre en FIXED centrée horizontalement :
     * left/right égaux + margin auto = centrage parfait
     * même si le bouton est à droite
     */
    .tc-chat-window {
        position: fixed !important;
        bottom: 78px;
        left: 50% !important;
        right: auto !important;
        -webkit-transform: translateX(-50%);
        transform: translateX(-50%);
        width: calc(100vw - 28px) !important;
        max-width: 400px;
        height: auto !important;
        max-height: 72vh;
        min-height: 280px;
        margin-bottom: 0;
        border-radius: 14px;
    }

    /* Formulaire compact */
    .tc-form-intro { padding: 12px 14px 0; }
    .tc-form-intro p { font-size: 12px; padding: 8px 10px; }
    .tc-form-body { padding: 10px 14px 12px; gap: 8px; }
    .tc-input { padding: 8px 10px; font-size: 13px; }
    .tc-btn-primary { padding: 10px; font-size: 13px; margin: 0; }
}

/* Fix Safari iOS uniquement */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 520px) {
        .tc-chat-window { max-height: 72vh; }
    }
}
