:root {
  --ink: #17181a;
  --paper: #fafaf8;
  --surface: #ffffff;
  --surface-2: #f4f3f0;
  --rule: #e6e4de;
  --muted: #8b877e;
  --signal: #3d4a3d;
  --signal-2: #5c6b58;
  --on-signal: #ffffff;
  --accent-2: #6e5f48;
  --danger: #963a30;
  --warn: #8a5a12;
  --chart-1: #5a8a4a; /* แท่งกราฟ (ผ่านเกณฑ์ lightness/chroma/contrast บนพื้นขาว) */
  --ok: #3f5f47;
  --shadow-sm: 0 1px 2px rgba(23, 24, 26, .04);
  --shadow-md: 0 4px 16px rgba(23, 24, 26, .06);
  --shadow-lg: 0 16px 40px rgba(23, 24, 26, .10);
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Anuphan", "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  font-weight: 400;
  font-size: 1rem;
  line-height: 1.7;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 1.25rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease, border-color .15s ease, color .15s ease; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; border-radius: 4px; }

/* Header */
.top {
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-top: 1.25rem; }
.brand h1 {
  font-size: 1.45rem; line-height: 1.3; margin: 0; font-weight: 500; letter-spacing: .01em;
  color: var(--ink);
}
.brand p { margin: .3rem 0 0; color: var(--muted); font-size: .85rem; font-weight: 300; }
.tabs { display: flex; gap: 1.5rem; margin-top: 1.1rem; border-bottom: 1px solid var(--rule); }
.tabs button {
  background: none; border: 0; padding: 0 0 .85rem; cursor: pointer; border-radius: 0;
  color: var(--muted); font-weight: 400; font-size: .9rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] {
  color: var(--ink); font-weight: 500; border-bottom-color: var(--signal);
}

/* Buttons */
.primary, .ghost, .danger {
  border-radius: var(--r-sm); padding: .6rem 1.25rem; cursor: pointer; font-weight: 500; border: 1px solid transparent;
  font-size: .92rem;
}
.primary {
  background: var(--ink);
  color: var(--on-signal);
}
.primary:hover { background: var(--signal); }
.primary:active { opacity: .9; }
.primary:disabled { opacity: .4; cursor: progress; }
.ghost { background: transparent; border-color: var(--rule); color: var(--ink); }
.ghost:hover { border-color: var(--ink); }
.danger { background: transparent; color: var(--danger); border-color: var(--rule); }
.danger:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 6%, transparent); }
.icon {
  background: transparent; border: 1px solid var(--rule); border-radius: var(--r-sm); font-size: 1rem;
  cursor: pointer; padding: .4rem .6rem; color: var(--muted); line-height: 1;
}
.icon:hover { color: var(--ink); border-color: var(--ink); }

/* Toolbar */
.toolbar { display: flex; gap: .75rem; margin: 2rem 0 1.5rem; }
.toolbar input { flex: 1; }
.view-toggle {
  display: flex; flex-shrink: 0; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: transparent; overflow: hidden;
}
.view-toggle button {
  background: none; border: 0; padding: .6rem 1rem; cursor: pointer; font-weight: 400;
  color: var(--muted); white-space: nowrap; font-size: .9rem;
}
.view-toggle button[aria-pressed="true"] { color: var(--ink); font-weight: 500; background: var(--surface-2); }
@media (max-width: 480px) { .toolbar { flex-wrap: wrap; } .view-toggle { order: 3; width: 100%; } .view-toggle button { flex: 1; } }
input[type=search], input[type=text], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: .65rem .9rem; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--surface); transition: border-color .15s ease;
}
input[type=search]:focus, input[type=text]:focus, input[type=date]:focus, input[type=password]:focus,
select:focus, textarea:focus { border-color: var(--ink); }
textarea { min-height: 7rem; resize: vertical; }

/* Works: card grid */
.works-grid { columns: 3 260px; column-gap: 1.5rem; }
.work {
  break-inside: avoid; margin: 0 0 1.5rem; cursor: pointer; padding: 0; text-align: left; display: block; width: 100%;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); overflow: hidden;
  transition: border-color .2s ease;
}
.work:hover { border-color: var(--ink); }
.work img { width: 100%; display: block; background: var(--surface-2); }
.work .noimg {
  aspect-ratio: 4/3; border-bottom: 1px solid var(--rule); background: var(--surface-2);
  display: grid; place-items: center; color: var(--muted); font-size: .9rem;
}
.work h3 { font-weight: 500; font-size: 1.08rem; margin: 1rem 1.1rem 0; line-height: 1.5; }
.work .meta { color: var(--muted); font-size: .84rem; margin: .35rem 1.1rem 1.1rem; display: block; }
.badge {
  display: inline-block; font-size: .72rem; padding: .12rem .5rem; border: 1px solid var(--rule); border-radius: var(--r-sm);
  color: var(--muted); margin-left: .35rem; background: transparent; font-weight: 400;
}

/* Lessons: dated log */
.log { list-style: none; margin: 0; padding: 0; border-top: 0; display: flex; flex-direction: column; gap: .6rem; }
.log li { border-bottom: 0; }
.log button {
  display: grid; grid-template-columns: 3rem 7.5rem 1fr auto; gap: 1rem; align-items: center;
  width: 100%; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md);
  padding: .7rem 1.1rem; text-align: left; cursor: pointer;
  transition: border-color .15s ease;
}
.log button:hover { border-color: var(--ink); }
.log-thumb {
  width: 3rem; height: 3rem; border-radius: var(--r-sm); object-fit: cover; background: var(--surface-2); flex-shrink: 0;
}
.log-thumb.noimg { border: 1px dashed var(--rule); }
.log .date { color: var(--signal); font-variant-numeric: tabular-nums; font-size: .88rem; font-weight: 700; }
.log .subj { font-weight: 700; }
.log .topic { display: block; color: var(--muted); font-size: .92rem; }
.log .count { color: var(--muted); font-size: .85rem; white-space: nowrap; }
@media (max-width: 560px) {
  .log button { grid-template-columns: 2.4rem 1fr auto; }
  .log-thumb { width: 2.4rem; height: 2.4rem; }
  .log .date { grid-column: 1 / -1; order: 3; }
}

.empty {
  padding: 4rem 1.5rem; text-align: center; color: var(--muted);
  background: transparent; border: 1px dashed var(--rule); border-radius: var(--r-lg);
}

/* Dialogs */
dialog {
  border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 1.65rem 1.75rem; width: min(680px, 94vw);
  max-height: 90vh; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(23, 24, 26, .4); }
.dlg-head { display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.dlg-head h2 { font-weight: 500; margin: 0 0 1rem; font-size: 1.3rem; line-height: 1.4; }
.dlg-foot { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.35rem; flex-wrap: wrap; }
.field { display: block; margin-bottom: .9rem; }
.field > span { display: block; font-size: .9rem; font-weight: 600; margin-bottom: .3rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 480px) { .row2 { grid-template-columns: 1fr; } }
.check { display: flex; gap: .5rem; align-items: center; margin-bottom: .9rem; }
.error { color: var(--danger); min-height: 1.2em; margin: .3rem 0 0; font-size: .92rem; font-weight: 600; }

.gallery { display: grid; gap: .6rem; margin: .5rem 0 1rem; }
.gallery img { width: 100%; border-radius: var(--r-md); box-shadow: var(--shadow-sm); }
.detail dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.detail .desc { white-space: pre-wrap; max-width: 70ch; }

.thumbs { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.thumb { position: relative; width: 84px; height: 84px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--r-sm); box-shadow: var(--shadow-sm); }
.thumb button {
  position: absolute; top: -7px; right: -7px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--surface); background: var(--danger); color: #fff; cursor: pointer; font-size: .72rem; line-height: 1;
  box-shadow: var(--shadow-sm);
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Tabs as links (หน้าบันทึกคะแนน) ---------- */
.tabs a {
  padding: 0 0 .85rem; color: var(--muted); font-weight: 400; text-decoration: none;
  font-size: .9rem; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a[aria-current="page"] {
  color: var(--ink); font-weight: 500; border-bottom-color: var(--signal);
}
.tabs a:hover, .tabs button:hover { color: var(--ink); }
.tabs a[aria-current="page"]:hover, .tabs button[aria-selected="true"]:hover { color: var(--ink); }

/* ---------- Gradebook ---------- */
.gb-page .wrap { max-width: 1400px; }
.course-list { display: flex; flex-direction: column; gap: .6rem; }
.course-list a {
  display: grid; grid-template-columns: 7.5rem 1fr auto; gap: 1rem; align-items: baseline;
  padding: 1rem 1.1rem; color: inherit; text-decoration: none;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md);
  transition: border-color .15s ease;
}
.course-list a:hover { border-color: var(--ink); }
.course-list a:hover .subj { text-decoration: underline; }
@media (max-width: 560px) {
  .course-list a { grid-template-columns: 1fr auto; }
  .course-list .date { grid-column: 1 / -1; }
}

.gb-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin: 1.25rem 0 .5rem; }
.gb-head h2 { font-weight: 500; margin: .25rem 0 0; font-size: 1.4rem; line-height: 1.4; }
.gb-meta { margin: .1rem 0 0; color: var(--muted); font-size: .92rem; }
.gb-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.gb-actions .ghost { padding: .45rem .9rem; font-size: .92rem; }
.back { color: var(--muted); text-decoration: none; font-size: .92rem; font-weight: 600; }
.back:hover { color: var(--signal); }
.save-state { min-height: 1.4em; margin: 0 0 .5rem; font-size: .88rem; color: var(--muted); }
.notice { border-left: 4px solid var(--signal); padding: .55rem .9rem; background: var(--surface); border-radius: 0 var(--r-sm) var(--r-sm) 0; margin: 0 0 .75rem; font-size: .92rem; box-shadow: var(--shadow-sm); }
.hint { color: var(--muted); font-size: .88rem; margin: .4rem 0; }

.gb-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-sm); }
table.gb { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-variant-numeric: tabular-nums; }
.gb th, .gb td { border-bottom: 1px solid var(--rule); border-right: 1px solid var(--rule); padding: .35rem .5rem; text-align: center; white-space: nowrap; }
.gb thead th { background: var(--surface-2); font-weight: 700; font-size: .88rem; line-height: 1.3; position: sticky; top: 0; z-index: 2; }
.gb thead tr:nth-child(2) th { top: 2.05rem; }
.gb th small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.gb .grp { border-bottom: 3px solid var(--rule); }
.gb .grp-affective.grp { border-bottom-color: var(--accent-2); }
.gb .grp-coursework.grp { border-bottom-color: var(--signal); }
.gb tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
/* คอลัมน์ ที่/รหัส/ชื่อ ติดซ้ายเวลาเลื่อน */
.gb .no, .gb .code, .gb .name { position: sticky; background: var(--surface); z-index: 1; }
.gb tbody tr:nth-child(even) .no, .gb tbody tr:nth-child(even) .code, .gb tbody tr:nth-child(even) .name {
  background: color-mix(in srgb, var(--surface-2) 55%, var(--surface));
}
.gb thead .no, .gb thead .code, .gb thead .name { background: var(--surface-2); z-index: 3; }
.gb .no { left: 0; min-width: 2.6rem; color: var(--muted); }
.gb .code { left: 2.6rem; min-width: 7.5rem; text-align: left; }
.gb .name { left: 10.1rem; min-width: 13rem; text-align: left; box-shadow: 2px 0 0 var(--rule); }
.gb .sum { background: color-mix(in srgb, var(--signal) 8%, var(--surface)); font-weight: 700; min-width: 3.6rem; }
.gb .total { font-weight: 800; min-width: 3.8rem; color: var(--signal); }
.gb .auto { color: var(--muted); min-width: 3.6rem; }
.gb td.in { padding: 0; }
.item-btn, .name-btn { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: inherit; text-align: inherit; }
.item-btn span { display: block; max-width: 7rem; overflow: hidden; text-overflow: ellipsis; }
.item-btn:hover span, .name-btn:hover { text-decoration: underline; color: var(--signal); }
.item-btn small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
input.sc {
  width: 4.2rem; border: 0; background: transparent; text-align: center; padding: .5rem .25rem;
  font-variant-numeric: tabular-nums; border-radius: 0;
}
input.sc:focus { background: color-mix(in srgb, var(--signal) 16%, transparent); outline: 2px solid var(--signal); outline-offset: -2px; }
input.sc.bad { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); font-weight: 700; }
select.grade { width: auto; padding: .3rem .5rem; font-weight: 700; min-width: 7.5rem; border-radius: var(--r-sm); }
select.grade.manual { border-color: var(--signal); }
select.grade.g-special, select.grade.g-fail { color: var(--danger); }
.final-print { display: none; font-weight: 700; }
#authBtn { white-space: nowrap; }
.gb tbody tr:hover td { background: color-mix(in srgb, var(--signal) 9%, var(--surface)) !important; }

.gb-summary { margin: 1.5rem 0 2.75rem; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 1.25rem 1.4rem; box-shadow: var(--shadow-sm); }
.stats { display: flex; gap: 2rem; flex-wrap: wrap; margin-bottom: .75rem; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 1.7rem; line-height: 1.2; font-variant-numeric: tabular-nums; color: var(--signal); }
.stats span { color: var(--muted); font-size: .88rem; }
table.dist { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--rule); }
.dist th, .dist td { border-bottom: 1px solid var(--rule); border-right: 1px solid var(--rule); padding: .3rem .9rem; text-align: center; }
.dist th:last-child, .dist td:last-child { border-right: 0; }
.dist th { background: var(--surface-2); font-weight: 700; }

a.btn-link { display: inline-flex; align-items: center; text-decoration: none; color: inherit; }
.hint a, .steps a { color: var(--signal); font-weight: 700; }
.steps { margin: 0 0 1rem; padding-left: 1.3rem; font-size: .95rem; }
.steps li { margin-bottom: .3rem; }
.stats.small { gap: 1.5rem; margin: .5rem 0 .75rem; }
.stats.small b { font-size: 1.35rem; }
table.preview { width: 100%; font-size: .88rem; margin-bottom: .5rem; border-collapse: collapse; }
table.preview td { padding: .3rem .4rem; }
table.preview td.l { text-align: left; }
.msgs { margin: .25rem 0 .75rem; padding-left: 1.2rem; font-size: .88rem; max-height: 10rem; overflow-y: auto; color: var(--muted); }
.msgs.err { color: var(--danger); }
.error-title, .warn-title { font-weight: 700; font-size: .9rem; margin: .75rem 0 0; }
.error-title { color: var(--danger); }
fieldset.box { border: 1px solid var(--rule); border-radius: var(--r-md); padding: .8rem 1.1rem .35rem; margin: 0 0 1rem; background: var(--surface-2); }
fieldset.box legend { font-weight: 700; padding: 0 .4rem; font-size: .95rem; color: var(--signal); }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .75rem; }
@media (max-width: 560px) { .row3 { grid-template-columns: 1fr; } }
.scale-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); gap: 0 .6rem; }
input[type=number] { width: 100%; padding: .6rem .85rem; border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.dlg-foot .spacer { flex: 1; }

/* ---------- Dashboard ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.stat-card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.4rem; display: flex; flex-direction: column; gap: .3rem;
}
.stat-card b { font-size: 2.1rem; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--signal); }
.stat-card span { color: var(--muted); font-size: .88rem; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 2rem; }
@media (max-width: 760px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 1.25rem 1.4rem; }
.dash-panel h2 { font-weight: 500; margin: 0 0 .9rem; font-size: 1.1rem; }
.activity-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.activity-list a {
  display: grid; grid-template-columns: 6rem 1fr; gap: .75rem; align-items: baseline; text-decoration: none; color: inherit;
  padding: .6rem .75rem; border-radius: var(--r-sm); transition: background-color .15s ease;
}
.activity-list a:hover { background: var(--surface-2); }
.activity-list .date { color: var(--signal); font-variant-numeric: tabular-nums; font-size: .85rem; font-weight: 700; }
.activity-list .subj { font-weight: 700; }
.activity-list .topic { display: block; color: var(--muted); font-size: .88rem; }
.type-badge { display: inline-block; font-size: .74rem; padding: .05rem .45rem; border-radius: 999px; margin-left: .35rem; font-weight: 600; }
.type-badge.works { background: color-mix(in srgb, var(--signal) 16%, transparent); color: var(--signal); }
.type-badge.lessons { background: color-mix(in srgb, var(--accent-2) 16%, transparent); color: var(--accent-2); }

/* ---------- Calendar ---------- */
.legend { display: inline-flex; align-items: center; gap: .3rem; margin-right: 1rem; font-size: .88rem; }
.legend .dot { width: .6rem; height: .6rem; border-radius: 50%; display: inline-block; }
.legend .dot.works { background: var(--signal); }
.legend .dot.lessons { background: var(--accent-2); }
.cal-grid { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--surface-2); }
.cal-weekdays div { padding: .6rem; text-align: center; font-weight: 700; font-size: .85rem; color: var(--muted); }
.cal-days { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-cell { height: 6.5rem; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: .4rem; display: flex; flex-direction: column; gap: .3rem; overflow: hidden; }
.cal-cell.empty { background: var(--surface-2); }
.cal-cell.today { background: color-mix(in srgb, var(--signal) 7%, var(--surface)); }
.cal-cell.today .cal-day { color: var(--signal); font-weight: 800; }
.cal-day { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.cal-events { display: flex; flex-direction: column; gap: .2rem; min-height: 0; overflow-y: auto; }
.cal-pill {
  border: 0; border-radius: 4px; padding: .12rem .4rem; font-size: .74rem; text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.cal-pill.works { background: color-mix(in srgb, var(--signal) 18%, transparent); color: var(--signal); }
.cal-pill.lessons { background: color-mix(in srgb, var(--accent-2) 18%, transparent); color: var(--accent-2); }
.cal-more { font-size: .72rem; color: var(--muted); }
@media (max-width: 700px) {
  .cal-cell { height: 4rem; }
  .cal-pill { font-size: 0; padding: .2rem; width: .5rem; height: .5rem; border-radius: 50%; }
}

@media print {
  .top, .gb-actions, .back, .save-state, .no-print, .notice, #summary .hint { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .gb-scroll { overflow: visible; border: 0; box-shadow: none; }
  .gb th, .gb td { border-color: #999; }
  .gb .no, .gb .code, .gb .name, .gb thead th { position: static; }
  .gb tbody tr:nth-child(even) td, .gb tbody tr:nth-child(even) .no, .gb tbody tr:nth-child(even) .code, .gb tbody tr:nth-child(even) .name { background: none; }
  select.grade { display: none; }
  .final-print { display: inline; color: #000; }
  .gb tbody tr:hover td { background: none !important; }
  .gb .sum { background: none; }
  input.sc { width: 3rem; padding: .1rem; }
}

/* ---------- บันทึกข้อความ ---------- */
.memo-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.5rem; margin: 2rem 0; align-items: start; }
@media (max-width: 900px) { .memo-grid { grid-template-columns: 1fr; } }
.memo-form h2 { font-weight: 500; margin: 0 0 .9rem; font-size: 1.1rem; }
.memo-form small { font-weight: 400; color: var(--muted); }
.memo-form textarea { min-height: 12rem; }
.memo-subject { grid-template-columns: 2fr 1fr; }
@media (max-width: 480px) { .memo-subject { grid-template-columns: 1fr; } }
.memo-signers { border: 1px solid var(--rule); border-radius: var(--r-md); padding: .5rem 1rem 0; margin: 0 0 .5rem; }
.memo-signers legend { font-size: .9rem; font-weight: 600; padding: 0 .3rem; }
.memo-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .5rem; }
.memo-preview-wrap { position: sticky; top: 1rem; }
.memo-preview-wrap > .hint { margin-top: 0; }
/* ตัวอย่างกระดาษ: ใช้ฟอนต์และขนาดเดียวกับต้นแบบ (TH SarabunIT๙ 16pt บนกระดาษ A4)
   --pt = 1 pt ของกระดาษจริง ย่อตามความกว้างกระดาษบนจอ (A4 กว้าง 595.3pt); ตัวเลขทั้งหมดวัดจากไฟล์ต้นแบบใน Word */
@font-face { font-family: "THSarabunIT9"; src: url("/fonts/THSarabunIT9.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "THSarabunIT9"; src: url("/fonts/THSarabunIT9-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
.memo-pages, #previewPhotos { container-type: inline-size; }
.memo-paper {
  --pt: calc(100cqw / 595.3);
  background: #fff; color: #000; border: 1px solid var(--rule); box-shadow: var(--shadow-md);
  aspect-ratio: 210 / 297; overflow: hidden; box-sizing: border-box;
  padding: calc(49.7 * var(--pt)) calc(49.6 * var(--pt)) calc(21.3 * var(--pt)) calc(89.8 * var(--pt));
  font-family: "THSarabunIT9", "TH SarabunIT๙", "Sarabun", serif;
  font-size: calc(16 * var(--pt)); line-height: calc(18.1 * var(--pt));
}
.memo-paper p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
/* หัว: ตราครุฑ 42pt ยื่นออกซ้ายขอบ 11.2pt, "บันทึกข้อความ" 24pt ตัวหนา เริ่มที่ 143.9pt จากขอบซ้าย, เว้น 36.2pt ก่อน "ส่วนราชการ" */
.mp-head { position: relative; margin-bottom: calc(36.2 * var(--pt)); }
.mp-garuda { position: absolute; left: calc(-11.2 * var(--pt)); top: calc(13.5 * var(--pt)); width: calc(42 * var(--pt)); height: auto; }
.mp-head h3 { margin: 0 0 0 calc(143.9 * var(--pt)); font-size: calc(24 * var(--pt)); line-height: calc(26.9 * var(--pt)); font-weight: 700; }
.mp-row { display: flex; }
.mp-row > span:first-child { flex: 0 0 calc(226.8 * var(--pt)); } /* แท็บ "วันที่" */
.mp-rule { border-bottom: calc(.5 * var(--pt)) solid #000; padding-bottom: calc(11.8 * var(--pt)); margin-bottom: calc(11.9 * var(--pt)) !important; }
.mp-to { margin-bottom: calc(13.5 * var(--pt)) !important; }
/* ย่อหน้า 1.25 ซม. (35.45pt) = ตำแหน่งข้อความหลัง "เรียน" */
.mp-tab { display: inline-block; min-width: calc(35.45 * var(--pt)); }
.mp-body { text-indent: calc(35.45 * var(--pt)); text-align: justify; }
.mp-closing { margin-top: calc(18.1 * var(--pt)) !important; }
/* ผู้ลงนาม: "ลงชื่อ…" เริ่มที่ 288pt, ชื่อ/ตำแหน่งกึ่งกลางช่วง 250–468.9pt; คนแรกเว้น 2 บรรทัด คนถัดไปเว้น 1 บรรทัด */
.mp-sign { margin: calc(36.2 * var(--pt)) 0 0 calc(250 * var(--pt)); width: calc(218.9 * var(--pt)); text-align: center; }
.mp-sign + .mp-sign { margin-top: calc(18.1 * var(--pt)); }
.mp-sign p:first-child { text-align: left; padding-left: calc(38 * var(--pt)); white-space: nowrap; }
.mp-missing { color: #b0a99c; }

/* บันทึกบนเซิร์ฟเวอร์ */
.memo-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem 1rem; flex-wrap: wrap; margin-bottom: .9rem; }
.memo-head h2 { margin: 0; }
.memo-status { font-size: .85rem; color: var(--muted); }
.memo-saved { margin: 0 0 2.5rem; }
.memo-saved h2 small { color: var(--muted); font-weight: 400; font-size: .9rem; }
.saved-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.saved-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: .82rem; padding: .4rem .6rem; border-bottom: 1px solid var(--rule); }
.saved-table td { padding: .55rem .6rem; border-bottom: 1px solid var(--rule); vertical-align: middle; overflow-wrap: anywhere; }
.saved-table tr.current td { background: var(--surface-2); }
.saved-table .nowrap { white-space: nowrap; }
.saved-table .muted { color: var(--muted); }
.saved-acts { white-space: nowrap; text-align: right; }
.saved-acts button { padding: .3rem .7rem; font-size: .84rem; margin-left: .25rem; }
.saved-table .pill { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border: 1px solid var(--rule); border-radius: var(--r-sm); color: var(--muted); margin-left: .35rem; }
@media (max-width: 640px) {
  .saved-table thead { display: none; }
  .saved-table tr { display: grid; grid-template-columns: auto 1fr; gap: 0 .75rem; padding: .55rem 0; border-bottom: 1px solid var(--rule); }
  .saved-table td { border: 0; padding: .1rem 0; }
  .saved-table td:nth-child(2) { grid-column: 1 / -1; order: -1; font-weight: 500; }
  .saved-table td:nth-child(3) { display: none; }
  .saved-acts { grid-column: 1 / -1; text-align: left; margin-top: .3rem; }
  .saved-acts button { margin: 0 .25rem 0 0; }
}

/* ผู้ลงนาม (สูงสุด 10 คน) */
.signer-list { list-style: none; margin: .25rem 0 .75rem; padding: 0; display: grid; gap: .5rem; }
.signer-list li { display: flex; align-items: center; gap: .5rem; }
.signer-list input { flex: 1 1 0; min-width: 0; padding: .5rem .7rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; }
.signer-no { width: 1.4rem; text-align: center; color: var(--muted); font-size: .85rem; flex-shrink: 0; }
.memo-signers > .photo-add { margin-bottom: .75rem; }
@media (max-width: 560px) {
  .signer-list li { flex-wrap: wrap; }
  .signer-list input { flex-basis: calc(100% - 2rem); }
  .signer-list .photo-btns { margin-left: 1.9rem; }
}
/* ตัวอย่างแบ่งเป็นกระดาษ A4 ทีละหน้า เหมือนไฟล์ Word */
.memo-pages > .memo-paper + .memo-paper { margin-top: 1rem; }
/* จอกว้าง: ตัวอย่างหลายหน้าเลื่อนดูในคอลัมน์ของตัวเอง (ไม่งั้นหน้าล่างๆ จะมองไม่เห็นตอนติดอยู่ด้านบน) */
@media (min-width: 901px) {
  .memo-preview-wrap { max-height: calc(100vh - 2rem); overflow-y: auto; padding: 0 .5rem .5rem 0; }
}

/* ภาพประกอบ — ฟอร์ม */
.memo-photos { padding-bottom: .75rem; }
.photo-list { list-style: none; margin: .25rem 0 .75rem; padding: 0; display: grid; gap: .5rem; }
.photo-list:empty { display: none; }
.photo-list li { display: flex; align-items: center; gap: .6rem; }
.photo-list img { width: 4rem; height: 3rem; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--rule); flex-shrink: 0; }
.photo-list .photo-cap { flex: 1; min-width: 0; padding: .45rem .7rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; }
.photo-btns { display: flex; gap: .25rem; flex-shrink: 0; }
.photo-btns .icon:disabled { opacity: .35; cursor: default; }
.photo-add { display: inline-block; font-size: .9rem; padding: .45rem 1rem; }
.photo-add[hidden] { display: none; }
@media (max-width: 480px) {
  .photo-list li { flex-wrap: wrap; }
  .photo-list .photo-cap { flex-basis: calc(100% - 4.6rem); }
  .photo-btns { margin-left: 4.6rem; }
}

/* ภาพประกอบ — ตัวอย่างหน้าแนบ */
/* ตรงกับไฟล์ Word: หัวข้อ 18pt, คำบรรยาย 14pt, รูปกว้างไม่เกิน 6 นิ้ว (432pt) สูงไม่เกิน 4.1 นิ้ว (295.2pt) — รูปเดียว 7.5 นิ้ว */
.mp-photos { margin-top: 1rem; }
.mp-photo-title { text-align: center; font-size: calc(18 * var(--pt)); line-height: calc(20.3 * var(--pt)); font-weight: 700; margin: 0; }
.mp-photo-sub { text-align: center; margin-bottom: calc(6 * var(--pt)) !important; }
.mp-photos figure { margin: calc(12 * var(--pt)) 0 0; text-align: center; }
.mp-photos img { width: calc(432 * var(--pt)); height: calc(295.2 * var(--pt)); object-fit: contain; display: block; margin: 0 auto; }
.mp-photos.single img { height: calc(540 * var(--pt)); }
.mp-photos figcaption { font-size: calc(14 * var(--pt)); line-height: calc(15.8 * var(--pt)); min-height: calc(15.8 * var(--pt)); margin-bottom: calc(6 * var(--pt)); overflow-wrap: anywhere; }

/* ---------- โครงงานนักเรียน ---------- */
.muted { color: var(--muted); }
.pill { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border: 1px solid var(--rule); border-radius: var(--r-sm); color: var(--muted); }
.join-label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
.join-code { display: inline-block; font-family: ui-monospace, Consolas, monospace; font-size: 1.6rem; font-weight: 700; letter-spacing: .18em; padding: .15rem .6rem; border: 1px dashed var(--ink); border-radius: var(--r-sm); background: var(--surface-2); }
.code-input { text-transform: uppercase; letter-spacing: .15em; font-family: ui-monospace, Consolas, monospace; }
.pd-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: .2rem 0 .6rem; }
.log-card { border: 1px solid var(--rule); border-radius: var(--r-md); padding: .8rem 1rem; margin-bottom: .75rem; background: var(--surface); }
.log-card.editing { border-color: var(--ink); }
.log-card header { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.log-acts button { padding: .25rem .65rem; font-size: .82rem; margin-left: .25rem; }
.log-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .4rem; }
.log-photos img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--rule); display: block; }

/* ครู */
.pj-grid { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 1.25rem; margin: 2rem 0; align-items: start; }
@media (max-width: 860px) { .pj-grid { grid-template-columns: 1fr; } }
.room-list { list-style: none; margin: 0 0 .9rem; padding: 0; display: grid; gap: .35rem; }
.room-list button { width: 100%; text-align: left; background: transparent; border: 1px solid var(--rule); border-radius: var(--r-sm); padding: .55rem .75rem; cursor: pointer; font: inherit; color: inherit; }
.room-list button:hover { border-color: var(--ink); }
.room-list button[aria-current="true"] { border-color: var(--ink); background: var(--surface-2); }
.room-list span { display: block; font-weight: 500; }
.room-list small { color: var(--muted); font-size: .78rem; }
.room-new { display: grid; gap: .5rem; }
.room-new input { padding: .55rem .75rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; }
.room-detail { display: grid; gap: 1.25rem; }
.room-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem 1rem; flex-wrap: wrap; }
.room-head h2 { margin: 0 0 .75rem; }
.room-acts button, .join-acts button { padding: .35rem .8rem; font-size: .85rem; }
.join-box { display: flex; justify-content: space-between; align-items: end; gap: 1rem; flex-wrap: wrap; }
.join-acts { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: .35rem; font-size: .9rem; cursor: pointer; }
.pj-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .6rem; }
.pj-card { text-align: left; display: grid; gap: .25rem; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: .8rem .9rem; cursor: pointer; font: inherit; color: inherit; }
.pj-card:hover { border-color: var(--ink); }
.pj-card small { font-size: .8rem; }
.wide-dlg { width: min(820px, 94vw); }
.wide-dlg h3 { font-size: 1rem; font-weight: 600; margin: 1.1rem 0 .3rem; }

/* นักเรียน */
.st-acts { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.st-main { margin: 2rem auto; }
.st-auth { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.25rem; align-items: start; }
.st-auth form .primary { margin-top: .25rem; }
.st-group { display: flex; justify-content: space-between; gap: 1rem 2rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem 1.2rem; }
.st-invite { text-align: right; }
.st-leave { display: block; margin: .6rem 0 0 auto; padding: .3rem .8rem; font-size: .85rem; }
.st-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .st-grid { grid-template-columns: 1fr; } .st-invite { text-align: left; } .st-leave { margin-left: 0; } }
.st-logs-title { font-size: 1.05rem; font-weight: 500; margin: 1.5rem 0 .75rem; }
.log-photo-edit { list-style: none; margin: 0 0 .5rem; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.log-photo-edit:empty { display: none; }
.log-photo-edit li { position: relative; }
.log-photo-edit img { width: 88px; height: 66px; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--rule); display: block; }
.log-photo-edit .icon { position: absolute; top: 2px; right: 2px; padding: .1rem .35rem; font-size: .75rem; background: var(--surface); }
#logForm .photo-add { margin-bottom: .25rem; }
/* หน้านักเรียนบนมือถือ: หัวไม่ติดด้านบน (กินพื้นที่จอ) และปุ่มบัญชีเล็กลง */
@media (max-width: 560px) {
  .st-page .top { position: static; }
  .st-page .top-inner { flex-wrap: wrap; padding-bottom: .75rem; }
  .st-acts { justify-content: flex-start; gap: .4rem; }
  .st-acts button { padding: .35rem .7rem; font-size: .82rem; white-space: nowrap; }
}
/* เมนูบนจอแคบ: ขึ้นบรรทัดใหม่ทั้งเมนู ไม่ตัดคำกลางชื่อเมนู */
@media (max-width: 640px) {
  .tabs { flex-wrap: wrap; gap: .5rem 1.1rem; }
  .tabs a, .tabs button { white-space: nowrap; }
}

/* ---------- แดชบอร์ดโครงงาน ---------- */
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--r-md); padding: 3px; margin: 1.75rem 0 0; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: .45rem 1.1rem; border-radius: var(--r-sm); cursor: pointer; font: inherit; font-size: .92rem; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--ink); color: var(--surface); }
#manageView.pj-grid { margin-top: 1.25rem; }
.dash-filter { display: flex; align-items: center; gap: .5rem 1rem; flex-wrap: wrap; margin: 1.25rem 0 0; }
.dash-filter label { display: inline-flex; align-items: center; gap: .5rem; font-size: .92rem; font-weight: 600; }
.dash-filter select { padding: .45rem .7rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; font-weight: 400; background: var(--surface); }
.dash-filter .hint { margin: 0; }
.stat-card small { font-size: .8rem; }
.pd-panel { margin-bottom: 1.5rem; }

/* กราฟแท่งรายสัปดาห์ */
.week-chart { position: relative; height: 190px; margin: .75rem 0 .25rem; padding-left: 1.6rem; }
.wc-grid { position: absolute; inset: 0 0 1.4rem 1.6rem; display: flex; flex-direction: column; justify-content: space-between; }
.wc-line { border-top: 1px solid var(--rule); position: relative; height: 0; }
.wc-line:last-child { border-top-color: var(--muted); }
.wc-line span { position: absolute; right: calc(100% + .35rem); top: -.6em; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.wc-bars { position: absolute; inset: 0 0 1.4rem 1.6rem; display: flex; align-items: stretch; gap: 2px; }
.wc-col { flex: 1; position: relative; display: flex; align-items: flex-end; justify-content: center; outline: none; cursor: default; }
.wc-col:hover, .wc-col:focus-visible { background: var(--surface-2); }
.wc-col:focus-visible { box-shadow: inset 0 0 0 2px var(--ink); }
.wc-bar { width: min(70%, 28px); background: var(--chart-1); border-radius: 4px 4px 0 0; min-height: 0; }
.wc-val { position: absolute; transform: translateY(-1.25em); font-size: .75rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.wc-x { position: absolute; left: 1.6rem; right: 0; bottom: 0; display: flex; gap: 2px; }
.wc-x span { flex: 1; text-align: center; font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: visible; }
.chart-tip { position: absolute; z-index: 20; pointer-events: none; background: var(--ink); color: var(--surface); font-size: .82rem; padding: .35rem .6rem; border-radius: var(--r-sm); box-shadow: var(--shadow-md); line-height: 1.35; }
.chart-tip span { opacity: .8; font-size: .76rem; }
.chart-table summary { cursor: pointer; font-size: .85rem; color: var(--muted); margin-top: .5rem; }
.chart-table table { margin-top: .5rem; }

/* ตารางความคืบหน้า */
.pd-table tbody tr { cursor: pointer; }
.pd-table tbody tr:hover td, .pd-table tbody tr:focus-visible td { background: var(--surface-2); }
.pd-table tbody tr:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.pd-title { font-weight: 500; }
.pd-meter { display: inline-block; width: 3.2rem; height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--rule); vertical-align: middle; overflow: hidden; }
.pd-meter i { display: block; height: 100%; background: var(--chart-1); }
.status { display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; font-weight: 600; padding: .1rem .5rem; border-radius: var(--r-sm); border: 1px solid currentColor; }
.status-active { color: var(--ok); }
.status-stale { color: var(--warn); }
.status-none { color: var(--danger); }
/* จอแคบ: ชื่อกลุ่ม → "บันทึก n · วันที่ล่าสุด" → สถานะ (ซ่อนสมาชิก/ความครบของข้อมูล) */
@media (max-width: 640px) {
  .pd-table td:nth-child(2), .pd-table td:nth-child(3) { display: none; }
  .pd-table tr { grid-template-columns: auto 1fr auto; align-items: center; gap: .15rem .6rem; }
  .pd-table td:nth-child(1) { grid-column: 1 / -1; }
  .pd-table td:nth-child(4)::before { content: 'บันทึก '; color: var(--muted); }
  .pd-table td:nth-child(5) br { display: none; }
  .pd-table td:nth-child(5) small { margin-left: .3rem; }
  .pd-table td:nth-child(6) { justify-self: end; }
}
.stat-card span a { color: inherit; }
/* บันทึกล่าสุด: เนื้อหาแสดงบรรทัดเดียว */
.recent-log .topic { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- ครูที่ปรึกษา ---------- */
.warn-text { color: var(--warn); font-weight: 600; }
.adv-form { margin-bottom: 1.25rem; }
.adv-form select, .pd-adv select { width: 100%; padding: .55rem .7rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; background: var(--surface); }
.adv-settings { display: grid; gap: .25rem; }
.adv-settings .hint { margin: 0; }
.adv-new { display: flex; gap: .5rem .75rem; flex-wrap: wrap; align-items: center; margin-bottom: .25rem; }
.adv-new > input[type="text"] { flex: 1 1 260px; padding: .55rem .75rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; }
.adv-new label { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; }
.adv-new input[type="number"], .adv-quota { width: 4.5rem; padding: .4rem .5rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; }
.adv-table td { vertical-align: top; }
.quota-list { display: grid; gap: .55rem; }
.quota-row { display: grid; grid-template-columns: minmax(8rem, 14rem) minmax(6rem, 1fr) 11rem; align-items: center; gap: .75rem; font-size: .92rem; } /* คอลัมน์คงที่ แถบทุกแถวจึงตรงกัน */
.quota-row.inactive .quota-name { color: var(--muted); }
.quota-meter { width: 100%; height: 8px; border-radius: 4px; }
.quota-meter.full i { background: var(--signal); }
.quota-meter.over i { background: var(--warn); }
.quota-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pd-adv { display: grid; grid-template-columns: 1fr 1fr auto; gap: .5rem .75rem; align-items: end; padding: .75rem; margin-bottom: .75rem; background: var(--surface-2); border-radius: var(--r-md); }
.pd-adv label { display: grid; gap: .2rem; font-size: .85rem; font-weight: 600; }
.pd-adv .hint { grid-column: 1 / -1; margin: 0; }
@media (max-width: 640px) {
  .quota-row { grid-template-columns: 1fr auto; }
  .quota-row .quota-meter { grid-column: 1 / -1; order: 3; }
  .pd-adv { grid-template-columns: 1fr; }
}

/* ---------- บัญชีครู ---------- */
.whoami { font-size: .88rem; align-self: center; }
.tch-new > input[type="text"] { flex: 1 1 160px; }
.tch-new select { flex: 1 1 200px; padding: .55rem .7rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; background: var(--surface); }
.tch-adv { max-width: 14rem; padding: .35rem .5rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; background: var(--surface); }
.top-inner .st-acts { align-items: center; }
.error.ok-msg { color: var(--ok); }

/* ---------- หน้าผู้ดูแล ---------- */
.adm-main { margin: 2rem auto; }
.adm-login { max-width: 420px; margin: 3rem auto; }
.adm-status { display: grid; grid-template-columns: auto 1fr; gap: .55rem 1rem; margin: 0; font-size: .92rem; }
.adm-status dt { color: var(--muted); }
.adm-status dd { margin: 0; }
.adm-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .5rem; }
.adm-links a { display: grid; gap: .15rem; padding: .65rem .8rem; border: 1px solid var(--rule); border-radius: var(--r-md); color: inherit; text-decoration: none; }
.adm-links a:hover { border-color: var(--ink); background: var(--surface-2); }
.adm-links b { font-weight: 600; font-size: .92rem; }
.adm-links span { font-size: .8rem; color: var(--muted); }
.adm-search { width: 100%; padding: .6rem .8rem; border: 1px solid var(--rule); border-radius: var(--r-sm); font: inherit; margin-bottom: .75rem; }
.site-foot { padding: 1.5rem 1.25rem 2.5rem; text-align: right; font-size: .82rem; }
.site-foot a { color: var(--muted); }

/* ---------- แบบฟอร์ม PJ.1 (pj1.html) ---------- */
a.btn-link.primary { color: var(--on-signal); }
.pj-adv-name { margin: .25rem 0 .5rem; font-weight: 600; font-size: .92rem; }
#coAdv { margin-top: .75rem; padding-top: .5rem; border-top: 1px dashed var(--rule); }
.pj-preview-acts { margin: 0 0 .5rem; }
.pj-staff { grid-template-columns: minmax(0, 820px); justify-content: center; }
/* ขนาดตามไฟล์ Word: A4, ขอบ บน/ขวา/ล่าง 2 ซม. (56.7pt) ซ้าย 3 ซม. (85pt), TH Sarabun New 16pt ระยะบรรทัด ~23pt */
/* ตัวเลขในตัวอย่างเป็นเลขอารบิกเหมือนไฟล์ Word (ฟอนต์ TH SarabunIT๙ วาดตัวเลขเป็นเลขไทย) — ย่อขนาดให้เท่าตัว TH */
@font-face { font-family: "PJDigits"; src: local("Arial"), local("Helvetica"), local("Roboto"), local("Liberation Sans"); unicode-range: U+0030-0039; size-adjust: 72%; }
.pj-paper {
  font-family: "PJDigits", "THSarabunIT9", "TH SarabunIT๙", "Sarabun", serif;
  position: relative;
  padding: calc(56.7 * var(--pt)) calc(56.7 * var(--pt)) calc(56.7 * var(--pt)) calc(85 * var(--pt));
  line-height: calc(23 * var(--pt));
}
.pj-paper p { white-space: normal; }
.pj-pno { position: absolute; top: calc(28.35 * var(--pt)); left: 0; right: 0; text-align: center; }
.pj-c { text-align: center; }
.pj-r { text-align: right; }
.pj-rule { height: calc(12 * var(--pt)); margin: 0 calc(113 * var(--pt)) calc(6 * var(--pt)) !important; border-bottom: calc(.75 * var(--pt)) solid #000; }
.pj-gap { margin-top: calc(6 * var(--pt)) !important; }
.pj-gap2 { margin-top: calc(18 * var(--pt)) !important; }
.pj-line { display: flex; align-items: baseline; min-height: calc(23 * var(--pt)); }
.pj-line > span:first-child:not(.pj-dots) { flex: 0 1 auto; }
.pj-dots { flex: 1 1 0; min-width: calc(20 * var(--pt)); margin-left: calc(3 * var(--pt)); border-bottom: calc(1.2 * var(--pt)) dotted #000; transform: translateY(calc(-4 * var(--pt))); }
.pj-ind { padding-left: calc(28.35 * var(--pt)); }
.pj-ind2 { padding-left: calc(70.9 * var(--pt)); }
.pj-ind3 { padding-left: calc(99.25 * var(--pt)); }
.pj-ind4 { padding-left: calc(127.6 * var(--pt)); }
.pj-st { display: grid; grid-template-columns: calc(56.7 * var(--pt)) calc(226.8 * var(--pt)) auto; }
.pj-body { text-indent: calc(28.35 * var(--pt)); text-align: justify; }
.pj-sec { margin-top: calc(3 * var(--pt)) !important; }
.pj-num { padding-left: calc(56.7 * var(--pt)); }
.pj-line.pj-num > span.pj-no:first-child { flex: 0 0 calc(28.35 * var(--pt)); }
.pj-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.pj-table th, .pj-table td { border: calc(.5 * var(--pt)) solid #000; padding: 0 calc(5.4 * var(--pt)); vertical-align: top; text-align: left; font-weight: 400; }
.pj-table th { text-align: center; font-weight: 700; }
.pj-table p { margin: 0; }
/* ช่องลงชื่อ: "ลงชื่อ…" เริ่มที่ 170pt (คนที่ n: 85pt) ชื่อ/วันที่อยู่กึ่งกลางเส้นจุด (กว้าง ~157pt) */
.pj-sign { --at: calc(170.1 * var(--pt)); position: relative; margin-top: calc(12 * var(--pt)); }
.pj-sign-n { --at: calc(85 * var(--pt)); }
.pj-sign-first { margin-top: calc(18 * var(--pt)); }
.pj-sign-tight { margin-top: calc(6 * var(--pt)); }
.pj-sign-pre { position: absolute; left: 0; top: 0; }
.pj-sign-line { padding-left: var(--at); white-space: nowrap !important; }
.pj-sign-c { margin-left: var(--at) !important; width: calc(157.5 * var(--pt)); text-align: center; white-space: nowrap !important; display: flex; justify-content: center; }
.pj-sign-date { margin-left: calc(170.1 * var(--pt)) !important; margin-top: calc(6 * var(--pt)) !important; }
.pj-opinion { display: grid; grid-template-columns: calc(70.9 * var(--pt)) calc(155.9 * var(--pt)) auto; padding-left: calc(28.35 * var(--pt)); }
.pj-box { font-family: "Segoe UI Symbol", sans-serif; }
@media print {
  body.st-page > header, #pj1Form, .pj-preview-acts, #previewHint { display: none !important; }
  .memo-grid { display: block; margin: 0; }
  .memo-preview-wrap { position: static; max-height: none; overflow: visible; padding: 0; }
  main.wrap { padding: 0; max-width: none; }
  .memo-pages { width: 210mm; }
  .memo-paper { border: 0; box-shadow: none; break-after: page; }
  .memo-pages > .memo-paper + .memo-paper { margin-top: 0; }
  @page { size: A4; margin: 0; }
}
