/* ════════════════════════════════════════════════════
   M-COMMERCE ERP — sign-in screen
   Loaded only by login.php, which declares its own <!doctype> and does not go
   through includes/header.php. It DOES load app.css first, so the design tokens
   (--mg-*, --sp-*, --radius-*) are available here.

   Extracted from a 234-line inline <style> in login.php so it can be cached,
   edited without touching PHP, and version-stamped like every other stylesheet.
   ════════════════════════════════════════════════════ */

  html, body { height: 100%; }
  body { margin: 0; display: block; overflow: auto; background: var(--mg-bg); font-family: 'Inter', system-ui, sans-serif; }

  .mg-auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.05fr 1fr;
  }

  /* ── Hero panel ───────────────────────────────────────────── */
  .mg-auth__hero {
    position: relative;
    overflow: hidden;
    color: #fff;
    padding: 56px 64px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background:
      radial-gradient(1100px 600px at 110% -10%, hsl(38 92% 50% / .40), transparent 60%),
      radial-gradient(900px 500px at -10% 110%, hsl(28 80% 45% / .35), transparent 60%),
      linear-gradient(135deg, hsl(215 28% 15%) 0%, hsl(221 39% 8%) 100%);
  }
  .mg-auth__hero::before,
  .mg-auth__hero::after {
    content: ""; position: absolute; border-radius: 50%; filter: blur(60px); pointer-events: none;
    animation: mgFloat 14s ease-in-out infinite;
  }
  .mg-auth__hero::before {
    width: 360px; height: 360px; top: -80px; right: -60px;
    background: radial-gradient(closest-side, hsl(38 92% 52% / .50), transparent 70%);
  }
  .mg-auth__hero::after {
    width: 320px; height: 320px; bottom: -90px; left: 20%;
    background: radial-gradient(closest-side, hsl(28 80% 50% / .42), transparent 70%);
    animation-delay: -7s;
  }
  @keyframes mgFloat {
    0%,100% { transform: translate3d(0,0,0); }
    50%     { transform: translate3d(0,-22px,0); }
  }
  .mg-auth__grid {
    position: absolute; inset: 0;
    background-image:
      linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
    pointer-events: none;
  }
  .mg-auth__brand { position: relative; display: flex; align-items: center; gap: 14px; z-index: 2; }
  .mg-auth__brand img { max-height: 44px; max-width: 180px; object-fit: contain; }
  .mg-auth__brand .mg-mark {
    width: 44px; height: 44px; border-radius: 12px;
    display: grid; place-items: center; font-size: 22px;
    background: rgba(255,255,255,.14); backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,.22);
  }
  .mg-auth__brand .mg-brand-name {
    font-family: 'Sora','Inter',sans-serif; font-weight: 600;
    font-size: 1.05rem; letter-spacing: .01em;
  }
  .mg-auth__badge {
    display: inline-flex; align-items: center; gap: 7px; margin-bottom: 16px;
    font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: #fff; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.24);
    padding: 5px 12px; border-radius: 999px;
  }
  .mg-auth__copy { position: relative; z-index: 2; max-width: 480px; }
  .mg-auth__copy h1 {
    font-family: 'Sora','Inter',sans-serif;
    font-size: clamp(2rem, 3.6vw, 3rem);
    line-height: 1.1; letter-spacing: -0.02em; font-weight: 700; margin: 0 0 18px;
  }
  .mg-auth__copy p { font-size: 1.02rem; color: rgba(255,255,255,.78); margin: 0 0 28px; line-height: 1.55; }
  .mg-auth__features { display: grid; gap: 14px; }
  .mg-auth__feature {
    display: flex; align-items: flex-start; gap: 12px; color: rgba(255,255,255,.92);
  }
  .mg-auth__feature .ico {
    flex: 0 0 36px; width: 36px; height: 36px; border-radius: 10px;
    background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18);
    display: grid; place-items: center; font-size: 16px;
  }
  .mg-auth__feature .ttl { font-weight: 600; font-size: .95rem; line-height: 1.2; }
  .mg-auth__feature .sub { font-size: .82rem; color: rgba(255,255,255,.65); margin-top: 2px; }
  .mg-auth__foot { position: relative; z-index: 2; font-size: .78rem; color: rgba(255,255,255,.55); }

  /* ── Form panel ───────────────────────────────────────────── */
  .mg-auth__form-wrap {
    display: flex; align-items: center; justify-content: center;
    padding: 48px 32px; background: var(--mg-bg);
  }
  .mg-auth__form {
    width: 100%; max-width: 420px;
  }
  .mg-auth__form .mobile-brand { display: none; text-align: center; margin-bottom: 24px; }
  .mg-auth__form .mobile-brand img { max-height: 56px; max-width: 200px; object-fit: contain; }
  .mg-auth__form h2 {
    font-family: 'Sora','Inter',sans-serif; font-weight: 700;
    font-size: 1.6rem; letter-spacing: -0.01em; color: var(--mg-text); margin: 0 0 6px;
  }
  .mg-auth__form .lead { color: var(--mg-text-muted); margin: 0 0 28px; font-size: .95rem; }

  .mg-field { position: relative; margin-bottom: 16px; }
  .mg-field > input {
    width: 100%; height: 52px;
    padding: 22px 14px 8px 44px;
    font-size: .95rem; color: var(--mg-text);
    background: var(--mg-surface);
    border: 1px solid var(--mg-border); border-radius: 12px;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
    outline: none;
  }
  .mg-field > input:focus {
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 4px hsl(var(--primary) / .14);
  }
  .mg-field > label {
    position: absolute; left: 44px; top: 50%;
    transform: translateY(-50%);
    color: var(--mg-text-muted); font-size: .95rem; pointer-events: none;
    transition: all .15s ease; background: transparent; padding: 0 2px;
  }
  .mg-field > input:focus + label,
  .mg-field > input:not(:placeholder-shown) + label {
    top: 14px; transform: translateY(0); font-size: .72rem;
    color: hsl(var(--primary)); font-weight: 600; letter-spacing: .02em;
  }
  .mg-field .lead-icon {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: var(--mg-text-muted); font-size: 1.05rem; pointer-events: none;
  }
  .mg-field .trail-btn {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: transparent; border: 0; color: var(--mg-text-muted);
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
    display: grid; place-items: center; font-size: 1.05rem;
    transition: background .15s ease, color .15s ease;
  }
  .mg-field .trail-btn:hover { background: var(--mg-surface-2); color: hsl(var(--primary)); }

  .mg-auth__row {
    display: flex; align-items: center; justify-content: space-between;
    margin: 4px 0 22px;
  }
  .mg-auth__row .form-check { margin: 0; }
  .mg-auth__row .form-check-label { font-size: .88rem; color: var(--mg-text-muted); }
  .mg-auth__row a { font-size: .88rem; color: hsl(var(--primary)); text-decoration: none; font-weight: 500; }
  .mg-auth__row a:hover { text-decoration: underline; }

  .mg-auth__submit {
    width: 100%; height: 50px; border: 0; border-radius: 12px; cursor: pointer;
    color: hsl(221 39% 11%); font-weight: 700; font-size: .98rem; letter-spacing: .01em;
    background: linear-gradient(135deg, hsl(38 92% 52%) 0%, hsl(28 80% 50%) 100%);
    box-shadow: 0 10px 22px hsl(38 92% 50% / .30);
    transition: transform .12s ease, box-shadow .18s ease, filter .18s ease;
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  }
  .mg-auth__submit:hover { transform: translateY(-1px); box-shadow: 0 14px 28px hsl(var(--primary) / .35); filter: brightness(1.04); }
  .mg-auth__submit:active { transform: translateY(0); }

  /* ── SSO ──────────────────────────────────────────────────────
     Same footprint as the primary submit but visually secondary: the password
     form stays the default path, and Lark is the alternative for staff whose
     account is linked. */
  .mg-auth__sep {
    display: flex; align-items: center; gap: 12px;
    margin: 18px 0 14px; font-size: .74rem; letter-spacing: .08em;
    text-transform: uppercase; color: var(--mg-text-muted);
  }
  .mg-auth__sep::before, .mg-auth__sep::after {
    content: ''; flex: 1; height: 1px; background: currentColor; opacity: .25;
  }
  .mg-auth__sso {
    width: 100%; height: 50px; border-radius: 12px; cursor: pointer;
    border: 1px solid hsl(0 0% 100% / .18); background: hsl(0 0% 100% / .06);
    color: inherit; font-weight: 600; font-size: .95rem; text-decoration: none;
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    transition: transform .12s ease, background .18s ease, border-color .18s ease;
  }
  .mg-auth__sso:hover {
    transform: translateY(-1px);
    background: hsl(0 0% 100% / .11); border-color: hsl(0 0% 100% / .3); color: inherit;
  }
  .mg-auth__sso:active { transform: translateY(0); }

  .mg-auth__meta { text-align: center; margin-top: 22px; font-size: .8rem; color: var(--mg-text-muted); }
  .mg-auth__meta a { color: hsl(var(--primary)); text-decoration: none; font-weight: 500; }
  .mg-auth__meta a:hover { text-decoration: underline; }

  /* ── Lark QR panel (?qr=1) ────────────────────────────────────
     Lark serves its widget as an iframe it paints white, and a QR code inverted
     by a dark theme does not scan — so the plate under it is white in both
     themes, and only the chrome around it follows the surface colours. */
  .mg-auth__qr {
    display: flex; flex-direction: column; align-items: center; gap: 16px;
    padding: 20px; margin-bottom: 6px;
    background: var(--mg-surface);
    border: 1px solid var(--mg-border); border-radius: 16px;
  }
  .mg-auth__qr-frame {
    width: 260px; height: 260px; border-radius: 12px; overflow: hidden;
    background: #fff; display: grid; place-items: center;
  }
  .mg-auth__qr-frame iframe { border: 0; display: block; }
  .mg-auth__qr-steps { font-size: .84rem; line-height: 1.55; text-align: center; color: var(--mg-text-muted); }
  .mg-auth__qr-steps b { color: var(--mg-text); font-weight: 600; }

  /* ── Automatic Lark sign-in overlay ───────────────────────────
     Covers the viewport rather than the card so it reads the same on the
     two-column desktop layout and the single-column mobile one. Ships hidden
     and is revealed only by JS, so a browser without scripting falls back to
     the plain form instead of staring at a spinner that never resolves. */
  .mg-auth__overlay {
    position: fixed; inset: 0; z-index: 50;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 18px; padding: 32px; text-align: center;
    background: hsl(221 39% 8% / .88); backdrop-filter: blur(6px);
  }
  .mg-auth__overlay[hidden] { display: none; }
  .mg-auth__overlay img { max-height: 54px; width: auto; }
  .mg-auth__overlay .ttl { font-weight: 600; font-size: 1.02rem; }
  .mg-auth__overlay .sub { font-size: .84rem; color: var(--mg-text-muted); }

  .alert { border-radius: 12px; }

  /* ── Responsive ─────────────────────────────────────────────
     Was a lone ad-hoc 960px breakpoint with nothing below it, so a 360px phone
     got the same 48px/32px padding and 52px fields as a tablet. Normalised onto
     the app's canonical ladder and given the two tiers it was missing. */

  /* Tablet and below: the hero column goes, the form takes the screen. */
  @media (max-width: 991.98px) {
    .mg-auth { grid-template-columns: 1fr; }
    .mg-auth__hero { display: none; }
    .mg-auth__form .mobile-brand { display: block; }
  }

  @media (max-width: 767.98px) {
    .mg-auth__form-wrap { padding: 32px 20px; align-items: flex-start; }
    .mg-auth__form h2 { font-size: 1.4rem; }
    .mg-auth__form .lead { margin-bottom: 20px; }
  }

  @media (max-width: 575.98px) {
    /* min-height:100vh + centred content pushes the submit button under the
       keyboard on a short phone. Start at the top and let the page scroll. */
    .mg-auth { min-height: 100dvh; }
    .mg-auth__form-wrap { padding: 24px 16px 40px; }
    .mg-auth__form .mobile-brand { margin-bottom: 18px; }
    .mg-auth__form .mobile-brand img { max-height: 44px; }
    /* Fields and buttons keep a 44px+ target; 52/50px already clear it, so this
       is only about the horizontal breathing room. */
    .mg-field > input { padding-left: 40px; }
    .mg-field > label { left: 40px; }
    .mg-field .lead-icon { left: 12px; }
    /* "Remember me" and "Forgot password?" on one line is ~30px each at 320px. */
    .mg-auth__row { flex-wrap: wrap; gap: 10px; }
    .mg-auth__qr-frame { width: min(260px, 78vw); height: min(260px, 78vw); }
  }

  /* The hero's blurred blobs animate forever; honour a reduced-motion request.
     The gradient background stays — it is decoration that doesn't move. */
  @media (prefers-reduced-motion: reduce) {
    .mg-auth__hero::before, .mg-auth__hero::after { animation: none; }
    .mg-auth__submit:hover, .mg-auth__sso:hover { transform: none; }
  }
