
:root {
    --primary-color: #F74C43;
    --primary-light: rgba(247, 76, 67, 0.1);
    --bg-page: #F8F9FA;
    --white: #FFFFFF;
    --text-main: #2D3436;
    --text-muted: #636E72;
    --border: #E2E8F0;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
    --border-radius: 20px;
    --sidebar-w: 264px;
    --topbar-h: 64px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Prompt', 'Sarabun', sans-serif;
}

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

/* ===== Styled scrollbars — เข้ากับธีม OomMe ===== */
* {
    scrollbar-width: thin;
    scrollbar-color: #CBD5E1 transparent;
}
::-webkit-scrollbar { width: 10px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
    background-clip: content-box;
    border: 2px solid transparent;
}
::-webkit-scrollbar-corner { background: transparent; }

/* Sidebar (พื้นเข้ม): thumb สีอ่อน โปร่งใส hover เป็นสี primary */
.sidebar-nav {
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.22) transparent;
    overscroll-behavior: contain;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.18);
    border: none;
    border-radius: 999px;
    background-clip: border-box;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: var(--primary-color); }

/* ตารางแนวนอน + modal: บางลง */
.table-responsive::-webkit-scrollbar { height: 6px; }
.table-responsive::-webkit-scrollbar-thumb { background: var(--primary-light); border: 1px solid transparent; }
.table-responsive::-webkit-scrollbar-thumb:hover { background: var(--primary-color); }
.modal-card::-webkit-scrollbar { width: 6px; }

body {
    background-color: var(--bg-page);
    color: var(--text-main);
    padding-bottom: calc(44px + env(safe-area-inset-bottom)); /* ให้เนื้อหาเลื่อนลอดใต้ bottom-nav โชว์เอฟเฟกต์กระจก */
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.6;
}

img { max-width: 100%; height: auto; }

/* ===== Fluid container (ยืดหยุ่นจริง ไม่ล็อกตาย) ===== */
.container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 16px;
}
@media (min-width: 640px) {
    .container { max-width: 640px; padding: 20px; }
}
@media (min-width: 768px) {
    .container { max-width: 768px; }
}
@media (min-width: 1024px) {
    body { padding-bottom: 0; }
    .container { max-width: 100%; padding: 24px 28px; }
}
@media (min-width: 1280px) {
    .container { max-width: 1200px; }
}
@media (min-width: 1536px) {
    .container { max-width: 1320px; }
}

/* ===== App shell: sidebar + main ===== */
.sidebar {
    display: none; /* mobile: ซ่อน ใช้ bottom-nav แทน */
}
.app-main {
    min-width: 0;
    width: 100%;
}
@media (min-width: 1024px) {
    .sidebar {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: var(--sidebar-w);
        background: #111418;
        color: #E5E7EB;
        z-index: 1000;
        padding: 20px 14px;
    }
    .app-main {
        margin-left: var(--sidebar-w);
        width: calc(100% - var(--sidebar-w));
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }
    .app-main > .container { flex: 1; }
}

/* Sidebar parts */
.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 6px 10px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 14px;
}
.sidebar-brand .logo-box {
    width: 42px; height: 42px; border-radius: 12px; overflow: hidden;
    background: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-brand .logo-box img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand .brand-name { font-weight: 700; font-size: 18px; color: #fff; line-height: 1.2; }
.sidebar-brand .brand-sub { font-size: 11px; color: #9CA3AF; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.sidebar-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #9CA3AF; padding: 14px 12px 6px; }
.sidebar-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 12px;
    color: #D1D5DB; text-decoration: none; font-size: 14px; font-weight: 500;
    transition: .2s;
}
.sidebar-link i.material-icons { font-size: 21px; color: #9CA3AF; }
.sidebar-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-link.active { background: var(--primary-color); color: #fff; }
.sidebar-link.active i.material-icons { color: #fff; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 14px; margin-top: 10px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; font-size: 13px; }
.sidebar-user .avatar { width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.12); display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; flex-shrink: 0; }

/* Topbar */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.app-topbar-inner {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 16px;
}
@media (min-width: 1024px) {
    .app-topbar-inner { padding: 14px 28px; }
}
.topbar-title { font-weight: 700; font-size: 15px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
    background: #fff; display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-muted); position: relative; transition: .2s;
}
.icon-btn:hover { border-color: var(--primary-color); color: var(--primary-color); }

/* ===== Cards ===== */
.card {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid rgba(226,232,240,.6);
    min-width: 0;
}
@media (min-width: 1024px) {
    .card { padding: 24px; }
}

.primary-card {
    background: var(--primary-color);
    color: var(--white);
    border-radius: 30px;
    position: relative;
    overflow: hidden;
    border: none;
}
.primary-card::after {
    content: '';
    position: absolute;
    top: 20px;
    right: -15px;
    width: 200px;
    height: 200px;
    background: url('../banner.png') no-repeat center / contain;
    opacity: 0.25;
    transform: rotate(-15deg);
    pointer-events: none;
    z-index: 0;
}

/* ===== Dashboard hero (mobile stacked / desktop 2-col admin) ===== */
.dash-hero-grid { display: grid; gap: 16px; grid-template-columns: 1fr; margin-bottom: 20px; }
.dash-hero-main { min-width: 0; display: grid; gap: 0; }
.dash-hero-main .card { margin-bottom: 0; }
.dash-side { display: none; }
.dash-mobile-only { display: grid; }
@media (min-width: 1024px) {
    .dash-hero-grid { grid-template-columns: 1.65fr .85fr; align-items: stretch; }
    .dash-side { display: flex; flex-direction: column; gap: 12px; margin-bottom: 0; }
    .dash-mobile-only { display: none !important; }
    .dash-side .btn { width: 100%; padding: 14px; font-size: 14px; }
    .dash-side-menu { display: flex; flex-direction: column; margin-top: 4px; border-top: 1px solid #F1F5F9; }
    .dash-side-menu a {
        display: flex; align-items: center; gap: 12px;
        padding: 12px 4px; text-decoration: none; color: var(--text-main);
        font-size: 14px; font-weight: 500; border-bottom: 1px solid #F8FAFC;
    }
    .dash-side-menu a:last-child { border-bottom: none; }
    .dash-side-menu .m-ic {
        width: 38px; height: 38px; border-radius: 11px; background: #F1F5F9;
        display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    }
    .dash-side-menu .m-ic i { font-size: 19px; color: var(--text-main); }
    .dash-side-menu .chev { margin-left: auto; color: #CBD5E1; }
}

/* ===== Responsive grids (แทน grid-template-columns ตายตัว) ===== */
.responsive-grid { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
.grid-3 { display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr); }
.quick-actions { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; margin-bottom: 24px; }
.icon-grid { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); margin-bottom: 24px; }
.dashboard-columns { display: grid; gap: 20px; grid-template-columns: 1fr; }
.table-grid-2 { display: grid; gap: 20px; grid-template-columns: 1fr; }

@media (min-width: 768px) {
    .grid-2 { grid-template-columns: 1fr 1fr; }
    .quick-actions { grid-template-columns: repeat(4, 1fr); }
    .icon-grid { grid-template-columns: repeat(6, 1fr); max-width: 640px; }
}
@media (min-width: 1024px) {
    .dashboard-columns { grid-template-columns: 1.6fr 1fr; align-items: start; }
    .table-grid-2 { grid-template-columns: 1fr 1fr; align-items: start; }
    .icon-grid { max-width: none; }
}
@media (min-width: 1280px) {
    .responsive-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
    .responsive-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Stat cards for desktop dashboard */
.stat-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .stat-value { font-size: clamp(20px, 2.5vw, 28px); font-weight: 700; }

/* ===== Buttons / forms ===== */
.btn {
    padding: 12px 16px;
    border-radius: 15px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    font-size: 14px;
    justify-content: center;
    white-space: normal;
    line-height: 1.4;
    text-align: center;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.btn-primary { background-color: var(--primary-color); color: var(--white); }
.btn-primary:hover { filter: brightness(.95); }
.btn-light { background-color: var(--white); color: var(--primary-color); }
.btn-ghost { background-color: var(--primary-light); color: var(--primary-color); }

input[type="text"], input[type="number"], input[type="date"], select, textarea {
    max-width: 100%;
    font-size: 14px;
}
.form-row { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 768px) { .form-row.cols-2 { grid-template-columns: 1fr 1fr; } .form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }

/* Tables */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; }
.table-responsive table { min-width: 560px; }
@media (min-width: 1024px) { .table-responsive table { min-width: 100%; } }
/* ตาราง 2 คอลัมน์: ไม่ต้อง scroll ให้พอดีจอ */
.table-responsive.compact { overflow: visible; }
.table-responsive.compact table { min-width: 0; width: 100%; }
.table-responsive.compact th, .table-responsive.compact td { white-space: normal; overflow-wrap: anywhere; }

/* Modals: fluid, ไม่ล็อก 400px ตายบน desktop */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 3000;
    align-items: center; justify-content: center; padding: 16px;
}
.modal-card { width: 100%; max-width: 440px; max-height: 88vh; overflow-y: auto; margin-bottom: 0; }
@media (min-width: 768px) { .modal-card { max-width: 560px; } }

/* ===== Idle lock splash (liquid glass) — พักจอแทน logout ===== */
.lock-splash { position: fixed; inset: 0; z-index: 5000; display: none; align-items: center; justify-content: center; overflow: hidden; background: rgba(15,18,22,.5); }
.lock-splash.show { display: flex; }
.lock-splash .blob { position: absolute; width: 44vmax; height: 44vmax; border-radius: 50%; filter: blur(70px); opacity: .5; pointer-events: none; }
.lock-splash .b1 { background: var(--primary-color); top: -12vmax; left: -10vmax; animation: blobFloat 11s ease-in-out infinite alternate; }
.lock-splash .b2 { background: #7C3AED; bottom: -14vmax; right: -8vmax; animation: blobFloat 13s ease-in-out infinite alternate-reverse; }
.lock-splash .b3 { background: #F59E0B; width: 30vmax; height: 30vmax; bottom: 8%; left: 12%; opacity: .35; animation: blobFloat 9s ease-in-out infinite alternate; }
@keyframes blobFloat { from { transform: translate(0,0) scale(1); } to { transform: translate(6vmax,4vmax) scale(1.15); } }
.lock-splash .glass { position: absolute; inset: 0; backdrop-filter: blur(22px) saturate(1.3); -webkit-backdrop-filter: blur(22px) saturate(1.3); }
.lock-card { position: relative; z-index: 1; width: min(360px, calc(100% - 40px)); background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.35); border-radius: 28px; padding: 30px 26px; text-align: center; color: #fff; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.lock-card .lock-logo { width: 72px; height: 72px; border-radius: 22px; background: #fff; margin: 0 auto 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.lock-card .lock-logo img { width: 100%; height: 100%; object-fit: contain; }
.lock-clock { font-size: 34px; font-weight: 700; letter-spacing: 1px; }
.lock-date { font-size: 12px; opacity: .75; margin-bottom: 14px; }
.lock-sub { font-size: 12px; opacity: .8; margin-bottom: 12px; }
.lock-card input { width: 100%; padding: 14px; border-radius: 14px; border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.15); color: #fff; font-size: 22px; letter-spacing: 8px; text-align: center; outline: none; }
.lock-card input::placeholder { color: rgba(255,255,255,.5); }
.lock-err { font-size: 12px; color: #FECACA; min-height: 18px; margin-top: 8px; }

/* PIN ผิด: สั่นเตือน */
@keyframes pinShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-10px); }
    40% { transform: translateX(9px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(4px); }
}
.shake { animation: pinShake .45s ease; border-color: #F74C43 !important; }

/* Topbar user menu (avatar dropdown) */
.user-menu { display: none; position: absolute; right: 0; top: 48px; background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); min-width: 220px; max-width: 260px; overflow: hidden; z-index: 1200; }
.user-menu.open { display: block; }
.user-menu-head { padding: 12px 16px; border-bottom: 1px solid #F1F5F9; background: #F8FAFC; }
.user-menu a { display: flex; align-items: center; gap: 10px; padding: 11px 16px; font-size: 13px; font-weight: 500; color: var(--text-main); text-decoration: none; }
.user-menu a:hover { background: #F8FAFC; }
.user-menu a i.material-icons { font-size: 19px; color: var(--text-muted); }
.user-menu a.danger, .user-menu a.danger i.material-icons { color: var(--primary-color); }

/* Bottom Navigation — Liquid Glass docked bar (mobile only) */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
    padding: 12px 8px calc(12px + env(safe-area-inset-bottom));
    border-radius: 26px 26px 0 0;
    overflow: hidden;
    border: none; /* ใช้ขอบเลนส์เรืองแสงจาก ::after แทน */
    background: linear-gradient(180deg, rgba(255, 238, 230, 0.24), rgba(255, 238, 230, 0.12) 55%, rgba(255, 238, 230, 0.18));
    -webkit-backdrop-filter: blur(32px) saturate(240%) contrast(1.05) brightness(1.05);
    backdrop-filter: blur(32px) saturate(240%) contrast(1.05) brightness(1.05);
    box-shadow:
        0 -14px 44px rgba(15, 23, 42, 0.18),
        0 -4px 24px #F74C4314,
        inset 0 -10px 18px rgba(255, 255, 255, 0.14);
    z-index: 1000;
}
/* gloss + แสงไหลเอื่อยๆ แบบของเหลว */
.bottom-nav::before {
    content: "";
    position: absolute;
    inset: -20% -60%;
    border-radius: inherit;
    pointer-events: none;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0) 34%),
        linear-gradient(115deg, transparent 42%, rgba(255, 255, 255, 0.16) 50%, transparent 58%);
    animation: liquidSheen 9s ease-in-out infinite alternate;
}
@keyframes liquidSheen {
    from { transform: translateX(-6%); }
    to { transform: translateX(6%); }
}
@media (prefers-reduced-motion: reduce) {
    .bottom-nav::before { animation: none; }
}
/* ขอบเลนส์เรืองแสงเกาะตามมุมมน — ลายเซ็น Liquid Glass */
.bottom-nav::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1.5px 1.5px 0 1.5px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.25) 30%, rgba(255, 255, 255, 0.05) 55%, transparent 75%);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
    pointer-events: none;
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    min-width: 56px;
}
.nav-item.active { color: var(--primary-color); }
.nav-item i { font-size: 24px; margin-bottom: 4px; }
/* แท็บในแถบล่าง: กางเต็มความกว้างเท่าๆ กันแบบ ref, ไม่มีเม็ดสีหลัง active */
.bottom-nav .nav-item {
    position: relative;
    z-index: 1;
    flex: 1 1 0;
    min-width: 0;
    padding: 4px 2px 2px;
    border-radius: 0;
    background: none;
    box-shadow: none;
    gap: 3px;
    font-size: 10.5px;
    color: #566070; /* เข้มกว่า text-muted เล็กน้อย ให้อ่านชัดบนกระจกสว่าง */
    text-shadow: 0 1px 3px rgba(255, 255, 255, 0.9), 0 0 1px rgba(255, 255, 255, 0.8);
    transition: transform .15s ease;
}
.bottom-nav .nav-item:active { transform: scale(0.94); }
.bottom-nav .nav-item .material-symbols-rounded {
    font-family: 'Material Symbols Rounded';
    font-weight: normal;
    font-style: normal;
    line-height: 1;
    display: inline-block;
    font-size: 27px;
    margin: 0;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    transition: transform .18s ease;
}
/* แท็บที่เลือก: ไอคอนเติมสีทึบ + ตัวหนังสือสีธีม เหมือน ref (ไม่มีพื้นหลัง) */
.bottom-nav .nav-item.active {
    background: none;
    box-shadow: none;
}
.bottom-nav .nav-item.active .material-symbols-rounded {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    transform: scale(1.06);
    filter: drop-shadow(0 2px 8px #F74C4373);
}
@media (min-width: 1024px) {
    .bottom-nav { display: none; }
}

/* Typography fluid */
h1 { font-size: clamp(20px, 2.5vw, 28px); font-weight: 700; }
h2 { font-size: clamp(17px, 2vw, 22px); font-weight: 600; }
h3 { font-size: clamp(15px, 1.6vw, 18px); font-weight: 600; }

.text-center { text-align: center; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }

/* Login: split layout บน desktop */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; width: 100%; max-width: 440px; margin: 0 auto; }
@media (min-width: 1024px) {
    .login-wrap { max-width: 960px; flex-direction: row; align-items: center; gap: 48px; }
    .login-hero { flex: 1; display: block !important; }
    .login-card { flex: 1; }
}
.login-hero { display: none; }

/* Batch list -> card grid บน desktop */
.batch-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 768px) { .batch-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1280px) { .batch-grid { grid-template-columns: 1fr 1fr 1fr; } }

/* Leaderboard rows ยืดหยุ่น */
.leader-row { display: flex; justify-content: space-between; align-items: center; padding: 14px 10px; border-bottom: 1px solid #F1F5F9; gap: 12px; min-width: 0; }
.leader-row > div { min-width: 0; }
