/* ==============================================================================
   SA Green School — Design System (PHP)
   อ้างอิงต้นฉบับ Next.js: app/globals.css + Tailwind classes ใน components/layout/*,
   components/auth/*, components/dashboard/*
   ค่าสีเป็น hex ของ Tailwind palette (gray / green / emerald ฯลฯ)
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400&family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Brand (globals.css) */
    --primary: #16a34a;          /* green-600 */
    --primary-hover: #15803d;    /* green-700 */
    --primary-light: #f0fdf4;    /* green-50 */
    --primary-dark: #14532d;     /* green-900 */
    --secondary: #3b82f6;
    --accent: #f59e0b;

    /* Surfaces & text (Tailwind gray) */
    --bg-main: #f9fafb;          /* gray-50  : พื้นหลัง shell */
    --surface: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.7);
    --border: #f3f4f6;           /* gray-100 : เส้นขอบ sidebar/header/card */
    --border-strong: #e5e7eb;    /* gray-200 : เส้นขอบ input/ปุ่ม */
    --text-main: #111827;        /* gray-900 */
    --text-muted: #6b7280;       /* gray-500 */
    --text-sub: #9ca3af;         /* gray-400 */

    /* Grade (คงชื่อเดิมไว้ให้ view ที่ยังไม่ได้ปรับใช้ต่อได้) */
    --gold-bg: #fffbeb;
    --gold-text: #b45309;
    --gold-border: #fde68a;
    --silver-bg: #f8fafc;
    --silver-text: #475569;
    --silver-border: #e2e8f0;
    --bronze-bg: #fff7ed;
    --bronze-text: #c2410c;
    --bronze-border: #fed7aa;
    --fail-bg: #fef2f2;
    --fail-text: #b91c1c;
    --fail-border: #fecaca;

    --radius: 0.75rem;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.1);

    --sidebar-width: 260px;
    --sidebar-width-collapsed: 72px;
    --header-height: 64px;
}

/* ── Base (Tailwind preflight แบบย่อ + globals.css) ─────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    border: 0 solid;
    transition-property: background-color, border-color, color, opacity;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 150ms;
}

html {
    font-family: 'Sarabun', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-text-size-adjust: 100%;
    font-feature-settings: "kern" 1;
    font-kerning: normal;
}

body {
    background-color: #f7fbf7; /* hsl(120 20% 98%) — --background ของต้นฉบับ */
    color: var(--text-main);
    min-height: 100vh;
    line-height: 1.6;
    font-size: 16px;
}

h1, h2, h3, h4, h5, h6 {
    font-size: inherit;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

a { color: inherit; text-decoration: inherit; }
img, svg { display: block; vertical-align: middle; }
img { max-width: 100%; height: auto; }
button, input, select, textarea {
    font: inherit;
    color: inherit;
    background-color: transparent;
}
button { cursor: pointer; }
table { border-collapse: collapse; }

.hidden { display: none !important; }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #6b7280; }

/* Lucide icon sizes (w-4 / w-5 / w-6 ...) */
.icon   { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }
.icon-3 { width: 0.75rem; height: 0.75rem; flex-shrink: 0; }
.icon-3-5 { width: 0.875rem; height: 0.875rem; flex-shrink: 0; }
.icon-4 { width: 1rem; height: 1rem; flex-shrink: 0; }
.icon-5 { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }
.icon-6 { width: 1.5rem; height: 1.5rem; flex-shrink: 0; }
.icon-8 { width: 2rem; height: 2rem; flex-shrink: 0; }

/* ==============================================================================
   APP SHELL — components/layout/dashboard-shell.tsx
   ============================================================================== */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-main);
}

/* ── Sidebar — components/layout/sidebar.tsx ──────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-right: 1px solid #f3f4f6;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: width 300ms cubic-bezier(0.4, 0, 0.2, 1), transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-close {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    padding: 0.375rem;
    color: #9ca3af;
    border-radius: 0.5rem;
    z-index: 1;
}
.sidebar-close:hover { color: #4b5563; }

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid #f3f4f6;
}

.sidebar-logo {
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 0.75rem;
    background: #ffffff;
    box-shadow: var(--shadow-sm);
    border: 1px solid #f3f4f6;
    padding: 0.25rem;
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: contain; }

.sidebar-brand { overflow: hidden; white-space: nowrap; }
.sidebar-brand-title {
    font-size: 0.875rem;
    font-weight: 700;
    color: #111827;
    line-height: 1.25;
}
.sidebar-brand-sub {
    font-size: 0.75rem;
    line-height: 1rem;
    color: #16a34a;
    font-weight: 500;
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: #4b5563;
    transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-link:hover { background: #f3f4f6; color: #111827; }
.nav-link.active { background: #f0fdf4; color: #15803d; }
.nav-link.active .nav-icon { color: #16a34a; }
/* แถบ active ด้านซ้าย (absolute left-0 w-0.5 h-6 bg-green-600 rounded-r-full) */
.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    width: 2px;
    height: 1.5rem;
    background: #16a34a;
    border-radius: 0 9999px 9999px 0;
}

.nav-icon { flex-shrink: 0; display: flex; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-tag {
    margin-left: auto;
    font-size: 10px;
    line-height: 1rem;
    font-weight: 700;
    background: #dcfce7;
    color: #15803d;
    padding: 0.125rem 0.375rem;
    border-radius: 0.375rem;
}

.badge-count {
    margin-left: auto;
    min-width: 20px;
    height: 1.25rem;
    padding: 0 0.375rem;
    font-size: 0.75rem;
    font-weight: 700;
    background: #ef4444;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.375rem;
    box-shadow: var(--shadow-sm);
}

.sidebar-user {
    border-top: 1px solid #f3f4f6;
    padding: 0.75rem;
}
.sidebar-user-row { display: flex; align-items: center; gap: 0.75rem; }
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: #111827;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user-role {
    font-size: 0.75rem;
    line-height: 1rem;
    color: #6b7280;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.avatar {
    position: relative;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 0.875rem;
    font-weight: 700;
    flex-shrink: 0;
}
.avatar-online {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0.625rem;
    height: 0.625rem;
    background: #22c55e;
    border-radius: 9999px;
    border: 2px solid #ffffff;
}

.logout-btn {
    padding: 0.375rem;
    color: #9ca3af;
    border-radius: 0.5rem;
    display: flex;
}
.logout-btn:hover { color: #ef4444; background: #fef2f2; }

/* Collapsed (72px) */
html.sidebar-collapsed .sidebar { width: var(--sidebar-width-collapsed); }
html.sidebar-collapsed .sidebar-header,
html.sidebar-collapsed .nav-link { justify-content: center; }
html.sidebar-collapsed .sidebar-brand,
html.sidebar-collapsed .nav-label,
html.sidebar-collapsed .nav-tag,
html.sidebar-collapsed .badge-count,
html.sidebar-collapsed .sidebar-user .avatar,
html.sidebar-collapsed .sidebar-user-info { display: none; }
html.sidebar-collapsed .sidebar-user-row { justify-content: center; }
html.sidebar-collapsed .logout-btn { padding: 0.5rem; }

/* ── Main area ─────────────────────────────────────────────────────────────── */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    margin-left: var(--sidebar-width);
    transition: margin-left 300ms cubic-bezier(0.4, 0, 0.2, 1);
}
html.sidebar-collapsed .main-wrapper { margin-left: var(--sidebar-width-collapsed); }

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}
@media (min-width: 768px)  { .page-content { padding: 1.5rem; } }
@media (min-width: 1024px) { .page-content { padding: 2rem; } }

/* ── Header — components/layout/header.tsx ────────────────────────────────── */
.top-navbar {
    height: var(--header-height);
    flex-shrink: 0;
    background: #ffffff;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: var(--shadow-sm);
}
@media (min-width: 768px) { .top-navbar { padding: 0 1.5rem; } }

.header-icon-btn {
    position: relative;
    padding: 0.5rem;
    color: #6b7280;
    border-radius: 0.75rem;
    display: flex;
}
.header-icon-btn:hover { color: #374151; background: #f3f4f6; }

.header-search { flex: 1; max-width: 28rem; }
.header-search-btn {
    display: none;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    max-width: 20rem;
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid #f3f4f6;
    background: #f9fafb;
    color: #9ca3af;
    font-size: 0.875rem;
    line-height: 1.25rem;
}
.header-search-btn:hover { border-color: #e5e7eb; background: #f3f4f6; }
.header-search-btn kbd {
    margin-left: auto;
    font-family: inherit;
    font-size: 0.75rem;
    line-height: 1rem;
    background: #f3f4f6;
    color: #9ca3af;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
}
.header-search-input {
    width: 100%;
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    font-size: 0.875rem;
    outline: none;
}
.header-search-input:focus { box-shadow: 0 0 0 2px #22c55e; }
@media (min-width: 768px) {
    .header-search-btn { display: flex; }
    .header-search-mobile { display: none; }
}

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }

.header-notif-badge {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 16px;
    height: 1rem;
    padding: 0 0.25rem;
    font-size: 10px;
    font-weight: 700;
    background: #ef4444;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    box-shadow: 0 0 0 2px #ffffff;
}

.header-avatar { border: 2px solid #bbf7d0; overflow: hidden; }

/* ── Mobile (< 768px) — sidebar เป็น drawer ──────────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
}

@media (max-width: 767.98px) {
    .sidebar {
        z-index: 50;
        transform: translateX(-280px);
        box-shadow: var(--shadow-2xl);
    }
    html.sidebar-collapsed .sidebar { width: var(--sidebar-width); }
    html.sidebar-collapsed .sidebar-header,
    html.sidebar-collapsed .nav-link { justify-content: flex-start; }
    html.sidebar-collapsed .sidebar-brand,
    html.sidebar-collapsed .sidebar-user-info { display: block; }
    html.sidebar-collapsed .nav-label { display: block; }
    html.sidebar-collapsed .nav-tag,
    html.sidebar-collapsed .badge-count,
    html.sidebar-collapsed .sidebar-user .avatar { display: flex; }
    html.sidebar-collapsed .sidebar-user-row { justify-content: flex-start; }

    body.mobile-nav-open .sidebar { transform: translateX(0); }
    body.mobile-nav-open .sidebar-backdrop { display: block; }
    .sidebar-close { display: flex; }

    .main-wrapper,
    html.sidebar-collapsed .main-wrapper { margin-left: 0; }
}

/* ==============================================================================
   COMPONENTS
   ============================================================================== */

/* Card — bg-white rounded-2xl border-gray-100 shadow-sm */
.card {
    background: #ffffff;
    border: 1px solid #f3f4f6;
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

/* .stat-card ของ globals.css (ใช้ทั้งการ์ดกราฟและ Hall of Fame) */
.stat-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.2s, transform 0.2s;
}
.stat-card:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}
.stat-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Gradients (globals.css) */
.gradient-green { background: linear-gradient(135deg, #16a34a 0%, #15803d 50%, #166534 100%); }
.gradient-green-light { background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%); }
.glass-card {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.5);
}
.gradient-text {
    background: linear-gradient(90deg, #16a34a, #0d9488, #2563eb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    background-size: 200% auto;
    animation: gradient-shift 3s linear infinite;
}
@keyframes gradient-shift {
    0% { background-position: 0% center; }
    100% { background-position: 200% center; }
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    line-height: 1.25rem;
    font-weight: 600;
}
/* Grade badges (globals.css) */
.badge-gold   { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #78350f; box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4); }
.badge-silver { background: linear-gradient(135deg, #cbd5e1, #94a3b8); color: #1e293b; box-shadow: 0 2px 8px rgba(148, 163, 184, 0.4); }
.badge-bronze { background: linear-gradient(135deg, #d97706, #b45309); color: #fff;    box-shadow: 0 2px 8px rgba(180, 83, 9, 0.4); }
.badge-pass   { background: linear-gradient(135deg, #4ade80, #22c55e); color: #14532d; box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3); }
.badge-fail   { background: linear-gradient(135deg, #f87171, #ef4444); color: #fff;    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3); }

/* Buttons — primary: bg-green-600 hover:bg-green-700 rounded-xl text-sm font-medium */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.5rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #16a34a; color: #ffffff; }
.btn-primary:hover { background: #15803d; }
/* secondary: bg-white border-gray-200 text-gray-600 hover:bg-gray-50 */
.btn-secondary {
    background: #ffffff;
    color: #4b5563;
    border-color: #e5e7eb;
    box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: #f9fafb; color: #111827; }
/* sm: px-3 py-1.5 text-xs */
.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    line-height: 1rem;
    border-radius: 0.5rem;
    gap: 0.375rem;
}

/* Form controls — bg-gray-50 border-gray-200 rounded-xl focus:ring-green-500/20 */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: #374151;
}
.form-input {
    width: 100%;
    padding: 0.625rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #f9fafb;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: #111827;
    outline: none;
    transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.form-input::placeholder { color: #9ca3af; }
.form-input:focus {
    border-color: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

/* Alerts — p-3 rounded-xl text-sm */
.alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.75rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    border: 1px solid;
}
.alert-success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.alert-error   { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

/* Data table (globals.css .data-table) */
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.data-table th {
    background: #f9fafb;
    color: #6b7280;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem;
}
.data-table td {
    color: #111827;
    border-bottom: 1px solid #f3f4f6;
    padding: 0.875rem 1rem;
}
.data-table tbody tr:hover td { background: #f9fafb; }

/* Mock data label — ใช้ระบุชัดเจนว่าตัวเลขบนหน้าเป็นข้อมูลจำลอง */
.mock-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 0.375rem;
    background: #fffbeb;
    border: 1px dashed #f59e0b;
    color: #b45309;
    font-size: 0.75rem;
    line-height: 1rem;
    font-weight: 600;
    white-space: nowrap;
}

.skeleton {
    background: linear-gradient(90deg, #f3f4f6 0%, #e5e7eb 50%, #f3f4f6 100%);
    background-size: 200px 100%;
    animation: skeleton-loading 1.4s ease infinite;
    border-radius: 0.375rem;
}
@keyframes skeleton-loading {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}

/* Entrance animation (framer-motion: opacity 0, y 20 → 1, 0) */
@keyframes fade-up {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fade-up 0.5s ease-out both; }

/* ==============================================================================
   DASHBOARD — components/dashboard/dashboard-content.tsx, stat-card.tsx
   ============================================================================== */
.dash { display: flex; flex-direction: column; gap: 1.5rem; }
.dash > * { animation: fade-up 0.5s ease-out both; }
.dash > *:nth-child(2) { animation-delay: 0.08s; }
.dash > *:nth-child(3) { animation-delay: 0.16s; }
.dash > *:nth-child(4) { animation-delay: 0.24s; }
.dash > *:nth-child(5) { animation-delay: 0.32s; }

.dash-title { font-size: 1.5rem; line-height: 2rem; font-weight: 700; color: #111827; }
.dash-subtitle {
    color: #6b7280;
    font-size: 0.875rem;
    line-height: 1.25rem;
    margin-top: 0.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.kpi-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 640px)  { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1280px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }

.kpi-card {
    position: relative;
    overflow: hidden;
    border-radius: 20px;
    background: #ffffff;
    border: 1px solid #f3f4f6;
    box-shadow: var(--shadow-sm);
    cursor: default;
    transition: box-shadow 300ms, transform 300ms;
    animation: fade-up 0.5s ease-out both;
}
.kpi-card:hover { box-shadow: var(--shadow-xl); transform: translateY(-6px) scale(1.02); }
.kpi-glow {
    position: absolute;
    right: -1.5rem;
    top: -1.5rem;
    width: 6rem;
    height: 6rem;
    border-radius: 9999px;
    opacity: 0.2;
    filter: blur(40px);
    transition: opacity 300ms;
}
.kpi-card:hover .kpi-glow { opacity: 0.4; }
.kpi-body { padding: 1.5rem; }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1rem; }
.kpi-icon {
    padding: 0.75rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
    color: #ffffff;
    display: flex;
}
.kpi-value {
    font-size: 1.875rem;
    line-height: 2.25rem;
    font-weight: 800;
    color: #111827;
    letter-spacing: -0.025em;
}
.kpi-label { font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; color: #6b7280; margin-top: 0.25rem; }
.kpi-line {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0.375rem;
    opacity: 0;
    transition: opacity 300ms;
}
.kpi-card:hover .kpi-line { opacity: 1; }
.grad-green  { background: linear-gradient(to bottom right, #4ade80, #059669); }
.grad-blue   { background: linear-gradient(to bottom right, #38bdf8, #2563eb); }
.grad-purple { background: linear-gradient(to bottom right, #c084fc, #c026d3); }
.grad-cyan   { background: linear-gradient(to bottom right, #22d3ee, #3b82f6); }
.kpi-line.grad-green  { background: linear-gradient(to right, #4ade80, #059669); }
.kpi-line.grad-blue   { background: linear-gradient(to right, #38bdf8, #2563eb); }
.kpi-line.grad-purple { background: linear-gradient(to right, #c084fc, #c026d3); }
.kpi-line.grad-cyan   { background: linear-gradient(to right, #22d3ee, #3b82f6); }

.section-head {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (min-width: 640px) { .section-head { flex-direction: row; align-items: center; } }
.section-title-lg {
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-weight: 700;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.section-title { font-weight: 600; color: #111827; }
.section-desc { font-size: 0.875rem; line-height: 1.25rem; color: #6b7280; margin-top: 0.25rem; }
.section-desc-xs { font-size: 0.75rem; line-height: 1rem; color: #9ca3af; margin-top: 0.125rem; }

.select-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    color: #374151;
    outline: none;
    cursor: pointer;
}
.select-sm:focus { box-shadow: 0 0 0 2px #a855f7; }
.select-plain {
    padding: 0.25rem 2rem 0.25rem 0.75rem;
    font-size: 0.75rem;
    line-height: 1rem;
    background: #f9fafb;
    border: none;
    border-radius: 0.5rem;
    color: #111827;
    cursor: pointer;
}

.star-amber { color: #f59e0b; fill: #f59e0b; }

/* Daily quests table */
.quest-card { position: relative; background: #ffffff; border-radius: 1rem; box-shadow: var(--shadow-sm); border: 1px solid #f3f4f6; padding: 1.5rem; }
.table-scroll { overflow-x: auto; }
.quest-table { width: 100%; font-size: 0.875rem; line-height: 1.25rem; text-align: left; }
.quest-table thead { background: #f9fafb; color: #4b5563; font-weight: 500; white-space: nowrap; }
.quest-table th { padding: 0.75rem 1rem; font-weight: 500; }
.quest-table td { padding: 0.75rem 1rem; }
.quest-table tbody tr { border-top: 1px solid #f3f4f6; cursor: default; transition: background-color 150ms, transform 150ms; }
.quest-table tbody tr:first-child { border-top: 0; }
.quest-table tbody tr:hover { background: #f9fafb; transform: scale(1.01); }
.quest-table tbody tr:hover .quest-class { color: #9333ea; }
.quest-class { font-weight: 600; color: #111827; }
.text-center { text-align: center; }
.quest-done {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    box-shadow: var(--shadow-sm);
    margin: 0 auto;
    animation: pop-in 0.3s ease-out both;
}
.quest-done.green { background: #dcfce7; color: #16a34a; }
.quest-done.blue  { background: #dbeafe; color: #2563eb; }
.quest-done.cyan  { background: #cffafe; color: #0891b2; }
.quest-todo { display: inline-block; width: 0.75rem; height: 0.75rem; border-radius: 9999px; background: #e5e7eb; }
@keyframes pop-in { from { transform: scale(0); } to { transform: scale(1); } }
.empty-row { text-align: center; padding: 2rem 0; color: #6b7280; }

.dash-row2 { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 1024px) { .dash-row2 { grid-template-columns: repeat(2, 1fr); } }

.chart-pending {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 12rem;
    color: #9ca3af;
    border: 2px dashed #f3f4f6;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    text-align: center;
    padding: 1rem;
}

/* Hall of Fame */
.hof-list { display: flex; flex-direction: column; gap: 0.75rem; flex: 1; }
.hof-item {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    border-radius: 1rem;
    background: #ffffff;
    border: 1px solid #f3f4f6;
    box-shadow: var(--shadow-sm);
    cursor: default;
    transition: all 150ms;
}
.hof-item:hover { box-shadow: var(--shadow-md); transform: scale(1.02); }
.hof-rank {
    width: 3rem;
    height: 3rem;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    font-weight: 900;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    z-index: 1;
    background: #f3f4f6;
    color: #4b5563;
}
.hof-rank.r1 { background: linear-gradient(to bottom right, #fcd34d, #f59e0b); color: #fff; }
.hof-rank.r2 { background: linear-gradient(to bottom right, #cbd5e1, #64748b); color: #fff; }
.hof-rank.r3 { background: linear-gradient(to bottom right, #fdba74, #f97316); color: #fff; }
.hof-info { flex: 1; min-width: 0; z-index: 1; }
.hof-class { font-weight: 700; color: #111827; font-size: 1rem; }
.hof-building { font-size: 0.75rem; line-height: 1rem; color: #6b7280; font-weight: 500; }
.hof-score-wrap { text-align: right; z-index: 1; display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }
.hof-score { font-weight: 900; color: #111827; font-size: 1.125rem; line-height: 1.75rem; }
.hof-grade { font-size: 10px; font-weight: 700; padding: 0.125rem 0.5rem; border-radius: 0.375rem; box-shadow: var(--shadow-sm); background: #f3f4f6; color: #6b7280; }
.hof-grade.gold   { background: linear-gradient(to right, #fbbf24, #f59e0b); color: #fff; }
.hof-grade.silver { background: linear-gradient(to right, #94a3b8, #64748b); color: #fff; }
.hof-grade.bronze { background: linear-gradient(to right, #fb923c, #f97316); color: #fff; }
.hof-glow { position: absolute; right: -1rem; top: -1rem; width: 5rem; height: 5rem; border-radius: 9999px; opacity: 0.1; filter: blur(24px); pointer-events: none; }
.hof-glow.r1 { background: #f59e0b; }
.hof-glow.r2 { background: #64748b; }
.hof-glow.r3 { background: #f97316; }
.hof-empty { font-size: 0.875rem; color: #6b7280; padding: 1rem 0; text-align: center; border: 2px dashed #f3f4f6; border-radius: 0.75rem; }

/* ==============================================================================
   AUTH — app/(auth)/login, components/auth/login-form.tsx, nature-background.tsx
   ============================================================================== */
.auth-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background: linear-gradient(to bottom, #f0fdf4, rgba(209, 250, 229, 0.5));
}
.auth-page.auth-register {
    padding: 3rem 0;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(22,163,74,0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(37,99,235,0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 100%, rgba(16,185,129,0.1) 0%, transparent 50%),
        #f7fbf7;
}
.auth-deco-1 { position: absolute; top: 5rem; left: 5rem; width: 16rem; height: 16rem; background: rgba(187, 247, 208, 0.3); border-radius: 9999px; filter: blur(64px); pointer-events: none; }
.auth-deco-2 { position: absolute; bottom: 5rem; right: 5rem; width: 24rem; height: 24rem; background: rgba(191, 219, 254, 0.2); border-radius: 9999px; filter: blur(64px); pointer-events: none; }

.auth-wrap {
    width: 100%;
    max-width: 28rem;
    margin: 0 auto;
    padding: 0 1rem;
    position: relative;
    z-index: 10;
    animation: auth-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes auth-in { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }

.auth-card {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: 24px;
    box-shadow: var(--shadow-glass);
    border: 1px solid rgba(255, 255, 255, 0.5);
    overflow: hidden;
    position: relative;
}
.auth-card-header {
    background: linear-gradient(to bottom right, rgba(34, 197, 94, 0.9), rgba(5, 150, 105, 0.9));
    padding: 2.5rem 2rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.auth-card-pattern {
    position: absolute;
    inset: 0;
    background-image: url('https://www.transparenttextures.com/patterns/cubes.png');
    opacity: 0.2;
}
.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 5rem;
    height: 5rem;
    background: #ffffff;
    border-radius: 1rem;
    margin-bottom: 1rem;
    padding: 0.5rem;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: logo-pop 0.6s 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.auth-logo img { width: 100%; height: 100%; object-fit: contain; }
@keyframes logo-pop { from { transform: scale(0); } to { transform: scale(1); } }
.auth-title { font-size: 1.5rem; line-height: 2rem; font-weight: 700; color: #ffffff; position: relative; }
.auth-subtitle { color: #dcfce7; font-size: 0.875rem; line-height: 1.25rem; margin-top: 0.25rem; position: relative; }

.auth-body { padding: 2rem; display: flex; flex-direction: column; gap: 1.25rem; }

.btn-google {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.9);
    font-weight: 700;
    color: #1f2937;
    box-shadow: var(--shadow-sm);
    transition: all 300ms;
}
.btn-google:hover { background: #ffffff; box-shadow: var(--shadow-lg); border-color: #4ade80; color: #15803d; transform: scale(1.02); }
.btn-google:active { transform: scale(0.98); }
.btn-google span { font-size: 1.125rem; line-height: 1.75rem; letter-spacing: -0.025em; }
.btn-google svg { width: 1.5rem; height: 1.5rem; }

.auth-divider { position: relative; }
.auth-divider-line { position: absolute; inset: 0; display: flex; align-items: center; }
.auth-divider-line div { width: 100%; border-top: 1px solid #e5e7eb; }
.auth-divider-text {
    position: relative;
    display: flex;
    justify-content: center;
    font-size: 0.75rem;
    line-height: 1rem;
    text-transform: uppercase;
    font-weight: 500;
}
.auth-divider-text span {
    padding: 0 0.75rem;
    color: #6b7280;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.auth-alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    border: 1px solid;
    animation: slide-in 0.3s ease-out both;
}
.auth-alert.error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.auth-alert.success { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }
@keyframes slide-in { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-label { display: block; font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; color: #374151; margin-bottom: 0.375rem; }
.input-wrap { position: relative; }
.input-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    height: 1rem;
    color: #9ca3af;
    pointer-events: none;
}
.auth-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: #111827;
    box-shadow: var(--shadow-sm);
    outline: none;
    transition: all 150ms;
}
.auth-input::placeholder { color: #9ca3af; }
.auth-input:hover { box-shadow: var(--shadow-md); }
.auth-input:focus { background: #ffffff; box-shadow: 0 0 0 2px #4ade80; }
.auth-input.has-toggle { padding-right: 3rem; }
.input-toggle {
    position: absolute;
    right: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    display: flex;
}
.input-toggle:hover { color: #4b5563; }

.btn-auth-submit {
    width: 100%;
    padding: 0.875rem 0;
    border-radius: 16px;
    background: linear-gradient(to right, #10b981, #16a34a);
    color: #ffffff;
    font-weight: 700;
    font-size: 1.125rem;
    line-height: 1.75rem;
    box-shadow: var(--shadow-lg);
    transition: all 150ms;
}
.btn-auth-submit:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 10px 15px -3px rgba(74, 222, 128, 0.4), 0 4px 6px -4px rgba(74, 222, 128, 0.4); }
.btn-auth-submit:active { transform: scale(0.98); }

.auth-link-row { padding-top: 0.5rem; text-align: center; }
.auth-link { font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; color: #16a34a; }
.auth-link:hover { color: #15803d; }
.auth-footer { text-align: center; font-size: 0.75rem; line-height: 1rem; color: #9ca3af; padding-top: 0.5rem; border-top: 1px solid #f3f4f6; }

/* Dev-only (env = development + mock_mode) — ไม่ใช่ส่วนของดีไซน์ต้นฉบับ */
.dev-accounts {
    margin-top: 1rem;
    padding: 0.75rem 0.875rem;
    background: rgba(255, 255, 255, 0.85);
    border: 1px dashed #f59e0b;
    border-radius: 0.75rem;
    font-size: 0.75rem;
    line-height: 1.25rem;
    color: #374151;
}
.dev-accounts strong { color: #b45309; }
.dev-accounts code { font-family: ui-monospace, Consolas, monospace; font-size: 0.7rem; }

/* Register card (register-form.tsx) */
.reg-card {
    background: #ffffff;
    border-radius: 1rem;
    box-shadow: var(--shadow-2xl);
    border: 1px solid #f3f4f6;
    overflow: hidden;
}
.reg-header { padding: 2rem; text-align: center; }
.reg-roles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
.reg-role {
    padding: 0.75rem;
    border-radius: 0.75rem;
    border: 2px solid #f3f4f6;
    background: #ffffff;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: #6b7280;
    transition: all 150ms;
}
.reg-role:hover { border-color: #e5e7eb; }
.reg-role.active-green { border-color: #22c55e; background: #f0fdf4; color: #15803d; }
.reg-role.active-indigo { border-color: #6366f1; background: #eef2ff; color: #4338ca; }
.reg-input {
    width: 100%;
    padding: 0.625rem 1rem 0.625rem 2.5rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    outline: none;
    color: #111827;
    transition: all 150ms;
    appearance: none;
}
.reg-input:focus { border-color: #22c55e; box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2); }
.reg-input.code { text-transform: uppercase; font-weight: 500; letter-spacing: 0.05em; }
.reg-input.code:focus { border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2); }
.reg-input-icon-indigo { color: #6366f1; }
.btn-reg-submit {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
    margin-top: 0.5rem;
    border-radius: 0.75rem;
    color: #ffffff;
    font-weight: 500;
    background: #16a34a;
    box-shadow: 0 10px 15px -3px rgba(187, 247, 208, 0.5), 0 4px 6px -4px rgba(187, 247, 208, 0.5);
    transition: all 150ms;
}
.btn-reg-submit:hover { background: #15803d; }
.btn-reg-submit:active { transform: scale(0.98); }
.reg-divider { position: relative; padding-top: 0.5rem; }
.reg-divider .auth-divider-line { padding-top: 0.5rem; }
.reg-divider .auth-divider-text { padding-top: 0.5rem; font-weight: 400; }
.reg-divider .auth-divider-text span { background: #ffffff; color: #9ca3af; backdrop-filter: none; }
.btn-reg-back {
    width: 100%;
    display: block;
    text-align: center;
    padding: 0.625rem 0;
    border-radius: 0.75rem;
    font-weight: 500;
    color: #4b5563;
}
.btn-reg-back:hover { background: #f9fafb; }

/* ── Nature background (nature-background.tsx) ───────────────────────────── */
.nature-bg {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
    background: linear-gradient(to bottom right, #f0fdf4, rgba(236, 253, 245, 0.8), rgba(239, 246, 255, 0.5));
}
.nature-sun {
    position: absolute;
    top: 2.5rem;
    left: 2.5rem;
    width: 24rem;
    height: 24rem;
    background: rgba(254, 240, 138, 0.4);
    border-radius: 9999px;
    filter: blur(100px);
    animation: sun-pulse 8s ease-in-out infinite;
}
@keyframes sun-pulse {
    0%, 100% { transform: scale(1); opacity: 0.3; }
    50% { transform: scale(1.05); opacity: 0.4; }
}
.nature-cloud { position: absolute; filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.05)); }
.nature-cloud svg { width: 100%; height: 100%; fill: #ffffff; }
.cloud-1 { top: 6rem; left: -8rem; width: 8rem; height: 8rem; color: rgba(255,255,255,0.8); animation: cloud-r1 60s linear infinite; }
.cloud-2 { top: 10rem; left: -12rem; width: 12rem; height: 12rem; color: rgba(255,255,255,0.7); animation: cloud-r2 80s linear infinite; animation-delay: -20s; }
.cloud-3 { top: 4rem; right: -8rem; width: 6rem; height: 6rem; color: rgba(255,255,255,0.6); animation: cloud-l 90s linear infinite; animation-delay: -10s; }
@keyframes cloud-r1 { from { transform: translateX(0); } to { transform: translateX(1000px); } }
@keyframes cloud-r2 { from { transform: translateX(0); } to { transform: translateX(1500px); } }
@keyframes cloud-l  { from { transform: translateX(0); } to { transform: translateX(-1000px); } }

.nature-bird { position: absolute; }
.nature-bird svg { width: 100%; height: 100%; fill: #bae6fd; }
.bird-1 { top: 8rem; left: 0; width: 2rem; height: 2rem; color: #7dd3fc; opacity: 0.6; animation: bird-1 25s linear infinite; }
.bird-2 { top: 7rem; left: 1rem; width: 1.5rem; height: 1.5rem; color: #38bdf8; opacity: 0.5; animation: bird-2 28s linear infinite; animation-delay: 2s; }
@keyframes bird-1 {
    0% { transform: translate(-100px, 0); } 25% { transform: translate(425px, -50px); }
    50% { transform: translate(950px, 20px); } 75% { transform: translate(1475px, -30px); }
    100% { transform: translate(2000px, 0); }
}
@keyframes bird-2 {
    0% { transform: translate(-100px, 0); } 25% { transform: translate(425px, 30px); }
    50% { transform: translate(950px, -20px); } 75% { transform: translate(1475px, 10px); }
    100% { transform: translate(2000px, 0); }
}

.nature-trees {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 12rem;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 0 10%;
    opacity: 0.4;
}
.nature-trees > div { transform-origin: bottom center; }
.tree-1 { width: 12rem; height: 12rem; color: #059669; animation: sway-a 4s ease-in-out infinite; }
.tree-1 svg { fill: rgba(16, 185, 129, 0.2); }
.tree-2 { width: 10rem; height: 10rem; color: #16a34a; animation: sway-b 5s ease-in-out infinite; animation-delay: 1s; }
.tree-2 svg { fill: rgba(34, 197, 94, 0.2); }
.tree-3 { width: 14rem; height: 14rem; color: #0d9488; animation: sway-c 4.5s ease-in-out infinite; animation-delay: 2s; display: none; }
.tree-3 svg { fill: rgba(20, 184, 166, 0.2); }
.nature-trees svg { width: 100%; height: 100%; }
@media (min-width: 768px) { .tree-3 { display: block; } }
@keyframes sway-a { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
@keyframes sway-b { 0%, 100% { transform: rotate(1deg); } 50% { transform: rotate(-1deg); } }
@keyframes sway-c { 0%, 100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } }

.falling-leaf {
    position: absolute;
    top: 0;
    left: 0;
    width: 1.5rem;
    height: 1.5rem;
    color: rgba(16, 185, 129, 0.4);
    opacity: 0;
    animation: leaf-fall var(--duration, 15s) linear infinite;
    animation-delay: var(--delay, 0s);
}
.falling-leaf svg { width: 100%; height: 100%; fill: rgba(52, 211, 153, 0.2); transform: scale(var(--scale, 1)); }
@keyframes leaf-fall {
    0%   { transform: translate(var(--x0), -10vh) rotate(0deg); opacity: 0; }
    50%  { opacity: 0.8; }
    100% { transform: translate(var(--x1), 110vh) rotate(360deg); opacity: 0; }
}

.nature-mascot {
    position: absolute;
    bottom: 3rem;
    right: 15%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    cursor: pointer;
    animation: mascot-float 4s ease-in-out infinite;
}
@media (min-width: 1024px) { .nature-mascot { display: flex; } }
@keyframes mascot-float {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-15px) rotate(5deg); }
}
.mascot-body-wrap { position: relative; }
.mascot-body {
    width: 6rem;
    height: 6rem;
    background: linear-gradient(to bottom right, #86efac, #10b981);
    border-radius: 40%;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
}
.mascot-body svg { width: 3rem; height: 3rem; fill: rgba(255, 255, 255, 0.2); }
.mascot-leaf { position: absolute; top: -1rem; right: -0.5rem; width: 2rem; height: 2rem; color: #059669; transform: rotate(45deg); }
.mascot-leaf svg { width: 100%; height: 100%; fill: #34d399; }
.mascot-sparkle { position: absolute; top: -1.5rem; left: -1rem; width: 1.5rem; height: 1.5rem; color: #facc15; opacity: 0; transition: opacity 150ms; }
.mascot-sparkle svg { width: 100%; height: 100%; fill: #facc15; }
.mascot-bubble {
    margin-top: 1rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(4px);
    padding: 0.5rem 1rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 700;
    color: #047857;
    opacity: 0;
    transition: opacity 150ms;
    white-space: nowrap;
}
.nature-mascot:hover .mascot-sparkle,
.nature-mascot:hover .mascot-bubble { opacity: 1; }

/* ── Confetti (ใช้โดย app.js) ───────────────────────────────────────────────── */
.confetti-particle {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    will-change: transform, opacity;
}

/* ── Print ──────────────────────────────────────────────────────────────────── */
@media print {
    @page { size: A4; margin: 1.5cm; }
    body {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        background: white !important;
        color: black !important;
    }
    .no-print, .sidebar, .top-navbar, .sidebar-backdrop { display: none !important; }
    .app-layout { height: auto; overflow: visible; display: block; }
    .main-wrapper { margin-left: 0 !important; overflow: visible; }
    .page-content { padding: 0; overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* ==============================================================================
   WATER BOTTLE ANNOUNCEMENT SETTINGS (หน้าใหม่ — ไม่มีในต้นฉบับ ใช้ token เดิม)
   ============================================================================== */
.wa-page { display: flex; flex-direction: column; gap: 1.5rem; }
.wa-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.wa-notice {
    display: flex; gap: 0.75rem; align-items: flex-start;
    padding: 1rem 1.25rem; border-radius: 0.75rem;
    background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
    font-size: 0.875rem; line-height: 1.5;
}
.wa-notice strong { display: block; color: #78350f; }
.wa-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 1024px) { .wa-grid { grid-template-columns: 3fr 2fr; } }
.wa-form .section-title-lg, .wa-range .section-title-lg { margin-bottom: 1rem; font-size: 1.05rem; }
.wa-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.wa-meta { margin-top: 0.75rem; font-size: 0.75rem; color: #6b7280; line-height: 1.5; }
.wa-error { margin-top: 0.375rem; font-size: 0.75rem; color: #b91c1c; }
.form-input.is-invalid { border-color: #f87171; background: #fef2f2; }
.wa-warning { display: flex; gap: 0.5rem; align-items: flex-start; margin-top: 0.5rem; font-size: 0.8125rem; color: #92400e; }
.wa-dl { display: grid; grid-template-columns: auto 1fr; gap: 0.375rem 1rem; font-size: 0.875rem; }
.wa-dl dt { color: #6b7280; }
.wa-dl dd { color: #111827; }
.wa-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
@media (min-width: 768px) { .wa-stats { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1280px) { .wa-stats { grid-template-columns: repeat(6, 1fr); } }
.wa-stat { background: #fff; border: 1px solid #f3f4f6; border-radius: 1rem; padding: 0.875rem 1rem; box-shadow: var(--shadow-sm); border-left: 4px solid #16a34a; }
.wa-stat span { display: block; font-size: 0.75rem; color: #6b7280; }
.wa-stat strong { font-size: 1.5rem; font-weight: 800; color: #111827; }
.wa-stat.warn { border-left-color: #f59e0b; }
.wa-stat.bad { border-left-color: #ef4444; }
.wa-stat.muted { border-left-color: #9ca3af; }
.wa-table { font-size: 0.875rem; }
.wa-table th { text-transform: none; letter-spacing: 0; white-space: nowrap; }
.wa-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wa-table tfoot td { font-weight: 700; background: #f9fafb; padding: 0.75rem 1rem; }
.wa-row-empty td { background: #fafafa; }
.wa-muted { color: #9ca3af; font-size: 0.8125rem; }
.wa-issues { margin-top: 0.25rem; font-size: 0.7rem; color: #92400e; max-width: 18rem; }
.wa-flag { margin-top: 0.25rem; font-size: 0.7rem; color: #b91c1c; }
.wa-badge { display: inline-block; padding: 0.0625rem 0.5rem; border-radius: 9999px; font-size: 0.7rem; font-weight: 600; white-space: nowrap; }
.wa-badge.ok { background: #dcfce7; color: #15803d; }
.wa-badge.warn { background: #fef3c7; color: #b45309; }
.wa-badge.bad { background: #fee2e2; color: #b91c1c; }
.wa-badge.info { background: #e0f2fe; color: #0369a1; }
.wa-badge.muted { background: #f3f4f6; color: #6b7280; }
.wa-formula { font-size: 0.875rem; color: #374151; display: flex; flex-direction: column; gap: 0.375rem; }
.wa-formula code { font-size: 0.8rem; background: #f3f4f6; padding: 0 0.25rem; border-radius: 0.25rem; }
.wa-detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.wa-threshold summary { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-weight: 600; color: #92400e; }
.wa-threshold[open] summary { margin-bottom: 0.75rem; }
.wa-table td:first-child { white-space: nowrap; }

/* Filter bar & submission stats (ใช้ร่วมกันกับหน้าประกาศผล) */
.wa-filter { display: grid; grid-template-columns: 1fr; gap: 0 1rem; align-items: end; padding: 1.25rem 1.5rem; }
@media (min-width: 768px) { .wa-filter { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.wa-filter .form-group { margin-bottom: 0.75rem; }
.wa-filter-submit .btn { width: 100%; }
.wa-filter-note { grid-column: 1 / -1; margin-top: 0; }
.wa-module-totals { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 1024px) { .wa-module-totals { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.wa-module-card h3 { font-size: 1rem; font-weight: 700; margin-bottom: 0.75rem; color: #111827; }
.wa-row-first td { border-top: 2px solid #e5e7eb; }
.wa-nowrap { white-space: nowrap; }
.wa-room-link { font-weight: 700; color: #15803d; white-space: nowrap; } .wa-room-link:hover { text-decoration: underline; }
.wa-subhead { margin-top: 1.25rem; }
.wa-period-table td:last-child { min-width: 18rem; } .wa-period-table .form-input { min-width: 10rem; }

/* ===== Semester selector & banner (ภาคเรียน) ===== */
.header-semester { display: flex; align-items: center; gap: 0.25rem; }
.header-semester .form-input { padding: 0.375rem 0.625rem; font-size: 0.8125rem; max-width: 15rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.sem-banner { display: flex; gap: 0.625rem; align-items: flex-start; padding: 0.75rem 1rem; margin-bottom: 1rem; border: 1px solid #bbf7d0; border-radius: 0.75rem; background: #f0fdf4; color: #166534; font-size: 0.875rem; }
.sem-banner p { margin: 0.25rem 0 0; }
.sem-banner .sem-status { margin-left: 0.375rem; font-weight: 600; }
.sem-banner .sem-range { margin-left: 0.25rem; color: #4b5563; }
.sem-banner.sem-past { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.sem-banner.sem-upcoming { border-color: #bfdbfe; background: #eff6ff; color: #1e40af; }
.sem-banner.sem-static { border-color: #e5e7eb; background: #f9fafb; color: #374151; }
.wa-page > .sem-banner { margin-bottom: 0; }
@media (max-width: 640px) {
    .header-semester .form-input { max-width: 9.5rem; font-size: 0.75rem; }
}

/* ===== Dashboard Gamification — Emerald / Ivory / Gold ===== */
:root {
    --emerald-900: #064e3b;
    --emerald-800: #065f46;
    --emerald-700: #047857;
    --emerald-600: #059669;
    --emerald-500: #10b981;
    --emerald-100: #d1fae5;
    --emerald-50: #ecfdf5;
    --ivory: #fffdf5;
    --ivory-200: #f6f0dc;
    --ivory-300: #ece3c4;
    --gold-600: #b7861b;
    --gold-500: #d4a72c;
    --gold-400: #e8c25a;
    --gold-100: #fbf1d3;
}
.gd { gap: 1.25rem; }
.gd-hero {
    position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 1rem;
    padding: 1.5rem; border-radius: 1.25rem; color: var(--ivory);
    background: radial-gradient(120% 140% at 100% 0%, rgba(232, 194, 90, 0.28) 0%, rgba(232, 194, 90, 0) 45%),
                linear-gradient(135deg, var(--emerald-800) 0%, var(--emerald-700) 55%, var(--emerald-600) 100%);
    box-shadow: 0 10px 30px -12px rgba(6, 78, 59, 0.55);
}
.gd-hero::after {
    content: ""; position: absolute; right: -2.5rem; bottom: -2.5rem; width: 10rem; height: 10rem; border-radius: 9999px;
    border: 2px solid rgba(255, 253, 245, 0.18); pointer-events: none;
}
.gd-hello { font-size: 0.9375rem; opacity: 0.9; }
.gd-title { font-size: 1.625rem; line-height: 2.125rem; font-weight: 800; letter-spacing: -0.01em; }
.gd-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.gd-chip {
    display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.3rem 0.75rem; border-radius: 9999px;
    font-size: 0.8125rem; font-weight: 600; background: rgba(255, 253, 245, 0.16); border: 1px solid rgba(255, 253, 245, 0.28);
}
.gd-chip-mock { background: var(--gold-100); color: #7a5410; border-color: var(--gold-400); }
.gd-hero-asof {
    position: relative; z-index: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 0.125rem; padding: 0.875rem 1.125rem;
    border-radius: 1rem; background: rgba(6, 78, 59, 0.55); border: 1px solid rgba(232, 194, 90, 0.55); min-width: 11rem;
}
.gd-asof-num { font-size: 2.25rem; line-height: 1; font-weight: 800; color: var(--gold-400); }
.gd-asof-label { font-size: 0.8125rem; opacity: 0.92; line-height: 1.35; }
.gd-asof-date { font-size: 1.0625rem; font-weight: 700; color: var(--gold-400); }
@media (min-width: 768px) {
    .gd-hero { flex-direction: row; align-items: center; justify-content: space-between; padding: 1.75rem 2rem; }
    .gd-hero-asof { align-items: flex-end; text-align: right; }
}

.gd-mock-note {
    display: flex; gap: 0.625rem; align-items: flex-start; padding: 0.75rem 1rem; border-radius: 0.875rem;
    background: var(--gold-100); border: 1px solid var(--gold-400); color: #6b4a0e; font-size: 0.875rem;
}

.gd-card {
    background: var(--ivory); border: 1px solid var(--ivory-300); border-radius: 1.25rem; padding: 1.25rem;
    box-shadow: 0 1px 2px rgba(6, 78, 59, 0.06), 0 6px 18px -10px rgba(6, 78, 59, 0.18);
}
.gd-card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.gd-card-head.gd-wrap { flex-wrap: wrap; align-items: flex-start; }
.gd-card-title { display: flex; align-items: center; gap: 0.5rem; font-size: 1.0625rem; font-weight: 700; color: var(--emerald-900); }
.gd-card-title svg { color: var(--emerald-600); }
.gd-card-sub { margin-top: 0.25rem; font-size: 0.8125rem; color: #6b7280; }
.gd-tag { padding: 0.15rem 0.6rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 700; background: var(--gold-100); color: var(--gold-600); border: 1px solid var(--gold-400); }
.gd-count { min-width: 1.75rem; height: 1.75rem; display: inline-grid; place-items: center; border-radius: 9999px; font-size: 0.8125rem; font-weight: 700; background: var(--emerald-100); color: var(--emerald-800); }
.gd-footnote { margin-top: 0.875rem; font-size: 0.75rem; line-height: 1.5; color: #6b7280; }
.gd-gold-text { color: var(--gold-600); font-weight: 600; }

.gd-top { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
@media (min-width: 1024px) { .gd-top { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; } }

/* ต้นไม้ดิจิทัล */
.gd-tree-card { text-align: center; }
.gd-tree-stage { position: relative; display: grid; place-items: center; padding: 0.5rem 0 0.25rem; }
.gd-tree-ring {
    position: relative; z-index: 1; width: 8.5rem; height: 8.5rem; border-radius: 9999px; display: grid; place-items: center;
    background: radial-gradient(circle at 50% 35%, #ffffff 0%, var(--emerald-50) 70%);
    border: 3px solid var(--emerald-100); transition: transform 300ms ease;
}
.gd-tree-icon { color: var(--emerald-600); display: grid; place-items: center; }
.icon-tree { width: 3rem; height: 3rem; transition: transform 300ms ease; }
.lv0 .gd-tree-icon, .lv1 .gd-tree-icon { color: var(--gold-500); }
.lv2 .icon-tree { width: 3.75rem; height: 3.75rem; }
.lv3 .icon-tree { width: 4.25rem; height: 4.25rem; color: var(--emerald-700); }
.lv4 .icon-tree { width: 4.75rem; height: 4.75rem; color: var(--emerald-800); }
.lv4 .gd-tree-ring { border-color: var(--gold-400); box-shadow: 0 0 0 6px rgba(232, 194, 90, 0.22), 0 10px 24px -10px rgba(183, 134, 27, 0.6); }
.lv0 .gd-tree-ring { filter: grayscale(0.4); opacity: 0.85; }
.gd-tree-ring:hover { transform: translateY(-2px) scale(1.02); }
.gd-ground { width: 11rem; height: 0.875rem; margin-top: -0.375rem; border-radius: 50%; background: radial-gradient(ellipse at center, rgba(6, 95, 70, 0.22) 0%, rgba(6, 95, 70, 0) 70%); }
.gd-tree-name { margin-top: 0.5rem; font-size: 1.25rem; font-weight: 800; color: var(--emerald-900); }
.gd-tree-name span { margin-left: 0.25rem; font-size: 0.8125rem; font-weight: 700; color: var(--gold-600); }
.gd-tree-rate { margin-top: 0.25rem; font-size: 0.875rem; color: #4b5563; }
.gd-tree-rate strong { color: var(--emerald-700); }
.gd-bar { height: 0.625rem; margin: 0.875rem auto 0; max-width: 20rem; border-radius: 9999px; background: var(--ivory-200); overflow: hidden; }
.gd-bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--emerald-500), var(--gold-400)); transition: width 600ms ease; }
.gd-bar.thin { height: 0.5rem; margin: 0.5rem 0 0; max-width: none; }
.gd-bar-note { margin-top: 0.375rem; font-size: 0.8125rem; color: #6b7280; }
.gd-steps { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.375rem; margin-top: 1.125rem; padding: 0; }
.gd-steps li { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; padding: 0.5rem 0.25rem; border-radius: 0.75rem; background: #ffffff; border: 1px solid var(--ivory-300); color: #9ca3af; }
.gd-steps li.on { color: var(--emerald-700); border-color: var(--emerald-100); background: var(--emerald-50); }
.gd-steps li.now { border-color: var(--gold-400); box-shadow: 0 0 0 2px rgba(232, 194, 90, 0.35); }
.gd-step-name { font-size: 0.75rem; font-weight: 700; line-height: 1.2; }
.gd-step-min { font-size: 0.6875rem; color: #9ca3af; }

/* การ์ดความก้าวหน้า */
.gd-progress { display: grid; grid-template-columns: 1fr; gap: 1rem; align-content: start; }
@media (min-width: 640px) { .gd-progress { grid-template-columns: repeat(3, 1fr); } }
.gd-progress-note { grid-column: 1 / -1; margin-top: 0; }
.gd-prog { display: flex; flex-direction: column; padding: 1rem; transition: transform 200ms ease, box-shadow 200ms ease; }
.gd-prog:hover { transform: translateY(-2px); box-shadow: 0 10px 24px -12px rgba(6, 78, 59, 0.35); }
.gd-prog-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.625rem; }
.gd-prog-icon { width: 2.25rem; height: 2.25rem; flex: none; display: grid; place-items: center; border-radius: 0.75rem; color: #ffffff; }
.gd-prog-icon.area { background: linear-gradient(135deg, var(--emerald-600), var(--emerald-800)); }
.gd-prog-icon.classroom { background: linear-gradient(135deg, var(--emerald-500), var(--emerald-700)); }
.gd-prog-icon.water { background: linear-gradient(135deg, var(--gold-400), var(--gold-600)); }
.gd-prog-title { font-size: 0.875rem; font-weight: 700; color: var(--emerald-900); line-height: 1.3; }
.gd-prog-value { font-size: 1.75rem; font-weight: 800; color: var(--emerald-800); line-height: 1.1; }
.gd-prog-wait { font-size: 0.9375rem; font-weight: 700; color: var(--gold-600); }
.gd-prog-sub { margin-top: 0.375rem; font-size: 0.75rem; color: #6b7280; }
.gd-prog-period { margin-top: auto; padding-top: 0.625rem; font-size: 0.6875rem; color: #9ca3af; }

/* งานที่ต้องติดตาม */
.gd-tasks { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; padding: 0; }
.gd-task { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.75rem 0.875rem; border-radius: 0.875rem; background: #ffffff; border: 1px solid var(--ivory-300); }
.gd-task-dot { width: 0.625rem; height: 0.625rem; margin-top: 0.4rem; flex: none; border-radius: 9999px; background: #9ca3af; }
.gd-task.danger .gd-task-dot { background: #dc2626; box-shadow: 0 0 0 3px #fee2e2; }
.gd-task.warn .gd-task-dot { background: var(--gold-500); box-shadow: 0 0 0 3px var(--gold-100); }
.gd-task.info .gd-task-dot { background: var(--emerald-500); box-shadow: 0 0 0 3px var(--emerald-100); }
.gd-task-body { flex: 1; min-width: 0; }
.gd-task-title { font-size: 0.875rem; font-weight: 700; color: #1f2937; }
.gd-task-detail { font-size: 0.75rem; color: #6b7280; margin-top: 0.125rem; }
.gd-task-link { flex: none; font-size: 0.8125rem; font-weight: 700; color: var(--emerald-700); text-decoration: none; white-space: nowrap; }
.gd-task-link:hover { color: var(--gold-600); }
.gd-empty { display: flex; align-items: center; gap: 0.5rem; color: var(--emerald-700); font-weight: 600; font-size: 0.875rem; }

/* ภารกิจประจำวัน */
.gd-quest { width: 100%; font-size: 0.875rem; border-collapse: separate; border-spacing: 0; }
.gd-quest th { padding: 0.625rem 0.75rem; font-weight: 600; font-size: 0.8125rem; color: var(--emerald-900); background: var(--ivory-200); white-space: nowrap; text-align: left; }
.gd-quest th.text-center { text-align: center; }
.gd-quest th:first-child { border-radius: 0.75rem 0 0 0.75rem; }
.gd-quest th:last-child { border-radius: 0 0.75rem 0.75rem 0; }
.gd-quest td { padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--ivory-200); }
.gd-quest-class { font-weight: 700; color: #1f2937; white-space: nowrap; }
.gd-pill { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.gd-pill.ok { background: var(--emerald-100); color: var(--emerald-800); }
.gd-pill.ok2 { background: #ccfbf1; color: #0f766e; }
.gd-pill.gold { background: var(--gold-100); color: var(--gold-600); }
.gd-pill.warn { background: #ffedd5; color: #c2410c; }
.gd-pill.bad { background: #fee2e2; color: #b91c1c; }
.gd-pill.muted { background: #f3f4f6; color: #4b5563; }
.gd-pill.none { background: #ffffff; color: #9ca3af; border: 1px dashed #d1d5db; }
.gd-pill.na { background: transparent; color: #9ca3af; }
@media (max-width: 639.98px) {
    .gd-card { padding: 1rem; border-radius: 1rem; }
    .gd-title { font-size: 1.375rem; line-height: 1.875rem; }
    .gd-hero-asof { min-width: 0; }
    .gd-quest th, .gd-quest td { padding: 0.5rem; }
}
@media (prefers-reduced-motion: reduce) {
    .gd-tree-ring, .gd-prog, .gd-bar span, .icon-tree { transition: none; }
}

/* ===== ตั้งค่า: ฟอร์มแก้ไขข้อมูลหลัก (W3) ===== */
.md-details { display: inline-block; position: relative; text-align: left; }
.md-details > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; user-select: none; }
.md-details > summary::-webkit-details-marker { display: none; }
.md-details[open] { display: block; width: 100%; }
.md-form {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem;
    margin-top: 0.5rem; padding: 1rem; background: #ffffff; border: 1px solid var(--border-strong); border-radius: var(--radius-md, 0.5rem);
    box-shadow: var(--shadow-sm); min-width: min(100%, 22rem);
}
.md-field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.md-field .form-input { font-size: 0.875rem; padding: 0.45rem 0.65rem; }
.md-wide, .md-hint, .md-actions { grid-column: 1 / -1; }
.md-hint { font-size: 0.75rem; color: var(--text-muted); font-weight: 400; }
.md-actions { display: flex; justify-content: flex-end; }
.md-inline { display: inline; }
.md-row-actions { display: flex; flex-wrap: wrap; gap: 0.375rem; justify-content: flex-end; align-items: flex-start; }
.md-btn-off { background: #ffffff; border: 1px solid #fecaca; color: #b91c1c; }
.md-btn-on { background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857; }
.md-badge-off { background: #f3f4f6; color: #6b7280; font-size: 0.7rem; }
.md-row-off { opacity: 0.6; }
.md-row-off .md-row-actions, .md-row-off .md-details { opacity: 1; }
.md-rooms { display: block; }
.md-room-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.75rem; }
.md-room { display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; align-items: flex-start; padding: 0.5rem 0.625rem; background: #ffffff; border: 1px solid var(--border); border-radius: 0.5rem; font-size: 0.85rem; }
.md-room .md-hint { display: block; }

/* นำเข้าบัญชี (W5): ตารางตัวอย่างไม่บีบคอลัมน์ — เลื่อนข้างในกรอบแทน */
.md-import-table { min-width: 760px; }
.md-import-table th, .md-import-table td { padding: 0.55rem 0.65rem; vertical-align: top; text-align: left; }
.md-import-table td:nth-child(5) { white-space: nowrap; }

/* ===== บันทึกแก้วน้ำ (W6) ===== */
.wb-tally { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.wb-chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.3rem 0.7rem; border-radius: 9999px; font-size: 0.8rem; background: #ffffff; border: 1px solid var(--border-strong); color: var(--c, #374151); }
.wb-chip strong { font-size: 0.95rem; }
.wb-rate { --c: #065f46; background: #ecfdf5; border-color: #a7f3d0; }
.wb-table { min-width: 560px; }
.wb-table td, .wb-table th { padding: 0.45rem 0.6rem; }
.wb-table tbody tr:hover { background: #f9fafb; }
.wb-radio { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; padding: 0.15rem; }
.wb-opt-text { display: none; }
/* มือถือ: แต่ละคนเป็นการ์ด — ชื่อด้านบน ตัวเลือก 4 ช่องพร้อมป้ายด้านล่าง (ไม่ต้องเลื่อนข้าง) */
@media (max-width: 640px) {
    .wb-table { min-width: 0; }
    .wb-table thead { display: none; }
    .wb-table tr { display: flex; flex-wrap: wrap; align-items: center; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
    .wb-table td { border: 0 !important; padding: 0.2rem 0.3rem; }
    .wb-table td.num { width: 2.25rem; text-align: right; color: var(--text-muted); }
    .wb-table td.wb-name { flex: 1 1 calc(100% - 2.5rem); font-weight: 600; }
    .wb-table td.wb-opt { flex: 1 1 25%; display: flex; align-items: center; justify-content: center; gap: 0.3rem; font-size: 0.78rem; }
    .wb-opt-text { display: inline !important; color: var(--text-muted); }
}
/* รออนุมัติ (W9) */
.ap-table { min-width: 720px; }
.ap-table td { vertical-align: top; padding: 0.55rem 0.6rem; }
.ap-table .md-details[open] { min-width: 18rem; }

/* รออนุมัติบนมือถือ: แต่ละรายการเป็นการ์ด ปุ่มตัดสินอยู่ล่างสุด (ไม่ต้องเลื่อนข้าง) */
@media (max-width: 640px) {
    .ap-cards { min-width: 0; }
    .ap-cards thead { display: none; }
    .ap-cards tr { display: grid; grid-template-columns: 1fr 1fr; gap: 0.15rem 0.75rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
    .ap-cards td { border: 0 !important; padding: 0.15rem 0 !important; text-align: left !important; }
    .ap-cards td[data-label]::before { content: attr(data-label); display: block; font-size: 0.7rem; color: var(--text-muted); }
    .ap-cards td.ap-actions { grid-column: 1 / -1; padding-top: 0.5rem !important; }
    .ap-cards .md-details[open] { min-width: 0; width: 100%; }
}
/* ===== ประเมินห้องเรียน (W7) ===== */
.ce-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.ce-item { padding: 0.75rem 0.85rem; border: 1px solid var(--border); border-radius: 0.75rem; background: #ffffff; display: flex; flex-direction: column; gap: 0.4rem; }
.ce-head { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.ce-scores { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.ce-score { position: relative; }
.ce-score input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ce-score span { display: inline-grid; place-items: center; min-width: 2.6rem; height: 2.4rem; padding: 0 0.6rem; border-radius: 0.6rem; border: 1px solid var(--border-strong); font-weight: 700; color: #374151; background: #f9fafb; cursor: pointer; transition: all 120ms ease; }
.ce-score input:checked + span { background: #047857; border-color: #047857; color: #ffffff; }
.ce-score input:focus-visible + span { outline: 2px solid #10b981; outline-offset: 2px; }
.ce-num { max-width: 8rem; }
.ce-note { font-size: 0.8rem; padding: 0.35rem 0.6rem; }
/* รายงานสรุปรายห้อง (W10) */
.rp-table { min-width: 1120px; }
.rp-table th, .rp-table td { padding: 0.5rem 0.6rem; }
.rp-group { background: #ecfdf5; color: #065f46; border-bottom: 1px solid #a7f3d0; }

/* ===== การมอบหมายพื้นที่/ครูที่ปรึกษา (W4) ===== */
.as-tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.as-tab { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.5rem 0.9rem; border-radius: 9999px; border: 1px solid var(--border-strong); background: #ffffff; font-size: 0.85rem; font-weight: 600; color: #374151; }
.as-tab.active { background: #065f46; border-color: #065f46; color: #ffffff; }
.as-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; }
.as-grid > * { min-width: 0; }
@media (min-width: 1024px) { .as-grid { grid-template-columns: minmax(18rem, 2fr) 3fr; } }
.as-list, .as-detail { padding: 1.25rem; }
.as-list-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.as-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.375rem; max-height: 70vh; overflow-y: auto; }
.as-item { display: grid; grid-template-columns: 1fr auto; gap: 0.125rem 0.5rem; padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: 0.5rem; background: #ffffff; font-size: 0.85rem; }
.as-item:hover { border-color: #a7f3d0; }
.as-item.active { border-color: #065f46; background: #ecfdf5; }
.as-item-name { font-weight: 700; color: var(--text-main); }
.as-item-cur { grid-column: 1; color: var(--text-muted); font-size: 0.78rem; overflow-wrap: anywhere; }
.as-item .wa-badge { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.as-has { background: #ecfdf5; color: #047857; }
.as-none { background: #fef3c7; color: #92400e; }
.as-subtitle { font-size: 0.9rem; font-weight: 700; margin: 1.1rem 0 0.5rem; color: var(--text-main); }
.as-timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.as-row { padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-left: 4px solid #d1d5db; border-radius: 0.5rem; background: #ffffff; display: flex; flex-direction: column; gap: 0.25rem; }
.as-open { border-left-color: #059669; }
.as-void { opacity: 0.6; text-decoration-line: none; }
.as-void .as-row-main strong, .as-void .as-row-range { text-decoration: line-through; }
.as-row-main { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.as-row-range { font-size: 0.82rem; color: #374151; }
.as-check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 500; }
.wa-notice code { overflow-wrap: anywhere; }
.as-detail { scroll-margin-top: 5rem; }

/* ===== ประเมินพื้นที่ (W8) ===== */
.ae-table { min-width: 640px; }
.ae-table th, .ae-table td { padding: 0.5rem 0.75rem; }

/* ===== การจัดอันดับ / เกียรติบัตร (W13) ===== */
.rk-table { min-width: 720px; }
.rk-steps { margin: 0.5rem 0 0 1.25rem; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: #374151; list-style: decimal; }

/* ===== การแจ้งเตือน ===== */
.nf-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.nf-item > a, .nf-item > div { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.65rem 0.8rem; border: 1px solid var(--border); border-radius: 0.6rem; background: #ffffff; color: var(--text-main); }
.nf-item > a:hover { border-color: #a7f3d0; }
.nf-item span { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; overflow-wrap: anywhere; }
.nf-pending > a { border-left: 4px solid #d97706; }
.nf-rejected > a { border-left: 4px solid #dc2626; }
.st-table { min-width: 620px; }
