/* ==========================================================================
   全聯條碼查詢 APP - 精緻核心設計系統
   ========================================================================== */

:root {
    --primary-color: #004ea2;       /* 全聯藍 - 專業信賴 */
    --primary-dark: #003670;
    --primary-light: #e6f0fa;
    --accent-color: #da251d;        /* 全聯紅 - 熱情活力 */
    --accent-hover: #b51a14;
    --accent-light: #fdeaea;
    --bg-main: #f8fafc;             /* 淺石板灰 - 極簡背景 */
    --card-bg: #ffffff;
    --text-main: #0f172a;           /* 深石板灰 - 超高易讀性 */
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-premium: 0 12px 30px rgba(0, 78, 162, 0.06);
    --shadow-hover: 0 20px 40px rgba(0, 78, 162, 0.12);
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-app: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ==========================================================================
   基礎重設與滾動條
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-app);
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* 隱藏滾動條但保留功能 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   1. 封面設計 (Cover Page)
   ========================================================================== */
.cover-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: url('封面.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.5s;
}

.cover-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(0, 54, 112, 0.85) 0%, rgba(15, 23, 42, 0.95) 100%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.cover-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 2.5rem;
    max-width: 600px;
    width: 90%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3);
    color: #ffffff;
    animation: coverFadeIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes coverFadeIn {
    0% {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(218, 37, 29, 0.2);
    border: 1px solid var(--accent-color);
    color: #ff9e99;
    padding: 6px 14px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1.5rem;
}

.cover-title {
    font-family: 'Outfit', var(--font-app);
    font-size: 2.5rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    margin-bottom: 0.75rem;
    line-height: 1.2;
}

.cover-title span {
    background: linear-gradient(135deg, #ff9e99 0%, var(--accent-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.cover-subtitle {
    font-size: 1.05rem;
    color: rgba(255, 255, 255, 0.75);
    font-weight: 300;
    margin-bottom: 2.5rem;
}

.cover-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 2rem;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(135deg, var(--accent-color) 0%, #b51a14 100%);
    color: #ffffff;
    border: none;
    padding: 16px 32px;
    border-radius: var(--radius-md);
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(218, 37, 29, 0.4);
    transition: var(--transition-smooth);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(218, 37, 29, 0.6);
}

.btn-primary:active {
    transform: translateY(-1px);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 14px 28px;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.cover-footer {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 0.5px;
}

/* ==========================================================================
   2. 主應用程式容器 (Main App Container)
   ========================================================================== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* 頂部導覽列 (App Header) */
.app-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.logo-icon {
    font-size: 1.8rem;
    color: var(--primary-color);
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    color: var(--primary-color);
}

.logo-text .text-accent {
    color: var(--accent-color);
}

.btn-install-shortcut {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--accent-light);
    border: 1px dashed var(--accent-color);
    color: var(--accent-color);
    padding: 8px 16px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-install-shortcut:hover {
    background: var(--accent-color);
    color: #ffffff;
    transform: translateY(-2px);
}

/* 搜尋欄 (Search Bar Area) */
.search-area {
    width: 100%;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    background: #f1f5f9;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    transition: var(--transition-smooth);
}

.search-box:focus-within {
    background: #ffffff;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(0, 78, 162, 0.1);
}

.search-icon {
    position: absolute;
    left: 16px;
    color: var(--text-muted);
    font-size: 1rem;
}

.search-box input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    padding: 14px 45px 14px 45px;
    font-size: 1rem;
    font-family: var(--font-app);
    color: var(--text-main);
}

.search-box input::placeholder {
    color: #94a3b8;
}

.btn-clear-search {
    position: absolute;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.15rem;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-clear-search:hover {
    color: var(--accent-color);
}

/* ==========================================================================
   分類標籤滑動列 (Responsive Tab Bar)
   ========================================================================== */
.category-tabs-container {
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    position: relative;
    padding: 0 10px;
}

.category-tabs {
    display: flex;
    overflow-x: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    scrollbar-width: none; /* Firefox */
}

.category-tabs::-webkit-scrollbar {
    display: none; /* Safari & Chrome */
}

.tab-btn {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 16px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    position: relative;
    transition: var(--transition-smooth);
}

.tab-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    opacity: 0.5;
    transition: var(--transition-smooth);
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn:hover .tab-icon {
    opacity: 0.8;
}

.tab-btn.active {
    color: var(--primary-color);
}

.tab-btn.active .tab-icon {
    opacity: 1;
    transform: scale(1.1);
}

.tab-btn::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--primary-color);
    transform: scaleX(0);
    transition: var(--transition-smooth);
}

.tab-btn.active::after {
    transform: scaleX(1);
}

.tab-scroll-indicator {
    width: 32px;
    height: 100%;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    z-index: 10;
    cursor: pointer;
    color: var(--text-muted);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
}

.scroll-left {
    left: 0;
}

.scroll-right {
    right: 0;
}

/* ==========================================================================
   主體內容區與網格 (Main Content & Grid)
   ========================================================================== */
.main-content {
    flex: 1;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1.5px solid var(--border-color);
}

.search-results-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary-color);
}

.search-results-count {
    background: var(--primary-light);
    color: var(--primary-color);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    animation: gridFadeIn 0.5s ease-out;
}

@keyframes gridFadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 商品卡片 (Product Card) */
.product-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-premium);
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    transition: var(--transition-smooth);
}

.product-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-hover);
    border-color: rgba(0, 78, 162, 0.2);
}

/* 條碼縮圖框 (Thumbnail Frame) */
.product-img-frame {
    height: 140px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.product-thumbnail {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: var(--transition-smooth);
}

.product-card:hover .product-thumbnail {
    transform: scale(1.05);
}

.product-card-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--primary-color);
    color: #ffffff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* 商品資訊 (Card Info) */
.product-info {
    padding: 14px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    gap: 6px;
}

.product-code {
    font-family: 'Outfit', var(--font-app);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-color);
    background: var(--accent-light);
    align-self: flex-start;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.product-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.4;
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 2.7em;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 3.5rem;
    color: #cbd5e1;
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.25rem;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

/* ==========================================================================
   3. 彈窗基底與放大視窗 (Modal Overlay & Wrapper)
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-wrapper {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalScaleIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalScaleIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
}

.modal-title-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 85%;
}

.modal-product-code {
    font-family: 'Outfit', var(--font-app);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent-color);
    letter-spacing: 0.5px;
}

.modal-product-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-modal-close {
    background: #e2e8f0;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-main);
    font-size: 1.1rem;
    transition: var(--transition-smooth);
}

.btn-modal-close:hover {
    background: var(--accent-color);
    color: #ffffff;
    transform: rotate(90deg);
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* 核心掃描優化區 (Scan Optimization Frame) */
.barcode-container {
    width: 100%;
    background: #ffffff; /* 強制純白 */
    border: 3px solid var(--primary-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 20px rgba(0, 78, 162, 0.05);
}

.barcode-img {
    max-width: 100%;
    max-height: 250px;
    object-fit: contain;
}

.modal-actions {
    width: 100%;
}

.btn-action-outline {
    width: 100%;
    padding: 12px;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

.btn-action-outline:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--primary-light);
}

/* ==========================================================================
   4. 手機安裝說明彈窗 (PWA Install Guide)
   ========================================================================== */
.install-guide-wrapper {
    max-width: 450px;
}

.modal-body.scrollable {
    max-height: 70vh;
    overflow-y: auto;
    align-items: stretch;
    gap: 16px;
    padding-top: 16px;
}

.guide-intro {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
    margin-bottom: 5px;
}

/* 原生安裝條 */
.native-install-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary-light) 0%, #d4e6f9 100%);
    border: 1px solid var(--primary-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 8px;
}

.native-install-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.magic-icon {
    font-size: 1.5rem;
    color: var(--primary-color);
    animation: wizardSparks 2s infinite ease-in-out;
}

@keyframes wizardSparks {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.8; }
    50% { transform: scale(1.15) rotate(10deg); opacity: 1; }
}

.native-install-info h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.native-install-info p {
    font-size: 0.75rem;
    color: var(--primary-color);
}

.btn-native-install {
    background: var(--primary-color);
    color: #ffffff;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 10px rgba(0, 78, 162, 0.2);
}

.btn-native-install:hover {
    background: var(--primary-dark);
    transform: scale(1.03);
}

/* 教學平台分頁 */
.guide-tabs {
    display: flex;
    background: #f1f5f9;
    border-radius: var(--radius-sm);
    padding: 4px;
    gap: 4px;
}

.guide-tab-btn {
    flex: 1;
    border: none;
    background: none;
    padding: 10px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

.guide-tab-btn.active {
    background: #ffffff;
    color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* 步驟卡片 */
.guide-content {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.guide-content.active {
    display: flex;
}

.step-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
}

.step-num {
    background: var(--primary-color);
    color: #ffffff;
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 900;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.step-desc {
    font-size: 0.85rem;
    color: var(--text-main);
    line-height: 1.6;
}

.step-desc strong {
    color: var(--primary-color);
}

.step-desc i {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ==========================================================================
   頁尾樣式 (Footer)
   ========================================================================== */
.app-footer {
    border-top: 1px solid var(--border-color);
    background: #ffffff;
    padding: 24px;
    text-align: center;
    margin-top: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.footer-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.footer-links a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 700;
    transition: var(--transition-smooth);
}

.footer-links a:hover {
    color: var(--accent-color);
}

.footer-links .divider {
    color: #cbd5e1;
}

/* ==========================================================================
   響應式設計調整 (Responsive Adjustments)
   ========================================================================== */

/* 桌上型/寬螢幕 */
@media (min-width: 768px) {
    .app-header {
        padding: 16px 40px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    
    .header-top {
        width: auto;
    }
    
    .search-area {
        max-width: 450px;
    }
    
    .category-tabs-container {
        padding: 0 40px;
    }
    
    .main-content {
        padding: 30px 40px;
    }
    
    .cover-actions {
        flex-direction: row;
        justify-content: center;
    }
    
    .btn-primary, .btn-secondary {
        flex: 1;
    }
}

/* 行動端與微調 */
@media (max-width: 480px) {
    .cover-content {
        padding: 1.5rem;
    }
    
    .cover-title {
        font-size: 1.85rem;
    }
    
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }
    
    .product-img-frame {
        height: 110px;
        padding: 10px;
    }
    
    .product-info {
        padding: 10px;
        gap: 4px;
    }
    
    .product-name {
        font-size: 0.85rem;
        height: 2.8em;
    }
    
    .tab-btn {
        padding: 12px 14px;
        font-size: 0.85rem;
    }
}
