:root {
    --bg-dark: #fcfaf6;
    --bg-card: #ffffff;
    --bg-sidebar: #fcfcfc;
    --accent: #ff85b2;
    --accent-hover: #ff649f;
    --accent-secondary: #00a8ff;
    --text-primary: #334155;
    --text-secondary: #64748b;
    --danger: #ff4d4f;
    --success: #52c41a;
    --border: #e2e8f0;
    --sidebar-width: 260px;
    --radius: 4px;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'PingFang SC', 'Microsoft JhengHei', sans-serif; }

body { background-color: #f8fafc; color: var(--text-primary); overflow: hidden; height: 100vh; }
#app { display: flex; height: 100vh; }

/* Sidebar */
.sidebar { width: var(--sidebar-width); background-color: #fff; border-right: 1px solid #eee; display: flex; flex-direction: column; z-index: 100; box-shadow: 2px 0 10px rgba(0,0,0,0.02); }
.nav-logo { padding: 2rem 1.5rem; display: flex; align-items: center; gap: 0.5rem; font-size: 1.4rem; font-weight: 800; color: var(--accent); }
.nav-logo img { height: 36px; }

.nav-links { list-style: none; flex: 1; padding: 0 0.75rem; }
.nav-links li { padding: 0.9rem 1.5rem; margin: 0.3rem 0; border-radius: var(--radius); display: flex; align-items: center; gap: 1rem; cursor: pointer; color: #444; font-weight: 600; transition: all 0.2s; }
.nav-links li i { width: 20px; text-align: center; }
.nav-links li:hover { background: #fcfafc; color: var(--accent); }
.nav-links li.active { background-color: var(--accent); color: white; box-shadow: 0 4px 12px rgba(255, 133, 178, 0.2); }

.sidebar-campaign { padding: 1.2rem; margin: 1rem; background: #fff; border: 1px solid #eee; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.02); }
.sidebar-campaign label { font-size: 0.75rem; color: #888; margin-bottom: 0.5rem; display: block; font-weight: 800; }
.sidebar-campaign input { width: 100%; padding: 0.7rem; border: 1px solid #ddd; border-radius: var(--radius); background: #fcfcfc; }

.nav-footer { padding: 1.5rem; border-top: 1px solid #eee; }
.sync-status { font-size: 0.8rem; color: #999; margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; }

/* Main Content */
.content { flex: 1; overflow-y: auto; padding: 2.5rem; background-color: #fff; }
.view { display: none; max-width: 1400px; margin: 0 auto; }
.view.active { display: block; }

.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2.5rem; border-bottom: 2px solid #f8fafc; padding-bottom: 1.5rem; gap: 2rem; }
.view-header h1 { font-size: 2rem; color: #1e293b; font-weight: 900; white-space: nowrap; }

/* Buttons Style */
.btn { padding: 0.7rem 1.4rem; border-radius: var(--radius); font-weight: 800; font-size: 0.95rem; cursor: pointer; display: inline-flex; align-items: center; gap: 0.6rem; border: 1px solid transparent; transition: all 0.2s; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: white; }
.btn-warning { background: #ffcc33; color: white; }
.btn-danger { background: #ff4d4f; color: white; }
.btn-success { background: #2ecc71; color: white; }

.btn-outline-blue { background: white; border-color: #38bdf8; color: #38bdf8; }
.btn-outline-accent { background: white; border-color: var(--accent); color: var(--accent); }
.btn-outline-danger { background: white; border-color: #ff4d4f; color: #ff4d4f; }
.btn-outline-grey { background: white; border-color: #ccc; color: #334155; }
.btn-block { width: 100%; justify-content: center; }

/* Stats Bar - Original Card Style */
.stats-bar { display: flex; align-items: center; gap: 2rem; background: white; padding: 1rem 2rem; border-radius: 8px; border: 2px solid var(--accent); box-shadow: 0 4px 15px rgba(255, 133, 178, 0.1); }
.stat-item { display: flex; align-items: center; gap: 1.2rem; }
.label-stack { display: flex; flex-direction: column; align-items: flex-end; }
.stat-item .label { font-size: 0.85rem; color: var(--text-secondary); font-weight: 700; line-height: 1.2; }
.label-unit { font-size: 0.7rem; color: var(--accent); font-weight: 800; }
.stat-item .value { font-size: 2rem; color: var(--accent); font-weight: 900; }
.stat-divider { width: 1px; height: 35px; background: #f1f5f9; }

/* Filter Bar */
.toolbar { display: flex; gap: 1rem; align-items: center; }
.campaign-select { padding: 0.7rem 1rem; border: 1px solid #ddd; border-radius: var(--radius); background: white; font-weight: 700; color: #444; }

/* Tables - Pixel Perfect 4/17 */
.table-container { background: #fff; border: 1px solid #eee; border-radius: 8px; overflow-x: auto; margin-top: 1.5rem; box-shadow: 0 2px 10px rgba(0,0,0,0.02); }
table { width: 100%; border-collapse: collapse; min-width: 1400px; table-layout: fixed !important; }
th { background: #fcfcfc; padding: 1.2rem 0.5rem; font-size: 0.85rem; color: #888; border-bottom: 2px solid #f1f5f9; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; }
td { padding: 1.2rem 0.5rem; text-align: center; border-bottom: 1px solid #f1f5f9; font-weight: 600; font-size: 0.9rem; color: #334155; word-break: break-all; }
tr:hover td { background: #fcfcfc; }

/* Fixed widths for table columns to prevent squishing */
th:nth-child(1), td.order-photo-cell { width: 140px !important; } /* 圖片 */
th:nth-child(2), td.font-bold { width: 180px !important; } /* 商品名稱 */

.order-thumb { 
    width: 120px !important; 
    height: 80px !important; 
    max-width: 120px !important;
    max-height: 80px !important;
    object-fit: cover !important; 
    border-radius: 4px; 
    border: 1px solid #eee; 
    display: block; 
    margin: 0 auto; 
    cursor: zoom-in; 
    transition: transform 0.2s; 
}
.order-thumb:hover { transform: scale(1.05); }

/* Image Preview Overlay */
.image-preview-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.8); z-index: 20000; display: flex; justify-content: center; align-items: center; cursor: zoom-out; backdrop-filter: blur(5px); }
.preview-img { max-width: 90%; max-height: 90%; border-radius: 8px; box-shadow: 0 0 30px rgba(0,0,0,0.5); }

/* Order Grouping Styles */
.group-header-row td {
    background: linear-gradient(to right, rgba(255, 133, 178, 0.08), transparent) !important;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
}

.subtotal-row td {
    border-bottom: 2px solid #f0f0f0 !important;
}

/* Form Styles */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 2rem; margin-top: 2rem; }
.rate-card, .user-card { background: #fff; padding: 2rem; border-radius: 10px; border: 1px solid #eee; box-shadow: 0 4px 10px rgba(0,0,0,0.02); }
.currency-info { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1.5rem; font-size: 1.1rem; font-weight: 900; }
.currency-info .flag { font-size: 1.5rem; }

.add-user-card { background: #fff; padding: 2.5rem; border-radius: 12px; border: 2px solid var(--border); grid-column: 1 / -1; margin-bottom: 3rem; display: flex; align-items: flex-start; gap: 4rem; }
.add-user-card h3 { color: #1e293b; font-weight: 900; font-size: 1.3rem; white-space: nowrap; margin-top: 0.5rem; }
.add-user-grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1.5rem; align-items: flex-end; }

.input-group { display: flex; align-items: center; gap: 0.8rem; background: #f8fafc; border: 1px solid #ddd; border-radius: var(--radius); padding: 0.2rem 0.8rem; }
.input-group i { color: #94a3b8; }
.input-group input, .input-group select { border: none; background: transparent; padding: 0.6rem 0; width: 100%; font-weight: 600; color: #334155; outline: none; }

/* Editor Layout */
.editor-container { display: grid; grid-template-columns: 1fr 340px; gap: 2.5rem; }
.canvas-wrapper { background: #000; border-radius: 12px; height: 650px; position: relative; border: 2px dashed #333; display: flex; justify-content: center; align-items: center; overflow: hidden; }
canvas { max-width: 100%; max-height: 100%; object-fit: contain; }
.placeholder { 
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #888; 
    text-align: center; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    pointer-events: none; /* 防止干擾點擊 */
}
.placeholder i { font-size: 5rem; margin-bottom: 1.5rem; display: block; opacity: 0.2; }
.placeholder p { font-size: 1.2rem; font-weight: 700; letter-spacing: 1px; white-space: nowrap; }

.editor-controls { background: #fff; padding: 2rem; border-radius: 12px; border: 1px solid #eee; box-shadow: 0 4px 20px rgba(0,0,0,0.03); display: flex; flex-direction: column; gap: 2rem; }
.tool-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.tool-btn { padding: 1rem; border-radius: var(--radius); border: 1px solid #ddd; background: #fff; cursor: pointer; display: flex; align-items: center; gap: 1rem; font-weight: 800; font-size: 1rem; transition: all 0.2s; }
.tool-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.tool-options label { font-size: 0.85rem; color: #888; font-weight: 800; margin-bottom: 0.8rem; display: block; }
.actions { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-top: 1rem; }

/* Status Badges */
.status-badge { padding: 0.4rem 0.8rem; border-radius: 4px; font-size: 0.75rem; font-weight: 800; }
.status-unpaid { background: #fee2e2; color: #ef4444; border: 1px solid #fecaca; }
.status-pending { background: #fef3c7; color: #d97706; border: 1px solid #fde68a; }
.status-paid { background: #dcfce7; color: #16a34a; border: 1px solid #bbf7d0; }

/* Login Overlay */
#login-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(255,255,255,0.9); z-index: 10000; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(10px); }
.login-card { background: white; padding: 4rem 3rem; border-radius: 20px; width: 420px; text-align: center; border: 1px solid #eee; box-shadow: 0 25px 50px rgba(0,0,0,0.05); }
.login-card img { width: 100px; margin-bottom: 2rem; }
.login-card h2 { margin-bottom: 2.5rem; color: var(--accent); font-weight: 900; font-size: 2rem; }
.login-card .input-group { margin-bottom: 1.5rem; padding: 0.5rem 1rem; }

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

/* ==========================================================================
   MOBILE RESPONSIVE (iPhone/iPad)
   ========================================================================== */

@media (max-width: 1024px) {
    /* Global layout */
    #app { flex-direction: column; }
    
    .mobile-header { 
        display: flex; 
        justify-content: space-between; 
        align-items: center; 
        padding: 0.8rem 1.5rem; 
        background: #fff; 
        border-bottom: 1px solid #eee;
        position: sticky;
        top: 0;
        z-index: 1000;
        box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    }
    .mobile-header .nav-logo { padding: 0; font-size: 1.1rem; }
    .mobile-header .nav-logo img { height: 28px; }
    .btn-icon { background: none; border: none; font-size: 1.5rem; color: var(--text-primary); cursor: pointer; }

    /* Sidebar Drawer */
    .sidebar { 
        position: fixed; 
        top: 0; 
        left: 0; 
        height: 100vh; 
        width: 280px; 
        transform: translateX(-100%); 
        transition: transform 0.3s ease; 
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { 
        display: none; 
        position: fixed; 
        top: 0; 
        left: 0; 
        width: 100vw; 
        height: 100vh; 
        background: rgba(0,0,0,0.5); 
        z-index: 90; 
        backdrop-filter: blur(2px);
    }
    .sidebar-overlay.active { display: block; }

    /* Content Area */
    .content { padding: 1.2rem; overflow-x: hidden; }
    .view-header { flex-direction: column; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem; }
    .view-header h1 { font-size: 1.5rem; }
    .toolbar { width: 100%; overflow-x: auto; padding-bottom: 0.5rem; }
    
    /* Stats Bar */
    .stats-bar { 
        width: 100%; 
        flex-direction: column; 
        align-items: stretch; 
        gap: 1rem; 
        padding: 1rem;
    }
    .stat-item { justify-content: space-between; }
    .stat-divider { display: none; }

    /* Table to Card View */
    .table-container { border: none; box-shadow: none; overflow-x: visible; }
    table, thead, tbody, th, td, tr { display: block; }
    thead tr { position: absolute; top: -9999px; left: -9999px; }
    tr { 
        background: #fff; 
        border: 1px solid #eee; 
        border-radius: 12px; 
        margin-bottom: 2rem; /* 增加卡片間距 */
        padding: 1.2rem;
        box-shadow: 0 4px 15px rgba(0,0,0,0.04);
    }
    td { 
        border: none; 
        padding: 0.8rem 0; 
        text-align: left !important; 
        display: flex;
        flex-direction: column; /* 強制上下堆疊 */
        align-items: flex-start;
        gap: 0.4rem;
        min-height: auto;
    }
    td:before { 
        content: attr(data-label); 
        position: static; /* 恢復正常文件流 */
        width: 100%; 
        font-weight: 800; 
        color: #94a3b8; /* 標籤顏色變淡 */
        font-size: 0.75rem;
        text-transform: uppercase;
    }

    /* 圖片專屬優化 */
    td.order-photo-cell { 
        padding-left: 0; 
        text-align: center !important; 
        border-bottom: 2px solid #f8fafc; 
        margin-bottom: 1rem; 
        padding-bottom: 1.5rem;
    }
    td.order-photo-cell:before { margin-bottom: 0.5rem; }
    .order-thumb { 
        width: 100% !important; 
        height: auto !important; 
        max-height: 400px !important; 
        border-radius: 8px;
    }

    /* 編輯器優化 */
    .editor-container { grid-template-columns: 1fr; gap: 1.5rem; }
    .canvas-wrapper { height: 45vh; min-height: 300px; }
    .editor-controls { padding: 1.5rem; }
    .editor-controls .input-group { flex-direction: row; } /* 編輯器內部維持橫向 */

    /* 修正橫向模式 */
    @media (orientation: landscape) {
        .canvas-wrapper { height: 70vh; }
        .sidebar { width: 240px; }
    }
}

/* Modal & Notifications */
.custom-modal-overlay { 
    position: fixed; 
    top: 0; left: 0; 
    width: 100vw; height: 100vh; 
    background: rgba(0,0,0,0.4); 
    backdrop-filter: blur(8px); 
    z-index: 99999; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    padding: 1.5rem;
    animation: fadeIn 0.2s ease-out;
}
.custom-modal { 
    background: white; 
    padding: 2.5rem; 
    border-radius: 20px; 
    width: 100%; 
    max-width: 500px; 
    box-shadow: 0 25px 50px rgba(0,0,0,0.15); 
    max-height: 90vh; 
    overflow-y: auto; 
}
.custom-modal h3 { margin-bottom: 1.5rem; font-weight: 900; color: var(--accent); font-size: 1.4rem; }
.modal-input-group { margin-bottom: 1.2rem; }
.modal-input-group label { display: block; font-size: 0.85rem; color: #64748b; margin-bottom: 0.5rem; font-weight: 800; }
.modal-input, .modal-input-group select { 
    width: 100%; 
    padding: 0.8rem; 
    border: 2px solid #f1f5f9; 
    border-radius: 10px; 
    background: #f8fafc; 
    font-weight: 600; 
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}
.modal-input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 1rem; margin-top: 2rem; }
.modal-btn { flex: 1; padding: 1rem; border-radius: 10px; border: none; font-weight: 800; cursor: pointer; transition: all 0.2s; }
.btn-cancel { background: #f1f5f9; color: #64748b; }
.btn-save, .btn-confirm { background: var(--accent); color: white; }

/* Toast Notifications */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 100000; display: flex; flex-direction: column; gap: 10px; }
.toast-item { 
    background: white; padding: 1rem 1.5rem; border-radius: 12px; 
    box-shadow: 0 10px 25px rgba(0,0,0,0.1); 
    display: flex; align-items: center; gap: 1rem; 
    font-weight: 800; border-left: 5px solid var(--accent);
    animation: slideInRight 0.3s ease-out;
}
.toast-item.error { border-left-color: var(--danger); color: var(--danger); }
.toast-item.info { border-left-color: var(--accent-secondary); color: var(--accent-secondary); }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* User Management Cards */
.user-card { 
    background: white; 
    padding: 1.8rem; 
    border-radius: 15px; 
    border: 1px solid #f1f5f9; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    transition: transform 0.2s;
}
.user-card:hover { transform: translateY(-5px); box-shadow: 0 10px 25px rgba(0,0,0,0.06); }
.user-info { display: flex; align-items: center; gap: 1rem; }
.user-info i { font-size: 2.5rem; color: #cbd5e1; }
.user-info span { font-size: 0.8rem; color: #94a3b8; font-weight: 700; display: block; }
.edit-name-input { 
    border: none; 
    background: transparent; 
    font-size: 1.1rem; 
    font-weight: 900; 
    color: var(--text-primary); 
    width: 100%;
    outline: none;
}
.edit-name-input:focus { color: var(--accent); }
.user-actions { display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; }
.user-actions .input-group-sm { flex: 1; min-width: 120px; }
.user-actions .input-group-sm input { 
    width: 100%; padding: 0.6rem; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 0.9rem; 
}
.user-actions .btn { padding: 0.6rem 1rem; }

@media (min-width: 1025px) {
    .mobile-header { display: none; }
    .sidebar-overlay { display: none !important; }
}
/* Tiered Rates UI - Premium Edition */
.tiered-inputs {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
}

.input-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #fdf4f8; /* Soft pink background */
    padding: 10px 14px;
    border-radius: 10px;
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 133, 178, 0.05);
}

.input-row:hover {
    background: #fce9f2;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 133, 178, 0.08);
}

.input-row span {
    font-size: 0.85rem;
    color: #94a3b8; /* Slate text */
    white-space: nowrap;
    font-weight: 700;
}

.input-row input {
    width: 85px;
    border: 1px solid #ffdae9;
    background: white;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 1rem;
    text-align: right;
    font-weight: 800;
    color: var(--accent);
    outline: none;
    -webkit-appearance: none; /* Fix Safari default look */
    -moz-appearance: textfield;
}

.input-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 133, 178, 0.15);
}

/* Remove number spinners for Safari/Chrome */
.input-row input::-webkit-outer-spin-button,
.input-row input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
