/* Reset and Base Styles */
body {
    font-family: 'Noto Sans JP', 'Roboto', sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f0f4f8;
}

/* Chat Widget Container */
#chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 95dvh;
    background: #f9f9f9;
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform-origin: bottom right;
    z-index: 10000;
}

/* Minimized State */
#chat-widget-container.minimized {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    overflow: visible;
}

#chat-widget-container.minimized #chat-widget-body,
#chat-widget-container.minimized #chat-widget-footer {
    display: none;
}

/* 最大化時のアニメーション */ 
#chat-widget-container:not(.minimized) #chat-widget-body {
    animation: fadeInBody 0.3s forwards 0.3s; /* 0.3秒遅延で表示 */
}

@keyframes fadeInBody {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Overlay */
#chat-widget-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.05); /* desktopではわずかに暗く */
    z-index: 0;
    display: none;
    pointer-events: none; /* 親ページはクリック可能 */
}

/* Header */
#chat-widget-header {
    background: #1F3249;
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px;
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

#chat-widget-container.minimized #chat-widget-header {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #011c29;
}

#chat-widget-header .header-text {
    font-size: 1.1rem;
    font-weight: 600;
    margin-left: 0.3rem;
    transition: opacity 0.3s;
}

#chat-widget-container.minimized .header-text,
#chat-widget-container.minimized #chat-widget-toggle-btn {
    display: none;
}

#chat-widget-icon {
    display: none;
    width: 28px;
    height: 28px;
    color: white;
}

#chat-widget-container.minimized #chat-widget-icon {
    display: flex;
    justify-content: center;
    align-items: center;
}

.header-text-wrapper {
  display: flex;
  flex-direction: column;
}

.header-note {
  font-size: 0.7rem;
  color: #e5e5e5;
  margin-top: 0.2rem;
  margin-left: 0.3rem;
  white-space: normal;
}

#chat-widget-container.minimized .header-note {
  display: none;
}

/* Attention Note */
.attention-note {
  font-size: 0.7rem;
  color: #6c6c6c;
  background-color: white;
  padding: 8px 12px;
  text-align: center;
}

#chat-widget-container.minimized .attention-note {
  display: none;
}

/* Body */
#chat-widget-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background-color: #f2f2f2;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-overflow-scrolling: touch; /* iOS Safariのスクロール安定 */
}

#chat-widget-body:focus {
    outline: none; /* フォーカス時の青い枠を消す */
}

/* Chat Messages */
.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    max-width: 85%;
    word-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.5;
}

.chat-message.user {
    background: #e5d7c2;
    color: #3a3a3a;
    margin-left: auto;
    border-radius: 1.25rem 1.25rem 0.5rem 1.25rem;
    padding: 0.75rem 1rem;
    position: relative;
    box-shadow: 0 4px 8px rgba(31, 50, 73, 0.2);
    white-space: pre-wrap;
}

/* New CSS for bot messages */
.chat-message.bot {
    align-self: flex-start;
    display: flex;
    align-items: flex-start;
    gap: 8px; /* アイコンと内容の間 */
    margin-bottom: 12px;
}

.bot-message-bubble {
    background: #ffffff;
    color: #3a3a3a;
    border-radius: 1.25rem 1.25rem 1.25rem 0.5rem;
    padding: 0.75rem 1rem;
    position: relative;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
    word-break: break-word;
}

.chatbot-icon-container img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.chat-message-content {
    display: flex;
    flex-direction: column; /* ラベルと吹き出しを縦に */
}

.bot-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
    padding-left: 0.3rem;
}

/* Style for nested elements in bot message bubble */
.bot-message-bubble > * {
    margin: 0;
    padding: 0;
}
.bot-message-bubble p {
    margin: 0.5rem 0;
    white-space: pre-wrap;
}

.bot-message-bubble ol,
.bot-message-bubble ul {
    margin: 0.75rem 0;
    padding-left: 1.2rem;
}

.bot-message-bubble li {
    margin-bottom: 0.25rem;
}

.bot-message-bubble hr {
    border: none;
    border-top: 1px solid #d0d0d0;
    margin: 1rem 0;
}

.chat-message.bot > .bot-message-bubble > .message-content {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Links in bot messages */
.chat-message.bot a {
    color: #1F3249;
    text-decoration: underline;
    word-break: break-all;
}

/* Footer */
#chat-widget-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.8rem 1.2rem;
    background-color: #ffffff;
    gap: 0.75rem;
}

.footer-note {
    font-size: 0.7rem;
    color: #6c6c6c;
    text-align: left;
}

.footer-note a {
  color: #32aed7;
  text-decoration: none;
}

/* Input and Send Button */
#input-send-container {
    display: flex;
    width: 100%;
    align-items: flex-end;
}

#chat-widget-input {
    flex-grow: 1;
    padding: 0.75rem 1.25rem;
    border: 1px solid #ccc;
    border-radius: 1.5rem;
    font-size: 1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
    height: 48px; /* 初期高さを固定 */
    resize: none; 
    max-height: 150px;
    overflow-y: auto;
}

#chat-widget-input:focus {
    outline: none;
}

#chat-widget-send-btn {
    background-color: #011c29;
    color: #e5d7c2;
    border: none;
    border-radius: 12px;
    width: 60px;
    height: 40px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 0.5rem;
    transition: background-color 0.3s, transform 0.2s;
}

#chat-widget-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    background-color: #32aed7;
    border-color: #32aed7;
    color: #ffffff
}

#chat-widget-send-btn:disabled {
    background-color: #b4b4b4;
    border-color: #b4b4b4;
    color: #ffffff;
    cursor: not-allowed;
}

/* Feedback Buttons in chat body */
.solve-feedback-container {
    width: 100%;
    margin-top: 1rem;
    text-align: center;
    font-size: 0.875rem;
    color: #6c6c6c;
}
.solve-feedback-container p {
    margin: 0;
}
.solve-feedback-container div {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 5px;
}
.solve-feedback-container button {
    background: #011c29;
    color: #e5d7c2;
    border: none;
    border-radius: 1.25rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background-color 0.3s;
}
.solve-feedback-container button:hover {
    transform: scale(1.05);
    background-color: #32aed7;
    border-color: #32aed7;
    color: #ffffff
}

/* SVG icons */
#chat-widget-toggle-btn svg,
#chat-widget-icon svg,
#chat-widget-send-btn svg {
    width: 28px;
    height: 28px;
}

/* Close button specific styling */
#chat-widget-toggle-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    cursor: pointer;
    color: #3a3a3a;
}
#chat-widget-toggle-btn svg {
    stroke: white;
}

/* Chatbot Icon */
.chatbot-icon-container {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}
.chatbot-icon {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

/* ローディングスピナーのCSS */
.loading-message-content {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    color: #3a3a3a;
}

/* スピナーアイコンのスタイルと回転アニメーション */
.loading-message-content .dots-spinner {
  display: flex;
  gap: 8px;
}

.dots-spinner span {
  width: 8px;
  height: 8px;
  background: #949494;
  border-radius: 50%;
  animation: bounce 0.6s infinite alternate;
}

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

@keyframes bounce {
  to { transform: translateY(-10px); opacity: 0.5; }
}

/* 通知バッジ */
#chat-widget-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 15px;
    height: 15px;
    background-color: #e32226;
    border-radius: 50%;
    display: none;
    z-index: 10;
    pointer-events: none; /* クリックを邪魔しない */
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

/* リマインダーメッセージ */
#chat-reminder-bubble {
    position: fixed;
    bottom: 100px;
    right: 75px;
    background: #ffffff;
    color: #3a3a3a;
    padding: 10px 14px;
    border-radius: 1.25rem 1.25rem 0.5rem 1.25rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    font-size: 0.85rem;
    display: none; /* 初期状態でflexにするとロード時に一瞬ちらつくのでnoneにしておく */
    align-items: center;
    gap: 8px;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: all 0.4s ease;
    z-index: 10002;
}

#chat-reminder-bubble.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#chat-reminder-bubble .bubble-text { flex-grow: 1; }
#chat-reminder-bubble .bubble-close {
    background: none;
    border: none;
    color: #999;
    font-size: 1rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

#chat-reminder-bubble .bubble-close:hover { color: #333; }

/* Responsive Styles */
@media (max-width: 768px) {
    #chat-widget-container.minimized {
        width: 64px;
        height: 64px;
        bottom: 20px;
        right: 20px;
        left: auto;
        border-radius: 50%;
    }

    #chat-widget-container {
        width: 100%;
        height: 100dvh; /* vhではなくdvhを使う */
        max-height: 100dvh;
        bottom: 0;
        right: 0;
        left: auto;
        border-radius: 0;
    }

    #chat-widget-overlay {
        background: rgba(0, 0, 0, 0.6); /* mobileでは暗く */
        pointer-events: auto; /* 親ページはクリック不可 */
    }

    #chat-widget-header {
        position: sticky; 
        top: 0;
        z-index: 10;
        height: 50px;
        border-radius: 0%;
    }

    #chat-widget-header .header-text {
        font-size: 1.1rem;
    }
    
    /* Safariのfocus対応 */
    #chat-widget-input {
        font-size: 16px; /* レイアウトに影響するためtransformせず16px固定 */
    }

    #chat-reminder-bubble {
        bottom: 85px;
        right: 85px;
        font-size: 0.8rem;
        padding: 8px 12px;
    }
}
