:root {
  --orange:       #ee4d2d;
  --orange-light: #fff2f0;
  --orange-mid:   #ffd5cc;
  --bg:           #f5f5f5;
  --white:        #fff;
  --border:       #e8e8e8;
  --text:         #222;
  --text-2:       #555;
  --text-3:       #999;
  --green:        #26aa63;
  --radius:       4px;
}

html { font-size: 14px; }
body {
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* ── LOGIN PAGE WRAP ── */
.login-page {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  /* ลด padding ซ้าย-ขวาบนมือถือ */
  padding: 16px 12px 32px;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

/* ── CARD ── */
.login-container {
  position: relative;
  z-index: 1;
  /* ต้องมี width: 100% เพื่อไม่ให้ card ล้น */
  width: 100%;
  max-width: 500px;
  background: var(--white);
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,.15);
  /* เปลี่ยนจาก overflow:hidden เป็น visible
     เพื่อไม่ตัด input ที่มี focus ring */
  overflow: visible;
  display: flex;
  /* ลบ min-height ออก ให้ card สูงตาม content */
  min-height: unset;
  box-sizing: border-box;
}

/* ── RIGHT PANEL (form) ── */
.login-right {
  flex: 1;
  /* ลด padding บนมือถือ */
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* สำคัญ: ป้องกัน children ล้นออกนอก flex item */
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

@media (min-width: 480px) {
  .login-right { padding: 36px 28px; }
}

@media (min-width: 640px) {
  .login-right { padding: 48px 40px; }
}

/* ── HEADER ── */
.login-header { margin-bottom: 22px; }

.login-header h1 {
  font-family: 'Kanit', sans-serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

@media (min-width: 400px) {
  .login-header h1 { font-size: 22px; }
}

.login-header p {
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.5;
}

.login-header .mobile-logo {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 18px;
}

@media (min-width: 640px) {
  .login-header .mobile-logo { display: none; }
}

.mobile-logo .micon {
  width: 36px; height: 36px;
  background: var(--orange-light);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  color: var(--orange);
  flex-shrink: 0;
}

.mobile-logo .mname {
  font-family: 'Kanit', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.mobile-logo .mname span {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-3);
}

/* ── FORM FIELDS ── */
.form-group {
  margin-bottom: 14px;
  position: relative;
  /* สำคัญ: ป้องกัน input ล้นออกนอก group */
  width: 100%;
  box-sizing: border-box;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
  font-family: 'Kanit', sans-serif;
}

.input-wrap {
  position: relative;
  /* สำคัญ: ทำให้ input-wrap ไม่ขยายเกิน parent */
  width: 100%;
  box-sizing: border-box;
}

.input-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 13px;
  pointer-events: none;
  z-index: 1;
  transition: color .2s;
}
.input-wrap:focus-within .input-icon { color: var(--orange); }

.form-input {
  /* สำคัญที่สุด: width:100% + box-sizing ป้องกันล้น */
  width: 100%;
  box-sizing: border-box;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px 11px 36px;
  /* font-size: 16px ป้องกัน iOS zoom เมื่อ focus */
  font-size: 16px;
  font-family: 'Sarabun', sans-serif;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
  /* ลบ style เฉพาะ browser บน iOS */
  -webkit-appearance: none;
  appearance: none;
}

@media (min-width: 640px) {
  .form-input { font-size: 14px; }
}

.form-input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(238,77,45,.1);
  background: #fffcfb;
}

/* password toggle */
.pw-toggle {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  cursor: pointer;
  font-size: 13px;
  border: none;
  background: none;
  /* เพิ่ม touch target */
  padding: 6px;
  transition: color .2s;
  -webkit-tap-highlight-color: transparent;
}
.pw-toggle:hover { color: var(--orange); }

/* ── reCAPTCHA responsive ── */
.recaptcha-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
  width: 100%;
  overflow: hidden;
}

@media (max-width: 339px) {
  .recaptcha-wrap { transform: scale(0.82); transform-origin: center top; height: 64px; }
}
@media (min-width: 340px) and (max-width: 374px) {
  .recaptcha-wrap { transform: scale(0.88); transform-origin: center top; height: 68px; }
}
@media (min-width: 375px) and (max-width: 413px) {
  .recaptcha-wrap { transform: scale(0.94); transform-origin: center top; height: 72px; }
}
@media (min-width: 414px) {
  .recaptcha-wrap { transform: none; height: auto; }
}

/* ── SUBMIT BTN ── */
.btn-login {
  width: 100%;
  box-sizing: border-box;
  padding: 13px;
  background: var(--orange);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-family: 'Kanit', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s, box-shadow .2s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 6px;
  box-shadow: 0 2px 12px rgba(238,77,45,.25);
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn-login:hover {
  background: #d9401f;
  box-shadow: 0 4px 18px rgba(238,77,45,.35);
  transform: translateY(-1px);
}
.btn-login:active { transform: translateY(0); }

.btn-login .spinner {
  display: none;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.btn-login.loading .spinner { display: block; }
.btn-login.loading .btn-text { opacity: .7; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── DIVIDER ── */
.divider {
  display: flex; align-items: center; gap: 10px;
  margin: 18px 0;
  color: var(--text-3); font-size: 12px;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ── REGISTER LINK ── */
.register-link {
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}
.register-link a {
  color: var(--orange);
  font-weight: 600;
  text-decoration: none;
  font-family: 'Kanit', sans-serif;
}
.register-link a:hover { text-decoration: underline; }

/* ── FORGOT PW ── */
.forgot-link {
  display: block;
  text-align: right;
  font-size: 11px;
  color: var(--text-3);
  text-decoration: none;
  margin-top: 6px;
  padding: 4px 0;
  transition: color .15s;
}
.forgot-link:hover { color: var(--orange); }