/* ═══════════════════════════════════════════════════════════
   RentalOS — Login / Register Styles
   Premium dark mode with glassmorphism & indigo accent
   ═══════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ── */
:root {
  --bg:              #0b1120;
  --bg-card:         rgba(17, 24, 39, 0.80);
  --bg-card-solid:   #111827;
  --bg-input:        #0f172a;
  --input-bg:        #1a2332;
  --primary:         #4F46E5;
  --primary-hover:   #4338CA;
  --primary-light:   rgba(79, 70, 229, 0.15);
  --primary-glow:    rgba(79, 70, 229, 0.35);
  --text:            #f1f5f9;
  --text-secondary:  #94a3b8;
  --text-muted:      #64748b;
  --border:          #1e293b;
  --border-focus:    #4F46E5;
  --danger:          #ef4444;
  --danger-bg:       rgba(239, 68, 68, 0.08);
  --danger-border:   rgba(239, 68, 68, 0.20);
  --success:         #22c55e;
  --success-bg:      rgba(34, 197, 94, 0.08);
  --shadow:          0 4px 24px rgba(0,0,0,0.3);
  --card-shadow:     0 8px 32px rgba(0,0,0,0.4);
  --link:            #818cf8;
  --link-hover:      #a5b4fc;
  --radius:          16px;
  --radius-sm:       10px;
  --radius-xs:       8px;
  --transition:      0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --font:            'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ── Light Theme Overrides ── */
:root[data-theme="light"] {
  --bg:              #f0f2f5;
  --bg-card:         #ffffff;
  --bg-card-solid:   #ffffff;
  --bg-input:        #f8fafc;
  --input-bg:        #f8fafc;
  --primary:         #4F46E5;
  --primary-hover:   #4338CA;
  --primary-light:   rgba(79, 70, 229, 0.10);
  --primary-glow:    rgba(79, 70, 229, 0.18);
  --text:            #1e293b;
  --text-secondary:  #64748b;
  --text-muted:      #94a3b8;
  --border:          #e2e8f0;
  --border-focus:    #4F46E5;
  --danger:          #dc2626;
  --danger-bg:       rgba(220, 38, 38, 0.06);
  --danger-border:   rgba(220, 38, 38, 0.18);
  --success:         #16a34a;
  --success-bg:      rgba(22, 163, 74, 0.06);
  --shadow:          0 4px 24px rgba(0,0,0,0.08);
  --card-shadow:     0 8px 32px rgba(0,0,0,0.08);
  --link:            #4F46E5;
  --link-hover:      #4338CA;
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: hidden;
  position: relative;
}

/* ── Background Decorations ── */
.bg-gradient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(79, 70, 229, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 100%, rgba(79, 70, 229, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
  animation: glowFloat 12s ease-in-out infinite alternate;
}

.bg-glow--1 {
  width: 400px;
  height: 400px;
  background: rgba(79, 70, 229, 0.12);
  top: -100px;
  left: -100px;
}

.bg-glow--2 {
  width: 350px;
  height: 350px;
  background: rgba(99, 102, 241, 0.08);
  bottom: -80px;
  right: -80px;
  animation-delay: -6s;
}

@keyframes glowFloat {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(30px, 20px) scale(1.1); }
}

/* ── Grid dot pattern (desktop) ── */
@media (min-width: 768px) {
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: radial-gradient(rgba(148, 163, 184, 0.08) 1px, transparent 1px);
    background-size: 32px 32px;
    pointer-events: none;
    z-index: 0;
  }
}

/* ── Auth Wrapper ── */
.auth-wrapper {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  min-height: calc(100dvh - 60px);
  padding: 2rem 1rem;
}

/* ── Logo / Branding ── */
.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
  animation: fadeSlideDown 0.6s ease-out both;
}

.auth-logo__icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 0.75rem;
  filter: drop-shadow(0 4px 12px rgba(79, 70, 229, 0.3));
  animation: vanBounce 3s ease-in-out infinite;
}

@keyframes vanBounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

.auth-logo__title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #e0e7ff 0%, #a5b4fc 40%, #818cf8 70%, #6366f1 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.auth-logo__subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.375rem;
  font-weight: 400;
}

/* ── Auth Card (Glassmorphism) ── */
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 2.5rem;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.02),
    0 4px 6px -1px rgba(0, 0, 0, 0.3),
    0 20px 40px -8px rgba(0, 0, 0, 0.5),
    0 0 80px -20px rgba(79, 70, 229, 0.08);
  position: relative;
  overflow: hidden;
  animation: fadeSlideUp 0.5s ease-out 0.15s both;
}

:root[data-theme="light"] .auth-card {
  backdrop-filter: blur(12px) saturate(1.1);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  border-color: var(--border);
  box-shadow: var(--card-shadow);
}

/* Top accent line */
.auth-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  opacity: 0.6;
}

/* ── View System ── */
.auth-view {
  display: none;
  opacity: 0;
  transform: translateY(8px);
}

.auth-view--active {
  display: block;
  animation: viewEnter 0.35s ease-out forwards;
}

.auth-view--exiting {
  display: block;
  animation: viewExit 0.2s ease-in forwards;
}

@keyframes viewEnter {
  0%   { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes viewExit {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-8px); }
}

@keyframes fadeSlideUp {
  0%   { opacity: 0; transform: translateY(16px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes fadeSlideDown {
  0%   { opacity: 0; transform: translateY(-12px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ── View Header ── */
.auth-view__header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.auth-view__icon {
  color: var(--primary);
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: center;
}

.auth-view__title {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.auth-view__desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.375rem;
}

/* ── Form ── */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
  transition: color var(--transition);
  z-index: 1;
}

.form-input {
  width: 100%;
  height: 48px;
  padding: 0 14px 0 42px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9375rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input:hover {
  border-color: rgba(79, 70, 229, 0.3);
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light), 0 0 20px -4px var(--primary-glow);
  background: var(--input-bg);
}

.form-input:focus ~ .input-icon,
.input-wrapper:focus-within .input-icon {
  color: var(--primary);
}

/* Password toggle */
.input-toggle-password {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color var(--transition);
  z-index: 1;
}

.input-toggle-password:hover {
  color: var(--text-secondary);
}

/* ── Password Strength Indicator ── */
.password-strength {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}

.password-strength__bar {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

.password-strength__bar[data-strength="1"] {
  width: 25%;
  background: var(--danger);
}

.password-strength__bar[data-strength="2"] {
  width: 50%;
  background: #f59e0b;
}

.password-strength__bar[data-strength="3"] {
  width: 75%;
  background: #eab308;
}

.password-strength__bar[data-strength="4"] {
  width: 100%;
  background: var(--success);
}

/* ── Error Messages ── */
.form-error {
  font-size: 0.8125rem;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-xs);
  padding: 0.625rem 0.875rem;
  display: none;
  align-items: center;
  gap: 0.5rem;
  line-height: 1.4;
  animation: shakeError 0.4s ease-out;
}

.form-error--visible {
  display: flex;
}

.form-error::before {
  content: '⚠';
  flex-shrink: 0;
  font-size: 0.875rem;
}

@keyframes shakeError {
  0%, 100% { transform: translateX(0); }
  15%      { transform: translateX(-6px); }
  30%      { transform: translateX(5px); }
  45%      { transform: translateX(-4px); }
  60%      { transform: translateX(3px); }
  75%      { transform: translateX(-2px); }
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  height: 48px;
  padding: 0 1.5rem;
  border: none;
  border-radius: var(--radius-xs);
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:focus-visible {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary);
}

/* Primary button */
.btn--primary {
  background: linear-gradient(135deg, var(--primary) 0%, #6366f1 100%);
  color: #fff;
  box-shadow: 0 2px 8px -2px rgba(79, 70, 229, 0.4);
}

.btn--primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-hover) 0%, #4f46e5 100%);
  box-shadow: 0 4px 16px -2px rgba(79, 70, 229, 0.5);
  transform: translateY(-1px);
}

.btn--primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 4px -1px rgba(79, 70, 229, 0.4);
}

/* Secondary button */
.btn--secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}

.btn--secondary:hover:not(:disabled) {
  border-color: rgba(79, 70, 229, 0.4);
  color: var(--text);
  background: rgba(79, 70, 229, 0.06);
}

/* Disabled state */
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

/* Loading state */
.btn--loading .btn__text {
  opacity: 0;
}

.btn--loading .btn__spinner {
  display: block;
}

.btn__spinner {
  display: none;
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

.btn--secondary .btn__spinner {
  border-color: rgba(148, 163, 184, 0.25);
  border-top-color: var(--text-secondary);
}

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

.btn__icon {
  font-size: 1.125rem;
  line-height: 1;
}

/* ── Divider ── */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Switch Links ── */
.auth-switch {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.auth-switch__link {
  color: var(--link);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}

.auth-switch__link:hover {
  color: var(--link-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── TOTP Inputs ── */
.totp-inputs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.totp-separator {
  color: var(--text-muted);
  font-size: 1.25rem;
  font-weight: 300;
  margin: 0 0.125rem;
  user-select: none;
}

.totp-input {
  width: 52px;
  height: 56px;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  caret-color: var(--primary);
  -webkit-appearance: none;
  appearance: none;
}

.totp-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.totp-input--filled {
  border-color: rgba(79, 70, 229, 0.5);
  background: rgba(79, 70, 229, 0.05);
}

.totp-input--error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
  animation: shakeError 0.4s ease-out;
}

/* ── Toast Notifications ── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-card-solid);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: var(--font);
  box-shadow: var(--card-shadow);
  animation: toastIn 0.35s ease-out;
  max-width: 360px;
  text-align: center;
  line-height: 1.4;
}

.toast--info {
  border-color: rgba(79, 70, 229, 0.3);
}

.toast--exiting {
  animation: toastOut 0.25s ease-in forwards;
}

@keyframes toastIn {
  0%   { opacity: 0; transform: translateY(12px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(8px) scale(0.95); }
}

/* ── Footer ── */
.auth-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ── Theme Toggle Button ── */
.theme-toggle {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  transition: all 0.3s ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  color: var(--text);
}

.theme-toggle:hover {
  transform: scale(1.1);
  border-color: var(--primary);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* ── Light mode adjustments ── */
:root[data-theme="light"] .bg-glow {
  opacity: 0.15;
}

:root[data-theme="light"] .bg-gradient {
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(79, 70, 229, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 100%, rgba(79, 70, 229, 0.03) 0%, transparent 50%);
}

:root[data-theme="light"] .auth-logo__title {
  background: linear-gradient(135deg, #4338CA 0%, #4F46E5 40%, #6366f1 70%, #818cf8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

:root[data-theme="light"] .toast {
  box-shadow: var(--card-shadow);
}

/* ══════════════════════════════════
   Responsive
   ══════════════════════════════════ */

@media (max-width: 480px) {
  .auth-card {
    padding: 1.75rem 1.25rem;
    border-radius: 12px;
  }

  .auth-logo__title {
    font-size: 1.5rem;
  }

  .auth-logo__icon {
    font-size: 2.5rem;
  }

  .totp-input {
    width: 44px;
    height: 48px;
    font-size: 1.25rem;
  }

  .totp-inputs {
    gap: 0.375rem;
  }
}

@media (min-width: 481px) and (max-width: 767px) {
  .auth-card {
    padding: 2rem 1.75rem;
  }
}

/* Safe area padding for notched devices (Capacitor / PWA) */
@supports (padding: env(safe-area-inset-bottom)) {
  .auth-footer {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  .toast-container {
    bottom: calc(1.5rem + env(safe-area-inset-bottom));
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
