* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    /* Purple Pastel Theme - Professional */
    --primary: #7c6ce7;
    --primary-light: #b8b0f5;
    --primary-dark: #5a4db8;
    --primary-soft: #ebe8fc;
    --primary-gradient: linear-gradient(135deg, #7c6ce7 0%, #a99ef5 100%);
    --primary-gradient-dark: linear-gradient(135deg, #5a4db8 0%, #7c6ce7 50%, #a99ef5 100%);
    
    --success: #10b981;
    --success-light: #ecfdf5;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --info: #6366f1;
    
    --bg: #f8f7fc;
    --bg-secondary: #f1eff9;
    --card-bg: #ffffff;
    --text: #1e1b4b;
    --text-secondary: #4c4687;
    --text-muted: #9490b3;
    --border: #e5e2f0;
    --border-light: #f0eef7;
    
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    
    --shadow-xs: 0 1px 2px rgba(124,108,231,0.04);
    --shadow-sm: 0 2px 8px rgba(124,108,231,0.06);
    --shadow: 0 4px 16px rgba(124,108,231,0.08);
    --shadow-md: 0 8px 24px rgba(124,108,231,0.1);
    --shadow-lg: 0 16px 48px rgba(124,108,231,0.12);
    --shadow-primary: 0 8px 24px rgba(124,108,231,0.25);
    
    --sidebar-width: 280px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Thai', 'SF Pro Display', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
}

/* ===== LAYOUT ===== */
.app-wrapper { display: flex; min-height: 100vh; width: 100%; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--primary-gradient-dark);
    color: #fff;
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 200; padding: 32px 20px;
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header { 
    display: flex; align-items: center; gap: 14px; 
    margin-bottom: 40px; padding-bottom: 24px; 
    border-bottom: 1px solid rgba(255,255,255,0.1); 
}
.sidebar-logo { 
    width: 52px; height: 52px; 
    border-radius: 16px; 
    object-fit: cover; 
    border: 2px solid rgba(255,255,255,0.25);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.sidebar-brand h2 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.3px; }
.sidebar-brand p { font-size: 0.72rem; opacity: 0.6; margin-top: 3px; font-weight: 500; }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.sidebar-item {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 18px; border: none; background: none;
    color: rgba(255,255,255,0.7); font-size: 0.9rem; font-weight: 500;
    border-radius: var(--radius-sm); cursor: pointer; 
    transition: all var(--transition);
    text-align: left; width: 100%;
}
.sidebar-item:hover { background: rgba(255,255,255,0.1); color: #fff; }
.sidebar-item.active { 
    background: rgba(255,255,255,0.18); 
    color: #fff; 
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.sidebar-icon { font-size: 1.2rem; width: 26px; text-align: center; }

.sidebar-footer { margin-top: auto; padding-top: 24px; border-top: 1px solid rgba(255,255,255,0.1); }
.sidebar-logout { 
    width: 100%; padding: 14px 18px; border: none; 
    background: rgba(255,255,255,0.08); 
    color: rgba(255,255,255,0.85); 
    font-size: 0.85rem; font-weight: 600; 
    border-radius: var(--radius-sm); cursor: pointer; 
    transition: all var(--transition); text-align: left; 
}
.sidebar-logout:hover { background: rgba(239,68,68,0.2); color: #fff; }

.sidebar-overlay { 
    display: none; position: fixed; 
    top: 0; left: 0; right: 0; bottom: 0; 
    background: rgba(30,27,75,0.5); 
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 199; 
}
.sidebar-overlay.open { display: block; }

/* ===== MAIN CONTENT ===== */
.main-content { flex: 1; display: flex; flex-direction: column; min-height: 100vh; width: 100%; }

/* ===== HEADER ===== */
.header {
    display: flex; align-items: center; gap: 16px;
    background: var(--primary-gradient-dark); color: #fff;
    padding: 18px 24px; 
    padding-top: calc(18px + env(safe-area-inset-top, 0));
    position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow-md);
}
.menu-btn { 
    background: rgba(255,255,255,0.15); 
    border: none; color: #fff; 
    font-size: 1.3rem; 
    padding: 10px 14px; 
    border-radius: var(--radius-sm); 
    cursor: pointer; 
    line-height: 1;
    transition: all var(--transition);
}
.menu-btn:active { background: rgba(255,255,255,0.25); transform: scale(0.95); }
.header-logo { 
    width: 44px; height: 44px; 
    border-radius: 14px; 
    object-fit: cover; 
    border: 2px solid rgba(255,255,255,0.25);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-text { flex: 1; }
.header h1 { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.3px; }
.header .subtitle { font-size: 0.72rem; opacity: 0.7; margin-top: 2px; font-weight: 500; }

/* ===== BOTTOM NAV ===== */
.tabs {
    display: flex; 
    background: #fff; 
    position: fixed; bottom: 0; left: 0; right: 0;
    z-index: 99; 
    padding: 10px 8px; 
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 6px));
    box-shadow: 0 -4px 24px rgba(124,108,231,0.08); 
    justify-content: space-around;
    border-top: 1px solid var(--border-light);
}
.tab {
    flex: 1; padding: 10px 4px; border: none; background: none;
    font-size: 0.65rem; color: var(--text-muted); cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    border-radius: var(--radius-sm); transition: all var(--transition); 
    position: relative; font-weight: 500;
}
.tab .tab-icon { font-size: 1.25rem; transition: transform var(--transition); }
.tab.active { color: var(--primary); font-weight: 600; }
.tab.active .tab-icon { transform: scale(1.1); }
.tab.active::after { 
    content: ''; position: absolute; top: 0; 
    left: 50%; transform: translateX(-50%); 
    width: 24px; height: 3px; 
    background: var(--primary-gradient); 
    border-radius: 0 0 4px 4px; 
}

/* ===== PAGE CONTENT ===== */
.tab-content { 
    display: none; flex: 1; 
    padding: 24px 20px; 
    animation: fadeIn 0.25s ease; 
    max-width: 680px; 
    margin: 0 auto; width: 100%; 
}
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== TOGGLE BAR ===== */
.toggle-bar { 
    display: flex; 
    background: var(--card-bg); 
    border-radius: var(--radius); 
    padding: 5px; 
    margin-bottom: 20px; 
    box-shadow: var(--shadow); 
    border: 1px solid var(--border-light);
}
.toggle-btn { 
    flex: 1; padding: 14px 16px; 
    border: none; border-radius: var(--radius-sm); 
    font-size: 0.88rem; font-weight: 600; 
    cursor: pointer; transition: all var(--transition); 
    color: var(--text-muted); background: none; 
}
.toggle-btn.active { 
    background: var(--primary-gradient); 
    color: #fff; 
    box-shadow: var(--shadow-primary); 
}

/* ===== SEARCH ===== */
.search-bar { margin-bottom: 16px; }
.search-bar input { 
    width: 100%; padding: 16px 20px; 
    border: 2px solid transparent; 
    border-radius: var(--radius); 
    font-size: 15px; outline: none; 
    background: var(--card-bg); 
    color: var(--text); 
    box-shadow: var(--shadow);
    transition: all var(--transition);
}
.search-bar input:focus { 
    border-color: var(--primary-light);
    box-shadow: var(--shadow-md), 0 0 0 4px var(--primary-soft); 
}
.search-bar input::placeholder { color: var(--text-muted); }

/* ===== CARDS ===== */
.card-list { display: flex; flex-direction: column; gap: 14px; }
.card { 
    background: var(--card-bg); 
    border-radius: var(--radius); 
    padding: 20px; 
    box-shadow: var(--shadow); 
    position: relative; 
    overflow: hidden; 
    transition: all var(--transition);
    border: 1px solid var(--border-light);
}
.card:hover { 
    box-shadow: var(--shadow-md); 
    transform: translateY(-2px);
}
.card::before { 
    content: ''; position: absolute; 
    top: 0; left: 0; 
    width: 4px; height: 100%; 
    border-radius: 4px 0 0 4px;
}
.card.sold::before { background: linear-gradient(180deg, var(--success), #059669); }
.card.instock::before { background: linear-gradient(180deg, var(--warning), #d97706); }
.card.personal::before { background: linear-gradient(180deg, var(--primary-light), var(--primary)); }
.card.scammed::before { background: linear-gradient(180deg, var(--danger), #dc2626); }

.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.card-badge { 
    font-size: 0.68rem; 
    padding: 5px 12px; 
    border-radius: 20px; 
    font-weight: 600;
    letter-spacing: 0.2px;
}
.badge-sold { background: var(--success-light); color: var(--success); }
.badge-instock { background: var(--warning-light); color: #b45309; }
.badge-personal { background: var(--primary-soft); color: var(--primary); }
.badge-scammed { background: var(--danger-light); color: var(--danger); }
.badge-carried { background: var(--primary-soft); color: var(--primary-dark); }

.card-image { 
    width: 100%; max-height: 200px; 
    object-fit: cover; 
    border-radius: var(--radius-sm); 
    margin-bottom: 12px; 
    cursor: pointer;
    transition: transform var(--transition);
}
.card-image:hover { transform: scale(1.02); }

.card-info { margin-top: 8px; }
.card-row { 
    display: flex; justify-content: space-between; 
    align-items: center; padding: 8px 0; 
    border-bottom: 1px solid var(--border-light); 
}
.card-row:last-child { border-bottom: none; }
.card-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.card-value { font-size: 0.85rem; color: var(--text); font-weight: 600; text-align: right; }
.card-value.highlight { color: var(--success); font-weight: 700; }
.card-divider { height: 1px; background: var(--border); margin: 12px 0; }
.card-profit { 
    margin-top: 14px; font-weight: 700; 
    font-size: 0.88rem; padding: 10px 16px; 
    border-radius: var(--radius-sm); 
    display: inline-block; 
    background: var(--success-light); 
    color: var(--success); 
}
.card-profit.negative { background: var(--danger-light); color: var(--danger); }
.card-actions { margin-top: 14px; display: flex; gap: 10px; }

/* ===== BUTTONS ===== */
.btn { 
    width: 100%; padding: 16px; 
    border: none; border-radius: var(--radius-sm); 
    font-size: 0.95rem; font-weight: 700; 
    cursor: pointer; transition: all var(--transition);
    letter-spacing: 0.2px;
}
.btn:active { transform: scale(0.98); }
.btn-primary { 
    background: var(--primary-gradient); 
    color: #fff; 
    box-shadow: var(--shadow-primary); 
}
.btn-primary:hover { box-shadow: 0 12px 32px rgba(124,108,231,0.35); }
.btn-success { 
    background: linear-gradient(135deg, var(--success), #059669); 
    color: #fff; 
    box-shadow: 0 8px 24px rgba(16,185,129,0.25); 
}
.btn-edit { 
    background: var(--primary-soft); 
    border: none; color: var(--primary); 
    font-size: 0.78rem; font-weight: 600; 
    padding: 10px 18px; 
    border-radius: var(--radius-sm); 
    cursor: pointer;
    transition: all var(--transition);
}
.btn-edit:hover { background: #ddd8f7; }
.btn-delete { 
    background: var(--danger-light); 
    border: none; color: var(--danger); 
    font-size: 0.78rem; font-weight: 600; 
    padding: 10px 18px; 
    border-radius: var(--radius-sm); 
    cursor: pointer;
    transition: all var(--transition);
}
.btn-delete:hover { background: #fde4e4; }

/* ===== IMAGE UPLOAD ===== */
.image-upload { 
    position: relative; 
    border: 2px dashed var(--border); 
    border-radius: var(--radius-sm); 
    overflow: hidden; 
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-secondary);
}
.image-upload:hover { border-color: var(--primary); background: var(--primary-soft); }
.image-upload input[type="file"] { 
    position: absolute; top: 0; left: 0; 
    width: 100%; height: 100%; 
    opacity: 0; cursor: pointer; z-index: 2; 
}
.image-upload-placeholder { 
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center; 
    padding: 28px; color: var(--text-muted); 
    font-size: 0.85rem; gap: 8px; 
    font-weight: 500;
}
.image-upload-placeholder span:first-child { font-size: 1.8rem; }
.image-preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: var(--radius-sm); }
.sell-product-preview { margin-bottom: 14px; text-align: center; }
.sell-product-preview img { 
    max-width: 100%; max-height: 160px; 
    border-radius: var(--radius-sm); 
    object-fit: cover;
    box-shadow: var(--shadow);
}

/* ===== FORMS ===== */
.form { 
    background: var(--card-bg); 
    padding: 28px 24px; 
    border-radius: var(--radius); 
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}
.form-group { margin-bottom: 20px; }
.form-group label { 
    display: block; 
    font-size: 0.8rem; 
    font-weight: 600; 
    color: var(--primary-dark); 
    margin-bottom: 8px;
    letter-spacing: 0.2px;
}
.form-group input, .form-group select { 
    width: 100%; padding: 14px 18px; 
    border: 2px solid var(--border); 
    border-radius: var(--radius-sm); 
    font-size: 16px; outline: none; 
    background: var(--bg-secondary); 
    color: var(--text); 
    -webkit-appearance: none; appearance: none; 
    transition: all var(--transition); 
    line-height: 1.5; 
}
.form-group input:focus, .form-group select:focus { 
    border-color: var(--primary); 
    box-shadow: 0 0 0 4px var(--primary-soft); 
    background: #fff; 
}
.form-group input::placeholder { color: var(--text-muted); }

/* ===== FILTER ===== */
.filter-bar { margin-bottom: 14px; }
.filter-bar select { 
    width: 100%; padding: 14px 18px; 
    border: 2px solid var(--border); 
    border-radius: var(--radius-sm); 
    font-size: 16px; background: var(--card-bg); 
    color: var(--text); outline: none; 
    box-shadow: var(--shadow-xs); 
    line-height: 1.5; 
    -webkit-appearance: none; appearance: none;
    cursor: pointer;
}
.filter-bar select:focus { border-color: var(--primary); }

/* ===== MONTH SELECTOR ===== */
.month-selector { 
    display: flex; gap: 10px; 
    overflow-x: auto; padding: 6px 0; 
    margin-bottom: 18px; 
    -webkit-overflow-scrolling: touch; 
}
.month-selector::-webkit-scrollbar { display: none; }
.month-btn { 
    flex: 0 0 auto; padding: 10px 18px; 
    border-radius: 24px; border: 2px solid var(--border); 
    background: var(--card-bg); color: var(--text-secondary); 
    font-size: 0.8rem; font-weight: 600; 
    cursor: pointer; transition: all var(--transition); 
    white-space: nowrap; 
}
.month-btn:hover { border-color: var(--primary-light); }
.month-btn.active { 
    background: var(--primary-gradient); 
    color: #fff; 
    border-color: transparent;
    box-shadow: var(--shadow-primary); 
}

/* ===== DASHBOARD ===== */
.dashboard { display: flex; flex-direction: column; gap: 14px; width: 100%; }
.dash-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dash-card { 
    background: var(--card-bg); 
    border-radius: var(--radius); 
    padding: 22px 18px; 
    text-align: center; 
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    transition: all var(--transition);
}
.dash-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.dash-card.dash-highlight { 
    background: var(--primary-gradient-dark); 
    padding: 32px 20px; 
    border-radius: var(--radius-lg); 
    box-shadow: var(--shadow-lg);
    border: none;
}
.dash-card.dash-highlight .dash-value { font-size: 2.2rem; color: #fff; }
.dash-card.dash-highlight .dash-label { color: rgba(255,255,255,0.75); }

.dash-card.dash-danger .dash-value { color: var(--danger); }

.dash-card.dash-capital { 
    background: linear-gradient(135deg, var(--primary-soft), #e8e4fa); 
    border: 1px solid rgba(124,108,231,0.15); 
}
.dash-card.dash-capital .dash-value { color: var(--primary); }

.dash-card.dash-profit { 
    background: linear-gradient(135deg, var(--success-light), #d1fae5); 
    border: 1px solid rgba(16,185,129,0.15); 
    padding: 22px 18px; 
}
.dash-card.dash-profit .dash-value { font-size: 1.8rem; color: var(--success); }

.dash-icon { display: block; font-size: 1.2rem; margin-bottom: 8px; }
.dash-value { display: block; font-size: 1.35rem; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.dash-label { display: block; font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }

.profit-toggle { 
    display: flex; gap: 4px; 
    margin-bottom: 12px; 
    background: rgba(0,0,0,0.06); 
    border-radius: var(--radius-sm); 
    padding: 4px; 
}
.profit-mode-btn { 
    flex: 1; padding: 6px 10px; 
    border: none; border-radius: 8px; 
    font-size: 0.68rem; font-weight: 600; 
    cursor: pointer; color: var(--text-muted); 
    background: none; transition: all var(--transition); 
}
.profit-mode-btn.active { 
    background: var(--primary-gradient); 
    color: #fff; 
    box-shadow: 0 2px 8px rgba(124,108,231,0.25); 
}

/* ===== TOP SELLING ===== */
.section-title { 
    font-size: 1rem; 
    font-weight: 700; 
    margin-bottom: 14px;
    color: var(--text);
}
.top-list { display: flex; flex-direction: column; gap: 12px; }
.top-item { 
    background: var(--card-bg); 
    border-radius: var(--radius); 
    padding: 18px 20px; 
    box-shadow: var(--shadow); 
    display: flex; align-items: center; 
    gap: 16px;
    border: 1px solid var(--border-light);
    transition: all var(--transition);
}
.top-item:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.top-rank { 
    width: 40px; height: 40px; 
    border-radius: var(--radius-sm); 
    display: flex; align-items: center; 
    justify-content: center; 
    font-weight: 800; font-size: 0.95rem; 
    color: #fff; flex-shrink: 0; 
}
.top-rank.rank-1 { background: linear-gradient(135deg, #fbbf24, #f59e0b); box-shadow: 0 4px 12px rgba(251,191,36,0.3); }
.top-rank.rank-2 { background: linear-gradient(135deg, #9ca3af, #6b7280); }
.top-rank.rank-3 { background: linear-gradient(135deg, #f97316, #ea580c); }
.top-rank.rank-other { background: var(--primary-gradient); }

.top-info { flex: 1; }
.top-name { font-weight: 700; font-size: 0.9rem; color: var(--text); }
.top-detail { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }
.top-count { font-weight: 800; font-size: 1.1rem; color: var(--primary); }
.top-bar { height: 5px; background: var(--border); border-radius: 5px; margin-top: 10px; overflow: hidden; }
.top-bar-fill { height: 100%; border-radius: 5px; background: var(--primary-gradient); transition: width 0.6s ease; }

/* ===== MISC ===== */
.total-badge { 
    background: var(--primary-soft); 
    color: var(--primary-dark); 
    font-size: 0.8rem; font-weight: 600; 
    padding: 10px 18px; 
    border-radius: var(--radius-sm); 
    margin-bottom: 14px; 
    text-align: center;
    border: 1px solid rgba(124,108,231,0.1);
}
.empty-state { 
    text-align: center; padding: 56px 24px; 
    color: var(--text-muted); font-size: 0.95rem; 
    background: var(--card-bg); 
    border-radius: var(--radius); 
    border: 2px dashed var(--border);
    font-weight: 500;
}

/* ===== PAGINATION ===== */
.pagination { 
    display: flex; align-items: center; 
    justify-content: center; gap: 8px; 
    margin-top: 28px; padding: 18px 0; 
    grid-column: 1 / -1; 
}
.page-btn { 
    width: 42px; height: 42px; 
    border: 2px solid var(--border); 
    border-radius: var(--radius-sm); 
    background: var(--card-bg); 
    color: var(--text-secondary); 
    font-size: 0.88rem; font-weight: 600; 
    cursor: pointer; 
    display: flex; align-items: center; 
    justify-content: center; 
    transition: all var(--transition); 
}
.page-btn:hover { border-color: var(--primary-light); }
.page-btn.active { 
    background: var(--primary-gradient); 
    color: #fff; 
    border-color: transparent;
    box-shadow: var(--shadow-primary); 
}
.page-btn.disabled { opacity: 0.35; cursor: not-allowed; }
.page-dots { font-size: 0.85rem; color: var(--text-muted); }

/* ===== TOAST ===== */
.toast { 
    position: fixed; bottom: 100px; 
    left: 50%; transform: translateX(-50%); 
    background: var(--text); color: #fff; 
    padding: 16px 32px; 
    border-radius: var(--radius); 
    font-size: 0.9rem; font-weight: 600; 
    z-index: 1000; 
    box-shadow: var(--shadow-lg); 
    animation: toastIn 0.35s cubic-bezier(0.16, 1, 0.3, 1); 
}
@keyframes toastIn { 
    from { opacity: 0; transform: translateX(-50%) translateY(16px) scale(0.95); } 
    to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); } 
}

/* ===== MODAL ===== */
.modal { 
    position: fixed; top: 0; left: 0; 
    width: 100%; height: 100%; 
    background: rgba(30,27,75,0.6); 
    backdrop-filter: blur(12px); 
    -webkit-backdrop-filter: blur(12px); 
    z-index: 300; 
    display: flex; align-items: flex-end; 
    justify-content: center; 
}
/* โครง modal: หัวตรึง เนื้อหาเลื่อน ปุ่มตรึงล่าง (ใช้เหมือนกันทั้งมือถือและคอม) */
.modal-content {
    background: var(--card-bg);
    width: 100%; max-width: 560px;
    max-height: 92vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-header {
    display: flex; justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin: 0;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-light);
    flex: 0 0 auto;
}
.modal-header h3 { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.modal-close { 
    background: var(--bg-secondary); 
    border: none; font-size: 1.4rem; 
    cursor: pointer; color: var(--text-muted); 
    padding: 10px 14px; 
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.modal-close:hover { background: var(--border); }

.image-viewer-content { 
    display: flex; align-items: center; 
    justify-content: center; 
    width: 100%; height: 100%; 
    padding: 24px; 
}
.image-viewer-content img { 
    max-width: 100%; max-height: 85vh; 
    border-radius: var(--radius); 
    box-shadow: var(--shadow-lg); 
    object-fit: contain; 
}

/* ===== LOGIN ===== */
.login-screen { 
    position: fixed; top: 0; left: 0; 
    width: 100%; height: 100%; 
    background: linear-gradient(160deg, #f1eff9 0%, #e5e1f5 40%, #d9d3f0 100%); 
    display: flex; align-items: center; 
    justify-content: center; z-index: 500; 
    padding: 24px; 
}
.login-card { 
    background: #fff; 
    border-radius: var(--radius-xl); 
    padding: 52px 36px; 
    width: 100%; max-width: 380px; 
    text-align: center; 
    box-shadow: var(--shadow-lg); 
    animation: loginIn 0.5s cubic-bezier(0.16, 1, 0.3, 1); 
}
@keyframes loginIn { 
    from { opacity: 0; transform: scale(0.9) translateY(24px); } 
    to { opacity: 1; transform: scale(1) translateY(0); } 
}
.login-logo { 
    width: 88px; height: 88px; 
    border-radius: 24px; 
    object-fit: cover; 
    margin-bottom: 20px; 
    border: 3px solid var(--primary-light);
    box-shadow: var(--shadow-md);
}
.login-card h2 { 
    font-size: 1.6rem; font-weight: 800; 
    color: var(--primary); margin-bottom: 6px;
    letter-spacing: -0.5px;
}
.login-subtitle { 
    color: var(--text-muted); 
    font-size: 0.9rem; 
    margin-bottom: 32px;
    font-weight: 500;
}
.login-form .form-group { margin-bottom: 20px; }
.login-form input { 
    width: 100%; padding: 18px; 
    border: 2px solid var(--border); 
    border-radius: var(--radius-sm); 
    font-size: 16px; text-align: center; 
    outline: none; background: var(--bg-secondary); 
    color: var(--text);
    font-weight: 500;
}
.login-form input:focus { 
    border-color: var(--primary); 
    box-shadow: 0 0 0 4px var(--primary-soft); 
    background: #fff; 
}
.login-form input::placeholder { color: var(--text-muted); }
.login-error { 
    color: var(--danger); 
    font-size: 0.85rem; 
    margin-top: 14px;
    font-weight: 600;
}

/* ===== RESPONSIVE ===== */

/* Desktop */
@media (min-width: 769px) {
    .tabs { display: none; }
    .main-content { padding-bottom: 48px; }
    .tab-content { padding: 32px 24px; max-width: 780px; }
    .header { padding: 20px 40px; }

    .card-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 18px;
    }
    .top-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 14px;
    }
}

/* Large desktop */
@media (min-width: 1200px) {
    .tab-content { padding: 40px 28px; max-width: 880px; }
    .header { padding: 22px 56px; }
}

/* Mobile */
@media (max-width: 768px) {
    .tab-content { padding: 20px 16px; }
    .main-content { padding-bottom: 90px; }
}

/* Small mobile */
@media (max-width: 374px) {
    .header h1 { font-size: 1.05rem; }
    .tab { font-size: 0.58rem; }
    .tab .tab-icon { font-size: 1.1rem; }
    .card { padding: 16px; }
    .tab-content { padding: 16px 12px; }
    .form { padding: 24px 18px; }
}

/* ===== Add/Delete Category Buttons ===== */
.cat-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}
.btn-add-cat, .btn-del-cat {
    flex: 1;
    padding: 10px 16px;
    border: 2px dashed var(--primary-light);
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}
.btn-add-cat:hover { 
    background: #ddd8f7; 
    border-color: var(--primary); 
}
.btn-del-cat {
    border-color: rgba(239,68,68,0.4);
    background: var(--danger-light);
    color: var(--danger);
}
.btn-del-cat:hover { 
    background: #fde4e4; 
    border-color: var(--danger); 
}


/* ===== Capital Edit Hint ===== */
.dash-edit-hint {
    display: block;
    font-size: 0.65rem;
    color: var(--primary);
    margin-top: 6px;
    opacity: 0.7;
    font-weight: 500;
}
.dash-card.dash-capital:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}
.dash-card.dash-capital:active {
    transform: scale(0.98);
}


/* ===== Slip button ===== */
.btn-slip {
    background: var(--primary-soft);
    border: none;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}
.btn-slip:hover { background: #ddd8f7; }


/* ===== มุมมองตาราง (จอคอมเท่านั้น) ===== */
.data-table {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.data-head,
.data-row {
    display: grid;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
}

.table-stock { grid-template-columns: 1.3fr 1.6fr 1.1fr 1.2fr 1fr 84px; }
.table-history { grid-template-columns: 1.3fr 1fr 1.1fr 0.9fr 0.9fr 0.9fr 1fr 84px; }

.data-head {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
    text-transform: none;
}

.data-row {
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background var(--transition);
    font-size: 0.85rem;
}
.data-row:last-of-type { border-bottom: none; }
.data-row:hover { background: var(--primary-soft); }

.data-cell {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.data-cell.data-num { text-align: right; font-variant-numeric: tabular-nums; }
.data-head .data-cell.data-num { text-align: right; }
.data-code { font-weight: 700; color: var(--text); }
.has-photo { margin-right: 5px; font-size: 0.8rem; opacity: 0.75; }
.data-sub {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.data-cell.data-num .data-sub { text-align: right; }

.profit-pos { color: var(--success); font-weight: 700; }
.profit-neg { color: var(--danger); font-weight: 700; }

.data-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}
.data-actions .btn-edit,
.data-actions .btn-delete {
    padding: 7px 10px;
    font-size: 0.85rem;
    line-height: 1;
}

.data-table .pagination { margin-top: 0; padding: 14px 0; }

/* ===== Modal รายละเอียด ===== */
.detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.detail-code { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.detail-image {
    width: 100%;
    max-height: 260px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    cursor: pointer;
    display: block;
}
.detail-slip { margin-top: 16px; }
.detail-slip .card-label { display: block; margin-bottom: 8px; }

/* จอคอม: ให้พื้นที่ตารางกว้างขึ้น แต่ฟอร์ม/แดชบอร์ดยังคงอ่านง่าย */
@media (min-width: 769px) {
    .tab-content { max-width: 1120px; padding: 32px 28px; }
    .form,
    .dashboard,
    .toggle-bar,
    .sell-product-preview { max-width: 720px; margin-left: auto; margin-right: auto; }
}


/* ============================================================
   LAYOUT แบบ Web App บนจอคอม
   ============================================================ */

/* ฟอร์มสองคอลัมน์บนจอกว้าง */
@media (min-width: 769px) {
    .form {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 20px;
        row-gap: 0;
        align-items: start;
        max-width: 760px;
    }
    .form > .form-group { margin-bottom: 18px; }
    .form > .span-2,
    .form > .btn,
    .form > .sell-product-preview,
    .form > #editSoldFields,
    .form > input[type="hidden"] { grid-column: 1 / -1; }

    #editSoldFields {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 20px;
        padding: 18px 20px;
        margin-bottom: 18px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-light);
        border-radius: var(--radius-sm);
    }
    #editSoldFields > .form-group { margin-bottom: 14px; }
    #editSoldFields > .span-2 { grid-column: 1 / -1; }
}

/* Sidebar ค้างอยู่ตลอดบนจอคอม ไม่ต้องกดแฮมเบอร์เกอร์ */
@media (min-width: 1024px) {
    .sidebar {
        transform: none;
        box-shadow: 2px 0 24px rgba(124, 108, 231, 0.12);
    }
    /* width:auto สำคัญ: ถ้าปล่อยเป็น width:100% จากกฎพื้นฐาน
       เนื้อหาจะกว้างเท่าจอเต็มแล้วถูกดันขวาอีก 280px ทำให้หน้าล้นแนวนอน */
    .main-content { margin-left: var(--sidebar-width); width: auto; }
    .menu-btn { display: none; }
    .sidebar-overlay,
    .sidebar-overlay.open { display: none !important; }

    .header {
        padding: 16px 32px;
        padding-top: 16px;
        background: rgba(255, 255, 255, 0.85);
        backdrop-filter: saturate(180%) blur(12px);
        -webkit-backdrop-filter: saturate(180%) blur(12px);
        border-bottom: 1px solid var(--border-light);
        box-shadow: none;
        color: var(--text);
    }
    .header h1 { color: var(--text); font-size: 1.05rem; }
    .header .subtitle { color: var(--text-muted); }
    .header-logo { display: none; }

    .tab-content { padding: 28px 32px 48px; }
}

/* ============================================================
   MODAL — จอคอมให้กว้าง หัว/ท้ายตรึง เนื้อหาเลื่อนเฉพาะส่วนกลาง
   ============================================================ */

/* ส่วนเนื้อหาของ modal ที่เลื่อนได้
   margin: 0 สำคัญมาก เพราะ margin auto บน flex item จะยกเลิก stretch
   ทำให้ฟอร์มหุบแคบลอยกลางกล่อง */
.modal-content > .form,
.modal-content > #detailBody {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0;
    max-width: none;
    background: none;
    box-shadow: none;
    border: none;
    padding: 20px;
}

/* แถบปุ่มท้าย modal */
.modal-footer {
    flex: 0 0 auto;
    display: flex;
    gap: 10px;
    padding: 14px 20px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-light);
    background: var(--card-bg);
}
.modal-footer .btn { width: auto; flex: 1 1 auto; padding: 14px; }
.modal-footer .btn-primary { flex: 2 1 auto; }

/* ซ่อนด้วยคลาส เพื่อไม่ให้ inline display ทับ display:grid ของฟอร์ม */
.is-hidden { display: none !important; }

.btn-ghost {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--border-light); color: var(--text); }

/* ที่จับลากบนมือถือ ให้รู้ว่าเลื่อนปิดได้ */
.modal-header::before {
    content: '';
    position: absolute;
    top: 7px; left: 50%;
    transform: translateX(-50%);
    width: 38px; height: 4px;
    border-radius: 4px;
    background: var(--border);
}
.modal-header { position: relative; padding-top: 22px; }

@media (min-width: 769px) {
    .modal { align-items: center; padding: 24px; }

    .modal-content {
        max-width: 860px;
        max-height: 88vh;
        border-radius: var(--radius-lg);
        animation: modalPop 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .modal-header { padding: 20px 28px; }
    .modal-header::before { display: none; }

    .modal-content > .form { padding: 24px 28px; }
    .modal-content > #detailBody { padding: 24px 28px; }
    .modal-footer { padding: 16px 28px; justify-content: flex-end; }
    .modal-footer .btn { flex: 0 0 auto; min-width: 120px; }
    .modal-footer .btn-primary { min-width: 190px; }
}

/* ============================================================
   MODAL รายละเอียด — จอคอมวางรูปคู่กับข้อมูล
   ============================================================ */
@media (min-width: 769px) {
    .detail-grid {
        display: grid;
        grid-template-columns: 300px 1fr;
        gap: 24px;
        align-items: start;
    }
    .detail-media { position: sticky; top: 0; }
    .detail-image { max-height: 300px; margin-bottom: 12px; }
    .detail-slip { margin-top: 0; }
}

.detail-media:empty { display: none; }

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.96) translateY(12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* แท็บเล็ต: ยังไม่มี sidebar ค้าง จึงต้องคงแถบเมนูล่างไว้ */
@media (min-width: 769px) and (max-width: 1023px) {
    .tabs { display: flex; }
    .main-content { padding-bottom: 92px; }
}


/* ============================================================
   แดชบอร์ดหน้าสรุป: จอคอมกระจายเป็นกริด ใช้พื้นที่เต็ม
   ============================================================ */
@media (min-width: 769px) {
    .dashboard {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 16px;
        max-width: none;
        margin: 0;
    }
    /* ให้การ์ดใน .dash-row ไหลเข้ากริดหลักโดยตรง */
    .dash-row { display: contents; }

    .dash-card.dash-highlight { grid-column: span 2; padding: 30px 24px; }
    .dash-card.dash-profit { grid-column: span 2; }
    .dash-card.dash-highlight .dash-value { font-size: 2.1rem; }
    .dash-card.dash-profit .dash-value { font-size: 1.75rem; }

    .month-selector { margin-bottom: 20px; }
}

@media (min-width: 1280px) {
    .dashboard { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .dash-card.dash-highlight { grid-column: span 3; }
    .dash-card.dash-profit { grid-column: span 3; }
}

/* อันดับขายดี: จอคอมวางสองคอลัมน์ให้เต็มพื้นที่ */
@media (min-width: 1024px) {
    .top-list { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
    .section-title { font-size: 1.05rem; }
}


/* ============================================================
   ใช้พื้นที่จอกว้างให้เต็ม (เดิมถูกบีบไว้ 1120px)
   ============================================================ */
@media (min-width: 769px) {
    .tab-content { max-width: 1600px; }
}
@media (min-width: 1024px) {
    .tab-content { padding: 28px 40px 56px; }
}

/* ============================================================
   DASHBOARD PANELS
   ============================================================ */
.dash-panels {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 16px;
}

.panel {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.panel-head { margin-bottom: 16px; }
.panel-title { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.panel-sub { display: block; font-size: 0.72rem; color: var(--text-muted); margin-top: 3px; font-weight: 500; }

.chart-empty {
    padding: 36px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

/* --- แถบเปรียบเทียบแนวนอน --- */
.hbar-item { margin-bottom: 18px; }
.hbar-item:last-child { margin-bottom: 0; }
.hbar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 7px; }
.hbar-label { font-size: 0.78rem; color: var(--text-secondary); font-weight: 600; }
.hbar-value { font-size: 0.92rem; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.hbar-track { height: 10px; background: var(--bg-secondary); border-radius: 6px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 6px; transition: width 0.5s ease; }
.hbar-note { display: block; font-size: 0.68rem; color: var(--text-muted); margin-top: 5px; font-weight: 500; }

.bar-revenue { background: var(--primary-light); fill: var(--primary-light); }
.bar-cost { background: var(--warning); fill: var(--warning); }
.bar-profit { background: var(--success); fill: var(--success); }
.bar-loss { background: var(--danger); fill: var(--danger); }

/* --- โดนัทสถานะ --- */
.donut-wrap { position: relative; width: 168px; margin: 0 auto 16px; }
.donut { width: 100%; height: auto; display: block; }
.donut-track { fill: none; stroke: var(--bg-secondary); stroke-width: 16; }
.donut-seg { fill: none; stroke-width: 16; stroke-linecap: butt; transition: stroke-dasharray 0.5s ease; }
.donut-center {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    pointer-events: none;
}
.donut-total { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1.1; }
.donut-caption { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; }

.chart-legend { list-style: none; display: flex; flex-direction: column; gap: 9px; }
.chart-legend li { display: flex; align-items: center; gap: 9px; font-size: 0.78rem; }
.chart-legend .legend-label { flex: 1; color: var(--text-secondary); font-weight: 500; }
.chart-legend .legend-value { font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.legend-dot { width: 11px; height: 11px; border-radius: 4px; flex-shrink: 0; }
.legend-dot-outline { background: none; border: 2px dashed var(--primary-light); }
.legend-extra { padding-top: 9px; border-top: 1px dashed var(--border); }
.chart-legend-row { flex-direction: row; gap: 20px; justify-content: center; margin-top: 12px; }

/* --- กราฟแท่งแนวโน้ม --- */
.chart-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    text-align: center;
    padding-bottom: 4px;
}
.chart-scroll::-webkit-scrollbar { height: 6px; }
.chart-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
/* ตรึงขนาดจริงเป็นพิกเซล ไม่ยืดตามความกว้างแผง ตัวหนังสือจึงไม่ถูกขยาย
   ใช้ inline-block + text-align กลาง เพื่อไม่ให้ด้านซ้ายถูกตัดตอนกราฟกว้างกว่ากรอบ */
.trend-chart { display: inline-block; height: 220px; width: auto; max-width: none; vertical-align: top; }
.trend-axis { stroke: var(--border); stroke-width: 1.5; }
.trend-bar { transition: opacity 0.2s; }
.trend-group { opacity: 0.55; transition: opacity 0.2s; }
.trend-group.is-active { opacity: 1; }
.dash-panels:hover .trend-group { opacity: 1; }
.trend-group:hover { opacity: 1; }
.trend-label { font-size: 12px; font-weight: 700; fill: var(--text-secondary); }
.trend-count { font-size: 10px; fill: var(--text-muted); }

/* --- จัดวางแผงบนจอกว้าง --- */
@media (min-width: 769px) {
    .dash-panels {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 16px;
        margin-top: 16px;
    }
    .panel { padding: 22px 24px; grid-column: span 2; }
    .panel.panel-wide { grid-column: span 4; }
}

@media (min-width: 1280px) {
    .dash-panels { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .panel { grid-column: span 3; }
    .panel.panel-wide { grid-column: span 6; }
}
