/**
 * 모바일 최적화 스타일시트
 * 터치 친화적 인터페이스 및 반응형 디자인
 */

/* ===================================
   모바일 기본 설정
   =================================== */
@media (max-width: 768px) {
    /* 터치 타겟 크기 최적화 (최소 44x44px) */
    .btn,
    button,
    .search-input,
    .filter-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        min-height: 44px;
        min-width: 44px;
        font-size: 16px; /* iOS 자동 줌 방지 */
    }
    
    /* 패딩 증가 */
    .btn,
    button {
        padding: 12px 24px;
    }
    
    /* 입력 필드 */
    input,
    select,
    textarea {
        padding: 12px 16px;
    }
}

/* ===================================
   스와이프 제스처 지원
   =================================== */
@media (max-width: 768px) {
    .analysis-results,
    .keyword-list,
    .chart-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        scrollbar-width: none; /* Firefox */
    }
    
    .analysis-results::-webkit-scrollbar,
    .keyword-list::-webkit-scrollbar {
        display: none; /* Chrome, Safari */
    }
    
    /* 스크롤 인디케이터 */
    .scroll-indicator {
        position: absolute;
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        gap: 6px;
        z-index: 10;
    }
    
    .scroll-indicator-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.5);
        transition: background 0.3s;
    }
    
    .scroll-indicator-dot.active {
        background: rgba(255, 255, 255, 1);
    }
}

/* ===================================
   모바일 하단 네비게이션
   =================================== */
@media (max-width: 768px) {
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-primary, #ffffff);
        border-top: 1px solid var(--border-color, #e0e0e0);
        padding: 8px 0;
        z-index: 1000;
        display: flex;
        justify-content: space-around;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 8px 12px;
        text-decoration: none;
        color: var(--text-secondary, #666);
        font-size: 12px;
        transition: color 0.3s;
        cursor: pointer;
    }
    
    .mobile-nav-item.active {
        color: var(--primary-color, #667eea);
    }
    
    .mobile-nav-item i,
    .mobile-nav-item svg {
        font-size: 24px;
        margin-bottom: 4px;
    }
    
    /* 하단 네비게이션이 있을 때 본문 패딩 */
    body.has-mobile-nav {
        padding-bottom: 70px;
    }
}

/* ===================================
   풀스크린 모달 (모바일)
   =================================== */
@media (max-width: 768px) {
    .mobile-modal {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--bg-primary, #ffffff);
        z-index: 9999;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
    }
    
    .mobile-modal.active {
        transform: translateY(0);
    }
    
    .mobile-modal-header {
        position: sticky;
        top: 0;
        background: var(--bg-primary, #ffffff);
        padding: 16px;
        border-bottom: 1px solid var(--border-color, #e0e0e0);
        display: flex;
        align-items: center;
        justify-content: space-between;
        z-index: 10;
    }
    
    .mobile-modal-title {
        font-size: 18px;
        font-weight: 600;
        color: var(--text-primary, #333);
    }
    
    .mobile-modal-close {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: none;
        background: transparent;
        color: var(--text-primary, #333);
        font-size: 24px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .mobile-modal-content {
        padding: 20px;
    }
}

/* ===================================
   모바일 테이블 최적화
   =================================== */
@media (max-width: 768px) {
    /* 테이블을 카드 형식으로 변환 */
    .responsive-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .responsive-table table {
        min-width: 600px;
    }
    
    /* 카드 스타일 테이블 */
    .table-card-view {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
    
    .table-card {
        background: var(--bg-primary, #ffffff);
        border-radius: 12px;
        padding: 16px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .table-card-row {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid var(--border-color, #e0e0e0);
    }
    
    .table-card-row:last-child {
        border-bottom: none;
    }
    
    .table-card-label {
        font-weight: 600;
        color: var(--text-secondary, #666);
        font-size: 14px;
    }
    
    .table-card-value {
        color: var(--text-primary, #333);
        font-size: 14px;
        text-align: right;
    }
}

/* ===================================
   모바일 헤더 최적화
   =================================== */
@media (max-width: 768px) {
    .mobile-header {
        position: sticky;
        top: 0;
        background: var(--bg-primary, #ffffff);
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-color, #e0e0e0);
        z-index: 100;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .mobile-menu-btn {
        width: 40px;
        height: 40px;
        border: none;
        background: transparent;
        color: var(--text-primary, #333);
        font-size: 24px;
        cursor: pointer;
    }
    
    .mobile-logo {
        font-size: 18px;
        font-weight: 700;
        color: var(--primary-color, #667eea);
    }
}

/* ===================================
   모바일 사이드 메뉴
   =================================== */
@media (max-width: 768px) {
    .mobile-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 80%;
        max-width: 300px;
        background: var(--bg-primary, #ffffff);
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 9998;
        overflow-y: auto;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }
    
    .mobile-sidebar.active {
        transform: translateX(0);
    }
    
    .mobile-sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0.3s;
        z-index: 9997;
    }
    
    .mobile-sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

/* ===================================
   모바일 검색 바
   =================================== */
@media (max-width: 768px) {
    .mobile-search-container {
        padding: 16px;
        background: var(--bg-primary, #ffffff);
    }
    
    .mobile-search-wrapper {
        position: relative;
        display: flex;
        gap: 8px;
    }
    
    .mobile-search-input {
        flex: 1;
        height: 44px;
        padding: 0 44px 0 16px;
        border: 2px solid var(--border-color, #e0e0e0);
        border-radius: 22px;
        font-size: 16px;
        background: var(--bg-secondary, #f5f5f5);
        transition: all 0.3s;
    }
    
    .mobile-search-input:focus {
        outline: none;
        border-color: var(--primary-color, #667eea);
        background: #ffffff;
    }
    
    .mobile-search-btn {
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        width: 36px;
        height: 36px;
        border: none;
        background: var(--primary-color, #667eea);
        color: white;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ===================================
   모바일 카드 레이아웃
   =================================== */
@media (max-width: 768px) {
    .mobile-card {
        background: var(--bg-primary, #ffffff);
        border-radius: 16px;
        padding: 20px;
        margin-bottom: 16px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    }
    
    .mobile-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 16px;
    }
    
    .mobile-card-title {
        font-size: 18px;
        font-weight: 600;
        color: var(--text-primary, #333);
    }
    
    .mobile-card-badge {
        padding: 4px 12px;
        border-radius: 12px;
        font-size: 12px;
        font-weight: 600;
    }
    
    .mobile-card-content {
        color: var(--text-secondary, #666);
        line-height: 1.6;
    }
}

/* ===================================
   모바일 액션 시트
   =================================== */
@media (max-width: 768px) {
    .mobile-action-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-primary, #ffffff);
        border-radius: 16px 16px 0 0;
        padding: 24px;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 9999;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }
    
    .mobile-action-sheet.active {
        transform: translateY(0);
    }
    
    .mobile-action-sheet-handle {
        width: 40px;
        height: 4px;
        background: var(--border-color, #e0e0e0);
        border-radius: 2px;
        margin: 0 auto 16px;
    }
    
    .mobile-action-item {
        padding: 16px;
        border-radius: 8px;
        text-align: center;
        cursor: pointer;
        transition: background 0.3s;
        border: none;
        background: transparent;
        width: 100%;
        font-size: 16px;
        color: var(--text-primary, #333);
    }
    
    .mobile-action-item:active {
        background: var(--bg-secondary, #f5f5f5);
    }
    
    .mobile-action-item.danger {
        color: #f44336;
    }
}

/* ===================================
   모바일 차트 최적화
   =================================== */
@media (max-width: 768px) {
    .mobile-chart-container {
        position: relative;
        width: 100%;
        height: 250px;
        margin: 16px 0;
    }
    
    .mobile-chart-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    canvas {
        max-width: 100%;
        height: auto !important;
    }
}

/* ===================================
   모바일 폰트 크기 조정
   =================================== */
@media (max-width: 768px) {
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    h4 { font-size: 16px; }
    p, body { font-size: 14px; }
    
    .text-sm { font-size: 12px; }
    .text-lg { font-size: 16px; }
    .text-xl { font-size: 18px; }
}

/* ===================================
   모바일 여백 조정
   =================================== */
@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }
    
    .section {
        padding: 24px 0;
    }
    
    .page-content {
        padding: 16px;
    }
}

/* ===================================
   모바일 버튼 그룹
   =================================== */
@media (max-width: 768px) {
    .mobile-btn-group {
        display: flex;
        flex-direction: column;
        gap: 12px;
        width: 100%;
    }
    
    .mobile-btn-group .btn {
        width: 100%;
        justify-content: center;
    }
    
    .mobile-btn-row {
        display: flex;
        gap: 12px;
    }
    
    .mobile-btn-row .btn {
        flex: 1;
    }
}

/* ===================================
   모바일 Pull to Refresh
   =================================== */
@media (max-width: 768px) {
    .pull-to-refresh {
        position: relative;
        overflow: hidden;
    }
    
    .pull-to-refresh-indicator {
        position: absolute;
        top: -50px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: top 0.3s;
    }
    
    .pull-to-refresh.pulling .pull-to-refresh-indicator {
        top: 10px;
    }
}

/* ===================================
   모바일 토스트 메시지
   =================================== */
@media (max-width: 768px) {
    .mobile-toast {
        position: fixed;
        bottom: 80px;
        left: 16px;
        right: 16px;
        background: rgba(0, 0, 0, 0.8);
        color: white;
        padding: 16px;
        border-radius: 12px;
        z-index: 10000;
        transform: translateY(100px);
        opacity: 0;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .mobile-toast.active {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ===================================
   가로 모드 최적화
   =================================== */
@media (max-width: 768px) and (orientation: landscape) {
    .mobile-header {
        padding: 8px 16px;
    }
    
    .mobile-modal-header {
        padding: 12px 16px;
    }
    
    .mobile-bottom-nav {
        padding: 4px 0;
    }
    
    .mobile-nav-item {
        padding: 4px 8px;
        font-size: 11px;
    }
    
    .mobile-nav-item i,
    .mobile-nav-item svg {
        font-size: 20px;
        margin-bottom: 2px;
    }
}

/* ===================================
   Safe Area 지원 (iOS)
   =================================== */
@media (max-width: 768px) {
    .mobile-header {
        padding-top: max(12px, env(safe-area-inset-top));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    
    .mobile-bottom-nav {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

