/**
 * ChatGPT風 UIスタイル
 * OpenAI Assistants API チャットシステム
 */

/* ========================================
 * グローバルスタイル
 * ======================================== */
* {
    box-sizing: border-box;
}

/* body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
} */

/* ========================================
 * デモページスタイル
 * ======================================== */
.demo-header {
    text-align: center;
    padding: 60px 20px 40px;
    color: white;
}

.demo-header h1 {
    font-size: 2.5rem;
    margin: 0 0 10px;
    font-weight: 700;
}

.demo-header p {
    font-size: 1.1rem;
    opacity: 0.9;
    margin: 0;
}

.demo-main {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

.demo-content {
    background: white;
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.demo-content h2 {
    color: #333;
    margin-top: 0;
}

.demo-card {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 24px;
    margin-top: 24px;
}

.demo-card h3 {
    color: #495057;
    margin-top: 0;
}

.demo-card ul {
    list-style: none;
    padding: 0;
    margin: 16px 0 0;
}

.demo-card li {
    padding: 8px 0;
    color: #495057;
    font-size: 1rem;
}

/* ========================================
 * チャット起動ボタン
 * ======================================== */
.chat-trigger-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.chat-trigger-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.chat-trigger-button:active {
    transform: scale(1.05);
}

/* ========================================
 * チャットモーダルオーバーレイ
 * ======================================== */
.chat-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

/* ========================================
 * チャットモーダル本体
 * ======================================== */
.chat-modal {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    height: 80vh;
    max-height: 700px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* ========================================
 * ヘッダー
 * ======================================== */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

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

.chat-reset-button,
.chat-close-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-reset-button:hover,
.chat-close-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-reset-button {
    display: none;
}

.chat-reset-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================================
 * メッセージエリア
 * ======================================== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

.chat-welcome {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.chat-welcome p {
    margin: 8px 0;
    font-size: 1.1rem;
}

/* ========================================
 * メッセージ
 * ======================================== */
.chat-message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: messageSlideIn 0.3s ease-out;
}

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

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #e9ecef;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    flex-shrink: 0;
}

.chat-message-content {
    flex: 1;
    display: flex;
    align-items: flex-start;
    gap: 4px;
}

.chat-message-text {
    background: white;
    border-radius: 12px;
    padding: 12px 16px;
    color: #212529;
    line-height: 1.6;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.chat-message-user {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.chat-message-user .chat-message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.chat-message-user .chat-message-content {
    display: flex;
    justify-content: flex-end;
}

.chat-message-user .chat-message-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-align: left;
}

.chat-message-cursor {
    color: #667eea;
    font-weight: bold;
    animation: cursorBlink 1s infinite;
    margin-top: 12px;
}

@keyframes cursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* 質問内容を分析中です。しばらくお待ち下さい⋯アニメーション */
.chat-message-text.waiting {
    animation: pulse 1.5s ease-in-out infinite;
    color: #6c757d;
    font-style: italic;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* リンクスタイル */
.chat-link {
    color: #667eea;
    text-decoration: underline;
    word-break: break-all;
    transition: opacity 0.2s;
}

.chat-link:hover {
    opacity: 0.8;
}

.chat-message-user .chat-link {
    color: #ffffff;
    text-decoration: underline;
}

/* ========================================
 * エラーメッセージ
 * ======================================== */
.chat-error {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
    padding: 12px 16px;
    border-radius: 8px;
    margin-top: 16px;
    text-align: center;
}

/* ========================================
 * 入力エリア
 * ======================================== */
.chat-input-area {
    background: white;
    padding: 16px 24px;
    border-top: 1px solid #dee2e6;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    max-height: 200px;
    min-height: 80px;
    overflow-y: auto;
    height: auto;
}

.chat-input:focus {
    border-color: #667eea;
}

.chat-input:disabled {
    background: #f8f9fa;
    cursor: not-allowed;
}

.chat-send-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
    min-width: 70px;
}

.chat-send-button:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.chat-send-button:active:not(:disabled) {
    transform: translateY(0);
}

.chat-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================================
 * フッター
 * ======================================== */
.chat-footer {
    display: none;
}

.chat-footer small {
    color: #6c757d;
    font-size: 12px;
}

/* ========================================
 * レスポンシブデザイン
 * ======================================== */
@media (max-width: 768px) {
    .demo-header h1 {
        font-size: 2rem;
    }

    .demo-content {
        padding: 24px;
    }

    .chat-modal {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .chat-trigger-button {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .chat-messages {
        padding: 16px;
    }

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

/* ========================================
 * スクロールバーカスタマイズ
 * ======================================== */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

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

/* ========================================
 * ユーザー情報フォーム
 * ======================================== */
.user-form-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: 16px;
}

.user-form-container {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.user-form-container h3 {
    margin: 0 0 20px;
    font-size: 1.4rem;
    color: #333;
    text-align: center;
}

.user-form-errors {
    background: #fee;
    border: 1px solid #fcc;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 20px;
}

.user-form-errors p {
    margin: 0;
    padding: 4px 0;
    color: #c00;
    font-size: 0.9rem;
}

.user-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.form-group .required-mark {
    color: #e74c3c;
    font-weight: bold;
}

.form-group input {
    padding: 10px 12px;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #10a37f;
}

.form-group input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.user-form-submit {
    margin-top: 10px;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background: #10a37f;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.user-form-submit:hover:not(:disabled) {
    background: #0d8c6a;
}

.user-form-submit:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* レスポンシブ対応 */
@media (max-width: 600px) {
    .user-form-container {
        padding: 20px;
    }

    .user-form-container h3 {
        font-size: 1.2rem;
    }
}
