/* 모바일 최적화 스타일 */

/* 터치 인터페이스 최적화 */
@media (hover: none) and (pointer: coarse) {
    .emotion-dot {
        width: 90px;
        height: 90px;
        font-size: 14px;
    }
    
    .emotion-point {
        width: 24px;
        height: 24px;
    }
    
    /* 터치하기 좋은 버튼 크기 */
    button, .nav-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* 입력 필드 크기 증가 */
    input, select, textarea {
        min-height: 44px;
        font-size: 16px; /* iOS 줌 방지 */
    }
    
    /* 슬라이더 터치 영역 증가 */
    input[type="range"] {
        height: 8px;
    }
    
    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    input[type="range"]::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }
}

/* 작은 화면 최적화 */
@media (max-width: 640px) {
    /* 네비게이션 반응형 */
    nav .flex {
        flex-wrap: wrap;
    }
    
    nav .flex > div:last-child {
        flex-basis: 100%;
        justify-content: space-around;
        margin-top: 12px;
        padding-bottom: 12px;
    }
    
    .nav-btn {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    .nav-btn i {
        display: none; /* 작은 화면에서 아이콘 숨김 */
    }
    
    /* 페이지 제목 */
    h2 {
        font-size: 24px !important;
        line-height: 1.2;
    }
    
    /* 통계 카드 그리드 */
    .grid.md\\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    
    .grid.md\\:grid-cols-4 > div {
        padding: 16px;
    }
    
    .grid.md\\:grid-cols-4 .text-2xl {
        font-size: 20px;
    }
    
    /* 차트 컨테이너 */
    .grid.lg\\:grid-cols-2 {
        grid-template-columns: 1fr;
        gap: 24px;
    }
    
    /* 감정 맵 크기 조정 */
    .emotion-map {
        width: 90vw;
        height: 90vw;
        max-width: 350px;
        max-height: 350px;
    }
    
    /* 감정 그리드 */
    .emotion-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        padding: 0 16px;
    }
    
    .emotion-dot {
        width: 70px;
        height: 70px;
        font-size: 11px;
    }
    
    /* 폼 요소들 */
    .grid.lg\\:grid-cols-2,
    .grid.lg\\:grid-cols-3 {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    /* 버튼 조정 */
    .flex.justify-end button {
        width: 100%;
        justify-content: center;
    }
    
    /* 일지 카드 */
    .bg-white.rounded-xl.shadow-sm {
        margin: 0 -16px;
        border-radius: 0;
        box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
        border-bottom: 1px solid #e5e7eb;
    }
    
    .bg-white.rounded-xl.shadow-sm:last-child {
        border-bottom: none;
    }
    
    /* 검색 및 필터 */
    .grid.md\\:grid-cols-4 input,
    .grid.md\\:grid-cols-4 select {
        margin-bottom: 8px;
    }
}

/* 매우 작은 화면 (320px 이하) */
@media (max-width: 320px) {
    /* 컨테이너 패딩 줄이기 */
    .max-w-7xl {
        padding-left: 12px;
        padding-right: 12px;
    }
    
    /* 감정 그리드 2열로 변경 */
    .emotion-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* 통계 카드 1열로 변경 */
    .grid.md\\:grid-cols-4 {
        grid-template-columns: 1fr;
    }
    
    /* 감정 맵 더 작게 */
    .emotion-map {
        width: 85vw;
        height: 85vw;
    }
}

/* 가로 모드 최적화 */
@media (orientation: landscape) and (max-height: 500px) {
    /* 네비게이션 높이 줄이기 */
    nav .h-16 {
        height: 48px;
    }
    
    /* 페이지 패딩 줄이기 */
    .py-8 {
        padding-top: 16px;
        padding-bottom: 16px;
    }
    
    /* 감정 맵 크기 조정 */
    .emotion-map {
        width: 40vw;
        height: 40vw;
        max-width: 250px;
        max-height: 250px;
    }
    
    /* 폼 레이아웃 조정 */
    .space-y-8 > * + * {
        margin-top: 16px;
    }
}

/* 다크 모드 지원 */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #0f172a;
        color: #e2e8f0;
    }
    
    .bg-white {
        background-color: #1e293b;
        color: #e2e8f0;
    }
    
    .bg-gray-50 {
        background-color: #0f172a;
    }
    
    .text-gray-900 {
        color: #e2e8f0;
    }
    
    .text-gray-600 {
        color: #94a3b8;
    }
    
    .text-gray-500 {
        color: #64748b;
    }
    
    .border-gray-300 {
        border-color: #475569;
    }
    
    input, select, textarea {
        background-color: #334155;
        border-color: #475569;
        color: #e2e8f0;
    }
    
    input:focus, select:focus, textarea:focus {
        background-color: #334155;
        border-color: #3b82f6;
    }
    
    .shadow-lg {
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.15);
    }
    
    .shadow-sm {
        box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    }
}

/* 고대비 모드 지원 */
@media (prefers-contrast: high) {
    .emotion-dot {
        border: 2px solid #000000;
    }
    
    .emotion-dot.selected {
        border-width: 4px;
    }
    
    button {
        border: 2px solid #000000;
    }
    
    input, select, textarea {
        border: 2px solid #000000;
    }
}

/* 애니메이션 감소 모드 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .emotion-dot {
        transition: none;
    }
    
    .emotion-point {
        transition: none;
    }
}

/* 인쇄용 스타일 */
@media print {
    nav {
        display: none;
    }
    
    .bg-white {
        background-color: white !important;
        color: black !important;
    }
    
    .text-gray-600,
    .text-gray-500 {
        color: #666666 !important;
    }
    
    .shadow-lg,
    .shadow-sm {
        box-shadow: none !important;
    }
    
    .emotion-dot {
        border: 1px solid black;
    }
    
    /* 차트는 인쇄에서 숨김 */
    canvas {
        display: none;
    }
}

/* PWA 지원을 위한 viewport 메타 스타일 */
@supports (display: standalone) {
    /* PWA 모드에서 상단 여백 추가 */
    body {
        padding-top: env(safe-area-inset-top);
    }
    
    nav {
        padding-top: env(safe-area-inset-top);
    }
}

/* 스크롤바 스타일링 */
::-webkit-scrollbar {
    width: 8px;
}

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

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

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

/* Firefox 스크롤바 */
* {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

/* 접근성 개선 */
.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,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.emotion-dot:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* 로딩 상태 스타일 */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

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