/* ==========================================================================
 * chat.css — chat assistant widget (entry button, drawer, messages, actions)
 * Loaded only on pages that include partials/chat_widget.php (currently
 * /access and /register). v2 (2026-05-09): A1 structured-actions render.
 * ========================================================================== */

/* Open-state body lock to keep mobile drawer from scrolling the page behind. */
body.chat-open { overflow: hidden; }

/* --- Entry trigger (the "Don't know your code?" button) -------------------- */
.chat-entry {
    margin-top: 1.5rem;
    text-align: center;
}
.chat-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.1rem;
    border: 1px solid color-mix(in srgb, var(--m-red) 35%, transparent);
    background: color-mix(in srgb, var(--m-red) 6%, white);
    color: var(--m-red-deep);
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.chat-trigger:hover {
    background: color-mix(in srgb, var(--m-red) 10%, white);
    border-color: color-mix(in srgb, var(--m-red) 55%, transparent);
}

/* --- Drawer (right side on desktop, full-screen on mobile) ----------------- */
.chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 60;
}
.chat-drawer {
    position: fixed;
    z-index: 61;
    background: white;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chat-slide-in 0.18s ease-out;
}
@keyframes chat-slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }

@media (min-width: 768px) {
    .chat-drawer {
        top: 0; right: 0; bottom: 0;
        width: 420px;
        max-width: 90vw;
    }
}
@media (max-width: 767.98px) {
    .chat-drawer {
        inset: 0;
        width: 100vw;
        height: 100vh;
        animation: chat-slide-in-mobile 0.18s ease-out;
    }
    @keyframes chat-slide-in-mobile { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

/* --- Drawer header --------------------------------------------------------- */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--m-red);
    color: var(--brand-text-on-primary, white);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.chat-ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.875rem;
    font-weight: 600;
}
.chat-close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}
.chat-close:hover { background: rgba(255, 255, 255, 0.15); }

/* --- Consent gate ---------------------------------------------------------- */
.chat-consent {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.chat-consent p {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--m-ink);
}
.chat-consent-accept {
    align-self: flex-start;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    background: var(--m-red);
    color: var(--brand-text-on-primary, white);
    border: none;
    font-weight: 600;
    cursor: pointer;
}
.chat-consent-accept:hover { opacity: 0.92; }

/* --- Messages -------------------------------------------------------------- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: color-mix(in srgb, var(--m-red) 3%, white);
}
.chat-msg {
    max-width: 85%;
    padding: 0.6rem 0.85rem;
    border-radius: 0.75rem;
    font-size: 0.92rem;
    line-height: 1.45;
    word-wrap: break-word;
}
.chat-msg-text { white-space: pre-wrap; }
.chat-msg-user {
    align-self: flex-end;
    background: var(--m-red);
    color: var(--brand-text-on-primary, white);
    border-bottom-right-radius: 0.25rem;
}
.chat-msg-assistant {
    align-self: flex-start;
    background: white;
    color: var(--m-ink);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-bottom-left-radius: 0.25rem;
}
.chat-msg-error {
    align-self: stretch;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    font-size: 0.85rem;
    text-align: center;
}
.chat-msg-loading {
    align-self: flex-start;
    color: var(--m-ink-muted, #6b7280);
    font-style: italic;
    padding: 0.4rem 0.85rem;
}

/* --- Action buttons (A1 structured) ---------------------------------------- */
.chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.55rem;
}
.chat-action-btn {
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid color-mix(in srgb, var(--m-red) 35%, transparent);
    background: white;
    color: var(--m-red-deep);
    transition: background 0.15s;
}
.chat-action-btn:hover {
    background: color-mix(in srgb, var(--m-red) 8%, white);
}
.chat-action-join_link {
    background: var(--m-red);
    color: var(--brand-text-on-primary, white);
    border-color: var(--m-red);
}
.chat-action-join_link:hover {
    background: var(--m-red-deep);
}

/* --- Input row ------------------------------------------------------------- */
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    background: white;
}
.chat-input {
    flex: 1;
    padding: 0.55rem 0.75rem;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 0.5rem;
    font-size: 0.95rem;
    line-height: 1.4;
    resize: none;
    min-height: 2.5rem;
    max-height: 8rem;
    font-family: inherit;
}
.chat-input:focus {
    outline: 2px solid color-mix(in srgb, var(--m-red) 40%, transparent);
    outline-offset: 0;
    border-color: var(--m-red);
}
.chat-send {
    padding: 0.55rem 0.9rem;
    border-radius: 0.5rem;
    background: var(--m-red);
    color: var(--brand-text-on-primary, white);
    border: none;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
}
.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.chat-send:not(:disabled):hover { background: var(--m-red-deep); }

/* --- Footer (privacy hint) ------------------------------------------------- */
.chat-footer {
    padding: 0.4rem 0.75rem;
    font-size: 0.7rem;
    color: var(--m-ink-muted, #6b7280);
    text-align: center;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* Reset-conversation button (header). Added 2026-05-09 evening. */
.chat-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}
.chat-reset {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    opacity: 0.85;
}
.chat-reset:hover { background: rgba(255,255,255,0.15); opacity: 1; }
