/*
 * Edel AI Hybrid Chat — フロントウィジェット
 * すべてのセレクタを #edel-nbc-widget 配下にスコープし、詳細度を高めて
 * 設置先テーマのスタイル干渉（特に a / button の色）に強くしている。
 * 色など競合しやすいプロパティには !important を併用。
 */

#edel-nbc-widget {
    --c: var(--edel-nbc-base-color, #0073aa);
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

#edel-nbc-widget #edel-nbc-button {
    background: var(--c);
    color: #fff;
    padding: 12px 18px;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(0,0,0,.25);
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}
#edel-nbc-widget #edel-nbc-button .dashicons { font-size: 18px; width: 18px; height: 18px; }

#edel-nbc-widget #edel-nbc-window {
    position: absolute;
    bottom: 60px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#edel-nbc-widget .edel-nbc-header {
    background: var(--c);
    color: #fff;
    padding: 12px 16px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#edel-nbc-widget .edel-nbc-actions { display: flex; align-items: center; gap: 4px; }
#edel-nbc-widget #edel-nbc-close,
#edel-nbc-widget #edel-nbc-expand {
    background: none; border: none; color: #fff !important;
    line-height: 1; cursor: pointer; padding: 2px 4px;
    display: inline-flex; align-items: center; opacity: .9;
}
#edel-nbc-widget #edel-nbc-close { font-size: 22px; }
#edel-nbc-widget #edel-nbc-close:hover,
#edel-nbc-widget #edel-nbc-expand:hover { opacity: 1; }

/* 拡大表示（ページ中央に大画面） */
#edel-nbc-widget #edel-nbc-overlay {
    position: fixed; inset: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(2px);
    z-index: 99998;
}
#edel-nbc-widget.edel-nbc-expanded #edel-nbc-window {
    position: fixed;
    width: 640px; max-width: 92vw;
    height: 82vh; max-height: 82vh;
    top: 50%; left: 50%; right: auto; bottom: auto;
    transform: translate(-50%, -50%);
    z-index: 99999;
}

#edel-nbc-widget #edel-nbc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #f7f7f8;
}

#edel-nbc-widget .edel-nbc-message { display: flex; margin-bottom: 12px; }
#edel-nbc-widget .edel-nbc-message.user { justify-content: flex-end; }
#edel-nbc-widget .edel-nbc-message.ai { justify-content: flex-start; }

#edel-nbc-widget .edel-nbc-bubble {
    max-width: 80%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    color: #1a1a1a;
}
#edel-nbc-widget .edel-nbc-message.user .edel-nbc-bubble { background: var(--c); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
#edel-nbc-widget .edel-nbc-message.ai .edel-nbc-bubble { background: #fff; color: #1a1a1a; border: 1px solid #e3e3e6; border-bottom-left-radius: 4px; }

/* オペレーター（管理者）メッセージ */
#edel-nbc-widget .edel-nbc-message.admin { justify-content: flex-start; }
#edel-nbc-widget .edel-nbc-message.admin .edel-nbc-bubble { background: #e1f5fe; color: #0a3d52; border: 1px solid #b3e5fc; border-bottom-left-radius: 4px; white-space: pre-wrap; }
/* システム通知（中央・小） */
#edel-nbc-widget .edel-nbc-message.system { justify-content: center; }
#edel-nbc-widget .edel-nbc-message.system .edel-nbc-bubble { background: #fff3e0; color: #7a4f01; font-size: 12px; max-width: 90%; text-align: center; border-radius: 8px; }

/* AIバブル内のMarkdown要素 */
#edel-nbc-widget .edel-nbc-message.ai .edel-nbc-bubble p { margin: 0 0 8px; }
#edel-nbc-widget .edel-nbc-message.ai .edel-nbc-bubble p:last-child { margin-bottom: 0; }
#edel-nbc-widget .edel-nbc-message.ai .edel-nbc-bubble ul,
#edel-nbc-widget .edel-nbc-message.ai .edel-nbc-bubble ol { margin: 4px 0 8px; padding-left: 1.4em; }
#edel-nbc-widget .edel-nbc-message.ai .edel-nbc-bubble li { margin: 2px 0; }
#edel-nbc-widget .edel-nbc-message.ai .edel-nbc-bubble code { background: #f2f2f5; border-radius: 4px; padding: 1px 4px; font-size: .9em; }
#edel-nbc-widget .edel-nbc-message.ai .edel-nbc-bubble .edel-nbc-h { display: block; margin: 6px 0 2px; }
#edel-nbc-widget .edel-nbc-message.ai .edel-nbc-bubble a { color: var(--c) !important; text-decoration: underline; }

#edel-nbc-widget .edel-nbc-ref { color: var(--c); font-weight: 700; font-size: .7em; }

#edel-nbc-widget .edel-nbc-citations {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #ddd;
    font-size: 12px;
}
#edel-nbc-widget .edel-nbc-cite-label { display: block; color: #888; margin-bottom: 4px; }
#edel-nbc-widget .edel-nbc-chip {
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    background: #f0f4f8;
    border: 1px solid #d6e0ea;
    color: #334455 !important;
    -webkit-text-fill-color: #334455; /* テーマのリンク色に上書きされないよう字面色を固定 */
    border-radius: 12px;
    padding: 3px 10px;
    margin: 0 0 4px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#edel-nbc-widget a.edel-nbc-chip.edel-nbc-chip-link { text-decoration: none !important; cursor: pointer; }
/* ホバー：詳細度を最大限上げ、color と -webkit-text-fill-color の両方で白を強制（テーマのa:hover対策） */
#edel-nbc-widget a.edel-nbc-chip.edel-nbc-chip-link:hover,
#edel-nbc-widget a.edel-nbc-chip.edel-nbc-chip-link:focus {
    background: var(--c) !important;
    border-color: var(--c) !important;
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
}

#edel-nbc-widget .edel-nbc-status { color: #888; font-style: italic; }
#edel-nbc-widget .edel-nbc-error { color: #d63638; }

#edel-nbc-widget .edel-nbc-dots i {
    display: inline-block; width: 6px; height: 6px; margin: 0 2px;
    background: #bbb; border-radius: 50%;
    animation: edel-nbc-blink 1.2s infinite both;
}
#edel-nbc-widget .edel-nbc-dots i:nth-child(2) { animation-delay: .2s; }
#edel-nbc-widget .edel-nbc-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes edel-nbc-blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

#edel-nbc-widget .edel-nbc-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #eee;
    background: #fff;
}
#edel-nbc-widget #edel-nbc-input {
    flex: 1;
    resize: none;
    border: 1px solid #ccc;
    border-radius: 18px;
    padding: 9px 14px;
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
    outline: none;
    font-family: inherit;
    color: #1a1a1a;
    background: #fff;
}
#edel-nbc-widget #edel-nbc-input:focus { border-color: var(--c); }
#edel-nbc-widget #edel-nbc-send {
    background: var(--c) !important;
    color: #fff !important;
    border: none;
    border-radius: 18px;
    padding: 9px 16px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
}
#edel-nbc-widget #edel-nbc-send:disabled { opacity: .5; cursor: default; }

#edel-nbc-widget .edel-nbc-footer { padding: 6px 10px; text-align: center; }
#edel-nbc-widget .edel-nbc-footer button {
    background: none; border: none; cursor: pointer;
    font-size: 12px; color: var(--c) !important; padding: 2px 6px; margin: 0 4px;
}
#edel-nbc-widget .edel-nbc-footer button:hover { text-decoration: underline; }
#edel-nbc-widget .edel-nbc-credit { font-size: 10px; color: #aaa; margin-top: 2px; }
