/* Core Reset & Variables */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-primary: #6366f1;
  --accent-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --success: #10b981;
  --error: #ef4444;
  --border-color: rgba(255, 255, 255, 0.08);
  --glass-bg: rgba(30, 41, 59, 0.65);
  --glass-border: rgba(255, 255, 255, 0.08);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none; /* Deter standard text selection */
  -webkit-user-select: none;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Utilities */
.hide {
  display: none !important;
}

/* ==========================================================================
   Auth Gate Screen
   ========================================================================== */
.auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100vh;
  background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.15) 0%, rgba(15, 23, 42, 1) 70%);
  padding: 20px;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}

.auth-card {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 40px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.lock-icon-container {
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(99, 102, 241, 0.05) 100%);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px auto;
}

.lock-icon {
  font-size: 30px;
  color: var(--accent-primary);
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.4));
}

.auth-card h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
}

.auth-card p {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.input-group label {
  position: absolute;
  left: 18px;
  color: var(--text-secondary);
  font-size: 16px;
  pointer-events: none;
  transition: color 0.3s ease;
}

.input-group input {
  width: 100%;
  padding: 16px 16px 16px 48px;
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  letter-spacing: 0.5px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
  background-color: rgba(15, 23, 42, 0.8);
}

.input-group input:focus + label {
  color: var(--accent-primary);
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  border: none;
  border-radius: 14px;
  padding: 16px 24px;
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: opacity 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover {
  opacity: 0.95;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: scale(0.98);
}

.auth-error-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
  color: var(--error);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.auth-error-msg.show {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   Main Viewer Dashboard
   ========================================================================== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

.toolbar {
  height: 70px;
  background-color: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pdf-brand-icon {
  font-size: 24px;
  color: var(--accent-primary);
}

.brand-text {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.toolbar-selector-container {
  flex: 1;
  max-width: 380px;
  margin: 0 20px;
}

.doc-selector {
  width: 100%;
  padding: 8px 14px;
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
}

.doc-selector:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.doc-selector.hide-selector {
  opacity: 0;
  pointer-events: none;
}

.toolbar-navigation {
  display: flex;
  align-items: center;
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  padding: 6px;
  border-radius: 12px;
  gap: 14px;
}

.btn-toolbar {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.btn-toolbar:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.btn-toolbar:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-counter {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 90px;
  text-align: center;
}

#current-page-num {
  color: var(--text-primary);
  font-weight: 600;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-print {
  background: var(--accent-gradient);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
  transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-print:hover {
  opacity: 0.95;
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}

.btn-print:active {
  transform: scale(0.97);
}

.btn-toolbar-sec {
  background-color: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.btn-toolbar-sec:hover {
  background-color: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
}

/* ==========================================================================
   Viewport and Canvas
   ========================================================================== */
.viewport {
  flex: 1;
  overflow-y: auto;
  padding: 40px 20px;
  display: flex;
  justify-content: center;
  background-color: var(--bg-primary);
}

.viewer-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  max-width: 100%;
}

.canvas-wrapper {
  position: relative;
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6), 0 5px 15px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  max-width: 100%;
}

#pdf-render-canvas {
  display: block;
  max-width: 100%;
  height: auto !important;
}

.canvas-loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.canvas-loader.show {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-left-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* ==========================================================================
   Progress Modal (Print Rasterization)
   ========================================================================== */
.progress-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.progress-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes scaleIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.progress-spinner {
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
}

.spinner-large {
  width: 60px;
  height: 60px;
  border: 4px dashed var(--accent-primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1.5s linear infinite;
}

.progress-card h2 {
  font-size: 20px;
  margin-bottom: 8px;
  font-weight: 600;
}

.progress-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.progress-bar-container {
  width: 100%;
  height: 8px;
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 10px;
  width: 0%;
  transition: width 0.2s ease;
}

.progress-subtext {
  font-size: 12px !important;
  opacity: 0.6;
  margin-bottom: 0 !important;
}

/* ==========================================================================
   Printing Framework
   ========================================================================== */
.print-section {
  display: none;
}

@media print {
  /* Hide all interactive and GUI elements */
  body, html {
    background-color: #ffffff !important;
    color: #000000 !important;
    height: auto !important;
    overflow: visible !important;
  }

  body > *:not(#print-section) {
    display: none !important;
  }

  #print-section {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .print-page-image {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    page-break-after: always !important;
    page-break-inside: avoid !important;
  }

  /* Remove page margins and header/footer stamps from browsers */
  @page {
    size: auto;
    margin: 0mm;
  }
}
