/* ระบบฐานข้อมูลคณะสงฆ์จังหวัดสุโขทัย — สไตล์หลัก (ไม่มีขั้นตอน build) */
@font-face { font-family: "Sarabun"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/sarabun-thai-400-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Sarabun"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/sarabun-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Sarabun"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/sarabun-thai-600-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Sarabun"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/sarabun-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Sarabun"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/sarabun-thai-700-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Sarabun"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/sarabun-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }

:root {
  --bg: #f7f3ec;
  --surface: #ffffff;
  --surface-2: #fbf8f3;
  --text: #221c15;
  --muted: #6d6358;
  --border: #e3d9ca;
  --border-strong: #cbbda8;
  --primary: #8a4b08;
  --primary-hover: #723d05;
  --primary-ink: #ffffff;
  --primary-soft: #f5e8d3;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --success: #1c7a3a;
  --success-soft: #e5f4ea;
  --warn: #8f5f00;
  --warn-soft: #fff3d4;
  --info: #1f5ea8;
  --info-soft: #e8f0fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 2px 8px rgba(60, 40, 10, .05);
  --focus: 0 0 0 3px rgba(138, 75, 8, .28);
  --sidebar-w: 264px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Tahoma", system-ui, sans-serif;
  font-size: 17px; line-height: 1.6;
}
a { color: var(--primary); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.12rem; }
p { margin: 0 0 .8em; }
small, .small { font-size: .88rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; } .text-center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.mt-0{margin-top:0}.mt-1{margin-top:.5rem}.mt-2{margin-top:1rem}.mt-3{margin-top:1.5rem}.mb-0{margin-bottom:0}.mb-1{margin-bottom:.5rem}.mb-2{margin-bottom:1rem}
.stack > * + * { margin-top: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

/* ---------- ส่วนหัวสาธารณะ ---------- */
.site-header { background: var(--primary); color: var(--primary-ink); }
.site-header .inner { max-width: 1100px; margin: 0 auto; padding: .8rem 16px; display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.site-header a { color: #fff; text-decoration: none; }
.brand { display: flex; align-items: center; gap: .65rem; font-weight: 700; font-size: 1.12rem; }
.brand-mark { width: 38px; height: 38px; border-radius: 50%; background: #f3c77b; color: #5a2f00; display: grid; place-items: center; font-weight: 700; flex: none; }
.brand small { display: block; font-weight: 400; opacity: .85; font-size: .82rem; }
.site-main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .88rem; }
.site-footer .inner { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 2rem; }

/* ---------- breadcrumb ---------- */
.breadcrumb { display: flex; flex-wrap: wrap; gap: .25rem .4rem; padding: 0; margin: 0 0 1rem; list-style: none; font-size: .95rem; }
.breadcrumb li + li::before { content: "›"; color: var(--muted); margin-right: .4rem; }
.breadcrumb a { text-decoration: none; }

/* ---------- การ์ด ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-header h2, .card-header h3 { margin: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.area-card { display: block; text-decoration: none; color: inherit; position: relative; transition: border-color .15s, transform .15s; }
.area-card:hover { border-color: var(--primary); transform: translateY(-1px); color: inherit; }
.area-card .no { position: absolute; top: .9rem; right: 1rem; color: var(--muted); font-size: .85rem; }
.area-card h2 { font-size: 1.25rem; margin: 0 0 .6rem; color: var(--primary); }
.area-card .counts { display: flex; gap: 1.25rem; }
.area-card .counts b { display: block; font-size: 1.5rem; line-height: 1.1; }
.area-card .go { margin-top: .8rem; display: inline-flex; gap: .3rem; font-weight: 600; color: var(--primary); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .label { color: var(--muted); font-size: .9rem; }
.stat .value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.stat .hint { color: var(--muted); font-size: .82rem; }

/* ---------- ปุ่ม ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem 1rem; min-height: 42px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.small { min-height: 34px; padding: .25rem .65rem; font-size: .9rem; }
.btn[disabled], .btn.disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-group { display: flex; flex-wrap: wrap; gap: .5rem; }
form.inline { display: inline; }

/* ---------- แบบฟอร์ม ---------- */
label { font-weight: 600; display: block; margin-bottom: .25rem; }
.field { margin-bottom: 1rem; }
.field .help { color: var(--muted); font-size: .86rem; margin-top: .2rem; }
.field .error, .error-text { color: var(--danger); font-size: .9rem; margin-top: .2rem; }
.field-row { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input[type=date], input[type=file], select, textarea {
  width: 100%; font: inherit; color: inherit; background: #fff; border: 1px solid var(--border-strong); border-radius: 8px; padding: .5rem .7rem; min-height: 42px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--danger); }
.check { display: flex; align-items: flex-start; gap: .5rem; font-weight: 400; }
.check input { margin-top: .35rem; width: 18px; height: 18px; }
.date-parts { display: grid; grid-template-columns: 1.2fr 1fr .8fr; gap: .4rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .3rem; }
.required::after { content: " *"; color: var(--danger); }

/* ---------- ตาราง ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: .96rem; }
.table th, .table td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table thead th { background: var(--surface-2); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
.table tbody tr:hover { background: #fffaf2; }
.table tr:last-child td { border-bottom: none; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table.compact th, .table.compact td { padding: .35rem .5rem; font-size: .9rem; }
.table.report th, .table.report td { border: 1px solid var(--border); }

/* ---------- ป้าย/แจ้งเตือน ---------- */
.badge { display: inline-block; padding: .05rem .55rem; border-radius: 999px; font-size: .82rem; font-weight: 600; background: #eee8de; color: #4c4339; white-space: nowrap; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.alert { border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid; }
.alert.success { background: var(--success-soft); border-color: #b9dfc5; color: #14532d; }
.alert.danger { background: var(--danger-soft); border-color: #f3c1bd; color: #7a1a12; }
.alert.warn { background: var(--warn-soft); border-color: #f0d68f; color: #5f4100; }
.alert.info { background: var(--info-soft); border-color: #bcd3f0; color: #173f70; }
.alert ul { margin: .3rem 0 0 1.2rem; padding: 0; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }

/* ---------- รายการคีย์-ค่า ---------- */
dl.kv { display: grid; grid-template-columns: minmax(130px, 32%) 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* ---------- แท็บ/เมนู ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 600; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 160px; flex: 1 1 160px; }
.pagination { display: flex; flex-wrap: wrap; gap: .3rem; list-style: none; padding: 0; margin: 1rem 0; }
.pagination a, .pagination span { display: inline-block; min-width: 38px; text-align: center; padding: .3rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; text-decoration: none; }
.pagination .active span { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled span { opacity: .5; }

/* ---------- ความคืบหน้า ---------- */
.progress { height: 12px; background: #ece4d7; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); width: 0; transition: width .4s; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #e7d7bf; border-top-color: var(--primary); display: inline-block; animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- autocomplete ---------- */
.ac-wrap { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; margin-top: 2px; }
.ac-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: .45rem .7rem; font: inherit; cursor: pointer; }
.ac-list button:hover, .ac-list button.active { background: var(--primary-soft); }
.ac-list .ac-empty { padding: .45rem .7rem; color: var(--muted); }

/* ---------- เทียบเคียงข้าง ---------- */
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.diff-old { background: var(--danger-soft); text-decoration: line-through; padding: 0 .2rem; border-radius: 4px; }
.diff-new { background: var(--success-soft); padding: 0 .2rem; border-radius: 4px; }
.raw-cells { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .5rem; white-space: pre-wrap; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 .8rem .6rem; }
.timeline li::before { content: ""; position: absolute; left: -1.38rem; top: .5rem; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }

/* ---------- หลังบ้าน ---------- */
.admin { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: #2a2017; color: #efe6d8; padding: 1rem .75rem 2rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { color: #fff; margin: 0 .3rem 1rem; }
.sidebar nav h3 { font-size: .78rem; text-transform: none; letter-spacing: .02em; color: #b9a98f; margin: 1rem .5rem .3rem; font-weight: 600; }
.sidebar nav a { display: flex; gap: .55rem; align-items: center; padding: .45rem .6rem; color: #efe6d8; text-decoration: none; border-radius: 8px; font-size: .97rem; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar nav a .count { margin-left: auto; background: #f3c77b; color: #4a2700; border-radius: 999px; font-size: .75rem; padding: 0 .45rem; font-weight: 700; }
.admin-main { min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: .6rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; position: sticky; top: 0; z-index: 20; }
.topbar .who { font-size: .93rem; color: var(--muted); }
.topbar .who b { color: var(--text); }
.content { padding: 1.25rem; max-width: 1280px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-header h1 { margin: 0; }
.page-header .sub { color: var(--muted); margin-top: .2rem; }
.nav-toggle { display: none; }

@media (max-width: 960px) {
  .admin { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; width: min(86vw, 300px); transform: translateX(-102%); transition: transform .2s; height: auto; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .nav-toggle { display: inline-flex; }
  .content { padding: 1rem 16px; }
  .compare { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dt { margin-top: .4rem; }
}
@media (max-width: 560px) {
  body { font-size: 16px; }
  h1 { font-size: 1.35rem; }
  .btn { min-height: 44px; }
  .area-card .counts b { font-size: 1.3rem; }
}

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 16px; }
.auth-card { width: min(440px, 100%); }

/* ---------- พิมพ์ ---------- */
@media print {
  .sidebar, .topbar, .no-print, .btn, .filters, .pagination { display: none !important; }
  .admin { display: block; }
  body { background: #fff; font-size: 13pt; }
  .card { box-shadow: none; border: none; padding: 0; }
  .table-wrap { border: none; overflow: visible; }
  .table thead { display: table-header-group; }
}

/* ---------- รายงาน ---------- */
.report-doc .report-titles { text-align: center; margin-bottom: .75rem; }
.report-doc .report-titles .t { font-weight: 700; font-size: 1.05rem; }
.report-doc .report-titles .m { color: var(--muted); font-size: .9rem; }
.report-scroll { max-height: 75vh; }
.table.report { font-size: .9rem; }
.table.report th { text-align: center; vertical-align: middle; white-space: normal; }
.table.report td { padding: .3rem .45rem; }
.table.report td.c { text-align: center; }
.table.report.plain td { border-left: none; border-right: none; }
.table.report tr.sec td { background: #e8eef4; font-weight: 700; }
.table.report tr.sec-2 td { background: #f3f6f9; }
.table.report tr.sec-3 td { background: #fbfcfd; font-weight: 600; }
.table.report tr.hdr th { position: static; background: var(--surface-2); }
.table.report tr.bold td { font-weight: 700; }
.table.report tr.muted td { color: var(--muted); font-style: italic; }
.table.report tr.note td { font-style: italic; }
.table.report tr.tot td { font-weight: 700; background: var(--surface-2); }
.report-sum { margin: .6rem 0 .2rem; }
.report-notes { margin: .2rem 0 0 1.2rem; padding: 0; color: var(--muted); font-size: .88rem; }
.report-list .code { font-weight: 700; color: var(--primary); min-width: 2.2rem; display: inline-block; }
.report-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.coverage td, .coverage th { font-size: .85rem; }
.filters .field.wide { min-width: 270px; flex: 2 1 270px; }
.card .filters.card { box-shadow: none; }
@media print {
  .report-scroll { max-height: none; overflow: visible; }
  .table.report thead th { position: static; }
}
