/* Ensure html and body don't overflow horizontally */
html, body {
    min-height: 100vh;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
    max-width: 100vw;
}

/* Images max-width - prevent overflow */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Touch-friendly tap targets - minimum 44px */
a, button, input[type="submit"], input[type="button"], .btn {
    min-height: 44px;
    min-width: 40px;
}

/* Card responsive - vertical stack */
.card, .news-item, .feature-item, .platform-item {
    width: 100%;
    margin-bottom: 20px;
    float: none !important;
}

/* Form elements responsive */
input, select, textarea {
    width: 100%;
    max-width: 100%;
}

@media (max-width: 960px) {

    /* ==================== Header 固定頂部 ==================== */
    #header {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 60px;
        z-index: 1000;
        background: #fff;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    }

    /* Header 容器 - Logo 置中，三條線右上角 */
    .navContainer {
        width: 100% !important;
        padding: 0 15px !important;
        box-sizing: border-box;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        height: 60px !important;
        background: #fff;
        position: relative;
        z-index: 1001;
    }

    /* Logo - 水平置中 */
    #logo {
        position: static !important;
        float: none !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        flex: 1;
        order: 1;
    }

    #logo img {
        height: 35px;
        width: auto;
    }

    /* ==================== 漢堡按鈕 ==================== */
    #mobileMenuBtn {
        display: flex !important;
        order: 2;
        flex-shrink: 0;
        width: 36px;
        height: 36px;
        cursor: pointer;
        padding: 6px;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        gap: 5px;
        border-radius: 6px;
        transition: background 0.2s;
    }

    #mobileMenuBtn:hover {
        background: #f5f5f5;
    }

    #mobileMenuBtn span {
        display: block;
        width: 22px;
        height: 2px;
        background: #333;
        border-radius: 2px;
        transition: transform 0.3s ease, opacity 0.3s ease, width 0.3s ease;
        transform-origin: center;
    }

    /* X 動畫 */
    #mobileMenuBtn.open span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }
    #mobileMenuBtn.open span:nth-child(2) {
        opacity: 0;
        width: 0;
    }
    #mobileMenuBtn.open span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    /* ==================== 遮罩層 ==================== */
    #drawerOverlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 1100;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    #drawerOverlay.active {
        display: block;
        opacity: 1;
    }

    /* ==================== 右側 Drawer 選單 ==================== */
    #drawerLinks {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        top: 0;
        right: -220px;
        width: 200px;
        height: 100%;
        background: #1e1e1e;
        z-index: 1200;
        list-style: none;
        padding: 80px 0 30px;
        margin: 0;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.25);
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
    }

    #drawerLinks.active {
        right: 0;
    }

    #drawerLinks li {
        float: none !important;
        border-bottom: 1px solid #2e2e2e;
    }

    #drawerLinks li a {
        display: flex;
        align-items: center;
        padding: 14px 24px;
        color: #e0e0e0 !important;
        font-size: 15px;
        font-weight: 400;
        letter-spacing: 0.3px;
        transition: background 0.2s, color 0.2s, padding-left 0.2s;
        text-decoration: none !important;
        min-height: 44px;
    }

    #drawerLinks li a:hover {
        background: #2a2a2a;
        color: #FFB630 !important;
        padding-left: 30px;
    }

    /* 選單頂部品牌色條 */
    #drawerLinks::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 4px;
        background: #FFB630;
    }

    /* 漢堡按鈕永遠在最上層，不被 drawer 或 overlay 遮住 */
    #mobileMenuBtn {
        position: relative;
        z-index: 1300 !important;
    }

    /* ==================== 內容區域 - 可滑動 ==================== */
    body {
        padding-top: 60px; /* Header 高度 */
        min-height: 100vh;
    }

    #main-content-wrapper {
        min-height: calc(100vh - 80px) !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0;
        margin: 0;
    }

    /* ==================== Footer 手機版 ==================== */
    #footer {
        position: static;
        width: 100%;
        background: #2b2b2b !important;
        border-top: 3px solid #FFB630;
        margin-top: 0;
    }

    #footer .links {
        background: transparent;
    }

    .footerContainer {
        padding: 16px 20px 12px !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    #footer .social_media {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 8px;
        color: #aaa !important;
        font-size: 11px !important;
    }

    #footer .social_media a {
        opacity: 0.75;
    }

    .footerContainer ul {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0;
        padding: 0;
        margin: 0;
        list-style: none;
    }

    .footerContainer ul li {
        display: inline-block;
    }

    .footerContainer ul li a {
        color: #bbb !important;
        font-size: 12px;
        padding: 4px 10px;
        border-right: 1px solid #555;
        display: inline-block;
        line-height: 1.4;
    }

    .footerContainer ul li:last-child a {
        border-right: none;
    }

    #copyright {
        color: #777 !important;
        border-top: 1px solid #444 !important;
        padding-top: 10px !important;
        margin-top: 4px !important;
        text-align: center;
        font-size: 11px;
        width: 100%;
    }

    /* ==================== 手機版 mainheader 橘色背景 ==================== */
    #mainheader {
        margin-top: 0 !important;
        padding: 0 20px 20px !important;
        height: auto !important;
        min-height: auto;
        background: #FFB630 !important;
        background: -webkit-gradient(linear, left top, left bottom, from(#FFB630), to(#FFCF31)) !important;
        background: linear-gradient(to bottom, #FFB630, #FFCF31) !important;
        position: relative;
        z-index: 1;
    }

    #mainheader div.headerContent {
        width: 100% !important;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-start;
        padding: 0;
        box-sizing: border-box;
        gap: 8px;
    }

    #mainheader div.headerContent img {
        max-height: 50px;
        max-width: 80%;
        width: auto;
        height: auto;
        display: block;
    }

    #mainheader div.headerContent h1 {
        display: block;
        font-size: 20px !important;
        color: #fff;
        margin: 0;
        padding: 0;
        font-weight: bold;
        text-shadow: 0 1px 2px rgba(0,0,0,0.2);
        text-align: left;
        line-height: 1.4;
    }

    /* ==================== 輪播樣式 ==================== */
    .carousel-container {
        display: block;
        position: relative;
        overflow: hidden;
        width: 100%;
        background: #fff;
        margin-top: 0;
        padding: 16px 0 30px;
        box-sizing: border-box;
        z-index: 2;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
    }

    .desktop-column-wrapper { display: none; }

    .carousel-wrapper {
        display: flex;
        flex-wrap: nowrap;
        transition: transform 0.3s ease-in-out;
        width: 100%;
        overflow: visible;
    }

    .carousel-item {
        width: 100%;
        flex-shrink: 0;
        box-sizing: border-box;
        padding: 0 12px;
    }

    .carousel-item .columnItem {
        background: white;
        border-radius: 0;
        padding: 15px 15px 20px;
        box-shadow: none;
        min-height: 200px;
    }

    .carousel-item img {
        max-width: 100%;
        height: auto;
        display: block;
        margin: 0 auto 10px;
        border-radius: 6px;
    }

    .carousel-item h2, .carousel-item h3 {
        text-align: center;
        font-size: 16px;
        margin: 5px 0;
    }

    .carousel-item h3 {
        font-size: 14px;
        color: #666;
    }

    .carousel-item p {
        font-size: 13px;
        text-align: center;
        color: #555;
        margin: 8px 0;
    }

    .carousel-item ul {
        padding-left: 18px;
        font-size: 13px;
        color: #444;
        margin: 8px 0 0;
    }

    .carousel-item ul li {
        line-height: 24px;
    }

    /* 輪播點 */
    .carousel-dots {
        position: relative;
        bottom: auto;
        left: auto;
        transform: none;
        display: flex;
        justify-content: center;
        gap: 10px;
        margin-top: 14px;
        z-index: 10;
    }

    .carousel-dot {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background: #ccc;
        cursor: pointer;
        transition: background 0.3s;
    }

    .carousel-dot.active {
        background: #FFB630;
    }

    /* ==================== 手機版廣告圖區塊（輪播下方） ==================== */
    .mobile-banner-nav {
        width: 100%;
        padding: 0 5px;
        box-sizing: border-box;
        text-align: center;
        margin-top: 16px;
    }

    .mobile-banner-nav img {
        max-width: 100%;
        height: auto;
        border-radius: 8px;
        display: block;
        margin: 0 auto;
    }

    #mobileMenuBtn.open span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    /* ==================== DIY 第一層：條碼種類選單 ==================== */
    #mobileDiyNav {
        background: #fff;
        margin-bottom: 0;
        padding: 0;
        position: sticky;
        top: 0px;
        z-index: 100;
        border-bottom: 1px solid #eee;
    }

    #mobileDiyNav .nav-title {
        display: none;
    }

    #mobileDiyNav ul {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 0;
        padding: 0;
        margin: 0;
        list-style: none;
        width: 100%;
    }

    #mobileDiyNav ul::-webkit-scrollbar { display: none; }

    #mobileDiyNav ul li {
        flex: 1;
        min-width: 0;
    }

    #mobileDiyNav ul li a {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 7px 4px 5px;
        font-size: 14px;
        font-weight: 600;
        color: #999;
        white-space: nowrap;
        text-align: center;
        background: transparent;
        border: none;
        border-bottom: 3px solid transparent;
        text-decoration: none;
        overflow: visible;
        text-overflow: unset;
        line-height: 1;
        min-height: 36px;
    }

    #mobileDiyNav ul li a.active {
        color: #1a1a1a;
        border-bottom-color: #FFB630;
    }

    /* ==================== DIY 第二層：細項選單（從屬於第一層） ==================== */
    #diyTopMenu {
        background: #f5f5f5;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        border-bottom: 2px solid #e8e8e8;
        position: sticky;
        top: 44px;   /* 緊接在第一層下方 */
        z-index: 99;
    }

    /* 分類 Tab 列 */
    .cat-tab-bar {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        background: #f0f0f0;
        border-bottom: 1px solid #e0e0e0;
        padding: 0 4px;
        align-items: flex-end;
    }

    .cat-tab-bar::-webkit-scrollbar { display: none; }

    .cat-tab-btn {
        flex-shrink: 0;
        padding: 0% 12px 6px;
        font-size: 14px;
        font-weight: 500;
        color: #888;
        background: transparent;
        border: none;
        border-bottom: 2px solid transparent;
        cursor: pointer;
        white-space: nowrap;
        transition: color 0.2s, background 0.2s;
        border-radius: 6px 6px 0 0;
        display: flex;
        align-items: flex-end;
        margin-top: 0;
    }

    .cat-tab-btn.active {
        color: #e67e00;
        background: #fff;
        border-bottom-color: #fff;
        font-weight: 700;
    }

    /* 分類內容 Grid */
    .cat-panel {
        display: none;
        grid-template-columns: repeat(4, 1fr);
        gap: 4px;
        padding: 8px 8px 10px;
        background: #fff;
        border-top: none;
    }

    .cat-panel.active {
        display: grid;
    }

    .cat-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 8px 4px;
        gap: 4px;
        border-radius: 8px;
        text-decoration: none !important;
        background: #fafafa;
        border: 1.5px solid #eee;
        transition: background 0.15s, border-color 0.15s;
    }

    .cat-item:hover,
    .cat-item:link,
    .cat-item:visited,
    .cat-item:active {
        text-decoration: none !important;
    }

    .cat-item.selected {
        background: #FFF5E0;
        border-color: #FFB630;
    }

    .cat-item img {
        width: 30px;
        height: 30px;
        object-fit: contain;
        display: block;
    }

    .cat-item span {
        font-size: 10px;
        color: #666;
        text-align: center;
        line-height: 1.3;
        word-break: keep-all;
        text-decoration: none;
    }

    .cat-item.selected span {
        color: #e67e00;
        font-weight: 700;
    }

    /* ==================== 右側表單面板 ==================== */
    .rightPanel .grayBox {
        border: none !important;
        background: #fff !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }

    div#form {
        padding: 16px !important;
    }

    div#img {
        padding: 24px 16px !important;
        background: #f9f9f9;
        border-top: 1px solid #eee;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    /* footer styles consolidated above */
}

.mobile-only {
    display: none;
}

@media (max-width: 960px) {
    .mobile-only {
        display: flex;
    }

    .desktop-only {
        display: none !important;
    }
}