/* css/aichat.css — AI 회복 상담사 UI */

/* ═══════════════════════════════════════════
   Floating Action Button (홈탭 우하단)
   ═══════════════════════════════════════════ */
/* Pill-shaped FAB: Coby 얼굴 + "AI" 텍스트를 나란히 */
/* ── AI FAB: 원형 버튼, 코비/AI 교대 ── */
.aichat-fab {
    position: fixed;
    right: 14px;
    bottom: calc(96px + env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
    padding: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #2DA89B, #1E8F85);
    border: none;
    box-shadow: 0 6px 20px rgba(45,168,155,0.4);
    cursor: pointer;
    z-index: 995;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, box-shadow 0.2s;
    animation: aichatFabPulse 4s ease-in-out infinite;
    overflow: hidden;
}
.aichat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 28px rgba(45,168,155,0.5);
}
.aichat-fab:active {
    transform: scale(0.92);
}
/* AI 텍스트: 항상 보임 (코비 아래 깔림) */
.aichat-fab-text {
    position: absolute;
    color: #fff;
    font-size: 22px;
    font-weight: 900;
    letter-spacing: 1.5px;
    line-height: 1;
    -webkit-text-fill-color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.2);
    z-index: 1;
}
/* 코비: AI 위에 겹쳐서 보였다 사라졌다 */
.aichat-fab-coby {
    position: absolute;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #fff;
    padding: 2px;
    object-fit: contain;
    z-index: 2;
    opacity: 0; /* 디폴트: AI 마크 보임 (코비 숨김) */
    animation: fabCobyFade 11s ease-in-out infinite;
}
/* 총 11초: AI 5초 → fade in 1.5초 → 코비 3초 → fade out 1.5초 */
@keyframes fabCobyFade {
    0%, 45% { opacity: 0; }       /* 0~5초: AI만 보임 */
    59% { opacity: 1; }           /* 5~6.5초: 코비 fade in */
    86% { opacity: 1; }           /* 6.5~9.5초: 코비 보임 */
    100% { opacity: 0; }          /* 9.5~11초: 코비 fade out → AI */
}
@keyframes aichatFabPulse {
    0%, 100% { box-shadow: 0 6px 20px rgba(45,168,155,0.4); }
    50% { box-shadow: 0 6px 20px rgba(45,168,155,0.4), 0 0 0 6px rgba(45,168,155,0.12); }
}
[data-theme="dark"] .aichat-fab {
    box-shadow: 0 8px 24px rgba(45,168,155,0.5);
}

/* ═══════════════════════════════════════════
   Chat Modal Overlay
   ═══════════════════════════════════════════ */
.aichat-overlay {
    position: fixed;
    inset: 0;
    background: var(--ap-bg);
    z-index: 10003;
    display: none;
    flex-direction: column;
    animation: fadeIn 0.25s ease;
}
.aichat-overlay.active {
    display: flex;
}
[data-theme="dark"] .aichat-overlay {
    background: var(--ap-bg);
}

/* ═══════════════════════════════════════════
   Header
   ═══════════════════════════════════════════ */
.aichat-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    padding-top: calc(16px + env(safe-area-inset-top));
    background: linear-gradient(135deg, #2DA89B, #1E8F85);
    color: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
.aichat-header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.aichat-header-avatar img {
    width: 36px;
    height: 36px;
    object-fit: contain;
}
.aichat-header-info {
    flex: 1;
    min-width: 0;
}
.aichat-header-title {
    font-size: 16px;
    font-weight: 800;
    margin: 0;
    letter-spacing: -0.2px;
}
.aichat-header-sub {
    font-size: 11px;
    opacity: 0.85;
    margin: 2px 0 0;
}
.aichat-header-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.aichat-header-close:active { background: rgba(255,255,255,0.25); }

/* ═══════════════════════════════════════════
   Disclaimer Banner
   ═══════════════════════════════════════════ */
.aichat-disclaimer {
    flex-shrink: 0;
    padding: 10px 18px;
    background: rgba(232,168,80,0.12);
    border-bottom: 1px solid rgba(232,168,80,0.2);
    font-size: 11px;
    color: var(--ap-text-secondary);
    text-align: center;
    line-height: 1.5;
    word-break: keep-all;
}
[data-theme="dark"] .aichat-disclaimer {
    background: rgba(240,192,96,0.10);
    border-bottom-color: rgba(240,192,96,0.2);
}
.aichat-disclaimer strong {
    color: var(--ap-text);
    font-weight: 700;
}

/* ═══════════════════════════════════════════
   Messages Area
   ═══════════════════════════════════════════ */
.aichat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}
.aichat-messages::-webkit-scrollbar { width: 4px; }
.aichat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 4px;
}

/* ─ Welcome Screen (no messages yet) ─ */
.aichat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 8px;
    text-align: center;
}
.aichat-welcome-coby {
    width: 80px;
    height: 80px;
    margin-bottom: 12px;
}
.aichat-welcome-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--ap-text);
    margin: 0 0 6px;
    letter-spacing: -0.3px;
}
.aichat-welcome-sub {
    font-size: 13px;
    color: var(--ap-text-secondary);
    margin: 0 0 20px;
    line-height: 1.55;
    max-width: 300px;
    word-break: keep-all;
}

/* ─ Suggested Questions ─ */
.aichat-suggestions {
    width: 100%;
    max-width: 420px;
}
.aichat-suggestions-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--ap-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin: 0 0 8px 4px;
}
.aichat-suggestion {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--ap-card);
    border: 1.5px solid var(--ap-border);
    border-radius: 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.2s;
    text-align: left;
    width: 100%;
    font-family: inherit;
}
.aichat-suggestion:active {
    transform: scale(0.98);
    border-color: var(--ap-primary);
}
[data-theme="dark"] .aichat-suggestion {
    background: var(--ap-surface-1);
    border-color: rgba(255,255,255,0.08);
}
.aichat-suggestion-icon {
    font-size: 20px;
    flex-shrink: 0;
}
.aichat-suggestion-text {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--ap-text);
    line-height: 1.4;
    word-break: keep-all;
}
.aichat-suggestion-arrow {
    color: var(--ap-text-muted);
    font-size: 16px;
    flex-shrink: 0;
}

/* ─ Chat Bubbles ─ */
.aichat-msg {
    display: flex;
    gap: 8px;
    max-width: 90%;
    animation: aichatMsgIn 0.25s ease;
}
@keyframes aichatMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.aichat-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.aichat-msg-ai {
    align-self: flex-start;
}
.aichat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: contain;
    background: var(--ap-bg-secondary);
    padding: 2px;
}
[data-theme="dark"] .aichat-msg-avatar {
    background: var(--ap-surface-2);
}
.aichat-msg-bubble {
    padding: 12px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}
.aichat-msg-user .aichat-msg-bubble {
    background: var(--ap-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.aichat-msg-ai .aichat-msg-bubble {
    background: var(--ap-card);
    color: var(--ap-text);
    border: 1px solid var(--ap-border);
    border-bottom-left-radius: 4px;
}
[data-theme="dark"] .aichat-msg-ai .aichat-msg-bubble {
    background: var(--ap-surface-1);
    border-color: rgba(255,255,255,0.08);
}
.aichat-msg-bubble strong { font-weight: 800; color: var(--ap-text); }
.aichat-msg-user .aichat-msg-bubble strong { color: #fff; }
.aichat-msg-bubble p { margin: 0 0 8px; }
.aichat-msg-bubble p:last-child { margin-bottom: 0; }
.aichat-msg-bubble ul, .aichat-msg-bubble ol {
    margin: 6px 0;
    padding-left: 18px;
}
.aichat-msg-bubble li { margin-bottom: 3px; }
.aichat-msg-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--ap-text);
    margin: 0 0 6px;
}
.aichat-msg-user .aichat-msg-title { color: #fff; }

/* Emergency message styling */
.aichat-msg-emergency .aichat-msg-bubble {
    background: linear-gradient(135deg, rgba(197,61,61,0.1), rgba(232,168,80,0.08));
    border: 2px solid rgba(197,61,61,0.3);
    color: var(--ap-text);
}
[data-theme="dark"] .aichat-msg-emergency .aichat-msg-bubble {
    background: linear-gradient(135deg, rgba(224,96,96,0.15), rgba(240,192,96,0.1));
    border-color: rgba(224,96,96,0.4);
}
.aichat-msg-emergency .aichat-msg-title {
    color: #C53D3D;
    display: flex;
    align-items: center;
    gap: 6px;
}
[data-theme="dark"] .aichat-msg-emergency .aichat-msg-title { color: #ff8080; }
.aichat-emergency-icon { font-size: 20px; }

/* Typing indicator */
.aichat-typing {
    display: flex;
    gap: 4px;
    padding: 14px 16px;
    background: var(--ap-card);
    border: 1px solid var(--ap-border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 80px;
}
[data-theme="dark"] .aichat-typing {
    background: var(--ap-surface-1);
    border-color: rgba(255,255,255,0.08);
}
.aichat-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ap-text-muted);
    animation: aichatTyping 1.4s ease-in-out infinite;
}
.aichat-typing span:nth-child(2) { animation-delay: 0.2s; }
.aichat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes aichatTyping {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* ── Streaming cursor ── */
.aichat-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--ap-primary, #2DA89B);
    animation: aichatBlink 0.8s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 1px;
}
@keyframes aichatBlink {
    50% { opacity: 0; }
}
.aichat-stream-text {
    white-space: pre-wrap;
    line-height: 1.6;
}

/* ═══════════════════════════════════════════
   Input Area
   ═══════════════════════════════════════════ */
.aichat-input-area {
    flex-shrink: 0;
    padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
    background: var(--ap-card);
    border-top: 1px solid var(--ap-border);
}
[data-theme="dark"] .aichat-input-area {
    background: var(--ap-surface-1);
    border-top-color: rgba(255,255,255,0.08);
}
.aichat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.aichat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1.5px solid var(--ap-border);
    border-radius: 20px;
    font-size: 15px;
    background: var(--ap-bg);
    color: var(--ap-text);
    outline: none;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    min-height: 44px;
    line-height: 1.4;
    transition: border-color 0.2s;
}
.aichat-input:focus { border-color: var(--ap-primary); }
[data-theme="dark"] .aichat-input {
    background: var(--ap-surface-2);
    border-color: rgba(255,255,255,0.1);
}
.aichat-send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--ap-primary);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.2s;
}
.aichat-send-btn:active { transform: scale(0.92); }
.aichat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Quota indicator */
.aichat-quota {
    font-size: 10px;
    color: var(--ap-text-muted);
    text-align: center;
    margin-top: 6px;
    line-height: 1.4;
}
.aichat-quota-highlight {
    color: var(--ap-primary);
    font-weight: 700;
}

/* ═══════════════════════════════════════════
   Galaxy Fold small screen
   ═══════════════════════════════════════════ */
@media (max-width: 380px) {
    .aichat-fab { width: 48px; height: 48px; right: 14px; }
    .aichat-fab-coby { width: 36px; height: 36px; }
    .aichat-fab-text { font-size: 18px; }
    .aichat-header { padding: 14px 14px; }
    .aichat-header-title { font-size: 15px; }
    .aichat-welcome-title { font-size: 18px; }
    .aichat-suggestion { padding: 12px 14px; }
    .aichat-suggestion-text { font-size: 13px; }
    .aichat-msg-bubble { font-size: 13px; padding: 10px 12px; }
    .aichat-input { font-size: 14px; padding: 10px 14px; }
}

/* ═══════════════════════════════════════════
   Header FAQ button
   ═══════════════════════════════════════════ */
.aichat-header-faq {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: 1.5px solid rgba(255,255,255,0.35);
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    margin-right: 8px;
    transition: background 0.15s, transform 0.15s;
}
.aichat-header-faq:active {
    background: rgba(255,255,255,0.28);
    transform: scale(0.95);
}
.aichat-header-faq-label {
    letter-spacing: 0.3px;
}

/* Input-row FAQ button (왼쪽) */
.aichat-faq-btn {
    width: 44px;
    height: 44px;
    border: 1.5px solid var(--ap-border);
    background: var(--ap-card);
    color: var(--ap-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
}
.aichat-faq-btn:active {
    transform: scale(0.92);
    background: rgba(45,168,155,0.12);
}
[data-theme="dark"] .aichat-faq-btn {
    background: var(--ap-surface-2);
    border-color: rgba(255,255,255,0.1);
}

/* FAQ message badge (무료 안내) */
.aichat-msg-faq-badge {
    margin-top: 10px;
    padding: 6px 10px;
    background: rgba(45,168,155,0.10);
    border: 1px solid rgba(45,168,155,0.22);
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--ap-primary);
    text-align: center;
    letter-spacing: -0.1px;
}
[data-theme="dark"] .aichat-msg-faq-badge {
    background: rgba(77,184,164,0.12);
    border-color: rgba(77,184,164,0.28);
    color: #5CC9B8;
}

/* ═══════════════════════════════════════════
   FAQ Sheet (Bottom sheet)
   ═══════════════════════════════════════════ */
.aichat-faq-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
    z-index: 10;
}
.aichat-faq-sheet-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.aichat-faq-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--ap-bg);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    max-height: 80%;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
    z-index: 11;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.15);
}
.aichat-faq-sheet.active {
    transform: translateY(0);
}
[data-theme="dark"] .aichat-faq-sheet {
    background: var(--ap-surface-1);
}

.aichat-faq-sheet-header {
    flex-shrink: 0;
    padding: 18px 18px 10px;
    position: relative;
    border-bottom: 1px solid var(--ap-border);
}
.aichat-faq-sheet-title {
    font-size: 17px;
    font-weight: 800;
    color: var(--ap-text);
    margin: 0 0 4px;
}
.aichat-faq-sheet-sub {
    font-size: 12px;
    color: var(--ap-text-secondary);
    margin: 0;
    line-height: 1.5;
}
.aichat-faq-sheet-sub strong {
    color: var(--ap-primary);
    font-weight: 800;
}
.aichat-faq-sheet-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--ap-bg-secondary);
    color: var(--ap-text-muted);
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aichat-faq-sheet-search {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 18px 8px;
    padding: 10px 14px;
    background: var(--ap-bg-secondary);
    border-radius: 12px;
}
.aichat-faq-sheet-search-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: var(--ap-text);
    font-family: inherit;
}
.aichat-faq-sheet-search-input::placeholder {
    color: var(--ap-text-muted);
}

.aichat-faq-sheet-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
}

.aichat-faq-sheet-group {
    margin-bottom: 16px;
}
.aichat-faq-sheet-group-label {
    font-size: 12px;
    font-weight: 800;
    color: var(--ap-text-secondary);
    margin: 10px 0 6px 4px;
    letter-spacing: -0.2px;
}
.aichat-faq-sheet-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 14px;
    background: var(--ap-card);
    border: 1px solid var(--ap-border);
    border-radius: 12px;
    margin-bottom: 6px;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
.aichat-faq-sheet-item:active {
    background: rgba(45,168,155,0.08);
    transform: scale(0.99);
}
[data-theme="dark"] .aichat-faq-sheet-item {
    background: var(--ap-surface-2);
    border-color: rgba(255,255,255,0.08);
}
.aichat-faq-sheet-item-text {
    flex: 1;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ap-text);
    line-height: 1.4;
    word-break: keep-all;
}
.aichat-faq-sheet-item-arrow {
    color: var(--ap-text-muted);
    font-size: 16px;
    flex-shrink: 0;
}
.aichat-faq-sheet-empty {
    text-align: center;
    padding: 40px 20px;
}

/* Galaxy Fold */
@media (max-width: 380px) {
    .aichat-header-faq { padding: 5px 8px; font-size: 11px; }
    .aichat-header-faq-label { display: none; }
    .aichat-faq-btn { width: 40px; height: 40px; }
    .aichat-faq-sheet-title { font-size: 15px; }
    .aichat-faq-sheet-item-text { font-size: 12.5px; }
}
