/*
 * RCA Track — หน้า auth (P1-T09 ; layouts/guest.php)
 * Split screen: brand panel navy (token sidebar เดียวกับ app shell) + "closed loop track" (signature) | ฟอร์มบน surface
 * < 992px: brand panel ยุบเป็นแถบหัว (logo + slogan) ; loop ซ่อนที่ < 768px ; ใช้ token จาก theme.css ทั้งหมด (รองรับ dark)
 */

.rt-auth-page { min-height: 100vh; background: var(--rt-bg); }

.rt-auth {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 5fr) 7fr;
}

/* ---------------- Brand panel ---------------- */
.rt-auth__brand {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 2.25rem;
  padding: 2.5rem clamp(2rem, 4vw, 3.5rem);
  color: var(--rt-sidebar-text);
  background:
    radial-gradient(120% 70% at 110% 0%, rgba(249, 115, 22, .16) 0%, transparent 55%),
    linear-gradient(180deg, var(--rt-sidebar-bg) 0%, var(--rt-sidebar-bg-2) 100%);
}
/* วงแหวนใหญ่จางๆ = logo mark ขยาย (ตกแต่ง) */
.rt-auth__brand::after {
  content: ""; position: absolute; width: 520px; height: 520px; right: -220px; bottom: -200px;
  border-radius: 50%; border: 44px solid rgba(249, 115, 22, .07);
  border-left-color: transparent; transform: rotate(-35deg); pointer-events: none;
}
.rt-auth__brand > * { position: relative; z-index: 1; }

.rt-auth__logo { display: inline-flex; align-items: center; gap: .75rem; color: #fff; text-decoration: none; width: max-content; border-radius: var(--rt-radius); }
.rt-auth__logo:hover { color: #fff; }
.rt-auth__logo .rt-brand__mark { width: 44px; height: 44px; }
.rt-auth__logo .rt-brand__mark .ring { stroke: var(--rt-primary); }
.rt-auth__logo .rt-brand__mark .check { stroke: #fff; }
.rt-auth__wordmark { font-size: 1.5rem; font-weight: 700; letter-spacing: .02em; }
.rt-auth__wordmark em { font-style: normal; color: var(--rt-primary); }

.rt-auth__thesis { margin-top: auto; }
.rt-auth__eyebrow { margin: 0 0 .9rem; font-size: .72rem; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; color: var(--rt-sidebar-muted); }
.rt-auth__slogan { margin: 0; font-size: clamp(1.9rem, 2.8vw, 2.6rem); font-weight: 700; line-height: 1.25; color: #fff; letter-spacing: -.01em; }
.rt-auth__slogan span { display: block; color: var(--rt-primary); }
.rt-auth__slogan-en { margin: .75rem 0 0; font-size: .95rem; color: var(--rt-sidebar-text); }

/* Signature: closed loop track — ขั้นตอนจริงของ workflow */
.rt-loop { border-top: 1px solid var(--rt-sidebar-border); padding-top: 1.5rem; }
.rt-loop__list { list-style: none; margin: 0; padding: 0; position: relative; }
.rt-loop__list::before {
  content: ""; position: absolute; left: 13px; top: 14px; bottom: 14px; width: 2px;
  background: linear-gradient(180deg, rgba(203, 213, 225, .25), var(--rt-primary));
}
.rt-loop__step { position: relative; display: flex; align-items: flex-start; gap: .9rem; padding: .35rem 0; }
.rt-loop__node {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--rt-sidebar-bg); border: 2px solid rgba(203, 213, 225, .35);
  font-size: .75rem; font-weight: 600; color: var(--rt-sidebar-text); font-variant-numeric: tabular-nums;
}
.rt-loop__step:last-child .rt-loop__node { background: var(--rt-primary-fill); border-color: var(--rt-primary-fill); color: #fff; }
.rt-loop__text { display: flex; flex-direction: column; line-height: 1.3; padding-top: .15rem; }
.rt-loop__text strong { color: #fff; font-weight: 600; font-size: .95rem; }
.rt-loop__text span { font-size: .8rem; color: var(--rt-sidebar-muted); }
.rt-loop__return { display: flex; align-items: center; gap: .5rem; margin: .9rem 0 0; font-size: .82rem; color: var(--rt-primary-text); }
[data-bs-theme="light"] .rt-loop__return { color: #FDBA74; }
.rt-loop__return .bi { font-size: 1rem; }

.rt-auth__foot { margin: 0; font-size: .78rem; color: var(--rt-sidebar-muted); line-height: 1.6; }

/* ไล่ไฮไลต์ node ทีละขั้นครั้งเดียวตอนโหลด (motion ที่สื่อ "วงจร") */
@media (prefers-reduced-motion: no-preference) {
  .rt-loop__step { animation: rt-loop-in .5s ease both; }
  .rt-loop__step:nth-child(2) { animation-delay: .08s; }
  .rt-loop__step:nth-child(3) { animation-delay: .16s; }
  .rt-loop__step:nth-child(4) { animation-delay: .24s; }
  .rt-loop__step:nth-child(5) { animation-delay: .32s; }
  .rt-loop__return { animation: rt-loop-in .5s ease .45s both; }
}
@keyframes rt-loop-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- Form side ---------------- */
.rt-auth__main {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3rem 1.5rem 2rem; min-width: 0;
}
.rt-auth__main:focus { outline: 0; }
.rt-auth__tools { position: absolute; top: 1rem; right: 1rem; }
.rt-auth__panel { width: min(440px, 100%); }
.rt-auth__legal { margin: 2rem 0 0; font-size: .75rem; color: var(--rt-text-muted); text-align: center; }
.rt-auth__version { margin: .35rem 0 0; font-size: .72rem; color: var(--rt-text-muted); text-align: center; letter-spacing: .03em; font-variant-numeric: tabular-nums; }

.rt-auth__card { width: 100%; }
.rt-auth__card--wide { max-width: 520px; }
.rt-auth__panel:has(.rt-auth__card--wide) { width: min(520px, 100%); }
.rt-auth__kicker {
  display: inline-flex; align-items: center; gap: .4rem; margin: 0 0 .4rem;
  font-size: .8rem; font-weight: 600; color: var(--rt-primary-text); letter-spacing: .02em;
}
.rt-auth__kicker--warn { color: var(--rt-warning-strong); }
.rt-auth__kicker--ok { color: var(--rt-success-strong); }
.rt-auth__title { font-size: 1.75rem; font-weight: 700; line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
.rt-auth__lead { color: var(--rt-text-muted); margin: 0 0 1.5rem; }

.rt-auth__alert { display: flex; gap: .6rem; align-items: flex-start; font-size: .9rem; border-radius: var(--rt-radius-lg); padding: .8rem 1rem; }
.rt-auth__alert[hidden] { display: none; }
.rt-auth__alert .bi { font-size: 1.05rem; line-height: 1.4; flex-shrink: 0; }
.alert-danger.rt-auth__alert { background: var(--rt-danger-soft); border-color: transparent; color: var(--rt-danger-strong); }
.alert-warning.rt-auth__alert { background: var(--rt-warning-soft); border-color: transparent; color: var(--rt-warning-strong); }
[data-bs-theme="light"] .alert-warning.rt-auth__alert { color: #92400E; }

.rt-auth .form-control { min-height: 46px; }
.rt-input-icon { position: relative; }
.rt-input-icon > .bi { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--rt-text-muted); pointer-events: none; }
.rt-input-icon > .form-control { padding-left: 2.5rem; }

.rt-auth__row { display: flex; justify-content: flex-end; margin: -.35rem 0 1.25rem; }
.rt-auth__link { font-size: .875rem; font-weight: 500; color: var(--rt-info); text-decoration: none; padding: 0; border: 0; display: inline-flex; align-items: center; gap: .35rem; }
.rt-auth__link:hover { text-decoration: underline; color: var(--bs-link-color); }
[data-bs-theme="dark"] .rt-auth__link { color: #93C5FD; }
.rt-auth__submit { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 48px; font-size: 1rem; margin-top: .25rem; }
.rt-auth__aside { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-top: 1.25rem; }
.rt-auth__aside form { margin: 0; }
.rt-auth__note { display: flex; gap: .5rem; align-items: flex-start; margin: 1.5rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--rt-border); font-size: .8rem; color: var(--rt-text-muted); }
.rt-auth__note .bi { color: var(--rt-success); }

/* ยืนยันอีเมลใหม่ (NEW-01): บัญชี + อีเมล (mask) ก่อนกดยืนยัน */
.rt-auth__summary { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0 0 1.25rem; padding: .85rem 1rem; border: 1px solid var(--rt-border); border-radius: .5rem; font-size: .9rem; }
.rt-auth__summary[hidden] { display: none; }
.rt-auth__summary dt { font-weight: 500; color: var(--rt-text-muted); }
.rt-auth__summary dd { margin: 0; word-break: break-all; }

/* OTP */
.rt-otp { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.35rem; letter-spacing: .3em; text-align: center; }
.rt-otp::placeholder { letter-spacing: .3em; opacity: .35; }

/* ---------------- MFA enroll ---------------- */
.rt-steps { list-style: none; display: flex; gap: .5rem; margin: 1.25rem 0 1.5rem; padding: 0; }
.rt-steps__item { flex: 1 1 0; display: flex; align-items: center; gap: .5rem; font-size: .8rem; color: var(--rt-text-muted); min-width: 0; }
.rt-steps__item + .rt-steps__item::before { content: ""; flex: 0 0 12px; height: 2px; background: var(--rt-border); margin-right: .1rem; }
.rt-steps__dot {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--rt-border); font-weight: 600; font-size: .75rem; background: var(--rt-surface);
}
.rt-steps__label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rt-steps__item.is-current { color: var(--rt-text); font-weight: 600; }
.rt-steps__item.is-current .rt-steps__dot { border-color: var(--rt-info); color: var(--rt-info); }
.rt-steps__item.is-done .rt-steps__dot { border-color: var(--rt-success); background: var(--rt-success); color: #fff; }

.rt-enroll { display: grid; grid-template-columns: auto 1fr; gap: 1.25rem; align-items: start; margin-bottom: 1.25rem; padding: 1rem; border: 1px solid var(--rt-border); border-radius: var(--rt-radius-lg); background: var(--rt-surface); }
.rt-enroll__qr { margin: 0; padding: 8px; background: #fff; border-radius: var(--rt-radius); line-height: 0; }
.rt-enroll__qr img { width: 180px; height: 180px; }
.rt-enroll__label { font-size: .8rem; color: var(--rt-text-muted); margin: 0 0 .35rem; }
.rt-secret { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 .6rem; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .95rem; user-select: all; }
.rt-secret span { padding: .15rem .4rem; border-radius: 5px; background: var(--rt-surface-2); border: 1px solid var(--rt-border); letter-spacing: .06em; }

/* ---------------- Recovery codes ---------------- */
.rt-codes {
  list-style: none; counter-reset: rt-code; margin: 0 0 1rem; padding: 1rem;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1rem;
  border: 1px dashed var(--rt-border); border-radius: var(--rt-radius-lg); background: var(--rt-surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .95rem; letter-spacing: .04em;
}
.rt-codes li { counter-increment: rt-code; display: flex; gap: .6rem; align-items: baseline; }
.rt-codes li::before { content: counter(rt-code, decimal-leading-zero); font-size: .72rem; color: var(--rt-text-muted); }
.rt-codes__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; }
.rt-codes__ack { margin-bottom: 1rem; }
.rt-auth__submit[aria-disabled="true"] { opacity: .55; pointer-events: auto; cursor: not-allowed; }

/* ---------------- Responsive ---------------- */
@media (max-width: 991.98px) {
  .rt-auth { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .rt-auth__brand { gap: 1rem; padding: 1.25rem 1.25rem 1.5rem; }
  .rt-auth__brand::after { width: 260px; height: 260px; right: -110px; bottom: -150px; border-width: 26px; }
  .rt-auth__thesis { margin-top: 0; }
  .rt-auth__eyebrow, .rt-auth__foot, .rt-loop { display: none; }
  .rt-auth__slogan { font-size: 1.35rem; }
  .rt-auth__slogan span { display: inline; }
  .rt-auth__slogan-en { font-size: .8rem; margin-top: .3rem; }
  .rt-auth__main { position: static; justify-content: flex-start; padding: 2rem 1rem 1.5rem; }
  .rt-auth__tools { top: .9rem; right: .75rem; z-index: 2; }
  .rt-auth__tools .rt-topbar__btn { color: var(--rt-sidebar-text); }
  .rt-auth__tools .rt-topbar__btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
}
@media (max-width: 575.98px) {
  .rt-auth__title { font-size: 1.45rem; }
  .rt-enroll { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .rt-secret { justify-content: center; }
  .rt-codes { grid-template-columns: 1fr; }
  .rt-steps__label { display: none; }
  .rt-steps__item.is-current .rt-steps__label { display: inline; }
}
