/* ============================================================
   ระบบทะเบียนคุมเงินสถานศึกษา — ชุดรูปแบบหน้าจอ
   แนวทาง: มินิมอล เส้นบาง พื้นที่หายใจกว้าง เน้นตัวเลขอ่านง่าย
   ============================================================ */

@font-face {
  font-family: 'TH Sarabun New';
  src: url('../fonts/THSarabunNew.ttf') format('truetype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'TH Sarabun New';
  src: url('../fonts/THSarabunNew-Bold.ttf') format('truetype');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'TH Sarabun New';
  src: url('../fonts/THSarabunNew-Italic.ttf') format('truetype');
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'TH Sarabun New';
  src: url('../fonts/THSarabunNew-BoldItalic.ttf') format('truetype');
  font-weight: 700; font-style: italic; font-display: swap;
}

:root {
  /* กระดาษอุ่น ๆ ตัดกับหมึกเข้ม */
  --paper:      #faf9f7;
  --surface:    #ffffff;
  --surface-2:  #f4f2ef;
  --ink:        #1a1917;
  --ink-2:      #55514c;
  --ink-3:      #8a847c;
  --line:       #e3dfd9;
  --line-2:     #cdc7bf;

  --accent:     #0f6f66;
  --accent-ink: #0a544d;
  --accent-bg:  #e6f2f0;

  --pos:        #17694f;
  --neg:        #a2371f;
  --warn-bg:    #fdf6e6;
  --warn-ink:   #7a5a12;

  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;

  --shadow: 0 1px 2px rgba(26,25,23,.05), 0 4px 14px rgba(26,25,23,.04);

  --ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Sukhumvit Set',
        'Noto Sans Thai', 'Leelawadee UI', 'Helvetica Neue', sans-serif;
  --num: 'SF Mono', 'JetBrains Mono', 'Menlo', 'Consolas', monospace;

  --sidebar-w: 244px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; line-height: 1.3; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* ---------------- โครงหน้า ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: .625rem;
  padding: 1.15rem 1.15rem 1rem;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: .95rem; letter-spacing: -.02em;
}
.brand-text { min-width: 0; }
.brand-name { font-weight: 650; font-size: .95rem; letter-spacing: -.01em; }
.brand-sub  { font-size: .75rem; color: var(--ink-3); }

.nav { padding: .75rem .625rem; overflow-y: auto; flex: 1; }
.nav-label {
  font-size: .688rem; font-weight: 600; letter-spacing: .06em;
  color: var(--ink-3); text-transform: uppercase;
  padding: .75rem .625rem .375rem;
}
.nav a {
  display: flex; align-items: center; gap: .625rem;
  padding: .5rem .625rem;
  border-radius: var(--r-sm);
  color: var(--ink-2); font-size: .906rem;
  text-decoration: none;
  transition: background .12s, color .12s;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-bg); color: var(--accent-ink); font-weight: 600; }
.nav a svg { width: 17px; height: 17px; flex: none; opacity: .78; }
.nav a.active svg { opacity: 1; }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: .75rem .875rem;
  font-size: .8rem; color: var(--ink-3);
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.75rem;
  background: rgba(250,249,247,.88);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }

.content { padding: 1.75rem; max-width: 1400px; width: 100%; }

.page-head {
  display: flex; align-items: flex-start; gap: 1rem;
  margin-bottom: 1.5rem; flex-wrap: wrap;
}
.page-head .grow { flex: 1; min-width: 260px; }
.page-head p { margin: .25rem 0 0; color: var(--ink-3); font-size: .906rem; }

/* ---------------- ตัวเลือกโรงเรียน / ปีงบ ---------------- */
.switcher { display: flex; align-items: center; gap: .5rem; }
.switcher select {
  font-family: inherit; font-size: .875rem;
  padding: .4rem 1.75rem .4rem .625rem;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface) url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%238a847c' stroke-width='1.6'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E") no-repeat right .45rem center/13px;
  appearance: none; color: var(--ink); cursor: pointer; max-width: 280px;
  text-overflow: ellipsis;
}
.switcher select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------- การ์ด ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.card + .card { margin-top: 1.25rem; }
.card-head {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 1.125rem;
  border-bottom: 1px solid var(--line);
}
.card-head .spacer { flex: 1; }
.card-head h2, .card-head h3 { font-size: .975rem; }
.card-body { padding: 1.125rem; }
.card-body.tight { padding: 0; }

/* ---------------- สถิติ ---------------- */
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 1.05rem 1.125rem;
}
.stat-label { font-size: .8rem; color: var(--ink-3); font-weight: 500; }
.stat-value {
  font-size: 1.55rem; font-weight: 650; letter-spacing: -.02em;
  margin-top: .2rem; font-variant-numeric: tabular-nums;
}
.stat-value.sm { font-size: 1.2rem; }
.stat-foot { font-size: .8rem; color: var(--ink-3); margin-top: .15rem; }
.stat.accent { background: var(--accent-bg); border-color: #cfe4e1; }
.stat.accent .stat-value { color: var(--accent-ink); }

/* ---------------- ตาราง ---------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .906rem; }
table.data th {
  text-align: left; font-weight: 600; font-size: .8rem;
  color: var(--ink-3); letter-spacing: .01em;
  padding: .625rem .875rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}
table.data td {
  padding: .625rem .875rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fbfaf8; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .nowrap { white-space: nowrap; }
table.data tfoot td {
  padding: .625rem .875rem; font-weight: 650;
  border-top: 2px solid var(--line-2); background: var(--surface-2);
}
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--ink-3); }
.empty {
  padding: 3rem 1.5rem; text-align: center; color: var(--ink-3);
}
.empty svg { width: 34px; height: 34px; opacity: .35; margin-bottom: .5rem; }

/* ---------------- ปุ่ม ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  font: inherit; font-size: .875rem; font-weight: 550;
  padding: .48rem .875rem;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none;
  transition: background .12s, border-color .12s, box-shadow .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(.5px); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-danger { color: var(--neg); border-color: #e6cfc8; }
.btn-danger:hover { background: #fbeeea; }
.btn-sm { padding: .3rem .55rem; font-size: .812rem; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------------- ฟอร์ม ---------------- */
.form-grid { display: grid; gap: 1rem 1.125rem; grid-template-columns: repeat(12, 1fr); }
.field { display: flex; flex-direction: column; gap: .3rem; grid-column: span 12; }
.field.c2  { grid-column: span 2; }
.field.c3  { grid-column: span 3; }
.field.c4  { grid-column: span 4; }
.field.c6  { grid-column: span 6; }
.field.c8  { grid-column: span 8; }
.field label { font-size: .812rem; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: .75rem; color: var(--ink-3); }
.field input, .field select, .field textarea {
  font: inherit; font-size: .906rem;
  padding: .5rem .625rem;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.field input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
.field.req label::after { content: ' *'; color: var(--neg); }
.form-actions {
  display: flex; gap: .625rem; align-items: center;
  margin-top: 1.25rem; padding-top: 1.125rem; border-top: 1px solid var(--line);
}

/* ---------------- ป้าย ---------------- */
.badge {
  display: inline-block; font-size: .75rem; font-weight: 600;
  padding: .12rem .45rem; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge.accent { background: var(--accent-bg); color: var(--accent-ink); border-color: #cfe4e1; }
.badge.warn   { background: var(--warn-bg);   color: var(--warn-ink);   border-color: #eadfc2; }

/* ---------------- แจ้งเตือน ---------------- */
.flash-stack { position: fixed; top: 1rem; right: 1rem; z-index: 90; display: grid; gap: .5rem; }
.flash {
  display: flex; align-items: center; gap: .625rem;
  padding: .7rem 1rem; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: .875rem; max-width: 380px;
  animation: slide-in .22s ease-out;
}
.flash.success { border-left: 3px solid var(--pos); }
.flash.error   { border-left: 3px solid var(--neg); }
.flash.info    { border-left: 3px solid var(--accent); }
@keyframes slide-in { from { opacity: 0; transform: translateX(12px); } }

.alert {
  padding: .75rem 1rem; border-radius: var(--r);
  background: var(--warn-bg); border: 1px solid #eadfc2; color: var(--warn-ink);
  font-size: .875rem;
}
.alert.info { background: var(--accent-bg); border-color: #cfe4e1; color: var(--accent-ink); }

/* ---------------- แถบเลือกเดือน ---------------- */
.month-bar {
  display: flex; gap: .25rem; overflow-x: auto;
  padding: .375rem; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r);
}
.month-bar a {
  padding: .35rem .7rem; border-radius: var(--r-sm);
  font-size: .844rem; color: var(--ink-2); white-space: nowrap; text-decoration: none;
}
.month-bar a:hover { background: var(--surface); text-decoration: none; }
.month-bar a.active { background: var(--surface); color: var(--accent-ink); font-weight: 650; box-shadow: var(--shadow); }

/* ---------------- รายการบัญชีเงิน ---------------- */
.fund-grid { display: grid; gap: .875rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.fund-card {
  display: block; padding: 1rem 1.125rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); color: inherit; text-decoration: none;
  transition: border-color .14s, box-shadow .14s, transform .14s;
}
.fund-card:hover {
  border-color: var(--line-2); box-shadow: var(--shadow);
  text-decoration: none; transform: translateY(-1px);
}
.fund-card .name { font-weight: 600; font-size: .938rem; line-height: 1.4; }
.fund-card .bal {
  font-size: 1.28rem; font-weight: 650; margin-top: .5rem;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.fund-card .meta { font-size: .781rem; color: var(--ink-3); margin-top: .1rem; }

/* ---------------- เข้าสู่ระบบ ---------------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 2rem 1.25rem;
  background:
    radial-gradient(900px 480px at 12% -8%, #eaf3f1 0%, transparent 62%),
    radial-gradient(700px 420px at 92% 108%, #f3eee7 0%, transparent 60%),
    var(--paper);
}
.login-card {
  width: 100%; max-width: 388px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 2rem 1.875rem;
  box-shadow: 0 1px 2px rgba(26,25,23,.04), 0 18px 46px rgba(26,25,23,.08);
}
.login-card .brand-mark { width: 42px; height: 42px; font-size: 1.15rem; border-radius: 12px; }
.login-title { font-size: 1.25rem; font-weight: 650; margin-top: 1rem; letter-spacing: -.02em; }
.login-sub { color: var(--ink-3); font-size: .875rem; margin: .2rem 0 1.5rem; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: .6rem; margin-top: .5rem; }
.login-foot { text-align: center; font-size: .781rem; color: var(--ink-3); margin-top: 1.5rem; }

/* ---------------- ตัวช่วย ---------------- */
.stack   { display: grid; gap: 1.25rem; }
.row     { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .75rem; } .mt-2 { margin-top: 1.5rem; }
.text-sm { font-size: .844rem; } .text-xs { font-size: .781rem; }
.hide { display: none !important; }
.sidebar-toggle { display: none; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; z-index: 60; left: 0; top: 0;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.14);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after {
    content: ''; position: fixed; inset: 0; background: rgba(26,25,23,.34); z-index: 50;
  }
  .sidebar-toggle { display: inline-flex; }
  .content { padding: 1.25rem; }
  .topbar { padding: .625rem 1.25rem; }
  .switcher select { max-width: 150px; }
}

@media print {
  .app, .sidebar, .topbar, .flash-stack, .no-print { display: none !important; }
}

/* ============================================================
   ปฏิทินไทย (พ.ศ.)
   ============================================================ */
.thdate { position: relative; display: block; }
.thdate > input[type=text] {
  font: inherit; font-size: .906rem;
  padding: .5rem 2.1rem .5rem .625rem;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); width: 100%;
}
.thdate > input[type=text]:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.thdate > input.thdate-invalid {
  border-color: var(--neg); box-shadow: 0 0 0 3px #fbeeea;
}
.thdate-btn {
  position: absolute; right: .3rem; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center;
  width: 26px; height: 26px; padding: 0;
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink-3); cursor: pointer;
}
.thdate-btn:hover { background: var(--surface-2); color: var(--ink); }
.thdate-btn svg { width: 16px; height: 16px; }

.thdate-panel {
  position: fixed; z-index: 200;
  width: 292px; padding: .625rem;
  background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r);
  box-shadow: 0 2px 4px rgba(26,25,23,.05), 0 12px 32px rgba(26,25,23,.14);
  animation: thdate-in .12s ease-out;
}
@keyframes thdate-in { from { opacity: 0; transform: translateY(-3px); } }

.thdate-head { display: flex; align-items: center; gap: .3rem; margin-bottom: .5rem; }
.thdate-nav {
  display: grid; place-items: center;
  width: 27px; height: 27px; flex: none; padding: 0;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.thdate-nav:hover { background: var(--surface-2); color: var(--ink); }
.thdate-nav svg { width: 15px; height: 15px; }
.thdate-head select {
  font: inherit; font-size: .844rem; font-weight: 600;
  min-width: 0;
  padding: .3rem 1.35rem .3rem .45rem;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%238a847c' stroke-width='1.6'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E") no-repeat right .25rem center/12px;
  appearance: none; color: var(--ink); cursor: pointer; text-align: center;
}
.thdate-head select:hover { background-color: var(--surface-2); }
.thdate-head select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.thdate-head .thdate-m { flex: 1.5; }
.thdate-head .thdate-y { flex: 1; }

.thdate-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.thdate-dow {
  text-align: center; font-size: .719rem; font-weight: 600;
  color: var(--ink-3); padding: .25rem 0 .35rem;
}
.thdate-day {
  font: inherit; font-size: .812rem;
  aspect-ratio: 1; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--ink);
  cursor: pointer; font-variant-numeric: tabular-nums;
}
.thdate-day:hover:not(.off) { background: var(--surface-2); }
.thdate-day.today { border-color: var(--line-2); font-weight: 650; }
.thdate-day.sel {
  background: var(--accent); border-color: var(--accent);
  color: #fff; font-weight: 650;
}
.thdate-day.sel:hover { background: var(--accent-ink); }
.thdate-day.off { color: var(--line-2); cursor: default; }

.thdate-foot {
  display: flex; gap: .5rem; justify-content: space-between;
  margin-top: .5rem; padding-top: .5rem; border-top: 1px solid var(--line);
}
.thdate-link {
  font: inherit; font-size: .812rem;
  padding: .2rem .5rem; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--accent-ink); cursor: pointer; font-weight: 550;
}
.thdate-link:hover { background: var(--accent-bg); }

/* ============================================================
   กราฟ
   ============================================================ */
.chart-scroll { overflow-x: auto; overflow-y: hidden; }
.chart { display: block; width: 100%; min-width: 620px; height: auto; }
.chart text { font-family: var(--ui); }
.chart .bar { transition: opacity .12s; }
.chart .bar:hover, .chart .dot:hover { opacity: .78; cursor: default; }

.chart-legend { display: flex; gap: .875rem; align-items: center; flex-wrap: wrap; }
.chart-key {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .812rem; color: var(--ink-2);
}
.chart-key i {
  width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none;
}

.chart-tip {
  position: fixed; z-index: 210; pointer-events: none;
  background: var(--ink); color: #fff;
  padding: .4rem .6rem; border-radius: var(--r-sm);
  font-size: .781rem; line-height: 1.45;
  box-shadow: 0 4px 14px rgba(26,25,23,.22);
  max-width: 260px;
}
.chart-tip b { font-weight: 650; }
.chart-tip .v { font-variant-numeric: tabular-nums; }

@media print {
  .chart-scroll { overflow: visible; }
  .chart { min-width: 0; }
}

/* ---------------- ตัวเลือกเดือน (dropdown) ---------------- */
.month-picker {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .625rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r);
}
.month-picker .btn { padding: .35rem .45rem; }
.month-picker .btn svg { width: 15px; height: 15px; }
.month-picker .btn.is-off {
  opacity: .32; pointer-events: none;
}
.month-select { display: flex; align-items: center; gap: .5rem; flex: 1; min-width: 0; }
.month-select label { flex: none; }
.month-select select {
  font: inherit; font-size: .906rem; font-weight: 600;
  flex: 1; min-width: 0;
  padding: .4rem 2rem .4rem .625rem;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface) url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%238a847c' stroke-width='1.6'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E") no-repeat right .5rem center/13px;
  appearance: none; color: var(--ink); cursor: pointer;
  text-overflow: ellipsis;
}
.month-select select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg);
}

/* ---------------- บันทึกการใช้งาน ---------------- */
.audit-table td { vertical-align: top; }
.audit-diff { margin-top: .35rem; }
.audit-diff summary {
  cursor: pointer; font-size: .781rem; color: var(--accent-ink);
  list-style: none; display: inline-block;
  padding: .1rem .4rem; border-radius: 5px; background: var(--accent-bg);
}
.audit-diff summary::-webkit-details-marker { display: none; }
.audit-diff summary:hover { background: #d9ebe8; }
table.diff {
  margin-top: .4rem; border-collapse: collapse; font-size: .781rem; width: 100%;
}
table.diff th {
  text-align: left; font-weight: 600; color: var(--ink-3);
  padding: .2rem .5rem .2rem 0; white-space: nowrap; vertical-align: top;
  background: none; border: 0; font-size: .75rem;
}
table.diff td { padding: .2rem .35rem; border: 0; vertical-align: top; }
table.diff .old { color: var(--neg); text-decoration: line-through; opacity: .8; }
table.diff .new { color: var(--pos); font-weight: 550; }
table.diff .arrow { color: var(--ink-3); padding: 0 .15rem; }

/* ============================================================
   หัวทะเบียน — หน้าภาพรวม
   วางอย่างหัวกระดาษเอกสารราชการ : ตราสัญลักษณ์ ชื่อหน่วยงาน
   ยอดคงเหลือเป็นตัวเลข แล้วเขียนจำนวนเงินเป็นตัวอักษรกำกับ
   สีทองและสีชาดหยิบมาจากตราสัญลักษณ์ สพฐ.
   ============================================================ */
:root {
  --seal:      #b02a1e;
  --gold:      #c8912a;
  --gold-soft: #e8c37a;
  --hero-1:    #0e6259;
  --hero-2:    #093f3a;
  --hero-ink:  #f4f1ea;
}

.ledger-head {
  position: relative; overflow: hidden;
  border-radius: var(--r-lg);
  background: linear-gradient(155deg, var(--hero-1) 0%, var(--hero-2) 78%);
  color: var(--hero-ink);
  padding: 1.6rem 1.75rem 1.35rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 2px rgba(9,63,58,.18), 0 10px 30px rgba(9,63,58,.13);
}
.ledger-head::before {
  content: ''; position: absolute; inset: 0 0 auto; height: 3px;
  background: linear-gradient(90deg, var(--gold), #f0d79a 45%, var(--gold));
}

.ledger-grid {
  display: grid; gap: 1.15rem 1.6rem;
  grid-template-columns: auto 1fr auto; align-items: start;
}

/* ตราสัญลักษณ์บนแผ่นกลมอย่างตราประทับ */
.seal {
  width: 96px; height: 96px; flex: none;
  display: grid; place-items: center;
  background: #fffdf8; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(232,195,122,.5), 0 0 0 7px rgba(255,253,248,.08);
}
.seal img { width: 78px; height: 78px; object-fit: contain; display: block; }

.eyebrow {
  font-size: .75rem; font-weight: 600; letter-spacing: .13em;
  color: var(--gold-soft);
}
.ledger-school {
  font-size: 1.5rem; font-weight: 700; letter-spacing: -.015em;
  line-height: 1.25; margin: .2rem 0 .35rem;
}
.ledger-meta { font-size: .875rem; color: rgba(244,241,234,.7); }
/* คั่นด้วยจุดท้ายข้อความ เพื่อไม่ให้จุดตกไปขึ้นต้นบรรทัดใหม่เวลาข้อความพับ */
.ledger-meta span { white-space: nowrap; }
.ledger-meta span:not(:last-child)::after { content: ' ·'; margin-right: .35rem; opacity: .55; }

.ledger-amount { text-align: right; min-width: 250px; }
.ledger-amount .label { font-size: .8rem; color: rgba(244,241,234,.7); }
.ledger-figure {
  font-variant-numeric: tabular-nums; font-weight: 700;
  font-size: 2.85rem; line-height: 1.05; letter-spacing: -.03em; margin-top: .1rem;
}
.ledger-figure .satang { font-size: 1.45rem; font-weight: 600; opacity: .72; }
.ledger-figure .unit   { font-size: .95rem; font-weight: 500; opacity: .7; margin-left: .45rem; }
.ledger-rule {
  height: 1px; margin: .55rem 0 .4rem; opacity: .75;
  background: linear-gradient(90deg, transparent, var(--gold-soft));
}
.ledger-words { font-size: .812rem; color: rgba(244,241,234,.62); }

/* แถบสัดส่วนเงินแยกช่อง */
.bucket { margin-top: 1.3rem; padding-top: 1.1rem; border-top: 1px solid rgba(244,241,234,.13); }
.bucket-bar {
  display: flex; height: 10px; border-radius: 999px; overflow: hidden;
  background: rgba(244,241,234,.11);
}
.bucket-bar i { display: block; height: 100%; }
.bucket-legend { display: flex; flex-wrap: wrap; gap: .5rem 2rem; margin-top: .8rem; }
.bucket-item { display: flex; gap: .5rem; font-size: .8rem; color: rgba(244,241,234,.7); }
.bucket-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; margin-top: .32rem; }
.bucket-item b {
  display: block; margin-top: .05rem; color: #fff;
  font-size: 1.02rem; font-weight: 650; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}

.ledger-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.15rem; }
.btn-light {
  background: #fffdf8; border-color: transparent; color: var(--hero-2); font-weight: 600;
}
.btn-light:hover { background: #fff; }
.btn-ghost-light {
  background: transparent; color: var(--hero-ink); border-color: rgba(244,241,234,.3);
}
.btn-ghost-light:hover { background: rgba(244,241,234,.1); border-color: rgba(244,241,234,.5); }
.btn-light:focus-visible, .btn-ghost-light:focus-visible {
  outline: 2px solid var(--gold-soft); outline-offset: 2px;
}

/* แถบเตือนตามระเบียบ — ใช้สีชาดจากตราสัญลักษณ์ */
.notice-seal {
  border-left: 3px solid var(--seal);
  background: #fdf3f0; border-color: #eddbd5; color: #7a2618;
}

/* ตัวเลขสรุประหว่างปี */
.tile { position: relative; padding-left: 1.3rem; }
.tile::before {
  content: ''; position: absolute; left: 0; top: 1.05rem; bottom: 1.05rem;
  width: 3px; border-radius: 3px; background: var(--line-2);
}
.tile.in::before  { background: var(--pos); }
.tile.out::before { background: var(--neg); }
.tile.n::before   { background: var(--gold); }

@media (max-width: 1080px) {
  .ledger-grid { grid-template-columns: auto 1fr; }
  .ledger-amount {
    grid-column: 1 / -1; text-align: left; min-width: 0;
    border-top: 1px solid rgba(244,241,234,.13); padding-top: 1rem;
  }
  .ledger-rule { background: linear-gradient(90deg, var(--gold-soft), transparent); }
}
@media (max-width: 560px) {
  .ledger-head { padding: 1.25rem 1.25rem 1.15rem; }
  .seal { width: 62px; height: 62px; }
  .seal img { width: 50px; height: 50px; }
  .ledger-school { font-size: 1.18rem; }
  .ledger-figure { font-size: 2.1rem; }
  .ledger-figure .satang { font-size: 1.15rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ตราสัญลักษณ์ในแถบเมนูและหน้าเข้าสู่ระบบ */
.brand-mark.logo {
  background: #fffdf8; border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--line);
  padding: 2px;
}
.brand-mark.logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.login-card .brand-mark.logo {
  width: 62px; height: 62px; padding: 4px;
  box-shadow: inset 0 0 0 1px var(--line), 0 1px 3px rgba(26,25,23,.08);
}

/* ---------------- ไอคอนเส้นใช้ร่วมกัน ---------------- */
.ic { width: 1.05em; height: 1.05em; vertical-align: -.16em; flex: none; }
.nav-ic { width: 17px; height: 17px; flex: none; opacity: .75; }
.nav a.active .nav-ic { opacity: 1; }
.btn .ic { margin-right: .3rem; }
.card-head .ic { color: var(--ink-3); }
.card-head h2 .ic { color: var(--accent); margin-right: .35rem; }

/* ---------------- ภาพสมุดบัญชีธนาคาร ---------------- */
.photo-grid {
  display: grid; gap: .875rem;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.photo-item {
  border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden; background: var(--surface-2);
}
.photo-item .thumb {
  display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #ece9e4;
}
.photo-item .cap { padding: .5rem .625rem; font-size: .781rem; line-height: 1.45; }
.photo-item .cap b { font-variant-numeric: tabular-nums; }
.photo-item .cap .row { display: flex; align-items: center; gap: .35rem; justify-content: space-between; }

/* ---------------- ปุ่มเข้าสู่ระบบด้วย LINE ---------------- */
.or-line {
  display: flex; align-items: center; gap: .75rem;
  margin: 1rem 0 .875rem; color: var(--ink-3); font-size: .812rem;
}
.or-line::before, .or-line::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.btn-line {
  width: 100%; justify-content: center; gap: .5rem;
  background: #06c755; border-color: #06c755; color: #fff; font-weight: 600;
}
.btn-line:hover { background: #05b64c; border-color: #05b64c; color: #fff; text-decoration: none; }
.btn-line:focus-visible { outline: 2px solid #06c755; outline-offset: 2px; }
