/* Permit AI — self-hosted chat widget, gated by /api/ai-chat/status. See js/permit-ai-widget.js.
   Bottom-right, the conventional chat-widget corner. --pai-offset is kept in sync with the cookie
   consent banner's live height by permit-ai-widget.js so the two never overlap while the banner
   (shown on first visit only) is up — once it's dismissed the offset drops back to 1rem, clear of
   the cookie-settings icon which lives in the opposite (bottom-left) corner. */
:root { --pai-offset: 1rem; }

#pai-launcher {
    position: fixed;
    right: 1rem;
    bottom: var(--pai-offset);
    z-index: 9997;
    transition: bottom 0.2s ease;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
    color: #fff;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(109, 92, 232, 0.45);
}

#pai-launcher:hover { filter: brightness(1.08); }

#pai-panel {
    position: fixed;
    right: 1rem;
    bottom: calc(var(--pai-offset) + 70px);
    z-index: 9997;
    transition: bottom 0.2s ease;
    width: min(360px, calc(100vw - 2rem));
    height: min(520px, calc(100vh - var(--pai-offset) - 70px - 2rem));
    background: #0c0f1c;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}

#pai-panel-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.9rem 1rem;
    background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
    color: #fff;
}

#pai-panel-header .pai-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}

#pai-panel-header .pai-title { font-weight: 700; font-size: 0.92rem; flex: 1; }
#pai-panel-header .pai-subtitle { font-size: 0.7rem; opacity: 0.85; margin-top: 1px; }

#pai-panel-close {
    background: none;
    border: none;
    color: #fff;
    opacity: 0.85;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
}

#pai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.pai-msg {
    max-width: 85%;
    padding: 0.55rem 0.8rem;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

.pai-msg.pai-user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 3px;
}

.pai-msg.pai-bot {
    align-self: flex-start;
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border-bottom-left-radius: 3px;
}

.pai-sources {
    align-self: flex-start;
    max-width: 85%;
    font-size: 0.72rem;
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.pai-sources a { color: var(--primary-light); text-decoration: none; }
.pai-sources a:hover { text-decoration: underline; }

.pai-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 0.6rem 0.8rem;
}

.pai-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
    animation: pai-bounce 1.2s infinite ease-in-out;
}

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

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

#pai-input-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}

#pai-input {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 0.5rem 0.7rem;
    font-size: 0.85rem;
    resize: none;
    font-family: inherit;
}

#pai-input:focus { outline: none; border-color: var(--primary-light); }

#pai-send {
    background: var(--primary);
    border: none;
    border-radius: 8px;
    color: #fff;
    width: 40px;
    flex-shrink: 0;
    cursor: pointer;
    font-size: 0.9rem;
}

#pai-send:hover { background: var(--primary-dark); }
#pai-send:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 480px) {
    #pai-panel { right: 0.5rem; bottom: calc(var(--pai-offset) + 66px); }
    #pai-launcher { right: 0.5rem; bottom: var(--pai-offset); }
}
