@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@400;600;700&family=Sarabun:wght@300;400;600;700&display=swap');

/* ════════════════════════════════
   DESIGN TOKENS
   ════════════════════════════════ */
:root {
    --charcoal:        #0f0f1e;
    --slate-deep:      #1a1a2e;
    --slate-mid:       #252545;
    --slate-light:     #3a3a5c;
    --silver-mist:     #a8a8c8;
    --platinum:        #e0e0f0;
    --pure-white:      #ffffff;

    --matisse:         #3d6a96;
    --matisse-light:   #5b8fc0;
    --princely:        #7c6ba0;
    --rose-edge:       #e07a85;

    --green:           #22c55e;
    --green-dim:       rgba(34, 197, 94, 0.15);
    --red:             #f87171;
    --red-dim:         rgba(248, 113, 113, 0.15);
    --amber:           #fbbf24;
    --amber-dim:       rgba(251, 191, 36, 0.15);
    --blue:            #60a5fa;
    --blue-dim:        rgba(96, 165, 250, 0.15);
    --purple:          #c084fc;
    --purple-dim:      rgba(192, 132, 252, 0.15);

    --glass-1:         rgba(255, 255, 255, 0.06);
    --glass-2:         rgba(255, 255, 255, 0.10);
    --glass-3:         rgba(255, 255, 255, 0.15);
    --glass-4:         rgba(255, 255, 255, 0.22);
    --glass-white:     rgba(255, 255, 255, 0.92);
    --glass-border:    rgba(255, 255, 255, 0.14);
    --glass-border-2:  rgba(255, 255, 255, 0.22);
    --glass-shadow:    0 8px 32px rgba(0,0,0,0.35), 0 2px 8px rgba(0,0,0,0.20), inset 0 1px 0 rgba(255,255,255,0.18);
    --glass-shadow-lg: 0 20px 60px rgba(0,0,0,0.50), 0 4px 16px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.20);
    --glass-shadow-sm: 0 4px 16px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.12);

    --r-sm:   8px;
    --r-md:   14px;
    --r-lg:   20px;
    --r-xl:   28px;
    --r-full: 9999px;

    --font-body:    'Sarabun', sans-serif;
    --font-display: 'Kanit', sans-serif;

    --text-primary:   #f0f0ff;
    --text-secondary: #a0a0c0;
    --text-muted:     #606080;
    --text-inverse:   #0f0f1e;

    --t-fast:   0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --t-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --t-slow:   0.40s cubic-bezier(0.4, 0, 0.2, 1);

    --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;

    --header-h: 64px;
    --max-w:    1200px;
}

/* ════════════════════════════════
   RESET & BASE
   ════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--charcoal);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ════════════════════════════════
   BG SCENE
   ════════════════════════════════ */
.bg-scene {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background: radial-gradient(ellipse at 15% 20%, rgba(61,106,150,0.30) 0%, transparent 55%),
                radial-gradient(ellipse at 85% 75%, rgba(124,107,160,0.28) 0%, transparent 55%),
                radial-gradient(ellipse at 50% 50%, rgba(37,37,69,0.60) 0%, transparent 70%),
                linear-gradient(170deg, #0f0f1e 0%, #1a1a2e 45%, #12122a 100%);
}
.bg-scene::before,
.bg-scene::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    /* ลด blur ลงเพื่อลด GPU load และป้องกัน stacking context ซ้อนกัน */
    filter: blur(60px);
    pointer-events: none;
}
.bg-scene::before {
    width: min(500px, 60vw); height: min(500px, 60vw);
    top: -10%; left: -10%;
    background: radial-gradient(circle, rgba(61,106,150,0.18) 0%, transparent 70%);
    animation: orb1 18s ease-in-out infinite alternate;
}
.bg-scene::after {
    width: min(400px, 50vw); height: min(400px, 50vw);
    bottom: -5%; right: -8%;
    background: radial-gradient(circle, rgba(124,107,160,0.16) 0%, transparent 70%);
    animation: orb2 22s ease-in-out infinite alternate;
}
@keyframes orb1 { from { transform: translate(0,0) scale(1); } to { transform: translate(6%,4%) scale(1.1); } }
@keyframes orb2 { from { transform: translate(0,0) scale(1); } to { transform: translate(-5%,-4%) scale(1.08); } }

/* ════════════════════════════════
   DNA CANVAS
   ════════════════════════════════ */
.dna-canvas-wrap {
    position: absolute;
    top: 0;
    left: clamp(10px, 4vw, 60px);
    width: clamp(80px, 8vw, 120px);
    height: 100%;
    opacity: 0.45;
    pointer-events: none;
}
.dna-canvas-wrap canvas { width: 100%; height: 100%; }

/* ════════════════════════════════
   APP SHELL
   ════════════════════════════════ */
.app { position: relative; z-index: 1; min-height: 100vh; }

/* ════════════════════════════════
   HEADER
   ════════════════════════════════ */
header {
    position: sticky;
    top: 0;
    z-index: 200;
    height: var(--header-h);
    width: 100%;
    padding: 0 var(--sp-5);
    background: rgba(15,15,30,0.80);
    /* FIX: ลด blur ลงเพื่อลด stacking context ที่ทำให้ table render ผิด */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: 0 1px 0 rgba(255,255,255,0.06), 0 4px 24px rgba(0,0,0,0.30);
}
header::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.25) 30%, rgba(200,180,255,0.30) 60%, transparent 100%);
}
.header-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
}
.logo span {
    font-family: var(--font-display);
    font-size: clamp(1rem, 2.5vw, 1.35rem);
    font-weight: 700;
    white-space: nowrap;
    background: linear-gradient(135deg, #fff 30%, rgba(192,180,255,0.9) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
nav { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }

.nav-btn {
    padding: 7px 16px;
    border-radius: var(--r-full);
    border: 1px solid transparent;
    background: var(--glass-1);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--t-normal);
    white-space: nowrap;
}
.nav-btn:hover { background: var(--glass-3); color: var(--text-primary); border-color: var(--glass-border); }
.nav-btn.active {
    background: linear-gradient(135deg, var(--matisse) 0%, var(--princely) 100%);
    color: #fff;
    border-color: rgba(255,255,255,0.15);
    box-shadow: 0 4px 16px rgba(61,106,150,0.40), inset 0 1px 0 rgba(255,255,255,0.20);
}

.cfg-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--amber);
    display: inline-block;
    margin-left: 4px;
    box-shadow: 0 0 6px var(--amber);
}
.cfg-dot.ok { background: var(--green); box-shadow: 0 0 6px var(--green); }

/* ════════════════════════════════
   MAIN CONTENT
   ════════════════════════════════ */
main {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: clamp(16px, 4vw, 36px) clamp(12px, 3vw, 20px);
}
.page        { display: none; }
.page.active { display: block; }

/* ════════════════════════════════
   GLASS CARDS
   ════════════════════════════════ */
.card {
    background: var(--glass-2);
    /* FIX: ลด blur และเอา saturate ออก เพื่อลด stacking context */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    padding: clamp(20px, 4vw, 32px);
    box-shadow: var(--glass-shadow);
    color: var(--text-primary);
    margin-bottom: clamp(16px, 3vw, 28px);
    position: relative;
    overflow: visible;
}
.card::before {
    content: '';
    position: absolute;
    top: 0; left: 8px; right: 8px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.20) 40%, rgba(255,255,255,0.20) 60%, transparent);
    border-radius: var(--r-full);
}
.card-light {
    background: rgba(255,255,255,0.90);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #1a1a2e;
    border: 1px solid rgba(200,200,220,0.40);
    box-shadow: 0 8px 32px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.90);
}
.card-light .card-title { color: var(--matisse); }
.card-light td          { color: #1e2040; }
.card-light label       { color: #4a4a6a; }

.card-title {
    font-family: var(--font-display);
    font-size: clamp(1rem, 2.5vw, 1.15rem);
    font-weight: 600;
    color: var(--platinum);
    margin-bottom: clamp(16px, 3vw, 24px);
    padding-left: 14px;
    border-left: 3px solid;
    border-image: linear-gradient(180deg, var(--matisse-light), var(--princely)) 1;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.3;
}

/* ════════════════════════════════
   HERO
   ════════════════════════════════ */
.hero {
    text-align: center;
    padding: clamp(32px, 6vw, 56px) clamp(16px, 5vw, 32px);
    background: linear-gradient(145deg, rgba(61,106,150,0.20) 0%, rgba(124,107,160,0.15) 50%, rgba(37,37,69,0.25) 100%);
    /* FIX: ลด blur */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: var(--r-xl);
    border: 1px solid var(--glass-border);
    margin-bottom: clamp(20px, 4vw, 32px);
    box-shadow: var(--glass-shadow);
    position: relative;
    overflow: hidden;
}
.hero::before {
    content: '';
    position: absolute;
    top: 0; left: 10%; right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
}
.hero h1 {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 4vw, 2.2rem);
    font-weight: 700;
    color: var(--platinum);
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}
.hero p { color: var(--text-secondary); font-size: clamp(0.875rem, 2vw, 1rem); max-width: 480px; margin: 0 auto; }
.search-row { display: flex; gap: 10px; max-width: 460px; margin: clamp(16px, 3vw, 22px) auto 0; }

/* ════════════════════════════════
   INPUTS & FORM
   ════════════════════════════════ */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 11px 14px;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: #1a1a2e;
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(180,180,210,0.50);
    border-radius: var(--r-md);
    outline: none;
    transition: all var(--t-fast);
    box-sizing: border-box;
}
select option { background: #ffffff; color: #1a1a2e; }
input::placeholder, textarea::placeholder { color: #9090aa; }
input:hover, select:hover { border-color: rgba(120,120,180,0.70); background: #ffffff; }
input:focus, select:focus, textarea:focus {
    border-color: var(--matisse);
    background: #ffffff;
    color: #1a1a2e;
    box-shadow: 0 0 0 3px rgba(61,106,150,0.18);
}
.card-light input,
.card-light select,
.card-light textarea { background: #ffffff; border: 1px solid rgba(180,180,210,0.60); color: #1a1a2e; }
.card-light input::placeholder { color: #8888aa; }
.card-light input:focus,
.card-light select:focus,
.card-light textarea:focus { border-color: var(--matisse); background: #ffffff; box-shadow: 0 0 0 3px rgba(61,106,150,0.15); }

label { display: block; margin-bottom: 6px; font-size: 0.8125rem; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.02em; }
.card-light label { color: #5a5a80; }

/* ════════════════════════════════
   BUTTONS
   ════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 20px;
    border-radius: var(--r-md);
    border: 1px solid transparent;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--t-normal);
    position: relative;
    overflow: hidden;
    min-height: 44px;
}
.btn::after { content: ''; position: absolute; inset: 0; border-radius: inherit; opacity: 0; background: rgba(255,255,255,0.10); transition: opacity var(--t-fast); }
.btn:hover::after { opacity: 1; }
.btn:active       { transform: scale(0.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--matisse) 0%, var(--princely) 100%);
    color: #fff;
    border-color: rgba(255,255,255,0.12);
    box-shadow: 0 4px 16px rgba(61,106,150,0.35), inset 0 1px 0 rgba(255,255,255,0.18);
}
.btn-primary:hover { box-shadow: 0 6px 24px rgba(61,106,150,0.50), inset 0 1px 0 rgba(255,255,255,0.22); transform: translateY(-1px); }
.btn-success { background: linear-gradient(135deg, #15803d 0%, #22c55e 100%); color: #fff; box-shadow: 0 4px 16px rgba(34,197,94,0.30), inset 0 1px 0 rgba(255,255,255,0.15); }
.btn-success:hover { transform: translateY(-1px); }
.btn-danger  { background: linear-gradient(135deg, #b91c1c 0%, #ef4444 100%); color: #fff; box-shadow: 0 4px 16px rgba(239,68,68,0.30), inset 0 1px 0 rgba(255,255,255,0.12); }
/* FIX: เอา backdrop-filter ออกจาก btn-outline เพราะเป็น element เล็กไม่จำเป็น */
.btn-outline { background: var(--glass-1); border: 1px solid var(--glass-border-2); color: var(--text-primary); }
.btn-outline:hover { background: var(--glass-3); border-color: rgba(255,255,255,0.28); }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover { background: var(--glass-2); color: var(--text-primary); }
.btn-sm  { padding: 6px 14px;  font-size: 0.8125rem;  border-radius: var(--r-sm); min-height: 36px; }
.btn-lg  { padding: 13px 28px; font-size: 1rem;        min-height: 50px; }
.btn-xl  { padding: 14px 26px; font-size: 1.0625rem;   border-radius: var(--r-lg); min-height: 54px; }
.w-full  { width: 100%; }

/* ════════════════════════════════
   GRID & FLEX UTILITIES
   ════════════════════════════════ */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.gap-2  { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); } .gap-5 { gap: var(--sp-5); }
.flex            { display: flex; }
.flex-1          { flex: 1; }
.flex-wrap       { flex-wrap: wrap; }
.items-center    { align-items: center; }
.justify-end     { justify-content: flex-end; }
.justify-center  { justify-content: center; }
.justify-between { justify-content: space-between; }
.text-center     { text-align: center; }
.text-sm         { font-size: 0.875rem; }
.text-muted      { color: var(--text-secondary); }
.font-bold       { font-weight: 700; }
.mb-2 { margin-bottom: var(--sp-2); } .mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); } .mb-5 { margin-bottom: var(--sp-5); }
.mt-2 { margin-top: var(--sp-2); }    .mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }    .mt-5 { margin-top: var(--sp-5); }

/* ════════════════════════════════
   STAT CARDS
   ════════════════════════════════ */
.stat-card {
    background: var(--glass-2);
    /* FIX: ลด blur */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: clamp(14px, 3vw, 20px);
    border-radius: var(--r-lg);
    text-align: center;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform var(--t-normal), box-shadow var(--t-normal);
}
.stat-card::before { content: ''; position: absolute; top: 0; left: 20%; right: 20%; height: 1px; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.18), transparent); }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--glass-shadow); }
.stat-num   { font-family: var(--font-display); font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 700; display: block; line-height: 1.1; color: var(--platinum); }
.stat-label { color: var(--text-secondary); font-size: clamp(0.75rem, 1.5vw, 0.85rem); margin-top: 6px; display: block; }

/* ════════════════════════════════
   TABLES  ← จุดหลักที่แก้
   ════════════════════════════════ */
.tbl-wrap {
    /* FIX: เอา backdrop-filter และ transform ออกทั้งหมด
       แทนด้วย isolation: isolate เพื่อสร้าง stacking context แบบเบา
       ไม่ขัดการ render ของ table rows */
    background: rgba(255,255,255,0.07);
    border-radius: var(--r-lg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    isolation: isolate;
}
.tbl-wrap table,
.tbl-scroll table { min-width: 560px; }
.tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-lg); }

table              { width: 100%; border-collapse: collapse; }
thead tr           { background: linear-gradient(90deg, rgba(61,106,150,0.75) 0%, rgba(124,107,160,0.70) 100%) !important; }
thead tr::after    { display: block; content: ''; height: 1px; background: rgba(255,255,255,0.12); }
th {
    color: rgba(255,255,255,0.95) !important;
    padding: clamp(12px, 2vw, 18px) clamp(10px, 2vw, 16px) !important;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    white-space: nowrap;
}
td {
    padding: clamp(10px, 2vw, 14px) clamp(10px, 2vw, 16px);
    color: var(--text-primary);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    vertical-align: middle;
    font-size: 0.9375rem;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td      { background: rgba(255,255,255,0.04); }

.card-light .tbl-wrap  { background: rgba(255,255,255,0.70); border: 1px solid rgba(200,200,220,0.40); }
.card-light td         { color: #1e2040; border-bottom: 1px solid rgba(0,0,0,0.06); }
.card-light tbody tr:hover td { background: rgba(0,0,0,0.025); }

/* Row states */
.row-มา  { background: rgba(34,197,94,0.08) !important;   border-left: 3px solid var(--green) !important; }
.row-ขาด { background: rgba(248,113,113,0.09) !important; border-left: 3px solid var(--red) !important; }
.row-ลา  { background: rgba(168,168,200,0.09) !important; border-left: 3px solid var(--silver-mist) !important; }
.row-สาย { background: rgba(251,191,36,0.09) !important;  border-left: 3px solid var(--amber) !important; }

/* ════════════════════════════════
   BADGES
   ════════════════════════════════ */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    border-radius: var(--r-full);
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 72px;
    /* FIX: เอา backdrop-filter ออกจาก badge เพราะซ้ำซ้อนและหนักเกิน */
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge-green  { background: var(--green-dim);  color: #4ade80; border-color: rgba(34,197,94,0.25); }
.badge-red    { background: var(--red-dim);    color: #fca5a5; border-color: rgba(248,113,113,0.25); }
.badge-blue   { background: var(--blue-dim);   color: #93c5fd; border-color: rgba(96,165,250,0.25); }
.badge-amber  { background: var(--amber-dim);  color: #fcd34d; border-color: rgba(251,191,36,0.25); }
.badge-purple { background: var(--purple-dim); color: #d8b4fe; border-color: rgba(192,132,252,0.25); }

.badge-pending  { background: rgba(251,191,36,0.12); color: #fbbf24; border: 1px solid rgba(251,191,36,0.28); padding: 4px 12px; border-radius: var(--r-full); font-size: 0.8rem; font-weight: 600; }
.badge-not-sent { background: var(--red-dim); color: #fca5a5; border: 1px solid rgba(248,113,113,0.25); padding: 4px 12px; border-radius: var(--r-full); font-size: 0.8rem; font-weight: 600; }

/* ════════════════════════════════
   TOGGLE BUTTONS
   ════════════════════════════════ */
.tog {
    padding: 6px 14px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    cursor: pointer;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.8125rem;
    transition: all var(--t-fast);
    /* FIX: เอา backdrop-filter ออก */
    min-height: 36px;
}
.tog.checked  { background: var(--green-dim);  color: #4ade80; border-color: rgba(34,197,94,0.30); }
.tog.waiting  { background: var(--amber-dim);  color: #fcd34d; border-color: rgba(251,191,36,0.30); }
.tog.not-sent { background: var(--red-dim);    color: #fca5a5; border-color: rgba(248,113,113,0.25); }
.tog:hover    { transform: scale(1.06); }
.tog:active   { transform: scale(0.97); }

.score-in { width: 72px !important; text-align: center; font-weight: 700; font-size: 1rem; padding: 6px 8px !important; }

.att-select { min-width: 80px; padding: 6px 10px; border-radius: var(--r-sm); font-weight: 700; font-family: var(--font-body); font-size: 0.875rem; cursor: pointer; border: none; }
.select-มา  { background: rgba(34,197,94,0.18);  color: #4ade80; }
.select-ขาด { background: rgba(248,113,113,0.18); color: #fca5a5; }
.select-ลา  { background: rgba(168,168,200,0.18); color: #b8b8e8; }
.select-สาย { background: rgba(251,191,36,0.18);  color: #fcd34d; }

/* ════════════════════════════════
   TAB BAR
   ════════════════════════════════ */
.tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: clamp(14px, 3vw, 22px);
    background: rgba(255,255,255,0.05);
    padding: 5px;
    border-radius: var(--r-md);
    border: 1px solid var(--glass-border);
    /* FIX: ลด blur ใน tab-bar */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    flex-wrap: wrap;
}
.tab-btn {
    padding: 8px clamp(12px, 2.5vw, 18px);
    border-radius: var(--r-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: clamp(0.8rem, 1.8vw, 0.9rem);
    transition: all var(--t-normal);
    white-space: nowrap;
    min-height: 38px;
}
.tab-btn:hover  { background: var(--glass-2); color: var(--text-primary); }
.tab-btn.active { background: linear-gradient(135deg, var(--matisse) 0%, var(--princely) 100%); color: #fff; box-shadow: 0 4px 14px rgba(61,106,150,0.35), inset 0 1px 0 rgba(255,255,255,0.18); }

/* ════════════════════════════════
   SWITCH
   ════════════════════════════════ */
.sw { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw-slider { position: absolute; inset: 0; cursor: pointer; background: rgba(255,255,255,0.15); border-radius: 26px; transition: all var(--t-normal); border: 1px solid var(--glass-border); }
.sw-slider::before { content: ''; position: absolute; height: 20px; width: 20px; left: 2px; bottom: 2px; background: #fff; border-radius: 50%; transition: transform var(--t-normal), box-shadow var(--t-normal); box-shadow: 0 2px 6px rgba(0,0,0,0.25); }
.sw input:checked + .sw-slider { background: linear-gradient(135deg, #15803d, var(--green)); border-color: rgba(34,197,94,0.30); box-shadow: 0 0 12px rgba(34,197,94,0.25); }
.sw input:checked + .sw-slider::before { transform: translateX(20px); }

.scan-bar { background: rgba(34,197,94,0.07); border: 1px solid rgba(34,197,94,0.20); border-radius: var(--r-md); padding: 12px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ════════════════════════════════
   LOADING & EMPTY
   ════════════════════════════════ */
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: clamp(20px, 4vw, 32px); color: var(--text-secondary); font-size: 0.9375rem; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid rgba(168,168,200,0.18); border-top-color: var(--silver-mist); animation: spin 0.75s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: clamp(32px, 6vw, 60px) 20px; }
.empty-ico   { font-size: clamp(2rem, 6vw, 3.5rem); margin-bottom: 12px; }
.empty-title { font-family: var(--font-display); font-size: clamp(1rem, 2.5vw, 1.25rem); color: var(--text-secondary); }

/* ════════════════════════════════
   MODALS
   ════════════════════════════════ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.65);
    /* FIX: ลด blur modal overlay */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: clamp(12px, 3vw, 20px);
}
.modal-overlay.open { display: flex; }
.modal {
    background: rgba(26,26,46,0.92);
    /* FIX: ลด blur modal */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: var(--text-primary);
    width: 100%;
    max-width: 520px;
    padding: clamp(22px, 4vw, 32px);
    border-radius: var(--r-xl);
    border: 1px solid var(--glass-border-2);
    box-shadow: var(--glass-shadow-lg);
    max-height: 90dvh;
    overflow-y: auto;
    position: relative;
}
.modal::before { content: ''; position: absolute; top: 0; left: 12%; right: 12%; height: 1px; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.28), transparent); border-radius: var(--r-full); }
.modal-hd { font-family: var(--font-display); font-size: clamp(1.05rem, 3vw, 1.3rem); font-weight: 600; margin-bottom: clamp(18px, 3vw, 24px); color: var(--platinum); display: flex; align-items: center; gap: 10px; }
.modal-close { margin-left: auto; background: var(--glass-1); border: 1px solid var(--glass-border); color: var(--text-secondary); cursor: pointer; width: 30px; height: 30px; border-radius: var(--r-full); display: flex; align-items: center; justify-content: center; font-size: 1rem; transition: all var(--t-fast); }
.modal-close:hover { background: var(--glass-3); color: var(--text-primary); }

.modal textarea,
textarea#na-desc {
    color: #1a1a2e !important;
    background: rgba(255,255,255,0.92) !important;
    border: 1px solid rgba(180,180,210,0.55) !important;
    font-family: var(--font-body) !important;
    resize: vertical;
}
.modal textarea:focus,
textarea#na-desc:focus { border-color: var(--matisse) !important; background: #ffffff !important; box-shadow: 0 0 0 3px rgba(61,106,150,0.18) !important; }

/* ════════════════════════════════
   SCORE DISPLAY
   ════════════════════════════════ */
.score-big { font-size: clamp(1.4rem, 3.5vw, 1.9rem); font-weight: 700; color: var(--platinum); }
.score-sep { color: var(--text-muted); margin: 0 3px; }
.score-max { font-size: clamp(1rem, 2.5vw, 1.35rem); color: var(--text-secondary); }

/* ════════════════════════════════
   ATTENDANCE GRID
   ════════════════════════════════ */
.att-side-label { background: rgba(15,15,30,0.85) !important; font-family: var(--font-display); font-weight: 600; color: var(--platinum) !important; white-space: nowrap; min-width: 160px; }
.att-summary-col { background: rgba(91,96,128,0.12) !important; font-weight: 700; }

/* ════════════════════════════════
   TOASTS
   ════════════════════════════════ */
#toasts { position: fixed; bottom: clamp(16px,4vw,24px); right: clamp(12px,3vw,20px); z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-width: min(340px, calc(100vw - 24px)); }
.toast {
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px;
    border-radius: var(--r-md); font-size: 0.875rem;
    box-shadow: 0 8px 28px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.10);
    animation: toastIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
    font-family: var(--font-body); pointer-events: all;
    /* FIX: ลด blur toast */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid transparent; line-height: 1.5;
}
@keyframes toastIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.success { background: rgba(5,78,50,0.92);  border-color: rgba(34,197,94,0.35);   color: #bbf7d0; }
.toast.error   { background: rgba(90,15,15,0.95);  border-color: rgba(248,113,113,0.35); color: #fecaca; }
.toast.info    { background: rgba(15,30,55,0.92);  border-color: rgba(96,165,250,0.30);  color: #bfdbfe; }
.toast.warn    { background: rgba(80,40,5,0.95);   border-color: rgba(251,191,36,0.35);  color: #fef08a; }

/* ════════════════════════════════
   DASHBOARD
   ════════════════════════════════ */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1.2fr; gap: clamp(14px,3vw,22px); margin-bottom: clamp(18px,3vw,26px); }
.prog-container { margin-bottom: 14px; }
.prog-label     { display: flex; justify-content: space-between; font-size: 0.8125rem; margin-bottom: 6px; color: var(--text-secondary); }
.prog-bar-bg    { width: 100%; height: 8px; background: rgba(255,255,255,0.08); border-radius: var(--r-full); overflow: hidden; }
.prog-bar-fill  { height: 100%; border-radius: var(--r-full); transition: width 1s cubic-bezier(0.4,0,0.2,1); box-shadow: 0 0 8px rgba(255,255,255,0.15); }

.tr-subject-group td { background: rgba(61,106,150,0.18) !important; font-family: var(--font-display); font-weight: 600; color: var(--platinum) !important; padding: 8px 16px !important; font-size: 0.875rem; border-bottom: 1px solid rgba(255,255,255,0.06) !important; }

.row-pending td  { background: rgba(251,191,36,0.05) !important; color: var(--text-secondary) !important; font-style: italic; }
.row-not-sent td { color: var(--text-secondary) !important; }

/* ════════════════════════════════
   SYNC OVERLAY
   ════════════════════════════════ */
#sync-overlay { display: none; position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,0.70); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); align-items: center; justify-content: center; flex-direction: column; gap: 18px; }
#sync-overlay.open   { display: flex; }
#sync-progress-text  { font-family: var(--font-display); font-size: 1.05rem; color: var(--platinum); }
#sync-progress-bar-wrap { width: clamp(240px,40vw,320px); height: 8px; background: rgba(255,255,255,0.10); border-radius: var(--r-full); overflow: hidden; }
#sync-progress-bar   { height: 100%; width: 0%; background: linear-gradient(90deg, var(--matisse), var(--princely)); border-radius: var(--r-full); transition: width 0.35s ease; box-shadow: 0 0 10px rgba(61,106,150,0.5); }

/* ════════════════════════════════
   SCROLLBAR
   ════════════════════════════════ */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(168,168,200,0.25); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(168,168,200,0.45); }

/* ════════════════════════════════
   ATTENDANCE RADIO GROUP
   ════════════════════════════════ */
.att-radio-label input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.att-radio-group { display: flex; gap: 5px; flex-wrap: nowrap; }
.att-radio-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 13px;
    border-radius: var(--r-full);
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: all var(--t-fast);
    user-select: none;
    min-height: 34px;
    min-width: 48px;
    position: relative;
    background: rgba(255,255,255,0.06);
    color: var(--text-secondary);
}
.att-radio-label:hover  { transform: scale(1.06); filter: brightness(1.2); }
.att-radio-label:active { transform: scale(0.96); }
.att-radio-มา  { border-color: rgba(34,197,94,0.20); }
.att-radio-สาย { border-color: rgba(251,191,36,0.20); }
.att-radio-ลา  { border-color: rgba(96,165,250,0.20); }
.att-radio-ขาด { border-color: rgba(248,113,113,0.20); }
.att-radio-มา.checked  { background: rgba(34,197,94,0.25);  color: #4ade80; border-color: rgba(34,197,94,0.60);  box-shadow: 0 0 12px rgba(34,197,94,0.30),  inset 0 1px 0 rgba(255,255,255,0.12); }
.att-radio-สาย.checked { background: rgba(251,191,36,0.25); color: #fcd34d; border-color: rgba(251,191,36,0.60); box-shadow: 0 0 12px rgba(251,191,36,0.25), inset 0 1px 0 rgba(255,255,255,0.12); }
.att-radio-ลา.checked  { background: rgba(96,165,250,0.25); color: #93c5fd; border-color: rgba(96,165,250,0.60);  box-shadow: 0 0 12px rgba(96,165,250,0.25),  inset 0 1px 0 rgba(255,255,255,0.12); }
.att-radio-ขาด.checked { background: rgba(248,113,113,0.25); color: #fca5a5; border-color: rgba(248,113,113,0.60); box-shadow: 0 0 12px rgba(248,113,113,0.25), inset 0 1px 0 rgba(255,255,255,0.12); }

/* ════════════════════════════════
   RESPONSIVE
   ════════════════════════════════ */
@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    :root { --header-h: auto; }
    header { height: auto; padding: 10px var(--sp-4) 12px; }
    .header-inner { flex-direction: column; align-items: flex-start; gap: 10px; height: auto; }
    .header-inner nav { width: 100%; gap: 6px; }
    .nav-btn { padding: 7px 12px; font-size: 0.8125rem; flex: 1; justify-content: center; text-align: center; }
    .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2           { grid-template-columns: 1fr; }
    .card             { padding: 18px; border-radius: var(--r-lg); }
    input[type="text"], input[type="number"], input[type="date"],
    input[type="password"], select, textarea { font-size: 16px; }
    .tbl-scroll     { overflow-x: auto; }
    .tab-btn        { padding: 8px 12px; font-size: 0.8rem; }
    .search-row     { flex-direction: column; }
    .modal          { padding: 20px 18px; border-radius: var(--r-lg); }
    .att-radio-label { padding: 5px 9px; font-size: 0.75rem; min-width: 38px; }
    .att-radio-group { gap: 4px; }
}
@media (max-width: 380px) {
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .nav-btn   { font-size: 0.75rem; padding: 6px 8px; }
    .stat-num  { font-size: 1.4rem; }
}
@media (hover: none) and (pointer: coarse) {
    .btn { min-height: 48px; } .tab-btn { min-height: 44px; } .tog { min-height: 42px; } .nav-btn { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}