/* Product Knowledge Bot - Chat Widget */
#pkb-widget-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
#pkb-toggle {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: #2271b1;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.2);
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}
#pkb-toggle:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(0,0,0,0.25); }

/* ----- Teaser bubble (pre-open nudge) ----- */
#pkb-teaser {
    display: none;
    align-items: center;
    gap: 10px;
    position: absolute;
    bottom: 72px;
    right: 0;
    max-width: 360px;
    width: 300px;
    background: #fff;
    color: #1d2327;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 12px 14px;
    cursor: pointer;
    font-size: 13.5px;
    line-height: 1.4;
    border: 1px solid #eee;
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 0;
    transform: translateY(8px);
    z-index: 5;
}
.pkb-teaser-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.pkb-teaser-greeting {
    font-weight: 700;
    font-size: 14px;
    color: #1d2327;
    line-height: 1.3;
}
.pkb-teaser-greeting.pkb-teaser-fade {
    opacity: 0;
    transition: opacity 0.2s ease;
}
.pkb-teaser-greeting {
    transition: opacity 0.2s ease;
}
#pkb-teaser.visible {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}
#pkb-teaser:hover { box-shadow: 0 6px 24px rgba(0,0,0,0.22); }
.pkb-teaser-text {
    flex: 1;
    word-wrap: break-word;
    transition: opacity 0.2s ease;
}
.pkb-teaser-text.pkb-teaser-fade {
    opacity: 0;
    transition: opacity 0.2s ease;
}
.pkb-teaser-close {
    background: none;
    border: none;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    padding: 2px;
    flex-shrink: 0;
    line-height: 1;
}
.pkb-teaser-close:hover { color: #555; }
#pkb-widget-container.open #pkb-teaser { display: none; }
@media (max-width: 480px) {
    #pkb-teaser {
        max-width: calc(100vw - 24px);
        font-size: 13px;
    }
    #pkb-widget-container.expanded #pkb-panel {
        width: 100vw; max-width: 100vw;
        height: 100vh; max-height: 100vh;
        bottom: 0; right: 0;
        transform: none;
        border-radius: 0;
    }
}
#pkb-panel {
    display: none;
    flex-direction: column;
    position: fixed; bottom: 30px; right: 16px;
    width: 380px; max-width: calc(100vw - 32px);
    height: 560px; max-height: calc(100vh - 54px);
    background: #fff;
    border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    overflow: hidden;
    font-size: 14px; line-height: 1.5; color: #1d2327;
}
#pkb-widget-container.open #pkb-panel { display: flex; }
#pkb-widget-container.open #pkb-toggle { display: none; }
#pkb-header {
    background: #2271b1; color: #fff;
    padding: 10px 18px;
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 600; font-size: 15px; flex-shrink: 0;
}
#pkb-header-left {
    display: flex; flex-direction: column;
    gap: 3px;
    min-width: 0;
}
#pkb-header-title {
    line-height: 1.3;
}
/* Online status indicator below bot name */
#pkb-header-status {
    display: flex; align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 400;
    opacity: 0.9;
    line-height: 1;
    transition: opacity 0.3s ease;
}
#pkb-header-status.pkb-status-offline {
    opacity: 0.6;
}
.pkb-status-dot-online {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}
#pkb-header-status.pkb-status-offline .pkb-status-dot-online {
    background: #9ca3af;
    box-shadow: none;
}
#pkb-header-close {
    background: none; border: none; color: #fff; cursor: pointer;
    font-size: 18px; opacity: 0.8; padding: 0 4px;
}
#pkb-header-close:hover { opacity: 1; }
#pkb-header-actions {
    display: flex; align-items: center; gap: 6px;
}
#pkb-header-expand,
#pkb-header-collapse {
    background: none; border: none; color: #fff; cursor: pointer;
    opacity: 0.8; padding: 0 4px;
    display: flex; align-items: center; justify-content: center;
}
#pkb-header-expand:hover,
#pkb-header-collapse:hover { opacity: 1; }

/* ----- Expanded state ----- */
#pkb-widget-container.expanded #pkb-panel {
    width: 580px;
    max-width: calc(100vw - 32px);
    height: calc(100vh - 40px);
    max-height: calc(100vh - 40px);
    border-radius: 12px;
}
#pkb-widget-container.expanded #pkb-toggle { display: none; }
#pkb-messages {
    flex: 1; overflow-y: auto;
    padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
    scroll-behavior: smooth;
}
#pkb-messages::-webkit-scrollbar { width: 6px; }
#pkb-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.pkb-msg {
    display: flex;
    margin-bottom: 2px;
    align-items: flex-end;
}
.pkb-user { justify-content: flex-end; }
.pkb-bot { justify-content: flex-start; }

/* ----- Avatars ----- */
.pkb-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.pkb-bot .pkb-avatar {
    background: #e8e8eb;
    margin-right: 8px;
}
.pkb-user .pkb-avatar {
    background: var(--pkb-color, #2271b1);
    margin-left: 8px;
}
.pkb-avatar svg {
    width: 18px; height: 18px;
    display: block;
}

/* ----- Message Bubbles ----- */
.pkb-msg-content {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
}
.pkb-msg-body {
    white-space: pre-wrap;
}
.pkb-user .pkb-msg-content {
    background: var(--pkb-color, #2271b1); color: #fff;
    border-bottom-right-radius: 4px;
}
.pkb-bot .pkb-msg-content {
    background: #f0f0f1; color: #1d2327;
    border-bottom-left-radius: 4px;
    text-align: left;
}

/* Agent name label inside bot bubble */
.pkb-msg-sender-name {
    font-size: 11px;
    font-weight: 600;
    color: #888;
    margin-bottom: 2px;
    line-height: 1.3;
}
.pkb-user .pkb-msg-sender-name {
    text-align: right;
}
.pkb-msg-time {
    font-size: 10px;
    color: #aaa;
    margin-top: 3px;
    text-align: right;
    line-height: 1.2;
}
.pkb-msg.pkb-user .pkb-msg-time {
    text-align: left;
}

/* ----- System notification (agent joined/left, etc.) ----- */
.pkb-system {
    justify-content: center !important;
    margin: 6px 0;
}
.pkb-system-msg {
    display: inline-block;
    background: #e8e8eb;
    color: #555;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 10px;
    text-align: center;
    max-width: 85%;
    line-height: 1.4;
}
.pkb-msg-content a { color: inherit; text-decoration: underline; }
.pkb-msg-content strong { font-weight: 700; }
.pkb-msg-content em { font-style: italic; }
.pkb-msg-content code {
    background: rgba(0,0,0,0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.9em;
}
.pkb-user .pkb-msg-content code {
    background: rgba(255,255,255,0.2);
}
.pkb-msg-content u { text-decoration: underline; }
.pkb-msg-content s { text-decoration: line-through; }
.pkb-msg-content ul, .pkb-msg-content ol {
    margin: 6px 0;
    padding-left: 20px;
}
.pkb-msg-content li {
    margin-bottom: 3px;
}
.pkb-msg-content h3, .pkb-msg-content h4 {
    margin: 8px 0 4px;
    font-size: 1em;
}

/* ----- Typing Indicator (animated dots + cycling status) ----- */
.pkb-typing {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
}
.pkb-typing-dots {
    display: flex; gap: 4px; align-items: center;
}
.pkb-typing-dots span {
    width: 7px; height: 7px; background: #888; border-radius: 50%;
    animation: pkb-bounce 1.4s infinite both;
}
.pkb-typing-dots span:nth-child(1) { animation-delay: 0s; }
.pkb-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.pkb-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pkb-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Cycling status text */
.pkb-typing-status {
    font-size: 11px;
    color: #888;
    position: relative;
    height: 16px;
    line-height: 16px;
    overflow: hidden;
    min-width: 90px;
}
.pkb-typing-status span {
    display: block;
    position: absolute;
    width: 100%;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.pkb-typing-status span.active {
    opacity: 1;
    transform: translateY(0);
}

/* ----- Status row (below bot bubble, outside bubble) ----- */
#pkb-typing-indicator {
    flex-wrap: wrap;
}
.pkb-typing-status-row {
    width: 100%;
    padding-left: 38px; /* align with bubble text, avatar is 30px + 8px margin */
    margin-top: 2px;
    margin-bottom: 6px;
}

/* ----- "Start New Chat" button (shown when chat is resolved) ----- */
#pkb-new-chat-btn {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background: var(--pkb-color, #2271b1);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    margin: 0;
}
#pkb-new-chat-btn:hover {
    opacity: 0.9;
    transform: scale(1.02);
}
#pkb-new-chat-btn:active {
    transform: scale(0.98);
}

/* ----- Input Area ----- */
#pkb-input-area {
    flex-shrink: 0; display: flex;
    align-items: flex-end;
    padding: 12px; border-top: 1px solid #e5e5e5; gap: 8px;
    background: #fff;
}
#pkb-input {
    flex: 1;
    border: 1px solid #dcdcde; border-radius: 12px;
    padding: 10px 16px; font-size: 14px; outline: none;
    transition: border-color 0.2s;
    resize: none; overflow-y: auto;
    font-family: inherit; line-height: 1.4;
    min-height: 40px; max-height: 100px;
}
#pkb-input:focus { border-color: var(--pkb-color, #2271b1); }
#pkb-send {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--pkb-color, #2271b1); border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background 0.2s;
}
#pkb-send:hover { opacity: 0.9; }
#pkb-send:disabled { opacity: 0.4; cursor: not-allowed; }
/* Robust against theme CSS conflicts: always show the send icon */
#pkb-widget-container #pkb-send {
    color: #fff !important;
}
#pkb-widget-container #pkb-send svg,
#pkb-widget-container .pkb-icon-send {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    fill: currentColor !important;
    color: #fff !important;
    width: 20px !important;
    min-width: 20px !important;
    max-width: 20px !important;
    height: 20px !important;
    min-height: 20px !important;
    max-height: 20px !important;
    flex: 0 0 20px !important;
    overflow: visible !important;
}
#pkb-widget-container #pkb-send svg path,
#pkb-widget-container .pkb-icon-send path {
    fill: #fff !important;
    visibility: visible !important;
    opacity: 1 !important;
}
/* Robust: always show the toggle (chat bubble) icon at a good size */
#pkb-widget-container #pkb-toggle svg {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    fill: #fff !important;
    width: 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    max-height: 32px !important;
    flex: 0 0 32px !important;
    overflow: visible !important;
}
#pkb-widget-container #pkb-toggle svg path {
    fill: #fff !important;
    visibility: visible !important;
    opacity: 1 !important;
}
/* Normalize chat input sizing against theme button/textarea styles */
#pkb-widget-container #pkb-input-area {
    align-items: flex-end !important;
    gap: 10px !important;
}
#pkb-widget-container #pkb-input {
    height: 80px !important;
    min-height: 80px !important;
    max-height: 110px !important;
    padding: 11px 16px !important;
    line-height: 22px !important;
    box-sizing: border-box !important;
}
#pkb-widget-container #pkb-send {
    width: 46px !important;
    min-width: 46px !important;
    max-width: 46px !important;
    height: 46px !important;
    min-height: 46px !important;
    max-height: 46px !important;
    flex: 0 0 46px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 50% !important;
    aspect-ratio: 1 / 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
}

/* ----- Chat Popup (name/email capture) ----- */
#pkb-chat-popup {
    display: none;
    flex-shrink: 0;
    background: #f7f8fa;
    border-top: 1px solid #e5e5e5;
    padding: 10px 16px 14px;
    box-sizing: border-box;
}
#pkb-chat-popup.open { display: block; }
#pkb-chat-popup-inner {
    position: relative;
    width: 100%;
    max-width: none;
    box-shadow: none;
    text-align: left;
}
#pkb-chat-popup-inner #pkb-popup-close {
    position: absolute;
    top: -2px;
    right: 4px;
    width: auto;
    padding: 2px 6px;
    margin: 0;
    background: none;
    color: #999;
    border: none;
    border-radius: 0;
    cursor: pointer;
    font-size: 18px;
    font-weight: 400;
    line-height: 1;
}
#pkb-chat-popup-inner #pkb-popup-close:hover { color: #333; }
#pkb-chat-popup-inner p {
    margin: 0 0 6px 0;
    font-size: 12px;
    color: #333;
    font-weight: 600;
    line-height: 1.3;
}
#pkb-chat-popup-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-bottom: 6px;
}
#pkb-chat-popup-inner input {
    width: 100%;
    min-width: 0;
    padding: 6px 8px;
    margin: 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
    outline: none;
    background: #fff;
}
#pkb-chat-popup-inner input:focus {
    border-color: var(--pkb-color, #2271b1);
    box-shadow: 0 0 0 1px var(--pkb-color, #2271b1);
}
#pkb-chat-popup-inner button {
    width: 100%;
    padding: 7px 10px;
    background: var(--pkb-color, #2271b1);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}
#pkb-chat-popup-inner button:disabled {
    opacity: 0.6;
    cursor: default;
}
#pkb-chat-popup-skip {
    margin-top: 12px;
    font-size: 12px;
    color: #999;
    cursor: pointer;
    display: inline-block;
}
#pkb-chat-popup-skip:hover { color: #666; }
#pkb-chat-popup-status {
    font-size: 12px;
    margin-top: 6px;
    min-height: 0;
}
@media (max-width: 420px) {
    #pkb-chat-popup { padding: 10px 14px 12px; }
    #pkb-chat-popup-fields { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    #pkb-panel {
        right: 12px; width: calc(100vw - 24px);
        height: calc(100vh - 100px); max-height: calc(100vh - 100px);
    }
}

/* ----- "Powered by WPExperts.io" footer (visible only when chat panel is open) ----- */
#pkb-footer {
    display: none;
    position: fixed;
    right: 20px;
    bottom: 10px;
    font-size: 11px;
    color: #a7aaad;
    line-height: 1.4;
    text-align: right;
    white-space: nowrap;
    z-index: 100000;
}
#pkb-widget-container.open #pkb-footer { display: block; }
#pkb-footer a {
    color: #c3c4c7;   /* light gray link */
    text-decoration: none;
    transition: color 0.2s;
}
#pkb-footer a:hover { color: #2271b1; text-decoration: underline; }
