/* ============================================================
   toolmaster 공통 셸 (좌측 고정 사이드바 + 컨텐츠 컬럼)
   - layouts/default.php, layouts/user.php 에서 로드
   - oklch 미지원 브라우저를 위해 hex 를 먼저, oklch 를 뒤에 선언
   ============================================================ */

:root {
    --tm-header-h: 60px;
    --tm-sidebar-w: 264px;

    --tm-accent: #3b6fe0;
    --tm-accent: oklch(0.55 0.14 255);
    --tm-accent-strong: #2c56b8;
    --tm-accent-strong: oklch(0.45 0.15 255);
    --tm-accent-soft: #eef3fd;
    --tm-accent-soft: oklch(0.96 0.02 255);

    --tm-page-bg: #f6f7f9;
    --tm-surface: #ffffff;
    --tm-border: #e5e8ed;
    --tm-border-soft: #eef0f4;
    --tm-border-dash: #d8dce4;

    --tm-ink: #1b1e24;
    --tm-ink-2: #3d434d;
    --tm-muted: #6b7280;
    --tm-faint: #8a919c;
    --tm-faint-2: #9aa1ac;

    --tm-star-on: #e8a33d;
    --tm-star-on: oklch(0.68 0.16 75);
    --tm-star-off: #c9ced7;

    --tm-new-fg: #2f9e5f;
    --tm-new-fg: oklch(0.55 0.14 145);
    --tm-new-bg: #e9f7ee;
    --tm-new-bg: oklch(0.95 0.04 145);

    --tm-hot-fg: #c06a2b;
    --tm-hot-fg: oklch(0.58 0.13 60);
    --tm-hot-bg: #fdf0e3;
    --tm-hot-bg: oklch(0.95 0.04 60);

    --tm-font: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Segoe UI', system-ui, sans-serif;
}

body {
    background: #f6f7f9;
    background: var(--tm-page-bg);
    font-family: var(--tm-font);
    color: #1b1e24;
    color: var(--tm-ink);
    -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------
   건너뛰기 링크
   포커스를 받기 «전»에도 문서에 존재해야 한다 — display:none 이나
   visibility:hidden 은 포커스를 못 받아 링크가 없는 것과 같다.
   ------------------------------------------------------------ */
/* 🔴 `left: -9999px` 로 치우지 «않는다» — 그 방식은 문서를 가로로 늘려
   브라우저에 따라 가로 스크롤을 만든다. 1px 로 접고 clip 으로 가린다. */
.tm-skip-link {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1100;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
    background: #1b1e24;
    background: var(--tm-ink, #1b1e24);
    color: #fff;
    border-radius: 0 0 .4rem 0;
    text-decoration: none;
    font-weight: 600;
}

.tm-skip-link:focus {
    width: auto;
    height: auto;
    margin: 0;
    padding: .6rem 1rem;
    overflow: visible;
    clip: auto;
    clip-path: none;
    outline: 2px solid #fff;
    outline-offset: -4px;
}

/* ------------------------------------------------------------
   셸 레이아웃
   ------------------------------------------------------------ */
.tm-shell {
    display: grid;
    grid-template-columns: var(--tm-sidebar-w) minmax(0, 1fr);
    align-items: start;
    min-height: calc(100vh - var(--tm-header-h));
}

/* 🔴 **칸을 «못박는다» — HTML 순서와 화면 위치를 떼어 놓기 위해서다** (2026-09-14).
   사이드바는 HTML 에서 본문 «뒤»에 온다(레이아웃 주석 참고). 종전에는 앞에 있어서
   `<h1>` 이 문서의 111KB 지점에 나왔고, 76개 도구 링크 73KB 를 모든 페이지가 먼저 실었다.

   그리드는 자동 배치가 «소스 순서»를 따르므로, 순서를 바꾸면 사이드바가 오른쪽으로 간다.
   그래서 둘 다 칸과 행을 명시한다 — 이러면 소스 순서가 어떻든 보이는 자리는 고정이다.
   ⚠️ 이 두 규칙과 레이아웃의 순서는 **한 쌍이다.** 한쪽만 지우면 화면이 뒤집힌다. */
.tm-shell > .tm-sidebar   { grid-column: 1; grid-row: 1; }
.tm-shell > .tm-shell-main { grid-column: 2; grid-row: 1; }

.tm-shell-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--tm-header-h));
}

/* main.css 의 main{margin:0 auto} 가 flex 컨테이너 안에서 shrink-to-fit 을 유발하므로
   컬럼 폭을 그대로 쓰도록 width 를 고정합니다. */
.tm-shell-main > main {
    flex: 1 0 auto;
    width: 100%;
}

.tm-shell-main > * {
    width: 100%;
}

/* ------------------------------------------------------------
   사이드바
   ------------------------------------------------------------ */
.tm-sidebar {
    position: sticky;
    top: var(--tm-header-h);
    align-self: start;
    height: calc(100vh - var(--tm-header-h));
    display: flex;
    flex-direction: column;
    background: #fff;
    background: var(--tm-surface);
    border-right: 1px solid #e5e8ed;
    border-right: 1px solid var(--tm-border);
    z-index: 900;
}

.tm-sidebar-head {
    padding: 14px 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-bottom: 1px solid #eef0f4;
    border-bottom: 1px solid var(--tm-border-soft);
    flex: none;
}

.tm-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tm-brand-link {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    min-width: 0;
}

.tm-brand-link:hover { text-decoration: none; }

.tm-brand-mark {
    width: 26px;
    height: 26px;
    flex: none;
    border-radius: 7px;
    background: #3b6fe0;
    background: var(--tm-accent);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 800;
}

.tm-brand-name {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #1b1e24;
    color: var(--tm-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tm-brand-count {
    margin-left: auto;
    font-size: 11px;
    color: #8a919c;
    color: var(--tm-faint);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.tm-sidebar-close {
    display: none;
    margin-left: 6px;
    border: 0;
    background: transparent;
    color: #8a919c;
    color: var(--tm-faint);
    font-size: 16px;
    line-height: 1;
    padding: 4px;
    cursor: pointer;
}

.tm-search { position: relative; }

.tm-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: #9aa1ac;
    color: var(--tm-faint-2);
    pointer-events: none;
}

.tm-search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 12px 9px 30px;
    font-size: 13px;
    font-family: inherit;
    border: 1px solid #dfe3ea;
    border-radius: 9px;
    background: #fafbfc;
    color: #1b1e24;
    color: var(--tm-ink);
    outline: none;
    transition: border-color .15s ease, background .15s ease;
}

.tm-search-input::-webkit-search-cancel-button { cursor: pointer; }

.tm-search-input:focus {
    border-color: #3b6fe0;
    border-color: var(--tm-accent);
    background: #fff;
}

.tm-sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px 8px 24px;
}

/* ------------------------------------------------------------
   빠른 접근 — 즐겨찾기 · 최근 사용 · 신규
   사이드바 위쪽은 "지금 쓸 것", 아래쪽 전체 도구는 "찾을 것"이다.
   ------------------------------------------------------------ */
.tm-quick { margin-bottom: 12px; }
.tm-quick[hidden] { display: none; }

/* 검색 중에는 감춘다 — 같은 도구가 위아래로 두 번 나오면 결과를 잘못 읽는다.
   [hidden] 과 따로 두는 이유: 검색이 끝나면 원래의 "비었으면 숨김"으로 돌아가야 한다. */
.tm-quick.is-search-hidden { display: none; }

.tm-quick-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 2px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    /* 종전 헤더는 항목(#3d434d)보다 흐린 #8a919c 라 계층 신호가 본문보다 약했다. */
    color: #4b515b;
    color: var(--tm-ink-2);
}

.tm-quick-count {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: #8a919c;
    color: var(--tm-faint);
}

.tm-quick-icon { font-size: 11px; line-height: 1; }
.tm-quick-icon-fav { color: #e8a33d; color: var(--tm-star-on); }
.tm-quick-icon-new { color: #2f9e5f; color: var(--tm-new-fg); }

/* ------------------------------------------------------------
   전체 도구 — 카테고리 8개, 기본은 접힘
   ------------------------------------------------------------ */
.tm-nav-all {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid #eef0f4;
    border-top-color: var(--tm-border-soft);
}

.tm-nav-all-head {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 2px 8px 6px;
}

.tm-nav-all-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #4b515b;
    color: var(--tm-ink-2);
}

.tm-nav-all-link {
    margin-left: auto;
    font-size: 11px;
    color: #6b7280;
    color: var(--tm-muted);
    text-decoration: none;
}

.tm-nav-all-link:hover {
    color: #2c56b8;
    color: var(--tm-accent-strong);
    text-decoration: underline;
}

.tm-nav-group { margin-bottom: 2px; }
.tm-nav-group[hidden] { display: none; }

.tm-nav-group-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
    color: #3d434d;
    color: var(--tm-ink-2);
    cursor: pointer;
    list-style: none;   /* 기본 삼각형 제거 — 오른쪽 chevron 으로 대체한다 */
    user-select: none;
}

/* 사파리는 list-style 로 지워지지 않는다 */
.tm-nav-group-head::-webkit-details-marker { display: none; }

.tm-nav-group-head:hover { background: #f2f4f8; }

.tm-nav-group-head:focus-visible {
    outline: 2px solid #3b6fe0;
    outline: 2px solid var(--tm-accent);
    outline-offset: -2px;
}

.tm-nav-group-name { flex: 1 1 auto; min-width: 0; }

.tm-nav-group-count {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 11px;
    color: #8a919c;
    color: var(--tm-faint);
}

.tm-nav-chevron {
    flex: none;
    font-size: 9px;
    color: #9aa1ac;
    color: var(--tm-faint-2);
    transition: transform .15s ease;
}

.tm-nav-group[open] > .tm-nav-group-head > .tm-nav-chevron { transform: rotate(180deg); }

/* 펼친 그룹은 왼쪽 안내선으로 소속을 보인다 — 헤더와 항목이 한 줄로 섞이던 문제. */
.tm-nav-group-body {
    margin: 2px 0 8px 15px;
    padding-left: 5px;
    border-left: 1px solid #eef0f4;
    border-left-color: var(--tm-border-soft);
}

@media (prefers-reduced-motion: reduce) {
    .tm-nav-chevron { transition: none; }
}

.tm-dot {
    width: 6px;
    height: 6px;
    flex: none;
    border-radius: 2px;
    display: inline-block;
}

.tm-dot-neutral { background: #b6bcc6; }

/*
 * 항목 아이콘 — 모양은 도구마다, 색은 카테고리마다.
 * 폭을 **고정**한다: 아이콘마다 글리프 너비가 달라(fa-i-cursor 는 좁고 fa-table-cells 는 넓다)
 * 그대로 두면 도구 이름의 시작점이 줄마다 어긋나 목록이 들쭉날쭉해진다.
 */
.tm-nav-icon {
    flex: none;
    width: 15px;
    font-size: 12px;
    text-align: center;
    /* 아이콘이 이름보다 튀면 안 된다 — 앵커지 주인공이 아니다. */
    opacity: .85;
}

.tm-nav-item:hover .tm-nav-icon,
.tm-nav-item.is-active .tm-nav-icon { opacity: 1; }

/* 아이콘 자리를 못 채운 도구(카탈로그에 'icon' 없음)를 위한 예비 표시. */
.tm-item-dot {
    width: 5px;
    height: 5px;
    flex: none;
    border-radius: 2px;
    display: inline-block;
}

.tm-nav-item {
    display: flex;
    align-items: center;
    gap: 4px;
    border-radius: 7px;
    transition: background .12s ease;
}

.tm-nav-item[hidden] { display: none; }

.tm-nav-item:hover { background: #f2f4f8; }

.tm-nav-item.is-active {
    background: #eef3fd;
    background: var(--tm-accent-soft);
}

.tm-nav-item.is-active .tm-nav-link-text {
    color: #2c56b8;
    color: var(--tm-accent-strong);
    font-weight: 700;
}

.tm-nav-link {
    flex: 1 1 auto;
    min-width: 0;
    /* 색 점과 이름을 한 줄에 놓는다. 점이 없는 항목도 같은 규칙으로 흐른다. */
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 4px 6px 8px;
    /* 13px 은 utilzip(14px)보다 작아 같은 폭에서 더 빽빽해 보였다. */
    font-size: 14px;
    color: #3d434d;
    color: var(--tm-ink-2);
    text-decoration: none;
}

.tm-nav-link:hover {
    color: #1b1e24;
    color: var(--tm-ink);
    text-decoration: none;
}

.tm-nav-link-text {
    display: block;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tm-star {
    flex: none;
    border: 0;
    background: transparent;
    padding: 2px 8px 2px 2px;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    color: #c9ced7;
    color: var(--tm-star-off);
}

.tm-star.is-on {
    color: #e8a33d;
    color: var(--tm-star-on);
}

.tm-nav-empty {
    padding: 24px 12px;
    font-size: 12px;
    color: #8a919c;
    color: var(--tm-faint);
    line-height: 1.7;
}

.tm-nav-extra { display: none; }

.tm-nav-extra-head {
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #4b515b;
    color: var(--tm-ink-2);
}

/* ------------------------------------------------------------
   오프캔버스 (≤991px)
   ------------------------------------------------------------ */
.tm-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 20, 30, 0.45);
    z-index: 1040;
    display: none;
}

@media (max-width: 991.98px) {
    .tm-shell {
        grid-template-columns: minmax(0, 1fr);
    }

    /* 한 칸짜리 그리드에서는 위의 칸 못박기를 푼다. 사이드바는 아래에서 position:fixed
       가 되어 그리드 흐름을 벗어나지만, 명시된 grid-column:1 을 남겨 두면 «없는 2번 칸»을
       기대하는 상태가 남는다. 푸는 쪽이 읽기에도 분명하다. */
    .tm-shell > .tm-sidebar,
    .tm-shell > .tm-shell-main { grid-column: auto; grid-row: auto; }

    /* 🔴 모바일에서는 건너뛰기 링크를 «내지 않는다».
       여기서 사이드바는 화면 밖(translateX(-100%))이라 포커스를 옮겨 봐야
       보이지 않는 것에 포커스가 간다 — 링크가 오히려 사람을 잃어버리게 만든다.
       그리고 이 폭에서는 헤더 «첫 번째» 요소가 햄버거 버튼이라,
       키보드로 도구 목록에 닿는 길이 이미 한 번에 있다. */
    .tm-skip-link { display: none; }

    .tm-nav-extra { display: block; }

    .tm-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100%;
        width: min(84vw, var(--tm-sidebar-w));
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 0 0 30px rgba(15, 20, 30, 0.12);
        z-index: 1050;
    }

    .tm-sidebar.is-open { transform: translateX(0); }

    .tm-sidebar-close { display: block; }

    .tm-sidebar-backdrop.is-open { display: block; }

    body.tm-sidebar-open { overflow: hidden; }
}

/* 데스크톱에서 오프캔버스 잔여 상태 제거 */
@media (min-width: 992px) {
    .tm-sidebar { transform: none !important; }
    .tm-sidebar-backdrop { display: none !important; }
}

/* ------------------------------------------------------------
   컨텐츠 컬럼 보정
   main.css 의 main{max-width:1400px} 은 컬럼 안에서 그대로 동작
   ------------------------------------------------------------ */
.tm-shell-main .site-footer { margin-top: 3rem; }
.tm-shell-main .site-footer.home-footer { margin-top: 0; }

/* ------------------------------------------------------------
   도구별 CSS(tools-common.css 등)가 a 태그 색을 덮어쓰는 것을 차단
   ------------------------------------------------------------ */
.tm-sidebar a.tm-brand-link,
.tm-sidebar a.tm-nav-link {
    text-decoration: none;
}

.tm-sidebar a.tm-nav-link {
    color: #3d434d;
    color: var(--tm-ink-2);
}

.tm-sidebar a.tm-nav-link:hover,
.tm-sidebar a.tm-nav-link:focus {
    color: #1b1e24;
    color: var(--tm-ink);
    text-decoration: none;
}

.tm-sidebar .tm-nav-item.is-active a.tm-nav-link {
    color: #2c56b8;
    color: var(--tm-accent-strong);
}

.tm-sidebar .tm-brand-name { color: #1b1e24; color: var(--tm-ink); }
.tm-sidebar .tm-search-input { color: #1b1e24; color: var(--tm-ink); background: #fafbfc; }
