/* CMMS PM – Auth / PIN Login (mobile-first) */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1e3a5f;
  --primary-light: #2c5282;
  --accent: #e67e22;
  --accent-dark: #c96a12;
  --bg-deep: #eef2f7;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: rgba(30, 58, 95, 0.18);
  --card-bg: rgba(255, 255, 255, 0.98);
  --success: #059669;
  --danger: #dc2626;
  --radius: 22px;
}

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

body.page-login {
  font-family: 'Noto Sans Thai', 'Segoe UI', 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);
}

.bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: linear-gradient(145deg, #1e3a5f 0%, #2c5282 45%, #1a3352 100%);
}

.bg-canvas::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(230, 126, 34, 0.12) 0%, transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.06) 0%, transparent 40%);
}

.bg-canvas::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.07) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.5), transparent 85%);
}

.orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: 1;
}

.orb-1 {
  width: min(320px, 75vw);
  height: min(320px, 75vw);
  background: rgba(230, 126, 34, 0.25);
  top: -80px;
  right: -60px;
}

.orb-2 {
  width: min(280px, 65vw);
  height: min(280px, 65vw);
  background: rgba(44, 82, 130, 0.45);
  bottom: -70px;
  left: -50px;
}

.brand-badge {
  position: relative;
  z-index: 10;
  text-align: center;
  color: rgba(255, 255, 255, 0.92);
  margin-bottom: 1.25rem;
  animation: fadeDown 0.5s ease;
}

.brand-badge .brand-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 0.65rem;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 8px 24px rgba(230, 126, 34, 0.4);
}

.brand-badge h1 {
  font-size: clamp(1.15rem, 4vw, 1.35rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-badge p {
  font-size: 0.78rem;
  opacity: 0.82;
  margin-top: 0.25rem;
}

.login-shell {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 400px;
  animation: slideUp 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.card-login {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  padding: clamp(1.25rem, 4vw, 1.75rem);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.22),
    0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.header-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  box-shadow: 0 6px 18px rgba(30, 58, 95, 0.35);
}

.header-title {
  font-size: clamp(1rem, 3.5vw, 1.1rem);
  font-weight: 700;
  color: var(--primary);
}

.header-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.alert {
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 0.84rem;
  margin-bottom: 1rem;
  display: none;
  line-height: 1.5;
}

.alert.error {
  display: block;
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: #b91c1c;
}

.alert.success {
  display: block;
  background: rgba(5, 150, 105, 0.08);
  border: 1px solid rgba(5, 150, 105, 0.25);
  color: var(--success);
}

.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;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

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

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

.pin-dot.filled {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-color: var(--accent);
  transform: scale(1.1);
  box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.2);
}

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

.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.45rem, 2vw, 0.65rem);
  max-width: 300px;
  margin: 0 auto 1rem;
}

.numpad-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(50px, 13vw, 58px);
  font-family: 'Inter', 'Segoe UI', sans-serif;
  font-size: clamp(1.2rem, 4.2vw, 1.45rem);
  font-weight: 600;
  color: var(--primary);
  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, border-color 0.12s;
  box-shadow: 0 2px 0 rgba(30, 58, 95, 0.08);
}

.numpad-btn:hover:not(:disabled) {
  border-color: rgba(230, 126, 34, 0.45);
  background: rgba(230, 126, 34, 0.06);
}

.numpad-btn:active:not(:disabled) {
  transform: scale(0.96);
  box-shadow: none;
}

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

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

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

.numpad-btn.action-danger:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.06);
  border-color: rgba(220, 38, 38, 0.3);
}

.btn-submit {
  width: 100%;
  height: 52px;
  min-height: 44px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dark) 100%);
  border: none;
  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, opacity 0.2s;
  box-shadow: 0 4px 0 #a8550f, 0 8px 20px rgba(230, 126, 34, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-submit:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #a8550f, 0 4px 10px rgba(230, 126, 34, 0.3);
}

.btn-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: 0 2px 0 #a8550f;
}

.card-footer {
  text-align: center;
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.card-footer a {
  color: var(--primary-light);
  text-decoration: none;
  font-weight: 600;
}

.card-footer a:hover {
  color: var(--accent);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

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

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

@media (min-width: 768px) {
  body.page-login { padding: 2rem; }
  .numpad { max-width: 320px; }
}

@media (max-width: 360px) {
  .card-login { padding: 1.1rem; }
  .numpad { gap: 0.4rem; }
}
