/* ==========================================================================
   SARA — หน้าเข้าสู่ระบบ: แบ่งครึ่งจอ (ภาพ | ฟอร์ม) แนวทางการ ทันสมัย
   ========================================================================== */
.lx-body { background: #fff; color-scheme: light; }
.lg {
  --brand: #1D4ED8;
  min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(400px, 1fr);
  color: #1F2937; font-family: var(--font-body);
}

/* ---------- ฝั่งซ้าย ---------- */
.lg-art {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 2rem;
  padding: 2.25rem 3rem 2.5rem; color: #fff; background-color: #0B2559; background-size: cover; background-position: center;
  /* วงกลมพื้นหลัง (สีทึบ ไม่เรือง) */
  background-image:
    radial-gradient(circle at 88% 12%, #143474 0 170px, transparent 171px),
    radial-gradient(circle at 6% 96%, #10306B 0 220px, transparent 221px);
}
.lg-art.has-img { background-size: cover; }
.lg-art.has-img::before { content: ""; position: absolute; inset: 0; background: rgba(11, 37, 89, .78); }
.lg-art > * { position: relative; z-index: 1; }

.lg-art-top { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.lg-art-mark { width: 42px; height: 42px; border-radius: 11px; background: #fff; display: grid; place-items: center; padding: 3px; flex: none; }
.lg-art-mark img { width: 100%; height: 100%; object-fit: contain; }
.lg-art-brand { font-family: var(--font-head); font-weight: 700; font-size: 1.3rem; letter-spacing: .08em; }
.lg-art-chip { font-size: .85rem; padding: .3rem .8rem; border-radius: 999px; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18); color: #E7EDFA; }

.lg-art-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, .8fr); gap: 2rem; align-items: center; }
.lg-art-title { font-family: var(--font-head); font-weight: 700; color: #fff; font-size: clamp(1.6rem, 1.1rem + 1.4vw, 2.35rem); line-height: 1.3; margin: 0; }
.lg-art-en { color: #AFC0E2; margin: .5rem 0 1.75rem; font-size: 1rem; letter-spacing: .01em; }
.lg-feats { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; }
.lg-feats li { display: flex; gap: .85rem; align-items: flex-start; }
.lg-feats b { display: block; font-weight: 600; font-size: 1rem; color: #fff; }
.lg-feats small { display: block; color: #AFC0E2; font-size: .88rem; margin-top: .1rem; }
.fi { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 1.1rem; color: #fff; }
.fi-blue { background: #2563EB; }
.fi-gold { background: #F5B301; color: #0B2559; }
.fi-green { background: #16A34A; }
.lg-art-visual { width: 100%; max-width: 360px; height: auto; justify-self: center; }

.lg-steps { list-style: none; margin: 0; padding: 1.1rem 1.25rem; display: flex; justify-content: space-between; gap: .5rem; border-radius: 14px; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .1); counter-reset: none; }
.lg-steps li { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: .4rem; font-size: .84rem; color: #DCE4F5; text-align: center; white-space: nowrap; }
.lg-steps li span { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #fff; color: #0B2559; font-weight: 700; font-size: .85rem; position: relative; z-index: 1; }
.lg-steps li:last-child span { background: #F5B301; }
.lg-steps li:not(:last-child)::after { content: ""; position: absolute; top: 15px; left: calc(50% + 18px); right: calc(-50% + 18px); height: 2px; background: rgba(255, 255, 255, .25); }

@media (max-width: 1250px) {
  .lg-art-body { grid-template-columns: 1fr; }
  .lg-art-visual { max-width: 260px; order: -1; }
}
@media (max-width: 900px) {
  .lg-art:not(.has-img) { display: none; }
  .lg-art.has-img { padding: 1.25rem; min-height: 170px; gap: 1rem; }
  .lg-art.has-img .lg-feats, .lg-art.has-img .lg-art-visual, .lg-art.has-img .lg-steps, .lg-art.has-img .lg-art-chip { display: none; }
  .lg-art.has-img .lg-art-title { font-size: 1.2rem; }
  .lg-art.has-img .lg-art-en { margin-bottom: 0; font-size: .82rem; }
}

/* ---------- ฟอร์มด้านขวา ---------- */
.lg-side { display: flex; align-items: center; justify-content: center; padding: 2.5rem 1.5rem; background: #fff; }
.lg-box { width: 100%; max-width: 380px; }
.lg-brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 2.25rem; }
.lg-mark { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; background: var(--brand); color: #fff; font-family: var(--font-head); font-weight: 700; font-size: 1.3rem; flex: none; transition: background .3s; }
.lg-name { font-family: var(--font-head); font-weight: 700; font-size: 1.3rem; letter-spacing: .05em; line-height: 1.1; color: #0B2559; }
.lg-sub { font-size: .84rem; color: #6B7280; line-height: 1.35; }
.lg-title { font-family: var(--font-head); font-size: 1.75rem; font-weight: 700; margin: 0 0 .25rem; color: #111827; }
.lg-hint { color: #6B7280; margin: 0 0 1.5rem; }

.lg-label { display: block; font-weight: 600; font-size: .92rem; margin: 0 0 .35rem; color: #374151; }
.lg-input {
  display: block; width: 100%; height: 50px; padding: 0 .95rem; margin-bottom: 1.05rem; border: 1px solid #D1D7E2; border-radius: 10px;
  background: #fff; color: #111827; font-size: 1.02rem; font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
select.lg-input { appearance: none; -webkit-appearance: none; padding-right: 2.5rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%236B7280' stroke-width='2' d='M3 6l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .95rem center; }
.lg-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.lg-pw { position: relative; }
.lg-pw .lg-input { padding-right: 3rem; }
.lg-pw button { position: absolute; right: .35rem; top: 5px; width: 40px; height: 40px; border: 0; background: none; color: #6B7280; border-radius: 8px; }
.lg-pw button:hover { background: #F3F4F6; color: #111827; }
.lg-caps { display: block; margin: -.6rem 0 .8rem; color: #B45309; font-size: .85rem; }
.lg-btn {
  width: 100%; height: 50px; margin-top: .35rem; border: 0; border-radius: 10px; background: var(--brand); color: #fff;
  font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; cursor: pointer; transition: filter .15s, background .3s;
}
.lg-btn:hover { filter: brightness(.92); }
.lg-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 2px; }
.lg-btn:disabled { opacity: .75; }
.lg-btn .spinner-border { width: 1rem; height: 1rem; margin-right: .4rem; }

.lg-alert { display: flex; gap: .55rem; align-items: flex-start; padding: .7rem .85rem; border-radius: 10px; margin-bottom: 1rem; font-size: .92rem; }
.lg-alert-danger { background: #FEF2F2; color: #B42318; border: 1px solid #FECACA; }
.lg-alert-warning { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }
.lg-alert-success, .lg-alert-info { background: #ECFDF3; color: #067647; border: 1px solid #ABEFC6; }

.lg-test { margin-top: 1.25rem; font-size: .88rem; color: #4B5563; }
.lg-test summary { cursor: pointer; color: #6B7280; text-align: center; list-style: none; }
.lg-test summary::-webkit-details-marker { display: none; }
.lg-test summary::after { content: " ▾"; }
.lg-test[open] summary::after { content: " ▴"; }
.lg-test p { margin: .6rem 0; text-align: center; }
.lg-test code { background: #EEF2F7; padding: .1rem .35rem; border-radius: 5px; color: #111827; }
.lg-test-list { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; }
.lg-test-list button { border: 1px solid #E5E9F0; background: #fff; border-radius: 8px; padding: .4rem .55rem; text-align: left; font-size: .85rem; color: #1F2937; }
.lg-test-list button:hover { border-color: var(--brand); }
.lg-test-list span { display: block; color: #8A94A6; font-size: .75rem; font-family: ui-monospace, monospace; }
.lg-foot { text-align: center; color: #9AA3B2; font-size: .78rem; margin: 1.5rem 0 0; }

/* มือถือ/แท็บเล็ต: ภาพเป็นแถบด้านบน */
@media (max-width: 900px) {
  .lg { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .lg-side { align-items: flex-start; padding: 1.75rem 1.25rem 2rem; }
  .lg-brand { margin-bottom: 1.5rem; }
}
@media (max-width: 480px) {
  .lg-test-list { grid-template-columns: 1fr; }
}

/* โลโก้ระบบ */
.lg-logo { display: block; width: 150px; max-width: 50%; height: auto; margin: 0 auto 1.5rem; }
@media (max-width: 900px) { .lg-logo { width: 120px; margin-bottom: 1rem; } }

/* ---------- มือถือ: แถบหัวน้ำเงิน + การ์ดฟอร์ม ---------- */
.lg-m-head, .lg-m-feats { display: none; }
@media (max-width: 900px) {
  .lx-body { background: #F4F6F9; }
  .lg-side {
    position: relative; padding: 0 1rem 2rem; align-items: flex-start; background: #F4F6F9;
  }
  .lg-side::before { /* แถบหัวน้ำเงิน */
    content: ""; position: absolute; left: 0; right: 0; top: 0; height: 250px; background-color: #0B2559;
  }
  .lg-box { position: relative; z-index: 1; }
  .lg-box { max-width: 460px; }
  .lg-logo { display: none; }
  .lg-m-head { display: block; text-align: center; color: #fff; padding: 1.6rem .5rem 1.4rem; }
  .lg-m-logo { width: 64px; height: 64px; margin: 0 auto .6rem; border-radius: 16px; background: #fff; display: grid; place-items: center; padding: 5px; box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .4); }
  .lg-m-logo img { width: 100%; height: 100%; object-fit: contain; }
  .lg-m-name { font-family: var(--font-head); font-weight: 700; font-size: 1.35rem; letter-spacing: .1em; }
  .lg-m-th { font-size: .92rem; color: #E1E8F7; margin-top: .15rem; line-height: 1.4; }
  .lg-m-en { font-size: .75rem; color: #9FB2DA; margin-top: .1rem; }
  .lg-card { background: #fff; border: 1px solid #E5E9F0; border-radius: 16px; padding: 1.4rem 1.25rem; box-shadow: 0 10px 30px -14px rgba(11, 37, 89, .35); }
  .lg-title { font-size: 1.45rem; }
  .lg-hint { margin-bottom: 1.1rem; font-size: .92rem; }
  .lg-m-feats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; list-style: none; padding: 0; margin: 1.1rem 0 0; }
  .lg-m-feats li { background: #fff; border: 1px solid #E5E9F0; border-radius: 12px; padding: .75rem .4rem; text-align: center; font-size: .78rem; line-height: 1.35; color: #374151; }
  .lg-m-feats .fi { width: 34px; height: 34px; font-size: .95rem; margin: 0 auto .45rem; }
}

/* ---------- พอดีทุกขนาดจอ (Desktop): ปรับตามความกว้างและความสูงของจอ ไม่ให้ล้นจนต้องเลื่อน ---------- */
@media (min-width: 901px) {
  .lg { height: 100vh; height: 100dvh; min-height: 0; }
  .lg-art, .lg-side { min-height: 0; overflow-y: auto; scrollbar-width: none; }
  .lg-art::-webkit-scrollbar, .lg-side::-webkit-scrollbar { display: none; }
  .lg-art-body { grid-template-columns: minmax(0, 1.4fr) minmax(180px, .6fr); }
  .lg-art-title { font-size: clamp(1.5rem, .9rem + 1.1vw, 2.35rem); }
  .lg-art-visual { max-height: 34vh; }
}
@media (min-width: 901px) and (max-width: 1250px) {
  .lg-art-body { grid-template-columns: 1fr; align-content: center; }
  .lg-art-visual { max-height: 22vh; }
}
/* จอเตี้ย เช่น โน้ตบุ๊ก 1366×768 */
@media (min-width: 901px) and (max-height: 820px) {
  .lg-art { padding: 1.5rem 2.5rem 1.75rem; gap: 1.25rem; }
  .lg-art-en { margin-bottom: 1.1rem; }
  .lg-feats { gap: .7rem; }
  .fi { width: 36px; height: 36px; font-size: 1rem; }
  .lg-steps { padding: .8rem 1rem; }
  .lg-side { padding: 1.5rem; }
  .lg-logo { width: 120px; margin-bottom: 1rem; }
  .lg-hint { margin-bottom: 1.1rem; }
  .lg-input, .lg-btn { height: 46px; }
  .lg-input { margin-bottom: .85rem; }
  .lg-pw button { top: 3px; }
  .lg-foot { margin-top: 1rem; }
}
/* จอเตี้ยมาก (≤ 680px) — เหลือเฉพาะสาระสำคัญ */
@media (min-width: 901px) and (max-height: 680px) {
  .lg-art-visual, .lg-steps { display: none; }
  .lg-art-body { grid-template-columns: 1fr; }
  .lg-feats small { display: none; }
  .lg-logo { width: 84px; margin-bottom: .6rem; }
  .lg-title { font-size: 1.5rem; }
  .lg-hint { margin-bottom: .8rem; font-size: .92rem; }
  .lg-label { margin-bottom: .25rem; }
  .lg-input, .lg-btn { height: 42px; }
  .lg-input { margin-bottom: .7rem; }
  .lg-pw button { top: 1px; }
  .lg-test { margin-top: .8rem; }
}

/* ---------- Effect หน้าเข้าสู่ระบบ: จางเข้าครั้งเดียว · ไม่มี loop · ไม่ใช้ transform กับตัวอักษร (เต้นบน Safari) · แสงเรืองนิ่งอยู่มุมจอ เพราะโลโก้เป็นภาพพื้นขาว ---------- */
.lg-input:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 16%, transparent); }
.lg-art::after {
  content: ""; position: absolute; z-index: 0; pointer-events: none; left: -12%; bottom: -30%; width: 70%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 132, 255, .34), rgba(124, 58, 237, .12) 48%, transparent 70%);
}
@media (min-width: 901px) {
  .lg-side { position: relative; overflow-x: hidden; }
  .lg-side::before {
    content: ""; position: absolute; pointer-events: none; top: -130px; right: -130px; width: 340px; height: 340px; border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--brand) 12%, transparent), transparent 68%);
  }
  .lg-box { position: relative; z-index: 1; }
}
@media (max-width: 900px) {
  .lg-side::before { background-image: linear-gradient(120deg, #0B2559, #1D4ED8 60%, #0B2559); }
}

@media (prefers-reduced-motion: no-preference) {
  .lg-art-copy, .lg-art-top, .lg-art-visual, .lg-steps, .lg-box { animation: lg-fade .5s ease-out backwards; }
  .lg-alert-danger { animation: lg-shake .35s ease-in-out .1s backwards; }
  .lg-btn { transition: filter .15s, background .3s; }
}
@keyframes lg-fade { from { opacity: 0; } }
@keyframes lg-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 50% { transform: translateX(4px); } 75% { transform: translateX(-2px); } }

/* ---------- มือถือ: พื้นสีเต็มจอ + การ์ดขาวกลางจอ ----------
   สีไล่จากน้ำเงินไปฟ้าตามโลโก้ · วงแหวนมุมจอมาจากตราประทับ · แถบล่างคือเส้นทางหนังสือ 6 ขั้น · ไม่มีอะไรเคลื่อนไหว
   ความสูงจอกำหนดว่าแสดงอะไร เพื่อให้พอดีจอเดียวเสมอ */
.lg-m-route { display: none; }
@media (max-width: 900px), (orientation: landscape) and (max-height: 520px) {
  :root { --m-top: #0F2F8F; --m-mid: #1D4ED8; --m-low: #0B7FB0; --m-gold: #F5B301; --m-ink: #10204A; --m-field: #F3F6FD; --m-line: #DCE4F5; }
  html, .lx-body { background: var(--m-top); }
  .lg { min-height: 100vh; min-height: 100dvh; grid-template-rows: 1fr; }
  .lg-art, .lg-art.has-img, .lg-m-feats { display: none; }

  .lg-side {
    position: relative; overflow: hidden; align-items: center; justify-content: center;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    background:
      radial-gradient(circle at 92% 4%, rgba(56, 189, 248, .5), transparent 42%),
      radial-gradient(circle at 4% 96%, rgba(34, 211, 238, .38), transparent 42%),
      linear-gradient(168deg, var(--m-top) 0%, var(--m-mid) 52%, var(--m-low) 100%);
  }
  .lg-side::before, .lg-side::after { /* วงแหวนตราประทับ */
    content: ""; position: absolute; z-index: 0; width: 240px; height: 240px; border-radius: 50%; pointer-events: none;
    background: none; border: 1px solid rgba(255, 255, 255, .2);
    box-shadow: 0 0 0 26px rgba(255, 255, 255, .04), 0 0 0 27px rgba(255, 255, 255, .13), 0 0 0 64px rgba(255, 255, 255, .03);
  }
  .lg-side::before { top: -112px; right: -92px; height: 240px; }
  .lg-side::after { bottom: -128px; left: -104px; }

  .lg-box { position: relative; z-index: 1; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: .85rem; }
  .lg-m-head { padding: 0; }
  .lg-m-logo { width: 62px; height: 62px; margin: 0 auto .5rem; border-radius: 18px; padding: 5px; box-shadow: 0 0 0 5px rgba(255, 255, 255, .16), 0 12px 24px -10px rgba(5, 15, 60, .6); }
  .lg-m-name { font-size: 1.3rem; line-height: 1.2; letter-spacing: .16em; text-indent: .16em; }
  .lg-m-th { font-size: .8rem; margin-top: .1rem; line-height: 1.35; color: #EAF1FF; text-wrap: balance; }
  .lg-m-en { display: block; font-size: .7rem; line-height: 1.3; margin-top: .15rem; letter-spacing: .03em; color: #C7D7F7; text-wrap: balance; }

  .lg-card { padding: 1.3rem 1.25rem 1.35rem; border: 0; border-radius: 22px; box-shadow: 0 24px 48px -22px rgba(5, 15, 60, .75); }
  .lg-title { font-size: 1.4rem; line-height: 1.3; text-align: center; color: var(--m-ink); margin: 0; }
  .lg-hint { margin: .05rem 0 .95rem; font-size: .84rem; text-align: center; }
  .lg-label { margin-bottom: .22rem; font-size: .85rem; color: var(--m-ink); }
  .lg-input {
    height: 47px; margin-bottom: .7rem; padding-left: 2.6rem; border-color: var(--m-line); border-radius: 13px; background-color: var(--m-field);
    background-repeat: no-repeat; background-position: .85rem center; background-size: 18px;
  }
  .lg-input:focus { background-color: #fff; }
  #username { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%231D4ED8'%3E%3Cpath d='M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm-5 6s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3Z'/%3E%3C/svg%3E"); }
  #password { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%231D4ED8'%3E%3Cpath d='M8 1a3 3 0 0 0-3 3v3H4a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V8a1 1 0 0 0-1-1h-1V4a3 3 0 0 0-3-3Zm2 6H6V4a2 2 0 1 1 4 0v3Z'/%3E%3C/svg%3E"); }
  select#school {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%231D4ED8'%3E%3Cpath d='M8 1 1 4.5v1h14v-1L8 1ZM2.5 6.5V13H1v2h14v-2h-1.5V6.5h-2V13h-1.5V6.5h-2V13H7.5V6.5h-2V13H4V6.5H2.5Z'/%3E%3C/svg%3E"), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%236B7280' stroke-width='2' d='M3 6l5 5 5-5'/%3E%3C/svg%3E");
    background-position: .85rem center, right .95rem center; background-size: 18px, 12px;
  }
  .lg-pw button { top: 3px; color: #5B6B8F; }
  .lg-caps { margin: -.35rem 0 .6rem; }
  .lg-btn {
    height: 49px; margin-top: .3rem; border-radius: 14px;
    background: linear-gradient(100deg, var(--brand), color-mix(in srgb, var(--brand) 62%, #0B7FB0));
    box-shadow: 0 12px 22px -12px var(--brand);
  }
  .lg-foot { margin: 0; color: rgba(255, 255, 255, .86); }
  .lg-foot a { color: #fff; }
  .lg-test { color: #fff; } .lg-test summary { color: rgba(255, 255, 255, .86); } .lg-test code { background: rgba(255, 255, 255, .92); }
}
/* จอสูง: เพิ่มเส้นทางหนังสือ ใช้พื้นที่ที่เหลือให้สมดุล */
@media (max-width: 900px) and (min-height: 780px) {
  .lg-box { gap: 1.1rem; }
  .lg-m-logo { width: 70px; height: 70px; }
}
@media (max-width: 900px) and (orientation: portrait) and (min-height: 680px) {
  .lg-m-route {
    display: flex; justify-content: space-between; list-style: none; margin: 0; padding: .7rem .55rem .6rem; border-radius: 16px;
    background: rgba(255, 255, 255, .13); border: 1px solid rgba(255, 255, 255, .22);
  }
  .lg-m-route li { position: relative; flex: 1 1 0; min-width: 0; padding-top: 1.05rem; text-align: center; font-size: .66rem; line-height: 1.2; color: #fff; white-space: nowrap; }
  .lg-m-route li::before { content: ""; position: absolute; z-index: 1; top: 0; left: 50%; width: 11px; height: 11px; margin-left: -5.5px; border-radius: 50%; background: #fff; }
  .lg-m-route li:last-child::before { background: var(--m-gold); }
  .lg-m-route li:not(:last-child)::after { content: ""; position: absolute; top: 5px; left: 50%; width: 100%; height: 1px; background: rgba(255, 255, 255, .5); }
}
/* จอเตี้ยมาก เช่น iPhone SE ใน Safari */
@media (max-width: 900px) and (max-height: 620px), (orientation: landscape) and (max-height: 520px) {
  .lg-box { gap: .55rem; }
  .lg-m-head { display: flex; align-items: center; justify-content: center; gap: .55rem; }
  .lg-m-logo { width: 36px; height: 36px; margin: 0; border-radius: 10px; padding: 3px; box-shadow: none; }
  .lg-m-th, .lg-m-en, .lg-hint, .lg-foot { display: none; }
  .lg-card { padding: .9rem 1rem 1rem; }
  .lg-title { font-size: 1.15rem; margin-bottom: .45rem; }
  .lg-input { height: 42px; margin-bottom: .5rem; }
  .lg-btn { height: 44px; }
  .lg-pw button { top: 1px; }
}
/* จอสูงพอ: ขยายการ์ดบนล่างให้โปร่งขึ้น */
@media (max-width: 900px) and (min-height: 680px) {
  .lg-card { padding: 1.9rem 1.25rem 2rem; }
  .lg-title { font-size: 1.55rem; }
  .lg-hint { margin-bottom: 1.25rem; font-size: .88rem; }
  .lg-label { margin-bottom: .3rem; }
  .lg-input { height: 52px; margin-bottom: .95rem; }
  .lg-pw button { top: 6px; }
  .lg-btn { height: 54px; margin-top: .55rem; font-size: 1.1rem; }
}
@media (max-width: 340px) { .lg-m-route { display: none !important; } } /* จอแคบ: ชื่อขั้นตอนไม่พอพื้นที่ */

/* ---------- มือถือแนวนอน: โลโก้ซ้าย การ์ดขวา ชื่อผู้ใช้กับรหัสผ่านคู่กัน ให้พอดีจอเดียว ----------
   เผื่อขอบซ้ายขวาให้ Dynamic Island ด้วย safe-area */
@media (orientation: landscape) and (max-height: 520px) {
  .lg { display: block; height: auto; min-height: 100vh; min-height: 100dvh; }
  .lg-side { min-height: 100vh; min-height: 100dvh; overflow: hidden; padding: max(.6rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(.6rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left)); }
  .lg-box { max-width: 860px; display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); align-items: center; gap: 1.5rem; }
  .lg-logo, .lg-m-route, .lg-m-feats, .lg-foot, .lg-hint { display: none; }
  .lg-m-head { display: block; grid-column: 1; text-align: center; color: #fff; }
  .lg-m-logo { display: grid; place-items: center; width: 72px; height: 72px; margin: 0 auto .5rem; border-radius: 20px; padding: 6px; background: #fff; box-shadow: 0 0 0 5px rgba(255, 255, 255, .16); }
  .lg-m-logo img { width: 100%; height: 100%; object-fit: contain; }
  .lg-m-name { font-family: var(--font-head); font-weight: 700; font-size: 1.35rem; }
  .lg-m-th { display: block; font-size: .8rem; }
  .lg-m-en { display: none; }
  .lg-card { grid-column: 2; background: #fff; padding: .85rem 1.1rem 1rem; border-radius: 20px; }
  .lg-title { font-size: 1.15rem; margin-bottom: .4rem; }
  #loginForm { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: .7rem; }
  #loginForm > label[for="school"], #loginForm > .lg-school, #loginForm > .lg-caps, #loginForm > .lg-actions { grid-column: 1 / -1; }
  #loginForm > label[for="username"] { grid-column: 1; grid-row: 3; }
  #loginForm > label[for="password"] { grid-column: 2; grid-row: 3; }
  #loginForm > #username { grid-column: 1; grid-row: 4; }
  #loginForm > .lg-pw { grid-column: 2; grid-row: 4; }
  .lg-label { font-size: .8rem; margin-bottom: .12rem; }
  .lg-input { height: 40px; margin-bottom: .45rem; }
  .lg-pw button { top: 0; }
  .lg-btn { height: 42px; margin-top: .1rem; }
}

/* มือถือจอเตี้ย: ย่อส่วนหัวและระยะ ให้พอดีจอเดียวแม้มีกล่องข้อความแจ้ง */
@media (max-width: 900px) and (min-height: 621px) and (max-height: 760px) {
  .lg-m-logo { width: 46px; height: 46px; margin-bottom: .3rem; border-radius: 13px; padding: 3px; box-shadow: 0 0 0 3px rgba(255, 255, 255, .16); }
  .lg-m-name { font-size: 1.1rem; }
  .lg-m-th { font-size: .74rem; }
  .lg-m-en { font-size: .64rem; margin-top: 0; }
  .lg-card { padding: .85rem 1rem .95rem; }
  .lg-title { font-size: 1.3rem; }
  .lg-hint { margin-bottom: .5rem; font-size: .84rem; }
  .lg-alert { padding: .4rem .7rem; margin-bottom: .5rem; }
  .lg-label { margin-bottom: .15rem; }
  .lg-input, .lg-btn { height: 42px; }
  .lg-input { margin-bottom: .45rem; }
  .lg-pw button { top: 1px; }
  .lg-foot { margin-top: .35rem; }
}

/* มือถือแนวตั้ง: ส่วนหัวแบบแนวนอน โลโก้ซ้าย ตัวอักษรขวา ชิดซ้ายแนวเดียวกัน */
@media (max-width: 900px) and (orientation: portrait) and (min-height: 621px) {
  .lg-m-head { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: .8rem; align-items: center; width: fit-content; max-width: 100%; margin-inline: auto; text-align: left; }
  .lg-m-logo { grid-row: 1 / span 3; width: 60px; height: 60px; margin: 0; border-radius: 16px; padding: 4px; box-shadow: 0 0 0 2px rgba(255, 255, 255, .18), 0 10px 20px -10px rgba(5, 15, 60, .6); }
  .lg-m-name, .lg-m-th, .lg-m-en { grid-column: 2; }
  .lg-m-name { font-size: 1.3rem; line-height: 1.15; letter-spacing: .06em; text-indent: 0; }
  .lg-m-th { font-size: .76rem; line-height: 1.3; margin-top: .1rem; text-wrap: pretty; }
  .lg-m-en { font-size: .66rem; margin-top: .05rem; letter-spacing: .01em; }
  .lg-side::before, .lg-side::after { opacity: .5; } /* วงแหวนพื้นหลังจางลง ไม่รบกวนตัวอักษร */
}
@media (max-width: 900px) and (orientation: portrait) and (min-height: 621px) and (max-height: 760px) {
  .lg-m-logo { width: 50px; height: 50px; border-radius: 13px; padding: 3px; }
  .lg-m-name { font-size: 1.1rem; }
  .lg-m-th { font-size: .72rem; }
  .lg-m-en { font-size: .62rem; }
}

/* ปุ่มล้างข้างปุ่มเข้าสู่ระบบ */
.lg-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2.2fr); gap: .6rem; }
.lg-actions .lg-btn { width: 100%; }
.lg-btn.lg-btn-clear { background: #EEF2FB; background-image: none; color: #1F2A44; border: 1px solid #DCE4F5; box-shadow: none; }
.lg-btn.lg-btn-clear:hover { background: #E2E8F5; filter: none; }

/* มือถือแนวตั้ง: การ์ดสูงขึ้น เว้นระยะจากส่วนหัว */
@media (max-width: 900px) and (orientation: portrait) and (min-height: 761px) {
  .lg-box { gap: 1.1rem; }
  .lg-card { padding-block: 2.5rem 2.6rem; }
}
@media (max-width: 900px) and (orientation: portrait) and (min-height: 621px) and (max-height: 760px) {
  .lg-box { gap: 1rem; }
  .lg-card { padding-block: 1.5rem 1.6rem; }
  .lg-input, .lg-btn { height: 46px; }
  .lg-input { margin-bottom: .6rem; }
  .lg-pw button { top: 3px; }
}

/* ชื่อ Sara แบบลายมือหางยาว (Great Vibes, SIL OFL) เฉพาะส่วนหัวมือถือ */
@font-face { font-family: "Great Vibes"; font-weight: 400; font-display: swap; src: url("../fonts/great-vibes/great-vibes-latin-400-normal.woff") format("woff"); }
@media (max-width: 900px), (orientation: landscape) and (max-height: 520px) {
  .lg-m-name {
    position: relative; display: inline-block; justify-self: start; font-family: "Great Vibes", var(--font-head); font-weight: 400; font-synthesis: none;
    font-size: 2.3rem; line-height: 1.05; letter-spacing: 0; text-indent: 0;
  }
  .lg-m-name::after { content: ""; position: absolute; left: 100%; top: .025em; width: 1.8em; height: 1em; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1800 1000'%3E%3Cpath fill='%23fff' d='M63 559L73 543L83 526L94 508L106 490L119 471L134 453L150 435L167 419L185 403L205 389L227 376L250 366L276 357L303 351L335 349L367 351L400 357L435 366L472 379L510 393L551 409L594 425L640 441L689 456L741 469L797 478L857 485L920 486L982 483L1043 474L1105 461L1166 444L1227 423L1288 399L1348 373L1407 344L1465 314L1523 282L1579 249L1634 216L1688 183L1740 150L1740 150L1688 182L1633 214L1577 246L1520 276L1462 306L1402 334L1342 360L1282 383L1221 404L1160 422L1099 436L1039 446L979 452L920 454L859 451L802 444L749 433L699 420L652 406L607 390L564 374L523 359L484 344L446 332L408 322L371 316L334 315L297 319L267 326L239 337L213 350L189 365L168 382L149 400L131 419L115 439L102 459L89 479L78 499L68 518L60 536L53 553Z'/%3E%3C/svg%3E") no-repeat left top / 100% 100%; pointer-events: none; } /* หางเริ่มจากปลายตัว a ตามทิศเส้นเดิม แล้วเรียวไปจนสุด */
}
@media (max-width: 900px) and (orientation: portrait) and (min-height: 621px) {
  .lg-m-name { font-size: 2.3rem; line-height: 1.05; letter-spacing: 0; }
}
@media (max-width: 900px) and (orientation: portrait) and (min-height: 621px) and (max-height: 760px) {
  .lg-m-name { font-size: 2rem; }
}
@media (max-width: 900px) and (max-height: 620px) {
  .lg-m-name { font-size: 1.7rem; }
  .lg-m-name::after { display: none; } /* จอเล็กมาก: ไม่พอให้เส้นหาง */
}

/* มือถือแนวตั้ง: การ์ดสูงขึ้นอีก · มีกล่องแจ้งเตือนให้ซ่อนเส้นทางหนังสือชั่วคราวเพื่อให้พอดีจอ */
@media (max-width: 900px) and (orientation: portrait) and (min-height: 761px) {
  .lg-card { padding-block: 3rem 3.1rem; }
}
@media (max-width: 900px) and (orientation: portrait) and (min-height: 680px) and (max-height: 760px) {
  .lg-card { padding-block: 1.85rem 1.95rem; }
}
@media (max-width: 900px) and (orientation: portrait) {
  .lg-box:has(.lg-alert) .lg-m-route { display: none; }
}

/* รายการเลือกโรงเรียนบนมือถือ: ชื่อบรรทัดเดียว */
.lg-school { position: relative; }
.lg-school.has-picker select { pointer-events: none; }
.lg-school.is-open select { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.lg-school-panel { position: absolute; z-index: 20; left: 0; right: 0; padding: .3rem; background: #fff; border: 1px solid #DCE4F5; border-radius: 13px; box-shadow: 0 16px 30px -14px rgba(5, 15, 60, .55); }
.lg-school-search { display: block; width: 100%; height: 42px; margin-bottom: .3rem; padding: 0 .75rem; border: 1px solid #DCE4F5; border-radius: 9px; background: #F3F6FD; color: #1F2A44; font: inherit; font-size: 16px; outline: none; } /* 16px กัน iPhone ซูมเอง */
.lg-school-search:focus { border-color: var(--brand); background: #fff; }
.lg-school-menu { max-height: min(40vh, 16rem); overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.lg-school-empty { margin: 0; padding: .7rem .75rem; color: #64748B; font-size: .92rem; }
.lg-school-menu li { padding: .7rem .75rem; border-radius: 9px; color: #1F2A44; font-size: .98rem; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.lg-school-menu li[aria-selected="true"] { background: #EAF0FD; color: #1D4ED8; font-weight: 600; }
.lg-school-menu li[hidden] { display: none; }
