/* style.css - 디자인 토큰 및 다크/라이트 모드 변수 */

:root {
    /* 라이트 모드 (기본, 할머니를 위한 고대비 가독성 테마) */
    --bg-gradient: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --primary-color: #2196F3;
    --primary-hover: #1976D2;
    --input-bg: rgba(255, 255, 255, 0.9);
    --msg-bg: #ffffff;
    --system-msg: #888888;
}

[data-theme="dark"] {
    /* 다크 모드 (세련되고 눈이 편안한 테마) */
    --bg-gradient: linear-gradient(135deg, #1f1c2c 0%, #928dab 100%);
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --glass-bg: rgba(20, 20, 20, 0.6);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary-color: #64b5f6;
    --primary-hover: #42a5f5;
    --input-bg: rgba(0, 0, 0, 0.4);
    --msg-bg: rgba(40, 40, 40, 0.8);
    --system-msg: #b0b0b0;
}

/* 기본 초기화 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Noto Sans KR', sans-serif;
}

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
    height: 100vh; /* 폴백 */
    height: 100dvh; /* 모바일 브라우저 주소창 높이를 제외한 실제 뷰포트 */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* 유틸리티: 숨김 */
.hidden {
    display: none !important;
}

/* 글래스모피즘 공통 패널 */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}

/* ---------------- 로그인/회원가입 모달 ---------------- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    padding: 3rem 2.5rem;
    width: 90%;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    background: var(--glass-bg);
}

.modal-content h2 { 
    margin-bottom: 0.5rem; 
    font-size: 1.8rem;
    font-weight: 700;
}
.modal-content p { 
    margin-bottom: 2rem; 
    color: var(--text-secondary); 
    font-size: 1.05rem; 
}

#auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.input-group input {
    width: 100%;
    padding: 1.1rem;
    font-size: 1.1rem;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-primary);
    outline: none;
    transition: all 0.3s ease;
}

.input-group input:focus {
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.3);
    border-color: var(--primary-color);
}

/* 4자리 PIN 입력창 UI */
.pin-group-container label {
    display: block;
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-align: left;
    margin-left: 0.5rem;
}
.pin-group {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}
.pin-box {
    width: 60px !important;
    height: 60px;
    text-align: center;
    font-size: 2rem !important;
    font-weight: bold;
    letter-spacing: 0;
    padding: 0 !important;
    border-radius: 12px;
}

.primary-btn {
    margin-top: 0.5rem;
    padding: 1.1rem;
    font-size: 1.2rem;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.4);
}
.primary-btn:hover { 
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.6);
}

.error-msg {
    color: #ef5350;
    margin-top: 1rem;
    font-weight: 500;
    font-size: 0.95rem;
}

/* 전환(스위치) 텍스트 버튼 */
.auth-switch {
    margin-top: 1.5rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
}
.text-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-weight: 700;
    cursor: pointer;
    font-size: 0.95rem;
    margin-left: 0.3rem;
}
.text-btn:hover {
    text-decoration: underline;
}

/* ---------------- 메인 앱 컨테이너 ---------------- */
.app-container {
    width: 95%;
    max-width: 1400px;
    height: 90vh;
    display: flex;
    gap: 1.5rem;
}

/* 사이드바 */
.sidebar {
    width: 300px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    margin-bottom: 2rem;
    text-align: center;
}
.sidebar-nav {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}
.tab-btn {
    padding: 1rem;
    font-size: 1.2rem;
    font-weight: 500;
    text-align: left;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s;
}
.tab-btn:hover {
    background: rgba(100, 181, 246, 0.1);
}
.tab-btn.active {
    background: var(--primary-color);
    color: #fff;
    font-weight: 700;
}

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}
.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 500;
}
.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s;
}
.icon-btn:hover { transform: scale(1.1); }

/* 메인 채팅 영역 */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}
.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.chat-header {
    padding: 1.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.hamburger-btn {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--text-primary);
    cursor: pointer;
    display: none; /* 데스크탑에선 숨김 */
}
.chat-header h3 { font-size: 1.5rem; margin-bottom: 0.2rem;}
.chat-header p { color: var(--text-secondary); }

/* AI 모델 선택 드롭다운 */
.model-select-wrapper {
    margin-left: auto; /* 헤더 우측 끝으로 밀기 */
}
.model-selector {
    padding: 0.5rem 2.2rem 0.5rem 1rem; /* 우측 화살표 여백 넉넉히 확보 */
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    outline: none;
    cursor: pointer;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}
.model-selector:focus, .model-selector:hover {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

.chat-history {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* 메시지 말풍선 공통 스타일 */
.message {
    max-width: 75%;
    padding: 0.8rem 1.2rem;
    border-radius: 18px;
    font-size: 1.05rem;
    line-height: 1.4;
    word-break: break-all;
    white-space: pre-wrap;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    animation: fadeIn 0.3s ease-out;
}

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

/* 내가 보낸 메시지 */
.message.my {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border-bottom-right-radius: 4px;
}

/* 상대방(가족) 메시지 */
.message.ai {
    align-self: flex-start;
    background: var(--msg-bg);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
}

/* AI가 생성한 답변 (프리미엄 우주색 그라데이션) */
.message.ai-reply {
    align-self: flex-start;
    background: linear-gradient(135deg, #1e1e2f, #3a1c71, #d76d77);
    background-size: 200% 200%;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-bottom-left-radius: 4px;
    animation: gradientShift 5s ease infinite, fadeIn 0.3s ease-out;
    box-shadow: 0 4px 15px rgba(58, 28, 113, 0.3);
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* 사용자가 AI(🤖) 버튼을 켜고 던진 질문 (빛나는 글로우 테두리 및 프리미엄 배경) */
.message.my.ai-prompt {
    background: linear-gradient(135deg, #4a148c, #7b1fa2);
    color: white;
    border: 2px solid #9c27b0;
    box-shadow: 0 0 12px rgba(156, 39, 176, 0.6);
}

.message.system {
    align-self: center;
    color: var(--system-msg);
    font-size: 0.95rem;
    margin: 1rem 0;
    box-shadow: none;
    background: transparent;
}

/* AI 토글 버튼 스타일 */
.ai-toggle-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: var(--input-bg);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    filter: grayscale(100%);
    opacity: 0.6;
}

.ai-toggle-btn.active {
    filter: grayscale(0%);
    opacity: 1;
    background: rgba(33, 150, 243, 0.15);
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.3);
}

.chat-input-area {
    display: flex;
    padding: 1.5rem;
    gap: 1rem;
    background: var(--glass-bg);
    border-top: 1px solid var(--glass-border);
    border-radius: 0 0 16px 16px;
    align-items: center;
}
.chat-input-area .chat-input {
    flex-grow: 1;
    border-radius: 30px;
    padding: 1rem 1.5rem;
    font-size: 1.05rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: var(--msg-bg);
    color: var(--text-primary);
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.05);
    outline: none;
    transition: all 0.3s ease;
}
.chat-input-area .chat-input:focus {
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2), inset 0 2px 5px rgba(0,0,0,0.05);
    border-color: var(--primary-color);
}
.chat-input-area .send-btn {
    padding: 1rem 2rem;
    border-radius: 30px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}
.chat-input-area .send-btn:hover { 
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.5);
}

/* ---------------- 반응형 모바일 (Mobile Responsive) ---------------- */
@media (max-width: 768px) {
    /* 모바일에서는 기본 폰트 사이즈를 줄여서 밀림 현상 방지 */
    html {
        font-size: 14px;
    }
    
    .app-container {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        flex-direction: column;
        gap: 0;
        border-radius: 0;
        border: none;
    }
    
    .hamburger-btn {
        display: block; /* 모바일에서 햄버거 보임 */
    }
    
    /* 사이드바를 좌측 슬라이드 햄버거 메뉴로 변경 */
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%; /* 기본 숨김 */
        width: 280px;
        height: 100vh;
        height: 100dvh;
        padding: 1.5rem;
        flex-direction: column;
        background: var(--bg-gradient);
        box-shadow: 5px 0 25px rgba(0,0,0,0.2);
        z-index: 2000;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-right: 1px solid var(--glass-border);
    }
    
    .sidebar.open {
        left: 0; /* 열렸을 때 */
    }
    
    .sidebar-header h2 {
        font-size: 1.5rem;
    }
    
    .sidebar-nav {
        flex-direction: column;
        gap: 1rem;
    }
    
    .main-content {
        height: 100vh;
        height: 100dvh;
        border: none;
        border-radius: 0;
    }
    
    .chat-header {
        padding: 0.8rem;
        border-bottom: 1px solid var(--glass-border);
        flex-wrap: nowrap; /* 억지로 줄바꿈 방지, 한 줄에 배치 */
        align-items: center;
        gap: 0.5rem;
    }
    
    .chat-header-text {
        flex-grow: 1; /* 남은 공간을 차지하여 드롭다운을 우측으로 밈 */
        word-break: keep-all;
    }
    
    .chat-header h3 {
        font-size: 1.2rem;
        white-space: nowrap; /* 제목이 두 줄로 꺾이는 것 방지 */
    }
    
    .chat-header p {
        display: none; /* 모바일에서는 설명 텍스트를 숨겨서 헤더 높이 최소화 (채팅 영역 확보) */
    }
    
    /* 모델 선택 드롭다운도 모바일 크기에 맞춰 미세조정 */
    .model-selector {
        padding: 0.4rem 1.6rem 0.4rem 0.6rem;
        font-size: 0.8rem;
        max-width: 130px; /* 너무 넓어지지 않게 고정 */
        text-overflow: ellipsis;
    }
    
    .chat-input-area {
        padding: 1rem 0.8rem;
    }
    .chat-input-area .chat-input {
        padding: 0.8rem 1.2rem;
    }
    
    .chat-input-area .send-btn {
        padding: 0.8rem 1.5rem;
    }
}
