/* ============================================================
   DigitrendZ Editor — semantic search chat widget
   Floating launcher → slide-in chat panel with grounded result cards.
   Accent colors are injected at runtime via --acp-accent / --acp-accent-2.
   ============================================================ */

.acp-bot {
    --acp-accent: #e63329;
    --acp-accent-2: #b01e15;
    --acp-grad: linear-gradient(135deg, var(--acp-accent), var(--acp-accent-2));
    --acp-width: 400px;
    --acp-radius: 16px;
    --acp-bg: #ffffff;
    --acp-bg-2: #f6f7fb;
    --acp-text: #1f2937;
    --acp-border: #e5e7eb;
}

/* ===== Launcher bubble ===== */
.acp-bot-bubble {
    position: fixed;
    bottom: 24px;
    inset-inline-end: 24px;
    width: 78px;
    height: 78px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    z-index: 999940;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--acp-grad);
    box-shadow: 0 8px 24px rgba(230, 51, 41, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
    color: #fff;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s, opacity 0.2s;
    animation: acp-bubble-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.acp-bot-bubble:hover { transform: scale(1.08) translateY(-2px); }
.acp-bot-bubble:active { transform: scale(0.96); }

/* Centered bot icon */
.acp-bot-bubble-icon { display: flex; align-items: center; justify-content: center; margin-top: 6px; }
.acp-bot-bubble.no-arc .acp-bot-bubble-icon,
.acp-bot-bubble.ring-mode .acp-bot-bubble-icon { margin-top: 0; }
.acp-bot-bubble-icon svg { width: 30px; height: 30px; display: block; }

/* "Ask The Wiz" arc / ring text hugging the launcher edge */
.acp-bot-ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}
.acp-bot-ring text {
    fill: #fff;
    font-family: inherit;
    font-weight: 700;
}
/* Full-ring rotating badge */
.acp-bot-ring.spin {
    transform-origin: 50% 50%;
    animation: acp-ring-spin 16s linear infinite;
}
@keyframes acp-ring-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .acp-bot-ring.spin { animation: none; }
}

.acp-bot-bubble::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(230, 51, 41, 0.45);
    animation: acp-pulse 2.6s ease-out infinite;
}
@keyframes acp-pulse {
    0% { box-shadow: 0 0 0 0 rgba(230, 51, 41, 0.4); }
    70% { box-shadow: 0 0 0 16px rgba(230, 51, 41, 0); }
    100% { box-shadow: 0 0 0 0 rgba(230, 51, 41, 0); }
}
@keyframes acp-bubble-in {
    from { opacity: 0; transform: scale(0.4) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.acp-bot.is-open .acp-bot-bubble { opacity: 0; pointer-events: none; transform: scale(0.5); }

/* ===== First-visit callout ===== */
.acp-bot-callout {
    position: fixed;
    bottom: 114px;
    inset-inline-end: 24px;
    z-index: 999941;
    max-width: 244px;
    background: var(--acp-bg);
    color: var(--acp-text);
    border: 1px solid var(--acp-border);
    border-radius: 14px;
    padding: 12px 32px 12px 14px;
    font-size: 0.86rem;
    line-height: 1.45;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}
.acp-bot-callout.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
/* little tail pointing down toward the launcher */
.acp-bot-callout::after {
    content: '';
    position: absolute;
    bottom: -7px;
    inset-inline-end: 26px;
    width: 14px;
    height: 14px;
    background: var(--acp-bg);
    border-right: 1px solid var(--acp-border);
    border-bottom: 1px solid var(--acp-border);
    transform: rotate(45deg);
}
.acp-bot-callout-text { display: block; }
.acp-bot-callout-close {
    position: absolute;
    top: 6px;
    inset-inline-end: 6px;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--acp-text);
    opacity: 0.5;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    transition: opacity 0.2s, background 0.2s;
}
.acp-bot-callout-close:hover { opacity: 1; background: rgba(0, 0, 0, 0.06); }
.acp-bot-callout-close svg { width: 13px; height: 13px; }

@media (max-width: 600px) {
    .acp-bot-callout { bottom: 98px; inset-inline-end: 18px; }
}
@media (prefers-reduced-motion: reduce) {
    .acp-bot-callout { transition: opacity 0.2s ease; transform: none; }
    .acp-bot-callout.show { transform: none; }
}

/* ===== Panel ===== */
.acp-bot-panel {
    position: fixed;
    bottom: 24px;
    inset-inline-end: 24px;
    width: var(--acp-width);
    max-width: calc(100vw - 32px);
    height: min(640px, calc(100vh - 48px));
    background: var(--acp-bg);
    border: 1px solid var(--acp-border);
    border-radius: var(--acp-radius);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
    z-index: 999945;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(24px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s;
}
.acp-bot.is-open .acp-bot-panel {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* ===== Header ===== */
.acp-bot-header {
    flex-shrink: 0;
    padding: 14px 16px;
    background: var(--acp-grad);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
}
.acp-bot-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.acp-bot-avatar svg { width: 22px; height: 22px; }
.acp-bot-htext { flex: 1; min-width: 0; line-height: 1.25; }
.acp-bot-title { font-weight: 700; font-size: 1rem; }
.acp-bot-sub { font-size: 0.72rem; opacity: 0.9; }
.acp-bot-sub::before { content: '●'; color: #4ade80; font-size: 0.7em; margin-inline-end: 4px; vertical-align: middle; }
.acp-bot-close {
    width: 36px; height: 36px; border-radius: 9px; border: none;
    background: transparent; color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s; flex-shrink: 0;
}
.acp-bot-close:hover { background: rgba(255, 255, 255, 0.2); }
.acp-bot-close svg { width: 20px; height: 20px; }

/* ===== Messages ===== */
.acp-bot-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--acp-bg-2);
}
.acp-bot-messages > * { flex-shrink: 0; }

.acp-bot-msg {
    max-width: 90%;
    padding: 11px 15px;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.55;
    word-wrap: break-word;
    animation: acp-msg-in 0.3s ease-out;
}
@keyframes acp-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.acp-bot-msg.bot {
    align-self: flex-start;
    background: var(--acp-bg);
    color: var(--acp-text);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}
/* Markdown rendered inside bot bubbles */
.acp-bot-msg.bot p { margin: 0 0 0.6em; }
.acp-bot-msg.bot p:last-child { margin-bottom: 0; }
.acp-bot-msg.bot ul,
.acp-bot-msg.bot ol { margin: 0 0 0.6em; padding-inline-start: 1.2em; }
.acp-bot-msg.bot ul:last-child,
.acp-bot-msg.bot ol:last-child { margin-bottom: 0; }
.acp-bot-msg.bot li { margin: 0.15em 0; }
.acp-bot-msg.bot strong { font-weight: 700; }
.acp-bot-msg.bot em { font-style: italic; }
.acp-bot-msg.bot code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86em;
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 5px;
}
.acp-bot-msg.bot a { color: var(--acp-accent) !important; text-decoration: underline; }
.acp-bot-msg.user {
    align-self: flex-end;
    background: var(--acp-grad);
    color: #fff;
    border-bottom-right-radius: 5px;
    box-shadow: 0 2px 8px rgba(230, 51, 41, 0.25);
}

/* ===== Result cards ===== */
.acp-bot-results {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.acp-bot-card {
    display: block;
    text-decoration: none;
    color: var(--acp-text) !important;
    background: var(--acp-bg);
    border: 1px solid var(--acp-border);
    border-radius: 12px;
    padding: 11px 13px;
    transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s;
}
.acp-bot-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
    border-color: var(--acp-accent);
}
.acp-bot-card-title {
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1.35;
    color: var(--acp-accent) !important;
    margin-bottom: 4px;
}
.acp-bot-card-date {
    font-size: 0.7rem;
    color: var(--acp-text) !important;
    opacity: 0.6;
    margin-bottom: 5px;
}
.acp-bot-card-date::before {
    content: '🕒';
    margin-inline-end: 4px;
    font-size: 0.9em;
}
.acp-bot-card-excerpt {
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--acp-text) !important;
    opacity: 0.85;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.acp-bot-card-topics {
    margin-top: 7px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.acp-bot-tag {
    font-size: 0.68rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(230, 51, 41, 0.08);
    color: var(--acp-accent);
}

/* ===== Trending chips ===== */
.acp-bot-chips-label {
    align-self: flex-start;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.55;
    color: var(--acp-text);
    margin: 2px 0 -4px;
}
.acp-bot-chips {
    align-self: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 100%;
}
.acp-bot-chip {
    border: 1px solid var(--acp-accent);
    background: rgba(230, 51, 41, 0.06);
    color: var(--acp-accent) !important;
    border-radius: 16px;
    padding: 5px 11px;
    font-size: 0.76rem;
    line-height: 1.3;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, color 0.2s;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.acp-bot-chip:hover { background: var(--acp-accent); color: #fff !important; transform: translateY(-1px); }
.acp-bot-chip.is-entity::before {
    content: '#';
    opacity: 0.6;
    margin-inline-end: 3px;
}

/* ===== Typing indicator ===== */
.acp-bot-typing { display: inline-flex; gap: 4px; align-items: center; }
.acp-bot-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--acp-accent-2);
    opacity: 0.45;
    animation: acp-typing 1s infinite;
}
.acp-bot-typing span:nth-child(2) { animation-delay: 0.2s; }
.acp-bot-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes acp-typing {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50% { transform: translateY(-4px); opacity: 1; }
}

/* ===== Input ===== */
.acp-bot-input-area {
    flex-shrink: 0;
    padding: 12px 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: var(--acp-bg);
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.acp-bot-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--acp-border);
    border-radius: 14px;
    padding: 11px 14px;
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    height: 44px;
    outline: none;
    background: var(--acp-bg-2);
    color: var(--acp-text) !important;
    -webkit-text-fill-color: var(--acp-text);
    transition: border-color 0.2s, box-shadow 0.2s;
    overflow-y: auto;
    scrollbar-width: none;
}
.acp-bot-input::placeholder { color: var(--acp-text); opacity: 0.45; }
.acp-bot-input::-webkit-scrollbar { width: 0; height: 0; display: none; }
.acp-bot-input:focus { border-color: var(--acp-accent); box-shadow: 0 0 0 3px rgba(230, 51, 41, 0.12); }
.acp-bot-send {
    width: 44px; height: 44px; flex-shrink: 0;
    border-radius: 50%; border: none;
    background: var(--acp-grad); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.2s, transform 0.15s;
}
.acp-bot-send:hover:not(:disabled) { transform: scale(1.06); }
.acp-bot-send:disabled { opacity: 0.4; cursor: default; }
.acp-bot-send svg { width: 20px; height: 20px; }
[dir="rtl"] .acp-bot-send svg { transform: scaleX(-1); }

/* ===== Mobile ===== */
@media (max-width: 600px) {
    .acp-bot-panel {
        bottom: 0;
        inset-inline-end: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        border-radius: 0;
    }
    .acp-bot-bubble { bottom: 18px; inset-inline-end: 18px; width: 68px; height: 68px; }
    .acp-bot-bubble-icon svg { width: 26px; height: 26px; }
}

@media (prefers-reduced-motion: reduce) {
    .acp-bot-bubble, .acp-bot-bubble::after, .acp-bot-msg { animation: none !important; }
    .acp-bot-panel { transition: opacity 0.2s !important; }
}
