@extends('layouts.app')

@section('title', '리눅스 & 서버 명령어')

@push('styles')
<style>
    .academy-img-hover {
        transition: box-shadow 0.2s ease;
    }
    .academy-img-hover:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .help-balloon-trigger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: #eff6ff;
        color: #1d4ed8;
        font-size: 11px;
        font-weight: 700;
        cursor: pointer;
        border: 1.5px solid #93c5fd;
        vertical-align: middle;
        margin-left: 4px;
        transition: all 0.15s ease;
        position: relative;
        user-select: none;
    }
    .help-balloon-trigger:hover {
        background: #1d4ed8;
        color: white;
        border-color: #3b82f6;
    }
    .help-balloon {
        display: none;
        position: absolute;
        bottom: calc(100% + 10px);
        left: 50%;
        transform: translateX(-50%) scale(0.95);
        background: #1e293b;
        color: #f1f5f9;
        font-size: 12px;
        font-weight: 400;
        line-height: 1.6;
        padding: 10px 14px;
        border-radius: 10px;
        max-width: 300px;
        min-width: 200px;
        width: max-content;
        white-space: normal;
        word-break: keep-all;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
        z-index: 40;
        opacity: 0;
        transition: opacity 0.15s ease, transform 0.15s ease;
        pointer-events: none;
    }
    .help-balloon::after {
        content: '';
        position: absolute;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        border: 7px solid transparent;
        border-top-color: #1e293b;
    }
    .help-balloon-trigger.is-active .help-balloon {
        display: block;
        opacity: 1;
        transform: translateX(-50%) scale(1);
        pointer-events: auto;
    }

    .code-block {
        background: #1e1e2e;
        color: #a6e3a1;
        border-radius: 0.75rem;
        padding: 1rem 1.25rem;
        font-family: 'Courier New', Courier, monospace;
        font-size: 0.75rem;
        line-height: 1.7;
        overflow-x: auto;
        white-space: pre;
    }
    .code-block .code-comment { color: #6c7086; }
    .code-block .code-keyword { color: #cba6f7; }
    .code-block .code-string { color: #a6e3a1; }
    .code-block .code-flag { color: #89b4fa; }
    .code-block .code-path { color: #f9e2af; }
    .code-block .code-output { color: #9399b2; }
    .code-block .code-danger { color: #f38ba8; }
    .code-block .code-prompt { color: #89dceb; }

    .cmd-card {
        transition: all 0.15s ease;
    }
    .cmd-card:hover {
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    }

    .danger-badge {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 2px 8px;
        border-radius: 9999px;
        font-size: 10px;
        font-weight: 600;
    }
</style>
@endpush

@section('content')
<div class="max-w-6xl mx-auto">

    {{-- ============================================================ --}}
    {{-- 히어로 배너 --}}
    {{-- ============================================================ --}}
    <div class="rounded-2xl overflow-hidden mb-8 shadow-lg" style="background: linear-gradient(135deg, #1e1b4b 0%, #0f172a 100%);">
        <div class="flex items-center" style="flex-wrap: wrap;">
            <div style="flex: 1 1 300px; padding: 2rem 2.5rem;">
                <div class="flex items-center gap-2 text-sm mb-2" style="color: #93c5fd;">
                    <span>아카데미</span>
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" /></svg>
                    <span style="color: #bfdbfe;">리눅스 & 서버 명령어</span>
                </div>
                <h1 class="text-3xl font-bold mb-2" style="color: #ffffff;">리눅스 & 서버 명령어</h1>
                <p class="text-sm" style="color: #cbd5e1;">서버 운영에 필요한 기본 명령어부터 권한 관리까지 — 초보자를 위한 실전 가이드</p>
            </div>
            <div class="shrink-0" style="width: 240px; padding: 1.5rem;">
                <div class="text-center" style="font-size: 100px; line-height: 1;">
                    <span style="filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));">🐧</span>
                </div>
            </div>
        </div>
    </div>

    <div class="flex gap-8">
        {{-- ============================================================ --}}
        {{-- 좌측 고정 목차 (TOC) --}}
        {{-- ============================================================ --}}
        <nav class="hidden lg:block shrink-0" style="width: 220px;">
            <div class="sticky top-24">
                <div class="bg-blue-50 border border-blue-200 rounded-xl p-5">
                    <h2 class="font-semibold text-blue-800 mb-3 flex items-center gap-2 text-sm">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16" /></svg>
                        목차
                    </h2>
                    <div class="space-y-0.5 text-xs">
                        <a href="#terminal-basics" class="block text-blue-700 hover:text-blue-900 py-1 font-medium">1. 터미널 기초</a>
                        <a href="#what-is-terminal" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">터미널이란?</a>
                        <a href="#prompt-anatomy" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">프롬프트 읽기</a>

                        <a href="#file-navigation" class="block text-blue-700 hover:text-blue-900 py-1 font-medium mt-2">2. 파일 탐색</a>
                        <a href="#pwd-cd" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">pwd / cd</a>
                        <a href="#ls-ll" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">ls / ll</a>

                        <a href="#file-operations" class="block text-blue-700 hover:text-blue-900 py-1 font-medium mt-2">3. 파일 조작</a>
                        <a href="#cat-head-tail" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">cat / head / tail</a>
                        <a href="#cp-mv-rm" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">cp / mv / rm</a>
                        <a href="#mkdir-touch" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">mkdir / touch</a>

                        <a href="#permissions" class="block text-blue-700 hover:text-blue-900 py-1 font-medium mt-2">4. 권한 관리</a>
                        <a href="#chmod" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">chmod</a>
                        <a href="#chown" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">chown</a>

                        <a href="#search-filter" class="block text-blue-700 hover:text-blue-900 py-1 font-medium mt-2">5. 검색 & 필터</a>
                        <a href="#grep" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">grep</a>
                        <a href="#find" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">find</a>
                        <a href="#pipe" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">파이프 ( | )</a>

                        <a href="#system-monitoring" class="block text-blue-700 hover:text-blue-900 py-1 font-medium mt-2">6. 시스템 모니터링</a>
                        <a href="#top-htop" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">top / htop</a>
                        <a href="#df-free" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">df / free</a>

                        <a href="#process-service" class="block text-blue-700 hover:text-blue-900 py-1 font-medium mt-2">7. 프로세스 & 서비스</a>
                        <a href="#ps-kill" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">ps / kill</a>
                        <a href="#systemctl" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">systemctl</a>

                        <a href="#network" class="block text-blue-700 hover:text-blue-900 py-1 font-medium mt-2">8. 네트워크</a>
                        <a href="#curl-wget" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">curl / wget</a>
                        <a href="#ss-netstat" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">ss / netstat</a>

                        <a href="#text-editing" class="block text-blue-700 hover:text-blue-900 py-1 font-medium mt-2">9. 텍스트 편집</a>
                        <a href="#nano-vi" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">nano / vi</a>

                        <a href="#danger-zone" class="block text-blue-700 hover:text-blue-900 py-1 font-medium mt-2">10. 위험 명령어</a>
                        <a href="#dangerous-cmds" class="block text-blue-600 hover:text-blue-800 py-0.5 pl-3">절대 주의!</a>
                    </div>
                </div>
            </div>
        </nav>

        {{-- ============================================================ --}}
        {{-- 우측 콘텐츠 --}}
        {{-- ============================================================ --}}
        <div class="flex-1 min-w-0 space-y-10">

            {{-- 모바일 목차 --}}
            <div class="lg:hidden bg-blue-50 border border-blue-200 rounded-xl p-4 mb-6">
                <details>
                    <summary class="font-semibold text-blue-800 text-sm cursor-pointer flex items-center gap-2">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16" /></svg>
                        목차 보기
                    </summary>
                    <nav class="mt-3 space-y-1 text-sm">
                        <a href="#terminal-basics" class="block text-blue-700 hover:text-blue-900 py-1">1. 터미널 기초</a>
                        <a href="#file-navigation" class="block text-blue-700 hover:text-blue-900 py-1">2. 파일 탐색</a>
                        <a href="#file-operations" class="block text-blue-700 hover:text-blue-900 py-1">3. 파일 조작</a>
                        <a href="#permissions" class="block text-blue-700 hover:text-blue-900 py-1">4. 권한 관리</a>
                        <a href="#search-filter" class="block text-blue-700 hover:text-blue-900 py-1">5. 검색 & 필터</a>
                        <a href="#system-monitoring" class="block text-blue-700 hover:text-blue-900 py-1">6. 시스템 모니터링</a>
                        <a href="#process-service" class="block text-blue-700 hover:text-blue-900 py-1">7. 프로세스 & 서비스</a>
                        <a href="#network" class="block text-blue-700 hover:text-blue-900 py-1">8. 네트워크</a>
                        <a href="#text-editing" class="block text-blue-700 hover:text-blue-900 py-1">9. 텍스트 편집</a>
                        <a href="#danger-zone" class="block text-blue-700 hover:text-blue-900 py-1">10. 위험 명령어</a>
                    </nav>
                </details>
            </div>

            {{-- ============================================================ --}}
            {{-- 1. 터미널 기초 --}}
            {{-- ============================================================ --}}
            <section id="terminal-basics" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-blue-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">1</span>
                        터미널 기초
                    </h2>

                    <div id="what-is-terminal" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            터미널이란?
                            <span class="help-balloon-trigger" onclick="toggleBalloon(this)">?<span class="help-balloon">터미널(Terminal)은 컴퓨터에게 텍스트로 명령을 내리는 창이다. 마우스 클릭 대신 키보드로 모든 작업을 수행할 수 있다.</span></span>
                        </h3>
                        <div class="bg-blue-50 rounded-lg p-4 border border-blue-100 mb-4">
                            <p class="font-semibold text-blue-800 mb-2">비유: 카카오톡 대화처럼</p>
                            <p class="text-xs text-blue-900 leading-relaxed">
                                카카오톡에서 친구에게 메시지를 보내면 답장이 오듯, 터미널에서 <strong>명령어를 입력</strong>하면
                                컴퓨터가 <strong>결과를 보여준다</strong>. GUI(그래픽 화면)에서 마우스로 폴더를 더블클릭하는 것을,
                                터미널에서는 <code class="bg-blue-100 px-1.5 py-0.5 rounded text-xs">cd 폴더이름</code>이라고 타이핑하는 것이다.
                            </p>
                        </div>
                    </div>

                    <div id="prompt-anatomy" class="scroll-mt-20">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            프롬프트 읽는 법
                        </h3>
                        <div class="code-block mb-3"><span class="code-prompt">pro@sam-server</span>:<span class="code-path">~</span>$</div>
                        <div class="grid grid-cols-1 gap-2 text-xs">
                            <div class="flex items-start gap-3 bg-gray-50 rounded-lg p-3">
                                <code class="bg-cyan-100 text-cyan-800 px-2 py-0.5 rounded font-bold shrink-0">pro</code>
                                <span class="text-gray-700">현재 로그인한 <strong>사용자 이름</strong></span>
                            </div>
                            <div class="flex items-start gap-3 bg-gray-50 rounded-lg p-3">
                                <code class="bg-amber-100 text-amber-800 px-2 py-0.5 rounded font-bold shrink-0">sam-server</code>
                                <span class="text-gray-700">접속 중인 <strong>서버(호스트) 이름</strong></span>
                            </div>
                            <div class="flex items-start gap-3 bg-gray-50 rounded-lg p-3">
                                <code class="bg-yellow-100 text-yellow-800 px-2 py-0.5 rounded font-bold shrink-0">~</code>
                                <span class="text-gray-700">현재 위치. <strong>~</strong>는 홈 디렉토리 (<code>/home/pro</code>)</span>
                            </div>
                            <div class="flex items-start gap-3 bg-gray-50 rounded-lg p-3">
                                <code class="bg-green-100 text-green-800 px-2 py-0.5 rounded font-bold shrink-0">$</code>
                                <span class="text-gray-700">일반 사용자. <strong>#</strong>이면 관리자(root) 권한</span>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            {{-- ============================================================ --}}
            {{-- 2. 파일 탐색 --}}
            {{-- ============================================================ --}}
            <section id="file-navigation" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-blue-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">2</span>
                        파일 탐색 — "내가 지금 어디에 있고, 뭐가 있지?"
                    </h2>

                    <div id="pwd-cd" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            pwd / cd — 현재 위치 확인 & 이동
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># 현재 위치 확인</span>
<span class="code-prompt">$</span> <span class="code-keyword">pwd</span>
<span class="code-output">/home/webservice/mng</span>

<span class="code-comment"># 폴더 이동</span>
<span class="code-prompt">$</span> <span class="code-keyword">cd</span> <span class="code-path">/home/webservice/api</span>     <span class="code-comment"># 절대 경로로 이동</span>
<span class="code-prompt">$</span> <span class="code-keyword">cd</span> <span class="code-path">storage/logs</span>             <span class="code-comment"># 상대 경로로 이동</span>
<span class="code-prompt">$</span> <span class="code-keyword">cd</span> <span class="code-path">..</span>                         <span class="code-comment"># 한 단계 위(부모 폴더)로</span>
<span class="code-prompt">$</span> <span class="code-keyword">cd</span> <span class="code-path">~</span>                          <span class="code-comment"># 홈 디렉토리로</span>
<span class="code-prompt">$</span> <span class="code-keyword">cd</span> <span class="code-path">-</span>                          <span class="code-comment"># 직전 디렉토리로 되돌아가기</span></div>
                        <div class="bg-amber-50 rounded-lg p-3 border border-amber-100 text-xs text-amber-800">
                            <strong>팁:</strong> 폴더 이름을 몇 글자 치고 <kbd class="bg-amber-200 px-1.5 py-0.5 rounded text-xs">Tab</kbd> 키를 누르면 자동 완성된다!
                        </div>
                    </div>

                    <div id="ls-ll" class="scroll-mt-20">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            ls / ll — 파일 목록 보기
                            <span class="help-balloon-trigger" onclick="toggleBalloon(this)">?<span class="help-balloon"><strong>ll</strong>은 <code>ls -la</code>의 별칭(alias)이다. 대부분의 서버에서 기본 설정되어 있다.</span></span>
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># 기본 목록</span>
<span class="code-prompt">$</span> <span class="code-keyword">ls</span>                             <span class="code-comment"># 파일/폴더 이름만</span>
<span class="code-prompt">$</span> <span class="code-keyword">ls</span> <span class="code-flag">-l</span>                          <span class="code-comment"># 상세 정보 (권한, 크기, 날짜)</span>
<span class="code-prompt">$</span> <span class="code-keyword">ls</span> <span class="code-flag">-la</span>                         <span class="code-comment"># 숨김 파일(.env 등)까지 포함</span>
<span class="code-prompt">$</span> <span class="code-keyword">ls</span> <span class="code-flag">-lh</span>                         <span class="code-comment"># 사람이 읽기 쉬운 크기 (KB, MB)</span>
<span class="code-prompt">$</span> <span class="code-keyword">ll</span>                             <span class="code-comment"># ls -la 와 동일 (단축 명령)</span></div>
                        <p class="text-xs text-gray-600 mb-3"><strong>ls -l</strong> 출력 읽는 법:</p>
                        <div class="code-block mb-3"><span class="code-output">-rw-r--r--  1  pro  pro  4.2K  Jan 15 10:30  .env</span>
<span class="code-output">drwxr-xr-x  5  pro  pro  4.0K  Jan 15 10:30  storage</span>
<span class="code-comment">│           │  │    │    │      │              └─ 파일/폴더 이름</span>
<span class="code-comment">│           │  │    │    │      └─ 수정 날짜</span>
<span class="code-comment">│           │  │    │    └─ 파일 크기</span>
<span class="code-comment">│           │  │    └─ 소유 그룹</span>
<span class="code-comment">│           │  └─ 소유자</span>
<span class="code-comment">│           └─ 링크 수</span>
<span class="code-comment">└─ 권한 (d=폴더, -=파일 / r읽기 w쓰기 x실행)</span></div>
                    </div>
                </div>
            </section>

            {{-- ============================================================ --}}
            {{-- 3. 파일 조작 --}}
            {{-- ============================================================ --}}
            <section id="file-operations" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-blue-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">3</span>
                        파일 조작 — "읽고, 복사하고, 이동하고, 삭제하기"
                    </h2>

                    <div id="cat-head-tail" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            cat / head / tail — 파일 내용 보기
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># 파일 전체 내용 출력</span>
<span class="code-prompt">$</span> <span class="code-keyword">cat</span> <span class="code-path">.env</span>

<span class="code-comment"># 파일 처음 20줄만</span>
<span class="code-prompt">$</span> <span class="code-keyword">head</span> <span class="code-flag">-n 20</span> <span class="code-path">storage/logs/laravel.log</span>

<span class="code-comment"># 파일 마지막 50줄만</span>
<span class="code-prompt">$</span> <span class="code-keyword">tail</span> <span class="code-flag">-n 50</span> <span class="code-path">storage/logs/laravel.log</span>

<span class="code-comment"># 실시간 로그 모니터링 (새 내용이 추가되면 자동 표시)</span>
<span class="code-prompt">$</span> <span class="code-keyword">tail</span> <span class="code-flag">-f</span> <span class="code-path">storage/logs/laravel.log</span>    <span class="code-comment"># Ctrl+C로 종료</span></div>
                        <div class="bg-green-50 rounded-lg p-3 border border-green-100 text-xs text-green-800">
                            <strong>실무 팁:</strong> 서버 에러가 발생하면 <code class="bg-green-100 px-1 rounded">tail -f storage/logs/laravel.log</code>로 실시간 로그를 확인한다.
                        </div>
                    </div>

                    <div id="cp-mv-rm" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            cp / mv / rm — 복사 / 이동 / 삭제
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># 파일 복사</span>
<span class="code-prompt">$</span> <span class="code-keyword">cp</span> <span class="code-path">.env</span> <span class="code-path">.env.backup</span>              <span class="code-comment"># .env를 .env.backup으로 복사</span>
<span class="code-prompt">$</span> <span class="code-keyword">cp</span> <span class="code-flag">-r</span> <span class="code-path">storage/</span> <span class="code-path">storage_backup/</span>    <span class="code-comment"># 폴더 전체 복사 (-r 필수)</span>

<span class="code-comment"># 파일/폴더 이동 (이름 변경에도 사용)</span>
<span class="code-prompt">$</span> <span class="code-keyword">mv</span> <span class="code-path">old_name.txt</span> <span class="code-path">new_name.txt</span>      <span class="code-comment"># 이름 변경</span>
<span class="code-prompt">$</span> <span class="code-keyword">mv</span> <span class="code-path">file.txt</span> <span class="code-path">/home/pro/backup/</span>      <span class="code-comment"># 다른 폴더로 이동</span>

<span class="code-comment"># 파일 삭제 (⚠️ 휴지통 없음! 바로 삭제됨)</span>
<span class="code-prompt">$</span> <span class="code-keyword">rm</span> <span class="code-path">file.txt</span>                       <span class="code-comment"># 파일 삭제</span>
<span class="code-prompt">$</span> <span class="code-keyword">rm</span> <span class="code-flag">-r</span> <span class="code-path">folder/</span>                    <span class="code-comment"># 폴더 삭제 (하위 포함)</span></div>
                        <div class="bg-red-50 rounded-lg p-3 border border-red-200 text-xs text-red-800">
                            <strong>주의:</strong> 리눅스에는 <strong>휴지통이 없다</strong>. <code>rm</code>으로 삭제하면 복구 불가. 중요한 파일은 삭제 전 <code>cp</code>로 백업하자.
                        </div>
                    </div>

                    <div id="mkdir-touch" class="scroll-mt-20">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            mkdir / touch — 폴더 & 파일 생성
                        </h3>
                        <div class="code-block"><span class="code-comment"># 폴더 생성</span>
<span class="code-prompt">$</span> <span class="code-keyword">mkdir</span> <span class="code-path">backup</span>                     <span class="code-comment"># 폴더 생성</span>
<span class="code-prompt">$</span> <span class="code-keyword">mkdir</span> <span class="code-flag">-p</span> <span class="code-path">backup/2026/01</span>           <span class="code-comment"># 중간 폴더까지 한번에 생성</span>

<span class="code-comment"># 빈 파일 생성</span>
<span class="code-prompt">$</span> <span class="code-keyword">touch</span> <span class="code-path">memo.txt</span>                    <span class="code-comment"># 빈 파일 생성</span></div>
                    </div>
                </div>
            </section>

            {{-- ============================================================ --}}
            {{-- 4. 권한 관리 --}}
            {{-- ============================================================ --}}
            <section id="permissions" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-blue-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">4</span>
                        권한 관리 — "누가 읽고, 쓰고, 실행할 수 있나?"
                    </h2>

                    <div class="bg-indigo-50 rounded-lg p-4 border border-indigo-100 mb-6">
                        <p class="text-xs text-indigo-900 leading-relaxed">
                            리눅스 파일에는 3종류의 사용자 × 3종류의 권한이 있다.
                        </p>
                        <div class="grid grid-cols-2 gap-3 mt-3 text-xs">
                            <div>
                                <p class="font-bold text-indigo-800 mb-1">사용자 구분</p>
                                <ul class="space-y-0.5 text-indigo-700">
                                    <li><code class="bg-indigo-100 px-1 rounded">u</code> — 소유자 (Owner)</li>
                                    <li><code class="bg-indigo-100 px-1 rounded">g</code> — 그룹 (Group)</li>
                                    <li><code class="bg-indigo-100 px-1 rounded">o</code> — 기타 (Others)</li>
                                </ul>
                            </div>
                            <div>
                                <p class="font-bold text-indigo-800 mb-1">권한 종류</p>
                                <ul class="space-y-0.5 text-indigo-700">
                                    <li><code class="bg-indigo-100 px-1 rounded">r</code> (4) — 읽기 (Read)</li>
                                    <li><code class="bg-indigo-100 px-1 rounded">w</code> (2) — 쓰기 (Write)</li>
                                    <li><code class="bg-indigo-100 px-1 rounded">x</code> (1) — 실행 (Execute)</li>
                                </ul>
                            </div>
                        </div>
                    </div>

                    <div id="chmod" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            chmod — 권한 변경
                            <span class="help-balloon-trigger" onclick="toggleBalloon(this)">?<span class="help-balloon"><strong>chmod</strong> = CHange MODe. 숫자 3자리로 소유자/그룹/기타의 권한을 한번에 설정한다. 예: 755 = rwxr-xr-x</span></span>
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># 숫자 방식 (가장 많이 사용)</span>
<span class="code-prompt">$</span> <span class="code-keyword">chmod</span> <span class="code-string">755</span> <span class="code-path">deploy.sh</span>       <span class="code-comment"># rwxr-xr-x (소유자: 모두, 나머지: 읽기+실행)</span>
<span class="code-prompt">$</span> <span class="code-keyword">chmod</span> <span class="code-string">644</span> <span class="code-path">.env</span>            <span class="code-comment"># rw-r--r-- (소유자: 읽기+쓰기, 나머지: 읽기만)</span>
<span class="code-prompt">$</span> <span class="code-keyword">chmod</span> <span class="code-string">600</span> <span class="code-path">.env</span>            <span class="code-comment"># rw------- (소유자만 읽기+쓰기, 나머지: 접근 불가)</span>
<span class="code-prompt">$</span> <span class="code-keyword">chmod</span> <span class="code-flag">-R</span> <span class="code-string">775</span> <span class="code-path">storage/</span>   <span class="code-comment"># 폴더 하위 전체에 적용 (-R = Recursive)</span>

<span class="code-comment"># 문자 방식</span>
<span class="code-prompt">$</span> <span class="code-keyword">chmod</span> <span class="code-string">+x</span> <span class="code-path">script.sh</span>       <span class="code-comment"># 실행 권한 추가</span>
<span class="code-prompt">$</span> <span class="code-keyword">chmod</span> <span class="code-string">u+w</span> <span class="code-path">file.txt</span>      <span class="code-comment"># 소유자에게 쓰기 권한 추가</span></div>

                        <p class="text-xs font-semibold text-gray-700 mb-2">자주 쓰는 권한 조합:</p>
                        <div class="overflow-x-auto">
                            <table class="w-full text-xs border-collapse">
                                <thead>
                                    <tr class="bg-gray-50">
                                        <th class="border border-gray-200 px-3 py-2 text-left">숫자</th>
                                        <th class="border border-gray-200 px-3 py-2 text-left">문자</th>
                                        <th class="border border-gray-200 px-3 py-2 text-left">의미</th>
                                        <th class="border border-gray-200 px-3 py-2 text-left">대상</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr><td class="border border-gray-200 px-3 py-2 font-mono font-bold">755</td><td class="border border-gray-200 px-3 py-2 font-mono">rwxr-xr-x</td><td class="border border-gray-200 px-3 py-2">실행 가능 스크립트</td><td class="border border-gray-200 px-3 py-2">deploy.sh, artisan</td></tr>
                                    <tr class="bg-gray-50"><td class="border border-gray-200 px-3 py-2 font-mono font-bold">644</td><td class="border border-gray-200 px-3 py-2 font-mono">rw-r--r--</td><td class="border border-gray-200 px-3 py-2">일반 파일</td><td class="border border-gray-200 px-3 py-2">*.php, *.html</td></tr>
                                    <tr><td class="border border-gray-200 px-3 py-2 font-mono font-bold">600</td><td class="border border-gray-200 px-3 py-2 font-mono">rw-------</td><td class="border border-gray-200 px-3 py-2">비밀 파일</td><td class="border border-gray-200 px-3 py-2">.env, SSH 키</td></tr>
                                    <tr class="bg-gray-50"><td class="border border-gray-200 px-3 py-2 font-mono font-bold">775</td><td class="border border-gray-200 px-3 py-2 font-mono">rwxrwxr-x</td><td class="border border-gray-200 px-3 py-2">공유 폴더</td><td class="border border-gray-200 px-3 py-2">storage/, logs/</td></tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div id="chown" class="scroll-mt-20">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            chown — 소유자 변경
                            <span class="help-balloon-trigger" onclick="toggleBalloon(this)">?<span class="help-balloon"><strong>chown</strong> = CHange OWNer. 파일의 주인을 바꾼다. 웹 서버가 파일에 접근하려면 올바른 소유자 설정이 중요하다.</span></span>
                        </h3>
                        <div class="code-block"><span class="code-comment"># 소유자 변경</span>
<span class="code-prompt">$</span> <span class="code-keyword">chown</span> <span class="code-string">pro:pro</span> <span class="code-path">file.txt</span>            <span class="code-comment"># 소유자와 그룹을 pro로</span>
<span class="code-prompt">$</span> <span class="code-keyword">chown</span> <span class="code-flag">-R</span> <span class="code-string">www-data:www-data</span> <span class="code-path">storage/</span> <span class="code-comment"># 웹서버가 접근하도록</span>

<span class="code-comment"># SAM 서버에서 자주 사용하는 패턴</span>
<span class="code-prompt">$</span> <span class="code-keyword">chown</span> <span class="code-flag">-R</span> <span class="code-string">pro:pro</span> <span class="code-path">/home/webservice/mng</span></div>
                    </div>
                </div>
            </section>

            {{-- ============================================================ --}}
            {{-- 5. 검색 & 필터 --}}
            {{-- ============================================================ --}}
            <section id="search-filter" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-blue-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">5</span>
                        검색 & 필터 — "원하는 것을 찾아내기"
                    </h2>

                    <div id="grep" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            grep — 텍스트 검색
                            <span class="help-balloon-trigger" onclick="toggleBalloon(this)">?<span class="help-balloon"><strong>grep</strong> = Global Regular Expression Print. 파일 안에서 특정 텍스트를 찾아 그 줄을 출력한다.</span></span>
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># 파일에서 특정 문자열 검색</span>
<span class="code-prompt">$</span> <span class="code-keyword">grep</span> <span class="code-string">"DB_HOST"</span> <span class="code-path">.env</span>               <span class="code-comment"># .env에서 DB_HOST 찾기</span>

<span class="code-comment"># 폴더 전체에서 검색 (-r = 재귀, -n = 줄번호)</span>
<span class="code-prompt">$</span> <span class="code-keyword">grep</span> <span class="code-flag">-rn</span> <span class="code-string">"Exception"</span> <span class="code-path">storage/logs/</span> <span class="code-comment"># 로그에서 Exception 검색</span>

<span class="code-comment"># 대소문자 무시 (-i)</span>
<span class="code-prompt">$</span> <span class="code-keyword">grep</span> <span class="code-flag">-i</span> <span class="code-string">"error"</span> <span class="code-path">laravel.log</span>       <span class="code-comment"># error, Error, ERROR 모두 검색</span>

<span class="code-comment"># 해당 문자열이 없는 줄 찾기 (-v)</span>
<span class="code-prompt">$</span> <span class="code-keyword">grep</span> <span class="code-flag">-v</span> <span class="code-string">"#"</span> <span class="code-path">.env</span>                  <span class="code-comment"># 주석 제외하고 보기</span></div>
                    </div>

                    <div id="find" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            find — 파일 찾기
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># 파일명으로 찾기</span>
<span class="code-prompt">$</span> <span class="code-keyword">find</span> <span class="code-path">.</span> <span class="code-flag">-name</span> <span class="code-string">"*.log"</span>              <span class="code-comment"># 현재 폴더에서 .log 파일 찾기</span>
<span class="code-prompt">$</span> <span class="code-keyword">find</span> <span class="code-path">/home</span> <span class="code-flag">-name</span> <span class="code-string">".env"</span>            <span class="code-comment"># /home 아래 모든 .env 찾기</span>

<span class="code-comment"># 크기 기준 (100MB 이상 파일)</span>
<span class="code-prompt">$</span> <span class="code-keyword">find</span> <span class="code-path">/</span> <span class="code-flag">-size</span> <span class="code-string">+100M</span>                <span class="code-comment"># 디스크 용량 잡아먹는 파일 추적</span>

<span class="code-comment"># 최근 7일 내 수정된 파일</span>
<span class="code-prompt">$</span> <span class="code-keyword">find</span> <span class="code-path">.</span> <span class="code-flag">-mtime</span> <span class="code-string">-7</span>                  <span class="code-comment"># 최근 1주일 내 변경된 파일</span></div>
                    </div>

                    <div id="pipe" class="scroll-mt-20">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            파이프 ( | ) — 명령어 연결하기
                            <span class="help-balloon-trigger" onclick="toggleBalloon(this)">?<span class="help-balloon">파이프(<code>|</code>)는 앞 명령의 출력을 뒤 명령의 입력으로 넘긴다. 여러 명령을 조합해서 강력한 작업을 수행할 수 있다.</span></span>
                        </h3>
                        <div class="code-block"><span class="code-comment"># 프로세스 중에서 nginx 찾기</span>
<span class="code-prompt">$</span> <span class="code-keyword">ps aux</span> | <span class="code-keyword">grep</span> <span class="code-string">"nginx"</span>

<span class="code-comment"># 파일 목록을 줄 수 세기</span>
<span class="code-prompt">$</span> <span class="code-keyword">ls</span> <span class="code-flag">-la</span> | <span class="code-keyword">wc</span> <span class="code-flag">-l</span>                    <span class="code-comment"># 현재 폴더의 파일 개수</span>

<span class="code-comment"># 로그에서 에러만 뽑아서 최근 10개만</span>
<span class="code-prompt">$</span> <span class="code-keyword">grep</span> <span class="code-string">"ERROR"</span> <span class="code-path">laravel.log</span> | <span class="code-keyword">tail</span> <span class="code-flag">-n 10</span></div>
                    </div>
                </div>
            </section>

            {{-- ============================================================ --}}
            {{-- 6. 시스템 모니터링 --}}
            {{-- ============================================================ --}}
            <section id="system-monitoring" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-blue-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">6</span>
                        시스템 모니터링 — "서버 상태 확인하기"
                    </h2>

                    <div id="top-htop" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            top / htop — CPU & 메모리 사용량
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># 실시간 프로세스 모니터 (기본 내장)</span>
<span class="code-prompt">$</span> <span class="code-keyword">top</span>                <span class="code-comment"># q 키로 종료</span>

<span class="code-comment"># 더 보기 쉬운 모니터 (설치 필요할 수 있음)</span>
<span class="code-prompt">$</span> <span class="code-keyword">htop</span>               <span class="code-comment"># 컬러풀한 UI, F10 또는 q로 종료</span></div>
                        <div class="bg-blue-50 rounded-lg p-3 border border-blue-100 text-xs text-blue-800">
                            <strong>확인 포인트:</strong> CPU가 100%에 가까우면 서버가 바쁜 것, 메모리(MEM)가 90% 이상이면 메모리 부족 위험.
                        </div>
                    </div>

                    <div id="df-free" class="scroll-mt-20">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            df / free — 디스크 & 메모리 확인
                        </h3>
                        <div class="code-block"><span class="code-comment"># 디스크 용량 확인 (-h = 사람이 읽기 쉬운 형태)</span>
<span class="code-prompt">$</span> <span class="code-keyword">df</span> <span class="code-flag">-h</span>
<span class="code-output">Filesystem      Size  Used Avail Use% Mounted on</span>
<span class="code-output">/dev/sda1        50G   32G   16G  67% /</span>

<span class="code-comment"># 메모리 사용량 확인</span>
<span class="code-prompt">$</span> <span class="code-keyword">free</span> <span class="code-flag">-h</span>
<span class="code-output">              total   used   free  shared  buff/cache  available</span>
<span class="code-output">Mem:          3.8Gi  2.1Gi  0.3Gi   45Mi      1.4Gi     1.4Gi</span>

<span class="code-comment"># 특정 폴더 용량 확인</span>
<span class="code-prompt">$</span> <span class="code-keyword">du</span> <span class="code-flag">-sh</span> <span class="code-path">storage/logs/</span>     <span class="code-comment"># 로그 폴더 크기 확인</span>
<span class="code-prompt">$</span> <span class="code-keyword">du</span> <span class="code-flag">-sh</span> <span class="code-path">*</span>                 <span class="code-comment"># 현재 폴더의 각 항목 크기</span></div>
                    </div>
                </div>
            </section>

            {{-- ============================================================ --}}
            {{-- 7. 프로세스 & 서비스 --}}
            {{-- ============================================================ --}}
            <section id="process-service" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-blue-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">7</span>
                        프로세스 & 서비스 — "실행 중인 프로그램 관리"
                    </h2>

                    <div id="ps-kill" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            ps / kill — 프로세스 확인 & 종료
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># 모든 프로세스 보기</span>
<span class="code-prompt">$</span> <span class="code-keyword">ps aux</span>                        <span class="code-comment"># 전체 프로세스 목록</span>
<span class="code-prompt">$</span> <span class="code-keyword">ps aux</span> | <span class="code-keyword">grep</span> <span class="code-string">"php"</span>          <span class="code-comment"># PHP 관련 프로세스만</span>
<span class="code-prompt">$</span> <span class="code-keyword">ps aux</span> | <span class="code-keyword">grep</span> <span class="code-string">"nginx"</span>        <span class="code-comment"># Nginx 프로세스 확인</span>

<span class="code-comment"># 프로세스 종료 (PID = 프로세스 번호)</span>
<span class="code-prompt">$</span> <span class="code-keyword">kill</span> <span class="code-string">1234</span>                      <span class="code-comment"># 정상 종료 요청</span>
<span class="code-prompt">$</span> <span class="code-keyword">kill</span> <span class="code-flag">-9</span> <span class="code-string">1234</span>                   <span class="code-comment"># ⚠️ 강제 종료 (최후의 수단)</span></div>
                    </div>

                    <div id="systemctl" class="scroll-mt-20">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            systemctl — 서비스 관리
                            <span class="help-balloon-trigger" onclick="toggleBalloon(this)">?<span class="help-balloon"><strong>systemctl</strong>은 리눅스의 서비스(=백그라운드 프로그램) 관리 도구다. Nginx, PHP-FPM, MySQL 등을 시작/중지/재시작할 때 사용한다.</span></span>
                        </h3>
                        <div class="code-block"><span class="code-comment"># 서비스 상태 확인 (안전, 언제든 OK)</span>
<span class="code-prompt">$</span> <span class="code-keyword">systemctl</span> <span class="code-string">status</span> <span class="code-path">nginx</span>         <span class="code-comment"># Nginx 상태</span>
<span class="code-prompt">$</span> <span class="code-keyword">systemctl</span> <span class="code-string">status</span> <span class="code-path">php8.3-fpm</span>    <span class="code-comment"># PHP-FPM 상태</span>
<span class="code-prompt">$</span> <span class="code-keyword">systemctl</span> <span class="code-string">status</span> <span class="code-path">mysql</span>         <span class="code-comment"># MySQL 상태</span>

<span class="code-comment"># ⚠️ 서비스 제어 (서비스 중단 위험 — 확인 후 실행)</span>
<span class="code-prompt">$</span> <span class="code-keyword">sudo systemctl</span> <span class="code-string">restart</span> <span class="code-path">nginx</span>   <span class="code-comment"># Nginx 재시작</span>
<span class="code-prompt">$</span> <span class="code-keyword">sudo systemctl</span> <span class="code-string">restart</span> <span class="code-path">php8.3-fpm</span>
<span class="code-prompt">$</span> <span class="code-keyword">sudo systemctl</span> <span class="code-string">stop</span> <span class="code-path">nginx</span>      <span class="code-comment"># Nginx 중지 (사이트 접속 불가!)</span>
<span class="code-prompt">$</span> <span class="code-keyword">sudo systemctl</span> <span class="code-string">start</span> <span class="code-path">nginx</span>     <span class="code-comment"># Nginx 시작</span></div>
                    </div>
                </div>
            </section>

            {{-- ============================================================ --}}
            {{-- 8. 네트워크 --}}
            {{-- ============================================================ --}}
            <section id="network" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-blue-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">8</span>
                        네트워크 — "외부와 통신하기"
                    </h2>

                    <div id="curl-wget" class="scroll-mt-20 mb-8">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            curl / wget — URL 요청 & 파일 다운로드
                        </h3>
                        <div class="code-block mb-3"><span class="code-comment"># URL 응답 확인 (API 테스트에 유용)</span>
<span class="code-prompt">$</span> <span class="code-keyword">curl</span> <span class="code-path">https://sam.codebridgex.com</span>       <span class="code-comment"># 응답 본문 출력</span>
<span class="code-prompt">$</span> <span class="code-keyword">curl</span> <span class="code-flag">-I</span> <span class="code-path">https://sam.codebridgex.com</span>    <span class="code-comment"># 헤더만 확인 (상태 코드)</span>

<span class="code-comment"># 파일 다운로드</span>
<span class="code-prompt">$</span> <span class="code-keyword">wget</span> <span class="code-path">https://example.com/file.zip</span>      <span class="code-comment"># 파일 다운로드</span></div>
                    </div>

                    <div id="ss-netstat" class="scroll-mt-20">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            ss / netstat — 포트 & 연결 확인
                        </h3>
                        <div class="code-block"><span class="code-comment"># 열려있는 포트 확인</span>
<span class="code-prompt">$</span> <span class="code-keyword">ss</span> <span class="code-flag">-tulnp</span>                        <span class="code-comment"># TCP/UDP 열린 포트 목록</span>
<span class="code-prompt">$</span> <span class="code-keyword">ss</span> <span class="code-flag">-tulnp</span> | <span class="code-keyword">grep</span> <span class="code-string">":80"</span>          <span class="code-comment"># 80번 포트(HTTP) 사용 중인지 확인</span>
<span class="code-prompt">$</span> <span class="code-keyword">ss</span> <span class="code-flag">-tulnp</span> | <span class="code-keyword">grep</span> <span class="code-string">":3306"</span>        <span class="code-comment"># MySQL(3306) 포트 확인</span></div>
                    </div>
                </div>
            </section>

            {{-- ============================================================ --}}
            {{-- 9. 텍스트 편집 --}}
            {{-- ============================================================ --}}
            <section id="text-editing" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-blue-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">9</span>
                        텍스트 편집 — "서버에서 직접 파일 수정하기"
                    </h2>

                    <div id="nano-vi" class="scroll-mt-20">
                        <h3 class="text-lg font-semibold text-gray-800 mb-3 flex items-center gap-2">
                            <span class="w-2 h-2 bg-blue-400 rounded-full"></span>
                            nano / vi — 터미널 텍스트 편집기
                        </h3>

                        <div class="grid gap-4 mb-4" style="grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));">
                            <div class="bg-green-50 rounded-lg p-4 border border-green-200">
                                <p class="font-bold text-green-800 mb-2">nano (초보자 추천)</p>
                                <div class="code-block" style="font-size: 11px;"><span class="code-prompt">$</span> <span class="code-keyword">nano</span> <span class="code-path">.env</span>

<span class="code-comment"># 편집 후:</span>
<span class="code-comment"># Ctrl+O → 저장</span>
<span class="code-comment"># Ctrl+X → 종료</span></div>
                            </div>
                            <div class="bg-purple-50 rounded-lg p-4 border border-purple-200">
                                <p class="font-bold text-purple-800 mb-2">vi / vim (고급)</p>
                                <div class="code-block" style="font-size: 11px;"><span class="code-prompt">$</span> <span class="code-keyword">vi</span> <span class="code-path">.env</span>

<span class="code-comment"># i → 편집 모드 진입</span>
<span class="code-comment"># Esc → 편집 모드 종료</span>
<span class="code-comment"># :wq → 저장 후 종료</span>
<span class="code-comment"># :q! → 저장 안하고 종료</span></div>
                            </div>
                        </div>
                        <div class="bg-amber-50 rounded-lg p-3 border border-amber-100 text-xs text-amber-800">
                            <strong>팁:</strong> vi에서 빠져나오지 못할 때는 <kbd class="bg-amber-200 px-1.5 py-0.5 rounded">Esc</kbd>를 여러 번 누른 후 <code>:q!</code>를 입력하면 된다.
                        </div>
                    </div>
                </div>
            </section>

            {{-- ============================================================ --}}
            {{-- 10. 위험 명령어 --}}
            {{-- ============================================================ --}}
            <section id="danger-zone" class="scroll-mt-20">
                <div class="bg-white rounded-xl shadow-sm border border-red-200 p-6">
                    <h2 class="text-xl font-bold text-red-700 mb-6 flex items-center gap-3">
                        <span class="w-8 h-8 bg-red-600 text-white rounded-lg flex items-center justify-center text-sm font-bold">10</span>
                        위험 명령어 — "절대 주의!"
                    </h2>

                    <div class="bg-red-50 rounded-lg p-4 border border-red-200 mb-6">
                        <p class="text-sm font-bold text-red-800 mb-2">아래 명령어들은 서버를 망가뜨릴 수 있다. 실행 전 반드시 확인하자.</p>
                        <p class="text-xs text-red-700">SAM 서버 정책: 이 명령어들은 <strong>팀장/관리자에게 확인 후</strong>에만 실행한다.</p>
                    </div>

                    <div id="dangerous-cmds" class="scroll-mt-20 space-y-4">
                        <div class="border border-red-200 rounded-lg p-4 cmd-card">
                            <div class="flex items-center gap-2 mb-2">
                                <span class="danger-badge bg-red-100 text-red-700 border border-red-300">치명적</span>
                                <code class="font-bold text-gray-900">rm -rf /</code>
                            </div>
                            <p class="text-xs text-gray-600 mb-2">서버의 <strong>모든 파일을 삭제</strong>한다. 절대 실행하면 안 된다.</p>
                            <div class="code-block"><span class="code-comment"># ❌ 절대 금지</span>
<span class="code-danger">rm -rf /</span>                 <span class="code-comment"># 서버 전체 삭제</span>
<span class="code-danger">rm -rf /*</span>                <span class="code-comment"># 서버 전체 삭제 (같은 의미)</span>
<span class="code-danger">rm -rf ~</span>                 <span class="code-comment"># 홈 디렉토리 전체 삭제</span>

<span class="code-comment"># ✅ 올바른 사용: 삭제할 대상을 명확히 지정</span>
<span class="code-string">rm -r /home/pro/backup/old-logs/</span></div>
                        </div>

                        <div class="border border-red-200 rounded-lg p-4 cmd-card">
                            <div class="flex items-center gap-2 mb-2">
                                <span class="danger-badge bg-orange-100 text-orange-700 border border-orange-300">위험</span>
                                <code class="font-bold text-gray-900">chmod -R 777</code>
                            </div>
                            <p class="text-xs text-gray-600 mb-2">모든 사용자에게 모든 권한을 부여한다. <strong>보안 구멍</strong>이 된다.</p>
                            <div class="code-block"><span class="code-comment"># ❌ 보안 위험</span>
<span class="code-danger">chmod -R 777 /home/webservice/</span>

<span class="code-comment"># ✅ 올바른 권한 설정</span>
<span class="code-string">chmod -R 755 /home/webservice/mng/</span>
<span class="code-string">chmod 600 /home/webservice/mng/.env</span></div>
                        </div>

                        <div class="border border-red-200 rounded-lg p-4 cmd-card">
                            <div class="flex items-center gap-2 mb-2">
                                <span class="danger-badge bg-orange-100 text-orange-700 border border-orange-300">위험</span>
                                <code class="font-bold text-gray-900">kill -9</code>
                            </div>
                            <p class="text-xs text-gray-600 mb-2">프로세스를 <strong>강제 종료</strong>한다. 데이터 손실 위험.</p>
                            <div class="code-block"><span class="code-comment"># ❌ 데이터 손실 위험 (MySQL 등에 사용 금지)</span>
<span class="code-danger">kill -9 $(pgrep mysql)</span>

<span class="code-comment"># ✅ 서비스는 systemctl로 안전하게 종료</span>
<span class="code-string">sudo systemctl stop mysql</span></div>
                        </div>

                        <div class="border border-red-200 rounded-lg p-4 cmd-card">
                            <div class="flex items-center gap-2 mb-2">
                                <span class="danger-badge bg-yellow-100 text-yellow-700 border border-yellow-300">주의</span>
                                <code class="font-bold text-gray-900">reboot / shutdown</code>
                            </div>
                            <p class="text-xs text-gray-600 mb-2">서버를 재부팅/종료한다. 운영 중인 서비스가 모두 중단된다.</p>
                            <div class="code-block"><span class="code-comment"># ⚠️ 운영 서버에서 함부로 실행 금지</span>
<span class="code-danger">sudo reboot</span>              <span class="code-comment"># 서버 재시작</span>
<span class="code-danger">sudo shutdown -h now</span>     <span class="code-comment"># 서버 즉시 종료</span></div>
                        </div>
                    </div>

                    {{-- 안전 수칙 요약 --}}
                    <div class="mt-6 bg-green-50 rounded-lg p-4 border border-green-200">
                        <p class="font-bold text-green-800 mb-2">안전 수칙 요약</p>
                        <ul class="text-xs text-green-700 space-y-1">
                            <li>1. <code class="bg-green-100 px-1 rounded">rm</code> 실행 전, 삭제 대상 경로를 <strong>두 번 확인</strong>한다.</li>
                            <li>2. <code class="bg-green-100 px-1 rounded">chmod 777</code> 대신 <strong>필요한 최소 권한</strong>만 부여한다.</li>
                            <li>3. 서비스 중지/재시작은 <strong>팀장에게 확인</strong> 후 실행한다.</li>
                            <li>4. 모르는 명령어는 <code class="bg-green-100 px-1 rounded">man 명령어</code> 또는 <code class="bg-green-100 px-1 rounded">명령어 --help</code>로 먼저 확인한다.</li>
                            <li>5. 중요한 작업 전에는 항상 <strong>백업</strong>한다. (<code class="bg-green-100 px-1 rounded">cp -r 원본 백업경로</code>)</li>
                        </ul>
                    </div>
                </div>
            </section>

        </div>
    </div>

</div>

{{-- Hover Preview --}}
<div id="hover-preview">
    <img id="hover-preview-img" src="" alt="">
    <div class="hover-caption" id="hover-preview-caption"></div>
</div>

{{-- Lightbox --}}
<div id="lightbox" onclick="closeLightbox()">
    <img id="lightbox-img" src="" alt="">
</div>
@endsection

@push('scripts')
<script>
(function() {
    // 도움말 풍선 토글
    window.toggleBalloon = function(el) {
        var wasActive = el.classList.contains('is-active');
        document.querySelectorAll('.help-balloon-trigger.is-active').forEach(function(t) {
            t.classList.remove('is-active');
        });
        if (!wasActive) {
            el.classList.add('is-active');
        }
    };

    // 풍선 외부 클릭 시 닫기
    document.addEventListener('click', function(e) {
        if (!e.target.closest('.help-balloon-trigger')) {
            document.querySelectorAll('.help-balloon-trigger.is-active').forEach(function(t) {
                t.classList.remove('is-active');
            });
        }
    });

    // Lightbox
    window.openLightbox = function(el) {
        var lb = document.getElementById('lightbox');
        var img = document.getElementById('lightbox-img');
        img.src = el.src;
        img.alt = el.alt;
        lb.classList.add('is-open');
        document.body.style.overflow = 'hidden';
    };

    window.closeLightbox = function() {
        var lb = document.getElementById('lightbox');
        lb.classList.remove('is-open');
        document.body.style.overflow = '';
    };

    document.addEventListener('keydown', function(e) {
        if (e.key === 'Escape') {
            closeLightbox();
        }
    });
})();
</script>
@endpush
