/**
 * AIアシスタントチャット機能のスタイルシート
 * モダンで直感的なチャットインターフェースを提供
 */

/* ========================================
   グローバル変数定義
   ======================================== */
:root {
    /* サイト全体のカラーと統一 */
    --chat-primary-color: #ff6156;
    --chat-secondary-color: #ff8c6b;
    --chat-success-color: #10b981;
    --chat-warning-color: #f59e0b;
    --chat-danger-color: #ef4444;
    --chat-text-primary: #1e293b;
    --chat-text-secondary: #64748b;
    --chat-text-light: #94a3b8;
    --chat-bg-primary: #ffffff;
    --chat-bg-secondary: #f8fafc;
    --chat-bg-tertiary: #f1f5f9;

    /* Force light mode for recommendations */
    --rec-text-primary: #1e293b;
    --rec-text-secondary: #64748b;
    --rec-bg-primary: #ffffff;
    --rec-border-color: #e5e7eb;
    --chat-border-color: #e2e8f0;
    --chat-border-light: #f3f4f6;
    --chat-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --chat-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --chat-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --chat-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --chat-radius-sm: 0.375rem;
    --chat-radius-md: 0.5rem;
    --chat-radius-lg: 0.75rem;
    --chat-radius-xl: 1rem;
    --chat-z-index: 9999;
}

/* ダークモードサポート */
@media (prefers-color-scheme: dark) {
    :root {
        /* チャット内は常に白背景・濃いテキストを維持 */
        /* 変数は定義するが、チャット内要素では直接固定値を使用 */
        --chat-primary-color: #ff6156;
        --chat-secondary-color: #ff8c6b;
        --chat-text-primary: #1e293b;
        --chat-text-secondary: #64748b;
        --chat-text-light: #94a3b8;
        --chat-bg-primary: #ffffff;
        --chat-bg-secondary: #f8fafc;
        --chat-bg-tertiary: #f1f5f9;
        --chat-border-color: #e2e8f0;
        --chat-border-light: #f3f4f6;
    }
}


/* ========================================
   チャットコンテナ全体
   ======================================== */
#ai-assistant-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--chat-z-index);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ========================================
   フローティングチャットボタン
   ======================================== */
.chat-toggle-btn {
    position: relative;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #4f46e5, #06b6d4);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chat-shadow-lg);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: white;
    outline: none;
    overflow: hidden;
}

.chat-toggle-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #06b6d4, #4f46e5);
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: inherit;
}

.chat-toggle-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: var(--chat-shadow-xl);
}

.chat-toggle-btn:hover::before {
    opacity: 1;
}

.chat-toggle-btn:active {
    transform: translateY(-1px) scale(1.02);
}

.chat-toggle-btn.active {
    background: var(--chat-danger-color);
}

.chat-toggle-btn svg {
    position: relative;
    z-index: 1;
    transition: transform 0.3s ease;
}

.chat-toggle-btn:hover svg {
    transform: scale(1.1);
}

/* 通知バッジ */
.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: var(--chat-danger-color);
    border: 2px solid white;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* ========================================
   チャットウィンドウ
   ======================================== */
.chat-window {
    position: fixed;
    bottom: 72px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 750px;
    max-height: calc(100vh - 120px);
    min-height: 400px;
    background: var(--chat-bg-primary);
    border-radius: var(--chat-radius-xl);
    box-shadow: var(--chat-shadow-xl);
    border: 2px solid var(--chat-primary-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUpFade 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
    z-index: var(--chat-z-index);
    box-sizing: border-box;
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ========================================
   チャットヘッダー
   ======================================== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: #ff6156;
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-avatar {
    width: 36px;
    height: 36px;
    background: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.chat-title-text {
    font-weight: 600;
    font-size: 16px;
    line-height: 1.2;
}

.chat-subtitle {
    font-size: 12px;
    opacity: 0.8;
    line-height: 1.2;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.chat-action-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--chat-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.chat-action-btn:active {
    transform: scale(0.95);
}

/* ========================================
   メッセージ領域
   ======================================== */
.chat-messages {
    padding: 20px;
    background: #ffffff;
    overflow-y: auto !important;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    min-height: 0;
    flex: 1 1 0%;
    position: relative;
    box-sizing: border-box;
    /* スクロールのタッチサポートを強化 */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: #94a3b8 #f8fafc;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f8fafc;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 3px;
    transition: background 0.2s ease;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* メッセージアイテムの調整 */
.message {
    flex-shrink: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ========================================
   メッセージ
   ======================================== */
.chat-message {
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: fadeInUp 0.4s ease;
}

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

.user-message {
    align-items: flex-end;
}

.ai-message {
    align-items: flex-start;
}

.message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--chat-radius-lg);
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
}

.user-message .message-content {
    background: #ff6156;
    color: white;
    border-bottom-right-radius: var(--chat-radius-sm);
}

.ai-message .message-content {
    background: #f8fafc;
    color: #1e293b;
    border-bottom-left-radius: var(--chat-radius-sm);
    border: 1px solid #e2e8f0;
}

.message-time {
    font-size: 11px;
    color: #94a3b8;
    padding: 0 4px;
    margin-top: -4px;
}

/* ========================================
   推奨カード
   ======================================== */
.recommendations {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Chat-specific recommendation card styles */
.chat-window .recommendation-card,
#ai-assistant-chat .recommendation-card {
    background: var(--chat-bg-primary);
    border: 2px solid var(--chat-border-color);
    border-radius: var(--chat-radius-md);
    padding: 16px;
    transition: all 0.3s ease;
    cursor: pointer;
    color: var(--chat-text-primary);
    box-shadow: var(--chat-shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: auto;
    height: auto;
}

.chat-window .recommendation-card:hover,
#ai-assistant-chat .recommendation-card:hover {
    border-color: var(--chat-primary-color);
    box-shadow: var(--chat-shadow-md);
    transform: translateY(-2px);
}

.rec-header {
    margin-bottom: 8px;
    flex-shrink: 0;
}

.rec-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--chat-text-primary) !important;
    margin: 0;
    line-height: 1.3;
}

.rec-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
    flex-shrink: 0;
}

.rec-time {
    font-size: 11px;
    color: var(--chat-text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.rec-skills {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.chat-window .skill-tag,
#ai-assistant-chat .skill-tag {
    font-size: 10px;
    background: rgba(255, 97, 86, 0.1);
    color: #000000;
    padding: 2px 6px;
    border-radius: var(--chat-radius-sm);
    border: none;
}

.rec-description {
    font-size: 12px;
    color: var(--chat-text-secondary) !important;
    line-height: 1.4;
    margin: 0;
    flex-shrink: 0;
    padding-bottom: 0;
}

/* ========================================
   進捗サマリー
   ======================================== */
.progress-summary {
    margin-top: 12px;
    display: flex;
    justify-content: center;
}

.progress-circle {
    position: relative;
    width: 80px;
    height: 80px;
}

.progress-ring {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: conic-gradient(
        var(--chat-success-color) calc(var(--progress) * 3.6deg),
        var(--chat-bg-tertiary) 0deg
    );
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-ring::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    right: 4px;
    bottom: 4px;
    background: var(--chat-bg-primary);
    border-radius: 50%;
}

.progress-text {
    position: relative;
    z-index: 1;
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-text-primary);
}

/* ========================================
   タイピングインジケーター
   ======================================== */
.typing-indicator .message-content {
    background: #f8fafc;
    padding: 12px 16px;
    width: fit-content;
}

.typing-animation {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-animation span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-animation span:nth-child(1) { animation-delay: -0.32s; }
.typing-animation span:nth-child(2) { animation-delay: -0.16s; }
.typing-animation span:nth-child(3) { animation-delay: 0s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ========================================
   入力エリア
   ======================================== */
.chat-input-area {
    padding: 16px 20px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

/* クイックアクション */
.quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-action-btn {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    padding: 6px 12px;
    border-radius: var(--chat-radius-md);
    font-size: 12px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.quick-action-btn:hover {
    background: #ff6156;
    color: white;
    border-color: #ff6156;
    transform: translateY(-1px);
}

.quick-action-btn:active {
    transform: translateY(0);
}

/* 入力コンテナ */
.chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: var(--chat-radius-lg);
    padding: 8px;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 14px;
    line-height: 1.4;
    color: #1e293b;
    font-family: inherit;
    min-height: 20px;
    max-height: 100px;
    padding: 4px 0;
}

.chat-input::placeholder {
    color: #94a3b8;
}

.chat-send-btn {
    width: 32px;
    height: 32px;
    background: #ff6156;
    border: none;
    border-radius: var(--chat-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: #ff4842;
    transform: scale(1.05);
}

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
    opacity: 0.5;
}

/* ========================================
   レスポンシブデザイン
   ======================================== */
@media (max-width: 768px) {
    #ai-assistant-chat {
        bottom: 16px;
        right: 16px;
        left: 16px;
    }

    .chat-window {
        position: fixed;
        bottom: 80px;
        left: 16px;
        right: 16px;
        width: auto;
        max-width: none;
        height: calc(100vh - 120px);
        max-height: calc(100vh - 120px);
        min-height: 300px;
        display: flex;
        flex-direction: column;
    }

    .chat-toggle-btn {
        width: 48px;
        height: 48px;
        position: fixed;
        bottom: 16px;
        right: auto;
        left: 16px;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-area {
        padding: 12px 16px;
    }

    .message-content {
        max-width: 90%;
        font-size: 13px;
    }

    .chat-window .recommendation-card,
    #ai-assistant-chat .recommendation-card {
        padding: 12px;
    }

    .quick-actions {
        gap: 6px;
    }

    .quick-action-btn {
        font-size: 11px;
        padding: 6px 10px;
    }
}

@media (max-width: 480px) {
    .chat-header {
        padding: 12px 16px;
    }

    .chat-title-text {
        font-size: 15px;
    }

    .chat-subtitle {
        font-size: 11px;
    }

    .message-content {
        font-size: 12px;
        padding: 10px 12px;
    }

    .recommendations {
        gap: 8px;
    }

    .chat-window .recommendation-card,
    #ai-assistant-chat .recommendation-card {
        padding: 10px;
    }

    .rec-title {
        font-size: 13px;
    }

    .rec-description {
        font-size: 11px;
    }

    .chat-window {
        right: 8px;
        bottom: 70px;
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
        height: calc(100vh - 100px);
        max-height: calc(100vh - 100px);
        min-height: 250px;
        display: flex;
        flex-direction: column;
    }
}

/* ========================================
   アクセシビリティ
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ハイコントラストモード */
@media (prefers-contrast: high) {
    :root {
        --chat-border-color: #000000;
        --chat-text-light: #000000;
        --chat-bg-tertiary: #ffffff;
    }

    .chat-toggle-btn {
        border: 2px solid #000000;
    }

    .chat-window {
        border: 2px solid #000000;
    }
}

/* フォーカス表示の改善 */
button:focus,
.quick-action-btn:focus,
.rec-start-btn:focus {
    outline: 2px solid var(--chat-primary-color);
    outline-offset: 2px;
}

.chat-input:focus {
    outline: none;
}

/* ========================================
   ユーティリティクラス
   ======================================== */
.chat-hidden {
    display: none !important;
}

.chat-fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.chat-fade-out {
    animation: fadeOut 0.3s ease;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* セレクション時の色 */
::selection {
    background-color: var(--chat-primary-color);
    color: white;
}

/* ========================================
   クイズメッセージスタイル
   ======================================== */
.quiz-message {
    background: var(--chat-bg-tertiary);
    padding: 16px;
    border-radius: var(--chat-radius-lg);
    border: 2px solid var(--chat-border-color);
    width: 100%;
    max-width: 100%;
}

.quiz-question {
    font-size: 14px;
    line-height: 1.6;
    color: var(--chat-text-primary);
    margin-bottom: 16px;
    font-weight: 500;
}

.quiz-question strong {
    color: var(--chat-primary-color);
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

.quiz-option-btn {
    width: 100%;
    background: var(--chat-bg-primary);
    border: 2px solid var(--chat-border-color);
    padding: 12px 16px;
    border-radius: var(--chat-radius-md);
    font-size: 14px;
    color: var(--chat-text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    font-weight: 500;
    display: flex;
    align-items: center;
    line-height: 1.5;
}

.quiz-option-btn:hover:not(:disabled) {
    background: var(--chat-primary-color);
    color: white;
    border-color: var(--chat-primary-color);
    transform: translateX(4px);
    box-shadow: var(--chat-shadow-sm);
}

.quiz-option-btn:active:not(:disabled) {
    transform: translateX(2px);
}

.quiz-option-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.quiz-option-btn.selected {
    background: var(--chat-secondary-color);
    color: white;
    border-color: var(--chat-secondary-color);
    font-weight: 600;
}

.quiz-option-btn.correct {
    background: var(--chat-success-color);
    color: white;
    border-color: var(--chat-success-color);
}

.quiz-option-btn.incorrect {
    background: var(--chat-danger-color);
    color: white;
    border-color: var(--chat-danger-color);
}

/* クイズ結果メッセージ */
.quiz-result {
    margin-top: 12px;
    padding: 12px 16px;
    border-radius: var(--chat-radius-md);
    background: var(--chat-bg-secondary);
    border-left: 4px solid var(--chat-primary-color);
}

.quiz-result.correct {
    border-left-color: var(--chat-success-color);
    background: rgba(16, 185, 129, 0.1);
}

.quiz-result.incorrect {
    border-left-color: var(--chat-danger-color);
    background: rgba(239, 68, 68, 0.1);
}

.quiz-explanation {
    margin-top: 8px;
    font-size: 13px;
    color: var(--chat-text-secondary);
    line-height: 1.6;
    padding: 8px 12px;
    background: var(--chat-bg-primary);
    border-radius: var(--chat-radius-sm);
}

/* レスポンシブ調整 */
@media (max-width: 768px) {
    .quiz-message {
        padding: 12px;
    }

    .quiz-question {
        font-size: 13px;
    }

    .quiz-option-btn {
        padding: 10px 12px;
        font-size: 13px;
    }

    .quiz-options {
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .quiz-message {
        padding: 10px;
    }

    .quiz-question {
        font-size: 12px;
    }

    .quiz-option-btn {
        padding: 8px 10px;
        font-size: 12px;
    }

    .quiz-explanation {
        font-size: 12px;
    }
}
