/* ============================================================
   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: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Malgun Gothic', 'Apple SD Gothic Neo', 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;
}

/* ------------------------------------------------------------
   셸 레이아웃
   ------------------------------------------------------------ */
.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));
}

.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-nav-group { margin-bottom: 14px; }
.tm-nav-group[hidden] { display: none; }

.tm-nav-group-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 700;
    color: #8a919c;
    color: var(--tm-faint);
    letter-spacing: 0.04em;
}

.tm-nav-group-count {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

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

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

.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: block;
    padding: 6px 4px 6px 8px;
    font-size: 13px;
    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;
    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; }

/* ------------------------------------------------------------
   오프캔버스 (≤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);
    }

    .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; }
