/* BKKPEO_Edu-Info */
:root {
  --brand: #173a6b;
  --brand-2: #1f4f8f;
  --accent: #2a78d6;
  --page: #f5f6f8;
  --surface: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hair: #e1e0d9;
  --up: #2a78d6;
  --down: #e34948;
  --good-text: #006300;
  --radius: 12px;
  --bs-font-sans-serif: "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
}

html, body { font-family: var(--bs-font-sans-serif); }
body { background: var(--page); color: var(--ink); font-size: 15px; }
a { color: var(--brand-2); }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.site-header { background: linear-gradient(120deg, var(--brand) 0%, var(--brand-2) 100%); color: #fff; }
.site-header .brand-mark {
  width: 44px; height: 44px; border-radius: 12px; background: rgba(255,255,255,.14);
  display: grid; place-items: center; font-size: 1.35rem; flex: none;
}
.brand-logo {
  width: 52px; height: 52px; flex: none; border-radius: 50%; object-fit: contain;
  background: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.35);
}
.brand-logo.sm { width: 40px; height: 40px; }
.brand-logo.lg { width: 96px; height: 96px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.site-header .brand-title { font-weight: 700; font-size: 1.05rem; line-height: 1.3; }
.site-header .brand-sub { font-size: .8rem; opacity: .8; }
.site-nav { background: #fff; border-bottom: 1px solid var(--hair); z-index: 1030; }
.site-nav .nav-link { color: var(--ink-2); font-weight: 500; padding: .8rem .9rem; border-bottom: 2px solid transparent; }
.site-nav .nav-link:hover { color: var(--brand); }
.site-nav .nav-link.active { color: var(--brand); border-bottom-color: var(--brand); }
.site-nav .dropdown-menu { max-height: 70vh; overflow-y: auto; z-index: 1060; }
.site-nav .dropdown-item { white-space: normal; min-width: 280px; max-width: min(520px, 92vw); padding: .45rem 1rem; }
.site-nav .dropdown-item small { display: block; }

/* ---------- cards ---------- */
.card { border: 1px solid var(--hair); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.03); }
.card-header { background: transparent; border-bottom: 1px solid var(--hair); font-weight: 600; padding: .85rem 1.1rem; }
.card-title-sm { font-size: .95rem; font-weight: 600; margin: 0; }
.card-sub { font-size: .8rem; color: var(--muted); font-weight: 400; }

.page-head h1 { font-size: 1.45rem; font-weight: 700; margin: 0; }
.page-head .lead-sm { color: var(--ink-2); font-size: .92rem; }

/* stat tiles */
.stat { padding: 1rem 1.15rem; height: 100%; }
.stat .label { color: var(--ink-2); font-size: .85rem; display: flex; gap: .4rem; align-items: center; }
.stat .value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; margin-top: .2rem; }
.stat .meta { font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.stat .icon { width: 30px; height: 30px; border-radius: 8px; display: inline-grid; place-items: center; background: #eef3fb; color: var(--brand-2); }
.delta-up { color: var(--up); font-weight: 600; }
.delta-down { color: var(--down); font-weight: 600; }
.delta-flat { color: var(--muted); }

/* charts */
.chart-box { position: relative; height: 320px; }
.chart-box.sm { height: 240px; }
.chart-box.lg { height: 400px; }
.chart-box.tall { height: 520px; }
.legend-inline { display: flex; flex-wrap: wrap; gap: .35rem 1rem; font-size: .82rem; color: var(--ink-2); }
.legend-inline .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }

/* tables */
.table { --bs-table-bg: transparent; font-size: .9rem; }
.table thead th { background: #f3f4f7; color: var(--ink-2); font-weight: 600; font-size: .82rem; white-space: nowrap; border-bottom-color: var(--hair); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-sticky thead th { position: sticky; top: 0; z-index: 1; }
.table-scroll { max-height: 560px; overflow: auto; }
.table tfoot td, .table tfoot th { font-weight: 700; background: #f8f9fb; }

/* heatmap cells (diverging blue <-> red, neutral gray midpoint) */
.hm { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hm-n3 { background: #f4b5b4; } .hm-n2 { background: #f8cfce; } .hm-n1 { background: #fbe6e5; }
.hm-0 { background: #f0efec; }
.hm-p1 { background: #e3eefc; } .hm-p2 { background: #cde2fb; } .hm-p3 { background: #9ec5f4; }
.hm-na { color: var(--muted); background: #fafafa; }

.badge-soft { background: #eef3fb; color: var(--brand-2); font-weight: 500; }
.note { background: #fffaf0; border: 1px solid #f3e3bd; border-radius: 10px; padding: .75rem 1rem; font-size: .88rem; color: #5b4a1d; }
.insight { border-left: 3px solid var(--accent); padding: .1rem 0 .1rem .9rem; color: var(--ink-2); }
.report-section { scroll-margin-top: 80px; }
.toc-sticky { position: sticky; top: 70px; z-index: 1; max-height: calc(100vh - 90px); overflow-y: auto; }
.toc a { text-decoration: none; display: block; padding: .3rem .6rem; border-radius: 8px; color: var(--ink-2); font-size: .9rem; }
.toc a:hover { background: #eef3fb; color: var(--brand); }

.aff-card { transition: box-shadow .15s, transform .15s; text-decoration: none; color: inherit; display: block; height: 100%; }
.aff-card:hover { box-shadow: 0 6px 18px rgba(23,58,107,.12); transform: translateY(-1px); color: inherit; }
.spark-bar { height: 6px; border-radius: 3px; background: #eef1f5; overflow: hidden; }
.spark-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

footer.site-footer { color: var(--ink-2); font-size: .85rem; border-top: 1px solid var(--hair); background: #fff; }
footer.site-footer .footer-logo { width: 64px; height: 64px; box-shadow: none; }
footer.site-footer address { line-height: 1.6; }
.login-contact { color: rgba(255,255,255,.75); }
.login-contact address { line-height: 1.6; }
.login-contact a { color: #fff; }

/* ---------- system (back office) ---------- */
.sys-body { background: var(--page); }
.sys-sidebar { width: 260px; background: #0f2747; color: #cfd8e6; min-height: 100vh; flex: none; }
.sys-sidebar .brand { color: #fff; font-weight: 700; padding: 1rem 1.1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.sys-sidebar .brand small { display: block; font-weight: 400; color: #9fb0c9; font-size: .75rem; }
.sys-sidebar .nav-section { font-size: .72rem; letter-spacing: .04em; color: #8397b5; padding: 1rem 1.1rem .35rem; text-transform: uppercase; }
.sys-sidebar a.nav-link { color: #cfd8e6; padding: .5rem 1.1rem; display: flex; gap: .6rem; align-items: center; font-size: .92rem; border-left: 3px solid transparent; }
.sys-sidebar a.nav-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.sys-sidebar a.nav-link.active { background: rgba(42,120,214,.18); color: #fff; border-left-color: #3987e5; }
.sys-main { flex: 1; min-width: 0; }
.sys-topbar { background: #fff; border-bottom: 1px solid var(--hair); }
.form-label { font-weight: 500; font-size: .9rem; }
.grid-input { width: 100%; min-width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0f2747, #1f4f8f); }
.login-card { width: 100%; max-width: 420px; }

/* ---------- AI chat widget ---------- */
.ai-chat { position: fixed; right: 20px; bottom: 20px; z-index: 1050; }
.ai-fab {
  display: flex; align-items: center; gap: .45rem; border: 0; border-radius: 999px; padding: .75rem 1.1rem;
  background: linear-gradient(120deg, var(--brand), var(--accent)); color: #fff; font-weight: 600;
  box-shadow: 0 8px 24px rgba(23,58,107,.35);
}
.ai-fab i { font-size: 1.15rem; }
.ai-chat.open .ai-fab { display: none; }
.ai-panel {
  width: 380px; max-width: calc(100vw - 32px); height: 560px; max-height: calc(100vh - 40px);
  background: #fff; border-radius: 16px; box-shadow: 0 16px 48px rgba(0,0,0,.22); display: flex; flex-direction: column; overflow: hidden;
}
.ai-panel[hidden] { display: none; }
.ai-head { display: flex; align-items: center; gap: .6rem; padding: .7rem .8rem; background: linear-gradient(120deg, var(--brand), var(--brand-2)); color: #fff; }
.ai-head img { border-radius: 50%; background: #fff; flex: none; }
.ai-body { flex: 1; overflow-y: auto; padding: 1rem; background: var(--page); display: flex; flex-direction: column; gap: .6rem; }
.ai-msg { max-width: 88%; padding: .55rem .8rem; border-radius: 14px; font-size: .92rem; line-height: 1.55; word-wrap: break-word; }
.ai-msg p { margin: 0 0 .35rem; } .ai-msg p:last-child { margin: 0; }
.ai-msg ul { margin: .2rem 0 .35rem; padding-left: 1.1rem; }
.ai-bot { background: #fff; border: 1px solid var(--hair); align-self: flex-start; border-bottom-left-radius: 4px; }
.ai-user { background: var(--brand-2); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.ai-err { border-color: #f4b5b4; background: #fdf2f2; color: #8a1f1f; }
.ai-wait { color: var(--ink-2); }
.ai-dots i { display: inline-block; width: 6px; height: 6px; margin-right: 3px; border-radius: 50%; background: var(--accent); animation: ai-blink 1.2s infinite; }
.ai-dots i:nth-child(2) { animation-delay: .2s; } .ai-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes ai-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.ai-suggest { display: flex; flex-wrap: wrap; gap: .4rem; }
.ai-chip { border: 1px solid #cde2fb; background: #eef3fb; color: var(--brand-2); border-radius: 999px; padding: .3rem .75rem; font-size: .82rem; text-align: left; }
.ai-chip:hover { background: #cde2fb; }
.ai-input { display: flex; gap: .5rem; padding: .6rem; border-top: 1px solid var(--hair); background: #fff; }
.ai-input textarea { flex: 1; resize: none; border: 1px solid var(--hair); border-radius: 10px; padding: .45rem .65rem; font-size: .92rem; max-height: 120px; }
.ai-input textarea:focus { outline: 2px solid #9ec5f4; border-color: transparent; }
.ai-foot { font-size: .72rem; color: var(--muted); text-align: center; padding: 0 .6rem .5rem; background: #fff; }
@media (max-width: 575.98px) {
  .ai-chat { right: 12px; bottom: 12px; }
  .ai-chat.open { left: 12px; }
  .ai-panel { width: 100%; height: calc(100vh - 24px); }
}
@media print { .ai-chat { display: none !important; } }

@media (max-width: 991.98px) {
  .sys-sidebar { position: fixed; left: -270px; top: 0; bottom: 0; z-index: 1040; transition: left .2s; overflow-y: auto; }
  .sys-sidebar.show { left: 0; }
  .chart-box { height: 280px; }
  .chart-box.tall { height: 440px; }
}
@media print {
  .site-nav, .site-header .btn, footer, .no-print { display: none !important; }
  .card { break-inside: avoid; }
}
