/* Admin Dashboard - Chatbot Management */

.chatbot-card-header {
    padding: 0.75rem 1.5rem !important;
}

.chatbot-title {
    float: right;
    line-height: 2.2;
}

.chatbot-back-btn {
    float: left;
}

.chatbot-textarea-sm {
    font-family: 'RubikLocal', sans-serif;
    font-size: 0.9rem;
}

.chatbot-textarea-lg {
    font-family: monospace, 'RubikLocal', sans-serif;
    font-size: 0.85rem;
    min-height: 400px;
}

.chatbot-module-textarea {
    font-family: monospace, 'RubikLocal', sans-serif;
    font-size: 0.82rem;
    min-height: 180px;
}

.chatbot-module-header:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.chatbot-module-chars {
    font-size: 0.7rem;
    min-width: 50px;
    text-align: center;
}

.chatbot-scan-log {
    background: #1e1e2e;
    color: #cdd6f4;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.8rem;
    padding: 12px 16px;
    border-radius: 8px;
    max-height: 350px;
    overflow-y: auto;
    direction: ltr;
    text-align: left;
    line-height: 1.7;
}

.chatbot-scan-log .log-ok {
    color: #a6e3a1;
}

.chatbot-scan-log .log-err {
    color: #f38ba8;
}

.chatbot-scan-log .log-warn {
    color: #f9e2af;
}

.chatbot-scan-log .log-info {
    color: #89b4fa;
}

.chatbot-scan-log .log-dim {
    color: #6c7086;
}

.chatbot-scan-log .log-head {
    color: #cba6f7;
    font-weight: bold;
}

/* Conversation Log in Modal */
.chatbot-conversation-log {
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem;
    background: var(--bs-tertiary-bg, #f8f9fa);
    border-radius: 0.5rem;
}

.chatbot-msg-user,
.chatbot-msg-assistant {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    max-width: 85%;
}

.chatbot-msg-user {
    background: var(--pg-chat-primary-light, #e3f2fd);
    margin-right: auto;
    margin-left: 15%;
}

.chatbot-msg-assistant {
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #dee2e6);
    margin-left: auto;
    margin-right: 15%;
}

.chatbot-msg-label {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--bs-secondary-color, #6c757d);
}

.chatbot-msg-content {
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Rating Stars */
.chatbot-rating-stars {
    font-size: 1.5rem;
    cursor: pointer;
}

.chatbot-rating-stars i {
    color: var(--bs-border-color, #dee2e6);
    transition: color 0.15s;
}

.chatbot-rating-stars i:hover,
.chatbot-rating-stars i:hover ~ i {
    color: #ffc107;
}

.chatbot-star-active {
    color: #ffc107 !important;
}

/* Per-message rating */
.chatbot-msg-rating {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--bs-border-color, #e9ecef);
}

.chatbot-msg-stars {
    font-size: 1rem;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.chatbot-msg-stars i {
    color: var(--bs-border-color, #dee2e6);
    transition: color 0.15s;
}

.chatbot-msg-stars i:hover,
.chatbot-msg-stars i:hover ~ i {
    color: #ffc107;
}

.chatbot-msg-feedback-input {
    font-size: 0.8rem !important;
    padding: 0.2rem 0.5rem !important;
    max-width: 280px;
}

/* Frontend Chat Widget Styles */

/* Auto-adapt to panel: admin uses --dashui-primary (purple), regular uses --pg-chat-primary (blue) */
:root {
    --pg-ai-primary: var(--bs-primary, var(--dashui-primary, #152b78));
}

#pgLoginChatBody {
    min-height: 0;
}

.pg-ai-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
}

.pg-ai-chat-bubble {
    margin-bottom: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 1rem;
    max-width: 85%;
    font-size: 0.85rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    text-align: right;
}

.pg-ai-chat-bubble-user {
    background: var(--pg-ai-primary);
    color: #fff;
    align-self: flex-start;
    border-bottom-right-radius: 0.25rem;
}

.pg-ai-chat-bubble-ai {
    background: var(--pg-chat-bubble-them, #f0f0f0);
    color: var(--pg-chat-text, #333);
    align-self: flex-end;
    border-bottom-left-radius: 0.25rem;
}

.pg-ai-chat-input-wrap {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
    border-top: 1px solid var(--pg-chat-border, #eee);
    flex-shrink: 0;
}

.pg-ai-chat-input-wrap input {
    flex: 1;
    border: 1px solid var(--pg-chat-border, #ddd);
    border-radius: 1.5rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    outline: none;
    direction: rtl;
    background: var(--bs-body-bg, #fff);
    color: var(--pg-chat-text, inherit);
}

.pg-ai-chat-input-wrap input:focus {
    border-color: var(--pg-ai-primary);
}

.pg-ai-chat-send-btn {
    background: var(--pg-ai-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.pg-ai-chat-send-btn:hover {
    background: var(--pg-ai-primary);
}

.pg-ai-chat-typing {
    display: inline-flex;
    gap: 4px;
    padding: 4px 8px;
}

.pg-ai-chat-typing span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: pgAiTyping 1.2s infinite;
}

.pg-ai-chat-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.pg-ai-chat-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pgAiTyping {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

.pg-ai-chat-escalate-btn {
    display: block;
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.5rem;
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--pg-ai-primary);
    color: var(--pg-ai-primary);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    text-align: center;
}

.pg-ai-chat-escalate-btn:hover {
    background: var(--pg-chat-primary-light, #f5f3ff);
}

.pg-ai-chat-navigate-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 6px 14px;
    background: var(--pg-ai-primary);
    color: #fff !important;
    border: none;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none !important;
    transition: opacity 0.2s;
}

.pg-ai-chat-navigate-btn:hover {
    opacity: 0.85;
    color: #fff !important;
}

.pg-ai-chat-navigate-btn i {
    font-size: 0.9rem;
}

.pg-ai-chat-back-btn {
    background: none;
    border: none;
    color: var(--pg-ai-primary);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.25rem 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.pg-ai-chat-bubble a {
    color: var(--pg-ai-primary);
    text-decoration: underline;
    word-break: break-all;
}

.pg-ai-chat-bubble-user a {
    color: #fff;
}

/* Login page standalone AI chat widget */
.pg-login-chat-toggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #152b78;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1056;
    font-size: 1.75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    padding: 0;
}

.pg-login-chat-toggle i {
    margin: 0 !important;
    padding: 0 !important;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-size: 1.75rem;
}

.pg-login-chat-toggle:hover {
    transform: scale(1.05);
}

.pg-login-chat-widget {
    position: fixed;
    bottom: 90px;
    left: 20px;
    width: 360px;
    height: 520px;
    max-height: calc(100vh - 110px);
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    display: none;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    direction: rtl;
    --pg-ai-primary: #152b78;
}

.pg-login-chat-widget.open {
    display: flex;
}

.pg-login-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    background: #152b78;
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.pg-login-chat-subtitle {
    font-weight: 400;
    font-size: 0.78rem;
    opacity: 0.7;
}

.pg-login-chat-close-btn {
    color: rgba(255, 255, 255, 0.8) !important;
    line-height: 1;
    font-size: 1.1rem;
}

.pg-login-chat-close-btn:hover {
    color: #fff !important;
}

.pg-login-escalate-wrap {
    padding: 0 0.5rem;
    display: none;
    direction: rtl;
}

.pg-login-escalate-wrap.visible {
    display: block;
}

.pg-login-prechat {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    gap: 0.75rem;
    direction: rtl;
    overflow-y: auto;
}

.pg-login-prechat-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1a1a2e;
    text-align: center;
    margin-bottom: 0.25rem;
}

.pg-login-prechat-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.pg-login-prechat-field label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #555;
}

.pg-login-prechat-field input:not([type="radio"]),
.pg-login-prechat-field select,
.pg-login-prechat-field textarea {
    border: 1px solid #ddd;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    outline: none;
    direction: rtl;
    resize: none;
}

.pg-login-prechat-field input[dir="ltr"] {
    text-align: left;
}

.pg-login-prechat-field input:not([type="radio"]):focus,
.pg-login-prechat-field select:focus,
.pg-login-prechat-field textarea:focus {
    border-color: #152b78;
}


.pg-login-prechat .form-check {
    padding: 0;
    margin: 0;
}

.pg-login-prechat .form-check .form-check-input {
    float: none;
    margin: 0;
}

.pg-login-escalate-info {
    padding: 0.5rem 0.75rem;
    background: #f0f4ff;
    border-bottom: 1px solid #dde3f0;
    font-size: 0.8rem;
    color: #152b78;
    font-weight: 500;
    direction: rtl;
    text-align: center;
    flex-shrink: 0;
}

.pg-login-prechat-btn {
    margin-top: 0.5rem;
    background: #152b78;
    color: #fff;
    border: none;
    border-radius: 0.5rem;
    padding: 0.6rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.pg-login-prechat-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 576px) {
    .pg-login-chat-widget {
        bottom: 0;
        left: 0;
        width: 100vw;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
    }

    .pg-login-chat-toggle {
        bottom: 16px;
        left: 16px;
    }
}

/* ===== AI Interactive Guides ===== */

/* --- Trainings index card --- */
.pg-ai-guides-card {
    border: 1px solid rgba(245, 158, 11, 0.3);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.pg-ai-guides-card:hover {
    border-color: rgba(245, 158, 11, 0.6);
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.15);
}

.pg-ai-guides-icon {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
}

/* --- Guide recorder floating bar --- */
.pg-guide-recorder-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100000;
    background: #1e293b;
    border-radius: 12px;
    padding: 10px 18px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    direction: rtl;
}

.pg-guide-recorder-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

.pg-guide-recorder-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
    animation: pg-rec-blink 1s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pg-rec-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.pg-guide-recorder-title {
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
}

.pg-guide-recorder-count {
    color: #94a3b8;
    font-size: 0.85rem;
}

.pg-guide-recorder-btn {
    font-size: 0.8rem;
    padding: 4px 12px;
    border-radius: 6px;
}

/* --- Guide recorder overlay & picking --- */
.pg-guide-recorder-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    pointer-events: none;
}

.pg-guide-picking * {
    cursor: crosshair !important;
}

.pg-guide-highlight {
    outline: 3px solid #f59e0b !important;
    outline-offset: 2px;
    border-radius: 4px;
    transition: outline-color 0.2s;
}

/* --- Guide player fallback popup --- */
.pg-guide-fallback {
    position: fixed;
    inset: 0;
    z-index: 100001;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
}

.pg-guide-fallback-inner {
    background: #fff;
    border-radius: 14px;
    padding: 24px 28px;
    max-width: 380px;
    width: 90%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    direction: rtl;
    text-align: right;
}

.pg-guide-fallback-step {
    font-size: 0.78rem;
    color: #94a3b8;
    margin-bottom: 4px;
}

.pg-guide-fallback-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 6px;
}

.pg-guide-fallback-desc {
    font-size: 0.9rem;
    color: #475569;
    margin-bottom: 8px;
    line-height: 1.5;
}

.pg-guide-fallback-page {
    color: #94a3b8;
    margin-bottom: 8px;
}

/* --- Support widget guide list item --- */
.pg-support-guide-item {
    transition: background 0.15s;
}

.pg-support-guide-item:hover {
    background: var(--bs-tertiary-bg, #f8fafc) !important;
}

/* --- Guide action bar (floating bottom bar during "performing" phase) --- */
.pg-guide-action-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100000;
    background: #1e293b;
    border-radius: 16px;
    padding: 0;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.06);
    direction: rtl;
    min-width: 380px;
    max-width: 90vw;
    overflow: hidden;
    animation: pgGuideBarSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.pg-guide-action-bar::before {
    content: '';
    display: block;
    height: 3px;
    width: var(--pg-guide-progress, 0%);
    margin-left: auto;
    background: linear-gradient(to left, var(--dashui-primary-super-light), var(--dashui-primary));
    transition: width 0.4s ease;
}

@keyframes pgGuideBarSlideUp {
    from { transform: translateX(-50%) translateY(30px); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

.pg-guide-action-bar-progress-wrap {
    display: none;
}

.pg-guide-action-bar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    white-space: nowrap;
}

.pg-guide-action-bar-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.pg-guide-action-bar-step {
    font-size: 0.8rem;
    color: var(--dashui-primary-super-light);
    font-weight: 700;
    letter-spacing: 0.03em;
}

.pg-guide-action-bar-title {
    font-size: 0.95rem;
    color: #e2e8f0;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pg-guide-action-bar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.pg-guide-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s ease;
}

.pg-guide-btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: #cbd5e1;
    font-size: 1rem;
    padding: 0;
}

.pg-guide-btn-icon:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.pg-guide-action-bar .btn {
    height: 38px;
    padding: 0 1.2rem;
    font-size: 0.85rem;
    border-radius: 10px;
    box-shadow: none;
}

.pg-guide-btn-cancel {
    color: #64748b;
}

.pg-guide-btn-cancel:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

/* --- Guide unsaved changes warning --- */
.pg-guide-unsaved-warning {
    position: fixed;
    inset: 0;
    z-index: 100002;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
}

.pg-guide-unsaved-warning-inner {
    background: #fff;
    border-radius: 14px;
    padding: 28px 32px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    direction: rtl;
    text-align: center;
}

/* --- Bootstrap tooltips for guide action bar --- */
.pg-guide-action-bar-tooltip.tooltip {
    z-index: 100001 !important;
    opacity: 1 !important;
}

/* --- Guide info tooltip (above action bar) --- */
.pg-guide-info-tip {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 10px;
    background: #334155;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 14px 18px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    min-width: 250px;
    max-width: 350px;
    direction: rtl;
    text-align: right;
    white-space: normal;
    animation: pgGuideTipFadeIn 0.2s ease;
}

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

.pg-guide-info-tip .pg-guide-fallback-title {
    color: #e2e8f0;
}

.pg-guide-info-tip .pg-guide-fallback-desc {
    color: #94a3b8;
}

/* --- Guide cancel link --- */
.pg-guide-cancel-link {
    display: block;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.pg-guide-cancel-link:hover {
    color: #64748b;
}

/* --- Chat guide start button --- */
.pg-ai-chat-guide-btn {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.pg-ai-chat-guide-btn:hover {
    opacity: 0.85;
}

.pg-guide-popover .driver-popover-turn-off-container,
.pg-guide-popover .driver-popover-footer {
    display: none !important;
}
