/**
 * 모바일 반응형 테이블 -> 카드 박스 자동 변환 스타일
 *
 * @author Claude Assistant
 * @since 2025.01.15
 * @version 2.0
 * @description 기존 테이블을 자동으로 카드 형식으로 변환 (HTML 수정 불필요)
 */

/* 모바일 반응형 테이블 -> 카드 자동 변환 */
@media (max-width: 768px) {
    /* 테이블을 블록 레이아웃으로 변환 */
    .table-responsive {
        border: none;
        overflow: visible !important;
        width: 100% !important;
    }

    .table-responsive .table {
        width: 100% !important;
    }

    /* 모달 내부 가로 스크롤 방지 */
    .modal .modal-body {
        overflow-x: hidden !important;
    }

    /* thead 숨김 */
    .table thead {
        display: none !important;
    }

    /* tbody를 flexbox 컨테이너로 */
    .table tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        width: 100% !important;
    }

    /* 각 tr을 카드로 변환 */
    .table tbody tr {
        display: block !important;
        width: 100% !important;
        background: #fff !important;
        border: 1px solid #dee2e6 !important;
        border-radius: 8px !important;
        padding: 8px !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
        margin-bottom: 0 !important;
    }

    /* 각 td를 행으로 표시 */
    .table tbody tr td {
        display: flex !important;
        align-items: center !important;
        padding: 8px 0 !important;
        border: none !important;
        text-align: right !important;
    }

    /* td::before로 라벨 표시 (data-label 속성 사용) */
    .table tbody tr td::before {
        content: attr(data-label) !important;
        font-weight: 600 !important;
        color: #6c757d !important;
        font-size: 15px !important;
        text-align: left !important;
        padding-right: 16px !important;
        min-width: 100px !important;
        flex-shrink: 0 !important;
    }

    /* 첫 번째 td (보통 제목이나 번호) 강조 */
    .table tbody tr td:first-child {
        font-weight: 600 !important;
        font-size: 16px !important;
        padding-bottom: 12px !important;
        margin-bottom: 8px !important;
        border-bottom: 1px solid #eee !important;
    }

    /* 모바일 리스트 컨테이너 표시 (선택적 사용) */
    .mobile-list-container {
        display: block !important;
    }
    
    /* 데스크톱 전용 요소 숨김 */
    .desktop-only {
        display: none !important;
    }
    
    /* 모바일 헤더 스타일 */
    .card-header .d-flex {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .card-header .card-title {
        flex: 1;
        min-width: 120px;
        font-size: 18px;
        margin-bottom: 0;
    }
    
    .card-header .d-flex > div:last-child {
        flex-shrink: 0;
    }
    
    .card-header .d-flex .gap-2 {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        flex-wrap: nowrap;
        gap: 8px !important;
    }
    
    .card-header .form-label {
        display: none !important;
    }
    
    .card-header .form-select,
    .card-header select.form-select,
    select#pageSize {
        width: 80px !important; /* 고정 너비로 변경 */
        min-width: 80px !important;
        max-width: 80px !important;
        font-size: 13px !important;
        padding: 6px 30px 6px 10px !important; /* 오른쪽 padding 더 넉넉하게 */
        flex-shrink: 0 !important;
        background-position: right 8px center !important; /* 화살표 위치 조정 */
        background-size: 13px 13px !important; /* 화살표 크기 */
        line-height: 1.2 !important;
        text-align: left !important;
        overflow: hidden !important;
        text-overflow: clip !important;
    }

    .card-header .btn {
        font-size: 15px;
        min-height: 44px;
        min-width: 44px;
        padding: 0.625rem 1rem;
        flex-shrink: 0;
        white-space: nowrap;
    }
    
    /* 모바일 리스트 아이템 스타일 */
    .mobile-list-item {
        background: #fff;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 16px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        cursor: pointer;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
        position: relative;
    }

    /* 클릭 가능한 아이템에 호버 효과 */
    .mobile-list-item[data-href]:hover,
    .mobile-list-item.clickable:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }

    /* 클릭 가능한 아이템의 터치 피드백 */
    .mobile-list-item[data-href]:active,
    .mobile-list-item.clickable:active {
        transform: translateY(0);
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .mobile-list-item .item-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
        padding-bottom: 8px;
        border-bottom: 1px solid #eee;
    }
    
    .mobile-list-item .item-title {
        font-weight: 600;
        font-size: 16px;
        color: #2c3e50;
        margin: 0;
        flex: 1;
        margin-right: 8px;

        /* 텍스트 말줄임 처리 */
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0; /* flex 아이템에서 텍스트 말줄임을 위해 필요 */
    }

    /* 제목 링크를 전체 영역으로 확장 */
    .mobile-list-item .item-title a::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1;
    }
    
    .mobile-list-item .item-number {
        background: #f8f9fa;
        color: #6c757d;
        padding: 4px 8px;
        border-radius: 12px;
        font-size: 15px;
        font-weight: 500;
        flex-shrink: 0;
    }
    
    .mobile-list-item .item-details {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .mobile-list-item .detail-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 4px 0;
    }
    
    .mobile-list-item .detail-label {
        font-weight: 500;
        color: #6c757d;
        font-size: 15px;
        min-width: 80px;
        flex-shrink: 0;
    }

    .mobile-list-item .detail-value {
        text-align: right;
        font-size: 15px;
        color: #2c3e50;
        flex: 1;
        word-break: break-word;
    }
    
    /* 상태 배지 스타일 */
    .mobile-list-item .badge {
        font-size: 15px;
        padding: 4px 8px;
    }

    /* 액션 버튼 영역 */
    .mobile-list-item .item-actions {
        display: flex;
        gap: 8px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid #eee;
        position: relative;
        z-index: 2; /* 버튼이 링크 위에 표시되도록 */
    }

    .mobile-list-item .item-actions .btn {
        flex: 1;
        font-size: 15px;
        min-height: 44px;
        min-width: 44px;
        padding: 0.625rem 1rem;
        position: relative;
        z-index: 2;
    }

    /* 배지와 기타 인터랙티브 요소 */
    .mobile-list-item .badge,
    .mobile-list-item button,
    .mobile-list-item a:not(.item-title a),
    .mobile-list-item select,
    .mobile-list-item input {
        position: relative;
        z-index: 2;
    }
    
    /* 링크 스타일 */
    .mobile-list-item .item-title a {
        text-decoration: none;
        color: inherit;
    }
    
    .mobile-list-item .item-title a:hover {
        color: #0d6efd;
    }
    
    /* 빈 상태 */
    .mobile-list-container .empty-state {
        text-align: center;
        padding: 40px 20px;
        color: #6c757d;
    }
    
    .mobile-list-container .empty-state i {
        font-size: 48px;
        margin-bottom: 16px;
        opacity: 0.3;
    }
}

/* 390px 이하: 그림자 제거, 간격 축소 */
@media (max-width: 430px) {
    .table tbody tr {
        box-shadow: none !important;
    }

    .table tbody {
        gap: 8px !important;
    }

    .mobile-list-item {
        box-shadow: none !important;
        margin-bottom: 8px;
    }
}

/* 작은 모바일 화면 (480px 이하) */
@media (max-width: 480px) {
    .card-header .card-title {
        font-size: 16px;
    }
    
    .card-header .btn {
        font-size: 15px;
        min-height: 44px;
        min-width: 44px;
        padding: 0.5rem 0.75rem;
    }

    .card-header .form-select,
    .card-header select.form-select,
    select#pageSize {
        width: 75px !important; /* 고정 너비로 변경 */
        font-size: 12px !important;
        padding: 4px 28px 4px 8px !important; /* 오른쪽 padding 더 넉넉하게 */
        min-width: 75px !important;
        max-width: 75px !important;
        background-position: right 7px center !important; /* 화살표 위치 조정 */
        background-size: 12px 12px !important; /* 화살표 크기 조정 */
        line-height: 1.2 !important;
        text-align: left !important;
        overflow: hidden !important;
        text-overflow: clip !important;
    }
    
    .card-header .d-flex .gap-2 {
        gap: 6px !important;
    }
    
    .mobile-list-item {
        padding: 12px;
        margin-bottom: 10px;
    }
    
    .mobile-list-item .item-title {
        font-size: 15px;
        /* 작은 화면에서도 텍스트 말줄임 유지 */
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
    }
    
    .mobile-list-item .detail-label {
        font-size: 15px;
        min-width: 70px;
    }

    .mobile-list-item .detail-value {
        font-size: 15px;
    }

    .mobile-list-item .item-actions .btn {
        font-size: 15px;
        min-height: 44px;
        min-width: 44px;
        padding: 0.5rem 0.75rem;
    }
}

/* 데스크톱에서는 모바일 요소 숨김 */
@media (min-width: 769px) {
    .mobile-list-container {
        display: none !important;
    }
    
    .mobile-only {
        display: none !important;
    }
}