/* リセット */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* チャットボットコンテナ */
.chatbot-container {
    max-width: 100%;
    margin: 0 auto;
    background: white;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* iOS Safari で flex 配下の横スクロールが効かないことがあるため、
   横スクロール対象の幅を明示し、親の最小幅制約も緩める */
.chat-header,
.chat-main,
.chat-input-area {
    min-width: 0;
    /*display: flex;*/
    /* 初期表示（入力欄はJS側で制御） */
}

/* ヘッダー */
.chat-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(64, 16, 0, 0.90);
    color: white;
    display: flex;
    align-items: center;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
    min-height: 56px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-between;
    gap: 12px;
}

.header-text {
    flex: 1;
    text-align: left;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
}

.chat-header h1 {
    font-size: 18px;
    margin: 0;
    color: #fff;
}

.chat-header p {
    font-size: 14px;
    opacity: 0.9;
}

.reset-btn {
    position: relative;
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.6);
    padding: 4px 8px;
    border-radius: 16px;
    font-size: 22px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    backdrop-filter: none;
}

.close-btn {
    position: relative;
    background: transparent;
    color: #fff;
    border: none;
    padding: 4px 6px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    backdrop-filter: none;
}

.reset-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.8);
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.8);
}

.reset-btn:active {
    transform: scale(0.98);
}

.close-btn:active {
    transform: scale(0.98);
}

@media (max-width: 768px) {
    .reset-btn {
        padding: 0 10px;
        font-size: 30px;
        border-radius: 0;
        border: none;
    }
}

/* チャットメインエリア */
.chat-main {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    background: #f9f9f9;
}

/* メッセージ */
.message {
    margin-bottom: 15px;
    display: flex;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
}

.bot-message .message-content {
    background: white;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.bot-message .message-content a.phone-link {
    color: #401000;
    text-decoration: underline;
    font-weight: 600;
    transition: color 0.3s;
    cursor: pointer;
}

.bot-message .message-content a.phone-link:hover {
    color: #5a1a00;
    text-decoration: underline;
}

.bot-message .message-content a.phone-link:active {
    color: #2d0a00;
}

.user-message .message-content {
    background: rgba(64, 16, 0, 0.90);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-hint {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
}

/* 症状選択UI */
.symptom-selector {
    margin-top: 14px;
}

/* 検索バー */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.search-bar input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
}

.search-bar input:focus {
    border-color: #401000;
}

.search-bar button {
    padding: 12px 24px;
    background: #401000;
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
}

.search-bar button:hover {
    background: #5a1a00;
}

/* よくある症状 */
.popular-symptoms {
    margin-bottom: 20px;
}

.popular-symptoms h3,
.category-selector h3 {
    font-size: 16px;
    margin-bottom: 10px;
    color: #333;
}

.symptom-buttons {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.symptom-btn {
    padding: 10px 16px;
    background: white;
    border: 2px solid #401000;
    border-radius: 20px;
    color: #401000;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.symptom-btn:hover {
    background: #401000;
    color: white;
}

.symptom-btn.selected {
    background: #401000;
    color: white;
}

/* カテゴリーボタン */
.category-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.category-btn {
    padding: 10px 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.category-btn:hover {
    border-color: #401000;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(64, 16, 0, 0.2);
}

.category-btn .icon {
    font-size: 32px;
}

.category-btn .name {
    font-size: 15px;
    font-weight: 600;
    color: #333;
}

/* 症状リスト */
.symptom-list {
    margin-top: 16px;
}

.symptom-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}

.symptom-item {
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 10px;
}

@media (max-width: 430px) {

    /* 狭い画面でも2列を維持しつつ圧迫を抑える */
    .symptom-items {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .symptom-item {
        padding: 10px;
    }

    .symptom-item label {
        font-size: 14px;
    }
}

.symptom-item:hover {
    border-color: #401000;
    background: rgba(64, 16, 0, 0.05);
}

.symptom-item input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: #401000;
    /* native check色をブランドカラーに */
    border: 2px solid #c6b6ad;
    border-radius: 4px;
    background: #fff;
    appearance: none;
    display: grid;
    place-items: center;
    transition: all 0.15s ease;
}

.symptom-item input[type="checkbox"]::after {
    content: '';
    width: 10px;
    height: 10px;
    transform: scale(0);
    transition: transform 0.15s ease;
    background: #401000;
    clip-path: polygon(14% 44%, 0 62%, 47% 100%, 100% 12%, 80% 0, 43% 62%);
}

.symptom-item input[type="checkbox"]:checked {
    border-color: #401000;
    background: #f7eee9;
    box-shadow: inset 0 0 0 2px rgba(64, 16, 0, 0.08);
}

.symptom-item input[type="checkbox"]:checked::after {
    transform: scale(1);
}

.symptom-item label {
    flex: 1;
    cursor: pointer;
    font-size: 14px;
}

.symptom-list-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.submit-btn {
    width: 100%;
    padding: 12px;
    background: #401000;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.submit-btn:hover {
    background: #5a1a00;
}

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

.back-btn {
    width: 100%;
    padding: 12px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s;
}

.back-btn:hover {
    background: #e0e0e0;
}

/* チャット入力エリア */
.chat-input-area {
    padding: 15px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    display: none;
}

.input-container {
    display: none;
    gap: 10px;
    margin-bottom: 10px;
}

.input-container input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 16px;
    outline: none;
}

.input-container input:focus {
    border-color: #401000;
}

.input-container button {
    padding: 12px 24px;
    background: #401000;
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
}

.input-container button:hover {
    background: #5a1a00;
}

/* クイックアクション */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.quick-action-btn {
    padding: 8px 16px;
    background: rgba(64, 16, 0, 0.05);
    border: 1px solid #401000;
    border-radius: 20px;
    color: #401000;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

/* 選択中（複数選択など） */
.quick-action-btn.selected {
    background: #401000;
    color: #ffffff;
}

/* 「次へ」などの主要ボタン */
.quick-action-btn.primary {
    background: #401000;
    color: #ffffff;
    border-color: #401000;
}

.quick-action-btn:hover {
    background: #401000;
    color: white;
}

/* 予約セクション */
.appointment-section {
    padding: 8px 10px;
    margin-top: 4px;
    background: #4a1300;
    /* 本体サイトの濃茶に合わせる */
    border-top: none;
}

.appointment-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* モバイル時は予約ボタンを横並びに */
@media (max-width: 768px) {
    .appointment-buttons {
        flex-direction: row;
        gap: 8px;
    }
}

.appointment-btn {
    padding: 12px;
    text-align: center;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex: 1;
}

.appointment-btn .icon {
    font-size: 18px;
    line-height: 1;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.appointment-btn .text {
    font-size: 12px;
    line-height: 1.2;
}

.appointment-btn {
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: #ffffff;
    color: #401000;
}

.appointment-btn.phone {
    background: #f15a24;
    color: #fff;
    border-color: #d94e1a;
}

.appointment-btn.line {
    background: #009800;
    color: #fff;
    border-color: #009800;
}

.appointment-btn.web {
    background: #b38d67;
    /* 指定ベージュ */
    color: #3b0f00;
    border-color: #a57f5d;
}

.appointment-btn .icon {
    color: inherit;
}

.appointment-btn.line .icon {
    display: inline-flex;
}

.appointment-btn.line .icon img {
    width: 18px;
    height: 18px;
    display: block;
}

.appointment-btn.phone .icon {
    color: #fff;
    /* 明示的に白固定 */
}

.appointment-btn.web .icon {
    color: #3b0f00;
    font-size: 20px;
    width: 20px;
    height: 20px;
}

.appointment-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
}

.appointment-btn.web:hover {
    background: #c19a72;
}

/* ローディング */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #401000;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* モバイル最適化 */
@media (max-width: 768px) {
    .header-content {
        /* flex-direction: column; */
        gap: 10px;
    }

    .header-text {
        width: 100%;
    }

    .reset-btn {
        font-size: 12px;
        padding: 6px 12px;
    }

    .chat-header h1 {
        font-size: 18px;
    }

    .chat-main {
        padding: 12px;
    }

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

    .category-buttons {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .symptom-buttons {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .symptom-btn {
        font-size: 13px;
        padding: 8px 14px;
        width: 100%;
        justify-content: center;
    }

    .search-bar {
        flex-direction: column;
        gap: 8px;
    }

    .search-bar button {
        width: 100%;
    }

    .appointment-section {
        padding: 12px;
    }

    .appointment-btn {
        padding: 12px 8px;
        min-height: 70px;
    }

    .appointment-btn .icon {
        font-size: 20px;
    }

    .appointment-btn .text {
        font-size: 11px;
    }
}

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

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

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

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



/* Mobile compact overrides */
@media (max-width: 768px) {

    /* Header: compact */
    .chat-header h1 {
        font-size: 16px;
        margin-bottom: 0;
    }

    .chat-header p {
        display: none;
    }

    .reset-btn {
        padding: 0 10px;
        font-size: 30px;
        border-radius: 0;
        border: none;
    }

    /* Chat area: a bit tighter */
    .chat-main {
        padding: 12px;
    }

    .message-content {
        padding: 10px 12px;
        max-width: 86%;
        font-size: 14px;
    }

    /* モバイルではBot側の吹き出しをフル幅にして、読みやすさと高さの無駄を減らす */
    .bot-message .message-content {
        max-width: 100%;
        width: 100%;
    }

    .message-hint {
        font-size: 11px;
        margin-top: 3px;
    }

    /* Search bar: compact */
    .search-bar {
        gap: 8px;
        margin-bottom: 14px;
    }

    .search-bar input {
        padding: 10px 12px;
        font-size: 15px;
    }

    .search-bar button {
        padding: 10px 14px;
        font-size: 14px;
    }

    /* Popular symptom buttons: smaller */
    .symptom-buttons {
        gap: 8px;
    }

    .symptom-btn {
        padding: 6px 10px;
        font-size: 13px;
        border-width: 1.5px;
    }

    /* Category buttons: 2 columns, low height */
    .category-buttons {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .category-btn {
        padding: 12px 10px;
        gap: 6px;
        border-radius: 10px;
    }

    .category-btn .icon {
        font-size: 22px;
    }

    .category-btn .name {
        font-size: 13px;
    }

    /* Quick actions: single-row horizontal scroll */
    .quick-actions {
        width: 100%;
        max-width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x;
        gap: 8px;
        padding-bottom: 6px;
    }

    .quick-action-btn {
        padding: 7px 12px;
        font-size: 13px;
        white-space: nowrap;
        flex: 0 0 auto;
        /* iOSでボタンが縮んで横スクロールできなくなるのを防ぐ */
    }

    .quick-action-btn.next-btn {
        margin-left: auto;
    }

    .quick-action-btn.skip-btn {
        margin-left: auto;
        background: #401000;
        color: #fff;
        border-color: #401000;
    }

    /* Appointment: compact row, icon left */
    .appointment-section {
        padding: 10px 12px;
    }

    .appointment-buttons {
        gap: 8px;
    }

    .appointment-btn {
        padding: 9px 10px;
        border-radius: 10px;
        flex-direction: row;
        justify-content: center;
        gap: 6px;
    }

    .appointment-btn .icon {
        font-size: 16px;
    }

    .appointment-btn .text {
        font-size: 12px;
    }
}


/* === Mobile-first compact booking buttons === */
@media (max-width: 768px) {
    .appointment-section {
        padding: 6px 10px;
    }

    .appointment-buttons {
        gap: 8px;
    }

    .appointment-btn {
        padding: 8px 10px;
        min-height: 38px;
        border-radius: 10px;
        font-size: 13px;
        line-height: 1;
    }

    .appointment-btn .icon {
        font-size: 14px;
        margin-right: 6px;
    }

    .appointment-btn .text {
        font-size: 13px;
        white-space: nowrap;
    }
}

/* === Question buttons: 2-row layout (options row + controls row) === */
#quickActions {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    min-height: 44px;
}

#quickActions .qa-options-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    touch-action: pan-x;
    padding: 2px 0;
}

#quickActions .qa-options-row::-webkit-scrollbar {
    display: none;
}

#quickActions .qa-controls-row {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

#quickActions .qa-controls-row .quick-action-btn {
    flex: 0 0 auto;
}

/* Ensure option buttons don't shrink so horizontal scroll always works */
#quickActions .qa-options-row .quick-action-btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

#quickActions .qa-options-row .quick-action-btn.scale-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 28px;
}

#quickActions .qa-options-row.scale-mode {
    flex-wrap: wrap;
}

/* PC時は全設問で折り返しを許可（横幅を超える場合は次行へ） */
@media (min-width: 769px) {
    #quickActions .qa-options-row {
        flex-wrap: wrap;
    }
}

@media (max-width:768px) {
    #quickActions {
        gap: 6px;
    }

    #quickActions .qa-options-row {
        gap: 8px;
    }
}

/* 回答後の並列ボタン用 */
#quickActions.post-actions {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 10px;
    padding: 4px 0;
    margin: 0;
}

#quickActions.post-actions .quick-action-btn {
    flex: 1 1 0;
    width: auto;
    white-space: nowrap;
}


/* === Mobile-first tweaks (v5.2.5) === */

/* Post-answer actions: two buttons side-by-side */
.quick-actions.post-actions {
    display: flex;
    gap: 10px;
    overflow: visible;
    flex-wrap: nowrap;
    padding: 4px 0;
    margin: 0;
}

.quick-actions.post-actions .quick-action-btn {
    flex: 1 1 0;
    min-width: 0;
}

/* Appointment buttons compact + icon smaller */
.appointment-buttons {
    gap: 8px;
}

.appointment-btn {
    padding: 8px 10px;
    border-radius: 10px;
}

.appointment-btn .icon {
    font-size: 14px;
    line-height: 1;
}

.appointment-btn .text {
    font-size: 13px;
    line-height: 1;
}

.appointment-btn.line {
    background: #06C755;
    border-color: #06C755;
}

.appointment-btn.line .line-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 4px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.22);
}

/* Category buttons: lower height and avoid awkward wraps */
.category-buttons {
    gap: 10px;
}

.category-btn {
    padding: 8px 10px;
    border-radius: 10px;
    gap: 6px;
}

.category-btn .icon {
    font-size: 16px;
    line-height: 1;
}

.category-btn .name {
    font-size: 15px;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile: keep category 2 columns and make them row layout */
@media (max-width: 768px) {
    .category-buttons {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .category-btn {
        flex-direction: row;
        justify-content: flex-start;
    }
}
