/* 모바일 반응형 CSS */

/* 기본 설정 */
* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    width: 100%;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    padding: 0;
}

/* 컨테이너 너비 제한 */
.container-fluid,
.container {
    max-width: 100vw;
    overflow-x: hidden;
}

.row {
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* 이미지 및 미디어 제한 */
img,
video,
canvas,
iframe {
    max-width: 100%;
    height: auto;
}

/* 테이블 제한 */
table {
    max-width: 100%;
}

/* 네비게이션 바 모바일 반응형 */
@media (max-width: 991.98px) {
    .navbar-brand img {
        max-width: 150px;
        height: auto;
    }

    .navbar {
        padding: 0.5rem 1rem;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1039;
        margin-top: 0;
    }

    /* 모바일에서 로고 크기 조정 */
    .navbar-brand {
        font-size: 1rem;
    }

    /* navbar 고정 + 통계 바는 일반 흐름이므로 main 여백 불필요 */
    main {
        padding-top: 0;
    }

    /* 컨테이너 상단 여백 조정 */
    main .container-fluid:first-child {
        padding-top: 1rem;
    }
}

/* 태블릿 및 소형 데스크톱 */
@media (max-width: 1199.98px) {
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* 테이블 스크롤 */
    #contentTable {
        font-size: 0.9rem;
    }

    #contentTable th,
    #contentTable td {
        padding: 0.5rem;
    }
}

/* 모바일 디바이스 */
@media (max-width: 767.98px) {
    /* 전체 너비 제한 강화 */
    * {
        max-width: 100vw;
    }

    /* main.php 레이아웃 */
    .row {
        flex-direction: column;
        width: 100%;
        margin: 0;
    }

    .row > .col,
    .row > .col-auto {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* 제품 정보 입력 영역 */
    .d-flex.border.rounded.p-3 {
        flex-direction: column !important;
        gap: 0.5rem;
        max-width: 100%;
    }

    .input-group {
        width: 100% !important;
        max-width: 100%;
    }

    .input-group > * {
        max-width: 100%;
    }

    /* 버튼 그룹 */
    .d-flex.justify-content-start.gap-2 {
        flex-direction: column;
    }

    .d-flex.justify-content-start.gap-2 button {
        width: 100%;
    }

    /* 테이블 반응형 - 모바일에서는 display: none이므로 숨김 */
    #contentGroup {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100vw;
    }

    #contentTable {
        font-size: 0.8rem;
        min-width: 800px; /* 가로 스크롤 */
        max-width: none;
    }

    #contentTable th,
    #contentTable td {
        padding: 0.25rem;
        white-space: nowrap;
    }

    /* 모바일 카드 그룹 */
    #mobileCardGroup {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* 모바일 카드 */
    .mobile-nutrition-card {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* 캔버스 영역 */
    #mainCanvasGroup {
        margin-top: 1rem;
        padding: 1rem !important;
        max-width: 100vw;
        overflow-x: hidden;
    }

    #canvasParent {
        display: flex;
        flex-direction: column;
        align-items: center;
        max-width: 100%;
    }

    #mainCanvas {
        max-width: 100%;
        width: 100%;
        height: auto;
    }

    #downloadButton {
        position: static;
        width: 100%;
        max-width: 100%;
        margin-top: 1rem;
    }

    /* 이미지 컨테이너 */
    #imagePreviewList {
        justify-content: center;
        max-width: 100%;
        overflow-x: auto;
    }

    .image-slot {
        width: 80px !important;
        height: 80px !important;
        flex-shrink: 0;
    }

    /* 공유 버튼 */
    #shareButton {
        width: 100%;
        max-width: 100%;
    }

    /* 버튼들 */
    button,
    .btn {
        max-width: 100%;
    }

    /* 스위치 영역 */
    .form-check.form-switch {
        font-size: 0.9rem;
    }

    /* 광고 영역 */
    .ad-container {
        max-width: 100%;
        overflow: hidden;
    }
}

/* 초소형 디바이스 (작은 스마트폰) */
@media (max-width: 575.98px) {
    .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        max-width: 100vw;
    }

    /* 네비게이션 */
    .navbar {
        padding: 0.25rem 0.5rem;
        top: 0;
        margin-top: 0;
        max-width: 100vw;
    }

    /* navbar 고정 + 통계 바는 일반 흐름이므로 main 여백 불필요 */
    main {
        padding-top: 0;
    }

    /* 카드 */
    .card {
        font-size: 0.85rem;
        max-width: 100%;
    }

    .card-body {
        padding: 0.75rem;
        max-width: 100%;
    }

    /* 버튼 */
    .btn {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
        max-width: 100%;
    }

    .btn-sm {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    /* 입력 필드 */
    .form-control,
    .input-group-text {
        font-size: 0.875rem;
        max-width: 100%;
    }

    /* 모달 */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100vw - 1rem);
    }

    /* Floating 버튼 크기 조정 */
    .btn.position-fixed {
        width: 50px !important;
        height: 50px !important;
        bottom: 15px !important;
        right: 15px !important;
    }

    .btn.position-fixed i {
        font-size: 1.2rem !important;
    }

    /* 오프캔버스 */
    .offcanvas {
        font-size: 0.9rem;
        max-width: 90vw;
    }

    /* 이미지 슬롯 */
    .image-slot {
        width: 60px !important;
        height: 60px !important;
    }

    /* 모든 텍스트 요소 줄바꿈 */
    p, h1, h2, h3, h4, h5, h6, span, div, a, label {
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 100%;
    }
}

/* 가로 모드 스마트폰 */
@media (max-width: 767.98px) and (orientation: landscape) {
    .navbar {
        min-height: 60px;
    }

    #mainCanvasGroup {
        max-height: 80vh;
        overflow-y: auto;
    }
}

/* 테이블 반응형 스타일 */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* 영양성분 카드 스타일 */
.nutrition-card {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.nutrition-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.nutrition-card:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Offcanvas 스타일 개선 */
.offcanvas-start,
.offcanvas-end {
    max-width: 90vw;
}

@media (min-width: 576px) {
    .offcanvas-start {
        max-width: 400px;
    }

    .offcanvas-end {
        max-width: 450px;
    }
}

/* 로그인 버튼 영역 */
#mobile-login-section {
    margin-bottom: 1rem;
}

#mobile-login-before,
#mobile-login-after {
    width: 100%;
}

/* 스크롤바 스타일 (웹킷 브라우저) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 터치 디바이스 최적화 */
@media (hover: none) and (pointer: coarse) {
    /* 호버 효과 제거 */
    .nutrition-card:hover {
        transform: none;
        box-shadow: none;
    }
}

/* 데스크톱에서 모바일 전용 요소 숨김 */
@media (min-width: 992px) {
    .d-lg-none {
        display: none !important;
    }

    .d-none.d-lg-flex {
        display: flex !important;
    }

    .d-none.d-lg-block {
        display: block !important;
    }
}

/* 모바일용 카드 스타일 */
.mobile-nutrition-card {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    max-width: 100%;
    overflow-x: hidden;
    word-wrap: break-word;
}

.mobile-nutrition-card-header {
    background: linear-gradient(135deg, #2c5530 0%, #3d7040 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: bold;
    font-size: 1.1rem;
    max-width: 100%;
    overflow-wrap: break-word;
}

.mobile-nutrition-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
    max-width: 100%;
    overflow-x: hidden;
}

.mobile-nutrition-row:last-child {
    border-bottom: none;
}

.mobile-nutrition-label {
    font-weight: 600;
    color: #495057;
    flex: 0 0 40%;
    max-width: 40%;
    overflow-wrap: break-word;
}

.mobile-nutrition-value {
    flex: 0 0 55%;
    max-width: 55%;
    text-align: right;
    color: #212529;
    overflow-wrap: break-word;
}

.mobile-nutrition-value input {
    width: 100%;
    max-width: 150px;
    float: right;
}

.mobile-nutrition-value .form-check {
    display: inline-block;
    margin-right: 8px;
    margin-bottom: 8px;
    max-width: 100%;
}

/* Bootstrap form-switch 스타일 유지 */
.mobile-nutrition-value .form-check.form-switch {
    display: block !important;
    padding-left: 2.5em !important;
    min-height: 1.5rem;
}

.mobile-nutrition-value .form-check-input[type="radio"],
.mobile-nutrition-value .form-check-input[type="checkbox"] {
    width: 1em !important;
    height: 1em !important;
    margin-top: 0.25em !important;
    vertical-align: top !important;
    background-size: contain !important;
    border: 1px solid rgba(0,0,0,.25) !important;
    float: none !important;
}

.mobile-nutrition-value .form-check-input[type="radio"] {
    border-radius: 50% !important;
}

.mobile-nutrition-value .form-check.form-switch .form-check-input {
    width: 2em !important;
    height: 1em !important;
    margin-left: -2.5em !important;
    border-radius: 2em !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba%280, 0, 0, 0.25%29'/%3e%3c/svg%3e") !important;
    background-position: left center !important;
    transition: background-position .15s ease-in-out !important;
}

.mobile-nutrition-value .form-check.form-switch .form-check-input:checked {
    background-position: right center !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e") !important;
}

.mobile-nutrition-value .form-check-label {
    display: inline-block;
    margin-left: 0.5em;
}

/* 맨 위로 버튼 스타일 */
#scrollToTopBtn {
    transition: opacity 0.3s ease-in-out;
}

#scrollToTopBtn button {
    transition: transform 0.2s ease;
    cursor: pointer;
}

#scrollToTopBtn button:hover {
    transform: scale(1.1);
}

#scrollToTopBtn button:active {
    transform: scale(0.95);
}

#scrollProgressCircle {
    transition: stroke-dashoffset 0.3s ease;
}

/* 공유 페이지 배너 */
.share-notice {
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* 영양성분 바로가기 카드 스타일 */
.nutrition-shortcut-card,
.nutrition_link_buttton {
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.nutrition-shortcut-card:hover,
.nutrition_link_buttton:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.nutrition-shortcut-card:active,
.nutrition_link_buttton:active {
    transform: translateY(0);
}

/* 카드 강조 효과 */
.mobile-nutrition-card.highlight-card {
    animation: highlightPulse 1.5s ease-in-out;
    border-color: #0d6efd;
}

@keyframes highlightPulse {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 4px 20px rgba(13, 110, 253, 0.4);
        transform: scale(1.02);
    }
}

/* 모바일 카드 내 Accordion 스타일 */
.mobile-nutrition-card .accordion {
    margin-top: 12px;
}

.mobile-nutrition-card .accordion-button {
    padding: 10px 12px;
    font-size: 0.9rem;
    background-color: #fff;
    color: #dc3545;
    font-weight: 600;
}

.mobile-nutrition-card .accordion-button:not(.collapsed) {
    background-color: #fff3cd;
    color: #856404;
    box-shadow: none;
}

.mobile-nutrition-card .accordion-button:focus {
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.25);
}

.mobile-nutrition-card .accordion-body {
    padding: 12px;
    font-size: 0.85rem;
    background-color: #fffbf0;
}

.mobile-nutrition-card .accordion-item {
    border-color: #ffc107;
}

/* 프린트 스타일 */
@media print {
    .navbar,
    .offcanvas,
    .btn.position-fixed,
    button,
    .no-print {
        display: none !important;
    }

    body {
        margin: 0;
        padding: 0;
    }

    #mainCanvas {
        max-width: 100%;
        page-break-inside: avoid;
    }
}