/* ===== โทเคนสี: ธีมสว่างเป็นค่าหลัก ธีมมืดเลือกได้ (html[data-theme=dark]) ===== */
:root {
  --bg: #f7f7f5; --surface: #ffffff; --card: #f3f3f0; --fg: #1d1d1b; --muted: #6b6a66; --line: #e4e3df; --line-strong: #cfcdc7;
  --accent: #d85a30; --accent-ink: #993c1d; --accent-bg: #faece7;
  --good: #2f6f2a; --good-bg: #eaf3de; --bad: #b42525; --bad-bg: #fcebeb; --warn: #8a5300; --warn-bg: #faeeda;
  --radius: 10px; --side-w: 236px;
  font-family: 'IBM Plex Sans Thai', Inter, system-ui, sans-serif; font-size: 16.5px;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #141413; --surface: #1c1c1b; --card: #232321; --fg: #ececea; --muted: #a3a29d; --line: #2e2e2c; --line-strong: #44433f;
  --accent: #f0997b; --accent-ink: #f5c4b3; --accent-bg: #4a1b0c;
  --good: #97c459; --good-bg: #173404; --bad: #f09595; --bad-bg: #501313; --warn: #fac775; --warn-bg: #412402;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); line-height: 1.6; }
a { color: inherit; }
a.strong { font-weight: 600; }
.ic { flex: none; vertical-align: -3px; }

/* ===== โครงหน้า: เมนูด้านข้าง (คอม) · แถบล่าง + ลิ้นชักเมนู (มือถือ) ===== */
.shell { min-height: 100vh; }
body.has-side .shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
.side { display: none; }
body.has-side .side { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--line); }
.side .brand { display: block; padding: 2px 10px 14px; }
.side .school { font-size: .82rem; color: var(--muted); padding: 0 10px 12px; line-height: 1.4; }
.side a.nav { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: .95rem; }
.side a.nav:hover { background: var(--card); color: var(--fg); }
.side a.nav.on { background: var(--card); color: var(--fg); font-weight: 500; }
.side .sep { height: 1px; background: var(--line); margin: 10px 4px; }
.side .foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.side .hint { font-size: .75rem; color: var(--muted); padding: 6px 10px; }
.side button.nav { all: unset; display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: .95rem; }
.side button.nav:hover { background: var(--card); color: var(--fg); }
.brand { color: var(--fg); text-decoration: none; font-weight: 600; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
.top { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding: 12px 24px; }
.top .brand { margin-right: auto; }
.icon-btn { all: unset; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--fg); display: inline-flex; }
.only-mobile { display: none !important; }
main { max-width: 960px; margin: 0 auto; padding: 4px 24px 72px; }
.bottom { display: none; }
.side-scrim { display: none; }
@media (max-width: 760px) {
  body.has-side .shell { display: block; }
  body.has-side .side { position: fixed; z-index: 30; left: 0; top: 0; width: 82vw; max-width: 300px; transform: translateX(-105%); transition: transform .18s ease; }
  body.side-open .side { transform: none; }
  body.side-open .side-scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 25; }
  body.has-side .only-mobile { display: inline-flex !important; }
  .top { padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
  main { padding: 12px 16px 96px; }
  body.has-side .bottom { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom a, .bottom button { all: unset; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); text-decoration: none; }
  .bottom .on { color: var(--fg); }
}

/* ===== ส่วนประกอบพื้นฐาน ===== */
h1 { font-size: 1.45rem; font-weight: 600; margin: 8px 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; font-weight: 600; margin: 28px 0 10px; }
.muted { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin: 10px 0; }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--line-strong); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th { font-weight: 500; color: var(--muted); font-size: .85rem; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: .82rem; background: var(--card); color: var(--muted); }
.error { color: var(--bad); }
button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--fg); cursor: pointer; }
button:hover { background: var(--card); }
.tabs { display: none; }
.pill.good { color: var(--good); background: var(--good-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.form label { display: block; margin: 12px 0; font-size: .92rem; color: var(--muted); }
input, select { font: inherit; width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--fg); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-bg); border-color: var(--accent); }
input.num { text-align: right; }
.grid3, .funds { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 560px) { .grid3, .funds { grid-template-columns: 1fr; } }
button.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
a.button { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; background: var(--card); color: var(--fg); }
button:disabled { opacity: .5; cursor: wait; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
#items td:nth-child(2) { width: 160px; }
#items td:nth-child(3) { width: 44px; }

/* บันทึกข้อความ A4 */
.print-page .side, .print-page .top, .print-page .bottom { display: none !important; }
body.print-page.has-side .shell { display: block; }
.memo { font-family: 'Sarabun', 'IBM Plex Sans Thai', serif; font-size: 16px; color: #000; background: #fff; max-width: 210mm; margin: 0 auto; padding: 25mm 20mm 20mm 30mm; border: 1px solid var(--line); }
.memo p { margin: 6px 0; }
.memo-title { text-align: center; font-size: 26px; margin: 0 0 12px; }
.memo .row2 { display: flex; justify-content: space-between; gap: 16px; }
.memo .indent { text-indent: 2.5em; }
.memo-table { margin: 8px 0; }
.memo-table th, .memo-table td { border: 1px solid #000; padding: 4px 8px; }
.memo .signs { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 24px; margin-top: 20px; }
.memo .sign { text-align: center; }
.memo .sign p { margin: 4px 0; }
.memo-ref { margin-top: 18px !important; font-size: 12px; color: #555; }
/* กระดาษ A4 ขอบตามแบบหนังสือราชการ: บน 2.5 ซม. ล่าง 2 ซม. ซ้าย 3 ซม. ขวา 2 ซม. · เลขหน้ากลางหัวกระดาษตั้งแต่หน้า 2
   (กำหนดช่องหัว/ท้ายกระดาษเองแล้ว เบราว์เซอร์จึงไม่พิมพ์ URL และวันที่ทับ) */
@page { size: A4; margin: 25mm 20mm 20mm 30mm;
  @top-center { content: "- " counter(page) " -"; font-family: 'Sarabun', serif; font-size: 14px; color: #000; }
  @bottom-center { content: ""; } }
@page :first { @top-center { content: ""; } }
@media print {
  .memo, .book { padding: 0 !important; max-width: none; }
  body { background: #fff; }
  .noprint, .bar { display: none !important; }
  main { padding: 0; max-width: none; }
  .memo { border: 0; }
}

/* รายงานผล */
textarea { font: inherit; width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--fg); resize: vertical; line-height: 1.7; }
label { display: block; margin: 10px 0; font-size: .92rem; color: var(--muted); }
details summary { cursor: pointer; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0; }
.thumbs figure { margin: 0; text-align: center; }
.thumbs img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.thumbs .file { display: inline-block; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; max-width: 200px; overflow-wrap: anywhere; }
button.link { background: none; border: 0; padding: 2px; color: var(--bad); font-size: .85rem; }
.upload { display: inline-block; padding: 8px 14px; border: 1px dashed var(--line); border-radius: 8px; cursor: pointer; color: var(--fg); }

/* เล่มรายงาน */
.book .cover { text-align: center; padding: 60mm 0 40mm; }
.book .cover h1 { font-size: 30px; margin: 0 0 8px; }
.book .cover h2 { font-size: 22px; font-weight: 400; margin: 0 0 6px; }
.book .cover .school { font-size: 22px; margin-top: 40mm; }
.book .cover .logo { width: 110px; height: auto; margin-bottom: 18px; }
.book .page h2 { font-size: 20px; margin: 0 0 8px; }
.book .page { padding-top: 6mm; }
.book-photos { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.book-photos img { width: 100%; height: 55mm; object-fit: cover; }
@media print {
  .book .cover, .book .page { break-after: page; }
}

/* แผนงาน / รายรับ / จัดสรร */
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
label.check { display: flex; gap: 8px; align-items: baseline; color: var(--fg); }
label.check input { width: auto; }
.scroll { overflow-x: auto; }
.scroll table input, .scroll table select { min-width: 80px; }
td input[type=checkbox] { width: auto; }
tr.strongrow td { font-weight: 600; }
tr.netrow td { font-weight: 600; border-top: 2px solid var(--fg); }
.sticky { position: sticky; top: 0; background: var(--bg); padding: 6px 0; z-index: 2; }
label.check.inline { display: inline-flex; margin: 2px 10px 2px 0; font-size: .85rem; }
td.roles { min-width: 260px; }
#members input { min-width: 140px; margin-bottom: 4px; }
#who select { width: auto; margin: 0; padding: 4px 8px; font-size: .85rem; }
tr.proj-row td { border-top: 1px solid var(--muted); }
tr.act-row td { color: var(--muted); font-size: .92rem; padding-top: 4px; padding-bottom: 4px; }
tr.act-row td:first-child { padding-left: 18px; color: var(--fg); }
fieldset.align-pick { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; padding: 6px 12px; }
fieldset.align-pick legend { font-weight: 600; padding: 0 4px; }
p.align-level { margin: 10px 0 2px; }
ul.align-items { margin: 0 0 6px; }
.doc-head p { margin: 4px 0; }
#steps textarea { min-width: 240px; }
#steps input { min-width: 110px; }
.act-summary { border-left: 3px solid var(--line); padding-left: 12px; margin: 10px 0 16px; }
ol.plain { margin: 2px 0 8px; padding-left: 22px; }
#steps textarea[name=stage] { min-width: 150px; }
table.estimate input, table.estimate select { min-width: 70px; }
table.estimate input[name=item] { min-width: 180px; }
table.estimate input[readonly] { background: var(--card); color: var(--muted); }
table.estimate input[name=amount], table.estimate input[name=unit_price] { min-width: 110px; }

/* ===== งานของฉัน ===== */
.phasebar { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.phasebar span { height: 6px; border-radius: 3px; background: var(--line); }
.phasebar span.done { background: var(--good); }
.phasebar span.now { background: var(--accent); }
.phase-now { font-size: .88rem; color: var(--muted); margin: 8px 0 0; }
.tasks { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
a.task { display: flex; gap: 12px; align-items: center; padding: 12px 16px; text-decoration: none; color: inherit; border-top: 1px solid var(--line); }
a.task:first-child { border-top: 0; }
a.task:hover { background: var(--card); }
.task-ic { color: var(--accent); display: inline-flex; }
.task-ic.done { color: var(--good); }
.task-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.task-title { font-size: .97rem; }
.task-detail { font-size: .82rem; color: var(--muted); }
.task-go { display: inline-flex; gap: 4px; align-items: center; font-size: .85rem; white-space: nowrap; border: 1px solid var(--line-strong); border-radius: 8px; padding: 5px 10px; }
@media (max-width: 760px) { .task-go { display: none; } }

/* ===== หน้าเขียนกิจกรรมแบบแบ่งขั้น ===== */
.alloc-box { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; padding: 10px 14px; margin: 14px 0; border-radius: var(--radius); background: var(--card); font-size: .9rem; }
.writer { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 18px; align-items: start; }
.steps-side { position: sticky; top: 12px; }
button.step { all: unset; box-sizing: border-box; cursor: pointer; display: flex; gap: 10px; align-items: center; width: 100%; padding: 7px 8px; border-radius: 8px; font-size: .92rem; color: var(--muted); }
button.step:hover { background: var(--card); }
button.step.on { color: var(--fg); font-weight: 500; background: var(--card); }
.step-dot { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; border: 1px solid var(--line-strong); flex: none; }
.step-dot.ok { background: var(--good-bg); color: var(--good); border-color: transparent; }
button.step.on .step-dot:not(.ok) { border: 1.5px solid var(--accent); color: var(--accent-ink); }
.step-of { margin: 0 0 2px; font-size: .82rem; }
.step-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); }
a.button.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
@media (max-width: 760px) {
  .writer { grid-template-columns: minmax(0, 1fr); }
  .steps-side { position: static; }
  #stepList { display: flex; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  button.step { width: auto; white-space: nowrap; }
}

/* ===== ประมาณการบนมือถือ: ตาราง → การ์ดทีละรายการ ===== */
@media (max-width: 760px) {
  table.estimate thead { display: none; }
  table.estimate, table.estimate tbody, table.estimate tr, table.estimate td { display: block; width: 100%; }
  table.estimate tr { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; margin: 10px 0; background: var(--surface); }
  table.estimate td { border: 0; padding: 4px 0; display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; align-items: center; text-align: left; }
  table.estimate td::before { content: attr(data-label); font-size: .8rem; color: var(--muted); }
  table.estimate td:not([data-label]) { display: block; }
  table.estimate td:not([data-label])::before { content: none; }
  table.estimate td.num { text-align: left; }
  table.estimate input, table.estimate select { margin: 0; min-width: 0 !important; }
  table.estimate tr.total-row { display: flex; justify-content: space-between; background: var(--card); }
  table.estimate tr.total-row td { display: inline; width: auto; }
  table.estimate .actions-cell { display: flex; gap: 8px; justify-content: flex-end; padding-top: 8px; }
}

/* เอกสารโครงการ (รายกิจกรรม) ตามแบบฟอร์มโรงเรียน */
.doc h3 { font-size: 17px; margin: 14px 0 4px; }
.doc .doc-head { text-align: center; font-weight: 700; margin: 0 0 12px; }
.doc .item { padding-left: 2em; }
.doc .sub { padding-left: 1em; font-weight: 700; }
.doc-fields th, .doc-fields td { border: 0; padding: 2px 6px 2px 0; color: #000; font-size: 16px; }
.doc-fields th { width: 150px; font-weight: 700; white-space: nowrap; }
.doc-steps { font-size: 14px; table-layout: fixed; }
.doc-steps th, .doc-steps td { padding: 4px 5px; }
.doc-steps th { text-align: center; color: #000; }
.doc-budget { width: auto; min-width: 60%; }
.doc-budget td { border: 0; padding: 2px 12px 2px 2em; color: #000; }
.doc-budget .total { text-align: right; font-weight: 700; }
.doc-estimate { font-size: 13.5px; }
.doc-estimate th { text-align: center; color: #000; }
.doc .doc-signs { margin-top: 28px; break-inside: avoid; }
.doc .doc-signs.one { grid-template-columns: 1fr; max-width: 50%; margin-left: auto; }
.doc .page { margin-top: 24px; }
.doc .muted { color: #555; }
@media print {
  .doc .page { break-before: page; margin-top: 0; }
  .doc .sign { break-inside: avoid; }
}
.memo th { color: #000; }
.doc .sign-line { white-space: nowrap; }
.doc .doc-signs:not(.one) .sign:last-child:nth-child(odd) { grid-column: 1 / -1; }
#signers input[type=text], #signers input:not([type]), #signers select { min-width: 150px; }
#signers input[name=position]:not([type]) { min-width: 220px; }
.doc .doc-logo { display: block; width: 26mm; height: auto; margin: 0 auto 6mm; }
.doc .doc-head { break-after: avoid; }
.doc h3 { break-after: avoid; }
.doc-steps tr, .memo-table tr { break-inside: avoid; }
.logo-field { display: flex; gap: 16px; align-items: center; margin: 10px 0; }
.logo-preview { width: 72px; height: 72px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; flex: none; }
.logo-preview.empty { display: flex; align-items: center; justify-content: center; font-size: .75rem; color: var(--muted); text-align: center; }
.doc .keep { break-inside: avoid; }
/* ตัวชี้วัดในหน้าเขียนกิจกรรม */
.writer .ind { margin: 10px 0; }
.writer .ind label { margin: 6px 0; }
.ind-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 12px; }
.ind-target { display: flex; gap: 6px; }
.ind-target select { width: auto; flex: none; }
.ind-target input { min-width: 0; }

/* แถบแจ้งการใช้บริการ (ทดลองใช้ / ใกล้หมดอายุ / หมดอายุ) */
.sub-notice { margin: 0 24px 8px; padding: 8px 14px; border-radius: 8px; background: var(--card); color: var(--muted); font-size: .9rem; }
.sub-notice.warn { background: var(--warn-bg); color: var(--warn); }
.sub-notice.bad { background: var(--bad-bg); color: var(--bad); font-weight: 500; }
.sub-notice[hidden] { display: none; }
@media (max-width: 760px) { .sub-notice { margin: 8px 16px 0; } }
.print-page .sub-notice { display: none !important; }
