/* AI Manager Chat - KakaoTalk Style */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* Reset for chat page */
body.chat-page {
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    height: 100vh !important;
    height: 100dvh !important;
}

/* Chat Container - Full Screen */
.chat-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background: #B2C7D9;
    overflow: hidden;
}

/* Chat Header - Fixed at Top */
.chat-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    z-index: 100;
    height: 60px;
    flex-shrink: 0;
    box-sizing: border-box;
}

.back-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 50%;
    transition: background 0.2s;
}

.back-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.chat-header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-avatar {
    width: 44px;
    height: 44px;
    border-radius: 16px;
    background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.chat-header-text h1 {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.chat-header-text .status {
    font-size: 13px;
    color: #34C759;
    margin: 2px 0 0 0;
}

.menu-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.menu-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Chat Messages Area - Scrollable */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
    min-height: 0; /* Required for flex children to scroll */
}

/* Bottom Area - Fixed at Bottom */
.chat-bottom {
    flex-shrink: 0;
    background: transparent;
}

/* Date Divider */
.chat-date-divider {
    display: flex;
    justify-content: center;
    padding: 16px 0;
}

.chat-date-divider span {
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    padding: 6px 16px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Message Bubble */
.message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: messageIn 0.3s ease;
}

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

/* AI Message (left) */
.message.ai {
    align-self: flex-start;
}

.message.ai .avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
    align-self: flex-end;
}

.message.ai .bubble {
    background: #fff;
    border-radius: 4px 20px 20px 20px;
    padding: 12px 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* User Message (right) */
.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.user .bubble {
    background: #FEE500;
    border-radius: 20px 4px 20px 20px;
    padding: 12px 16px;
}

.message .bubble p {
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-primary);
    word-break: break-word;
}

.message .bubble p + p {
    margin-top: 8px;
}

/* Message Time */
.message .time {
    font-size: 11px;
    color: rgba(0, 0, 0, 0.4);
    align-self: flex-end;
    flex-shrink: 0;
    padding-bottom: 4px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Message with Cards */
.message-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.message-card {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 12px;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.message-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.message-card-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

.message-card-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    padding: 8px 16px;
    background: #007AFF;
    color: #ffffff !important;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: rgba(178, 199, 217, 0.9);
}

.quick-actions::-webkit-scrollbar {
    display: none;
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: #fff;
    border: none;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.quick-action-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.quick-action-btn:active {
    transform: scale(0.98);
}

.quick-action-btn .icon {
    font-size: 16px;
}

/* Chat Input Area */
.chat-input-area {
    background: #fff;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f5f5f5;
    border-radius: 24px;
    padding: 6px;
}

.attach-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;
}

.attach-btn:hover {
    color: var(--accent);
    background: rgba(0, 122, 255, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 4px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    color: var(--text-primary);
}

.chat-input:focus {
    outline: none;
}

.chat-input::placeholder {
    color: var(--text-tertiary);
}

.send-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn svg {
    width: 18px;
    height: 18px;
    margin-left: 2px;
}

/* Menu Modal */
.menu-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.menu-modal.show {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.menu-modal-content {
    background: #fff;
    width: 100%;
    max-width: 500px;
    border-radius: 20px 20px 0 0;
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    cursor: pointer;
    transition: background 0.2s;
}

.menu-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.menu-icon {
    font-size: 20px;
}

.menu-item span:last-child {
    font-size: 16px;
    color: var(--text-primary);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 122, 255, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Markdown in messages */
.bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', monospace;
    font-size: 14px;
}

.bubble strong {
    font-weight: 600;
}

.bubble a {
    color: var(--accent);
    text-decoration: none;
}

.bubble a:hover {
    text-decoration: underline;
}

.bubble ul, .bubble ol {
    margin: 8px 0;
    padding-left: 20px;
}

.bubble li {
    margin: 4px 0;
}

/* XP Badge in messages */
.xp-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    color: #333;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 700;
    margin-left: 4px;
}

/* Profile Score in messages */
.profile-score {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 12px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
}

.score-ring {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: conic-gradient(var(--accent) var(--score-percent, 0%), #e0e0e0 0%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.score-ring::after {
    content: '';
    position: absolute;
    width: 38px;
    height: 38px;
    background: #fff;
    border-radius: 50%;
}

.score-ring span {
    position: relative;
    z-index: 1;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.score-info {
    flex: 1;
}

.score-info h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 4px 0;
}

.score-info p {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chat-header {
        padding: 8px 12px;
    }

    .message {
        max-width: 90%;
    }

    .chat-messages {
        padding: 12px;
    }

    .quick-actions {
        padding: 8px 12px;
    }

    .quick-action-btn {
        padding: 8px 14px;
        font-size: 13px;
    }
}

/* iPhone SE (375px) */
@media (max-width: 375px) {
    .ai-avatar {
        width: 38px;
        height: 38px;
    }

    .chat-header-text h1 {
        font-size: 15px;
    }

    .message .bubble {
        padding: 10px 14px;
    }

    .message .bubble p {
        font-size: 14px;
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    .chat-page {
        background: #1C1C1E;
    }

    .chat-header {
        background: rgba(28, 28, 30, 0.95);
        border-color: rgba(255, 255, 255, 0.1);
    }

    .chat-header-text h1 {
        color: #fff;
    }

    .back-btn, .menu-btn {
        color: #fff;
    }

    .chat-date-divider span {
        background: rgba(255, 255, 255, 0.15);
    }

    .message.ai .bubble {
        background: #2C2C2E;
    }

    .message.ai .bubble p {
        color: #fff;
    }

    .message.user .bubble {
        background: #007AFF;
    }

    .message.user .bubble p {
        color: #fff;
    }

    .quick-action-btn {
        background: #2C2C2E;
        color: #fff;
    }

    .chat-input-area {
        background: #1C1C1E;
        border-color: rgba(255, 255, 255, 0.1);
    }

    .chat-input-wrapper {
        background: #2C2C2E;
    }

    .chat-input {
        color: #fff;
    }

    .menu-modal-content {
        background: #2C2C2E;
    }

    .menu-item span:last-child {
        color: #fff;
    }
}

/* ========================================
   앱 모드 (Standalone/PWA) 스타일
   ======================================== */

/* 앱 모드에서 chat-container 위치 조정 (하단 탭바 공간 확보) */
body.app-mode.chat-page .chat-container {
    bottom: calc(56px + env(safe-area-inset-bottom));
}

/* 앱 모드에서 AI 매니저 페이지는 앱 헤더 숨김 (자체 헤더 사용) */
body.app-mode.chat-page .app-header {
    display: none !important;
}

/* 앱 모드에서 메뉴 모달 위치 조정 */
body.app-mode.chat-page .menu-modal-content {
    padding-bottom: max(8px, calc(56px + env(safe-area-inset-bottom)));
}

/* 앱 모드에서 채팅 입력 영역 하단 여백 */
body.app-mode.chat-page .chat-bottom {
    padding-bottom: 0;
}

/* 앱 모드에서 데스크탑은 기존 스타일 유지 */
@media (min-width: 1024px) {
    body.app-mode.chat-page .chat-container {
        bottom: 0;
    }

    body.app-mode.chat-page .menu-modal-content {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}
