/* ระบบสารสนเทศทุนการศึกษา — stylesheet
   โทน: ส้ม มทส. บนพื้นเทาเย็น อ่านตัวเลขง่าย ไม่ตกแต่งเกินจำเป็น */

@font-face { font-family: "Plex Thai"; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-thai-400-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-thai-500-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-thai-600-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 700; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-thai-700-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Plex Thai"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Plex Thai"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Plex Thai"; font-weight: 700; font-display: swap; src: url("../fonts/ibm-plex-sans-thai-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }

:root {
  --ink: #1E2532;
  --ink-2: #3A4354;
  --muted: #667085;
  --line: #E2E5EA;
  --line-2: #EEF0F3;
  --bg: #F4F5F7;
  --panel: #FFFFFF;
  --orange: #E8731A;
  --orange-ink: #A9500C;
  --orange-soft: #FDF0E4;
  --orange-line: #F6CFAB;
  --teal: #0E8A8C;
  --teal-soft: #E3F3F3;
  --gold: #C99A06;
  --danger: #B93A26;
  --danger-soft: #FBEAE6;
  --ok: #2F7D4F;
  --ok-soft: #E6F3EB;
  --warn-soft: #FFF6DB;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(30, 37, 50, .06), 0 1px 1px rgba(30, 37, 50, .04);
  --sidebar: 248px;
  --font: "Plex Thai", "Sarabun", "Leelawadee UI", "Tahoma", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.6; color: var(--ink); background: var(--bg); }
img { max-width: 100%; }
a { color: var(--orange-ink); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--orange); }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; font-weight: 600; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.num, .tnum { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.ico { flex: none; vertical-align: -3px; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: 6px 12px; border-radius: 6px; z-index: 100; }
.skip:focus { left: 8px; }
.pad { padding: 10px 12px; }
.hidden { display: none !important; }

/* ---------------- layout ---------------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 40; overflow-y: auto;
}
.brand, .brand:hover { color: var(--ink); }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; text-decoration: none; color: var(--ink); }
.brand-mark {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 8px; background: var(--orange);
  color: #fff; font-weight: 700; font-size: .82rem; letter-spacing: .02em;
}
.brand-logo { height: 42px; width: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text b { font-size: 1rem; }
.brand-text small { color: var(--muted); font-size: .74rem; }
.nav { padding: 4px 10px 16px; flex: 1; }
.nav-label { font-size: .78rem; color: var(--muted); padding: 16px 10px 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2);
  text-decoration: none; font-size: .95rem; position: relative;
}
.nav-link:hover { background: var(--bg); color: var(--ink); }
.nav-link.on { background: var(--orange-soft); color: var(--orange-ink); font-weight: 600; }
.nav-link.on::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--orange); }
.nav-sub { margin: 2px 0 6px 28px; border-left: 1px solid var(--line); padding-left: 8px; }
.nav-sub a { display: block; font-size: .85rem; padding: 4px 8px; border-radius: 6px; color: var(--muted); text-decoration: none; line-height: 1.35; }
.nav-sub a:hover { color: var(--ink); background: var(--bg); }
.nav-sub a.on { color: var(--orange-ink); font-weight: 600; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 10px; }
.sidebar-foot a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; color: var(--muted); text-decoration: none; border-radius: 8px; font-size: .9rem; }
.sidebar-foot a:hover { background: var(--bg); color: var(--ink); }

.shell { min-height: 100vh; display: flex; flex-direction: column; }
.sidebar ~ .shell { margin-left: var(--sidebar); }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 10px 28px;
  background: rgba(244, 245, 247, .92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
.page-title { font-size: 1.12rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user { display: flex; align-items: center; gap: 8px; }
.topbar-user form { margin: 0; }
.who { display: flex; flex-direction: column; text-align: right; line-height: 1.2; }
.who b { font-size: .9rem; font-weight: 600; }
.who small { color: var(--muted); font-size: .76rem; }
.icon-btn.menu-btn { display: none; }
.main { padding: 24px 28px 40px; flex: 1; width: 100%; max-width: 1480px; }
.foot { padding: 14px 28px 22px; color: var(--muted); font-size: .8rem; }
.scrim { display: none; }

@media (max-width: 980px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 30px rgba(0,0,0,.15); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(30,37,50,.35); z-index: 35; }
  .sidebar ~ .shell { margin-left: 0; }
  .icon-btn.menu-btn { display: inline-grid; }
  .topbar, .main { padding-left: 16px; padding-right: 16px; }
  .who { display: none; }
}

/* ---------------- controls ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit;
  font-size: .92rem; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #C9CED6; color: var(--ink); background: #FAFBFC; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-primary:hover { background: #D5650F; border-color: #D5650F; color: #fff; }
.btn-danger { color: var(--danger); border-color: #EBC3BA; }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn-sm { height: 32px; padding: 0 12px; font-size: .86rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; border: 1px solid transparent; background: none; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--panel); border-color: var(--line); }
.link-btn { background: none; border: 0; color: var(--orange-ink); font: inherit; font-size: .85rem; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: .82rem; color: var(--muted); font-weight: 500; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=email], input:not([type]), select, textarea {
  font: inherit; font-size: .93rem; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; height: 38px; padding: 0 12px; width: 100%; min-width: 0;
}
textarea { height: auto; padding: 8px 12px; min-height: 90px; resize: vertical; }
select { padding-right: 30px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.4'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(232,115,26,.15); }
input[type=checkbox], input[type=radio] { accent-color: var(--orange); width: 16px; height: 16px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

/* multi-select */
.ms { position: relative; }
.ms-sum {
  list-style: none; cursor: pointer; height: 38px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
  display: flex; align-items: center; padding: 0 30px 0 12px; font-size: .93rem; color: var(--muted); position: relative;
}
.ms-sum::-webkit-details-marker { display: none; }
.ms-sum::after { content: ""; position: absolute; right: 12px; top: 50%; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-70%) rotate(45deg); }
.ms-sum.has { color: var(--ink); border-color: var(--orange-line); background: #FFFBF7; }
.ms-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms[open] .ms-sum { border-color: var(--orange); }
.ms-pop {
  position: absolute; z-index: 25; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: min(460px, calc(100vw - 40px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(30,37,50,.14); padding: 8px;
}
.ms-search { margin-bottom: 6px; height: 34px !important; }
.ms-list { max-height: 280px; overflow-y: auto; }
.ms-opt { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: .9rem; line-height: 1.4; }
.ms-opt:hover { background: var(--bg); }
.ms-opt input { margin-top: 2px; }
.ms-actions { border-top: 1px solid var(--line-2); margin-top: 6px; padding: 6px 8px 2px; display: flex; justify-content: space-between; }

/* segmented */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 2px; flex-wrap: wrap; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 0 12px; height: 32px; display: inline-flex; align-items: center; border-radius: 6px; cursor: pointer; font-size: .88rem; color: var(--ink-2); white-space: nowrap; }
.seg input:checked + label { background: var(--ink); color: #fff; }
.seg input:focus-visible + label { outline: 2px solid var(--orange); }

/* ---------------- panels ---------------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel + .panel, .panel + .grid, .grid + .panel, .grid + .grid { margin-top: 20px; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px 0; flex-wrap: wrap; }
.panel-head h2, .panel-head h3 { margin: 0; flex: 1; min-width: 200px; }
.panel-head .sub { color: var(--muted); font-size: .84rem; font-weight: 400; display: block; }
.panel-body { padding: 16px 20px 20px; }
.panel-body.flush { padding: 12px 0 0; }
.grid { display: grid; gap: 20px; }
.grid > .panel { margin-top: 0; }
.grid > * { min-width: 0; }
.alert div { min-width: 0; overflow-wrap: anywhere; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-wide { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-wide { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .g2, .g3 { grid-template-columns: 1fr; } }

/* filter bar */
.filters { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; }
.filters-foot { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.filters-foot .spacer { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 16px; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: .82rem; color: var(--ink-2); }

/* ---------------- dashboard ---------------- */
.ledger {
  display: grid; grid-template-columns: minmax(220px, auto) 1fr; gap: 28px; align-items: end;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 28px; box-shadow: var(--shadow);
}
.ledger-year { border-right: 1px solid var(--line); padding-right: 28px; }
.ledger-year .label { color: var(--muted); font-size: .9rem; }
.ledger-year .yr { font-size: clamp(2.6rem, 5vw, 3.6rem); font-weight: 700; line-height: 1; letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.year-switch { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; }
.year-switch a { font-size: .82rem; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.year-switch a:hover { border-color: var(--orange-line); color: var(--orange-ink); }
.year-switch a.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.figures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.fig { padding: 0 20px; border-left: 1px solid var(--line-2); }
.fig:first-child { border-left: 0; padding-left: 0; }
.fig .k { font-size: .84rem; color: var(--muted); }
.fig .v { font-size: 1.85rem; font-weight: 600; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fig .v small { font-size: .9rem; font-weight: 500; color: var(--muted); margin-left: 4px; }
.fig .d { font-size: .82rem; margin-top: 2px; }
.up { color: var(--ok); }
.down { color: var(--danger); }
.fig.lead .v { color: var(--orange-ink); }
.termbar { grid-column: 1 / -1; }
.termbar-track { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--line-2); }
.termbar-track span { display: block; height: 100%; }
.termbar-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: .84rem; color: var(--muted); margin-top: 8px; }
.termbar-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
@media (max-width: 1100px) {
  .ledger { grid-template-columns: 1fr; }
  .ledger-year { border-right: 0; padding-right: 0; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
  .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 0; }
  .fig:nth-child(3) { border-left: 0; padding-left: 0; }
}
@media (max-width: 520px) { .figures { grid-template-columns: 1fr; } .fig { border-left: 0; padding-left: 0; } }

.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 380px; }
.chart-box.short { height: 220px; }

/* ranked bar list */
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 9px 0; border-bottom: 1px solid var(--line-2); }
.bars li:last-child { border-bottom: 0; }
.bars .nm { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .nm a { color: var(--ink); text-decoration: none; }
.bars .nm a:hover { color: var(--orange-ink); text-decoration: underline; }
.bars .vl { font-size: .9rem; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.bars .vl small { color: var(--muted); margin-left: 6px; }
.bars .track { grid-column: 1 / -1; height: 6px; border-radius: 99px; background: var(--line-2); overflow: hidden; }
.bars .track span { display: block; height: 100%; background: var(--orange); border-radius: 99px; }

/* ---------------- tables ---------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .9rem; }
table.data th, table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; }
table.data thead th { background: #F8F9FB; color: var(--ink-2); font-weight: 600; font-size: .83rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1; }
table.data th.r, table.data td.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data th.c, table.data td.c { text-align: center; }
table.data tbody tr:hover td { background: #FBFBFC; }
table.data tfoot td, table.data tr.total td { background: var(--orange-soft); font-weight: 600; border-top: 1px solid var(--orange-line); }
table.data .grp th { text-align: center; border-left: 1px solid var(--line); }
table.data .grp th:first-child { border-left: 0; }
table.data td.sep, table.data th.sep { border-left: 1px solid var(--line); }
table.data td.stub { min-width: 220px; max-width: 420px; }
table.data .zero { color: #A5ACB8; }
table.pivot thead tr:first-child th { top: 0; }
table.pivot thead tr:nth-child(2) th { top: 37px; }
.cellbar { display: block; height: 3px; border-radius: 9px; background: var(--orange-line); margin-top: 4px; }
.cellbar span { display: block; height: 100%; background: var(--orange); border-radius: 9px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .76rem; font-weight: 500; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.badge.orange { background: var(--orange-soft); color: var(--orange-ink); }
.badge.teal { background: var(--teal-soft); color: var(--teal); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

.pager { display: flex; gap: 4px; justify-content: center; padding: 14px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 8px; padding: 0 8px; font-size: .88rem; text-decoration: none; color: var(--ink-2); border: 1px solid var(--line); background: var(--panel); }
.pager a:hover { border-color: var(--orange-line); color: var(--orange-ink); }
.pager .cur { background: var(--ink); color: #fff; border-color: var(--ink); }
.pager .gap { border: 0; background: none; }

/* ---------------- alerts / empty ---------------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: .92rem; border: 1px solid; }
.alert .ico { margin-top: 3px; }
.alert-success { background: var(--ok-soft); border-color: #BFDFCB; color: #1F5C38; }
.alert-error { background: var(--danger-soft); border-color: #EBC3BA; color: #8A2A1A; }
.alert-info { background: #EEF3FB; border-color: #CBD8EE; color: #23477D; }
.alert-warn { background: var(--warn-soft); border-color: #EDD9A0; color: #6E5309; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state h2 { color: var(--ink); }
.empty-state .mascot { max-width: 160px; margin: 0 auto 12px; display: block; }

/* ---------------- definition list ---------------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.spec { white-space: pre-line; background: #FAFAFB; border: 1px solid var(--line-2); border-radius: 8px; padding: 12px 14px; font-size: .9rem; color: var(--ink-2); }

/* ---------------- import ---------------- */
.steps { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.step-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.step-card h3 { margin: 0; display: flex; gap: 10px; align-items: baseline; }
.step-card .stepno { flex: none; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--orange-soft); color: var(--orange-ink); font-size: .8rem; font-weight: 700; }
.step-card p { color: var(--muted); font-size: .88rem; margin: 0; flex: 1; }
.step-card .meta { font-size: .82rem; color: var(--muted); }
.dropzone { display: block; cursor: pointer; border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; background: #FBFBFC; transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--orange); background: var(--orange-soft); }
.dropzone input[type=file] { margin: 12px auto 0; display: block; font: inherit; font-size: .9rem; }
.mapping { display: flex; flex-wrap: wrap; gap: 6px; }
.mapping .badge { font-size: .8rem; }
.statline { display: flex; gap: 28px; flex-wrap: wrap; }
.statline div b { display: block; font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.statline div span { color: var(--muted); font-size: .84rem; }
.progress-note { display: none; align-items: center; gap: 10px; color: var(--muted); font-size: .9rem; }
.busy .progress-note { display: inline-flex; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--orange-line); border-top-color: var(--orange); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } * { transition: none !important; } }

/* ---------------- auth ---------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  linear-gradient(180deg, var(--bg) 0, var(--bg) 60%, #EEE7DF 100%); }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: 0 10px 40px rgba(30,37,50,.08); display: flex; flex-direction: column; gap: 14px; }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 4px; }
.auth-brand b { display: block; font-size: 1.05rem; }
.auth-brand small { color: var(--muted); }
body:not(.app) .main, .shell:has(.auth-wrap) .main { padding: 0; max-width: none; }
.shell:has(.auth-wrap) .foot { display: none; }

/* ---------------- tabs ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-size: .92rem; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--orange-ink); border-bottom-color: var(--orange); font-weight: 600; }
.group-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.group-tabs a { font-size: .86rem; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); text-decoration: none; color: var(--ink-2); }
.group-tabs a:hover { border-color: var(--orange-line); }
.group-tabs a.on { background: var(--orange); border-color: var(--orange); color: #fff; }

/* timeline (student) */
.term-block { border-left: 2px solid var(--line); padding: 0 0 18px 18px; position: relative; }
.term-block::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--orange); }
.term-block h3 { font-size: .95rem; margin-bottom: 6px; }

/* ---------------- public page ---------------- */
.public body, body.public { background: var(--bg); }
.pub-top { background: var(--panel); border-bottom: 1px solid var(--line); }
.pub-top .inner { max-width: 1200px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 12px; }
.pub-top .brand { padding: 0; }
.pub-top .spacer { flex: 1; }
.pub-hero { max-width: 1200px; margin: 0 auto; padding: 36px 24px 8px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: end; }
.pub-hero h1 { font-size: clamp(1.6rem, 3.4vw, 2.3rem); font-weight: 700; letter-spacing: -.01em; margin-bottom: 8px; max-width: 22ch; }
.pub-hero p { color: var(--muted); max-width: 62ch; }
.pub-hero .mascot { width: 150px; height: auto; }
.pub-main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 48px; }
@media (max-width: 700px) { .pub-hero { grid-template-columns: 1fr; } .pub-hero .mascot { width: 110px; } }

/* ---------------- print ---------------- */
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; font-size: 11pt; }
  .sidebar, .topbar, .filters, .no-print, .foot, .btn, .pager, .menu-btn, .group-tabs, .tabs { display: none !important; }
  .sidebar ~ .shell { margin-left: 0; }
  .main { padding: 0; max-width: none; }
  .panel { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .print-only { display: block !important; }
  table.data thead th { position: static; }
  .table-wrap { overflow: visible; }
  .chart-box { height: 260px; }
}
.print-only { display: none; }
.print-head h2 { margin-bottom: 2px; }

@media (max-width: 760px) {
  .filters-grid { grid-template-columns: 1fr !important; }
  .filters, .panel-body, .panel-head { padding-left: 14px; padding-right: 14px; }
  .ledger { padding: 18px; }
}
.bulkbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 20px; margin-top: 12px; background: var(--orange-soft); border-top: 1px solid var(--orange-line); border-bottom: 1px solid var(--orange-line); }
.bulkbar .field { min-width: 180px; }
.bulkbar select { height: 34px; }
.field-label:empty { display: none; }

/* =========================================================
   ธีม มทส. + น้องมีทุน (เพิ่มชีวิตชีวาเล็กน้อย ไม่รบกวนการอ่านตัวเลข)
   ========================================================= */
:root { --gold-soft: #FFF7E0; --brand-grad: linear-gradient(90deg, #E8731A 0%, #F2A33A 55%, #C99A06 100%); }
/* แถบสีมหาวิทยาลัยบนสุดของหน้า */
body.app .shell::before, body.public::before { content: ""; display: block; height: 4px; background: var(--brand-grad); }
body.public::before { position: sticky; top: 0; z-index: 30; }
/* ลวดลายจาง ๆ ด้านบนพื้นที่เนื้อหา */
body.app .shell { background:
  radial-gradient(1200px 260px at 85% -60px, rgba(242, 163, 58, .13), transparent 70%),
  radial-gradient(700px 200px at 10% -80px, rgba(14, 138, 140, .07), transparent 70%) no-repeat, var(--bg); }
.brand-logo { height: 42px; width: auto; }
.sidebar { background: linear-gradient(180deg, #fff 0, #fff 70%, #FFF8F1 100%); }
.sidebar-mascot { display: flex; align-items: center; gap: 8px; margin: 0 14px 6px; padding: 10px 12px; border-radius: 12px; background: var(--orange-soft); border: 1px solid var(--orange-line); color: var(--orange-ink); font-size: .82rem; line-height: 1.3; }
.sidebar-mascot .side-mascot { width: 46px; height: 46px; object-fit: contain; flex: none; }
.sidebar-mascot small { color: var(--muted); }
@media (max-height: 760px) { .sidebar-mascot { display: none; } }
.nav-link.on::before { background: var(--brand-grad) !important; }
.panel-head h2 { position: relative; }

/* ทักทายบนหน้าภาพรวม */
.greet { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 18px; align-items: center; margin-bottom: 20px; padding: 18px 22px;
  background: linear-gradient(110deg, #FFF6EC 0%, #FFFBF6 55%, #F2FAFA 100%); border: 1px solid var(--orange-line); border-radius: 14px; position: relative; overflow: hidden; }
.greet::after { content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%; border: 22px solid rgba(232, 115, 26, .06); }
.greet-mascot { width: 96px; height: 96px; object-fit: contain; }
.greet-hi { color: var(--orange-ink); font-size: .88rem; font-weight: 600; }
.greet h2 { margin: 2px 0 6px; font-size: 1.12rem; }
.greet ul { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: .9rem; }
.greet ul li { margin: 2px 0; }
.greet-link { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; font-size: .88rem; font-weight: 600; text-decoration: none; position: relative; z-index: 1; }
@media (max-width: 640px) { .greet { grid-template-columns: 1fr; } .greet-mascot { width: 72px; height: 72px; } }

/* หน้าเข้าสู่ระบบ */
.auth-wrap { grid-template-columns: auto auto; justify-content: center; gap: 36px; align-content: center;
  background: radial-gradient(900px 420px at 20% 10%, rgba(242, 163, 58, .16), transparent 70%), radial-gradient(800px 380px at 90% 100%, rgba(14, 138, 140, .10), transparent 70%), var(--bg); }
.auth-art { text-align: center; max-width: 260px; color: var(--ink-2); }
.auth-mascot { width: 220px; height: auto; filter: drop-shadow(0 12px 18px rgba(169, 80, 12, .15)); }
.auth-art p { margin-top: 8px; font-size: .95rem; }
.auth-art b { color: var(--orange-ink); font-size: 1.1rem; }
.auth-card { border-top: 4px solid var(--orange); }
@media (max-width: 760px) { .auth-wrap { grid-template-columns: 1fr; gap: 8px; } .auth-mascot { width: 120px; } .auth-art p { display: none; } }

/* หน้าสาธารณะ */
.pub-top { background: rgba(255, 255, 255, .92); backdrop-filter: blur(6px); position: sticky; top: 4px; z-index: 20; }
.pub-hero { position: relative; }
.pub-hero::before { content: ""; position: absolute; inset: 0 -200px auto; height: 100%; z-index: -1;
  background: radial-gradient(600px 220px at 80% 40%, rgba(242, 163, 58, .18), transparent 70%); }
.pub-hero .mascot { filter: drop-shadow(0 10px 16px rgba(169, 80, 12, .15)); }
.empty-state .mascot { max-width: 150px; }
.empty-state img:not(.mascot) { width: 140px; height: auto; display: block; margin: 0 auto 10px; }

/* ---------------- รายงาน ---------------- */
.filters.inline { display: flex; flex-wrap: wrap; gap: 12px 14px; align-items: flex-end; }
.filters.inline .field { min-width: 180px; margin: 0; }
.filters-end { margin-left: auto; display: flex; gap: 8px; }
.page-intro { display: flex; align-items: center; gap: 20px; justify-content: space-between; margin-bottom: 18px; padding: 18px 22px;
  background: linear-gradient(110deg, #FFF6EC, #FFFDF9 60%, #F2FAFA); border: 1px solid var(--orange-line); border-radius: 14px; }
.page-intro h2 { margin: 0 0 4px; }
.page-intro p { margin: 0; max-width: 70ch; }
.intro-mascot { width: 92px; height: 92px; object-fit: contain; flex: none; }
.report-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.report-card { display: flex; flex-direction: column; gap: 6px; padding: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: border-color .15s, transform .15s, box-shadow .15s; position: relative; overflow: hidden; }
.report-card::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--brand-grad); opacity: .0; transition: opacity .15s; }
.report-card:hover { color: var(--ink); border-color: var(--orange-line); transform: translateY(-2px); box-shadow: 0 8px 22px rgba(30, 37, 50, .08); }
.report-card:hover::after { opacity: 1; }
.report-card b { font-size: 1.05rem; }
.rc-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--orange-soft); color: var(--orange-ink); margin-bottom: 4px; }
.rc-go { margin-top: auto; padding-top: 8px; color: var(--orange-ink); font-weight: 600; font-size: .88rem; display: inline-flex; align-items: center; gap: 4px; }

.report { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 32px; box-shadow: var(--shadow); }
.report-head { display: flex; gap: 18px; align-items: center; padding-bottom: 18px; border-bottom: 3px solid transparent; border-image: var(--brand-grad) 1; margin-bottom: 20px; }
.report-logo { width: 54px; height: auto; flex: none; }
.report-org { color: var(--muted); font-size: .86rem; }
.report-title { margin: 2px 0; font-size: 1.4rem; }
.report-sub { color: var(--muted); font-size: .86rem; }
.report-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; background: linear-gradient(180deg, #fff, #FCFCFD); }
.kpi:first-child { border-color: var(--orange-line); background: linear-gradient(180deg, #FFF8F1, #fff); }
.kpi .k { color: var(--muted); font-size: .84rem; }
.kpi .v { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.25; }
.kpi .v small { font-size: .8rem; font-weight: 400; color: var(--muted); margin-left: 4px; }
.kpi .n { color: var(--muted); font-size: .8rem; }
.insights { display: flex; gap: 14px; align-items: flex-start; padding: 14px 18px; border-radius: 12px; background: var(--gold-soft); border: 1px solid #EFDCA6; margin-bottom: 22px; }
.insights h3 { margin: 0 0 4px; font-size: .98rem; color: #6E5309; }
.insights ul { margin: 0; padding-left: 18px; font-size: .92rem; }
.insights-mascot { width: 64px; height: 64px; object-fit: contain; flex: none; }
.report-sec { margin-top: 26px; break-inside: avoid-page; }
.report-sec h3 { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; margin-bottom: 4px; }
.sec-no { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--orange); color: #fff; font-size: .8rem; font-weight: 700; flex: none; }
.report-sec .chart-box { margin: 10px 0 12px; }
.report-table td.up { color: var(--ok); }
.report-table td.down { color: var(--danger); }
.report-table tfoot th, .report-table tfoot td { font-weight: 600; background: #FAFAFB; border-top: 2px solid var(--line); }
.report-foot { margin-top: 26px; padding-top: 12px; border-top: 1px dashed var(--line); color: var(--muted); font-size: .8rem; }
@media (max-width: 700px) { .report { padding: 18px 16px; } .report-head { flex-direction: column; align-items: flex-start; } .filters-end { margin-left: 0; } }
@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body.app .shell, body.app .shell::before { background: #fff; }
  body.app .shell::before { display: none; }
  .greet, .sidebar-mascot { display: none !important; }
  .report { border: 0; box-shadow: none; padding: 0; }
  .report-sec { break-inside: auto; }
  .report-sec h3, .report-sec .chart-box { break-after: avoid; break-inside: avoid; }
  .report-table tr { break-inside: avoid; }
  .report-kpis { grid-template-columns: repeat(4, 1fr); }
  .kpi .v { font-size: 1.25rem; }
  .insights { break-inside: avoid; }
  .report .chart-box { height: 230px; }
  .report-card:hover { transform: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.mascot-strip { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; } .mascot-strip .ms { width: 52px; height: 52px; object-fit: contain; background: var(--orange-soft); border-radius: 10px; padding: 3px; }
.row-void td { background: #FCF4F2; } .row-void td:not(:last-child) { color: var(--muted); } .row-void td .tnum, .row-void td a { text-decoration: line-through; text-decoration-color: rgba(185, 58, 38, .5); }

/* ---------------- หน้านำเข้า: ส่วนหัวและแถบความคืบหน้า ---------------- */
.import-hero { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; padding: 18px 22px;
  background: linear-gradient(110deg, #FFF6EC, #FFFDF9 60%, #F2FAFA); border: 1px solid var(--orange-line); border-radius: 14px; }
.import-hero h2 { margin: 0 0 4px; }
.import-hero p { margin: 0; color: var(--ink-2); max-width: 75ch; }
.run-body { display: flex; gap: 22px; align-items: center; }
.run-main { flex: 1; min-width: 0; }
.progress { height: 12px; border-radius: 999px; background: var(--line-2); overflow: hidden; margin: 12px 0 6px; }
.progress > span { display: block; height: 100%; background: var(--brand-grad); border-radius: 999px; transition: width .4s ease; }
.run-status { margin: 0; font-size: .92rem; }
@media (max-width: 640px) { .import-hero, .run-body { flex-direction: column; align-items: flex-start; } }

/* =========================================================
   ขนาดน้องมีทุน — ปรับได้ที่นี่ที่เดียว (หน่วย px)
   ========================================================= */
:root {
  --mascot-sidebar: 46px;   /* กล่องเล็กล่างเมนูซ้าย */
  --mascot-greet:   96px;   /* กล่องทักทาย หน้าภาพรวม */
  --mascot-intro:   92px;   /* กล่องหัวหน้า: รายงาน, จัดการรายการรับทุน */
  --mascot-hero:    110px;  /* หัวหน้านำเข้าข้อมูล */
  --mascot-run:     120px;  /* ระหว่างนำเข้า / ผลการนำเข้า */
  --mascot-insight: 64px;   /* กล่อง “ข้อสังเกตจากข้อมูล” ในรายงาน */
  --mascot-empty:   150px;  /* หน้าว่าง (ยังไม่มีข้อมูล) */
  --mascot-login:   220px;  /* หน้าเข้าสู่ระบบ / หน้าติดตั้ง */
  --mascot-public:  150px;  /* หน้าสถิติสาธารณะ */
}
.sidebar-mascot .side-mascot { width: var(--mascot-sidebar); height: var(--mascot-sidebar); }
.greet-mascot   { width: var(--mascot-greet);   height: var(--mascot-greet); }
.intro-mascot   { width: var(--mascot-intro);   height: var(--mascot-intro); }
.hero-mascot    { width: var(--mascot-hero);    height: var(--mascot-hero); }
.run-mascot     { width: var(--mascot-run);     height: var(--mascot-run); }
.insights-mascot { width: var(--mascot-insight); height: var(--mascot-insight); }
.auth-mascot    { width: var(--mascot-login);   height: auto; }
.pub-hero .mascot { width: var(--mascot-public); height: auto; }
.empty-state .mascot, .empty-state img { width: var(--mascot-empty); max-width: var(--mascot-empty); height: auto; }
.side-mascot, .greet-mascot, .intro-mascot, .hero-mascot, .run-mascot, .insights-mascot { object-fit: contain; flex: none; }
@media (max-width: 700px) {   /* มือถือ: ย่อลงอัตโนมัติ */
  .greet-mascot, .intro-mascot, .hero-mascot, .run-mascot { width: calc(var(--mascot-intro) * .75); height: calc(var(--mascot-intro) * .75); }
  .auth-mascot { width: calc(var(--mascot-login) * .55); }
  .pub-hero .mascot { width: calc(var(--mascot-public) * .75); }
}

/* ---------------- งบประมาณ ---------------- */
.budget-table .cat-row td { background: #FAF6F1; border-top: 2px solid var(--line); padding-top: 10px; }
.budget-table .sub-row td { background: #FCFBF9; font-weight: 600; font-size: .9rem; }
.budget-table td.neg { color: var(--danger); }
.num-input { text-align: right; font-variant-numeric: tabular-nums; }
body.public { overflow-x: clip; }
.filters-grid .field > .btn, .filters-grid .field > button { align-self: flex-start; }
.pub-hero::before { left: 0; right: 0; }
/* กล่องอัปโหลด: ซ่อนปุ่มไฟล์ของเบราว์เซอร์ (ยังกด/ลากวางได้ทั้งกล่อง) แสดงชื่อไฟล์บรรทัดเดียว */
.dropzone { position: relative; }
.dropzone .dz-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; margin: 0; }
.dropzone .dz-btn { margin-top: 12px; pointer-events: none; }
.dropzone .dz-name { margin-top: 8px; font-size: .88rem; color: var(--muted); }
.dropzone.has-file { border-color: var(--orange-line); background: var(--orange-soft); }
.dropzone.has-file .dz-name { color: var(--orange-ink); font-weight: 600; }
.dropzone:focus-within { outline: 2px solid var(--orange); outline-offset: 2px; }
.dropzone.too-big { border-color: var(--danger); background: var(--danger-soft); } .dropzone.too-big .dz-name { color: var(--danger); font-weight: 600; }

/* ---------------- นักศึกษาหลายรหัส ---------------- */
.person-codes { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
.person-codes h3 { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .98rem; margin-bottom: 10px; }
.code-line { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.code-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; }
.code-card.me { border-color: var(--orange-line); background: var(--orange-soft); }
.code-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }
.code-link { display: flex; align-items: center; gap: 6px; padding: 2px 0 2px 14px; font-size: .84rem; font-weight: 600; }
.code-link .ico { transform: rotate(90deg); }
.code-link.tone-green { color: var(--ok); } .code-link.tone-red { color: var(--danger); }
.code-link.tone-teal { color: var(--teal); } .code-link.tone-orange { color: var(--orange-ink); }
.multi-badge { white-space: nowrap; }
tr.grp-alt td { background: #FAF7F3; }

/* ---------------- ตารางเรียงลำดับได้ ---------------- */
table.sortable th.sort-th { cursor: pointer; user-select: none; white-space: nowrap; }
table.sortable th.sort-th:hover { color: var(--orange-ink); background: #FBF4EC; }
table.sortable th.sort-th::after { content: "↕"; display: inline-block; margin-left: 4px; font-size: .78em; color: #B8BEC8; }
table.sortable th.sort-th[aria-sort="ascending"]::after { content: "▲"; color: var(--orange); }
table.sortable th.sort-th[aria-sort="descending"]::after { content: "▼"; color: var(--orange); }
table.sortable th.sort-th[aria-sort="ascending"], table.sortable th.sort-th[aria-sort="descending"] { color: var(--orange-ink); }
@media print { table.sortable th.sort-th::after { content: none; } }

/* ---------------- แผนภาพกล่องสัดส่วน (treemap) ---------------- */
.treemap { position: relative; width: 100%; aspect-ratio: var(--tm-ratio, 2.4); min-height: 200px; border-radius: 10px; overflow: hidden; background: var(--line-2); }
.tm-cell { position: absolute; box-sizing: border-box; border: 2px solid var(--panel); background: var(--c); color: var(--tc, #fff); padding: 8px 10px; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-start; gap: 2px; text-decoration: none; transition: filter .15s; line-height: 1.25; }
a.tm-cell:hover, .tm-cell:hover { filter: brightness(1.08) saturate(1.05); color: var(--tc, #fff); }
.tm-label { font-weight: 600; font-size: .86rem; text-shadow: 0 1px 2px rgba(0,0,0,.18); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tm-val { font-size: .78rem; opacity: .92; font-variant-numeric: tabular-nums; }
.tm-md { padding: 5px 7px; } .tm-md .tm-label { font-size: .74rem; -webkit-line-clamp: 2; } .tm-md .tm-val { font-size: .7rem; }
.tm-sm { padding: 0; } .tm-sm .tm-label, .tm-sm .tm-val { display: none; }
.tm-legend { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 18px; font-size: .84rem; }
.tm-legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 48px; gap: 8px; align-items: center; }
.tm-legend i { width: 12px; height: 12px; border-radius: 3px; }
.tm-legend span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-legend small { color: var(--muted); text-align: right; }
@media (max-width: 700px) { .treemap { aspect-ratio: 1.4; } .tm-label { font-size: .74rem; } }
@media print { .tm-cell { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
.report-tm { margin: 10px 0 14px; }
.back-row { margin: 0 0 12px; } .back-link { display: inline-flex; align-items: center; gap: 4px; font-size: .9rem; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 16px 0 0; font-size: .92rem; } .crumbs span { color: var(--muted); }

/* ---------------- ผู้รับทุนในหน้ารายละเอียดทุน ---------------- */
.recipients { scroll-margin-top: 16px; }
.ctx-bar { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; padding: 10px 20px 0; }
.ctx-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--orange-soft); border: 1px solid var(--orange-line); color: var(--orange-ink); font-size: .84rem; text-decoration: none; }
.ctx-chip:hover { background: #FBE2CC; color: var(--orange-ink); }
.ctx-chip span { font-size: 1rem; line-height: 1; opacity: .7; }
.rcp-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; padding: 14px 20px 4px; }
.rcp-kpis div { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #FCFCFD; }
.rcp-kpis div:first-child { border-color: var(--orange-line); background: var(--orange-soft); }
.rcp-kpis b { display: block; font-size: 1.2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.rcp-kpis span { color: var(--muted); font-size: .8rem; }
.rcp-break { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px 28px; padding: 10px 20px 0; }
.rcp-col h3 { font-size: .92rem; margin: 6px 0 4px; }
.rcp-break .bars li { padding: 4px 0; }
.rcp-filter { border-top: 1px dashed var(--line); margin-top: 12px; }
.th-sort { color: inherit; text-decoration: none; display: inline-flex; gap: 4px; align-items: center; white-space: nowrap; }
.th-sort span { font-size: .78em; color: #B8BEC8; }
.th-sort.on, .th-sort.on span { color: var(--orange-ink); }
a.cell-link { color: inherit; text-decoration: none; border-bottom: 1px dotted #C3C8D0; }
a.cell-link:hover { color: var(--orange-ink); border-bottom-color: var(--orange); }

/* ---------------- v2.9: ตัวกรองเชื่อมกัน / คำอธิบายเมนู / pivot แยกปี / สีกราฟ ---------------- */
.ms-opt.ms-off { display: none !important; }
.ms-note { font-size: .78rem; color: var(--orange-ink); background: var(--orange-soft); border-radius: 6px; padding: 4px 8px; margin-bottom: 6px; }
.page-desc { display: flex; gap: 10px; align-items: flex-start; margin: -6px 0 18px; padding: 10px 14px; border: 1px solid var(--line); border-left: 3px solid var(--orange);
  border-radius: 8px; background: var(--panel); font-size: .9rem; color: var(--ink-2); line-height: 1.55; }
.page-desc > svg { flex: none; width: 18px; height: 18px; margin-top: 2px; color: var(--orange); }
.page-desc p { margin: 0; }
.page-desc .alt { margin-top: 3px; color: var(--muted); font-size: .84rem; }
.page-desc .alt a { white-space: nowrap; }
table.pivot thead tr:nth-child(3) th { top: 74px; }
table.data th.subcol, table.data td.subcol { background: #FAF6F1; }
table.data tfoot td.subcol { background: #FBE7D5; }
table.data thead th.subcol { background: #F6EEE5; }
table.data .grp th.yr { background: #F1F3F6; color: var(--ink); }
.year-sum { width: 100%; border-collapse: collapse; font-size: .88rem; margin-top: 4px; }
.year-sum th, .year-sum td { padding: 5px 8px; border-bottom: 1px solid var(--line-2); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.year-sum th:first-child, .year-sum td:first-child { text-align: left; }
.year-sum thead th { color: var(--muted); font-weight: 600; font-size: .78rem; }
.year-sum tfoot td { font-weight: 600; border-top: 1px solid var(--line); border-bottom: 0; }
.year-sum i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; padding: 0; font-size: .82rem; color: var(--ink-2); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.org-tree td { vertical-align: middle; }
.org-tree tr.lv-department td { background: #F8F9FB; font-weight: 600; }
.org-tree tr.lv-major td:nth-child(2) { padding-left: 28px; }
.org-tree tr.lv-program td:nth-child(2) { padding-left: 52px; color: var(--ink-2); }
.org-tree tr.is-hidden td { color: #A5ACB8; }
.matrix td.r b { color: var(--ink); }
@media print { .page-desc { display: none; } }
.g-types { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
@media (max-width: 1100px) { .g-types { grid-template-columns: 1fr; } }

/* ---------------- v2.10: สรุปการให้บริการทุน ---------------- */
.svc-table tr.code-row { display: none; }
.svc-table.show-codes tr.code-row { display: table-row; }
.svc-table tr.code-row td { background: #FBFBFC; padding-top: 5px; padding-bottom: 5px; }
.svc-table tr.code-row td.stub { padding-left: 34px; }
.svc-table.show-codes tr.grp-row td { border-top: 1px solid var(--line); }
.svc-table th.reg-col, .svc-table td.reg-col { background: #F6F8FB; color: var(--ink-2); }
.svc-table td.diff { background: #FFF1C2 !important; color: #7A5A00; font-weight: 600; }
.svc-table th small { font-weight: 400; color: var(--muted); }
.warn-panel { border-color: #F1C3B8; }
.warn-panel .panel-head h2 { color: var(--danger); }
.svc-map td.need { background: #FFF4E5; }
.svc-map select { height: 34px; }
@media print { .svc-table.show-codes tr.code-row { display: table-row; } }

/* รูปภาพสรุป (กว้าง 2000 px) — 3 แบบ: pv-clean / pv-night / pv-cards
   สีทั้งหมดเป็นตัวแปร (--p-*) ค่าตั้งต้นอยู่ที่ service_poster_vars() ใน includes/service.php และแอดมินปรับได้ในหน้าจอ */
.poster-wrap { position: relative; width: 100%; overflow: hidden; margin-bottom: 12px; border-radius: 10px; box-shadow: var(--shadow); }
.poster-scale { transform-origin: 0 0; width: 2000px; }
.poster { position: relative; width: 2000px; overflow: hidden; font-family: var(--font); font-variant-numeric: tabular-nums; }
.poster h1, .poster h2 { margin: 0; white-space: nowrap; }
.poster .mascot { object-fit: contain; object-position: center bottom; }
.seg-link { display: inline-block; padding: 6px 12px; border-radius: 6px; color: var(--ink-2); text-decoration: none; font-size: .9rem; }
.seg-link.on { background: var(--ink); color: #fff; }
.poster-tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 16px; margin-top: 12px; }
.poster-tools .field-label { font-size: .8rem; }
.color-field { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; background: var(--panel); }
.color-field input[type=color] { width: 38px; height: 30px; padding: 0; border: 0; background: none; }
.color-field code { font-size: .8rem; color: var(--muted); }
.mascot-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.mascot-pick label { cursor: pointer; border: 2px solid var(--line); border-radius: 10px; padding: 4px; background: #fff; display: grid; place-items: center; width: 64px; height: 64px; font-size: .72rem; text-align: center; line-height: 1.15; }
.mascot-pick input { position: absolute; opacity: 0; pointer-events: none; }
.mascot-pick img { max-width: 52px; max-height: 52px; }
.mascot-pick input:checked + label { border-color: var(--orange); background: var(--orange-soft); }
.mascot-pick input:focus-visible + label { outline: 2px solid var(--orange); }

/* แบบ 1: สว่าง มินิมอล */
.pv-clean { --p-bg1: #FFFFFF; --p-bg2: #FCE9D8; --p-shape: #FDE2CA; --p-title: #1E2532; --p-accent: #E8731A; --p-dark: #1E2532; --p-text: #1E2532; --p-money: #A9500C; --p-card: #FFFFFF; --p-onaccent: #FFFFFF;
  background: linear-gradient(160deg, var(--p-bg1) 0%, var(--p-bg1) 35%, var(--p-bg2) 100%); color: var(--p-text); padding: 70px 90px 0; }
.pc-blob { position: absolute; border-radius: 50%; background: var(--p-shape); }
.pc-blob.b1 { width: 760px; height: 760px; right: -260px; top: -320px; }
.pc-blob.b2 { width: 420px; height: 420px; left: -200px; bottom: 120px; opacity: .6; }
.pc-head { position: relative; display: grid; grid-template-columns: 1fr 340px; align-items: end; min-height: 300px; }
.pc-logos { display: flex; gap: 28px; align-items: center; margin-bottom: 26px; grid-column: 1 / -1; }
.pc-logos img { height: 92px; }
.pc-title { grid-column: 1; }
.pc-title h1 { font-size: 84px; font-weight: 700; letter-spacing: -.5px; line-height: 1.2; color: var(--p-title); }
.pc-title h2 { display: inline-block; margin-top: 18px; font-size: 52px; font-weight: 600; color: var(--p-onaccent); background: var(--p-accent); border-radius: 999px; padding: 6px 40px 10px; }
.pc-mascot { position: absolute; right: -10px; bottom: -40px; width: 340px; height: 340px; }
.pc-kpis { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin: 56px 0 36px; }
.pc-kpi { background: var(--p-dark); color: #fff; border-radius: 28px; padding: 30px 44px 34px; }
.pc-kpi.alt { background: var(--p-accent); color: var(--p-onaccent); }
.pc-kpi span { display: block; font-size: 32px; opacity: .85; }
.pc-kpi b { display: block; font-size: 96px; font-weight: 700; line-height: 1.1; margin-top: 6px; }
.pc-card { position: relative; background: var(--p-card); border-radius: 32px; padding: 18px 40px 10px; border: 2px solid rgba(169, 80, 12, .14); }
.pc-table { width: 100%; border-collapse: collapse; font-size: 36px; color: var(--p-text); }
.pc-table th { text-align: left; font-size: 28px; font-weight: 600; color: var(--p-money); padding: 20px 10px 18px; border-bottom: 3px solid var(--p-shape); }
.pc-table td { padding: 15px 10px; border-bottom: 1px solid rgba(169, 80, 12, .12); white-space: nowrap; }
.pc-table .r { text-align: right; }
.pc-table th.r { width: 300px; }
.pc-table td.nm i { display: inline-block; width: 50px; height: 50px; line-height: 50px; border-radius: 50%; background: var(--p-shape); color: var(--p-money); font-style: normal; font-size: 26px; font-weight: 700; text-align: center; margin-right: 20px; vertical-align: 4px; }
.pc-table td.nm.long { font-size: 31px; } .pc-table td.nm.xlong { font-size: 26px; }
.pc-table tbody td:nth-child(3) { color: var(--p-money); font-weight: 600; }
.pc-table tfoot td { border-bottom: 0; border-top: 3px solid var(--p-dark); font-weight: 700; font-size: 44px; padding: 22px 10px 24px; }
.pc-foot { position: relative; display: flex; justify-content: space-between; align-items: center; margin: 40px -90px 0; padding: 30px 90px; background: var(--p-dark); color: #fff; font-size: 34px; font-weight: 600; }
.pc-foot small { font-size: 26px; font-weight: 400; opacity: .75; }

/* แบบ 2: พื้นเข้ม พรีเมียม */
.pv-night { --p-bg1: #0F1626; --p-bg2: #22304D; --p-glow1: #E8731A; --p-glow2: #E6B450; --p-title: #FFFFFF; --p-accent: #FF9A4A; --p-gold: #F4C46A; --p-sub: #F2B66B; --p-text: #FFFFFF; --p-total: #E8731A;
  background: linear-gradient(150deg, var(--p-bg1) 0%, var(--p-bg2) 100%); color: var(--p-text); padding: 76px 90px 0; }
.pn-glow { position: absolute; border-radius: 50%; opacity: .32; }
.pn-glow.g1 { width: 900px; height: 900px; left: -380px; top: 380px; background: radial-gradient(circle, var(--p-glow1) 0%, transparent 65%); }
.pn-glow.g2 { width: 800px; height: 800px; right: -300px; top: -360px; background: radial-gradient(circle, var(--p-glow2) 0%, transparent 65%); opacity: .26; }
.pn-head { position: relative; display: grid; grid-template-columns: 250px 1fr auto; gap: 50px; align-items: center; padding-bottom: 50px; border-bottom: 2px solid rgba(255,255,255,.14); }
.pn-logo { width: 250px; }
.pn-logo2 { max-height: 150px; max-width: 240px; }
.pn-title small { display: block; font-size: 32px; color: var(--p-sub); font-weight: 500; letter-spacing: 1px; }
.pn-title h1 { font-size: 84px; font-weight: 700; line-height: 1.2; color: var(--p-title); }
.pn-title h2 { font-size: 60px; font-weight: 600; color: var(--p-accent); line-height: 1.25; }
.pn-body { position: relative; display: grid; grid-template-columns: 470px 1fr; gap: 60px; padding: 50px 0 40px; }
.pn-side { position: relative; }
.pn-total { background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.12); border-radius: 30px; padding: 30px 36px; margin-bottom: 26px; }
.pn-total span { display: block; font-size: 30px; color: var(--p-text); opacity: .7; }
.pn-total b { display: block; font-size: 92px; font-weight: 700; line-height: 1.1; color: var(--p-accent); }
.pn-total.gold b { color: var(--p-gold); font-size: 64px; letter-spacing: -1px; white-space: nowrap; }
.pn-mascot { display: block; width: 380px; height: 400px; margin: 40px auto 0; }
.pn-table { width: 100%; border-collapse: collapse; font-size: 35px; align-self: start; color: var(--p-text); }
.pn-table th { text-align: left; font-size: 27px; font-weight: 500; opacity: .65; padding: 0 16px 18px; border-bottom: 2px solid rgba(255,255,255,.18); }
.pn-table th.r { width: 270px; }
.pn-table td { padding: 15px 16px; border-bottom: 1px solid rgba(255,255,255,.08); white-space: nowrap; }
.pn-table tbody tr:nth-child(odd) td { background: rgba(255,255,255,.035); }
.pn-table .r { text-align: right; }
.pn-table td.m { color: var(--p-gold); }
.pn-table td.nm.long { font-size: 30px; } .pn-table td.nm.xlong { font-size: 25px; }
.pn-table tfoot td { background: var(--p-total); color: #fff; font-weight: 700; font-size: 44px; padding: 22px 16px; border: 0; }
.pn-table tfoot td:first-child { border-radius: 18px 0 0 18px; } .pn-table tfoot td:last-child { border-radius: 0 18px 18px 0; }
.pn-foot { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 30px 0 40px; border-top: 2px solid rgba(255,255,255,.14); font-size: 34px; font-weight: 600; color: var(--p-sub); }
.pn-foot small { font-size: 26px; color: var(--p-text); opacity: .6; font-weight: 400; }

/* แบบ 3: การ์ดอินโฟกราฟิก */
.pv-cards { --p-head1: #D9601A; --p-head2: #F4A04A; --p-title: #FFFFFF; --p-bg: #FBF6F0; --p-text: #1E2532; --p-money: #A9500C; --p-total: #D9601A; --p-dark: #1E2532; --p-card: #FFFFFF;
  background: var(--p-bg); color: var(--p-text); }
.pk-head { position: relative; display: grid; grid-template-columns: 1fr 360px; align-items: center; padding: 64px 80px 70px; background: linear-gradient(120deg, var(--p-head1) 0%, var(--p-head2) 100%); color: var(--p-title); border-radius: 0 0 70px 70px; min-height: 380px; }
.pk-logos { display: flex; gap: 26px; align-items: center; margin-bottom: 26px; grid-column: 1 / -1; }
.pk-logos img { height: 84px; }
.pk-title { grid-column: 1; }
.pk-title h1 { font-size: 82px; font-weight: 700; line-height: 1.2; text-shadow: 0 3px 0 rgba(0,0,0,.12); }
.pk-title h2 { font-size: 58px; font-weight: 600; line-height: 1.3; opacity: .92; }
.pk-mascot { position: absolute; right: 70px; bottom: -40px; width: 340px; height: 360px; }
.pk-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin: -50px 80px 40px; position: relative; }
.pk-kpis div { background: var(--p-card); border-radius: 30px; padding: 26px 40px 30px; border: 2px solid rgba(169, 80, 12, .14); }
.pk-kpis span { display: block; font-size: 28px; color: #8A93A3; }
.pk-kpis b { display: block; font-size: 88px; font-weight: 700; line-height: 1.1; color: var(--p-text); }
.pk-kpis div:last-child b { color: var(--p-total); }
.pk-kpis em { font-style: normal; font-size: 28px; color: #667085; }
.pk-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; padding: 0 80px; }
.pk-card { position: relative; background: var(--p-card); border-radius: 26px; padding: 26px 30px 24px 38px; border: 2px solid rgba(30, 37, 50, .07); overflow: hidden; min-height: 200px; display: flex; flex-direction: column; justify-content: space-between; }
.pk-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 12px; background: var(--c); }
.pk-name { display: flex; gap: 16px; align-items: flex-start; font-size: 29px; font-weight: 600; line-height: 1.35; }
.pk-name.long { font-size: 26px; } .pk-name.xlong { font-size: 23px; }
.pk-name i { flex: none; width: 44px; height: 44px; line-height: 44px; border-radius: 50%; background: var(--c); color: #fff; font-style: normal; font-size: 23px; text-align: center; margin-top: 2px; }
.pk-nums { display: flex; align-items: baseline; gap: 10px; margin-top: 14px; }
.pk-nums b { font-size: 62px; font-weight: 700; line-height: 1; }
.pk-nums small { font-size: 26px; color: #667085; }
.pk-nums span { margin-left: auto; font-size: 32px; font-weight: 600; color: var(--p-money); }
.pk-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 46px; padding: 30px 80px 34px; background: var(--p-dark); color: #fff; font-size: 34px; font-weight: 600; }
.pk-foot small { font-size: 26px; font-weight: 400; opacity: .75; }
@media print { .poster-wrap { box-shadow: none; } }
.poster .mascot[hidden] { display: none !important; }
.pv-cards.cards-single .pk-card { --c: var(--p-total) !important; }
/* v2.12.1 รูปภาพรายปีแบบแยกรายภาค (ตาราง .multi / การ์ด .pk-terms / ตัวเลขรายภาคใต้ยอดรวม .kterms) */
.poster .kterms { display: block; margin-top: 10px; font-size: 26px; font-weight: 500; opacity: .85; white-space: nowrap; }
.poster table.multi { table-layout: auto; }
.poster table.multi th, .poster table.multi td { padding-left: 8px; padding-right: 8px; }
.poster table.multi th { white-space: nowrap; }
.poster table.multi th.c { text-align: center; }
.poster table.multi td.nm { white-space: normal; line-height: 1.3; }
.pc-table.multi { font-size: 27px; }
.pc-table.multi th { font-size: 23px; padding-top: 14px; padding-bottom: 12px; }
.pc-table.multi th.r { width: auto; }
.pc-table.multi thead tr:first-child th.c { border-bottom: 1px solid var(--p-shape); font-size: 26px; color: var(--p-text); }
.pc-table.multi td.nm { font-size: 27px; } .pc-table.multi td.nm.long { font-size: 25px; } .pc-table.multi td.nm.xlong { font-size: 23px; }
.pc-table.multi td.nm i { width: 40px; height: 40px; line-height: 40px; font-size: 21px; margin-right: 12px; vertical-align: 2px; }
.pc-table.multi tbody td.m { color: var(--p-money); font-weight: 400; }
.pc-table.multi .tot { background: var(--p-bg2); font-weight: 700; }
.pc-table.multi tbody td.tot { font-weight: 700; }
.pc-table.multi tfoot td { font-size: 30px; }
.pc-table.multi tfoot td.tot { background: var(--p-accent); color: var(--p-onaccent); }
.pn-body.wide { grid-template-columns: 1fr; gap: 34px; }
.pn-body.wide .pn-side { display: grid; grid-template-columns: 1fr 1fr 220px; gap: 26px; align-items: stretch; }
.pn-body.wide .pn-mascot { align-self: end; }
.pn-body.wide .pn-total { margin: 0; }
.pn-body.wide .pn-mascot { width: 220px; height: 240px; margin: 0; }
.pn-table.multi { font-size: 27px; }
.pn-table.multi th { font-size: 23px; padding-bottom: 12px; }
.pn-table.multi th.r { width: auto; }
.pn-table.multi thead tr:first-child th.c { opacity: .9; font-size: 26px; color: var(--p-sub); border-bottom: 1px solid rgba(255,255,255,.18); }
.pn-table.multi td.nm { font-size: 27px; } .pn-table.multi td.nm.long { font-size: 25px; } .pn-table.multi td.nm.xlong { font-size: 23px; }
.pn-table.multi .tot { background: rgba(255,255,255,.08); font-weight: 700; }
.pn-table.multi tfoot td { font-size: 30px; }
.pn-table.multi tfoot td.tot { background: var(--p-total); box-shadow: inset 0 0 0 999px rgba(0,0,0,.14); }
.pk-terms { display: flex; gap: 8px; margin-top: 14px; }
.pk-terms div { flex: 1; min-width: 0; background: rgba(30, 37, 50, .045); border-radius: 12px; padding: 8px 10px; line-height: 1.2; }
.pk-terms em { display: block; font-style: normal; font-size: 19px; color: #667085; }
.pk-terms b { font-size: 30px; font-weight: 700; margin-right: 6px; }
.pk-terms span { display: block; font-size: 20px; color: var(--p-money); white-space: nowrap; }
.pk-nums .pk-sum { font-style: normal; font-size: 22px; color: #667085; white-space: nowrap; }
.pv-cards.bt .pk-nums { flex-wrap: wrap; row-gap: 4px; }
.pv-cards.bt .pk-nums b { font-size: 52px; }
.pv-cards.bt .pk-nums small, .pv-cards.bt .pk-nums span { white-space: nowrap; }
.pk-kpis .kterms { color: #667085; font-size: 24px; }
.poster-custom summary { cursor: pointer; list-style: none; }
.poster-custom summary::-webkit-details-marker { display: none; }
.poster-custom summary::before { content: "▸ "; }
.poster-custom[open] summary::before { content: "▾ "; }

/* =====================================================================
   v2.11 ลูกเล่นการเคลื่อนไหว (motion) — เล็กน้อย ไม่รบกวนการอ่าน
   ทั้งหมดอยู่ใน prefers-reduced-motion: no-preference (ผู้ที่ตั้งลดการเคลื่อนไหวจะไม่เห็น)
   ไม่ใช้กับรูปภาพสรุป (.poster) เพื่อไม่ให้กระทบการสร้างไฟล์ PNG
   ===================================================================== */
.nav-link .ico { transition: transform .25s cubic-bezier(.3, 1.6, .5, 1), color .15s; }
.nav-link { transition: background-color .18s, color .18s, padding-left .18s; }
.btn { transition: background-color .15s, border-color .15s, color .15s, transform .12s, box-shadow .15s; }
table.data tbody tr { transition: background-color .12s; }
.sidebar-foot a .ico, .greet-link .ico { transition: transform .2s; }
.count-up { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: no-preference) {
  /* ---- เมนูซ้าย ---- */
  .nav-link:hover { padding-left: 13px; }
  .nav-link:hover .ico { transform: rotate(-10deg) scale(1.15); color: var(--orange); }
  .nav-link.on .ico { animation: mo-pop .6s cubic-bezier(.3, 1.6, .5, 1) .15s backwards; }
  .nav-link.on::before { animation: mo-grow-y .45s cubic-bezier(.2, .8, .2, 1) .05s backwards; transform-origin: 50% 50%; }
  .nav-link.on::after { content: ""; position: absolute; right: 10px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--orange); animation: mo-blink 2.8s ease-in-out 1s infinite; }
  .nav-sub a { transition: color .15s, background-color .15s, transform .15s; }
  .nav-sub a:hover { transform: translateX(3px); }
  .nav-sub { animation: mo-fade-down .35s ease-out backwards; }
  .sidebar-foot a:hover .ico { transform: translateX(2px) rotate(-12deg); }
  .brand:hover .brand-logo, .brand:hover .brand-mark { animation: mo-nod .6s ease; }
  .sidebar-mascot { transition: transform .2s; }
  .sidebar-mascot .side-mascot { animation: mo-float 4.8s ease-in-out infinite; transform-origin: 50% 100%; }
  .sidebar-mascot:hover .side-mascot { animation: mo-wave .7s ease; }

  /* ---- หัวหน้า / ข้อความแจ้ง ---- */
  .page-title { animation: mo-slide-in .4s cubic-bezier(.2, .8, .2, 1) backwards; }
  .alert { animation: mo-fade-down .4s cubic-bezier(.2, .8, .2, 1) backwards; }
  .page-desc { animation: mo-rise .45s cubic-bezier(.2, .8, .2, 1) backwards; }

  /* ---- กล่องเนื้อหาเลื่อนขึ้นตามลำดับ (ทำครั้งเดียวตอนเปิดหน้า) ---- */
  .main > .panel, .main > .grid > *, .main > .greet, .main > form, .main > .kpis, .main > .tabs, .main > section:not(.poster-page),
  .pub-main > .panel, .pub-main > .grid > *, .pub-main > section {
    animation: mo-rise .55s cubic-bezier(.2, .8, .2, 1) backwards;
    animation-delay: calc(var(--mo-i, 0) * 70ms + 60ms);
  }
  .main > :nth-child(2) { --mo-i: 1; } .main > :nth-child(3) { --mo-i: 2; } .main > :nth-child(4) { --mo-i: 3; }
  .main > :nth-child(5) { --mo-i: 4; } .main > :nth-child(6) { --mo-i: 5; } .main > :nth-child(n+7) { --mo-i: 6; }
  .grid > :nth-child(2) { --mo-i: 2; } .grid > :nth-child(3) { --mo-i: 3; } .grid > :nth-child(4) { --mo-i: 4; } .grid > :nth-child(n+5) { --mo-i: 5; }
  .pub-main > :nth-child(2) { --mo-i: 1; } .pub-main > :nth-child(3) { --mo-i: 2; } .pub-main > :nth-child(n+4) { --mo-i: 3; }
  .panel { transition: box-shadow .2s, border-color .2s; }
  .panel:hover { box-shadow: 0 6px 22px -12px rgba(30, 37, 50, .25); }

  /* ---- ตัวเลขสำคัญ / การ์ด ---- */
  .kpi, .fig { animation: mo-rise .5s cubic-bezier(.2, .8, .2, 1) backwards; }
  .kpi:nth-child(2), .fig:nth-child(2) { animation-delay: .08s; }
  .kpi:nth-child(3), .fig:nth-child(3) { animation-delay: .16s; }
  .kpi:nth-child(4), .fig:nth-child(4) { animation-delay: .24s; }
  .kpi:nth-child(n+5) { animation-delay: .3s; }
  .kpi { transition: transform .18s, box-shadow .18s; }
  .kpi:hover { transform: translateY(-2px); box-shadow: 0 8px 18px -12px rgba(232, 115, 26, .55); }
  .report-card:hover { transform: translateY(-3px); }

  /* ---- แท่งสัดส่วน (HTML) ขยายจากซ้าย เมื่อเลื่อนมาถึง ---- */
  .bars .track span, .termbar-track span, .progress > span { transform-origin: 0 50%; }
  .mo-wait .bars .track span, .mo-wait .termbar-track span, .mo-wait.progress > span, .mo-wait .progress > span { transform: scaleX(0); }
  .mo-in .bars .track span, .mo-in .termbar-track span, .mo-in.progress > span, .mo-in .progress > span { transform: scaleX(1); transition: transform .9s cubic-bezier(.2, .8, .2, 1); }
  .bars li:nth-child(2) .track span { transition-delay: .05s !important; } .bars li:nth-child(3) .track span { transition-delay: .1s !important; }
  .bars li:nth-child(4) .track span { transition-delay: .15s !important; } .bars li:nth-child(5) .track span { transition-delay: .2s !important; }
  .bars li:nth-child(n+6) .track span { transition-delay: .25s !important; }
  .bars li { transition: background-color .15s; }
  .bars li:hover { background: linear-gradient(90deg, transparent, var(--orange-soft) 40%, transparent); }

  /* ---- แผนภาพกล่องสัดส่วน ---- */
  .mo-wait .tm-cell { opacity: 0; transform: scale(.9); }
  .mo-in .tm-cell { opacity: 1; transform: none; transition: opacity .5s ease, transform .55s cubic-bezier(.3, 1.4, .5, 1), filter .15s; transition-delay: calc(var(--tm-i, 0) * 45ms); }
  .tm-cell:hover { filter: brightness(1.08) saturate(1.05); }

  /* ---- กราฟ: ระหว่างรอเลื่อนมาถึง ---- */
  canvas[data-chart].mo-chart-wait { opacity: 0; }
  canvas[data-chart] { transition: opacity .35s ease; }

  /* ---- น้องมีทุน ---- */
  .greet-mascot { animation: mo-wave-in .7s cubic-bezier(.3, 1.5, .5, 1) .15s backwards; transform-origin: 50% 100%; }
  .greet:hover .greet-mascot { animation: mo-wave .7s ease; }
  .greet-link:hover .ico { transform: translateX(3px); }
  .empty-state .mascot, .empty-state img { animation: mo-wave-in .7s cubic-bezier(.3, 1.5, .5, 1) .1s backwards, mo-float 5s ease-in-out 1s infinite; transform-origin: 50% 100%; }
  .api-newkey-mascot { animation: mo-wave-in .7s cubic-bezier(.3, 1.5, .5, 1) backwards; transform-origin: 50% 100%; }

  /* ---- ปุ่ม ---- */
  .btn:active { transform: scale(.97); }
  .btn-primary:hover { box-shadow: 0 6px 14px -8px rgba(232, 115, 26, .8); }

  /* ---- แท็บ / ตัวเลือกแบบปุ่ม ---- */
  .tabs a, .seg label { transition: background-color .15s, color .15s, box-shadow .15s; }

  /* ไม่เคลื่อนไหวในรูปภาพสรุป */
  .poster, .poster * { animation: none !important; }
}
@keyframes mo-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes mo-fade-down { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes mo-slide-in { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes mo-grow-y { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes mo-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.2) rotate(-10deg); } 100% { transform: none; } }
@keyframes mo-blink { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }
@keyframes mo-float { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-5px) rotate(-2deg); } }
@keyframes mo-wave { 25% { transform: rotate(-9deg); } 60% { transform: rotate(7deg); } 100% { transform: none; } }
@keyframes mo-wave-in { from { opacity: 0; transform: translateY(14px) scale(.8) rotate(-6deg); } to { opacity: 1; transform: none; } }
@keyframes mo-nod { 30% { transform: rotate(-8deg); } 70% { transform: rotate(6deg); } }
@media print {
  .main > *, .grid > *, .kpi, .fig, canvas[data-chart] { animation: none !important; opacity: 1 !important; transform: none !important; }
  .mo-wait .bars .track span, .mo-wait .termbar-track span, .mo-wait .tm-cell { transform: none !important; opacity: 1 !important; }
}

/* v2.11.1 แก้ตัวเลือกถูกกล่องถัดไปทับ: ภาพเคลื่อนไหวที่ค้างค่าไว้ (fill-mode both) ทำให้ทุกกล่องเป็นชั้นซ้อนแยก (stacking context)
   → ใช้ backwards (ไม่ค้างค่าหลังจบ) และยกกล่องที่มีตัวเลือกเปิดอยู่ขึ้นมาบนสุดเสมอ */
.panel:has(details[open]), .grid > :has(details[open]), .main > :has(details.ms[open]), .kpis:has(details[open]) { position: relative; z-index: 26; }
.ms[open] { z-index: 27; }

/* ---- v2.11 หน้าตั้งค่า: API ---- */
.api-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; }
.api-grid .field-label { font-weight: 600; }
.api-key-box { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0 8px; }
.api-key-box code { flex: 1; min-width: 0; padding: 7px 10px; border: 1px dashed var(--orange-line); border-radius: 8px; background: #FFFBF6; word-break: break-all; font-size: .86rem; }
.api-endpoints { margin: 6px 0 8px; padding-left: 18px; }
.api-endpoints li { margin: 3px 0; }
.api-create { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: #FCFCFD; }
.api-newkey { display: flex; gap: 14px; align-items: center; padding: 12px 16px; margin-bottom: 16px; border: 1px solid var(--orange-line); border-radius: 12px; background: var(--orange-soft); }
.api-newkey-mascot { width: 72px; height: 72px; object-fit: contain; flex: none; }
.api-newkey > div { flex: 1; min-width: 0; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline-form input { height: 32px; padding: 0 8px; font-size: .84rem; }
tr.row-off td { opacity: .55; }
.api-log summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
.api-log .table-wrap { margin-top: 10px; }
.copied { background: var(--ok-soft) !important; border-color: var(--ok) !important; color: var(--ok) !important; }
@media (max-width: 900px) { .api-grid { grid-template-columns: 1fr; } }
