/**
 * 9ブログ接客AI ウィジェット
 * セレクタは .nbcg-* に統一（既存 .nb-* / .pmgb-* と非衝突）。
 * 配色は nineblog.css の --nb-* トークンにフォールバック付きで追従する。
 */

#nbcgRoot {
    position: relative;
    z-index: 9000;
}

/* ---------- バブル ---------- */
.nbcg-bubble {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 1px solid var(--nb-accent-soft, #e0e7ff);
    background: var(--nb-accent, #6366f1);
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9001;
}
.nbcg-bubble:hover { transform: scale(1.06); }
.nbcg-bubble--hidden { display: none; }

/* ---------- パネル ---------- */
.nbcg-panel {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: min(360px, calc(100vw - 24px));
    max-height: min(560px, calc(100vh - 40px));
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    box-shadow: 0 12px 36px rgba(16, 24, 40, 0.22);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9002;
}
.nbcg-panel--open { display: flex; }

.nbcg-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--nb-accent, #6366f1);
    color: #fff;
}
.nbcg-head-title {
    font-weight: 700;
    font-size: 14px;
}
.nbcg-head-note {
    font-size: 11px;
    opacity: 0.85;
    margin-left: auto;
}
.nbcg-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}

.nbcg-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fafafa;
    min-height: 180px;
}

.nbcg-msg {
    max-width: 85%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.nbcg-msg--ai {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e5e7eb;
    color: var(--nb-text, #1f2937);
    border-bottom-left-radius: 4px;
}
.nbcg-msg--user {
    align-self: flex-end;
    background: var(--nb-accent, #6366f1);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* タイピングインジケータ */
.nbcg-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    min-height: 20px;
}
.nbcg-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: nbcg-blink 1.2s infinite ease-in-out;
}
.nbcg-typing span:nth-child(2) { animation-delay: 0.2s; }
.nbcg-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes nbcg-blink {
    0%, 80%, 100% { opacity: 0.25; }
    40% { opacity: 1; }
}

/* ---------- 体験入会（P3） ---------- */
.nbcg-trial {
    padding: 12px 14px;
    border-top: 1px solid #e5e7eb;
    background: var(--nb-accent-soft, #eef2ff);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.nbcg-trial-lead {
    margin: 0;
    font-size: 12.5px;
    color: var(--nb-text, #1f2937);
    font-weight: 600;
}
.nbcg-trial-name {
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: 13px;
}
.nbcg-trial-name:focus {
    outline: none;
    border-color: var(--nb-accent, #6366f1);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.nbcg-trial-consent {
    font-size: 12px;
    color: var(--nb-text-soft, #6b7280);
    display: flex;
    align-items: center;
    gap: 6px;
}
.nbcg-trial-btn {
    padding: 9px 12px;
    border: none;
    border-radius: 10px;
    background: var(--nb-accent, #6366f1);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}
.nbcg-trial-btn:hover { opacity: 0.9; }
.nbcg-trial-btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- 入力フォーム ---------- */
.nbcg-form {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}
.nbcg-input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: 13.5px;
}
.nbcg-input:focus {
    outline: none;
    border-color: var(--nb-accent, #6366f1);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.nbcg-send {
    padding: 9px 14px;
    border: none;
    border-radius: 10px;
    background: var(--nb-accent, #6366f1);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}
.nbcg-send:hover { opacity: 0.9; }

/* ---------- モバイル ---------- */
@media (max-width: 480px) {
    .nbcg-panel {
        right: 8px;
        bottom: 8px;
        width: calc(100vw - 16px);
        max-height: calc(100vh - 24px);
    }
    .nbcg-bubble {
        right: 14px;
        bottom: 14px;
    }
}
