/* SUGO AI Chat Widget v3 */

#sugo-chat-widget {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 0 !important;
    height: 0 !important;
    z-index: 2147483646 !important;
    pointer-events: none !important;
}

#sugo-chat-widget * {
    box-sizing: border-box !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif !important;
}

/* トグルボタン */
#sugo-chat-widget #sugo-chat-toggle {
    position: fixed !important;
    right: 0 !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: auto !important;
    height: 44px !important;
    border: none !important;
    border-radius: 22px 0 0 22px !important;
    background: linear-gradient(135deg, #2563eb 0%, #059669 100%) !important;
    color: #fff !important;
    cursor: pointer !important;
    box-shadow: -2px 2px 12px rgba(37, 99, 235, 0.3) !important;
    z-index: 2147483647 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 14px 0 16px !important;
    transition: padding 0.3s ease, box-shadow 0.3s ease !important;
    pointer-events: auto !important;
    -webkit-tap-highlight-color: transparent !important;
    outline: none !important;
    margin: 0 !important;
    overflow: hidden !important;
    animation: sugo-float 3s ease-in-out infinite !important;
}

@keyframes sugo-float {
    0%, 100% { transform: translateY(-50%) translateX(0); }
    50% { transform: translateY(-50%) translateX(-3px); }
}

#sugo-chat-widget #sugo-chat-toggle:hover {
    padding-right: 18px !important;
    box-shadow: -4px 4px 16px rgba(37, 99, 235, 0.4) !important;
    animation: none !important;
}

#sugo-chat-widget #sugo-chat-toggle .toggle-text {
    font-size: 14px !important;
    font-weight: 600 !important;
    letter-spacing: 0.5px !important;
    white-space: nowrap !important;
    transition: opacity 0.3s ease !important;
}

#sugo-chat-widget #sugo-chat-toggle svg {
    width: 20px !important;
    height: 20px !important;
    transition: transform 0.3s ease, opacity 0.3s ease !important;
    pointer-events: none !important;
}

#sugo-chat-widget #sugo-chat-toggle .icon-close {
    position: absolute !important;
    opacity: 0 !important;
    transform: rotate(-90deg) !important;
}

#sugo-chat-widget #sugo-chat-toggle.active .toggle-text {
    opacity: 0 !important;
    position: absolute !important;
}

#sugo-chat-widget #sugo-chat-toggle.active .icon-close {
    opacity: 1 !important;
    transform: rotate(0) !important;
    position: relative !important;
}

#sugo-chat-widget #sugo-chat-toggle.active {
    width: 44px !important;
    padding: 0 !important;
    border-radius: 22px 0 0 22px !important;
    animation: none !important;
}

#sugo-chat-widget #sugo-chat-toggle::before {
    content: '' !important;
    position: absolute !important;
    top: 0 !important;
    left: -100% !important;
    width: 100% !important;
    height: 100% !important;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent) !important;
    animation: sugo-shimmer 3s infinite !important;
    border-radius: inherit !important;
    pointer-events: none !important;
}

@keyframes sugo-shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* パネル */
#sugo-chat-widget #sugo-chat-panel {
    position: fixed !important;
    right: 20px !important;
    bottom: 20px !important;
    width: 360px !important;
    max-width: calc(100vw - 40px) !important;
    height: 520px !important;
    max-height: calc(100vh - 100px) !important;
    background: #fff !important;
    border-radius: 20px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    z-index: 2147483646 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transform: translateY(20px) scale(0.95) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    pointer-events: none !important;
}

#sugo-chat-widget #sugo-chat-panel.active {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto !important;
}

/* ヘッダー */
#sugo-chat-widget .chat-header {
    background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%) !important;
    padding: 16px 20px !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    flex-shrink: 0 !important;
}

#sugo-chat-widget .chat-header-icon {
    width: 44px !important;
    height: 44px !important;
    background: rgba(255, 255, 255, 0.2) !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    overflow: hidden !important;
}

#sugo-chat-widget .chat-header-icon img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border-radius: 50% !important;
}

#sugo-chat-widget .chat-header-info {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
}

#sugo-chat-widget .chat-title {
    color: #fff !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    line-height: 1.3 !important;
}

#sugo-chat-widget .chat-status {
    color: rgba(255, 255, 255, 0.9) !important;
    font-size: 12px !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    line-height: 1.3 !important;
}

#sugo-chat-widget .status-dot {
    width: 8px !important;
    height: 8px !important;
    border-radius: 50% !important;
    flex-shrink: 0 !important;
}

#sugo-chat-widget .status-dot.status-green {
    background: #4ade80 !important;
    animation: sugo-pulse 2s infinite !important;
}

#sugo-chat-widget .status-dot.status-yellow {
    background: #fbbf24 !important;
    animation: sugo-pulse 3s infinite !important;
}

#sugo-chat-widget .status-dot.status-red {
    background: #f87171 !important;
}

@keyframes sugo-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* 終了ボタン */
#sugo-chat-widget #sugo-chat-end {
    width: 32px !important;
    height: 32px !important;
    border: none !important;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.2) !important;
    color: #fff !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    transition: background 0.2s !important;
    padding: 0 !important;
}

#sugo-chat-widget #sugo-chat-end:hover {
    background: rgba(255, 255, 255, 0.3) !important;
}

#sugo-chat-widget #sugo-chat-end svg {
    width: 16px !important;
    height: 16px !important;
    pointer-events: none !important;
}

/* 名前入力画面 */
#sugo-chat-widget #sugo-chat-name-screen {
    flex: 1 !important;
    display: none !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 30px !important;
    background: linear-gradient(180deg, #f8f9fa 0%, #fff 100%) !important;
}

#sugo-chat-widget #sugo-chat-name-screen.active {
    display: flex !important;
}

#sugo-chat-widget .name-screen-content {
    text-align: center !important;
    width: 100% !important;
}

#sugo-chat-widget .name-screen-avatar {
    width: 80px !important;
    height: 80px !important;
    border-radius: 50% !important;
    margin-bottom: 16px !important;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3) !important;
}

#sugo-chat-widget .name-screen-greeting {
    font-size: 18px !important;
    font-weight: 600 !important;
    color: #333 !important;
    margin: 0 0 8px 0 !important;
}

#sugo-chat-widget .name-screen-text {
    font-size: 14px !important;
    color: #666 !important;
    margin: 0 0 20px 0 !important;
}

#sugo-chat-widget .name-input-wrap {
    display: flex !important;
    gap: 10px !important;
    max-width: 260px !important;
    margin: 0 auto !important;
}

#sugo-chat-widget #sugo-chat-name-input {
    flex: 1 !important;
    border: 2px solid #e5e5e5 !important;
    border-radius: 12px !important;
    padding: 12px 16px !important;
    font-size: 16px !important;
    outline: none !important;
    transition: border-color 0.2s !important;
    background: #fff !important;
    color: #333 !important;
}

#sugo-chat-widget #sugo-chat-name-input:focus {
    border-color: #8b5cf6 !important;
}

#sugo-chat-widget #sugo-chat-name-submit {
    border: none !important;
    border-radius: 12px !important;
    background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%) !important;
    color: #fff !important;
    padding: 12px 20px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: transform 0.2s, box-shadow 0.2s !important;
}

#sugo-chat-widget #sugo-chat-name-submit:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4) !important;
}

/* メイン画面 */
#sugo-chat-widget #sugo-chat-main {
    flex: 1 !important;
    display: none !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

#sugo-chat-widget #sugo-chat-main.active {
    display: flex !important;
}

/* メッセージエリア */
#sugo-chat-widget #sugo-chat-messages {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 20px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
    background: #f8f9fa !important;
}

#sugo-chat-widget #sugo-chat-messages::-webkit-scrollbar {
    width: 6px !important;
}

#sugo-chat-widget #sugo-chat-messages::-webkit-scrollbar-thumb {
    background: #ddd !important;
    border-radius: 3px !important;
}

/* メッセージ */
#sugo-chat-widget .chat-message {
    display: flex !important;
    flex-direction: column !important;
    max-width: 85% !important;
    animation: sugo-messageIn 0.3s ease !important;
}

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

#sugo-chat-widget .chat-message.user {
    align-self: flex-end !important;
    align-items: flex-end !important;
}

#sugo-chat-widget .chat-message.ai {
    align-self: flex-start !important;
    align-items: flex-start !important;
    flex-direction: row !important;
    gap: 8px !important;
    max-width: 90% !important;
}

#sugo-chat-widget .chat-message.ai .ai-avatar {
    width: 32px !important;
    height: 32px !important;
    border-radius: 50% !important;
    flex-shrink: 0 !important;
    object-fit: cover !important;
}

#sugo-chat-widget .chat-message.ai .message-wrap {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
}

#sugo-chat-widget .message-bubble {
    padding: 12px 16px !important;
    border-radius: 18px !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    word-break: break-word !important;
}

#sugo-chat-widget .chat-message.user .message-bubble {
    background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%) !important;
    color: #fff !important;
    border-bottom-right-radius: 4px !important;
}

#sugo-chat-widget .chat-message.ai .message-bubble {
    background: #fff !important;
    color: #333 !important;
    border-bottom-left-radius: 4px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06) !important;
}

#sugo-chat-widget .chat-link {
    color: #8b5cf6 !important;
    text-decoration: underline !important;
    font-weight: 500 !important;
}

#sugo-chat-widget .message-time {
    font-size: 11px !important;
    color: #999 !important;
    margin-top: 4px !important;
    padding: 0 4px !important;
}

/* ローディング */
#sugo-chat-widget .chat-message.loading .message-bubble {
    display: flex !important;
    gap: 4px !important;
    padding: 16px 20px !important;
}

#sugo-chat-widget .typing-dot {
    width: 8px !important;
    height: 8px !important;
    background: #aaa !important;
    border-radius: 50% !important;
    animation: sugo-typing 1.4s infinite !important;
}

#sugo-chat-widget .typing-dot:nth-child(2) { animation-delay: 0.2s !important; }
#sugo-chat-widget .typing-dot:nth-child(3) { animation-delay: 0.4s !important; }

@keyframes sugo-typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* 入力エリア */
#sugo-chat-widget .chat-input-area {
    padding: 16px !important;
    background: #fff !important;
    border-top: 1px solid #eee !important;
    display: flex !important;
    gap: 12px !important;
    align-items: flex-end !important;
    flex-shrink: 0 !important;
}

#sugo-chat-widget #sugo-chat-input {
    flex: 1 !important;
    border: 1px solid #e5e5e5 !important;
    border-radius: 20px !important;
    padding: 12px 16px !important;
    font-size: 16px !important;
    resize: none !important;
    max-height: 100px !important;
    line-height: 1.4 !important;
    outline: none !important;
    background: #fff !important;
    color: #333 !important;
}

#sugo-chat-widget #sugo-chat-input:focus {
    border-color: #8b5cf6 !important;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1) !important;
}

#sugo-chat-widget #sugo-chat-send {
    width: 44px !important;
    height: 44px !important;
    border: none !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%) !important;
    color: #fff !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    transition: transform 0.2s, box-shadow 0.2s !important;
    padding: 0 !important;
}

#sugo-chat-widget #sugo-chat-send:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4) !important;
}

#sugo-chat-widget #sugo-chat-send:disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
}

#sugo-chat-widget #sugo-chat-send svg {
    width: 20px !important;
    height: 20px !important;
    pointer-events: none !important;
}

/* ポップアップ */
#sugo-chat-widget #sugo-chat-popup {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 2147483647 !important;
    pointer-events: auto !important;
}

#sugo-chat-widget .popup-overlay {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.7) !important;
}

#sugo-chat-widget .popup-content {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    background: #fff !important;
    border-radius: 20px !important;
    padding: 30px !important;
    text-align: center !important;
    max-width: 340px !important;
    width: calc(100vw - 40px) !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
}

#sugo-chat-widget #sugo-popup-close {
    position: absolute !important;
    top: 12px !important;
    right: 12px !important;
    width: 32px !important;
    height: 32px !important;
    border: none !important;
    border-radius: 50% !important;
    background: #f0f0f0 !important;
    color: #666 !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    transition: background 0.2s !important;
}

#sugo-chat-widget #sugo-popup-close:hover {
    background: #e0e0e0 !important;
}

#sugo-chat-widget #sugo-popup-close svg {
    width: 16px !important;
    height: 16px !important;
    pointer-events: none !important;
}

#sugo-chat-widget .popup-title {
    font-size: 22px !important;
    font-weight: 700 !important;
    color: #333 !important;
    margin: 0 0 20px 0 !important;
    background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    background-clip: text !important;
}

#sugo-chat-widget #sugo-popup-link {
    display: block !important;
    margin-bottom: 20px !important;
}

#sugo-chat-widget #sugo-popup-image {
    width: 200px !important;
    height: 200px !important;
    object-fit: cover !important;
    border-radius: 16px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1) !important;
}

#sugo-chat-widget #sugo-popup-button {
    display: inline-block !important;
    background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%) !important;
    color: #fff !important;
    text-decoration: none !important;
    padding: 14px 40px !important;
    border-radius: 30px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    transition: transform 0.2s, box-shadow 0.2s !important;
}

#sugo-chat-widget #sugo-popup-button:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4) !important;
}

/* モバイル対応 */
@media (max-width: 480px) {
    #sugo-chat-widget #sugo-chat-toggle {
        height: 40px !important;
        padding: 0 12px 0 14px !important;
    }
    
    #sugo-chat-widget #sugo-chat-toggle .toggle-text {
        font-size: 13px !important;
    }
    
    #sugo-chat-widget #sugo-chat-toggle.active {
        width: 40px !important;
    }
    
    #sugo-chat-widget #sugo-chat-panel {
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: calc(100% - 60px) !important;
        max-height: calc(100% - 60px) !important;
        border-radius: 16px 16px 0 0 !important;
    }
    
    #sugo-chat-widget .chat-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom)) !important;
    }
    
    #sugo-chat-widget .popup-content {
        max-width: calc(100vw - 30px) !important;
        padding: 24px !important;
    }
    
    #sugo-chat-widget #sugo-popup-image {
        width: 160px !important;
        height: 160px !important;
    }
}