/* ===================================================================
 * 右下FABチャット風ウィジェット
 * プレフィックス: .acw-（all-connect widget）
 * 既存島型ヘッダー(z:100)より遥か上に配置
 * =================================================================== */

:root {
    --acw-z-fab: 9990;
    --acw-z-panel: 9991;
    --acw-z-backdrop: 9989;

    --acw-color-bg: #ffffff;
    --acw-color-fg: #1a1a1a;
    --acw-color-sub: #5a6273;
    --acw-color-accent: var(--color_main, #00bcd1);
    --acw-color-accent-dark: #0098ac;
    --acw-color-bubble-bot: #f4f6f8;
    --acw-color-bubble-user: #d9f5f8;
    --acw-color-card-border: #e3e6ea;
    --acw-color-card-hover: #f7fafb;

    --acw-shadow-fab: 0 8px 24px rgba(0, 164, 173, 0.35);
    --acw-shadow-panel: 0 16px 40px rgba(0, 0, 0, 0.18);
    --acw-radius-panel: 16px;
    --acw-radius-bubble: 14px;
    --acw-radius-chip: 999px;
    --acw-radius-card: 12px;

    --acw-fab-size: 52px;
    --acw-panel-w: 360px;
    --acw-panel-h: 580px;
}

/* isolation/transform/filter/contain は付けない（stacking context を作ると
   内部の position:fixed 要素の z-index が閉じ込められ <main> の裏に沈むため） */
.acw-root {
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
        "ヒラギノ角ゴシック", "Hiragino Kaku Gothic ProN",
        "Yu Gothic UI", "Meiryo UI", sans-serif;
    color: var(--acw-color-fg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ---------- FAB ---------- */
.acw-fab {
    position: fixed;
    bottom: calc(192px + env(safe-area-inset-bottom));
    right: 40px;
    z-index: var(--acw-z-fab);
    width: var(--acw-fab-size);
    height: var(--acw-fab-size);
    border-radius: 50%;
    border: 0;
    background: linear-gradient(135deg, var(--acw-color-accent) 0%, var(--acw-color-accent-dark) 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: var(--acw-shadow-fab);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    padding: 0;
}
.acw-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(0, 164, 173, 0.45);
}
.acw-fab:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
}
.acw-fab__avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 20%;
    background: #fff;
    position: relative;
    z-index: 1;
    pointer-events: none;
}
.acw-fab__pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--acw-color-accent);
    opacity: 0;
    pointer-events: none;
    animation: acw-pulse 1.8s ease-out 3;  /* 3回だけ */
    animation-delay: 1s;
}
@keyframes acw-pulse {
    0%   { transform: scale(0.95); opacity: 0.8; }
    100% { transform: scale(1.45); opacity: 0; }
}
/* ---------- Callout（FAB横の常時吹き出し） ---------- */
.acw-callout {
    position: fixed;
    bottom: calc(202px + env(safe-area-inset-bottom));
    right: 100px;
    z-index: var(--acw-z-fab);
    background: #fff;
    color: var(--acw-color-fg);
    font-size: 12px;
    line-height: 1.45;
    font-weight: 700;
    padding: 10px 30px 10px 14px;
    border-radius: 14px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(0, 164, 173, 0.18);
    max-width: 180px;
    animation: acw-callout-in 0.6s ease-out 0.4s both;
}
.acw-callout::after {
    content: "";
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 7px solid transparent;
    border-left-color: #fff;
    filter: drop-shadow(2px 0 1px rgba(0,0,0,0.04));
}
.acw-callout__close {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 0;
    background: rgba(0, 0, 0, 0.06);
    color: var(--acw-color-sub);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease;
}
.acw-callout__close:hover {
    background: rgba(0, 0, 0, 0.12);
    color: var(--acw-color-fg);
}
.acw-callout__close:focus-visible {
    outline: 2px solid var(--acw-color-accent);
    outline-offset: 2px;
}
@keyframes acw-callout-in {
    from { opacity: 0; transform: translateX(10px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* 開いている時 or 閉じられた時は非表示 */
.acw-root[data-acw-open="1"] .acw-callout,
.acw-root[data-acw-callout-dismissed="1"] .acw-callout {
    display: none;
}
.acw-root[data-acw-open="1"] .acw-fab__pulse {
    display: none;
}

/* ---------- Backdrop (モバイルのみ表示) ---------- */
.acw-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 20, 28, 0.45);
    z-index: var(--acw-z-backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    display: none;
}
.acw-root[data-acw-open="1"] .acw-backdrop {
    opacity: 1;
    pointer-events: auto;
}
@media (max-width: 640px) {
    .acw-backdrop { display: block; }
}

/* ---------- Panel ---------- */
.acw-panel {
    position: fixed;
    bottom: 110px;
    right: 40px;
    width: var(--acw-panel-w);
    height: var(--acw-panel-h);
    max-height: calc(100dvh - 140px);
    background: var(--acw-color-bg);
    border-radius: var(--acw-radius-panel);
    box-shadow: var(--acw-shadow-panel);
    z-index: var(--acw-z-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(8px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
}
.acw-root[data-acw-open="1"] .acw-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.acw-panel__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px 12px;
    background: linear-gradient(135deg, var(--acw-color-accent) 0%, var(--acw-color-accent-dark) 100%);
    color: #fff;
    flex-shrink: 0;
}
.acw-panel__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 22%;
    background: #fff;
    border: 2px solid rgba(255, 255, 255, 0.45);
    flex-shrink: 0;
}
.acw-title-group { min-width: 0; flex: 1; }
.acw-panel__title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    margin: 0;
}
.acw-panel__subtitle {
    font-size: 11px;
    opacity: 0.85;
    margin-top: 2px;
    line-height: 1.4;
}
.acw-panel__close {
    background: rgba(255, 255, 255, 0.18);
    border: 0;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    padding: 0;
}
.acw-panel__close:hover { background: rgba(255, 255, 255, 0.3); }
.acw-panel__close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.acw-panel__body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fafbfc;
}
.acw-panel__body::-webkit-scrollbar { width: 6px; }
.acw-panel__body::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,.15);
    border-radius: 3px;
}

.acw-panel__footer {
    display: flex;
    justify-content: center;
    padding: 8px 16px 12px;
    background: #fafbfc;
    border-top: 1px solid var(--acw-color-card-border);
    flex-shrink: 0;
}
.acw-restart {
    background: none;
    border: 0;
    color: var(--acw-color-sub);
    font-size: 12px;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 999px;
    transition: background 0.15s ease;
}
.acw-restart:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--acw-color-fg);
}

/* ---------- Messages（チャットバブル） ---------- */
.acw-msg {
    display: flex;
    gap: 6px;
    max-width: 100%;
    align-items: flex-end;
    animation: acw-fadeup 0.25s ease-out;
}
@keyframes acw-fadeup {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.acw-msg--bot { align-self: flex-start; }
.acw-msg--user { align-self: flex-end; flex-direction: row-reverse; }

.acw-msg__avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 18%;
    background: #fff;
    flex-shrink: 0;
    margin-bottom: 2px;
}
.acw-msg__bubble {
    background: var(--acw-color-bubble-bot);
    color: var(--acw-color-fg);
    border-radius: var(--acw-radius-bubble);
    padding: 10px 13px;
    font-size: 13px;
    line-height: 1.65;
    max-width: calc(100% - 38px);
}
.acw-msg--user .acw-msg__bubble {
    max-width: 260px;
}
.acw-msg--user .acw-msg__bubble {
    background: var(--acw-color-bubble-user);
    color: var(--acw-color-accent-dark);
    font-weight: 600;
}

/* ---------- Chips（2カラム） ---------- */
.acw-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 6px 0;
    align-self: stretch;
    width: 100%;
}
.acw-chips--col {
    grid-template-columns: 1fr;
}
.acw-chip {
    width: 100%;
    text-align: center;
    background: #fff;
    border: 1px solid var(--acw-color-card-border);
    color: var(--acw-color-fg);
    font-size: 13px;
    font-weight: 700;
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    line-height: 1.4;
}
.acw-chip:hover {
    border-color: var(--acw-color-accent);
    color: var(--acw-color-accent-dark);
    background: var(--acw-color-card-hover);
}
.acw-chip:focus-visible {
    outline: 2px solid var(--acw-color-accent);
    outline-offset: 2px;
}
.acw-chip[aria-pressed="true"] {
    background: var(--acw-color-accent);
    color: #fff;
    border-color: var(--acw-color-accent);
}
.acw-chip__sub {
    display: block;
    font-size: 11px;
    font-weight: 400;
    opacity: 0.7;
    margin-top: 2px;
}

/* ---------- Article cards ---------- */
/* ---------- 記事カード（横スクロール・アイキャッチ＋タイトル） ---------- */
.acw-cards--scroll {
    display: flex;
    flex-direction: row;
    gap: 10px;
    margin-top: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding: 2px 2px 8px;
    align-self: stretch;
    align-items: stretch;
    width: 100%;
    min-height: 182px;
}
.acw-cards--scroll::-webkit-scrollbar { height: 5px; }
.acw-cards--scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}
.acw-root .acw-card {
    flex: 0 0 168px !important;
    width: 168px !important;
    scroll-snap-align: start;
    display: flex !important;
    flex-direction: column !important;
    min-height: 170px !important;
    background: #fff;
    border: 1px solid var(--acw-color-card-border);
    border-radius: var(--acw-radius-card);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.acw-card:hover {
    border-color: var(--acw-color-accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 164, 173, 0.15);
}
.acw-card:focus-visible {
    outline: 2px solid var(--acw-color-accent);
    outline-offset: 2px;
}
.acw-root .acw-card__thumb {
    width: 100% !important;
    height: 105px !important;
    min-height: 105px !important;
    flex: 0 0 105px !important;
    background: #eef1f4;
    overflow: hidden;
}
.acw-root .acw-card__title {
    flex: 1 1 auto;
}
.acw-root .acw-card__thumb img {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    object-fit: cover !important;
    display: block !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
}
.acw-card__title {
    font-size: 12px;
    font-weight: 700;
    line-height: 1.55;
    color: var(--acw-color-fg);
    margin: 0;
    padding: 10px 11px 12px;
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
    .acw-fab {
        bottom: calc(182px + env(safe-area-inset-bottom));
        right: 40px;
    }
    .acw-callout {
        bottom: calc(192px + env(safe-area-inset-bottom));
        right: 100px;
        max-width: 156px;
        font-size: 11.5px;
        padding: 8px 26px 8px 12px;
    }
    .acw-panel {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 85dvh;
        max-height: 85dvh;
        border-radius: var(--acw-radius-panel) var(--acw-radius-panel) 0 0;
    }
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .acw-fab__pulse { animation: none; }
    .acw-msg { animation: none; }
    .acw-fab, .acw-panel, .acw-card, .acw-chip {
        transition: none;
    }
}
