/* 新しいエージェントチャット機能のスタイル */

.agent-chat {
    max-width: 448px;
    margin: 0 auto;
    background: var(--surface-color, #ffffff);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* 共通モーダルスタイル */
.agent-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 1020;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.agent-modal-overlay:not(.hidden) {
    opacity: 1;
}

.agent-modal {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(100%); /* センタリング + 初期状態は非表示 */
    width: 100%;
    max-width: 26rem;
    height: calc(var(--vh, 1vh) * 85);
    background-color: var(--surface-color, white);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    z-index: 1030;
    visibility: hidden;
    opacity: 0;
    transition: transform 0.3s ease-in-out, visibility 0.3s ease-in-out, opacity 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    box-sizing: border-box;
}

.agent-modal.show {
    transform: translateX(-50%) translateY(0); /* 表示状態（センタリング維持） */
    visibility: visible;
    opacity: 1;
}

.agent-modal-header {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    margin-bottom: 1rem;
}

.agent-modal-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary, #111827);
    margin: 0;
}

.agent-modal-close {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0.25rem;
    transition: color 0.2s ease;
}

.agent-modal-close:hover {
    color: #374151;
}

.agent-chat-content {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.agent-input-area {
    flex-shrink: 0;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background-color: var(--surface-color, white);
    padding-top: 1rem;
}

.agent-quick-prompts {
    width: 100%;
    overflow-x: auto;
    margin-bottom: 0.75rem;
    display: grid; /* Flexboxの子要素が親を押し広げる問題の対策 */
}

.agent-quick-prompts-container {
    display: flex;
    gap: 0.5rem;
    white-space: nowrap;
    padding-bottom: 0.5rem;
}

.agent-chat-input {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    max-width: 100%; /* 親要素の幅を超えない */
    box-sizing: border-box; /* パディング・ボーダーを含めた幅計算 */
}

.agent-input-field {
    flex: 1;
    min-width: 0; /* flexアイテムの最小幅をリセット */
    border: 1px solid #d1d5db;
    border-radius: 9999px;
    padding: 0.5rem 1rem;
    font-size: 16px; /* iOSの自動ズームを防ぐための重要な設定 */
    background-color: #f9fafb;
    transition: all 0.2s ease;
    outline: none;
    box-sizing: border-box; /* パディング・ボーダーを含めた幅計算 */
}

.agent-input-field:focus {
    ring: 2px;
    ring-color: var(--primary-color, #2563eb);
    border-color: transparent;
}

.agent-send-button {
    background-color: var(--primary-color, #2563eb);
    color: white;
    border: none;
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.agent-send-button:hover {
    background-color: #1d4ed8;
}

.agent-send-button .material-icons {
    font-size: 1.125rem;
    color: white;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .agent-modal {
        padding: 0.75rem; /* モバイルでは少し小さく */
    }
    
    .agent-input-field {
        font-size: 16px; /* iOSでズームを防ぐ */
    }
}

/* クイックプロンプトセクション */
.quick-prompts-section {
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    padding: 20px;
}

.quick-prompts-header h4 {
    margin: 0 0 15px 0;
    color: #495057;
    font-size: 16px;
    font-weight: 600;
}

.quick-prompts-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-prompt-btn {
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    border: 1px solid var(--primary-color, #2563eb);
    color: var(--primary-color, #2563eb);
    font-size: 0.75rem;
    font-weight: 500;
    background-color: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.quick-prompt-btn:hover {
    background-color: var(--hover-bg-color, #dbeafe);
}

.prompt-icon {
    font-size: 16px;
}

.prompt-text {
    line-height: 1.2;
}

.loading-spinner, .no-prompts, .prompts-error {
    text-align: center;
    color: #6c757d;
    font-size: 14px;
    padding: 10px;
}

.prompts-error {
    color: #dc3545;
}

/* チャット履歴 */
.chat-history {
    height: 400px;
    overflow-y: auto;
    padding: 20px;
    background: #ffffff;
}

.welcome-message {
    margin-bottom: 20px;
}

.message {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 1.25rem;
    overflow-wrap: break-word;
    line-height: 1.5;
}

.message.user {
    align-self: flex-end;
    background-color: var(--primary-color, #2563eb);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.assistant {
    align-self: flex-start;
    background: #f1f3f4;
    color: #202124;
    border-bottom-left-radius: 0.25rem;
}

.message.assistant li {
    margin: 0 0 0.7em;
}

/* 従来の .message-content 構造との互換性のため残す */
.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
}

.message.user .message-content {
    background: #007bff;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: #f1f3f4;
    color: #202124;
    border-bottom-left-radius: 4px;
}

.message.assistant.clarification .message-content {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
}

.message.assistant.error .message-content {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

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

.confidence-note {
    margin-top: 8px;
    padding: 8px 12px;
    background: #e7f3ff;
    border: 1px solid #b3d7ff;
    border-radius: 8px;
    font-size: 12px;
    color: #0056b3;
}

/* メッセージ入力エリア */
.chat-input-section {
    background: #ffffff;
    border-top: 1px solid #e9ecef;
    padding: 16px 20px;
}

.input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    resize: none;
    border: 1px solid #ced4da;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px; /* iOSの自動ズームを防ぐ */
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s ease;
}

#messageInput:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

#messageInput:disabled {
    background: #f8f9fa;
    color: #6c757d;
}

.send-button {
    background: #007bff;
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.send-button:hover:not(:disabled) {
    background: #0056b3;
    transform: scale(1.05);
}

.send-button:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
}

.send-text, .loading-spinner {
    font-size: 14px;
    font-weight: 600;
}

.loading-spinner {
    display: inline-block;
}

.hidden {
    display: none !important;
}

.input-info {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.char-count {
    font-size: 11px;
    color: #6c757d;
}

/* スクロールバーのスタイル */
.chat-history::-webkit-scrollbar {
    width: 6px;
}

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

.chat-history::-webkit-scrollbar-thumb {
    background: #c1c8cd;
    border-radius: 3px;
}

.chat-history::-webkit-scrollbar-thumb:hover {
    background: #a8b0b5;
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    .agent-chat {
        margin: 0;
        border-radius: 0;
        min-height: 100vh;
    }
    
    .quick-prompts-container {
        gap: 6px;
    }
    
    .quick-prompt-btn {
        font-size: 13px;
        padding: 6px 12px;
    }
    
    .chat-history {
        height: calc(100vh - 300px);
        padding: 16px;
    }
    
    .message-content {
        max-width: 85%;
        font-size: 14px;
    }
    
    .chat-input-section {
        padding: 12px 16px;
    }
    
    #messageInput {
        font-size: 16px; /* iOSでズームを防ぐ */
    }
}

/* アニメーション */
/* スケルトンローディングアニメーション */
.agent-loading {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 16px;
}

.agent-loading-content {
    max-width: 70%;
    padding: 16px 20px;
    background: #f1f3f4;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.loading-text {
    color: #495057;
    font-size: 14px;
    margin-bottom: 16px;
    font-weight: 500;
}

.skeleton-lines {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.skeleton-line {
    height: 12px;
    background: #e2e5e7;
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.skeleton-line::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.6),
        transparent
    );
    animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-line:nth-child(1) {
    width: 85%;
}

.skeleton-line:nth-child(2) {
    width: 100%;
}

.skeleton-line:nth-child(3) {
    width: 70%;
}

.skeleton-line:nth-child(4) {
    width: 45%;
}

.skeleton-line:nth-child(5) {
    width: 60%;
}

@keyframes shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

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

.message {
    animation: fadeInUp 0.3s ease;
}

/* エージェント専用スポットカード - チャットメッセージ内でのみ適用 */
.message-content .agent-spot-card,
#chat-messages .agent-spot-card {
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 1rem;
    background: white;
    transition: box-shadow 0.3s ease;
}

.message-content .agent-spot-card:hover,
#chat-messages .agent-spot-card:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.message-content .agent-spot-card h3,
#chat-messages .agent-spot-card h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 0.5rem;
}

.message-content .agent-spot-card .spot-info p,
#chat-messages .agent-spot-card .spot-info p {
    margin-bottom: 0.5rem;
}

.message-content .agent-spot-card .spot-description,
#chat-messages .agent-spot-card .spot-description {
    background: #f9fafb;
    padding: 0.75rem;
    border-radius: 0.5rem;
    margin: 0.75rem 0;
}

.message-content .agent-spot-card .spot-actions,
#chat-messages .agent-spot-card .spot-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
}

/* リッチテキスト要素 */
.message-content h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 0.5rem;
}

.message-content .location-info {
    color: #6b7280;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.message-content .creator-info {
    color: #2563eb;
    font-size: 0.875rem;  
    margin-bottom: 0.5rem;
}

.message-content .rating-info {
    color: #d97706;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.message-content .description-quote {
    background: #f9fafb;
    padding: 0.5rem;
    border-radius: 0.5rem;
    font-style: italic;
    color: #374151;
    margin: 0.5rem 0;
}

.message-content .photo-info {
    color: #6b7280;
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
}

.message-content .success-message {
    color: #059669;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

/* 段階的質問UI */
.step-question {
    margin-bottom: 1rem;
    color: #1f2937;
}

.step-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.step-button {
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
}

.step-button.primary {
    background: #2563eb;
    color: white;
}

.step-button.primary:hover {
    background: #1d4ed8;
}

.step-button.secondary {
    background: white;
    color: #374151;
    border: 1px solid #d1d5db;
}

.step-button.secondary:hover {
    background: #f9fafb;
}

/* 詳細ページリンクボタン */
.detail-link {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: #2563eb;
    color: white;
    text-decoration: none;
    border-radius: 9999px;
    font-size: 0.875rem;
    transition: background-color 0.3s ease;
}

.detail-link:hover {
    background: #1d4ed8;
    text-decoration: none;
    color: white;
}

/* 地図ボタン */
.map-button {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: white;
    color: #374151;
    border: 1px solid #d1d5db;
    border-radius: 9999px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.map-button:hover {
    background: #f9fafb;
}

/* 成功メッセージボックス */
.success-box {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 1rem;
}

.success-box p {
    color: #065f46;
    font-weight: 500;
    margin: 0;
}

/* 区切り線 */
.message-content hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 1rem 0;
}

/* アイコンの色分け */
.message-content .icon-location { color: #6b7280; }
.message-content .icon-creator { color: #2563eb; }  
.message-content .icon-rating { color: #d97706; }
.message-content .icon-photo { color: #6b7280; }
.message-content .icon-success { color: #059669; }
.message-content .icon-bullet { color: #2563eb; }

/* レスポンシブ対応 */
@media (max-width: 640px) {
    .message-content .agent-spot-card .spot-actions,
    #chat-messages .agent-spot-card .spot-actions {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }
    
    .step-buttons {
        flex-direction: column;
    }
    
    .detail-link, .map-button {
        text-align: center;
        width: 100%;
    }
}

.message a {
    color: #2563eb;
    text-decoration: underline;
}

.message a:hover {
    color: #1d4ed8;
}

/* External link button style */
.message a[href^="http"] {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 20px;
    background-color: #f3f4f6;
    color: #1f2937;
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    border: 1px solid #e5e7eb;
    transition: background-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    word-break: break-all;
}

.message a[href^="http"]:hover {
    background-color: #e5e7eb;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Headings style */
.message h1, .message h2, .message h3, .message h4, .message h5, .message h6 {
    font-weight: 600;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

.message h1 { font-size: 1.5em; }
.message h2 { font-size: 1.25em; }
.message h3 { font-size: 1.1em; }


/* List style */
.message ul, .message ol {
    padding-left: 1.5em;
    margin-top: 0.5em;
    margin-bottom: 0.5em;
}
.message ul {
    list-style-type: disc;
}
.message ol {
    list-style-type: decimal;
}

/* Agent Spot Card style */
.agent-spot-card.spot-card-container {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    background-color: var(--card-background, #FFFFFF);
    border: 1px solid var(--card-border, #F1F5F9);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(0, 0, 0, 0.04);
    text-decoration: none !important;
    color: inherit;
    margin: 12px 0;
}

.agent-spot-card.spot-card-container:hover {
    transform: translateY(-1px);
    border-color: var(--card-hover-border, #E2E8F0);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06), 0 4px 8px rgba(0, 0, 0, 0.04);
}

.agent-spot-card img {
    /* Styles are now matched in the JS render function using Tailwind classes */
}

.agent-spot-card h3 {
    margin: 0;
}
.agent-spot-card p {
    margin-top: 4px;
}

.no-underline {
    text-decoration: none !important;
}