/* 짠툴 — 모바일 보정 (2026-09-28)
 *
 * 왜 따로 만드나
 *   index.html 안에 도구 46종의 스타일이 흩어져 있고, 그중 상당수가
 *   ★인라인 style="" 로 박혀 있다. 인라인은 보통 CSS 로 못 덮으므로
 *   여기서 미디어쿼리 + !important 로 한 번에 바로잡는다.
 *   본문 CSS 는 건드리지 않는다 — PC 화면을 망가뜨리지 않기 위해서다.
 *
 * 무엇을 고치나 (375×812 실측으로 찾은 것)
 *   ① 2열 배치가 안 접혀 오른쪽이 통째로 잘림   (가장 큰 문제)
 *   ② 단추가 24~30px 라 누르기 어려움           (최소 44px)
 *   ③ 글자가 11.5~12.8px 라 읽기 어려움          (최소 13px)
 *   ④ 단추 안에서 글자가 위아래로 치우침         (flex 가운데)
 *   ⑤ 표가 화면을 밀어냄                        (가로 스크롤 상자로)
 *
 * ★이 파일은 맨 마지막에 실어야 한다 (나중에 온 규칙이 이긴다).
 */

@media (max-width: 768px) {

    /* ─────────────────────────────────────────────────────────
       ① 2열 → 1열
       사이드 패널(1fr 340px 같은 것)이 안 접히면 화면이 835px 이 되고
       그 안의 모든 글자·입력칸이 오른쪽으로 잘려 나간다. 보이지도 않는다.
       인라인으로 박힌 것이 많아 [style*=...] 로 집어낸다.
       ───────────────────────────────────────────────────────── */
    /* ★값을 하나씩 나열하면 반드시 놓친다 (1fr 1.2fr 을 놓쳐 견적서가 깨져 있었다).
         「fr 이 두 번 이상 나오거나, px 이 섞인 여러 칸」을 통째로 잡는다.
         칸이 하나뿐인 것(1fr)은 [style*="fr "] 에 안 걸리므로 안전하다. */
    .tool-view-container [style*="grid-template-columns"],
    .passport-workspace,
    .calc-split-container,
    .cleaner-split-grid,
    .color-contrast-grid,
    .diff-editor-split,
    .diff-side-container,
    .encoder-split,
    .md-split-wrap,
    .table-converter-split {
        grid-template-columns: 1fr !important;
    }

    /* 단, auto-fit/auto-fill 은 이미 스스로 접힌다 — 그대로 둔다.
       (숫자 칩 같은 것까지 1열로 만들면 화면이 길어지기만 한다) */
    .tool-view-container [style*="auto-fit"],
    .tool-view-container [style*="auto-fill"] {
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)) !important;
    }

    /* 고정 폭을 쓴 상자도 화면에 맞춘다 */
    .calc-input-card,
    .calc-result-card {
        max-width: 100% !important;
        min-width: 0 !important;
    }

    /* ★그리드·flex 칸이 안쪽 내용 때문에 안 줄어드는 것을 막는다
       -------------------------------------------------------------
       flex·grid 자식의 min-width 기본값은 auto 다. 그래서 안쪽에 긴 줄이
       하나라도 있으면 칸이 그만큼 벌어지고, max-width:100% 를 줘도
       「이미 벌어진 부모의 100%」라 아무 소용이 없다.
       그래서 도구 화면 안의 ★모든 요소★ 에 min-width:0 을 건다.
       (마크다운 편집칸이 337px 칸 안에서 517px 로 벌어져 있었다) */
    .tool-view-container * {
        min-width: 0;
    }

    /* ─────────────────────────────────────────────────────────
       ② 누를 수 있는 크기 — 최소 44px
       46개 화면에서 24~30px 짜리 단추가 238개 나왔다.
       ───────────────────────────────────────────────────────── */
    .chip-btn,
    .seg-btn,
    .btn-primary,
    .btn-secondary,
    .tool-view-container button {
        min-height: 44px;
    }

    /* 아이콘만 있는 동그란 단추는 가로도 함께 */
    .wt-help-btn {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.05rem !important;
    }

    /* ★가로도 44px — 세로만 늘리면 36~43px 짜리 좁은 단추가 남는다
       (아이콘만 든 단추가 그랬다: 36×44, 38×44, 43×44) */
    .tool-view-container button { min-width: 44px; }

    /* 안에 글자가 있는 단추는 세로 가운데로 — 위아래 치우침을 없앤다
       ★:not([style*="display: none"]) 이 꼭 필요하다.
         display:inline-flex !important 는 인라인 style="display:none" 보다 강해서,
         JS 로 숨긴 단추가 그대로 보인다.
         (처리가 끝났는데 「전부 처리하기」가 계속 남아 있었다) */
    .chip-btn:not([style*="display: none"]):not([style*="display:none"]),
    .seg-btn:not([style*="display: none"]):not([style*="display:none"]),
    .btn-primary:not([style*="display: none"]):not([style*="display:none"]),
    .btn-secondary:not([style*="display: none"]):not([style*="display:none"]) {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: .35rem;
    }

    /* ③ 글자 크기 — 11.5~12.8px 짜리를 13px 위로 */
    .chip-btn { font-size: .88rem !important; padding: 10px 14px !important; }
    .seg-btn { font-size: .88rem !important; padding: 11px 10px !important; }
    .btn-secondary { font-size: .85rem !important; padding: 10px 12px !important; }

    /* ★단추 글자가 「웹 / 사 / 이 / 트」처럼 세로로 꺾이는 것
       -------------------------------------------------------------
       .seg-btn 은 flex:1 이라 개수가 많으면 한 칸이 60px 까지 좁아진다.
       min-width:0 을 걸어 둔 탓에 더 좁아져 글자가 한 자씩 끊긴다.
       → 줄바꿈을 허용하고, 한 칸이 일정 폭 아래로는 안 내려가게 한다.
       (QR 유형 5개·JSON 보기 3개가 이 모양이었다) */
    .segmented-row,
    .chip-group,
    .btn-group { flex-wrap: wrap !important; }

    .seg-btn {
        flex: 1 1 auto !important;
        min-width: 96px !important;
        white-space: normal;
        word-break: keep-all;          /* 한글은 낱말 단위로만 끊는다 */
    }
    .chip-btn {
        white-space: normal;
        word-break: keep-all;
    }
    /* 단추 안 글자가 한 자씩 끊기지 않게 — 전체에 적용 */
    .tool-view-container button { word-break: keep-all; }

    /* 인라인으로 작게 박힌 글씨들
       ★[style*="font-size: 0."] 하나로 0.x rem 을 전부 잡는다.
         값을 하나씩 나열하면 빠뜨린 것이 반드시 생긴다(0.68·0.74rem 이 그랬다). */
    .tool-view-container [style*="font-size: 0."],
    .tool-view-container [style*="font-size:0."] {
        font-size: .82rem !important;
    }
    /* ★도구 화면 밖(머리말·사이드바)의 작은 글씨
       .tool-view-container 범위 밖이라 위 규칙에 안 걸린다.
       「무료」 뱃지 10.9px · 분류별 개수 11.2px 이었다. */
    .logo-badge { font-size: .76rem !important; padding: 3px 8px !important; }
    .nav-category-count { font-size: .76rem !important; padding: 2px 7px !important; }

    /* 클래스로 작게 지정된 보조 글씨들 (실측으로 찾은 것) */
    .tool-view-container .stat-label,
    .tool-view-container .stat-sub,
    .tool-view-container .hint,
    .tool-view-container .note,
    .tool-view-container .badge,
    .tool-view-container .sep,
    .palette-chip-item,
    .palette-chip-item div,
    .counter-card-sub,
    .deduct-rate,
    .wt-ad-label { font-size: .8rem !important; }

    /* 라벨·도움말 글씨 */
    .calc-input-group label,
    .tool-view-container label {
        font-size: .9rem;
    }

    /* 입력칸도 손가락으로 누를 수 있게 —
       ★16px 미만이면 iOS 사파리가 화면을 확대해 버린다 */
    .tool-view-container input[type="text"],
    .tool-view-container input[type="number"],
    .tool-view-container input[type="password"],
    .tool-view-container input[type="date"],
    .tool-view-container select,
    .tool-view-container textarea {
        font-size: 16px !important;
        min-height: 44px;
    }
    .tool-view-container textarea { min-height: 120px; }

    /* ★입력칸이 제 칸보다 넓어져 옆 칸을 덮는 것
       select 는 안에 든 옵션 글이 길면 부모보다 커진다(162px 칸에 228px).
       그러면 옆 칸 입력칸과 포개져 어느 쪽을 누르는지 알 수 없게 된다. */
    .tool-view-container input,
    .tool-view-container select,
    .tool-view-container textarea,
    .tool-view-container .form-control {
        max-width: 100% !important;
        width: 100%;
        box-sizing: border-box;
    }
    /* 체크상자·라디오는 100% 로 늘리면 안 된다 */
    .tool-view-container input[type="checkbox"],
    .tool-view-container input[type="radio"],
    .tool-view-container input[type="color"] {
        width: auto;
        min-height: 0;
    }

    /* ★flex 줄 안의 입력칸은 남은 자리만 쓰게 한다
       (width:100% 를 주면 옆의 라벨·단위 글자를 밀어낸다)
       단, .calc-currency-input 은 건드리지 않는다 —
       거기서는 ₩ 기호가 position:absolute 로 입력칸 「위에」 겹쳐 있고
       입력칸이 padding-left 로 자리를 비워 두는 올바른 설계다.
       (이걸 넘침으로 잘못 보고 flex 로 바꿨다가 되돌렸다) */
    .tool-view-container [style*="display: flex"] > input:not(.calc-currency-input),
    .tool-view-container [style*="display:flex"] > input:not(.calc-currency-input) {
        width: auto !important;
        flex: 1 1 0 !important;
        min-width: 0 !important;
    }

    /* ─────────────────────────────────────────────────────────
       ④ 표 — 화면을 밀어내지 않게 가로 스크롤 상자에 담는다
       ───────────────────────────────────────────────────────── */
    .tool-view-container table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    .tool-view-container table th,
    .tool-view-container table td { font-size: .85rem; }

    /* ⑤ 긴 글자(주소·코드)가 칸을 벌리지 않게 */
    .tool-view-container pre,
    .tool-view-container code {
        max-width: 100%;
        overflow-x: auto;
        word-break: break-all;
        overflow-wrap: anywhere;
    }

    /* ⑥ 제목 — 24px 를 넘지 않게 (긴 제목이 세 줄이 되면 첫 화면이 제목만 남는다) */
    .page-title { font-size: 1.35rem !important; line-height: 1.35 !important; }
    .page-subtitle { font-size: .92rem !important; }

    /* ★? 단추가 제목 아래로 떨어져 혼자 놓이는 것
       제목이 길면 inline-flex 단추가 줄바꿈되어 「? 만 있는 줄」이 생긴다.
       제목 마지막 글자에 붙여 함께 흐르게 한다. */
    .page-title { display: block; }
    .page-title .wt-help-btn {
        display: inline-flex !important;
        vertical-align: middle;
        margin-left: 8px;
        /* 앞 글자와 떨어지지 않게 */
        position: relative;
        top: -2px;
    }

    /* ⑦ 캔버스·미리보기가 화면을 넘지 않게 */
    .tool-view-container canvas,
    .tool-view-container img,
    .tool-view-container svg {
        max-width: 100%;
        height: auto;
    }

    /* ─────────────────────────────────────────────────────────
       ⑧ textarea 가 화면을 밀어내는 것
       ★ .text-editor-area 는 클래스만 붙어 있고 CSS 정의가 없다.
         그래서 textarea 가 기본 cols 값(보통 20자)만큼의 폭을 그대로 갖는데,
         한글·고정폭 글꼴이라 517px 이 되어 화면 밖으로 나간다.
       ───────────────────────────────────────────────────────── */
    .tool-view-container textarea,
    .text-editor-area,
    .md-preview-pane,
    .md-toolbar {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box;
    }
    /* 도구모음 단추가 오른쪽에서 잘리지 않게 줄바꿈 */
    .md-toolbar { flex-wrap: wrap !important; }
    .md-tool-btn { min-height: 44px; min-width: 44px; }

    /* 미리보기 안의 긴 글도 접히게 */
    .md-preview-pane * { max-width: 100%; overflow-wrap: anywhere; }

    /* ─────────────────────────────────────────────────────────
       ⑨ 표를 감싸는 상자
       table 에만 overflow 를 주면 thead·tbody 가 여전히 밀어낸다.
       표를 감싼 부모에 스크롤을 주고, 표 자체는 원래대로 둔다.
       ───────────────────────────────────────────────────────── */
    .tool-view-container .table-wrap,
    .tool-view-container [class*="table-container"],
    .tool-view-container [class*="schedule"] {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ─────────────────────────────────────────────────────────
       ⑩ ★「제목 ─ 단추」를 한 줄에 놓은 flex 가 겹치는 것
       -------------------------------------------------------------
       display:flex + justify-content:space-between 으로 제목과 단추를
       양 끝에 놓은 자리가 53곳 있는데, flex-wrap 이 없다.
       375px 에서는 둘 다 들어갈 자리가 없어 제목이 두 줄이 되고
       그 두 번째 줄이 ★단추 뒤로 파고들어 글자를 읽을 수 없게 된다.
       (색상 추출 화면에서 「하기」가 단추 밑에 깔려 있었다)
       ───────────────────────────────────────────────────────── */
    .tool-view-container [style*="justify-content: space-between"],
    .tool-view-container [style*="justify-content:space-between"],
    /* ★클래스로 지정된 것도 같은 문제를 낸다 — 인라인만 잡으면 놓친다
         (.case-card 에서 「복사하기」 단추가 코드 글자 위에 겹쳐 있었다) */
    .case-card,
    .hash-card-row,
    .counter-card,
    .stat-row {
        flex-wrap: wrap !important;
        gap: 8px;
    }

    /* ─────────────────────────────────────────────────────────
       ⑪ 서식 문서(견적서·영수증)의 「라벨: [입력칸]」 줄
       라벨에 width:85px 가 인라인으로 박혀 있어 좁은 칸에서
       라벨과 입력칸이 서로를 밀어낸다. 라벨을 위로 올린다.
       ★85px 만 잡았다가 70px 짜리를 놓쳤다. 서식 문서의 라벨을 통째로 잡는다.
       ───────────────────────────────────────────────────────── */
    .tool-view-container [style*="display: flex"] > span[style*="width:"],
    .tool-view-container [style*="display:flex"] > span[style*="width:"] {
        flex-shrink: 0;
    }
    .doc-input { min-width: 0 !important; flex: 1 1 0 !important; width: auto !important; }

    /* ⑫ 가로 스크롤 자체를 막는다 — 어딘가 새는 것이 있어도 화면은 안 흔들리게 */
    html, body { overflow-x: hidden; }
}

/* 아주 좁은 화면 (360px 안팎) */
@media (max-width: 400px) {
    .page-title { font-size: 1.25rem !important; }
    .chip-btn { padding: 10px 12px !important; }
    /* 단추가 한 줄에 억지로 들어가려다 글자가 잘리는 것을 막는다 */
    .chip-group { gap: 8px; }
}
