/* ระบบออมเงินนักเรียน — mobile-first */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600;700&display=swap');

:root {
  --navy: #1e3a6e;
  --navy-dark: #16294f;
  --gold: #e8a020;
  --gold-light: #fdf3e0;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #22304a;
  --muted: #6b7688;
  --line: #e3e6ec;
  --green: #1e8a4c;
  --green-bg: #e6f5ec;
  --red: #c23434;
  --red-bg: #fbeaea;
  --amber: #a06a00;
  --amber-bg: #fff4d9;
  --blue-bg: #e8f0fd;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(30, 58, 110, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Sarabun', 'Leelawadee UI', 'Segoe UI', Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  padding-bottom: 76px; /* เผื่อ bottom nav */
}
@media (min-width: 900px) { body { padding-bottom: 0; } }

h1 { font-size: 1.35rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.12rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
a { color: var(--navy); }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mb0 { margin-bottom: 0; }

/* ---------- top bar ---------- */
.topbar {
  background: linear-gradient(135deg, var(--navy-dark), var(--navy));
  color: #fff;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .9rem;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar img.logo { height: 40px; width: auto; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title .t1 { font-weight: 700; font-size: .98rem; line-height: 1.25; }
.topbar .title .t2 { font-size: .74rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar a { color: #fff; text-decoration: none; }
.topbar .user { font-size: .8rem; text-align: right; line-height: 1.3; }
.topbar .user .logout { color: var(--gold); font-weight: 600; }

/* ---------- desktop nav ---------- */
.mainnav {
  display: none;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0 .9rem;
  position: sticky;
  top: 56px;
  z-index: 49;
}
.mainnav a {
  display: inline-block;
  padding: .7rem .9rem;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 3px solid transparent;
}
.mainnav a.active, .mainnav a:hover { color: var(--navy); border-bottom-color: var(--gold); }
@media (min-width: 900px) { .mainnav { display: block; } }

/* ---------- bottom nav (มือถือ) ---------- */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 600;
  padding: .45rem 0 .5rem;
}
.bottomnav a .ico { display: block; font-size: 1.35rem; line-height: 1.2; }
.bottomnav a.active { color: var(--navy); }
@media (min-width: 900px) { .bottomnav { display: none; } }

/* ---------- layout ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 1rem .9rem 2rem; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}
.card h2:first-child, .card h1:first-child { margin-top: 0; }

.grid2 { display: grid; gap: 1rem; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* stat cards */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin-bottom: 1rem; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .8rem .9rem;
}
.stat .label { font-size: .78rem; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 1.35rem; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat.gold { background: linear-gradient(135deg, #fff8ec, #fdeecb); }
.stat.gold .value { color: var(--amber); }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-block;
  border: 0;
  border-radius: 10px;
  padding: .6rem 1.1rem;
  min-height: 44px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  background: #e9ecf2;
  color: var(--text);
  line-height: 1.4;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--navy); color: #fff; }
.btn-gold { background: var(--gold); color: #3a2a00; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--navy); color: var(--navy); }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .88rem; border-radius: 8px; }
.btn-block { display: block; width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .8rem; }
.actions .btn { flex: 1 1 auto; }
@media (min-width: 760px) { .actions .btn { flex: 0 0 auto; } }

/* ---------- ฟอร์ม ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .8rem; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: .25rem;
  padding: .55rem .7rem;
  font: inherit;
  font-size: 16px; /* กัน iOS ซูม */
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(232, 160, 32, .18);
}
input[type=checkbox] { display: inline-block; width: auto; min-height: 0; margin: 0 .35rem 0 0; }
.formrow { display: grid; gap: 0 1rem; }
@media (min-width: 760px) { .formrow { grid-template-columns: 1fr 1fr; } }

/* ---------- ตาราง ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 700; background: #fafbfc; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: var(--gold-light); }
.row-click { cursor: pointer; }
.row-click:hover { background: #f7f9fc; }

/* ---------- ลิสต์กรอกเงินรายคน (มือถือ) ---------- */
.money-list { list-style: none; margin: 0; padding: 0; }
.money-list li {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--line);
}
.money-list li:last-child { border-bottom: 0; }
.money-list .no { width: 1.6rem; text-align: center; color: var(--muted); font-size: .85rem; flex-shrink: 0; }
.money-list .who { flex: 1; min-width: 0; }
.money-list .who .name { font-weight: 600; }
.money-list .who .bal { font-size: .78rem; color: var(--muted); }
.money-list input.amt {
  width: 110px;
  flex-shrink: 0;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 0;
}

/* แถบยอดรวมลอยล่าง (หน้ากรอกเงิน) */
.sumbar {
  position: fixed;
  left: 0; right: 0;
  bottom: 56px;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem .9rem calc(.6rem + env(safe-area-inset-bottom));
  z-index: 40;
  font-weight: 700;
}
.sumbar .total { font-size: 1.2rem; color: var(--gold); font-variant-numeric: tabular-nums; }
@media (min-width: 900px) { .sumbar { bottom: 0; } }
body.has-sumbar { padding-bottom: 132px; }
@media (min-width: 900px) { body.has-sumbar { padding-bottom: 70px; } }

/* ---------- ป้ายสถานะ ---------- */
.badge {
  display: inline-block;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
  padding: .12rem .6rem;
  white-space: nowrap;
}
.badge-draft { background: #eceff3; color: var(--muted); }
.badge-submitted { background: var(--amber-bg); color: var(--amber); }
.badge-confirmed { background: var(--green-bg); color: var(--green); }
.badge-pending { background: var(--amber-bg); color: var(--amber); }
.badge-paid { background: var(--green-bg); color: var(--green); }
.badge-rejected, .badge-left { background: var(--red-bg); color: var(--red); }
.badge-active { background: var(--blue-bg); color: var(--navy); }
.badge-graduated { background: var(--gold-light); color: var(--amber); }

/* ---------- alert ---------- */
.alert { border-radius: 10px; padding: .7rem .9rem; margin-bottom: .9rem; font-weight: 500; }
.alert-success { background: var(--green-bg); color: var(--green); }
.alert-danger { background: var(--red-bg); color: var(--red); }
.alert-warning { background: var(--amber-bg); color: var(--amber); }
.alert-info { background: var(--blue-bg); color: var(--navy); }

/* ---------- หน้า login / install ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, var(--navy-dark), var(--navy) 55%, #2c4d8c);
  padding: 1.2rem;
}
.auth-card {
  background: var(--card);
  border-radius: 18px;
  padding: 1.6rem 1.4rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
  text-align: center;
}
.auth-card h1 { font-size: 1.2rem; margin: .6rem 0 .1rem; }
.auth-card form { text-align: left; margin-top: 1rem; }
.auth-logo { height: 92px; width: auto; }

/* ---------- รายการเมนู (หน้า อื่นๆ) ---------- */
.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list li { border-bottom: 1px solid var(--line); }
.menu-list li:last-child { border-bottom: 0; }
.menu-list a {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .85rem .3rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
}
.menu-list .ico { font-size: 1.3rem; width: 2rem; text-align: center; }
.menu-list .arr { margin-left: auto; color: var(--muted); }

/* ---------- หน้าพิมพ์เอกสาร ---------- */
.print-header { display: none; }
@media print {
  body { background: #fff; padding: 0; font-size: 13px; color: #000; }
  .topbar, .mainnav, .bottomnav, .sumbar, .no-print, .alert { display: none !important; }
  .container { max-width: none; padding: 0; }
  .card { box-shadow: none; padding: 0; margin: 0 0 1rem; border-radius: 0; }
  .print-header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
  .print-header img { height: 64px; }
  .print-header .ph-name { font-size: 16px; font-weight: 700; }
  .print-header .ph-doc { font-size: 14px; }
  table { font-size: 12.5px; }
  th, td { border: 1px solid #999; padding: 3px 6px; }
  th { background: #eee !important; color: #000; }
  a { color: #000; text-decoration: none; }
  .sign-row { display: flex; justify-content: space-around; margin-top: 40px; page-break-inside: avoid; }
  .sign-box { text-align: center; width: 40%; }
  .sign-row .sign-box:first-child:nth-last-child(3),
  .sign-row .sign-box:first-child:nth-last-child(3) ~ .sign-box { width: 30%; }
  .sign-box .line { border-bottom: 1px dotted #000; height: 40px; margin-bottom: 6px; }
}
.sign-row { display: none; }
@media print { .sign-row { display: flex; } }
