/* =========================================================================
   Samo ERP v2 — Mobile Login & QR Login ("Frost / Obsidian")
   Loaded after samo-v2/tokens.css + palettes.css + samo-v2.css + login.css.
   Colours ONLY via var(--s-*) / var(--lg-*) tokens — zero hex/rgb literals.
   ========================================================================= */

body.mlg-body {
  margin: 0;
  padding: 0;
  background: var(--s-bg);
  color: var(--s-ink);
  font-family: var(--s-font);
  font-size: var(--s-fs-base);
  line-height: var(--s-lh);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.mlg,
.mlg *,
.mlg *::before,
.mlg *::after {
  box-sizing: border-box;
}

.mlg [hidden] {
  display: none !important;
}

/* ---------- Page shell: 100dvh, safe-area insets, no keyboard jump -------- */
.mlg {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  overflow-x: clip;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: max(14px, env(safe-area-inset-top));
  padding-right: max(14px, env(safe-area-inset-right));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-left: max(14px, env(safe-area-inset-left));
  background: var(--s-bg);
  color: var(--s-ink);
  transition: background-color var(--s-dur) var(--s-ease), color var(--s-dur) var(--s-ease);
}

html[data-theme="dark"] body.mlg-body .mlg {
  background:
    radial-gradient(520px 320px at 50% 0%, color-mix(in srgb, var(--s-accent) 12%, transparent), transparent 68%),
    var(--s-bg);
}

/* Fixed ambient layer so opening the mobile keyboard never shifts background */
.mlg-blobs {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.mlg-blob {
  position: absolute;
  border-radius: var(--s-r-pill);
  pointer-events: none;
}

.mlg-blob--a {
  top: -160px;
  right: -120px;
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, color-mix(in srgb, var(--s-accent) 18%, transparent), transparent 68%);
}

.mlg-blob--b {
  bottom: -180px;
  left: -120px;
  width: 360px;
  height: 360px;
  background: radial-gradient(circle, color-mix(in srgb, var(--s-primary) 14%, transparent), transparent 68%);
}

/* Center vertically when room is available; scroll cleanly from top with keyboard */
.mlg-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  min-width: 0;
  margin-block: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Compact Obsidian Hero Header (matches v2-Login hero) ---------- */
.mlg-hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--s-r-2xl);
  background: var(--s-sidebar-bg, var(--lg-hero));
  color: var(--lg-hero-ink, var(--s-primary-ink));
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--s-shadow);
  animation: s-rise .5s var(--s-ease) both;
}

.mlg-threads {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .7;
}

.mlg-threads svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.mlg-brand {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mlg-brand__logo {
  flex: none;
  width: 38px;
  display: block;
}

.mlg-brand__logo img {
  display: block;
  width: 100%;
  height: auto;
}

.mlg-brand__name {
  display: block;
  flex: none;
  height: 16px;
  width: calc(16px * 254 / 55);
  background: var(--lg-hero-ink, var(--s-primary-ink));
  font-size: 0;
  -webkit-mask: url(../../img/v2/samo-word.png) center / contain no-repeat;
  mask: url(../../img/v2/samo-word.png) center / contain no-repeat;
}

.mlg-brand__tag {
  flex: none;
  height: 22px;
  padding: 0 9px;
  border-radius: var(--s-r-pill);
  border: 1px solid var(--lg-hero-t3, var(--s-panel-line));
  background: transparent;
  background: color-mix(in srgb, var(--lg-hero-ink, var(--s-primary-ink)) 12%, transparent);
  color: var(--lg-hero-t3, var(--s-panel-line));
  font-size: 11px;
  font-weight: 800;
  line-height: 20px;
  letter-spacing: .04em;
  white-space: nowrap;
}

/* Theme toggle button (44px min touch target) */
.mlg-theme-btn {
  position: relative;
  z-index: 1;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--s-r-lg);
  border: 1px solid var(--lg-hero-t3, var(--s-panel-line));
  border-color: color-mix(in srgb, var(--lg-hero-ink, var(--s-primary-ink)) 22%, transparent);
  background: transparent;
  background: color-mix(in srgb, var(--lg-hero-ink, var(--s-primary-ink)) 10%, transparent);
  color: var(--lg-hero-ink, var(--s-primary-ink));
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--s-dur-fast) var(--s-ease), transform var(--s-dur-fast) var(--s-ease);
}

.mlg-theme-btn:hover {
  background: color-mix(in srgb, var(--lg-hero-ink, var(--s-primary-ink)) 18%, transparent);
}

.mlg-theme-btn:active {
  transform: scale(.96);
}

.mlg-theme-btn > span {
  display: grid;
  place-items: center;
}

/* ---------- Frost / Obsidian Glass Card ----------------------------------- */
.mlg-card {
  position: relative;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  padding: 22px 18px;
  border-radius: var(--s-r-2xl);
  background: var(--s-panel);
  border: 1px solid var(--s-panel-line);
  backdrop-filter: blur(var(--s-blur));
  -webkit-backdrop-filter: blur(var(--s-blur));
  box-shadow: var(--s-shadow);
  animation: s-rise .55s .06s var(--s-ease) both;
}

.mlg-card.is-shake {
  animation: s-shake .45s ease-in-out;
}

@media (min-width: 440px) {
  .mlg-card {
    padding: 28px 26px;
  }
}

.mlg-head {
  margin-bottom: 18px;
}

.mlg-title {
  margin: 0;
  font-family: var(--s-font);
  font-size: 24px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -.03em;
  color: var(--s-ink);
}

/* ---------- Alert banner -------------------------------------------------- */
.mlg-alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: var(--s-r-lg);
  background: var(--s-bad-bg);
  background: color-mix(in srgb, var(--s-error) 12%, transparent);
  border: 1px solid var(--s-error);
  border-color: color-mix(in srgb, var(--s-error) 28%, transparent);
  color: var(--s-error);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
  animation: s-rise .25s ease-out both;
}

.mlg-alert svg {
  flex: none;
  margin-top: 1px;
}

/* ---------- Form & ActiveForm overrides ----------------------------------- */
body.mlg-body .mlg-form {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

body.mlg-body .mlg-field {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

body.mlg-body .mlg-label {
  display: block;
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--s-text-2);
}

body.mlg-body .mlg-fld {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0 12px;
  border-radius: var(--s-r-lg);
  background: var(--s-field);
  border: 1px solid var(--s-field-line);
  color: var(--s-text-3);
  transition: border-color var(--s-dur-fast) var(--s-ease), box-shadow var(--s-dur-fast) var(--s-ease), background var(--s-dur-fast) var(--s-ease);
}

body.mlg-body .mlg-fld--pw {
  padding-right: 4px;
}

body.mlg-body .mlg-fld:focus-within {
  border-color: var(--s-accent);
  box-shadow: var(--s-focus-ring);
  color: var(--s-accent-ink);
}

body.mlg-body .has-error .mlg-fld,
body.mlg-body .mlg-fld.is-error {
  border-color: var(--s-error);
}

body.mlg-body .has-error .mlg-fld:focus-within,
body.mlg-body .mlg-fld.is-error:focus-within {
  border-color: var(--s-error);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--s-error) 22%, transparent);
}

body.mlg-body .mlg-fld > svg {
  flex: none;
}

/* 16px font prevents iOS Safari zoom on input focus */
body.mlg-body input.mlg-input,
body.mlg-body .mlg-fld input.form-control {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: 46px;
  min-height: 44px;
  padding: 0;
  margin: 0;
  border: 0 !important;
  outline: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  font-family: var(--s-font);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--s-ink);
}

body.mlg-body input.mlg-input::placeholder {
  color: var(--s-text-3);
  opacity: 1;
}

body.mlg-body input.mlg-input:-webkit-autofill {
  -webkit-text-fill-color: var(--s-ink);
  box-shadow: 0 0 0 40px var(--s-field) inset !important;
}

[data-theme="dark"] body.mlg-body input.mlg-input {
  color-scheme: dark;
}

/* Error text below field */
body.mlg-body .mlg-error-text,
body.mlg-body .help-block-error {
  margin: 0;
  color: var(--s-error);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.35;
}

body.mlg-body .mlg-error-text:empty,
body.mlg-body .help-block:empty {
  display: none;
}

/* Password visibility toggle (44x44 touch target) */
.mlg-eye {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--s-r-sm);
  background: transparent;
  color: var(--s-text-3);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color var(--s-dur-fast), background var(--s-dur-fast);
}

.mlg-eye:hover {
  color: var(--s-ink);
  background: var(--s-soft);
}

.mlg-eye span {
  display: grid;
  place-items: center;
}

/* Remember me checkbox row (44px min touch height) */
body.mlg-body .mlg-check-wrap {
  margin: 0;
}

body.mlg-body .mlg-check-wrap .checkbox {
  margin: 0;
}

body.mlg-body .mlg-check-wrap label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 0;
  padding: 4px 2px;
  font-size: 14px;
  font-weight: 600;
  color: var(--s-text-2);
  cursor: pointer;
  user-select: none;
}

body.mlg-body .mlg-check-wrap input[type="checkbox"] {
  position: static;
  flex: none;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--s-accent);
  cursor: pointer;
}

/* ---------- Primary Submit / Action Button (48-52px touch target) --------- */
body.mlg-body .mlg-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--s-r-lg);
  background: var(--s-primary);
  background-image: var(--s-primary-grad, none);
  color: var(--s-primary-ink);
  font-family: var(--s-font);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: transform var(--s-dur-fast) var(--s-ease), box-shadow var(--s-dur-fast) var(--s-ease), opacity var(--s-dur-fast);
}

body.mlg-body .mlg-submit:hover {
  transform: translateY(-1px);
  box-shadow: var(--s-shadow);
}

body.mlg-body .mlg-submit:active {
  transform: translateY(0) scale(.99);
}

body.mlg-body .mlg-submit[aria-busy="true"] {
  pointer-events: none;
  opacity: .92;
}

.mlg-submit__idle,
.mlg-submit__busy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.mlg-loader path:nth-child(odd) {
  stroke: var(--lg-glow, var(--s-accent-ink));
}

.mlg-loader path:nth-child(even) {
  stroke: currentColor;
}

/* ---------- Divider & Secondary Switch Link (Password <-> QR) ------------- */
.mlg-divider {
  height: 1px;
  margin: 16px 0 14px;
  background: var(--s-line);
}

body.mlg-body a.mlg-alt-btn,
body.mlg-body button.mlg-alt-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 8px 14px;
  border-radius: var(--s-r-lg);
  border: 1px solid var(--s-field-line);
  background: var(--s-soft);
  color: var(--s-ink);
  font-family: var(--s-font);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--s-dur-fast) var(--s-ease), border-color var(--s-dur-fast) var(--s-ease), transform var(--s-dur-fast) var(--s-ease);
}

body.mlg-body a.mlg-alt-btn:hover,
body.mlg-body button.mlg-alt-btn:hover {
  background: var(--s-hover);
  border-color: var(--s-accent);
  text-decoration: none;
  color: var(--s-ink);
}

body.mlg-body a.mlg-alt-btn:active,
body.mlg-body button.mlg-alt-btn:active {
  transform: scale(.99);
}

.mlg-alt-btn__icon {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: var(--s-r-sm);
  background: var(--s-accent-soft);
  color: var(--s-accent-ink);
  display: grid;
  place-items: center;
}

.mlg-alt-btn__text {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
}

.mlg-alt-btn__chev {
  flex: none;
  color: var(--s-text-3);
  display: grid;
  place-items: center;
}

/* ---------- QR Screen Specifics ------------------------------------------- */
.mlg-qr-visual {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 148px;
  margin-bottom: 16px;
  border-radius: var(--s-r-xl);
  background: var(--s-soft);
  border: 1px solid var(--s-line);
  overflow: hidden;
}

.mlg-qr-frame {
  position: relative;
  width: 108px;
  height: 108px;
  display: grid;
  place-items: center;
  color: var(--s-ink);
}

.mlg-qr-corners {
  position: absolute;
  inset: 0;
  color: var(--s-accent);
}

.mlg-qr-beam {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 12px;
  height: 2px;
  border-radius: var(--s-r-pill);
  background: var(--s-accent);
  box-shadow: 0 0 10px var(--s-accent);
  animation: mlg-scan 2.2s ease-in-out infinite alternate;
}

@keyframes mlg-scan {
  from { transform: translateY(0); }
  to { transform: translateY(82px); }
}

.mlg-qr-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- Focus States (Keyboard / A11y) -------------------------------- */
.mlg button:focus-visible,
.mlg a:focus-visible,
.mlg input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--s-accent);
  outline-offset: 2px;
  box-shadow: var(--s-focus-ring);
}

/* ---------- Footer -------------------------------------------------------- */
.mlg-foot {
  text-align: center;
  padding: 2px 0;
  color: var(--s-text-3);
  font-size: 12.5px;
  font-weight: 600;
}

/* ---------- Reduced Motion ------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .mlg *,
  .mlg *::before,
  .mlg *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- Narrow 360px phones ------------------------------------------- */
@media (max-width: 375px) {
  .mlg {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .mlg-brand__tag {
    display: none;
  }

  .mlg-card {
    padding: 20px 16px;
  }

  .mlg-title {
    font-size: 22px;
  }
}
