/* ═══════════════════════════════════════════════════════════════
 * mobile.css — 모바일/태블릿 반응형 레이어 (theme-light-admin.css 위에 얹음)
 *
 * 데스크톱(>1024px)에는 아무 영향이 없다 — 전 규칙이 미디어쿼리 안.
 *
 * 브레이크포인트 2단:
 *   ≤1024px  네비 접힘 → 햄버거 + 우측 슬라이드 드로어 (#nav-drawer)
 *   ≤820px   콘텐츠 모바일 밀도 — 하단 탭바(.m-tabbar), 바텀시트 모달,
 *            터치 타겟 확대, iOS 포커스 줌 방지(입력 16px)
 *
 * 마크업 계약 (_Layout.cshtml):
 *   .m-nav-toggle   햄버거 버튼 — 데스크톱에서는 숨김
 *   #nav-drawer     기존 ul.nav-tabs-custom + .nav-right 를 감싸는 컨테이너
 *                   데스크톱: display:contents → 레이아웃 기존과 100% 동일
 *                   모바일: 우측 고정 오프캔버스 패널
 *   .m-drawer-head  드로어 상단 타이틀/닫기 — 데스크톱에서는 숨김
 *   .m-nav-backdrop 드로어 뒤 딤 배경
 *   body.nav-open   드로어 열림 상태 (JS 토글)
 *   .m-tabbar       관리자/협력사 하단 퀵 탭바 — body.has-tabbar 와 세트
 * ═══════════════════════════════════════════════════════════════ */

/* 데스크톱 기본: 드로어 래퍼는 레이아웃에 존재하지 않는 것처럼 */
#nav-drawer { display: contents; }
.m-nav-toggle, .m-drawer-head, .m-nav-backdrop, .m-tabbar { display: none; }

/* ─────────────────────────────────────────────
 * 1. 네비 접힘 — 햄버거 + 오프캔버스 드로어 (≤1024px)
 * ──────────────────────────────────────────── */
@media (max-width: 1024px) {

    .top-nav { padding: 0 14px; }
    .nav-logo { margin-right: 0; }

    /* 햄버거 버튼 — 3선 → X 모핑 */
    .m-nav-toggle {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        width: 44px;
        height: 44px;
        margin-left: auto;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .m-nav-toggle:active { background: var(--bg-hover); }
    .m-nav-toggle .bar {
        width: 20px;
        height: 2px;
        border-radius: 2px;
        background: var(--text-primary);
        transition: transform 0.25s cubic-bezier(.32,.72,.28,1), opacity 0.2s;
    }
    body.nav-open .m-nav-toggle .bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    body.nav-open .m-nav-toggle .bar:nth-child(2) { opacity: 0; }
    body.nav-open .m-nav-toggle .bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

    /* 드로어 열림 시 top-nav(sticky, z:100)가 만든 스태킹 컨텍스트를 백드롭(z:210) 위로 올림
       — 드로어는 top-nav 자식이라 자체 z-index(220)가 컨텍스트 밖 백드롭과 비교되지 않기 때문 */
    body.nav-open .top-nav { z-index: 230; }

    /* 드로어 본체 — 우측에서 슬라이드 인 */
    #nav-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(320px, 86vw);
        background: var(--bg-secondary);
        border-left: 1px solid var(--border-color);
        box-shadow: var(--shadow-lg);
        z-index: 220;
        transform: translateX(105%);
        visibility: hidden;
        transition: transform 0.3s cubic-bezier(.32,.72,.28,1), visibility 0.3s;
        overscroll-behavior: contain;
        padding-bottom: env(safe-area-inset-bottom);
    }
    body.nav-open #nav-drawer {
        transform: translateX(0);
        visibility: visible;
    }

    .m-drawer-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex: 0 0 auto;
        padding: 16px 18px 14px;
        border-bottom: 1px solid var(--border-color);
    }
    .m-drawer-head .m-drawer-title {
        font-size: 1.02rem;
        font-weight: 700;
        color: var(--text-primary);
    }
    .m-drawer-head .m-drawer-role {
        display: inline-block;
        margin-left: 8px;
        padding: 2px 9px;
        border-radius: 999px;
        background: var(--tint-blue);
        color: var(--accent-blue);
        font-size: 0.7rem;
        font-weight: 700;
        vertical-align: 2px;
    }
    .m-drawer-close {
        background: none;
        border: none;
        color: var(--text-secondary);
        font-size: 1.5rem;
        line-height: 1;
        padding: 6px 10px;
        border-radius: 8px;
        cursor: pointer;
    }
    .m-drawer-close:active { background: var(--bg-hover); }

    /* 기존 탭 목록 → 세로 메뉴 */
    .nav-tabs-custom {
        flex: 1 1 auto;
        flex-direction: column;
        height: auto;
        overflow-y: auto;
        padding: 10px 10px 16px;
        gap: 2px;
    }
    .nav-tabs-custom li a {
        height: auto;
        min-height: 48px;
        padding: 0 14px;
        border-bottom: none;
        border-radius: 8px;
        font-size: 0.95rem;
        /* 열림 시 스태거 페이드 */
        opacity: 0;
        transform: translateX(14px);
        transition: opacity 0.25s ease, transform 0.28s cubic-bezier(.32,.72,.28,1), background 0.15s;
    }
    body.nav-open .nav-tabs-custom li a { opacity: 1; transform: translateX(0); }
    body.nav-open .nav-tabs-custom li:nth-child(1) a { transition-delay: 0.04s; }
    body.nav-open .nav-tabs-custom li:nth-child(2) a { transition-delay: 0.07s; }
    body.nav-open .nav-tabs-custom li:nth-child(3) a { transition-delay: 0.10s; }
    body.nav-open .nav-tabs-custom li:nth-child(4) a { transition-delay: 0.13s; }
    body.nav-open .nav-tabs-custom li:nth-child(5) a { transition-delay: 0.16s; }
    body.nav-open .nav-tabs-custom li:nth-child(6) a { transition-delay: 0.19s; }
    body.nav-open .nav-tabs-custom li:nth-child(7) a { transition-delay: 0.22s; }
    body.nav-open .nav-tabs-custom li:nth-child(8) a { transition-delay: 0.25s; }
    body.nav-open .nav-tabs-custom li:nth-child(9) a { transition-delay: 0.28s; }
    body.nav-open .nav-tabs-custom li:nth-child(n+10) a { transition-delay: 0.31s; }

    .nav-tabs-custom li a.active {
        background: var(--tint-blue);
        color: var(--accent-blue);
        font-weight: 700;
        box-shadow: inset 3px 0 0 var(--accent-blue);
    }
    .nav-tabs-custom li a.nav-guide-link.active {
        background: var(--tint-orange);
        box-shadow: inset 3px 0 0 var(--accent-orange);
    }
    /* 대기 알림 점은 우측 끝으로 */
    .nav-tabs-custom li a .nav-request-dot { margin-left: auto; }

    /* 유저 정보/로그아웃 → 드로어 하단 푸터 (세로 스택: 이름/크레딧 위, 로그아웃 전체 폭 버튼 아래) */
    .nav-right {
        margin-left: 0;
        flex: 0 0 auto;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border-color);
        background: var(--bg-tertiary);
    }
    .nav-right > span { text-align: center; }
    .nav-right .language-picker { width: 100%; }
    .nav-right .language-picker-toggle {
        width: 100%;
        min-height: 46px;
        justify-content: flex-start;
        padding: 10px 13px;
    }
    .nav-right .language-picker-chevron { margin-left: auto; }
    .nav-right .language-picker-menu {
        position: static;
        width: 100%;
        margin-top: 8px;
        box-shadow: var(--shadow-sm);
    }
    .nav-right .btn-outline-secondary {
        margin-left: 0;
        width: 100%;
        justify-content: center;
        min-height: 44px;
        padding: 11px 16px;
        font-size: 0.9rem;
        font-weight: 600;
        border-radius: 8px;
        color: var(--accent-red);
        border-color: rgba(201, 48, 44, 0.35);
        background: var(--tint-red);
        text-align: center;
    }
    .nav-right .btn-outline-secondary:active { background: var(--tint-red-hover); }
    .nav-right .btn-login {
        width: 100%;
        text-align: center;
        padding: 12px 16px;
        border-radius: 8px;
    }

    /* 딤 배경 */
    .m-nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.45);
        backdrop-filter: blur(2px);
        z-index: 210;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }
    body.nav-open .m-nav-backdrop { opacity: 1; pointer-events: auto; }

    body.nav-open { overflow: hidden; }
}

/* ─────────────────────────────────────────────
 * 2. 모바일 밀도 (≤820px)
 * ──────────────────────────────────────────── */
@media (max-width: 820px) {

    .main-content { padding: 14px 12px 20px; }

    /* ── 액션 바: 검색/필터가 폭을 채우도록 ── */
    .action-bar { gap: 8px; }
    .action-right {
        margin-left: 0;
        width: 100%;
        flex-wrap: wrap;
    }
    .action-right .search-input { flex: 1 1 160px; width: auto; min-width: 0; }

    /* ── iOS 포커스 줌 방지: 입력류는 16px 고정 + 터치 높이 확보 ── */
    .search-input,
    .table-input,
    select.table-input,
    .page-size-select {
        font-size: 16px;
        min-height: 42px;
    }
    td .table-input.compact-input {
        font-size: 16px;
        min-height: 38px;
        height: auto;
    }
    input[type="checkbox"], input[type="radio"] { min-width: 18px; min-height: 18px; }

    /* ── 버튼 터치 타겟 ── */
    .btn-add, .btn-batch, .btn-login, .btn-device, .btn-join,
    .toolbar-action-btn, .btn-edit, .btn-delete {
        min-height: 40px;
        padding-top: 8px;
        padding-bottom: 8px;
    }
    .btn-mini, .btn-mini-danger,
    .row-actions .btn-row-action,
    .row-action-buttons .btn-row-mini {
        min-height: 34px;
        padding-top: 6px;
        padding-bottom: 6px;
    }
    .btn-outline-secondary { min-height: 34px; display: inline-flex; align-items: center; }
    .pagination-btns button, .btn-page { min-height: 38px; min-width: 38px; }
    .chip { padding: 8px 14px; }
    .period-radio label { min-height: 38px; }

    /* ── 통계 바: 2열 그리드 ── */
    .stats-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px 14px;
        padding: 14px;
    }
    .stat-divider { display: none; }
    .stat-cell { min-width: 0; }

    /* ── 테이블: 밀도 축소 + 관성 가로 스크롤 ── */
    .table-wrapper, .modal-table-scroll {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }
    .data-table thead th { padding: 10px 10px; font-size: 0.74rem; }
    .data-table tbody td { padding: 12px 10px; font-size: 0.85rem; }

    .table-footer { flex-wrap: wrap; gap: 10px; }

    /* ── 모달 → 바텀시트 ── */
    .modal-overlay { align-items: flex-end; }
    .modal-overlay .modal-box,
    .modal-overlay .modal-box.modal-lg,
    .modal-overlay .modal-box.modal-md {
        width: 100%;
        max-width: 100% !important;
        max-height: calc(100dvh - 36px);
        border-radius: 16px 16px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    .modal-overlay.show .modal-box { animation: m-sheet-up 0.3s cubic-bezier(.32,.72,.28,1); }
    @keyframes m-sheet-up {
        from { transform: translateY(48px); opacity: 0.4; }
        to   { transform: translateY(0);    opacity: 1; }
    }
    /* 시트 상단 그랩 핸들 느낌 */
    .modal-header { position: relative; padding: 18px 16px 14px; }
    .modal-header::before {
        content: '';
        position: absolute;
        top: 7px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        border-radius: 999px;
        background: var(--border-color);
    }
    .modal-body { padding: 18px 14px; }
    .modal-close { font-size: 1.6rem; padding: 6px 12px; }
    .modal-table-scroll { max-height: min(52dvh, 480px); }

    /* ── 공지 팝업 등 인라인 max-width 지정 모달도 폭 통일 ── */
    .modal-overlay .modal-box[style*="max-width"] { max-width: 100% !important; }

    /* ── 하단 퀵 탭바 (관리자/협력사) ── */
    body.has-tabbar { padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
    body.has-tabbar .site-footer { margin-bottom: 0; }

    .m-tabbar {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 150;
        background: rgba(255, 255, 255, 0.92);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--border-color);
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.06);
    }
    .m-tab {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-height: 60px;
        padding: 8px 2px 6px;
        color: var(--text-muted);
        font-size: 0.68rem;
        font-weight: 600;
        letter-spacing: -0.01em;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.15s;
    }
    .m-tab:active { color: var(--text-secondary); }
    .m-tab-ico {
        position: relative;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 26px;
        border-radius: 999px;
        transition: background 0.2s;
    }
    .m-tab-ico svg { width: 21px; height: 21px; }
    .m-tab.active { color: var(--accent-blue); }
    .m-tab.active .m-tab-ico { background: var(--tint-blue); }
    /* 알림 점 — 상단 폴링(nav-dot-*)이 그대로 토글 */
    .m-tab-ico .nav-request-dot {
        position: absolute;
        top: -1px;
        right: 4px;
        margin-left: 0;
        width: 8px;
        height: 8px;
        flex-basis: 8px;
        box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
    }
}

/* ─────────────────────────────────────────────
 * 3. 초소형 화면 미세 조정 (≤400px)
 * ──────────────────────────────────────────── */
@media (max-width: 400px) {
    .main-content { padding: 12px 10px 18px; }
    .stats-bar { grid-template-columns: 1fr 1fr; padding: 12px; }
    .m-tab { font-size: 0.64rem; }
}
