/* ============================================================
   PHONY — Chat diagnostic (partagé page + widget)
============================================================ */

.dg-chat-card {
    background: #fff;
    border-radius: var(--radius-lg, 24px);
    box-shadow: var(--shadow-lg, 0 8px 32px oklch(20% 0.01 260 / 0.16));
    border: 1px solid var(--gray-100, oklch(94% 0.01 260));
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
        "head"
        "body"
        "form"
        "disclaimer";
    min-height: 0;
}

.dg-chat-head { grid-area: head; }

.dg-chat-card > .dg-gate,
.dg-chat-card > .dg-chat {
    grid-area: body;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.dg-chat-card > .dg-form { grid-area: form; }
.dg-chat-card > .dg-disclaimer { grid-area: disclaimer; }

.dg-gate.is-gate-hidden {
    display: none !important;
}

.dg-chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: var(--primary-blue, oklch(45% 0.19 260));
    color: #fff;
    flex-shrink: 0;
}

.dg-chat-head-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.dg-chat-head-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.dg-chat-avatar {
    width: 44px;
    height: 44px;
    background: var(--accent-yellow, oklch(85% 0.21 85));
    border: 2px solid oklch(99% 0.01 260 / 0.35);
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.dg-chat-avatar img,
.diag-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 12%;
    display: block;
}

.dg-chat-head strong {
    display: block;
    font-size: 15px;
    line-height: 1.2;
}

.dg-chat-head span {
    display: block;
    font-size: 12px;
    opacity: 0.88;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.dg-reset {
    background: oklch(99% 0.01 260 / 0.12);
    border: 1px solid oklch(99% 0.01 260 / 0.25);
    color: #fff;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.dg-reset:hover { background: oklch(99% 0.01 260 / 0.22); }

.dg-end-chat {
    background: oklch(99% 0.01 260 / 0.12);
    border: 1px solid oklch(99% 0.01 260 / 0.25);
    color: #fff;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.dg-end-chat:hover { background: oklch(99% 0.01 260 / 0.22); }

/* Masquer actions / saisie uniquement avant ouverture du chat (gate visible) */
.dg-chat-card.is-locked:has(.dg-chat.is-hidden) .dg-end-chat { display: none; }

.dg-chat {
    flex: 1 1 0;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.diag-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 92%;
}

.diag-msg--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.diag-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
}

.diag-msg--assistant .diag-msg-avatar {
    background: var(--accent-yellow, oklch(85% 0.21 85));
    overflow: hidden;
}

.diag-msg--user .diag-msg-avatar {
    background: var(--gray-200, oklch(88% 0.01 260));
    color: var(--gray-700, oklch(45% 0.01 260));
}

.diag-msg-bubble {
    padding: 8px 11px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.32;
    word-break: break-word;
}

.diag-msg-bubble br {
    line-height: 1.1;
}

.diag-msg--assistant .diag-msg-bubble {
    background: var(--gray-50, oklch(97% 0.01 260));
    border: 1px solid var(--gray-100, oklch(94% 0.01 260));
}

.diag-msg--user .diag-msg-bubble {
    background: var(--primary-blue, oklch(45% 0.19 260));
    color: #fff;
}

.diag-msg-bubble ol { margin: 4px 0 0; padding-left: 18px; }
.diag-msg-bubble li { margin-bottom: 2px; }
.diag-msg-bubble li:last-child { margin-bottom: 0; }
.diag-msg-bubble a { color: inherit; text-decoration: underline; }

.diag-dots {
    display: inline-flex;
    gap: 4px;
    padding: 2px 0;
}

.diag-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--gray-700, oklch(45% 0.01 260));
    opacity: 0.45;
    animation: diagDot 1.2s ease-in-out infinite;
}

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

@keyframes diagDot {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
    40% { transform: translateY(-4px); opacity: 1; }
}

.dg-form {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--gray-100, oklch(94% 0.01 260));
    background: #fff;
    flex-shrink: 0;
}

.dg-form textarea {
    flex: 1;
    resize: none;
    border: 2px solid var(--gray-200, oklch(88% 0.01 260));
    border-radius: 12px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    min-height: 44px;
    max-height: 100px;
}

.dg-form textarea:focus {
    outline: none;
    border-color: var(--primary-blue, oklch(45% 0.19 260));
}

.dg-send {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: var(--primary-blue, oklch(45% 0.19 260));
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
}

.dg-send:hover:not(:disabled) { background: var(--primary-blue-dark, oklch(35% 0.20 260)); }
.dg-send:disabled { opacity: 0.5; cursor: not-allowed; }

.dg-disclaimer {
    padding: 8px 12px 10px;
    font-size: 11px;
    color: var(--gray-700, oklch(45% 0.01 260));
    background: oklch(97% 0.02 85);
    border-top: 1px solid oklch(92% 0.04 85);
    line-height: 1.4;
    flex-shrink: 0;
}

.dg-disclaimer i { margin-right: 4px; }

/* Gate (identification) */
.dg-gate {
    flex: 1 1 auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 10px 12px;
    background: linear-gradient(180deg, var(--gray-50, oklch(97% 0.01 260)), #fff);
    overflow-y: auto;
    min-height: 0;
}

.dg-gate-card {
    width: 100%;
    max-width: 340px;
    background: #fff;
    border: 1px solid var(--gray-100, oklch(94% 0.01 260));
    border-radius: 16px;
    padding: 14px 16px;
    box-shadow: var(--shadow-md, 0 4px 16px oklch(20% 0.01 260 / 0.12));
    text-align: center;
}

.dg-gate-logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
}

.dg-gate-logos img.dg-gate-phony { height: 26px; width: auto; }

.dg-gate-logos .dg-gate-bolt {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid var(--primary-blue, oklch(45% 0.19 260));
    overflow: hidden;
    background: var(--accent-yellow, oklch(85% 0.21 85));
}

.dg-gate-logos .dg-gate-bolt img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 12%;
}

.dg-gate-card h2 {
    font-family: var(--font-heading, Montserrat, sans-serif);
    font-size: 16px;
    font-weight: 800;
    margin: 0 0 4px;
}

.dg-gate-card p {
    font-size: 13px;
    color: var(--gray-700, oklch(45% 0.01 260));
    margin: 0 0 10px;
}

.dg-gate-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}

.dg-gate-form label {
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-700, oklch(45% 0.01 260));
}

.dg-gate-form input {
    width: 100%;
    border: 2px solid var(--gray-200, oklch(88% 0.01 260));
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 15px;
    font-family: inherit;
}

.dg-gate-form input:focus {
    outline: none;
    border-color: var(--primary-blue, oklch(45% 0.19 260));
}

.dg-gate-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 6px;
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: var(--primary-blue, oklch(45% 0.19 260));
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.dg-gate-submit:hover:not(:disabled) { background: var(--primary-blue-dark, oklch(35% 0.20 260)); }
.dg-gate-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.dg-gate-error {
    font-size: 12px;
    color: oklch(50% 0.18 25);
    margin: 4px 0 0;
    min-height: 0;
}

.dg-chat-card.is-locked:has(.dg-chat.is-hidden) .dg-form,
.dg-chat-card.is-locked:has(.dg-chat.is-hidden) .dg-disclaimer { display: none; }
.dg-chat-card.is-locked .dg-reset { display: none; }
.dg-chat.is-hidden { display: none !important; }

/* Chat ouvert : footer et actions toujours visibles (même si is-locked désynchronisé) */
.dg-chat-card:has(.dg-chat:not(.is-hidden)) .dg-form { display: flex; }
.dg-chat-card:has(.dg-chat:not(.is-hidden)) .dg-end-chat { display: inline-flex; align-items: center; }

@media (max-width: 400px) {
    .dg-reset-label,
    .dg-end-chat-label { display: none; }
}
