/* ==============================================
   RESET & SYSTEM DEFAULTS
   ============================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100vh;
  overflow: hidden;
}

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

/* ==============================================
   SCROLLBAR STYLING
   ============================================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-canvas);
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: var(--border-radius-sm);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ==============================================
   TOP APPLICATION BAR
   ============================================== */
.app-header {
  height: var(--topbar-height);
  background-color: var(--bg-canvas);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-container {
  position: relative;
  width: 100%;
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-width: 0;
}

.header-brand-section {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text-primary);
  flex-shrink: 0;
  transition: opacity var(--transition-fast);
}

.brand-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  border-radius: var(--border-radius-sm);
  display: block;
}

.brand-name {
  font-weight: 600;
  font-size: var(--font-size-sm);
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.header-divider {
  color: var(--border-medium);
  font-size: var(--font-size-xs);
  user-select: none;
}

.doc-path {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--text-faint);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

/* ==============================================
   MAIN WORKSPACE & VIEWPORT
   ============================================== */
.app-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.app-workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-main {
  flex: 1;
  width: 100%;
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
}

.document-viewport {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: var(--space-10) var(--space-6) var(--space-16);
}

.document-container {
  max-width: var(--content-max-width);
  margin: 0 auto;
}

/* ==============================================
   STATE OVERLAYS & MESSAGES
   ============================================== */
.loading-veil {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-canvas);
  opacity: 1;
  transition: opacity var(--transition-fast);
  pointer-events: auto;
}

.loading-veil.is-fading {
  opacity: 0;
  pointer-events: none;
}

.veil-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  text-align: center;
}

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  text-align: center;
  gap: var(--space-4);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border-medium);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.state-title {
  font-size: var(--font-size-lg);
  font-weight: 500;
  color: var(--text-primary);
}

.state-description {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  max-width: 480px;
}

/* ==============================================
   FLOATING SCROLL-TO-TOP BUTTON
   ============================================== */
.btn-scroll-top {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 30;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background-color: var(--bg-surface-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-elevated);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity var(--transition-fast), transform var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.btn-scroll-top:hover {
  color: var(--text-primary);
  background-color: var(--bg-surface-hover);
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.btn-scroll-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.btn-scroll-top svg {
  display: block;
  width: 14px;
  height: 14px;
}

/* ==============================================
   KEYFRAME ANIMATIONS
   ============================================== */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.fade-in {
  animation: fadeIn var(--transition-fast);
}

/* ==============================================
   RESPONSIVE MEDIA QUERIES
   ============================================== */
@media (max-width: 768px) {
  .document-viewport {
    padding: var(--space-6) var(--space-4) var(--space-12);
  }

  .header-container {
    padding: 0 var(--space-4);
  }
}
