/* =========================================
   全局與變數設定
   ========================================= */
:root {
    --primary-color: #233026;
    --accent-color: #c5a880;
    --bg-color: #f4f6f4;
    --text-color: #333333;
    --border-color: #e2e8f0;
    --card-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    --border-radius: 8px;
}

* {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

body.frontend {
    font-family: 'Noto Serif TC', serif;
    background-color: #fdfaf5;
}

/* =========================================
   導覽列 (Navbar)
   ========================================= */
.navbar {
    background: var(--primary-color);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 1001;
}

.navbar .brand {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 1px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-item {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 14px;
    transition: 0.3s;
    padding-bottom: 5px;
}

.nav-item:hover, .nav-item.active {
    color: white;
    font-weight: bold;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: white;
    min-width: 140px;
    box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    top: 100%;
    left: 0;
    margin-top: 5px;
    z-index: 10;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown-content a {
    color: #333;
    padding: 12px 16px;
    display: block;
    text-decoration: none;
    font-size: 14px;
}

.dropdown-content a:hover {
    background-color: #f4f6f9;
    color: var(--primary-color);
    font-weight: bold;
}

.welcome-msg {
    color: var(--accent-color);
    font-size: 14px;
    margin-right: 10px;
}

/* 側邊選單元件 (預設隱藏) */
.mobile-menu-btn {
    display: none; background: none; border: none; font-size: 28px; color: white; cursor: pointer; padding: 0;
}
.mobile-header { display: none; justify-content: space-between; align-items: center; width: 100%; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid #eee; }
.mobile-close-btn { background: none; border: none; font-size: 28px; color: var(--text-color); cursor: pointer; }
.mobile-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 999; }
.logout-btn { text-decoration: none; font-weight: bold; }

/* =========================================
   版面佈局容器
   ========================================= */
.container { max-width: 1200px; margin: 30px auto; padding: 0 20px; flex: 1; width: 100%; }
.container-sm { max-width: 800px; }
.flex-container { display: flex; gap: 20px; flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 100%; }
.flex-2 { flex: 2; min-width: 100%; }

@media (min-width: 992px) {
    .flex-1 { min-width: 350px; }
    .flex-2 { min-width: 600px; }
}

.card-section { background: white; padding: 25px; border-radius: var(--border-radius); box-shadow: var(--card-shadow); }

/* =========================================
   儀表板數據卡片
   ========================================= */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-bottom: 20px; }
.stat-card { background: white; padding: 20px 25px; border-radius: var(--border-radius); box-shadow: var(--card-shadow); border-left: 5px solid var(--primary-color); }
.stat-card.accent { border-left-color: var(--accent-color); }

/* =========================================
   表單與按鈕
   ========================================= */
.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; font-weight: bold; }
.form-control { width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: 4px; font-size: 14px; background: #fff; }
.form-control:focus { outline: none; border-color: var(--primary-color); }

.btn { background-color: var(--primary-color); color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; transition: 0.2s; font-weight: bold; }
.btn:hover { background-color: #151d17; }
.btn-accent { background-color: var(--accent-color); }
.btn-accent:hover { background-color: #b09570; }
.btn-danger { background-color: #ef4444; }
.btn-outline { background: transparent; border: 1px solid var(--primary-color); color: var(--primary-color); }
.btn-outline:hover { background: var(--primary-color); color: white; }
.btn-full { width: 100%; padding: 12px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* =========================================
   購物車明細 (Cart Item Card)
   ========================================= */
.cart-section { background: #fafbfc; padding: 15px; border-radius: 8px; border: 1px dashed #cbd5e1; margin-bottom: 20px; }
.cart-item-card { background: #ffffff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.02); }
.cart-item-card .top-row { display: flex; gap: 10px; margin-bottom: 10px; }
.cart-item-card .top-row select { margin: 0; flex: 1; }
.cart-item-card .bottom-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; align-items: end; }
.cart-item-card .field label { display: block; font-size: 11px; color: #64748b; margin-bottom: 4px; text-align: center; }
.cart-item-card .field input { margin: 0; text-align: center; padding: 6px; width: 100%; }

/* =========================================
   結帳總計區塊 (Total Box)
   ========================================= */
.crm-total-box { background: #f8fafc; padding: 20px; border-radius: 8px; border: 1px solid #e2e8f0; display: flex; flex-direction: column; gap: 12px; }
.summary-line { display: flex; justify-content: flex-end; align-items: center; width: 100%; }
.summary-line label { text-align: right; margin: 0; color: #475569; font-weight: bold; font-size: 14px; margin-right: 15px; flex: 1; }
.summary-line span, .summary-line input { width: 120px; text-align: right; margin: 0; flex-shrink: 0; }
.summary-line.total-line { margin-top: 5px; }
.summary-line.total-line label { font-size: 16px; color: #0f172a; }

/* =========================================
   過濾工具列 (Filter Bar)
   ========================================= */
.filter-bar { padding: 15px 20px; border-bottom: 1px solid #e2e8f0; display: flex; gap: 10px; align-items: center; background: #fff; border-radius: 8px 8px 0 0; flex-wrap: wrap; }
.filter-bar label { font-size: 14px; font-weight: bold; color: #475569; margin: 0; }
.filter-bar input[type="date"], .filter-bar select { margin: 0; padding: 6px 10px; }
.btn-group, .date-group, .sort-group { display: flex; gap: 5px; align-items: center; }
.sort-group { margin-left: auto; }
.btn-filter { padding: 6px 12px; font-size: 13px; border-radius: 4px; cursor: pointer; background: #f1f5f9; border: 1px solid #cbd5e1; color: #475569; transition: 0.2s; }
.btn-filter.active, .btn-filter:hover { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }

/* =========================================
   表格 (Table)
   ========================================= */
.table-responsive { width: 100%; overflow-x: auto; background: white; border-radius: 0 0 8px 8px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 700px; }
th, td { padding: 15px; text-align: left; border-bottom: 1px solid var(--border-color); font-size: 13px; }
th { background-color: #f8fafc; color: #475569; font-weight: bold; }
tr:hover { background-color: #f8fafc; }
.hover-row { cursor: pointer; }

/* =========================================
   元件與標籤 (Tags & Badges)
   ========================================= */
.status-badge { padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: bold; }
.status-pending { background-color: #fef08a; color: #9a3412; }
.status-paid { background-color: #bbf7d0; color: #166534; }
.role-boss { background-color: #d4edda; color: #155724; }
.role-staff { background-color: #e2e3e5; color: #383d41; }
.badge-method { background: #e0f2fe; color: #0369a1; padding: 4px 8px; border-radius: 4px; font-size: 12px; }
.item-chip { display: inline-block; background: #f1f5f9; color: #475569; padding: 4px 8px; border-radius: 4px; font-size: 12px; margin: 2px; }

/* =========================================
   輔助排版類別
   ========================================= */
.text-center { text-align: center; }
.text-primary { color: var(--primary-color); }
.text-accent { color: var(--accent-color); }
.text-danger { color: #ef4444; }
.text-muted { color: #64748b; }
.fw-bold { font-weight: bold; }
.fs-sm { font-size: 12px; }
.fs-md { font-size: 14px; }
.fs-lg { font-size: 18px; }
.fs-xl { font-size: 24px; }
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.mb-20 { margin-bottom: 20px; }
.mb-30 { margin-bottom: 30px; }
.p-0 { padding: 0; }
.p-20 { padding: 20px; }
.d-none { display: none !important; }

/* =========================================
   頁尾 (Footer)
   ========================================= */
footer { background: var(--primary-color); color: rgba(255,255,255,0.7); text-align: center; padding: 20px; font-size: 13px; margin-top: auto; }

/* =========================================
   特定頁面樣式
   ========================================= */
/* 首頁 */
.hero { background: linear-gradient(rgba(35, 48, 38, 0.8), rgba(35, 48, 38, 0.8)), url('https://images.unsplash.com/photo-1576092762791-dd9e2220cad1?ixlib=rb-1.2.1&auto=format&fit=crop&w=1920&q=80') center/cover; height: 40vh; display: flex; flex-direction: column; justify-content: center; align-items: center; color: white; text-align: center; }
.hero h1 { font-size: 36px; letter-spacing: 4px; margin-bottom: 10px; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; }

/* 登入頁 */
.login-wrapper { background: var(--primary-color); min-height: 100vh; display: flex; justify-content: center; align-items: center; padding: 20px; }
.login-card { background: white; padding: 40px; border-radius: var(--border-radius); box-shadow: var(--card-shadow); width: 100%; max-width: 320px; text-align: center; }

/* 模態視窗 */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center; }
.modal-content { background: #fff; padding: 25px; border-radius: 8px; width: 90%; max-width: 600px; max-height: 80vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; border-bottom: 2px solid var(--border-color); padding-bottom: 10px; }

/* =========================================
   RWD 手機版響應式設定
   ========================================= */
@media (max-width: 768px) {
    /* 側邊導覽列設定 */
    .mobile-menu-btn { display: block; }
    .nav-links {
        position: fixed; top: 0; right: -280px; width: 260px; height: 100vh;
        background: white; flex-direction: column; align-items: flex-start;
        padding: 20px; box-shadow: -2px 0 10px rgba(0,0,0,0.1); transition: right 0.3s ease; z-index: 1002;
    }
    .nav-links.active { right: 0; }
    .mobile-overlay.active { display: block; }
    .mobile-header { display: flex; }
    
    .nav-item { color: var(--text-color); width: 100%; padding: 12px 0; border-bottom: 1px solid #eee; display: block; }
    .nav-item:hover, .nav-item.active { color: var(--primary-color); }
    .welcome-msg { margin: 0; }
    
    .dropdown { width: 100%; }
    .dropdown-content { position: static; box-shadow: none; padding-left: 15px; background: transparent; display: block; border-bottom: none; }
    .dropdown-content a { padding: 10px 0; border-bottom: 1px dashed #eee; }
    
    /* 購物車明細響應式換行 */
    .cart-item-card .top-row { flex-direction: column; }
    .cart-item-card .top-row .btn-danger { width: 100%; padding: 10px; }
    .cart-item-card .bottom-row { grid-template-columns: 1fr 1fr; gap: 12px 10px; }
    .cart-item-card .bottom-row .field:nth-child(5) { grid-column: span 2; }
    
    /* 結帳總計響應式 */
    .crm-total-box { padding: 15px; }
    .summary-line label { text-align: left; font-size: 13px; margin-right: 5px; }
    .summary-line span, .summary-line input { width: 100px; }
    
    /* 過濾列響應式 */
    .filter-bar { flex-direction: column; align-items: stretch; gap: 12px; }
    .btn-group { display: flex; width: 100%; }
    .btn-group .btn-filter { flex: 1; text-align: center; }
    .date-group { display: flex; width: 100%; justify-content: space-between; }
    .date-group input { flex: 1; min-width: 0; }
    .sort-group { width: 100%; margin: 0; justify-content: space-between; }
    .sort-group select { flex: 1; margin-left: 10px; }
}
/* ==========================================
   📄 列印與 PDF 匯出專屬排版 (@media print)
   ========================================== */
@media print {
    /* 強制設定背景為純白，文字為純黑 */
    body { background: white !important; color: black !important; }
    
    /* 🌟 魔法核心：把不需要印出來的元素全部隱藏！ */
    .navbar, .card-section.flex-1, .filter-bar, .stats-grid, footer, .mobile-menu-btn { 
        display: none !important; 
    }
    
    /* 隱藏表格最後一欄的「編輯/作廢」按鈕 */
    th:last-child, td:last-child { display: none !important; }
    
    /* 釋放畫面空間，讓表格佔滿整張 A4 紙 */
    .container { max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
    .flex-container { display: block !important; }
    .card-section.flex-2 { box-shadow: none !important; padding: 0 !important; margin: 0 !important; width: 100% !important; }
    
    /* 強化表格框線，確保在 PDF 中清晰可見 */
    .table-responsive { overflow: visible !important; box-shadow: none !important; }
    table { border-collapse: collapse !important; width: 100% !important; }
    th, td { border: 1px solid #ccc !important; padding: 12px !important; text-align: left !important; }
    
    /* 強制列印出表格標題的灰色底色 */
    th { background-color: #f4f4f4 !important; color: black !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    
    /* 🌟 自動在 PDF 頂部加上報表標題 */
    .card-section.flex-2::before {
        content: '見研有限公司 (禾茶) - 區間銷售明細報表';
        display: block;
        font-size: 24px;
        font-weight: bold;
        text-align: center;
        margin-bottom: 20px;
        padding-bottom: 10px;
        border-bottom: 2px solid #333;
        color: #2b3a2a;
    }
}