/*
    ============================================================
    Document   : no-more-tables
    ============================================================
    Created on : 28/02/2012, 11:01:54 AM
    Updated on : 2025-01-16 (Grid 기반으로 개선)
    Author     : Simon Elvery (original), Updated by Dev Team
    
    Description:
        반응형 테이블 CSS - 데스크톱은 테이블, 모바일은 Grid 카드 레이아웃
        Tailwind나 복잡한 CSS 없이 손쉽게 반응형 테이블 구현
        
    ============================================================
    📋 기본 사용법
    ============================================================
    
    1. HTML 구조
    
    <div class="no-more-tables">
        <table class="table">
            <thead>
                <tr>
                    <th>이름</th>
                    <th>전화번호</th>
                    <th>이메일</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td data-title="이름">홍길동</td>
                    <td data-title="전화번호">010-1234-5678</td>
                    <td data-title="이메일">hong@example.com</td>
                </tr>
            </tbody>
        </table>
    </div>
    
    2. 필수 속성
       - data-title="레이블명" : 모바일에서 각 항목 앞에 표시될 레이블
    
    ============================================================
    📱 클래스 목록
    ============================================================
    
    ─────────────────────────────────────────────────────────
    [래퍼 클래스]
    ─────────────────────────────────────────────────────────
    
    .no-more-tables
        - 테이블을 감싸는 div에 적용
        - 데스크톱: 일반 테이블
        - 모바일: Grid 카드 레이아웃
    
    ─────────────────────────────────────────────────────────
    [TD 클래스 - 레이아웃]
    ─────────────────────────────────────────────────────────
    
    .nmt-half
        - 모바일에서 2열 레이아웃으로 표시
        - 사용: 짧은 정보 2개를 나란히 배치
        - 예: <td class="nmt-half">직책</td>
              <td class="nmt-half">활동기간</td>
        - 결과: [직책: 구역장][활동기간: 25.01~12.31]
    
    ─────────────────────────────────────────────────────────
    [TD 클래스 - 스타일]
    ─────────────────────────────────────────────────────────
    
    .title-cell
        - 그룹 헤더/제목 셀로 표시
        - 데스크톱: 일반 표시
        - 모바일: 크고 굵은 글자 (18px, bold, #222)
                 하단 2px 구분선
                 data-title 레이블 숨김
        - 예: <td class="title-cell">2025</td>
        - 자동으로 전체 너비 차지 (grid-column: 1 / -1)
    
    .same-title-cell
        - 연속된 동일 제목 처리
        - 데스크톱: 투명 (color: transparent)
        - 모바일: 완전 숨김 (display: none)
        - 사용: JavaScript로 이전 값과 비교 후 자동 적용
        - 예: 같은 년도가 연속될 때
              <td class="title-cell">2025</td>
              <td class="same-title-cell">2025</td>  ← 숨김
    
    .nmt-last
        - 마지막 셀 표시 (하단 테두리 제거)
        - border-bottom: 0 적용
        - 예: <td class="nmt-last">마지막 항목</td>
    
    .nmt-hide
        - 특정 셀 숨김
        - display: none
        - 예: <td class="nmt-hide">숨길 내용</td>
    
    ─────────────────────────────────────────────────────────
    [TR 클래스]
    ─────────────────────────────────────────────────────────
    
    .nmt-has-chk
        - 체크박스가 있는 행
        - 모바일: 14% (체크박스) + 86% (내용) Grid
        - 예: <tr class="nmt-has-chk">
                  <td class="nmt-chk"><input type="checkbox"></td>
                  <td>내용</td>
              </tr>
    
    ─────────────────────────────────────────────────────────
    [TD 클래스 - 체크박스]
    ─────────────────────────────────────────────────────────
    
    .nmt-chk
        - 체크박스 전용 셀
        - nmt-has-chk와 함께 사용
        - 모바일: 왼쪽 14% 영역, 세로 전체 높이 차지
        - 자동 중앙 정렬 (flexbox)
        - 예: <td class="nmt-chk"><input type="checkbox"></td>
    
    ─────────────────────────────────────────────────────────
    [속성 - HTML Attributes]
    ─────────────────────────────────────────────────────────
    
    data-title="레이블명"
        - 필수 속성
        - 모바일에서 각 항목 위에 표시될 레이블
        - 예: <td data-title="이름">홍길동</td>
        - 모바일 표시: "이름: 홍길동"
        - title-cell에는 레이블 표시 안됨
    
    data-mobile-order="1~20"
        - 모바일 순서 변경 (선택 속성)
        - 1~20 사이 숫자로 지정
        - 속성 없으면 HTML 순서 그대로
        - 예: <td data-mobile-order="1">첫번째</td>
              <td data-mobile-order="3">세번째</td>
              <td data-mobile-order="2">두번째</td>
        - 모바일에서 1→2→3 순서로 재배치됨
    
    ============================================================
    💡 사용 예시
    ============================================================
    
    ─────────────────────────────────────────────────────────
    예시 1: 기본 테이블
    ─────────────────────────────────────────────────────────
    
    <div class="no-more-tables">
        <table class="table">
            <tbody>
                <tr>
                    <td data-title="이름">홍길동</td>
                    <td data-title="나이">30</td>
                </tr>
            </tbody>
        </table>
    </div>
    
    [데스크톱] 이름 | 나이
              홍길동 | 30
    
    [모바일] 이름: 홍길동
            나이: 30
    
    ─────────────────────────────────────────────────────────
    예시 2: 2열 레이아웃 (nmt-half)
    ─────────────────────────────────────────────────────────
    
    <tr>
        <td data-title="이름">홍길동</td>
        <td data-title="전화번호" class="nmt-half">010-1234-5678</td>
        <td data-title="이메일" class="nmt-half">hong@example.com</td>
    </tr>
    
    [데스크톱] 이름 | 전화번호 | 이메일
    
    [모바일] 이름: 홍길동
            [전화번호: 010-...][이메일: hong@...]
            ↑ 2열로 나란히 배치
    
    ─────────────────────────────────────────────────────────
    예시 3: 제목 셀 (title-cell)
    ─────────────────────────────────────────────────────────
    
    <tr>
        <td data-title="년도" class="title-cell">2025</td>
        <td data-title="부서">개발팀</td>
    </tr>
    
    [모바일] 2025           ← 크고 굵은 제목 (레이블 없음)
            ─────────────
            부서: 개발팀
    
    ─────────────────────────────────────────────────────────
    예시 4: 연속 제목 숨김 (same-title-cell)
    ─────────────────────────────────────────────────────────
    
    <tr>
        <td class="title-cell">2025</td>
        <td>개발팀</td>
    </tr>
    <tr>
        <td class="same-title-cell">2025</td>  ← 숨김 처리
        <td>디자인팀</td>
    </tr>
    
    [데스크톱] 2025 | 개발팀
                    | 디자인팀   ← 투명 (공간 유지)
    
    [모바일] 2025           ← 표시
            개발팀
            ─────
            디자인팀       ← 2025 숨김
    
    ─────────────────────────────────────────────────────────
    예시 5: 순서 변경 (data-mobile-order)
    ─────────────────────────────────────────────────────────
    
    <tr>
        <td data-mobile-order="1">이름</td>
        <td data-mobile-order="3">나이</td>
        <td data-mobile-order="2">전화번호</td>
    </tr>
    
    [데스크톱] 이름 | 나이 | 전화번호
    
    [모바일] 이름          order: 1
            전화번호       order: 2 (원래 3번)
            나이           order: 3 (원래 2번)
    
    ─────────────────────────────────────────────────────────
    예시 6: 체크박스 있는 테이블
    ─────────────────────────────────────────────────────────
    
    <tr class="nmt-has-chk">
        <td class="nmt-chk"><input type="checkbox"></td>
        <td data-title="이름">홍길동</td>
        <td data-title="나이" class="nmt-half">30</td>
        <td data-title="전화" class="nmt-half">010-1234</td>
    </tr>
    
    [모바일] ☐ 이름: 홍길동
            ☐ [나이: 30][전화: 010-1234]
            ↑ 체크박스가 세로로 모든 항목 옆에 표시
    
    ─────────────────────────────────────────────────────────
    예시 7: 복합 사용 (봉사이력 실제 예시)
    ─────────────────────────────────────────────────────────
    
    <tbody id="serve_history">
        <tr>
            <td data-mobile-order="1" class="title-cell">2025</td>
            <td data-mobile-order="2">교구 / 1교구</td>
            <td data-mobile-order="3" class="nmt-half">구역장</td>
            <td data-mobile-order="4" class="nmt-half">25.01~12.31</td>
        </tr>
        <tr>
            <td data-mobile-order="1" class="same-title-cell">2025</td>
            <td data-mobile-order="2">봉사부서 / 찬양대</td>
            <td data-mobile-order="3" class="nmt-half">소속</td>
            <td data-mobile-order="4" class="nmt-half">25.03~12.31</td>
        </tr>
    </tbody>
    
    [데스크톱]
    ┌──────┬──────────────┬────────┬──────────────┐
    │ 2025 │ 교구 / 1교구 │ 구역장 │ 25.01~12.31  │
    │      │ 봉사부서     │ 소속   │ 25.03~12.31  │ ← 투명
    └──────┴──────────────┴────────┴──────────────┘
    
    [모바일]
    ┌─────────────────────────┐
    │ 2025                    │ ← 크고 굵게
    ├─────────────────────────┤
    │ 부서/소속: 교구/1교구   │
    ├─────────────────────────┤
    │[직책: 구역장][기간: ...]│ ← 2열
    ├─────────────────────────┤
    │ 부서/소속: 봉사부서     │ ← 2025 숨김
    ├─────────────────────────┤
    │[직책: 소속][기간: ...]  │
    └─────────────────────────┘
    
    ============================================================
    🎨 클래스 레퍼런스
    ============================================================
    
    ┌─────────────────────┬──────────────────────────────────┐
    │ 클래스/속성         │ 설명                             │
    ├─────────────────────┼──────────────────────────────────┤
    │ .no-more-tables     │ [래퍼] 테이블 컨테이너           │
    ├─────────────────────┼──────────────────────────────────┤
    │ .nmt-half           │ [TD] 2열 레이아웃 (50% 너비)     │
    │                     │ 모바일에서 옆에 나란히 배치      │
    ├─────────────────────┼──────────────────────────────────┤
    │ .title-cell         │ [TD] 제목 셀                     │
    │                     │ 모바일: 크고 굵게, 구분선         │
    │                     │ 레이블 숨김, 전체 너비           │
    ├─────────────────────┼──────────────────────────────────┤
    │ .same-title-cell    │ [TD] 연속 제목 숨김              │
    │                     │ 데스크톱: 투명 (공간 유지)       │
    │                     │ 모바일: 완전 숨김                │
    ├─────────────────────┼──────────────────────────────────┤
    │ .nmt-last           │ [TD] 마지막 셀                   │
    │                     │ border-bottom 제거               │
    ├─────────────────────┼──────────────────────────────────┤
    │ .nmt-hide           │ [TD] 숨김                        │
    │                     │ display: none                    │
    ├─────────────────────┼──────────────────────────────────┤
    │ .nmt-has-chk        │ [TR] 체크박스 포함 행            │
    │                     │ 모바일: 14% + 86% Grid          │
    ├─────────────────────┼──────────────────────────────────┤
    │ .nmt-chk            │ [TD] 체크박스 셀                 │
    │                     │ 왼쪽 14% 영역, 세로 전체         │
    │                     │ nmt-has-chk와 함께 사용          │
    ├─────────────────────┼──────────────────────────────────┤
    │ data-title="..."    │ [속성] 모바일 레이블 (필수)      │
    │                     │ 각 항목 위에 표시                │
    ├─────────────────────┼──────────────────────────────────┤
    │ data-mobile-order   │ [속성] 모바일 순서 (1~20)        │
    │                     │ 속성 없으면 HTML 순서 유지       │
    └─────────────────────┴──────────────────────────────────┘
    
    ============================================================
    ⚙️ 기술 사양
    ============================================================
    
    - 브레이크포인트: 768px
    - Grid 지원: Chrome 57+, Safari 10.1+, Firefox 52+, Edge 16+
    - :has() 지원: Chrome 105+, Safari 15.4+, Firefox 121+
    - 최대 필드 수: 20개 (data-mobile-order)
    - 최대 열 수: 제한 없음 (nmt-half로 조절)
    
    ============================================================
*/

.no-more-tables td.same-title-cell {
    color: transparent;
}

@media only screen and (max-width: 768px) {

    /* 테이블을 블록으로 변환 */
    .no-more-tables table,
    .no-more-tables thead,
    .no-more-tables tbody {
        display: block;
    }

    /* TR을 Grid 컨테이너로 */
    .no-more-tables tr {
        display: grid;
        grid-template-columns: 1fr;
        border-top: 2px solid #888;
        border-left: 0;
        border-right: 0;
        position: relative;
    }
    
    .no-more-tables tr:first-child {
        border-top: 0;
    }
    
    .no-more-tables tr:nth-child(even) {
        background: #f2f2f2;
    }

    /* 봉사이력 - 짝수 행 배경 제거 */
    .serve-history-section tr:nth-child(even) {
        background: transparent;
    }

    /* 봉사이력 - 년도 셀만 배경 적용 */
    .serve-history-section td.title-cell:not(.same-title-cell) {
        background: #f2f2f2;
    }

    /* 테이블 헤더 숨김 (접근성 유지) */
    .no-more-tables thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    /* TD 기본 스타일 */
    .no-more-tables td {
        border: none;
        border-bottom: 1px solid #ccc;
        position: relative;
        padding-top: 0;
        white-space: normal;
        text-align: left;
        font-size: 15px;
        color: #333;
        min-height: 48px;
    }
    
    .no-more-tables td[data-title] {
        padding-top: 24px !important;
    }
    
    .no-more-tables td:last-child,
    .no-more-tables td.nmt-last {
        border-bottom: 0;
    }
    
    .no-more-tables td.nmt-hide {
        display: none;
    }

    /* nmt-half가 있으면 2열 Grid */
    .no-more-tables tr:has(.nmt-half) {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* 일반 TD는 전체 너비 차지 */
    .no-more-tables td:not(.nmt-half) {
        grid-column: 1 / -1;
    }

    /* 체크박스 있는 행 */
    .no-more-tables tr.nmt-has-chk {
        grid-template-columns: 14% 1fr;
        padding-left: 0;
    }
    
    .no-more-tables tr.nmt-has-chk td {
        grid-column: 2;
    }
    
    .no-more-tables tr.nmt-has-chk td.nmt-half {
        grid-column: auto;
    }

    .no-more-tables tr.nmt-has-chk td.nmt-chk {
        grid-column: 1;
        grid-row: 1 / -1;
        display: flex;
        align-items: center;
        justify-content: center;
        border-bottom: 0;
        text-align: center;
    }

    /* data-title 레이블 */
    .no-more-tables td:before {
        position: absolute;
        top: 4px;
        left: 8px;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: normal;
        font-size: 12px;
        color: #8697a9;
        content: attr(data-title);
    }
    
    /* 제목 셀 스타일 */
    .no-more-tables td.title-cell {
        grid-column: 1 / -1;
        font-size: 18px;
        font-weight: bold;
        color: #222222;
        padding-top: 35px !important;
        padding-bottom: 8px !important;
        border-bottom: 2px solid #222222 !important;
    }
    
    /* 제목 셀 스타일 */
    .no-more-tables td.same-title-cell {
        display: none;
    }
    
    .no-more-tables td.title-cell:before {
        content: none;
    }
    
    /* ================================================
       모바일 순서 변경 지원 (data-mobile-order)
       속성 없으면 HTML 순서 유지, 있으면 지정 순서
       최대 20개 필드 지원
       ================================================ */
    
    .no-more-tables td[data-mobile-order="1"] { order: 1; }
    .no-more-tables td[data-mobile-order="2"] { order: 2; }
    .no-more-tables td[data-mobile-order="3"] { order: 3; }
    .no-more-tables td[data-mobile-order="4"] { order: 4; }
    .no-more-tables td[data-mobile-order="5"] { order: 5; }
    .no-more-tables td[data-mobile-order="6"] { order: 6; }
    .no-more-tables td[data-mobile-order="7"] { order: 7; }
    .no-more-tables td[data-mobile-order="8"] { order: 8; }
    .no-more-tables td[data-mobile-order="9"] { order: 9; }
    .no-more-tables td[data-mobile-order="10"] { order: 10; }
    .no-more-tables td[data-mobile-order="11"] { order: 11; }
    .no-more-tables td[data-mobile-order="12"] { order: 12; }
    .no-more-tables td[data-mobile-order="13"] { order: 13; }
    .no-more-tables td[data-mobile-order="14"] { order: 14; }
    .no-more-tables td[data-mobile-order="15"] { order: 15; }
    .no-more-tables td[data-mobile-order="16"] { order: 16; }
    .no-more-tables td[data-mobile-order="17"] { order: 17; }
    .no-more-tables td[data-mobile-order="18"] { order: 18; }
    .no-more-tables td[data-mobile-order="19"] { order: 19; }
    .no-more-tables td[data-mobile-order="20"] { order: 20; }
    
    /* 순서 미지정 시 기본값 (HTML 순서) */
    .no-more-tables td:not([data-mobile-order]) {
        order: 0;
    }
}


@media (max-width: 768px) {

    table.grid-table  {
        display: block;
        border:0;
        width:100%;
    }

    table.grid-table tbody {
        display: block;
        overflow: auto;
        width:100%;
    }

    .grid-table thead td {
        display: none;
    }

    .grid-table tbody tr {
        width:100%;
        display: grid;
        grid-template-columns: repeat(2,minmax(100px, auto));
        /*grid-gap: 10px;*/
    }

    .grid-table tr { border-top:2px solid #888;border-left:0;border-right:0;position: relative;}
    .grid-table tr:last-child { border-bottom:1px solid #ddd;}
    .grid-table tr:after{content:"";display:block;clear:both;}
    .grid-table tr:nth-child(even) {background:#f2f2f2;}
    .grid-table td.nmt-hide{display:none;}

    .grid-table td[data-title]{
        padding-top:24px !important;
    }
    .grid-table td {
        /* Behave  like a "row" */
        border: none;
        border-bottom: 0 !important;
        border-top: 0 !important;
        border-right:0 !important;
        border-left:0 !important;
        position: relative;
        /*padding-left: 25% !important;*/
        padding-top:0;
        white-space: normal;
        text-align:left;
        clear:both;
        font-size:15px;
        color:#333;
        min-height:48px;
    }

    .grid-table td.nmt-half:after {
        content : ' ';
        display: inline-block;
    }

    .grid-table td:before {
        /* Now like a table header */
        position: absolute;
        /* Top/left values mimic padding */
        top: 4px;
        left: 8px;
        padding-right: 10px;
        white-space: nowrap;
        text-align:left;
        font-weight: normal;
        font-size:12px;
        /*color: #128ecc !important;*/
        color:#8697a9;
    }
    .grid-table td:before { content: attr(data-title); }

    .grid-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

}
