/* =========================================================================
   ระบบบริหารจัดการกิจกรรมพหุปัญญา โรงเรียนสา — Theme
   Modern Education Dashboard · Emerald / White / Light gray / Soft gold
   ========================================================================= */
:root {
    --em-900: #064e3b;
    --em-800: #065f46;
    --em-700: #047857;
    --em-600: #059669;
    --em-500: #10b981;
    --em-100: #d1fae5;
    --em-50: #ecfdf5;
    --gold-600: #b08a1e;
    --gold-500: #c9a227;
    --gold-100: #fbf3d9;
    --gray-50: #f7f8f7;
    --gray-100: #f0f2f1;
    --gray-200: #e3e7e5;
    --gray-500: #6b7470;
    --gray-700: #3d4541;
    --ink: #1c2421;
    --radius: 14px;
    --shadow-sm: 0 1px 2px rgba(6, 78, 59, .06), 0 1px 3px rgba(6, 78, 59, .05);
    --shadow: 0 4px 18px rgba(6, 78, 59, .08);
    --sidebar-w: 256px;

    --bs-primary: var(--em-700);
    --bs-primary-rgb: 4, 120, 87;
    --bs-body-font-family: 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', 'Tahoma', sans-serif;
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--gray-50);
    --bs-border-color: var(--gray-200);
    --bs-link-color: var(--em-700);
    --bs-link-hover-color: var(--em-900);
    --bs-link-color-rgb: 4, 120, 87;
    --bs-border-radius: 10px;
}

body { font-size: 1rem; line-height: 1.6; background: var(--gray-50); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, h5, .h1, .h2, .h3, .h4, .h5 { font-weight: 700; color: var(--ink); }
.text-emerald { color: var(--em-700) !important; }
.text-gold { color: var(--gold-600) !important; }
.bg-emerald { background: var(--em-700) !important; color: #fff; }
.bg-emerald-soft { background: var(--em-50) !important; }
.bg-gold-soft { background: var(--gold-100) !important; }
.fw-semibold { font-weight: 600 !important; }
.small-muted { font-size: .875rem; color: var(--gray-500); }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn { font-weight: 600; border-radius: 10px; padding: .5rem 1rem; }
.btn-emerald { background: var(--em-700); border-color: var(--em-700); color: #fff; }
.btn-emerald:hover, .btn-emerald:focus { background: var(--em-800); border-color: var(--em-800); color: #fff; }
.btn-emerald:disabled { background: #9bb5ab; border-color: #9bb5ab; color: #fff; }
.btn-outline-emerald { border-color: var(--em-600); color: var(--em-700); background: #fff; }
.btn-outline-emerald:hover { background: var(--em-50); color: var(--em-800); border-color: var(--em-700); }
.btn-gold { background: var(--gold-500); border-color: var(--gold-500); color: #fff; }
.btn-gold:hover { background: var(--gold-600); border-color: var(--gold-600); color: #fff; }
.btn-lg { padding: .75rem 1.25rem; font-size: 1.05rem; border-radius: 12px; }
.btn-icon { display: inline-flex; align-items: center; gap: .4rem; }
.form-control, .form-select { border-radius: 10px; border-color: var(--gray-200); padding: .55rem .8rem; }
.form-control:focus, .form-select:focus { border-color: var(--em-500); box-shadow: 0 0 0 .2rem rgba(16, 185, 129, .18); }
.form-label { font-weight: 600; font-size: .925rem; color: var(--gray-700); }
.form-check-input:checked { background-color: var(--em-600); border-color: var(--em-600); }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--gray-200); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-header { background: #fff; border-bottom: 1px solid var(--gray-200); font-weight: 700; padding: .9rem 1.1rem; border-radius: var(--radius) var(--radius) 0 0 !important; }
.card-body { padding: 1.1rem; }

.stat-card { position: relative; overflow: hidden; height: 100%; }
.stat-card .stat-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; background: var(--em-50); color: var(--em-700); }
.stat-card .stat-icon.gold { background: var(--gold-100); color: var(--gold-600); }
.stat-card .stat-icon.red { background: #fde8e8; color: #b42318; }
.stat-card .stat-icon.blue { background: #e6f0ff; color: #1d4ed8; }
.stat-card .stat-icon.gray { background: var(--gray-100); color: var(--gray-700); }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-card .stat-label { color: var(--gray-500); font-size: .9rem; }
.stat-card .stat-sub { font-size: .8rem; color: var(--gray-500); }

/* ---------- Progress ---------- */
.progress { height: .6rem; border-radius: 99px; background: var(--gray-100); }
.progress-bar { background: var(--em-600); border-radius: 99px; transition: width .6s ease; }
.progress-bar.warn { background: var(--gold-500); }
.progress-bar.full { background: #c2410c; }

/* ---------- Status badges ---------- */
.badge-status { display: inline-flex; align-items: center; gap: .3rem; padding: .3rem .6rem; border-radius: 99px; font-weight: 600; font-size: .8rem; white-space: nowrap; }
.st-open { background: var(--em-100); color: var(--em-800); }
.st-full { background: #ffe4d5; color: #9a3412; }
.st-admin_closed { background: #fde8e8; color: #9f1239; }
.st-not_open_yet { background: #e6f0ff; color: #1e40af; }
.st-time_ended { background: var(--gray-200); color: var(--gray-700); }
.st-inactive { background: var(--gray-100); color: var(--gray-500); }
.badge-type { display: inline-block; padding: .2rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 600; color: #fff; }

/* ---------- Auth pages ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem;
    background: radial-gradient(1200px 600px at 10% -10%, rgba(16, 185, 129, .25), transparent 60%),
                radial-gradient(900px 500px at 110% 110%, rgba(201, 162, 39, .18), transparent 60%),
                linear-gradient(160deg, var(--em-900), var(--em-700)); }
.auth-card { width: 100%; max-width: 430px; border: 0; border-radius: 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.auth-card .card-body { padding: 2rem 1.75rem; }
.auth-logo { width: 76px; height: 76px; border-radius: 22px; margin: 0 auto 1rem; display: grid; place-items: center; font-size: 2.2rem;
    color: #fff; background: linear-gradient(135deg, var(--em-600), var(--em-800)); box-shadow: 0 8px 22px rgba(4, 120, 87, .35); }
.auth-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: 22px; background: #fff; }
.auth-title { font-size: 1.25rem; text-align: center; margin-bottom: .15rem; }
.auth-sub { text-align: center; color: var(--gray-500); font-size: .9rem; }
.auth-divider { height: 3px; width: 56px; background: var(--gold-500); border-radius: 3px; margin: .9rem auto 1.4rem; }
.auth-foot { color: rgba(255, 255, 255, .8); font-size: .85rem; text-align: center; margin-top: 1rem; }
.auth-foot a { color: #fff; }

/* ---------- Student layout (mobile first) ---------- */
.student-top { background: linear-gradient(135deg, var(--em-800), var(--em-600)); color: #fff; padding: .75rem 0; position: sticky; top: 0; z-index: 1020; box-shadow: var(--shadow); }
.student-top .brand { color: #fff; font-weight: 700; text-decoration: none; display: flex; align-items: center; gap: .5rem; font-size: 1rem; }
.student-top .brand i { color: var(--gold-500); font-size: 1.3rem; }
.student-main { padding: 1rem 0 6rem; }
.student-nav { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--gray-200); z-index: 1030;
    display: flex; justify-content: space-around; padding: .35rem 0 calc(.35rem + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(0, 0, 0, .05); }
.student-nav a { flex: 1; text-align: center; color: var(--gray-500); text-decoration: none; font-size: .78rem; padding: .3rem 0; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.student-nav a i { font-size: 1.35rem; line-height: 1.1; }
.student-nav a.active { color: var(--em-700); font-weight: 700; }
@media (min-width: 992px) {
    .student-nav { position: static; box-shadow: none; border: 0; background: transparent; justify-content: flex-start; gap: .25rem; padding: 0; }
    .student-nav a { flex: none; flex-direction: row; gap: .4rem; font-size: .95rem; padding: .45rem .9rem; border-radius: 10px; min-height: 0; color: rgba(255, 255, 255, .85); }
    .student-nav a i { font-size: 1.05rem; }
    .student-nav a.active { background: rgba(255, 255, 255, .16); color: #fff; }
    .student-main { padding-bottom: 2rem; }
}

.hello-card { background: linear-gradient(135deg, #fff, var(--em-50)); border: 1px solid var(--em-100); }
.window-banner { border-radius: var(--radius); padding: .85rem 1rem; display: flex; gap: .75rem; align-items: flex-start; }
.window-banner i { font-size: 1.4rem; line-height: 1; margin-top: .1rem; }
.window-banner.open { background: var(--em-50); border: 1px solid var(--em-100); color: var(--em-900); }
.window-banner.closed { background: #fff4ed; border: 1px solid #fed7c3; color: #7c2d12; }
.window-banner.wait { background: #eef4ff; border: 1px solid #d3e2ff; color: #1e3a8a; }

.activity-card { transition: transform .15s ease, box-shadow .15s ease; height: 100%; display: flex; flex-direction: column; }
.activity-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.activity-card .card-body { display: flex; flex-direction: column; gap: .55rem; flex: 1; }
.activity-card .code { font-size: .75rem; color: var(--gray-500); font-weight: 600; letter-spacing: .02em; }
.activity-card .title { font-size: 1.05rem; font-weight: 700; line-height: 1.35; margin: 0; }
.activity-card .meta { font-size: .875rem; color: var(--gray-700); display: flex; gap: .4rem; align-items: flex-start; }
.activity-card .meta i { color: var(--em-600); margin-top: .15rem; }
.activity-card .nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; text-align: center; background: var(--gray-50); border-radius: 10px; padding: .5rem .25rem; }
.activity-card .nums b { display: block; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.activity-card .nums span { font-size: .72rem; color: var(--gray-500); }
.activity-card .actions { display: flex; gap: .5rem; margin-top: auto; }
.activity-card .actions .btn { flex: 1; min-height: 46px; }
.activity-card.is-mine { border: 2px solid var(--em-500); }
.activity-card .mine-flag { position: absolute; top: -1px; right: 12px; background: var(--em-600); color: #fff; font-size: .72rem; font-weight: 700; padding: .2rem .55rem; border-radius: 0 0 8px 8px; }

.filter-bar { position: sticky; top: 64px; z-index: 1010; background: var(--gray-50); padding: .5rem 0 .75rem; }
.chip { border: 1px solid var(--gray-200); background: #fff; border-radius: 99px; padding: .3rem .8rem; font-size: .85rem; color: var(--gray-700); white-space: nowrap; cursor: pointer; }
.chip.active { background: var(--em-700); border-color: var(--em-700); color: #fff; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.detail-hero { background: linear-gradient(135deg, var(--em-800), var(--em-600)); color: #fff; border-radius: var(--radius); padding: 1.25rem; }
.detail-hero h1 { color: #fff; font-size: 1.35rem; }
.info-list { list-style: none; padding: 0; margin: 0; }
.info-list li { display: flex; gap: .75rem; padding: .65rem 0; border-bottom: 1px dashed var(--gray-200); }
.info-list li:last-child { border-bottom: 0; }
.info-list i { color: var(--em-600); font-size: 1.15rem; width: 1.4rem; text-align: center; }
.info-list .k { font-size: .8rem; color: var(--gray-500); }
.sticky-action { position: sticky; bottom: 70px; z-index: 5; }
@media (min-width: 992px) { .sticky-action { bottom: 1rem; } }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--gray-500); }
.empty-state i { font-size: 2.6rem; color: var(--em-500); display: block; margin-bottom: .5rem; }

/* ---------- Admin layout ---------- */
.admin-shell { min-height: 100vh; }
.admin-sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--em-900); color: #cfe9df; z-index: 1040;
    display: flex; flex-direction: column; transition: transform .2s ease; }
.admin-sidebar .brand { padding: 1.1rem 1.1rem 1rem; display: flex; gap: .7rem; align-items: center; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.admin-sidebar .brand .logo { width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(135deg, var(--em-500), var(--em-700)); display: grid; place-items: center; font-size: 1.25rem; color: #fff; flex: none; }
.admin-sidebar .brand .t1 { font-weight: 700; font-size: .95rem; line-height: 1.2; }
.admin-sidebar .brand .t2 { font-size: .75rem; color: var(--gold-500); }
.admin-sidebar nav { padding: .75rem .6rem; overflow-y: auto; flex: 1; }
.admin-sidebar .nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: rgba(207, 233, 223, .55); padding: .9rem .75rem .35rem; }
.admin-sidebar a.nav-item { display: flex; align-items: center; gap: .7rem; padding: .55rem .75rem; border-radius: 10px; color: #cfe9df; text-decoration: none; font-size: .95rem; margin-bottom: 2px; }
.admin-sidebar a.nav-item i { font-size: 1.1rem; width: 1.2rem; text-align: center; }
.admin-sidebar a.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.admin-sidebar a.nav-item.active { background: rgba(16, 185, 129, .18); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--gold-500); }
.admin-sidebar .side-foot { padding: .9rem 1.1rem; border-top: 1px solid rgba(255, 255, 255, .08); font-size: .8rem; color: rgba(207, 233, 223, .7); }
.admin-main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.admin-topbar { position: sticky; top: 0; z-index: 1030; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; gap: .75rem; padding: .65rem 1.25rem; min-height: 60px; }
.admin-topbar .page-title { font-size: 1.1rem; font-weight: 700; margin: 0; }
.admin-content { padding: 1.25rem; flex: 1; }
.admin-backdrop { display: none; }
@media (max-width: 991.98px) {
    .admin-sidebar { transform: translateX(-100%); }
    .admin-shell.nav-open .admin-sidebar { transform: none; }
    .admin-shell.nav-open .admin-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 1035; }
    .admin-main { margin-left: 0; }
    .admin-content { padding: 1rem .75rem; }
}
.live-dot { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--gray-500); }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--em-500); box-shadow: 0 0 0 0 rgba(16, 185, 129, .6); animation: pulse 2s infinite; }
.live-dot.off::before { background: #d97706; animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, .55); } 70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); } 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } }

/* ---------- Tables ---------- */
.table { --bs-table-hover-bg: var(--em-50); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .65rem .75rem; border-bottom-color: var(--gray-100); vertical-align: middle; }
.table thead th { font-size: .8rem; text-transform: none; color: var(--gray-500); font-weight: 700; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
.table-card { overflow: hidden; }
.table-responsive { border-radius: 0 0 var(--radius) var(--radius); }
.cell-progress { min-width: 130px; }
.cell-progress .pct { font-size: .75rem; color: var(--gray-500); font-variant-numeric: tabular-nums; }
tr.row-over td { background: #fff7ed !important; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.toolbar .form-control, .toolbar .form-select { width: auto; min-width: 150px; }
.toolbar .search { flex: 1 1 220px; }
@media (max-width: 575.98px) { .toolbar .form-control, .toolbar .form-select { min-width: 0; flex: 1 1 45%; } }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 420px; }

/* ---------- Import ---------- */
.dropzone { border: 2px dashed var(--em-500); background: var(--em-50); border-radius: var(--radius); padding: 1.75rem 1rem; text-align: center; cursor: pointer; transition: background .15s; }
.dropzone:hover, .dropzone.drag { background: var(--em-100); }
.dropzone i { font-size: 2.2rem; color: var(--em-600); }
.steps { display: flex; gap: .25rem; flex-wrap: wrap; counter-reset: s; }
.steps .step { flex: 1 1 120px; font-size: .8rem; color: var(--gray-500); padding: .5rem .6rem; border-radius: 10px; background: var(--gray-100); }
.steps .step.done { background: var(--em-50); color: var(--em-800); }
.steps .step.current { background: var(--em-700); color: #fff; font-weight: 700; }
.act-insert { color: var(--em-700); }
.act-update { color: #1d4ed8; }
.act-unchanged { color: var(--gray-500); }
.act-error { color: #b42318; }
.diff-old { text-decoration: line-through; color: #b42318; }
.diff-new { color: var(--em-800); font-weight: 600; }

/* ---------- Toast / misc ---------- */
.toast-container { z-index: 2000; }
.toast { border: 0; border-radius: 12px; box-shadow: var(--shadow); }
.toast.text-bg-success { background: var(--em-700) !important; }
.loading-overlay { position: absolute; inset: 0; background: rgba(255, 255, 255, .6); display: grid; place-items: center; z-index: 5; border-radius: inherit; }
.skeleton { background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 37%, var(--gray-100) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: 8px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.modal-content { border: 0; border-radius: 16px; }
.modal-header { border-bottom-color: var(--gray-100); }
.modal-footer { border-top-color: var(--gray-100); }
.list-plain { list-style: none; padding: 0; margin: 0; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: .35rem .75rem; font-size: .925rem; }
.kv dt { color: var(--gray-500); font-weight: 500; }
.kv dd { margin: 0; }
.password-slip { border: 1px dashed var(--gray-500); border-radius: 10px; padding: .75rem; break-inside: avoid; }
@media print {
    .no-print, .admin-sidebar, .admin-topbar, .student-nav, .student-top { display: none !important; }
    .admin-main { margin-left: 0; }
    body { background: #fff; }
}
.error-page { background: var(--gray-50); }

/* จอสัมผัส (มือถือ/iPad): ช่องกรอกต้อง ≥ 16px ไม่ให้ iOS ซูมหน้าจอเองเมื่อแตะ */
@media (pointer: coarse) {
    .form-control, .form-select, .form-control-sm, .form-select-sm { font-size: 16px; }
}

/* เมนู Live: ไอคอนจุดแดงแบบไลฟ์สด */
.bi-record-circle::before, .bi-record-circle-fill::before { color: #ef4444; }
