* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --pink: #DB2777; --teal: #0F766E; --yellow: #B45309; --mint: #15803D; --coral: #EA580C;
  --line: #E2E8F0; --glass: #FFFFFF;
}
html { background: #F3F6FA; }
body {
  font-family: 'Sarabun', 'Kanit', sans-serif;
  background: #F3F6FA;
  color: #1E293B; font-size: 16px; line-height: 1.6; min-height: 100vh; padding: 2rem;
}
a { color: var(--teal); }
.container { max-width: 1400px; margin: 0 auto; }
.container.narrow { max-width: 820px; }
.header { text-align: center; margin-bottom: 2.5rem; animation: fadeInUp .4s ease-out; }
.title {
  font-family: 'Kanit', sans-serif; font-size: 2.1rem; font-weight: 700; margin-bottom: .5rem; line-height: 1.45;
  color: #0B3B6F;
}
@keyframes shimmer { 0% { background-position: -1000px 0; } 100% { background-position: 1000px 0; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
.subtitle { font-size: 1rem; color: #475569; margin-top: .6rem; }
.card {
  background: #FFFFFF; border-radius: 16px; border: 1px solid #E2E8F0; padding: 1.6rem;
  margin-bottom: 1.6rem; animation: fadeInUp .5s ease-out; box-shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.04);
}
.card-title { font-family: 'Kanit', sans-serif; font-size: 1.3rem; font-weight: 600; color: #0B3B6F; margin-bottom: 1rem; }
.card-sub { font-size: .92rem; color: #64748B; margin: -.6rem 0 1.2rem; }
.stat-card {
  background: #F8FAFC; border: 1px solid #E2E8F0;
  padding: 1.5rem; border-radius: 14px; text-align: center; transition: transform .3s ease;
}
.stat-card:hover { transform: translateY(-5px); }
.stat-value { font-size: 2rem; font-weight: 700; margin: .5rem 0; }
.stat-label { font-size: .9rem; color: #475569; }
.stat-card-diff {
  background: linear-gradient(135deg, rgba(217,119,6,0.25) 0%, rgba(219,39,119,0.25) 100%);
  padding: 1.5rem; border-radius: 15px; text-align: center; transition: transform .3s ease;
  border: 2px solid rgba(217,119,6,0.6); box-shadow: 0 0 18px rgba(217,119,6,0.25); position: relative;
}
.stat-card-diff .badge {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  background: linear-gradient(135deg, #B45309, #DB2777); color: #1a1a2e;
  font-size: .72rem; font-weight: 700; padding: 2px 10px; border-radius: 20px; white-space: nowrap;
}
.loading { text-align: center; padding: 4rem; font-size: 1.5rem; }
.btn {
  display: inline-block; background: #0B5CAD;
  border: none; padding: .6rem 1.5rem; border-radius: 12px; color: #fff; font-size: .9rem;
  font-weight: 600; cursor: pointer; font-family: 'Kanit', sans-serif; transition: all .3s ease; text-decoration: none;
}
.btn:hover { background: #094C8F; } .btn-ghost:hover { background: #EFF6FF; }
.btn-ghost { background: #FFFFFF; color: #0B5CAD; border: 1px solid #0B5CAD; }
.btn-sm { padding: .35rem .9rem; font-size: .8rem; border-radius: 9px; }
.linkbtn { background: none; border: none; color: var(--teal); cursor: pointer; font-family: inherit; font-size: .88rem; text-decoration: underline; }
.filter-btn {
  background: #FFFFFF; border: 1px solid #CBD5E1; color: #334155;
  padding: .6rem 1.3rem; border-radius: 10px; cursor: pointer; transition: all .2s ease;
  font-family: 'Kanit', sans-serif; font-weight: 400; font-size: .95rem;
}
.filter-btn:hover { background: #F1F5F9; border-color: #94A3B8; }
.filter-btn.active { background: #0B5CAD; border-color: #0B5CAD; color: #fff; font-weight: 600; }
.btn-row { display: flex; gap: .8rem; flex-wrap: wrap; }
.filter-label { font-size: .95rem; margin-bottom: .7rem; opacity: .9; }
.chart-container { position: relative; height: 350px; margin: 1.5rem 0; }
.status-bar {
  display: inline-flex; gap: 1rem; align-items: center; padding: .7rem 1.3rem;
  background: #FFFFFF; border-radius: 12px; border: 1px solid #E2E8F0;
  font-size: .92rem; margin-top: 1rem; flex-wrap: wrap; justify-content: center; color: #334155;
}
.user-chip { background: #F1F5F9; color: #334155; padding: .25rem .8rem; border-radius: 20px; font-size: .85rem; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; align-items: start; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(450px, 1fr)); gap: 2rem; margin-bottom: 2rem; }
.grid-2 > .card { margin-bottom: 0; }
.note-box { margin-top: 1.5rem; padding: 1rem; background: rgba(15,23,42,0.04); border-radius: 12px; font-size: .9rem; line-height: 1.6; }

/* service flow */
.service-flow { display: flex; align-items: stretch; flex-wrap: wrap; justify-content: center; margin: 1.2rem 0; }
.flow-step {
  flex: 1; min-width: 160px; max-width: 220px; background: rgba(15,118,110,0.1);
  border: 1px solid rgba(15,118,110,0.3); border-radius: 14px; padding: 1.1rem 1rem; text-align: center; transition: transform .3s ease;
}
.flow-step:hover { transform: translateY(-4px); }
.flow-step .step-num {
  width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #0F766E, #115E59);
  color: #1a1a2e; font-weight: 700; font-size: .85rem; display: flex; align-items: center; justify-content: center; margin: 0 auto .6rem;
}
.flow-step .step-icon { font-size: 1.6rem; margin-bottom: .4rem; }
.flow-step .step-title { font-size: .88rem; font-weight: 600; color: var(--teal); margin-bottom: .3rem; }
.flow-step .step-desc { font-size: .78rem; opacity: .85; line-height: 1.5; }
.flow-arrow { display: flex; align-items: center; justify-content: center; color: var(--yellow); font-size: 1.4rem; padding: 0 .3rem; }
.highlight-15days { display: inline-block; background: linear-gradient(135deg, #B45309, #DB2777); color: #1a1a2e; font-weight: 700; font-size: .85rem; padding: 2px 8px; border-radius: 8px; margin-top: .3rem; }
.no-debt-badge {
  display: inline-flex; align-items: center; gap: .5rem; background: linear-gradient(135deg, rgba(21,128,61,0.2), rgba(15,118,110,0.2));
  border: 1.5px solid #15803D; border-radius: 12px; padding: .7rem 1.2rem; font-size: .95rem; font-weight: 600; color: #15803D; margin-top: 1rem;
}

/* diff card */
.diff-card {
  background: linear-gradient(135deg, rgba(217,119,6,0.08) 0%, rgba(219,39,119,0.08) 100%);
  border: 2px solid rgba(217,119,6,0.4); border-radius: 20px; padding: 1.5rem; margin-bottom: 2rem; box-shadow: 0 0 24px rgba(217,119,6,0.1);
}
.diff-title { font-size: 1.35rem; font-weight: 700; color: var(--yellow); margin-bottom: 1rem; }
.diff-reason-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; margin-bottom: 1.2rem; }
.diff-reason-box { border-radius: 12px; padding: 1rem 1.2rem; font-size: .88rem; line-height: 1.7; }
.diff-reason-box.major { background: rgba(219,39,119,0.12); border-left: 4px solid #DB2777; }
.diff-reason-box.minor { background: rgba(217,119,6,0.08); border-left: 4px solid #B45309; }
.diff-reason-box .box-title { font-weight: 700; font-size: .92rem; margin-bottom: .5rem; }
.diff-trend { background: rgba(21,128,61,0.1); border: 1px solid rgba(21,128,61,0.3); border-radius: 12px; padding: 1rem 1.2rem; font-size: .88rem; line-height: 1.7; }
.pill { display: inline-block; background: rgba(15,118,110,0.15); border: 1px solid rgba(15,118,110,0.4); color: var(--teal); font-size: .78rem; font-weight: 600; padding: 2px 10px; border-radius: 20px; margin: 2px; }

/* latest term */
.term-hero { display: grid; grid-template-columns: 1.1fr 2fr; gap: 1.5rem; }
.term-big { background: linear-gradient(135deg, rgba(15,118,110,0.18), rgba(217,119,6,0.14)); border-radius: 16px; padding: 1.4rem; text-align: center; border: 1px solid rgba(15,118,110,0.35); }
.term-big .big { font-size: 3rem; font-weight: 700; color: var(--teal); line-height: 1.1; }
.mini-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .9rem; }
.mini { background: rgba(15,23,42,0.04); border: 1px solid var(--line); border-radius: 12px; padding: .9rem; }
.mini .k { font-size: .86rem; color: #475569; }
.mini .v { font-size: 1.35rem; font-weight: 700; margin-top: .2rem; }
.mini .s { font-size: .82rem; color: #64748B; }
.type-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem; margin-top: 1rem; }
.type-card { border-radius: 12px; padding: .9rem 1rem; background: rgba(15,23,42,0.034); border-left: 4px solid var(--c, #0F766E); }
.type-card .name { font-weight: 600; color: var(--c); font-size: .92rem; }
.type-card .line { display: flex; justify-content: space-between; font-size: .82rem; opacity: .9; margin-top: .25rem; gap: .5rem; }

/* level/faculty analysis */
.toolbar { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
select, .sel {
  background: #FFFFFF; color: #1E293B; border: 1px solid #CBD5E1;
  padding: .55rem .9rem; border-radius: 10px; font-family: 'Sarabun', sans-serif; font-size: 1rem;
}
select option { color: #111; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { border-radius: 14px; padding: 1rem; background: rgba(15,23,42,0.046); border: 1px solid var(--line); text-align: center; }
.kpi .v { font-size: 1.7rem; font-weight: 700; }
.kpi .k { font-size: .9rem; color: #475569; }
.kpi .s { font-size: .8rem; color: #64748B; margin-top: .2rem; }
.data-table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 640px; }
table.data th, table.data td { padding: .6rem .75rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.data th { background: #F1F5F9; color: #334155; font-weight: 600; text-align: center; }
table.data td:first-child, table.data th:first-child { text-align: left; }
table.data tr.total td { font-weight: 700; background: rgba(217,119,6,0.08); color: var(--yellow); }
.na { color: #94A3B8; font-size: .82rem; }
.bar-pct { display: inline-block; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #0F766E, #B45309); vertical-align: middle; margin-left: .4rem; }
.heat td.cell { text-align: center; }
.heat td.cell .p { font-weight: 700; font-size: .95rem; }
.heat td.cell .n { font-size: .7rem; opacity: .75; }
.legend-inline { font-size: .85rem; color: #64748B; margin-top: .6rem; }
.missing-box { border: 1px dashed rgba(217,119,6,0.5); border-radius: 14px; padding: 1.2rem; text-align: center; opacity: .9; background: rgba(217,119,6,0.05); }
.completeness { display: flex; flex-wrap: wrap; gap: .5rem; margin: .4rem 0 1rem; }
.chip { font-size: .78rem; padding: .2rem .7rem; border-radius: 20px; border: 1px solid var(--line); background: rgba(15,23,42,0.04); }
.chip.ok { border-color: rgba(21,128,61,0.5); color: var(--mint); }
.chip.no { border-color: rgba(219,39,119,0.45); color: var(--pink); }

/* contact */
.contact-card { background: linear-gradient(135deg, rgba(15,118,110,0.08) 0%, rgba(219,39,119,0.08) 100%); border: 1px solid rgba(15,23,42,0.058); border-radius: 20px; padding: 2rem; margin-bottom: 2rem; }
.contact-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.2rem; margin-top: 1.2rem; }
.contact-item { background: rgba(15,23,42,0.04); border-radius: 14px; padding: 1.1rem 1.2rem; font-size: .9rem; line-height: 1.8; }
.contact-item .ci-title { font-weight: 700; font-size: 1rem; margin-bottom: .5rem; }
.contact-item a { color: inherit; text-decoration: none; }
.contact-item a:hover { text-decoration: underline; }

/* register */
.reg-form { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.2rem; }
.reg-form .field { display: flex; flex-direction: column; gap: .35rem; }
.reg-form .full { grid-column: 1 / -1; }
.reg-form label { font-size: .9rem; opacity: .9; }
.reg-form small { font-size: .75rem; opacity: .6; }
.reg-form input:not([type=checkbox]), .reg-form select {
  background: #FFFFFF; border: 1px solid #CBD5E1; color: #1E293B; padding: .7rem .9rem; border-radius: 10px; font-family: 'Sarabun', sans-serif; font-size: 1rem;
}
.reg-form input:focus, .reg-form select:focus { outline: 2px solid var(--teal); border-color: transparent; }
.check { display: flex; gap: .55rem; align-items: flex-start; font-size: .88rem; line-height: 1.5; cursor: pointer; }
.check input { margin-top: .3rem; accent-color: var(--teal); }
.admin-box { background: rgba(217,119,6,0.07); border: 1px dashed rgba(217,119,6,0.5); border-radius: 12px; padding: .9rem; }
.notice { padding: .8rem 1rem; border-radius: 12px; margin-bottom: 1rem; font-size: .92rem; }
.notice.ok { background: rgba(21,128,61,0.15); border: 1px solid rgba(21,128,61,0.5); }
.notice.err { background: rgba(219,39,119,0.15); border: 1px solid rgba(219,39,119,0.5); }
.notice.warn { background: rgba(217,119,6,0.12); border: 1px solid rgba(217,119,6,0.5); }

@media (max-width: 900px) { .term-hero { grid-template-columns: 1fr; } .type-row { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
  body { padding: 1rem; }
  .title { font-size: 1.5rem; }
  .stat-value { font-size: 1.5rem; }
  .chart-container { height: 260px; }
  .flow-arrow { display: none; }
  .flow-step { min-width: 140px; }
  .grid-2 { grid-template-columns: 1fr; }
  .diff-reason-grid { grid-template-columns: 1fr; }
  .reg-form { grid-template-columns: 1fr; }
}
@media print {
  body { background: #fff; color: #000; }
  .btn, .filter-btn, .status-bar button { display: none !important; }
}

/* ===== แบ่ง 2 ส่วน ===== */
.part-nav { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; margin: -1rem 0 2rem; }
.part-nav a { display: flex; align-items: center; gap: .6rem; background: #fff; border: 1px solid #CBD5E1; border-radius: 999px;
  padding: .55rem 1.2rem .55rem .55rem; color: #0B3B6F; text-decoration: none; font-family: 'Kanit', sans-serif; font-size: 1rem; }
.part-nav a:hover { border-color: #0B5CAD; background: #EFF6FF; }
.part-nav span { width: 30px; height: 30px; border-radius: 50%; background: #0B5CAD; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.part-nav a:nth-child(2) span { background: #0F766E; }
.part { margin-bottom: 2.4rem; scroll-margin-top: 1rem; }
.part-head { display: flex; gap: 1rem; align-items: center; padding: 1.1rem 1.4rem; border-radius: 16px; margin-bottom: 1.4rem; color: #fff; }
.part-head.p1 { background: linear-gradient(135deg, #0B3B6F, #0B5CAD); }
.part-head.p2 { background: linear-gradient(135deg, #115E59, #0F766E); }
.part-head .num { flex: none; width: 52px; height: 52px; border-radius: 14px; background: rgba(255,255,255,.18); display: flex; align-items: center; justify-content: center; font: 700 1.7rem 'Kanit', sans-serif; }
.part-head h2 { font: 600 1.45rem 'Kanit', sans-serif; margin: 0; }
.part-head p { margin: .2rem 0 0; font-size: .95rem; opacity: .92; }
table.money td.loss { color: #B91C1C; font-weight: 600; }
table.money th { white-space: normal; min-width: 90px; font-size: .82rem; } table.money { font-size: .85rem; }

/* รายละเอียดขั้นตอน */
.service-flow .flow-step { max-width: 210px; }
.flow-detail { margin-top: 1.2rem; border: 1px solid #E2E8F0; border-radius: 14px; background: #F8FAFC; }
.flow-detail summary { cursor: pointer; padding: .9rem 1.2rem; font-family: 'Kanit', sans-serif; font-weight: 600; color: #0B3B6F; list-style: none; }
.flow-detail summary::before { content: '▸ '; }
.flow-detail[open] summary::before { content: '▾ '; }
.flow-detail[open] summary { border-bottom: 1px solid #E2E8F0; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: .9rem; padding: 1rem 1.2rem; }
.dstep { display: flex; gap: .8rem; background: #fff; border: 1px solid #E2E8F0; border-radius: 12px; padding: .9rem 1rem; font-size: .92rem; line-height: 1.6; }
.dstep .dn { flex: none; width: 30px; height: 30px; border-radius: 50%; background: #0F766E; color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.dstep p { margin: .35rem 0 0; color: #475569; }
.dstep .dt { display: inline-block; font-size: .8rem; background: #FEF3C7; color: #92400E; border-radius: 6px; padding: 0 .45rem; margin-left: .2rem; white-space: nowrap; }
.dstep .warn { color: #B91C1C; }
.flow-detail .legend-inline { padding: 0 1.2rem 1rem; }
