/**
 * Tokyo MK タクシー予約チャットボット CSS
 * チャットボット用のスタイルシート
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    background: #34495e;
    height: 100vh; /* Fallback for older browsers */
    height: 100svh; /* Small viewport height */
    height: 100dvh; /* Dynamic viewport height - adapts to keyboard */
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.chat-container {
    width: 100%;
    max-width: 900px;
    height: 100vh; /* Fallback for older browsers */
    height: 100svh; /* Small viewport height */
    height: 100dvh; /* Dynamic viewport height - adapts to keyboard */
    background: rgba(255, 255, 255, 0.98);
    border-radius: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, #1a252f 0%, #2c3e50 100%);
    color: white;
    padding: 24px 30px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 3px solid #1a252f;
}

.header-icon {
    width: 48px;
    height: 48px;
    background: #1a252f;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    overflow: hidden;
}

.logo-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 12px;
}

.header-content h1 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 4px;
}

.header-content p {
    font-size: 13px;
    opacity: 0.9;
}

.status-indicator {
    width: 8px;
    height: 8px;
    background: #2ecc71;
    border-radius: 50%;
    margin-left: auto;
    animation: pulse 2s infinite;
}

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

/* Language Switcher */
.language-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    margin-right: 16px;
}

.language-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.6);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.language-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.8);
}

.language-btn.active {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(255, 255, 255, 1);
    color: #2c3e50;
    font-weight: 600;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    background: #f8f9fa;
    /* スムーズなスクロール */
    scroll-behavior: smooth;
    /* iOS Safari用のスクロール改善 */
    -webkit-overflow-scrolling: touch;
}

.message {
    display: flex;
    margin-bottom: 16px;
    animation: slideIn 0.3s ease-out;
}

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

.message.bot {
    justify-content: flex-start;
}

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.message.bot .message-avatar {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    margin-right: 12px;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #f8c471 0%, #f39c12 100%);
    color: white;
    margin-left: 12px;
    box-shadow: 0 2px 8px rgba(243, 156, 18, 0.3);
}

.message-content {
    max-width: 120%;
    padding: 16px 20px;
    border-radius: 18px;
    line-height: 1.6;
    font-size: 14px;
    white-space: pre-wrap;
}

.message-notes {
    background:#f5f5f5;
    padding:10px;
    border-radius:5px;
    margin:5px 0;
    white-space:pre-wrap;
}

.message.bot .message-content {
    background: white;
    color: #2c3e50;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.message.user .message-content {
    background: linear-gradient(135deg, #ecf0f1 0%, #d5dbdb 100%);
    color: #2c3e50;
}

.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.quick-reply-btn {
    padding: 10px 18px;
    background: white;
    border: 2px solid #2c3e50;
    color: #2c3e50;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    font-weight: 500;
}

.quick-reply-btn:hover {
    background: #2c3e50;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(44, 62, 80, 0.3);
}

.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 16px 20px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #95a5a6;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.chat-input-container {
    padding: 20px 30px;
    padding-bottom: max(20px, env(safe-area-inset-bottom)); /* Safe Area for iPhone notch/home indicator */
    background: white;
    border-top: 1px solid #e0e0e0;
}

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

.chat-input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid #bdc3c7;
    border-radius: 24px;
    font-size: 16px; /* Prevent iOS Safari auto-zoom (must be >= 16px) */
    min-height: 52px; /* Comfortable touch target for mobile */
    outline: none;
    transition: border-color 0.3s ease;
    font-family: inherit;
    background: #f8f9fa;
    color: #2c3e50;
    touch-action: manipulation; /* Prevent double-tap zoom */
}

.chat-input:focus {
    border-color: #7f8c8d;
}

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

.send-button {
    width: 56px;
    height: 56px;
    min-width: 56px; /* Prevent shrinking */
    min-height: 56px;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(44, 62, 80, 0.4);
}

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

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

.error-message {
    background: #fee;
    border-left: 4px solid #2c3e50;
    padding: 10px 14px;
    margin: 8px 0;
    border-radius: 8px;
    color: #666;
    font-size: 11px;
    opacity: 0.9;
}

/* デスクトップ・タブレット用の設定 */
@media (min-width: 769px) {
    body {
        padding: 20px;
    }
    
    .chat-container {
        height: calc(100vh - 40px);
        max-width: 900px;
        border-radius: 24px;
    }
}

/* モバイル用の設定 */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .chat-container {
        height: 100vh;
        height: 100svh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        border-radius: 0;
        max-width: 100%;
    }

    .message-content {
        max-width: 120%;
    }

    .chat-header {
        padding: 16px 20px; /* Reduced from 20px 24px */
    }

    .chat-messages {
        padding: 16px; /* Reduced from 20px */
        will-change: scroll-position; /* Smooth scrolling */
        overscroll-behavior: contain; /* Prevent iOS bounce affecting layout */
    }

    .chat-input-container {
        padding: 12px 16px; /* Reduced from 16px 20px */
        padding-bottom: max(12px, env(safe-area-inset-bottom)); /* Safe Area support */
    }

    .language-switcher {
        flex-direction: column; /* ボタンを縦に並べる */
        gap: 4px;
        margin-right: 8px;
    }

    .language-btn {
        padding: 4px 8px;
        font-size: 11px;
        white-space: nowrap; /* ボタン内のテキスト（国旗+言語名）を1行に保つ */
    }
}

/* 小型スマートフォン用の設定 (iPhone SE等) */
@media (max-width: 480px) {
    .chat-header {
        padding: 12px 16px;
    }

    .header-content h1 {
        font-size: 18px; /* Reduced from 22px */
    }

    .header-content p {
        font-size: 11px; /* Reduced from 13px */
    }

    .message-avatar {
        width: 36px; /* Reduced from 40px */
        height: 36px;
        font-size: 16px; /* Reduced from 18px */
    }

    .chat-messages {
        padding: 12px; /* Further reduced */
    }

    .chat-input-container {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* 横画面モード用の設定 */
@media (max-height: 500px) and (orientation: landscape) {
    .chat-header {
        padding: 8px 16px; /* More compact header */
    }

    .header-content h1 {
        font-size: 16px;
    }

    .header-content p {
        font-size: 10px;
    }

    .header-icon {
        width: 36px; /* Smaller logo */
        height: 36px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .chat-messages {
        padding: 12px;
    }

    .chat-input-container {
        padding: 8px 12px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

/* マークダウン要素のスタイル */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 8px 0 4px 0;
    color: inherit;
    font-weight: 600;
}

.message-content h1 {
    font-size: 1.2em;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 4px;
}

.message-content h2 {
    font-size: 1.1em;
}

.message-content h3 {
    font-size: 1.05em;
}

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

.message-content code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 2px 0;
    border-left: 3px solid #2c3e50;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content ul,
.message-content ol {
    margin: 6px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 2px 0;
}

.message-content blockquote {
    border-left: 3px solid #2c3e50;
    padding-left: 12px;
    margin: 2px 0;
    opacity: 0.8;
    font-style: italic;
}

.message-content p {
    margin: 0 0 8px 0;
    line-height: 1.4;
}

.message-content p:first-child {
    margin-top: 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.service-block {
    display: block;
    white-space: normal;
    word-break: break-word;
}

.service-title {
    white-space: normal;
}

.service-list li {
    white-space: normal;
}

/* reCAPTCHA Badge を左上に配置して最小限に小さく */
.grecaptcha-badge {
    position: fixed !important;
    left: 8px !important;
    top: 8px !important;
    right: auto !important;
    bottom: auto !important;
    z-index: 9999 !important;
    transform: scale(0.7) !important; /* 70%のサイズに縮小 */
    transform-origin: left top !important; /* 左上を基準に縮小 */
    opacity: 0.5 !important; /* 半透明にして目立たなくする */
    transition: opacity 0.3s ease !important;
}

.grecaptcha-badge:hover {
    opacity: 0.8 !important; /* ホバー時は少し濃く */
}

/* モバイル用の調整 */
@media (max-width: 768px) {
    .grecaptcha-badge {
        left: 4px !important;
        top: 4px !important;
        transform: scale(0.6) !important; /* モバイルではさらに小さく60% */
        opacity: 0.4 !important;
    }

    .grecaptcha-badge:hover {
        opacity: 0.7 !important;
    }
}
