/* ══════════════════════════════════════════════
   AI Concierge — style.css
   既存サイトのカラーシステムに合わせた調整版
   ライト / ダークモード両対応
   ══════════════════════════════════════════════ */

/* ── 変数（ライトモード） ── */
:root {
    /* サイト既存変数を継承・参照 */
    --primary:       #0056b3;   /* サイトの --link-color */
    --primary-dark:  #003d80;
    --primary-rgb:   0, 86, 179;

    --bg-card:       #ffffff;   /* --section-bg */
    --bg-chat:       #f9f9fa;   /* --bg-color */
    --bg-ai:         #f0f7ff;   /* --quote-bg */
    --bg-user:       #0056b3;
    --border:        #e1e4e8;   /* --border-color */

    --text-main:     #333333;   /* --text-color */
    --text-sub:      #555555;   /* --comment-text */
    --text-muted:    #888888;

    --green:         #28a745;
    --red:           #dc3545;
    --amber:         #f59e0b;

    --shadow-card:   0 4px 16px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05);
    --radius-card:   10px;
    --radius-msg:    16px;
}

/* ── 変数（ダークモード） ── */
@media (prefers-color-scheme: dark) {
    :root {
        --primary:       #66b2ff;   /* サイトの dark --link-color */
        --primary-dark:  #99ccff;
        --primary-rgb:   102, 178, 255;

        --bg-card:       #1e1e1e;   /* --section-bg dark */
        --bg-chat:       #121212;   /* --bg-color dark */
        --bg-ai:         #0f2942;   /* --quote-bg dark */
        --bg-user:       #0051a8;
        --border:        #333333;   /* --border-color dark */

        --text-main:     #e0e0e0;   /* --text-color dark */
        --text-sub:      #aaaaaa;   /* --comment-text dark */
        --text-muted:    #666666;

        --green:         #4caf82;
        --red:           #e57373;
        --amber:         #ffb74d;

        --shadow-card:   0 4px 20px rgba(0,0,0,0.4), 0 1px 4px rgba(0,0,0,0.3);
    }
}

/* ── リセット ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ══════════════════════════════════════════════
   メインカード — 既存 section と統一感
   ══════════════════════════════════════════════ */
.ai-concierge {
    width: 100%;
    max-width: 520px;
    height: 92vh;
    max-height: 760px;
    margin: 0 auto;
    background: var(--bg-card);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ══════════════════════════════════════════════
   ヘッダー
   ══════════════════════════════════════════════ */
.concierge-header {
    padding: 14px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.title-group .icon {
    font-size: 20px;
    line-height: 1;
}

.concierge-header h1 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: 0.01em;
    border-bottom: none;
    padding-bottom: 0;
    margin-top: 0;
}

/* ── ステータスバッジ ── */
#status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-chat);
    color: var(--text-sub);
    transition: background .3s, color .3s, border-color .3s;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background .3s, box-shadow .3s;
}

/* オンライン */
.status-online {
    background: rgba(40, 167, 69, 0.08);
    color: var(--green);
    border-color: rgba(40, 167, 69, 0.25);
}
.status-online .dot {
    background: var(--green);
    box-shadow: 0 0 5px var(--green);
}

/* 接続中 */
.status-pending {
    background: rgba(245, 158, 11, 0.08);
    color: var(--amber);
    border-color: rgba(245, 158, 11, 0.3);
}
.status-pending .dot {
    background: var(--amber);
    box-shadow: 0 0 5px var(--amber);
    animation: dotPulse .8s infinite;
}

/* オフライン */
.status-offline {
    background: rgba(220, 53, 69, 0.07);
    color: var(--red);
    border-color: rgba(220, 53, 69, 0.2);
}
.status-offline .dot { background: var(--red); }

@keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .25; }
}

/* ══════════════════════════════════════════════
   チャットエリア
   ══════════════════════════════════════════════ */
.chat-main {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--bg-chat);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* スクロールバー */
.chat-main::-webkit-scrollbar { width: 4px; }
.chat-main::-webkit-scrollbar-track { background: transparent; }
.chat-main::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ── メッセージ共通 ── */
.message {
    max-width: 82%;
    padding: 10px 15px;
    border-radius: var(--radius-msg);
    font-size: 0.93rem;
    line-height: 1.62;
    word-break: break-word;
    white-space: pre-wrap;
    animation: msgFadeUp .22s ease;
}

@keyframes msgFadeUp {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* AI メッセージ — quote-bg / quote-border に合わせる */
.ai-message {
    background: var(--bg-ai);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    border-left: 3px solid var(--primary);
}

/* ストリーミングカーソル */
.ai-message.streaming::after {
    content: '▋';
    display: inline-block;
    color: var(--primary);
    animation: cursorBlink .55s infinite;
    margin-left: 2px;
}
@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* ユーザーメッセージ */
.user-message {
    background: var(--bg-user);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

/* ── 参照元 ── */
.sources-info {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-sub);
    line-height: 1.65;
}
.sources-info a {
    color: var(--primary);
    text-decoration: none;
    word-break: break-all;
    display: block;
}
.sources-info a:hover { text-decoration: underline; }

/* ── 参照文書プレビュー ── */
.context-preview {
    align-self: flex-start;
    max-width: 90%;
    background: var(--bg-ai);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: 0 8px 8px 0;
    padding: 9px 13px;
    font-size: 0.78rem;
    color: var(--text-sub);
    line-height: 1.55;
    animation: msgFadeUp .22s ease;
}
.context-preview .preview-label {
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 5px;
    font-size: 0.71rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.context-preview .preview-item { margin-top: 4px; }
.context-preview .preview-item a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}
.context-preview .preview-item a:hover { text-decoration: underline; }
.context-preview .preview-text {
    color: var(--text-muted);
    font-size: 0.73rem;
}

/* ── システムメッセージ ── */
.system-message {
    align-self: center;
    font-size: 0.71rem;
    color: var(--text-muted);
    background: var(--bg-chat);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 11px;
    animation: msgFadeUp .2s ease;
}

/* ══════════════════════════════════════════════
   入力フッター
   ══════════════════════════════════════════════ */
.chat-input-area {
    padding: 11px 16px 13px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ── ローディングバー ── */
#loading-bar {
    height: 2px;
    background: linear-gradient(
        90deg,
        var(--primary),
        rgba(var(--primary-rgb), 0.25),
        var(--primary)
    );
    background-size: 200% 100%;
    border-radius: 2px;
    margin-bottom: 10px;
    animation: loadingSlide 1.8s linear infinite;
}
#loading-bar.hidden { display: none; }

@keyframes loadingSlide {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── 入力ラッパー ── */
.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

textarea#user-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 15px;
    resize: none;
    outline: none;
    font-size: 0.93rem;
    font-family: inherit;
    max-height: 110px;
    min-height: 42px;
    line-height: 1.5;
    color: var(--text-main);
    background: var(--bg-chat);
    transition: border-color .2s, box-shadow .2s;
    overflow-y: auto;
}
textarea#user-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
    background: var(--bg-card);
}
textarea#user-input::placeholder { color: var(--text-muted); }
textarea#user-input:disabled { opacity: .45; cursor: not-allowed; }

/* ── 送信ボタン ── */
#send-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    transition: background .2s, transform .15s, box-shadow .2s;
    box-shadow: 0 2px 6px rgba(var(--primary-rgb), 0.3);
}
#send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.07);
    box-shadow: 0 3px 10px rgba(var(--primary-rgb), 0.4);
}
#send-btn:active:not(:disabled) { transform: scale(0.95); }
#send-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
    box-shadow: none;
}

/* ── フッター情報行 ── */
.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 0.69rem;
    color: var(--text-muted);
    min-height: 15px;
}

#elapsed-time {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
    transition: color .3s;
}
#elapsed-time.running {
    color: var(--amber);
    font-weight: 600;
}

#system-status {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
}

/* ── キュー待ちバッジ ── */
.queue-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(245, 158, 11, 0.1);
    color: var(--amber);
    font-size: 0.69rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid rgba(245, 158, 11, 0.3);
}
