/* DenkiCheck Form フロントエンドスタイル */

.denkicheck-form {
    max-width: 800px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* プログレスバー */
.denkicheck-progress {
    margin-top: 2rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.denkicheck-progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.denkicheck-progress-bar::before {
    content: '';
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #007cba, #00a0d2);
    width: var(--progress, 0%);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.denkicheck-progress-text {
    font-size: 0.9rem;
    color: #666;
    text-align: center;
}

/* チャットコンテナ */
.denkicheck-chat-container {
    background: #fff;
    border: 1px solid #e1e5e9;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* メッセージエリア */
.denkicheck-messages {
    padding: 1.5rem;
    max-height: 400px;
    overflow-y: auto;
    background: linear-gradient(to bottom, #f8f9fa, #fff);
}

.denkicheck-message {
    margin-bottom: 1.5rem;
    animation: slideInUp 0.3s ease;
}

.denkicheck-message.bot {
    text-align: left;
}

.denkicheck-message.user {
    text-align: right;
}

.denkicheck-message-bubble {
    display: inline-block;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    max-width: 80%;
    word-wrap: break-word;
    position: relative;
}

.denkicheck-message.bot .denkicheck-message-bubble {
    background: #007cba;
    color: white;
    border-bottom-left-radius: 4px;
}

.denkicheck-message.bot.success .denkicheck-message-bubble {
    background: #28a745;
    color: white;
    border-bottom-left-radius: 4px;
}

.denkicheck-message.bot.error .denkicheck-message-bubble {
    background: #dc3545;
    color: white;
    border-bottom-left-radius: 4px;
}

.denkicheck-message.user .denkicheck-message-bubble {
    background: #e9ecef;
    color: #333;
    border-bottom-right-radius: 4px;
}

.denkicheck-message-bubble::before {
    content: '';
    position: absolute;
    bottom: 0;
    width: 0;
    height: 0;
    border: 6px solid transparent;
}

.denkicheck-message.bot .denkicheck-message-bubble::before {
    left: -6px;
    border-right-color: #007cba;
    border-bottom: none;
}

.denkicheck-message.bot.success .denkicheck-message-bubble::before {
    border-right-color: #28a745;
}

.denkicheck-message.bot.error .denkicheck-message-bubble::before {
    border-right-color: #dc3545;
}

.denkicheck-message.user .denkicheck-message-bubble::before {
    right: -6px;
    border-left-color: #e9ecef;
    border-bottom: none;
}

/* 過去のステップに戻る機能 */
.denkicheck-message-bubble.clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.denkicheck-message-bubble.clickable:hover {
    opacity: 0.8;
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.denkicheck-message.bot .denkicheck-message-bubble.clickable:hover {
    background: #005a87;
}

.denkicheck-message.user .denkicheck-message-bubble.clickable:hover {
    background: #d6d6d6;
}

/* 入力エリア */
.denkicheck-input-area {
    padding: 1.5rem;
    background: #fff;
    border-top: 1px solid #e1e5e9;
}

.denkicheck-current-step {
    margin-bottom: 1rem;
}

/* フィールドスタイル */
.denkicheck-field {
    margin-bottom: 1rem;
}

.denkicheck-field label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #2c3e50; /* より濃い色でコントラスト向上 */
    font-size: 1rem;
}

.denkicheck-field label .required-mark {
    color: #e74c3c;
    font-weight: 600;
    font-size: 0.9rem;
    margin-left: 0.25rem;
}

.denkicheck-field input[type="text"],
.denkicheck-field input[type="email"],
.denkicheck-field input[type="number"],
.denkicheck-field select,
.denkicheck-field textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #bdc3c7; /* より濃いボーダー色 */
    border-radius: 8px;
    font-size: 1rem;
    background: #ffffff;
    color: #2c3e50; /* 濃いテキスト色でコントラスト向上 */
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    line-height: 1.5;
}

.denkicheck-field input::placeholder,
.denkicheck-field textarea::placeholder {
    color: #7f8c8d; /* より濃いプレースホルダー色 */
    opacity: 1;
}

.denkicheck-field input:focus,
.denkicheck-field select:focus,
.denkicheck-field textarea:focus {
    outline: none;
    border-color: #0066cc; /* より濃いフォーカス色 */
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.25); /* より目立つフォーカスリング */
    background: #ffffff;
}

.denkicheck-field input:hover:not(:focus),
.denkicheck-field select:hover:not(:focus),
.denkicheck-field textarea:hover:not(:focus) {
    border-color: #95a5a6; /* ホバー時のボーダー色 */
}

.denkicheck-field input.error,
.denkicheck-field select.error,
.denkicheck-field textarea.error {
    border-color: #c0392b; /* より濃いエラー色 */
    background: #fdf2f2; /* 薄いエラー背景 */
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.15);
}

#top .denkicheck-form .denkicheck-input-with-suffix,
.denkicheck-form .denkicheck-input-with-suffix {
    display: flex;
    align-items: stretch;
    width: 100%;
}

#top .denkicheck-form .denkicheck-input-with-suffix input,
.denkicheck-form .denkicheck-input-with-suffix input {
    box-sizing: border-box;
    margin: 0;
    border: 2px solid #bdc3c7;
    border-right: 0;
    padding: 0.75rem;
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    background: #ffffff;
    color: #2c3e50;
}

#top .denkicheck-form .denkicheck-input-with-suffix input:focus:not(.error),
.denkicheck-form .denkicheck-input-with-suffix input:focus:not(.error) {
    border-color: #0066cc;
    box-shadow: none;
}

#top .denkicheck-form .denkicheck-input-with-suffix:focus-within:not(.denkicheck-has-error),
.denkicheck-form .denkicheck-input-with-suffix:focus-within:not(.denkicheck-has-error) {
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.25);
    border-radius: 8px;
}

#top .denkicheck-form .denkicheck-input-suffix,
.denkicheck-form .denkicheck-input-suffix {
    display: inline-flex;
    align-items: center;
    padding: 0 0.75rem;
    background: #f2f4f6;
    border: 2px solid #bdc3c7;
    border-left: 0;
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #5f6b76;
    white-space: nowrap;
}

#top .denkicheck-form .denkicheck-input-with-suffix input:focus + .denkicheck-input-suffix,
.denkicheck-form .denkicheck-input-with-suffix input:focus + .denkicheck-input-suffix {
    border-color: #0066cc;
}

#top .denkicheck-form .denkicheck-input-with-suffix input.error,
.denkicheck-form .denkicheck-input-with-suffix input.error {
    border-color: #c0392b;
    background: #fdf2f2;
}

#top .denkicheck-form .denkicheck-input-with-suffix input.error + .denkicheck-input-suffix,
.denkicheck-form .denkicheck-input-with-suffix input.error + .denkicheck-input-suffix {
    border-color: #c0392b;
    background: #fdf2f2;
}

.denkicheck-input-with-suffix.denkicheck-has-error,
#top .denkicheck-form .denkicheck-input-with-suffix.denkicheck-has-error {
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.15);
    border-radius: 8px;
}

.denkicheck-field .error-message {
    color: #c0392b; /* より濃いエラーメッセージ色 */
    font-size: 0.875rem;
    margin-top: 0.25rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.denkicheck-field .error-message::before {
    content: "⚠";
    color: #c0392b;
    font-size: 1rem;
}

/* ラジオボタン */
.denkicheck-radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.denkicheck-radio-option {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff;
    color: #2c3e50; /* テキスト色改善 */
    font-weight: 500;
    min-height: 48px; /* 最小高さを設定 */
}

.denkicheck-radio-option:hover {
    border-color: #0066cc;
    background: #f8f9fb;
}

.denkicheck-radio-option.selected {
    border-color: #0066cc;
    background: #e8f3ff;
    color: #2c3e50;
}

.denkicheck-radio-option:focus-within {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

.denkicheck-radio-option input[type="radio"] {
    margin-right: 0.75rem;
    width: 16px;
    height: 16px;
    flex-shrink: 0; /* サイズ変更を防ぐ */
    accent-color: #0066cc; /* ラジオボタンの色改善 */
    vertical-align: middle; /* 垂直位置調整 */
}

.denkicheck-radio-option label {
    flex: 1;
    cursor: pointer;
    line-height: 1.4;
    margin: 0; /* デフォルトのマージンを削除 */
    display: flex;
    align-items: center; /* ラベル内の垂直位置調整 */
}

/* 選択肢ボタン */
.denkicheck-choices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.denkicheck-choice {
    border: 2px solid #bdc3c7;
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff;
    color: #2c3e50; /* テキスト色改善 */
    position: relative;
    display: flex;
    align-items: flex-start;
    text-align: left;
    gap: 1rem;
}

.denkicheck-choice:hover {
    border-color: #0066cc;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.denkicheck-choice.selected {
    border-color: #0066cc;
    background: #e8f3ff;
    color: #2c3e50;
}

.denkicheck-choice:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

.denkicheck-choice-thumbnail {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}

.denkicheck-choice-content {
    flex: 1;
    min-width: 0; /* flexアイテムでのオーバーフロー防止 */
}

.denkicheck-choice-label {
    font-weight: 600;
    color: inherit; /* 親要素の色を継承 */
    margin-bottom: 0.25rem;
    font-size: 1rem;
    line-height: 1.4;
}

.denkicheck-choice-description {
    font-size: 0.875rem;
    color: #6c757d; /* ラベルより薄い色 */
    line-height: 1.4;
    margin: 0;
    font-weight: 400;
}

/* ボタン */
.denkicheck-buttons {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    margin-top: 1rem;
}

.denkicheck-buttons .button-group {
    display: flex;
    gap: 0.5rem;
}

.denkicheck-next-btn,
.denkicheck-submit-btn {
    background: #0066cc;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px; /* タッチターゲットサイズ改善 */
}

.denkicheck-next-btn:hover,
.denkicheck-submit-btn:hover {
    background: #004499;
    transform: translateY(-1px);
}

.denkicheck-next-btn:focus,
.denkicheck-submit-btn:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
    background: #004499;
}

.denkicheck-next-btn:disabled,
.denkicheck-submit-btn:disabled {
    background: #95a5a6;
    cursor: not-allowed;
    transform: none;
    opacity: 0.7;
}

.denkicheck-reset-btn {
    background: transparent;
    color: #DA2C00;
    border: none;
    padding: 0.5rem 0;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: underline;
    font-weight: bold;
    min-height: auto;
}

.denkicheck-reset-btn:hover {
    color: #b12400;
    text-decoration: underline;
}

.denkicheck-reset-btn:focus {
    outline: 2px solid #DA2C00;
    outline-offset: 2px;
}

/* リセットボタンエリア */
.denkicheck-reset-area {
    text-align: center;
    margin-top: 0.5rem;
}

/* アニメーション */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.denkicheck-current-step {
    animation: fadeIn 0.3s ease;
}

/* ローカルストレージ復元時のアニメーション */
.denkicheck-form.restoring .denkicheck-message {
    animation: fadeInUp 0.3s ease forwards;
}

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

/* レスポンシブ */
@media (max-width: 768px) {
    .denkicheck-form {
        margin: 0 1rem;
    }
    
    .denkicheck-choices {
        grid-template-columns: 1fr;
    }
    
    .denkicheck-message-bubble {
        max-width: 90%;
    }
    
    .denkicheck-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .denkicheck-buttons .button-group {
        justify-content: center;
    }
}

/* アクセシビリティ */
@media (prefers-reduced-motion: reduce) {
    .denkicheck-message,
    .denkicheck-current-step {
        animation: none;
    }
    
    .denkicheck-choice:hover,
    .denkicheck-next-btn:hover,
    .denkicheck-submit-btn:hover {
        transform: none;
    }
}

/* フォーカススタイル */
.denkicheck-choice:focus,
.denkicheck-radio-option:focus-within,
.denkicheck-next-btn:focus,
.denkicheck-submit-btn:focus,
.denkicheck-reset-btn:focus {
    outline: 3px solid #0066cc; /* より目立つアウトライン */
    outline-offset: 2px;
}

/* 高コントラストモード対応 */
@media (prefers-contrast: high) {
    .denkicheck-field input[type="text"],
    .denkicheck-field input[type="email"],
    .denkicheck-field input[type="number"],
    .denkicheck-field select,
    .denkicheck-field textarea {
        border-width: 3px;
        border-color: #000000;
    }
    
    .denkicheck-field label,
    .denkicheck-choice-label,
    .denkicheck-radio-option {
        color: #000000;
        font-weight: 700;
    }
    
    .denkicheck-choice-description {
        color: #333333; /* 高コントラストモードでも十分なコントラスト */
        font-weight: 600;
    }
    
    .denkicheck-choice,
    .denkicheck-radio-option {
        border-width: 3px;
        border-color: #000000;
    }
}

/* スクリーンリーダー用 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 入力フィールドの可読性向上 */
.denkicheck-field input[type="text"]:valid,
.denkicheck-field input[type="email"]:valid,
.denkicheck-field input[type="number"]:valid,
.denkicheck-field textarea:valid {
    background: #f8fff8; /* 薄い緑の背景で入力済みを示す */
}

.denkicheck-field select:valid {
    background: #f8fff8;
}

/* 入力中のスタイル */
.denkicheck-field input:not(:placeholder-shown),
.denkicheck-field textarea:not(:placeholder-shown) {
    background: #ffffff;
    border-color: #0066cc;
}

/* キーボードアクセシビリティ向上 */
.denkicheck-form-accessible {
    font-size: 16px; /* iOSでズームを防ぐ */
}

.denkicheck-form-accessible *:focus-visible {
    outline: 3px solid #0066cc !important;
    outline-offset: 2px !important;
}

/* タッチデバイス対応 */
@media (hover: none) and (pointer: coarse) {
    .denkicheck-choice,
    .denkicheck-radio-option,
    .denkicheck-next-btn,
    .denkicheck-submit-btn,
    .denkicheck-reset-btn {
        min-height: 44px; /* Appleガイドライン準拠 */
        min-width: 44px;
    }
    
    .denkicheck-field input,
    .denkicheck-field select,
    .denkicheck-field textarea {
        min-height: 44px;
        font-size: 16px; /* iOSでズームを防ぐ */
    }
}

/* アニメーション削減設定対応 */
@media (prefers-reduced-motion: reduce) {
    .denkicheck-message,
    .denkicheck-current-step,
    .denkicheck-choice:hover,
    .denkicheck-next-btn:hover,
    .denkicheck-submit-btn:hover {
        animation: none !important;
        transition: none !important;
        transform: none !important;
    }
}

/* 色覚特性対応 - 削除: 各項目の警告アイコンは不要
.denkicheck-field input.error::before {
    content: "⚠ ";
    color: #c0392b;
    font-weight: bold;
    margin-right: 0.25rem;
}
*/

/* Windows High Contrast Mode対応 */
@media screen and (-ms-high-contrast: active) {
    .denkicheck-field input,
    .denkicheck-field select,
    .denkicheck-field textarea,
    .denkicheck-choice,
    .denkicheck-radio-option {
        border: 2px solid WindowText;
    }
    
    .denkicheck-choice.selected,
    .denkicheck-radio-option.selected {
        background: Highlight;
        color: HighlightText;
    }
    
    .denkicheck-next-btn,
    .denkicheck-submit-btn {
        background: ButtonFace;
        color: ButtonText;
        border: 2px solid ButtonText;
    }
}
