/* 마랭 커뮤니티 커스텀 스타일 */

/* Hero 배너 - 이미지 비율에 맞춰 동적 크기 조정 */
.hero-banner {
    width: 100%;
    max-height: 300px; /* 최대 높이 제한 */
    min-height: 120px; /* 최소 높이 보장 */
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent; /* 배경 투명 */
    overflow: hidden;
}

/* 화면 크기별 Hero 배너 최적화 */
@media (max-width: 640px) {
    .hero-banner {
        max-height: 200px;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .hero-banner {
        max-height: 250px;
    }
}

@media (min-width: 1025px) {
    .hero-banner {
        max-height: 300px;
    }
}

/* Hero 배너 이미지 - 동적 크기 조정 */
.hero-banner img {
    object-fit: cover; /* 비율 유지하면서 영역 채우기 */
    object-position: center center;
    transition: all 0.3s ease;
    width: 100%;
    height: 100%;
}

/* 그리드 배너 - 이미지 비율에 맞춰 동적 크기 조정 */
.banner-card {
    min-height: 80px;
    max-height: 250px !important; /* 🎯 Ultra Think 수정: 키워드 배너 250px 높이 허용 */
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent; /* 배경 투명 */
    overflow: hidden;
}

.banner-card img {
    object-fit: contain; /* 이미지 전체 표시 - 크롭 방지 */
    object-position: center center;
    width: 100%;
    height: 100%;
    transition: all 0.3s ease;
}

/* qLayer 사이드 배너 - 150x500 크기에서 이미진 전체 표시 */
.qlayer-banner {
    object-fit: contain !important; /* 이미지 전체가 보이도록 */
    object-position: center center;
    width: 150px;
    height: 500px;
    background-color: #f8f9fa; /* 여백 부분 배경색 */
}

/* 키워드 배너 컨테이너 - 350x250 비율 유지 (7:5) */
/* Ultra Think 수정: min-width 제거하여 그리드에 맞춰 자연스럽게 축소 */
.keyword-banner-container {
    position: relative;
    display: block;
    width: 100%;
    /* min-width 제거: 그리드 크기에 맞춰 자연스럽게 축소되도록 함 */
    aspect-ratio: 7 / 5; /* 350:250 비율 자동 계산 */
    overflow: hidden;
    border-radius: 8px;
    background-color: #f1f3f4;
    transition: all 0.3s ease;
}

.keyword-banner-container img {
    width: 100%;
    height: 100%;
    object-fit: contain !important; /* 이미지 전체 표시 (잘림 방지) - Ultra Think 수정 */
    object-position: center center;
    transition: transform 0.3s ease;
}

/* 화면 크기별 최소 너비 - Ultra Think: 모두 제거하여 aspect-ratio가 정상 작동하도록 함 */
/*
@media (min-width: 768px) {
    .keyword-banner-container {
        min-width: 300px;
    }
}

@media (min-width: 1024px) {
    .keyword-banner-container {
        min-width: 320px;
    }
}

@media (min-width: 1280px) {
    .keyword-banner-container {
        min-width: 350px;
    }
}
*/

/* 키워드 배너 호버 효과 - Ultra Think: scale 제거하여 이미지 잘림 방지 */
.keyword-banner-container:hover img {
    /* transform: scale(1.05); 주석 처리 - 확대하면 이미지가 컨테이너를 벗어남 */
    opacity: 0.95; /* 대신 살짝 투명도 변경으로 호버 효과 */
    transition: opacity 0.3s ease;
}

/* 모바일에서 텍스트 가독성 개선 */
@media (max-width: 639px) {
    .hero-banner h1 {
        line-height: 1.2 !important;
        word-break: keep-all;
    }

    .hero-banner p {
        line-height: 1.4 !important;
        word-break: keep-all;
    }
}

/* HTMX 로딩 인디케이터 */
.htmx-indicator {
    opacity: 0;
    transition: opacity 200ms ease-in;
}
.htmx-request .htmx-indicator {
    opacity: 1;
}
.htmx-request.htmx-indicator {
    opacity: 1;
}

/* 로딩 스피너 */
.loading-spinner {
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 폼 인풋 포커스 스타일 개선 */
.form-input:focus {
    @apply ring-2 ring-primary ring-opacity-50 border-primary;
}

/* 버튼 호버 효과 개선 */
.btn-primary {
    background-color: #007bff;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
}

.btn-primary:hover {
    background-color: #0056b3;
    transform: scale(1.02);
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
}

.btn-secondary:hover {
    background-color: #545b62;
    transform: scale(1.02);
}

.btn-success {
    background-color: #28a745;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
}

.btn-success:hover {
    background-color: #1e7e34;
    transform: scale(1.02);
}

/* 댓글 버튼 시각성 개선 - 더 눈에 잘 띄게 (반응형) */
.comment-edit-btn {
    background-color: #007bff;
    color: white;
    padding: 0.25rem 0.5rem;        /* 모바일용 작은 패딩 */
    border-radius: 0.375rem;
    font-size: 0.625rem;            /* 모바일용 작은 폰트 (10px) */
    font-weight: 500;
    border: 2px solid #007bff;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 123, 255, 0.3);
}

/* 태블릿 이상에서 더 큰 크기 */
@media (min-width: 640px) {
    .comment-edit-btn {
        padding: 0.375rem 0.75rem;   /* 데스크톱용 표준 패딩 */
        font-size: 0.75rem;         /* 데스크톱용 표준 폰트 (12px) */
    }
}

.comment-edit-btn:hover {
    background-color: #0056b3;
    border-color: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 123, 255, 0.4);
}

.comment-delete-btn {
    background-color: #dc3545;
    color: white;
    padding: 0.25rem 0.5rem;        /* 모바일용 작은 패딩 */
    border-radius: 0.375rem;
    font-size: 0.625rem;            /* 모바일용 작은 폰트 (10px) */
    font-weight: 500;
    border: 2px solid #dc3545;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(220, 53, 69, 0.3);
}

/* 태블릿 이상에서 더 큰 크기 */
@media (min-width: 640px) {
    .comment-delete-btn {
        padding: 0.375rem 0.75rem;   /* 데스크톱용 표준 패딩 */
        font-size: 0.75rem;         /* 데스크톱용 표준 폰트 (12px) */
    }
}

.comment-delete-btn:hover {
    background-color: #c82333;
    border-color: #c82333;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.4);
}

/* 카드 컴포넌트 */
.card {
    background-color: white;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    border: 1px solid rgb(229 231 235);
    padding: 1.5rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.card-hover {
    transition: box-shadow 0.2s;
}

.card-hover:hover {
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

/* 네비게이션 링크 */
.nav-link {
    @apply text-gray-700 hover:text-primary transition-colors duration-200;
}

.nav-link.active {
    @apply text-primary font-medium;
}

/* 게시판 랭킹 표시 */
.rank-up {
    @apply text-success;
}

.rank-down {
    @apply text-danger;
}

.rank-same {
    @apply text-secondary;
}

/* 반응형 그리드 */
.responsive-grid {
    @apply grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6;
}

/* 배너 그리드 스타일 */
.banner-card {
    @apply transition-all duration-300 cursor-pointer;
}

.banner-card:hover {
    @apply transform scale-105 shadow-xl;
}

/* 반응형 레이아웃 */
@media (max-width: 1024px) {
    .max-w-7xl {
        @apply px-2;
    }

    /* 🎯 Ultra Think 수정: 데스크톱 사이드바만 너비 조정, 모바일 사이드바 제외 */
    aside#sidebar {
        @apply w-28;
    }
}

/* 🎯 Ultra Think 최종 해결책: 드롭다운 메뉴 방식 */
/* 복잡한 슬라이드 사이드바 대신 간단한 드롭다운 사용 */

/* 🔧 Fix: 모바일 사이드바 초기 상태 (숨김이지만 JavaScript로 제어 가능) */
aside#mobile-sidebar {
    /* display 제거 - JavaScript가 제어 */
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    width: 280px !important;
    height: 100vh !important;
    transform: translateX(-100%) !important; /* 초기: 왼쪽 밖으로 숨김 */
    transition: transform 0.3s ease-in-out !important;
    background: white !important;
    z-index: 9999 !important;
    overflow-y: auto !important;
}

#mobile-sidebar-overlay {
    display: none !important; /* 초기: 숨김 */
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    z-index: 9998 !important;
}

/* 데스크톱 사이드바는 정상 표시 (lg 이상에서만) */
aside#sidebar {
    /* 기본 스타일 유지 */
}

/* 기존 CSS 무효화 - 사용하지 않음 */
div#mobile-sidebar {
    /* 레이아웃 강제 */
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;

    /* 크기 강제 */
    width: 280px !important;
    min-width: 280px !important;
    max-width: 280px !important;
    height: 100vh !important;
    min-height: 100vh !important;

    /* 위치 강제 */
    position: fixed !important;
    left: -280px !important; /* 기본: 왼쪽 밖으로 숨김 */
    top: 0 !important;
    bottom: 0 !important;

    /* 렌더링 강제 */
    contain: none !important;
    isolation: auto !important;
    will-change: left !important;
    unicode-bidi: normal !important; /* 🎯 User Agent Stylesheet 문제 해결! */

    /* 스타일 */
    background: white !important;
    z-index: 9999 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;

    /* 애니메이션 */
    transition: left 0.3s ease-in-out !important;

    /* Tailwind Preflight 완전 무효화 */
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
}

/* 모바일 사이드바 열림 상태 (.open 클래스 추가시) */
div#mobile-sidebar.open {
    left: 0 !important; /* left: 0으로 화면에 표시 */
    visibility: visible !important;
    opacity: 1 !important;
}

/* 모바일 오버레이 기본 스타일 */
#mobile-sidebar-overlay {
    display: none !important;
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    z-index: 9998 !important;
}

/* 모바일 오버레이 표시 상태 (.show 클래스 추가시) */
#mobile-sidebar-overlay.show {
    display: block !important;
}

/* 모바일 최적화 */
@media (max-width: 768px) {
    /* 데스크톱 고정 사이드바만 숨김 */
    aside#sidebar {
        display: none !important;
    }

    .max-w-7xl {
        @apply px-1;
    }

    main {
        @apply w-full;
    }

    .banner-card {
        @apply h-24;
    }

    /* 모바일에서 Hero 배너 하단 마진 증가 */
    .hero-banner-section {
        @apply mb-8;
    }

    /* 모바일에서 배너 섹션들 간격 조정 */
    .banner-section,
    .rankings-section,
    .boards-preview-section {
        @apply mb-8;
    }

    .card {
        @apply p-3;
    }

    h1 {
        @apply text-xl;
    }

    h2 {
        @apply text-lg;
    }

    .grid {
        @apply gap-2;
    }
}

/* 초소형 모바일 */
@media (max-width: 480px) {
    .banner-card {
        @apply h-16;
    }

    .grid-cols-2 {
        @apply grid-cols-1;
    }

    .card {
        @apply p-2 text-xs;
    }

    .space-y-8 > * + * {
        @apply mt-4;
    }
}

/* 사이드바 숨김/표시 애니메이션 */
@media (min-width: 1024px) {
    aside {
        @apply block;
    }
}

/* 모바일 메뉴 스타일 */
.mobile-menu-overlay {
    @apply backdrop-blur-sm;
}

/* 호버 효과 개선 */
.card-hover:hover {
    @apply shadow-md transform translate-y-[-2px];
}

/* 텍스트 잘림 방지 */
.truncate-multiline {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* 스크롤 개선 */
@media (max-width: 768px) {
    .overflow-x-auto {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .overflow-x-auto::-webkit-scrollbar {
        display: none;
    }
}

/* 반응형 간격 조정 */
@media (max-width: 768px) {
    .gap-6 {
        @apply gap-2;
    }

    .gap-4 {
        @apply gap-2;
    }

    .gap-3 {
        @apply gap-2;
    }
}

/* 모바일 전용 플로팅 버튼 */
.mobile-fab {
    @apply animate-bounce;
    animation-iteration-count: 3;
    animation-delay: 2s;
}

/* 에러 메시지 */
.error-message {
    @apply bg-red-50 border border-red-200 text-red-800 px-4 py-3 rounded-md;
}

/* 성공 메시지 */
.success-message {
    @apply bg-green-50 border border-green-200 text-green-800 px-4 py-3 rounded-md;
}

/* 정보 메시지 */
.info-message {
    @apply bg-blue-50 border border-blue-200 text-blue-800 px-4 py-3 rounded-md;
}

/* 커스텀 스크롤바 (Webkit 기반 브라우저) */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    @apply bg-gray-100 rounded-full;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    @apply bg-gray-300 rounded-full;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    @apply bg-gray-400;
}

/* 애니메이션 */
.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

/* 모바일 반응형 */
@media (max-width: 768px) {
    .mobile-hidden {
        @apply hidden;
    }

    .mobile-full-width {
        @apply w-full;
    }
}

/* 게시판 테이블 스타일 개선 */
.board-table {
    @apply w-full border-collapse bg-white rounded-lg overflow-hidden shadow-sm;
}

.board-table thead {
    @apply bg-gray-50;
}

.board-table th {
    @apply px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200;
}

.board-table td {
    @apply px-4 py-4 text-sm border-b border-gray-100;
}

.board-table tbody tr {
    @apply hover:bg-gray-50 transition-colors duration-150;
}

.board-table .post-title {
    @apply text-gray-900 hover:text-primary font-medium transition-colors duration-150;
}

.board-table .post-meta {
    @apply text-gray-600;
}

.board-table .comment-count {
    @apply text-primary font-medium;
}

.board-table .new-badge {
    @apply bg-red-500 text-white text-xs px-2 py-1 rounded-full ml-2;
}

/* 페이지네이션 스타일 개선 */
.pagination {
    @apply flex justify-center items-center space-x-1 mt-6;
}

.pagination button {
    @apply px-3 py-2 text-sm border border-gray-300 bg-white text-gray-700 hover:bg-gray-50 transition-colors duration-150;
}

.pagination button:first-child {
    @apply rounded-l-md;
}

.pagination button:last-child {
    @apply rounded-r-md;
}

.pagination button.active {
    @apply bg-primary text-white border-primary;
}

.pagination button:disabled {
    @apply bg-gray-100 text-gray-400 cursor-not-allowed;
}

/* 검색 폼 스타일 개선 */
.search-form select {
    @apply border-gray-300 rounded-l-md focus:ring-primary focus:border-primary;
}

.search-form input {
    @apply border-gray-300 focus:ring-primary focus:border-primary;
}

.search-form button {
    @apply bg-primary text-white hover:bg-blue-600 px-4 py-2 rounded-r-md transition-colors duration-150;
}

/* 통계 카드 스타일 개선 */
.stat-card {
    @apply text-center p-4 rounded-lg;
}

.stat-card.blue {
    @apply bg-blue-50 border border-blue-200;
}

.stat-card.green {
    @apply bg-green-50 border border-green-200;
}

.stat-card.purple {
    @apply bg-purple-50 border border-purple-200;
}

.stat-number {
    @apply text-2xl font-bold;
}

.stat-number.blue {
    @apply text-blue-600;
}

.stat-number.green {
    @apply text-green-600;
}

.stat-number.purple {
    @apply text-purple-600;
}

.stat-label {
    @apply text-xs text-gray-500 mt-1;
}

/* 드래그 앤 드롭 스타일 */
#drop-zone {
    transition: all 0.3s ease;
}

#drop-zone.drag-over {
    border-color: #007bff;
    background-color: #f0f8ff;
    transform: scale(1.02);
}

#drop-zone:hover {
    border-color: #007bff;
    background-color: #f8f9fa;
}

/* 드래그 중일 때 전체 페이지 스타일 */
.drag-active {
    position: relative;
}

.drag-active::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 123, 255, 0.1);
    z-index: 10;
    pointer-events: none;
}

/* 🎯 Ultra Think 수정된 해결책: 350×250 크기 + 모바일 최적화 반응형 그리드 */

/* 배너 그리드 컨테이너 - 반응형 최적화 */
.banner-grid {
    display: grid !important;
    gap: 15px !important;
    width: 100% !important;
    max-width: 1445px !important; /* 350×4 + 15×3 = 1445px 안전한 최대폭 */
    margin: 0 auto !important;
    padding: 20px !important;
    box-sizing: border-box !important;
    justify-content: center !important;
}

/* 배너 카드 기본 설정 - 7:5 비율 유지 (350:250) */
.banner-card {
    position: relative !important;
    display: block !important;
    aspect-ratio: 7/5 !important; /* 350:250 = 7:5 비율 */
    overflow: hidden !important;
    border-radius: 8px !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
    box-sizing: border-box !important;
}

/* 📱 모바일 (320px-768px): 1×16 그리드 - 가시성 크게 개선 */
@media (max-width: 767px) {
    .banner-grid {
        grid-template-columns: 1fr !important; /* 1열로 변경하여 크기 확보 */
        gap: 15px !important; /* 더 큰 간격 */
        padding: 20px !important;
        max-width: 100% !important;
    }
    .banner-card {
        width: 100% !important;
        max-width: 320px !important; /* 모바일에서 충분한 크기 */
        min-width: 280px !important;
        margin: 0 auto !important; /* 중앙 정렬 */
    }
}

/* 📲 태블릿 (768px-1024px): 2×8 그리드 - 적당한 크기 */
@media (min-width: 768px) and (max-width: 1023px) {
    .banner-grid {
        grid-template-columns: repeat(2, minmax(250px, 1fr)) !important;
        gap: 20px !important;
        padding: 25px !important;
    }
    .banner-card {
        max-width: 300px !important;
        min-width: 250px !important;
    }
}

/* 💻 데스크톱 (1024px+): 4×4 그리드 - 350×250 새로운 표준 크기 */
@media (min-width: 1024px) {
    .banner-grid {
        grid-template-columns: repeat(4, 350px) !important; /* 새로운 350px 표준 */
        gap: 15px !important;
        padding: 20px !important;
    }
    .banner-card {
        width: 350px !important;
        height: 250px !important; /* 7:5 비율 = 350×250 */
    }
}

/* 🎯 Ultra Think 분리 해결책: 키워드 배너와 메인 그리드 배너 별도 관리 */

/* 키워드 배너 전용 클래스 (350×250 크기 유지) */
.keyword-banner-card {
    aspect-ratio: 7/5 !important; /* 350:250 = 7:5 비율 */
    overflow: hidden !important;
    border-radius: 8px !important;
    max-height: 250px !important; /* 키워드 배너 250px 높이 허용 */
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    transition: all 0.3s ease;
}

.keyword-banner-card img {
    object-fit: contain;
    object-position: center center;
    width: 100%;
    height: 100%;
    transition: all 0.3s ease;
}

/* 메인 그리드 배너 전용 클래스 (원래 크기 120px로 복구) */
.main-grid-banner {
    min-height: 80px;
    max-height: 120px !important; /* 🔄 원래 크기로 복구 */
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    overflow: hidden;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.main-grid-banner img {
    object-fit: contain;
    object-position: center center;
    width: 100%;
    height: 100%;
    transition: all 0.3s ease;
}

/* 다크 모드 준비 (추후 구현) */
@media (prefers-color-scheme: dark) {
    /* TODO: Phase 3에서 다크 모드 스타일 구현 */
}

/* ===== 🎯 Ultra Think: 랭킹 키워드 통일된 스타일 (1~10위 동일) ===== */
.ranking-keyword {
    font-size: 0.95rem;
    font-weight: 600;
    color: #000000;
    letter-spacing: -0.02em;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: inline-block;
    line-height: 1.4;
}

/* 1~10위 모두 동일한 스타일 적용 */
.ranking-keyword.rank-1,
.ranking-keyword.rank-2,
.ranking-keyword.rank-3,
.ranking-keyword.rank-4,
.ranking-keyword.rank-5,
.ranking-keyword.rank-6,
.ranking-keyword.rank-7,
.ranking-keyword.rank-other {
    color: #000000;
    font-weight: 600;
}

/* 호버 효과 - 모든 순위에 적용 */
.ranking-keyword:hover {
    transform: scale(1.08) translateX(2px);
    filter: brightness(1.15);
}

/* 모바일에서 폰트 크기 조정 - 모든 순위 동일 */
@media (max-width: 768px) {
    .ranking-keyword {
        font-size: 0.875rem;
    }
}