/* BFG CMMS (EN) – Auth pages (mobile-first, responsive) */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep: #ffffff;
  --accent: #10b981;
  --accent2: #059669;
  --text: #0f172a;
  --text-muted: #475569;
  --border: rgba(16, 185, 129, 0.4);
  --card-bg: rgba(255, 255, 255, 0.98);
  --success: #059669;
  --danger: #dc2626;
  --input-bg: #ffffff;
  --radius: 20px;
}

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; height: 100%; }

body {
  font-family: 'Noto Sans Thai', 'Inter', sans-serif;
  background: var(--bg-deep);
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  position: relative;
  overflow-x: hidden;
  color: var(--text);
}

body.page-register {
  align-items: flex-start;
  padding-top: max(1.5rem, env(safe-area-inset-top));
}

.bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg-deep);
}
.bg-canvas::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(52, 211, 153, 0.08) 1px, transparent 1px);
  background-size: 36px 36px;
}
.orb { position: fixed; border-radius: 50%; filter: blur(90px); opacity: 0.35; pointer-events: none; }
.orb-1 { width: min(360px, 80vw); height: min(360px, 80vw); background: rgba(16, 185, 129, 0.15); top: -100px; left: -80px; }
.orb-2 { width: min(300px, 70vw); height: min(300px, 70vw); background: rgba(20, 184, 166, 0.1); bottom: -60px; right: -50px; }

.card {
  position: relative;
  z-index: 10;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.3rem, 4vw, 2.2rem) clamp(1rem, 4vw, 1.8rem);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.08), 0 0 0 4px rgba(16, 185, 129, 0.08);
  animation: slideUp 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.card.card-wide { max-width: 520px; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--border);
}
.header-icon {
  width: 50px;
  height: 50px;
  flex-shrink: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.35);
}
.header-title { font-size: clamp(1.05rem, 3.5vw, 1.2rem); font-weight: 700; }
.header-sub { font-size: 0.74rem; color: var(--text-muted); margin-top: 0.15rem; }

.alert {
  border-radius: 12px;
  padding: 0.8rem 1rem;
  font-size: 0.84rem;
  margin-bottom: 1.2rem;
  display: none;
  line-height: 1.5;
}
.alert.error { background: rgba(255, 77, 109, 0.1); border: 1px solid rgba(255, 77, 109, 0.3); color: #b91c1c; display: block; }
.alert.success { background: rgba(0, 229, 160, 0.08); border: 1px solid rgba(0, 229, 160, 0.3); color: var(--success); display: block; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}
.form-group { margin-bottom: 0.85rem; }

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
label .required { color: var(--danger); margin-left: 2px; }
label .badge-th {
  display: inline-block;
  font-size: 0.62rem;
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent2);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 6px;
  padding: 1px 6px;
  margin-left: 5px;
  font-weight: 500;
}

.input-wrap { position: relative; }
.input-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
  pointer-events: none;
  color: var(--text-muted);
  z-index: 1;
}

input, select {
  width: 100%;
  height: 50px;
  min-height: 44px;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: 'Noto Sans Thai', sans-serif;
  font-size: 16px;
  padding: 0 14px 0 40px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input::placeholder { color: var(--text-muted); opacity: 0.65; }
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}
.input-wrap:focus-within .input-icon { color: var(--accent); }
input.valid { border-color: var(--success); }
input.invalid { border-color: var(--danger); }

select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b8db5' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
select option { background: #fff; color: var(--text); }

.field-hint { font-size: 0.71rem; color: var(--text-muted); margin-top: 0.3rem; display: block; min-height: 0.9rem; }
.field-hint.err { color: var(--danger); }
.field-hint.ok { color: var(--success); }

.divider {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
  color: var(--text-muted);
  font-size: 0.72rem;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.pin-preview {
  background: rgba(16, 185, 129, 0.06);
  border: 1px dashed rgba(16, 185, 129, 0.25);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.pin-preview .pin-val {
  font-family: 'Inter', monospace;
  font-size: 1.05rem;
  color: var(--accent2);
  font-weight: 700;
  letter-spacing: 4px;
}

.btn-submit {
  width: 100%;
  height: 52px;
  min-height: 44px;
  background: linear-gradient(180deg, #10b981 0%, #059669 100%);
  border: 1px solid #059669;
  border-radius: 14px;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  font-family: 'Noto Sans Thai', sans-serif;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 4px 0 #047857, 0 8px 16px rgba(16, 185, 129, 0.3);
}
.btn-submit:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 0 0 #047857, 0 2px 6px rgba(16, 185, 129, 0.3);
}
.btn-submit:disabled { opacity: 0.6; cursor: wait; }

.card-footer {
  text-align: center;
  margin-top: 1.2rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.card-footer a { color: var(--accent2); text-decoration: none; font-weight: 500; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: middle;
  margin-right: 5px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
}

@media (min-width: 768px) {
  body { padding-left: 2rem; padding-right: 2rem; }
}

@media (min-width: 1024px) {
  .card { padding: 2.2rem 2rem; }
}

/* ── PIN keypad (login) ─────────────────────── */
body.page-login {
  align-items: flex-start;
  padding-top: max(1rem, env(safe-area-inset-top));
}

.card.card-login {
  max-width: 400px;
}

.pin-section {
  text-align: center;
  margin-bottom: 1rem;
}

.pin-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: clamp(0.55rem, 3vw, 0.85rem);
  margin-bottom: 0.5rem;
}

.pin-dot {
  width: clamp(12px, 3.5vw, 16px);
  height: clamp(12px, 3.5vw, 16px);
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.pin-dot.filled {
  background: var(--accent2);
  border-color: var(--accent2);
  transform: scale(1.08);
}

.pin-dot.error {
  border-color: var(--danger);
  background: rgba(220, 38, 38, 0.25);
  animation: pinShake 0.4s ease;
}

@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.pin-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  min-height: 1.1rem;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(0.5rem, 2vw, 0.75rem);
  margin-bottom: 1rem;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.numpad-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(52px, 14vw, 64px);
  aspect-ratio: 1.4 / 1;
  font-family: 'Inter', sans-serif;
  font-size: clamp(1.25rem, 4.5vw, 1.6rem);
  font-weight: 600;
  color: var(--text);
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background 0.12s, transform 0.1s, box-shadow 0.12s;
  box-shadow: 0 2px 0 rgba(16, 185, 129, 0.12);
}

.numpad-btn:active:not(:disabled) {
  background: rgba(16, 185, 129, 0.12);
  transform: scale(0.96);
  box-shadow: none;
}

.numpad-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.numpad-btn.action {
  font-size: clamp(0.85rem, 3vw, 1rem);
  font-family: 'Noto Sans Thai', sans-serif;
  font-weight: 600;
  color: var(--text-muted);
}

.numpad-btn.action-danger {
  color: var(--danger);
}

@media (min-width: 768px) {
  body.page-login { align-items: center; }
  .numpad { max-width: 340px; }
}
