/* ========================================
   모바일 반응형 CSS - 전면 개선 버전
   ======================================== */

/* 햄버거 메뉴 버튼 */
.mobile-menu-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    z-index: 998;
    position: relative;
}

/* 모바일 메뉴가 열렸을 때 햄버거 버튼 숨기기 */
.mobile-menu-btn.active {
    opacity: 0;
    pointer-events: none;
}

.hamburger {
    width: 25px;
    height: 3px;
    background-color: #333;
    margin: 3px 0;
    transition: all 0.3s ease;
    border-radius: 2px;
}

/* 모바일 메뉴 오버레이 */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 999;
    backdrop-filter: blur(2px);
}

.mobile-menu-overlay.active {
    display: block;
}

/* 모바일 메뉴 */
.mobile-menu {
    position: fixed;
    top: 0;
    right: -100%;
    width: 85%;
    max-width: 320px;
    height: 100%;
    background-color: #fff;
    transition: right 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
    overflow-y: auto;
    box-shadow: -5px 0 20px rgba(0,0,0,0.3);
}

.mobile-menu.active {
    right: 0;
}

.mobile-menu-header {
    padding: 20px;
    border-bottom: 2px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.mobile-menu-header .logo-text {
    font-size: 18px;
    font-weight: bold;
}

.mobile-menu-close {
    background: rgba(255,255,255,0.2);
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
}

.mobile-menu-close:hover {
    background: rgba(255,255,255,0.3);
}

.mobile-menu-nav {
    padding: 10px 0;
}

.mobile-menu-nav > ul > li {
    border-bottom: 1px solid #f0f0f0;
}

.mobile-menu-nav > ul > li > a {
    display: block;
    padding: 16px 20px;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    transition: background 0.2s;
}

.mobile-menu-nav > ul > li > a:hover {
    background: #f8f9fa;
}

.mobile-menu-nav .mobile-submenu {
    display: none;
    background-color: #f8f9fa;
}

.mobile-menu-nav .mobile-submenu.active {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mobile-menu-nav .mobile-submenu li a {
    display: block;
    padding: 12px 20px 12px 40px;
    font-size: 14px;
    color: #666;
    border-bottom: 1px solid #e9ecef;
    transition: all 0.2s;
}

.mobile-menu-nav .mobile-submenu li a:hover {
    background: #fff;
    color: #667eea;
    padding-left: 45px;
}

.mobile-menu-toggle {
    position: relative;
}

.mobile-menu-toggle::after {
    content: "▼";
    position: absolute;
    right: 20px;
    font-size: 12px;
    transition: transform 0.3s ease;
    color: #999;
}

.mobile-menu-toggle.active::after {
    transform: rotate(180deg);
}

/* 햄버거 메뉴 활성화 시 애니메이션 */
.mobile-menu-btn.active .hamburger:nth-child(1) {
    transform: rotate(-45deg) translate(-5px, 6px);
}

.mobile-menu-btn.active .hamburger:nth-child(2) {
    opacity: 0;
    transform: translateX(-20px);
}

.mobile-menu-btn.active .hamburger:nth-child(3) {
    transform: rotate(45deg) translate(-5px, -6px);
}

/* ========================================
   태블릿 & 모바일 반응형 (1024px 이하)
   ======================================== */

@media (max-width: 1024px) {
    /* 기본 레이아웃 */
    #wrap {
        min-width: 320px;
        width: 100%;
        overflow-x: hidden;
    }

    body {
        overflow-x: hidden;
    }

    /* 헤더 */
    .header-container {
        width: 100%;
        padding: 0 15px;
        height: 70px;
    }

    .logo-text {
        font-size: 18px;
    }

    .logo-flag {
        font-size: 16px;
    }

    /* 햄버거 메뉴 표시 */
    .mobile-menu-btn {
        display: flex;
    }

    /* 기본 GNB 숨기기 */
    .gnb {
        display: none;
    }

    /* 메인 레이아웃 */
    #main {
        width: 100%;
        margin: 15px 0;
        padding: 0 10px;
        flex-direction: column;
        gap: 15px;
    }

    .sidebar {
        width: 100%;
        display: flex;
        flex-direction: column;
    }

    /* 메인배너(컨테이너)를 가장 위로 */
    .container {
        width: 100%;
        order: -1; /* 메인배너가 있는 컨테이너가 가장 위 */
        padding: 15px;
    }

    /* 채팅창을 메인배너 다음, 자유게시판 위로 */
    .chat-box {
        order: 0; /* 컨테이너 다음 */
    }

    .login-box {
        order: 1; /* 채팅창 다음 */
    }

    .sidebar-banners {
        order: 2; /* 로그인 박스 다음 */
    }

    /* 로그인 박스 */
    .login-box {
        margin-bottom: 15px;
    }

    .login-form {
        padding: 15px;
    }

    .login-form input {
        padding: 10px;
    }

    .login-btn {
        padding: 12px;
        font-size: 16px;
    }

    /* 채팅 박스 */
    .chat-box {
        height: 550px;
        margin-bottom: 15px;
    }

    /* 사이드바 배너 그리드로 변경 */
    .sidebar-banners {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0; /* 배너 간 공백 제거 */
    }

    /* 게시물 목록 */
    .latest-posts {
        flex-direction: column;
        gap: 15px;
    }

    .post-column {
        width: 100%;
    }

    .post-list li a {
        font-size: 13px;
    }

    /* 배너 */
    .main-banner-section,
    .central-banners {
        margin-bottom: 15px;
    }

    /* 메인 배너 그리드 배치 유지 (모바일에서도 2열 그리드) */
    .banners.two-banners,
    #main-slides.two-banners {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .banners.two-banners .fixed-banner,
    #main-slides.two-banners .fixed-banner {
        width: 100% !important;
    }

    .banners.two-banners .fixed-banner img,
    #main-slides.two-banners .fixed-banner img {
        object-fit: cover !important;
    }

    /* 달력 */
    .server-calendar-section {
        margin-bottom: 15px;
    }

    /* 달력 위 배너 반응형 */
    .calendar-banner-section {
        width: 100%;
        overflow: hidden;
        margin-bottom: 15px;
    }

    #calendar-banner-container {
        width: 100%;
    }

    #calendar-banner-container img {
        width: 100%;
        max-width: 100%;
        height: auto;
        object-fit: contain;
        display: block;
    }

    .calendar-day {
        min-height: 90px;
        padding: 6px;
    }

    .event-box {
        font-size: 10px;
        padding: 4px 6px;
    }
}

/* ========================================
   모바일 (768px 이하)
   ======================================== */

@media (max-width: 768px) {
    /* 헤더 */
    .header-container {
        height: 60px;
        padding: 0 10px;
    }

    .logo-text {
        font-size: 16px;
    }

    .logo-flag {
        font-size: 14px;
    }

    /* 메인 레이아웃 */
    #main {
        padding: 0 8px;
        margin: 10px 0;
        gap: 12px;
    }

    .container {
        padding: 12px;
        border-radius: 8px;
    }

    /* 로그인 박스 */
    .login-box .tab {
        padding: 12px;
        font-size: 14px;
    }

    .login-form {
        padding: 12px;
        gap: 8px;
    }

    .login-form input {
        padding: 10px 12px;
        font-size: 14px;
    }

    .login-btn {
        padding: 12px;
        font-size: 15px;
    }

    /* 채팅 박스 */
    .chat-box {
        height: 500px;
        padding: 12px;
    }

    .chat-header h3 {
        font-size: 15px;
    }

    .chat-messages {
        font-size: 13px;
    }

    #chat-input {
        font-size: 14px;
        padding: 8px 10px;
    }

    /* 사이드바 배너 */
    .sidebar-banners {
        grid-template-columns: 1fr;
        gap: 0; /* 배너 간 공백 제거 */
    }

    /* 게시물 */
    .post-header {
        padding: 10px 12px;
    }

    .post-header h3 {
        font-size: 15px;
    }

    .post-list {
        padding: 12px;
    }

    .post-list li {
        padding: 8px 0;
        font-size: 13px;
    }

    .post-list li .time {
        font-size: 11px;
    }

    /* 배너 */
    .fixed-banner,
    .central-banners img,
    #board-bottom-central-banners img {
        border-radius: 6px;
    }

    /* 게시판 하단 배너 모바일 */
    .central-banners img,
    #board-bottom-central-banners img {
        width: 100% !important;
        height: auto !important;
        max-height: 80px;
    }

    /* 달력 */
    .calendar-header {
        padding: 15px 12px;
    }

    .calendar-header h2 {
        font-size: 18px;
    }

    .calendar-nav-btn {
        padding: 8px 14px;
        font-size: 16px;
    }

    #current-month {
        font-size: 16px;
    }

    .calendar-weekdays .weekday {
        padding: 10px 5px;
        font-size: 13px;
    }

    .calendar-day {
        min-height: 75px;
        padding: 5px;
        font-size: 11px;
    }

    .day-number {
        font-size: 11px;
    }

    .event-box {
        font-size: 9px;
        padding: 3px 5px;
        margin-bottom: 3px;
    }

    /* 유튜브 섹션 */
    .youtube-grid {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    /* 푸터 */
    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }

    .footer-links {
        justify-content: center;
        flex-wrap: wrap;
    }

    .footer-text,
    .footer-contact {
        font-size: 13px;
    }
}

/* ========================================
   소형 모바일 (480px 이하)
   ======================================== */

@media (max-width: 480px) {
    /* 헤더 */
    .header-container {
        height: 55px;
        padding: 0 8px;
    }

    .logo-text {
        font-size: 15px;
    }

    .logo-flag {
        font-size: 13px;
    }

    .mobile-menu-btn {
        width: 35px;
        height: 35px;
    }

    .hamburger {
        width: 22px;
        height: 2.5px;
    }

    /* 메인 레이아웃 */
    #main {
        padding: 0 5px;
        margin: 8px 0;
        gap: 10px;
    }

    .container {
        padding: 10px;
        border-left: none;
        border-right: none;
        border-radius: 0;
    }

    /* 로그인 */
    .login-box .tab {
        padding: 10px;
        font-size: 13px;
    }

    .login-form {
        padding: 10px;
    }

    .login-form input {
        padding: 9px 10px;
        font-size: 13px;
    }

    .login-btn {
        padding: 11px;
        font-size: 14px;
    }

    /* 채팅 */
    .chat-box {
        height: 450px;
        padding: 10px;
    }

    .chat-header h3 {
        font-size: 14px;
    }

    .chat-messages {
        font-size: 12px;
    }

    .chat-input-form {
        gap: 6px;
    }

    #chat-input {
        font-size: 13px;
        padding: 7px 9px;
    }

    .chat-input-form button {
        padding: 7px 12px;
        font-size: 13px;
    }

    /* 게시물 */
    .post-header {
        padding: 8px 10px;
    }

    .post-header h3 {
        font-size: 14px;
    }

    .post-list {
        padding: 10px;
    }

    .post-list li {
        padding: 7px 0;
        font-size: 12px;
    }

    .post-list li .time {
        font-size: 10px;
    }

    /* 달력 */
    .calendar-header {
        padding: 12px 10px;
        flex-direction: column;
        gap: 10px;
    }

    .calendar-header h2 {
        font-size: 16px;
    }

    .calendar-nav {
        gap: 12px;
    }

    .calendar-nav-btn {
        padding: 7px 12px;
        font-size: 14px;
    }

    #current-month {
        font-size: 14px;
        min-width: 90px;
    }

    .calendar-weekdays .weekday {
        padding: 8px 3px;
        font-size: 11px;
    }

    .calendar-day {
        min-height: 65px;
        padding: 4px;
        font-size: 10px;
    }

    .day-number {
        font-size: 10px;
        margin-bottom: 3px;
    }

    .event-box {
        font-size: 8px;
        padding: 2px 4px;
        margin-bottom: 2px;
    }

    /* 푸터 */
    .footer-content {
        padding: 0 10px;
    }

    .footer-text,
    .footer-contact {
        font-size: 12px;
    }

    .footer-links a {
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* ========================================
   초소형 모바일 (360px 이하)
   ======================================== */

@media (max-width: 360px) {
    .header-container {
        height: 50px;
        padding: 0 6px;
    }

    .logo-text {
        font-size: 14px;
    }

    .logo-flag {
        font-size: 12px;
    }

    #main {
        padding: 0 3px;
    }

    .container {
        padding: 8px;
    }

    .chat-box {
        height: 400px;
        padding: 8px;
    }

    .calendar-header h2 {
        font-size: 15px;
    }

    .calendar-day {
        min-height: 55px;
        padding: 3px;
    }

    .event-box {
        font-size: 7px;
        padding: 2px 3px;
    }
}

/* ========================================
   모바일 전용 유틸리티
   ======================================== */

@media (max-width: 1024px) {
    /* 터치 타겟 크기 보장 */
    button, a, input, select, textarea {
        min-height: 44px;
        touch-action: manipulation;
    }

    /* 스크롤 최적화 */
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* 이미지 최적화 */
    img {
        max-width: 100%;
        height: auto;
    }

    /* 테이블 반응형 */
    table {
        width: 100%;
        overflow-x: auto;
        display: block;
    }

    /* 폰트 크기 자동 조정 방지 */
    input, textarea, select {
        font-size: 16px;
    }
}

/* 가로 모드 최적화 */
@media (max-width: 1024px) and (orientation: landscape) {
    .chat-box {
        height: 450px;
    }

    .calendar-day {
        min-height: 60px;
    }

    .mobile-menu {
        max-width: 280px;
    }
}
