/**
 * 公開ページのAIサポートチャット。
 * 色はサイト既存のパレット(#123d61 / #1788d1 / #137cbe)に合わせている。
 *
 * ウィジェットはサイトのどのページにも重ねて出すため、ページ側のCSSが
 * 要素セレクタ(トップページの section{padding:90px 0} など)で入り込んでこないよう、
 * 自分が使う箱の余白は必ず自前で明示する。
 */

/* ページ側の指定に勝てるよう、ウィジェット内の余白は明示的に打ち消してから組み立てる */
.chat-widget,
.chat-widget *,
.chat-widget *:before,
.chat-widget *:after {
    box-sizing: border-box;
}

.chat-widget > *,
.chat-panel > * {
    margin: 0;
}

.chat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 900;
    font-size: 15px;
    line-height: 1.75;
}

/* ---- 起動ボタン ---- */

.chat-launcher {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 13px 20px 13px 16px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, #1788d1, #137cbe);
    box-shadow: 0 10px 28px rgba(18, 61, 97, .28);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
}

.chat-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 32px rgba(18, 61, 97, .34);
}

.chat-launcher-icon {
    display: grid;
    width: 24px;
    height: 24px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, .22);
    font-size: 14px;
    font-weight: 900;
}

.chat-widget.is-open .chat-launcher {
    display: none;
}

/* ---- パネル ---- */

.chat-panel {
    display: flex;
    width: min(380px, calc(100vw - 32px));
    max-height: min(620px, calc(100vh - 100px));
    /* ページ側の section{padding:90px 0} 等に上書きされないよう明示する */
    padding: 0;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #dfeaf3;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 22px 60px rgba(18, 61, 97, .26);
}

.chat-panel[hidden] {
    display: none;
}

.chat-panel-head {
    display: flex;
    padding: 16px 16px 14px;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    background: #123d61;
    color: #fff;
}

.chat-panel-eyebrow {
    margin: 0 0 3px;
    color: #a9cbe4;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
}

.chat-panel-title {
    margin: 0;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.5;
}

.chat-close {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}

.chat-close:hover {
    background: rgba(255, 255, 255, .26);
}

/* ---- 会話ログ ---- */

.chat-log {
    flex: 1 1 auto;
    min-height: 200px;
    padding: 16px 14px 6px;
    overflow-y: auto;
    background: #f7f9fa;
    overscroll-behavior: contain;
}

.chat-bubble {
    max-width: 88%;
    margin-bottom: 12px;
    padding: 11px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.8;
}

.chat-bubble p {
    margin: 0 0 6px;
}

.chat-bubble p:last-child {
    margin-bottom: 0;
}

.chat-bubble-bot {
    border: 1px solid #e2eaf0;
    border-top-left-radius: 4px;
    background: #fff;
    color: #294f6d;
}

.chat-bubble-user {
    margin-left: auto;
    border-top-right-radius: 4px;
    background: #1788d1;
    color: #fff;
}

/* ---- 質問例 ---- */

.chat-suggestions {
    display: flex;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 7px;
}

.chat-suggestion {
    padding: 8px 13px;
    border: 1px solid #bcd7e9;
    border-radius: 999px;
    background: #fff;
    color: #0e70ae;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s ease;
}

.chat-suggestion:hover {
    background: #f3f9fd;
}

/* ---- お問い合わせへの導線 ---- */

.chat-handoff {
    margin: -4px 0 14px;
}

.chat-handoff-link {
    display: inline-block;
    padding: 9px 16px;
    border-radius: 8px;
    background: #123d61;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.chat-handoff-link:hover {
    background: #0b426f;
    color: #fff;
}

/* ---- 入力中の表示 ---- */

.chat-typing {
    display: flex;
    width: auto;
    max-width: 72px;
    align-items: center;
    gap: 5px;
}

.chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #91a2af;
    animation: chat-typing-bounce 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) {
    animation-delay: .15s;
}

.chat-typing span:nth-child(3) {
    animation-delay: .3s;
}

@keyframes chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-typing span { animation: none; }
    .chat-launcher { transition: none; }
}

/* ---- 入力欄 ---- */

.chat-form {
    display: flex;
    padding: 11px 12px;
    align-items: flex-end;
    gap: 8px;
    border-top: 1px solid #e6edf2;
    background: #fff;
}

.chat-input {
    flex: 1 1 auto;
    min-height: 42px;
    max-height: 120px;
    padding: 10px 12px;
    border: 1px solid #cdd9e2;
    border-radius: 10px;
    color: #243b49;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    resize: none;
}

.chat-input:focus {
    border-color: #1788d1;
    outline: 2px solid rgba(23, 136, 209, .18);
    outline-offset: 0;
}

.chat-send {
    flex: 0 0 auto;
    min-height: 42px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: #1788d1;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.chat-send:hover:not(:disabled) {
    background: #0e70ae;
}

.chat-send:disabled {
    background: #a9c3d4;
    cursor: default;
}

/* ---- 注意書き ---- */

.chat-note {
    margin: 0;
    padding: 0 14px 13px;
    background: #fff;
    color: #6b7d8a;
    font-size: 11.5px;
    line-height: 1.7;
}

.chat-note a {
    color: #0e70ae;
    font-weight: 700;
}

.chat-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---- スマートフォン ---- */

@media (max-width: 575.98px) {
    .chat-widget {
        right: 12px;
        bottom: 12px;
    }

    .chat-launcher-label {
        font-size: 13px;
    }

    .chat-panel {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 80px);
    }
}
