/* iOSの自動ズームを防ぐ */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="tel"],
textarea,
select {
    font-size: 16px !important; /* iOS自動ズームを防ぐ最小サイズ */
}

/* 計算フォームの入力フィールドも16px以上に */
form input[type="text"],
form input[type="number"] {
    font-size: 16px !important;
    -webkit-appearance: none;
    appearance: none;
}

/* モバイルでの入力フィールド最適化 */
@media (max-width: 800px) {
    form input[type="text"],
    form input[type="number"] {
        font-size: 16px !important;
        padding: 10px;
        border-radius: 5px;
    }
}

/* チャットウィンドウのスタイル */
#chat-popup {
    position: fixed;
    width: 350px;
    height: 500px;
    border: 1px solid #ccc;
    border-radius: 10px;
    background: #f9f9f9;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-family: 'Hiragino Sans', 'Meiryo', Arial, sans-serif;
    overflow: hidden;
    display: none;
    flex-direction: column;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* JavaScriptでmobile-viewクラスが付いた場合（モバイル） */
#chat-popup.mobile-view {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 85vh !important;
    max-height: 85vh !important;
    border-radius: 20px 20px 0 0 !important;
    transform: translateY(100%) !important;
}

#chat-popup.mobile-view.show {
    opacity: 1 !important;
    transform: translateY(0) !important;
    visibility: visible !important;
}

#chat-popup.mobile-view.closing {
    opacity: 0 !important;
    transform: translateY(100%) !important;
}

/* デフォルト（PC表示） */
#chat-popup:not(.mobile-view) {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 400px;
    height: 550px;
    max-width: 90vw;
    max-height: 85vh;
}

#chat-popup:not(.mobile-view).show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) !important;
    visibility: visible;
}

#chat-popup:not(.mobile-view).closing {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95) !important;
    transition: all 0.25s ease-out;
}

/* ビューポート幅でのフォールバック */
@media only screen and (max-width: 800px) {
    #chat-popup {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    #chat-messages {
        max-height: calc(85vh - 140px);
    }
}

/* iPhone Pro Max等の大画面スマホ対応 */
@media only screen 
    and (min-device-width: 414px) 
    and (max-device-width: 448px)
    and (-webkit-min-device-pixel-ratio: 3) {
    #chat-popup {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 85vh !important;
        max-height: 85vh !important;
        border-radius: 20px 20px 0 0 !important;
    }
}

/* タッチデバイス判定 */
@media (pointer: coarse) and (max-width: 1024px) {
    #chat-popup {
        /* タッチデバイスでの調整 */
    }
    
    .option-button,
    .radio-option,
    .submit-radio-button {
        min-height: 44px; /* Apple推奨のタップターゲットサイズ */
    }
}

/* ヘッダー（×ボタン削除版） */
#chat-header {
    background: #e94b35;
    color: white;
    padding: 15px;
    font-weight: bold;
    display: flex;
    justify-content: center; /* 中央寄せに変更 */
    align-items: center;
    flex-shrink: 0;
    min-height: 50px;
}

/* モバイルビューでのヘッダー調整 */
.mobile-view #chat-header {
    padding: 12px 15px;
    font-size: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* メッセージエリア */
#chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: white;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.mobile-view #chat-messages {
    padding: 10px;
    max-height: calc(85vh - 140px);
}

.message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    animation: messageFadeIn 0.3s ease-out;
}

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

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

.bot-message .bubble {
    background: #e9e9eb;
    color: #333;
    border-radius: 15px 15px 15px 5px;
    padding: 10px 15px;
    max-width: 85%;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 15px; /* 14px → 15pxに変更 */
}

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

.user-message .bubble {
    background: #e94b35;
    color: white;
    border-radius: 15px 15px 5px 15px;
    padding: 10px 15px;
    max-width: 85%;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 15px; /* 14px → 15pxに変更 */
}

/* モバイルビューでのメッセージ調整 */
.mobile-view .bot-message .bubble,
.mobile-view .user-message .bubble {
    font-size: 15px; /* 13px → 15pxに変更 */
    padding: 10px 14px; /* パディングも少し増やす */
    max-width: 90%;
    line-height: 1.6; /* 行間も少し広げる */
}

/* 計算結果表示用スタイル */
.result-display {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 12px;
    padding-bottom: 40px;
    margin: 10px 0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    position: relative;
    white-space: pre-wrap;
    min-height: 60px;
    word-break: break-all;
    overflow-x: auto;
    /* テキスト選択を可能にする */
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

.mobile-view .result-display {
    font-size: 13px; /* 11px → 13pxに変更 */
    padding: 12px; /* 10px → 12pxに変更 */
    padding-bottom: 40px; /* 35px → 40pxに変更 */
    line-height: 1.7; /* 行間も広げる */
}

.copy-button {
    position: absolute !important;
    bottom: 8px !important;
    right: 8px !important;
    background: #e94b35;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
    white-space: nowrap;
    /* タッチデバイス用の最適化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.copy-button:active {
    transform: scale(0.95);
}

.copy-button:hover {
    background: #c73926;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.copy-button.copied {
    background: #28a745 !important;
}

/* オプションエリア */
#chat-options {
    padding: 10px 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: white;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    justify-content: center;
}

.mobile-view #chat-options {
    padding: 8px 10px;
    gap: 6px;
}

.option-button {
    background: #fff;
    border: 2px solid #e94b35;
    color: #e94b35;
    border-radius: 20px;
    padding: 10px 16px; /* 8px 15px → 10px 16pxに変更 */
    cursor: pointer;
    font-size: 15px; /* 14px → 15pxに変更 */
    transition: all 0.2s;
    flex: 0 1 auto;
    min-width: 100px;
    text-align: center;
}

.mobile-view .option-button {
    font-size: 15px; /* 13px → 15pxに変更 */
    padding: 10px 14px; /* 6px 12px → 10px 14pxに変更 */
    min-width: 45%;
    min-height: 44px; /* タップしやすい高さを確保 */
}

.option-button:hover {
    background: #e94b35;
    color: white;
    transform: translateY(-2px);
}

/* ラジオボタン選択肢のスタイル */
.radio-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 15px;
    background: white;
    border-top: 1px solid #eee;
    width: 100%;
}

.mobile-view .radio-options {
    padding: 8px 10px;
    gap: 6px;
}

.radio-option {
    display: flex;
    align-items: center;
    padding: 10px 14px; /* 8px 12px → 10px 14pxに変更 */
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.mobile-view .radio-option {
    padding: 12px; /* 10px → 12pxに変更 */
    font-size: 15px; /* 13px → 15pxに変更 */
    min-height: 48px; /* 44px → 48pxに変更 */
}

.radio-option:hover {
    background: #fff5f5;
    border-color: #e94b35;
}

.radio-option input[type="radio"] {
    margin-right: 10px;
    flex-shrink: 0;
}

.radio-option label {
    cursor: pointer;
    flex: 1;
    margin: 0;
    line-height: 1.5; /* 1.4 → 1.5に変更 */
    font-size: 15px; /* フォントサイズを明示的に指定 */
}

.radio-option.selected {
    background: #ffe9e6;
    border-color: #e94b35;
}

.submit-radio-button {
    background: #e94b35;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 12px 20px; /* 10px 20px → 12px 20pxに変更 */
    cursor: pointer;
    font-size: 15px; /* 14px → 15pxに変更 */
    margin-top: 10px;
    transition: all 0.2s;
    width: 100%;
}

.mobile-view .submit-radio-button {
    padding: 12px 18px; /* 8px 16px → 12px 18pxに変更 */
    font-size: 15px; /* 13px → 15pxに変更 */
    min-height: 48px; /* 44px → 48pxに変更 */
}

.submit-radio-button:hover {
    background: #c73926;
    transform: translateY(-2px);
}

.submit-radio-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* 入力エリア */
#chat-input-area {
    display: none;
    border-top: 1px solid #ccc;
    padding: 10px;
    background: #fff;
    flex-shrink: 0;
    flex-direction: row;
    align-items: center;
    gap: 5px;
}

.mobile-view #chat-input-area {
    padding: 8px;
    gap: 4px;
}

#chat-input {
    flex-grow: 1;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 10px; /* 8px → 10pxに変更 */
    font-size: 16px !important;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
}

.mobile-view #chat-input {
    padding: 10px 12px; /* 8px 10px → 10px 12pxに変更 */
    font-size: 16px !important;
}

#chat-send, #chat-skip {
    background: #e94b35;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px 14px; /* 8px 12px → 10px 14pxに変更 */
    cursor: pointer;
    font-size: 15px; /* 14px → 15pxに変更 */
    white-space: nowrap;
    flex-shrink: 0;
}

#chat-skip {
    background: #6c757d;
}

.mobile-view #chat-send,
.mobile-view #chat-skip {
    padding: 10px 12px; /* 6px 10px → 10px 12pxに変更 */
    font-size: 14px; /* 12px → 14pxに変更 */
    min-height: 40px; /* 最小高さを設定 */
}

/* デモ確認画面 */
#demo-message {
    animation: fadeIn 0.3s ease-out;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 20000;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    text-align: left;
}

@media (max-width: 600px) {
    #demo-message {
        width: 90%;
        max-width: none;
        padding: 20px;
        max-height: 85vh;
    }
}

@media (max-width: 400px) {
    #demo-message {
        width: 95%;
        padding: 15px;
        max-height: 90vh;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* スクロールバーのスタイル（Webkit系ブラウザ） */
#chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

#chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

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