/* ============================================================================
   login-brand.css — หน้าเข้าสู่ระบบ (Emerald + Deep Green + Mint)
   โหลดหลัง <style> เดิมในหน้า จึงทับค่าเดิมได้โดยไม่ต้องแก้ตรรกะ/ฟอร์ม
   เบา: ไม่มี JS/ไลบรารี/canvas — พื้นหลังเป็น CSS ไล่สีอย่างเดียว + แอนิเมชันเข้าฉากสั้นๆ (ปิดเองเมื่อผู้ใช้ตั้งลดการเคลื่อนไหว)
   ============================================================================ */
:root {
  --primary: #059669;
  --primary-hover: #047857;
  --accent: #34D399;
  --navy: #052E26;
  --text-main: #052E26;
  --text-muted: #5B7A6E;
  --border-color: #DDEBE4;
  --card-bg: #FFFFFF;
  --field-bg: #F1F7F4;
}
html[data-theme="dark"] {
  --text-main: #DDEBE4;
  --text-muted: #8AA89B;
  --border-color: #1F4A3D;
  --card-bg: #0A241D;
  --field-bg: #10302A;
}

html, body { min-height: 100%; }
body {
  background: var(--navy) !important;
  color: var(--text-main);
  position: relative;
  overflow-x: hidden;
}

/* ---------- พื้นหลัง: ไล่สีกรมท่า → รอยัล + แสงฟ้าอมเขียวนุ่มๆ + ลายตารางจาง ---------- */
.login-bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background:
    radial-gradient(60% 55% at 85% 12%, rgba(52, 211, 153, .30) 0%, rgba(52, 211, 153, 0) 70%),
    radial-gradient(70% 60% at 8% 92%, rgba(5, 150, 105, .45) 0%, rgba(5, 150, 105, 0) 70%),
    linear-gradient(135deg, #031F19 0%, #052E26 35%, #0B6B50 75%, #047857 130%);
}
.login-bg::before {          /* ลายตาราง ERP จาง ๆ */
  content: ''; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(148, 163, 184, .07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, .07) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(75% 75% at 50% 45%, #000 20%, transparent 100%);
          mask-image: radial-gradient(75% 75% at 50% 45%, #000 20%, transparent 100%);
}
.login-bg::after {           /* วงแสงลอยช้าๆ ตัวเดียว (transform อย่างเดียว = ไม่ทำให้เครื่องช้า) */
  content: ''; position: absolute; width: 46vmax; height: 46vmax; right: -14vmax; top: -16vmax;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(52, 211, 153, .22) 0%, rgba(52, 211, 153, 0) 65%);
  animation: lg-float 22s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes lg-float { to { transform: translate3d(-6vmax, 5vmax, 0) scale(1.08); } }

/* ---------- การ์ดล็อกอิน ---------- */
.login-app-container {
  max-width: 420px;
  min-height: 0;
  background: var(--card-bg);
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: 28px;
  -webkit-backdrop-filter: none; backdrop-filter: none;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset, 0 24px 60px -12px rgba(1, 20, 15, .55), 0 0 0 1px rgba(15, 23, 42, .06);
  animation: lg-in .55s cubic-bezier(.2, .7, .2, 1) both;
}
html[data-theme="dark"] .login-app-container { border-color: rgba(148, 163, 184, .16); }
@keyframes lg-in { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- หัวโค้ง (Wave) — ไล่สีเต็มความกว้าง ไม่มีแถบขาวด้านบน ---------- */
.header-wave { height: 188px; }
.header-wave svg { width: 100%; height: 100%; display: block; }
.header-content { padding: 22px 30px 6px; }
.header-content h1 {
  font-size: 2rem; font-weight: 700; letter-spacing: .3px; color: #fff;
  text-shadow: 0 1px 2px rgba(1, 20, 15, .45), 0 2px 10px rgba(1, 20, 15, .3);
}

/* ---------- โลโก้ + ชื่อระบบ ---------- */
.logo-area { margin-top: 30px; margin-bottom: 24px; }
.logo-img {
  display: block; box-sizing: border-box; width: 128px; height: 128px; margin: 0 auto 10px; padding: 12px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 12px 28px -8px rgba(5, 150, 105, .45), 0 0 0 5px rgba(255, 255, 255, .92);
}
.logo-text {
  font-size: 1.2rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  background: linear-gradient(90deg, #047857, #059669 55%, #34D399);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  -webkit-text-fill-color: transparent;
}
.logo-sub { margin-top: 2px; color: var(--text-muted); font-size: .86rem; }

/* ---------- ช่องกรอก: พื้นเทาฟ้า (เลิกสีเหลือง Autofill ของเบราว์เซอร์) ---------- */
.input-group label { background: var(--card-bg); color: var(--text-muted); border-radius: 4px; }
.input-group input {
  background: var(--field-bg);
  border: 1.5px solid var(--border-color);
  color: var(--text-main);
  border-radius: 14px;
  transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}
.input-group input::placeholder { color: #8AA89B; }
.input-group input:hover { border-color: #CFE3DA; }
.input-group input:focus { background: var(--card-bg); border-color: var(--primary); box-shadow: 0 0 0 4px rgba(5, 150, 105, .16); }
.input-group input:focus + label, .input-group input:focus ~ i { color: var(--primary); }
.input-group input:-webkit-autofill,
.input-group input:-webkit-autofill:hover,
.input-group input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-main);
  -webkit-box-shadow: 0 0 0 1000px var(--field-bg) inset;
  box-shadow: 0 0 0 1000px var(--field-bg) inset;
  caret-color: var(--text-main);
  transition: background-color 9999s ease-out 0s;
}
.btn-toggle-pw { color: var(--text-muted); border-radius: 8px; transition: color .15s, background-color .15s; }
.btn-toggle-pw:hover { color: var(--primary); background: rgba(5, 150, 105, .08); }
.remember-me input[type="checkbox"] { accent-color: var(--primary); }
.forgot-password:hover { color: var(--primary); }

/* ---------- ปุ่ม Log in ---------- */
.btn-login {
  background: linear-gradient(135deg, #047857 0%, #059669 50%, #34D399 140%);
  background-size: 140% 100%;
  background-position: 0 0;
  border-radius: 16px;
  padding: 15px;
  letter-spacing: .02em;
  box-shadow: 0 10px 22px -8px rgba(5, 150, 105, .65);
  transition: transform .18s ease, box-shadow .18s ease, background-position .35s ease, filter .18s ease;
}
.btn-login:hover { background: linear-gradient(135deg, #047857 0%, #059669 50%, #34D399 140%); background-size: 140% 100%; background-position: 100% 0; transform: translateY(-2px); box-shadow: 0 16px 28px -10px rgba(5, 150, 105, .7); }
.btn-login:active { transform: translateY(0); box-shadow: 0 6px 14px -6px rgba(5, 150, 105, .7); filter: brightness(.96); }
.btn-login:focus-visible { outline: 3px solid rgba(52, 211, 153, .55); outline-offset: 2px; }
.btn-login:disabled { background: #8AA89B; box-shadow: none; }
.login-helper-text { color: var(--text-muted); }
.alert-error { border-radius: 12px; }
.btn-microsoft { border-radius: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .login-app-container { border-radius: 0; border: 0; box-shadow: none; min-height: 100vh; min-height: 100dvh; animation: none; max-width: 100%; }
  .login-bg::after { display: none; }
  html[data-theme="dark"] body { background: var(--navy) !important; }
  body { background: var(--card-bg) !important; }
}
@media (min-width: 481px) and (max-width: 900px) { .login-app-container { max-width: 460px; } }
@media (max-width: 896px) and (orientation: landscape) { .logo-area { margin-top: 28px; margin-bottom: 14px; } .logo-img { width: 88px; height: 88px; padding: 9px; } }
@media (prefers-reduced-motion: reduce) {
  .login-bg::after, .login-app-container { animation: none !important; }
  .btn-login, .input-group input { transition: none; }
}

/* มือถือ: แถบเลือกภาษาลอยมุมขวาบน — เว้นที่ให้หัวเรื่องไม่ถูกทับ */
@media (max-width: 480px) {
  .header-wave { height: 212px; }
  .header-content { padding-top: 66px; }
  .logo-area { margin-top: 66px; }
}

/* ============================================================================
   มือถือ / Safe area / คีย์บอร์ด / Touch / แนวนอน / โหมดมืด  (2026-10-10)
   ============================================================================ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* ---------- Safe area (รอยบาก / Dynamic Island / แถบ Home) ----------
   จอกว้าง (แท็บเล็ต, iPhone แนวนอน): เว้นขอบ body ตาม inset — การ์ดลอยกลางจอไม่ไปอยู่ใต้รอยบากข้าง
   จอแคบ (โทรศัพท์แนวตั้ง): การ์ดเต็มจอ — หัวสีเขียวขยายไปใต้รอยบากด้านบน แล้วดันเนื้อหาลงด้วย padding ของการ์ด */
body {
  min-height: 100vh; min-height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
@media (max-width: 480px) {
  body { padding: 0; }
  .login-app-container {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .header-wave { height: calc(212px + env(safe-area-inset-top)); }
}

/* ---------- Touch / Gesture ---------- */
.btn-login, .btn-toggle-pw, .forgot-password, .remember-me, .btn-microsoft, .input-group input {
  touch-action: manipulation;                        /* ไม่รอ 300ms/ไม่ซูมเมื่อแตะสองครั้ง — แต่ยังถ่างนิ้วซูมได้ (เพื่อการเข้าถึง) */
  -webkit-tap-highlight-color: rgba(5, 150, 105, .18);
}
.input-group input { min-height: 52px; font-size: max(16px, 1rem); padding-right: 54px; }   /* ≥16px = iOS ไม่ซูมหน้าเองตอนแตะช่อง */
.btn-toggle-pw {
  right: 4px; width: 44px; height: 44px; padding: 0; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-toggle-pw:focus-visible, .forgot-password:focus-visible, .remember-me:focus-within { outline: 3px solid rgba(52, 211, 153, .6); outline-offset: 2px; border-radius: 8px; }
.btn-login { min-height: 52px; }
.forgot-password { display: inline-flex; align-items: center; min-height: 44px; }
.remember-me { min-height: 44px; }
.remember-me input[type="checkbox"] { width: 20px; height: 20px; flex-shrink: 0; }
/* Edge/IE วาดปุ่มตาของตัวเองในช่องรหัสผ่านซ้อนกับปุ่มของเรา — ซ่อนของเบราว์เซอร์ */
.input-group input::-ms-reveal, .input-group input::-ms-clear { display: none; }
@media (hover: none) {                              /* จอสัมผัส: ไม่ให้ hover ค้างหลังแตะ */
  .btn-login:hover { transform: none; background-position: 0 0; box-shadow: 0 10px 22px -8px rgba(5, 150, 105, .65); }
  .btn-login:active { transform: scale(.985); }
}

/* ---------- ข้อความผิดพลาด / Caps Lock ---------- */
.alert-error[hidden], .caps-hint[hidden] { display: none; }
.alert-error { align-items: flex-start; line-height: 1.45; overflow-wrap: anywhere; }
.alert-error i { margin-top: .2em; flex-shrink: 0; }
.caps-hint { position: absolute; left: 6px; top: 100%; margin-top: 3px; font-size: .75rem; font-weight: 600; color: #b45309; display: flex; align-items: center; gap: 5px; }

/* ---------- จอเตี้ยแนวตั้ง (เช่น 320×568, iPhone SE): ย่อหัว/โลโก้ให้เห็นปุ่ม Log in โดยไม่ต้องเลื่อนมาก ---------- */
@media (max-width: 480px) and (max-height: 700px) {
  .header-wave { height: calc(150px + env(safe-area-inset-top)); }
  .header-content { padding-top: 54px; }
  .header-content h1 { font-size: 1.7rem; }
  .logo-area { margin-top: 30px; margin-bottom: 14px; }
  .logo-img { width: 88px; height: 88px; padding: 9px; margin-bottom: 6px; }
  .logo-text { font-size: 1.05rem; }
  .form-container { padding-bottom: 18px; }
  .input-group { margin-bottom: 20px; }
  .form-options { margin-bottom: 14px; }
  .btn-login { margin-top: 4px; }
  .login-helper-text { margin: 10px 0 6px; }
}
@media (max-width: 359px) {                         /* 320–359px */
  .form-container { padding-left: 20px; padding-right: 20px; }
  .header-content h1 { font-size: 1.6rem; }
  .form-options { font-size: .8rem; }
  .logo-text { letter-spacing: .1em; }
}

/* ---------- แนวนอนบนมือถือ (จอเตี้ย): แบ่ง 2 คอลัมน์ ซ้ายแบรนด์ ขวาฟอร์ม — เห็นครบไม่ต้องเลื่อน ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  /* เว้นที่ด้านบนให้แถบเลือกภาษา (ลอยมุมขวาบน) ไม่ทับช่อง Username */
  body { align-items: flex-start; padding-top: calc(max(10px, env(safe-area-inset-top)) + 46px); }
  .login-app-container {
    max-width: min(780px, 100%); min-height: 0; max-height: none; overflow: hidden;
    border-radius: 20px; padding: 0; border: 1px solid rgba(255, 255, 255, .5);
  }
  .header-wave, .header-content { display: none; }
  .form-container { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); column-gap: 26px; align-items: center; padding: 18px 24px; }
  .logo-area {
    grid-column: 1; grid-row: 1 / span 8; align-self: stretch; margin: 0; padding: 16px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
    border-radius: 16px; background: linear-gradient(135deg, #052E26 0%, #047857 60%, #059669 100%);
  }
  .logo-img { width: 84px; height: 84px; padding: 8px; margin-bottom: 8px; }
  .logo-text { background: none; -webkit-text-fill-color: #fff; color: #fff; font-size: 1rem; }
  .logo-sub { color: rgba(255, 255, 255, .85); }
  .form-container > *:not(.logo-area) { grid-column: 2; }
  .form-container form { flex: none; }
  .input-group { margin-bottom: 18px; }
  .input-group input { min-height: 46px; padding-top: 10px; padding-bottom: 10px; }
  .form-options { margin-bottom: 8px; }
  .btn-login { margin-top: 0; min-height: 48px; padding: 11px; }
  .login-helper-text { margin: 8px 0 0; }
  .btn-microsoft { margin-bottom: 0; }
  .alert-error { margin-bottom: 12px; }
}

/* ---------- โหมดมืด (ตามค่าระบบ): ส่วนที่เดิมเป็นสีสว่างตายตัว ---------- */
html[data-theme="dark"] .alert-error { background: rgba(239, 68, 68, .14); color: #fecaca; border-left-color: #f87171; }
html[data-theme="dark"] .caps-hint { color: #fbbf24; }
html[data-theme="dark"] .btn-microsoft { background: var(--field-bg); color: var(--text-main); border-color: var(--border-color); }
html[data-theme="dark"] .btn-microsoft:hover { background: #17403a; color: #fff; }
html[data-theme="dark"] .ms-divider { color: var(--text-muted); }
html[data-theme="dark"] .login-app-container { box-shadow: 0 24px 60px -12px rgba(0, 0, 0, .6), 0 0 0 1px rgba(148, 163, 184, .12); }
html[data-theme="dark"] .logo-text { background: linear-gradient(90deg, #34D399, #6EE7B7); -webkit-background-clip: text; background-clip: text; }   /* คอนทราสต์พอบนพื้นมืด */
@media (orientation: landscape) and (max-height: 520px) { html[data-theme="dark"] .logo-text { background: none; } }

/* ไอคอน SVG ของหน้า Login (แทน Font Awesome) */
.alert-error .ico { margin-top: .2em; }
.btn-toggle-pw .ico { width: 1.3rem; height: 1.3rem; }
.caps-hint .ico { width: .95em; height: .95em; }
.btn-login .ico { width: 1.1em; height: 1.1em; vertical-align: -0.18em; }

/* ---------- เส้นใยสีเขียวบาง ๆ เคลื่อนไหวช้า ๆ ที่พื้นหลัง ----------
   แยกเป็น <svg> 3 ชั้น แล้วขยับ "ตัว svg" ด้วย transform → เบราว์เซอร์ยกขึ้นเป็นเลเยอร์ GPU (compositor) ไม่ต้อง layout/คำนวณสไตล์ทุกเฟรม
   (ขยับ <g> ภายใน SVG ไม่ถูกยกเป็นเลเยอร์ — วัดแล้ว layout ~60 ครั้ง/วินาที) · ไม่มี JS/canvas/filter/blur */
.login-fibers { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; fill: none; stroke-linecap: round; will-change: transform; }
.login-fibers path { vector-effect: non-scaling-stroke; stroke-width: .6; }
.fib-a { stroke: rgba(110, 231, 183, .24); animation: fibA 46s ease-in-out infinite alternate; }
.fib-b { stroke: rgba(52, 211, 153, .22);  animation: fibB 58s ease-in-out infinite alternate; }
.fib-c { stroke: rgba(167, 243, 208, .16); animation: fibC 70s ease-in-out infinite alternate; }
@keyframes fibA { from { transform: translate3d(-2.5%, 1.5%, 0) rotate(-.7deg) scale(1.06); } to { transform: translate3d(2.5%, -2%, 0) rotate(.7deg) scale(1.06); } }
@keyframes fibB { from { transform: translate3d(2%, -1.5%, 0) rotate(.5deg) scale(1.06); } to { transform: translate3d(-2.5%, 2%, 0) rotate(-.6deg) scale(1.06); } }
@keyframes fibC { from { transform: translate3d(-1.5%, 0, 0) scale(1.07, 1.04); } to { transform: translate3d(2%, 1.5%, 0) scale(1.04, 1.07); } }
@media (max-width: 480px) { .fib-c { display: none; } }                     /* มือถือ: เหลือ 2 ชั้น เบาลงอีก */
@media (prefers-reduced-motion: reduce) { .login-fibers { animation: none; } }
