/* ==========================================================================
   Green Nature Crop ERP — Authentication styles
   Design Identity: White 75% / Charcoal 15% / Green 10%
   No gradient, no glassmorphism, no neumorphism, no 3D.
   Mobile-first: 360 / 390 / 412 / 430, desktop is the enhancement.
   ========================================================================== */

:root {
  /* Brand palette (from the spec) */
  --green:        #508444;
  --green-hover:  #437038;   /* darker shade for hover/active, still flat */
  --green-active: #386030;
  --green-soft:   #eef3ec;   /* very light tint for subtle fills only */
  --text:         #1F2937;
  --text-soft:    #6B7280;
  --bg:           #F8FAF7;
  --surface:      #FFFFFF;
  --border:       #E5E7EB;
  --border-strong:#d1d5db;

  /* Semantic */
  --error:        #b42318;
  --error-bg:     #fef3f2;
  --error-border: #fecdca;
  --warning:      #b54708;
  --warning-bg:   #fffaeb;
  --warning-border:#fedf89;
  --success:      #508444;
  --success-bg:   #eef3ec;

  /* Radius */
  --r-card:   16px;
  --r-input:  10px;
  --r-btn:    11px;
  --r-pill:   100px;

  /* Type */
  --ff: 'Inter', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Soft, single-direction shadow — not neumorphism */
  --shadow-card: 0 1px 2px rgba(16,24,40,0.04), 0 8px 24px rgba(16,24,40,0.06);
  --shadow-pop:  0 4px 16px rgba(16,24,40,0.10);

  --ring: 0 0 0 3px rgba(80,132,68,0.22);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--ff);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
}

img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-hover); text-decoration: underline; }

/* ── Page frame (mobile baseline) ────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Brand panel — hidden on mobile, becomes the left column on desktop */
.auth-brand { display: none; }

/* The scrollable column that holds the card on mobile */
.auth-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 28px 20px 20px;
}

/* ── Top brand area (mobile) ─────────────────────────────────────────────── */
.auth-top {
  text-align: center;
  margin-bottom: 24px;
}
.auth-top__logo {
  height: 52px;
  width: auto;
  margin: 0 auto 14px;
}
.auth-top__name {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.auth-top__tagline {
  font-size: 0.8125rem;
  color: var(--text-soft);
  margin-top: 2px;
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: 24px;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}
.auth-card__head { margin-bottom: 20px; }
.auth-card__title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}
.auth-card__subtitle {
  margin-top: 6px;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text-soft);
}

/* ── Form fields ─────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field__label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 7px;
}
.field__wrap { position: relative; display: flex; align-items: center; }
.field__icon {
  position: absolute;
  left: 13px;
  display: inline-flex;
  color: var(--text-soft);
  pointer-events: none;
}
.field__input,
.field__select {
  width: 100%;
  height: 48px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9375rem;
  padding: 0 14px 0 42px;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.field__select { padding-right: 40px; cursor: pointer; }
.field__input::placeholder { color: #9ca3af; }
.field__input:hover,
.field__select:hover { border-color: var(--text-soft); }
.field__input:focus,
.field__select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: var(--ring);
}
/* Right-side affordance (show/hide, chevron) leaves room on the right */
.field--with-action .field__input { padding-right: 46px; }

.field__action {
  position: absolute;
  right: 8px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-soft);
  border-radius: 8px;
}
.field__action:hover { color: var(--text); background: var(--green-soft); }
.field__action:focus-visible { outline: none; box-shadow: var(--ring); }

.field__chevron {
  position: absolute;
  right: 14px;
  color: var(--text-soft);
  pointer-events: none;
}

/* Field-level error */
.field--error .field__input,
.field--error .field__select { border-color: var(--error); }
.field--error .field__input:focus,
.field--error .field__select:focus { box-shadow: 0 0 0 3px rgba(180,35,24,0.18); }
.field__error {
  display: none;
  margin-top: 6px;
  font-size: 0.8125rem;
  color: var(--error);
}
.field--error .field__error { display: block; }

/* ── Row: remember + forgot ──────────────────────────────────────────────── */
.auth-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 20px;
  flex-wrap: wrap;
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.checkbox input {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}
.checkbox__box {
  width: 18px; height: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
}
.checkbox__box svg { opacity: 0; transition: opacity .12s; }
.checkbox input:checked + .checkbox__box {
  background: var(--green);
  border-color: var(--green);
}
.checkbox input:checked + .checkbox__box svg { opacity: 1; }
.checkbox input:focus-visible + .checkbox__box { box-shadow: var(--ring); }
.auth-row__forgot { font-size: 0.875rem; font-weight: 500; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: var(--r-btn);
  font-size: 0.9375rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  transition: background .15s, opacity .15s;
}
.btn--primary { background: var(--green); color: #fff; }
.btn--primary:hover { background: var(--green-hover); }
.btn--primary:active { background: var(--green-active); }
.btn--primary:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn__spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: gnc-spin .7s linear infinite;
  display: none;
}
.btn.is-loading .btn__spinner { display: inline-block; }
.btn.is-loading .btn__label { opacity: .9; }

@keyframes gnc-spin { to { transform: rotate(360deg); } }

.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn--ghost:hover { background: var(--bg); text-decoration: none; }

/* ── Alerts (form-level) ─────────────────────────────────────────────────── */
.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 0.8438rem;
  line-height: 1.45;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert svg { flex-shrink: 0; margin-top: 1px; }
.alert--error   { background: var(--error-bg);   border-color: var(--error-border);   color: var(--error); }
.alert--warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.alert--success { background: var(--success-bg); border-color: #cfe0c9;                color: var(--success); }
.alert--info    { background: var(--green-soft); border-color: #d7e3d3;                color: var(--green-active); }
.alert[hidden] { display: none; }

/* ── Password strength meter ─────────────────────────────────────────────── */
.strength { margin: -6px 0 16px; }
.strength__track {
  height: 5px;
  background: var(--border);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.strength__bar {
  height: 100%;
  width: 0;
  border-radius: var(--r-pill);
  transition: width .2s, background .2s;
}
.strength__bar.is-weak   { width: 33%;  background: var(--error); }
.strength__bar.is-medium { width: 66%;  background: var(--warning); }
.strength__bar.is-strong { width: 100%; background: var(--green); }
.strength__label {
  font-size: 0.75rem;
  color: var(--text-soft);
  margin-top: 5px;
}

/* ── Help link + secondary actions ───────────────────────────────────────── */
.auth-help {
  text-align: center;
  margin-top: 18px;
  font-size: 0.8125rem;
  color: var(--text-soft);
}
.auth-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 18px;
  font-size: 0.875rem;
  font-weight: 500;
}

/* ── Language selector ───────────────────────────────────────────────────── */
.lang {
  display: inline-flex;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-pill);
  padding: 3px;
  gap: 2px;
}
.lang__btn {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--r-pill);
  text-decoration: none;
}
.lang__btn:hover { color: var(--text); text-decoration: none; }
.lang__btn.is-active { background: var(--green); color: #fff; }

.auth-langwrap { display: flex; justify-content: center; margin-top: 22px; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.auth-footer {
  text-align: center;
  padding: 22px 20px 26px;
  color: var(--text-soft);
  font-size: 0.75rem;
}
.auth-footer__links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 8px;
}
.auth-footer__links a { color: var(--text-soft); }
.auth-footer__links a:hover { color: var(--green); }
.auth-footer__meta { display: block; }

/* ── Environment badge ───────────────────────────────────────────────────── */
.env-badge {
  position: fixed;
  top: 12px; right: 12px;
  z-index: 50;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  border: 1px solid;
}
.env-badge--dev { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.env-badge--uat { background: var(--green-soft); border-color: #d7e3d3; color: var(--green-active); }

/* ── System notice ───────────────────────────────────────────────────────── */
.sys-notice {
  margin-bottom: 18px;
}

/* ── Workspace summary chip (single-warehouse hint) ──────────────────────── */
.ws-current {
  background: var(--green-soft);
  border: 1px solid #d7e3d3;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.8438rem;
  color: var(--green-active);
  margin-bottom: 16px;
}

/* ==========================================================================
   Desktop — two columns. Brand/illustration left, form right.
   The form column keeps the exact same card; desktop is additive.
   ========================================================================== */
@media (min-width: 920px) {
  .auth-page {
    flex-direction: row;
  }

  /* Left brand column — flat color, no gradient. Quiet line illustration. */
  .auth-brand {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 46%;
    max-width: 620px;
    padding: 48px 52px;
    background: var(--green);
    color: #fff;
    position: relative;
    overflow: hidden;
  }
  .auth-brand__logo {
    height: 46px;
    width: auto;
    /* logo art already reads on color; sits in a white pill for contrast */
    background: #fff;
    padding: 8px 14px;
    border-radius: 12px;
    align-self: flex-start;
  }
  .auth-brand__body { max-width: 420px; }
  .auth-brand__name {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.01em;
  }
  .auth-brand__tagline {
    font-size: 1.0625rem;
    font-weight: 500;
    margin-top: 8px;
    color: rgba(255,255,255,0.92);
  }
  .auth-brand__desc {
    font-size: 0.9375rem;
    line-height: 1.65;
    margin-top: 16px;
    color: rgba(255,255,255,0.82);
  }
  .auth-brand__pillars {
    list-style: none;
    margin-top: 28px;
    display: grid;
    gap: 11px;
  }
  .auth-brand__pillars li {
    display: flex;
    align-items: center;
    gap: 11px;
    font-size: 0.9375rem;
    color: rgba(255,255,255,0.95);
  }
  .auth-brand__pillars svg { flex-shrink: 0; opacity: .9; }
  .auth-brand__foot {
    font-size: 0.8125rem;
    color: rgba(255,255,255,0.7);
  }

  /* Decorative supply-chain line motif — flat strokes, sits behind content */
  .auth-brand__motif {
    position: absolute;
    right: -60px;
    bottom: -40px;
    width: 360px;
    height: 360px;
    color: rgba(255,255,255,0.10);
    pointer-events: none;
  }

  /* Right column holds the existing main + footer stacked */
  .auth-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .auth-main {
    justify-content: center;
    padding: 40px;
  }
  .auth-card { padding: 32px; }
  .auth-card__title { font-size: 1.5rem; }

  /* On desktop the in-card brand header is redundant */
  .auth-top { display: none; }

  /* Language selector floats top-right of the form column on desktop */
  .auth-langwrap {
    position: absolute;
    top: 24px; right: 28px;
    margin: 0;
  }
}

/* Larger desktop spacing */
@media (min-width: 1280px) {
  .auth-brand { padding: 60px 64px; }
  .auth-main { padding: 48px; }
}

/* ── Accessibility: reduced motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}

/* Visible keyboard focus everywhere as a floor */
:focus-visible { outline: 2px solid transparent; }
