/* ============================================================
 * そらっきーに質問 チャット画面 (DD 002_user / XD そらっきーに質問1007)
 * ヘッダー (75px) とフッター (70px) の間に固定表示する
 * ============================================================ */
:root {
    /* XD 01〜36 の選択ボタン・「質問終了」の色 */
    --sorakky-blue: #6aa9dd;
    --sorakky-blue-strong: #3b8be6;
    --sorakky-link: #3b8be6;
    --sorakky-bubble: #f6f6f6;
    --sorakky-bubble-border: #c8c8c8;
    --sorakky-user: #f0f6ff;
    --sorakky-input-area: #eef5ff;
    --sorakky-header: 75px;
    --sorakky-footer: 70px;
    --sorakky-input-height: 72px;
}

.is-hidden {
    display: none !important;
}

/* 利用者側の共通 CSS (button / form の幅・余白・色) を打ち消す。
   共通 CSS は button:not(...) で詳細度が高いため id で指定する */
#sorakky button,
#classifySheet button {
    border: none;
    background: transparent;
    width: auto;
    height: auto;
    min-width: 0;
    max-width: none;
    margin: 0;
    padding: 0;
    line-height: normal;
    font-size: inherit;
    box-shadow: none;
}

#sorakky form {
    width: auto;
    max-width: none;
    margin: 0;
}

/* iOS (Safari / Chrome) は viewport の user-scalable=0 を無視するため、送信アイコンなどを続けて押すと
   ダブルタップで画面が拡大され、左に寄ったまま戻らない。この画面ではダブルタップの拡大だけ止める (ピンチ拡大は残す) */
html,
body {
    touch-action: manipulation;
}

.sorakky {
    position: fixed;
    top: var(--sorakky-header);
    bottom: var(--sorakky-footer);
    left: 0;
    right: 0;
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.sorakky__messages {
    flex: 1;
    overflow-y: auto;
    /* 下は「質問終了」ボタンと重ならないよう空ける */
    padding: 16px 16px 52px;
    -webkit-overflow-scrolling: touch;
}

/* --- 吹き出し --- */
.sorakky-msg {
    display: flex;
    align-items: flex-start;
    margin-bottom: 14px;
}

.sorakky-msg.is-user {
    justify-content: flex-end;
    padding-left: 70px;
}

.sorakky-msg__avatar {
    width: 52px;
    flex-shrink: 0;
    margin-right: 20px;
}

.sorakky-bubble {
    max-width: calc(100% - 62px);
    padding: 12px 14px;
    border: 1px solid var(--sorakky-bubble-border);
    border-radius: 18px;
    background: var(--sorakky-bubble);
    /* XD 01: 吹き出しの文字は 16px Medium */
    font-size: 16px;
    font-weight: 500;
    line-height: 1.6;
    color: #000;
    word-break: break-word;
}

.sorakky-msg.is-bot .sorakky-bubble {
    flex: 1;
    /* XD: そらっきー (アイコン) 側の左上だけ角を付けない */
    border-radius: 0 18px 18px 18px;
}

.sorakky-msg.is-user .sorakky-bubble {
    max-width: 100%;
    flex: 1;
    background: var(--sorakky-user);
    border-color: var(--sorakky-blue-strong);
    border-radius: 18px 18px 0 18px;
}

.sorakky-text {
    margin: 0;
    white-space: pre-line;
}

.sorakky-spacer {
    height: 1em;
    margin: 0;
}

.sorakky-link {
    color: var(--sorakky-link);
    text-decoration: underline;
}

/* 資源物の早見表で両地域を出すときの地域名の見出し (【女満別】/【東藻琴】。基本設計 v0.5 5.3.4) */
.sorakky-area-title {
    margin: 0;
    font-weight: bold;
    color: #0c3679; /* XD の見出しの濃い紺色 */
}

/* 資源物の早見表 (XD)。品名を 2 列に並べ、長い品名は 1 行を使う */
.sorakky-quick-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.sorakky-quick-list li::before {
    content: "・";
}

.sorakky-quick-list li.is-wide {
    grid-column: 1 / -1;
}

/* 外部リンクのアイコン (XD の「別ウィンドウで開く」)。文字 (⧉) はフォントで形が変わるため SVG で描き、リンクの色に合わせる */
.sorakky-link.is-external::after {
    content: "";
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-left: 4px;
    vertical-align: -0.15em;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19 19H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z'/%3E%3C/svg%3E") no-repeat center / contain;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19 19H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z'/%3E%3C/svg%3E") no-repeat center / contain;
}

/* --- ボタン (よくある質問・選択肢・地区) --- */
.sorakky-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.sorakky-buttons.is-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

/* 地区名は 15px 固定で 1 行 (XD)。収まらない名前は JS (fitGridButtons) が is-wrap で「（」の前で 2 行にし、
   それでも入らなければ is-break で普通に折り返す */
#sorakky .sorakky-buttons.is-grid .sorakky-btn {
    padding: 8px 14px !important;
    white-space: nowrap;
    overflow: hidden;
}

#sorakky .sorakky-buttons.is-grid .sorakky-btn.is-wrap .sorakky-btn__part {
    display: block;
}

#sorakky .sorakky-buttons.is-grid .sorakky-btn.is-break {
    white-space: normal;
}

#sorakky .sorakky-btn {
    display: block;
    width: 100%;
    /* 共通 CSS (aiot/components/buttons.css) が全 button に padding 8px 24px を !important で付ける。
       上下 (8px) はそのままに、左右だけ XD の 14px に戻す (text-align:left の行頭が右に寄りすぎないように) */
    padding: 8px 14px !important;
    border: none;
    border-radius: 5px;
    background: var(--sorakky-blue);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    /* 共通 CSS の letter-spacing を打ち消す */
    letter-spacing: 0;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

#sorakky .sorakky-buttons.is-large .sorakky-btn {
    /* 基本の !important を上書きし直す (大きいボタンは縦 10px) */
    padding: 10px 14px !important;
    border-radius: 8px;
    font-size: 16px;
    text-align: center;
}

.sorakky-btn:active {
    opacity: 0.8;
}

/* --- 収集区分のラベル --- */
.sorakky-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
}

.sorakky-chip {
    padding: 1px 14px;
    border-radius: 999px;
    color: #fff;
    font-weight: 700;
}

/* --- 早見表 (2 列) --- */
.sorakky-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin: 0;
    padding: 0;
    list-style: none;
}

.sorakky-sources {
    margin: 4px 0 0;
    padding: 0;
    list-style: none;
}

/* 「・」の箱。全角「・」は字面が左寄りのため 1em だと本文との間が空きすぎる (STG ≈14px)。
   箱を 0.5em に詰めて XD (≈6.5px) にそろえる。はみ出す右側の余白は空白なので本文に重ならない */
.sorakky-sources li::before {
    content: "・";
    display: inline-block;
    width: 0.5em;
    margin-right: 4px;
    text-indent: 0;
}

/* 出典のリンク文言。題 (日本語) は文字で自然に折り返す。題が無く短縮 URL を出す場合は、
   JS が入れた <wbr> の位置 (区切り) を優先して折り返し、1 文字だけ次行に残らないようにする。
   それでも 1 かたまりが長いときだけ任意位置で折り返す (overflow-wrap: anywhere)。
   折り返した 2 行目は「・」ではなく本文にそろえる (ぶら下げ)。先頭行は負の text-indent で
   「・」を行頭に戻し、本文・2 行目を padding-left (「・」の箱 0.5em + 余白 4px) にそろえる (XD) */
.sorakky-sources li {
    padding-left: calc(0.5em + 4px);
    text-indent: calc(-0.5em - 4px);
    overflow-wrap: anywhere;
    word-break: normal;
}

/* --- 満足度 --- */
.sorakky-rating {
    /* 低い [1]〜[5] 高い。左に寄せる (広い画面で間を空けない) */
    display: grid;
    grid-template-columns: auto repeat(5, 32px) auto;
    justify-content: start;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

/* 低い / 高い は 1 行のまま */
.sorakky-rating span {
    white-space: nowrap;
}

/* 数字はボタンの中央。利用者側の共通 CSS (aiot/components/buttons.css) が全ボタンに余白を !important で付けるため打ち消す
   (余白が残ると 32px に収まらず、ボタン同士が重なる・数字が下にずれる) */
#sorakky .sorakky-rating button {
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: 0;
    line-height: 1;
    border: none;
    border-radius: 4px;
    background: var(--sorakky-blue);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.sorakky-rating button:disabled {
    opacity: 0.5;
    cursor: default;
}

/* --- ローディング --- */
.sorakky-typing {
    display: inline-flex;
    gap: 4px;
}

.sorakky-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: sorakky-typing 1.2s infinite ease-in-out;
}

.sorakky-typing span:nth-child(2) { animation-delay: 0.2s; }
.sorakky-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sorakky-typing {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* --- 質問終了 / 追加質問 / 新規質問 と 分類表ボタン --- */
.sorakky__actions {
    position: relative;
    height: 0;
}

#sorakky .sorakky__end {
    position: absolute;
    left: 6px;
    bottom: 8px;
    padding: 4px 6px !important;
    line-height: 1.5;
    border: 1px solid var(--sorakky-blue);
    border-radius: 12px;
    background: #fff;
    color: var(--sorakky-blue) !important;
    font-size: 16px;
    font-weight: 700;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16);
    letter-spacing: normal;
    cursor: pointer;
    z-index: 2;
}

.sorakky-fab {
    /* 下から上へのスワイプで分類表を開く (DD 002-3 №7) */
    touch-action: none;
    position: absolute;
    right: 18px;
    bottom: 10px;
    z-index: 2;
}

#sorakky .sorakky-fab__open {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px !important;
    line-height: 1.5;
    border: 2px solid #fff;
    border-radius: 8px;
    background: var(--sorakky-blue);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
    letter-spacing: normal;
    cursor: pointer;
}

.sorakky-fab__open svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}

#sorakky .sorakky-fab__close {
    position: absolute;
    top: -12px;
    right: -12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0 !important;
    border: 1.5px solid #8a8a8a;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
}

/* 円の中央に × を置く */
.sorakky-fab__close svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: #8a8a8a;
    stroke-width: 2;
    stroke-linecap: round;
}

/* --- 入力エリア --- */
.sorakky__input {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    min-height: 72px;
    padding: 13px 16px;
    background: var(--sorakky-input-area);
}

/* 長文は枠内で折り返し、高さの上限を超えたら枠内でスクロールする (高さは JS で合わせる) */
#sorakky .sorakky__input textarea {
    flex: 1;
    width: auto;
    height: 46px;
    min-height: 46px;
    max-height: 118px;
    margin: 0;
    padding: 11px 18px;
    border: 1px solid #aaa;
    border-radius: 23px;
    background: #fff;
    /* 16px 未満だと iOS Safari がフォーカス時に画面を拡大する */
    font-size: 16px;
    line-height: 22px;
    box-sizing: border-box;
    resize: none;
    overflow-y: auto;
}

#sorakky .sorakky__input textarea:focus {
    border-color: var(--sorakky-blue-strong);
    outline: none;
}

#sorakky .sorakky__input textarea:disabled {
    background: #fff;
}

#sorakky .sorakky__input textarea:disabled::placeholder {
    color: #999;
}

#sorakky .sorakky__icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0 !important;
    border: none;
    background: transparent;
    cursor: pointer;
}

#sorakky .sorakky__icon-button svg {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    fill: #6e6e6e;
    stroke: #6e6e6e;
}

/* マイクの弧・柄・台座は線で描く */
#sorakky .sorakky__icon-button svg .is-stroke {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
}

#sorakky .sorakky__send svg {
    fill: var(--sorakky-blue-strong);
    stroke: none;
}

#sorakky .sorakky__icon-button.is-recording svg {
    fill: #e03131;
    stroke: #e03131;
}

/* 音声入力中はマイクを脈打たせて、押すと止まることを示す */
#sorakky .sorakky__icon-button.is-recording {
    border-radius: 50%;
    animation: sorakky-mic-pulse 1.4s ease-out infinite;
}

@keyframes sorakky-mic-pulse {
    0% { box-shadow: 0 0 0 0 rgba(224, 49, 49, 0.4); }
    100% { box-shadow: 0 0 0 12px rgba(224, 49, 49, 0); }
}

@media (prefers-reduced-motion: reduce) {
    #sorakky .sorakky__icon-button.is-recording { animation: none; }
}

/* 共通 CSS の button:disabled は背景色を !important で塗るため打ち消す */
#sorakky .sorakky__icon-button:disabled {
    background: transparent !important;
    opacity: 0.4;
}

/* --- 分類表 (全画面。入力エリアは見えたままにする) --- */
.sorakky-classify {
    position: fixed;
    top: var(--sorakky-header);
    bottom: calc(var(--sorakky-footer) + var(--sorakky-input-height));
    left: 0;
    right: 0;
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    border-radius: 20px 20px 0 0;
    background: #fff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.sorakky-classify__bar {
    position: relative;
    height: 44px;
    flex-shrink: 0;
    /* 上部バーはドラッグで高さを変える。ブラウザのスクロールに取られないようにする */
    touch-action: none;
    cursor: grab;
}

.sorakky-classify.is-dragging,
.sorakky-classify.is-dragging .sorakky-classify__bar {
    cursor: grabbing;
    user-select: none;
}

.sorakky-classify__grip {
    position: absolute;
    top: 8px;
    left: 50%;
    width: 44px;
    height: 4px;
    margin-left: -22px;
    border-radius: 2px;
    background: #ccc;
}

#classifySheet .sorakky-classify__minimize,
#classifySheet .sorakky-classify__close {
    color: #333 !important;
    position: absolute;
    top: 10px;
    /* 共通 CSS が button に padding:8px 24px を付けて当たり判定が広がり、
       × の判定が − に重なって「−を押すと閉じる」ため 30×30 に固定する */
    width: 30px !important;
    height: 30px !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    border: none;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

#classifySheet .sorakky-classify__minimize { right: 44px; }
#classifySheet .sorakky-classify__close { right: 10px; }

.sorakky-classify__body {
    flex: 1;
    display: flex;
    min-height: 0;
}

.sorakky-classify__index {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 10px 10px;
    overflow-y: auto;
    /* 五十音は縦にスクロールできるが、スクロールバーは文字に重なるため出さない */
    scrollbar-width: none;
}

.sorakky-classify__index::-webkit-scrollbar {
    display: none;
}

#classifySheet .sorakky-classify__kana {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    padding: 0 !important;
    border: 1px solid var(--sorakky-blue);
    border-radius: 50%;
    background: #fff;
    color: var(--sorakky-blue) !important;
    font-size: 15px;
    cursor: pointer;
}

/* 文字色は上の !important (共通 CSS の button の色を打ち消す) より強くする。選択中は白文字 */
#classifySheet .sorakky-classify__kana.is-active {
    background: var(--sorakky-blue);
    color: #fff !important;
}

/* 共通 CSS の button:disabled (背景を !important で塗る) を打ち消す */
#classifySheet .sorakky-classify__kana:disabled {
    background: #fff !important;
    border-color: var(--sorakky-blue);
    opacity: 0.4;
    cursor: default;
}

.sorakky-classify__list {
    position: relative;
    flex: 1;
    margin: 0;
    padding: 0 16px 16px 0;
    overflow-y: auto;
    list-style: none;
}

.sorakky-classify__item {
    padding: 8px 0;
    cursor: pointer;
    border-bottom: 1px solid #e5e5e5;
}

.sorakky-classify__item.is-continued {
    padding-top: 4px;
}

.sorakky-classify__name {
    margin: 0;
    font-size: 15px;
    /* XD: 品名と分類ラベルの間は約 6px。body の line-height (1.75) のままだと行の上下の余白で約 14px 空く */
    line-height: 1.4;
    font-weight: 700;
}

.sorakky-classify__label {
    /* inline-block だと li の行 (16px × 1.75 = 28px) の中に置かれ、上に約 7px 余分に空くため、ブロックにして文字幅に合わせる */
    display: block;
    width: fit-content;
    margin: 1px 0 0;
    /* 高さ 19px で文字を上下中央に置く (游ゴシック Medium は上下の余白がそろう。上だけ余白を足すと下に寄る) */
    padding: 0 8px;
    line-height: 19px;
    /* XD: 両端が丸いラベル */
    border-radius: 999px;
    color: #fff;
    font-size: 11px;
    /* XD: ラベルの文字は太字にしない (游ゴシックは 400 だと Windows で細すぎるため Medium) */
    font-weight: 500;
}

.sorakky-classify__note {
    margin: 0;
    font-size: 13px;
    /* XD: 分類ラベルと説明の間は約 4px */
    line-height: 1.5;
}

/* 狭い画面: 満足度のボタンの間隔を詰める */
@media (max-width: 400px) {
    .sorakky-rating {
        gap: 4px;
    }
}

/* さらに狭い画面: 1 行に収まらないため、低い / 高い をボタンの下の両端に置く */
@media (max-width: 374px) {
    .sorakky-rating {
        grid-template-columns: repeat(5, 32px);
        row-gap: 2px;
    }

    .sorakky-rating span {
        grid-row: 2;
        font-size: 13px;
    }

    .sorakky-rating span:first-child {
        grid-column: 1 / span 2;
        justify-self: start;
    }

    .sorakky-rating span:last-child {
        grid-column: 4 / span 2;
        justify-self: end;
    }
}

/* 375px 以下: 共通 CSS (user/css/aiot/components/buttons.css) が button の文字を 12px に縮めるため、
   リンクのボタン (会員登録する)・吹き出しの文字・「質問終了」も合わせて小さくし、大きさの差をそろえる */
@media (max-width: 375px) {
    .sorakky-bubble {
        font-size: 14px;
    }

    #sorakky .sorakky-buttons.is-large .sorakky-btn {
        font-size: 14px;
    }

    #sorakky .sorakky__end {
        left: 10px;
        padding: 8px 10px !important;
    }
}

/* ============================================================
 * iOS 横向き (ノッチ・ホームインジケータ) 対応
 * chatbot.blade に viewport-fit=cover を付け、画面の端まで body (白) を敷く。
 * その上で、固定ヘッダー・フッター・チャット領域の中身が safe-area に
 * 隠れないよう、その分だけ内側に寄せる。safe-area は縦向き・ノッチ無しの
 * 端末では 0 になるため、それ以外の見た目は変わらない (.sorakky-page は chat 画面のみ)。
 * ============================================================ */
.sorakky-page #header {
    /* ノッチ側にロゴ・会員名が隠れないよう左右を safe-area 分あける (既定の左 1rem は残す) */
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: env(safe-area-inset-right);
}

.sorakky {
    /* フッターがホームインジケータ分だけ下に伸びるので、その分チャットを上に詰める */
    bottom: calc(var(--sorakky-footer) + env(safe-area-inset-bottom));
}

.sorakky-page #footer {
    /* ノッチ側にメニューが隠れないよう左右をあける */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    /* ホームインジケータの高さ分、下へ伸ばして白で埋め、メニューはその上に置く */
    height: calc(var(--aiot-nav-bar-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
}
