/* สรุปคำถามที่ออกบ่อย · ค้นรายข้อ (/page/exam_summary/) — ออกแบบใหม่ ๘ ต.ค. ๒๕๖๙
   ธีมคราม ชุดเดียวกับคลังข้อสอบ (/exam-bank) · สีหมวดส่งมาทาง --c = ความหมาย
   หน้า dashboard.php ยังใช้ style.css เดิม — ไฟล์นี้ใช้กับ index.php เท่านั้น */

:root {
	--eb-primary: #4f46e5;
	--eb-primary-dim: #4338ca;
	--eb-primary-soft: #e0e7ff;
	--eb-primary-wash: #eef2ff;
	--eb-ink: #1e293b;
	--eb-ink-soft: #475569;
	--eb-ink-mute: #64748b;
	--eb-line: #e2e8f0;
	--eb-surface: #f8fafc;
	--eb-surface-2: #f1f5f9;
}
* { box-sizing: border-box; }
body.es-body {
	background: var(--eb-surface);
	color: var(--eb-ink);
	font-family: 'Sarabun', system-ui, sans-serif;
	font-size: 16px;
	-webkit-font-smoothing: antialiased;
	margin: 0; min-height: 100vh;
}
.font-pali { font-family: 'Sarabun', 'Source Serif 4', serif; }
[v-cloak] { display: none; }
.es-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.es-body button { font-family: inherit; }
.es-body :focus-visible { outline: 2px solid var(--eb-primary); outline-offset: 2px; }

.es-shell { max-width: 840px; margin: 0 auto; padding: 0 1rem 3rem; }

/* ── แถบย้อนกลับ (ยกหน้าตา .eb-backbar ของ /exam-bank) ── */
.eb-backbar { background: rgba(255,255,255,.7); border-bottom: 1px solid #e0e7ff; }
.eb-backbar-inner {
	max-width: 840px; margin: 0 auto; padding: .55rem 1rem;
	display: flex; align-items: center; gap: .75rem; min-width: 0;
}
.eb-back-link {
	display: inline-flex; align-items: center; gap: .45rem; flex-shrink: 0;
	padding: .38rem .8rem; border-radius: 999px; border: 1px solid #c7d2fe;
	background: #fff; color: var(--eb-primary); font-size: .85rem; font-weight: 700;
	text-decoration: none; transition: all .15s;
}
.eb-back-link:hover { background: var(--eb-primary-wash); border-color: var(--eb-primary); color: var(--eb-primary); }
.eb-backbar-sub { color: var(--eb-ink-soft); font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── สถานะโหลด / ผิดพลาด ── */
.es-state { text-align: center; padding-top: 4rem; color: var(--eb-ink-soft); }
.es-state > i { font-size: 2rem; color: var(--eb-primary); }
.es-state p { margin-top: .8rem; }
.es-error { text-align: left; background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; padding: 1rem 1.2rem; border-radius: 14px; font-weight: 600; }

/* ── หัวหน้า ── */
.es-head { margin: 1.1rem 0 .6rem; }
.es-head h1 { margin: 0; font-size: clamp(1.45rem, 4.4vw, 1.95rem); font-weight: 800; color: var(--eb-ink); letter-spacing: -.01em; line-height: 1.3; }
.es-head h1 span { color: var(--eb-primary); }
.es-head p { margin: .25rem 0 0; font-size: .88rem; color: var(--eb-ink-soft); line-height: 1.6; }

/* ── แถบกรอง (ติดบน) ── */
.es-filter-bar {
	position: sticky; top: 0; z-index: 40;
	margin: 0 -1rem .8rem; padding: .6rem 1rem .55rem;
	background: rgba(248,250,252,.96);
	-webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
	border-bottom: 1px solid var(--eb-line);
	display: grid; gap: .5rem;
}
.es-topics { display: flex; flex-wrap: wrap; gap: .35rem; }
.es-chip {
	--c: var(--eb-primary);
	display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; flex: none;
	background: #fff; border: 1px solid var(--eb-line); color: var(--eb-ink-soft);
	padding: .3rem .7rem; border-radius: 999px; font-size: .84rem; font-weight: 600; line-height: 1.4;
	cursor: pointer; transition: background .12s, border-color .12s, color .12s;
}
.es-chip small { font-size: .72rem; font-weight: 700; color: var(--eb-ink-mute); font-variant-numeric: tabular-nums; }
.es-chip:hover { border-color: var(--c); color: var(--eb-ink); }
.es-chip.on {
	background: color-mix(in srgb, var(--c) 13%, #fff);
	border-color: var(--c); color: color-mix(in srgb, var(--c) 55%, #0f172a); font-weight: 800;
}
.es-chip.on small { color: inherit; }
.es-chip-all.on { background: var(--eb-primary); border-color: var(--eb-primary); color: #fff; }
.es-dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: var(--c); flex: none; }

.es-tools { display: flex; gap: .45rem; min-width: 0; }
.es-search-wrap { position: relative; flex: 1 1 auto; min-width: 0; margin: 0; }
.es-search-wrap > i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--eb-ink-mute); font-size: .85rem; pointer-events: none; }
.es-search {
	width: 100%; height: 2.4rem; padding: 0 .75rem 0 2.1rem;
	border: 1px solid var(--eb-line); border-radius: 12px; background: #fff;
	font-family: inherit; font-size: .95rem; color: var(--eb-ink);
}
.es-search::placeholder { color: #94a3b8; }
.es-search:focus { outline: none; border-color: var(--eb-primary); box-shadow: 0 0 0 3px var(--eb-primary-soft); }
.es-sort { flex: none; margin: 0; }
.es-sort select {
	height: 2.4rem; padding: 0 2rem 0 .75rem; border: 1px solid var(--eb-line); border-radius: 12px;
	font-family: inherit; font-size: .88rem; font-weight: 700; color: var(--eb-ink); cursor: pointer;
	-webkit-appearance: none; appearance: none;
	background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right .7rem center;
}
.es-sort select:focus { outline: none; border-color: var(--eb-primary); box-shadow: 0 0 0 3px var(--eb-primary-soft); }

.es-meta-row { display: flex; align-items: center; justify-content: space-between; gap: .4rem .8rem; flex-wrap: wrap; }
.es-seg { display: inline-flex; background: var(--eb-surface-2); border: 1px solid var(--eb-line); border-radius: 11px; padding: 2px; }
.es-seg button {
	border: 0; background: transparent; color: var(--eb-ink-soft); cursor: pointer; white-space: nowrap;
	font-size: .8rem; font-weight: 700; padding: .28rem .7rem; border-radius: 9px;
}
.es-seg button:hover { color: var(--eb-primary); }
.es-seg button.on { background: #fff; color: var(--eb-primary); box-shadow: 0 1px 3px rgba(15,23,42,.12); }
.es-count { margin: 0; font-size: .82rem; color: var(--eb-ink-soft); }
.es-count b { color: var(--eb-ink); font-variant-numeric: tabular-nums; }

/* ── การ์ดคำถาม ── */
.es-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .65rem; }
.es-card {
	--c: var(--eb-primary);
	background: #fff; border: 1px solid var(--eb-line); border-left: 4px solid var(--c);
	border-radius: 14px; padding: .8rem 1rem .85rem; min-width: 0;
}
.es-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-bottom: .45rem; }
.es-topic-badge {
	display: inline-flex; align-items: center; gap: .35rem;
	font-size: .76rem; font-weight: 800; color: color-mix(in srgb, var(--c) 55%, #0f172a);
	background: color-mix(in srgb, var(--c) 11%, #fff); padding: .15rem .55rem; border-radius: 999px;
}
.es-sub-badge { font-size: .74rem; font-weight: 600; color: var(--eb-ink-soft); background: var(--eb-surface-2); padding: .15rem .55rem; border-radius: 999px; }
.es-freq-badge {
	margin-left: auto; white-space: nowrap;
	font-size: .76rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px;
	background: var(--eb-surface-2); color: var(--eb-ink-mute);
}
.es-freq-badge.warm { background: #fef3c7; color: #92400e; }
.es-freq-badge.hot { background: #fee2e2; color: #991b1b; }

.es-context {
	margin: 0 0 .35rem; padding: .35rem .7rem; border-radius: 8px;
	background: var(--eb-surface-2); border-left: 3px solid var(--eb-primary-soft);
	font-size: .86rem; line-height: 1.55; color: var(--eb-ink-soft);
	white-space: pre-wrap; overflow-wrap: anywhere;
}
.es-question { margin: 0; font-size: 1.02rem; line-height: 1.7; color: var(--eb-ink); font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }

.es-years { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; margin-top: .5rem; }
.es-year-label { font-size: .74rem; font-weight: 700; color: var(--eb-ink-mute); margin-right: .15rem; }
.es-year-pill { font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: var(--eb-surface-2); color: var(--eb-ink-mute); font-variant-numeric: tabular-nums; }
.es-year-pill.is-recent { background: #dbeafe; color: #1e40af; font-weight: 700; }

.es-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-top: .6rem; }
.es-ans-btn, .es-var-btn {
	display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; white-space: nowrap;
	font-size: .84rem; font-weight: 700; line-height: 1.3; padding: .4rem .85rem; border-radius: 999px;
	transition: background .12s, border-color .12s;
}
.es-ans-btn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.es-ans-btn:hover { background: #fef3c7; border-color: #fbbf24; }
.es-ans-btn.on { background: #fef3c7; border-color: #f59e0b; }
.es-var-btn { background: #fff; border: 1px solid var(--eb-line); color: var(--eb-primary); }
.es-var-btn:hover { background: var(--eb-primary-wash); border-color: #c7d2fe; }
.es-caret { font-size: .7rem; transition: transform .15s; }
.es-caret.up { transform: rotate(180deg); }

.es-answer-box {
	margin-top: .6rem; padding: .65rem .9rem .75rem; border-radius: 12px;
	background: #fffbeb; border: 1px solid #fde68a;
}
.es-answer-k { font-size: .72rem; font-weight: 800; color: #b45309; letter-spacing: .02em; margin-bottom: .15rem; }
.es-answer { font-size: .97rem; line-height: 1.8; color: var(--eb-ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.es-answer-note { margin: .35rem 0 0; font-size: .8rem; line-height: 1.6; color: #92400e; }
.es-answer-note i { margin-right: .2rem; }

.es-variants { margin-top: .6rem; border-top: 1px dashed var(--eb-line); }
.es-variant { padding: .55rem 0; border-bottom: 1px dashed var(--eb-line); }
.es-variant:last-child { border-bottom: 0; padding-bottom: 0; }
.es-variant-year { display: inline-block; font-size: .72rem; font-weight: 700; padding: .05rem .5rem; border-radius: 999px; background: var(--eb-primary-wash); color: var(--eb-primary-dim); margin-bottom: .25rem; font-variant-numeric: tabular-nums; }
.es-variant-q { font-size: .92rem; line-height: 1.65; color: var(--eb-ink); white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: .2rem; }
.es-variant-a { font-size: .88rem; line-height: 1.65; color: var(--eb-ink-soft); padding-left: .7rem; border-left: 2px solid #fde68a; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── แสดงเพิ่ม / ท้ายรายการ / ว่าง ── */
.es-more { display: flex; justify-content: center; margin-top: 1rem; }
.es-more-btn {
	display: inline-flex; align-items: center; gap: .5rem; cursor: pointer;
	background: var(--eb-primary); color: #fff; border: 0; border-radius: 12px;
	font-size: .92rem; font-weight: 800; padding: .7rem 1.3rem; transition: background .15s;
}
.es-more-btn:hover { background: var(--eb-primary-dim); }
.es-more-btn small { font-size: .76rem; font-weight: 600; opacity: .85; }
.es-end { text-align: center; color: var(--eb-ink-mute); font-size: .84rem; margin: 1rem 0 0; }
.es-empty { text-align: center; padding: 2.5rem 1rem; color: var(--eb-ink-soft); }
.es-empty > i { font-size: 1.8rem; color: #94a3b8; }
.es-empty p { margin: .7rem 0 1rem; }

/* footer ของหน้าเก่า: ให้กลืนกับพื้น */
.es-body .content-footer { background: transparent !important; color: var(--eb-ink-mute); font-size: .78rem; text-align: center; }

@media (min-width: 760px) {
	/* จอกว้าง: ช่องค้น + ช่วงปี + จำนวน อยู่แถวเดียว แถบติดบนเตี้ยลง */
	.es-filter-bar { grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: .8rem; }
	.es-topics { grid-column: 1 / -1; }
	.es-meta-row { flex-wrap: nowrap; }
}
@media (max-width: 640px) {
	/* หมวดเลื่อนข้างในแถวเดียว ประหยัดความสูงของแถบติดบน */
	.es-topics {
		flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
		margin: 0 -1rem; padding: 0 1rem 2px; scroll-padding: 0 1rem;
	}
	.es-topics::-webkit-scrollbar { display: none; }
	.es-card { padding: .75rem .85rem .8rem; }
	.es-sort select { padding-right: 1.8rem; font-size: .84rem; }
}
@media (max-width: 380px) {
	.es-seg button { padding: .28rem .55rem; font-size: .76rem; }
	.es-search { font-size: .9rem; }
	.eb-backbar-sub { display: none; }
}
@media (prefers-reduced-motion: reduce) { .es-caret, .es-chip, .es-more-btn { transition: none; } }
