/* =========================================================
   ครูพัสดุ — สไตล์พื้นฐานที่ใช้ร่วมกันทุกหน้า
   (หน้าเว็บสาธารณะ public.css และหน้าหลังเข้าสู่ระบบ app.css โหลดต่อจากไฟล์นี้)
   ใช้ค่าจาก tokens.css เท่านั้น ห้ามใส่สีใหม่ในไฟล์นี้
   ========================================================= */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 600; line-height: 1.35; }
ul, ol { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
main:focus { outline: none; }

.i {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.flip { transform: scaleX(-1); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 16px; top: -60px; z-index: 100;
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  font-weight: 500;
}
.skip-link:focus { top: 12px; }

.brand { display: inline-flex; align-items: center; gap: 12px; min-width: 0; }
/* โลโก้ KPSD (ไฟล์ขาวพื้นใสจากเว็บเดิม) ใช้เป็น mask แล้วเติมสีด้วย currentColor → เปลี่ยนสีตามพื้นได้ */
.brand-logo {
  display: block; flex: none; width: 56px; height: 27px;
  background: currentColor;
  -webkit-mask: url("../img/brand/kpsd-wordmark.png") center / contain no-repeat;
          mask: url("../img/brand/kpsd-wordmark.png") center / contain no-repeat;
}
.brand .brand-logo + .brand-text { padding-left: 12px; border-left: 1px solid var(--chrome-line); }
.brand-on-light { color: var(--chrome-ink); }
.brand-on-light .brand-name { color: var(--text); }
.brand-on-light .brand-logo + .brand-text { border-left-color: var(--border); }
:root[data-theme="dark"] .brand-on-light { color: var(--accent-text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-on-light { color: var(--accent-text); } }
.brand-mark {
  width: 34px; height: 34px; flex: none; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--surface); color: var(--chrome-ink);
}
.brand-mark .i { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-name { font-size: 16px; font-weight: 600; }
.brand-sub { font-size: var(--fs-label); color: var(--on-chrome-3); white-space: nowrap; }

/* ปุ่มสลับธีม: โหมดสว่างแสดงพระจันทร์ โหมดมืดแสดงพระอาทิตย์ */
.i-light { display: none; }
:root[data-theme="dark"] .i-light { display: block; }
:root[data-theme="dark"] .i-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-light { display: block; }
  :root:not([data-theme="light"]) .i-dark { display: none; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: var(--fs-ui); font-weight: 500; white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn .i { width: 18px; height: 18px; }
.btn-lg { height: 46px; padding: 0 20px; font-size: 15px; font-weight: 600; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { border-color: var(--border-strong); background: var(--surface-2); }
/* ปุ่มบนพื้น chrome: ทึบ = พื้นขาวตัวหนังสือสีหลัก (เหมือนเมนูที่ถูกเลือกใน sidebar) / โปร่ง = ขอบขาวจาง */
.btn-chrome-solid { background: var(--surface); color: var(--chrome-ink); font-weight: 600; }
.btn-chrome-solid:hover { background: var(--surface-2); }
.btn-chrome-ghost { color: var(--on-chrome); border-color: var(--chrome-line); }
.btn-chrome-ghost:hover { background: var(--chrome-hover); }
.btn[aria-current="page"].btn-chrome-ghost { background: var(--chrome-hover); }
.btn[disabled] { opacity: .6; cursor: progress; }

.text-link { color: var(--accent-text); font-weight: 500; }
.text-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.small { font-size: var(--fs-meta); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }

.icon-box {
  --tint: var(--accent);
  width: 42px; height: 42px; flex: none; border-radius: var(--radius);
  display: grid; place-items: center;
  color: var(--tint); background: color-mix(in srgb, var(--tint) 15%, transparent);
}
.icon-box .i { width: 20px; height: 20px; }
.icon-box.sm { width: 34px; height: 34px; border-radius: 9px; }
.icon-box.sm .i { width: 17px; height: 17px; }
.tint-blue { --tint: var(--tint-blue); }
.tint-orange { --tint: var(--tint-orange); }
.tint-green { --tint: var(--tint-green); }
.tint-pink { --tint: var(--tint-pink); }
.tint-violet { --tint: var(--tint-violet); }

/* รายการช่องทางติดต่อ */
.contact-list { display: grid; gap: 4px; }
.contact-list a, .contact-list .contact-item {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 8px; margin: 0 -8px; border-radius: 9px;
}
.contact-list .i { width: 18px; height: 18px; }
.contact-label { font-weight: 600; margin-right: 4px; }
.contact-list--chrome a:hover { background: var(--chrome-hover); }
.contact-list--chrome .contact-empty { color: var(--on-chrome-2); }
.contact-list--footer a, .contact-list--aside a { color: var(--text-2); }
.contact-list--footer a:hover, .contact-list--aside a:hover { background: var(--hover); color: var(--text); }
.contact-list--footer .i, .contact-list--aside .i { color: var(--accent); }
.contact-empty { color: var(--text-3); font-size: var(--fs-ui); }

.form-section { border: 0; margin: 0; padding: 22px 0 6px; min-width: 0; }
.form-section + .form-section { border-top: 1px solid var(--border); }
/* legend ปกติจะวางทับเส้นขอบบนของ fieldset — ใช้ float ให้หลุดจากเส้นขอบแล้วต่อเนื้อหาด้านล่าง */
.form-section legend { float: left; width: 100%; display: flex; align-items: center; gap: 10px; padding: 0; margin-bottom: 16px; font-size: var(--fs-card-title); font-weight: 600; }
.form-section legend + * { clear: both; }
.legend-no {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-meta); font-weight: 600;
}
/* ---------- ฟอร์มแบ่งเป็นส่วน (ฟอร์มในแอป .form-card-app + ฟอร์มหน้าสาธารณะ .form-card) ----------
   แต่ละส่วนเป็นการ์ดของตัวเอง · หัวข้อเป็นแถบสีอ่อนเต็มความกว้าง + เลขวงกลมสีหลัก — เห็นทันทีว่าฟอร์มแบ่งเป็นกี่ส่วน
   การ์ดฟอร์มชั้นนอกโปร่งใสเมื่อมีส่วนอยู่ข้างใน (ไม่ให้กรอบซ้อนกรอบ) */
.card:is(.form-card-app, .form-card):has(> .form-section, > fieldset.plain > .form-section) { background: none; border: 0; box-shadow: none; padding: 0; }
:is(.form-card-app, .form-card) .form-section {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 0 24px 22px; overflow: clip;
}
:is(.form-card-app, .form-card) .form-section:first-child { padding-top: 0; }
:is(.form-card-app, .form-card) .form-section:not(:first-of-type) { margin-top: 16px; }
:is(.form-card-app, .form-card) .form-section > legend {
  width: calc(100% + 48px); margin: 0 -24px 18px; padding: 12px 24px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: var(--fs-stat); font-weight: 600; color: var(--text);
}
:is(.form-card-app, .form-card) .legend-no { width: 28px; height: 28px; flex: none; background: var(--accent); color: var(--on-accent); font-size: var(--fs-ui); }
:is(.form-card-app, .form-card) > .step-note, .form-card-app > fieldset.plain > .step-note { margin: 0 0 14px; }
:is(.form-card-app, .form-card) > .alert:first-of-type { margin-bottom: 16px; }
:is(.form-card-app, .form-card) .form-section + .form-actions, .form-card-app fieldset.plain > .form-actions { margin-top: 18px; }
@media (max-width: 767.98px) {
  :is(.form-card-app, .form-card) .form-section { padding: 0 16px 18px; }
  :is(.form-card-app, .form-card) .form-section > legend { width: calc(100% + 32px); margin: 0 -16px 16px; padding: 11px 16px; font-size: var(--fs-card-title); }
}

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.span-2 { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-bottom: 0; }
.form-section > .field + .field, .form-section > [data-legacy-box] + .field, .form-section > .field + [data-legacy-box] { margin-top: 16px; }
.field label, .field .label { font-size: var(--fs-ui); font-weight: 500; color: var(--text); }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.req { color: var(--bad-text); margin-left: 2px; }
.opt { color: var(--text-3); font-weight: 400; font-size: var(--fs-meta); margin-left: 4px; }

.input-wrap { position: relative; }
.input-wrap input, .input-wrap select, .field textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); font-size: var(--fs-body);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field textarea { min-height: 104px; resize: vertical; line-height: 1.6; }
.input-wrap.has-icon input, .input-wrap.has-icon select { padding-left: 40px; }
.input-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-3); pointer-events: none; }
.select-wrap select { appearance: none; padding-right: 36px; cursor: pointer; }
.select-chev { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-3); pointer-events: none; }
.input-wrap input::placeholder, .field textarea::placeholder { color: var(--text-3); }
.input-wrap input:hover, .input-wrap select:hover, .field textarea:hover { border-color: var(--text-3); }
.input-wrap input:focus, .input-wrap select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
.has-action input { padding-right: 46px; }
.input-action {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border: 0; border-radius: 8px;
  display: grid; place-items: center; background: transparent; color: var(--text-3);
}
.input-action:hover { background: var(--hover); color: var(--text); }
.input-action .i { width: 18px; height: 18px; }
.input-action .i-hide { display: none; }
.input-action[aria-pressed="true"] .i-show { display: none; }
.input-action[aria-pressed="true"] .i-hide { display: block; }

.help { font-size: var(--fs-meta); color: var(--text-3); line-height: 1.5; }
.help-right { text-align: right; min-height: 1.5em; }
.error { display: flex; align-items: flex-start; gap: 6px; font-size: var(--fs-meta); color: var(--bad-text); line-height: 1.5; }
.error .i { width: 15px; height: 15px; margin-top: 2px; }
.has-error .input-wrap input, .has-error .input-wrap select, .has-error textarea { border-color: var(--bad-text); }
.has-error .input-wrap input:focus, .has-error .input-wrap select:focus, .has-error textarea:focus { box-shadow: 0 0 0 3px var(--bad-soft); }

.choice-row { display: flex; flex-wrap: wrap; gap: 10px; }
.choice, .check { display: inline-flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.choice {
  min-height: 42px; align-items: center; padding: 8px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
  font-size: var(--fs-ui);
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.choice input, .check input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); }
.check { line-height: 1.6; color: var(--text-2); }
.check input { margin-top: 3px; }
.check-sm { font-size: var(--fs-ui); margin: 14px 0 18px; }

.consent { margin-top: 20px; padding: 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.consent.has-error { border-color: var(--bad-text); background: var(--bad-soft); }
.consent .error { margin-top: 8px; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 22px; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.alert {
  display: flex; gap: 12px; align-items: flex-start;
  margin-top: 20px; padding: 14px 16px; border-radius: var(--radius);
  font-size: var(--fs-ui); line-height: 1.55;
}
.alert .i { width: 20px; height: 20px; margin-top: 1px; }
.alert div { display: grid; gap: 2px; }
.alert b { font-weight: 600; }
.alert-bad { background: var(--bad-soft); color: var(--bad-text); }
.alert-info { background: var(--accent-soft); color: var(--accent-text); margin: 0 0 18px; }
.alert:focus { outline: 2px solid currentColor; outline-offset: 2px; }

/* ---------- Responsive (ส่วนที่ใช้ร่วมกัน) ---------- */
@media (max-width: 767px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  /* iOS ซูมหน้าเมื่อช่องกรอกเล็กกว่า 16px */
  .input-wrap input, .input-wrap select, .field textarea { font-size: 16px; }
}
@media (max-width: 480px) {
  .form-actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
