/* =============================================================
   AI開発コンシェルジュ – Chat Widget Styles
   v1.1 – reviewed & fixed

   Design tokens from style.css:
     --color-10c59a : #10C59A  (primary teal)
     --color-00827e : #00827E  (dark teal)
     --color-333333 : #333333  (body text)
     --color-f8f8f8 : #F8F8F8  (light bg)
     --color-fff    : #fff
   Font: "Zen Kaku Gothic New" (already loaded in main layout)
   All class/ID names are prefixed with "steah-bot-" or "bot-"
   to prevent conflicts with existing site CSS.
   ============================================================= */

/* ── Offset the existing .back-to-top so it doesn't overlap ──
   Desktop: nudge left so it clears the chat toggle (right: 28px).
   Mobile:  stack it directly above the chat toggle instead.       */
.back-to-top {
    right: 102px !important;
}
@media (max-width: 480px) {
    /* Bot toggle on mobile: bottom 22px, right 18px, height 54px.
       Pulse ring extends 5px beyond the button (top:-5px in ::before),
       so ring top edge ≈ 81px from viewport bottom.
       bottom:100px gives ~19px clearance above the ring.             */
    .back-to-top {
        right: 23px !important;   /* centers 50px TOP over 54px bot (adjusted for visual alignment) */
        bottom: 115px !important;
        transform: translateY(300px) !important;   /* fully off-screen when hidden */
    }
    .back-to-top.show {
        transform: translateY(0) !important;       /* restore to stacked position  */
    }
}

/* ── Floating toggle button ───────────────────────────────── */
#steah-bot-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9999;

    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;

    /* 3-stop premium gradient */
    background: linear-gradient(135deg, #1de8b0 0%, var(--color-10c59a) 52%, var(--color-00827e) 100%);
    /* 3-layer shadow: ambient glow + crisp drop + inner highlight */
    box-shadow:
        0 6px 24px rgba(16, 197, 154, 0.50),
        0 2px 6px  rgba(0, 0, 0, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.28);
    color: #fff;

    display: flex;
    align-items: center;
    justify-content: center;

    /* position: fixed already creates containing block for ::before */
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#steah-bot-toggle:hover {
    transform: scale(1.1);
    box-shadow:
        0 8px 32px rgba(16, 197, 154, 0.65),
        0 3px 8px  rgba(0, 0, 0, 0.22),
        inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

#steah-bot-toggle:focus-visible {
    outline: 3px solid var(--color-10c59a);
    outline-offset: 3px;
}

/* Icon swap */
#steah-bot-toggle .icon-open  { display: flex; }
#steah-bot-toggle .icon-close { display: none; }
#steah-bot-toggle.is-open .icon-open  { display: none; }
#steah-bot-toggle.is-open .icon-close { display: flex; }

/* Sparkle star breathing animation */
.bot-spark-icon {
    transform-box: fill-box;
    transform-origin: center;
    animation: botSparkBreath 5s ease-in-out infinite;
}

@keyframes botSparkBreath {
    0%   { transform: rotate(0deg)   scale(1);    }
    25%  { transform: rotate(45deg)  scale(1.12); }
    50%  { transform: rotate(0deg)   scale(0.90); }
    75%  { transform: rotate(-45deg) scale(1.12); }
    100% { transform: rotate(0deg)   scale(1);    }
}

/* Pulse ring – use explicit directions instead of `inset`
   for broader Safari / iOS compatibility                    */
#steah-bot-toggle::before {
    content: '';
    position: absolute;
    top: -5px;
    right: -5px;
    bottom: -5px;
    left: -5px;
    border-radius: 50%;
    border: 2px solid rgba(16, 197, 154, 0.75);
    animation: botPulse 2.8s ease-out infinite;
    pointer-events: none;
}

@keyframes botPulse {
    0%   { opacity: 0.8; transform: scale(1);    }
    70%  { opacity: 0;   transform: scale(1.55); }
    100% { opacity: 0;   transform: scale(1.55); }
}

/* ── Chat window ──────────────────────────────────────────── */
#steah-bot-window {
    position: fixed;
    bottom: 104px;
    right: 28px;
    z-index: 9998;

    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);

    background: #fff;
    border-radius: 16px;
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Hidden state */
    opacity: 0;
    transform: translateY(18px) scale(0.97);
    pointer-events: none;           /* FIX: was "all" which is non-standard */
    transition: opacity 0.28s ease, transform 0.28s ease;
    transform-origin: bottom right;
}

#steah-bot-window.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;           /* FIX: correct standard value */
}

/* ── Window header ────────────────────────────────────────── */
#steah-bot-header {
    background: linear-gradient(135deg, var(--color-10c59a) 0%, var(--color-00827e) 100%);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.bot-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.bot-header-info {
    flex: 1;
    min-width: 0;
}

.bot-header-name {
    color: #fff;
    font-family: 'Zen Kaku Gothic New', sans-serif;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.02em;
}

.bot-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.bot-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #a7f3d0;
    animation: statusBlink 2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes statusBlink {
    0%, 100% { opacity: 1;   }
    50%       { opacity: 0.4; }
}

.bot-status-label {
    color: rgba(255, 255, 255, 0.85);
    font-size: 11px;
    font-family: 'Zen Kaku Gothic New', sans-serif;
}

.bot-header-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    font-size: 18px;
    line-height: 1;
    transition: color 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bot-header-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

.bot-header-close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

/* ── Message area ─────────────────────────────────────────── */
#steah-bot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--color-f8f8f8);

    /* Thin teal scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(16, 197, 154, 0.3) transparent;
}

#steah-bot-messages::-webkit-scrollbar       { width: 4px; }
#steah-bot-messages::-webkit-scrollbar-track { background: transparent; }
#steah-bot-messages::-webkit-scrollbar-thumb {
    background: rgba(16, 197, 154, 0.3);
    border-radius: 4px;
}

/* ── Message bubbles ──────────────────────────────────────── */
.bot-msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.bot-msg-row.bot  { justify-content: flex-start; }
.bot-msg-row.user { justify-content: flex-end;   }

.bot-bubble-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-10c59a), var(--color-00827e));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    align-self: flex-end;
}

.bot-bubble {
    max-width: 78%;
    padding: 10px 13px;
    border-radius: 14px;
    font-family: 'Zen Kaku Gothic New', sans-serif;
    font-size: 13px;
    line-height: 1.7;
    color: var(--color-333333);
    word-break: break-word;
    white-space: pre-wrap;
}

/* Bot bubble */
.bot-msg-row.bot .bot-bubble {
    background: #fff;
    border: 1px solid rgba(16, 197, 154, 0.18);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* User bubble */
.bot-msg-row.user .bot-bubble {
    background: linear-gradient(135deg, var(--color-10c59a) 0%, var(--color-00827e) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.bot-typing .bot-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-10c59a);
    animation: typingBounce 1.2s ease-in-out infinite;
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0);    opacity: 0.4; }
    40%            { transform: translateY(-6px); opacity: 1;   }
}

/* ── Quick reply buttons ──────────────────────────────────── */
.bot-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 0 0 2px 36px;
}

.bot-quick-btn {
    background: #fff;
    border: 1.5px solid var(--color-10c59a);
    color: var(--color-10c59a);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 12px;
    font-family: 'Zen Kaku Gothic New', sans-serif;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s;
    white-space: nowrap;
    line-height: 1.5;
}

.bot-quick-btn:hover {
    background: var(--color-10c59a);
    color: #fff;
    transform: translateY(-1px);
}

.bot-quick-btn:focus-visible {
    outline: 2px solid var(--color-10c59a);
    outline-offset: 2px;
}

/* ── CTA block ────────────────────────────────────────────── */
.bot-cta-row {
    padding: 2px 0 2px 36px;
}

/* Small guide text shown above the CTA button */
.bot-cta-note {
    font-family: 'Zen Kaku Gothic New', sans-serif;
    font-size: 12px;
    color: #666;
    line-height: 1.6;
    margin: 0 0 7px 0;
}

.bot-cta-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: linear-gradient(135deg, var(--color-10c59a) 0%, var(--color-00827e) 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 13px;
    font-family: 'Zen Kaku Gothic New', sans-serif;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 3px 12px rgba(16, 197, 154, 0.35);
}

.bot-cta-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 5px 18px rgba(16, 197, 154, 0.45);
    color: #fff;
    text-decoration: none;
}

.bot-cta-btn:focus-visible {
    outline: 3px solid var(--color-00827e);
    outline-offset: 2px;
}

/* ── Input area ───────────────────────────────────────────── */
#steah-bot-input-area {
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid rgba(16, 197, 154, 0.15);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

#steah-bot-input {
    flex: 1;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    padding: 9px 12px;
    font-family: 'Zen Kaku Gothic New', sans-serif;
    font-size: 13px;
    color: var(--color-333333);
    resize: none;
    outline: none;
    background: var(--color-f8f8f8);
    transition: border-color 0.2s, box-shadow 0.2s;
    line-height: 1.5;
    max-height: 100px;
    overflow-y: auto;
    /* Prevent iOS auto-zoom on focus (font-size >= 16px threshold) */
    font-size: 16px;
}

/* Scale visual text down while keeping iOS happy */
@media (min-width: 481px) {
    #steah-bot-input { font-size: 13px; }
}

#steah-bot-input:focus {
    border-color: var(--color-10c59a);
    box-shadow: 0 0 0 3px rgba(16, 197, 154, 0.12);
    background: #fff;
}

#steah-bot-input::placeholder { color: #aab0bb; }

#steah-bot-send {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, var(--color-10c59a) 0%, var(--color-00827e) 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(16, 197, 154, 0.3);
}

#steah-bot-send:hover  { opacity: 0.88; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(16, 197, 154, 0.4); }
#steah-bot-send:active { transform: scale(0.95); }

#steah-bot-send:focus-visible {
    outline: 3px solid var(--color-00827e);
    outline-offset: 2px;
}

/* ── Powered-by footer strip ──────────────────────────────── */
.bot-powered-by {
    text-align: center;
    font-size: 10px;
    color: #b0bac5;
    padding: 4px 0 6px;
    font-family: 'Zen Kaku Gothic New', sans-serif;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    flex-shrink: 0;
    letter-spacing: 0.03em;
}

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 480px) {
    /* Toggle: keep at same right, raise above back-to-top */
    #steah-bot-toggle {
        bottom: 22px;
        right: 18px;
        width: 54px;
        height: 54px;
    }

    /* Window: full-width floating panel */
    #steah-bot-window {
        bottom: 90px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: 100%;
        /* Use dvh so address-bar changes don't clip the window */
        height: calc(100dvh - 108px);
        max-height: none;
        border-radius: 14px;
    }

    /* Fallback for browsers without dvh */
    @supports not (height: 100dvh) {
        #steah-bot-window {
            height: calc(100vh - 108px);
        }
    }

    .bot-quick-btn {
        font-size: 11px;
        padding: 5px 10px;
    }
}
