/**
 * Authentication Styles for Principia Metaphysica
 *
 * Styles for login overlay, auth states, and user controls.
 * Uses purple/pink gradient theme matching the site aesthetic.
 *
 * Copyright (c) 2025-2026 Andrew Keith Watts. All rights reserved.
 */

/* ============================================
   Auth State Classes
   ============================================ */

/* LOADING STATE - Show spinner while determining auth */
body.auth-loading {
  overflow: hidden;
}

body.auth-loading #main-content,
body.auth-loading .auth-overlay {
  display: none !important;
}

body.auth-loading #auth-loading-screen {
  display: flex !important;
}

/* Hide loading screen by default */
#auth-loading-screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 10001;
}

#auth-loading-screen .auth-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(139, 127, 255, 0.2);
  border-top-color: #8b7fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

#auth-loading-screen .loading-text {
  margin-top: 20px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 16px;
  font-family: 'Georgia', 'Times New Roman', serif;
}

/* Hide main content when not authenticated */
body.not-authenticated #main-content {
  display: none !important;
}

body.not-authenticated .auth-overlay {
  display: flex !important;
}

/* Show main content when authenticated */
body.authenticated #main-content {
  display: block;
}

body.authenticated .auth-overlay {
  display: none !important;
}

/* ============================================
   Auth Overlay (Login Screen)
   ============================================ */

.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  padding: 20px;
  box-sizing: border-box;
}

.auth-card {
  background: linear-gradient(145deg, rgba(30, 30, 50, 0.95), rgba(20, 20, 40, 0.98));
  border-radius: 20px;
  padding: 50px 40px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow:
    0 25px 50px -12px rgba(0, 0, 0, 0.5),
    0 0 60px rgba(139, 127, 255, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(139, 127, 255, 0.2);
}

/* Logo/Symbol */
.auth-logo {
  margin-bottom: 25px;
}

.pm-symbol {
  display: inline-block;
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 48px;
  font-weight: bold;
  font-style: italic;
  color: transparent;
  background: linear-gradient(135deg, #b794f6 0%, #8b7fff 50%, #e879f9 100%);
  -webkit-background-clip: text;
  background-clip: text;
  text-shadow: 0 0 30px rgba(139, 127, 255, 0.5);
}

/* Title */
.auth-title {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 32px;
  font-weight: normal;
  color: #ffffff;
  margin: 0 0 8px 0;
  letter-spacing: 1px;
}

/* Latin subtitle */
.auth-latin {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-style: italic;
  font-size: 14px;
  color: rgba(183, 148, 246, 0.8);
  margin: 0 0 30px 0;
  letter-spacing: 0.5px;
}

/* Framework title block */
.auth-framework {
  background: linear-gradient(135deg, rgba(139, 127, 255, 0.1), rgba(232, 121, 249, 0.1));
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 25px;
  border: 1px solid rgba(139, 127, 255, 0.15);
}

.auth-framework h2 {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 20px;
  font-weight: normal;
  color: #ffffff;
  margin: 0 0 6px 0;
}

.auth-framework p {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  margin: 0;
}

/* Description */
.auth-description {
  font-size: 15px;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.8);
  margin: 0 0 35px 0;
}

/* Google Login Button */
.google-login-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #ffffff;
  color: #444444;
  border: none;
  border-radius: 8px;
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 280px;
}

.google-login-btn:hover {
  background: #f8f8f8;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.google-login-btn:active {
  transform: translateY(0);
}

.google-login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.google-icon {
  width: 20px;
  height: 20px;
}

/* Footer */
.auth-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid rgba(139, 127, 255, 0.15);
}

.auth-footer p {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.5);
  margin: 0;
}

/* ============================================
   Header User Controls (inline in nav)
   ============================================ */

/* User controls nav item - sits inline with other nav items */
.user-controls-nav {
  display: flex;
  align-items: center;
  margin-left: auto;
}

/* User controls container */
.user-controls {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(139, 127, 255, 0.15);
  border-radius: 20px;
  border: 1px solid rgba(139, 127, 255, 0.25);
}

body.authenticated .user-controls {
  display: flex;
}

/* Header login button (shown when not authenticated) */
.header-login-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(139, 127, 255, 0.2);
  border: 1px solid rgba(139, 127, 255, 0.4);
  border-radius: 20px;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.header-login-btn:hover {
  background: rgba(139, 127, 255, 0.35);
  border-color: rgba(139, 127, 255, 0.6);
}

body.authenticated .header-login-btn {
  display: none;
}

.google-icon-small {
  width: 16px;
  height: 16px;
}

#user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(139, 127, 255, 0.5);
  object-fit: cover;
}

#user-email {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.9);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#logout-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease;
}

#logout-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.5);
  color: #ffffff;
}

/* ============================================
   Loading States
   ============================================ */

.auth-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.auth-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(139, 127, 255, 0.2);
  border-top-color: #8b7fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.auth-loading-text {
  margin-top: 16px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
  /* Mobile: Show only avatar and logout, hide email */
  #user-email {
    max-width: 80px;
    font-size: 11px;
  }

  .user-controls {
    padding: 4px 8px;
    gap: 6px;
  }

  #user-avatar {
    width: 24px;
    height: 24px;
  }

  #logout-btn {
    padding: 3px 8px;
    font-size: 10px;
  }

  .header-login-btn {
    padding: 4px 10px;
    font-size: 11px;
  }

  .google-icon-small {
    width: 14px;
    height: 14px;
  }
}

@media (max-width: 600px) {
  .auth-card {
    padding: 35px 25px;
    border-radius: 16px;
  }

  .pm-symbol {
    font-size: 40px;
  }

  .auth-title {
    font-size: 26px;
  }

  .auth-latin {
    font-size: 12px;
  }

  .auth-framework h2 {
    font-size: 18px;
  }

  .auth-description {
    font-size: 14px;
  }

  .google-login-btn {
    padding: 12px 24px;
    font-size: 15px;
  }

  /* Mobile nav: user controls in flex row */
  .user-controls-nav {
    flex-shrink: 0;
  }

  .user-controls {
    padding: 4px 8px;
    gap: 4px;
  }

  #user-email {
    display: none; /* Hide email on small screens */
  }

  #user-avatar {
    width: 22px;
    height: 22px;
  }

  #logout-btn {
    padding: 3px 6px;
    font-size: 9px;
  }

  .header-login-btn {
    padding: 4px 8px;
    font-size: 10px;
    gap: 4px;
  }

  .google-icon-small {
    width: 12px;
    height: 12px;
  }
}

@media (max-width: 400px) {
  .auth-card {
    padding: 30px 20px;
  }

  .auth-title {
    font-size: 22px;
  }

  .auth-framework {
    padding: 15px;
  }

  /* Very small screens: minimal user controls */
  .user-controls {
    padding: 3px 6px;
  }

  #logout-btn {
    padding: 2px 5px;
    font-size: 8px;
  }
}

/* ============================================
   Animation for overlay appearance
   ============================================ */

.auth-overlay {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.auth-card {
  animation: slideUp 0.4s ease-out;
}

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

/* ============================================
   User Identifier for Content Tracking
   ============================================ */

.pm-user-identifier {
  position: fixed;
  bottom: 10px;
  right: 10px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: #8b7fff;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 8px;
  border-radius: 4px;
  z-index: 1000;
  user-select: all;
  pointer-events: auto;
}

@media print {
  .pm-user-identifier {
    position: static;
    display: block;
    text-align: right;
    margin-top: 20px;
    background: none;
    color: #8b7fff;
  }
}

/* ============================================
   Terms of Service Styles
   ============================================ */

.auth-tos {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid rgba(139, 127, 255, 0.15);
}

.auth-tos .tos-notice {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  margin: 0 0 5px 0;
}

.auth-tos .tos-notice a {
  color: #8b7fff;
  text-decoration: underline;
  cursor: pointer;
}

.auth-tos .tos-notice a:hover {
  color: #b794f6;
}

.auth-tos .tos-summary {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  margin: 0;
  font-style: italic;
}

/* Terms of Service Modal */
.tos-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10002;
  padding: 20px;
  box-sizing: border-box;
}

.tos-content {
  background: linear-gradient(145deg, rgba(30, 30, 50, 0.98), rgba(20, 20, 40, 0.99));
  border-radius: 16px;
  padding: 30px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid rgba(139, 127, 255, 0.3);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
}

.tos-content h2 {
  font-family: 'Georgia', serif;
  font-size: 24px;
  color: #fff;
  margin: 0 0 20px 0;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(139, 127, 255, 0.2);
}

.tos-body h3 {
  font-size: 14px;
  color: #8b7fff;
  margin: 20px 0 10px 0;
}

.tos-body p {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.6;
  margin: 0 0 10px 0;
}

.tos-body ul {
  margin: 10px 0;
  padding-left: 20px;
}

.tos-body li {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 8px;
  line-height: 1.5;
}

.tos-close {
  display: block;
  width: 100%;
  margin-top: 25px;
  padding: 12px 24px;
  background: linear-gradient(135deg, #8b7fff, #e879f9);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tos-close:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 127, 255, 0.4);
}

/* ============================================
   Download Watermark Header
   ============================================ */

.download-watermark {
  background: linear-gradient(135deg, rgba(139, 127, 255, 0.1), rgba(232, 121, 249, 0.05));
  border: 1px solid rgba(139, 127, 255, 0.3);
  border-radius: 8px;
  padding: 15px 20px;
  margin-bottom: 20px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: #8b7fff;
}

.download-watermark .watermark-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}

.download-watermark .watermark-row:last-child {
  margin-bottom: 0;
}

.download-watermark .watermark-label {
  color: #8b7fff;
  font-weight: 500;
}

.download-watermark .watermark-value {
  color: #8b7fff;
  font-weight: 500;
}

.download-watermark .watermark-warning {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(139, 127, 255, 0.2);
  color: #8b7fff;
  font-size: 11px;
  font-weight: 500;
  text-align: center;
}

@media print {
  .download-watermark {
    background: #f5f5f5;
    border-color: #8b7fff;
    color: #8b7fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .download-watermark .watermark-label {
    color: #666;
  }

  .download-watermark .watermark-warning {
    color: #333;
  }
}

/* ============================================
   Embedded Identifiers (in-content tracking)
   ============================================ */

.pm-embedded-id {
  display: block;
  text-align: center;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  color: rgba(139, 127, 255, 0.01); /* Extremely subtle - barely visible */
  background: transparent; /* No background */
  padding: 2px 0;
  margin: 8px auto;
  max-width: fit-content;
  user-select: all;
  line-height: 1;
}

@media print {
  .pm-embedded-id {
    background: rgba(139, 127, 255, 0.05);
    color: #8b7fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
