/* ── Design tokens ── */
:root {
  --navy: #09052c;
  --navy-light: #151042;
  --navy-deep: #040030;
  --gold: #eabc73;
  --gold-light: #f5d9a8;
  --gold-glow: rgba(234, 188, 115, 0.45);
  --glass-border: rgba(255, 255, 255, 0.18);
  --glass-highlight: rgba(255, 255, 255, 0.35);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.65);
  --text-muted: rgba(255, 255, 255, 0.4);
  --blur: 24px;
  --radius: clamp(16px, 4vw, 24px);
  --radius-sm: clamp(10px, 2.5vw, 14px);
  --transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  --page-pad: clamp(0.75rem, 3vw, 2rem);
  --panel-pad-x: clamp(1.25rem, 4vw, 2.5rem);
  --panel-pad-y: clamp(1.25rem, 3.5vw, 2.75rem);
  --form-gap: clamp(0.75rem, 2.5vw, 1.25rem);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Outfit', system-ui, sans-serif;
  height: 100dvh;
  max-height: 100dvh;
  background-color: #000;
  background-image: url('../images/login-bg.jpg');
  background-position: center center;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text-primary);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(
      180deg,
      rgba(0, 0, 0, 0.25) 0%,
      rgba(0, 0, 0, 0.35) 50%,
      rgba(0, 0, 0, 0.45) 100%
    );
  pointer-events: none;
}

/* ── Layout ── */
.login-page {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(var(--page-pad), env(safe-area-inset-top))
    max(var(--page-pad), env(safe-area-inset-right))
    max(var(--page-pad), env(safe-area-inset-bottom))
    max(var(--page-pad), env(safe-area-inset-left));
  overflow: hidden;
}

/* ── Glass panel (login card) ── */
.glass-panel {
  position: relative;
  width: 100%;
  max-width: min(440px, 100%);
  padding: var(--panel-pad-y) var(--panel-pad-x);
  border-radius: var(--radius);
  background: linear-gradient(
    145deg,
    rgba(9, 5, 44, 0.94) 0%,
    rgba(13, 0, 102, 0.9) 45%,
    rgba(4, 0, 48, 0.95) 100%
  );
  backdrop-filter: blur(var(--blur)) saturate(1.6);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.6);
  border: 1px solid var(--glass-border);
  box-shadow:
    0 8px 32px rgba(9, 5, 44, 0.25),
    0 2px 8px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 var(--glass-highlight),
    inset 0 -1px 0 rgba(0, 0, 0, 0.1);
  overflow: hidden;
  flex-shrink: 1;
}

.glass-shine {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.12) 0%,
    rgba(255, 255, 255, 0.02) 60%,
    transparent 100%
  );
  border-radius: var(--radius) var(--radius) 0 0;
  pointer-events: none;
}

/* ── Brand header ── */
.brand {
  text-align: center;
  margin-bottom: clamp(1rem, 3vh, 2.25rem);
}

.brand-icon {
  display: block;
  width: clamp(44px, 12vw, 56px);
  height: clamp(44px, 12vw, 56px);
  margin: 0 auto clamp(0.5rem, 1.5vh, 1rem);
  filter: drop-shadow(0 4px 20px var(--gold-glow));
  animation: iconPulse 4s ease-in-out infinite;
}

@keyframes iconPulse {
  0%, 100% { filter: drop-shadow(0 4px 20px var(--gold-glow)); }
  50% { filter: drop-shadow(0 6px 28px rgba(234, 188, 115, 0.6)); }
}

.brand-wordmark {
  width: min(260px, 78%);
  height: auto;
  margin: 0 auto;
  display: block;
}

.brand-tagline {
  margin-top: clamp(0.35rem, 1vh, 0.75rem);
  font-size: clamp(0.6875rem, 2.5vw, 0.875rem);
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── Form ── */
.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--form-gap);
}

.field label {
  display: block;
  font-size: clamp(0.75rem, 2.5vw, 0.8125rem);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: clamp(0.3rem, 1vh, 0.5rem);
  letter-spacing: 0.02em;
}

.field-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: clamp(0.3rem, 1vh, 0.5rem);
}

.field-header label {
  margin-bottom: 0;
}

.input-glass {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  overflow: hidden;
}

.input-glass::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.08) 0%, transparent 50%);
  pointer-events: none;
}

.input-glass:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(234, 188, 115, 0.15), inset 0 1px 0 rgba(255,255,255,0.1);
  background: rgba(255, 255, 255, 0.09);
}

.input-glass.is-invalid {
  border-color: #ff6b6b;
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.15), inset 0 1px 0 rgba(255,255,255,0.1);
}

.input-glass.is-invalid .input-icon {
  color: #ff8a8a;
}

.field-error {
  margin-top: clamp(0.3rem, 1vh, 0.45rem);
  font-size: clamp(0.75rem, 2.2vw, 0.8125rem);
  font-weight: 500;
  color: #ff6b6b;
  line-height: 1.35;
}

.field-error[hidden] {
  display: none;
}

.input-icon {
  width: 18px;
  height: 18px;
  margin-left: 0.875rem;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color var(--transition);
}

.input-glass:focus-within .input-icon {
  color: var(--gold);
}

.input-glass input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  padding: clamp(0.7rem, 2vh, 0.9rem) 0.875rem;
  font-family: inherit;
  font-size: 16px;
  color: var(--text-primary);
}

.input-glass input::placeholder {
  color: var(--text-muted);
}

/* Keep glass look when browser autofills saved credentials */
.input-glass input:-webkit-autofill,
.input-glass input:-webkit-autofill:hover,
.input-glass input:-webkit-autofill:focus,
.input-glass input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text-primary) !important;
  caret-color: var(--text-primary);
  background-color: transparent !important;
  -webkit-box-shadow: 0 0 0 1000px transparent inset !important;
  box-shadow: 0 0 0 1000px transparent inset !important;
  transition: background-color 99999s ease-out 0s, color 99999s ease-out 0s;
}

.input-glass input:autofill,
.input-glass input:autofill:hover,
.input-glass input:autofill:focus,
.input-glass input:autofill:active {
  -webkit-text-fill-color: var(--text-primary);
  caret-color: var(--text-primary);
  background-color: transparent !important;
  box-shadow: 0 0 0 1000px transparent inset !important;
}

.toggle-password {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem 0.875rem;
  color: var(--text-muted);
  transition: color var(--transition);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  touch-action: manipulation;
}

.toggle-password:hover {
  color: var(--gold);
}

.toggle-password svg {
  width: 18px;
  height: 18px;
}

.toggle-password .eye-closed {
  display: none;
}

.toggle-password.is-visible .eye-open {
  display: none;
}

.toggle-password.is-visible .eye-closed {
  display: block;
}

/* ── Checkbox ── */
.checkbox-glass {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
  font-size: clamp(0.8125rem, 2.5vw, 0.875rem);
  color: var(--text-secondary);
  user-select: none;
  touch-action: manipulation;
}

.checkbox-glass input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.checkmark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.checkbox-glass input:checked + .checkmark {
  background: var(--gold);
  border-color: var(--gold);
}

.checkbox-glass input:checked + .checkmark::after {
  content: '';
  width: 5px;
  height: 8px;
  border: solid var(--navy);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translateY(-1px);
}

/* ── Primary button ── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: clamp(0.75rem, 2vh, 0.95rem) 1.25rem;
  margin-top: clamp(0.15rem, 0.5vh, 0.5rem);
  font-family: inherit;
  font-size: clamp(0.9375rem, 2.5vw, 1rem);
  font-weight: 600;
  color: var(--navy);
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 50%, #d4a85c 100%);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
  touch-action: manipulation;
  box-shadow:
    0 4px 20px rgba(234, 188, 115, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.3) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--transition);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow:
    0 8px 30px rgba(234, 188, 115, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.btn-primary:hover::before {
  opacity: 1;
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary svg {
  width: 18px;
  height: 18px;
  transition: transform var(--transition);
}

.btn-primary .btn-spinner {
  display: none;
  animation: btnSpin 0.75s linear infinite;
}

.btn-primary.is-loading,
.btn-primary:disabled {
  cursor: not-allowed;
  opacity: 0.88;
  transform: none;
  pointer-events: none;
}

.btn-primary.is-loading:hover,
.btn-primary:disabled:hover {
  transform: none;
  box-shadow:
    0 4px 20px rgba(234, 188, 115, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn-primary.is-loading .btn-arrow,
.btn-primary.is-loading:hover .btn-arrow {
  display: none;
  transform: none;
}

.btn-primary.is-loading .btn-spinner {
  display: block;
}

@keyframes btnSpin {
  to { transform: rotate(360deg); }
}

.btn-primary:hover .btn-arrow {
  transform: translateX(3px);
}

/* ── Links ── */
.link-subtle {
  font-size: clamp(0.6875rem, 2.2vw, 0.8125rem);
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.link-subtle:hover {
  color: var(--gold);
}

.link-gold {
  color: var(--gold);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}

.link-gold:hover {
  color: var(--gold-light);
}

.panel-footer {
  margin-top: clamp(1rem, 2.5vh, 2rem);
  text-align: center;
  font-size: clamp(0.75rem, 2.5vw, 0.875rem);
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Short screens: compact further to avoid scroll ── */
@media (max-height: 680px) {
  .brand-tagline {
    display: none;
  }

  .brand {
    margin-bottom: 0.875rem;
  }

  .panel-footer {
    margin-top: 0.875rem;
  }
}

@media (max-height: 580px) {
  :root {
    --panel-pad-y: 1rem;
    --form-gap: 0.625rem;
  }

  .brand-icon {
    width: 40px;
    height: 40px;
    margin-bottom: 0.375rem;
  }

  .brand-wordmark {
    width: min(220px, 72%);
  }

  .brand {
    margin-bottom: 0.75rem;
  }

  .panel-footer {
    margin-top: 0.75rem;
  }
}

/* ── Narrow screens ── */
@media (max-width: 360px) {
  .brand-wordmark {
    width: 88%;
  }

  .field-header {
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  body {
    background-attachment: scroll;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .brand-icon {
    animation: none;
  }

  .btn-primary:hover {
    transform: none;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
