/* M-Sphere AI 광고 플랫폼 Custom Styles */

/* 기본 폰트 및 레이아웃 */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    line-height: 1.6;
    scroll-behavior: smooth;
}

/* 그라디언트 배경 애니메이션 */
.gradient-bg {
    background: linear-gradient(-45deg, #667eea, #764ba2, #f093fb, #f5576c);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
}

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

/* 모바일 최적화 */
@media (max-width: 768px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    h2 {
        font-size: 2.5rem !important;
        line-height: 1.2;
    }
    
    .grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* 모바일에서 카드 간격 조정 */
    .bg-white {
        margin-bottom: 1rem;
    }
}

/* 터치 친화적 인터페이스 */
@media (max-width: 640px) {
    /* 버튼 크기 증대 */
    button {
        min-height: 48px;
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }
    
    /* 입력 필드 크기 조정 */
    input, select, textarea {
        min-height: 48px;
        font-size: 16px; /* iOS에서 줌 방지 */
    }
    
    /* 네비게이션 최적화 */
    header .container {
        padding: 1rem;
    }
    
    /* 섹션 간격 조정 */
    section {
        padding: 2rem 0;
    }
}

/* 커스텀 애니메이션 */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

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

/* 호버 효과 향상 */
.hover-lift {
    transition: all 0.3s ease;
}

.hover-lift:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* 성공/에러 메시지 애니메이션 */
.error-message, .success-message {
    animation: slideInDown 0.3s ease-out;
}

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

/* 로딩 스피너 */
.spinner {
    animation: spin 1s linear infinite;
}

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

/* 폼 스타일링 향상 */
.form-input:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    outline: none;
}

/* 차트 컨테이너 */
#budgetChart canvas {
    max-width: 100%;
    height: auto;
}

/* 프린트 스타일 */
@media print {
    body {
        background: white !important;
    }
    
    header, footer {
        display: none;
    }
    
    .no-print {
        display: none;
    }
    
    .bg-gradient-to-r, .bg-gradient-to-br {
        background: #f9fafb !important;
        border: 1px solid #e5e7eb;
    }
}

/* 다크모드 준비 (추후 구현) */
@media (prefers-color-scheme: dark) {
    /* 다크모드 스타일은 필요시 추가 */
}

/* 접근성 향상 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 포커스 표시 개선 */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid #3B82F6;
    outline-offset: 2px;
}

/* 스크롤바 스타일링 (웹킷 브라우저) */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 텍스트 선택 스타일 */
::selection {
    background-color: #3B82F6;
    color: white;
}

/* 모바일 터치 개선 */
@media (hover: none) {
    .hover\\:shadow-lg:hover {
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    }
}

/* 고해상도 디스플레이 대응 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* 레티나 디스플레이용 최적화 */
    canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: optimize-contrast;
    }
}

/* 플렉스 유틸리티 클래스 */
.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 그리드 반응형 최적화 */
.responsive-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* 카드 호버 효과 */
.card-hover {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* 텍스트 그라디언트 */
.text-gradient {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* 상태 표시 배지 */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-success {
    background-color: #d1fae5;
    color: #065f46;
}

.status-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.status-error {
    background-color: #fee2e2;
    color: #991b1b;
}

/* 반응형 타이포그래피 */
.responsive-text {
    font-size: clamp(1rem, 2.5vw, 1.125rem);
}

.responsive-heading {
    font-size: clamp(1.5rem, 5vw, 3rem);
}

/* 디바이스 미리보기 모달 */
#devicePreviewModal {
    backdrop-filter: blur(4px);
    z-index: 9999;
}

#deviceFrame {
    transition: all 0.3s ease;
    max-width: 100%;
}

#deviceFrame iframe {
    border-radius: 1rem;
}

/* 미리보기 모달 반응형 */
@media (max-width: 640px) {
    #devicePreviewModal .max-w-4xl {
        max-width: 95vw;
        margin: 1rem;
    }
    
    #deviceFrame {
        max-width: 100%;
        transform: scale(0.8);
    }
    
    #deviceFrame[style*="1200px"] {
        transform: scale(0.3);
    }
    
    #deviceFrame[style*="768px"] {
        transform: scale(0.45);
    }
    
    #deviceFrame[style*="375px"] {
        transform: scale(0.9);
    }
}

@media (max-width: 1024px) {
    #deviceFrame[style*="1200px"] {
        transform: scale(0.6);
    }
    
    #deviceFrame[style*="768px"] {
        transform: scale(0.8);
    }
}

/* 모바일 메뉴 애니메이션 */
#mobileMenu {
    transition: all 0.3s ease;
    transform-origin: top;
}

#mobileMenu.hidden {
    transform: scaleY(0);
    opacity: 0;
}

#mobileMenu:not(.hidden) {
    transform: scaleY(1);
    opacity: 1;
}

/* 미리보기 버튼 호버 효과 */
.preview-button {
    transition: all 0.2s ease;
}

.preview-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* 디바이스 프레임 그림자 */
#deviceFrame {
    box-shadow: 
        0 25px 50px -12px rgba(0, 0, 0, 0.25),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

/* 모달 스무스 애니메이션 */
#devicePreviewModal {
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* 미리보기 프레임 로딩 */
#previewFrame {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 2s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* PWA 및 모바일 최적화 */
/* 사용자 정의 CSS 변수 for viewport height */
:root {
    --vh: 1vh;
}

/* 키보드 열림 감지 */
.keyboard-open {
    --vh: 1vh;
}

.keyboard-open .min-h-screen {
    min-height: calc(var(--vh, 1vh) * 100);
}

/* 페이지 숨김 시 애니메이션 일시정지 */
.page-hidden * {
    animation-play-state: paused !important;
}

/* PWA 설치 버튼 */
#installButton, #installButtonMobile {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* 터치 피드백 개선 */
.touch-feedback {
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.touch-feedback:active {
    transform: scale(0.98);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* 모바일 타이핑 영역 최적화 */
@media (max-width: 640px) {
    /* 폼 입력 시 하단 여백 추가 */
    .keyboard-open #recommendationForm {
        padding-bottom: 200px;
    }
    
    /* 입력 필드 포커스 시 확대 */
    input:focus,
    select:focus,
    textarea:focus {
        transform: scale(1.02);
        z-index: 10;
        position: relative;
    }
}

/* 네트워크 상태 토스트 */
.network-toast {
    animation: slideInFromTop 0.3s ease-out;
}

@keyframes slideInFromTop {
    from {
        transform: translateX(-50%) translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* 햅틱 피드백 표시 */
.haptic-feedback {
    position: relative;
}

.haptic-feedback::after {
    content: '';
    position: absolute;
    inset: -2px;
    background: linear-gradient(45deg, transparent, rgba(59, 130, 246, 0.3), transparent);
    border-radius: inherit;
    opacity: 0;
    transition: opacity 0.1s ease;
}

.haptic-feedback.active::after {
    opacity: 1;
}

/* 세이프 에어리어 대응 (iOS) */
@supports (padding: max(0px)) {
    .safe-area-inset-top {
        padding-top: max(1rem, env(safe-area-inset-top));
    }
    
    .safe-area-inset-bottom {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
    
    .safe-area-inset-left {
        padding-left: max(1rem, env(safe-area-inset-left));
    }
    
    .safe-area-inset-right {
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* 다크모드 기본 지원 */
@media (prefers-color-scheme: dark) {
    .dark-mode-ready {
        --bg-primary: #1f2937;
        --text-primary: #f9fafb;
        --border-primary: #374151;
    }
}

/* 모션 감소 선호 사용자 대응 */
@media (prefers-reduced-motion: reduce) {
    *, 
    *::before, 
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* 고대비 모드 대응 */
@media (prefers-contrast: high) {
    .bg-primary {
        background-color: #000080 !important;
    }
    
    .text-gray-600 {
        color: #000000 !important;
    }
    
    .border-gray-300 {
        border-color: #000000 !important;
    }
}

/* 챗봇 스타일 */
#chatContainer {
    scroll-behavior: smooth;
}

#chatContainer::-webkit-scrollbar {
    width: 6px;
}

#chatContainer::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

#chatContainer::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

#chatContainer::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* 챗 메시지 애니메이션 */
.chat-message {
    animation: slideInMessage 0.3s ease-out;
}

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

/* 챗 옵션 버튼 */
.chat-option, .goal-option {
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.chat-option:hover, .goal-option:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border-color: currentColor;
}

.chat-option:active, .goal-option:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* 타이핑 애니메이션 */
.animate-bounce {
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% {
        transform: translate3d(0,0,0);
    }
    40%, 43% {
        transform: translate3d(0,-8px,0);
    }
    70% {
        transform: translate3d(0,-4px,0);
    }
    90% {
        transform: translate3d(0,-2px,0);
    }
}

/* 프로그레스 바 애니메이션 */
#progressBar {
    transition: width 0.5s ease-in-out;
}

/* 챗 입력 포커스 */
#chatInput:focus {
    outline: none;
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 모바일 챗봇 최적화 */
@media (max-width: 640px) {
    #chatContainer {
        height: 320px;
    }
    
    .chat-option, .goal-option {
        padding: 0.75rem;
        font-size: 0.875rem;
    }
    
    /* 모바일에서 채팅 메시지 크기 조정 */
    .max-w-md {
        max-width: 85%;
    }
    
    /* 챗 옵션 그리드 모바일 최적화 */
    .grid-cols-2 {
        grid-template-columns: 1fr;
    }
    
    @media (min-width: 380px) {
        .grid-cols-2 {
            grid-template-columns: repeat(2, 1fr);
        }
    }
}

/* 챗봇 헤더 아바타 애니메이션 */
.chat-avatar {
    animation: pulse 2s infinite;
}

/* 메시지 말풍선 그라데이션 */
.message-gradient {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* 호버 효과가 있는 챗 버튼 */
.chat-button-hover:hover {
    background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 100%);
    transform: scale(1.02);
    box-shadow: 0 8px 16px rgba(59, 130, 246, 0.3);
}

/* 채팅 완료 애니메이션 */
.chat-complete {
    animation: chatComplete 0.5s ease-out;
}

@keyframes chatComplete {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}