/* Global Panda Pax floating chatbot */
.panda-pax-chatbot-root {
    --panda-accent: #00539C;
    --panda-accent-light: #00A6FF;
    --panda-bg: #091c32;
    --panda-z: 10050;
}

/* FAB – pill with avatar + role label */
.panda-pax-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--panda-z);
    min-height: 52px;
    height: auto;
    width: auto;
    max-width: calc(100vw - 32px);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 8px 16px 8px 10px;
    background: linear-gradient(135deg, var(--panda-accent) 0%, var(--panda-accent-light) 100%);
    box-shadow: 0 6px 24px rgba(0, 83, 156, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
}

.panda-pax-launcher:hover {
    transform: scale(1.04);
    box-shadow: 0 8px 28px rgba(0, 166, 255, 0.5);
}

.panda-pax-launcher[aria-expanded="true"] {
    transform: scale(0.98);
}

.panda-pax-launcher-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.9);
    flex-shrink: 0;
}

.panda-pax-launcher-label {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #fff;
    line-height: 1.2;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.panda-pax-launcher-badge {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #10b981;
    border: 2px solid #fff;
    display: none;
}

.panda-pax-launcher.has-unread .panda-pax-launcher-badge {
    display: block;
}

@media (prefers-reduced-motion: no-preference) {
    .panda-pax-launcher:not([aria-expanded="true"]) {
        animation: pandaFabPulse 3s ease-in-out infinite;
    }
}

@keyframes pandaFabPulse {
    0%, 100% { box-shadow: 0 6px 24px rgba(0, 83, 156, 0.45); }
    50% { box-shadow: 0 6px 28px rgba(0, 166, 255, 0.55), 0 0 0 6px rgba(0, 166, 255, 0.12); }
}

/* Panel */
.panda-pax-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: calc(var(--panda-z) + 1);
    width: min(400px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 120px));
    display: flex;
    flex-direction: column;
    background: var(--panda-bg);
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    transform: translateY(12px) scale(0.98);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s linear 0.25s;
}

.panda-pax-panel.is-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s linear 0s;
}

.panda-pax-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(0, 83, 156, 0.95) 0%, rgba(0, 166, 255, 0.85) 100%);
    color: #fff;
    flex-shrink: 0;
}

.panda-pax-panel-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.panda-pax-panel-avatar {
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
}

.panda-pax-panel-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.2;
}

.panda-pax-panel-subtitle {
    margin: 0;
    font-size: 0.75rem;
    opacity: 0.9;
}

.panda-pax-panel-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.panda-pax-search-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s;
}

.panda-pax-search-link:hover {
    background: rgba(255, 255, 255, 0.28);
    color: #fff;
}

@media (max-width: 420px) {
    .panda-pax-search-link span { display: none; }
    .panda-pax-search-link { padding: 0 9px; }
}

.panda-pax-icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.panda-pax-icon-btn:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* Chat body inside panel */
.panda-pax-chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--panda-bg);
}

#panda_chat_history.panda-chat-history {
    flex: 1;
    padding: 16px;
    padding-top: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

#panda_chat_history::-webkit-scrollbar {
    width: 6px;
}

#panda_chat_history::-webkit-scrollbar-thumb {
    background: var(--panda-accent);
    border-radius: 3px;
}

.panda-chat-empty {
    text-align: center;
    color: #94a3b8;
    font-size: 14px;
    line-height: 1.5;
    padding: 24px 12px;
    margin: auto 0;
}

.panda-chat-empty.is-hidden {
    display: none;
}

/* Bubbles */
#panda-pax-panel .chat-bubble {
    max-width: 92%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    margin-bottom: 12px;
    animation: pandaFadeIn 0.3s ease;
}

@keyframes pandaFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

#panda-pax-panel .chat-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--panda-accent) 0%, var(--panda-accent-light) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

#panda-pax-panel .chat-bubble.ai.with-avatar {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    align-self: flex-start;
    max-width: 95%;
    background: transparent;
    padding: 0;
    margin-bottom: 14px;
}

#panda-pax-panel .chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--panda-accent);
    flex-shrink: 0;
}

#panda-pax-panel .chat-bubble-content {
    flex: 1;
    background: white;
    color: #334155;
    border-radius: 14px;
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    min-width: 0;
}

#panda-pax-panel .profession-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

#panda-pax-panel .profession-button {
    background: white;
    color: var(--panda-accent);
    border: 1px solid #cbd5e1;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

#panda-pax-panel .profession-button:hover {
    background: linear-gradient(135deg, var(--panda-accent), var(--panda-accent-light));
    color: white;
    border-color: transparent;
}

/* Tool result cards – grid so text stays readable in the narrow panel.
   The JS sets inline display:flex which squeezes the text column to near-zero
   width in the ~400px panel; grid + grid-areas restacks it cleanly. */
#panda-pax-panel .ai-tool-item {
    display: grid !important;
    grid-template-columns: 56px minmax(0, 1fr);
    grid-template-areas:
        "img text"
        "actions actions";
    align-items: center !important;
    gap: 10px;
}

#panda-pax-panel .ai-tool-item > img {
    grid-area: img;
}

#panda-pax-panel .ai-tool-item > div:not(.ai-tool-actions) {
    grid-area: text;
    min-width: 0;
}

#panda-pax-panel .ai-tool-item .ai-tool-actions {
    grid-area: actions;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: center;
}

#panda-pax-panel .ai-tool-item strong {
    display: block;
    word-break: break-word;
    font-size: 14px;
    line-height: 1.3;
}

#panda-pax-panel .ai-tool-name-link {
    cursor: pointer;
    color: var(--panda-accent);
    text-transform: capitalize;
}

#panda-pax-panel .ai-tool-name-link:hover {
    text-decoration: underline;
}

/* Prisjakt / Delatool in chat */
#panda-pax-panel .prisjakt-price-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: linear-gradient(135deg, #f0f9f4, #e6f7ed);
    border-radius: 10px;
    border: 2px solid #00D084;
    min-width: 110px;
}

#panda-pax-panel .prisjakt-price-main {
    font-size: 17px;
    font-weight: 800;
    color: #00A86B;
}

#panda-pax-panel .prisjakt-price-label,
#panda-pax-panel .delatool-price-label {
    font-size: 9px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
}

#panda-pax-panel .prisjakt-shop-info {
    font-size: 9px;
    color: #555;
    text-align: center;
}

#panda-pax-panel .prisjakt-logo-small {
    height: 36px;
    max-width: 80px;
    object-fit: contain;
    background: white;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
}

#panda-pax-panel .delatool-price-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: #f0f7ff;
    border-radius: 10px;
    border: 1px solid var(--panda-accent);
    min-width: 100px;
    cursor: pointer;
}

#panda-pax-panel .delatool-price-main {
    font-size: 15px;
    font-weight: 700;
    color: var(--panda-accent);
}

#panda-pax-panel .delatool-logo-small {
    height: 28px;
    max-width: 70px;
    object-fit: contain;
}

#panda-pax-panel .add-to-cart-button-ai {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#panda-pax-panel .add-to-cart-button-ai.added {
    background: #6b7280;
    cursor: not-allowed;
}

#panda-pax-panel .overview-button-subtle {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--panda-accent);
    background: white;
    color: var(--panda-accent);
    cursor: pointer;
}

/* Input area */
.panda-pax-chat-input-area {
    padding: 12px 14px 14px;
    background: linear-gradient(135deg, rgba(0, 83, 156, 0.12), rgba(0, 166, 255, 0.1));
    border-top: 1px solid rgba(0, 83, 156, 0.25);
    flex-shrink: 0;
}

.panda-pax-chat-input-area .chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.panda-pax-chat-input-area .chat-input-container {
    flex: 1;
    position: relative;
}

#panda_ai_prompt {
    width: 100%;
    min-height: 44px;
    max-height: 100px;
    padding: 10px 52px 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    font-size: 16px;
    line-height: 1.4;
    resize: none;
    overflow-y: hidden;
    background: white;
}

#panda_submit_prompt {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--panda-accent), var(--panda-accent-light));
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#panda_submit_prompt:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: linear-gradient(135deg, #64748b, #94a3b8);
}

.panda-remaining-prompts {
    display: block;
    text-align: right;
    font-size: 11px;
    color: #94a3b8;
    margin-top: 6px;
    min-height: 14px;
}

.panda-pax-chat-input-area .chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.panda-pax-chat-input-area .suggestion-chip {
    background: rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 14px;
    cursor: pointer;
}

.panda-pax-chat-input-area .suggestion-chip:hover {
    background: var(--panda-accent);
    color: white;
}

/* Loading */
#panda-pax-panel #loading-text-container {
    text-align: center;
    margin: 8px 0;
}

#panda-pax-panel #loading-text {
    display: inline-block;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    width: auto;
    margin: 0;
}

#panda-pax-panel .panda-name {
    font-weight: 700;
}

#panda-pax-panel #neon-loading {
    display: block;
    height: 3px;
    background: linear-gradient(90deg, var(--panda-accent), var(--panda-accent-light), var(--panda-accent));
    background-size: 200% 100%;
    animation: pandaShimmer 1.5s infinite linear;
    margin: 8px 0;
    border-radius: 3px;
}

@keyframes pandaShimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Mobile fullscreen */
@media (max-width: 576px) {
    .panda-pax-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .panda-pax-launcher {
        bottom: 16px;
        right: 16px;
        padding: 7px 12px 7px 8px;
        gap: 8px;
        min-height: 48px;
    }

    .panda-pax-launcher-label {
        font-size: 12px;
    }

    .panda-pax-launcher-img {
        width: 32px;
        height: 32px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .panda-pax-launcher {
        animation: none !important;
    }
    .panda-pax-panel {
        transition: none;
    }
}
