/* NOIM Chat Widget Styles */

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

html {
    height: -webkit-fill-available; /* iOS Safari */
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    height: -webkit-fill-available; /* iOS Safari */
    height: 100%;
    background: #ffffff; /* 透過すると親ページが見えるため */
    overflow: hidden;
}

.chat-container {
    width: 100%;
    height: 100vh;
    height: 100svh; /* iOS Safari: アドレスバー表示時の視認領域に合わせる */
    height: 100dvh;
    min-height: -webkit-fill-available; /* iOS Safari fallback */
    display: flex;
    flex-direction: column;
    background: linear-gradient(to bottom, #ebf8ff, #c9eaff);
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* ヘッダー */
.chat-header {
    background: none;
    height: 70px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    position: relative;
}

.chat-title {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.chat-icon {
    display: none; /* アイコンは非表示 */
}

.chat-logo {
    height: 30px;
    width: auto;
    object-fit: contain;
}

.consent-close-button {
    background: none;
    border: none;
    color: #4e9eff;
    width: 40px;
    height: 40px;
    padding: 0;
    cursor: pointer;
    font-size: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
    position: absolute;
    top: 5%;
    right: 10px;
    transform: translateY(-50%);
    z-index: 99;
}

.close-button {
    background: none;
    border: none;
    color: #4e9eff;
    width: 40px;
    height: 40px;
    padding: 0;
    cursor: pointer;
    font-size: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
}

.close-button:hover {
    opacity: 0.7;
}

/* メッセージエリア */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

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

.message.bot {
    align-self: flex-start;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
    max-width: 100%;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    overflow-wrap: anywhere;
    line-height: 1.4;
    font-size: 14px;
    white-space: pre-wrap;
}

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

.message.bot .message-content {
    background: #ffffff;
    color: #333333;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 4px;
}

.message-bot-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.message-bot-avatar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.bot-name {
    font-size: 10px;
    color: #444444;
    text-align: center;
    font-weight: 500;
}

.message-content-wrapper {
    display: flex;
    flex-direction: row;
    flex: 1;
    align-items: flex-end;
    gap: 8px;
}

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

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

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

.welcome-message {
    align-self: flex-start;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
    max-width: 80%;
}

.welcome-message .message-content {
    background: #ffffff;
    color: #333333;
    border: 1px solid #e9ecef;
    border-radius: 18px;
}

/* クイック選択ボタン（サジェストチップ） */
.quick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 50px; /* ボットアイコン幅に合わせてインデント */
    animation: messageSlideIn 0.3s ease-out;
}

.quick-chip {
    background: #ffffff;
    color: #4e9eff;
    border: 1px solid #79b2f7;
    border-radius: 18px;
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    white-space: nowrap;
}

.quick-chip:hover {
    background: #79b2f7;
    color: #ffffff;
}


/* 入力エリア */
.chat-input-area {
    padding: 20px;
    background: transparent;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

.input-container {
    display: flex;
    gap: 12px;
    align-items: center;
    background: #ffffff;
    border-radius: 24px;
    padding: 4px;
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: 0px none #ffffff;
    border-radius: 24px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s ease;
}

#message-input:focus {
    border-color: #007bff;
}

#message-input::placeholder {
    color: #6c757d;
}

.send-button {
    background: #79b2f7;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background-color 0.2s ease;
}

.send-button:hover {
    background: #0056b3;
}

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

.send-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.input-footer {
    text-align: center;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.input-footer small {
    color: #6c757d;
    font-size: 11px;
}

/* CTAボタン */
.cta-buttons {
    display: flex;
    gap: 8px;
    justify-content: left;
    width: 100%;
}

.cta-button {
    /* flex: 1; */
    padding: 8px 16px;
    border-radius: 18px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease;
    line-height: 1.4;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.cta-button--contact {
    background: #4e9eff;
    color: #ffffff;
    border: none;
}

.cta-button--contact:hover {
    background: #2e7dd4;
    color: #ffffff;
}

.cta-button--summary {
    background: #ffffff;
    color: #4e9eff;
    border: 1px solid #79b2f7;
}

.cta-button--summary:hover {
    background: #79b2f7;
    color: #ffffff;
}

.reset-conversation-button {
    appearance: none;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    color: #4e9eff;
    font-size: 11px;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.reset-conversation-button:hover,
.reset-conversation-button:focus {
    opacity: 0.85;
}

.reset-conversation-button:focus-visible {
    outline: 2px solid rgba(78, 158, 255, 0.5);
    outline-offset: 3px;
    border-radius: 4px;
}

/* フッター */
.chat-footer {
    padding: 8px 20px;
    background: transparent;
    border-top: 1px solid #e9ecef;
    text-align: center;
    flex-shrink: 0;
}

.chat-footer small {
    color: #6c757d;
    font-size: 10px;
}

.chat-footer a {
    color: #79b2f7;
    text-decoration: none;
}

.chat-footer a:hover {
    text-decoration: underline;
}

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

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

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

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

/* アニメーション */
.message {
    animation: messageSlideIn 0.3s ease-out;
}

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

/* レスポンシブデザイン */
@media (max-width: 480px) {
    .chat-container {
        border-radius: 0;
        height: 100vh;
        height: 100svh; /* iOS Safari: アドレスバー表示時の視認領域に合わせる */
        height: 100dvh;
        min-height: -webkit-fill-available; /* iOS Safari fallback */
        margin: 0;
        padding: 0;
        width: 100vw;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    /* iOS Safariの自動ズーム対策 */
    input, textarea {
        font-size: 16px;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .chat-messages {
        padding: 16px;
    }
    
    .chat-input-area {
        /* iOS Safari の下部バー/ホームインジケータに被らないよう余白を確保 */
        padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    }
    
    .message {
        max-width: 90%;
    }
}

/* ダークテーマ */
.chat-container.dark-theme {
    background: linear-gradient(to bottom, #1a1a1a, #2d2d2d);
    color: #ffffff;
}

.chat-container.dark-theme .chat-messages {
    background: transparent;
}

.chat-container.dark-theme .message.bot .message-content {
    background: #3a3a3a;
    color: #ffffff;
    border-color: #4a4a4a;
}

.chat-container.dark-theme .chat-input-area {
    background: transparent;
    border-top-color: #4a4a4a;
}

.chat-container.dark-theme #message-input {
    background: #3a3a3a;
    border-color: #4a4a4a;
    color: #ffffff;
}

.chat-container.dark-theme #message-input::placeholder {
    color: #888;
}

.chat-container.dark-theme .input-footer small {
    color: #888;
}

.chat-container.dark-theme .reset-conversation-button {
    color: #79b2f7;
}

.chat-container.dark-theme .chat-footer {
    border-top-color: #4a4a4a;
}

.chat-container.dark-theme .chat-footer small {
    color: #888;
}

.chat-container.dark-theme .chat-footer a {
    color: #79b2f7;
}

/* 開閉アニメーション */
.chat-container {
    animation: widgetSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes widgetSlideIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ウィジェットの開閉状態管理 */
.chat-container.closing {
    animation: widgetSlideOut 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes widgetSlideOut {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
}

/* レスポンシブ対応の改善 */
@media (max-width: 768px) {
    .chat-container {
        border-radius: 4px;
        height: 100vh;
        height: 100dvh;
        animation: widgetSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    @keyframes widgetSlideInMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .chat-container.closing {
        animation: widgetSlideOutMobile 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    }
    
    @keyframes widgetSlideOutMobile {
        from {
            opacity: 1;
            transform: translateY(0);
        }
        to {
            opacity: 0;
            transform: translateY(100%);
        }
    }
}

/* ボタンの状態管理 */
.noim-chat-button {
    transition: all 0.2s ease;
}

.noim-chat-button:hover {
    transform: scale(1.1);
}

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

/* ローディング状態 */
.chat-container.loading {
    opacity: 0.7;
    pointer-events: none;
}

.chat-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* メッセージ内のリンクスタイル */
.message-content a {
    color: #0066cc;
    text-decoration: underline;
    word-break: break-all;
}

.message-content a:hover {
    color: #0052a3;
    text-decoration: none;
}

.message-content a:visited {
    color: #551a8b;
}

/* 同意オーバーレイ */
.consent-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: linear-gradient(to bottom, #ebf8ff, #c9eaff); /* チャットと同背景 */
    display: none;
    align-items: stretch; /* 全画面を満たす */
    justify-content: center;
    padding: 16px;
    z-index: 2147483647; /* 最前面 */
    width: 100vw; /* 全画面カバーの明示 */
    height: 100vh;
    height: 100dvh; /* モバイルブラウザのUI考慮 */
    overscroll-behavior: none;
    touch-action: none;
}

.consent-overlay.visible {
    display: flex;
}

.consent-modal {
    width: 100%;
    height: 100%;
    max-width: none;
    background: transparent; /* 親のグラデーションを活かす */
    color: #333333;
    border-radius: 0;
    box-shadow: none;
    padding: 24px;
    overflow: hidden;
    transform: translateY(100%); /* 初期は画面下 */
    display: flex;
    flex-direction: column;
}

.consent-title {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 16px;
    letter-spacing: 0.02em;
}

.consent-title::after {
    content: '';
    display: block;
    width: 64px;
    height: 3px;
    background: #79b2f7;
    border-radius: 2px;
    margin: 10px auto 0;
}

.consent-card {
    width: 100%;
    max-width: 720px;
    margin: 12px auto 0;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    padding: 16px;
}

.consent-body {
    overflow: auto;
    margin-bottom: 12px; /* ボタンを本文直下に近づける */
}

.consent-body p {
    margin-bottom: 8px;
    line-height: 1.6;
}

/* 同意本文内リンク */
.consent-body a {
    color: #79b2f7;
    text-decoration: none;
}

.consent-body a:hover,
.consent-body a:focus {
    text-decoration: underline;
}

.consent-actions {
    display: flex;
    justify-content: center; /* 中央寄せ */
    gap: 12px;
    margin-top: 12px; /* 本文直下へ */
}

.consent-accept-button {
    background: #79b2f7;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
}

.consent-accept-button:hover {
    background: #0056b3;
}

/* 同意オーバーレイフッター */
.consent-footer {
    margin-top: 16px;
    text-align: center;
}

.consent-footer small {
    color: #6c757d;
    font-size: 10px;
}

.consent-footer a {
    color: #79b2f7;
    text-decoration: none;
}

.consent-footer a:hover {
    text-decoration: underline;
}

/* スライドアニメーション */
@keyframes consentModalIn {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@keyframes consentModalOut {
    from { transform: translateY(0); }
    to { transform: translateY(100%); }
}

.consent-overlay.visible .consent-modal {
    animation: consentModalIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.consent-overlay.closing .consent-modal {
    animation: consentModalOut 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}